Skip to content

Enable multiple audio presentations parsing for AC-4 in TS #2392

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static java.lang.Math.min;
import static java.lang.annotation.ElementType.TYPE_USE;

import android.media.AudioPresentation;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
Expand All @@ -37,6 +38,7 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.List;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;

Expand All @@ -59,6 +61,7 @@ public final class Ac4Reader implements ElementaryStreamReader {
@Nullable private final String language;
private final @C.RoleFlags int roleFlags;
private final String containerMimeType;
@Nullable private final List<AudioPresentation> audioPresentations;

private @MonotonicNonNull String formatId;
private @MonotonicNonNull TrackOutput output;
Expand All @@ -84,7 +87,7 @@ public final class Ac4Reader implements ElementaryStreamReader {
* @param containerMimeType The MIME type of the container holding the stream.
*/
public Ac4Reader(String containerMimeType) {
this(null, /* roleFlags= */ 0, containerMimeType);
this(null, /* roleFlags= */ 0, containerMimeType, null);
}

/**
Expand All @@ -93,9 +96,11 @@ public Ac4Reader(String containerMimeType) {
* @param language Track language.
* @param roleFlags Track role flags.
* @param containerMimeType The MIME type of the container holding the stream.
* @param audioPresentations Track audio presentations.
*/
public Ac4Reader(
@Nullable String language, @C.RoleFlags int roleFlags, String containerMimeType) {
@Nullable String language, @C.RoleFlags int roleFlags, String containerMimeType,
@Nullable List<AudioPresentation> audioPresentations) {
headerScratchBits = new ParsableBitArray(new byte[Ac4Util.HEADER_SIZE_FOR_PARSER]);
headerScratchBytes = new ParsableByteArray(headerScratchBits.data);
state = STATE_FINDING_SYNC;
Expand All @@ -106,6 +111,7 @@ public Ac4Reader(
this.language = language;
this.roleFlags = roleFlags;
this.containerMimeType = containerMimeType;
this.audioPresentations = audioPresentations;
}

@Override
Expand Down Expand Up @@ -230,6 +236,7 @@ private void parseHeader() {
.setSampleRate(frameInfo.sampleRate)
.setLanguage(language)
.setRoleFlags(roleFlags)
.setAudioPresentations(audioPresentations)
.build();
output.format(format);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ public TsPayloadReader createPayloadReader(int streamType, EsInfo esInfo) {
new Ac3Reader(esInfo.language, esInfo.getRoleFlags(), MimeTypes.VIDEO_MP2T));
case TsExtractor.TS_STREAM_TYPE_AC4:
return new PesReader(
new Ac4Reader(esInfo.language, esInfo.getRoleFlags(), MimeTypes.VIDEO_MP2T));
new Ac4Reader(esInfo.language, esInfo.getRoleFlags(), MimeTypes.VIDEO_MP2T,
esInfo.audioPresentations));
case TsExtractor.TS_STREAM_TYPE_HDMV_DTS:
if (!isSet(FLAG_ENABLE_HDMV_DTS_AUDIO_STREAMS)) {
return null;
Expand Down
Loading