History

avcodec/encode: restructure the core encoding code

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

James Almer committed 6 years ago

Commit 827d6fe1 parent 71f19bf27 files · +443 −220Browse files

Showing the changes to libavcodec/vaapi_encode.c (1 of 27 files). Show all

Unified · Split

libavcodec/vaapi_encode.c+23−4
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525 #include "libavutil/pixdesc.h"
2626
2727 #include "vaapi_encode.h"
28+#include "encode.h"
2829 #include "avcodec.h"
2930
3031 const AVCodecHWConfigInternal *ff_vaapi_encode_hw_configs[] = {
@@ -1043,7 +1044,7 @@ static int vaapi_encode_check_frame(AVCodecContext *avctx, · 1012 unmodified lines
10431044 return 0;
10441045 }
10451046
1046−int ff_vaapi_encode_send_frame(AVCodecContext *avctx, const AVFrame *frame)
1047+static int vaapi_encode_send_frame(AVCodecContext *avctx, AVFrame *frame)
10471048 {
10481049 VAAPIEncodeContext *ctx = avctx->priv_data;
10491050 VAAPIEncodePicture *pic;
@@ -1066,9 +1067,6 @@ int ff_vaapi_encode_send_frame(AVCodecContext *avctx, const AVFrame *frame) · 16 unmodified lines
10661067 err = AVERROR(ENOMEM);
10671068 goto fail;
10681069 }
1069− err = av_frame_ref(pic->input_image, frame);
1070− if (err < 0)
1071− goto fail;
10721070
10731071 if (ctx->input_order == 0 || frame->pict_type == AV_PICTURE_TYPE_I)
10741072 pic->force_idr = 1;
@@ -1076,6 +1074,8 @@ int ff_vaapi_encode_send_frame(AVCodecContext *avctx, const AVFrame *frame) · 1 unmodified line
10761074 pic->input_surface = (VASurfaceID)(uintptr_t)frame->data[3];
10771075 pic->pts = frame->pts;
10781076
1077+ av_frame_move_ref(pic->input_image, frame);
1078+
10791079 if (ctx->input_order == 0)
10801080 ctx->first_pts = pic->pts;
10811081 if (ctx->input_order == ctx->decode_delay)
@@ -1114,8 +1114,20 @@ int ff_vaapi_encode_receive_packet(AVCodecContext *avctx, AVPacket *pkt) · 32 unmodified lines
11141114 {
11151115 VAAPIEncodeContext *ctx = avctx->priv_data;
11161116 VAAPIEncodePicture *pic;
1117+ AVFrame *frame = ctx->frame;
11171118 int err;
11181119
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+
11191131 if (!ctx->pic_start) {
11201132 if (ctx->end_of_stream)
11211133 return AVERROR_EOF;
@@ -2214,6 +2226,11 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) · 1092 unmodified lines
22142226 VAStatus vas;
22152227 int err;
22162228
2229+ ctx->frame = av_frame_alloc();
2230+ if (!ctx->frame) {
2231+ return AVERROR(ENOMEM);
2232+ }
2233+
22172234 if (!avctx->hw_frames_ctx) {
22182235 av_log(avctx, AV_LOG_ERROR, "A hardware frames reference is "
22192236 "required to associate the encoding device.\n");
@@ -2391,6 +2408,8 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx) · 171 unmodified lines
23912408 ctx->va_config = VA_INVALID_ID;
23922409 }
23932410
2411+ av_frame_free(&ctx->frame);
2412+
23942413 av_freep(&ctx->codec_sequence_params);
23952414 av_freep(&ctx->codec_picture_params);
23962415

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t