<?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>252886</bug_id>
          
          <creation_ts>2023-02-23 22:38:41 -0800</creation_ts>
          <short_desc>[MSE] Too many durationchange events fired when appending data.</short_desc>
          <delta_ts>2023-03-01 16:03:02 -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>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=252782</see_also>
          <bug_file_loc>https://jyavenard.github.io/htmltests/tests/mse_webm/vorbis_timestampOffset.html</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="Jean-Yves Avenard [:jya]">jean-yves.avenard</reporter>
          <assigned_to name="Jean-Yves Avenard [:jya]">jean-yves.avenard</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1936447</commentid>
    <comment_count>0</comment_count>
    <who name="Jean-Yves Avenard [:jya]">jean-yves.avenard</who>
    <bug_when>2023-02-23 22:38:41 -0800</bug_when>
    <thetext>Per spec MSE spec and the Coded Frame Processing algorithm [1]
&quot;5. if the media segment contains data beyond the current duration, then run the duration change algorithm with new duration set to the maximum of the current duration and the [[group end timestamp]].&quot;

Which occurs once all frames of a buffer added to a source buffer have been processed.

However, the SourceBufferPrivate.cpp didReceiveSample performs this step for every single frame received.
https://jyavenard.github.io/htmltests/tests/mse_webm/vorbis_timestampOffset.html
(need bug 252782 fixed)

results in the following result:
```
1237: ok(true) Receive a sourceopen event
1303: got abort event
1303: got emptied event
1306: got loadstart event
1371: got durationchange event
1373: got loadedmetadata event
1374: got durationchange event
1381: Append a media segment.
1390: SourceBuffer buffered ranges grew from TimeRanges:  to TimeRanges: [0, 1.3392199546485262)
1390: Append a media segment.
1439: got durationchange event
1440: got loadeddata event
1440: got canplay event
1441: got canplaythrough event
1457: SourceBuffer buffered ranges grew from TimeRanges: [0, 1.3392199546485262) to TimeRanges: [0, 2.678440657773526)
1458: Append a media segment.
1520: got durationchange event
1521: got durationchange event
1522: got durationchange event
1522: got durationchange event
1523: got durationchange event
1523: got durationchange event
1524: got durationchange event
1525: got durationchange event
1526: got durationchange event
1526: got durationchange event
1527: got durationchange event
1528: got durationchange event
1529: got durationchange event
1530: got durationchange event
1530: got durationchange event
1531: got durationchange event
1532: got durationchange event
1532: got durationchange event
1533: got durationchange event
1534: got durationchange event
1535: got durationchange event
1537: got durationchange event
1538: got durationchange event
1539: got durationchange event
1539: got durationchange event
1540: got durationchange event
1541: got durationchange event
```

We get one `durationchange` event for every single frame added to the second buffer after the initial `durationchange` fired following the first segment.

Only one `durationchange` event should be fired.

[1] https://w3c.github.io/media-source/#sourcebuffer-coded-frame-processing the last step is:
[2] https://searchfox.org/wubkat/rev/e4f3157afc6ca0cf36b48e57e2337b4ceb66d459/Source/WebCore/platform/graphics/SourceBufferPrivate.cpp#1088-1093</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1936448</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-02-23 22:39:08 -0800</bug_when>
    <thetext>&lt;rdar://problem/105870526&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1937272</commentid>
    <comment_count>2</comment_count>
    <who name="Jean-Yves Avenard [:jya]">jean-yves.avenard</who>
    <bug_when>2023-02-27 20:47:30 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/10777</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1937953</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-03-01 16:02:51 -0800</bug_when>
    <thetext>Committed 261029@main (04a684748a69): &lt;https://commits.webkit.org/261029@main&gt;

Reviewed commits have been landed. Closing PR #10777 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>