Clarify naming & comments for distinction between Format and MediaFormat.

PiperOrigin-RevId: 276673410
This commit is contained in:
samrobinson 2019-10-25 13:53:30 +01:00 committed by Oliver Woodman
parent ac722a7a68
commit ea77defd38
3 changed files with 64 additions and 56 deletions

View file

@ -474,22 +474,22 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
}
@Override
protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputFormat)
protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputMediaFormat)
throws ExoPlaybackException {
@C.Encoding int encoding;
MediaFormat format;
MediaFormat mediaFormat;
if (passthroughMediaFormat != null) {
format = passthroughMediaFormat;
mediaFormat = passthroughMediaFormat;
encoding =
getPassthroughEncoding(
format.getInteger(MediaFormat.KEY_CHANNEL_COUNT),
format.getString(MediaFormat.KEY_MIME));
mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT),
mediaFormat.getString(MediaFormat.KEY_MIME));
} else {
format = outputFormat;
mediaFormat = outputMediaFormat;
encoding = pcmEncoding;
}
int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
int sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
int channelCount = mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
int sampleRate = mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE);
int[] channelMap;
if (codecNeedsDiscardChannelsWorkaround && channelCount == 6 && this.channelCount < 6) {
channelMap = new int[this.channelCount];
@ -769,7 +769,7 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
* will allow possible adaptation to other compatible formats in {@code streamFormats}.
*
* @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.
* @return A suitable maximum input size.
*/
@ -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 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
* be determined.
*/
@ -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}
* 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 codecMaxInputSize The maximum input size supported by the codec.
* @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
* no codec operating rate should be set.
* @return The framework media format.
* @return The framework {@link MediaFormat}.
*/
@SuppressLint("InlinedApi")
protected MediaFormat getMediaFormat(

View file

@ -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 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
* #supportsFormat(Format)} for more detail.
* @throws DecoderQueryException If there was an error querying decoders.
@ -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.
*
* @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.
* @return A list of {@link MediaCodecInfo}s corresponding to decoders. May be empty.
* @throws DecoderQueryException Thrown if there was an error querying decoders.
@ -481,7 +481,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
*
* @param codecInfo Information about the {@link MediaCodec} being configured.
* @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 codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
* no codec operating rate should be set.
@ -769,7 +769,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
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 {
FormatHolder formatHolder = getFormatHolder();
flagsOnlyBuffer.clear();
@ -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}.
* @throws ExoPlaybackException If an error occurs re-initializing the {@link MediaCodec}.
@ -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.
*
* @param codec The {@link MediaCodec} instance.
* @param outputFormat The new output MediaFormat.
* @throws ExoPlaybackException Thrown if an error occurs handling the new output format.
* @param outputMediaFormat The new output {@link MediaFormat}.
* @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 {
// Do nothing.
}
@ -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
* whether it requires reconfiguration.
* Determines whether the existing {@link MediaCodec} can be kept for a new {@link Format}, and if
* it can whether it requires reconfiguration.
*
* <p>The default implementation returns {@link #KEEP_CODEC_RESULT_NO}.
*
* @param codec The existing {@link MediaCodec} instance.
* @param codecInfo A {@link MediaCodecInfo} describing the decoder.
* @param oldFormat The format for which the existing instance is configured.
* @param newFormat The new format.
* @param oldFormat The {@link Format} for which the existing instance is configured.
* @param newFormat The new {@link Format}.
* @return Whether the instance can be kept, and if it can whether it requires reconfiguration.
*/
protected @KeepCodecResult int canKeepCodec(
@ -1363,12 +1363,12 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
/**
* 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}.
*
* @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.
* @return The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if no codec operating
* rate should be set.
@ -1622,7 +1622,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
* @param isDecodeOnlyBuffer Whether the buffer was marked with {@link C#BUFFER_FLAG_DECODE_ONLY}
* by the source.
* @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).
* @throws ExoPlaybackException If an error occurs processing the output buffer.
*/
@ -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
* 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 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.
*/
private static boolean codecNeedsDiscardToSpsWorkaround(String name, Format format) {
@ -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
* to 2 for the given input format, whilst only actually outputting a single channel.
* <p>
* If true is returned then we explicitly override the number of channels in the output format,
* setting it to 1.
* Returns whether the decoder is known to set the number of audio channels in the output {@link
* Format} to 2 for the given input {@link Format}, whilst only actually outputting a single
* channel.
*
* <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 format The input format.
* @return True if the decoder is known to set the number of audio channels in the output format
* to 2 for the given input format, whilst only actually outputting a single channel. False
* otherwise.
* @param format The input {@link Format}.
* @return True if the decoder is known to set the number of audio channels in the output {@link
* Format} to 2 for the given input {@link Format}, whilst only actually outputting a single
* channel. False otherwise.
*/
private static boolean codecNeedsMonoChannelCountWorkaround(String name, Format format) {
return Util.SDK_INT <= 18 && format.channelCount == 1

View file

@ -721,19 +721,25 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
}
@Override
protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputFormat) {
currentMediaFormat = outputFormat;
boolean hasCrop = outputFormat.containsKey(KEY_CROP_RIGHT)
&& outputFormat.containsKey(KEY_CROP_LEFT) && outputFormat.containsKey(KEY_CROP_BOTTOM)
&& outputFormat.containsKey(KEY_CROP_TOP);
protected void onOutputFormatChanged(MediaCodec codec, MediaFormat outputMediaFormat) {
currentMediaFormat = outputMediaFormat;
boolean hasCrop =
outputMediaFormat.containsKey(KEY_CROP_RIGHT)
&& outputMediaFormat.containsKey(KEY_CROP_LEFT)
&& outputMediaFormat.containsKey(KEY_CROP_BOTTOM)
&& outputMediaFormat.containsKey(KEY_CROP_TOP);
int width =
hasCrop
? outputFormat.getInteger(KEY_CROP_RIGHT) - outputFormat.getInteger(KEY_CROP_LEFT) + 1
: outputFormat.getInteger(MediaFormat.KEY_WIDTH);
? outputMediaFormat.getInteger(KEY_CROP_RIGHT)
- outputMediaFormat.getInteger(KEY_CROP_LEFT)
+ 1
: outputMediaFormat.getInteger(MediaFormat.KEY_WIDTH);
int height =
hasCrop
? outputFormat.getInteger(KEY_CROP_BOTTOM) - outputFormat.getInteger(KEY_CROP_TOP) + 1
: outputFormat.getInteger(MediaFormat.KEY_HEIGHT);
? outputMediaFormat.getInteger(KEY_CROP_BOTTOM)
- outputMediaFormat.getInteger(KEY_CROP_TOP)
+ 1
: outputMediaFormat.getInteger(MediaFormat.KEY_HEIGHT);
processOutputFormat(codec, width, height);
}
@ -905,7 +911,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
// On API level 20 and below the decoder does not apply the rotation.
currentUnappliedRotationDegrees = pendingRotationDegrees;
}
// Must be applied each time the output format changes.
// Must be applied each time the output MediaFormat changes.
codec.setVideoScalingMode(scalingMode);
}
@ -1242,7 +1248,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
/**
* 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 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
@ -1307,7 +1313,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
* that will allow possible adaptation to other compatible formats in {@code streamFormats}.
*
* @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.
* @return Suitable {@link CodecMaxValues}.
*/
@ -1373,7 +1379,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
* aspect ratio, but whose sizes are unknown.
*
* @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.
*/
private static Point getCodecMaxSize(MediaCodecInfo codecInfo, Format format) {
@ -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 format The format.