Bug 1209887. Part 1 - add assertions. r=jya.
authorJW Wang <jwwang@mozilla.com>
Wed, 30 Sep 2015 06:55:20 +0800
changeset 265591 4174ca0e2b32e2704438b93a1e1d8d7989f9fc3b
parent 265590 9c01e0e3da7418f130e33541314bdb3e5372fd15
child 265592 ef11325051ad4699e159fe4ecb4fe73f12a078fe
push id15472
push usercbook@mozilla.com
push dateFri, 02 Oct 2015 11:51:34 +0000
treeherderfx-team@2c33ef6b27e0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1209887
milestone44.0a1
Bug 1209887. Part 1 - add assertions. r=jya.
dom/media/MediaDecoderReader.h
dom/media/wave/WaveReader.cpp
--- a/dom/media/MediaDecoderReader.h
+++ b/dom/media/MediaDecoderReader.h
@@ -103,17 +103,17 @@ public:
   virtual void BreakCycles();
 
   // Destroys the decoding state. The reader cannot be made usable again.
   // This is different from ReleaseMediaResources() as it is irreversable,
   // whereas ReleaseMediaResources() is.  Must be called on the decode
   // thread.
   virtual nsRefPtr<ShutdownPromise> Shutdown();
 
-  virtual bool OnTaskQueue()
+  virtual bool OnTaskQueue() const
   {
     return OwnerThread()->IsCurrentThreadIn();
   }
 
   // Resets all state related to decoding, emptying all buffers etc.
   // Cancels all pending Request*Data() request callbacks, rejects any
   // outstanding seek promises, and flushes the decode pipeline. The
   // decoder must not call any of the callbacks for outstanding
@@ -303,17 +303,17 @@ public:
       MOZ_ASSERT(self->OnTaskQueue());
       MOZ_ASSERT(!self->HaveStartTime());
       self->mStartTime.emplace(aStartTime);
       self->UpdateBuffered();
     });
     OwnerThread()->Dispatch(r.forget());
   }
 
