<?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>272521</bug_id>
          
          <creation_ts>2024-04-11 02:48:23 -0700</creation_ts>
          <short_desc>[MSE] Decoding errors when appending segment with B-frames and previous segment ends with an I-frame</short_desc>
          <delta_ts>2024-04-15 23:38:14 -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>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>
          
          
          <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="Carlos Bentzen">cadubentzen</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2027739</commentid>
    <comment_count>0</comment_count>
    <who name="Carlos Bentzen">cadubentzen</who>
    <bug_when>2024-04-11 02:48:23 -0700</bug_when>
    <thetext>When a segment containing B-frames is appended (i.e. with out-of-display-order frames, and samples PTS and DTS values don&apos;t always match), WebKit has logic to erase frames from the previous segment and avoid decoding glitches (see bug 206412). However, the current logic falls short in one edge case: if the previous segment ends with an I-frame in the overlap region to be erased.

If the demuxer honors ISOBMFF edit lists, then the first I-frame from an incoming segment with B-frames can be placed earlier in decoding order than the last (I-)frame from the previous segment (potentially with different resolution), and that last I-frame doesn&apos;t get erased, and will be pushed for decoding. This confuses the decoder and the following P/B frames will fail to decode or decode incorrectly with artifacts due to missing/incorrect reference frame.

When this edge case is triggered:
- In Apple WebKit&apos;s, playback directly stops and we get an error event.
- In upstream GStreamer-based ports we don&apos;t have this problem due to ignoring edit lists (see bug 231019). But in downstream WPE ports where it&apos;s enabled, we get macroblock artifacts, but could potentially get fatal errors as well depending on the decoder plugin that&apos;s used.

Hosted test page to reproduce it manually: https://people.igalia.com/cadubentzen/webkit/out-of-order (EXPECTED: playback failure on Safari at 4s. For GStreamer-based ports, not reproducible upstream due to ignoring edit lists). It works with Firefox and Chromium.

A detailed analysis was done from a case that triggered this in https://github.com/WebPlatformForEmbedded/WPEWebKit/issues/1301 and https://github.com/WebPlatformForEmbedded/WPEWebKit/pull/1184. Credits to Vivek Arumugam.

I have patch with a possible fix and a layout test that reproduces this with `video/mock`, just need a bit more checking before opening for review. The patch is still only a mitigation as this scenario isn&apos;t well defined in the spec (https://github.com/w3c/media-source/issues/187).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2027747</commentid>
    <comment_count>1</comment_count>
    <who name="Carlos Bentzen">cadubentzen</who>
    <bug_when>2024-04-11 03:13:26 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/27033</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2028736</commentid>
    <comment_count>2</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-04-15 23:38:00 -0700</bug_when>
    <thetext>Committed 277532@main (ec49bb21041c): &lt;https://commits.webkit.org/277532@main&gt;

Reviewed commits have been landed. Closing PR #27033 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2028737</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-04-15 23:38:14 -0700</bug_when>
    <thetext>&lt;rdar://problem/126533350&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>