public void Init(Device device) { Utils.RegisterFFmpegBinaries(); //av_log_set_level(AV_LOG_MAX_OFFSET); av_log_set_level(AV_LOG_WARNING); av_log_set_callback(Utils.ffmpegLogCallback); vDecoder = new Decoder(Type.Video, this); aDecoder = new Decoder(Type.Audio, this); sDecoder = new Decoder(Type.Subs, this); demuxer = new Demuxer(Type.Video, this); aDemuxer = new Demuxer(Type.Audio, this); sDemuxer = new Demuxer(Type.Subs, this); va = new VideoAcceleration(); if (opt.video.HWAcceleration) { va.Init(device); } this.device = device; status = Status.NOTSET; GCHandle decCtxHandle = GCHandle.Alloc(this); decCtxPtr = (IntPtr)decCtxHandle; }
public int SetupVideo(AVCodec *codec) { hwAccelSuccess = false; if (opt.video.HWAcceleration && VideoAcceleration.CheckCodecSupport(codec)) { if (demuxer.decCtx.va.hw_device_ctx == null) { demuxer.decCtx.va.Init(demuxer.decCtx.device); } if (demuxer.decCtx.va.hw_device_ctx != null) { codecCtx->hw_device_ctx = av_buffer_ref(demuxer.decCtx.va.hw_device_ctx); hwAccelSuccess = true; } } codecCtx->thread_count = Math.Min(opt.video.DecoderThreads, 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; // Hardware Texture (NV12 | P010) | Format will be set from source textDescHW = new Texture2DDescription() { Usage = ResourceUsage.Default, Width = codecCtx->width, Height = codecCtx->height, BindFlags = BindFlags.Decoder, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), ArraySize = 1, MipLevels = 1 }; // YUV Pixel Shader (textureY | textureU | textureV) textDescYUV = new Texture2DDescription() { Usage = ResourceUsage.Immutable, Format = Format.R8_UNorm, Width = codecCtx->width, Height = codecCtx->height, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), ArraySize = 1, MipLevels = 1 }; // RGBA Sws Scale textDescRGB = new Texture2DDescription() { Usage = ResourceUsage.Immutable, Format = Format.R8G8B8A8_UNorm, Width = codecCtx->width, Height = codecCtx->height, BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, OptionFlags = ResourceOptionFlags.None, SampleDescription = new SampleDescription(1, 0), ArraySize = 1, MipLevels = 1 }; return(0); }