Bug 1248792 - [1.2] Replace MediaRawData raw pointers with RefPtr. r=snorp
authorEugen Sawin <esawin@mozilla.com>
Tue, 16 Feb 2016 23:50:04 +0100
changeset 322177 4225bacf6a97782d5884fa023a5f0259aaf3bb53
parent 322176 96077e578f26548b467e1ebc2decad451e9be467
child 322178 c1f50ba71bfe66fc1fd76cbfb5e8cf8bfa84a9b5
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1248792
milestone47.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 1248792 - [1.2] Replace MediaRawData raw pointers with RefPtr. r=snorp
dom/media/platforms/android/AndroidDecoderModule.cpp
dom/media/platforms/android/AndroidDecoderModule.h
--- a/dom/media/platforms/android/AndroidDecoderModule.cpp
+++ b/dom/media/platforms/android/AndroidDecoderModule.cpp
@@ -408,17 +408,17 @@ MediaCodecDataDecoder::WaitForInput()
     INVOKE_CALLBACK(InputExhausted);
     lock.Wait();
   }
 
   return State() != kStopping;
 }
 
 
-MediaRawData*
+already_AddRefed<MediaRawData>
 MediaCodecDataDecoder::PeekNextSample()
 {
   MonitorAutoLock lock(mMonitor);
 
   if (State() == kFlushing) {
     mDecoder->Flush();
     ClearQueue();
     State(kDecoding);
@@ -429,17 +429,17 @@ MediaCodecDataDecoder::PeekNextSample()
   if (mQueue.empty()) {
     if (State() == kDrainQueue) {
       State(kDrainDecoder);
     }
     return nullptr;
   }
 
   // We're not stopping or flushing, so try to get a sample.
-  return mQueue.front();
+  return RefPtr<MediaRawData>(mQueue.front()).forget();
 }
 
 nsresult
 MediaCodecDataDecoder::QueueSample(const MediaRawData* aSample)
 {
   MOZ_ASSERT(aSample);
   AutoLocalJNIFrame frame(jni::GetEnvForThread(), 1);
 
@@ -547,37 +547,37 @@ MediaCodecDataDecoder::ProcessOutput(
   return NS_OK;
 }
 
 void
 MediaCodecDataDecoder::DecoderLoop()
 {
   bool isOutputDone = false;
   AutoLocalJNIFrame frame(jni::GetEnvForThread(), 1);
-  RefPtr<MediaRawData> sample;
   MediaFormat::LocalRef outputFormat(frame.GetEnv());
   nsresult res = NS_OK;
 
   while (WaitForInput()) {
-    sample = PeekNextSample();
+    RefPtr<MediaRawData> sample = PeekNextSample();
 
     {
       MonitorAutoLock lock(mMonitor);
       if (State() == kDrainDecoder) {
         MOZ_ASSERT(!sample, "Shouldn't have a sample when pushing EOF frame");
         res = QueueEOS();
         BREAK_ON_DECODER_ERROR();
       }
     }
 
     if (sample) {
       res = QueueSample(sample);
       if (NS_SUCCEEDED(res)) {
         // We've fed this into the decoder, so remove it from the queue.
         MonitorAutoLock lock(mMonitor);
+        MOZ_RELEASE_ASSERT(mQueue.size(), "Queue may not be empty");
         mQueue.pop();
         isOutputDone = false;
       }
     }
 
     if (isOutputDone) {
       continue;
     }
--- a/dom/media/platforms/android/AndroidDecoderModule.h
+++ b/dom/media/platforms/android/AndroidDecoderModule.h
@@ -93,17 +93,17 @@ protected:
 
   virtual void Cleanup() {};
 
   nsresult ResetInputBuffers();
   nsresult ResetOutputBuffers();
 
   nsresult GetInputBuffer(JNIEnv* env, int index, jni::Object::LocalRef* buffer);
   bool WaitForInput();
-  MediaRawData* PeekNextSample();
+  already_AddRefed<MediaRawData> PeekNextSample();
   nsresult QueueSample(const MediaRawData* aSample);
   nsresult QueueEOS();
   void HandleEOS(int32_t aOutputStatus);
   media::TimeUnit GetOutputDuration();
   nsresult ProcessOutput(widget::sdk::BufferInfo::Param aInfo,
                          widget::sdk::MediaFormat::Param aFormat,
                          int32_t aStatus);
   ModuleState State() const;