Bug 1050667 - fix the non-synchronous waiting state between MediaDecoderStataMachine and MediaCodecReader. r=sotaro
☠☠ backed out by eac61c961c1b ☠ ☠
authorBenjamin Chen <bechen@mozilla.com>
Thu, 18 Sep 2014 15:29:38 +0800
changeset 206165 ed6f3ec5a71bfa6e51590d5720503bad865cf6be
parent 206164 1193525f1f15caeac54a07f2e635a1bf81558650
child 206166 1ca5ac2106b23e50d945623539c54c2a949bd006
push id27515
push userryanvm@gmail.com
push dateFri, 19 Sep 2014 17:29:33 +0000
treeherdermozilla-central@74d4fc84e39e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1050667
milestone35.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 1050667 - fix the non-synchronous waiting state between MediaDecoderStataMachine and MediaCodecReader. r=sotaro
content/media/omx/MediaCodecReader.cpp
content/media/omx/MediaCodecReader.h
--- a/content/media/omx/MediaCodecReader.cpp
+++ b/content/media/omx/MediaCodecReader.cpp
@@ -280,16 +280,17 @@ MediaCodecReader::ProcessCachedDataTask:
 MediaCodecReader::MediaCodecReader(AbstractMediaDecoder* aDecoder)
   : MediaOmxCommonReader(aDecoder)
   , mColorConverterBufferSize(0)
   , mExtractor(nullptr)
   , mParserMonitor("MediaCodecReader::mParserMonitor")
   , mParseDataFromCache(true)
   , mNextParserPosition(INT64_C(0))
   , mParsedDataLength(INT64_C(0))
+  , mIsWaitingResources(false)
 {
   mHandler = new MessageHandler(this);
   mVideoListener = new VideoResourceListener(this);
 }
 
 MediaCodecReader::~MediaCodecReader()
 {
   MOZ_ASSERT(NS_IsMainThread(), "Should be on main thread.");
@@ -299,17 +300,24 @@ nsresult
 MediaCodecReader::Init(MediaDecoderReader* aCloneDonor)
 {
   return NS_OK;
 }
 
 bool
 MediaCodecReader::IsWaitingMediaResources()
 {
-  return mVideoTrack.mCodec != nullptr && !mVideoTrack.mCodec->allocated();
+  return mIsWaitingResources;
+}
+
+void
+MediaCodecReader::UpdateIsWaitingMediaResources()
+{
+  mIsWaitingResources = (mVideoTrack.mCodec != nullptr) &&
+                        (!mVideoTrack.mCodec->allocated());
 }
 
 bool
 MediaCodecReader::IsDormantNeeded()
 {
   return mVideoTrack.mSource != nullptr;
 }
 
@@ -656,16 +664,21 @@ MediaCodecReader::ReadMetadata(MediaInfo
   if (!ReallocateResources()) {
     return NS_ERROR_FAILURE;
   }
 
   if (!TriggerIncrementalParser()) {
     return NS_ERROR_FAILURE;
   }
 
+  // Bug 1050667, both MediaDecoderStateMachine and MediaCodecReader
+  // relies on IsWaitingMediaResources() function. And the waiting state will be
+  // changed by binder thread, so we store the waiting state in a cache value to
+  // make them in the same waiting state.
+  UpdateIsWaitingMediaResources();
   if (IsWaitingMediaResources()) {
     return NS_OK;
   }
 
   // TODO: start streaming
 
   if (!UpdateDuration()) {
     return NS_ERROR_FAILURE;
--- a/content/media/omx/MediaCodecReader.h
+++ b/content/media/omx/MediaCodecReader.h
@@ -147,17 +147,24 @@ protected:
 
   // Receive a notify from ResourceListener.
   // Called on Binder thread.
   virtual void codecReserved(Track& aTrack);
   virtual void codecCanceled(Track& aTrack);
 
   virtual bool CreateExtractor();
 
+  // Check the underlying HW resource is available and store the result in
+  // mIsWaitingResources.
+  void UpdateIsWaitingMediaResources();
+
   android::sp<android::MediaExtractor> mExtractor;
+  // A cache value updated by UpdateIsWaitingMediaResources(), makes the
+  // "waiting resources state" is synchronous to StateMachine.
+  bool mIsWaitingResources;
 
 private:
   // An intermediary class that can be managed by android::sp<T>.
   // Redirect onMessageReceived() to MediaCodecReader.
   class MessageHandler : public android::AHandler
   {
   public:
     MessageHandler(MediaCodecReader* aReader);