using Scenes.scripts.utils;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine;

//���ͷ����ͻ���
public class TransmissionClient
{ 
    private static string UXR_TEXTURE_Send = "Sender.";
    private static AndroidJavaObject transmissionClient;

    public const int DefaultFrameRate = 60;
    public const int DefaultBitRate = 1024;

    //Start
    public static void Create()
    {
        Debug.Log("TransmissionClient Create");

        //�������Ͷ�
        transmissionClient = new AndroidJavaObject("com.rokid.mrcplugin.glass.codingtransmission.TransmissionClient");
    }

    public static void Start(int unityTextureId, int width, int height, int frameRate = 60, int bitRate = 1024)
    {
        Debug.Log($"TransmissionClient.Start TexID - {unityTextureId} Width - {width} Height - {height} FrameRate - {frameRate} BitRate - {bitRate}");
        
        CallBridge.callAndroid(Request.Build()
            .Name(UXR_TEXTURE_Send + "start")
            .Param("unityTextureId", unityTextureId)
            .Param("width", width)
            .Param("height", height)
            .Param("frameRate", frameRate)
            .Param("bitRate", bitRate * 1024));

        transmissionClient = CallBridge.callAndroid(Request.Build()
            .Name(UXR_TEXTURE_Send + "getInstance"));
    }

    public static void Release()
    {
        Debug.Log("TransmissionClient Release");

        transmissionClient.Call("release");
    }

    public static void UpdateTextureData()
    {
        transmissionClient?.Call("updateTextureData");
    }

    public static void PushTextureByteData(byte[] data, int length)
    {

#if !UNITY_EDITOR
        TransmissionClient_PushTextureData(data, length);
#endif
        transmissionClient.Call("updateTextureData");
    }

    [DllImport("transmissionlib")]
    private static extern void TransmissionClient_PushTextureData(byte[] data, int length);
}
