示例#1
0
        /*
         * Initialize the Twilio Conversations SDK
         */
        void initializeTwilioSdk()
        {
            TwilioConversations.SetLogLevel(TwilioConversations.LogLevel.Debug);

            if (!TwilioConversations.IsInitialized)
            {
                TwilioConversations.Initialize(ApplicationContext, new TwilioConversations.InitListener {
                    InitHandler = () => {
                        /*
                         * Now that the SDK is initialized we create a ConversationsClient and register for incoming calls.
                         */
                        // The TwilioAccessManager manages the lifetime of the access token and notifies the client of token expirations.
                        accessManager       = TwilioAccessManagerFactory.CreateAccessManager(accessToken, accessManagerListener());
                        conversationsClient = TwilioConversations.CreateConversationsClient(accessManager, conversationsClientListener());

                        // Specify the audio output to use for this conversation client
                        conversationsClient.AudioOutput = AudioOutput.Speakerphone;

                        // Initialize the camera capturer and start the camera preview
                        cameraCapturer = CameraCapturerFactory.CreateCameraCapturer(this, CameraCapturerCameraSource.CameraSourceFrontCamera, previewFrameLayout, capturerErrorListener());
                        startPreview();

                        // Register to receive incoming invites
                        conversationsClient.Listen();
                    },
                    ErrorHandler = err => {
                        Toast.MakeText(this,
                                       "Failed to initialize the Twilio Conversations SDK",
                                       ToastLength.Long).Show();
                    }
                });
            }
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //capture image from camera device
            this.cameraCapturer = CapturerFactory.CreateCameraCapturer(0, new Size(int.Parse("320"), int.Parse("240")), 20);
            this.cameraCapturer.ImageCaptured += new ESBasic.CbGeneric <Bitmap>(ImageCaptured);
            this.cameraCapturer.Start();

            //At the same time, capture voice from microphone device
            this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(int.Parse("0"));
            this.microphoneCapturer.AudioCaptured += new ESBasic.CbGeneric <byte[]>(microphoneCapturer_AudioCaptured);
            this.microphoneCapturer.Start();

            flag = false;
        }
