Bug 1262456 - [2.1] Replace queue adapter with deque. r=snorp
authorEugen Sawin <esawin@mozilla.com>
Mon, 18 Apr 2016 17:04:53 +0200
changeset 317436 cbf41516e4a3922aa856f0b0f781ea8e0664a436
parent 317435 4a137817e1f5033d579e48b329e5621e804fde40
child 317437 01267d99f891c525dc6af7eac888e08aa0aa923a
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1262456
milestone48.0a1
Bug 1262456 - [2.1] Replace queue adapter with deque. 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
@@ -497,17 +497,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();
 
@@ -542,17 +542,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);
@@ -595,17 +595,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;
     }
 
@@ -693,38 +693,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