Lines Matching defs:avctx
93 static int videotoolbox_postproc_frame(void *avctx, AVFrame *frame)
99 av_log(avctx, AV_LOG_ERROR, "No frame decoded?\n");
109 if ((ret = av_vt_pixbuf_set_attachments(avctx, ref->pixbuf, frame)) < 0)
124 int ff_videotoolbox_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
147 frame->width = avctx->width;
148 frame->height = avctx->height;
149 frame->format = avctx->pix_fmt;
185 CFDataRef ff_videotoolbox_avcc_extradata_create(AVCodecContext *avctx)
187 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
188 H264Context *h = avctx->priv_data;
230 CFDataRef ff_videotoolbox_hvcc_extradata_create(AVCodecContext *avctx)
232 HEVCContext *h = avctx->priv_data;
391 int ff_videotoolbox_h264_start_frame(AVCodecContext *avctx,
395 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
396 H264Context *h = avctx->priv_data;
405 static int videotoolbox_h264_decode_params(AVCodecContext *avctx,
410 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
411 H264Context *h = avctx->priv_data;
425 return ff_videotoolbox_h264_decode_slice(avctx, buffer, size);
428 static int videotoolbox_common_decode_slice(AVCodecContext *avctx,
432 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
451 int ff_videotoolbox_h264_decode_slice(AVCodecContext *avctx,
455 H264Context *h = avctx->priv_data;
460 return videotoolbox_common_decode_slice(avctx, buffer, size);
466 static AVVideotoolboxContext *videotoolbox_get_context(AVCodecContext *avctx)
470 if (avctx->internal && avctx->internal->hwaccel_priv_data) {
471 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
475 return avctx->hwaccel_context;
478 static void videotoolbox_stop(AVCodecContext *avctx)
480 AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
496 int ff_videotoolbox_uninit(AVCodecContext *avctx)
498 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
507 videotoolbox_stop(avctx);
515 static int videotoolbox_buffer_create(AVCodecContext *avctx, AVFrame *frame)
517 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
528 av_log(avctx, AV_LOG_ERROR, "videotoolbox: invalid state\n");
592 static CFDataRef videotoolbox_esds_extradata_create(AVCodecContext *avctx)
597 int full_size = 3 + 5 + 13 + 5 + avctx->extradata_size + 3;
599 int config_size = 13 + 5 + avctx->extradata_size;
626 videotoolbox_write_mp4_descr_length(&pb, avctx->extradata_size);
628 bytestream2_put_buffer(&pb, avctx->extradata, avctx->extradata_size);
709 static OSStatus videotoolbox_session_decode_frame(AVCodecContext *avctx)
713 AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
714 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
800 AVCodecContext *avctx)
823 if (avctx->extradata_size)
824 data = videotoolbox_esds_extradata_create(avctx);
829 data = ff_videotoolbox_avcc_extradata_create(avctx);
834 data = ff_videotoolbox_hvcc_extradata_create(avctx);
840 data = ff_videotoolbox_vpcc_extradata_create(avctx);
860 static int videotoolbox_start(AVCodecContext *avctx)
862 AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
869 av_log(avctx, AV_LOG_ERROR, "hwaccel context is not set\n");
873 switch( avctx->codec_id ) {
893 switch (avctx->codec_tag) {
895 av_log(avctx, AV_LOG_WARNING, "Unknown prores profile %d\n", avctx->codec_tag);
903 videotoolbox->cm_codec_type = av_bswap32(avctx->codec_tag);
915 if (avctx->codec_id == AV_CODEC_ID_PRORES) {
928 decoder_spec = videotoolbox_decoder_config_create(videotoolbox->cm_codec_type, avctx);
931 av_log(avctx, AV_LOG_ERROR, "decoder specification creation failed\n");
937 avctx->width,
938 avctx->height);
943 av_log(avctx, AV_LOG_ERROR, "format description creation failed\n");
947 buf_attr = videotoolbox_buffer_attributes_create(avctx->width,
948 avctx->height,
952 decoder_cb.decompressionOutputRefCon = avctx->internal->hwaccel_priv_data;
968 av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox session not available.\n");
971 av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox does not support this format.\n");
974 av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox decoder for this format not found.\n");
977 av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox malfunction.\n");
980 av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox reported invalid data.\n");
985 av_log(avctx, AV_LOG_VERBOSE, "Unknown VideoToolbox session creation error %d\n", (int)status);
1003 int ff_videotoolbox_common_end_frame(AVCodecContext *avctx, AVFrame *frame)
1006 AVVideotoolboxContext *videotoolbox = videotoolbox_get_context(avctx);
1007 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
1011 av_log(avctx, AV_LOG_VERBOSE, "VideoToolbox decoder needs reconfig, restarting..\n");
1012 videotoolbox_stop(avctx);
1013 if (videotoolbox_start(avctx) != 0) {
1021 status = videotoolbox_session_decode_frame(avctx);
1025 av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%s, %d)\n", videotoolbox_error_string(status), (int)status);
1034 return videotoolbox_buffer_create(avctx, frame);
1037 static int videotoolbox_h264_end_frame(AVCodecContext *avctx)
1039 H264Context *h = avctx->priv_data;
1041 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
1042 int ret = ff_videotoolbox_common_end_frame(avctx, frame);
1047 static int videotoolbox_hevc_start_frame(AVCodecContext *avctx,
1054 static int videotoolbox_hevc_decode_slice(AVCodecContext *avctx,
1058 return videotoolbox_common_decode_slice(avctx, buffer, size);
1062 static int videotoolbox_hevc_decode_params(AVCodecContext *avctx,
1067 return videotoolbox_common_decode_slice(avctx, buffer, size);
1070 static int videotoolbox_hevc_end_frame(AVCodecContext *avctx)
1072 HEVCContext *h = avctx->priv_data;
1074 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
1081 int ret = ff_videotoolbox_common_end_frame(avctx, frame);
1086 static int videotoolbox_mpeg_start_frame(AVCodecContext *avctx,
1090 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
1095 static int videotoolbox_mpeg_decode_slice(AVCodecContext *avctx,
1102 static int videotoolbox_mpeg_end_frame(AVCodecContext *avctx)
1104 MpegEncContext *s = avctx->priv_data;
1107 return ff_videotoolbox_common_end_frame(avctx, frame);
1110 static int videotoolbox_prores_start_frame(AVCodecContext *avctx,
1117 static int videotoolbox_prores_decode_slice(AVCodecContext *avctx,
1121 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
1126 static int videotoolbox_prores_end_frame(AVCodecContext *avctx)
1128 ProresContext *ctx = avctx->priv_data;
1131 return ff_videotoolbox_common_end_frame(avctx, frame);
1134 static enum AVPixelFormat videotoolbox_best_pixel_format(AVCodecContext *avctx) {
1135 const AVPixFmtDescriptor *descriptor = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
1176 int ff_videotoolbox_common_init(AVCodecContext *avctx)
1178 VTContext *vtctx = avctx->internal->hwaccel_priv_data;
1182 vtctx->logctx = avctx;
1185 if (avctx->hwaccel_context)
1188 if (!avctx->hw_frames_ctx && !avctx->hw_device_ctx) {
1189 av_log(avctx, AV_LOG_ERROR,
1200 if (avctx->hw_frames_ctx) {
1201 hw_frames = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1203 avctx->hw_frames_ctx = av_hwframe_ctx_alloc(avctx->hw_device_ctx);
1204 if (!avctx->hw_frames_ctx) {
1209 hw_frames = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
1211 hw_frames->sw_format = videotoolbox_best_pixel_format(avctx);
1212 hw_frames->width = avctx->width;
1213 hw_frames->height = avctx->height;
1215 err = av_hwframe_ctx_init(avctx->hw_frames_ctx);
1217 av_buffer_unref(&avctx->hw_frames_ctx);
1222 vtctx->cached_hw_frames_ctx = av_buffer_ref(avctx->hw_frames_ctx);
1228 bool full_range = avctx->color_range == AVCOL_RANGE_JPEG;
1234 av_log(avctx, AV_LOG_ERROR,
1238 av_color_range_name(avctx->color_range));
1243 err = videotoolbox_start(avctx);
1250 ff_videotoolbox_uninit(avctx);
1254 int ff_videotoolbox_frame_params(AVCodecContext *avctx,
1260 frames_ctx->width = avctx->coded_width;
1261 frames_ctx->height = avctx->coded_height;
1262 frames_ctx->sw_format = videotoolbox_best_pixel_format(avctx);
1397 int av_videotoolbox_default_init(AVCodecContext *avctx)
1399 return av_videotoolbox_default_init2(avctx, NULL);
1402 int av_videotoolbox_default_init2(AVCodecContext *avctx, AVVideotoolboxContext *vtctx)
1404 enum AVPixelFormat pix_fmt = videotoolbox_best_pixel_format(avctx);
1405 bool full_range = avctx->color_range == AVCOL_RANGE_JPEG;
1406 avctx->hwaccel_context = vtctx ?: av_videotoolbox_alloc_context_with_pix_fmt(pix_fmt, full_range);
1407 if (!avctx->hwaccel_context)
1409 return videotoolbox_start(avctx);
1412 void av_videotoolbox_default_free(AVCodecContext *avctx)
1415 videotoolbox_stop(avctx);
1416 av_freep(&avctx->hwaccel_context);