Replace static method with a static field.

PiperOrigin-RevId: 420307694
This commit is contained in:
claincly 2022-01-07 17:23:00 +00:00 committed by Ian Baker
parent bd52b19a85
commit d59cfb736a

View File

@ -36,6 +36,18 @@ import java.io.IOException;
/* package */ final class DefaultCodecFactory /* package */ final class DefaultCodecFactory
implements Codec.DecoderFactory, Codec.EncoderFactory { implements Codec.DecoderFactory, Codec.EncoderFactory {
private static final MediaCodecInfo PLACEHOLDER_MEDIA_CODEC_INFO =
MediaCodecInfo.newInstance(
/* name= */ "name-placeholder",
/* mimeType= */ "mime-type-placeholder",
/* codecMimeType= */ "mime-type-placeholder",
/* capabilities= */ null,
/* hardwareAccelerated= */ false,
/* softwareOnly= */ false,
/* vendor= */ false,
/* forceDisableAdaptive= */ false,
/* forceSecure= */ false);
@Override @Override
public Codec createForAudioDecoding(Format format) throws TransformationException { public Codec createForAudioDecoding(Format format) throws TransformationException {
MediaFormat mediaFormat = MediaFormat mediaFormat =
@ -51,7 +63,7 @@ import java.io.IOException;
new MediaCodecFactory() new MediaCodecFactory()
.createAdapter( .createAdapter(
MediaCodecAdapter.Configuration.createForAudioDecoding( MediaCodecAdapter.Configuration.createForAudioDecoding(
createPlaceholderMediaCodecInfo(), mediaFormat, format, /* crypto= */ null)); PLACEHOLDER_MEDIA_CODEC_INFO, mediaFormat, format, /* crypto= */ null));
} catch (Exception e) { } catch (Exception e) {
throw createTransformationException(e, format, /* isVideo= */ false, /* isDecoder= */ true); throw createTransformationException(e, format, /* isVideo= */ false, /* isDecoder= */ true);
} }
@ -81,7 +93,7 @@ import java.io.IOException;
new MediaCodecFactory() new MediaCodecFactory()
.createAdapter( .createAdapter(
MediaCodecAdapter.Configuration.createForVideoDecoding( MediaCodecAdapter.Configuration.createForVideoDecoding(
createPlaceholderMediaCodecInfo(), PLACEHOLDER_MEDIA_CODEC_INFO,
mediaFormat, mediaFormat,
format, format,
surface, surface,
@ -105,7 +117,7 @@ import java.io.IOException;
new MediaCodecFactory() new MediaCodecFactory()
.createAdapter( .createAdapter(
MediaCodecAdapter.Configuration.createForAudioEncoding( MediaCodecAdapter.Configuration.createForAudioEncoding(
createPlaceholderMediaCodecInfo(), mediaFormat, format)); PLACEHOLDER_MEDIA_CODEC_INFO, mediaFormat, format));
} catch (Exception e) { } catch (Exception e) {
throw createTransformationException(e, format, /* isVideo= */ false, /* isDecoder= */ false); throw createTransformationException(e, format, /* isVideo= */ false, /* isDecoder= */ false);
} }
@ -135,7 +147,7 @@ import java.io.IOException;
new MediaCodecFactory() new MediaCodecFactory()
.createAdapter( .createAdapter(
MediaCodecAdapter.Configuration.createForVideoEncoding( MediaCodecAdapter.Configuration.createForVideoEncoding(
createPlaceholderMediaCodecInfo(), mediaFormat, format)); PLACEHOLDER_MEDIA_CODEC_INFO, mediaFormat, format));
} catch (Exception e) { } catch (Exception e) {
throw createTransformationException(e, format, /* isVideo= */ true, /* isDecoder= */ false); throw createTransformationException(e, format, /* isVideo= */ true, /* isDecoder= */ false);
} }
@ -155,19 +167,6 @@ import java.io.IOException;
} }
} }
private static MediaCodecInfo createPlaceholderMediaCodecInfo() {
return MediaCodecInfo.newInstance(
/* name= */ "name-placeholder",
/* mimeType= */ "mime-type-placeholder",
/* codecMimeType= */ "mime-type-placeholder",
/* capabilities= */ null,
/* hardwareAccelerated= */ false,
/* softwareOnly= */ false,
/* vendor= */ false,
/* forceDisableAdaptive= */ false,
/* forceSecure= */ false);
}
private static TransformationException createTransformationException( private static TransformationException createTransformationException(
Exception cause, Format format, boolean isVideo, boolean isDecoder) { Exception cause, Format format, boolean isVideo, boolean isDecoder) {
String componentName = (isVideo ? "Video" : "Audio") + (isDecoder ? "Decoder" : "Encoder"); String componentName = (isVideo ? "Video" : "Audio") + (isDecoder ? "Decoder" : "Encoder");