<?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>264894</bug_id>
          
          <creation_ts>2023-11-15 12:26:50 -0800</creation_ts>
          <short_desc>VideoEncoder produces no frames with latencyMode &quot;realtime&quot; when framerate/bitrate are not given</short_desc>
          <delta_ts>2023-11-23 13:10:42 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Media</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 14</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</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="Jacob Bandes-Storch">jacob</reporter>
          <assigned_to name="youenn fablet">youennf</assigned_to>
          <cc>eric.carlson</cc>
    
    <cc>jer.noble</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1992863</commentid>
    <comment_count>0</comment_count>
    <who name="Jacob Bandes-Storch">jacob</who>
    <bug_when>2023-11-15 12:26:50 -0800</bug_when>
    <thetext>VideoEncoder with `latencyMode: &quot;realtime&quot;` but no `bitrate` or `framerate` specified does not output any frames, nor error messages.

Related: https://bugs.webkit.org/show_bug.cgi?id=264893 &amp; https://bugs.webkit.org/show_bug.cgi?id=258669

Steps to reproduce:
1. Visit https://codesandbox.io/s/cocky-ioana-pjyz5v?file=/src/index.mjs
2. Open the console tab and observe the output is &quot;{keyFrames: 0, deltaFrames: 0}&quot; -- i.e. no frames were output whatsoever. No error messages are present.
3. Uncomment `framerate: fps` and `bitrate: 100000` and observe that the output changes to &quot;{keyFrames: 1, deltaFrames: 19}&quot;.

Expected behavior:
If encoding without these parameters is not supported, then the browser should not claim to support the configuration (via isConfigSupported and by not calling the error callback).


Full code below:

```
import &quot;./styles.css&quot;;

async function main() {
  const width = 200;
  const height = 100;
  const img = new ImageData(width, height);
  
  for (let r=0;r&lt;height;r++) {
    for (let c=0;c&lt;width;c++) {
      img.data[(r*width+c)*4+0] = Math.floor(r/height*255);
      img.data[(r*width+c)*4+1] = Math.floor(c/width*255);
      img.data[(r*width+c)*4+2] = 127;
      img.data[(r*width+c)*4+3] = 255;
    }
  }

  const bitmap = await createImageBitmap(img);

  let keyFrames=0;
  let deltaFrames=0;
  const encoder = new VideoEncoder({
    output: (chunk, metadata) =&gt; {
      if (chunk.type===&quot;key&quot;) {
        ++keyFrames;
      } else if (chunk.type === &quot;delta&quot;) {
        ++deltaFrames;
      }
      console.log(&apos;output chunk&apos;,chunk,metadata);
    },
    error: (err) =&gt; {
      console.error(&apos;encode error&apos;, err)
    }
  })

  encoder.addEventListener(&quot;dequeue&quot;, (event) =&gt; {
    console.log(&apos;dequeued&apos;)
  })

  const fps = 30;

  encoder.configure({
    codec: &quot;avc1.42001f&quot;, // Baseline profile (42 00) with level 3.1 (1f)
    width,
    height,
    latencyMode: &quot;realtime&quot;,
    // framerate: fps,
    avc: { format: &quot;annexb&quot; },
    // hardwareAcceleration:&quot;prefer-software&quot;
    // bitrate:100000,
    // bitrate: 10000000,
  });

  for (let i=0; i &lt; 20; i++) {
    const frame = new VideoFrame(bitmap, {
      timestamp:i * 1/fps * 1e6,
      duration:1/fps * 1e6,
    });
    encoder.encode(frame, {keyFrame: i === 0});
    frame.close();
  }

  bitmap.close();
  console.log(&quot;sent frames&quot;);
  
  await encoder.flush();
  console.log(&quot;flushed&quot;, {keyFrames,deltaFrames})
  encoder.close();
  console.log(&quot;closed&quot;, {keyFrames,deltaFrames})
}

main().catch((e) =&gt; console.error(e,e.message));
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1992867</commentid>
    <comment_count>1</comment_count>
    <who name="Jacob Bandes-Storch">jacob</who>
    <bug_when>2023-11-15 12:29:09 -0800</bug_when>
    <thetext>Tested in Safari Technology Preview 182 (Safari 17.4, WebKit 19618.1.4.1). Note that due to https://bugs.webkit.org/show_bug.cgi?id=258669, step 3 does not work in Safari 17.0.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994437</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-11-22 12:27:13 -0800</bug_when>
    <thetext>&lt;rdar://problem/118725549&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994441</commentid>
    <comment_count>3</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2023-11-22 13:03:06 -0800</bug_when>
    <thetext>We might need to set a default bitrate allocation in this case, or bail out.
I wonder what other browsers are doing here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994495</commentid>
    <comment_count>4</comment_count>
    <who name="youenn fablet">youennf</who>
    <bug_when>2023-11-23 00:34:00 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/20842</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994578</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-11-23 12:01:18 -0800</bug_when>
    <thetext>Committed 271087@main (ef16bd3f9b1c): &lt;https://commits.webkit.org/271087@main&gt;

Reviewed commits have been landed. Closing PR #20842 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1994581</commentid>
    <comment_count>6</comment_count>
    <who name="Jacob Bandes-Storch">jacob</who>
    <bug_when>2023-11-23 13:10:42 -0800</bug_when>
    <thetext>Thanks for your quick response on this ticket.

Would there be any way of ensuring that other similar configuration problems in the future produce an isConfigSupported=false response?</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>