Bug 1317239 - Part2 - Config the video decoder with adaptive playback feature if it is supported. r=jolin
authorJames Cheng <jacheng@mozilla.com>
Wed, 23 Nov 2016 14:12:05 +0800
changeset 323997 2e9dbc8426fbc59271da469b6697a0aa037b2053
parent 323996 4d45db027c096f1038f47c748fdbd21e7effa7a4
child 323998 127fbc771149d9bf3fbc00047751f1430330d34e
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewersjolin
bugs1317239
milestone53.0a1
Bug 1317239 - Part2 - Config the video decoder with adaptive playback feature if it is supported. r=jolin 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().");
         }
     }