Bug 1049326 - Fix unit conversion of duration and other minor MSE cleanups. r=cajbir
authorMatthew Gregan <kinetik@flim.org>
Mon, 11 Aug 2014 13:21:18 +1200
changeset 198814 579f8a1cbf34fb13c718474b6bd36aa8b5e85d12
parent 198813 315d992d811e43f8a57b033723cb9aba79f05ff9
child 198815 20bdca5301b06b58b67e7303195d4a90b029efcb
push id27286
push usernigelbabu@gmail.com
push dateMon, 11 Aug 2014 06:26:45 +0000
treeherdermozilla-central@8c4a1b3a2a8b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1049326
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1049326 - Fix unit conversion of duration and other minor MSE cleanups. r=cajbir
content/media/mediasource/MediaSourceDecoder.cpp
--- a/content/media/mediasource/MediaSourceDecoder.cpp
+++ b/content/media/mediasource/MediaSourceDecoder.cpp
@@ -268,34 +268,37 @@ public:
   {
   }
 
   already_AddRefed<SubBufferDecoder> CreateSubDecoder(const nsACString& aType,
                                                       MediaSourceDecoder* aParentDecoder) {
     if (!mReader) {
       return nullptr;
     }
-    return static_cast<MediaSourceReader*>(mReader.get())->CreateSubDecoder(aType, aParentDecoder, mDecodeTaskQueue);
+    MediaSourceReader* reader = static_cast<MediaSourceReader*>(mReader.get());
+    return reader->CreateSubDecoder(aType, aParentDecoder, mDecodeTaskQueue);
   }
 
   nsresult EnqueueDecoderInitialization() {
     AssertCurrentThreadInMonitor();
     if (!mReader) {
       return NS_ERROR_FAILURE;
     }
-    return mDecodeTaskQueue->Dispatch(NS_NewRunnableMethod(this,
-                                                           &MediaSourceStateMachine::InitializePendingDecoders));
+    RefPtr<nsIRunnable> task =
+      NS_NewRunnableMethod(this, &MediaSourceStateMachine::InitializePendingDecoders);
+    return mDecodeTaskQueue->Dispatch(task);
   }
 
 private:
   void InitializePendingDecoders() {
     if (!mReader) {
       return;
     }
-    static_cast<MediaSourceReader*>(mReader.get())->InitializePendingDecoders();
+    MediaSourceReader* reader = static_cast<MediaSourceReader*>(mReader.get());
+    reader->InitializePendingDecoders();
   }
 };
 
 MediaSourceDecoder::MediaSourceDecoder(dom::HTMLMediaElement* aElement)
   : mMediaSource(nullptr)
 {
   Init(aElement);
 }
@@ -372,26 +375,28 @@ MediaSourceDecoder::DetachMediaSource()
 }
 
 already_AddRefed<SubBufferDecoder>
 MediaSourceDecoder::CreateSubDecoder(const nsACString& aType)
 {
   if (!mDecoderStateMachine) {
     return nullptr;
   }
-  return static_cast<MediaSourceStateMachine*>(mDecoderStateMachine.get())->CreateSubDecoder(aType, this);
+  MediaSourceStateMachine* sm = static_cast<MediaSourceStateMachine*>(mDecoderStateMachine.get());
+  return sm->CreateSubDecoder(aType, this);
 }
 
 nsresult
 MediaSourceDecoder::EnqueueDecoderInitialization()
 {
   if (!mDecoderStateMachine) {
     return NS_ERROR_FAILURE;
   }
-  return static_cast<MediaSourceStateMachine*>(mDecoderStateMachine.get())->EnqueueDecoderInitialization();
+  MediaSourceStateMachine* sm = static_cast<MediaSourceStateMachine*>(mDecoderStateMachine.get());
+  return sm->EnqueueDecoderInitialization();
 }
 
 class ReleaseDecodersTask : public nsRunnable {
 public:
   ReleaseDecodersTask(nsTArray<nsRefPtr<SubBufferDecoder>>& aDecoders)
   {
     mDecoders.SwapElements(aDecoders);
   }
@@ -413,28 +418,29 @@ MediaSourceReader::InitializePendingDeco
     nsRefPtr<SubBufferDecoder> decoder = mPendingDecoders[i];
     MediaDecoderReader* reader = decoder->GetReader();
     MSE_DEBUG("MediaSourceReader(%p): Initializing subdecoder %p reader %p",
               this, decoder.get(), reader);
 
     MediaInfo mi;
     nsAutoPtr<MetadataTags> tags; // TODO: Handle metadata.
     nsresult rv;
-    int64_t startTime = 0;
+    int64_t startTime = INT64_MIN;
     {
       ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor());
       rv = reader->ReadMetadata(&mi, getter_Transfers(tags));
       if (NS_SUCCEEDED(rv)) {
         reader->FindStartTime(startTime);
       }
     }
     reader->SetIdle();
-    if (NS_FAILED(rv)) {
+    if (NS_FAILED(rv) || startTime == INT64_MIN) {
       // XXX: Need to signal error back to owning SourceBuffer.
-      MSE_DEBUG("MediaSourceReader(%p): Reader %p failed to initialize, rv=%x", this, reader, rv);
+      MSE_DEBUG("MediaSourceReader(%p): Reader %p failed to initialize rv=%x startTime=%lld",
+                this, reader, rv, startTime);
       continue;
     }
     decoder->SetMediaStartTime(startTime);
 
     bool active = false;
     if (mi.HasVideo() || mi.HasAudio()) {
       MSE_DEBUG("MediaSourceReader(%p): Reader %p has video=%d audio=%d startTime=%lld",
                 this, reader, mi.HasVideo(), mi.HasAudio(), startTime);
@@ -628,17 +634,18 @@ MediaSourceReader::ReadMetadata(MediaInf
                 this, i, maxDuration);
     }
   }
 
   if (maxDuration != -1) {
     ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
     mDecoder->SetMediaDuration(maxDuration);
     nsRefPtr<nsIRunnable> task (
-      NS_NewRunnableMethodWithArg<double>(this, &MediaSourceReader::SetMediaSourceDuration, maxDuration));
+      NS_NewRunnableMethodWithArg<double>(this, &MediaSourceReader::SetMediaSourceDuration,
+                                          static_cast<double>(maxDuration) / USECS_PER_S));
     NS_DispatchToMainThread(task);
   }
 
   *aInfo = mInfo;
   *aTags = nullptr; // TODO: Handle metadata.
 
   return NS_OK;
 }