FFmpeg
Loading...
Searching...
No Matches
cbs_vp9_syntax_template.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
21{
22 int err;
23
24 fixed(8, frame_sync_byte_0, VP9_FRAME_SYNC_0);
25 fixed(8, frame_sync_byte_1, VP9_FRAME_SYNC_1);
26 fixed(8, frame_sync_byte_2, VP9_FRAME_SYNC_2);
27
28 return 0;
29}
30
33{
34 CodedBitstreamVP9Context *vp9 = ctx->priv_data;
35 int err;
36
37 if (profile >= 2) {
38 f(1, ten_or_twelve_bit);
39 vp9->bit_depth = current->ten_or_twelve_bit ? 12 : 10;
40 } else
41 vp9->bit_depth = 8;
42
43 f(3, color_space);
44
45 if (current->color_space != VP9_CS_RGB) {
46 f(1, color_range);
47 if (profile == 1 || profile == 3) {
48 f(1, subsampling_x);
49 f(1, subsampling_y);
50 fixed(1, reserved_zero, 0);
51 } else {
52 infer(subsampling_x, 1);
53 infer(subsampling_y, 1);
54 }
55 } else {
57 if (profile == 1 || profile == 3) {
58 infer(subsampling_x, 0);
59 infer(subsampling_y, 0);
60 fixed(1, reserved_zero, 0);
61 }
62 }
63
64 vp9->subsampling_x = current->subsampling_x;
65 vp9->subsampling_y = current->subsampling_y;
66
67 return 0;
68}
69
72{
73 CodedBitstreamVP9Context *vp9 = ctx->priv_data;
74 int err;
75
76 f(16, frame_width_minus_1);
77 f(16, frame_height_minus_1);
78
79 vp9->frame_width = current->frame_width_minus_1 + 1;
80 vp9->frame_height = current->frame_height_minus_1 + 1;
81
82 vp9->mi_cols = (vp9->frame_width + 7) >> 3;
83 vp9->mi_rows = (vp9->frame_height + 7) >> 3;
84 vp9->sb64_cols = (vp9->mi_cols + 7) >> 3;
85 vp9->sb64_rows = (vp9->mi_rows + 7) >> 3;
86
87 return 0;
88}
89
92{
93 int err;
94
95 f(1, render_and_frame_size_different);
96
97 if (current->render_and_frame_size_different) {
98 f(16, render_width_minus_1);
99 f(16, render_height_minus_1);
100 }
101
102 return 0;
103}
104
107{
108 CodedBitstreamVP9Context *vp9 = ctx->priv_data;
109 int err, i;
110
111 for (i = 0; i < VP9_REFS_PER_FRAME; i++) {
112 fs(1, found_ref[i], 1, i);
113 if (current->found_ref[i]) {
115 &vp9->ref[current->ref_frame_idx[i]];
116
117 vp9->frame_width = ref->frame_width;
118 vp9->frame_height = ref->frame_height;
119
120 vp9->subsampling_x = ref->subsampling_x;
121 vp9->subsampling_y = ref->subsampling_y;
122 vp9->bit_depth = ref->bit_depth;
123
124 break;
125 }
126 }
127 if (i >= VP9_REFS_PER_FRAME)
129 else {
130 vp9->mi_cols = (vp9->frame_width + 7) >> 3;
131 vp9->mi_rows = (vp9->frame_height + 7) >> 3;
132 vp9->sb64_cols = (vp9->mi_cols + 7) >> 3;
133 vp9->sb64_rows = (vp9->mi_rows + 7) >> 3;
134 }
136
137 return 0;
138}
139
142{
143 int err;
144
145 f(1, is_filter_switchable);
146 if (!current->is_filter_switchable)
147 f(2, raw_interpolation_filter_type);
148
149 return 0;
150}
151
154{
155 int err, i;
156
157 f(6, loop_filter_level);
158 f(3, loop_filter_sharpness);
159
160 f(1, loop_filter_delta_enabled);
161 if (current->loop_filter_delta_enabled) {
162 f(1, loop_filter_delta_update);
163 if (current->loop_filter_delta_update) {
164 for (i = 0; i < VP9_MAX_REF_FRAMES; i++) {
165 fs(1, update_ref_delta[i], 1, i);
166 if (current->update_ref_delta[i])
167 ss(6, loop_filter_ref_deltas[i], 1, i);
168 }
169 for (i = 0; i < 2; i++) {
170 fs(1, update_mode_delta[i], 1, i);
171 if (current->update_mode_delta[i])
172 ss(6, loop_filter_mode_deltas[i], 1, i);
173 }
174 }
175 } else {
176 infer(loop_filter_delta_update, 0);
177 }
178
179 return 0;
180}
181
184{
185 int err;
186
187 f(8, base_q_idx);
188
189 delta_q(delta_q_y_dc);
190 delta_q(delta_q_uv_dc);
191 delta_q(delta_q_uv_ac);
192
193 return 0;
194}
195
198{
199 static const uint8_t segmentation_feature_bits[VP9_SEG_LVL_MAX] = { 8, 6, 2, 0 };
200 static const uint8_t segmentation_feature_signed[VP9_SEG_LVL_MAX] = { 1, 1, 0, 0 };
201 int err, i, j;
202
203 f(1, segmentation_enabled);
204
205 if (current->segmentation_enabled) {
206 f(1, segmentation_update_map);
207 if (current->segmentation_update_map) {
208 for (i = 0; i < 7; i++)
209 prob(segmentation_tree_probs[i], 1, i);
210 f(1, segmentation_temporal_update);
211 for (i = 0; i < 3; i++) {
212 if (current->segmentation_temporal_update)
213 prob(segmentation_pred_prob[i], 1, i);
214 else
215 infer(segmentation_pred_prob[i], 255);
216 }
217 }
218
219 f(1, segmentation_update_data);
220 if (current->segmentation_update_data) {
221 f(1, segmentation_abs_or_delta_update);
222 for (i = 0; i < VP9_MAX_SEGMENTS; i++) {
223 for (j = 0; j < VP9_SEG_LVL_MAX; j++) {
224 fs(1, feature_enabled[i][j], 2, i, j);
225 if (current->feature_enabled[i][j] &&
226 segmentation_feature_bits[j]) {
227 fs(segmentation_feature_bits[j],
228 feature_value[i][j], 2, i, j);
229 if (segmentation_feature_signed[j])
230 fs(1, feature_sign[i][j], 2, i, j);
231 else
232 infer(feature_sign[i][j], 0);
233 } else {
234 infer(feature_value[i][j], 0);
235 infer(feature_sign[i][j], 0);
236 }
237 }
238 }
239 }
240 } else {
241 infer(segmentation_update_data, 0);
242 }
243
244 return 0;
245}
246
249{
250 CodedBitstreamVP9Context *vp9 = ctx->priv_data;
251 int min_log2_tile_cols, max_log2_tile_cols;
252 int err;
253
254 min_log2_tile_cols = 0;
255 while ((VP9_MAX_TILE_WIDTH_B64 << min_log2_tile_cols) < vp9->sb64_cols)
256 ++min_log2_tile_cols;
257 max_log2_tile_cols = 0;
258 while ((vp9->sb64_cols >> (max_log2_tile_cols + 1)) >= VP9_MIN_TILE_WIDTH_B64)
259 ++max_log2_tile_cols;
260
261 increment(tile_cols_log2, min_log2_tile_cols, max_log2_tile_cols);
262
263 increment(tile_rows_log2, 0, 2);
264
265 return 0;
266}
267
270{
271 CodedBitstreamVP9Context *vp9 = ctx->priv_data;
272 int err, i;
273
274 f(2, frame_marker);
275
276 f(1, profile_low_bit);
277 f(1, profile_high_bit);
278 vp9->profile = (current->profile_high_bit << 1) + current->profile_low_bit;
279 if (vp9->profile == 3)
280 fixed(1, reserved_zero, 0);
281
282 f(1, show_existing_frame);
283 if (current->show_existing_frame) {
284 f(3, frame_to_show_map_idx);
285 infer(header_size_in_bytes, 0);
286 infer(refresh_frame_flags, 0x00);
287 infer(loop_filter_level, 0);
288 return 0;
289 }
290
291 f(1, frame_type);
292 f(1, show_frame);
293 f(1, error_resilient_mode);
294
295 if (current->frame_type == VP9_KEY_FRAME) {
300
301 infer(refresh_frame_flags, 0xff);
302
303 } else {
304 if (current->show_frame == 0)
305 f(1, intra_only);
306 else
307 infer(intra_only, 0);
308
309 if (current->error_resilient_mode == 0)
310 f(2, reset_frame_context);
311 else
312 infer(reset_frame_context, 0);
313
314 if (current->intra_only == 1) {
316
317 if (vp9->profile > 0) {
319 } else {
320 infer(color_space, 1);
321 infer(subsampling_x, 1);
322 infer(subsampling_y, 1);
323 vp9->bit_depth = 8;
324
325 vp9->subsampling_x = current->subsampling_x;
326 vp9->subsampling_y = current->subsampling_y;
327 }
328
329 f(8, refresh_frame_flags);
330
333 } else {
334 f(8, refresh_frame_flags);
335
336 for (i = 0; i < VP9_REFS_PER_FRAME; i++) {
337 fs(3, ref_frame_idx[i], 1, i);
338 fs(1, ref_frame_sign_bias[VP9_LAST_FRAME + i],
339 1, VP9_LAST_FRAME + i);
340 }
341
343 f(1, allow_high_precision_mv);
345 }
346 }
347
348 if (current->error_resilient_mode == 0) {
349 f(1, refresh_frame_context);
350 f(1, frame_parallel_decoding_mode);
351 } else {
352 infer(refresh_frame_context, 0);
353 infer(frame_parallel_decoding_mode, 1);
354 }
355
356 f(2, frame_context_idx);
357
362
363 f(16, header_size_in_bytes);
364
365 for (i = 0; i < VP9_NUM_REF_FRAMES; i++) {
366 if (current->refresh_frame_flags & (1 << i)) {
367 vp9->ref[i] = (VP9ReferenceFrameState) {
368 .frame_width = vp9->frame_width,
369 .frame_height = vp9->frame_height,
370 .subsampling_x = vp9->subsampling_x,
371 .subsampling_y = vp9->subsampling_y,
372 .bit_depth = vp9->bit_depth,
373 };
374 }
375 }
376
377 // Update top-level loop filter and segmentation state with changes
378 // from this frame.
379 if (current->frame_type == VP9_KEY_FRAME ||
380 current->intra_only ||
381 current->error_resilient_mode) {
382 // setup_past_independence() - fill with the initial values.
383
388
389 vp9->loop_filter_mode_deltas[0] = 0;
390 vp9->loop_filter_mode_deltas[1] = 0;
391
392 memset(vp9->feature_enabled, 0, sizeof(vp9->feature_enabled));
393 memset(vp9->feature_value, 0, sizeof(vp9->feature_value));
394 memset(vp9->feature_sign, 0, sizeof(vp9->feature_sign));
395 }
396
397 // Modify previous state based on updates in this frame.
398 if (current->loop_filter_delta_update) {
399 for (i = 0; i < 4; i++) {
400 if (current->update_ref_delta[i])
402 current->loop_filter_ref_deltas[i];
403 }
404 for (i = 0; i < 2; i++) {
405 if (current->update_mode_delta[i])
407 current->loop_filter_mode_deltas[i];
408 }
409 }
410
411 if (current->segmentation_update_data) {
412 memcpy(vp9->feature_enabled, current->feature_enabled,
413 sizeof(vp9->feature_enabled));
414 memcpy(vp9->feature_value, current->feature_value,
415 sizeof(vp9->feature_value));
416 memcpy(vp9->feature_sign, current->feature_sign,
417 sizeof(vp9->feature_sign));
418
419 if (current->segmentation_update_map) {
420 memcpy(vp9->segmentation_tree_probs,
421 current->segmentation_tree_probs,
422 sizeof(vp9->segmentation_tree_probs));
423 memcpy(vp9->segmentation_pred_prob,
424 current->segmentation_pred_prob,
425 sizeof(vp9->segmentation_pred_prob));
426 }
427 }
428
429 av_log(ctx->log_ctx, AV_LOG_DEBUG, "Frame: size %dx%d "
430 "subsample %dx%d bit_depth %d tiles %dx%d.\n",
431 vp9->frame_width, vp9->frame_height,
432 vp9->subsampling_x, vp9->subsampling_y,
433 vp9->bit_depth, 1 << current->tile_cols_log2,
434 1 << current->tile_rows_log2);
435
436 return 0;
437}
438
440{
441 int err;
442 while (byte_alignment(rw) != 0)
443 fixed(1, zero_bit, 0);
444
445 return 0;
446}
447
450{
451 int err;
452
453 HEADER("Frame");
454
455 CHECK(FUNC(uncompressed_header)(ctx, rw, &current->header));
456
458
459 return 0;
460}
461
464{
465 int err, i;
466
467 HEADER("Superframe Index");
468
469 f(3, superframe_marker);
470 f(2, bytes_per_framesize_minus_1);
471 f(3, frames_in_superframe_minus_1);
472
473 for (i = 0; i <= current->frames_in_superframe_minus_1; i++) {
474 // Surprise little-endian!
475 fle(8 * (current->bytes_per_framesize_minus_1 + 1),
476 frame_sizes[i], 1, i);
477 }
478
479 f(3, superframe_marker);
480 f(2, bytes_per_framesize_minus_1);
481 f(3, frames_in_superframe_minus_1);
482
483 return 0;
484}
#define FUNC(a)
static int FUNC tile_info(CodedBitstreamContext *ctx, RWContext *rw, APVRawTileInfo *current, const APVRawFrameHeader *fh)
static int FUNC quantization_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
static int FUNC render_size(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
static int FUNC segmentation_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
static int FUNC color_config(CodedBitstreamContext *ctx, RWContext *rw, AV1RawColorConfig *current, int seq_profile)
static int FUNC interpolation_filter(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
static int FUNC frame_size_with_refs(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
static int FUNC loop_filter_params(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
static int FUNC uncompressed_header(CodedBitstreamContext *ctx, RWContext *rw, AV1RawFrameHeader *current)
static int FUNC trailing_bits(CodedBitstreamContext *ctx, RWContext *rw, int nb_bits)
#define infer(name, value)
Definition cbs_h264.c:131
#define byte_alignment(rw)
Definition cbs_h264.c:138
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define RWContext
Definition cbs_h264.c:93
#define f(width, name)
Definition cbs_vp8.c:236
#define ss(width, name, subs,...)
Definition cbs_vp9.c:202
#define fle(width, name, subs,...)
Definition cbs_vp9.c:236
#define prob(name, subs,...)
Definition cbs_vp9.c:252
#define fs(width, name, subs,...)
Definition cbs_vp9.c:200
#define increment(name, min, max)
Definition cbs_vp9.c:230
#define delta_q(name)
Definition cbs_vp9.c:241
@ VP9_CS_RGB
Definition cbs_vp9.h:64
@ VP9_ALTREF_FRAME
Definition cbs_vp9.h:72
@ VP9_INTRA_FRAME
Definition cbs_vp9.h:69
@ VP9_GOLDEN_FRAME
Definition cbs_vp9.h:71
@ VP9_LAST_FRAME
Definition cbs_vp9.h:70
@ VP9_MAX_REF_FRAMES
Definition cbs_vp9.h:36
@ VP9_REFS_PER_FRAME
Definition cbs_vp9.h:30
@ VP9_MAX_SEGMENTS
Definition cbs_vp9.h:38
@ VP9_MAX_TILE_WIDTH_B64
Definition cbs_vp9.h:33
@ VP9_MIN_TILE_WIDTH_B64
Definition cbs_vp9.h:32
@ VP9_NUM_REF_FRAMES
Definition cbs_vp9.h:35
@ VP9_SEG_LVL_MAX
Definition cbs_vp9.h:39
@ VP9_FRAME_SYNC_0
Definition cbs_vp9.h:50
@ VP9_FRAME_SYNC_2
Definition cbs_vp9.h:52
@ VP9_FRAME_SYNC_1
Definition cbs_vp9.h:51
@ VP9_KEY_FRAME
Definition cbs_vp9.h:44
static int FUNC superframe_index(CodedBitstreamContext *ctx, RWContext *rw, VP9RawSuperframeIndex *current)
static int FUNC frame_sync_code(CodedBitstreamContext *ctx, RWContext *rw, VP9RawFrameHeader *current)
static AVFrame * frame
static struct @111144215057303131116103221376075045141373005341 current
static void show_frame(AVTextFormatContext *tfc, AVFrame *frame, AVStream *stream, AVFormatContext *fmt_ctx)
Definition ffprobe.c:1509
static const uint8_t frame_size[4]
Definition g723_1.h:222
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition log.h:231
frame_type
#define fixed(width, name, value)
Definition cbs_apv.c:75
#define CHECK(call)
Definition cbs_apv.c:59
#define HEADER(name)
Definition cbs_apv.c:55
int profile
Definition mxfenc.c:2299
int8_t intra_only
Definition mxfenc.c:2492
static const uint8_t frame_sizes[]
Context structure for coded bitstream operations.
Definition cbs.h:226
uint8_t feature_enabled[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX]
Definition cbs_vp9.h:213
uint8_t feature_value[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX]
Definition cbs_vp9.h:214
int8_t loop_filter_ref_deltas[VP9_MAX_REF_FRAMES]
Definition cbs_vp9.h:209
VP9ReferenceFrameState ref[VP9_NUM_REF_FRAMES]
Definition cbs_vp9.h:217
uint8_t segmentation_pred_prob[3]
Definition cbs_vp9.h:212
int8_t loop_filter_mode_deltas[2]
Definition cbs_vp9.h:210
uint8_t segmentation_tree_probs[7]
Definition cbs_vp9.h:211
uint8_t feature_sign[VP9_MAX_SEGMENTS][VP9_SEG_LVL_MAX]
Definition cbs_vp9.h:215
#define av_log(a,...)
static int ref[MAX_W *MAX_W]
static AVFormatContext * ctx
Definition movenc.c:49
color_range