Multiple small fixes for subtitles/mp4.

1. [Cleanup] Remove unused Track types, including TYPE_TIME_CODE.
2. Add subtitle track type, which is different to the existing text type.
3. Set duration on the media formats for text and subtitle tracks. This
   was causing the player to report unknown media duration for mp4 files
   containing such tracks.
4. Make TextTrackRenderer do the right thing when not started.

Issue: #635
This commit is contained in:
Oliver Woodman 2015-07-23 13:43:48 +01:00
parent b44de0d250
commit b57b80f723
5 changed files with 26 additions and 23 deletions

View File

@ -94,11 +94,19 @@ public class MediaFormat {
} }
public static MediaFormat createTextFormat(String mimeType) { public static MediaFormat createTextFormat(String mimeType) {
return createFormatForMimeType(mimeType); return createTextFormat(mimeType, C.UNKNOWN_TIME_US);
}
public static MediaFormat createTextFormat(String mimeType, long durationUs) {
return createFormatForMimeType(mimeType, durationUs);
} }
public static MediaFormat createFormatForMimeType(String mimeType) { public static MediaFormat createFormatForMimeType(String mimeType) {
return new MediaFormat(mimeType, NO_VALUE, C.UNKNOWN_TIME_US, NO_VALUE, NO_VALUE, NO_VALUE, return createFormatForMimeType(mimeType, C.UNKNOWN_TIME_US);
}
public static MediaFormat createFormatForMimeType(String mimeType, long durationUs) {
return new MediaFormat(mimeType, NO_VALUE, durationUs, NO_VALUE, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, null); NO_VALUE, NO_VALUE, null);
} }

View File

@ -45,7 +45,7 @@ import java.util.List;
Atom.ContainerAtom mdia = trak.getContainerAtomOfType(Atom.TYPE_mdia); Atom.ContainerAtom mdia = trak.getContainerAtomOfType(Atom.TYPE_mdia);
int trackType = parseHdlr(mdia.getLeafAtomOfType(Atom.TYPE_hdlr).data); int trackType = parseHdlr(mdia.getLeafAtomOfType(Atom.TYPE_hdlr).data);
if (trackType != Track.TYPE_AUDIO && trackType != Track.TYPE_VIDEO if (trackType != Track.TYPE_AUDIO && trackType != Track.TYPE_VIDEO
&& trackType != Track.TYPE_TEXT && trackType != Track.TYPE_TIME_CODE) { && trackType != Track.TYPE_TEXT && trackType != Track.TYPE_SUBTITLE) {
return null; return null;
} }
@ -344,9 +344,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.createTextFormat(MimeTypes.APPLICATION_TTML); holder.mediaFormat = MediaFormat.createTextFormat(MimeTypes.APPLICATION_TTML, durationUs);
} else if (childAtomType == Atom.TYPE_tx3g) { } else if (childAtomType == Atom.TYPE_tx3g) {
holder.mediaFormat = MediaFormat.createTextFormat(MimeTypes.APPLICATION_TX3G); holder.mediaFormat = MediaFormat.createTextFormat(MimeTypes.APPLICATION_TX3G, durationUs);
} }
stsd.setPosition(childStartPosition + childAtomSize); stsd.setPosition(childStartPosition + childAtomSize);
} }

View File

@ -230,8 +230,7 @@ public final class Mp4Extractor implements Extractor, SeekMap {
} }
Track track = AtomParsers.parseTrak(atom, moov.getLeafAtomOfType(Atom.TYPE_mvhd)); Track track = AtomParsers.parseTrak(atom, moov.getLeafAtomOfType(Atom.TYPE_mvhd));
if (track == null || (track.type != Track.TYPE_AUDIO && track.type != Track.TYPE_VIDEO if (track == null) {
&& track.type != Track.TYPE_TEXT)) {
continue; continue;
} }

View File

@ -17,6 +17,7 @@ package com.google.android.exoplayer.extractor.mp4;
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.util.Util;
/** /**
* Encapsulates information describing an MP4 track. * Encapsulates information describing an MP4 track.
@ -26,27 +27,19 @@ public final class Track {
/** /**
* Type of a video track. * Type of a video track.
*/ */
public static final int TYPE_VIDEO = 0x76696465; public static final int TYPE_VIDEO = Util.getIntegerCodeForString("vide");
/** /**
* Type of an audio track. * Type of an audio track.
*/ */
public static final int TYPE_AUDIO = 0x736F756E; public static final int TYPE_AUDIO = Util.getIntegerCodeForString("soun");
/** /**
* Type of a text track. * Type of a text track.
*/ */
public static final int TYPE_TEXT = 0x74657874; public static final int TYPE_TEXT = Util.getIntegerCodeForString("text");
/** /**
* Type of a hint track. * Type of a subtitle track.
*/ */
public static final int TYPE_HINT = 0x68696E74; public static final int TYPE_SUBTITLE = Util.getIntegerCodeForString("sbtl");
/**
* Type of a meta track.
*/
public static final int TYPE_META = 0x6D657461;
/**
* Type of a time-code track.
*/
public static final int TYPE_TIME_CODE = 0x746D6364;
/** /**
* The track identifier. * The track identifier.
@ -54,8 +47,7 @@ public final class Track {
public final int id; public final int id;
/** /**
* One of {@link #TYPE_VIDEO}, {@link #TYPE_AUDIO}, {@link #TYPE_HINT}, {@link #TYPE_META} and * One of {@link #TYPE_VIDEO}, {@link #TYPE_AUDIO}, {@link #TYPE_TEXT} and {@link #TYPE_SUBTITLE}.
* {@link #TYPE_TIME_CODE}.
*/ */
public final int type; public final int type;

View File

@ -206,6 +206,10 @@ public class TextTrackRenderer extends TrackRenderer implements Callback {
} }
} }
if (getState() != TrackRenderer.STATE_STARTED) {
return;
}
boolean textRendererNeedsUpdate = false; boolean textRendererNeedsUpdate = false;
long subtitleNextEventTimeUs = Long.MAX_VALUE; long subtitleNextEventTimeUs = Long.MAX_VALUE;
if (subtitle != null) { if (subtitle != null) {
@ -228,7 +232,7 @@ public class TextTrackRenderer extends TrackRenderer implements Callback {
textRendererNeedsUpdate = true; textRendererNeedsUpdate = true;
} }
if (textRendererNeedsUpdate && getState() == TrackRenderer.STATE_STARTED) { if (textRendererNeedsUpdate) {
// textRendererNeedsUpdate is set and we're playing. Update the renderer. // textRendererNeedsUpdate is set and we're playing. Update the renderer.
updateTextRenderer(subtitle.getCues(positionUs)); updateTextRenderer(subtitle.getCues(positionUs));
} }