Skip to content

Commit

Permalink
Bug 1778393 - allow 10-bit video on Android. r=azebrowski,geckoview-r…
Browse files Browse the repository at this point in the history
…eviewers,m_kato

Depends on D164723

Differential Revision: https://phabricator.services.mozilla.com/D164724
  • Loading branch information
jhlin committed Mar 7, 2023
1 parent 9cdfb0d commit b87bc5d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
34 changes: 34 additions & 0 deletions dom/media/platforms/android/AndroidDecoderModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,40 @@ media::DecodeSupportSet AndroidDecoderModule::SupportsMimeType(
return AndroidDecoderModule::SupportsMimeType(aMimeType);
}

bool AndroidDecoderModule::SupportsColorDepth(
gfx::ColorDepth aColorDepth, DecoderDoctorDiagnostics* aDiagnostics) const {
// 10-bit support is codec dependent so this is not entirely accurate.
// Supports() will correct it.
return aColorDepth == gfx::ColorDepth::COLOR_8 ||
aColorDepth == gfx::ColorDepth::COLOR_10;
}

// Further check is needed because the base class uses the inaccurate
// SupportsColorDepth().
media::DecodeSupportSet AndroidDecoderModule::Supports(
const SupportDecoderParams& aParams,
DecoderDoctorDiagnostics* aDiagnostics) const {
media::DecodeSupportSet support =
PlatformDecoderModule::Supports(aParams, aDiagnostics);

// Short-circuit.
if (support == media::DecodeSupport::Unsupported) {
return support;
}

// Check 10-bit video.
const TrackInfo& trackInfo = aParams.mConfig;
const VideoInfo* videoInfo = trackInfo.GetAsVideoInfo();
if (!videoInfo || videoInfo->mColorDepth != gfx::ColorDepth::COLOR_10) {
return support;
}

return java::HardwareCodecCapabilityUtils::Decodes10Bit(
TranslateMimeType(aParams.MimeType()))
? support
: media::DecodeSupport::Unsupported;
}

already_AddRefed<MediaDataDecoder> AndroidDecoderModule::CreateVideoDecoder(
const CreateDecoderParams& aParams) {
// Temporary - forces use of VPXDecoder when alpha is present.
Expand Down
9 changes: 9 additions & 0 deletions dom/media/platforms/android/AndroidDecoderModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ class AndroidDecoderModule : public PlatformDecoderModule {

static void SetSupportedMimeTypes(nsTArray<nsCString>&& aSupportedTypes);

media::DecodeSupportSet Supports(
const SupportDecoderParams& aParams,
DecoderDoctorDiagnostics* aDiagnostics) const override;

protected:
bool SupportsColorDepth(
gfx::ColorDepth aColorDepth,
DecoderDoctorDiagnostics* aDiagnostics) const override;

private:
explicit AndroidDecoderModule(CDMProxy* aProxy = nullptr);
virtual ~AndroidDecoderModule() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.mozilla.gecko.util;

import android.annotation.SuppressLint;
import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaCodecInfo.CodecCapabilities;
Expand Down Expand Up @@ -262,4 +263,58 @@ public static boolean hasHWH264() {
return getHWCodecCapability(H264_MIME_TYPE, true)
&& getHWCodecCapability(H264_MIME_TYPE, false);
}

@WrapForJNI
@SuppressLint("NewApi")
public static boolean decodes10Bit(final String aMimeType) {
if (Build.VERSION.SDK_INT < 24) {
// Be conservative when we cannot get supported profile.
return false;
}

final MediaCodecList codecs = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
for (final MediaCodecInfo info : codecs.getCodecInfos()) {
if (info.isEncoder()) {
continue;
}
try {
for (final MediaCodecInfo.CodecProfileLevel pl :
info.getCapabilitiesForType(aMimeType).profileLevels) {
if ((aMimeType.equals(H264_MIME_TYPE)
&& pl.profile == MediaCodecInfo.CodecProfileLevel.AVCProfileHigh10)
|| (aMimeType.equals(VP9_MIME_TYPE) && is10BitVP9Profile(pl.profile))) {
return true;
}
}
} catch (final IllegalArgumentException e) {
// Type not supported.
continue;
}
}

return false;
}

@SuppressLint("NewApi")
private static boolean is10BitVP9Profile(final int profile) {
if (Build.VERSION.SDK_INT < 24) {
// Be conservative when we cannot get supported profile.
return false;
}

if ((profile == MediaCodecInfo.CodecProfileLevel.VP9Profile2)
|| (profile == MediaCodecInfo.CodecProfileLevel.VP9Profile3)
|| (profile == MediaCodecInfo.CodecProfileLevel.VP9Profile2HDR)
|| (profile == MediaCodecInfo.CodecProfileLevel.VP9Profile3HDR)) {
return true;
}

if (Build.VERSION.SDK_INT >= 29
&& ((profile == MediaCodecInfo.CodecProfileLevel.VP9Profile2HDR10Plus)
|| (profile == MediaCodecInfo.CodecProfileLevel.VP9Profile3HDR10Plus))) {
return true;
}

return false;
}
}

0 comments on commit b87bc5d

Please sign in to comment.