Bug 1259366 - Flush after eos of android::MediaCodec r=jolin
authorSotaro Ikeda <sotaro.ikeda.g@gmail.com>
Mon, 28 Mar 2016 21:39:05 -0700
changeset 290781 7a043400e5be3b3199017e85d9853721f880abcc
parent 290780 a8ec435d22564e64fdd03a71604ebf003b40a48a
child 290782 72c2846e2d161e3c73f04c679e52717ccde38f7b
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjolin
bugs1259366
milestone48.0a1
Bug 1259366 - Flush after eos of android::MediaCodec r=jolin
dom/media/platforms/gonk/GonkAudioDecoderManager.cpp
dom/media/platforms/gonk/GonkAudioDecoderManager.h
dom/media/platforms/gonk/GonkMediaDataDecoder.cpp
dom/media/platforms/gonk/GonkMediaDataDecoder.h
--- a/dom/media/platforms/gonk/GonkAudioDecoderManager.cpp
+++ b/dom/media/platforms/gonk/GonkAudioDecoderManager.cpp
@@ -248,9 +248,18 @@ void
 GonkAudioDecoderManager::ProcessFlush()
 {
   GADM_LOG("FLUSH<<<");
   mAudioQueue.Reset();
   GADM_LOG(">>>FLUSH");
   GonkDecoderManager::ProcessFlush();
 }
 
+void
+GonkAudioDecoderManager::ResetEOS()
+{
+  GADM_LOG("ResetEOS(<<<");
+  mAudioQueue.Reset();
+  GADM_LOG(">>>ResetEOS(");
+  GonkDecoderManager::ResetEOS();
+}
+
 } // namespace mozilla
--- a/dom/media/platforms/gonk/GonkAudioDecoderManager.h
+++ b/dom/media/platforms/gonk/GonkAudioDecoderManager.h
@@ -27,16 +27,17 @@ public:
   virtual ~GonkAudioDecoderManager();
 
   RefPtr<InitPromise> Init() override;
 
   nsresult Output(int64_t aStreamOffset,
                           RefPtr<MediaData>& aOutput) override;
 
   void ProcessFlush() override;
+  virtual void ResetEOS() override;
 
   const char* GetDescriptionName() const override
   {
     return "gonk audio decoder";
   }
 
 private:
   bool InitMediaCodecProxy();
--- a/dom/media/platforms/gonk/GonkMediaDataDecoder.cpp
+++ b/dom/media/platforms/gonk/GonkMediaDataDecoder.cpp
@@ -243,16 +243,17 @@ GonkDecoderManager::ProcessToDo(bool aEn
       MOZ_ASSERT(mQueuedSamples.IsEmpty());
       if (output) {
         mDecodeCallback->Output(output);
         UpdateWaitingList(output->mTime);
       }
       MOZ_ASSERT(mWaitOutput.Length() == 1);
       mWaitOutput.RemoveElementAt(0);
       mDecodeCallback->DrainComplete();
+      ResetEOS();
       return;
     } else if (rv == NS_ERROR_NOT_AVAILABLE) {
       break;
     } else {
       mDecodeCallback->Error();
       return;
     }
   }
@@ -269,16 +270,27 @@ GonkDecoderManager::ProcessToDo(bool aEn
     if (aEndOfStream) {
       mToDo->setInt32("input-eos", 1);
     }
     mDecoder->requestActivityNotification(mToDo);
   }
 }
 
 void
+GonkDecoderManager::ResetEOS()
+{
+  // After eos, android::MediaCodec needs to be flushed to receive next input
+  mWaitOutput.Clear();
+  if (mDecoder->flush() != OK) {
+    GMDD_LOG("flush error");
+    mDecodeCallback->Error();
+  }
+}
+
+void
 GonkDecoderManager::onMessageReceived(const sp<AMessage> &aMessage)
 {
   switch (aMessage->what()) {
     case kNotifyProcessInput:
     {
       int32_t eos = 0;
       ProcessInput(aMessage->findInt32("input-eos", &eos) && eos);
       break;
--- a/dom/media/platforms/gonk/GonkMediaDataDecoder.h
+++ b/dom/media/platforms/gonk/GonkMediaDataDecoder.h
@@ -72,16 +72,17 @@ protected:
 
   // Send queued samples to OMX. It returns how many samples are still in
   // queue after processing, or negative error code if failed.
   int32_t ProcessQueuedSamples();
 
   void ProcessInput(bool aEndOfStream);
   virtual void ProcessFlush();
   void ProcessToDo(bool aEndOfStream);
+  virtual void ResetEOS();
 
   RefPtr<MediaByteBuffer> mCodecSpecificData;
 
   nsAutoCString mMimeType;
 
   // MediaCodedc's wrapper that performs the decoding.
   android::sp<android::MediaCodecProxy> mDecoder;
   // Looper for mDecoder to run on.