Commit 02f1efd1 by Oliver Woodman

Add bitrate to MediaFormat.

Issue: #514
parent ff201db9
...@@ -68,6 +68,7 @@ import java.net.CookieHandler; ...@@ -68,6 +68,7 @@ import java.net.CookieHandler;
import java.net.CookieManager; import java.net.CookieManager;
import java.net.CookiePolicy; import java.net.CookiePolicy;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
/** /**
...@@ -450,16 +451,21 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback, ...@@ -450,16 +451,21 @@ public class PlayerActivity extends Activity implements SurfaceHolder.Callback,
if (format.adaptive) { if (format.adaptive) {
return "auto"; return "auto";
} else if (MimeTypes.isVideo(format.mimeType)) { } else if (MimeTypes.isVideo(format.mimeType)) {
return format.width + "x" + format.height; return format.width + "x" + format.height + buildBitrateString(format);
} else if (MimeTypes.isAudio(format.mimeType)) { } else if (MimeTypes.isAudio(format.mimeType)) {
return format.channelCount + "ch, " + format.sampleRate + "Hz"; return format.channelCount + "ch, " + format.sampleRate + "Hz" + buildBitrateString(format);
} else if (MimeTypes.isText(format.mimeType) && !TextUtils.isEmpty(format.language)) { } else if (MimeTypes.isText(format.mimeType) && !TextUtils.isEmpty(format.language)) {
return format.language; return format.language + buildBitrateString(format);
} else { } else {
return "unknown"; return "unknown" + buildBitrateString(format);
} }
} }
private static String buildBitrateString(MediaFormat format) {
return format.bitrate == MediaFormat.NO_VALUE ? ""
: String.format(Locale.US, " (%.2fMbit)", format.bitrate / 1000000f);
}
private boolean onTrackItemClick(MenuItem item, int type) { private boolean onTrackItemClick(MenuItem item, int type) {
if (player == null || item.getGroupId() != MENU_GROUP_TRACKS) { if (player == null || item.getGroupId() != MENU_GROUP_TRACKS) {
return false; return false;
......
...@@ -45,17 +45,17 @@ public final class MediaFormatTest extends TestCase { ...@@ -45,17 +45,17 @@ public final class MediaFormatTest extends TestCase {
initData.add(initData2); initData.add(initData2);
testConversionToFrameworkFormatV16(MediaFormat.createVideoFormat( testConversionToFrameworkFormatV16(MediaFormat.createVideoFormat(
"video/xyz", 102400, 1000L, 1280, 720, 1, initData)); "video/xyz", 5000, 102400, 1000L, 1280, 720, 1, initData));
testConversionToFrameworkFormatV16(MediaFormat.createVideoFormat( testConversionToFrameworkFormatV16(MediaFormat.createVideoFormat(
"video/xyz", MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, 1280, 720, 1, null)); "video/xyz", 5000, MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, 1280, 720, 1, null));
testConversionToFrameworkFormatV16(MediaFormat.createAudioFormat( testConversionToFrameworkFormatV16(MediaFormat.createAudioFormat(
"audio/xyz", 128, 1000L, 5, 44100, initData)); "audio/xyz", 500, 128, 1000L, 5, 44100, initData));
testConversionToFrameworkFormatV16(MediaFormat.createAudioFormat( testConversionToFrameworkFormatV16(MediaFormat.createAudioFormat(
"audio/xyz", MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, 5, 44100, null)); "audio/xyz", 500, MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, 5, 44100, null));
testConversionToFrameworkFormatV16( testConversionToFrameworkFormatV16(
MediaFormat.createTextFormat("text/xyz", "eng", 1000L)); MediaFormat.createTextFormat("text/xyz", MediaFormat.NO_VALUE, "eng", 1000L));
testConversionToFrameworkFormatV16( testConversionToFrameworkFormatV16(
MediaFormat.createTextFormat("text/xyz", null, C.UNKNOWN_TIME_US)); MediaFormat.createTextFormat("text/xyz", MediaFormat.NO_VALUE, null, C.UNKNOWN_TIME_US));
} }
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
......
...@@ -91,7 +91,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase { ...@@ -91,7 +91,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
public void testMaxVideoDimensions() { public void testMaxVideoDimensions() {
DashChunkSource chunkSource = new DashChunkSource(generateVodMpd(), AdaptationSet.TYPE_VIDEO, DashChunkSource chunkSource = new DashChunkSource(generateVodMpd(), AdaptationSet.TYPE_VIDEO,
null, null, null); null, null, null);
MediaFormat format = MediaFormat.createVideoFormat("video/h264", 1, 1, 1, 1, 1, null); MediaFormat format = MediaFormat.createVideoFormat("video/h264", 5000, 1, 1, 1, 1, 1, null);
format = chunkSource.getWithMaxVideoDimensions(format); format = chunkSource.getWithMaxVideoDimensions(format);
assertEquals(WIDE_WIDTH, format.maxWidth); assertEquals(WIDE_WIDTH, format.maxWidth);
...@@ -121,7 +121,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase { ...@@ -121,7 +121,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
Representation.newInstance(0, 0, null, 0, WIDE_VIDEO, segmentBase2); Representation.newInstance(0, 0, null, 0, WIDE_VIDEO, segmentBase2);
DashChunkSource chunkSource = new DashChunkSource(null, null, representation1, representation2); DashChunkSource chunkSource = new DashChunkSource(null, null, representation1, representation2);
MediaFormat format = MediaFormat.createVideoFormat("video/h264", 1, 1, 1, 1, 1, null); MediaFormat format = MediaFormat.createVideoFormat("video/h264", 5000, 1, 1, 1, 1, 1, null);
format = chunkSource.getWithMaxVideoDimensions(format); format = chunkSource.getWithMaxVideoDimensions(format);
assertEquals(WIDE_WIDTH, format.maxWidth); assertEquals(WIDE_WIDTH, format.maxWidth);
......
...@@ -315,10 +315,10 @@ public final class FrameworkSampleSource implements SampleSource, SampleSourceRe ...@@ -315,10 +315,10 @@ public final class FrameworkSampleSource implements SampleSource, SampleSourceRe
} }
long durationUs = format.containsKey(android.media.MediaFormat.KEY_DURATION) long durationUs = format.containsKey(android.media.MediaFormat.KEY_DURATION)
? format.getLong(android.media.MediaFormat.KEY_DURATION) : C.UNKNOWN_TIME_US; ? format.getLong(android.media.MediaFormat.KEY_DURATION) : C.UNKNOWN_TIME_US;
MediaFormat mediaFormat = new MediaFormat(mimeType, maxInputSize, durationUs, width, height, MediaFormat mediaFormat = new MediaFormat(mimeType, MediaFormat.NO_VALUE, maxInputSize,
rotationDegrees, MediaFormat.NO_VALUE, channelCount, sampleRate, language, durationUs, width, height, rotationDegrees, MediaFormat.NO_VALUE, channelCount, sampleRate,
MediaFormat.OFFSET_SAMPLE_RELATIVE, initializationData, false, MediaFormat.NO_VALUE, language, MediaFormat.OFFSET_SAMPLE_RELATIVE, initializationData, false,
MediaFormat.NO_VALUE); MediaFormat.NO_VALUE, MediaFormat.NO_VALUE);
mediaFormat.setFrameworkFormatV16(format); mediaFormat.setFrameworkFormatV16(format);
return mediaFormat; return mediaFormat;
} }
......
...@@ -44,6 +44,10 @@ public final class MediaFormat { ...@@ -44,6 +44,10 @@ public final class MediaFormat {
*/ */
public final String mimeType; public final String mimeType;
/** /**
* The average bandwidth in bits per second, or {@link #NO_VALUE} if unknown or not applicable.
*/
public final int bitrate;
/**
* The maximum size of a buffer of data (typically one sample) in the format, or {@link #NO_VALUE} * The maximum size of a buffer of data (typically one sample) in the format, or {@link #NO_VALUE}
* if unknown or not applicable. * if unknown or not applicable.
*/ */
...@@ -130,68 +134,71 @@ public final class MediaFormat { ...@@ -130,68 +134,71 @@ public final class MediaFormat {
private int hashCode; private int hashCode;
private android.media.MediaFormat frameworkMediaFormat; private android.media.MediaFormat frameworkMediaFormat;
public static MediaFormat createVideoFormat(String mimeType, int maxInputSize, int width, public static MediaFormat createVideoFormat(String mimeType, int bitrate, int maxInputSize,
int height, List<byte[]> initializationData) { int width, int height, List<byte[]> initializationData) {
return createVideoFormat( return createVideoFormat(mimeType, bitrate, maxInputSize, C.UNKNOWN_TIME_US, width, height,
mimeType, maxInputSize, C.UNKNOWN_TIME_US, width, height, NO_VALUE, initializationData); NO_VALUE, initializationData);
} }
public static MediaFormat createVideoFormat(String mimeType, int maxInputSize, long durationUs, public static MediaFormat createVideoFormat(String mimeType, int bitrate, int maxInputSize,
int width, int height, int rotationDegrees, List<byte[]> initializationData) { long durationUs, int width, int height, int rotationDegrees,
return createVideoFormat( List<byte[]> initializationData) {
mimeType, maxInputSize, durationUs, width, height, rotationDegrees, NO_VALUE, return createVideoFormat(mimeType, bitrate, maxInputSize, durationUs, width, height,
initializationData); rotationDegrees, NO_VALUE, initializationData);
} }
public static MediaFormat createVideoFormat(String mimeType, int maxInputSize, long durationUs, public static MediaFormat createVideoFormat(String mimeType, int bitrate, int maxInputSize,
int width, int height, int rotationDegrees, float pixelWidthHeightRatio, long durationUs, int width, int height, int rotationDegrees, float pixelWidthHeightRatio,
List<byte[]> initializationData) { List<byte[]> initializationData) {
return new MediaFormat(mimeType, maxInputSize, durationUs, width, height, rotationDegrees, return new MediaFormat(mimeType, bitrate, maxInputSize, durationUs, width, height,
pixelWidthHeightRatio, NO_VALUE, NO_VALUE, null, OFFSET_SAMPLE_RELATIVE, initializationData, rotationDegrees, pixelWidthHeightRatio, NO_VALUE, NO_VALUE, null, OFFSET_SAMPLE_RELATIVE,
false, NO_VALUE, NO_VALUE); initializationData, false, NO_VALUE, NO_VALUE);
} }
public static MediaFormat createAudioFormat(String mimeType, int maxInputSize, int channelCount, public static MediaFormat createAudioFormat(String mimeType, int bitrate, int maxInputSize,
int sampleRate, List<byte[]> initializationData) { int channelCount, int sampleRate, List<byte[]> initializationData) {
return createAudioFormat(mimeType, maxInputSize, C.UNKNOWN_TIME_US, channelCount, sampleRate, return createAudioFormat(mimeType, bitrate, maxInputSize, C.UNKNOWN_TIME_US, channelCount,
initializationData); sampleRate, initializationData);
} }
public static MediaFormat createAudioFormat(String mimeType, int maxInputSize, long durationUs, public static MediaFormat createAudioFormat(String mimeType, int bitrate, int maxInputSize,
int channelCount, int sampleRate, List<byte[]> initializationData) { long durationUs, int channelCount, int sampleRate, List<byte[]> initializationData) {
return new MediaFormat(mimeType, maxInputSize, durationUs, NO_VALUE, NO_VALUE, NO_VALUE, return new MediaFormat(mimeType, bitrate, maxInputSize, durationUs, NO_VALUE, NO_VALUE,
NO_VALUE, channelCount, sampleRate, null, OFFSET_SAMPLE_RELATIVE, initializationData, NO_VALUE, NO_VALUE, channelCount, sampleRate, null, OFFSET_SAMPLE_RELATIVE,
false, NO_VALUE, NO_VALUE); initializationData, false, NO_VALUE, NO_VALUE);
} }
public static MediaFormat createTextFormat(String mimeType, String language) { public static MediaFormat createTextFormat(String mimeType, int bitrate, String language) {
return createTextFormat(mimeType, language, C.UNKNOWN_TIME_US); return createTextFormat(mimeType, bitrate, language, C.UNKNOWN_TIME_US);
} }
public static MediaFormat createTextFormat(String mimeType, String language, long durationUs) { public static MediaFormat createTextFormat(String mimeType, int bitrate, String language,
return createTextFormat(mimeType, language, durationUs, OFFSET_SAMPLE_RELATIVE); long durationUs) {
return createTextFormat(mimeType, bitrate, language, durationUs, OFFSET_SAMPLE_RELATIVE);
} }
public static MediaFormat createTextFormat(String mimeType, String language, long durationUs, public static MediaFormat createTextFormat(String mimeType, int bitrate, String language,
long subsampleOffsetUs) { long durationUs, long subsampleOffsetUs) {
return new MediaFormat(mimeType, NO_VALUE, durationUs, NO_VALUE, NO_VALUE, NO_VALUE, NO_VALUE, return new MediaFormat(mimeType, bitrate, NO_VALUE, durationUs, NO_VALUE, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, language, subsampleOffsetUs, null, false, NO_VALUE, NO_VALUE); NO_VALUE, NO_VALUE, NO_VALUE, language, subsampleOffsetUs, null, false, NO_VALUE, NO_VALUE);
} }
public static MediaFormat createFormatForMimeType(String mimeType) { public static MediaFormat createFormatForMimeType(String mimeType, int bitrate) {
return createFormatForMimeType(mimeType, C.UNKNOWN_TIME_US); return createFormatForMimeType(mimeType, bitrate, C.UNKNOWN_TIME_US);
} }
public static MediaFormat createFormatForMimeType(String mimeType, long durationUs) { public static MediaFormat createFormatForMimeType(String mimeType, int bitrate, long durationUs) {
return new MediaFormat(mimeType, NO_VALUE, durationUs, NO_VALUE, NO_VALUE, NO_VALUE, NO_VALUE, return new MediaFormat(mimeType, bitrate, NO_VALUE, durationUs, NO_VALUE, NO_VALUE, NO_VALUE,
NO_VALUE, NO_VALUE, null, OFFSET_SAMPLE_RELATIVE, null, false, NO_VALUE, NO_VALUE); NO_VALUE, NO_VALUE, NO_VALUE, null, OFFSET_SAMPLE_RELATIVE, null, false, NO_VALUE,
NO_VALUE);
} }
/* package */ MediaFormat(String mimeType, int maxInputSize, long durationUs, int width, /* package */ MediaFormat(String mimeType, int bitrate, int maxInputSize, long durationUs,
int height, int rotationDegrees, float pixelWidthHeightRatio, int channelCount, int width, int height, int rotationDegrees, float pixelWidthHeightRatio, int channelCount,
int sampleRate, String language, long subsampleOffsetUs, List<byte[]> initializationData, int sampleRate, String language, long subsampleOffsetUs, List<byte[]> initializationData,
boolean adaptive, int maxWidth, int maxHeight) { boolean adaptive, int maxWidth, int maxHeight) {
this.mimeType = Assertions.checkNotEmpty(mimeType); this.mimeType = Assertions.checkNotEmpty(mimeType);
this.bitrate = bitrate;
this.maxInputSize = maxInputSize; this.maxInputSize = maxInputSize;
this.durationUs = durationUs; this.durationUs = durationUs;
this.width = width; this.width = width;
...@@ -210,27 +217,27 @@ public final class MediaFormat { ...@@ -210,27 +217,27 @@ public final class MediaFormat {
} }
public MediaFormat copyWithMaxVideoDimensions(int maxWidth, int maxHeight) { public MediaFormat copyWithMaxVideoDimensions(int maxWidth, int maxHeight) {
return new MediaFormat(mimeType, maxInputSize, durationUs, width, height, rotationDegrees, return new MediaFormat(mimeType, bitrate, maxInputSize, durationUs, width, height,
pixelWidthHeightRatio, channelCount, sampleRate, language, subsampleOffsetUs, rotationDegrees, pixelWidthHeightRatio, channelCount, sampleRate, language,
initializationData, adaptive, maxWidth, maxHeight); subsampleOffsetUs, initializationData, adaptive, maxWidth, maxHeight);
} }
public MediaFormat copyWithSubsampleOffsetUs(long subsampleOffsetUs) { public MediaFormat copyWithSubsampleOffsetUs(long subsampleOffsetUs) {
return new MediaFormat(mimeType, maxInputSize, durationUs, width, height, rotationDegrees, return new MediaFormat(mimeType, bitrate, maxInputSize, durationUs, width, height,
pixelWidthHeightRatio, channelCount, sampleRate, language, subsampleOffsetUs, rotationDegrees, pixelWidthHeightRatio, channelCount, sampleRate, language,
initializationData, adaptive, maxWidth, maxHeight); subsampleOffsetUs, initializationData, adaptive, maxWidth, maxHeight);
} }
public MediaFormat copyWithDurationUs(long durationUs) { public MediaFormat copyWithDurationUs(long durationUs) {
return new MediaFormat(mimeType, maxInputSize, durationUs, width, height, rotationDegrees, return new MediaFormat(mimeType, bitrate, maxInputSize, durationUs, width, height,
pixelWidthHeightRatio, channelCount, sampleRate, language, subsampleOffsetUs, rotationDegrees, pixelWidthHeightRatio, channelCount, sampleRate, language,
initializationData, adaptive, maxWidth, maxHeight); subsampleOffsetUs, initializationData, adaptive, maxWidth, maxHeight);
} }
public MediaFormat copyWithAdaptive(boolean adaptive) { public MediaFormat copyAsAdaptive() {
return new MediaFormat(mimeType, maxInputSize, durationUs, width, height, rotationDegrees, return new MediaFormat(mimeType, NO_VALUE, maxInputSize, durationUs, width, height,
pixelWidthHeightRatio, channelCount, sampleRate, language, subsampleOffsetUs, rotationDegrees, pixelWidthHeightRatio, channelCount, sampleRate, language,
initializationData, adaptive, maxWidth, maxHeight); subsampleOffsetUs, initializationData, true, maxWidth, maxHeight);
} }
/** /**
...@@ -276,10 +283,10 @@ public final class MediaFormat { ...@@ -276,10 +283,10 @@ public final class MediaFormat {
@Override @Override
public String toString() { public String toString() {
return "MediaFormat(" + mimeType + ", " + maxInputSize + ", " + width + ", " + height + ", " return "MediaFormat(" + mimeType + ", " + bitrate + ", " + maxInputSize + ", " + width + ", "
+ rotationDegrees + ", " + pixelWidthHeightRatio + ", " + channelCount + ", " + sampleRate + height + ", " + rotationDegrees + ", " + pixelWidthHeightRatio + ", " + channelCount
+ ", " + language + ", " + durationUs + ", " + adaptive + ", " + maxWidth + ", " + maxHeight + ", " + sampleRate + ", " + language + ", " + durationUs + ", " + adaptive + ", "
+ ")"; + maxWidth + ", " + maxHeight + ")";
} }
@Override @Override
...@@ -287,6 +294,7 @@ public final class MediaFormat { ...@@ -287,6 +294,7 @@ public final class MediaFormat {
if (hashCode == 0) { if (hashCode == 0) {
int result = 17; int result = 17;
result = 31 * result + (mimeType == null ? 0 : mimeType.hashCode()); result = 31 * result + (mimeType == null ? 0 : mimeType.hashCode());
result = 31 * result + bitrate;
result = 31 * result + maxInputSize; result = 31 * result + maxInputSize;
result = 31 * result + width; result = 31 * result + width;
result = 31 * result + height; result = 31 * result + height;
...@@ -329,8 +337,9 @@ public final class MediaFormat { ...@@ -329,8 +337,9 @@ public final class MediaFormat {
} }
private boolean equalsInternal(MediaFormat other, boolean ignoreMaxDimensions) { private boolean equalsInternal(MediaFormat other, boolean ignoreMaxDimensions) {
if (adaptive != other.adaptive || maxInputSize != other.maxInputSize || width != other.width if (adaptive != other.adaptive || bitrate != other.bitrate || maxInputSize != other.maxInputSize
|| height != other.height || rotationDegrees != other.rotationDegrees || width != other.width || height != other.height
|| rotationDegrees != other.rotationDegrees
|| pixelWidthHeightRatio != other.pixelWidthHeightRatio || pixelWidthHeightRatio != other.pixelWidthHeightRatio
|| (!ignoreMaxDimensions && (maxWidth != other.maxWidth || maxHeight != other.maxHeight)) || (!ignoreMaxDimensions && (maxWidth != other.maxWidth || maxHeight != other.maxHeight))
|| channelCount != other.channelCount || sampleRate != other.sampleRate || channelCount != other.channelCount || sampleRate != other.sampleRate
......
...@@ -148,7 +148,8 @@ public abstract class TrackRenderer implements ExoPlayerComponent { ...@@ -148,7 +148,8 @@ public abstract class TrackRenderer implements ExoPlayerComponent {
*/ */
// TODO: This method should be abstract. This implementation is provided as an interim step only. // TODO: This method should be abstract. This implementation is provided as an interim step only.
protected MediaFormat getFormat(int track) { protected MediaFormat getFormat(int track) {
return MediaFormat.createFormatForMimeType("application/octet-stream", getDurationUs()); return MediaFormat.createFormatForMimeType("application/octet-stream", MediaFormat.NO_VALUE,
getDurationUs());
} }
/** /**
......
...@@ -264,7 +264,7 @@ public class DashChunkSource implements ChunkSource { ...@@ -264,7 +264,7 @@ public class DashChunkSource implements ChunkSource {
? TrackRenderer.UNKNOWN_TIME_US : representations[0].periodDurationMs * 1000; ? TrackRenderer.UNKNOWN_TIME_US : representations[0].periodDurationMs * 1000;
// TODO: Remove this and pass proper formats instead (b/22996976). // TODO: Remove this and pass proper formats instead (b/22996976).
this.mediaFormat = MediaFormat.createFormatForMimeType(getMediaMimeType(representations[0]), this.mediaFormat = MediaFormat.createFormatForMimeType(getMediaMimeType(representations[0]),
periodDurationUs); MediaFormat.NO_VALUE, periodDurationUs);
this.formats = new Format[representations.length]; this.formats = new Format[representations.length];
this.representationHolders = new HashMap<>(); this.representationHolders = new HashMap<>();
...@@ -652,9 +652,11 @@ public class DashChunkSource implements ChunkSource { ...@@ -652,9 +652,11 @@ public class DashChunkSource implements ChunkSource {
long sampleOffsetUs = representation.periodStartMs * 1000 long sampleOffsetUs = representation.periodStartMs * 1000
- representation.presentationTimeOffsetUs; - representation.presentationTimeOffsetUs;
if (representation.format.mimeType.equals(MimeTypes.TEXT_VTT)) { if (representation.format.mimeType.equals(MimeTypes.TEXT_VTT)) {
MediaFormat mediaFormat = MediaFormat.createTextFormat(MimeTypes.TEXT_VTT,
MediaFormat.NO_VALUE, representation.format.language);
return new SingleSampleMediaChunk(dataSource, dataSpec, Chunk.TRIGGER_INITIAL, return new SingleSampleMediaChunk(dataSource, dataSpec, Chunk.TRIGGER_INITIAL,
representation.format, startTimeUs, endTimeUs, absoluteSegmentNum, isLastSegment, representation.format, startTimeUs, endTimeUs, absoluteSegmentNum, isLastSegment,
MediaFormat.createTextFormat(MimeTypes.TEXT_VTT, representation.format.language), null); mediaFormat, null);
} else { } else {
return new ContainerMediaChunk(dataSource, dataSpec, trigger, representation.format, return new ContainerMediaChunk(dataSource, dataSpec, trigger, representation.format,
startTimeUs, endTimeUs, absoluteSegmentNum, isLastSegment, sampleOffsetUs, startTimeUs, endTimeUs, absoluteSegmentNum, isLastSegment, sampleOffsetUs,
......
...@@ -312,8 +312,8 @@ public final class Mp3Extractor implements Extractor { ...@@ -312,8 +312,8 @@ public final class Mp3Extractor implements Extractor {
setupSeeker(extractorInput, headerPosition); setupSeeker(extractorInput, headerPosition);
extractorOutput.seekMap(seeker); extractorOutput.seekMap(seeker);
trackOutput.format(MediaFormat.createAudioFormat(synchronizedHeader.mimeType, trackOutput.format(MediaFormat.createAudioFormat(synchronizedHeader.mimeType,
MpegAudioHeader.MAX_FRAME_SIZE_BYTES, seeker.getDurationUs(), synchronizedHeader.channels, MediaFormat.NO_VALUE, MpegAudioHeader.MAX_FRAME_SIZE_BYTES, seeker.getDurationUs(),
synchronizedHeader.sampleRate, null)); synchronizedHeader.channels, synchronizedHeader.sampleRate, null));
} }
return headerPosition; return headerPosition;
......
...@@ -376,14 +376,14 @@ import java.util.List; ...@@ -376,14 +376,14 @@ import java.util.List;
parseAudioSampleEntry(stsd, childAtomType, childStartPosition, childAtomSize, durationUs, parseAudioSampleEntry(stsd, childAtomType, childStartPosition, childAtomSize, durationUs,
out, i); out, i);
} else if (childAtomType == Atom.TYPE_TTML) { } else if (childAtomType == Atom.TYPE_TTML) {
out.mediaFormat = MediaFormat.createTextFormat(MimeTypes.APPLICATION_TTML, language, out.mediaFormat = MediaFormat.createTextFormat(MimeTypes.APPLICATION_TTML,
durationUs); MediaFormat.NO_VALUE, language, durationUs);
} else if (childAtomType == Atom.TYPE_tx3g) { } else if (childAtomType == Atom.TYPE_tx3g) {
out.mediaFormat = MediaFormat.createTextFormat(MimeTypes.APPLICATION_TX3G, language, out.mediaFormat = MediaFormat.createTextFormat(MimeTypes.APPLICATION_TX3G,
durationUs); MediaFormat.NO_VALUE, language, durationUs);
} else if (childAtomType == Atom.TYPE_stpp) { } else if (childAtomType == Atom.TYPE_stpp) {
out.mediaFormat = MediaFormat.createTextFormat(MimeTypes.APPLICATION_TTML, language, out.mediaFormat = MediaFormat.createTextFormat(MimeTypes.APPLICATION_TTML,
durationUs, 0 /* subsample timing is absolute */); MediaFormat.NO_VALUE, language, durationUs, 0 /* subsample timing is absolute */);
} }
stsd.setPosition(childStartPosition + childAtomSize); stsd.setPosition(childStartPosition + childAtomSize);
} }
...@@ -453,8 +453,9 @@ import java.util.List; ...@@ -453,8 +453,9 @@ import java.util.List;
return; return;
} }
out.mediaFormat = MediaFormat.createVideoFormat(mimeType, MediaFormat.NO_VALUE, durationUs, out.mediaFormat = MediaFormat.createVideoFormat(mimeType, MediaFormat.NO_VALUE,
width, height, rotationDegrees, pixelWidthHeightRatio, initializationData); MediaFormat.NO_VALUE, durationUs, width, height, rotationDegrees, pixelWidthHeightRatio,
initializationData);
} }
private static AvcCData parseAvcCFromParent(ParsableByteArray parent, int position) { private static AvcCData parseAvcCFromParent(ParsableByteArray parent, int position) {
...@@ -643,8 +644,8 @@ import java.util.List; ...@@ -643,8 +644,8 @@ import java.util.List;
return; return;
} }
out.mediaFormat = MediaFormat.createAudioFormat(mimeType, sampleSize, durationUs, channelCount, out.mediaFormat = MediaFormat.createAudioFormat(mimeType, MediaFormat.NO_VALUE, sampleSize,
sampleRate, durationUs, channelCount, sampleRate,
initializationData == null ? null : Collections.singletonList(initializationData)); initializationData == null ? null : Collections.singletonList(initializationData));
} }
......
...@@ -171,7 +171,7 @@ import java.util.Collections; ...@@ -171,7 +171,7 @@ import java.util.Collections;
audioSpecificConfig); audioSpecificConfig);
MediaFormat mediaFormat = MediaFormat.createAudioFormat(MimeTypes.AUDIO_AAC, MediaFormat mediaFormat = MediaFormat.createAudioFormat(MimeTypes.AUDIO_AAC,
MediaFormat.NO_VALUE, audioParams.second, audioParams.first, MediaFormat.NO_VALUE, MediaFormat.NO_VALUE, audioParams.second, audioParams.first,
Collections.singletonList(audioSpecificConfig)); Collections.singletonList(audioSpecificConfig));
frameDurationUs = (C.MICROS_PER_SECOND * 1024L) / mediaFormat.sampleRate; frameDurationUs = (C.MICROS_PER_SECOND * 1024L) / mediaFormat.sampleRate;
output.format(mediaFormat); output.format(mediaFormat);
......
...@@ -211,7 +211,7 @@ import java.util.List; ...@@ -211,7 +211,7 @@ import java.util.List;
// Construct and output the format. // Construct and output the format.
output.format(MediaFormat.createVideoFormat(MimeTypes.VIDEO_H264, MediaFormat.NO_VALUE, output.format(MediaFormat.createVideoFormat(MimeTypes.VIDEO_H264, MediaFormat.NO_VALUE,
C.UNKNOWN_TIME_US, parsedSpsData.width, parsedSpsData.height, 0, MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, parsedSpsData.width, parsedSpsData.height, 0,
parsedSpsData.pixelWidthAspectRatio, initializationData)); parsedSpsData.pixelWidthAspectRatio, initializationData));
hasOutputFormat = true; hasOutputFormat = true;
} }
......
...@@ -295,8 +295,8 @@ import java.util.Collections; ...@@ -295,8 +295,8 @@ import java.util.Collections;
} }
output.format(MediaFormat.createVideoFormat(MimeTypes.VIDEO_H265, MediaFormat.NO_VALUE, output.format(MediaFormat.createVideoFormat(MimeTypes.VIDEO_H265, MediaFormat.NO_VALUE,
C.UNKNOWN_TIME_US, picWidthInLumaSamples, picHeightInLumaSamples, 0, pixelWidthHeightRatio, MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, picWidthInLumaSamples, picHeightInLumaSamples, 0,
Collections.singletonList(csd))); pixelWidthHeightRatio, Collections.singletonList(csd)));
hasOutputFormat = true; hasOutputFormat = true;
} }
......
...@@ -35,7 +35,8 @@ import com.google.android.exoplayer.util.ParsableByteArray; ...@@ -35,7 +35,8 @@ import com.google.android.exoplayer.util.ParsableByteArray;
public Id3Reader(TrackOutput output) { public Id3Reader(TrackOutput output) {
super(output); super(output);
output.format(MediaFormat.createFormatForMimeType(MimeTypes.APPLICATION_ID3)); output.format(MediaFormat.createFormatForMimeType(MimeTypes.APPLICATION_ID3,
MediaFormat.NO_VALUE));
} }
@Override @Override
......
...@@ -161,8 +161,8 @@ import com.google.android.exoplayer.util.ParsableByteArray; ...@@ -161,8 +161,8 @@ import com.google.android.exoplayer.util.ParsableByteArray;
if (!hasOutputFormat) { if (!hasOutputFormat) {
frameDurationUs = (C.MICROS_PER_SECOND * header.samplesPerFrame) / header.sampleRate; frameDurationUs = (C.MICROS_PER_SECOND * header.samplesPerFrame) / header.sampleRate;
MediaFormat mediaFormat = MediaFormat.createAudioFormat(header.mimeType, MediaFormat mediaFormat = MediaFormat.createAudioFormat(header.mimeType,
MpegAudioHeader.MAX_FRAME_SIZE_BYTES, C.UNKNOWN_TIME_US, header.channels, MediaFormat.NO_VALUE, MpegAudioHeader.MAX_FRAME_SIZE_BYTES, C.UNKNOWN_TIME_US,
header.sampleRate, null); header.channels, header.sampleRate, null);
output.format(mediaFormat); output.format(mediaFormat);
hasOutputFormat = true; hasOutputFormat = true;
} }
......
...@@ -32,7 +32,8 @@ import com.google.android.exoplayer.util.ParsableByteArray; ...@@ -32,7 +32,8 @@ import com.google.android.exoplayer.util.ParsableByteArray;
public SeiReader(TrackOutput output) { public SeiReader(TrackOutput output) {
super(output); super(output);
output.format(MediaFormat.createTextFormat(MimeTypes.APPLICATION_EIA608, null)); output.format(MediaFormat.createTextFormat(MimeTypes.APPLICATION_EIA608, MediaFormat.NO_VALUE,
null));
} }
@Override @Override
......
...@@ -1123,11 +1123,11 @@ public final class WebmExtractor implements Extractor { ...@@ -1123,11 +1123,11 @@ public final class WebmExtractor implements Extractor {
} }
if (MimeTypes.isAudio(mimeType)) { if (MimeTypes.isAudio(mimeType)) {
return MediaFormat.createAudioFormat(mimeType, maxInputSize, durationUs, channelCount, return MediaFormat.createAudioFormat(mimeType, MediaFormat.NO_VALUE, maxInputSize,
sampleRate, initializationData); durationUs, channelCount, sampleRate, initializationData);
} else if (MimeTypes.isVideo(mimeType)) { } else if (MimeTypes.isVideo(mimeType)) {
return MediaFormat.createVideoFormat(mimeType, maxInputSize, durationUs, pixelWidth, return MediaFormat.createVideoFormat(mimeType, MediaFormat.NO_VALUE, maxInputSize,
pixelHeight, 0, initializationData); durationUs, pixelWidth, pixelHeight, 0, initializationData);
} else { } else {
throw new ParserException("Unexpected MIME type."); throw new ParserException("Unexpected MIME type.");
} }
......
...@@ -374,7 +374,7 @@ public class SmoothStreamingChunkSource implements ChunkSource, ...@@ -374,7 +374,7 @@ public class SmoothStreamingChunkSource implements ChunkSource,
maxHeight = Math.max(maxHeight, mediaFormat.height); maxHeight = Math.max(maxHeight, mediaFormat.height);
} }
Arrays.sort(formats, new DecreasingBandwidthComparator()); Arrays.sort(formats, new DecreasingBandwidthComparator());
MediaFormat adaptiveMediaFormat = maxHeightMediaFormat.copyWithAdaptive(true); MediaFormat adaptiveMediaFormat = maxHeightMediaFormat.copyAsAdaptive();
tracks.add(new ExposedTrack(adaptiveMediaFormat, element, formats, maxWidth, maxHeight)); tracks.add(new ExposedTrack(adaptiveMediaFormat, element, formats, maxWidth, maxHeight));
} }
...@@ -404,8 +404,9 @@ public class SmoothStreamingChunkSource implements ChunkSource, ...@@ -404,8 +404,9 @@ public class SmoothStreamingChunkSource implements ChunkSource,
int mp4TrackType; int mp4TrackType;
switch (element.type) { switch (element.type) {
case StreamElement.TYPE_VIDEO: case StreamElement.TYPE_VIDEO:
mediaFormat = MediaFormat.createVideoFormat(format.mimeType, MediaFormat.NO_VALUE, mediaFormat = MediaFormat.createVideoFormat(format.mimeType, format.bitrate,
durationUs, format.width, format.height, 0, Arrays.asList(csdArray)); MediaFormat.NO_VALUE, durationUs, format.width, format.height, 0,
Arrays.asList(csdArray));
mp4TrackType = Track.TYPE_vide; mp4TrackType = Track.TYPE_vide;
break; break;
case StreamElement.TYPE_AUDIO: case StreamElement.TYPE_AUDIO:
...@@ -416,12 +417,13 @@ public class SmoothStreamingChunkSource implements ChunkSource, ...@@ -416,12 +417,13 @@ public class SmoothStreamingChunkSource implements ChunkSource,
csd = Collections.singletonList(CodecSpecificDataUtil.buildAacAudioSpecificConfig( csd = Collections.singletonList(CodecSpecificDataUtil.buildAacAudioSpecificConfig(
format.audioSamplingRate, format.audioChannels)); format.audioSamplingRate, format.audioChannels));
} }
mediaFormat = MediaFormat.createAudioFormat(format.mimeType, MediaFormat.NO_VALUE, mediaFormat = MediaFormat.createAudioFormat(format.mimeType, format.bitrate,
durationUs, format.audioChannels, format.audioSamplingRate, csd); MediaFormat.NO_VALUE, durationUs, format.audioChannels, format.audioSamplingRate, csd);
mp4TrackType = Track.TYPE_soun; mp4TrackType = Track.TYPE_soun;
break; break;
case StreamElement.TYPE_TEXT: case StreamElement.TYPE_TEXT:
mediaFormat = MediaFormat.createTextFormat(format.mimeType, format.language, durationUs); mediaFormat = MediaFormat.createTextFormat(format.mimeType, format.bitrate, format.language,
durationUs);
mp4TrackType = Track.TYPE_text; mp4TrackType = Track.TYPE_text;
break; break;
default: default:
......
...@@ -49,7 +49,7 @@ public final class Ac3Util { ...@@ -49,7 +49,7 @@ public final class Ac3Util {
channelCount++; channelCount++;
} }
return MediaFormat.createAudioFormat(MimeTypes.AUDIO_AC3, MediaFormat.NO_VALUE, return MediaFormat.createAudioFormat(MimeTypes.AUDIO_AC3, MediaFormat.NO_VALUE,
channelCount, sampleRate, null); MediaFormat.NO_VALUE, channelCount, sampleRate, null);
} }
/** /**
...@@ -72,7 +72,7 @@ public final class Ac3Util { ...@@ -72,7 +72,7 @@ public final class Ac3Util {
channelCount++; channelCount++;
} }
return MediaFormat.createAudioFormat(MimeTypes.AUDIO_EC3, MediaFormat.NO_VALUE, return MediaFormat.createAudioFormat(MimeTypes.AUDIO_EC3, MediaFormat.NO_VALUE,
channelCount, sampleRate, null); MediaFormat.NO_VALUE, channelCount, sampleRate, null);
} }
/** /**
...@@ -100,7 +100,7 @@ public final class Ac3Util { ...@@ -100,7 +100,7 @@ public final class Ac3Util {
} }
boolean lfeon = data.readBit(); boolean lfeon = data.readBit();
return MediaFormat.createAudioFormat(MimeTypes.AUDIO_AC3, MediaFormat.NO_VALUE, return MediaFormat.createAudioFormat(MimeTypes.AUDIO_AC3, MediaFormat.NO_VALUE,
CHANNEL_COUNTS[acmod] + (lfeon ? 1 : 0), SAMPLE_RATES[fscod], null); MediaFormat.NO_VALUE, CHANNEL_COUNTS[acmod] + (lfeon ? 1 : 0), SAMPLE_RATES[fscod], null);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment