Bug 1453078 - Do not assume segments are all non-null when not all null. r=padenot, a=RyanVM
authorAndreas Pehrson <apehrson@mozilla.com>
Mon, 29 Oct 2018 10:34:40 +0000
changeset 500942 43d2c9744a7d94ef0609d6f1e099ccb19c538297
parent 500941 af012e57e9de8ce72133fe5a1f2b8b0362336260
child 500943 3931ebbd558836838926001aef24f4c4d1120653
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, RyanVM
bugs1453078
milestone64.0
Bug 1453078 - Do not assume segments are all non-null when not all null. r=padenot, a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D9545
dom/media/encoder/MediaEncoder.cpp
--- a/dom/media/encoder/MediaEncoder.cpp
+++ b/dom/media/encoder/MediaEncoder.cpp
@@ -105,40 +105,52 @@ public:
           NewRunnableMethod<StreamTime>(
             "mozilla::AudioTrackEncoder::SetStartOffset",
             mEncoder, &AudioTrackEncoder::SetStartOffset, aTrackOffset));
       MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
       Unused << rv;
       mInitialized = true;
     }
 
-    if (mDirectConnected) {
-      if (aQueuedMedia.IsNull()) {
-        nsresult rv =
-          mEncoderThread->Dispatch(
-            NewRunnableMethod<StreamTime>(
-              "mozilla::AudioTrackEncoder::AdvanceBlockedInput",
-              mEncoder, &AudioTrackEncoder::AdvanceBlockedInput,
-              aQueuedMedia.GetDuration()));
-        MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
-        Unused << rv;
-        return;
-      }
-    } else {
+    if (!mDirectConnected) {
       NotifyRealtimeTrackData(aGraph, aTrackOffset, aQueuedMedia);
     }
 
-    nsresult rv =
-      mEncoderThread->Dispatch(
-        NewRunnableMethod<StreamTime>(
+    AutoTArray<Pair<bool, StreamTime>, 2> nulledSequence;
+    for (AudioSegment::ConstChunkIterator
+         iter(static_cast<const AudioSegment&>(aQueuedMedia));
+         !iter.IsEnded(); iter.Next()) {
+      if (!nulledSequence.IsEmpty()) {
+        Pair<bool, StreamTime>& last = nulledSequence.LastElement();
+        if (last.first() == iter->IsNull()) {
+          last.second() += iter->GetDuration();
+          continue;
+        }
+      }
+      nulledSequence.AppendElement(
+        MakePair(iter->IsNull(), iter->GetDuration()));
+    }
+
+    for (const Pair<bool, StreamTime>& nulledRange : nulledSequence) {
+      if (nulledRange.first()) {
+        nsresult rv = mEncoderThread->Dispatch(NewRunnableMethod<StreamTime>(
+          "mozilla::AudioTrackEncoder::AdvanceBlockedInput",
+          mEncoder, &AudioTrackEncoder::AdvanceBlockedInput,
+          nulledRange.second()));
+        MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
+        Unused << rv;
+      } else {
+        nsresult rv = mEncoderThread->Dispatch(NewRunnableMethod<StreamTime>(
           "mozilla::AudioTrackEncoder::AdvanceCurrentTime",
           mEncoder, &AudioTrackEncoder::AdvanceCurrentTime,
-          aQueuedMedia.GetDuration()));
-    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
-    Unused << rv;
+          nulledRange.second()));
+        MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
+        Unused << rv;
+      }
+    }
   }
 
   void NotifyRealtimeTrackData(MediaStreamGraph* aGraph,
                                StreamTime aTrackOffset,
                                const MediaSegment& aMedia) override
   {
     TRACE_COMMENT("Encoder %p", mEncoder.get());
     MOZ_ASSERT(mEncoder);
@@ -257,46 +269,56 @@ public:
     MOZ_ASSERT(mEncoder);
     MOZ_ASSERT(mEncoderThread);
 
     if (mShutdown) {
       return;
     }
 
     if (!mInitialized) {
-      nsresult rv =
-        mEncoderThread->Dispatch(
-          NewRunnableMethod<StreamTime>(
-            "mozilla::VideoTrackEncoder::SetStartOffset",
-            mEncoder, &VideoTrackEncoder::SetStartOffset, aTrackOffset));
+      nsresult rv =mEncoderThread->Dispatch(NewRunnableMethod<StreamTime>(
+        "mozilla::VideoTrackEncoder::SetStartOffset",
+        mEncoder, &VideoTrackEncoder::SetStartOffset, aTrackOffset));
       MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
       Unused << rv;
       mInitialized = true;
     }
 
-    if (aQueuedMedia.IsNull()) {
-      nsresult rv =
-        mEncoderThread->Dispatch(
-          NewRunnableMethod<StreamTime>(
-            "mozilla::VideoTrackEncoder::AdvanceBlockedInput",
-            mEncoder, &VideoTrackEncoder::AdvanceBlockedInput,
-            aQueuedMedia.GetDuration()));
-      MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
-      Unused << rv;
-      return;
+    AutoTArray<Pair<bool, StreamTime>, 2> nulledSequence;
+    for (VideoSegment::ConstChunkIterator
+         iter(static_cast<const VideoSegment&>(aQueuedMedia));
+         !iter.IsEnded(); iter.Next()) {
+      if (!nulledSequence.IsEmpty()) {
+        Pair<bool, StreamTime>& last = nulledSequence.LastElement();
+        if (last.first() == iter->IsNull()) {
+          last.second() += iter->GetDuration();
+          continue;
+        }
+      }
+      nulledSequence.AppendElement(
+        MakePair(iter->IsNull(), iter->GetDuration()));
     }
 
-    nsresult rv =
-      mEncoderThread->Dispatch(
-        NewRunnableMethod<StreamTime>(
+    for (const Pair<bool, StreamTime>& nulledRange : nulledSequence) {
+      if (nulledRange.first()) {
+        nsresult rv = mEncoderThread->Dispatch(NewRunnableMethod<StreamTime>(
+          "mozilla::VideoTrackEncoder::AdvanceBlockedInput",
+          mEncoder, &VideoTrackEncoder::AdvanceBlockedInput,
+          nulledRange.second()));
+        MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
+        Unused << rv;
+      } else {
+        nsresult rv = mEncoderThread->Dispatch(NewRunnableMethod<StreamTime>(
           "mozilla::VideoTrackEncoder::AdvanceCurrentTime",
           mEncoder, &VideoTrackEncoder::AdvanceCurrentTime,
-          aQueuedMedia.GetDuration()));
-    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
-    Unused << rv;
+          nulledRange.second()));
+        MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
+        Unused << rv;
+      }
+    }
   }
 
   void SetCurrentFrames(const VideoSegment& aMedia) override
   {
     TRACE_COMMENT("Encoder %p", mEncoder.get());
     MOZ_ASSERT(mEncoder);
     MOZ_ASSERT(mEncoderThread);