示例#1
0
        public void VideoRequest(String targetNeck, VideoMirror.OnFrameReceivedHandler onFRH)
        {
            // 获取本机的发送接收端口
            int thisSendPort = NetResource.Instance.GetNextUDPPort();
            int thisRecvPort = NetResource.Instance.GetNextUDPPort();

            // 初始化视频
            VideoMgr.InitVideoAsRequest(targetNeck, thisSendPort, thisRecvPort, onFRH);

            // 发送请求消息
            String dataStr = System.Convert.ToChar(CProtocol.VideoRequest).ToString();

            dataStr += ((char)System.Text.Encoding.UTF8.GetBytes(targetNeck).Length).ToString();
            dataStr += targetNeck;
            dataStr += ((char)thisSendPort).ToString();
            dataStr += ((char)thisRecvPort).ToString();
            sendData(dataStr);
        }
示例#2
0
        // 以视频接收方初始化
        public void InitVideoAsResponse(String otherNeck,
                                        int thisSendPort, int thisRecvPort,
                                        IPAddress otherIP,
                                        int otherSendPort, int otherRecvPort,
                                        VideoMirror.OnFrameReceivedHandler srcEP)
        {
            foreach (VideoMirror vr in videoList)
            {
                if (otherNeck == vr.OtherNeck)
                {
                    throw new Exception("视频连接重复!");
                }
            }

            VideoMirror newTarget = new VideoMirror(otherNeck);

            newTarget.thisSendEP            = new IPEndPoint(ChaitClient.Instance.LocalIP, thisSendPort);
            newTarget.thisRecvEP            = new IPEndPoint(ChaitClient.Instance.LocalIP, thisRecvPort);
            newTarget.otherSendEP           = new IPEndPoint(otherIP, otherSendPort);
            newTarget.otherRecvEP           = new IPEndPoint(otherIP, otherRecvPort);
            newTarget.OnFrameReceivedEvent += srcEP;

            videoList.Add(newTarget);
        }
示例#3
0
        public void AcceptVideo(String otherNeck, IPAddress otherIP, int otherSendPort, int otherRecvPort, VideoMirror.OnFrameReceivedHandler onFRH)
        {
            // 视频收发准备
            int thisSendPort = NetResource.Instance.GetNextUDPPort();
            int thisRecvPort = NetResource.Instance.GetNextUDPPort();

            // 初始化视频
            VideoMgr.InitVideoAsResponse(otherNeck, thisSendPort, thisRecvPort, otherIP, otherSendPort, otherRecvPort, onFRH);

            // 发送接受消息
            String dataStr = System.Convert.ToChar(CProtocol.VideoAccept).ToString();

            dataStr += ((char)System.Text.Encoding.UTF8.GetBytes(otherNeck).Length).ToString();
            dataStr += otherNeck;
            dataStr += ((char)thisSendPort).ToString();
            dataStr += ((char)thisRecvPort).ToString();
            sendData(dataStr);

            // 开始收发视频
            VideoMgr.BeginSession(otherNeck);


            // 另一种方式..
            //          注意参数:           对方昵称   对方EP   自己Port 接受回调
            // VideoMgr.BeginSession(otherNeck, otherEP.Address.ToString(), otherEP.Port, thisPort, onFRH);
        }
示例#4
0
        // 以视频发起方初始化
        public void InitVideoAsRequest(String tgtNeck, int thisSendPort, int thisRecvPort, VideoMirror.OnFrameReceivedHandler onFRH)
        {
            foreach (VideoMirror vs in videoList)
            {
                if (tgtNeck == vs.OtherNeck)
                {
                    throw new Exception(String.Format("视频连接重复!已经存在一个和{0}之间的视频回话", tgtNeck));
                }
            }

            VideoMirror newSource = new VideoMirror(tgtNeck);

            newSource.thisSendEP            = new IPEndPoint(ChaitClient.Instance.LocalIP, thisSendPort);
            newSource.thisRecvEP            = new IPEndPoint(ChaitClient.Instance.LocalIP, thisRecvPort);
            newSource.OnFrameReceivedEvent += onFRH;

            videoList.Add(newSource);
        }