/// <summary>
        /// MediaPlayer.MediaOpened event handler. Completes frame source initialization
        /// by allocating frame buffer and registering for VideoFrameAvailable event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void MediaPlayer_MediaOpened(MediaPlayer sender, object args)
        {
            // Retrieve media source resolution
            FrameWidth  = m_mediaPlayer.PlaybackSession.NaturalVideoWidth;
            FrameHeight = m_mediaPlayer.PlaybackSession.NaturalVideoHeight;

            // Allocate and register for frames
            m_videoFrame = VideoFrame.CreateAsDirect3D11SurfaceBacked(
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                (int)FrameWidth,
                (int)FrameHeight);

            // If a desired format was specified, create a staging VideoFrame to convert to when an image is obtained from the source before sending it out
            if (m_desiredImageDescriptor != null)
            {
                m_stagingVideoFrame = new VideoFrame(
                    m_desiredImageDescriptor.SupportedBitmapPixelFormat,
                    m_desiredImageDescriptor.Width == -1 ? (int)FrameWidth : m_desiredImageDescriptor.Width,
                    m_desiredImageDescriptor.Height == -1 ? (int)FrameHeight : m_desiredImageDescriptor.Height,
                    m_desiredImageDescriptor.SupportedBitmapAlphaMode);
            }

            m_mediaPlayer.VideoFrameAvailable += MediaPlayer_VideoFrameAvailable;

            m_frameSourceReadyEvent.Set();
        }
Example #2
0
        /// <summary>
        /// Configure an IFrameSource from a StorageFile or MediaCapture instance
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        private async Task ConfigureFrameSourceAsync(object source)
        {
            await m_skillLock.WaitAsync();

            {
                // Clean up previous frame source
                if (m_frameSource != null)
                {
                    m_frameSource.FrameArrived -= frameSource_FrameAvailable;
                    var disposableFrameSource = m_frameSource as IDisposable;
                    if (disposableFrameSource != null)
                    {
                        // Lock disposal based on frame source consumers
                        disposableFrameSource.Dispose();
                    }
                }

                // Create new frame source
                m_frameSource = await FrameSource.FrameSourceFactory.CreateFrameSourceAsync(source);

                m_cachedFrameForProcessing = VideoFrame.CreateAsDirect3D11SurfaceBacked(
                    DirectXPixelFormat.B8G8R8A8UIntNormalized,
                    (int)m_frameSource.FrameWidth,
                    (int)m_frameSource.FrameHeight);
                m_frameSource.FrameArrived += frameSource_FrameAvailable;
            }
            m_skillLock.Release();

            // Start frame source outside of lock so that skill can run
            await m_frameSource.StartAsync();
        }
Example #3
0
        public void SetEncodingProperties(VideoEncodingProperties encodingProperties, IDirect3DDevice device)
        {
            canvasDevice = CanvasDevice.CreateFromDirect3D11Device(device);
            output       = VideoFrame.CreateAsDirect3D11SurfaceBacked(DirectXPixelFormat.R8G8B8A8UIntNormalized, 128, 96, canvasDevice);

            features = new Dictionary <string, object>();
            features.Add("0", null);
            features.Add("794", output);
        }
Example #4
0
        /// <summary>
        /// MediaPlayer.MediaOpened event handler. Completes frame source initialization
        /// by allocating frame buffer and registering for VideoFrameAvailable event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void mediaPlayer_MediaOpened(MediaPlayer sender, object args)
        {
            // Retrieve media source resolution
            FrameWidth  = m_mediaPlayer.PlaybackSession.NaturalVideoWidth;
            FrameHeight = m_mediaPlayer.PlaybackSession.NaturalVideoHeight;

            // Allocate and register for frames
            m_videoFrame = VideoFrame.CreateAsDirect3D11SurfaceBacked(
                DirectXPixelFormat.B8G8R8A8UIntNormalized,
                (int)FrameWidth,
                (int)FrameHeight);

            m_mediaPlayer.VideoFrameAvailable += mediaPlayer_VideoFrameAvailable;

            m_frameSourceReadyEvent.Set();
        }