Lines Matching refs:ctx
116 #define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, ctx->cudl, x)
121 CuvidContext *ctx = avctx->priv_data;
122 AVHWFramesContext *hwframe_ctx = (AVHWFramesContext*)ctx->hwframe->data;
139 ctx->internal_error = 0;
145 cuinfo.display_area.left = format->display_area.left + ctx->crop.left;
146 cuinfo.display_area.top = format->display_area.top + ctx->crop.top;
147 cuinfo.display_area.right = format->display_area.right - ctx->crop.right;
148 cuinfo.display_area.bottom = format->display_area.bottom - ctx->crop.bottom;
151 if (ctx->resize_expr) {
152 avctx->width = ctx->resize.width;
153 avctx->height = ctx->resize.height;
174 caps = &ctx->caps8;
178 caps = &ctx->caps10;
182 caps = &ctx->caps12;
191 ctx->internal_error = AVERROR(EINVAL);
198 ctx->internal_error = AVERROR(EINVAL);
209 // Update our hwframe ctx, as the get_format callback might have refreshed it!
211 av_buffer_unref(&ctx->hwframe);
213 ctx->hwframe = av_buffer_ref(avctx->hw_frames_ctx);
214 if (!ctx->hwframe) {
215 ctx->internal_error = AVERROR(ENOMEM);
219 hwframe_ctx = (AVHWFramesContext*)ctx->hwframe->data;
226 ctx->deint_mode_current = format->progressive_sequence
228 : ctx->deint_mode;
230 ctx->progressive_sequence = format->progressive_sequence;
232 if (!format->progressive_sequence && ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave)
254 if (ctx->cudecoder
259 && ctx->chroma_format == format->chroma_format
260 && ctx->codec_type == format->codec)
263 if (ctx->cudecoder) {
265 ctx->internal_error = CHECK_CU(ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder));
266 if (ctx->internal_error < 0)
268 ctx->cudecoder = NULL;
282 ctx->internal_error = AVERROR(EINVAL);
286 ctx->chroma_format = format->chroma_format;
288 cuinfo.CodecType = ctx->codec_type = format->codec;
308 ctx->internal_error = AVERROR(EINVAL);
312 cuinfo.ulNumDecodeSurfaces = ctx->nb_surfaces;
316 cuinfo.DeinterlaceMode = ctx->deint_mode_current;
318 if (ctx->deint_mode_current != cudaVideoDeinterlaceMode_Weave && !ctx->drop_second_field)
321 ctx->internal_error = CHECK_CU(ctx->cvdl->cuvidCreateDecoder(&ctx->cudecoder, &cuinfo));
322 if (ctx->internal_error < 0)
331 if ((ctx->internal_error = av_hwframe_ctx_init(ctx->hwframe)) < 0) {
343 CuvidContext *ctx = avctx->priv_data;
348 ctx->key_frame[picparams->CurrPicIdx] = picparams->intra_pic_flag;
350 ctx->internal_error = CHECK_CU(ctx->cvdl->cuvidDecodePicture(ctx->cudecoder, picparams));
351 if (ctx->internal_error < 0)
360 CuvidContext *ctx = avctx->priv_data;
364 ctx->internal_error = 0;
367 parsed_frame.dispinfo.progressive_frame = ctx->progressive_sequence;
369 if (ctx->deint_mode_current == cudaVideoDeinterlaceMode_Weave) {
370 av_fifo_write(ctx->frame_queue, &parsed_frame, 1);
373 av_fifo_write(ctx->frame_queue, &parsed_frame, 1);
374 if (!ctx->drop_second_field) {
376 av_fifo_write(ctx->frame_queue, &parsed_frame, 1);
385 CuvidContext *ctx = avctx->priv_data;
387 int delay = ctx->cuparseinfo.ulMaxDisplayDelay;
388 if (ctx->deint_mode != cudaVideoDeinterlaceMode_Weave && !ctx->drop_second_field)
391 return av_fifo_can_read(ctx->frame_queue) + delay >= ctx->nb_surfaces;
396 CuvidContext *ctx = avctx->priv_data;
397 AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)ctx->hwdevice->data;
401 int ret = 0, eret = 0, is_flush = ctx->decoder_flushing;
411 ret = CHECK_CU(ctx->cudl->cuCtxPushCurrent(cuda_ctx));
431 ctx->decoder_flushing = 1;
434 ret = CHECK_CU(ctx->cvdl->cuvidParseVideoData(ctx->cuparser, &cupkt));
440 if (ctx->internal_error) {
442 ret = ctx->internal_error;
447 eret = CHECK_CU(ctx->cudl->cuCtxPopCurrent(&dummy));
461 CuvidContext *ctx = avctx->priv_data;
462 AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)ctx->hwdevice->data;
471 if (ctx->decoder_flushing) {
478 AVPacket *const pkt = ctx->pkt;
491 ret = CHECK_CU(ctx->cudl->cuCtxPushCurrent(cuda_ctx));
495 if (av_fifo_read(ctx->frame_queue, &parsed_frame, 1) >= 0) {
507 ret = CHECK_CU(ctx->cvdl->cuvidMapVideoFrame(ctx->cudecoder, parsed_frame.dispinfo.picture_index, &mapped_frame, &pitch, ¶ms));
512 ret = av_hwframe_get_buffer(ctx->hwframe, frame, 0);
540 ret = CHECK_CU(ctx->cudl->cuMemcpy2DAsync(&cpy, device_hwctx->stream));
562 tmp_frame->hw_frames_ctx = av_buffer_ref(ctx->hwframe);
602 frame->key_frame = ctx->key_frame[parsed_frame.dispinfo.picture_index];
603 ctx->key_frame[parsed_frame.dispinfo.picture_index] = 0;
613 if (ctx->prev_pts == INT64_MIN) {
614 ctx->prev_pts = frame->pts;
617 int pts_diff = (frame->pts - ctx->prev_pts) / 2;
618 ctx->prev_pts = frame->pts;
634 } else if (ctx->decoder_flushing) {
645 eret = CHECK_CU(ctx->cvdl->cuvidUnmapVideoFrame(ctx->cudecoder, mapped_frame));
647 eret = CHECK_CU(ctx->cudl->cuCtxPopCurrent(&dummy));
657 CuvidContext *ctx = avctx->priv_data;
658 AVHWDeviceContext *device_ctx = ctx->hwdevice ? (AVHWDeviceContext *)ctx->hwdevice->data : NULL;
662 av_fifo_freep2(&ctx->frame_queue);
665 ctx->cudl->cuCtxPushCurrent(cuda_ctx);
667 if (ctx->cuparser)
668 ctx->cvdl->cuvidDestroyVideoParser(ctx->cuparser);
670 if (ctx->cudecoder)
671 ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder);
673 ctx->cudl->cuCtxPopCurrent(&dummy);
676 ctx->cudl = NULL;
678 av_buffer_unref(&ctx->hwframe);
679 av_buffer_unref(&ctx->hwdevice);
681 av_freep(&ctx->key_frame);
682 av_freep(&ctx->cuparse_ext);
684 cuvid_free_functions(&ctx->cvdl);
695 CuvidContext *ctx = avctx->priv_data;
699 if (!ctx->cvdl->cuvidGetDecoderCaps) {
708 ctx->caps8.bIsSupported = ctx->caps10.bIsSupported = 1;
710 ctx->caps12.bIsSupported = 0;
714 ctx->caps8.eCodecType = ctx->caps10.eCodecType = ctx->caps12.eCodecType
716 ctx->caps8.eChromaFormat = ctx->caps10.eChromaFormat = ctx->caps12.eChromaFormat
719 ctx->caps8.nBitDepthMinus8 = 0;
720 ctx->caps10.nBitDepthMinus8 = 2;
721 ctx->caps12.nBitDepthMinus8 = 4;
723 res8 = CHECK_CU(ctx->cvdl->cuvidGetDecoderCaps(&ctx->caps8));
724 res10 = CHECK_CU(ctx->cvdl->cuvidGetDecoderCaps(&ctx->caps10));
725 res12 = CHECK_CU(ctx->cvdl->cuvidGetDecoderCaps(&ctx->caps12));
729 ctx->caps8.bIsSupported, ctx->caps8.nMinWidth, ctx->caps8.nMaxWidth, ctx->caps8.nMinHeight, ctx->caps8.nMaxHeight);
731 ctx->caps10.bIsSupported, ctx->caps10.nMinWidth, ctx->caps10.nMaxWidth, ctx->caps10.nMinHeight, ctx->caps10.nMaxHeight);
733 ctx->caps12.bIsSupported, ctx->caps12.nMinWidth, ctx->caps12.nMaxWidth, ctx->caps12.nMinHeight, ctx->caps12.nMaxHeight);
737 caps = &ctx->caps10;
742 caps = &ctx->caps12;
747 caps = &ctx->caps8;
752 if (!ctx->caps8.bIsSupported) {
785 CuvidContext *ctx = avctx->priv_data;
808 ctx->pkt = avctx->internal->in_pkt;
820 if (ctx->resize_expr && sscanf(ctx->resize_expr, "%dx%d",
821 &ctx->resize.width, &ctx->resize.height) != 2) {
827 if (ctx->crop_expr && sscanf(ctx->crop_expr, "%dx%dx%dx%d",
828 &ctx->crop.top, &ctx->crop.bottom,
829 &ctx->crop.left, &ctx->crop.right) != 4) {
835 ret = cuvid_load_functions(&ctx->cvdl, avctx);
841 ctx->frame_queue = av_fifo_alloc2(ctx->nb_surfaces, sizeof(CuvidParsedFrame), 0);
842 if (!ctx->frame_queue) {
848 ctx->hwframe = av_buffer_ref(avctx->hw_frames_ctx);
849 if (!ctx->hwframe) {
854 hwframe_ctx = (AVHWFramesContext*)ctx->hwframe->data;
856 ctx->hwdevice = av_buffer_ref(hwframe_ctx->device_ref);
857 if (!ctx->hwdevice) {
863 ctx->hwdevice = av_buffer_ref(avctx->hw_device_ctx);
864 if (!ctx->hwdevice) {
869 ret = av_hwdevice_ctx_create(&ctx->hwdevice, AV_HWDEVICE_TYPE_CUDA, ctx->cu_gpu, NULL, 0);
874 ctx->hwframe = av_hwframe_ctx_alloc(ctx->hwdevice);
875 if (!ctx->hwframe) {
881 hwframe_ctx = (AVHWFramesContext*)ctx->hwframe->data;
888 ctx->cudl = device_hwctx->internal->cuda_dl;
890 memset(&ctx->cuparseinfo, 0, sizeof(ctx->cuparseinfo));
896 ctx->cuparseinfo.CodecType = cudaVideoCodec_H264;
901 ctx->cuparseinfo.CodecType = cudaVideoCodec_HEVC;
906 ctx->cuparseinfo.CodecType = cudaVideoCodec_JPEG;
911 ctx->cuparseinfo.CodecType = cudaVideoCodec_MPEG1;
916 ctx->cuparseinfo.CodecType = cudaVideoCodec_MPEG2;
921 ctx->cuparseinfo.CodecType = cudaVideoCodec_MPEG4;
926 ctx->cuparseinfo.CodecType = cudaVideoCodec_VP8;
931 ctx->cuparseinfo.CodecType = cudaVideoCodec_VP9;
936 ctx->cuparseinfo.CodecType = cudaVideoCodec_VC1;
941 ctx->cuparseinfo.CodecType = cudaVideoCodec_AV1;
968 ctx->cuparse_ext = av_mallocz(sizeof(*ctx->cuparse_ext)
969 + FFMAX(extradata_size - (int)sizeof(ctx->cuparse_ext->raw_seqhdr_data), 0));
970 if (!ctx->cuparse_ext) {
976 memcpy(ctx->cuparse_ext->raw_seqhdr_data, extradata, extradata_size);
977 ctx->cuparse_ext->format.seqhdr_data_length = extradata_size;
979 ctx->cuparseinfo.pExtVideoInfo = ctx->cuparse_ext;
981 ctx->key_frame = av_mallocz(ctx->nb_surfaces * sizeof(int));
982 if (!ctx->key_frame) {
987 ctx->cuparseinfo.ulMaxNumDecodeSurfaces = ctx->nb_surfaces;
988 ctx->cuparseinfo.ulMaxDisplayDelay = (avctx->flags & AV_CODEC_FLAG_LOW_DELAY) ? 0 : 4;
989 ctx->cuparseinfo.pUserData = avctx;
990 ctx->cuparseinfo.pfnSequenceCallback = cuvid_handle_video_sequence;
991 ctx->cuparseinfo.pfnDecodePicture = cuvid_handle_picture_decode;
992 ctx->cuparseinfo.pfnDisplayPicture = cuvid_handle_picture_display;
994 ret = CHECK_CU(ctx->cudl->cuCtxPushCurrent(cuda_ctx));
998 ret = cuvid_test_capabilities(avctx, &ctx->cuparseinfo,
1005 ret = CHECK_CU(ctx->cvdl->cuvidCreateVideoParser(&ctx->cuparser, &ctx->cuparseinfo));
1009 seq_pkt.payload = ctx->cuparse_ext->raw_seqhdr_data;
1010 seq_pkt.payload_size = ctx->cuparse_ext->format.seqhdr_data_length;
1013 ret = CHECK_CU(ctx->cvdl->cuvidParseVideoData(ctx->cuparser, &seq_pkt));
1018 ret = CHECK_CU(ctx->cudl->cuCtxPopCurrent(&dummy));
1022 ctx->prev_pts = INT64_MIN;
1036 CuvidContext *ctx = avctx->priv_data;
1037 AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)ctx->hwdevice->data;
1043 ret = CHECK_CU(ctx->cudl->cuCtxPushCurrent(cuda_ctx));
1047 av_fifo_reset2(ctx->frame_queue);
1049 if (ctx->cudecoder) {
1050 ctx->cvdl->cuvidDestroyDecoder(ctx->cudecoder);
1051 ctx->cudecoder = NULL;
1054 if (ctx->cuparser) {
1055 ctx->cvdl->cuvidDestroyVideoParser(ctx->cuparser);
1056 ctx->cuparser = NULL;
1059 ret = CHECK_CU(ctx->cvdl->cuvidCreateVideoParser(&ctx->cuparser, &ctx->cuparseinfo));
1063 seq_pkt.payload = ctx->cuparse_ext->raw_seqhdr_data;
1064 seq_pkt.payload_size = ctx->cuparse_ext->format.seqhdr_data_length;
1067 ret = CHECK_CU(ctx->cvdl->cuvidParseVideoData(ctx->cuparser, &seq_pkt));
1072 ret = CHECK_CU(ctx->cudl->cuCtxPopCurrent(&dummy));
1076 ctx->prev_pts = INT64_MIN;
1077 ctx->decoder_flushing = 0;