Bug 1317239 - Part2 - Config the video decoder with adaptive playback feature if it is supported. draft
authorJames Cheng <jacheng@mozilla.com>
Wed, 23 Nov 2016 14:12:05 +0800
changeset 442844 e734e3a4b7e021f2854ab5fc0a80b51322c0e4b9
parent 442843 ee5e36b7d34467a119eccb1c80637f0ad94f562e
child 537907 488d17c9bb67b173e66cc723448c044b70f6c7be
push id36838
push userbmo:jacheng@mozilla.com
push dateWed, 23 Nov 2016 10:23:02 +0000
bugs1317239
milestone53.0a1
Bug 1317239 - Part2 - Config the video decoder with adaptive playback feature if it is supported. MozReview-Commit-ID: FORF2NNxgUH
dom/media/platforms/android/MediaCodecDataDecoder.cpp
mobile/android/base/java/org/mozilla/gecko/media/JellyBeanAsyncCodec.java
--- a/dom/media/platforms/android/MediaCodecDataDecoder.cpp
+++ b/dom/media/platforms/android/MediaCodecDataDecoder.cpp
@@ -368,22 +368,31 @@ MediaCodecDataDecoder::Init()
            InitPromise::CreateAndReject(
                NS_ERROR_DOM_MEDIA_FATAL_ERR, __func__);
 }
 
 nsresult
 MediaCodecDataDecoder::InitDecoder(Surface::Param aSurface)
 {
   mDecoder = CreateDecoder(mMimeType);
+
   if (!mDecoder) {
     INVOKE_CALLBACK(Error,
                     MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR, __func__));
     return NS_ERROR_FAILURE;
   }
 
+  // Check if the video codec supports adaptive playback or not.
+  if (aSurface && java::HardwareCodecCapabilityUtils::CheckSupportsAdaptivePlayback(
+                    mDecoder, nsCString(TranslateMimeType(mMimeType)))) {
+      // TODO: may need to find a way to not use hard code to decide the max w/h.
+      mFormat->SetInteger(MediaFormat::KEY_MAX_WIDTH, 1920);
+      mFormat->SetInteger(MediaFormat::KEY_MAX_HEIGHT, 1080);
+  }
+
   MediaCrypto::LocalRef crypto = MediaDrmProxy::GetMediaCrypto(mDrmStubId);
   bool hascrypto = !!crypto;
   LOG("Has(%d) MediaCrypto (%s)", hascrypto, NS_ConvertUTF16toUTF8(mDrmStubId).get());
   nsresult rv;
   NS_ENSURE_SUCCESS(rv = mDecoder->Configure(mFormat, aSurface, crypto, 0), rv);
   NS_ENSURE_SUCCESS(rv = mDecoder->Start(), rv);
 
   NS_ENSURE_SUCCESS(rv = ResetInputBuffers(), rv);
--- a/mobile/android/base/java/org/mozilla/gecko/media/JellyBeanAsyncCodec.java
+++ b/mobile/android/base/java/org/mozilla/gecko/media/JellyBeanAsyncCodec.java
@@ -1,14 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.media;
 
+import org.mozilla.gecko.util.HardwareCodecCapabilityUtils;
+
 import android.media.MediaCodec;
 import android.media.MediaCrypto;
 import android.media.MediaFormat;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.Looper;
 import android.os.Message;
 import android.util.Log;
@@ -293,16 +295,25 @@ final class JellyBeanAsyncCodec implemen
         mCallbackSender = new CallbackSender(looper, callbacks);
         if (DEBUG) Log.d(LOGTAG, "setCallbacks(): sender=" + mCallbackSender);
     }
 
     @Override
     public void configure(MediaFormat format, Surface surface, MediaCrypto crypto, int flags) {
         assertCallbacks();
 
+        // Video decoder should config with adaptive playback capability.
+        if (surface != null) {
+            if (HardwareCodecCapabilityUtils.checkSupportsAdaptivePlayback(
+                    mCodec, format.getString(MediaFormat.KEY_MIME))) {
+                // TODO: may need to find a way to not use hard code to decide the max w/h.
+                format.setInteger(MediaFormat.KEY_MAX_WIDTH, 1920);
+                format.setInteger(MediaFormat.KEY_MAX_HEIGHT, 1080);
+            }
+        }
         mCodec.configure(format, surface, crypto, flags);
     }
 
     private void assertCallbacks() {
         if (mCallbackSender == null) {
             throw new IllegalStateException(LOGTAG + ": callback must be supplied with setCallbacks().");
         }
     }