-  TaskQueue* OwnerThread() {
+  TaskQueue* OwnerThread() const {
     return mTaskQueue;
   }
 
   // Returns true if the reader implements RequestAudioData()
   // and RequestVideoData() asynchronously, rather than using the
   // implementation in this class to adapt the old synchronous to
   // the newer async model.
   virtual bool IsAsync() const { return false; }
--- a/dom/media/wave/WaveReader.cpp
+++ b/dom/media/wave/WaveReader.cpp
@@ -297,16 +297,18 @@ media::TimeIntervals WaveReader::GetBuff
     startOffset = resource->GetNextCachedData(endOffset);
   }
   return buffered;
 }
 
 bool
 WaveReader::ReadAll(char* aBuf, int64_t aSize, int64_t* aBytesRead)
 {
+  MOZ_ASSERT(OnTaskQueue());
+
   if (aBytesRead) {
     *aBytesRead = 0;
   }
   uint32_t read = 0;
   if (NS_FAILED(mResource.Read(aBuf, uint32_t(aSize), &read))) {
     NS_WARNING("Resource read failed");
     return false;
   }
@@ -317,16 +319,18 @@ WaveReader::ReadAll(char* aBuf, int64_t 
     *aBytesRead = read;
   }
   return true;
 }
 
 bool
 WaveReader::LoadRIFFChunk()
 {
+  MOZ_ASSERT(OnTaskQueue());
+
   char riffHeader[RIFF_INITIAL_SIZE];
   const char* p = riffHeader;
 
   MOZ_ASSERT(mResource.Tell() == 0,
              "LoadRIFFChunk called when resource in invalid state");
 
   if (!ReadAll(riffHeader, sizeof(riffHeader))) {
     return false;
@@ -348,16 +352,18 @@ WaveReader::LoadRIFFChunk()
   }
 
   return true;
 }
 
 bool
 WaveReader::LoadFormatChunk(uint32_t aChunkSize)
 {
+  MOZ_ASSERT(OnTaskQueue());
+
   uint32_t rate, channels, frameSize, sampleFormat;
   char waveFormat[WAVE_FORMAT_CHUNK_SIZE];
   const char* p = waveFormat;
 
   // RIFF chunks are always word (two byte) aligned.
   MOZ_ASSERT(mResource.Tell() % 2 == 0,
              "LoadFormatChunk called with unaligned resource");
 
@@ -448,16 +454,18 @@ WaveReader::LoadFormatChunk(uint32_t aCh
     mSampleFormat = FORMAT_S16;
   }
   return true;
 }
 
 bool
 WaveReader::FindDataOffset(uint32_t aChunkSize)
 {
+  MOZ_ASSERT(OnTaskQueue());
+
   // RIFF chunks are always word (two byte) aligned.
   MOZ_ASSERT(mResource.Tell() % 2 == 0,
              "FindDataOffset called with unaligned resource");
 
   int64_t offset = mResource.Tell();
   if (offset <= 0 || offset > UINT32_MAX) {
     NS_WARNING("PCM data offset out of range");
     return false;
@@ -467,37 +475,42 @@ WaveReader::FindDataOffset(uint32_t aChu
   mWaveLength = aChunkSize;
   mWavePCMOffset = uint32_t(offset);
   return true;
 }
 
 double
 WaveReader::BytesToTime(int64_t aBytes) const
 {
+  MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(aBytes >= 0, "Must be >= 0");
   return float(aBytes) / mSampleRate / mFrameSize;
 }
 
 int64_t
 WaveReader::TimeToBytes(double aTime) const
 {
+  MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(aTime >= 0.0f, "Must be >= 0");
   return RoundDownToFrame(int64_t(aTime * mSampleRate * mFrameSize));
 }
 
 int64_t
 WaveReader::RoundDownToFrame(int64_t aBytes) const
 {
+  MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(aBytes >= 0, "Must be >= 0");
   return aBytes - (aBytes % mFrameSize);
 }
 
 int64_t
 WaveReader::GetDataLength()
 {
+  MOZ_ASSERT(OnTaskQueue());
+
   int64_t length = mWaveLength;
   // If the decoder has a valid content length, and it's shorter than the
   // expected length of the PCM data, calculate the playback duration from
   // the content length rather than the expected PCM data length.
   int64_t streamLength = mDecoder->GetResource()->GetLength();
   if (streamLength >= 0) {
     int64_t dataLength = std::max<int64_t>(0, streamLength - mWavePCMOffset);
     length = std::min(dataLength, length);
@@ -533,16 +546,18 @@ WaveReader::GetNextChunk(uint32_t* aChun
 
   return true;
 }
 
 bool
 WaveReader::LoadListChunk(uint32_t aChunkSize,
                           nsAutoPtr<dom::HTMLMediaElement::MetadataTags> &aTags)
 {
+  MOZ_ASSERT(OnTaskQueue());
+
   // List chunks are always word (two byte) aligned.
   MOZ_ASSERT(mResource.Tell() % 2 == 0,
              "LoadListChunk called with unaligned resource");
 
   static const unsigned int MAX_CHUNK_SIZE = 1 << 16;
   static_assert(uint64_t(MAX_CHUNK_SIZE) < UINT_MAX / sizeof(char),
                 "MAX_CHUNK_SIZE too large for enumerator.");
 
@@ -609,16 +624,18 @@ WaveReader::LoadListChunk(uint32_t aChun
   }
 
   return true;
 }
 
 bool
 WaveReader::LoadAllChunks(nsAutoPtr<dom::HTMLMediaElement::MetadataTags> &aTags)
 {
+  MOZ_ASSERT(OnTaskQueue());
+
   // Chunks are always word (two byte) aligned.
   MOZ_ASSERT(mResource.Tell() % 2 == 0,
              "LoadAllChunks called with unaligned resource");
 
   bool loadFormatChunk = false;
   bool findDataOffset = false;
 
   for (;;) {