mirror of
https://github.com/samsonjs/media.git
synced 2026-04-05 11:15:46 +00:00
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
This commit is contained in:
parent
4df63314d4
commit
6528aef2bb
4 changed files with 9 additions and 11 deletions
|
|
@ -114,7 +114,7 @@ public final class Ac3Extractor implements Extractor {
|
|||
|
||||
@Override
|
||||
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.seekMap(new SeekMap.Unseekable(C.TIME_UNSET));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import com.google.android.exoplayer2.util.ParsableByteArray;
|
|||
|
||||
private static final int HEADER_SIZE = 8;
|
||||
|
||||
private final boolean isEac3;
|
||||
private final ParsableBitArray headerScratchBits;
|
||||
private final ParsableByteArray headerScratchBytes;
|
||||
|
||||
|
|
@ -47,21 +46,18 @@ import com.google.android.exoplayer2.util.ParsableByteArray;
|
|||
private long sampleDurationUs;
|
||||
private Format format;
|
||||
private int sampleSize;
|
||||
private boolean isEac3;
|
||||
|
||||
// Used when reading the samples.
|
||||
private long timeUs;
|
||||
|
||||
// TODO: Remove the isEac3 parameter by reading the BSID field.
|
||||
/**
|
||||
* Constructs a new reader for (E-)AC-3 elementary streams.
|
||||
*
|
||||
* @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);
|
||||
this.isEac3 = isEac3;
|
||||
headerScratchBits = new ParsableBitArray(new byte[HEADER_SIZE]);
|
||||
headerScratchBytes = new ParsableByteArray(headerScratchBits.data);
|
||||
state = STATE_FINDING_SYNC;
|
||||
|
|
@ -163,6 +159,10 @@ import com.google.android.exoplayer2.util.ParsableByteArray;
|
|||
*/
|
||||
private void parseHeader() {
|
||||
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)
|
||||
: Ac3Util.parseAc3SyncframeFormat(headerScratchBits, null, null, null);
|
||||
output.format(format);
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ public final class PsExtractor implements Extractor {
|
|||
// Private stream, used for AC3 audio.
|
||||
// NOTE: This may need further parsing to determine if its DTS, but that's likely only
|
||||
// valid for DVDs.
|
||||
elementaryStreamReader = new Ac3Reader(output.track(streamId), false);
|
||||
elementaryStreamReader = new Ac3Reader(output.track(streamId));
|
||||
foundAudioTrack = true;
|
||||
} else if (!foundAudioTrack && (streamId & AUDIO_STREAM_MASK) == AUDIO_STREAM) {
|
||||
elementaryStreamReader = new MpegAudioReader(output.track(streamId));
|
||||
|
|
|
|||
|
|
@ -406,10 +406,8 @@ public final class TsExtractor implements Extractor {
|
|||
: new AdtsReader(output.track(trackId), new DummyTrackOutput());
|
||||
break;
|
||||
case TS_STREAM_TYPE_AC3:
|
||||
pesPayloadReader = new Ac3Reader(output.track(trackId), false);
|
||||
break;
|
||||
case TS_STREAM_TYPE_E_AC3:
|
||||
pesPayloadReader = new Ac3Reader(output.track(trackId), true);
|
||||
pesPayloadReader = new Ac3Reader(output.track(trackId));
|
||||
break;
|
||||
case TS_STREAM_TYPE_DTS:
|
||||
case TS_STREAM_TYPE_HDMV_DTS:
|
||||
|
|
|
|||
Loading…
Reference in a new issue