Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions libraries/common/src/main/java/androidx/media3/common/C.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ private C() {}
ENCODING_OPUS,
ENCODING_DTS_UHD_P2,
ENCODING_DSD,
ENCODING_MPEGH_BL_L3,
ENCODING_MPEGH_BL_L4,
ENCODING_MPEGH_LC_L3,
ENCODING_MPEGH_LC_L4
})
public @interface Encoding {}

Expand Down Expand Up @@ -340,6 +344,18 @@ private C() {}
/** See {@link AudioFormat#ENCODING_DSD}. */
@UnstableApi public static final int ENCODING_DSD = AudioFormat.ENCODING_DSD;

/** See {@link AudioFormat#ENCODING_MPEGH_BL_L3}. */
@UnstableApi public static final int ENCODING_MPEGH_BL_L3 = AudioFormat.ENCODING_MPEGH_BL_L3;

/** See {@link AudioFormat#ENCODING_MPEGH_BL_L4}. */
@UnstableApi public static final int ENCODING_MPEGH_BL_L4 = AudioFormat.ENCODING_MPEGH_BL_L4;

/** See {@link AudioFormat#ENCODING_MPEGH_LC_L3}. */
@UnstableApi public static final int ENCODING_MPEGH_LC_L3 = AudioFormat.ENCODING_MPEGH_LC_L3;

/** See {@link AudioFormat#ENCODING_MPEGH_LC_L4}. */
@UnstableApi public static final int ENCODING_MPEGH_LC_L4 = AudioFormat.ENCODING_MPEGH_LC_L4;

/**
* Represents the behavior affecting whether spatialization will be used. One of {@link
* #SPATIALIZATION_BEHAVIOR_AUTO} or {@link #SPATIALIZATION_BEHAVIOR_NEVER}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,8 @@ public static boolean isDolbyVisionCodec(
return C.ENCODING_OPUS;
case MimeTypes.AUDIO_DSD:
return C.ENCODING_DSD;
case MimeTypes.AUDIO_MPEGH_MHM1:
return C.ENCODING_MPEGH_BL_L3;
default:
return C.ENCODING_INVALID;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,20 @@ public static boolean isEncodingLinearPcm(@C.Encoding int encoding) {
|| encoding == C.ENCODING_PCM_DOUBLE_BIG_ENDIAN;
}

/**
* Returns whether {@code encoding} is an MPEG-H encoding.
*
* @param encoding The encoding of the audio data.
* @return Whether the encoding is an MPEG-H encoding.
*/
@UnstableApi
public static boolean isMpegh(@C.Encoding int encoding) {
return encoding == C.ENCODING_MPEGH_BL_L3
|| encoding == C.ENCODING_MPEGH_BL_L4
|| encoding == C.ENCODING_MPEGH_LC_L3
|| encoding == C.ENCODING_MPEGH_LC_L4;
}

