Bug 1281193 - Lock when touching tracks in SourceAudioStreams. r=pehrsons, a=gchang
authorPaul Adenot <paul@paul.cx>
Wed, 22 Jun 2016 17:44:46 +0200
changeset 325587 822a68704ed4ab149303597be3a8b2870a9a9f77
parent 325586 ad0fd95d483125bbbf02538854e692bde5c4a09d
child 325588 e3d202c9c23067c2e3f18ee0d53a32ba98d4bcea
push id9843
push userryanvm@gmail.com
push dateFri, 29 Jul 2016 20:53:22 +0000
treeherdermozilla-aurora@42c3abe40b3b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons, gchang
bugs1281193
milestone49.0a2
Bug 1281193 - Lock when touching tracks in SourceAudioStreams. r=pehrsons, a=gchang MozReview-Commit-ID: 2aSS8esq5jq
dom/media/MediaStreamGraph.cpp
dom/media/MediaStreamGraph.h
--- a/dom/media/MediaStreamGraph.cpp
+++ b/dom/media/MediaStreamGraph.cpp
@@ -482,22 +482,17 @@ MediaStreamGraphImpl::AudioTrackPresent(
       audioTrackPresent = true;
     } else {
       for (StreamTracks::TrackIter tracks(stream->GetStreamTracks(), MediaSegment::AUDIO);
            !tracks.IsEnded(); tracks.Next()) {
         audioTrackPresent = true;
       }
     }
     if (source) {
-      for (auto& data : source->mPendingTracks) {
-        if (data.mData->GetType() == MediaSegment::AUDIO) {
-          audioTrackPresent = true;
-          break;
-        }
-      }
+      audioTrackPresent = source->HasPendingAudioTrack();
     }
   }
 
   // XXX For some reason, there are race conditions when starting an audio input where
   // we find no active audio tracks.  In any case, if we have an active audio input we
   // should not allow a switch back to a SystemClockDriver
   if (!audioTrackPresent && mInputDeviceUsers.Count() != 0) {
     NS_WARNING("No audio tracks, but full-duplex audio is enabled!!!!!");
@@ -3044,16 +3039,32 @@ SourceMediaStream::RegisterForAudioMixin
 
 bool
 SourceMediaStream::NeedsMixing()
 {
   MutexAutoLock lock(mMutex);
   return mNeedsMixing;
 }
 
+bool
+SourceMediaStream::HasPendingAudioTrack()
+{
+  MutexAutoLock lock(mMutex);
+  bool audioTrackPresent = false;
+
+  for (auto& data : mPendingTracks) {
+    if (data.mData->GetType() == MediaSegment::AUDIO) {
+      audioTrackPresent = true;
+      break;
+    }
+  }
+
+  return audioTrackPresent;
+}
+
 void
 MediaInputPort::Init()
 {
   STREAM_LOG(LogLevel::Debug, ("Adding MediaInputPort %p (from %p to %p) to the graph",
              this, mSource, mDest));
   mSource->AddConsumer(this);
   mDest->AddInput(this);
   // mPortCount decremented via MediaInputPort::Destroy's message
--- a/dom/media/MediaStreamGraph.h
+++ b/dom/media/MediaStreamGraph.h
@@ -1086,16 +1086,23 @@ public:
   /**
    * End all tracks and Finish() this stream.  Used to voluntarily revoke access
    * to a LocalMediaStream.
    */
   void EndAllTrackAndFinish();
 
   void RegisterForAudioMixing();
 
+  /**
+   * Returns true if this SourceMediaStream contains at least one audio track
+   * that is in pending state.
+   * This is thread safe, and takes the SourceMediaStream mutex.
+   */
+  bool HasPendingAudioTrack();
+
   // XXX need a Reset API
 
   friend class MediaStreamGraphImpl;
 
 protected:
   enum TrackCommands {
     TRACK_CREATE = MediaStreamListener::TRACK_EVENT_CREATED,
     TRACK_END = MediaStreamListener::TRACK_EVENT_ENDED,