Exemple #1
0
 public ID3D11VideoDecoderOutputView CreateVideoDecoderOutputView(ID3D11Resource resource, VideoDecoderOutputViewDescription description)
 {
     CreateVideoDecoderOutputView(resource, ref description, out ID3D11VideoDecoderOutputView view).CheckError();
     return(view);
 }
Exemple #2
0
 public Result CreateVideoDecoderOutputView(ID3D11Resource resource, VideoDecoderOutputViewDescription description, out ID3D11VideoDecoderOutputView view)
 {
     return(CreateVideoDecoderOutputView(resource, ref description, out view));
 }
Exemple #3
0
        private void CreateHarwareAccelerationContext(GraphicsDevice graphicsDevice, AVCodecContext *pAVCodecContext, AVCodec *pCodec)
        {
            var videoDevice  = graphicsDevice?.NativeDevice?.QueryInterface <VideoDevice1>();
            var videoContext = graphicsDevice?.NativeDeviceContext?.QueryInterface <VideoContext1>();

            if (videoDevice == null || videoContext == null)
            {
                return;
            }

            foreach (var profile in FindVideoFormatCompatibleProfiles(videoDevice, *pCodec))
            {
                // Create and configure the video decoder
                var videoDecoderDescription = new VideoDecoderDescription
                {
                    Guid         = profile,
                    SampleWidth  = pAVCodecContext->width,
                    SampleHeight = pAVCodecContext->height,
                    OutputFormat = DecoderOuputFormat,
                };

                videoDevice.GetVideoDecoderConfigCount(ref videoDecoderDescription, out var configCount);
                for (var i = 0; i < configCount; ++i)
                {
                    // get and check the decoder configuration for the profile
                    videoDevice.GetVideoDecoderConfig(ref videoDecoderDescription, i, out var decoderConfig);
                    //if (check to performe on the config)
                    //    continue;

                    // create the decoder from the configuration
                    videoDevice.CreateVideoDecoder(ref videoDecoderDescription, ref decoderConfig, out videoHardwareDecoder);

                    // create the decoder output view
                    var videoDecoderOutputViewDescription = new VideoDecoderOutputViewDescription
                    {
                        DecodeProfile = profile,
                        Dimension     = VdovDimension.Texture2D,
                        Texture2D     = new Texture2DVdov {
                            ArraySlice = 0,
                        },
                    };
                    DecoderOutputTexture = Texture.New2D(graphicsDevice, pAVCodecContext->width, pAVCodecContext->height, (PixelFormat)DecoderOuputFormat, TextureFlags.RenderTarget | TextureFlags.ShaderResource);
                    videoDevice.CreateVideoDecoderOutputView(DecoderOutputTexture.NativeResource, ref videoDecoderOutputViewDescription, out videoHardwareDecoderView);

                    // Create and fill the hardware context
                    var contextd3d11 = ffmpeg.av_d3d11va_alloc_context();

                    var iVideoContext = new ID3D11VideoContext {
                        lpVtbl = (ID3D11VideoContextVtbl *)videoContext.NativePointer
                    };
                    videoContextHandle          = new PinnedObject <ID3D11VideoContext>(iVideoContext);
                    contextd3d11->video_context = (ID3D11VideoContext *)videoContextHandle.Pointer;

                    var iVideoDecoder = new ID3D11VideoDecoder {
                        lpVtbl = (ID3D11VideoDecoderVtbl *)videoHardwareDecoder.NativePointer
                    };
                    videoDecoderHandle    = new PinnedObject <ID3D11VideoDecoder>(iVideoDecoder);
                    contextd3d11->decoder = (ID3D11VideoDecoder *)videoDecoderHandle.Pointer;

                    decoderConfigHandle = new PinnedObject <D3D11_VIDEO_DECODER_CONFIG>(decoderConfig.ToFFmpegDecoderConfig());
                    contextd3d11->cfg   = (D3D11_VIDEO_DECODER_CONFIG *)decoderConfigHandle.Pointer;

                    var iVideoOutputView = new ID3D11VideoDecoderOutputView {
                        lpVtbl = (ID3D11VideoDecoderOutputViewVtbl *)videoHardwareDecoderView.NativePointer
                    };
                    decoderOuputViewsHandle     = new PinnedObject <ID3D11VideoDecoderOutputView>(iVideoOutputView, true);
                    contextd3d11->surface       = (ID3D11VideoDecoderOutputView **)decoderOuputViewsHandle.Pointer;
                    contextd3d11->surface_count = 1;

                    pAVCodecContext->hwaccel_context = contextd3d11;
                }
            }
        }