camera/camera-video/src/main/java/androidx/camera/video/internal/workaround/EncoderFinder.java
/**
     * Selects an encoder by a given MediaFormat.
     *
     * <p>The encoder finder might temporarily alter the media format for better compatibility
     * based on OS version. It is not thread safe to use the same media format instance.
     *
     * @param mediaFormat the media format used to find the encoder.
     * @return the MediaCodec suitable for the given media format.
     * @throws InvalidConfigException if it is not able to find a MediaCodec by the given media
     * format.
     */
Selects an encoder by a given MediaFormat.
The encoder finder might temporarily alter the media format for better compatibility
based on OS version. It is not thread safe to use the same media format instance.

@param mediaFormat the media format used to find the encoder.
@return the MediaCodec suitable for the given media format.
@throws InvalidConfigException if it is not able to find a MediaCodec by the given media
format.
Selects an encoder by a given MediaFormat . The encoder finder might temporarily alter the media format for better compatibility based on OS version . It is not thread safe to use the same media format instance . @param mediaFormat the media format used to find the encoder . @return the MediaCodec suitable for the given media format . @throws InvalidConfigException if it is not able to find a MediaCodec by the given media format .
@NonNull
    public MediaCodec findEncoder(@NonNull MediaFormat mediaFormat,
            @NonNull MediaCodecList mediaCodecList) throws InvalidConfigException {
        MediaCodec codec;
        String encoderName = findEncoderForFormat(mediaFormat, mediaCodecList);
        try {
            if (TextUtils.isEmpty(encoderName)) {
                String mimeType = mediaFormat.getString(MediaFormat.KEY_MIME);
                codec = MediaCodec.createEncoderByType(mimeType);
                String msg = DebugUtils.dumpCodecCapabilities(mimeType, codec, mediaFormat);
                Logger.w(TAG, String.format("No encoder found that supports requested MediaFormat "
                                + "%s. Create encoder by MIME type. Dump codec info:\n%s",
                        mediaFormat, msg));
            } else {
                codec = MediaCodec.createByCodecName(encoderName);
            }
        } catch (IOException | NullPointerException | IllegalArgumentException e) {
            boolean isMediaFormatInQuirk = shouldCreateCodecByType(mediaFormat);
            String msg = DebugUtils.dumpMediaCodecListForFormat(mediaCodecList, mediaFormat);
            throw new InvalidConfigException(
                    "Encoder cannot created: " + encoderName + ", isMediaFormatInQuirk: "
                            + isMediaFormatInQuirk + "\n" + msg, e);
        }
        return codec;
    }
@ NonNull public MediaCodec findEncoder ( @ NonNull MediaFormat mediaFormat , @ NonNull MediaCodecList mediaCodecList ) throws InvalidConfigException { MediaCodec codec ; String encoderName = findEncoderForFormat ( mediaFormat , mediaCodecList ) ; try { if ( TextUtils . isEmpty ( encoderName ) ) { String mimeType = mediaFormat . getString ( MediaFormat . KEY_MIME ) ; codec = MediaCodec . createEncoderByType ( mimeType ) ; String msg = DebugUtils . dumpCodecCapabilities ( mimeType , codec , mediaFormat ) ; Logger . w ( TAG , String . format ( "No encoder found that supports requested MediaFormat " + "%s. Create encoder by MIME type. Dump codec info:\n%s" , mediaFormat , msg ) ) ; } else { codec = MediaCodec . createByCodecName ( encoderName ) ; } } catch ( IOException | NullPointerException | IllegalArgumentException e ) { boolean isMediaFormatInQuirk = shouldCreateCodecByType ( mediaFormat ) ; String msg = DebugUtils . dumpMediaCodecListForFormat ( mediaCodecList , mediaFormat ) ; throw new InvalidConfigException ( "Encoder cannot created: " + encoderName + ", isMediaFormatInQuirk: " + isMediaFormatInQuirk + "\n" + msg , e ) ; } return codec ; }
Selects an encoder by a given MediaFormat.
Selects an encoder by a given MediaFormat .