Commit ea77defd by samrobinson Committed by Oliver Woodman

Clarify naming & comments for distinction between Format and MediaFormat.

PiperOrigin-RevId: 276673410
parent ac722a7a
...@@ -474,22 +474,22 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -474,22 +474,22 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
} }
@Override @Override
protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputFormat) protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputMediaFormat)
throws ExoPlaybackException { throws ExoPlaybackException {
@C.Encoding int encoding; @C.Encoding int encoding;
MediaFormat format; MediaFormat mediaFormat;
if (passthroughMediaFormat != null) { if (passthroughMediaFormat != null) {
format = passthroughMediaFormat; mediaFormat = passthroughMediaFormat;
encoding = encoding =
getPassthroughEncoding( getPassthroughEncoding(
format.getInteger(MediaFormat.KEY_CHANNEL_COUNT), mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT),
format.getString(MediaFormat.KEY_MIME)); mediaFormat.getString(MediaFormat.KEY_MIME));
} else { } else {
format = outputFormat; mediaFormat = outputMediaFormat;
encoding = pcmEncoding; encoding = pcmEncoding;
} }
int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT); int channelCount = mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
int sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE); int sampleRate = mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE);
int[] channelMap; int[] channelMap;
if (codecNeedsDiscardChannelsWorkaround && channelCount == 6 && this.channelCount < 6) { if (codecNeedsDiscardChannelsWorkaround && channelCount == 6 && this.channelCount < 6) {
channelMap = new int[this.channelCount]; channelMap = new int[this.channelCount];
...@@ -769,7 +769,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -769,7 +769,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
* will allow possible adaptation to other compatible formats in {@code streamFormats}. * will allow possible adaptation to other compatible formats in {@code streamFormats}.
* *
* @param codecInfo A {@link MediaCodecInfo} describing the decoder. * @param codecInfo A {@link MediaCodecInfo} describing the decoder.
* @param format The format for which the codec is being configured. * @param format The {@link Format} for which the codec is being configured.
* @param streamFormats The possible stream formats. * @param streamFormats The possible stream formats.
* @return A suitable maximum input size. * @return A suitable maximum input size.
*/ */
...@@ -791,10 +791,10 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -791,10 +791,10 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
} }
/** /**
* Returns a maximum input buffer size for a given format. * Returns a maximum input buffer size for a given {@link Format}.
* *
* @param codecInfo A {@link MediaCodecInfo} describing the decoder. * @param codecInfo A {@link MediaCodecInfo} describing the decoder.
* @param format The format. * @param format The {@link Format}.
* @return A maximum input buffer size in bytes, or {@link Format#NO_VALUE} if a maximum could not * @return A maximum input buffer size in bytes, or {@link Format#NO_VALUE} if a maximum could not
* be determined. * be determined.
*/ */
...@@ -833,12 +833,12 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -833,12 +833,12 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
* Returns the framework {@link MediaFormat} that can be used to configure a {@link MediaCodec} * Returns the framework {@link MediaFormat} that can be used to configure a {@link MediaCodec}
* for decoding the given {@link Format} for playback. * for decoding the given {@link Format} for playback.
* *
* @param format The format of the media. * @param format The {@link Format} of the media.
* @param codecMimeType The MIME type handled by the codec. * @param codecMimeType The MIME type handled by the codec.
* @param codecMaxInputSize The maximum input size supported by the codec. * @param codecMaxInputSize The maximum input size supported by the codec.
* @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
* no codec operating rate should be set. * no codec operating rate should be set.
* @return The framework media format. * @return The framework {@link MediaFormat}.
*/ */
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat( protected MediaFormat getMediaFormat(
......
...@@ -448,11 +448,11 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -448,11 +448,11 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
} }
/** /**
* Returns the extent to which the renderer is capable of supporting a given format. * Returns the extent to which the renderer is capable of supporting a given {@link Format}.
* *
* @param mediaCodecSelector The decoder selector. * @param mediaCodecSelector The decoder selector.
* @param drmSessionManager The renderer's {@link DrmSessionManager}. * @param drmSessionManager The renderer's {@link DrmSessionManager}.
* @param format The format. * @param format The {@link Format}.
* @return The extent to which the renderer is capable of supporting the given format. See {@link * @return The extent to which the renderer is capable of supporting the given format. See {@link
* #supportsFormat(Format)} for more detail. * #supportsFormat(Format)} for more detail.
* @throws DecoderQueryException If there was an error querying decoders. * @throws DecoderQueryException If there was an error querying decoders.
...@@ -467,7 +467,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -467,7 +467,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
* Returns a list of decoders that can decode media in the specified format, in priority order. * Returns a list of decoders that can decode media in the specified format, in priority order.
* *
* @param mediaCodecSelector The decoder selector. * @param mediaCodecSelector The decoder selector.
* @param format The format for which a decoder is required. * @param format The {@link Format} for which a decoder is required.
* @param requiresSecureDecoder Whether a secure decoder is required. * @param requiresSecureDecoder Whether a secure decoder is required.
* @return A list of {@link MediaCodecInfo}s corresponding to decoders. May be empty. * @return A list of {@link MediaCodecInfo}s corresponding to decoders. May be empty.
* @throws DecoderQueryException Thrown if there was an error querying decoders. * @throws DecoderQueryException Thrown if there was an error querying decoders.
...@@ -481,7 +481,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -481,7 +481,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
* *
* @param codecInfo Information about the {@link MediaCodec} being configured. * @param codecInfo Information about the {@link MediaCodec} being configured.
* @param codec The {@link MediaCodec} to configure. * @param codec The {@link MediaCodec} to configure.
* @param format The format for which the codec is being configured. * @param format The {@link Format} for which the codec is being configured.
* @param crypto For drm protected playbacks, a {@link MediaCrypto} to use for decryption. * @param crypto For drm protected playbacks, a {@link MediaCrypto} to use for decryption.
* @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
* no codec operating rate should be set. * no codec operating rate should be set.
...@@ -769,7 +769,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -769,7 +769,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
return new DecoderException(cause, codecInfo); return new DecoderException(cause, codecInfo);
} }
/** Reads into {@link #flagsOnlyBuffer} and returns whether a format was read. */ /** Reads into {@link #flagsOnlyBuffer} and returns whether a {@link Format} was read. */
private boolean readToFlagsOnlyBuffer(boolean requireFormat) throws ExoPlaybackException { private boolean readToFlagsOnlyBuffer(boolean requireFormat) throws ExoPlaybackException {
FormatHolder formatHolder = getFormatHolder(); FormatHolder formatHolder = getFormatHolder();
flagsOnlyBuffer.clear(); flagsOnlyBuffer.clear();
...@@ -1192,7 +1192,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -1192,7 +1192,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
} }
/** /**
* Called when a new format is read from the upstream {@link MediaPeriod}. * Called when a new {@link Format} is read from the upstream {@link MediaPeriod}.
* *
* @param formatHolder A {@link FormatHolder} that holds the new {@link Format}. * @param formatHolder A {@link FormatHolder} that holds the new {@link Format}.
* @throws ExoPlaybackException If an error occurs re-initializing the {@link MediaCodec}. * @throws ExoPlaybackException If an error occurs re-initializing the {@link MediaCodec}.
...@@ -1272,15 +1272,15 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -1272,15 +1272,15 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
} }
/** /**
* Called when the output format of the {@link MediaCodec} changes. * Called when the output {@link MediaFormat} of the {@link MediaCodec} changes.
* *
* <p>The default implementation is a no-op. * <p>The default implementation is a no-op.
* *
* @param codec The {@link MediaCodec} instance. * @param codec The {@link MediaCodec} instance.
* @param outputFormat The new output MediaFormat. * @param outputMediaFormat The new output {@link MediaFormat}.
* @throws ExoPlaybackException Thrown if an error occurs handling the new output format. * @throws ExoPlaybackException Thrown if an error occurs handling the new output media format.
*/ */
protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputFormat) protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputMediaFormat)
throws ExoPlaybackException { throws ExoPlaybackException {
// Do nothing. // Do nothing.
} }
...@@ -1321,15 +1321,15 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -1321,15 +1321,15 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
} }
/** /**
* Determines whether the existing {@link MediaCodec} can be kept for a new format, and if it can * Determines whether the existing {@link MediaCodec} can be kept for a new {@link Format}, and if
* whether it requires reconfiguration. * it can whether it requires reconfiguration.
* *
* <p>The default implementation returns {@link #KEEP_CODEC_RESULT_NO}. * <p>The default implementation returns {@link #KEEP_CODEC_RESULT_NO}.
* *
* @param codec The existing {@link MediaCodec} instance. * @param codec The existing {@link MediaCodec} instance.
* @param codecInfo A {@link MediaCodecInfo} describing the decoder. * @param codecInfo A {@link MediaCodecInfo} describing the decoder.
* @param oldFormat The format for which the existing instance is configured. * @param oldFormat The {@link Format} for which the existing instance is configured.
* @param newFormat The new format. * @param newFormat The new {@link Format}.
* @return Whether the instance can be kept, and if it can whether it requires reconfiguration. * @return Whether the instance can be kept, and if it can whether it requires reconfiguration.
*/ */
protected @KeepCodecResult int canKeepCodec( protected @KeepCodecResult int canKeepCodec(
...@@ -1363,12 +1363,12 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -1363,12 +1363,12 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
/** /**
* Returns the {@link MediaFormat#KEY_OPERATING_RATE} value for a given renderer operating rate, * Returns the {@link MediaFormat#KEY_OPERATING_RATE} value for a given renderer operating rate,
* current format and set of possible stream formats. * current {@link Format} and set of possible stream formats.
* *
* <p>The default implementation returns {@link #CODEC_OPERATING_RATE_UNSET}. * <p>The default implementation returns {@link #CODEC_OPERATING_RATE_UNSET}.
* *
* @param operatingRate The renderer operating rate. * @param operatingRate The renderer operating rate.
* @param format The format for which the codec is being configured. * @param format The {@link Format} for which the codec is being configured.
* @param streamFormats The possible stream formats. * @param streamFormats The possible stream formats.
* @return The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if no codec operating * @return The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if no codec operating
* rate should be set. * rate should be set.
...@@ -1622,7 +1622,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -1622,7 +1622,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
* @param isDecodeOnlyBuffer Whether the buffer was marked with {@link C#BUFFER_FLAG_DECODE_ONLY} * @param isDecodeOnlyBuffer Whether the buffer was marked with {@link C#BUFFER_FLAG_DECODE_ONLY}
* by the source. * by the source.
* @param isLastBuffer Whether the buffer is the last sample of the current stream. * @param isLastBuffer Whether the buffer is the last sample of the current stream.
* @param format The format associated with the buffer. * @param format The {@link Format} associated with the buffer.
* @return Whether the output buffer was fully processed (e.g. rendered or skipped). * @return Whether the output buffer was fully processed (e.g. rendered or skipped).
* @throws ExoPlaybackException If an error occurs processing the output buffer. * @throws ExoPlaybackException If an error occurs processing the output buffer.
*/ */
...@@ -1822,11 +1822,12 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -1822,11 +1822,12 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
/** /**
* Returns whether the decoder is an H.264/AVC decoder known to fail if NAL units are queued * Returns whether the decoder is an H.264/AVC decoder known to fail if NAL units are queued
* before the codec specific data. * before the codec specific data.
* <p> *
* If true is returned, the renderer will work around the issue by discarding data up to the SPS. * <p>If true is returned, the renderer will work around the issue by discarding data up to the
* SPS.
* *
* @param name The name of the decoder. * @param name The name of the decoder.
* @param format The format used to configure the decoder. * @param format The {@link Format} used to configure the decoder.
* @return True if the decoder is known to fail if NAL units are queued before CSD. * @return True if the decoder is known to fail if NAL units are queued before CSD.
*/ */
private static boolean codecNeedsDiscardToSpsWorkaround(String name, Format format) { private static boolean codecNeedsDiscardToSpsWorkaround(String name, Format format) {
...@@ -1890,17 +1891,18 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -1890,17 +1891,18 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
} }
/** /**
* Returns whether the decoder is known to set the number of audio channels in the output format * Returns whether the decoder is known to set the number of audio channels in the output {@link
* to 2 for the given input format, whilst only actually outputting a single channel. * Format} to 2 for the given input {@link Format}, whilst only actually outputting a single
* <p> * channel.
* If true is returned then we explicitly override the number of channels in the output format, *
* setting it to 1. * <p>If true is returned then we explicitly override the number of channels in the output {@link
* Format}, setting it to 1.
* *
* @param name The decoder name. * @param name The decoder name.
* @param format The input format. * @param format The input {@link Format}.
* @return True if the decoder is known to set the number of audio channels in the output format * @return True if the decoder is known to set the number of audio channels in the output {@link
* to 2 for the given input format, whilst only actually outputting a single channel. False * Format} to 2 for the given input {@link Format}, whilst only actually outputting a single
* otherwise. * channel. False otherwise.
*/ */
private static boolean codecNeedsMonoChannelCountWorkaround(String name, Format format) { private static boolean codecNeedsMonoChannelCountWorkaround(String name, Format format) {
return Util.SDK_INT <= 18 && format.channelCount == 1 return Util.SDK_INT <= 18 && format.channelCount == 1
......
...@@ -721,19 +721,25 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -721,19 +721,25 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
} }
@Override @Override
protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputFormat) { protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputMediaFormat) {
currentMediaFormat = outputFormat; currentMediaFormat = outputMediaFormat;
boolean hasCrop = outputFormat.containsKey(KEY_CROP_RIGHT) boolean hasCrop =
&& outputFormat.containsKey(KEY_CROP_LEFT) && outputFormat.containsKey(KEY_CROP_BOTTOM) outputMediaFormat.containsKey(KEY_CROP_RIGHT)
&& outputFormat.containsKey(KEY_CROP_TOP); && outputMediaFormat.containsKey(KEY_CROP_LEFT)
&& outputMediaFormat.containsKey(KEY_CROP_BOTTOM)
&& outputMediaFormat.containsKey(KEY_CROP_TOP);
int width = int width =
hasCrop hasCrop
? outputFormat.getInteger(KEY_CROP_RIGHT) - outputFormat.getInteger(KEY_CROP_LEFT) + 1 ? outputMediaFormat.getInteger(KEY_CROP_RIGHT)
: outputFormat.getInteger(MediaFormat.KEY_WIDTH); - outputMediaFormat.getInteger(KEY_CROP_LEFT)
+ 1
: outputMediaFormat.getInteger(MediaFormat.KEY_WIDTH);
int height = int height =
hasCrop hasCrop
? outputFormat.getInteger(KEY_CROP_BOTTOM) - outputFormat.getInteger(KEY_CROP_TOP) + 1 ? outputMediaFormat.getInteger(KEY_CROP_BOTTOM)
: outputFormat.getInteger(MediaFormat.KEY_HEIGHT); - outputMediaFormat.getInteger(KEY_CROP_TOP)
+ 1
: outputMediaFormat.getInteger(MediaFormat.KEY_HEIGHT);
processOutputFormat(codec, width, height); processOutputFormat(codec, width, height);
} }
...@@ -905,7 +911,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -905,7 +911,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
// On API level 20 and below the decoder does not apply the rotation. // On API level 20 and below the decoder does not apply the rotation.
currentUnappliedRotationDegrees = pendingRotationDegrees; currentUnappliedRotationDegrees = pendingRotationDegrees;
} }
// Must be applied each time the output format changes. // Must be applied each time the output MediaFormat changes.
codec.setVideoScalingMode(scalingMode); codec.setVideoScalingMode(scalingMode);
} }
...@@ -1242,7 +1248,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -1242,7 +1248,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
/** /**
* Returns the framework {@link MediaFormat} that should be used to configure the decoder. * Returns the framework {@link MediaFormat} that should be used to configure the decoder.
* *
* @param format The format of media. * @param format The {@link Format} of media.
* @param codecMimeType The MIME type handled by the codec. * @param codecMimeType The MIME type handled by the codec.
* @param codecMaxValues Codec max values that should be used when configuring the decoder. * @param codecMaxValues Codec max values that should be used when configuring the decoder.
* @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if * @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
...@@ -1307,7 +1313,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -1307,7 +1313,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
* that will allow possible adaptation to other compatible formats in {@code streamFormats}. * that will allow possible adaptation to other compatible formats in {@code streamFormats}.
* *
* @param codecInfo Information about the {@link MediaCodec} being configured. * @param codecInfo Information about the {@link MediaCodec} being configured.
* @param format The format for which the codec is being configured. * @param format The {@link Format} for which the codec is being configured.
* @param streamFormats The possible stream formats. * @param streamFormats The possible stream formats.
* @return Suitable {@link CodecMaxValues}. * @return Suitable {@link CodecMaxValues}.
*/ */
...@@ -1373,7 +1379,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -1373,7 +1379,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
* aspect ratio, but whose sizes are unknown. * aspect ratio, but whose sizes are unknown.
* *
* @param codecInfo Information about the {@link MediaCodec} being configured. * @param codecInfo Information about the {@link MediaCodec} being configured.
* @param format The format for which the codec is being configured. * @param format The {@link Format} for which the codec is being configured.
* @return The maximum video size to use, or null if the size of {@code format} should be used. * @return The maximum video size to use, or null if the size of {@code format} should be used.
*/ */
private static Point getCodecMaxSize(MediaCodecInfo codecInfo, Format format) { private static Point getCodecMaxSize(MediaCodecInfo codecInfo, Format format) {
...@@ -1413,7 +1419,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer { ...@@ -1413,7 +1419,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
} }
/** /**
* Returns a maximum input buffer size for a given codec and format. * Returns a maximum input buffer size for a given {@link MediaCodec} and {@link Format}.
* *
* @param codecInfo Information about the {@link MediaCodec} being configured. * @param codecInfo Information about the {@link MediaCodec} being configured.
* @param format The format. * @param format The format.
......
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