Commit 0402191a by aquilescanta Committed by Oliver Woodman

Make SeiReader injectable to H26xReaders

This CL is a no-op refactor but allows defining the outputted
channels through the TsPayloadReaderFactory.

Issue:#2161

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=146243736
parent ee3c5f87
...@@ -74,10 +74,11 @@ public final class DefaultTsPayloadReaderFactory implements TsPayloadReader.Fact ...@@ -74,10 +74,11 @@ public final class DefaultTsPayloadReaderFactory implements TsPayloadReader.Fact
case TsExtractor.TS_STREAM_TYPE_H262: case TsExtractor.TS_STREAM_TYPE_H262:
return new PesReader(new H262Reader()); return new PesReader(new H262Reader());
case TsExtractor.TS_STREAM_TYPE_H264: case TsExtractor.TS_STREAM_TYPE_H264:
return isSet(FLAG_IGNORE_H264_STREAM) ? null : new PesReader( return isSet(FLAG_IGNORE_H264_STREAM) ? null
new H264Reader(isSet(FLAG_ALLOW_NON_IDR_KEYFRAMES), isSet(FLAG_DETECT_ACCESS_UNITS))); : new PesReader(new H264Reader(new SeiReader(), isSet(FLAG_ALLOW_NON_IDR_KEYFRAMES),
isSet(FLAG_DETECT_ACCESS_UNITS)));
case TsExtractor.TS_STREAM_TYPE_H265: case TsExtractor.TS_STREAM_TYPE_H265:
return new PesReader(new H265Reader()); return new PesReader(new H265Reader(new SeiReader()));
case TsExtractor.TS_STREAM_TYPE_SPLICE_INFO: case TsExtractor.TS_STREAM_TYPE_SPLICE_INFO:
return isSet(FLAG_IGNORE_SPLICE_INFO_STREAM) return isSet(FLAG_IGNORE_SPLICE_INFO_STREAM)
? null : new SectionReader(new SpliceInfoSectionReader()); ? null : new SectionReader(new SpliceInfoSectionReader());
......
...@@ -39,6 +39,7 @@ import java.util.List; ...@@ -39,6 +39,7 @@ import java.util.List;
private static final int NAL_UNIT_TYPE_SPS = 7; // Sequence parameter set private static final int NAL_UNIT_TYPE_SPS = 7; // Sequence parameter set
private static final int NAL_UNIT_TYPE_PPS = 8; // Picture parameter set private static final int NAL_UNIT_TYPE_PPS = 8; // Picture parameter set
private final SeiReader seiReader;
private final boolean allowNonIdrKeyframes; private final boolean allowNonIdrKeyframes;
private final boolean detectAccessUnits; private final boolean detectAccessUnits;
private final NalUnitTargetBuffer sps; private final NalUnitTargetBuffer sps;
...@@ -49,7 +50,6 @@ import java.util.List; ...@@ -49,7 +50,6 @@ import java.util.List;
private String formatId; private String formatId;
private TrackOutput output; private TrackOutput output;
private SeiReader seiReader;
private SampleReader sampleReader; private SampleReader sampleReader;
// State that should not be reset on seek. // State that should not be reset on seek.
...@@ -62,15 +62,17 @@ import java.util.List; ...@@ -62,15 +62,17 @@ import java.util.List;
private final ParsableByteArray seiWrapper; private final ParsableByteArray seiWrapper;
/** /**
* @param seiReader An SEI reader for consuming closed caption channels.
* @param allowNonIdrKeyframes Whether to treat samples consisting of non-IDR I slices as * @param allowNonIdrKeyframes Whether to treat samples consisting of non-IDR I slices as
* synchronization samples (key-frames). * synchronization samples (key-frames).
* @param detectAccessUnits Whether to split the input stream into access units (samples) based on * @param detectAccessUnits Whether to split the input stream into access units (samples) based on
* slice headers. Pass {@code false} if the stream contains access unit delimiters (AUDs). * slice headers. Pass {@code false} if the stream contains access unit delimiters (AUDs).
*/ */
public H264Reader(boolean allowNonIdrKeyframes, boolean detectAccessUnits) { public H264Reader(SeiReader seiReader, boolean allowNonIdrKeyframes, boolean detectAccessUnits) {
prefixFlags = new boolean[3]; this.seiReader = seiReader;
this.allowNonIdrKeyframes = allowNonIdrKeyframes; this.allowNonIdrKeyframes = allowNonIdrKeyframes;
this.detectAccessUnits = detectAccessUnits; this.detectAccessUnits = detectAccessUnits;
prefixFlags = new boolean[3];
sps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SPS, 128); sps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SPS, 128);
pps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_PPS, 128); pps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_PPS, 128);
sei = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SEI, 128); sei = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SEI, 128);
...@@ -93,9 +95,7 @@ import java.util.List; ...@@ -93,9 +95,7 @@ import java.util.List;
formatId = idGenerator.getFormatId(); formatId = idGenerator.getFormatId();
output = extractorOutput.track(idGenerator.getTrackId()); output = extractorOutput.track(idGenerator.getTrackId());
sampleReader = new SampleReader(output, allowNonIdrKeyframes, detectAccessUnits); sampleReader = new SampleReader(output, allowNonIdrKeyframes, detectAccessUnits);
idGenerator.generateNewId(); seiReader.createTracks(extractorOutput, idGenerator);
seiReader = new SeiReader(extractorOutput.track(idGenerator.getTrackId()),
idGenerator.getFormatId());
} }
@Override @Override
......
...@@ -44,10 +44,11 @@ import java.util.Collections; ...@@ -44,10 +44,11 @@ import java.util.Collections;
private static final int PREFIX_SEI_NUT = 39; private static final int PREFIX_SEI_NUT = 39;
private static final int SUFFIX_SEI_NUT = 40; private static final int SUFFIX_SEI_NUT = 40;
private final SeiReader seiReader;
private String formatId; private String formatId;
private TrackOutput output; private TrackOutput output;
private SampleReader sampleReader; private SampleReader sampleReader;
private SeiReader seiReader;
// State that should not be reset on seek. // State that should not be reset on seek.
private boolean hasOutputFormat; private boolean hasOutputFormat;
...@@ -67,7 +68,11 @@ import java.util.Collections; ...@@ -67,7 +68,11 @@ import java.util.Collections;
// Scratch variables to avoid allocations. // Scratch variables to avoid allocations.
private final ParsableByteArray seiWrapper; private final ParsableByteArray seiWrapper;
public H265Reader() { /**
* @param seiReader An SEI reader for consuming closed caption channels.
*/
public H265Reader(SeiReader seiReader) {
this.seiReader = seiReader;
prefixFlags = new boolean[3]; prefixFlags = new boolean[3];
vps = new NalUnitTargetBuffer(VPS_NUT, 128); vps = new NalUnitTargetBuffer(VPS_NUT, 128);
sps = new NalUnitTargetBuffer(SPS_NUT, 128); sps = new NalUnitTargetBuffer(SPS_NUT, 128);
...@@ -95,9 +100,7 @@ import java.util.Collections; ...@@ -95,9 +100,7 @@ import java.util.Collections;
formatId = idGenerator.getFormatId(); formatId = idGenerator.getFormatId();
output = extractorOutput.track(idGenerator.getTrackId()); output = extractorOutput.track(idGenerator.getTrackId());
sampleReader = new SampleReader(output); sampleReader = new SampleReader(output);
idGenerator.generateNewId(); seiReader.createTracks(extractorOutput, idGenerator);
seiReader = new SeiReader(extractorOutput.track(idGenerator.getTrackId()),
idGenerator.getFormatId());
} }
@Override @Override
......
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
package com.google.android.exoplayer2.extractor.ts; package com.google.android.exoplayer2.extractor.ts;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.ExtractorOutput;
import com.google.android.exoplayer2.extractor.TrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.extractor.ts.TsPayloadReader.TrackIdGenerator;
import com.google.android.exoplayer2.text.cea.CeaUtil; import com.google.android.exoplayer2.text.cea.CeaUtil;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
...@@ -26,12 +28,13 @@ import com.google.android.exoplayer2.util.ParsableByteArray; ...@@ -26,12 +28,13 @@ import com.google.android.exoplayer2.util.ParsableByteArray;
*/ */
/* package */ final class SeiReader { /* package */ final class SeiReader {
private final TrackOutput output; private TrackOutput output;
public SeiReader(TrackOutput output, String formatId) { public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGenerator) {
this.output = output; idGenerator.generateNewId();
output.format(Format.createTextSampleFormat(formatId, MimeTypes.APPLICATION_CEA608, null, output = extractorOutput.track(idGenerator.getTrackId());
Format.NO_VALUE, 0, null, null)); output.format(Format.createTextSampleFormat(idGenerator.getFormatId(),
MimeTypes.APPLICATION_CEA608, null, Format.NO_VALUE, 0, null, null));
} }
public void consume(long pesTimeUs, ParsableByteArray seiBuffer) { public void consume(long pesTimeUs, ParsableByteArray seiBuffer) {
......
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