Bug 1115749 - Assert that we hold the monitor at all the MP4Demuxer API entry points. r=rillian, a=sledru
authorBobby Holley <bobbyholley@gmail.com>
Mon, 29 Dec 2014 16:10:16 -0800
changeset 242744 eb36d731bf4708bf0525e20425eaaacf103d4e2c
parent 242743 c55d5658c65243bd978e7402d575dfb1e0a215e5
child 242745 6e5c3475184b3913a7849c515a8a9ce00b60cc88
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian, sledru
bugs1115749
milestone36.0a2
Bug 1115749 - Assert that we hold the monitor at all the MP4Demuxer API entry points. r=rillian, a=sledru 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));
   }