<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[269795] branches/safari-610-branch</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/269795">269795</a></dd>
<dt>Author</dt> <dd>repstein@apple.com</dd>
<dt>Date</dt> <dd>2020-11-13 14:16:45 -0800 (Fri, 13 Nov 2020)</dd>
</dl>

<h3>Log Message</h3>
<pre>Cherry-pick <a href="http://trac.webkit.org/projects/webkit/changeset/269121">r269121</a>. rdar://problem/71381839

    [MSE] Handle trackId changing across Initialization Segments
    https://bugs.webkit.org/show_bug.cgi?id=218294
    <rdar://problem/70771306>

    Reviewed by Eric Carlson.

    Source/WebCore:

    Test: media/media-source/media-source-trackid-change.html

    When appending an initialization segment after the receivedFirstInitializationSegment flag is
    true, and when the number of video or audio tracks is 1, the trackId is allowed to change across
    initialiaztion segments. When this occurs, move the TrackBuffer inside the trackBufferMap to
    refer to the new trackId, so that when MediaSamples are parsed, they're put into the correct
    TrackBuffer.

    * Modules/mediasource/SourceBuffer.cpp:
    (WebCore::SourceBuffer::sourceBufferPrivateDidReceiveInitializationSegment):
    * html/track/AudioTrack.cpp:
    (WebCore::AudioTrack::setPrivate):
    * html/track/InbandTextTrack.cpp:
    (WebCore::InbandTextTrack::setPrivate):
    * html/track/VideoTrack.cpp:
    (WebCore::VideoTrack::setPrivate):

    LayoutTests:

    * media/media-source/media-source-trackid-change-expected.txt: Added.
    * media/media-source/media-source-trackid-change.html: Added.

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269121 268f45cc-cd09-0410-ab3c-d52691b4dbfc</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari610branchLayoutTestsChangeLog">branches/safari-610-branch/LayoutTests/ChangeLog</a></li>
<li><a href="#branchessafari610branchSourceWebCoreChangeLog">branches/safari-610-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari610branchSourceWebCoreModulesmediasourceSourceBuffercpp">branches/safari-610-branch/Source/WebCore/Modules/mediasource/SourceBuffer.cpp</a></li>
<li><a href="#branchessafari610branchSourceWebCorehtmltrackAudioTrackcpp">branches/safari-610-branch/Source/WebCore/html/track/AudioTrack.cpp</a></li>
<li><a href="#branchessafari610branchSourceWebCorehtmltrackInbandTextTrackcpp">branches/safari-610-branch/Source/WebCore/html/track/InbandTextTrack.cpp</a></li>
<li><a href="#branchessafari610branchSourceWebCorehtmltrackVideoTrackcpp">branches/safari-610-branch/Source/WebCore/html/track/VideoTrack.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#branchessafari610branchLayoutTestsmediamediasourcemediasourcetrackidchangeexpectedtxt">branches/safari-610-branch/LayoutTests/media/media-source/media-source-trackid-change-expected.txt</a></li>
<li><a href="#branchessafari610branchLayoutTestsmediamediasourcemediasourcetrackidchangehtml">branches/safari-610-branch/LayoutTests/media/media-source/media-source-trackid-change.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari610branchLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-610-branch/LayoutTests/ChangeLog (269794 => 269795)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610-branch/LayoutTests/ChangeLog 2020-11-13 22:16:29 UTC (rev 269794)
+++ branches/safari-610-branch/LayoutTests/ChangeLog    2020-11-13 22:16:45 UTC (rev 269795)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2020-11-13  Russell Epstein  <repstein@apple.com>
+
+        Cherry-pick r269121. rdar://problem/71381839
+
+    [MSE] Handle trackId changing across Initialization Segments
+    https://bugs.webkit.org/show_bug.cgi?id=218294
+    <rdar://problem/70771306>
+    
+    Reviewed by Eric Carlson.
+    
+    Source/WebCore:
+    
+    Test: media/media-source/media-source-trackid-change.html
+    
+    When appending an initialization segment after the receivedFirstInitializationSegment flag is
+    true, and when the number of video or audio tracks is 1, the trackId is allowed to change across
+    initialiaztion segments. When this occurs, move the TrackBuffer inside the trackBufferMap to
+    refer to the new trackId, so that when MediaSamples are parsed, they're put into the correct
+    TrackBuffer.
+    
+    * Modules/mediasource/SourceBuffer.cpp:
+    (WebCore::SourceBuffer::sourceBufferPrivateDidReceiveInitializationSegment):
+    * html/track/AudioTrack.cpp:
+    (WebCore::AudioTrack::setPrivate):
+    * html/track/InbandTextTrack.cpp:
+    (WebCore::InbandTextTrack::setPrivate):
+    * html/track/VideoTrack.cpp:
+    (WebCore::VideoTrack::setPrivate):
+    
+    LayoutTests:
+    
+    * media/media-source/media-source-trackid-change-expected.txt: Added.
+    * media/media-source/media-source-trackid-change.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269121 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-10-28  Jer Noble  <jer.noble@apple.com>
+
+            [MSE] Handle trackId changing across Initialization Segments
+            https://bugs.webkit.org/show_bug.cgi?id=218294
+            <rdar://problem/70771306>
+
+            Reviewed by Eric Carlson.
+
+            * media/media-source/media-source-trackid-change-expected.txt: Added.
+            * media/media-source/media-source-trackid-change.html: Added.
+
</ins><span class="cx"> 2020-11-04  Alan Coon  <alancoon@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Cherry-pick r269025. rdar://problem/70970161
</span></span></pre></div>
<a id="branchessafari610branchLayoutTestsmediamediasourcemediasourcetrackidchangeexpectedtxt"></a>
<div class="addfile"><h4>Added: branches/safari-610-branch/LayoutTests/media/media-source/media-source-trackid-change-expected.txt (0 => 269795)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610-branch/LayoutTests/media/media-source/media-source-trackid-change-expected.txt                               (rev 0)
+++ branches/safari-610-branch/LayoutTests/media/media-source/media-source-trackid-change-expected.txt  2020-11-13 22:16:45 UTC (rev 269795)
</span><span class="lines">@@ -0,0 +1,43 @@
</span><ins>+This tests the ability of the SourceBuffer to change trackIds when a single videoTrack with a different trackId is appended.
+
+RUN(video.src = URL.createObjectURL(source))
+EVENT(sourceopen)
+RUN(source.duration = loader.duration())
+RUN(sourceBuffer = source.addSourceBuffer(loader.type()))
+RUN(sourceBuffer.appendBuffer(loader.initSegment()))
+EVENT(update)
+Append a media segment.
+RUN(sourceBuffer.appendBuffer(loader.mediaSegment(0)))
+EVENT(update)
+Get the current buffered range
+RUN(initialBufferedEnd = sourceBuffer.buffered.end(0))
+Modify an Init Segment to have a different trackID
+RUN(modifiedInitSegment = loader.initSegment().slice(0))
+RUN(initSegmentView = new DataView(modifiedInitSegment))
+EXPECTED (initSegmentView.getInt32(180) == '1') OK
+RUN(initSegmentView.setInt32(180, 3))
+EXPECTED (initSegmentView.getInt32(693) == '2') OK
+RUN(initSegmentView.setInt32(693, 4))
+EXPECTED (initSegmentView.getInt32(1109) == '1') OK
+RUN(initSegmentView.setInt32(1109, 3))
+EXPECTED (initSegmentView.getInt32(1141) == '2') OK
+RUN(initSegmentView.setInt32(1141, 4))
+Append the modified Init Segment
+RUN(sourceBuffer.appendBuffer(modifiedInitSegment))
+EVENT(update)
+EXPECTED (video.videoTracks[0].id == '3') OK
+EXPECTED (video.audioTracks[0].id == '4') OK
+Modify a Media Segment to have a different trackID
+RUN(modifiedMediaSegment = loader.mediaSegment(0).slice(0))
+RUN(mediaSegmentView = new DataView(modifiedMediaSegment))
+EXPECTED (mediaSegmentView.getInt32(44) == '1') OK
+RUN(mediaSegmentView.setInt32(44, 3))
+EXPECTED (mediaSegmentView.getInt32(324) == '2') OK
+RUN(mediaSegmentView.setInt32(324, 4))
+RUN(sourceBuffer.timestampOffset = sourceBuffer.buffered.end(0))
+Append a media segment.
+RUN(sourceBuffer.appendBuffer(modifiedMediaSegment))
+EVENT(update)
+EXPECTED (sourceBuffer.buffered.end(0) > '1') OK
+END OF TEST
+
</ins></span></pre></div>
<a id="branchessafari610branchLayoutTestsmediamediasourcemediasourcetrackidchangehtml"></a>
<div class="addfile"><h4>Added: branches/safari-610-branch/LayoutTests/media/media-source/media-source-trackid-change.html (0 => 269795)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610-branch/LayoutTests/media/media-source/media-source-trackid-change.html                               (rev 0)
+++ branches/safari-610-branch/LayoutTests/media/media-source/media-source-trackid-change.html  2020-11-13 22:16:45 UTC (rev 269795)
</span><span class="lines">@@ -0,0 +1,96 @@
</span><ins>+<!DOCTYPE html>
+<html>
+<head>
+    <title>media-source-trackid-change</title>
+    <script src="media-source-loader.js"></script>
+    <script src="../video-test.js"></script>
+    <script>
+    var loader;
+    var source;
+    var sourceBuffer;
+    var modifiedInitSegment;
+    var modifiedMediaSegment;
+
+    function loaderPromise(loader) {
+        return new Promise((resolve, reject) => {
+            loader.onload = resolve;
+            loader.onerror = reject;
+        });
+    }
+
+    window.addEventListener('load', async event => {
+        try {
+            findMediaElement();
+            loader = new MediaSourceLoader('content/test-fragmented-manifest.json');
+            await loaderPromise(loader);
+
+            source = new MediaSource();
+            run('video.src = URL.createObjectURL(source)');
+            await waitFor(source, 'sourceopen');
+            waitFor(source, 'error').then(endTest);
+            waitForEventAndFail('error');
+
+            run('source.duration = loader.duration()');
+            run('sourceBuffer = source.addSourceBuffer(loader.type())');
+            run('sourceBuffer.appendBuffer(loader.initSegment())');
+
+            await waitFor(sourceBuffer, 'update');
+
+            consoleWrite('Append a media segment.')
+            run('sourceBuffer.appendBuffer(loader.mediaSegment(0))');
+
+            await waitFor(sourceBuffer, 'update');
+
+            consoleWrite('Get the current buffered range');
+            run('initialBufferedEnd = sourceBuffer.buffered.end(0)');
+
+            consoleWrite('Modify an Init Segment to have a different trackID');
+            run('modifiedInitSegment = loader.initSegment().slice(0)');
+            run('initSegmentView = new DataView(modifiedInitSegment)');
+            testExpected('initSegmentView.getInt32(180)', 1);
+            run('initSegmentView.setInt32(180, 3)');
+            testExpected('initSegmentView.getInt32(693)', 2);
+            run('initSegmentView.setInt32(693, 4)');
+            testExpected('initSegmentView.getInt32(1109)', 1);
+            run('initSegmentView.setInt32(1109, 3)');
+            testExpected('initSegmentView.getInt32(1141)', 2);
+            run('initSegmentView.setInt32(1141, 4)');
+
+            consoleWrite('Append the modified Init Segment')
+            run('sourceBuffer.appendBuffer(modifiedInitSegment)');
+            await waitFor(sourceBuffer, 'update');
+
+            testExpected('video.videoTracks[0].id', 3);
+            testExpected('video.audioTracks[0].id', 4);
+
+            consoleWrite('Modify a Media Segment to have a different trackID');
+            run('modifiedMediaSegment = loader.mediaSegment(0).slice(0)');
+            run('mediaSegmentView = new DataView(modifiedMediaSegment)');
+            testExpected('mediaSegmentView.getInt32(44)', 1);
+            run('mediaSegmentView.setInt32(44, 3)');
+            testExpected('mediaSegmentView.getInt32(324)', 2);
+            run('mediaSegmentView.setInt32(324, 4)');
+
+            run('sourceBuffer.timestampOffset = sourceBuffer.buffered.end(0)');
+
+            consoleWrite('Append a media segment.')
+            run('sourceBuffer.appendBuffer(modifiedMediaSegment)');
+
+            await waitFor(sourceBuffer, 'update');
+
+            testExpected('sourceBuffer.buffered.end(0)', initialBufferedEnd, '>');
+
+            endTest();
+        } catch (e) {
+            failTest(`Caught exception: "${e}"`);
+        }
+    });
+    </script>
+</head>
+<body>
+    <div>
+        This tests the ability of the SourceBuffer to change trackIds when a single videoTrack with a different trackId is appended.
+    </div>
+    <video controls></video>
+</body>
+</html>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="branchessafari610branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-610-branch/Source/WebCore/ChangeLog (269794 => 269795)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610-branch/Source/WebCore/ChangeLog      2020-11-13 22:16:29 UTC (rev 269794)
+++ branches/safari-610-branch/Source/WebCore/ChangeLog 2020-11-13 22:16:45 UTC (rev 269795)
</span><span class="lines">@@ -1,5 +1,67 @@
</span><span class="cx"> 2020-11-13  Russell Epstein  <repstein@apple.com>
</span><span class="cx"> 
</span><ins>+        Cherry-pick r269121. rdar://problem/71381839
+
+    [MSE] Handle trackId changing across Initialization Segments
+    https://bugs.webkit.org/show_bug.cgi?id=218294
+    <rdar://problem/70771306>
+    
+    Reviewed by Eric Carlson.
+    
+    Source/WebCore:
+    
+    Test: media/media-source/media-source-trackid-change.html
+    
+    When appending an initialization segment after the receivedFirstInitializationSegment flag is
+    true, and when the number of video or audio tracks is 1, the trackId is allowed to change across
+    initialiaztion segments. When this occurs, move the TrackBuffer inside the trackBufferMap to
+    refer to the new trackId, so that when MediaSamples are parsed, they're put into the correct
+    TrackBuffer.
+    
+    * Modules/mediasource/SourceBuffer.cpp:
+    (WebCore::SourceBuffer::sourceBufferPrivateDidReceiveInitializationSegment):
+    * html/track/AudioTrack.cpp:
+    (WebCore::AudioTrack::setPrivate):
+    * html/track/InbandTextTrack.cpp:
+    (WebCore::InbandTextTrack::setPrivate):
+    * html/track/VideoTrack.cpp:
+    (WebCore::VideoTrack::setPrivate):
+    
+    LayoutTests:
+    
+    * media/media-source/media-source-trackid-change-expected.txt: Added.
+    * media/media-source/media-source-trackid-change.html: Added.
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269121 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-10-28  Jer Noble  <jer.noble@apple.com>
+
+            [MSE] Handle trackId changing across Initialization Segments
+            https://bugs.webkit.org/show_bug.cgi?id=218294
+            <rdar://problem/70771306>
+
+            Reviewed by Eric Carlson.
+
+            Test: media/media-source/media-source-trackid-change.html
+
+            When appending an initialization segment after the receivedFirstInitializationSegment flag is
+            true, and when the number of video or audio tracks is 1, the trackId is allowed to change across
+            initialiaztion segments. When this occurs, move the TrackBuffer inside the trackBufferMap to
+            refer to the new trackId, so that when MediaSamples are parsed, they're put into the correct
+            TrackBuffer.
+
+            * Modules/mediasource/SourceBuffer.cpp:
+            (WebCore::SourceBuffer::sourceBufferPrivateDidReceiveInitializationSegment):
+            * html/track/AudioTrack.cpp:
+            (WebCore::AudioTrack::setPrivate):
+            * html/track/InbandTextTrack.cpp:
+            (WebCore::InbandTextTrack::setPrivate):
+            * html/track/VideoTrack.cpp:
+            (WebCore::VideoTrack::setPrivate):
+
+2020-11-13  Russell Epstein  <repstein@apple.com>
+
</ins><span class="cx">         Cherry-pick r268782. rdar://problem/71381941
</span><span class="cx"> 
</span><span class="cx">     Release assert in ~Node due to render element of pseudo element not getting removed in time
</span></span></pre></div>
<a id="branchessafari610branchSourceWebCoreModulesmediasourceSourceBuffercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-610-branch/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (269794 => 269795)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610-branch/Source/WebCore/Modules/mediasource/SourceBuffer.cpp   2020-11-13 22:16:29 UTC (rev 269794)
+++ branches/safari-610-branch/Source/WebCore/Modules/mediasource/SourceBuffer.cpp      2020-11-13 22:16:45 UTC (rev 269795)
</span><span class="lines">@@ -1111,11 +1111,21 @@
</span><span class="cx">             appendError(true);
</span><span class="cx">             return;
</span><span class="cx">         }
</span><ins>+
+        Vector<std::pair<AtomString, TrackBuffer>> newTrackBuffers;
+
</ins><span class="cx">         // 3.2 Add the appropriate track descriptions from this initialization segment to each of the track buffers.
</span><span class="cx">         ASSERT(segment.audioTracks.size() == audioTracks().length());
</span><span class="cx">         for (auto& audioTrackInfo : segment.audioTracks) {
</span><span class="cx">             if (audioTracks().length() == 1) {
</span><del>-                audioTracks().item(0)->setPrivate(*audioTrackInfo.track);
</del><ins>+                auto* track = audioTracks().item(0);
+                auto oldId = track->id();
+                auto newId = audioTrackInfo.track->id();
+                track->setPrivate(*audioTrackInfo.track);
+                if (newId != oldId) {
+                    auto trackBuffer = m_trackBufferMap.take(oldId);
+                    newTrackBuffers.append(std::make_pair(newId, WTFMove(trackBuffer)));
+                }
</ins><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="lines">@@ -1127,7 +1137,14 @@
</span><span class="cx">         ASSERT(segment.videoTracks.size() == videoTracks().length());
</span><span class="cx">         for (auto& videoTrackInfo : segment.videoTracks) {
</span><span class="cx">             if (videoTracks().length() == 1) {
</span><del>-                videoTracks().item(0)->setPrivate(*videoTrackInfo.track);
</del><ins>+                auto* track = videoTracks().item(0);
+                auto oldId = track->id();
+                auto newId = videoTrackInfo.track->id();
+                track->setPrivate(*videoTrackInfo.track);
+                if (newId != oldId) {
+                    auto trackBuffer = m_trackBufferMap.take(oldId);
+                    newTrackBuffers.append(std::make_pair(newId, WTFMove(trackBuffer)));
+                }
</ins><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="lines">@@ -1139,7 +1156,14 @@
</span><span class="cx">         ASSERT(segment.textTracks.size() == textTracks().length());
</span><span class="cx">         for (auto& textTrackInfo : segment.textTracks) {
</span><span class="cx">             if (textTracks().length() == 1) {
</span><del>-                downcast<InbandTextTrack>(*textTracks().item(0)).setPrivate(*textTrackInfo.track);
</del><ins>+                auto* track = downcast<InbandTextTrack>(textTracks().item(0));
+                auto oldId = track->id();
+                auto newId = textTrackInfo.track->id();
+                track->setPrivate(*textTrackInfo.track);
+                if (newId != oldId) {
+                    auto trackBuffer = m_trackBufferMap.take(oldId);
+                    newTrackBuffers.append(std::make_pair(newId, WTFMove(trackBuffer)));
+                }
</ins><span class="cx">                 break;
</span><span class="cx">             }
</span><span class="cx"> 
</span><span class="lines">@@ -1148,6 +1172,11 @@
</span><span class="cx">             downcast<InbandTextTrack>(*textTrack).setPrivate(*textTrackInfo.track);
</span><span class="cx">         }
</span><span class="cx"> 
</span><ins>+        while (!newTrackBuffers.isEmpty()) {
+            auto trackPair = newTrackBuffers.takeLast();
+            m_trackBufferMap.add(trackPair.first, WTFMove(trackPair.second));
+        }
+
</ins><span class="cx">         // 3.3 Set the need random access point flag on all track buffers to true.
</span><span class="cx">         for (auto& trackBuffer : m_trackBufferMap.values())
</span><span class="cx">             trackBuffer.needRandomAccessFlag = true;
</span></span></pre></div>
<a id="branchessafari610branchSourceWebCorehtmltrackAudioTrackcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-610-branch/Source/WebCore/html/track/AudioTrack.cpp (269794 => 269795)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610-branch/Source/WebCore/html/track/AudioTrack.cpp      2020-11-13 22:16:29 UTC (rev 269794)
+++ branches/safari-610-branch/Source/WebCore/html/track/AudioTrack.cpp 2020-11-13 22:16:45 UTC (rev 269795)
</span><span class="lines">@@ -104,6 +104,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     updateKindFromPrivate();
</span><ins>+    setId(m_private->id());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool AudioTrack::isValidKind(const AtomString& value) const
</span></span></pre></div>
<a id="branchessafari610branchSourceWebCorehtmltrackInbandTextTrackcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-610-branch/Source/WebCore/html/track/InbandTextTrack.cpp (269794 => 269795)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610-branch/Source/WebCore/html/track/InbandTextTrack.cpp 2020-11-13 22:16:29 UTC (rev 269794)
+++ branches/safari-610-branch/Source/WebCore/html/track/InbandTextTrack.cpp    2020-11-13 22:16:45 UTC (rev 269795)
</span><span class="lines">@@ -77,6 +77,7 @@
</span><span class="cx"> 
</span><span class="cx">     setModeInternal(mode());
</span><span class="cx">     updateKindFromPrivate();
</span><ins>+    setId(m_private->id());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InbandTextTrack::setMode(Mode mode)
</span></span></pre></div>
<a id="branchessafari610branchSourceWebCorehtmltrackVideoTrackcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-610-branch/Source/WebCore/html/track/VideoTrack.cpp (269794 => 269795)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-610-branch/Source/WebCore/html/track/VideoTrack.cpp      2020-11-13 22:16:29 UTC (rev 269794)
+++ branches/safari-610-branch/Source/WebCore/html/track/VideoTrack.cpp 2020-11-13 22:16:45 UTC (rev 269795)
</span><span class="lines">@@ -109,6 +109,7 @@
</span><span class="cx"> 
</span><span class="cx">     m_private->setSelected(m_selected);
</span><span class="cx">     updateKindFromPrivate();
</span><ins>+    setId(m_private->id());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool VideoTrack::isValidKind(const AtomString& value) const
</span></span></pre>
</div>
</div>

</body>
</html>