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
48 PICTURE_TYPE_B = 3,48 PICTURE_TYPE_B = 3,
49};49};
50 50
51enum {
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
60typedef struct VAAPIEncodeSlice {51typedef struct VAAPIEncodeSlice {
61 void *priv_data;52 void *priv_data;
62 void *codec_slice_params;53 void *codec_slice_params;
@@ -102,43 +93,65 @@ typedef struct VAAPIEncodeContext { · 39 unmodified lines
102 // Codec-specific hooks.93 // Codec-specific hooks.
103 const struct VAAPIEncodeType *codec;94 const struct VAAPIEncodeType *codec;
104 95
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
105 // Codec-specific state.114 // Codec-specific state.
106 void *priv_data;115 void *priv_data;
107 116
108 VAProfile va_profile;117 // Configuration attributes to use when creating va_config.
109 VAEntrypoint va_entrypoint;118 VAConfigAttrib config_attributes[MAX_CONFIG_ATTRIBUTES];
119 int nb_config_attributes;
120
110 VAConfigID va_config;121 VAConfigID va_config;
111 VAContextID va_context;122 VAContextID va_context;
112 123
113 int va_rc_mode;
114
115 AVBufferRef *device_ref;124 AVBufferRef *device_ref;
116 AVHWDeviceContext *device;125 AVHWDeviceContext *device;
117 AVVAAPIDeviceContext *hwctx;126 AVVAAPIDeviceContext *hwctx;
118 127
128 // The hardware frame context containing the input frames.
119 AVBufferRef *input_frames_ref;129 AVBufferRef *input_frames_ref;
120 AVHWFramesContext *input_frames;130 AVHWFramesContext *input_frames;
121 131
122 // Input size, set from input frames.132 // The hardware frame context containing the reconstructed 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;
130 AVBufferRef *recon_frames_ref;133 AVBufferRef *recon_frames_ref;
131 AVHWFramesContext *recon_frames;134 AVHWFramesContext *recon_frames;
132 135
136 // Pool of (reusable) bitstream output buffers.
133 AVBufferPool *output_buffer_pool;137 AVBufferPool *output_buffer_pool;
134 138
135 VAConfigAttrib config_attributes[MAX_CONFIG_ATTRIBUTES];139 // Global parameters which will be applied at the start of the
136 int nb_config_attributes;140 // sequence (includes rate control parameters below).
137
138 VAEncMiscParameterBuffer *global_params[MAX_GLOBAL_PARAMS];141 VAEncMiscParameterBuffer *global_params[MAX_GLOBAL_PARAMS];
139 size_t global_params_size[MAX_GLOBAL_PARAMS];142 size_t global_params_size[MAX_GLOBAL_PARAMS];
140 int nb_global_params;143 int nb_global_params;
141 144
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
142 // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).155 // Per-sequence parameter structure (VAEncSequenceParameterBuffer*).
143 void *codec_sequence_params;156 void *codec_sequence_params;
144 157
@@ -158,7 +171,15 @@ typedef struct VAAPIEncodeContext { · 13 unmodified lines
158 // Next output order index (encode order).171 // Next output order index (encode order).
159 int64_t output_order;172 int64_t output_order;
160 173
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;
162 183
163 // Timestamp handling.184 // Timestamp handling.
164 int64_t first_pts;185 int64_t first_pts;
@@ -183,15 +204,20 @@ typedef struct VAAPIEncodeContext { · 18 unmodified lines
183 204
184 205
185typedef struct VAAPIEncodeType {206typedef struct VAAPIEncodeType {
186 size_t priv_data_size;207 size_t priv_data_size;
187 208
188 int (*init)(AVCodecContext *avctx);209 // Perform any extra codec-specific configuration after the
189 int (*close)(AVCodecContext *avctx);210 // codec context is initialised (set up the private data and
211 // add any necessary global parameters).
212 int (*configure)(AVCodecContext *avctx);
190 213
214 // The size of the parameter structures:
215 // sizeof(VAEnc{type}ParameterBuffer{codec}).
191 size_t sequence_params_size;216 size_t sequence_params_size;
192 size_t picture_params_size;217 size_t picture_params_size;
193 size_t slice_params_size;218 size_t slice_params_size;
194 219
220 // Fill the parameter structures.
195 int (*init_sequence_params)(AVCodecContext *avctx);221 int (*init_sequence_params)(AVCodecContext *avctx);
196 int (*init_picture_params)(AVCodecContext *avctx,222 int (*init_picture_params)(AVCodecContext *avctx,
197 VAAPIEncodePicture *pic);223 VAAPIEncodePicture *pic);
@@ -199,10 +225,13 @@ typedef struct VAAPIEncodeType { · 1 unmodified line
199 VAAPIEncodePicture *pic,225 VAAPIEncodePicture *pic,
200 VAAPIEncodeSlice *slice);226 VAAPIEncodeSlice *slice);
201 227
228 // The type used by the packed header: this should look like
229 // VAEncPackedHeader{something}.
202 int sequence_header_type;230 int sequence_header_type;
203 int picture_header_type;231 int picture_header_type;
204 int slice_header_type;232 int slice_header_type;
205 233
234 // Write the packed header data to the provided buffer.
206 int (*write_sequence_header)(AVCodecContext *avctx,235 int (*write_sequence_header)(AVCodecContext *avctx,
207 char *data, size_t *data_len);236 char *data, size_t *data_len);
208 int (*write_picture_header)(AVCodecContext *avctx,237 int (*write_picture_header)(AVCodecContext *avctx,
@@ -213,10 +242,18 @@ typedef struct VAAPIEncodeType { · 4 unmodified lines
213 VAAPIEncodeSlice *slice,242 VAAPIEncodeSlice *slice,
214 char *data, size_t *data_len);243 char *data, size_t *data_len);
215 244
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.
216 int (*write_extra_buffer)(AVCodecContext *avctx,249 int (*write_extra_buffer)(AVCodecContext *avctx,
217 VAAPIEncodePicture *pic,250 VAAPIEncodePicture *pic,
218 int index, int *type,251 int index, int *type,
219 char *data, size_t *data_len);252 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.
220 int (*write_extra_header)(AVCodecContext *avctx,257 int (*write_extra_header)(AVCodecContext *avctx,
221 VAAPIEncodePicture *pic,258 VAAPIEncodePicture *pic,
222 int index, int *type,259 int index, int *type,
@@ -227,8 +264,7 @@ typedef struct VAAPIEncodeType { · 4 unmodified lines
227int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,264int ff_vaapi_encode2(AVCodecContext *avctx, AVPacket *pkt,
228 const AVFrame *input_image, int *got_packet);265 const AVFrame *input_image, int *got_packet);
229 266
230int ff_vaapi_encode_init(AVCodecContext *avctx,267int ff_vaapi_encode_init(AVCodecContext *avctx);
231 const VAAPIEncodeType *type);
232int ff_vaapi_encode_close(AVCodecContext *avctx);268int ff_vaapi_encode_close(AVCodecContext *avctx);
233 269
234#endif /* AVCODEC_VAAPI_ENCODE_H */270#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