/**
* Returns whether {@code encoding} is high resolution (> 16-bit) PCM.
*
Expand Down Expand Up @@ -2801,6 +2815,10 @@ public static int getApiLevelThatAudioFormatIntroducedAudioEncoding(int encoding
return 30;
case C.ENCODING_PCM_24BIT:
case C.ENCODING_PCM_32BIT:
case C.ENCODING_MPEGH_BL_L3:
case C.ENCODING_MPEGH_BL_L4:
case C.ENCODING_MPEGH_LC_L3:
case C.ENCODING_MPEGH_LC_L4:
return 31;
case C.ENCODING_DTS_UHD_P2:
case C.ENCODING_DSD:
Expand Down
2 changes: 1 addition & 1 deletion libraries/decoder_mpegh/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ the root of your media3 check-out):
```shell
cd libraries/decoder_mpegh/src/main/jni && \
git clone https://github.com/Fraunhofer-IIS/mpeghdec.git \
--branch r3.0.2 \
--branch r3.0.3 \
--depth=1 \
libmpegh
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

/** Decodes and renders audio using the native MPEG-H decoder. */
@UnstableApi
public final class MpeghAudioRenderer extends DecoderAudioRenderer<MpeghDecoder> {
public final class MpeghAudioRenderer extends DecoderAudioRenderer<MpeghBaseDecoder> {

private static final String TAG = "MpeghAudioRenderer";

Expand All @@ -61,6 +61,9 @@ public final class MpeghAudioRenderer extends DecoderAudioRenderer<MpeghDecoder>
/** Helper for handling MPEG-H UI commands and system settings. */
private final MpeghUiCommandHelper uiHelper;

/** Whether the decoder is configured for direct (hardware offload) playback. */
private boolean isDirectPlayback;

/* Creates a new instance. */
public MpeghAudioRenderer() {
this(/* eventHandler= */ null, /* eventListener= */ null);
Expand Down Expand Up @@ -95,6 +98,7 @@ public MpeghAudioRenderer(
public MpeghAudioRenderer(
Handler eventHandler, AudioRendererEventListener eventListener, AudioSink audioSink) {
super(eventHandler, eventListener, audioSink);
audioSink.setOffloadMode(AudioSink.OFFLOAD_MODE_ENABLED_GAPLESS_NOT_REQUIRED);
uiHelper = new MpeghUiCommandHelper();
uiHelper.setEventDispatcher(
new AudioRendererEventListener.EventDispatcher(eventHandler, eventListener));
Expand All @@ -107,9 +111,19 @@ public String getName() {

@Override
protected @C.FormatSupport int supportsFormatInternal(Format format) {
// Check if JNI library is available.
if (!MpeghLibrary.isAvailable()) {
return C.FORMAT_UNSUPPORTED_TYPE;
if (format.channelCount <= 0) {
Format.Builder checkFormatBuilder = format.buildUpon();
checkFormatBuilder.setChannelCount(2);
format = checkFormatBuilder.build();
}
@AudioSink.SinkFormatSupport
int formatSupport = getSinkFormatSupport(format);
isDirectPlayback = formatSupport == AudioSink.SINK_FORMAT_SUPPORTED_DIRECTLY;

if (isDirectPlayback) {
if (!Objects.equals(format.sampleMimeType, MimeTypes.AUDIO_MPEGH_MHM1)) {
return C.FORMAT_UNSUPPORTED_TYPE;
}
}

// Check if MIME type is supported.
Expand All @@ -136,22 +150,35 @@ protected DecoderReuseEvaluation canReuseDecoder(
}

@Override
protected MpeghDecoder createDecoder(Format format, CryptoConfig cryptoConfig)
protected MpeghBaseDecoder createDecoder(Format format, CryptoConfig cryptoConfig)
throws MpeghDecoderException {
TraceUtil.beginSection("createMpeghDecoder");
MpeghDecoder decoder = new MpeghDecoder(format, NUM_BUFFERS, NUM_BUFFERS, uiHelper);
MpeghBaseDecoder decoder;
if (isDirectPlayback) {
decoder = new MpeghPassThroughDecoder(format, NUM_BUFFERS, NUM_BUFFERS, uiHelper);
} else {
decoder = new MpeghDecoder(format, NUM_BUFFERS, NUM_BUFFERS, uiHelper);
}
TraceUtil.endSection();
return decoder;
}

@Override
protected Format getOutputFormat(MpeghDecoder decoder) {
return new Format.Builder()
.setChannelCount(decoder.getChannelCount())
.setSampleRate(decoder.getSampleRate())
.setSampleMimeType(MimeTypes.AUDIO_RAW)
.setPcmEncoding(C.ENCODING_PCM_16BIT)
.build();
protected Format getOutputFormat(MpeghBaseDecoder decoder) {
int channelCount = decoder.getChannelCount();
int sampleRate = decoder.getSampleRate();
String sampleMimeType = decoder.getSampleMimeType();
@C.Encoding int pcmEncoding = decoder.getPcmEncoding();
Format.Builder builder = new Format.Builder();
builder
.setChannelCount(channelCount)
.setSampleRate(sampleRate)
.setSampleMimeType(sampleMimeType);
if (pcmEncoding != C.ENCODING_INVALID) {
builder.setPcmEncoding(pcmEncoding);
}

return builder.build();
}

@Override
Expand Down
Loading