Пример #1
0
    /// <summary>
    /// 发送视频数据
    /// </summary>
    void SendVideo()
    {
        //获取SDK捕捉的视频数据
        VideoPacket packet = UnityChatSDK.Instance.GetVideo();

        if (packet != null)
        {
            packet.Id = ChatManager.Instance.UserID;
            byte[] video = GetPbVideoPacket(packet).ToByteArray();

            udpPacketIndex++;
            List <UdpPacket> list = UdpPacketSpliter.Split(udpPacketIndex, video, ChunkLength);
            for (int i = 0; i < list.Count; i++)
            {
                UdplDataModel model = new UdplDataModel();
                model.Request = RequestByte.REQUEST_VIDEO;

                CallInfo info = new CallInfo();
                info.UserID = ChatManager.Instance.UserID;
                info.CallID = ChatManager.Instance.CallID;
                info.PeerList.Add(ChatManager.Instance.ChatPeerID);

                model.ChatInfoData = info.ToByteArray();
                model.ChatData     = UdpPacketEncode(list[i]);

                UdpSocketManager.Instance.Send(UdpMessageCodec.Encode(model));
            }
        }
    }
Пример #2
0
    /// <summary>
    /// 发送视频数据
    /// </summary>
    void SendVideo()
    {
        //获取SDK捕捉的视频数据
        byte[] video = UnityChatSDK.Instance.GetVideo();

        if (video != null)
        {
            udpPacketIndex++;
            List <UdpPacket> list = UdpPacketSpliter.Split(udpPacketIndex, video, ChunkLength);
            for (int i = 0; i < list.Count; i++)
            {
                UdpSocketManager._instance.Send(EncodeChatDataID(UdpPacketEncode(list[i]), RequestByte.REQUEST_VIDEO));
            }
        }
    }
Пример #3
0
    /// <summary>
    /// Send video data
    /// </summary>
    IEnumerator SendVideo()
    {
        //Get video data by SDK
        VideoPacket packet = UnityChatSDK.Instance.GetVideo();

        if (UnityChatSDK.Instance.EnableSync)
        {
            if (packet != null)
            {
                videoPacketQueue.Enqueue(packet);
            }

            if (videoPacketQueue.Count >= UnityChatSDK.Instance.Framerate / UnityChatSDK.Instance.AudioSample)
            {
                packet = videoPacketQueue.Dequeue();
            }
            else
            {
                yield return(null);
            }
        }

        if (packet != null)
        {
            packet.Id = ChatManager.Instance.UserID;
            byte[] video = GetPbVideoPacket(packet).ToByteArray();

            udpPacketIndex++;
            List <UdpPacket> list = UdpPacketSpliter.Split(udpPacketIndex, video, ChunkLength);

            UdplDataModel model = new UdplDataModel();
            model.Request = UdpRequest.REQUEST_VIDEO;
            IMInfo info = new IMInfo();
            info.UserID = ChatManager.Instance.UserID;
            info.CallID = ChatManager.Instance.CallID;
            info.UserList.Add(ChatManager.Instance.ChatPeers);
            model.ChatInfoData = info.ToByteArray();

            for (int i = 0; i < list.Count; i++)
            {
                model.ChatData = UdpPacketEncode(list[i]);
                UdpSocketManager.Instance.Send(UdpMessageCodec.Encode(model));
                yield return(new WaitForSeconds(0.01f));
            }
        }
    }
Пример #4
0
    /// <summary>
    /// 发送视频数据
    /// </summary>
    private async void SendVideo()
    {
        //获取SDK捕捉的视频数据
        VideoPacket packet = await CameraHelper.Instance.GetVideo();

        if (ConfigManager.ENABLE_SYNC)
        {
            if (packet != null)
            {
                videoPacketQueue.Enqueue(packet);
            }

            if (videoPacketQueue.Count >= ConfigManager.FRAME_RATE / ConfigManager.AUDIO_SAMPLE)
            {
                packet = videoPacketQueue.Dequeue();
            }
            else
            {
                return;
            }
        }

        if (packet != null)
        {
            packet.Id = ConfigManager.LOCAL_ID;
            byte[] video = VideoPack2ProtobufPack(packet).ToByteArray();

            udpPacketIndex++;
            List <UdpPacket> list = UdpPacketSpliter.Split(udpPacketIndex, video, ChunkLength);
            for (int i = 0; i < list.Count; i++)
            {
                UdplDataModel model = new UdplDataModel();
                model.Request = RequestByte.REQUEST_VIDEO;

                CallInfo info = new CallInfo();
                info.UserID = ConfigManager.LOCAL_ID;
                info.CallID = ConfigManager.CALL_ID;
                info.PeerList.Add(ConfigManager.REMOTE_ID);

                model.ChatInfoData = info.ToByteArray();
                model.ChatData     = UdpPacketEncode(list[i]);

                UdpSocketManager.Instance.Send(UdpMessageCodec.Encode(model));
            }
        }
    }
    /// <summary>
    /// Send video data
    /// </summary>
    IEnumerator SendVideo()
    {
        //Get video data by SDK
        VideoPacket packet = UnityChatSDK.Instance.GetVideo();

        if (UnityChatSDK.Instance.EnableSync)
        {
            if (packet != null)
            {
                videoPacketQueue.Enqueue(packet);
            }

            if (videoPacketQueue.Count >= UnityChatSDK.Instance.Framerate / UnityChatSDK.Instance.AudioSample)
            {
                packet = videoPacketQueue.Dequeue();
            }
            else
            {
                yield return(null);
            }
        }

        if (packet != null)
        {
            packet.Id = ChatManager.Instance.UserID;
            byte[] video = GetPbVideoPacket(packet).ToByteArray();

            switch (NetType)
            {
            case NetType.UdpStream:

                udpPacketIndex++;
                List <UdpPacket> list = UdpPacketSpliter.Split(udpPacketIndex, video, ChunkLength);

                UdplDataModel model = new UdplDataModel();
                model.Request = UdpRequest.REQUEST_VIDEO;
                IMInfo info = new IMInfo();
                info.UserID = ChatManager.Instance.UserID;
                info.CallID = ChatManager.Instance.CallID;
                info.UserList.Add(ChatManager.Instance.ChatPeers);
                model.ChatInfoData = info.ToByteArray();

                for (int i = 0; i < list.Count; i++)
                {
                    model.ChatData = UdpPacketEncode(list[i]);
                    UdpSocketManager.Instance.Send(UdpMessageCodec.Encode(model));
                    yield return(new WaitForSeconds(0.01f));
                }

                break;

            case NetType.TcpStream:

                if (video != null)
                {
                    DataModel tcpVideoData = new DataModel();
                    tcpVideoData.Type    = ChatProtocolType.TYPE_CHATDATA;
                    tcpVideoData.Request = ChatDataProtocol.CHAT_VIDEO;
                    tcpVideoData.Message = video;
                    ChatNetworkManager.Instance.Send(tcpVideoData);
                }

                break;

            default:
                break;
            }
        }
    }