Beispiel #1
0
        /// <summary>
        /// 初始化音视频通信组件
        /// </summary>
        /// <param name="Model">视频显示大小模式</param>
        public void iniAV(VideoSizeModel Model, System.Net.IPEndPoint ServerEP)
        {
            if (!IsIni)
            {
                IsIni = true;//标识已经初始化
            }
            else
            {
                return;                //如果已经初始化,则退出
            }
            VideoSize.SetModel(Model); //设置视频编码尺寸

            if (cam == null)
            {
                iniVideoCapturer();
            }

            #region //创建新的视频捕捉组件
            //if (VC == null)
            //{
            //    VC = new  VideoCapturer(this.cLocal);
            //    VC.VideoCapturerBefore += new VideoCapturer.VideoCaptureredEventHandler(VC_VideoCapturerBefore);
            //    VC.VideoDataCapturered += new VideoCapturer.VideoCaptureredEventHandler(VC_VideoDataCapturered);
            //    VC.StartVideoCapture(Model);//开始捕捉视频
            //}
            #endregion

            if (AE == null)
            {
                AE = new AudioEncoder();//创建G711音频编解码器
            }

            if (AC == null)
            {
                AC = new AudioCapturer(this.trackBarOut, this.trackBarIn);//创建新的音频捕捉组件
                AC.AudioDataCapturered += new AudioCapturer.AudioDataCaptureredEventHandler(AC_AudioDataCapturered);
            }

            if (AR == null)
            {
                AR = new AudioRender();//创建G711音频回放组件
            }

            if (frameTransmit == null)
            {
                frameTransmit = new FrameTransmit(ServerEP);
                frameTransmit.GetIPEndPoint     += new FrameTransmit.GetIPEndPointEventHandler(frameTransmit_GetIPEndPoint);
                frameTransmit.RecAudioData      += new FrameTransmit.RecDataEventHandler(frameTransmit_RecAudioData);
                frameTransmit.RecVideoData      += new FrameTransmit.RecDataEventHandler(frameTransmit_RecVideoData);
                frameTransmit.TransmitConnected += new FrameTransmit.TransmitEventHandler(frameTransmit_TransmitConnected);
                frameTransmit.Start();
            }
        }
Beispiel #2
0
        //收到视频数据
        private void frameTransmit_RecVideoData(object sender, byte[] data)
        {
            Console.WriteLine("RecVideoData:" + data.Length.ToString());

            //if (this.VD != null && this.VR != null)
            //{
            //    this.VR.DrawVideo(this.VD.Decode(data));//将收到的视频数据解码后回显
            //}

            VideoSize.SetModel(VideoSizeModel.W320_H240);
            if (data.Length > 0)
            {
                Byte[] localDecodeArray = decoder.Decode(data);
                if (localDecodeArray != null)
                {
                    Console.WriteLine(localDecodeArray.Length.ToString());
                    Bitmap pBmp = StreamCoders.Tools.Visuals.ByteArrayToBitmap_RGB24(VideoSize.Width, VideoSize.Height, localDecodeArray);
                    using (Graphics pGfx = cRemote.CreateGraphics())
                    {
                        pGfx.DrawImage(pBmp, 0, 0, cRemote.Width, cRemote.Height);
                    }
                }
            }
        }