Exemple #1
0
        private void DeckLinkInput_CaptureChanged(bool formatChanged)
        {
            logger.Debug("DeckLinkInput_StateChanged(...) " + deckLinkInput.State + " " + formatChanged);


            var state = deckLinkInput.State;

            if (formatChanged)
            {
                if (state == DeckLink.CaptureState.Starting)
                {// new format...
                    AudioRendererArgs audioArgs = GetAudioRenderArgs();
                    VideoRendererArgs videoArgs = GetVideoRenderArgs();

                    renderSession?.Setup(videoArgs, audioArgs);

                    OnCaptureInitialized();
                }
                else if (state == DeckLink.CaptureState.Capturing)
                {//  new format, restart media renderers...
                    if (renderSession != null)
                    {
                        renderSession.Close();

                        AudioRendererArgs audioArgs = GetAudioRenderArgs();
                        VideoRendererArgs videoArgs = GetVideoRenderArgs();

                        renderSession.Setup(videoArgs, audioArgs);

                        OnCaptureInitialized();

                        renderSession.Start();
                    }
                }
            }
            else
            {
                if (state == DeckLink.CaptureState.Capturing)
                {
                    renderSession?.Start();

                    OnCaptureStarted();
                }
                else if (state == DeckLink.CaptureState.Stopped)
                {
                    errorCode = deckLinkInput.ErrorCode;

                    deckLinkInput.Shutdown();

                    renderSession?.Close();

                    OnCaptureStopped();
                }
            }
        }
Exemple #2
0
        private void InitRenderSession()
        {
            AudioRendererArgs audioArgs = null;

            if (deckLinkInput.AudioEnabled)
            {
                var sampleRate    = deckLinkInput.AudioSampleRate;
                var bitsPerSample = deckLinkInput.AudioBitsPerSample;
                var channelsCount = deckLinkInput.AudioChannelsCount;

                audioArgs = new AudioRendererArgs
                {
                    DeviceId      = "",
                    SampleRate    = sampleRate,
                    BitsPerSample = bitsPerSample,
                    Channels      = channelsCount,
                    Encoding      = MediaToolkit.Core.WaveEncodingTag.PCM,
                };
            }


            var videoResoulution = deckLinkInput.FrameSize;

            var fourCC = deckLinkInput.VideoFormat.FourCC;

            var videoArgs = new VideoRendererArgs
            {
                hWnd       = windowHandle,
                Resolution = videoResoulution,
                FourCC     = fourCC,
            };

            renderSession.Setup(videoArgs, audioArgs);

            deckLinkInput.VideoDataArrived += CurrentDevice_VideoDataArrived;
            deckLinkInput.AudioDataArrived += CurrentDevice_AudioDataArrived;

            syncContext.Send(_ =>
            {
                ShowVideo();
            }, null);
        }