mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Add default
method durationUs(long)
in TrackOutput
The method allows extractors to set track duration when available. The `default` implementation does nothing, allowing implementers of `TrackOutput` to override it if they need to handle track duration. Implemented it in `FakeExtractor` to print track duration in dump files. PiperOrigin-RevId: 688110288
This commit is contained in:
parent
457bc55a4d
commit
847c1252e2
@ -36,6 +36,11 @@ public class ForwardingTrackOutput implements TrackOutput {
|
||||
this.trackOutput = trackOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void durationUs(long durationUs) {
|
||||
trackOutput.durationUs(durationUs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void format(Format format) {
|
||||
trackOutput.format(format);
|
||||
|
@ -146,6 +146,13 @@ public interface TrackOutput {
|
||||
*/
|
||||
int SAMPLE_DATA_PART_SUPPLEMENTAL = 2;
|
||||
|
||||
/**
|
||||
* Called to set the duration of the track in microseconds.
|
||||
*
|
||||
* @param durationUs The duration of the track in microseconds.
|
||||
*/
|
||||
default void durationUs(long durationUs) {}
|
||||
|
||||
/**
|
||||
* Called when the {@link Format} of the track has been extracted from the stream.
|
||||
*
|
||||
|
@ -54,6 +54,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
||||
private byte[] sampleData;
|
||||
private int formatCount;
|
||||
private boolean receivedSampleInFormat;
|
||||
private long durationUs;
|
||||
|
||||
@Nullable public Format lastFormat;
|
||||
|
||||
@ -64,6 +65,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
||||
sampleData = Util.EMPTY_BYTE_ARRAY;
|
||||
formatCount = 0;
|
||||
receivedSampleInFormat = true;
|
||||
durationUs = C.TIME_UNSET;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
@ -74,6 +76,11 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
||||
receivedSampleInFormat = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void durationUs(long durationUs) {
|
||||
this.durationUs = durationUs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void format(Format format) {
|
||||
if (!deduplicateConsecutiveFormats) {
|
||||
@ -188,6 +195,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
||||
public void dump(Dumper dumper) {
|
||||
dumper.add("total output bytes", sampleData.length);
|
||||
dumper.add("sample count", sampleInfos.size());
|
||||
dumper.addIfNonDefault("track duration", durationUs, C.TIME_UNSET);
|
||||
if (dumpables.isEmpty() && lastFormat != null) {
|
||||
new DumpableFormat(lastFormat, 0).dump(dumper);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user