This commit follows the same logic as 061a0c14bb, but for the encode API: The new public encoding API will no longer be a wrapper around the old deprecated one, and the internal API used by the encoders now consists of a single receive_packet() callback that pulls frames as required. amf encoders adapted by James Almer librav1e encoder adapted by James Almer nvidia encoders adapted by James Almer MediaFoundation encoders adapted by James Almer vaapi encoders adapted by Linjie Fu v4l2_m2m encoders adapted by Andriy Gelman
Showing the changes to libavcodec/vaapi_encode.c (1 of 27 files). Show all
Unified · Split
| @@ -25,6 +25,7 @@ · 24 unmodified lines | |||
| 25 | #include "libavutil/pixdesc.h" | 25 | #include "libavutil/pixdesc.h" |
| 26 | 26 | ||
| 27 | #include "vaapi_encode.h" | 27 | #include "vaapi_encode.h" |
| 28 | #include "encode.h" | ||
| 28 | #include "avcodec.h" | 29 | #include "avcodec.h" |
| 29 | 30 | ||
| 30 | const AVCodecHWConfigInternal *ff_vaapi_encode_hw_configs[] = { | 31 | const AVCodecHWConfigInternal *ff_vaapi_encode_hw_configs[] = { |
| @@ -1043,7 +1044,7 @@ static int vaapi_encode_check_frame(AVCodecContext *avctx, · 1012 unmodified lines | |||
| 1043 | return 0; | 1044 | return 0; |
| 1044 | } | 1045 | } |
| 1045 | 1046 | ||
| 1046 | int ff_vaapi_encode_send_frame(AVCodecContext *avctx, const AVFrame *frame) | 1047 | static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame) |
| 1047 | { | 1048 | { |
| 1048 | VAAPIEncodeContext *ctx = avctx->priv_data; | 1049 | VAAPIEncodeContext *ctx = avctx->priv_data; |
| 1049 | VAAPIEncodePicture *pic; | 1050 | VAAPIEncodePicture *pic; |
| @@ -1066,9 +1067,6 @@ int ff_vaapi_encode_send_frame(AVCodecContext *avctx, const AVFrame *frame) · 16 unmodified lines | |||
| 1066 | err = AVERROR(ENOMEM); | 1067 | err = AVERROR(ENOMEM); |
| 1067 | goto fail; | 1068 | goto fail; |
| 1068 | } | 1069 | } |
| 1069 | err = av_frame_ref(pic->input_image, frame); | ||
| 1070 | if (err < 0) | ||
| 1071 | goto fail; | ||
| 1072 | 1070 | ||
| 1073 | if (ctx->input_order == 0 || frame->pict_type == AV_PICTURE_TYPE_I) | 1071 | if (ctx->input_order == 0 || frame->pict_type == AV_PICTURE_TYPE_I) |
| 1074 | pic->force_idr = 1; | 1072 | pic->force_idr = 1; |
| @@ -1076,6 +1074,8 @@ int ff_vaapi_encode_send_frame(AVCodecContext *avctx, const AVFrame *frame) · 1 unmodified line | |||
| 1076 | pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3]; | 1074 | pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3]; |
| 1077 | pic->pts = frame->pts; | 1075 | pic->pts = frame->pts; |
| 1078 | 1076 | ||
| 1077 | av_frame_move_ref(pic->input_image, frame); | ||
| 1078 | |||
| 1079 | if (ctx->input_order == 0) | 1079 | if (ctx->input_order == 0) |
| 1080 | ctx->first_pts = pic->pts; | 1080 | ctx->first_pts = pic->pts; |
| 1081 | if (ctx->input_order == ctx->decode_delay) | 1081 | if (ctx->input_order == ctx->decode_delay) |
| @@ -1114,8 +1114,20 @@ int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt) · 32 unmodified lines | |||
| 1114 | { | 1114 | { |
| 1115 | VAAPIEncodeContext *ctx = avctx->priv_data; | 1115 | VAAPIEncodeContext *ctx = avctx->priv_data; |
| 1116 | VAAPIEncodePicture *pic; | 1116 | VAAPIEncodePicture *pic; |
| 1117 | AVFrame *frame = ctx->frame; | ||
| 1117 | int err; | 1118 | int err; |
| 1118 | 1119 | ||
| 1120 | err = ff_encode_get_frame(avctx, frame); | ||
| 1121 | if (err < 0 && err != AVERROR_EOF) | ||
| 1122 | return err; | ||
| 1123 | |||
| 1124 | if (err == AVERROR_EOF) | ||
| 1125 | frame = NULL; | ||
| 1126 | |||
| 1127 | err = vaapi_encode_send_frame(avctx, frame); | ||
| 1128 | if (err < 0) | ||
| 1129 | return err; | ||
| 1130 | |||
| 1119 | if (!ctx->pic_start) { | 1131 | if (!ctx->pic_start) { |
| 1120 | if (ctx->end_of_stream) | 1132 | if (ctx->end_of_stream) |
| 1121 | return AVERROR_EOF; | 1133 | return AVERROR_EOF; |
| @@ -2214,6 +2226,11 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) · 1092 unmodified lines | |||
| 2214 | VAStatus vas; | 2226 | VAStatus vas; |
| 2215 | int err; | 2227 | int err; |
| 2216 | 2228 | ||
| 2229 | ctx->frame = av_frame_alloc(); | ||
| 2230 | if (!ctx->frame) { | ||
| 2231 | return AVERROR(ENOMEM); | ||
| 2232 | } | ||
| 2233 | |||
| 2217 | if (!avctx->hw_frames_ctx) { | 2234 | if (!avctx->hw_frames_ctx) { |
| 2218 | av_log(avctx, AV_LOG_ERROR, "A hardware frames reference is " | 2235 | av_log(avctx, AV_LOG_ERROR, "A hardware frames reference is " |
| 2219 | "required to associate the encoding device.\n"); | 2236 | "required to associate the encoding device.\n"); |
| @@ -2391,6 +2408,8 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx) · 171 unmodified lines | |||
| 2391 | ctx->va_config = VA_INVALID_ID; | 2408 | ctx->va_config = VA_INVALID_ID; |
| 2392 | } | 2409 | } |
| 2393 | 2410 | ||
| 2411 | av_frame_free(&ctx->frame); | ||
| 2412 | |||
| 2394 | av_freep(&ctx->codec_sequence_params); | 2413 | av_freep(&ctx->codec_sequence_params); |
| 2395 | av_freep(&ctx->codec_picture_params); | 2414 | av_freep(&ctx->codec_picture_params); |
| 2396 | 2415 | ||