package com.foxx.androidcast.media.codec;

/*********************************************************************
 * CodecSessionRegistry.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 CodecSessionRegistry
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (2 commits, 76 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	b76039093ae82704f2530b0b5c5dcd745a7178425ff30cf5d27dd67612009c0c
**********************************************************************/
import com.foxx.androidcast.CastSettings;

/** Active codec backends for diagnostics overlay (receiver reads sender prefs + local decode). */
public final class CodecSessionRegistry {
    private static volatile CastSettings.VideoCodec videoPreference = CastSettings.VideoCodec.AUTO;
    private static volatile CastSettings.AudioCodec audioPreference = CastSettings.AudioCodec.AUTO;
    private static volatile VideoCodecBackend videoBackend = VideoCodecBackend.UNKNOWN;
    private static volatile AudioCodecBackend audioBackend = AudioCodecBackend.UNKNOWN;
    private static volatile String negotiatedVideoMime;
    private static volatile String protectionSummary = "AUTO";

    private CodecSessionRegistry() {}

    public static void setVideoPreference(CastSettings.VideoCodec pref) {
        videoPreference = pref != null ? pref : CastSettings.VideoCodec.AUTO;
    }

    public static void setAudioPreference(CastSettings.AudioCodec pref) {
        audioPreference = pref != null ? pref : CastSettings.AudioCodec.AUTO;
    }

    public static void setVideoBackend(VideoCodecBackend backend, String negotiatedMime) {
        videoBackend = backend != null ? backend : VideoCodecBackend.UNKNOWN;
        negotiatedVideoMime = negotiatedMime;
    }

    public static void setAudioBackend(AudioCodecBackend backend) {
        audioBackend = backend != null ? backend : AudioCodecBackend.UNKNOWN;
    }

    public static void setProtectionSummary(String summary) {
        protectionSummary = summary != null ? summary : "AUTO";
    }

    public static CastSettings.VideoCodec getVideoPreference() {
        return videoPreference;
    }

    public static CastSettings.AudioCodec getAudioPreference() {
        return audioPreference;
    }

    public static VideoCodecBackend getVideoBackend() {
        return videoBackend;
    }

    public static AudioCodecBackend getAudioBackend() {
        return audioBackend;
    }

    public static String getNegotiatedVideoMime() {
        return negotiatedVideoMime;
    }

    public static String getProtectionSummary() {
        return protectionSummary;
    }

    public static void clear() {
        videoPreference = CastSettings.VideoCodec.AUTO;
        audioPreference = CastSettings.AudioCodec.AUTO;
        videoBackend = VideoCodecBackend.UNKNOWN;
        audioBackend = AudioCodecBackend.UNKNOWN;
        negotiatedVideoMime = null;
        protectionSummary = "AUTO";
    }
}
