Example #1
0
        private void InitializeCaptureSource()
        {
            if (captureSource == null)
            {
                mediaElement      = new MediaElement();
                audioStreamSource = new TestAudioStreamSource(this);
                mediaElement.SetSource(audioStreamSource);

                // Set the audio properties.
                captureSource = new CaptureSource();
                captureSource.AudioCaptureDevice = CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
                if (captureSource.AudioCaptureDevice != null)
                {
                    MediaDeviceConfig.SelectBestAudioFormat(captureSource.AudioCaptureDevice);
                    if (captureSource.AudioCaptureDevice.DesiredFormat != null)
                    {
                        captureSource.AudioCaptureDevice.AudioFrameSize = AudioFormat.Default.MillisecondsPerFrame; // 20 milliseconds
                        audioSink = new TestAudioSinkAdapter(captureSource);
                        audioSink.ProcessedFrameAvailable += audioSink_FrameArrived;
                        ClientLogger.Debug("CaptureSource initialized.");
                    }
                    else
                    {
                        ClientLogger.Debug("No suitable audio format was found.");
                    }
                }
                else
                {
                    // Do something more here eventually, once we figure out what the user experience should be.
                    ClientLogger.Debug("No audio capture device was found.");
                }
            }
        }
Example #2
0
        private void InitializeCaptureSource()
        {
            if (captureSource != null)
            {
                captureSource.Stop();
            }
            captureSource = new CaptureSource();
            captureSource.AudioCaptureDevice = (AudioCaptureDevice)listBoxAudioSources.SelectedItem;

            MediaDeviceConfig.SelectBestAudioFormat(captureSource.AudioCaptureDevice);

            captureSource.AudioCaptureDevice.DesiredFormat = captureSource.AudioCaptureDevice.SupportedFormats
                                                             .First(format => format.BitsPerSample == AudioConstants.BitsPerSample &&
                                                                    format.WaveFormat == WaveFormatType.Pcm &&
                                                                    format.Channels == 1 &&
                                                                    format.SamplesPerSecond == sampleRate);
            captureSource.AudioCaptureDevice.AudioFrameSize = AudioFormat.Default.MillisecondsPerFrame;             // 20 milliseconds

            audioSink = new TestAudioSinkAdapter(captureSource, new NullAudioController());
            audioSink.RawFrameAvailable       += audioSink_RawFrameAvailable;
            audioSink.ProcessedFrameAvailable += audioSink_FrameArrived;

            ClientLogger.Debug("Checking device access.");
            if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
            {
                savedFramesForDebug = new List <byte[]>();
                captureSource.Start();
                ClientLogger.Debug("CaptureSource started.");
            }
        }
Example #3
0
        private void InitializeCaptureSource()
        {
            ClientLogger.Debug("AudioLoopbackTest:InitializeCaptureSource()");
            if (_captureSource != null)
            {
                _captureSource.Stop();
            }
            _captureSource = new CaptureSource();
            _captureSource.AudioCaptureDevice = (AudioCaptureDevice)lstAudioInputDevices.SelectedItem;
            _captureSource.VideoCaptureDevice = (VideoCaptureDevice)lstVideoInputDevices.SelectedItem;
            _mediaElement      = new MediaElement();
            _audioStreamSource = new TestAudioStreamSource(this);


            // Set the audio properties.
            if (_captureSource.AudioCaptureDevice != null)
            {
                MediaDeviceConfig.SelectBestAudioFormat(_captureSource.AudioCaptureDevice);
                if (_captureSource.AudioCaptureDevice.DesiredFormat != null)
                {
                    _captureSource.AudioCaptureDevice.AudioFrameSize = _audioFormat.MillisecondsPerFrame;                     // 20 milliseconds
                    _audioSink = new TestAudioSinkAdapter(_captureSource, new NullAudioController());
                    _audioSink.RawFrameAvailable       += audioSink_RawFrameAvailable;
                    _audioSink.ProcessedFrameAvailable += audioSink_FrameArrived;
                    ClientLogger.Debug("CaptureSource initialized.");
                }
                else
                {
                    ClientLogger.Debug("No suitable audio format was found.");
                }

                ClientLogger.Debug("Checking device access.");
                if (CaptureDeviceConfiguration.AllowedDeviceAccess || CaptureDeviceConfiguration.RequestDeviceAccess())
                {
                    ClientLogger.Debug("AudioLoopbackTest CaptureSource starting with audio device {0}, video device {1}.",
                                       _captureSource.AudioCaptureDevice.FriendlyName, _captureSource.VideoCaptureDevice.FriendlyName);
                    _captureSource.Start();
                    ClientLogger.Debug("CaptureSource started; setting media element source.");
                    _mediaElement.SetSource(_audioStreamSource);
                    ClientLogger.Debug("MediaElement source set; telling media element to play.");
                    _mediaElement.Play();
                }
            }
            else
            {
                // Do something more here eventually, once we figure out what the user experience should be.
                ClientLogger.Debug("No audio capture device was found.");
            }
        }