package com.foxx.androidcast.media.codec;

/*********************************************************************
 * VideoCodecFactory.java
 * Created at: Sun 17 May 2026 22:49:49 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class VideoCodecFactory
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (3 commits, 34 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	219cb0001dd6b968ca3039a8519888d4be431d9060e0843efed4b926b692f357
**********************************************************************/
import com.foxx.androidcast.CastSettings;
import com.foxx.androidcast.media.codec.jni.NativeCodecBridge;
import com.foxx.androidcast.sender.VideoEncoder;

/** Creates video encoder sinks; libvpx used when native library is linked. */
public final class VideoCodecFactory {
    private VideoCodecFactory() {}

    public static VideoEncoderSink createEncoder(CastSettings.VideoCodec preference) {
        CodecSessionRegistry.setVideoPreference(preference);
        if (preference == CastSettings.VideoCodec.LIBVPX_VP8
                || preference == CastSettings.VideoCodec.LIBVPX_VP9) {
            if (NativeCodecBridge.isLibvpxAvailable()) {
                return new LibvpxVideoEncoderSink(preference);
            }
            CodecSessionRegistry.setVideoBackend(VideoCodecBackend.MEDIA_CODEC_HW, null);
            return new PassthroughVideoEncoderSink(new VideoEncoder(), preference);
        }
        VideoCodecBackend backend = PassthroughCodecPolicy.videoBackendFor(preference);
        if (backend == VideoCodecBackend.PASSTHROUGH) {
            return new PassthroughVideoEncoderSink(new VideoEncoder(), preference);
        }
        return new VideoEncoder();
    }
}
