<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>227933</bug_id>
          
          <creation_ts>2021-07-13 17:41:51 -0700</creation_ts>
          <short_desc>applyConstraints recaptures camera and creates a lag</short_desc>
          <delta_ts>2021-08-03 10:57:55 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebRTC</component>
          <version>Safari 14</version>
          <rep_platform>Mac (Intel)</rep_platform>
          <op_sys>macOS 11</op_sys>
          <bug_status>REOPENED</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Manik">msach22</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>eric.carlson</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1776823</commentid>
    <comment_count>0</comment_count>
    <who name="Manik">msach22</who>
    <bug_when>2021-07-13 17:41:51 -0700</bug_when>
    <thetext>When using the applyConstraints API on getUserMedia, it seems like Safari is recapturing from the camera. You will also see a lag in the video rendering each time applyConstraints is called.

I&apos;ve set up a basic JSFiddle that helps repro this:
https://jsfiddle.net/3jztwxc6/

```

(async () =&gt; {

const stream = await navigator.mediaDevices.getUserMedia({audio: true, video: true});
const videoElement = document.getElementById(&quot;gum&quot;);
videoElement.srcObject = stream;
const videoTrack = stream.getVideoTracks()[0];

const constraints = videoTrack.getConstraints();

constraints.frameRate = { max: 20, min: 20 };

setTimeout(() =&gt; {
videoTrack.applyConstraints(constraints);

}, 5000);

})();
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1778323</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2021-07-20 17:42:15 -0700</bug_when>
    <thetext>&lt;rdar://problem/80868463&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1781210</commentid>
    <comment_count>2</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2021-08-02 02:13:16 -0700</bug_when>
    <thetext>Thanks for the report Manik, I think this is covered by https://bugs.webkit.org/show_bug.cgi?id=228634.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1781211</commentid>
    <comment_count>3</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2021-08-02 02:13:30 -0700</bug_when>
    <thetext>

*** This bug has been marked as a duplicate of bug 228634 ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1781258</commentid>
    <comment_count>4</comment_count>
    <who name="Manik">msach22</who>
    <bug_when>2021-08-02 09:06:47 -0700</bug_when>
    <thetext>Thanks Youenn - appreciate the fix!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1781647</commentid>
    <comment_count>5</comment_count>
    <who name="Manik">msach22</who>
    <bug_when>2021-08-03 10:23:52 -0700</bug_when>
    <thetext>@Youenn,

We reviewed the patch for the fix and it looks like it will only help if the new FPS constraints is the same as originally requested. I believe it does not fix our issue where we request an FPS os 30 (or default) and use applyConstraints to request 20, 15, etc thereafter.

I&apos;m reopening the issue, please let me know what you think.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1781655</commentid>
    <comment_count>6</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2021-08-03 10:57:55 -0700</bug_when>
    <thetext>Well, we do change the camera setup to match the application frame rate.
The alternative would be to always go to high frame rate and do software frame rate decimation.

To prevent this optimization, you can use track clone to keep a track with high frame rate and another track with a lower frame rate. This should work fine with https://bugs.webkit.org/show_bug.cgi?id=228634 fix.

For instance: https://jsfiddle.net/6qLsm7jp/ (doTest1 should recalibrate, doTest2 should not).
Can you clarify whether you would like doTest1 to not recalibrate either?</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>