package com.foxx.androidcast.receiver.av;

import android.content.Context;

/** Live receiver A/V pipelines (reloaded from developer settings). */
public final class ReceiverAvRuntime {
    private static volatile ReceiverVideoPipeline videoPipeline = ReceiverVideoPipeline.passthrough();
    private static volatile AudioFilterChain audioChain = AudioFilterChain.passthrough();

    private ReceiverAvRuntime() {}

    public static ReceiverVideoPipeline video() {
        return videoPipeline;
    }

    public static AudioFilterChain audio() {
        return audioChain;
    }

    public static void reload(Context context) {
        Context app = context.getApplicationContext();
        videoPipeline = ReceiverAvPipelineFactory.createVideo(app);
        audioChain = ReceiverAvPipelineFactory.createAudio(app);
        audioChain.reset(48_000, 2);
        if (!ReceiverVideoGlHub.isGlMode(app)) {
            ReceiverVideoGlHub.release(app);
        } else {
            ReceiverVideoGlHub.refreshPreset(app);
        }
    }
}
