public VideoRenderer(VideoTrack videoTrack, RendererOptions options)
        {
            VideoTrack = videoTrack;

            VideoFrameWidth     = options.VideoFrameWidth;
            VideoFrameHeight    = options.VideoFrameHeight;
            VideoFrameQueueSize = options.VideoFrameQueueSize;

            videoTrack.LocalVideoFrameEncoded += OnLocalVideoFrameEncoded;

            // _onMissedFrame = options.OnMissedFrame ?? OnMissedFrame;

            bool debug = options.CreationFlags.HasFlag(D3D11.DeviceCreationFlags.Debug);

            FactoryDXGI = new DXGI.Factory2(debug);

            // Find the requested adapter.
            using (var adapters = FactoryDXGI.Adapters.ToDisposableList())
            {
                var adapter = adapters.First(a => a.Description.VendorId == options.AdapterVendorId);

                Device3D = new D3D11.Device(adapter, options.CreationFlags, options.FeatureLevels);

                DeviceDXGI = Device3D.QueryInterface <DXGI.Device>();

                // We need to access D3D11 on multiple threads, so enable multi-threading
                ThreadLock3D = Device3D.ImmediateContext.QueryInterface <D3D11.Multithread>();
                ThreadLock3D.SetMultithreadProtected(true);
            }
        }
Пример #2
0
        public async Task EncodeAsync(IRandomAccessStream stream, uint width, uint height, uint bitrateInBps, uint frameRate)
        {
            if (!_isRecording)
            {
                _isRecording = true;

                _multithread = _d3dDevice.QueryInterface <SharpDX.Direct3D11.Multithread>();
                _multithread.SetMultithreadProtected(true);
                _frameEvent  = new ManualResetEvent(false);
                _closedEvent = new ManualResetEvent(false);
                _events      = new[] { _closedEvent, _frameEvent };

                InitializeComposeTexture(_captureItem.Size);
                InitializeCapture(_captureItem.Size);

                var encodingProfile = new MediaEncodingProfile();
                encodingProfile.Container.Subtype                  = "MPEG4";
                encodingProfile.Video.Subtype                      = "H264";
                encodingProfile.Video.Width                        = 1920;
                encodingProfile.Video.Height                       = 1080;
                encodingProfile.Video.Bitrate                      = bitrateInBps;
                encodingProfile.Video.FrameRate.Numerator          = frameRate;
                encodingProfile.Video.FrameRate.Denominator        = 1;
                encodingProfile.Video.PixelAspectRatio.Numerator   = 1;
                encodingProfile.Video.PixelAspectRatio.Denominator = 1;
                var transcode = await _transcoder.PrepareMediaStreamSourceTranscodeAsync(_mediaStreamSource, stream, encodingProfile);

                try
                {
                    await transcode.TranscodeAsync();
                }
                catch (Exception ex)
                {
                    Debugger.Break();
                }
            }
        }
Пример #3
0
 public MultithreadLock(SharpDX.Direct3D11.Multithread multithread)
 {
     _multithread = multithread;
     _multithread?.Enter();
 }