Exemple #1
0
        public void Init(Renderer renderer, Config cfg)
        {
            this.renderer = renderer;
            this.cfg      = cfg;
            status        = Status.None;

            Master.RegisterFFmpeg();

            vDecoder = new Decoder(MediaType.Video, this);
            aDecoder = new Decoder(MediaType.Audio, this);
            sDecoder = new Decoder(MediaType.Subs, this);

            demuxer  = new Demuxer(MediaType.Video, this);
            aDemuxer = new Demuxer(MediaType.Audio, this);
            sDemuxer = new Demuxer(MediaType.Subs, this);

            va = new VideoAcceleration();
            if (cfg.decoder.HWAcceleration)
            {
                va.Init(renderer.device);
            }

            GCHandle decCtxHandle = GCHandle.Alloc(this);

            decCtxPtr = (IntPtr)decCtxHandle;
        }
Exemple #2
0
        public int SetupVideo(AVCodec *codec)
        {
            hwAccelSuccess = false;

            if (decCtx.cfg.decoder.HWAcceleration)
            {
                if (VideoAcceleration.CheckCodecSupport(codec))
                {
                    if (demuxer.decCtx.va.hw_device_ctx == null)
                    {
                        demuxer.decCtx.va.Init(decCtx.renderer.device);
                    }

                    if (demuxer.decCtx.va.hw_device_ctx != null)
                    {
                        codecCtx->hw_device_ctx = av_buffer_ref(demuxer.decCtx.va.hw_device_ctx);
                        hwAccelSuccess          = true;
                        Log("HW Acceleration Success");
                    }
                }
                else
                {
                    Log("HW Acceleration Failed");
                }
            }
            else
            {
                Log("HW Acceleration Disabled");
            }

            codecCtx->thread_count = Math.Min(decCtx.cfg.decoder.VideoThreads, codecCtx->codec_id == AV_CODEC_ID_HEVC ? 32 : 16);
            codecCtx->thread_type  = 0;
            //vCodecCtx->active_thread_type = FF_THREAD_FRAME;
            //vCodecCtx->active_thread_type = FF_THREAD_SLICE;
            //codecCtx->thread_safe_callbacks = 1;

            int bits = info.PixelFormatDesc->comp.ToArray()[0].depth;

            textDesc = new Texture2DDescription()
            {
                Usage     = ResourceUsage.Default,
                BindFlags = BindFlags.ShaderResource,

                Format = bits > 8 ? Format.R16_UNorm : Format.R8_UNorm,              // FOR HW/SW will be set later
                Width  = codecCtx->width,
                Height = codecCtx->height,

                SampleDescription = new SampleDescription(1, 0),
                ArraySize         = 1,
                MipLevels         = 1
            };

            textDescUV = new Texture2DDescription()
            {
                Usage     = ResourceUsage.Default,
                BindFlags = BindFlags.ShaderResource,

                //Format              = bits > 8 ? Format.R16G16_UNorm : Format.R8G8_UNorm, // FOR HW/SW will be set later
                Format = bits > 8 ? Format.R16_UNorm : Format.R8_UNorm,              // FOR HW/SW will be set later
                Width  = codecCtx->width >> info.PixelFormatDesc->log2_chroma_w,
                Height = codecCtx->height >> info.PixelFormatDesc->log2_chroma_h,

                SampleDescription = new SampleDescription(1, 0),
                ArraySize         = 1,
                MipLevels         = 1
            };

            decCtx.renderer.FrameResized();

            return(0);
        }