Bug 1262456 - [2.1] Replace queue adapter with deque. r=snorp a=ritu
authorEugen Sawin <esawin@mozilla.com>
Mon, 18 Apr 2016 17:04:53 +0200
changeset 324488 12f8a808055570d529ec20a0da8dc9830c60b803
parent 324487 3d2d1c251cc80f8288cc7b320703e55c37a606fd
child 324489 c932429b46cebc672d9e18a56aba4adc94ba62d6
push id6031
push userkwierso@gmail.com
push dateThu, 26 May 2016 18:23:42 +0000
treeherdermozilla-beta@417e1ec42d8f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, ritu
bugs1262456
milestone47.0
Bug 1262456 - [2.1] Replace queue adapter with deque. r=snorp a=ritu
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
@@ -471,17 +471,17 @@ MediaCodecDataDecoder::QueueSample(const
   PodCopy(static_cast<uint8_t*>(directBuffer), aSample->Data(), aSample->Size());
 
   res = mDecoder->QueueInputBuffer(inputIndex, 0, aSample->Size(),
                                    aSample->mTime, 0);
   if (NS_FAILED(res)) {
     return res;
   }
 
-  mDurations.push(TimeUnit::FromMicroseconds(aSample->mDuration));
+  mDurations.push_back(TimeUnit::FromMicroseconds(aSample->mDuration));
   return NS_OK;
 }
 
 nsresult
 MediaCodecDataDecoder::QueueEOS()
 {
   mMonitor.AssertCurrentThreadOwns();
 
@@ -516,17 +516,17 @@ MediaCodecDataDecoder::HandleEOS(int32_t
   mDecoder->ReleaseOutputBuffer(aOutputStatus, false);
 }
 
 TimeUnit
 MediaCodecDataDecoder::GetOutputDuration()
 {
   MOZ_ASSERT(!mDurations.empty(), "Should have had a duration queued");
   const TimeUnit duration = mDurations.front();
-  mDurations.pop();
+  mDurations.pop_front();
   return duration;
 }
 
 nsresult
 MediaCodecDataDecoder::ProcessOutput(
     BufferInfo::Param aInfo, MediaFormat::Param aFormat, int32_t aStatus)
 {
   AutoLocalJNIFrame frame(jni::GetEnvForThread(), 1);
@@ -569,17 +569,17 @@ MediaCodecDataDecoder::DecoderLoop()
     }
 
     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();
+        mQueue.pop_front();
         isOutputDone = false;
       }
     }
 
     if (isOutputDone) {
       continue;
     }
 
@@ -667,38 +667,30 @@ MediaCodecDataDecoder::State(ModuleState
   if (ok) {
     LOG("%s -> %s", ModuleStateStr(mState), ModuleStateStr(aState));
     mState = aState;
   }
 
   return ok;
 }
 
-template<typename T>
-void
-Clear(T& aCont)
-{
-  T aEmpty = T();
-  swap(aCont, aEmpty);
-}
-
 void
 MediaCodecDataDecoder::ClearQueue()
 {
   mMonitor.AssertCurrentThreadOwns();
 
-  Clear(mQueue);
-  Clear(mDurations);
+  mQueue.clear();
+  mDurations.clear();
 }
 
 nsresult
 MediaCodecDataDecoder::Input(MediaRawData* aSample)
 {
   MonitorAutoLock lock(mMonitor);
-  mQueue.push(aSample);
+  mQueue.push_back(aSample);
   lock.NotifyAll();
 
   return NS_OK;
 }
 
 nsresult
 MediaCodecDataDecoder::ResetInputBuffers()
 {
--- a/dom/media/platforms/android/AndroidDecoderModule.h
+++ b/dom/media/platforms/android/AndroidDecoderModule.h
@@ -7,21 +7,21 @@
 
 #include "PlatformDecoderModule.h"
 
 #include "MediaCodec.h"
 #include "SurfaceTexture.h"
 #include "TimeUnits.h"
 #include "mozilla/Monitor.h"
 
-#include <queue>
+#include <deque>
 
 namespace mozilla {
 
-typedef std::queue<RefPtr<MediaRawData>> SampleQueue;
+typedef std::deque<RefPtr<MediaRawData>> SampleQueue;
 
 class AndroidDecoderModule : public PlatformDecoderModule {
 public:
   already_AddRefed<MediaDataDecoder>
   CreateVideoDecoder(const VideoInfo& aConfig,
                      layers::LayersBackend aLayersBackend,
                      layers::ImageContainer* aImageContainer,
                      FlushableTaskQueue* aVideoTaskQueue,
@@ -129,14 +129,14 @@ protected:
 
   // Only these members are protected by mMonitor.
   Monitor mMonitor;
 
   ModuleState mState;
 
   SampleQueue mQueue;
   // Durations are stored in microseconds.
-  std::queue<media::TimeUnit> mDurations;
+  std::deque<media::TimeUnit> mDurations;
 };
 
 } // namespace mozilla
 
 #endif