Commit 6528aef2 by aquilescanta Committed by Oliver Woodman

Add automatic E-AC-3 detection to the Ac3Reader

This is done through the bitstream id field and allows removing
the isEac3 parameter from the constructor.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=131393477
parent 4df63314
...@@ -114,7 +114,7 @@ public final class Ac3Extractor implements Extractor { ...@@ -114,7 +114,7 @@ public final class Ac3Extractor implements Extractor {
@Override @Override
public void init(ExtractorOutput output) { public void init(ExtractorOutput output) {
reader = new Ac3Reader(output.track(0), false); // TODO: Add support for embedded ID3. reader = new Ac3Reader(output.track(0)); // TODO: Add support for embedded ID3.
output.endTracks(); output.endTracks();
output.seekMap(new SeekMap.Unseekable(C.TIME_UNSET)); output.seekMap(new SeekMap.Unseekable(C.TIME_UNSET));
} }
......
...@@ -33,7 +33,6 @@ import com.google.android.exoplayer2.util.ParsableByteArray; ...@@ -33,7 +33,6 @@ import com.google.android.exoplayer2.util.ParsableByteArray;
private static final int HEADER_SIZE = 8; private static final int HEADER_SIZE = 8;
private final boolean isEac3;
private final ParsableBitArray headerScratchBits; private final ParsableBitArray headerScratchBits;
private final ParsableByteArray headerScratchBytes; private final ParsableByteArray headerScratchBytes;
...@@ -47,21 +46,18 @@ import com.google.android.exoplayer2.util.ParsableByteArray; ...@@ -47,21 +46,18 @@ import com.google.android.exoplayer2.util.ParsableByteArray;
private long sampleDurationUs; private long sampleDurationUs;
private Format format; private Format format;
private int sampleSize; private int sampleSize;
private boolean isEac3;
// Used when reading the samples. // Used when reading the samples.
private long timeUs; private long timeUs;
// TODO: Remove the isEac3 parameter by reading the BSID field.
/** /**
* Constructs a new reader for (E-)AC-3 elementary streams. * Constructs a new reader for (E-)AC-3 elementary streams.
* *
* @param output Track output for extracted samples. * @param output Track output for extracted samples.
* @param isEac3 Whether the stream is E-AC-3 (ETSI TS 102 366 Annex E). Specify {@code false} to
* decode sample headers as AC-3.
*/ */
public Ac3Reader(TrackOutput output, boolean isEac3) { public Ac3Reader(TrackOutput output) {
super(output); super(output);
this.isEac3 = isEac3;
headerScratchBits = new ParsableBitArray(new byte[HEADER_SIZE]); headerScratchBits = new ParsableBitArray(new byte[HEADER_SIZE]);
headerScratchBytes = new ParsableByteArray(headerScratchBits.data); headerScratchBytes = new ParsableByteArray(headerScratchBits.data);
state = STATE_FINDING_SYNC; state = STATE_FINDING_SYNC;
...@@ -163,6 +159,10 @@ import com.google.android.exoplayer2.util.ParsableByteArray; ...@@ -163,6 +159,10 @@ import com.google.android.exoplayer2.util.ParsableByteArray;
*/ */
private void parseHeader() { private void parseHeader() {
if (format == null) { if (format == null) {
// We read ahead to distinguish between AC-3 and E-AC-3.
headerScratchBits.skipBits(40);
isEac3 = headerScratchBits.readBits(5) == 16;
headerScratchBits.setPosition(headerScratchBits.getPosition() - 45);
format = isEac3 ? Ac3Util.parseEac3SyncframeFormat(headerScratchBits, null, null, null) format = isEac3 ? Ac3Util.parseEac3SyncframeFormat(headerScratchBits, null, null, null)
: Ac3Util.parseAc3SyncframeFormat(headerScratchBits, null, null, null); : Ac3Util.parseAc3SyncframeFormat(headerScratchBits, null, null, null);
output.format(format); output.format(format);
......
...@@ -189,7 +189,7 @@ public final class PsExtractor implements Extractor { ...@@ -189,7 +189,7 @@ public final class PsExtractor implements Extractor {
// Private stream, used for AC3 audio. // Private stream, used for AC3 audio.
// NOTE: This may need further parsing to determine if its DTS, but that's likely only // NOTE: This may need further parsing to determine if its DTS, but that's likely only
// valid for DVDs. // valid for DVDs.
elementaryStreamReader = new Ac3Reader(output.track(streamId), false); elementaryStreamReader = new Ac3Reader(output.track(streamId));
foundAudioTrack = true; foundAudioTrack = true;
} else if (!foundAudioTrack && (streamId & AUDIO_STREAM_MASK) == AUDIO_STREAM) { } else if (!foundAudioTrack && (streamId & AUDIO_STREAM_MASK) == AUDIO_STREAM) {
elementaryStreamReader = new MpegAudioReader(output.track(streamId)); elementaryStreamReader = new MpegAudioReader(output.track(streamId));
......
...@@ -406,10 +406,8 @@ public final class TsExtractor implements Extractor { ...@@ -406,10 +406,8 @@ public final class TsExtractor implements Extractor {
: new AdtsReader(output.track(trackId), new DummyTrackOutput()); : new AdtsReader(output.track(trackId), new DummyTrackOutput());
break; break;
case TS_STREAM_TYPE_AC3: case TS_STREAM_TYPE_AC3:
pesPayloadReader = new Ac3Reader(output.track(trackId), false);
break;
case TS_STREAM_TYPE_E_AC3: case TS_STREAM_TYPE_E_AC3:
pesPayloadReader = new Ac3Reader(output.track(trackId), true); pesPayloadReader = new Ac3Reader(output.track(trackId));
break; break;
case TS_STREAM_TYPE_DTS: case TS_STREAM_TYPE_DTS:
case TS_STREAM_TYPE_HDMV_DTS: case TS_STREAM_TYPE_HDMV_DTS:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment