Skip to content

Commit

Permalink
Make SeiReader injectable to H26xReaders
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AquilesCanta authored and ojw28 committed Feb 15, 2017
1 parent ee3c5f8 commit 0402191
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ public TsPayloadReader createPayloadReader(int streamType, EsInfo esInfo) {
case TsExtractor.TS_STREAM_TYPE_H262:
return new PesReader(new H262Reader());
case TsExtractor.TS_STREAM_TYPE_H264:
return isSet(FLAG_IGNORE_H264_STREAM) ? null : new PesReader(
new H264Reader(isSet(FLAG_ALLOW_NON_IDR_KEYFRAMES), isSet(FLAG_DETECT_ACCESS_UNITS)));
return isSet(FLAG_IGNORE_H264_STREAM) ? null
: new PesReader(new H264Reader(new SeiReader(), isSet(FLAG_ALLOW_NON_IDR_KEYFRAMES),
isSet(FLAG_DETECT_ACCESS_UNITS)));
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:
return isSet(FLAG_IGNORE_SPLICE_INFO_STREAM)
? null : new SectionReader(new SpliceInfoSectionReader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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 final SeiReader seiReader;
private final boolean allowNonIdrKeyframes;
private final boolean detectAccessUnits;
private final NalUnitTargetBuffer sps;
Expand All @@ -49,7 +50,6 @@

private String formatId;
private TrackOutput output;
private SeiReader seiReader;
private SampleReader sampleReader;

// State that should not be reset on seek.
Expand All @@ -62,15 +62,17 @@
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
* synchronization samples (key-frames).
* @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).
*/
public H264Reader(boolean allowNonIdrKeyframes, boolean detectAccessUnits) {
prefixFlags = new boolean[3];
public H264Reader(SeiReader seiReader, boolean allowNonIdrKeyframes, boolean detectAccessUnits) {
this.seiReader = seiReader;
this.allowNonIdrKeyframes = allowNonIdrKeyframes;
this.detectAccessUnits = detectAccessUnits;
prefixFlags = new boolean[3];
sps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SPS, 128);
pps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_PPS, 128);
sei = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SEI, 128);
Expand All @@ -93,9 +95,7 @@ public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGen
formatId = idGenerator.getFormatId();
output = extractorOutput.track(idGenerator.getTrackId());
sampleReader = new SampleReader(output, allowNonIdrKeyframes, detectAccessUnits);
idGenerator.generateNewId();
seiReader = new SeiReader(extractorOutput.track(idGenerator.getTrackId()),
idGenerator.getFormatId());
seiReader.createTracks(extractorOutput, idGenerator);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
private static final int PREFIX_SEI_NUT = 39;
private static final int SUFFIX_SEI_NUT = 40;

private final SeiReader seiReader;

private String formatId;
private TrackOutput output;
private SampleReader sampleReader;
private SeiReader seiReader;

// State that should not be reset on seek.
private boolean hasOutputFormat;
Expand All @@ -67,7 +68,11 @@
// Scratch variables to avoid allocations.
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];
vps = new NalUnitTargetBuffer(VPS_NUT, 128);
sps = new NalUnitTargetBuffer(SPS_NUT, 128);
Expand Down Expand Up @@ -95,9 +100,7 @@ public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGen
formatId = idGenerator.getFormatId();
output = extractorOutput.track(idGenerator.getTrackId());
sampleReader = new SampleReader(output);
idGenerator.generateNewId();
seiReader = new SeiReader(extractorOutput.track(idGenerator.getTrackId()),
idGenerator.getFormatId());
seiReader.createTracks(extractorOutput, idGenerator);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package com.google.android.exoplayer2.extractor.ts;

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.ts.TsPayloadReader.TrackIdGenerator;
import com.google.android.exoplayer2.text.cea.CeaUtil;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.ParsableByteArray;
Expand All @@ -26,12 +28,13 @@
*/
/* package */ final class SeiReader {

private final TrackOutput output;
private TrackOutput output;

public SeiReader(TrackOutput output, String formatId) {
this.output = output;
output.format(Format.createTextSampleFormat(formatId, MimeTypes.APPLICATION_CEA608, null,
Format.NO_VALUE, 0, null, null));
public void createTracks(ExtractorOutput extractorOutput, TrackIdGenerator idGenerator) {
idGenerator.generateNewId();
output = extractorOutput.track(idGenerator.getTrackId());
output.format(Format.createTextSampleFormat(idGenerator.getFormatId(),
MimeTypes.APPLICATION_CEA608, null, Format.NO_VALUE, 0, null, null));
}

public void consume(long pesTimeUs, ParsableByteArray seiBuffer) {
Expand Down

0 comments on commit 0402191

Please sign in to comment.