Skip to content

Commit

Permalink
Work around broken raw audio decoder on Oppo R9
Browse files Browse the repository at this point in the history
Issue: #5782
PiperOrigin-RevId: 247934223
  • Loading branch information
andrewlewis authored and ojw28 committed May 15, 2019
1 parent 43195ed commit a849f43
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
([#5784](https://github.com/google/ExoPlayer/issues/5784)).
* Add a workaround for a decoder failure on ZTE Axon7 mini devices when playing
48kHz audio ([#5821](https://github.com/google/ExoPlayer/issues/5821)).
* Add a workaround for broken raw audio decoding on Oppo R9
([#5782](https://github.com/google/ExoPlayer/issues/5782)).

### 2.10.0 ###

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public final class MediaCodecInfo {
public final String name;

/** The MIME type handled by the codec, or {@code null} if this is a passthrough codec. */
public final @Nullable String mimeType;
@Nullable public final String mimeType;

/**
* The capabilities of the decoder, like the profiles/levels it supports, or {@code null} if this
* is a passthrough codec.
* The capabilities of the decoder, like the profiles/levels it supports, or {@code null} if not
* known.
*/
public final @Nullable CodecCapabilities capabilities;
@Nullable public final CodecCapabilities capabilities;

/**
* Whether the decoder supports seamless resolution switches.
Expand Down Expand Up @@ -109,11 +109,12 @@ public static MediaCodecInfo newPassthroughInstance(String name) {
*
* @param name The name of the {@link MediaCodec}.
* @param mimeType A mime type supported by the {@link MediaCodec}.
* @param capabilities The capabilities of the {@link MediaCodec} for the specified mime type.
* @param capabilities The capabilities of the {@link MediaCodec} for the specified mime type, or
* {@code null} if not known.
* @return The created instance.
*/
public static MediaCodecInfo newInstance(String name, String mimeType,
CodecCapabilities capabilities) {
public static MediaCodecInfo newInstance(
String name, String mimeType, @Nullable CodecCapabilities capabilities) {
return new MediaCodecInfo(
name,
mimeType,
Expand All @@ -128,15 +129,16 @@ public static MediaCodecInfo newInstance(String name, String mimeType,
*
* @param name The name of the {@link MediaCodec}.
* @param mimeType A mime type supported by the {@link MediaCodec}.
* @param capabilities The capabilities of the {@link MediaCodec} for the specified mime type.
* @param capabilities The capabilities of the {@link MediaCodec} for the specified mime type, or
* {@code null} if not known.
* @param forceDisableAdaptive Whether {@link #adaptive} should be forced to {@code false}.
* @param forceSecure Whether {@link #secure} should be forced to {@code true}.
* @return The created instance.
*/
public static MediaCodecInfo newInstance(
String name,
String mimeType,
CodecCapabilities capabilities,
@Nullable CodecCapabilities capabilities,
boolean forceDisableAdaptive,
boolean forceSecure) {
return new MediaCodecInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,16 @@ private static boolean isCodecUsableDecoder(android.media.MediaCodecInfo info, S
*/
private static void applyWorkarounds(String mimeType, List<MediaCodecInfo> decoderInfos) {
if (MimeTypes.AUDIO_RAW.equals(mimeType)) {
if (Util.SDK_INT < 26
&& Util.DEVICE.equals("R9")
&& decoderInfos.size() == 1
&& decoderInfos.get(0).name.equals("OMX.MTK.AUDIO.DECODER.RAW")) {
// This device does not list a generic raw audio decoder, yet it can be instantiated by
// name. See <a href="https://github.com/google/ExoPlayer/issues/5782">Issue #5782</a>.
decoderInfos.add(
MediaCodecInfo.newInstance(
"OMX.google.raw.decoder", MimeTypes.AUDIO_RAW, /* capabilities= */ null));
}
// Work around inconsistent raw audio decoding behavior across different devices.
sortByScore(
decoderInfos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import android.media.MediaCodecInfo.CodecCapabilities;
import android.media.MediaCodecInfo.CodecProfileLevel;
import android.media.MediaCodecInfo.VideoCapabilities;
import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.mediacodec.MediaCodecInfo;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil;
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException;
import com.google.android.exoplayer2.testutil.MetricsLogger;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import java.util.Arrays;
Expand Down Expand Up @@ -93,14 +93,17 @@ private void logDecoderInfos(String mimeType, boolean secure, boolean tunneling)
List<MediaCodecInfo> mediaCodecInfos =
MediaCodecUtil.getDecoderInfos(mimeType, secure, tunneling);
for (MediaCodecInfo mediaCodecInfo : mediaCodecInfos) {
CodecCapabilities capabilities = Assertions.checkNotNull(mediaCodecInfo.capabilities);
CodecCapabilities capabilities = mediaCodecInfo.capabilities;
metricsLogger.logMetric(
"capabilities_" + mediaCodecInfo.name, codecCapabilitiesToString(mimeType, capabilities));
}
}

private static String codecCapabilitiesToString(
String requestedMimeType, CodecCapabilities codecCapabilities) {
String requestedMimeType, @Nullable CodecCapabilities codecCapabilities) {
if (codecCapabilities == null) {
return "[null]";
}
boolean isVideo = MimeTypes.isVideo(requestedMimeType);
boolean isAudio = MimeTypes.isAudio(requestedMimeType);
StringBuilder result = new StringBuilder();
Expand Down

0 comments on commit a849f43

Please sign in to comment.