<!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>[168790] branches/safari-538.34-branch/Source/WebCore</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/168790">168790</a></dd>
<dt>Author</dt> <dd>lforschler@apple.com</dd>
<dt>Date</dt> <dd>2014-05-13 23:32:56 -0700 (Tue, 13 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merged <a href="http://trac.webkit.org/projects/webkit/changeset/168508">r168508</a>.  </pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari53834branchSourceWebCoreChangeLog">branches/safari-538.34-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari53834branchSourceWebCoreModulesmediasourceSourceBuffercpp">branches/safari-538.34-branch/Source/WebCore/Modules/mediasource/SourceBuffer.cpp</a></li>
<li><a href="#branchessafari53834branchSourceWebCoreModulesmediasourceSourceBufferh">branches/safari-538.34-branch/Source/WebCore/Modules/mediasource/SourceBuffer.h</a></li>
<li><a href="#branchessafari53834branchSourceWebCoreplatformgraphicsSourceBufferPrivateh">branches/safari-538.34-branch/Source/WebCore/platform/graphics/SourceBufferPrivate.h</a></li>
<li><a href="#branchessafari53834branchSourceWebCoreplatformgraphicsSourceBufferPrivateClienth">branches/safari-538.34-branch/Source/WebCore/platform/graphics/SourceBufferPrivateClient.h</a></li>
<li><a href="#branchessafari53834branchSourceWebCoreplatformgraphicsavfoundationobjcSourceBufferPrivateAVFObjCh">branches/safari-538.34-branch/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h</a></li>
<li><a href="#branchessafari53834branchSourceWebCoreplatformgraphicsavfoundationobjcSourceBufferPrivateAVFObjCmm">branches/safari-538.34-branch/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm</a></li>
<li><a href="#branchessafari53834branchSourceWebCoreplatformgraphicsgstreamerSourceBufferPrivateGStreamercpp">branches/safari-538.34-branch/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.cpp</a></li>
<li><a href="#branchessafari53834branchSourceWebCoreplatformgraphicsgstreamerSourceBufferPrivateGStreamerh">branches/safari-538.34-branch/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.h</a></li>
<li><a href="#branchessafari53834branchSourceWebCoreplatformmockmediasourceMockSourceBufferPrivatecpp">branches/safari-538.34-branch/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp</a></li>
<li><a href="#branchessafari53834branchSourceWebCoreplatformmockmediasourceMockSourceBufferPrivateh">branches/safari-538.34-branch/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari53834branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-538.34-branch/Source/WebCore/ChangeLog (168789 => 168790)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-538.34-branch/Source/WebCore/ChangeLog        2014-05-14 06:24:48 UTC (rev 168789)
+++ branches/safari-538.34-branch/Source/WebCore/ChangeLog        2014-05-14 06:32:56 UTC (rev 168790)
</span><span class="lines">@@ -1,5 +1,49 @@
</span><span class="cx"> 2014-04-17  Lucas Forschler  &lt;lforschler@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r168508
+
+    2014-05-08  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+            [MSE][Mac] Move AVStreamDataParser off-main-thread.
+            https://bugs.webkit.org/show_bug.cgi?id=132698
+
+            Reviewed by Eric Carlson.
+
+            -[AVStreamDataParser appendStreamData:] can casue the main thread to hang when a
+            large amount of media data is appended at once. Move the actual parsing of data
+            to a background (synchronous) dispatch queue, and split SourceBuffer::appendBufferTimerFired
+            into two functions, the latter of which will be called after the background queue
+            completes.
+
+            * Modules/mediasource/SourceBuffer.cpp:
+            (WebCore::SourceBuffer::appendBufferTimerFired): Split into sourceBufferPrivateAppendComplete.
+            (WebCore::SourceBuffer::sourceBufferPrivateAppendComplete): Split from appendBufferTimerFired.
+            * Modules/mediasource/SourceBuffer.h:
+            * platform/graphics/SourceBufferPrivate.h:
+            * platform/graphics/SourceBufferPrivateClient.h:
+            * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h:
+            * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
+            (-[WebAVStreamDataParserListener streamDataParser:didParseStreamDataAsAsset:]): Re-dispatch to the
+                    web thread.
+            (-[WebAVStreamDataParserListener streamDataParser:didParseStreamDataAsAsset:withDiscontinuity:]): Ditto.
+            (-[WebAVStreamDataParserListener streamDataParser:didFailToParseStreamDataWithError:]): Ditto.
+            (-[WebAVStreamDataParserListener streamDataParser:didProvideMediaData:forTrackID:mediaType:flags:]): Ditto.
+            (-[WebAVStreamDataParserListener streamDataParser:didReachEndOfTrackWithTrackID:mediaType:]): Ditto.
+            (-[WebAVStreamDataParserListener streamDataParser:didProvideContentKeyRequestInitializationData:forTrackID:]): Ditto.
+            (WebCore::globalDataParserQueue): Added.
+            (WebCore::SourceBufferPrivateAVFObjC::append): Dispatch to the globalDataParserQueue.
+            (WebCore::SourceBufferPrivateAVFObjC::appendCompleted): Added.
+            * platform/mock/mediasource/MockSourceBufferPrivate.cpp:
+            (WebCore::MockSourceBufferPrivate::append): Adopt sourceBufferPrivateAppendComplete.
+            * platform/mock/mediasource/MockSourceBufferPrivate.h:
+
+            Update SourceBufferPrivateGStreamer to match the new append return value:
+            * platform/graphics/gstreamer/SourceBufferPrivateGStreamer.cpp:
+            (WebCore::SourceBufferPrivateGStreamer::append):
+            * platform/graphics/gstreamer/SourceBufferPrivateGStreamer.h:
+
+2014-04-17  Lucas Forschler  &lt;lforschler@apple.com&gt;
+
</ins><span class="cx">         Merge r168473
</span><span class="cx"> 
</span><span class="cx">     2014-05-08  Antti Koivisto  &lt;antti@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari53834branchSourceWebCoreModulesmediasourceSourceBuffercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-538.34-branch/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (168789 => 168790)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-538.34-branch/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2014-05-14 06:24:48 UTC (rev 168789)
+++ branches/safari-538.34-branch/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2014-05-14 06:32:56 UTC (rev 168790)
</span><span class="lines">@@ -472,31 +472,36 @@
</span><span class="cx">     // https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#sourcebuffer-segment-parser-loop
</span><span class="cx">     // When the segment parser loop algorithm is invoked, run the following steps:
</span><span class="cx"> 
</span><del>-    SourceBufferPrivate::AppendResult result = SourceBufferPrivate::AppendSucceeded;
-    do {
-        // 1. Loop Top: If the input buffer is empty, then jump to the need more data step below.
-        if (!m_pendingAppendData.size())
-            break;
</del><ins>+    // 1. Loop Top: If the input buffer is empty, then jump to the need more data step below.
+    if (!m_pendingAppendData.size()) {
+        sourceBufferPrivateAppendComplete(m_private.get(), AppendSucceeded);
+        return;
+    }
</ins><span class="cx"> 
</span><del>-        result = m_private-&gt;append(m_pendingAppendData.data(), appendSize);
-        m_pendingAppendData.clear();
</del><ins>+    m_private-&gt;append(m_pendingAppendData.data(), appendSize);
+    m_pendingAppendData.clear();
+}
</ins><span class="cx"> 
</span><del>-        // 2. If the input buffer contains bytes that violate the SourceBuffer byte stream format specification,
-        // then run the end of stream algorithm with the error parameter set to &quot;decode&quot; and abort this algorithm.
-        if (result == SourceBufferPrivate::ParsingFailed) {
-            m_source-&gt;streamEndedWithError(decodeError(), IgnorableExceptionCode());
-            break;
-        }
</del><ins>+void SourceBuffer::sourceBufferPrivateAppendComplete(SourceBufferPrivate*, AppendResult result)
+{
+    // Section 3.5.5 Buffer Append Algorithm, ctd.
+    // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#sourcebuffer-buffer-append
</ins><span class="cx"> 
</span><del>-        // NOTE: Steps 3 - 6 enforced by sourceBufferPrivateDidReceiveInitializationSegment() and
-        // sourceBufferPrivateDidReceiveSample below.
</del><ins>+    // 2. If the input buffer contains bytes that violate the SourceBuffer byte stream format specification,
+    // then run the end of stream algorithm with the error parameter set to &quot;decode&quot; and abort this algorithm.
+    if (result == ParsingFailed) {
+        m_source-&gt;streamEndedWithError(decodeError(), IgnorableExceptionCode());
+        return;
+    }
</ins><span class="cx"> 
</span><del>-        // 7. Need more data: Return control to the calling algorithm.
-    } while (0);
</del><ins>+    // NOTE: Steps 3 - 6 enforced by sourceBufferPrivateDidReceiveInitializationSegment() and
+    // sourceBufferPrivateDidReceiveSample below.
</ins><span class="cx"> 
</span><ins>+    // 7. Need more data: Return control to the calling algorithm.
+
</ins><span class="cx">     // NOTE: return to Section 3.5.5
</span><span class="cx">     // 2.If the segment parser loop algorithm in the previous step was aborted, then abort this algorithm.
</span><del>-    if (result != SourceBufferPrivate::AppendSucceeded)
</del><ins>+    if (result != AppendSucceeded)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     // 3. Set the updating attribute to false.
</span></span></pre></div>
<a id="branchessafari53834branchSourceWebCoreModulesmediasourceSourceBufferh"></a>
<div class="modfile"><h4>Modified: branches/safari-538.34-branch/Source/WebCore/Modules/mediasource/SourceBuffer.h (168789 => 168790)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-538.34-branch/Source/WebCore/Modules/mediasource/SourceBuffer.h        2014-05-14 06:24:48 UTC (rev 168789)
+++ branches/safari-538.34-branch/Source/WebCore/Modules/mediasource/SourceBuffer.h        2014-05-14 06:32:56 UTC (rev 168790)
</span><span class="lines">@@ -118,8 +118,8 @@
</span><span class="cx">     virtual void sourceBufferPrivateDidBecomeReadyForMoreSamples(SourceBufferPrivate*, AtomicString trackID) override;
</span><span class="cx">     virtual void sourceBufferPrivateSeekToTime(SourceBufferPrivate*, const MediaTime&amp;);
</span><span class="cx">     virtual MediaTime sourceBufferPrivateFastSeekTimeForMediaTime(SourceBufferPrivate*, const MediaTime&amp;, const MediaTime&amp; negativeThreshold, const MediaTime&amp; positiveThreshold);
</span><ins>+    virtual void sourceBufferPrivateAppendComplete(SourceBufferPrivate*, AppendResult) override;
</ins><span class="cx"> 
</span><del>-
</del><span class="cx">     // AudioTrackClient
</span><span class="cx">     virtual void audioTrackEnabledChanged(AudioTrack*) override;
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari53834branchSourceWebCoreplatformgraphicsSourceBufferPrivateh"></a>
<div class="modfile"><h4>Modified: branches/safari-538.34-branch/Source/WebCore/platform/graphics/SourceBufferPrivate.h (168789 => 168790)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-538.34-branch/Source/WebCore/platform/graphics/SourceBufferPrivate.h        2014-05-14 06:24:48 UTC (rev 168789)
+++ branches/safari-538.34-branch/Source/WebCore/platform/graphics/SourceBufferPrivate.h        2014-05-14 06:32:56 UTC (rev 168790)
</span><span class="lines">@@ -49,12 +49,7 @@
</span><span class="cx"> 
</span><span class="cx">     virtual void setClient(SourceBufferPrivateClient*) = 0;
</span><span class="cx"> 
</span><del>-    enum AppendResult {
-        AppendSucceeded,
-        ReadStreamFailed,
-        ParsingFailed,
-    };
-    virtual AppendResult append(const unsigned char* data, unsigned length) = 0;
</del><ins>+    virtual void append(const unsigned char* data, unsigned length) = 0;
</ins><span class="cx">     virtual void abort() = 0;
</span><span class="cx">     virtual void removedFromMediaSource() = 0;
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari53834branchSourceWebCoreplatformgraphicsSourceBufferPrivateClienth"></a>
<div class="modfile"><h4>Modified: branches/safari-538.34-branch/Source/WebCore/platform/graphics/SourceBufferPrivateClient.h (168789 => 168790)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-538.34-branch/Source/WebCore/platform/graphics/SourceBufferPrivateClient.h        2014-05-14 06:24:48 UTC (rev 168789)
+++ branches/safari-538.34-branch/Source/WebCore/platform/graphics/SourceBufferPrivateClient.h        2014-05-14 06:32:56 UTC (rev 168790)
</span><span class="lines">@@ -77,6 +77,13 @@
</span><span class="cx"> 
</span><span class="cx">     virtual MediaTime sourceBufferPrivateFastSeekTimeForMediaTime(SourceBufferPrivate*, const MediaTime&amp; time, const MediaTime&amp;, const MediaTime&amp;) { return time; }
</span><span class="cx">     virtual void sourceBufferPrivateSeekToTime(SourceBufferPrivate*, const MediaTime&amp;) { };
</span><ins>+
+    enum AppendResult {
+        AppendSucceeded,
+        ReadStreamFailed,
+        ParsingFailed,
+    };
+    virtual void sourceBufferPrivateAppendComplete(SourceBufferPrivate*, AppendResult) = 0;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari53834branchSourceWebCoreplatformgraphicsavfoundationobjcSourceBufferPrivateAVFObjCh"></a>
<div class="modfile"><h4>Modified: branches/safari-538.34-branch/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h (168789 => 168790)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-538.34-branch/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h        2014-05-14 06:24:48 UTC (rev 168789)
+++ branches/safari-538.34-branch/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h        2014-05-14 06:32:56 UTC (rev 168790)
</span><span class="lines">@@ -91,7 +91,7 @@
</span><span class="cx"> 
</span><span class="cx">     // SourceBufferPrivate overrides
</span><span class="cx">     virtual void setClient(SourceBufferPrivateClient*) override;
</span><del>-    virtual AppendResult append(const unsigned char* data, unsigned length) override;
</del><ins>+    virtual void append(const unsigned char* data, unsigned length) override;
</ins><span class="cx">     virtual void abort() override;
</span><span class="cx">     virtual void removedFromMediaSource() override;
</span><span class="cx">     virtual MediaPlayer::ReadyState readyState() const override;
</span><span class="lines">@@ -108,6 +108,7 @@
</span><span class="cx">     void flushAndEnqueueNonDisplayingSamples(Vector&lt;RefPtr&lt;MediaSample&gt;&gt;, AVSampleBufferDisplayLayer*);
</span><span class="cx"> 
</span><span class="cx">     void didBecomeReadyForMoreSamples(int trackID);
</span><ins>+    void appendCompleted();
</ins><span class="cx">     void destroyRenderers();
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;RefPtr&lt;VideoTrackPrivateMediaSourceAVFObjC&gt;&gt; m_videoTracks;
</span></span></pre></div>
<a id="branchessafari53834branchSourceWebCoreplatformgraphicsavfoundationobjcSourceBufferPrivateAVFObjCmm"></a>
<div class="modfile"><h4>Modified: branches/safari-538.34-branch/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm (168789 => 168790)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-538.34-branch/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm        2014-05-14 06:24:48 UTC (rev 168789)
+++ branches/safari-538.34-branch/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm        2014-05-14 06:32:56 UTC (rev 168790)
</span><span class="lines">@@ -185,7 +185,11 @@
</span><span class="cx">     UNUSED_PARAM(streamDataParser);
</span><span class="cx"> #endif
</span><span class="cx">     ASSERT(streamDataParser == _parser);
</span><del>-    _parent-&gt;didParseStreamDataAsAsset(asset);
</del><ins>+    RefPtr&lt;WebCore::SourceBufferPrivateAVFObjC&gt; strongParent = _parent;
+    RetainPtr&lt;AVAsset*&gt; strongAsset = asset;
+    callOnMainThread([strongParent, strongAsset] {
+        strongParent-&gt;didParseStreamDataAsAsset(strongAsset.get());
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)streamDataParser:(AVStreamDataParser *)streamDataParser didParseStreamDataAsAsset:(AVAsset *)asset withDiscontinuity:(BOOL)discontinuity
</span><span class="lines">@@ -195,7 +199,11 @@
</span><span class="cx">     UNUSED_PARAM(streamDataParser);
</span><span class="cx"> #endif
</span><span class="cx">     ASSERT(streamDataParser == _parser);
</span><del>-    _parent-&gt;didParseStreamDataAsAsset(asset);
</del><ins>+    RefPtr&lt;WebCore::SourceBufferPrivateAVFObjC&gt; strongParent = _parent;
+    RetainPtr&lt;AVAsset*&gt; strongAsset = asset;
+    callOnMainThread([strongParent, strongAsset] {
+        strongParent-&gt;didParseStreamDataAsAsset(strongAsset.get());
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)streamDataParser:(AVStreamDataParser *)streamDataParser didFailToParseStreamDataWithError:(NSError *)error
</span><span class="lines">@@ -204,25 +212,38 @@
</span><span class="cx">     UNUSED_PARAM(streamDataParser);
</span><span class="cx"> #endif
</span><span class="cx">     ASSERT(streamDataParser == _parser);
</span><del>-    _parent-&gt;didFailToParseStreamDataWithError(error);
</del><ins>+    RefPtr&lt;WebCore::SourceBufferPrivateAVFObjC&gt; strongParent = _parent;
+    RetainPtr&lt;NSError&gt; strongError = error;
+    callOnMainThread([strongParent, strongError] {
+        strongParent-&gt;didFailToParseStreamDataWithError(strongError.get());
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)streamDataParser:(AVStreamDataParser *)streamDataParser didProvideMediaData:(CMSampleBufferRef)mediaData forTrackID:(CMPersistentTrackID)trackID mediaType:(NSString *)mediaType flags:(NSUInteger)flags
</del><ins>+- (void)streamDataParser:(AVStreamDataParser *)streamDataParser didProvideMediaData:(CMSampleBufferRef)sample forTrackID:(CMPersistentTrackID)trackID mediaType:(NSString *)nsMediaType flags:(NSUInteger)flags
</ins><span class="cx"> {
</span><span class="cx"> #if ASSERT_DISABLED
</span><span class="cx">     UNUSED_PARAM(streamDataParser);
</span><span class="cx"> #endif
</span><span class="cx">     ASSERT(streamDataParser == _parser);
</span><del>-    _parent-&gt;didProvideMediaDataForTrackID(trackID, mediaData, mediaType, flags);
</del><ins>+    RefPtr&lt;WebCore::SourceBufferPrivateAVFObjC&gt; strongParent = _parent;
+    RetainPtr&lt;CMSampleBufferRef&gt; strongSample = sample;
+    String mediaType = nsMediaType;
+    callOnMainThread([strongParent, strongSample, trackID, mediaType, flags] {
+        strongParent-&gt;didProvideMediaDataForTrackID(trackID, strongSample.get(), mediaType, flags);
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)streamDataParser:(AVStreamDataParser *)streamDataParser didReachEndOfTrackWithTrackID:(CMPersistentTrackID)trackID mediaType:(NSString *)mediaType
</del><ins>+- (void)streamDataParser:(AVStreamDataParser *)streamDataParser didReachEndOfTrackWithTrackID:(CMPersistentTrackID)trackID mediaType:(NSString *)nsMediaType
</ins><span class="cx"> {
</span><span class="cx"> #if ASSERT_DISABLED
</span><span class="cx">     UNUSED_PARAM(streamDataParser);
</span><span class="cx"> #endif
</span><span class="cx">     ASSERT(streamDataParser == _parser);
</span><del>-    _parent-&gt;didReachEndOfTrackWithTrackID(trackID, mediaType);
</del><ins>+    RefPtr&lt;WebCore::SourceBufferPrivateAVFObjC&gt; strongParent = _parent;
+    String mediaType = nsMediaType;
+    callOnMainThread([strongParent, trackID, mediaType] {
+        strongParent-&gt;didReachEndOfTrackWithTrackID(trackID, mediaType);
+    });
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)streamDataParser:(AVStreamDataParser *)streamDataParser didProvideContentKeyRequestInitializationData:(NSData *)initData forTrackID:(CMPersistentTrackID)trackID
</span><span class="lines">@@ -231,7 +252,11 @@
</span><span class="cx">     UNUSED_PARAM(streamDataParser);
</span><span class="cx"> #endif
</span><span class="cx">     ASSERT(streamDataParser == _parser);
</span><del>-    _parent-&gt;didProvideContentKeyRequestInitializationDataForTrackID(initData, trackID);
</del><ins>+    RefPtr&lt;WebCore::SourceBufferPrivateAVFObjC&gt; strongParent = _parent;
+    RetainPtr&lt;NSData&gt; strongData = initData;
+    callOnMainThread([strongParent, strongData, trackID] {
+        strongParent-&gt;didProvideContentKeyRequestInitializationDataForTrackID(strongData.get(), trackID);
+    });
</ins><span class="cx"> }
</span><span class="cx"> @end
</span><span class="cx"> 
</span><span class="lines">@@ -453,17 +478,41 @@
</span><span class="cx">     m_client = client;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-SourceBufferPrivate::AppendResult SourceBufferPrivateAVFObjC::append(const unsigned char* data, unsigned length)
</del><ins>+static dispatch_queue_t globalDataParserQueue()
</ins><span class="cx"> {
</span><del>-    m_parsingSucceeded = true;
</del><ins>+    static dispatch_queue_t globalQueue;
+    static dispatch_once_t onceToken;
+    dispatch_once(&amp;onceToken, ^{
+        globalQueue = dispatch_queue_create(&quot;SourceBufferPrivateAVFObjC data parser queue&quot;, DISPATCH_QUEUE_SERIAL);
+    });
+    return globalQueue;
+}
</ins><span class="cx"> 
</span><ins>+void SourceBufferPrivateAVFObjC::append(const unsigned char* data, unsigned length)
+{
</ins><span class="cx">     LOG(Media, &quot;SourceBufferPrivateAVFObjC::append(%p) - data:%p, length:%d&quot;, this, data, length);
</span><del>-    [m_parser appendStreamData:[NSData dataWithBytes:data length:length]];
</del><span class="cx"> 
</span><ins>+    RetainPtr&lt;NSData&gt; nsData = adoptNS([[NSData alloc] initWithBytes:data length:length]);
+    RefPtr&lt;SourceBufferPrivateAVFObjC&gt; strongThis = this;
+
+    m_parsingSucceeded = true;
+
+    dispatch_async(globalDataParserQueue(), [nsData, strongThis] {
+        [strongThis-&gt;m_parser appendStreamData:nsData.get()];
+
+        callOnMainThread([strongThis] {
+            strongThis-&gt;appendCompleted();
+        });
+    });
+}
+
+void SourceBufferPrivateAVFObjC::appendCompleted()
+{
</ins><span class="cx">     if (m_parsingSucceeded &amp;&amp; m_mediaSource)
</span><span class="cx">         m_mediaSource-&gt;player()-&gt;setLoadingProgresssed(true);
</span><span class="cx"> 
</span><del>-    return m_parsingSucceeded ? AppendSucceeded : ParsingFailed;
</del><ins>+    if (m_client)
+        m_client-&gt;sourceBufferPrivateAppendComplete(this, m_parsingSucceeded ? SourceBufferPrivateClient::AppendSucceeded : SourceBufferPrivateClient::ParsingFailed);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void SourceBufferPrivateAVFObjC::abort()
</span></span></pre></div>
<a id="branchessafari53834branchSourceWebCoreplatformgraphicsgstreamerSourceBufferPrivateGStreamercpp"></a>
<div class="modfile"><h4>Modified: branches/safari-538.34-branch/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.cpp (168789 => 168790)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-538.34-branch/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.cpp        2014-05-14 06:24:48 UTC (rev 168789)
+++ branches/safari-538.34-branch/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.cpp        2014-05-14 06:32:56 UTC (rev 168790)
</span><span class="lines">@@ -46,12 +46,12 @@
</span><span class="cx">     m_type = contentType.type();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-SourceBufferPrivate::AppendResult SourceBufferPrivateGStreamer::append(const unsigned char* data, unsigned length)
</del><ins>+void SourceBufferPrivateGStreamer::append(const unsigned char* data, unsigned length)
</ins><span class="cx"> {
</span><del>-    AppendResult result = AppendSucceeded;
</del><span class="cx">     ASSERT(m_client);
</span><span class="cx">     m_client-&gt;didReceiveData(reinterpret_cast_ptr&lt;const char*&gt;(data), length, m_type);
</span><del>-    return result;
</del><ins>+
+    // FIXME: call SourceBufferPrivateClient::sourceBufferPrivateAppendComplete().
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void SourceBufferPrivateGStreamer::abort()
</span></span></pre></div>
<a id="branchessafari53834branchSourceWebCoreplatformgraphicsgstreamerSourceBufferPrivateGStreamerh"></a>
<div class="modfile"><h4>Modified: branches/safari-538.34-branch/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.h (168789 => 168790)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-538.34-branch/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.h        2014-05-14 06:24:48 UTC (rev 168789)
+++ branches/safari-538.34-branch/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.h        2014-05-14 06:32:56 UTC (rev 168790)
</span><span class="lines">@@ -45,7 +45,7 @@
</span><span class="cx">     ~SourceBufferPrivateGStreamer() { }
</span><span class="cx"> 
</span><span class="cx">     void setClient(SourceBufferPrivateClient*) { }
</span><del>-    AppendResult append(const unsigned char*, unsigned);
</del><ins>+    void append(const unsigned char*, unsigned);
</ins><span class="cx">     void abort();
</span><span class="cx">     void removedFromMediaSource();
</span><span class="cx">     MediaPlayer::ReadyState readyState() const { return m_readyState; }
</span></span></pre></div>
<a id="branchessafari53834branchSourceWebCoreplatformmockmediasourceMockSourceBufferPrivatecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-538.34-branch/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp (168789 => 168790)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-538.34-branch/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp        2014-05-14 06:24:48 UTC (rev 168789)
+++ branches/safari-538.34-branch/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp        2014-05-14 06:32:56 UTC (rev 168790)
</span><span class="lines">@@ -114,12 +114,12 @@
</span><span class="cx">     m_client = client;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-SourceBufferPrivate::AppendResult MockSourceBufferPrivate::append(const unsigned char* data, unsigned length)
</del><ins>+void MockSourceBufferPrivate::append(const unsigned char* data, unsigned length)
</ins><span class="cx"> {
</span><span class="cx">     m_inputBuffer.append(data, length);
</span><del>-    AppendResult result = AppendSucceeded;
</del><ins>+    SourceBufferPrivateClient::AppendResult result = SourceBufferPrivateClient::AppendSucceeded;
</ins><span class="cx"> 
</span><del>-    while (m_inputBuffer.size() &amp;&amp; result == AppendSucceeded) {
</del><ins>+    while (m_inputBuffer.size() &amp;&amp; result == SourceBufferPrivateClient::AppendSucceeded) {
</ins><span class="cx">         RefPtr&lt;ArrayBuffer&gt; buffer = ArrayBuffer::create(m_inputBuffer.data(), m_inputBuffer.size());
</span><span class="cx">         size_t boxLength = MockBox::peekLength(buffer.get());
</span><span class="cx">         if (boxLength &gt; buffer-&gt;byteLength())
</span><span class="lines">@@ -133,12 +133,13 @@
</span><span class="cx">             MockSampleBox sampleBox = MockSampleBox(buffer.get());
</span><span class="cx">             didReceiveSample(sampleBox);
</span><span class="cx">         } else
</span><del>-            result = ParsingFailed;
</del><ins>+            result = SourceBufferPrivateClient::ParsingFailed;
</ins><span class="cx"> 
</span><span class="cx">         m_inputBuffer.remove(0, boxLength);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    return result;
</del><ins>+    if (m_client)
+        m_client-&gt;sourceBufferPrivateAppendComplete(this, result);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void MockSourceBufferPrivate::didReceiveInitializationSegment(const MockInitializationBox&amp; initBox)
</span></span></pre></div>
<a id="branchessafari53834branchSourceWebCoreplatformmockmediasourceMockSourceBufferPrivateh"></a>
<div class="modfile"><h4>Modified: branches/safari-538.34-branch/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h (168789 => 168790)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-538.34-branch/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h        2014-05-14 06:24:48 UTC (rev 168789)
+++ branches/safari-538.34-branch/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h        2014-05-14 06:32:56 UTC (rev 168790)
</span><span class="lines">@@ -63,7 +63,7 @@
</span><span class="cx"> 
</span><span class="cx">     // SourceBufferPrivate overrides
</span><span class="cx">     virtual void setClient(SourceBufferPrivateClient*) override;
</span><del>-    virtual AppendResult append(const unsigned char* data, unsigned length) override;
</del><ins>+    virtual void append(const unsigned char* data, unsigned length) override;
</ins><span class="cx">     virtual void abort() override;
</span><span class="cx">     virtual void removedFromMediaSource() override;
</span><span class="cx">     virtual MediaPlayer::ReadyState readyState() const override;
</span></span></pre>
</div>
</div>

</body>
</html>