History

vaapi_encode: Refactor initialisation

This allows better checking of capabilities and will make it easier to add more functionality later. It also commonises some duplicated code around rate control setup and adds more comments explaining the internals. (cherry picked from commit 80a5d05108cb218e8cd2e25c6621a3bfef0a832e)

Mark Thompson committed 10 years ago

Commit c8241e71 parent 06d73d05 files · +420 −445Browse files

Showing the changes to libavcodec/vaapi_encode.h (1 of 5 files). Show all

Unified · Split

libavcodec/vaapi_encode.h+66−30
@@ -48,15 +48,6 @@ enum { · 47 unmodified lines
4848 PICTURE_TYPE_B = 3,
4949 };
5050
51−enum {
52− // All encode operations are done independently.
53− ISSUE_MODE_SERIALISE_EVERYTHING = 0,
54− // Overlap as many operations as possible.
55− ISSUE_MODE_MAXIMISE_THROUGHPUT,
56− // Overlap operations only when satisfying parallel dependencies.
57− ISSUE_MODE_MINIMISE_LATENCY,
58−};
59−
6051 typedef struct VAAPIEncodeSlice {
6152 void *priv_data;
6253 void *codec_slice_params;
@@ -102,43 +93,65 @@ typedef struct VAAPIEncodeContext { · 39 unmodified lines
10293 // Codec-specific hooks.
10394 const struct VAAPIEncodeType *codec;
10495
96+ // Encoding profile (VAProfileXXX).
97+ VAProfile va_profile;
98+ // Encoding entrypoint (usually VAEntryointEncSlice).
99+ VAEntrypoint va_entrypoint;
100+ // Surface colour/sampling format (usually VA_RT_FORMAT_YUV420).
101+ unsigned int va_rt_format;
102+ // Rate control mode.
103+ unsigned int va_rc_mode;
104+
105+ // The required size of surfaces. This is probably the input
106+ // size (AVCodecContext.width|height) aligned up to whatever
107+ // block size is required by the codec.
108+ int surface_width;
109+ int surface_height;
110+
111+ // Everything above this point must be set before calling
112+ // ff_vaapi_encode_init().
113+
105114 // Codec-specific state.
106115 void *priv_data;
107116
108− VAProfile va_profile;
109− VAEntrypoint va_entrypoint;
117+ // Configuration attributes to use when creating va_config.
118+ VAConfigAttrib config_attributes[MAX_CONFIG_ATTRIBUTES];
119+ int nb_config_attributes;
120+
110121 VAConfigID va_config;
111122 VAContextID va_context;
112123
113− int va_rc_mode;
114−
115124 AVBufferRef *device_ref;
116125 AVHWDeviceContext *device;
117126 AVVAAPIDeviceContext *hwctx;
118127
128+ // The hardware frame context containing the input frames.
119129 AVBufferRef *input_frames_ref;
120130 AVHWFramesContext *input_frames;
121131
122− // Input size, set from input frames.
123− int input_width;
124− int input_height;
125− // Aligned size, set by codec init, becomes hwframe size.
126− int aligned_width;
127− int aligned_height;
128−
129− int nb_recon_frames;
132+ // The hardware frame context containing the reconstructed frames.
130133 AVBufferRef *recon_frames_ref;
131134 AVHWFramesContext *recon_frames;
132135
136+ // Pool of (reusable) bitstream output buffers.
133137 AVBufferPool *output_buffer_pool;
134138
135− VAConfigAttrib config_attributes[MAX_CONFIG_ATTRIBUTES];
136− int nb_config_attributes;
137−
139+ // Global parameters which will be applied at the start of the
140+ // sequence (includes rate control parameters below).
138141 VAEncMiscParameterBuffer *global_params[MAX_GLOBAL_PARAMS];
139142 size_t global_params_size[MAX_GLOBAL_PARAMS];
140143 int nb_global_params;
141144
145+ // Rate control parameters.
146+ struct {
147+ VAEncMiscParameterBuffer misc;
148+ VAEncMiscParameterRateControl rc;
149+ } rc_params;
150+ struct {
151+ VAEncMiscParameterBuffer misc;
152+ VAEncMiscParameterHRD hrd;
153+ } hrd_params;
154+
142155 // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).
143156 void *codec_sequence_params;
144157
@@ -158,7 +171,15 @@ typedef struct VAAPIEncodeContext { · 13 unmodified lines
158171 // Next output order index (encode order).
159172 int64_t output_order;
160173
161− int issue_mode;
174+ enum {
175+ // All encode operations are done independently (synchronise
176+ // immediately after every operation).
177+ ISSUE_MODE_SERIALISE_EVERYTHING = 0,
178+ // Overlap as many operations as possible.
179+ ISSUE_MODE_MAXIMISE_THROUGHPUT,
180+ // Overlap operations only when satisfying parallel dependencies.
181+ ISSUE_MODE_MINIMISE_LATENCY,
182+ } issue_mode;
162183
163184 // Timestamp handling.
164185 int64_t first_pts;
@@ -183,15 +204,20 @@ typedef struct VAAPIEncodeContext { · 18 unmodified lines
183204
184205
185206 typedef struct VAAPIEncodeType {
186− size_t priv_data_size;
207+ size_t priv_data_size;
187208
188− int (*init)(AVCodecContext *avctx);
189− int (*close)(AVCodecContext *avctx);
209+ // Perform any extra codec-specific configuration after the
210+ // codec context is initialised (set up the private data and
211+ // add any necessary global parameters).
212+ int (*configure)(AVCodecContext *avctx);
190213
214+ // The size of the parameter structures:
215+ // sizeof(VAEnc{type}ParameterBuffer{codec}).
191216 size_t sequence_params_size;
192217 size_t picture_params_size;
193218 size_t slice_params_size;
194219
220+ // Fill the parameter structures.
195221 int (*init_sequence_params)(AVCodecContext *avctx);
196222 int (*init_picture_params)(AVCodecContext *avctx,
197223 VAAPIEncodePicture *pic);
@@ -199,10 +225,13 @@ typedef struct VAAPIEncodeType { · 1 unmodified line
199225 VAAPIEncodePicture *pic,
200226 VAAPIEncodeSlice *slice);
201227
228+ // The type used by the packed header: this should look like
229+ // VAEncPackedHeader{something}.
202230 int sequence_header_type;
203231 int picture_header_type;
204232 int slice_header_type;
205233
234+ // Write the packed header data to the provided buffer.
206235 int (*write_sequence_header)(AVCodecContext *avctx,
207236 char *data, size_t *data_len);
208237 int (*write_picture_header)(AVCodecContext *avctx,
@@ -213,10 +242,18 @@ typedef struct VAAPIEncodeType { · 4 unmodified lines
213242 VAAPIEncodeSlice *slice,
214243 char *data, size_t *data_len);
215244
245+ // Fill an extra parameter structure, which will then be
246+ // passed to vaRenderPicture(). Will be called repeatedly
247+ // with increasing index argument until AVERROR_EOF is
248+ // returned.
216249 int (*write_extra_buffer)(AVCodecContext *avctx,
217250 VAAPIEncodePicture *pic,
218251 int index, int *type,
219252 char *data, size_t *data_len);
253+
254+ // Write an extra packed header. Will be called repeatedly
255+ // with increasing index argument until AVERROR_EOF is
256+ // returned.
220257 int (*write_extra_header)(AVCodecContext *avctx,
221258 VAAPIEncodePicture *pic,
222259 int index, int *type,
@@ -227,8 +264,7 @@ typedef struct VAAPIEncodeType { · 4 unmodified lines
227264 int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,
228265 const AVFrame *input_image, int *got_packet);
229266
230−int ff_vaapi_encode_init(AVCodecContext *avctx,
231− const VAAPIEncodeType *type);
267+int ff_vaapi_encode_init(AVCodecContext *avctx);
232268 int ff_vaapi_encode_close(AVCodecContext *avctx);
233269
234270 #endif /* AVCODEC_VAAPI_ENCODE_H */

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