<!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>[168508] trunk/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/168508">168508</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2014-05-08 17:21:00 -0700 (Thu, 08 May 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>[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:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreModulesmediasourceSourceBuffercpp">trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp</a></li>
<li><a href="#trunkSourceWebCoreModulesmediasourceSourceBufferh">trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsSourceBufferPrivateh">trunk/Source/WebCore/platform/graphics/SourceBufferPrivate.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsSourceBufferPrivateClienth">trunk/Source/WebCore/platform/graphics/SourceBufferPrivateClient.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationobjcSourceBufferPrivateAVFObjCh">trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsavfoundationobjcSourceBufferPrivateAVFObjCmm">trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgstreamerSourceBufferPrivateGStreamercpp">trunk/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsgstreamerSourceBufferPrivateGStreamerh">trunk/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.h</a></li>
<li><a href="#trunkSourceWebCoreplatformmockmediasourceMockSourceBufferPrivatecpp">trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformmockmediasourceMockSourceBufferPrivateh">trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (168507 => 168508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-05-09 00:07:39 UTC (rev 168507)
+++ trunk/Source/WebCore/ChangeLog        2014-05-09 00:21:00 UTC (rev 168508)
</span><span class="lines">@@ -1,3 +1,43 @@
</span><ins>+2014-05-08 Jer Noble <jer.noble@apple.com>
+
+ [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:
+
</ins><span class="cx"> 2014-05-08 Commit Queue <commit-queue@webkit.org>
</span><span class="cx">
</span><span class="cx"> Unreviewed, rolling out r168498.
</span></span></pre></div>
<a id="trunkSourceWebCoreModulesmediasourceSourceBuffercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (168507 => 168508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2014-05-09 00:07:39 UTC (rev 168507)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp        2014-05-09 00:21:00 UTC (rev 168508)
</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->append(m_pendingAppendData.data(), appendSize);
- m_pendingAppendData.clear();
</del><ins>+ m_private->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 "decode" and abort this algorithm.
- if (result == SourceBufferPrivate::ParsingFailed) {
- m_source->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 "decode" and abort this algorithm.
+ if (result == ParsingFailed) {
+ m_source->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="trunkSourceWebCoreModulesmediasourceSourceBufferh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h (168507 => 168508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h        2014-05-09 00:07:39 UTC (rev 168507)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h        2014-05-09 00:21:00 UTC (rev 168508)
</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&);
</span><span class="cx"> virtual MediaTime sourceBufferPrivateFastSeekTimeForMediaTime(SourceBufferPrivate*, const MediaTime&, const MediaTime& negativeThreshold, const MediaTime& 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="trunkSourceWebCoreplatformgraphicsSourceBufferPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/SourceBufferPrivate.h (168507 => 168508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/SourceBufferPrivate.h        2014-05-09 00:07:39 UTC (rev 168507)
+++ trunk/Source/WebCore/platform/graphics/SourceBufferPrivate.h        2014-05-09 00:21:00 UTC (rev 168508)
</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="trunkSourceWebCoreplatformgraphicsSourceBufferPrivateClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/SourceBufferPrivateClient.h (168507 => 168508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/SourceBufferPrivateClient.h        2014-05-09 00:07:39 UTC (rev 168507)
+++ trunk/Source/WebCore/platform/graphics/SourceBufferPrivateClient.h        2014-05-09 00:21:00 UTC (rev 168508)
</span><span class="lines">@@ -77,6 +77,13 @@
</span><span class="cx">
</span><span class="cx"> virtual MediaTime sourceBufferPrivateFastSeekTimeForMediaTime(SourceBufferPrivate*, const MediaTime& time, const MediaTime&, const MediaTime&) { return time; }
</span><span class="cx"> virtual void sourceBufferPrivateSeekToTime(SourceBufferPrivate*, const MediaTime&) { };
</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="trunkSourceWebCoreplatformgraphicsavfoundationobjcSourceBufferPrivateAVFObjCh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h (168507 => 168508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h        2014-05-09 00:07:39 UTC (rev 168507)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.h        2014-05-09 00:21:00 UTC (rev 168508)
</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<RefPtr<MediaSample>>, 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<RefPtr<VideoTrackPrivateMediaSourceAVFObjC>> m_videoTracks;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsavfoundationobjcSourceBufferPrivateAVFObjCmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm (168507 => 168508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm        2014-05-09 00:07:39 UTC (rev 168507)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm        2014-05-09 00:21:00 UTC (rev 168508)
</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->didParseStreamDataAsAsset(asset);
</del><ins>+ RefPtr<WebCore::SourceBufferPrivateAVFObjC> strongParent = _parent;
+ RetainPtr<AVAsset*> strongAsset = asset;
+ callOnMainThread([strongParent, strongAsset] {
+ strongParent->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->didParseStreamDataAsAsset(asset);
</del><ins>+ RefPtr<WebCore::SourceBufferPrivateAVFObjC> strongParent = _parent;
+ RetainPtr<AVAsset*> strongAsset = asset;
+ callOnMainThread([strongParent, strongAsset] {
+ strongParent->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->didFailToParseStreamDataWithError(error);
</del><ins>+ RefPtr<WebCore::SourceBufferPrivateAVFObjC> strongParent = _parent;
+ RetainPtr<NSError> strongError = error;
+ callOnMainThread([strongParent, strongError] {
+ strongParent->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->didProvideMediaDataForTrackID(trackID, mediaData, mediaType, flags);
</del><ins>+ RefPtr<WebCore::SourceBufferPrivateAVFObjC> strongParent = _parent;
+ RetainPtr<CMSampleBufferRef> strongSample = sample;
+ String mediaType = nsMediaType;
+ callOnMainThread([strongParent, strongSample, trackID, mediaType, flags] {
+ strongParent->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->didReachEndOfTrackWithTrackID(trackID, mediaType);
</del><ins>+ RefPtr<WebCore::SourceBufferPrivateAVFObjC> strongParent = _parent;
+ String mediaType = nsMediaType;
+ callOnMainThread([strongParent, trackID, mediaType] {
+ strongParent->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->didProvideContentKeyRequestInitializationDataForTrackID(initData, trackID);
</del><ins>+ RefPtr<WebCore::SourceBufferPrivateAVFObjC> strongParent = _parent;
+ RetainPtr<NSData> strongData = initData;
+ callOnMainThread([strongParent, strongData, trackID] {
+ strongParent->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(&onceToken, ^{
+ globalQueue = dispatch_queue_create("SourceBufferPrivateAVFObjC data parser queue", 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, "SourceBufferPrivateAVFObjC::append(%p) - data:%p, length:%d", this, data, length);
</span><del>- [m_parser appendStreamData:[NSData dataWithBytes:data length:length]];
</del><span class="cx">
</span><ins>+ RetainPtr<NSData> nsData = adoptNS([[NSData alloc] initWithBytes:data length:length]);
+ RefPtr<SourceBufferPrivateAVFObjC> strongThis = this;
+
+ m_parsingSucceeded = true;
+
+ dispatch_async(globalDataParserQueue(), [nsData, strongThis] {
+ [strongThis->m_parser appendStreamData:nsData.get()];
+
+ callOnMainThread([strongThis] {
+ strongThis->appendCompleted();
+ });
+ });
+}
+
+void SourceBufferPrivateAVFObjC::appendCompleted()
+{
</ins><span class="cx"> if (m_parsingSucceeded && m_mediaSource)
</span><span class="cx"> m_mediaSource->player()->setLoadingProgresssed(true);
</span><span class="cx">
</span><del>- return m_parsingSucceeded ? AppendSucceeded : ParsingFailed;
</del><ins>+ if (m_client)
+ m_client->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="trunkSourceWebCoreplatformgraphicsgstreamerSourceBufferPrivateGStreamercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.cpp (168507 => 168508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.cpp        2014-05-09 00:07:39 UTC (rev 168507)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.cpp        2014-05-09 00:21:00 UTC (rev 168508)
</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->didReceiveData(reinterpret_cast_ptr<const char*>(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="trunkSourceWebCoreplatformgraphicsgstreamerSourceBufferPrivateGStreamerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.h (168507 => 168508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.h        2014-05-09 00:07:39 UTC (rev 168507)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/SourceBufferPrivateGStreamer.h        2014-05-09 00:21:00 UTC (rev 168508)
</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="trunkSourceWebCoreplatformmockmediasourceMockSourceBufferPrivatecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp (168507 => 168508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp        2014-05-09 00:07:39 UTC (rev 168507)
+++ trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp        2014-05-09 00:21:00 UTC (rev 168508)
</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() && result == AppendSucceeded) {
</del><ins>+ while (m_inputBuffer.size() && result == SourceBufferPrivateClient::AppendSucceeded) {
</ins><span class="cx"> RefPtr<ArrayBuffer> 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 > buffer->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->sourceBufferPrivateAppendComplete(this, result);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void MockSourceBufferPrivate::didReceiveInitializationSegment(const MockInitializationBox& initBox)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformmockmediasourceMockSourceBufferPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h (168507 => 168508)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h        2014-05-09 00:07:39 UTC (rev 168507)
+++ trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.h        2014-05-09 00:21:00 UTC (rev 168508)
</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>