mirror of
https://github.com/androidx/media.git
synced 2025-05-17 04:29:55 +08:00
Remove TrackInfo from the SampleExtractor interface.
This commit is contained in:
parent
fbd0a57e5c
commit
cdf19430ef
@ -62,9 +62,14 @@ public final class DefaultSampleSource implements SampleSource {
|
||||
|
||||
if (sampleExtractor.prepare()) {
|
||||
prepared = true;
|
||||
trackInfos = sampleExtractor.getTrackInfos();
|
||||
trackStates = new int[trackInfos.length];
|
||||
pendingDiscontinuities = new boolean[trackInfos.length];
|
||||
int trackCount = sampleExtractor.getTrackCount();
|
||||
trackStates = new int[trackCount];
|
||||
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;
|
||||
@ -119,7 +124,8 @@ public final class DefaultSampleSource implements SampleSource {
|
||||
return NOTHING_READ;
|
||||
}
|
||||
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;
|
||||
return FORMAT_READ;
|
||||
}
|
||||
|
@ -17,10 +17,8 @@ package com.google.android.exoplayer.source;
|
||||
|
||||
import com.google.android.exoplayer.C;
|
||||
import com.google.android.exoplayer.MediaFormat;
|
||||
import com.google.android.exoplayer.MediaFormatHolder;
|
||||
import com.google.android.exoplayer.SampleHolder;
|
||||
import com.google.android.exoplayer.SampleSource;
|
||||
import com.google.android.exoplayer.TrackInfo;
|
||||
import com.google.android.exoplayer.TrackRenderer;
|
||||
import com.google.android.exoplayer.util.Assertions;
|
||||
import com.google.android.exoplayer.util.Util;
|
||||
@ -53,8 +51,6 @@ public final class FrameworkSampleExtractor implements SampleExtractor {
|
||||
|
||||
private final MediaExtractor mediaExtractor;
|
||||
|
||||
private TrackInfo[] trackInfos;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TrackInfo[] getTrackInfos() {
|
||||
return trackInfos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectTrack(int index) {
|
||||
mediaExtractor.selectTrack(index);
|
||||
@ -151,10 +132,25 @@ public final class FrameworkSampleExtractor implements SampleExtractor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getTrackMediaFormat(int track, MediaFormatHolder mediaFormatHolder) {
|
||||
mediaFormatHolder.format =
|
||||
MediaFormat.createFromFrameworkMediaFormatV16(mediaExtractor.getTrackFormat(track));
|
||||
mediaFormatHolder.drmInitData = Util.SDK_INT >= 18 ? getPsshInfoV18() : null;
|
||||
public int getTrackCount() {
|
||||
return mediaExtractor.getTrackCount();
|
||||
}
|
||||
|
||||
@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
|
||||
|
@ -16,19 +16,19 @@
|
||||
package com.google.android.exoplayer.source;
|
||||
|
||||
import com.google.android.exoplayer.MediaFormat;
|
||||
import com.google.android.exoplayer.MediaFormatHolder;
|
||||
import com.google.android.exoplayer.SampleHolder;
|
||||
import com.google.android.exoplayer.SampleSource;
|
||||
import com.google.android.exoplayer.TrackInfo;
|
||||
import com.google.android.exoplayer.TrackRenderer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Extractor for reading track metadata and samples stored in tracks.
|
||||
*
|
||||
* <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
|
||||
* 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;
|
||||
|
||||
/** Returns track information about all tracks that can be selected. */
|
||||
TrackInfo[] getTrackInfos();
|
||||
|
||||
/** Selects the track at {@code index} for reading sample data. */
|
||||
void selectTrack(int index);
|
||||
|
||||
@ -75,8 +72,17 @@ public interface SampleExtractor {
|
||||
*/
|
||||
void seekTo(long positionUs);
|
||||
|
||||
/** Stores the {@link MediaFormat} of {@code track}. */
|
||||
void getTrackMediaFormat(int track, MediaFormatHolder mediaFormatHolder);
|
||||
/** Returns the number of tracks, if {@link #prepare} has returned {@code true}. */
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user