Bug 1317239 - Part2 - Config the video decoder with adaptive playback feature if it is supported.
MozReview-Commit-ID: FORF2NNxgUH
--- 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().");
}
}