Remove TrackInfo from the SampleExtractor interface.

This commit is contained in:
Oliver Woodman 2015-03-10 19:01:11 +00:00
parent fbd0a57e5c
commit cdf19430ef
3 changed files with 43 additions and 35 deletions

View File

@ -62,9 +62,14 @@ public final class DefaultSampleSource implements SampleSource {
if (sampleExtractor.prepare()) { if (sampleExtractor.prepare()) {
prepared = true; prepared = true;
trackInfos = sampleExtractor.getTrackInfos(); int trackCount = sampleExtractor.getTrackCount();
trackStates = new int[trackInfos.length]; trackStates = new int[trackCount];
pendingDiscontinuities = new boolean[trackInfos.length]; pendingDiscontinuities = new boolean[trackCount];
trackInfos = new TrackInfo[trackCount];
for (int track = 0; track < trackCount; track++) {
String mimeType = sampleExtractor.getMediaFormat(track).mimeType;
trackInfos[track] = new TrackInfo(mimeType, sampleExtractor.getDurationUs(track));
}
} }
return prepared; return prepared;
@ -119,7 +124,8 @@ public final class DefaultSampleSource implements SampleSource {
return NOTHING_READ; return NOTHING_READ;
} }
if (trackStates[track] != TRACK_STATE_FORMAT_SENT) { if (trackStates[track] != TRACK_STATE_FORMAT_SENT) {
sampleExtractor.getTrackMediaFormat(track, formatHolder); formatHolder.format = sampleExtractor.getMediaFormat(track);
formatHolder.drmInitData = sampleExtractor.getDrmInitData(track);
trackStates[track] = TRACK_STATE_FORMAT_SENT; trackStates[track] = TRACK_STATE_FORMAT_SENT;
return FORMAT_READ; return FORMAT_READ;
} }

View File

