mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Remove MediaFormat.create methods that don't take a duration.
This commit is contained in:
parent
e7926145c6
commit
721956710f
13 changed files with 35 additions and 48 deletions
|
|
@ -45,9 +45,9 @@ public final class MediaFormatTest extends TestCase {
|
||||||
initData.add(initData2);
|
initData.add(initData2);
|
||||||
|
|
||||||
testConversionToFrameworkFormatV16(MediaFormat.createVideoFormat(
|
testConversionToFrameworkFormatV16(MediaFormat.createVideoFormat(
|
||||||
"video/xyz", 5000, 102400, 1000L, 1280, 720, 1, initData));
|
"video/xyz", 5000, 102400, 1000L, 1280, 720, initData));
|
||||||
testConversionToFrameworkFormatV16(MediaFormat.createVideoFormat(
|
testConversionToFrameworkFormatV16(MediaFormat.createVideoFormat(
|
||||||
"video/xyz", 5000, MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, 1280, 720, 1, null));
|
"video/xyz", 5000, MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, 1280, 720, null));
|
||||||
testConversionToFrameworkFormatV16(MediaFormat.createAudioFormat(
|
testConversionToFrameworkFormatV16(MediaFormat.createAudioFormat(
|
||||||
"audio/xyz", 500, 128, 1000L, 5, 44100, initData));
|
"audio/xyz", 500, 128, 1000L, 5, 44100, initData));
|
||||||
testConversionToFrameworkFormatV16(MediaFormat.createAudioFormat(
|
testConversionToFrameworkFormatV16(MediaFormat.createAudioFormat(
|
||||||
|
|
|
||||||
|
|
@ -135,32 +135,19 @@ public final class MediaFormat {
|
||||||
private android.media.MediaFormat frameworkMediaFormat;
|
private android.media.MediaFormat frameworkMediaFormat;
|
||||||
|
|
||||||
public static MediaFormat createVideoFormat(String mimeType, int bitrate, int maxInputSize,
|
public static MediaFormat createVideoFormat(String mimeType, int bitrate, int maxInputSize,
|
||||||
int width, int height, List<byte[]> initializationData) {
|
long durationUs, int width, int height, List<byte[]> initializationData) {
|
||||||
return createVideoFormat(mimeType, bitrate, maxInputSize, C.UNKNOWN_TIME_US, width, height,
|
|
||||||
NO_VALUE, initializationData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MediaFormat createVideoFormat(String mimeType, int bitrate, int maxInputSize,
|
|
||||||
long durationUs, int width, int height, int rotationDegrees,
|
|
||||||
List<byte[]> initializationData) {
|
|
||||||
return createVideoFormat(mimeType, bitrate, maxInputSize, durationUs, width, height,
|
return createVideoFormat(mimeType, bitrate, maxInputSize, durationUs, width, height,
|
||||||
rotationDegrees, NO_VALUE, initializationData);
|
initializationData, NO_VALUE, NO_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MediaFormat createVideoFormat(String mimeType, int bitrate, int maxInputSize,
|
public static MediaFormat createVideoFormat(String mimeType, int bitrate, int maxInputSize,
|
||||||
long durationUs, int width, int height, int rotationDegrees, float pixelWidthHeightRatio,
|
long durationUs, int width, int height, List<byte[]> initializationData, int rotationDegrees,
|
||||||
List<byte[]> initializationData) {
|
float pixelWidthHeightRatio) {
|
||||||
return new MediaFormat(mimeType, bitrate, maxInputSize, durationUs, width, height,
|
return new MediaFormat(mimeType, bitrate, maxInputSize, durationUs, width, height,
|
||||||
rotationDegrees, pixelWidthHeightRatio, NO_VALUE, NO_VALUE, null, OFFSET_SAMPLE_RELATIVE,
|
rotationDegrees, pixelWidthHeightRatio, NO_VALUE, NO_VALUE, null, OFFSET_SAMPLE_RELATIVE,
|
||||||
initializationData, false, NO_VALUE, NO_VALUE);
|
initializationData, false, NO_VALUE, NO_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MediaFormat createAudioFormat(String mimeType, int bitrate, int maxInputSize,
|
|
||||||
int channelCount, int sampleRate, List<byte[]> initializationData) {
|
|
||||||
return createAudioFormat(mimeType, bitrate, maxInputSize, C.UNKNOWN_TIME_US, channelCount,
|
|
||||||
sampleRate, initializationData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MediaFormat createAudioFormat(String mimeType, int bitrate, int maxInputSize,
|
public static MediaFormat createAudioFormat(String mimeType, int bitrate, int maxInputSize,
|
||||||
long durationUs, int channelCount, int sampleRate, List<byte[]> initializationData) {
|
long durationUs, int channelCount, int sampleRate, List<byte[]> initializationData) {
|
||||||
return new MediaFormat(mimeType, bitrate, maxInputSize, durationUs, NO_VALUE, NO_VALUE,
|
return new MediaFormat(mimeType, bitrate, maxInputSize, durationUs, NO_VALUE, NO_VALUE,
|
||||||
|
|
@ -168,10 +155,6 @@ public final class MediaFormat {
|
||||||
initializationData, false, NO_VALUE, NO_VALUE);
|
initializationData, false, NO_VALUE, NO_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MediaFormat createTextFormat(String mimeType, int bitrate, String language) {
|
|
||||||
return createTextFormat(mimeType, bitrate, language, C.UNKNOWN_TIME_US);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MediaFormat createTextFormat(String mimeType, int bitrate, String language,
|
public static MediaFormat createTextFormat(String mimeType, int bitrate, String language,
|
||||||
long durationUs) {
|
long durationUs) {
|
||||||
return createTextFormat(mimeType, bitrate, language, durationUs, OFFSET_SAMPLE_RELATIVE);
|
return createTextFormat(mimeType, bitrate, language, durationUs, OFFSET_SAMPLE_RELATIVE);
|
||||||
|
|
@ -183,10 +166,6 @@ public final class MediaFormat {
|
||||||
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, int bitrate) {
|
|
||||||
return createFormatForMimeType(mimeType, bitrate, C.UNKNOWN_TIME_US);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MediaFormat createFormatForMimeType(String mimeType, int bitrate, long durationUs) {
|
public static MediaFormat createFormatForMimeType(String mimeType, int bitrate, long durationUs) {
|
||||||
return new MediaFormat(mimeType, bitrate, NO_VALUE, durationUs, NO_VALUE, NO_VALUE, NO_VALUE,
|
return new MediaFormat(mimeType, bitrate, NO_VALUE, durationUs, NO_VALUE, NO_VALUE, NO_VALUE,
|
||||||
NO_VALUE, NO_VALUE, NO_VALUE, null, OFFSET_SAMPLE_RELATIVE, null, false, NO_VALUE,
|
NO_VALUE, NO_VALUE, NO_VALUE, null, OFFSET_SAMPLE_RELATIVE, null, false, NO_VALUE,
|
||||||
|
|
|
||||||
|
|
@ -607,7 +607,7 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
switch (adaptationSetType) {
|
switch (adaptationSetType) {
|
||||||
case AdaptationSet.TYPE_VIDEO:
|
case AdaptationSet.TYPE_VIDEO:
|
||||||
return MediaFormat.createVideoFormat(mediaMimeType, format.bitrate, MediaFormat.NO_VALUE,
|
return MediaFormat.createVideoFormat(mediaMimeType, format.bitrate, MediaFormat.NO_VALUE,
|
||||||
durationUs, format.width, format.height, 0, null);
|
durationUs, format.width, format.height, null);
|
||||||
case AdaptationSet.TYPE_AUDIO:
|
case AdaptationSet.TYPE_AUDIO:
|
||||||
return MediaFormat.createAudioFormat(mediaMimeType, format.bitrate, MediaFormat.NO_VALUE,
|
return MediaFormat.createAudioFormat(mediaMimeType, format.bitrate, MediaFormat.NO_VALUE,
|
||||||
durationUs, format.audioChannels, format.audioSamplingRate, null);
|
durationUs, format.audioChannels, format.audioSamplingRate, null);
|
||||||
|
|
@ -716,9 +716,8 @@ public class DashChunkSource implements ChunkSource, Output {
|
||||||
long sampleOffsetUs = periodHolder.startTimeUs - representation.presentationTimeOffsetUs;
|
long sampleOffsetUs = periodHolder.startTimeUs - representation.presentationTimeOffsetUs;
|
||||||
if (mimeTypeIsRawText(format.mimeType)) {
|
if (mimeTypeIsRawText(format.mimeType)) {
|
||||||
return new SingleSampleMediaChunk(dataSource, dataSpec, Chunk.TRIGGER_INITIAL, format,
|
return new SingleSampleMediaChunk(dataSource, dataSpec, Chunk.TRIGGER_INITIAL, format,
|
||||||
startTimeUs, endTimeUs, segmentNum,
|
startTimeUs, endTimeUs, segmentNum, enabledTrack.trackFormat, null,
|
||||||
MediaFormat.createTextFormat(format.mimeType, MediaFormat.NO_VALUE, format.language),
|
periodHolder.localIndex);
|
||||||
null, periodHolder.localIndex);
|
|
||||||
} else {
|
} else {
|
||||||
boolean isMediaFormatFinal = (mediaFormat != null);
|
boolean isMediaFormatFinal = (mediaFormat != null);
|
||||||
return new ContainerMediaChunk(dataSource, dataSpec, trigger, format, startTimeUs, endTimeUs,
|
return new ContainerMediaChunk(dataSource, dataSpec, trigger, format, startTimeUs, endTimeUs,
|
||||||
|
|
|
||||||
|
|
@ -456,8 +456,8 @@ import java.util.List;
|
||||||
}
|
}
|
||||||
|
|
||||||
out.mediaFormat = MediaFormat.createVideoFormat(mimeType, MediaFormat.NO_VALUE,
|
out.mediaFormat = MediaFormat.createVideoFormat(mimeType, MediaFormat.NO_VALUE,
|
||||||
MediaFormat.NO_VALUE, durationUs, width, height, rotationDegrees, pixelWidthHeightRatio,
|
MediaFormat.NO_VALUE, durationUs, width, height, initializationData, rotationDegrees,
|
||||||
initializationData);
|
pixelWidthHeightRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AvcCData parseAvcCFromParent(ParsableByteArray parent, int position) {
|
private static AvcCData parseAvcCFromParent(ParsableByteArray parent, int position) {
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ import com.google.android.exoplayer.util.ParsableByteArray;
|
||||||
sampleSize = Ac3Util.parseFrameSize(headerScratchBits);
|
sampleSize = Ac3Util.parseFrameSize(headerScratchBits);
|
||||||
if (mediaFormat == null) {
|
if (mediaFormat == null) {
|
||||||
headerScratchBits.setPosition(0);
|
headerScratchBits.setPosition(0);
|
||||||
mediaFormat = Ac3Util.parseFrameAc3Format(headerScratchBits);
|
mediaFormat = Ac3Util.parseFrameAc3Format(headerScratchBits, C.UNKNOWN_TIME_US);
|
||||||
output.format(mediaFormat);
|
output.format(mediaFormat);
|
||||||
bitrate = Ac3Util.getBitrate(sampleSize, mediaFormat.sampleRate);
|
bitrate = Ac3Util.getBitrate(sampleSize, mediaFormat.sampleRate);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -171,8 +171,8 @@ import java.util.Collections;
|
||||||
audioSpecificConfig);
|
audioSpecificConfig);
|
||||||
|
|
||||||
MediaFormat mediaFormat = MediaFormat.createAudioFormat(MimeTypes.AUDIO_AAC,
|
MediaFormat mediaFormat = MediaFormat.createAudioFormat(MimeTypes.AUDIO_AAC,
|
||||||
MediaFormat.NO_VALUE, MediaFormat.NO_VALUE, audioParams.second, audioParams.first,
|
MediaFormat.NO_VALUE, MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, audioParams.second,
|
||||||
Collections.singletonList(audioSpecificConfig));
|
audioParams.first, 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);
|
||||||
hasOutputFormat = true;
|
hasOutputFormat = true;
|
||||||
|
|
|
||||||
|
|
@ -211,8 +211,8 @@ 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,
|
||||||
MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, parsedSpsData.width, parsedSpsData.height, 0,
|
MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, parsedSpsData.width, parsedSpsData.height,
|
||||||
parsedSpsData.pixelWidthAspectRatio, initializationData));
|
initializationData, MediaFormat.NO_VALUE, parsedSpsData.pixelWidthAspectRatio));
|
||||||
hasOutputFormat = true;
|
hasOutputFormat = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, picWidthInLumaSamples, picHeightInLumaSamples, 0,
|
MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US, picWidthInLumaSamples, picHeightInLumaSamples,
|
||||||
pixelWidthHeightRatio, Collections.singletonList(csd)));
|
Collections.singletonList(csd), MediaFormat.NO_VALUE, pixelWidthHeightRatio));
|
||||||
hasOutputFormat = true;
|
hasOutputFormat = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ 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));
|
MediaFormat.NO_VALUE, C.UNKNOWN_TIME_US));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ 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, MediaFormat.NO_VALUE,
|
output.format(MediaFormat.createTextFormat(MimeTypes.APPLICATION_EIA608, MediaFormat.NO_VALUE,
|
||||||
null));
|
null, C.UNKNOWN_TIME_US));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1213,7 +1213,7 @@ public final class WebmExtractor implements Extractor {
|
||||||
durationUs, channelCount, sampleRate, initializationData);
|
durationUs, channelCount, sampleRate, initializationData);
|
||||||
} else if (MimeTypes.isVideo(mimeType)) {
|
} else if (MimeTypes.isVideo(mimeType)) {
|
||||||
format = MediaFormat.createVideoFormat(mimeType, MediaFormat.NO_VALUE, maxInputSize,
|
format = MediaFormat.createVideoFormat(mimeType, MediaFormat.NO_VALUE, maxInputSize,
|
||||||
durationUs, width, height, 0, initializationData);
|
durationUs, width, height, initializationData);
|
||||||
} else if (MimeTypes.APPLICATION_SUBRIP.equals(mimeType)) {
|
} else if (MimeTypes.APPLICATION_SUBRIP.equals(mimeType)) {
|
||||||
format = MediaFormat.createTextFormat(mimeType, MediaFormat.NO_VALUE, language, durationUs);
|
format = MediaFormat.createTextFormat(mimeType, MediaFormat.NO_VALUE, language, durationUs);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -399,8 +399,7 @@ public class SmoothStreamingChunkSource implements ChunkSource,
|
||||||
switch (element.type) {
|
switch (element.type) {
|
||||||
case StreamElement.TYPE_VIDEO:
|
case StreamElement.TYPE_VIDEO:
|
||||||
mediaFormat = MediaFormat.createVideoFormat(format.mimeType, format.bitrate,
|
mediaFormat = MediaFormat.createVideoFormat(format.mimeType, format.bitrate,
|
||||||
MediaFormat.NO_VALUE, durationUs, format.width, format.height, 0,
|
MediaFormat.NO_VALUE, durationUs, format.width, format.height, Arrays.asList(csdArray));
|
||||||
Arrays.asList(csdArray));
|
|
||||||
mp4TrackType = Track.TYPE_vide;
|
mp4TrackType = Track.TYPE_vide;
|
||||||
break;
|
break;
|
||||||
case StreamElement.TYPE_AUDIO:
|
case StreamElement.TYPE_AUDIO:
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ public final class Ac3Util {
|
||||||
/**
|
/**
|
||||||
* Returns the AC-3 format given {@code data} containing the AC3SpecificBox according to
|
* Returns the AC-3 format given {@code data} containing the AC3SpecificBox according to
|
||||||
* ETSI TS 102 366 Annex F.
|
* ETSI TS 102 366 Annex F.
|
||||||
|
*
|
||||||
|
* @param data The AC3SpecificBox.
|
||||||
|
* @param durationUs The duration to set on the format, in microseconds.
|
||||||
|
* @return The FAc3 format parsed from data in the header.
|
||||||
*/
|
*/
|
||||||
public static MediaFormat parseAnnexFAc3Format(ParsableByteArray data, long durationUs) {
|
public static MediaFormat parseAnnexFAc3Format(ParsableByteArray data, long durationUs) {
|
||||||
// fscod (sample rate code)
|
// fscod (sample rate code)
|
||||||
|
|
@ -55,6 +59,10 @@ public final class Ac3Util {
|
||||||
/**
|
/**
|
||||||
* Returns the AC-3 format given {@code data} containing the EC3SpecificBox according to
|
* Returns the AC-3 format given {@code data} containing the EC3SpecificBox according to
|
||||||
* ETSI TS 102 366 Annex F.
|
* ETSI TS 102 366 Annex F.
|
||||||
|
*
|
||||||
|
* @param data The EC3SpecificBox.
|
||||||
|
* @param durationUs The duration to set on the format, in microseconds.
|
||||||
|
* @return The FEAc3 format parsed from data in the header.
|
||||||
*/
|
*/
|
||||||
public static MediaFormat parseAnnexFEAc3Format(ParsableByteArray data, long durationUs) {
|
public static MediaFormat parseAnnexFEAc3Format(ParsableByteArray data, long durationUs) {
|
||||||
data.skipBytes(2); // Skip data_rate and num_ind_sub.
|
data.skipBytes(2); // Skip data_rate and num_ind_sub.
|
||||||
|
|
@ -80,9 +88,10 @@ public final class Ac3Util {
|
||||||
* word.
|
* word.
|
||||||
*
|
*
|
||||||
* @param data Data to parse, positioned at the start of the syncword.
|
* @param data Data to parse, positioned at the start of the syncword.
|
||||||
* @return AC-3 format parsed from data in the header.
|
* @param durationUs The duration to set on the format, in microseconds.
|
||||||
|
* @return The AC-3 format parsed from data in the header.
|
||||||
*/
|
*/
|
||||||
public static MediaFormat parseFrameAc3Format(ParsableBitArray data) {
|
public static MediaFormat parseFrameAc3Format(ParsableBitArray data, long durationUs) {
|
||||||
// Skip syncword and crc1.
|
// Skip syncword and crc1.
|
||||||
data.skipBits(4 * 8);
|
data.skipBits(4 * 8);
|
||||||
|
|
||||||
|
|
@ -100,7 +109,8 @@ 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,
|
||||||
MediaFormat.NO_VALUE, CHANNEL_COUNTS[acmod] + (lfeon ? 1 : 0), SAMPLE_RATES[fscod], null);
|
MediaFormat.NO_VALUE, durationUs, CHANNEL_COUNTS[acmod] + (lfeon ? 1 : 0),
|
||||||
|
SAMPLE_RATES[fscod], null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue