Bug 1041374 - Fix deadlock in MSE reading vs data adding - r=kinetik
authorChris Double <chris.double@double.co.nz>
Tue, 26 Aug 2014 19:26:03 +1200
changeset 201542 2fc1d14dee3eb51b26da5375a092b04967f3b167
parent 201541 bfa272c7141e636291fc2771c5853bce6f2cde97
child 201543 7cb633f637af5de82058825127214f82081def40
push id48201
push usercdouble@mozilla.com
push dateTue, 26 Aug 2014 07:27:34 +0000
treeherdermozilla-inbound@2fc1d14dee3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1041374
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 1041374 - Fix deadlock in MSE reading vs data adding - r=kinetik
content/media/mediasource/MediaSourceReader.cpp
--- a/content/media/mediasource/MediaSourceReader.cpp
+++ b/content/media/mediasource/MediaSourceReader.cpp
@@ -210,19 +210,23 @@ MediaSourceReader::SwitchVideoReader(Med
   MSE_DEBUG("MediaDecoderReader(%p)::SwitchVideoReader(%p) switching video reader",
             this, mVideoReader.get());
   return true;
 }
 
 bool
 MediaSourceReader::SwitchReaders(SwitchType aType)
 {
-  ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
+  InitializePendingDecoders();
 
-  InitializePendingDecoders();
+  // This monitor must be held after the call to InitializePendingDecoders
+  // as that method also obtains the lock, and then attempts to exit it
+  // to call ReadMetadata on the readers. If we hold it before the call then
+  // it remains held during the ReadMetadata call causing a deadlock.
+  ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
 
   bool didSwitch = false;
   double decodeTarget = double(mTimeThreshold) / USECS_PER_S;
 
   for (uint32_t i = 0; i < mDecoders.Length(); ++i) {
     SourceBufferDecoder* decoder = mDecoders[i];
     const MediaInfo& info = decoder->GetReader()->GetMediaInfo();