Lines Matching defs:avctx
116 #define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, ctx->cudl, x)
120 AVCodecContext *avctx = opaque;
121 CuvidContext *ctx = avctx->priv_data;
128 int old_width = avctx->width;
129 int old_height = avctx->height;
135 av_log(avctx, AV_LOG_TRACE, "pfnSequenceCallback, progressive_sequence=%d\n", format->progressive_sequence);
141 avctx->coded_width = cuinfo.ulWidth = format->coded_width;
142 avctx->coded_height = cuinfo.ulHeight = format->coded_height;
152 avctx->width = ctx->resize.width;
153 avctx->height = ctx->resize.height;
155 avctx->width = cuinfo.display_area.right - cuinfo.display_area.left;
156 avctx->height = cuinfo.display_area.bottom - cuinfo.display_area.top;
160 cuinfo.ulTargetWidth = avctx->width = (avctx->width + 1) & ~1;
161 cuinfo.ulTargetHeight = avctx->height = (avctx->height + 1) & ~1;
189 av_log(avctx, AV_LOG_ERROR, "unsupported bit depth: %d\n",
195 surface_fmt = ff_get_format(avctx, pix_fmts);
197 av_log(avctx, AV_LOG_ERROR, "ff_get_format failed: %d\n", surface_fmt);
202 av_log(avctx, AV_LOG_VERBOSE, "Formats: Original: %s | HW: %s | SW: %s\n",
203 av_get_pix_fmt_name(avctx->pix_fmt),
205 av_get_pix_fmt_name(avctx->sw_pix_fmt));
207 avctx->pix_fmt = surface_fmt;
210 if (avctx->hw_frames_ctx) {
213 ctx->hwframe = av_buffer_ref(avctx->hw_frames_ctx);
222 ff_set_sar(avctx, av_div_q(
224 (AVRational){ avctx->width, avctx->height }));
233 avctx->flags |= AV_CODEC_FLAG_INTERLACED_DCT;
235 avctx->flags &= ~AV_CODEC_FLAG_INTERLACED_DCT;
238 avctx->color_range = AVCOL_RANGE_JPEG;
240 avctx->color_range = AVCOL_RANGE_MPEG;
242 avctx->color_primaries = format->video_signal_description.color_primaries;
243 avctx->color_trc = format->video_signal_description.transfer_characteristics;
244 avctx->colorspace = format->video_signal_description.matrix_coefficients;
247 avctx->bit_rate = format->bitrate;
250 avctx->framerate.num = format->frame_rate.numerator;
251 avctx->framerate.den = format->frame_rate.denominator;
255 && avctx->coded_width == format->coded_width
256 && avctx->coded_height == format->coded_height
257 && avctx->width == old_width
258 && avctx->height == old_height
264 av_log(avctx, AV_LOG_TRACE, "Re-initializing decoder\n");
272 hwframe_ctx->width < avctx->width ||
273 hwframe_ctx->height < avctx->height ||
275 hwframe_ctx->sw_format != avctx->sw_pix_fmt)) {
276 av_log(avctx, AV_LOG_ERROR, "AVHWFramesContext is already initialized with incompatible parameters\n");
277 av_log(avctx, AV_LOG_DEBUG, "width: %d <-> %d\n", hwframe_ctx->width, avctx->width);
278 av_log(avctx, AV_LOG_DEBUG, "height: %d <-> %d\n", hwframe_ctx->height, avctx->height);
279 av_log(avctx, AV_LOG_DEBUG, "format: %s <-> cuda\n", av_get_pix_fmt_name(hwframe_ctx->format));
280 av_log(avctx, AV_LOG_DEBUG, "sw_format: %s <-> %s\n",
281 av_get_pix_fmt_name(hwframe_ctx->sw_format), av_get_pix_fmt_name(avctx->sw_pix_fmt));
291 switch (avctx->sw_pix_fmt) {
306 av_log(avctx, AV_LOG_ERROR, "Unsupported output format: %s\n",
307 av_get_pix_fmt_name(avctx->sw_pix_fmt));
319 avctx->framerate = av_mul_q(avctx->framerate, (AVRational){2, 1});
327 hwframe_ctx->sw_format = avctx->sw_pix_fmt;
328 hwframe_ctx->width = avctx->width;
329 hwframe_ctx->height = avctx->height;
332 av_log(avctx, AV_LOG_ERROR, "av_hwframe_ctx_init failed\n");
342 AVCodecContext *avctx = opaque;
343 CuvidContext *ctx = avctx->priv_data;
345 av_log(avctx, AV_LOG_TRACE, "pfnDecodePicture\n");
359 AVCodecContext *avctx = opaque;
360 CuvidContext *ctx = avctx->priv_data;
383 static int cuvid_is_buffer_full(AVCodecContext *avctx)
385 CuvidContext *ctx = avctx->priv_data;
394 static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt)
396 CuvidContext *ctx = avctx->priv_data;
403 av_log(avctx, AV_LOG_TRACE, "cuvid_decode_packet\n");
408 if (cuvid_is_buffer_full(avctx) && avpkt && avpkt->size)
424 if (avctx->pkt_timebase.num && avctx->pkt_timebase.den)
425 cupkt.timestamp = av_rescale_q(avpkt->pts, avctx->pkt_timebase, (AVRational){1, 10000000});
441 av_log(avctx, AV_LOG_ERROR, "cuvid decode callback error\n");
459 static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame)
461 CuvidContext *ctx = avctx->priv_data;
469 av_log(avctx, AV_LOG_TRACE, "cuvid_output_frame\n");
472 ret = cuvid_decode_packet(avctx, NULL);
477 if (!cuvid_is_buffer_full(avctx)) {
479 ret = ff_decode_get_packet(avctx, pkt);
482 ret = cuvid_decode_packet(avctx, pkt);
511 if (avctx->pix_fmt == AV_PIX_FMT_CUDA) {
514 av_log(avctx, AV_LOG_ERROR, "av_hwframe_get_buffer failed\n");
518 ret = ff_decode_frame_props(avctx, frame);
520 av_log(avctx, AV_LOG_ERROR, "ff_decode_frame_props failed\n");
524 pixdesc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
527 int height = avctx->height >> (i ? pixdesc->log2_chroma_h : 0);
546 } else if (avctx->pix_fmt == AV_PIX_FMT_NV12 ||
547 avctx->pix_fmt == AV_PIX_FMT_P010 ||
548 avctx->pix_fmt == AV_PIX_FMT_P016 ||
549 avctx->pix_fmt == AV_PIX_FMT_YUV444P ||
550 avctx->pix_fmt == AV_PIX_FMT_YUV444P16) {
554 av_log(avctx, AV_LOG_ERROR, "av_frame_alloc failed\n");
559 pixdesc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
569 tmp_frame->width = avctx->width;
570 tmp_frame->height = avctx->height;
580 offset += pitch * (avctx->height >> (i ? pixdesc->log2_chroma_h : 0));
583 ret = ff_get_buffer(avctx, frame, 0);
585 av_log(avctx, AV_LOG_ERROR, "ff_get_buffer failed\n");
592 av_log(avctx, AV_LOG_ERROR, "av_hwframe_transfer_data failed\n");
605 frame->width = avctx->width;
606 frame->height = avctx->height;
607 if (avctx->pkt_timebase.num && avctx->pkt_timebase.den)
608 frame->pts = av_rescale_q(parsed_frame.dispinfo.timestamp, (AVRational){1, 10000000}, avctx->pkt_timebase);
615 frame->pts += (avctx->pkt_timebase.den * avctx->framerate.den) / (avctx->pkt_timebase.num * avctx->framerate.num);
655 static av_cold int cuvid_decode_end(AVCodecContext *avctx)
657 CuvidContext *ctx = avctx->priv_data;
689 static int cuvid_test_capabilities(AVCodecContext *avctx,
695 CuvidContext *ctx = avctx->priv_data;
700 av_log(avctx, AV_LOG_WARNING, "Used Nvidia driver is too old to perform a capability check.\n");
701 av_log(avctx, AV_LOG_WARNING, "The minimum required version is "
727 av_log(avctx, AV_LOG_VERBOSE, "CUVID capabilities for %s:\n", avctx->codec->name);
728 av_log(avctx, AV_LOG_VERBOSE, "8 bit: supported: %d, min_width: %d, max_width: %d, min_height: %d, max_height: %d\n",
730 av_log(avctx, AV_LOG_VERBOSE, "10 bit: supported: %d, min_width: %d, max_width: %d, min_height: %d, max_height: %d\n",
732 av_log(avctx, AV_LOG_VERBOSE, "12 bit: supported: %d, min_width: %d, max_width: %d, min_height: %d, max_height: %d\n",
753 av_log(avctx, AV_LOG_ERROR, "Codec %s is not supported.\n", avctx->codec->name);
758 av_log(avctx, AV_LOG_ERROR, "Bit depth %d is not supported.\n", bit_depth);
763 av_log(avctx, AV_LOG_ERROR, "Video width %d not within range from %d to %d\n",
769 av_log(avctx, AV_LOG_ERROR, "Video height %d not within range from %d to %d\n",
775 av_log(avctx, AV_LOG_ERROR, "Video macroblock count %d exceeds maximum of %d\n",
783 static av_cold int cuvid_decode_init(AVCodecContext *avctx)
785 CuvidContext *ctx = avctx->priv_data;
800 int probed_width = avctx->coded_width ? avctx->coded_width : 1280;
801 int probed_height = avctx->coded_height ? avctx->coded_height : 720;
804 const AVPixFmtDescriptor *probe_desc = av_pix_fmt_desc_get(avctx->pix_fmt);
808 ctx->pkt = avctx->internal->in_pkt;
813 ret = ff_get_format(avctx, pix_fmts);
815 av_log(avctx, AV_LOG_ERROR, "ff_get_format failed: %d\n", ret);
818 avctx->pix_fmt = ret;
822 av_log(avctx, AV_LOG_ERROR, "Invalid resize expressions\n");
830 av_log(avctx, AV_LOG_ERROR, "Invalid cropping expressions\n");
835 ret = cuvid_load_functions(&ctx->cvdl, avctx);
837 av_log(avctx, AV_LOG_ERROR, "Failed loading nvcuvid.\n");
847 if (avctx->hw_frames_ctx) {
848 ctx->hwframe = av_buffer_ref(avctx->hw_frames_ctx);
862 if (avctx->hw_device_ctx) {
863 ctx->hwdevice = av_buffer_ref(avctx->hw_device_ctx);
876 av_log(avctx, AV_LOG_ERROR, "av_hwframe_ctx_alloc failed\n");
893 switch (avctx->codec->id) {
945 av_log(avctx, AV_LOG_ERROR, "Invalid CUVID codec!\n");
949 if (ffcodec(avctx->codec)->bsfs) {
950 const AVCodecParameters *par = avctx->internal->bsf->par_out;
954 extradata = avctx->extradata;
955 extradata_size = avctx->extradata_size;
961 if (avctx->codec->id == AV_CODEC_ID_AV1 &&
988 ctx->cuparseinfo.ulMaxDisplayDelay = (avctx->flags & AV_CODEC_FLAG_LOW_DELAY) ? 0 : 4;
989 ctx->cuparseinfo.pUserData = avctx;
998 ret = cuvid_test_capabilities(avctx, &ctx->cuparseinfo,
1024 if (!avctx->pkt_timebase.num || !avctx->pkt_timebase.den)
1025 av_log(avctx, AV_LOG_WARNING, "Invalid pkt_timebase, passing timestamps as-is.\n");
1030 cuvid_decode_end(avctx);
1034 static void cuvid_flush(AVCodecContext *avctx)
1036 CuvidContext *ctx = avctx->priv_data;
1081 av_log(avctx, AV_LOG_ERROR, "CUDA reinit on flush failed\n");