Bug 1115749 - Assert that we hold the monitor at all the MP4Demuxer API entry points. r=rillian
authorBobby Holley <bobbyholley@gmail.com>
Mon, 29 Dec 2014 16:10:16 -0800
changeset 247424 30c89bc08ce5e09fb46009c78d1cf5ef985de6b2
parent 247423 ed1950e4c6979cea1da19c6ef4349af50c58aea6
child 247425 a90291c04e5b5eb7d4862069c4b273ffda715197
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1115749
milestone37.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 1115749 - Assert that we hold the monitor at all the MP4Demuxer API entry points. r=rillian MP4Demuxer accesses shared state (index, moofparser) in lots of shared helper routines, so we should assume that it's not safe to touch the demuxer at all without holding the lock (unless demonstrated otherwise). This stuff should probably be redesigned, but that's a problem for another day.
media/libstagefright/binding/mp4_demuxer.cpp
--- a/media/libstagefright/binding/mp4_demuxer.cpp
+++ b/media/libstagefright/binding/mp4_demuxer.cpp
@@ -87,16 +87,17 @@ MP4Demuxer::~MP4Demuxer()
   if (mPrivate->mVideo.get()) {
     mPrivate->mVideo->stop();
   }
 }
 
 bool
 MP4Demuxer::Init()
 {
+  mMonitor->AssertCurrentThreadOwns();
   sp<MediaExtractor> e = mPrivate->mExtractor;
   for (size_t i = 0; i < e->countTracks(); i++) {
     sp<MetaData> metaData = e->getTrackMetaData(i);
 
     const char* mimeType;
     if (metaData == nullptr || !metaData->findCString(kKeyMIMEType, &mimeType)) {
       continue;
     }
@@ -133,62 +134,69 @@ MP4Demuxer::Init()
   mCrypto.Update(metaData);
 
   return mPrivate->mAudio.get() || mPrivate->mVideo.get();
 }
 
 bool
 MP4Demuxer::HasValidAudio()
 {
+  mMonitor->AssertCurrentThreadOwns();
   return mPrivate->mAudio.get() && mAudioConfig.IsValid();
 }
 
 bool
 MP4Demuxer::HasValidVideo()
 {
+  mMonitor->AssertCurrentThreadOwns();
   return mPrivate->mVideo.get() && mVideoConfig.IsValid();
 }
 
 Microseconds
 MP4Demuxer::Duration()
 {
+  mMonitor->AssertCurrentThreadOwns();
   return std::max(mVideoConfig.duration, mAudioConfig.duration);
 }
 
 bool
 MP4Demuxer::CanSeek()
 {
+  mMonitor->AssertCurrentThreadOwns();
   return mPrivate->mExtractor->flags() & MediaExtractor::CAN_SEEK;
 }
 
 void
 MP4Demuxer::SeekAudio(Microseconds aTime)
 {
+  mMonitor->AssertCurrentThreadOwns();
   if (mPrivate->mAudioIterator) {
     mPrivate->mAudioIterator->Seek(aTime);
   } else {
     mPrivate->mAudioOptions.setSeekTo(
       aTime, MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC);
   }
 }
 
 void
 MP4Demuxer::SeekVideo(Microseconds aTime)
 {
+  mMonitor->AssertCurrentThreadOwns();
   if (mPrivate->mVideoIterator) {
     mPrivate->mVideoIterator->Seek(aTime);
   } else {
     mPrivate->mVideoOptions.setSeekTo(
       aTime, MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC);
   }
 }
 
 MP4Sample*
 MP4Demuxer::DemuxAudioSample()
 {
+  mMonitor->AssertCurrentThreadOwns();
   if (mPrivate->mAudioIterator) {
     nsAutoPtr<MP4Sample> sample(mPrivate->mAudioIterator->GetNext());
     if (sample) {
       if (sample->crypto.valid) {
         sample->crypto.mode = mAudioConfig.crypto.mode;
         sample->crypto.iv_size = mAudioConfig.crypto.iv_size;
         sample->crypto.key.AppendElements(mAudioConfig.crypto.key);
       }
@@ -208,16 +216,17 @@ MP4Demuxer::DemuxAudioSample()
   sample->Update(mAudioConfig.media_time);
 
   return sample.forget();
 }
 
 MP4Sample*
 MP4Demuxer::DemuxVideoSample()
 {
+  mMonitor->AssertCurrentThreadOwns();
   if (mPrivate->mVideoIterator) {
     nsAutoPtr<MP4Sample> sample(mPrivate->mVideoIterator->GetNext());
     if (sample) {
       sample->extra_data = mVideoConfig.extra_data;
       if (sample->crypto.valid) {
         sample->crypto.mode = mVideoConfig.crypto.mode;
         sample->crypto.key.AppendElements(mVideoConfig.crypto.key);
       }
@@ -238,26 +247,28 @@ MP4Demuxer::DemuxVideoSample()
   sample->extra_data = mVideoConfig.extra_data;
 
   return sample.forget();
 }
 
 void
 MP4Demuxer::UpdateIndex(const nsTArray<mozilla::MediaByteRange>& aByteRanges)
 {
+  mMonitor->AssertCurrentThreadOwns();
   for (int i = 0; i < mPrivate->mIndexes.Length(); i++) {
     mPrivate->mIndexes[i]->UpdateMoofIndex(aByteRanges);
   }
 }
 
 void
 MP4Demuxer::ConvertByteRangesToTime(
   const nsTArray<mozilla::MediaByteRange>& aByteRanges,
   nsTArray<Interval<Microseconds>>* aIntervals)
 {
+  mMonitor->AssertCurrentThreadOwns();
   if (mPrivate->mIndexes.IsEmpty()) {
     return;
   }
 
   Microseconds lastComposition = 0;
   nsTArray<Microseconds> endCompositions;
   for (int i = 0; i < mPrivate->mIndexes.Length(); i++) {
     Microseconds endComposition =
@@ -287,16 +298,17 @@ MP4Demuxer::ConvertByteRangesToTime(
     }
   }
   aIntervals->AppendElements(mCachedTimeRanges);
 }
 
 int64_t
 MP4Demuxer::GetEvictionOffset(Microseconds aTime)
 {
+  mMonitor->AssertCurrentThreadOwns();
   if (mPrivate->mIndexes.IsEmpty()) {
     return 0;
   }
 
   uint64_t offset = std::numeric_limits<uint64_t>::max();
   for (int i = 0; i < mPrivate->mIndexes.Length(); i++) {
     offset = std::min(offset, mPrivate->mIndexes[i]->GetEvictionOffset(aTime));
   }