@ -17,10 +17,8 @@ package com.google.android.exoplayer.source;
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.MediaFormatHolder;
import com.google.android.exoplayer.SampleHolder; import com.google.android.exoplayer.SampleHolder;
import com.google.android.exoplayer.SampleSource; import com.google.android.exoplayer.SampleSource;
import com.google.android.exoplayer.TrackInfo;
import com.google.android.exoplayer.TrackRenderer; import com.google.android.exoplayer.TrackRenderer;
import com.google.android.exoplayer.util.Assertions; import com.google.android.exoplayer.util.Assertions;
import com.google.android.exoplayer.util.Util; import com.google.android.exoplayer.util.Util;
@ -53,8 +51,6 @@ public final class FrameworkSampleExtractor implements SampleExtractor {
private final MediaExtractor mediaExtractor; private final MediaExtractor mediaExtractor;
private TrackInfo[] trackInfos;
/** /**
* Instantiates a new sample extractor reading from the specified {@code uri}. * Instantiates a new sample extractor reading from the specified {@code uri}.
* *
@ -106,24 +102,9 @@ public final class FrameworkSampleExtractor implements SampleExtractor {
mediaExtractor.setDataSource(fileDescriptor, fileDescriptorOffset, fileDescriptorLength); mediaExtractor.setDataSource(fileDescriptor, fileDescriptorOffset, fileDescriptorLength);
} }
int trackCount = mediaExtractor.getTrackCount();
trackInfos = new TrackInfo[trackCount];
for (int i = 0; i < trackCount; i++) {
android.media.MediaFormat format = mediaExtractor.getTrackFormat(i);
long durationUs = format.containsKey(android.media.MediaFormat.KEY_DURATION)
? format.getLong(android.media.MediaFormat.KEY_DURATION) : C.UNKNOWN_TIME_US;
String mime = format.getString(android.media.MediaFormat.KEY_MIME);
trackInfos[i] = new TrackInfo(mime, durationUs);
}
return true; return true;
} }
@Override
public TrackInfo[] getTrackInfos() {
return trackInfos;
}
@Override @Override
public void selectTrack(int index) { public void selectTrack(int index) {
mediaExtractor.selectTrack(index); mediaExtractor.selectTrack(index);
@ -151,10 +132,25 @@ public final class FrameworkSampleExtractor implements SampleExtractor {
} }
@Override @Override
public void getTrackMediaFormat(int track, MediaFormatHolder mediaFormatHolder) { public int getTrackCount() {
mediaFormatHolder.format = return mediaExtractor.getTrackCount();
MediaFormat.createFromFrameworkMediaFormatV16(mediaExtractor.getTrackFormat(track)); }
mediaFormatHolder.drmInitData = Util.SDK_INT >= 18 ? getPsshInfoV18() : null;
@Override
public MediaFormat getMediaFormat(int track) {
return MediaFormat.createFromFrameworkMediaFormatV16(mediaExtractor.getTrackFormat(track));
}
@Override
public Map<UUID, byte[]> getDrmInitData(int track) {
return Util.SDK_INT >= 18 ? getPsshInfoV18() : null;
}
@Override
public long getDurationUs(int track) {
android.media.MediaFormat format = mediaExtractor.getTrackFormat(track);
return format.containsKey(android.media.MediaFormat.KEY_DURATION)
? format.getLong(android.media.MediaFormat.KEY_DURATION) : C.UNKNOWN_TIME_US;
} }
@Override @Override

View File

@ -16,19 +16,19 @@
package com.google.android.exoplayer.source; package com.google.android.exoplayer.source;
import com.google.android.exoplayer.MediaFormat; import com.google.android.exoplayer.MediaFormat;
import com.google.android.exoplayer.MediaFormatHolder;
import com.google.android.exoplayer.SampleHolder; import com.google.android.exoplayer.SampleHolder;
import com.google.android.exoplayer.SampleSource; import com.google.android.exoplayer.SampleSource;
import com.google.android.exoplayer.TrackInfo;
import com.google.android.exoplayer.TrackRenderer; import com.google.android.exoplayer.TrackRenderer;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
import java.util.UUID;
/** /**
* Extractor for reading track metadata and samples stored in tracks. * Extractor for reading track metadata and samples stored in tracks.
* *
* <p>Call {@link #prepare} until it returns {@code true}, then access track metadata via * <p>Call {@link #prepare} until it returns {@code true}, then access track metadata via
* {@link #getTrackInfos} and {@link #getTrackMediaFormat}. * {@link #getMediaFormat}.
* *
* <p>Pass indices of tracks to read from to {@link #selectTrack}. A track can later be deselected * <p>Pass indices of tracks to read from to {@link #selectTrack}. A track can later be deselected
* by calling {@link #deselectTrack}. It is safe to select/deselect tracks after reading sample * by calling {@link #deselectTrack}. It is safe to select/deselect tracks after reading sample
@ -46,9 +46,6 @@ public interface SampleExtractor {
*/ */
boolean prepare() throws IOException; boolean prepare() throws IOException;
/** Returns track information about all tracks that can be selected. */
TrackInfo[] getTrackInfos();
/** Selects the track at {@code index} for reading sample data. */ /** Selects the track at {@code index} for reading sample data. */
void selectTrack(int index); void selectTrack(int index);
@ -75,8 +72,17 @@ public interface SampleExtractor {
*/ */
void seekTo(long positionUs); void seekTo(long positionUs);
/** Stores the {@link MediaFormat} of {@code track}. */ /** Returns the number of tracks, if {@link #prepare} has returned {@code true}. */
void getTrackMediaFormat(int track, MediaFormatHolder mediaFormatHolder); int getTrackCount();
/** Returns the {@link MediaFormat} of {@code track}. */
MediaFormat getMediaFormat(int track);
/** Returns the DRM initialization data for {@code track}. */
Map<UUID, byte[]> getDrmInitData(int track);
/** Returns the duration of {@code track} in microseconds. */
long getDurationUs(int track);
/** /**
* Reads the next sample in the track at index {@code track} into {@code sampleHolder}, returning * Reads the next sample in the track at index {@code track} into {@code sampleHolder}, returning