Set MediaFormat for VTT chunks + cleanup.

ChunkSampleSource had a null check solely for the VTT case,
where DashChunkSource wasn't setting a MediaFormat on VTT
chunks. It's trivial to do so, and is more consistent, so I've
done that and removed the null check. Also done some small
tidying.
This commit is contained in:
Oliver Woodman 2015-06-05 18:24:22 +01:00
parent 01affbb93e
commit 1732aa761c
9 changed files with 25 additions and 36 deletions

View File

@ -15,7 +15,6 @@
*/ */
package com.google.android.exoplayer; package com.google.android.exoplayer;
import com.google.android.exoplayer.util.MimeTypes;
import com.google.android.exoplayer.util.Util; import com.google.android.exoplayer.util.Util;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -94,20 +93,8 @@ public class MediaFormat {
channelCount, sampleRate, initializationData); channelCount, sampleRate, initializationData);
} }
public static MediaFormat createId3Format() { public static MediaFormat createTextFormat(String mimeType) {
return createFormatForMimeType(MimeTypes.APPLICATION_ID3); return createFormatForMimeType(mimeType);
}
public static MediaFormat createEia608Format() {
return createFormatForMimeType(MimeTypes.APPLICATION_EIA608);
}
public static MediaFormat createTtmlFormat() {
return createFormatForMimeType(MimeTypes.APPLICATION_TTML);
}
public static MediaFormat createTx3GFormat() {
return createFormatForMimeType(MimeTypes.APPLICATION_TX3G);
} }
public static MediaFormat createFormatForMimeType(String mimeType) { public static MediaFormat createFormatForMimeType(String mimeType) {

View File

@ -33,7 +33,7 @@ public abstract class BaseMediaChunk extends MediaChunk {
* obtain the chunk's media format and drm initialization data. If false, these methods are only * obtain the chunk's media format and drm initialization data. If false, these methods are only
* guaranteed to return correct data after the first sample data has been output from the chunk. * guaranteed to return correct data after the first sample data has been output from the chunk.
*/ */
public final boolean isFormatFinal; public final boolean isMediaFormatFinal;
private DefaultTrackOutput output; private DefaultTrackOutput output;
private int firstSampleIndex; private int firstSampleIndex;
@ -47,16 +47,16 @@ public abstract class BaseMediaChunk extends MediaChunk {
* @param endTimeUs The end time of the media contained by the chunk, in microseconds. * @param endTimeUs The end time of the media contained by the chunk, in microseconds.
* @param chunkIndex The index of the chunk. * @param chunkIndex The index of the chunk.
* @param isLastChunk True if this is the last chunk in the media. False otherwise. * @param isLastChunk True if this is the last chunk in the media. False otherwise.
* @param isFormatFinal True if {@link #getMediaFormat()} and {@link #getDrmInitData()} can be * @param isMediaFormatFinal True if {@link #getMediaFormat()} and {@link #getDrmInitData()} can
* called at any time to obtain the media format and drm initialization data. False if these * be called at any time to obtain the media format and drm initialization data. False if
* methods are only guaranteed to return correct data after the first sample data has been * these methods are only guaranteed to return correct data after the first sample data has
* output from the chunk. * been output from the chunk.
*/ */
public BaseMediaChunk(DataSource dataSource, DataSpec dataSpec, int trigger, Format format, public BaseMediaChunk(DataSource dataSource, DataSpec dataSpec, int trigger, Format format,
long startTimeUs, long endTimeUs, int chunkIndex, boolean isLastChunk, long startTimeUs, long endTimeUs, int chunkIndex, boolean isLastChunk,
boolean isFormatFinal) { boolean isMediaFormatFinal) {
super(dataSource, dataSpec, trigger, format, startTimeUs, endTimeUs, chunkIndex, isLastChunk); super(dataSource, dataSpec, trigger, format, startTimeUs, endTimeUs, chunkIndex, isLastChunk);
this.isFormatFinal = isFormatFinal; this.isMediaFormatFinal = isMediaFormatFinal;
} }
/** /**
@ -81,7 +81,7 @@ public abstract class BaseMediaChunk extends MediaChunk {
/** /**
* Gets the {@link MediaFormat} corresponding to the chunk. * Gets the {@link MediaFormat} corresponding to the chunk.
* <p> * <p>
* See {@link #isFormatFinal} for information about when this method is guaranteed to return * See {@link #isMediaFormatFinal} for information about when this method is guaranteed to return
* correct data. * correct data.
* *
* @return The {@link MediaFormat} corresponding to this chunk. * @return The {@link MediaFormat} corresponding to this chunk.
@ -91,7 +91,7 @@ public abstract class BaseMediaChunk extends MediaChunk {
/** /**
* Gets the {@link DrmInitData} corresponding to the chunk. * Gets the {@link DrmInitData} corresponding to the chunk.
* <p> * <p>
* See {@link #isFormatFinal} for information about when this method is guaranteed to return * See {@link #isMediaFormatFinal} for information about when this method is guaranteed to return
* correct data. * correct data.
* *
* @return The {@link DrmInitData} corresponding to this chunk. * @return The {@link DrmInitData} corresponding to this chunk.

View File

@ -225,9 +225,9 @@ public class ChunkSampleSource implements SampleSource, Loader.Callback {
downstreamFormat = currentChunk.format; downstreamFormat = currentChunk.format;
} }
if (haveSamples || currentChunk.isFormatFinal) { if (haveSamples || currentChunk.isMediaFormatFinal) {
MediaFormat mediaFormat = currentChunk.getMediaFormat(); MediaFormat mediaFormat = currentChunk.getMediaFormat();
if (mediaFormat != null && !mediaFormat.equals(downstreamMediaFormat, true)) { if (!mediaFormat.equals(downstreamMediaFormat, true)) {
chunkSource.getMaxVideoDimensions(mediaFormat); chunkSource.getMaxVideoDimensions(mediaFormat);
formatHolder.format = mediaFormat; formatHolder.format = mediaFormat;
formatHolder.drmInitData = currentChunk.getDrmInitData(); formatHolder.drmInitData = currentChunk.getDrmInitData();

View File

@ -62,15 +62,15 @@ public class ContainerMediaChunk extends BaseMediaChunk implements SingleTrackOu
* known to define its own format. * known to define its own format.
* @param drmInitData The {@link DrmInitData} for the chunk. Null if the media is not drm * @param drmInitData The {@link DrmInitData} for the chunk. Null if the media is not drm
* protected. May also be null if the data is known to define its own initialization data. * protected. May also be null if the data is known to define its own initialization data.
* @param isFormatFinal True if {@code mediaFormat} and {@code drmInitData} are known to be * @param isMediaFormatFinal True if {@code mediaFormat} and {@code drmInitData} are known to be
* correct and final. False if the data may define its own format or initialization data. * correct and final. False if the data may define its own format or initialization data.
*/ */
public ContainerMediaChunk(DataSource dataSource, DataSpec dataSpec, int trigger, Format format, public ContainerMediaChunk(DataSource dataSource, DataSpec dataSpec, int trigger, Format format,
long startTimeUs, long endTimeUs, int chunkIndex, boolean isLastChunk, long sampleOffsetUs, long startTimeUs, long endTimeUs, int chunkIndex, boolean isLastChunk, long sampleOffsetUs,
ChunkExtractorWrapper extractorWrapper, MediaFormat mediaFormat, DrmInitData drmInitData, ChunkExtractorWrapper extractorWrapper, MediaFormat mediaFormat, DrmInitData drmInitData,
boolean isFormatFinal) { boolean isMediaFormatFinal) {
super(dataSource, dataSpec, trigger, format, startTimeUs, endTimeUs, chunkIndex, isLastChunk, super(dataSource, dataSpec, trigger, format, startTimeUs, endTimeUs, chunkIndex, isLastChunk,
isFormatFinal); isMediaFormatFinal);
this.extractorWrapper = extractorWrapper; this.extractorWrapper = extractorWrapper;
this.sampleOffsetUs = sampleOffsetUs; this.sampleOffsetUs = sampleOffsetUs;
this.mediaFormat = mediaFormat; this.mediaFormat = mediaFormat;

View File

@ -503,8 +503,8 @@ public class DashChunkSource implements ChunkSource {
representationHolder.vttHeaderOffsetUs = presentationTimeOffsetUs; representationHolder.vttHeaderOffsetUs = presentationTimeOffsetUs;
} }
return new SingleSampleMediaChunk(dataSource, dataSpec, Chunk.TRIGGER_INITIAL, return new SingleSampleMediaChunk(dataSource, dataSpec, Chunk.TRIGGER_INITIAL,
representation.format, startTimeUs, endTimeUs, absoluteSegmentNum, isLastSegment, null, representation.format, startTimeUs, endTimeUs, absoluteSegmentNum, isLastSegment,
null, representationHolder.vttHeader); MediaFormat.createTextFormat(MimeTypes.TEXT_VTT), null, representationHolder.vttHeader);
} else { } else {
return new ContainerMediaChunk(dataSource, dataSpec, trigger, representation.format, return new ContainerMediaChunk(dataSource, dataSpec, trigger, representation.format,
startTimeUs, endTimeUs, absoluteSegmentNum, isLastSegment, 0, startTimeUs, endTimeUs, absoluteSegmentNum, isLastSegment, 0,

View File

@ -339,9 +339,9 @@ import java.util.List;
parseAudioSampleEntry(stsd, childAtomType, childStartPosition, childAtomSize, durationUs, parseAudioSampleEntry(stsd, childAtomType, childStartPosition, childAtomSize, durationUs,
holder, i); holder, i);
} else if (childAtomType == Atom.TYPE_TTML) { } else if (childAtomType == Atom.TYPE_TTML) {
holder.mediaFormat = MediaFormat.createTtmlFormat(); holder.mediaFormat = MediaFormat.createTextFormat(MimeTypes.APPLICATION_TTML);
} else if (childAtomType == Atom.TYPE_tx3g) { } else if (childAtomType == Atom.TYPE_tx3g) {
holder.mediaFormat = MediaFormat.createTx3GFormat(); holder.mediaFormat = MediaFormat.createTextFormat(MimeTypes.APPLICATION_TX3G);
} }
stsd.setPosition(childStartPosition + childAtomSize); stsd.setPosition(childStartPosition + childAtomSize);
} }

View File

@ -18,6 +18,7 @@ package com.google.android.exoplayer.extractor.ts;
import com.google.android.exoplayer.C; import com.google.android.exoplayer.C;
import com.google.android.exoplayer.MediaFormat; import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.extractor.TrackOutput; import com.google.android.exoplayer.extractor.TrackOutput;
import com.google.android.exoplayer.util.MimeTypes;
import com.google.android.exoplayer.util.ParsableByteArray; import com.google.android.exoplayer.util.ParsableByteArray;
/** /**
@ -34,7 +35,7 @@ import com.google.android.exoplayer.util.ParsableByteArray;
public Id3Reader(TrackOutput output) { public Id3Reader(TrackOutput output) {
super(output); super(output);
output.format(MediaFormat.createId3Format()); output.format(MediaFormat.createTextFormat(MimeTypes.APPLICATION_ID3));
} }
@Override @Override

View File

@ -19,6 +19,7 @@ import com.google.android.exoplayer.C;
import com.google.android.exoplayer.MediaFormat; import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.extractor.TrackOutput; import com.google.android.exoplayer.extractor.TrackOutput;
import com.google.android.exoplayer.text.eia608.Eia608Parser; import com.google.android.exoplayer.text.eia608.Eia608Parser;
import com.google.android.exoplayer.util.MimeTypes;
import com.google.android.exoplayer.util.ParsableByteArray; import com.google.android.exoplayer.util.ParsableByteArray;
/** /**
@ -31,7 +32,7 @@ import com.google.android.exoplayer.util.ParsableByteArray;
public SeiReader(TrackOutput output) { public SeiReader(TrackOutput output) {
super(output); super(output);
output.format(MediaFormat.createEia608Format()); output.format(MediaFormat.createTextFormat(MimeTypes.APPLICATION_EIA608));
} }
@Override @Override

View File

@ -395,7 +395,7 @@ public class SmoothStreamingChunkSource implements ChunkSource {
trackFormat.numChannels, trackFormat.audioSamplingRate, csd); trackFormat.numChannels, trackFormat.audioSamplingRate, csd);
return format; return format;
} else if (streamElement.type == StreamElement.TYPE_TEXT) { } else if (streamElement.type == StreamElement.TYPE_TEXT) {
return MediaFormat.createFormatForMimeType(trackFormat.mimeType); return MediaFormat.createTextFormat(trackFormat.mimeType);
} }
return null; return null;
} }