mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Add getInputFormat to Codec interface
PiperOrigin-RevId: 725552831
This commit is contained in:
parent
d022b570f2
commit
50d4e66308
@ -9,6 +9,7 @@
|
||||
* Transformer:
|
||||
* Add `MediaProjectionAssetLoader`, which provides media from a
|
||||
`MediaProjection` for screen recording.
|
||||
* Add `#getInputFormat()` to `Codec` interface.
|
||||
* Track Selection:
|
||||
* Extractors:
|
||||
* DataSource:
|
||||
|
@ -258,6 +258,11 @@ public class ForceEndOfStreamTest {
|
||||
wrappedDecoder.signalEndOfInputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Format getInputFormat() throws ExportException {
|
||||
return wrappedDecoder.getInputFormat();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Format getOutputFormat() throws ExportException {
|
||||
|
@ -182,6 +182,17 @@ public interface Codec {
|
||||
*/
|
||||
void signalEndOfInputStream() throws ExportException;
|
||||
|
||||
/**
|
||||
* Returns the {@link Format} accepted by the codec.
|
||||
*
|
||||
* <p>This format may differ from the {@link Format} returned by {@link
|
||||
* #getConfigurationFormat()}, depending on the underlying codec and configuration format
|
||||
* requested.
|
||||
*
|
||||
* @throws ExportException If the underlying decoder or encoder encounters a problem.
|
||||
*/
|
||||
Format getInputFormat() throws ExportException;
|
||||
|
||||
/**
|
||||
* Returns the current output format, or {@code null} if unavailable.
|
||||
*
|
||||
|
@ -272,6 +272,16 @@ public final class DefaultCodec implements Codec {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Format getInputFormat() throws ExportException {
|
||||
try {
|
||||
return convertToFormat(mediaCodec.getInputFormat(), isDecoder, configurationFormat.metadata);
|
||||
} catch (RuntimeException e) {
|
||||
Log.d(TAG, "MediaCodec error", e);
|
||||
throw createExportException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Format getOutputFormat() throws ExportException {
|
||||
|
@ -159,6 +159,11 @@ public final class ExperimentalAnalyzerModeFactory {
|
||||
inputStreamEnded = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Format getInputFormat() {
|
||||
return configurationFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Format getOutputFormat() {
|
||||
|
@ -265,32 +265,26 @@ public class DefaultEncoderFactoryTest {
|
||||
|
||||
@Test
|
||||
public void createForAudioEncoding_unsupportedSampleRateWithFallback() throws Exception {
|
||||
Format requestedAudioFormat = createAudioFormat(MimeTypes.AUDIO_AAC, /* sampleRate= */ 192_000);
|
||||
int highestSupportedSampleRate = 96_000;
|
||||
int unsupportedSampleRate = 192_000;
|
||||
Format requestedAudioFormat = createAudioFormat(MimeTypes.AUDIO_AAC, unsupportedSampleRate);
|
||||
|
||||
Format actualAudioFormat =
|
||||
DefaultCodec codec =
|
||||
new DefaultEncoderFactory.Builder(context)
|
||||
.setEnableFallback(true)
|
||||
.build()
|
||||
.createForAudioEncoding(requestedAudioFormat)
|
||||
.getConfigurationFormat();
|
||||
.createForAudioEncoding(requestedAudioFormat);
|
||||
|
||||
assertThat(actualAudioFormat.sampleMimeType).isEqualTo(MimeTypes.AUDIO_AAC);
|
||||
assertThat(actualAudioFormat.sampleRate).isEqualTo(96_000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createForAudioEncoding_unsupportedSampleRateWithoutFallback() throws Exception {
|
||||
Format requestedAudioFormat = createAudioFormat(MimeTypes.AUDIO_AAC, /* sampleRate= */ 192_000);
|
||||
|
||||
Format actualAudioFormat =
|
||||
new DefaultEncoderFactory.Builder(context)
|
||||
.setEnableFallback(false)
|
||||
.build()
|
||||
.createForAudioEncoding(requestedAudioFormat)
|
||||
.getConfigurationFormat();
|
||||
|
||||
assertThat(actualAudioFormat.sampleMimeType).isEqualTo(MimeTypes.AUDIO_AAC);
|
||||
assertThat(actualAudioFormat.sampleRate).isEqualTo(192_000);
|
||||
Format inputFormat = codec.getInputFormat();
|
||||
Format configurationFormat = codec.getConfigurationFormat();
|
||||
Format outputFormat = codec.getOutputFormat();
|
||||
assertThat(outputFormat).isNotNull();
|
||||
assertThat(inputFormat.sampleMimeType).isEqualTo(MimeTypes.AUDIO_AAC);
|
||||
assertThat(configurationFormat.sampleMimeType).isEqualTo(MimeTypes.AUDIO_AAC);
|
||||
assertThat(outputFormat.sampleMimeType).isEqualTo(MimeTypes.AUDIO_AAC);
|
||||
assertThat(inputFormat.sampleRate).isEqualTo(highestSupportedSampleRate);
|
||||
assertThat(configurationFormat.sampleRate).isEqualTo(highestSupportedSampleRate);
|
||||
assertThat(outputFormat.sampleRate).isEqualTo(highestSupportedSampleRate);
|
||||
}
|
||||
|
||||
private static Format createVideoFormat(String mimeType, int width, int height, int frameRate) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user