示例#3
0
        private void VideoChat()
        {
            epVideoLocal  = new IPEndPoint(IPAddress.Parse(textBox1.Text), Convert.ToInt32("110"));
            epVideoRemote = new IPEndPoint(IPAddress.Parse(textBox2.Text), Convert.ToInt32("110"));
            sckVideo.Bind(epVideoLocal);
            sckVideo.Connect(epVideoRemote);


            while (true)
            {
                if (sckVideo.Poll(5000, SelectMode.SelectRead))
                {
                    if (flag == true)
                    {
                        //capture image from camera device
                        this.cameraCapturer = CapturerFactory.CreateCameraCapturer(0, new Size(int.Parse("320"), int.Parse("240")), 20);
                        this.cameraCapturer.ImageCaptured += new ESBasic.CbGeneric <Bitmap>(ImageCaptured);
                        this.cameraCapturer.Start();

                        //At the same time, capture voice from microphone device
                        this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(int.Parse("0"));
                        this.microphoneCapturer.AudioCaptured += new ESBasic.CbGeneric <byte[]>(microphoneCapturer_AudioCaptured);
                        this.microphoneCapturer.Start();

                        flag = false;
                    }
                    Console.WriteLine("There are both images and voice !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

                    MemoryStream ms   = new MemoryStream();
                    int          size = 0;

                    while (size < 230454)
                    {
                        byte[] img = new byte[230454];
                        int    r   = sckVideo.Receive(img, img.Length, SocketFlags.None);
                        size = size + r;
                        Console.WriteLine("This time, there are " + r + " datagrams" + "\n" + "And in total " + size + " have been received");
                        ms.Write(img, 0, r);
                    }
                    if (size == 230454)
                    {
                        Form1_ImageCaptured(StreamToBitmap(ms));
                    }
                }
            }
        }
示例#4
0
        //Part3 视频通信
        private void button5_Click(object sender, EventArgs e)
        {
            if (button5.Text == "视频聊天")
            {
                ipeRemote2     = new IPEndPoint(IPAddress.Parse(label1.Text.ToString()), 9000);
                cameracapturer = CapturerFactory.CreateCameraCapturer(0, new Size(int.Parse("160"), int.Parse("120")), 10);//采集格式
                cameracapturer.ImageCaptured += new ESBasic.CbGeneric <Bitmap>(ImageCaptured);

                Listen_video();
                cameracapturer.Start();
                button5.Text = "停止视频聊天";
            }
            else
            {
                cameracapturer.Stop();
                ListenThread_video.Suspend();
                pictureBox1.Image = null;
                pictureBox2.Image = null;
                button5.Text      = "视频聊天";
            }
        }
示例#5
0
        /// <summary>
        /// 采用默认设置构造一个记录仪。
        /// </summary>
        public Recorder(ImageDelegate onImgCaptured) {
            instanceCount++;
            if (instanceCount > MAX_INSTANCE_COUNT) {
                throw new ApplicationException("当前仅支持一个记录仪实例。");
            }


            if (DEFAULT_VIDEO_WIDTH % 4 != 0 || DEFAULT_VIDEO_HEIGHT % 4 != 0) {
                throw new Exception("视频长度及宽度必须均设置为4的倍数。");
            }


            timing = new TimingHelper();
            this.cameraCapturer = DEFAULT_CAMERA_CAPTURE;
            this.cameraCapturer.ImageCaptured += new CbGeneric<Bitmap>(this.OnImageCaptured1);
            this.microphoneCapturer = DEFAULT_MICROPHONE_CAPTURE;
            this.microphoneCapturer.AudioCaptured += OnAudioMixed;

            this.onImageCaptured = onImgCaptured;
        }
示例#6
0
        private void button_Start_Click(object sender, RoutedEventArgs e)
        {
            //TODO 开始录制桌面,依据 声音复选框 来选择使用 声卡 麦克风 还是混合录制
            //TODO label 中显示实际录制的时间,需要考虑暂停和恢复这种情况。 格式为 hh:mm:ss
            if (string.IsNullOrEmpty(this.filePath.Text) || string.IsNullOrEmpty(this.fileNmae.Text))
            {
                MessageBox.Show("文件路径和文件名!");
                return;
            }
            else if (File.Exists(System.IO.Path.Combine(this.filePath.Text, this.fileNmae.Text)))
            {
                MessageBox.Show("文件已经存在");
                return;
            }
            try
            {
                int audioSampleRate = 16000;
                int channelCount    = 1;
                seconds = 0;

                System.Drawing.Size videoSize = Screen.PrimaryScreen.Bounds.Size;
                this.justRecordAudio = this.radioButton_justAudio.IsChecked.Value;

                if (this.justRecordAudio && this.checkBox_micro.IsChecked == false && this.checkBox_soundCard.IsChecked == false)
                {
                    MessageBox.Show("一定要选择一个声音的采集源!");
                    return;
                }

                #region 设置采集器
                if (this.radioButton_desktop.IsChecked == true)
                {
                    //桌面采集器

                    //如果需要录制鼠标的操作,第二个参数请设置为true
                    this.desktopCapturer = CapturerFactory.CreateDesktopCapturer(frameRate, false);
                    this.desktopCapturer.ImageCaptured += ImageCaptured;
                    videoSize = this.desktopCapturer.VideoSize;
                }
                else if (this.radioButton_camera.IsChecked == true)
                {
                    //摄像头采集器
                    videoSize           = new System.Drawing.Size(int.Parse(this.textBox_width.Text), int.Parse(this.textBox_height.Text));
                    this.cameraCapturer = CapturerFactory.CreateCameraCapturer(0, videoSize, frameRate);
                    this.cameraCapturer.ImageCaptured += new CbGeneric <Bitmap>(ImageCaptured);
                }

                if (this.checkBox_micro.IsChecked == true)
                {
                    //麦克风采集器
                    this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(0);
                    this.microphoneCapturer.CaptureError += capturer_CaptureError;
                }

                if (this.checkBox_soundCard.IsChecked == true)
                {
                    //声卡采集器 【目前声卡采集仅支持vista以及以上系统】
                    this.soundcardCapturer = CapturerFactory.CreateSoundcardCapturer();
                    this.soundcardCapturer.CaptureError += capturer_CaptureError;
                    audioSampleRate = this.soundcardCapturer.SampleRate;
                    channelCount    = this.soundcardCapturer.ChannelCount;
                }

                if (this.checkBox_micro.IsChecked == true && this.checkBox_soundCard.IsChecked == true)
                {
                    //混音器
                    this.audioMixter             = CapturerFactory.CreateAudioMixter(this.microphoneCapturer, this.soundcardCapturer, SoundcardMode4Mix.DoubleChannel, true);
                    this.audioMixter.AudioMixed += audioMixter_AudioMixed; //如果是混音,则不再需要预订microphoneCapturer和soundcardCapturer的AudioCaptured事件
                    audioSampleRate              = this.audioMixter.SampleRate;
                    channelCount = this.audioMixter.ChannelCount;
                }
                else if (this.checkBox_micro.IsChecked == true)
                {
                    this.microphoneCapturer.AudioCaptured += audioMixter_AudioMixed;
                }
                else if (this.checkBox_soundCard.IsChecked == true)
                {
                    this.soundcardCapturer.AudioCaptured += audioMixter_AudioMixed;
                }
                #endregion

                #region 开始采集
                if (this.checkBox_micro.IsChecked == true)
                {
                    this.microphoneCapturer.Start();
                }
                if (this.checkBox_soundCard.IsChecked == true)
                {
                    this.soundcardCapturer.Start();
                }

                if (this.radioButton_camera.IsChecked == true)
                {
                    this.cameraCapturer.Start();
                }
                else if (this.radioButton_desktop.IsChecked == true)
                {
                    this.desktopCapturer.Start();
                }
                #endregion

                #region 录制组件
                if (this.justRecordAudio) //仅仅录制声音
                {
                    this.audioFileMaker = new AudioFileMaker();
                    this.audioFileMaker.Initialize("test.mp3", audioSampleRate, channelCount);
                }
                else
                {
                    //宽和高修正为4的倍数
                    this.sizeRevised = (videoSize.Width % 4 != 0) || (videoSize.Height % 4 != 0);
                    if (this.sizeRevised)
                    {
                        videoSize = new System.Drawing.Size(videoSize.Width / 4 * 4, videoSize.Height / 4 * 4);
                    }

                    if (this.checkBox_micro.IsChecked == false && this.checkBox_soundCard.IsChecked == false) //仅仅录制图像
                    {
                        this.justRecordVideo       = true;
                        this.silenceVideoFileMaker = new SilenceVideoFileMaker();
                        this.silenceVideoFileMaker.Initialize(System.IO.Path.Combine(this.filePath.Text, this.fileNmae.Text) + ".mp4", VideoCodecType.H264, videoSize.Width, videoSize.Height, frameRate, VideoQuality.Middle);
                    }
                    else //录制声音+图像
                    {
                        this.justRecordVideo = false;
                        this.videoFileMaker  = new VideoFileMaker();
                        this.videoFileMaker.Initialize(System.IO.Path.Combine(this.filePath.Text, this.fileNmae.Text) + ".mp4", VideoCodecType.H264, videoSize.Width, videoSize.Height, frameRate, VideoQuality.High, AudioCodecType.AAC, audioSampleRate, channelCount, true);
                    }
                }
                #endregion

                this.isRecording = true;
                this.isParsing   = false;
                this.timer.Start();

                this.checkBox_micro.IsEnabled        = false;
                this.checkBox_soundCard.IsEnabled    = false;
                this.radioButton_desktop.IsEnabled   = false;
                this.radioButton_camera.IsEnabled    = false;
                this.radioButton_justAudio.IsEnabled = false;

                this.button_Start.IsEnabled = false;
            }
            catch (Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
        }