package com.foxx.androidcast.media.codec;

/*********************************************************************
 * PassthroughVideoEncoderSink.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
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (2 commits, 71 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	4767eda5f9d87dcc529c1e10b9d273213b8b2ea78069d643ce282df712bc9f9d
**********************************************************************/
import android.graphics.Bitmap;
import android.view.Surface;

import com.foxx.androidcast.CastSettings;
import com.foxx.androidcast.CastTuningEngine;

import java.io.IOException;

/**
 * Delegates to hardware {@link VideoEncoderSink} while preference is a future software codec.
 */
final class PassthroughVideoEncoderSink implements VideoEncoderSink {
    private final VideoEncoderSink delegate;
    private final CastSettings.VideoCodec preference;

    PassthroughVideoEncoderSink(VideoEncoderSink delegate, CastSettings.VideoCodec preference) {
        this.delegate = delegate;
        this.preference = preference;
    }

    @Override
    public Surface getInputSurface() {
        return delegate.getInputSurface();
    }

    @Override
    public void requestKeyframe() {
        delegate.requestKeyframe();
    }

    @Override
    public Surface prepare(int width, int height, String mime, CastTuningEngine.EffectiveParams params,
            Callback callback) throws IOException {
        CodecSessionRegistry.setVideoBackend(VideoCodecBackend.LIBVPX_STUB, mime);
        return delegate.prepare(width, height, mime, params, callback);
    }

    @Override
    public void prepareBufferInput(int width, int height, String mime, CastTuningEngine.EffectiveParams params,
            Callback callback) throws IOException {
        CodecSessionRegistry.setVideoBackend(VideoCodecBackend.LIBVPX_STUB, mime);
        delegate.prepareBufferInput(width, height, mime, params, callback);
    }

    @Override
    public void queueBitmapFrame(Bitmap bitmap, long ptsUs) {
        delegate.queueBitmapFrame(bitmap, ptsUs);
    }

    @Override
    public void queueYuvFrame(byte[] yuv, long ptsUs) {
        delegate.queueYuvFrame(yuv, ptsUs);
    }

    @Override
    public void stop() {
        delegate.stop();
    }

    CastSettings.VideoCodec getPreference() {
        return preference;
    }
}
