/src/ffmpeg/libavcodec/cbs_av1_syntax_template.c
Line | Count | Source |
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 | | |
19 | | static int FUNC(obu_header)(CodedBitstreamContext *ctx, RWContext *rw, |
20 | | AV1RawOBUHeader *current) |
21 | 38.9M | { |
22 | 38.9M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
23 | 38.9M | int err; |
24 | | |
25 | 38.9M | HEADER("OBU header"); |
26 | | |
27 | 38.9M | fc(1, obu_forbidden_bit, 0, 0); |
28 | | |
29 | 37.2M | fc(4, obu_type, 0, AV1_OBU_PADDING); |
30 | 37.2M | flag(obu_extension_flag); |
31 | 37.2M | flag(obu_has_size_field); |
32 | | |
33 | 37.2M | fc(1, obu_reserved_1bit, 0, 0); |
34 | | |
35 | 35.8M | if (current->obu_extension_flag) { |
36 | 1.97M | fb(3, temporal_id); |
37 | 1.90M | fb(2, spatial_id); |
38 | 1.90M | fc(3, extension_header_reserved_3bits, 0, 0); |
39 | 33.9M | } else { |
40 | 33.9M | infer(temporal_id, 0); |
41 | 33.9M | infer(spatial_id, 0); |
42 | 2.79M | } |
43 | | |
44 | 35.3M | priv->temporal_id = current->temporal_id; |
45 | 35.3M | priv->spatial_id = current->spatial_id; |
46 | | |
47 | 35.3M | return 0; |
48 | 35.8M | } cbs_av1.c:cbs_av1_read_obu_header Line | Count | Source | 21 | 35.9M | { | 22 | 35.9M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 23 | 35.9M | int err; | 24 | | | 25 | 35.9M | HEADER("OBU header"); | 26 | | | 27 | 35.9M | fc(1, obu_forbidden_bit, 0, 0); | 28 | | | 29 | 34.2M | fc(4, obu_type, 0, AV1_OBU_PADDING); | 30 | 34.2M | flag(obu_extension_flag); | 31 | 34.2M | flag(obu_has_size_field); | 32 | | | 33 | 34.2M | fc(1, obu_reserved_1bit, 0, 0); | 34 | | | 35 | 32.8M | if (current->obu_extension_flag) { | 36 | 1.76M | fb(3, temporal_id); | 37 | 1.69M | fb(2, spatial_id); | 38 | 1.69M | fc(3, extension_header_reserved_3bits, 0, 0); | 39 | 31.1M | } else { | 40 | 31.1M | infer(temporal_id, 0); | 41 | 31.1M | infer(spatial_id, 0); | 42 | 31.1M | } | 43 | | | 44 | 32.3M | priv->temporal_id = current->temporal_id; | 45 | 32.3M | priv->spatial_id = current->spatial_id; | 46 | | | 47 | 32.3M | return 0; | 48 | 32.8M | } |
cbs_av1.c:cbs_av1_write_obu_header Line | Count | Source | 21 | 3.00M | { | 22 | 3.00M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 23 | 3.00M | int err; | 24 | | | 25 | 3.00M | HEADER("OBU header"); | 26 | | | 27 | 3.00M | fc(1, obu_forbidden_bit, 0, 0); | 28 | | | 29 | 3.00M | fc(4, obu_type, 0, AV1_OBU_PADDING); | 30 | 3.00M | flag(obu_extension_flag); | 31 | 3.00M | flag(obu_has_size_field); | 32 | | | 33 | 3.00M | fc(1, obu_reserved_1bit, 0, 0); | 34 | | | 35 | 3.00M | if (current->obu_extension_flag) { | 36 | 206k | fb(3, temporal_id); | 37 | 206k | fb(2, spatial_id); | 38 | 206k | fc(3, extension_header_reserved_3bits, 0, 0); | 39 | 2.79M | } else { | 40 | 2.79M | infer(temporal_id, 0); | 41 | 2.79M | infer(spatial_id, 0); | 42 | 2.79M | } | 43 | | | 44 | 3.00M | priv->temporal_id = current->temporal_id; | 45 | 3.00M | priv->spatial_id = current->spatial_id; | 46 | | | 47 | 3.00M | return 0; | 48 | 3.00M | } |
|
49 | | |
50 | | static int FUNC(trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw, int nb_bits) |
51 | 1.11M | { |
52 | 1.11M | int err; |
53 | | |
54 | 1.11M | av_assert0(nb_bits > 0); |
55 | | |
56 | 1.11M | fixed(1, trailing_one_bit, 1); |
57 | 693k | --nb_bits; |
58 | | |
59 | 8.54M | while (nb_bits > 0) { |
60 | 7.99M | fixed(1, trailing_zero_bit, 0); |
61 | 7.84M | --nb_bits; |
62 | 7.84M | } |
63 | | |
64 | 549k | return 0; |
65 | 693k | } cbs_av1.c:cbs_av1_read_trailing_bits Line | Count | Source | 51 | 1.02M | { | 52 | 1.02M | int err; | 53 | | | 54 | 1.02M | av_assert0(nb_bits > 0); | 55 | | | 56 | 1.02M | fixed(1, trailing_one_bit, 1); | 57 | 608k | --nb_bits; | 58 | | | 59 | 8.20M | while (nb_bits > 0) { | 60 | 7.74M | fixed(1, trailing_zero_bit, 0); | 61 | 7.59M | --nb_bits; | 62 | 7.59M | } | 63 | | | 64 | 464k | return 0; | 65 | 608k | } |
cbs_av1.c:cbs_av1_write_trailing_bits Line | Count | Source | 51 | 85.8k | { | 52 | 85.8k | int err; | 53 | | | 54 | 85.8k | av_assert0(nb_bits > 0); | 55 | | | 56 | 85.8k | fixed(1, trailing_one_bit, 1); | 57 | 85.8k | --nb_bits; | 58 | | | 59 | 338k | while (nb_bits > 0) { | 60 | 252k | fixed(1, trailing_zero_bit, 0); | 61 | 252k | --nb_bits; | 62 | 252k | } | 63 | | | 64 | 85.8k | return 0; | 65 | 85.8k | } |
|
66 | | |
67 | | static int FUNC(byte_alignment)(CodedBitstreamContext *ctx, RWContext *rw) |
68 | 2.77M | { |
69 | 2.77M | int err; |
70 | | |
71 | 6.19M | while (byte_alignment(rw) != 0) |
72 | 3.50M | fixed(1, zero_bit, 0); |
73 | | |
74 | 2.69M | return 0; |
75 | 2.77M | } cbs_av1.c:cbs_av1_read_byte_alignment Line | Count | Source | 68 | 2.05M | { | 69 | 2.05M | int err; | 70 | | | 71 | 4.61M | while (byte_alignment(rw) != 0) | 72 | 2.64M | fixed(1, zero_bit, 0); | 73 | | | 74 | 1.97M | return 0; | 75 | 2.05M | } |
cbs_av1.c:cbs_av1_write_byte_alignment Line | Count | Source | 68 | 719k | { | 69 | 719k | int err; | 70 | | | 71 | 1.57M | while (byte_alignment(rw) != 0) | 72 | 858k | fixed(1, zero_bit, 0); | 73 | | | 74 | 719k | return 0; | 75 | 719k | } |
|
76 | | |
77 | | static int FUNC(color_config)(CodedBitstreamContext *ctx, RWContext *rw, |
78 | | AV1RawColorConfig *current, int seq_profile) |
79 | 660k | { |
80 | 660k | CodedBitstreamAV1Context *priv = ctx->priv_data; |
81 | 660k | int err; |
82 | | |
83 | 660k | flag(high_bitdepth); |
84 | | |
85 | 651k | if (seq_profile == AV_PROFILE_AV1_PROFESSIONAL && |
86 | 239k | current->high_bitdepth) { |
87 | 85.4k | flag(twelve_bit); |
88 | 81.2k | priv->bit_depth = current->twelve_bit ? 12 : 10; |
89 | 565k | } else { |
90 | 565k | priv->bit_depth = current->high_bitdepth ? 10 : 8; |
91 | 565k | } |
92 | | |
93 | 647k | if (seq_profile == AV_PROFILE_AV1_HIGH) |
94 | 135k | infer(mono_chrome, 0); |
95 | 511k | else |
96 | 647k | flag(mono_chrome); |
97 | 640k | priv->num_planes = current->mono_chrome ? 1 : 3; |
98 | | |
99 | 640k | flag(color_description_present_flag); |
100 | 629k | if (current->color_description_present_flag) { |
101 | 201k | fb(8, color_primaries); |
102 | 191k | fb(8, transfer_characteristics); |
103 | 184k | fb(8, matrix_coefficients); |
104 | 427k | } else { |
105 | 427k | infer(color_primaries, AVCOL_PRI_UNSPECIFIED); |
106 | 427k | infer(transfer_characteristics, AVCOL_TRC_UNSPECIFIED); |
107 | 427k | infer(matrix_coefficients, AVCOL_SPC_UNSPECIFIED); |
108 | 40.7k | } |
109 | | |
110 | 604k | if (current->mono_chrome) { |
111 | 129k | flag(color_range); |
112 | | |
113 | 125k | infer(subsampling_x, 1); |
114 | 125k | infer(subsampling_y, 1); |
115 | 125k | infer(chroma_sample_position, AV1_CSP_UNKNOWN); |
116 | 125k | infer(separate_uv_delta_q, 0); |
117 | | |
118 | 475k | } else if (current->color_primaries == AVCOL_PRI_BT709 && |
119 | 30.9k | current->transfer_characteristics == AVCOL_TRC_IEC61966_2_1 && |
120 | 21.1k | current->matrix_coefficients == AVCOL_SPC_RGB) { |
121 | 15.3k | infer(color_range, 1); |
122 | 15.3k | infer(subsampling_x, 0); |
123 | 15.3k | infer(subsampling_y, 0); |
124 | 15.3k | flag(separate_uv_delta_q); |
125 | | |
126 | 460k | } else { |
127 | 460k | flag(color_range); |
128 | | |
129 | 440k | if (seq_profile == AV_PROFILE_AV1_MAIN) { |
130 | 173k | infer(subsampling_x, 1); |
131 | 173k | infer(subsampling_y, 1); |
132 | 267k | } else if (seq_profile == AV_PROFILE_AV1_HIGH) { |
133 | 119k | infer(subsampling_x, 0); |
134 | 119k | infer(subsampling_y, 0); |
135 | 148k | } else { |
136 | 148k | if (priv->bit_depth == 12) { |
137 | 33.8k | fb(1, subsampling_x); |
138 | 30.6k | if (current->subsampling_x) |
139 | 18.9k | fb(1, subsampling_y); |
140 | 11.6k | else |
141 | 11.6k | infer(subsampling_y, 0); |
142 | 114k | } else { |
143 | 114k | infer(subsampling_x, 1); |
144 | 114k | infer(subsampling_y, 0); |
145 | 5.28k | } |
146 | 148k | } |
147 | 432k | if (current->subsampling_x && current->subsampling_y) { |
148 | 179k | fc(2, chroma_sample_position, AV1_CSP_UNKNOWN, |
149 | 179k | AV1_CSP_COLOCATED); |
150 | 179k | } |
151 | | |
152 | 415k | flag(separate_uv_delta_q); |
153 | 415k | } |
154 | | |
155 | 549k | return 0; |
156 | 604k | } cbs_av1.c:cbs_av1_read_color_config Line | Count | Source | 79 | 613k | { | 80 | 613k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 81 | 613k | int err; | 82 | | | 83 | 613k | flag(high_bitdepth); | 84 | | | 85 | 604k | if (seq_profile == AV_PROFILE_AV1_PROFESSIONAL && | 86 | 226k | current->high_bitdepth) { | 87 | 79.2k | flag(twelve_bit); | 88 | 74.9k | priv->bit_depth = current->twelve_bit ? 12 : 10; | 89 | 525k | } else { | 90 | 525k | priv->bit_depth = current->high_bitdepth ? 10 : 8; | 91 | 525k | } | 92 | | | 93 | 600k | if (seq_profile == AV_PROFILE_AV1_HIGH) | 94 | 127k | infer(mono_chrome, 0); | 95 | 472k | else | 96 | 600k | flag(mono_chrome); | 97 | 593k | priv->num_planes = current->mono_chrome ? 1 : 3; | 98 | | | 99 | 593k | flag(color_description_present_flag); | 100 | 582k | if (current->color_description_present_flag) { | 101 | 195k | fb(8, color_primaries); | 102 | 185k | fb(8, transfer_characteristics); | 103 | 178k | fb(8, matrix_coefficients); | 104 | 387k | } else { | 105 | 387k | infer(color_primaries, AVCOL_PRI_UNSPECIFIED); | 106 | 387k | infer(transfer_characteristics, AVCOL_TRC_UNSPECIFIED); | 107 | 387k | infer(matrix_coefficients, AVCOL_SPC_UNSPECIFIED); | 108 | 387k | } | 109 | | | 110 | 557k | if (current->mono_chrome) { | 111 | 116k | flag(color_range); | 112 | | | 113 | 112k | infer(subsampling_x, 1); | 114 | 112k | infer(subsampling_y, 1); | 115 | 112k | infer(chroma_sample_position, AV1_CSP_UNKNOWN); | 116 | 112k | infer(separate_uv_delta_q, 0); | 117 | | | 118 | 441k | } else if (current->color_primaries == AVCOL_PRI_BT709 && | 119 | 27.8k | current->transfer_characteristics == AVCOL_TRC_IEC61966_2_1 && | 120 | 19.4k | current->matrix_coefficients == AVCOL_SPC_RGB) { | 121 | 14.4k | infer(color_range, 1); | 122 | 14.4k | infer(subsampling_x, 0); | 123 | 14.4k | infer(subsampling_y, 0); | 124 | 14.4k | flag(separate_uv_delta_q); | 125 | | | 126 | 427k | } else { | 127 | 427k | flag(color_range); | 128 | | | 129 | 407k | if (seq_profile == AV_PROFILE_AV1_MAIN) { | 130 | 156k | infer(subsampling_x, 1); | 131 | 156k | infer(subsampling_y, 1); | 132 | 250k | } else if (seq_profile == AV_PROFILE_AV1_HIGH) { | 133 | 111k | infer(subsampling_x, 0); | 134 | 111k | infer(subsampling_y, 0); | 135 | 139k | } else { | 136 | 139k | if (priv->bit_depth == 12) { | 137 | 30.6k | fb(1, subsampling_x); | 138 | 27.4k | if (current->subsampling_x) | 139 | 17.3k | fb(1, subsampling_y); | 140 | 10.1k | else | 141 | 10.1k | infer(subsampling_y, 0); | 142 | 109k | } else { | 143 | 109k | infer(subsampling_x, 1); | 144 | 109k | infer(subsampling_y, 0); | 145 | 109k | } | 146 | 139k | } | 147 | 399k | if (current->subsampling_x && current->subsampling_y) { | 148 | 161k | fc(2, chroma_sample_position, AV1_CSP_UNKNOWN, | 149 | 161k | AV1_CSP_COLOCATED); | 150 | 161k | } | 151 | | | 152 | 382k | flag(separate_uv_delta_q); | 153 | 382k | } | 154 | | | 155 | 502k | return 0; | 156 | 557k | } |
cbs_av1.c:cbs_av1_write_color_config Line | Count | Source | 79 | 47.0k | { | 80 | 47.0k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 81 | 47.0k | int err; | 82 | | | 83 | 47.0k | flag(high_bitdepth); | 84 | | | 85 | 47.0k | if (seq_profile == AV_PROFILE_AV1_PROFESSIONAL && | 86 | 12.4k | current->high_bitdepth) { | 87 | 6.27k | flag(twelve_bit); | 88 | 6.27k | priv->bit_depth = current->twelve_bit ? 12 : 10; | 89 | 40.7k | } else { | 90 | 40.7k | priv->bit_depth = current->high_bitdepth ? 10 : 8; | 91 | 40.7k | } | 92 | | | 93 | 47.0k | if (seq_profile == AV_PROFILE_AV1_HIGH) | 94 | 8.17k | infer(mono_chrome, 0); | 95 | 38.8k | else | 96 | 47.0k | flag(mono_chrome); | 97 | 47.0k | priv->num_planes = current->mono_chrome ? 1 : 3; | 98 | | | 99 | 47.0k | flag(color_description_present_flag); | 100 | 47.0k | if (current->color_description_present_flag) { | 101 | 6.35k | fb(8, color_primaries); | 102 | 6.35k | fb(8, transfer_characteristics); | 103 | 6.35k | fb(8, matrix_coefficients); | 104 | 40.7k | } else { | 105 | 40.7k | infer(color_primaries, AVCOL_PRI_UNSPECIFIED); | 106 | 40.7k | infer(transfer_characteristics, AVCOL_TRC_UNSPECIFIED); | 107 | 40.7k | infer(matrix_coefficients, AVCOL_SPC_UNSPECIFIED); | 108 | 40.7k | } | 109 | | | 110 | 47.0k | if (current->mono_chrome) { | 111 | 13.0k | flag(color_range); | 112 | | | 113 | 13.0k | infer(subsampling_x, 1); | 114 | 13.0k | infer(subsampling_y, 1); | 115 | 13.0k | infer(chroma_sample_position, AV1_CSP_UNKNOWN); | 116 | 13.0k | infer(separate_uv_delta_q, 0); | 117 | | | 118 | 33.9k | } else if (current->color_primaries == AVCOL_PRI_BT709 && | 119 | 3.01k | current->transfer_characteristics == AVCOL_TRC_IEC61966_2_1 && | 120 | 1.74k | current->matrix_coefficients == AVCOL_SPC_RGB) { | 121 | 927 | infer(color_range, 1); | 122 | 927 | infer(subsampling_x, 0); | 123 | 927 | infer(subsampling_y, 0); | 124 | 927 | flag(separate_uv_delta_q); | 125 | | | 126 | 33.0k | } else { | 127 | 33.0k | flag(color_range); | 128 | | | 129 | 33.0k | if (seq_profile == AV_PROFILE_AV1_MAIN) { | 130 | 16.7k | infer(subsampling_x, 1); | 131 | 16.7k | infer(subsampling_y, 1); | 132 | 16.7k | } else if (seq_profile == AV_PROFILE_AV1_HIGH) { | 133 | 7.83k | infer(subsampling_x, 0); | 134 | 7.83k | infer(subsampling_y, 0); | 135 | 8.46k | } else { | 136 | 8.46k | if (priv->bit_depth == 12) { | 137 | 3.18k | fb(1, subsampling_x); | 138 | 3.18k | if (current->subsampling_x) | 139 | 1.62k | fb(1, subsampling_y); | 140 | 1.55k | else | 141 | 1.55k | infer(subsampling_y, 0); | 142 | 5.28k | } else { | 143 | 5.28k | infer(subsampling_x, 1); | 144 | 5.28k | infer(subsampling_y, 0); | 145 | 5.28k | } | 146 | 8.46k | } | 147 | 33.0k | if (current->subsampling_x && current->subsampling_y) { | 148 | 17.7k | fc(2, chroma_sample_position, AV1_CSP_UNKNOWN, | 149 | 17.7k | AV1_CSP_COLOCATED); | 150 | 17.7k | } | 151 | | | 152 | 33.0k | flag(separate_uv_delta_q); | 153 | 33.0k | } | 154 | | | 155 | 47.0k | return 0; | 156 | 47.0k | } |
|
157 | | |
158 | | static int FUNC(timing_info)(CodedBitstreamContext *ctx, RWContext *rw, |
159 | | AV1RawTimingInfo *current) |
160 | 405k | { |
161 | 405k | int err; |
162 | | |
163 | 405k | fc(32, num_units_in_display_tick, 1, MAX_UINT_BITS(32)); |
164 | 398k | fc(32, time_scale, 1, MAX_UINT_BITS(32)); |
165 | | |
166 | 390k | flag(equal_picture_interval); |
167 | 390k | if (current->equal_picture_interval) |
168 | 196k | uvlc(num_ticks_per_picture_minus_1, 0, MAX_UINT_BITS(32) - 1); |
169 | | |
170 | 377k | return 0; |
171 | 390k | } cbs_av1.c:cbs_av1_read_timing_info Line | Count | Source | 160 | 390k | { | 161 | 390k | int err; | 162 | | | 163 | 390k | fc(32, num_units_in_display_tick, 1, MAX_UINT_BITS(32)); | 164 | 383k | fc(32, time_scale, 1, MAX_UINT_BITS(32)); | 165 | | | 166 | 375k | flag(equal_picture_interval); | 167 | 375k | if (current->equal_picture_interval) | 168 | 190k | uvlc(num_ticks_per_picture_minus_1, 0, MAX_UINT_BITS(32) - 1); | 169 | | | 170 | 362k | return 0; | 171 | 375k | } |
cbs_av1.c:cbs_av1_write_timing_info Line | Count | Source | 160 | 14.9k | { | 161 | 14.9k | int err; | 162 | | | 163 | 14.9k | fc(32, num_units_in_display_tick, 1, MAX_UINT_BITS(32)); | 164 | 14.9k | fc(32, time_scale, 1, MAX_UINT_BITS(32)); | 165 | | | 166 | 14.9k | flag(equal_picture_interval); | 167 | 14.9k | if (current->equal_picture_interval) | 168 | 6.19k | uvlc(num_ticks_per_picture_minus_1, 0, MAX_UINT_BITS(32) - 1); | 169 | | | 170 | 14.9k | return 0; | 171 | 14.9k | } |
|
172 | | |
173 | | static int FUNC(decoder_model_info)(CodedBitstreamContext *ctx, RWContext *rw, |
174 | | AV1RawDecoderModelInfo *current) |
175 | 217k | { |
176 | 217k | int err; |
177 | | |
178 | 217k | fb(5, buffer_delay_length_minus_1); |
179 | 212k | fc(32, num_units_in_decoding_tick, 1, MAX_UINT_BITS(32)); |
180 | 201k | fb(5, buffer_removal_time_length_minus_1); |
181 | 197k | fb(5, frame_presentation_time_length_minus_1); |
182 | | |
183 | 192k | return 0; |
184 | 197k | } cbs_av1.c:cbs_av1_read_decoder_model_info Line | Count | Source | 175 | 210k | { | 176 | 210k | int err; | 177 | | | 178 | 210k | fb(5, buffer_delay_length_minus_1); | 179 | 205k | fc(32, num_units_in_decoding_tick, 1, MAX_UINT_BITS(32)); | 180 | 194k | fb(5, buffer_removal_time_length_minus_1); | 181 | 191k | fb(5, frame_presentation_time_length_minus_1); | 182 | | | 183 | 186k | return 0; | 184 | 191k | } |
cbs_av1.c:cbs_av1_write_decoder_model_info Line | Count | Source | 175 | 6.55k | { | 176 | 6.55k | int err; | 177 | | | 178 | 6.55k | fb(5, buffer_delay_length_minus_1); | 179 | 6.55k | fc(32, num_units_in_decoding_tick, 1, MAX_UINT_BITS(32)); | 180 | 6.55k | fb(5, buffer_removal_time_length_minus_1); | 181 | 6.55k | fb(5, frame_presentation_time_length_minus_1); | 182 | | | 183 | 6.55k | return 0; | 184 | 6.55k | } |
|
185 | | |
186 | | static int FUNC(sequence_header_obu)(CodedBitstreamContext *ctx, RWContext *rw, |
187 | | AV1RawSequenceHeader *current) |
188 | 1.12M | { |
189 | 1.12M | int i, err; |
190 | | |
191 | 1.12M | HEADER("Sequence Header"); |
192 | | |
193 | 1.12M | fc(3, seq_profile, AV_PROFILE_AV1_MAIN, |
194 | 1.08M | AV_PROFILE_AV1_PROFESSIONAL); |
195 | 1.08M | flag(still_picture); |
196 | 1.08M | flag(reduced_still_picture_header); |
197 | | |
198 | 1.08M | if (current->reduced_still_picture_header) { |
199 | 187k | infer(timing_info_present_flag, 0); |
200 | 187k | infer(decoder_model_info_present_flag, 0); |
201 | 187k | infer(initial_display_delay_present_flag, 0); |
202 | 187k | infer(operating_points_cnt_minus_1, 0); |
203 | 187k | infer(operating_point_idc[0], 0); |
204 | | |
205 | 187k | fb(5, seq_level_idx[0]); |
206 | | |
207 | 181k | infer(seq_tier[0], 0); |
208 | 181k | infer(decoder_model_present_for_this_op[0], 0); |
209 | 181k | infer(initial_display_delay_present_for_this_op[0], 0); |
210 | | |
211 | 895k | } else { |
212 | 895k | flag(timing_info_present_flag); |
213 | 895k | if (current->timing_info_present_flag) { |
214 | 405k | CHECK(FUNC(timing_info)(ctx, rw, ¤t->timing_info)); |
215 | | |
216 | 377k | flag(decoder_model_info_present_flag); |
217 | 373k | if (current->decoder_model_info_present_flag) { |
218 | 217k | CHECK(FUNC(decoder_model_info) |
219 | 217k | (ctx, rw, ¤t->decoder_model_info)); |
220 | 217k | } |
221 | 490k | } else { |
222 | 490k | infer(decoder_model_info_present_flag, 0); |
223 | 490k | } |
224 | | |
225 | 839k | flag(initial_display_delay_present_flag); |
226 | | |
227 | 834k | fb(5, operating_points_cnt_minus_1); |
228 | 6.48M | for (i = 0; i <= current->operating_points_cnt_minus_1; i++) { |
229 | 5.79M | fbs(12, operating_point_idc[i], 1, i); |
230 | 5.73M | fbs(5, seq_level_idx[i], 1, i); |
231 | | |
232 | 5.70M | if (current->seq_level_idx[i] > 7) |
233 | 5.70M | flags(seq_tier[i], 1, i); |
234 | 2.82M | else |
235 | 2.82M | infer(seq_tier[i], 0); |
236 | | |
237 | 5.70M | if (current->decoder_model_info_present_flag) { |
238 | 1.82M | flags(decoder_model_present_for_this_op[i], 1, i); |
239 | 1.82M | if (current->decoder_model_present_for_this_op[i]) { |
240 | 650k | int n = current->decoder_model_info.buffer_delay_length_minus_1 + 1; |
241 | 650k | fbs(n, decoder_buffer_delay[i], 1, i); |
242 | 641k | fbs(n, encoder_buffer_delay[i], 1, i); |
243 | 633k | flags(low_delay_mode_flag[i], 1, i); |
244 | 633k | } |
245 | 3.87M | } else { |
246 | 3.87M | infer(decoder_model_present_for_this_op[i], 0); |
247 | 3.87M | } |
248 | | |
249 | 5.67M | if (current->initial_display_delay_present_flag) { |
250 | 2.76M | flags(initial_display_delay_present_for_this_op[i], 1, i); |
251 | 2.76M | if (current->initial_display_delay_present_for_this_op[i]) |
252 | 2.76M | fbs(4, initial_display_delay_minus_1[i], 1, i); |
253 | 2.76M | } |
254 | 5.67M | } |
255 | 820k | } |
256 | | |
257 | 868k | fb(4, frame_width_bits_minus_1); |
258 | 858k | fb(4, frame_height_bits_minus_1); |
259 | | |
260 | 851k | fb(current->frame_width_bits_minus_1 + 1, max_frame_width_minus_1); |
261 | 837k | fb(current->frame_height_bits_minus_1 + 1, max_frame_height_minus_1); |
262 | | |
263 | 823k | if (current->reduced_still_picture_header) |
264 | 169k | infer(frame_id_numbers_present_flag, 0); |
265 | 653k | else |
266 | 823k | flag(frame_id_numbers_present_flag); |
267 | 819k | if (current->frame_id_numbers_present_flag) { |
268 | 239k | fb(4, delta_frame_id_length_minus_2); |
269 | 231k | fb(3, additional_frame_id_length_minus_1); |
270 | 231k | } |
271 | | |
272 | 804k | flag(use_128x128_superblock); |
273 | 792k | flag(enable_filter_intra); |
274 | 785k | flag(enable_intra_edge_filter); |
275 | | |
276 | 778k | if (current->reduced_still_picture_header) { |
277 | 164k | infer(enable_interintra_compound, 0); |
278 | 164k | infer(enable_masked_compound, 0); |
279 | 164k | infer(enable_warped_motion, 0); |
280 | 164k | infer(enable_dual_filter, 0); |
281 | 164k | infer(enable_order_hint, 0); |
282 | 164k | infer(enable_jnt_comp, 0); |
283 | 164k | infer(enable_ref_frame_mvs, 0); |
284 | | |
285 | 164k | infer(seq_force_screen_content_tools, |
286 | 15.2k | AV1_SELECT_SCREEN_CONTENT_TOOLS); |
287 | 164k | infer(seq_force_integer_mv, |
288 | 15.2k | AV1_SELECT_INTEGER_MV); |
289 | 613k | } else { |
290 | 613k | flag(enable_interintra_compound); |
291 | 606k | flag(enable_masked_compound); |
292 | 599k | flag(enable_warped_motion); |
293 | 587k | flag(enable_dual_filter); |
294 | | |
295 | 578k | flag(enable_order_hint); |
296 | 564k | if (current->enable_order_hint) { |
297 | 212k | flag(enable_jnt_comp); |
298 | 208k | flag(enable_ref_frame_mvs); |
299 | 351k | } else { |
300 | 351k | infer(enable_jnt_comp, 0); |
301 | 351k | infer(enable_ref_frame_mvs, 0); |
302 | 14.0k | } |
303 | | |
304 | 553k | flag(seq_choose_screen_content_tools); |
305 | 540k | if (current->seq_choose_screen_content_tools) |
306 | 204k | infer(seq_force_screen_content_tools, |
307 | 540k | AV1_SELECT_SCREEN_CONTENT_TOOLS); |
308 | 336k | else |
309 | 336k | fb(1, seq_force_screen_content_tools); |
310 | 534k | if (current->seq_force_screen_content_tools > 0) { |
311 | 291k | flag(seq_choose_integer_mv); |
312 | 285k | if (current->seq_choose_integer_mv) |
313 | 141k | infer(seq_force_integer_mv, |
314 | 285k | AV1_SELECT_INTEGER_MV); |
315 | 144k | else |
316 | 144k | fb(1, seq_force_integer_mv); |
317 | 285k | } else { |
318 | 242k | infer(seq_force_integer_mv, AV1_SELECT_INTEGER_MV); |
319 | 242k | } |
320 | | |
321 | 521k | if (current->enable_order_hint) |
322 | 190k | fb(3, order_hint_bits_minus_1); |
323 | 521k | } |
324 | | |
325 | 682k | flag(enable_superres); |
326 | 674k | flag(enable_cdef); |
327 | 667k | flag(enable_restoration); |
328 | | |
329 | 660k | CHECK(FUNC(color_config)(ctx, rw, ¤t->color_config, |
330 | 660k | current->seq_profile)); |
331 | | |
332 | 549k | flag(film_grain_params_present); |
333 | | |
334 | 541k | return 0; |
335 | 549k | } cbs_av1.c:cbs_av1_read_sequence_header_obu Line | Count | Source | 188 | 1.07M | { | 189 | 1.07M | int i, err; | 190 | | | 191 | 1.07M | HEADER("Sequence Header"); | 192 | | | 193 | 1.07M | fc(3, seq_profile, AV_PROFILE_AV1_MAIN, | 194 | 1.03M | AV_PROFILE_AV1_PROFESSIONAL); | 195 | 1.03M | flag(still_picture); | 196 | 1.03M | flag(reduced_still_picture_header); | 197 | | | 198 | 1.03M | if (current->reduced_still_picture_header) { | 199 | 172k | infer(timing_info_present_flag, 0); | 200 | 172k | infer(decoder_model_info_present_flag, 0); | 201 | 172k | infer(initial_display_delay_present_flag, 0); | 202 | 172k | infer(operating_points_cnt_minus_1, 0); | 203 | 172k | infer(operating_point_idc[0], 0); | 204 | | | 205 | 172k | fb(5, seq_level_idx[0]); | 206 | | | 207 | 166k | infer(seq_tier[0], 0); | 208 | 166k | infer(decoder_model_present_for_this_op[0], 0); | 209 | 166k | infer(initial_display_delay_present_for_this_op[0], 0); | 210 | | | 211 | 863k | } else { | 212 | 863k | flag(timing_info_present_flag); | 213 | 863k | if (current->timing_info_present_flag) { | 214 | 390k | CHECK(FUNC(timing_info)(ctx, rw, ¤t->timing_info)); | 215 | | | 216 | 362k | flag(decoder_model_info_present_flag); | 217 | 358k | if (current->decoder_model_info_present_flag) { | 218 | 210k | CHECK(FUNC(decoder_model_info) | 219 | 210k | (ctx, rw, ¤t->decoder_model_info)); | 220 | 210k | } | 221 | 473k | } else { | 222 | 473k | infer(decoder_model_info_present_flag, 0); | 223 | 473k | } | 224 | | | 225 | 807k | flag(initial_display_delay_present_flag); | 226 | | | 227 | 802k | fb(5, operating_points_cnt_minus_1); | 228 | 6.37M | for (i = 0; i <= current->operating_points_cnt_minus_1; i++) { | 229 | 5.72M | fbs(12, operating_point_idc[i], 1, i); | 230 | 5.65M | fbs(5, seq_level_idx[i], 1, i); | 231 | | | 232 | 5.63M | if (current->seq_level_idx[i] > 7) | 233 | 5.63M | flags(seq_tier[i], 1, i); | 234 | 2.78M | else | 235 | 2.78M | infer(seq_tier[i], 0); | 236 | | | 237 | 5.62M | if (current->decoder_model_info_present_flag) { | 238 | 1.79M | flags(decoder_model_present_for_this_op[i], 1, i); | 239 | 1.79M | if (current->decoder_model_present_for_this_op[i]) { | 240 | 639k | int n = current->decoder_model_info.buffer_delay_length_minus_1 + 1; | 241 | 639k | fbs(n, decoder_buffer_delay[i], 1, i); | 242 | 630k | fbs(n, encoder_buffer_delay[i], 1, i); | 243 | 622k | flags(low_delay_mode_flag[i], 1, i); | 244 | 622k | } | 245 | 3.82M | } else { | 246 | 3.82M | infer(decoder_model_present_for_this_op[i], 0); | 247 | 3.82M | } | 248 | | | 249 | 5.59M | if (current->initial_display_delay_present_flag) { | 250 | 2.74M | flags(initial_display_delay_present_for_this_op[i], 1, i); | 251 | 2.73M | if (current->initial_display_delay_present_for_this_op[i]) | 252 | 2.73M | fbs(4, initial_display_delay_minus_1[i], 1, i); | 253 | 2.73M | } | 254 | 5.59M | } | 255 | 789k | } | 256 | | | 257 | 821k | fb(4, frame_width_bits_minus_1); | 258 | 811k | fb(4, frame_height_bits_minus_1); | 259 | | | 260 | 804k | fb(current->frame_width_bits_minus_1 + 1, max_frame_width_minus_1); | 261 | 790k | fb(current->frame_height_bits_minus_1 + 1, max_frame_height_minus_1); | 262 | | | 263 | 775k | if (current->reduced_still_picture_header) | 264 | 154k | infer(frame_id_numbers_present_flag, 0); | 265 | 621k | else | 266 | 775k | flag(frame_id_numbers_present_flag); | 267 | 772k | if (current->frame_id_numbers_present_flag) { | 268 | 228k | fb(4, delta_frame_id_length_minus_2); | 269 | 221k | fb(3, additional_frame_id_length_minus_1); | 270 | 221k | } | 271 | | | 272 | 757k | flag(use_128x128_superblock); | 273 | 745k | flag(enable_filter_intra); | 274 | 738k | flag(enable_intra_edge_filter); | 275 | | | 276 | 731k | if (current->reduced_still_picture_header) { | 277 | 149k | infer(enable_interintra_compound, 0); | 278 | 149k | infer(enable_masked_compound, 0); | 279 | 149k | infer(enable_warped_motion, 0); | 280 | 149k | infer(enable_dual_filter, 0); | 281 | 149k | infer(enable_order_hint, 0); | 282 | 149k | infer(enable_jnt_comp, 0); | 283 | 149k | infer(enable_ref_frame_mvs, 0); | 284 | | | 285 | 149k | infer(seq_force_screen_content_tools, | 286 | 149k | AV1_SELECT_SCREEN_CONTENT_TOOLS); | 287 | 149k | infer(seq_force_integer_mv, | 288 | 149k | AV1_SELECT_INTEGER_MV); | 289 | 581k | } else { | 290 | 581k | flag(enable_interintra_compound); | 291 | 574k | flag(enable_masked_compound); | 292 | 568k | flag(enable_warped_motion); | 293 | 555k | flag(enable_dual_filter); | 294 | | | 295 | 546k | flag(enable_order_hint); | 296 | 532k | if (current->enable_order_hint) { | 297 | 195k | flag(enable_jnt_comp); | 298 | 190k | flag(enable_ref_frame_mvs); | 299 | 337k | } else { | 300 | 337k | infer(enable_jnt_comp, 0); | 301 | 337k | infer(enable_ref_frame_mvs, 0); | 302 | 337k | } | 303 | | | 304 | 522k | flag(seq_choose_screen_content_tools); | 305 | 508k | if (current->seq_choose_screen_content_tools) | 306 | 190k | infer(seq_force_screen_content_tools, | 307 | 508k | AV1_SELECT_SCREEN_CONTENT_TOOLS); | 308 | 318k | else | 309 | 318k | fb(1, seq_force_screen_content_tools); | 310 | 502k | if (current->seq_force_screen_content_tools > 0) { | 311 | 271k | flag(seq_choose_integer_mv); | 312 | 265k | if (current->seq_choose_integer_mv) | 313 | 129k | infer(seq_force_integer_mv, | 314 | 265k | AV1_SELECT_INTEGER_MV); | 315 | 135k | else | 316 | 135k | fb(1, seq_force_integer_mv); | 317 | 265k | } else { | 318 | 230k | infer(seq_force_integer_mv, AV1_SELECT_INTEGER_MV); | 319 | 230k | } | 320 | | | 321 | 489k | if (current->enable_order_hint) | 322 | 172k | fb(3, order_hint_bits_minus_1); | 323 | 489k | } | 324 | | | 325 | 635k | flag(enable_superres); | 326 | 627k | flag(enable_cdef); | 327 | 620k | flag(enable_restoration); | 328 | | | 329 | 613k | CHECK(FUNC(color_config)(ctx, rw, ¤t->color_config, | 330 | 613k | current->seq_profile)); | 331 | | | 332 | 502k | flag(film_grain_params_present); | 333 | | | 334 | 494k | return 0; | 335 | 502k | } |
cbs_av1.c:cbs_av1_write_sequence_header_obu Line | Count | Source | 188 | 47.0k | { | 189 | 47.0k | int i, err; | 190 | | | 191 | 47.0k | HEADER("Sequence Header"); | 192 | | | 193 | 47.0k | fc(3, seq_profile, AV_PROFILE_AV1_MAIN, | 194 | 47.0k | AV_PROFILE_AV1_PROFESSIONAL); | 195 | 47.0k | flag(still_picture); | 196 | 47.0k | flag(reduced_still_picture_header); | 197 | | | 198 | 47.0k | if (current->reduced_still_picture_header) { | 199 | 15.2k | infer(timing_info_present_flag, 0); | 200 | 15.2k | infer(decoder_model_info_present_flag, 0); | 201 | 15.2k | infer(initial_display_delay_present_flag, 0); | 202 | 15.2k | infer(operating_points_cnt_minus_1, 0); | 203 | 15.2k | infer(operating_point_idc[0], 0); | 204 | | | 205 | 15.2k | fb(5, seq_level_idx[0]); | 206 | | | 207 | 15.2k | infer(seq_tier[0], 0); | 208 | 15.2k | infer(decoder_model_present_for_this_op[0], 0); | 209 | 15.2k | infer(initial_display_delay_present_for_this_op[0], 0); | 210 | | | 211 | 31.8k | } else { | 212 | 31.8k | flag(timing_info_present_flag); | 213 | 31.8k | if (current->timing_info_present_flag) { | 214 | 14.9k | CHECK(FUNC(timing_info)(ctx, rw, ¤t->timing_info)); | 215 | | | 216 | 14.9k | flag(decoder_model_info_present_flag); | 217 | 14.9k | if (current->decoder_model_info_present_flag) { | 218 | 6.55k | CHECK(FUNC(decoder_model_info) | 219 | 6.55k | (ctx, rw, ¤t->decoder_model_info)); | 220 | 6.55k | } | 221 | 16.8k | } else { | 222 | 16.8k | infer(decoder_model_info_present_flag, 0); | 223 | 16.8k | } | 224 | | | 225 | 31.8k | flag(initial_display_delay_present_flag); | 226 | | | 227 | 31.8k | fb(5, operating_points_cnt_minus_1); | 228 | 107k | for (i = 0; i <= current->operating_points_cnt_minus_1; i++) { | 229 | 75.3k | fbs(12, operating_point_idc[i], 1, i); | 230 | 75.3k | fbs(5, seq_level_idx[i], 1, i); | 231 | | | 232 | 75.3k | if (current->seq_level_idx[i] > 7) | 233 | 75.3k | flags(seq_tier[i], 1, i); | 234 | 40.9k | else | 235 | 40.9k | infer(seq_tier[i], 0); | 236 | | | 237 | 75.3k | if (current->decoder_model_info_present_flag) { | 238 | 26.8k | flags(decoder_model_present_for_this_op[i], 1, i); | 239 | 26.8k | if (current->decoder_model_present_for_this_op[i]) { | 240 | 11.2k | int n = current->decoder_model_info.buffer_delay_length_minus_1 + 1; | 241 | 11.2k | fbs(n, decoder_buffer_delay[i], 1, i); | 242 | 11.2k | fbs(n, encoder_buffer_delay[i], 1, i); | 243 | 11.2k | flags(low_delay_mode_flag[i], 1, i); | 244 | 11.2k | } | 245 | 48.4k | } else { | 246 | 48.4k | infer(decoder_model_present_for_this_op[i], 0); | 247 | 48.4k | } | 248 | | | 249 | 75.3k | if (current->initial_display_delay_present_flag) { | 250 | 25.5k | flags(initial_display_delay_present_for_this_op[i], 1, i); | 251 | 25.5k | if (current->initial_display_delay_present_for_this_op[i]) | 252 | 25.5k | fbs(4, initial_display_delay_minus_1[i], 1, i); | 253 | 25.5k | } | 254 | 75.3k | } | 255 | 31.8k | } | 256 | | | 257 | 47.0k | fb(4, frame_width_bits_minus_1); | 258 | 47.0k | fb(4, frame_height_bits_minus_1); | 259 | | | 260 | 47.0k | fb(current->frame_width_bits_minus_1 + 1, max_frame_width_minus_1); | 261 | 47.0k | fb(current->frame_height_bits_minus_1 + 1, max_frame_height_minus_1); | 262 | | | 263 | 47.0k | if (current->reduced_still_picture_header) | 264 | 15.2k | infer(frame_id_numbers_present_flag, 0); | 265 | 31.8k | else | 266 | 47.0k | flag(frame_id_numbers_present_flag); | 267 | 47.0k | if (current->frame_id_numbers_present_flag) { | 268 | 10.7k | fb(4, delta_frame_id_length_minus_2); | 269 | 10.7k | fb(3, additional_frame_id_length_minus_1); | 270 | 10.7k | } | 271 | | | 272 | 47.0k | flag(use_128x128_superblock); | 273 | 47.0k | flag(enable_filter_intra); | 274 | 47.0k | flag(enable_intra_edge_filter); | 275 | | | 276 | 47.0k | if (current->reduced_still_picture_header) { | 277 | 15.2k | infer(enable_interintra_compound, 0); | 278 | 15.2k | infer(enable_masked_compound, 0); | 279 | 15.2k | infer(enable_warped_motion, 0); | 280 | 15.2k | infer(enable_dual_filter, 0); | 281 | 15.2k | infer(enable_order_hint, 0); | 282 | 15.2k | infer(enable_jnt_comp, 0); | 283 | 15.2k | infer(enable_ref_frame_mvs, 0); | 284 | | | 285 | 15.2k | infer(seq_force_screen_content_tools, | 286 | 15.2k | AV1_SELECT_SCREEN_CONTENT_TOOLS); | 287 | 15.2k | infer(seq_force_integer_mv, | 288 | 15.2k | AV1_SELECT_INTEGER_MV); | 289 | 31.8k | } else { | 290 | 31.8k | flag(enable_interintra_compound); | 291 | 31.8k | flag(enable_masked_compound); | 292 | 31.8k | flag(enable_warped_motion); | 293 | 31.8k | flag(enable_dual_filter); | 294 | | | 295 | 31.8k | flag(enable_order_hint); | 296 | 31.8k | if (current->enable_order_hint) { | 297 | 17.7k | flag(enable_jnt_comp); | 298 | 17.7k | flag(enable_ref_frame_mvs); | 299 | 17.7k | } else { | 300 | 14.0k | infer(enable_jnt_comp, 0); | 301 | 14.0k | infer(enable_ref_frame_mvs, 0); | 302 | 14.0k | } | 303 | | | 304 | 31.8k | flag(seq_choose_screen_content_tools); | 305 | 31.8k | if (current->seq_choose_screen_content_tools) | 306 | 14.2k | infer(seq_force_screen_content_tools, | 307 | 31.8k | AV1_SELECT_SCREEN_CONTENT_TOOLS); | 308 | 17.5k | else | 309 | 17.5k | fb(1, seq_force_screen_content_tools); | 310 | 31.8k | if (current->seq_force_screen_content_tools > 0) { | 311 | 20.0k | flag(seq_choose_integer_mv); | 312 | 20.0k | if (current->seq_choose_integer_mv) | 313 | 11.6k | infer(seq_force_integer_mv, | 314 | 20.0k | AV1_SELECT_INTEGER_MV); | 315 | 8.33k | else | 316 | 8.33k | fb(1, seq_force_integer_mv); | 317 | 20.0k | } else { | 318 | 11.7k | infer(seq_force_integer_mv, AV1_SELECT_INTEGER_MV); | 319 | 11.7k | } | 320 | | | 321 | 31.8k | if (current->enable_order_hint) | 322 | 17.7k | fb(3, order_hint_bits_minus_1); | 323 | 31.8k | } | 324 | | | 325 | 47.0k | flag(enable_superres); | 326 | 47.0k | flag(enable_cdef); | 327 | 47.0k | flag(enable_restoration); | 328 | | | 329 | 47.0k | CHECK(FUNC(color_config)(ctx, rw, ¤t->color_config, | 330 | 47.0k | current->seq_profile)); | 331 | | | 332 | 47.0k | flag(film_grain_params_present); | 333 | | | 334 | 47.0k | return 0; | 335 | 47.0k | } |
|
336 | | |
337 | | static int FUNC(temporal_delimiter_obu)(CodedBitstreamContext *ctx, RWContext *rw) |
338 | 1.26M | { |
339 | 1.26M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
340 | | |
341 | 1.26M | HEADER("Temporal Delimiter"); |
342 | | |
343 | 1.26M | priv->seen_frame_header = 0; |
344 | | |
345 | 1.26M | return 0; |
346 | 1.26M | } cbs_av1.c:cbs_av1_read_temporal_delimiter_obu Line | Count | Source | 338 | 927k | { | 339 | 927k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 340 | | | 341 | 927k | HEADER("Temporal Delimiter"); | 342 | | | 343 | 927k | priv->seen_frame_header = 0; | 344 | | | 345 | 927k | return 0; | 346 | 927k | } |
cbs_av1.c:cbs_av1_write_temporal_delimiter_obu Line | Count | Source | 338 | 340k | { | 339 | 340k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 340 | | | 341 | 340k | HEADER("Temporal Delimiter"); | 342 | | | 343 | 340k | priv->seen_frame_header = 0; | 344 | | | 345 | 340k | return 0; | 346 | 340k | } |
|
347 | | |
348 | | static int FUNC(set_frame_refs)(CodedBitstreamContext *ctx, RWContext *rw, |
349 | | AV1RawFrameHeader *current) |
350 | 568k | { |
351 | 568k | CodedBitstreamAV1Context *priv = ctx->priv_data; |
352 | 568k | const AV1RawSequenceHeader *seq = priv->sequence_header; |
353 | 568k | static const uint8_t ref_frame_list[AV1_NUM_REF_FRAMES - 2] = { |
354 | 568k | AV1_REF_FRAME_LAST2, AV1_REF_FRAME_LAST3, AV1_REF_FRAME_BWDREF, |
355 | 568k | AV1_REF_FRAME_ALTREF2, AV1_REF_FRAME_ALTREF |
356 | 568k | }; |
357 | 568k | int8_t ref_frame_idx[AV1_REFS_PER_FRAME], used_frame[AV1_NUM_REF_FRAMES]; |
358 | 568k | int16_t shifted_order_hints[AV1_NUM_REF_FRAMES]; |
359 | 568k | int cur_frame_hint, latest_order_hint, earliest_order_hint, ref; |
360 | 568k | int i, j; |
361 | | |
362 | 4.54M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) |
363 | 3.98M | ref_frame_idx[i] = AV1_REF_FRAME_NONE; |
364 | 568k | ref_frame_idx[AV1_REF_FRAME_LAST - AV1_REF_FRAME_LAST] = current->last_frame_idx; |
365 | 568k | ref_frame_idx[AV1_REF_FRAME_GOLDEN - AV1_REF_FRAME_LAST] = current->golden_frame_idx; |
366 | | |
367 | 5.11M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) |
368 | 4.54M | used_frame[i] = 0; |
369 | 568k | used_frame[current->last_frame_idx] = 1; |
370 | 568k | used_frame[current->golden_frame_idx] = 1; |
371 | | |
372 | 568k | cur_frame_hint = 1 << (seq->order_hint_bits_minus_1); |
373 | 5.11M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) |
374 | 4.54M | shifted_order_hints[i] = cur_frame_hint + |
375 | 4.54M | cbs_av1_get_relative_dist(seq, priv->ref[i].order_hint, |
376 | 4.54M | priv->order_hint); |
377 | | |
378 | 568k | latest_order_hint = shifted_order_hints[current->last_frame_idx]; |
379 | 568k | earliest_order_hint = shifted_order_hints[current->golden_frame_idx]; |
380 | | |
381 | 568k | ref = AV1_REF_FRAME_NONE; |
382 | 5.11M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { |
383 | 4.54M | int hint = shifted_order_hints[i]; |
384 | 4.54M | if (!used_frame[i] && hint >= cur_frame_hint && |
385 | 2.20M | (ref < 0 || hint >= latest_order_hint)) { |
386 | 1.89M | ref = i; |
387 | 1.89M | latest_order_hint = hint; |
388 | 1.89M | } |
389 | 4.54M | } |
390 | 568k | if (ref >= 0) { |
391 | 487k | ref_frame_idx[AV1_REF_FRAME_ALTREF - AV1_REF_FRAME_LAST] = ref; |
392 | 487k | used_frame[ref] = 1; |
393 | 487k | } |
394 | | |
395 | 568k | ref = AV1_REF_FRAME_NONE; |
396 | 5.11M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { |
397 | 4.54M | int hint = shifted_order_hints[i]; |
398 | 4.54M | if (!used_frame[i] && hint >= cur_frame_hint && |
399 | 1.71M | (ref < 0 || hint < earliest_order_hint)) { |
400 | 562k | ref = i; |
401 | 562k | earliest_order_hint = hint; |
402 | 562k | } |
403 | 4.54M | } |
404 | 568k | if (ref >= 0) { |
405 | 465k | ref_frame_idx[AV1_REF_FRAME_BWDREF - AV1_REF_FRAME_LAST] = ref; |
406 | 465k | used_frame[ref] = 1; |
407 | 465k | } |
408 | | |
409 | 568k | ref = AV1_REF_FRAME_NONE; |
410 | 5.11M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { |
411 | 4.54M | int hint = shifted_order_hints[i]; |
412 | 4.54M | if (!used_frame[i] && hint >= cur_frame_hint && |
413 | 1.25M | (ref < 0 || hint < earliest_order_hint)) { |
414 | 456k | ref = i; |
415 | 456k | earliest_order_hint = hint; |
416 | 456k | } |
417 | 4.54M | } |
418 | 568k | if (ref >= 0) { |
419 | 358k | ref_frame_idx[AV1_REF_FRAME_ALTREF2 - AV1_REF_FRAME_LAST] = ref; |
420 | 358k | used_frame[ref] = 1; |
421 | 358k | } |
422 | | |
423 | 3.41M | for (i = 0; i < AV1_REFS_PER_FRAME - 2; i++) { |
424 | 2.84M | int ref_frame = ref_frame_list[i]; |
425 | 2.84M | if (ref_frame_idx[ref_frame - AV1_REF_FRAME_LAST] < 0 ) { |
426 | 1.53M | ref = AV1_REF_FRAME_NONE; |
427 | 13.7M | for (j = 0; j < AV1_NUM_REF_FRAMES; j++) { |
428 | 12.2M | int hint = shifted_order_hints[j]; |
429 | 12.2M | if (!used_frame[j] && hint < cur_frame_hint && |
430 | 3.47M | (ref < 0 || hint >= latest_order_hint)) { |
431 | 3.26M | ref = j; |
432 | 3.26M | latest_order_hint = hint; |
433 | 3.26M | } |
434 | 12.2M | } |
435 | 1.53M | if (ref >= 0) { |
436 | 1.01M | ref_frame_idx[ref_frame - AV1_REF_FRAME_LAST] = ref; |
437 | 1.01M | used_frame[ref] = 1; |
438 | 1.01M | } |
439 | 1.53M | } |
440 | 2.84M | } |
441 | | |
442 | 568k | ref = AV1_REF_FRAME_NONE; |
443 | 5.11M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { |
444 | 4.54M | int hint = shifted_order_hints[i]; |
445 | 4.54M | if (ref < 0 || hint < earliest_order_hint) { |
446 | 779k | ref = i; |
447 | 779k | earliest_order_hint = hint; |
448 | 779k | } |
449 | 4.54M | } |
450 | 4.54M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { |
451 | 3.97M | if (ref_frame_idx[i] < 0) |
452 | 515k | ref_frame_idx[i] = ref; |
453 | 3.97M | infer(ref_frame_idx[i], ref_frame_idx[i]); |
454 | 3.97M | } |
455 | | |
456 | 95.8k | return 0; |
457 | 568k | } cbs_av1.c:cbs_av1_read_set_frame_refs Line | Count | Source | 350 | 472k | { | 351 | 472k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 352 | 472k | const AV1RawSequenceHeader *seq = priv->sequence_header; | 353 | 472k | static const uint8_t ref_frame_list[AV1_NUM_REF_FRAMES - 2] = { | 354 | 472k | AV1_REF_FRAME_LAST2, AV1_REF_FRAME_LAST3, AV1_REF_FRAME_BWDREF, | 355 | 472k | AV1_REF_FRAME_ALTREF2, AV1_REF_FRAME_ALTREF | 356 | 472k | }; | 357 | 472k | int8_t ref_frame_idx[AV1_REFS_PER_FRAME], used_frame[AV1_NUM_REF_FRAMES]; | 358 | 472k | int16_t shifted_order_hints[AV1_NUM_REF_FRAMES]; | 359 | 472k | int cur_frame_hint, latest_order_hint, earliest_order_hint, ref; | 360 | 472k | int i, j; | 361 | | | 362 | 3.77M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) | 363 | 3.30M | ref_frame_idx[i] = AV1_REF_FRAME_NONE; | 364 | 472k | ref_frame_idx[AV1_REF_FRAME_LAST - AV1_REF_FRAME_LAST] = current->last_frame_idx; | 365 | 472k | ref_frame_idx[AV1_REF_FRAME_GOLDEN - AV1_REF_FRAME_LAST] = current->golden_frame_idx; | 366 | | | 367 | 4.24M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) | 368 | 3.77M | used_frame[i] = 0; | 369 | 472k | used_frame[current->last_frame_idx] = 1; | 370 | 472k | used_frame[current->golden_frame_idx] = 1; | 371 | | | 372 | 472k | cur_frame_hint = 1 << (seq->order_hint_bits_minus_1); | 373 | 4.24M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) | 374 | 3.77M | shifted_order_hints[i] = cur_frame_hint + | 375 | 3.77M | cbs_av1_get_relative_dist(seq, priv->ref[i].order_hint, | 376 | 3.77M | priv->order_hint); | 377 | | | 378 | 472k | latest_order_hint = shifted_order_hints[current->last_frame_idx]; | 379 | 472k | earliest_order_hint = shifted_order_hints[current->golden_frame_idx]; | 380 | | | 381 | 472k | ref = AV1_REF_FRAME_NONE; | 382 | 4.24M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 383 | 3.77M | int hint = shifted_order_hints[i]; | 384 | 3.77M | if (!used_frame[i] && hint >= cur_frame_hint && | 385 | 1.80M | (ref < 0 || hint >= latest_order_hint)) { | 386 | 1.56M | ref = i; | 387 | 1.56M | latest_order_hint = hint; | 388 | 1.56M | } | 389 | 3.77M | } | 390 | 472k | if (ref >= 0) { | 391 | 398k | ref_frame_idx[AV1_REF_FRAME_ALTREF - AV1_REF_FRAME_LAST] = ref; | 392 | 398k | used_frame[ref] = 1; | 393 | 398k | } | 394 | | | 395 | 472k | ref = AV1_REF_FRAME_NONE; | 396 | 4.24M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 397 | 3.77M | int hint = shifted_order_hints[i]; | 398 | 3.77M | if (!used_frame[i] && hint >= cur_frame_hint && | 399 | 1.40M | (ref < 0 || hint < earliest_order_hint)) { | 400 | 455k | ref = i; | 401 | 455k | earliest_order_hint = hint; | 402 | 455k | } | 403 | 3.77M | } | 404 | 472k | if (ref >= 0) { | 405 | 380k | ref_frame_idx[AV1_REF_FRAME_BWDREF - AV1_REF_FRAME_LAST] = ref; | 406 | 380k | used_frame[ref] = 1; | 407 | 380k | } | 408 | | | 409 | 472k | ref = AV1_REF_FRAME_NONE; | 410 | 4.24M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 411 | 3.77M | int hint = shifted_order_hints[i]; | 412 | 3.77M | if (!used_frame[i] && hint >= cur_frame_hint && | 413 | 1.02M | (ref < 0 || hint < earliest_order_hint)) { | 414 | 369k | ref = i; | 415 | 369k | earliest_order_hint = hint; | 416 | 369k | } | 417 | 3.77M | } | 418 | 472k | if (ref >= 0) { | 419 | 295k | ref_frame_idx[AV1_REF_FRAME_ALTREF2 - AV1_REF_FRAME_LAST] = ref; | 420 | 295k | used_frame[ref] = 1; | 421 | 295k | } | 422 | | | 423 | 2.83M | for (i = 0; i < AV1_REFS_PER_FRAME - 2; i++) { | 424 | 2.36M | int ref_frame = ref_frame_list[i]; | 425 | 2.36M | if (ref_frame_idx[ref_frame - AV1_REF_FRAME_LAST] < 0 ) { | 426 | 1.28M | ref = AV1_REF_FRAME_NONE; | 427 | 11.5M | for (j = 0; j < AV1_NUM_REF_FRAMES; j++) { | 428 | 10.2M | int hint = shifted_order_hints[j]; | 429 | 10.2M | if (!used_frame[j] && hint < cur_frame_hint && | 430 | 2.99M | (ref < 0 || hint >= latest_order_hint)) { | 431 | 2.81M | ref = j; | 432 | 2.81M | latest_order_hint = hint; | 433 | 2.81M | } | 434 | 10.2M | } | 435 | 1.28M | if (ref >= 0) { | 436 | 868k | ref_frame_idx[ref_frame - AV1_REF_FRAME_LAST] = ref; | 437 | 868k | used_frame[ref] = 1; | 438 | 868k | } | 439 | 1.28M | } | 440 | 2.36M | } | 441 | | | 442 | 472k | ref = AV1_REF_FRAME_NONE; | 443 | 4.24M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 444 | 3.77M | int hint = shifted_order_hints[i]; | 445 | 3.77M | if (ref < 0 || hint < earliest_order_hint) { | 446 | 637k | ref = i; | 447 | 637k | earliest_order_hint = hint; | 448 | 637k | } | 449 | 3.77M | } | 450 | 3.77M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { | 451 | 3.30M | if (ref_frame_idx[i] < 0) | 452 | 418k | ref_frame_idx[i] = ref; | 453 | 3.30M | infer(ref_frame_idx[i], ref_frame_idx[i]); | 454 | 3.30M | } | 455 | | | 456 | 472k | return 0; | 457 | 472k | } |
cbs_av1.c:cbs_av1_write_set_frame_refs Line | Count | Source | 350 | 96.4k | { | 351 | 96.4k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 352 | 96.4k | const AV1RawSequenceHeader *seq = priv->sequence_header; | 353 | 96.4k | static const uint8_t ref_frame_list[AV1_NUM_REF_FRAMES - 2] = { | 354 | 96.4k | AV1_REF_FRAME_LAST2, AV1_REF_FRAME_LAST3, AV1_REF_FRAME_BWDREF, | 355 | 96.4k | AV1_REF_FRAME_ALTREF2, AV1_REF_FRAME_ALTREF | 356 | 96.4k | }; | 357 | 96.4k | int8_t ref_frame_idx[AV1_REFS_PER_FRAME], used_frame[AV1_NUM_REF_FRAMES]; | 358 | 96.4k | int16_t shifted_order_hints[AV1_NUM_REF_FRAMES]; | 359 | 96.4k | int cur_frame_hint, latest_order_hint, earliest_order_hint, ref; | 360 | 96.4k | int i, j; | 361 | | | 362 | 771k | for (i = 0; i < AV1_REFS_PER_FRAME; i++) | 363 | 675k | ref_frame_idx[i] = AV1_REF_FRAME_NONE; | 364 | 96.4k | ref_frame_idx[AV1_REF_FRAME_LAST - AV1_REF_FRAME_LAST] = current->last_frame_idx; | 365 | 96.4k | ref_frame_idx[AV1_REF_FRAME_GOLDEN - AV1_REF_FRAME_LAST] = current->golden_frame_idx; | 366 | | | 367 | 868k | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) | 368 | 771k | used_frame[i] = 0; | 369 | 96.4k | used_frame[current->last_frame_idx] = 1; | 370 | 96.4k | used_frame[current->golden_frame_idx] = 1; | 371 | | | 372 | 96.4k | cur_frame_hint = 1 << (seq->order_hint_bits_minus_1); | 373 | 868k | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) | 374 | 771k | shifted_order_hints[i] = cur_frame_hint + | 375 | 771k | cbs_av1_get_relative_dist(seq, priv->ref[i].order_hint, | 376 | 771k | priv->order_hint); | 377 | | | 378 | 96.4k | latest_order_hint = shifted_order_hints[current->last_frame_idx]; | 379 | 96.4k | earliest_order_hint = shifted_order_hints[current->golden_frame_idx]; | 380 | | | 381 | 96.4k | ref = AV1_REF_FRAME_NONE; | 382 | 868k | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 383 | 771k | int hint = shifted_order_hints[i]; | 384 | 771k | if (!used_frame[i] && hint >= cur_frame_hint && | 385 | 397k | (ref < 0 || hint >= latest_order_hint)) { | 386 | 333k | ref = i; | 387 | 333k | latest_order_hint = hint; | 388 | 333k | } | 389 | 771k | } | 390 | 96.4k | if (ref >= 0) { | 391 | 89.2k | ref_frame_idx[AV1_REF_FRAME_ALTREF - AV1_REF_FRAME_LAST] = ref; | 392 | 89.2k | used_frame[ref] = 1; | 393 | 89.2k | } | 394 | | | 395 | 96.4k | ref = AV1_REF_FRAME_NONE; | 396 | 868k | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 397 | 771k | int hint = shifted_order_hints[i]; | 398 | 771k | if (!used_frame[i] && hint >= cur_frame_hint && | 399 | 308k | (ref < 0 || hint < earliest_order_hint)) { | 400 | 107k | ref = i; | 401 | 107k | earliest_order_hint = hint; | 402 | 107k | } | 403 | 771k | } | 404 | 96.4k | if (ref >= 0) { | 405 | 84.4k | ref_frame_idx[AV1_REF_FRAME_BWDREF - AV1_REF_FRAME_LAST] = ref; | 406 | 84.4k | used_frame[ref] = 1; | 407 | 84.4k | } | 408 | | | 409 | 96.4k | ref = AV1_REF_FRAME_NONE; | 410 | 868k | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 411 | 771k | int hint = shifted_order_hints[i]; | 412 | 771k | if (!used_frame[i] && hint >= cur_frame_hint && | 413 | 223k | (ref < 0 || hint < earliest_order_hint)) { | 414 | 86.8k | ref = i; | 415 | 86.8k | earliest_order_hint = hint; | 416 | 86.8k | } | 417 | 771k | } | 418 | 96.4k | if (ref >= 0) { | 419 | 62.9k | ref_frame_idx[AV1_REF_FRAME_ALTREF2 - AV1_REF_FRAME_LAST] = ref; | 420 | 62.9k | used_frame[ref] = 1; | 421 | 62.9k | } | 422 | | | 423 | 578k | for (i = 0; i < AV1_REFS_PER_FRAME - 2; i++) { | 424 | 482k | int ref_frame = ref_frame_list[i]; | 425 | 482k | if (ref_frame_idx[ref_frame - AV1_REF_FRAME_LAST] < 0 ) { | 426 | 245k | ref = AV1_REF_FRAME_NONE; | 427 | 2.21M | for (j = 0; j < AV1_NUM_REF_FRAMES; j++) { | 428 | 1.96M | int hint = shifted_order_hints[j]; | 429 | 1.96M | if (!used_frame[j] && hint < cur_frame_hint && | 430 | 476k | (ref < 0 || hint >= latest_order_hint)) { | 431 | 442k | ref = j; | 432 | 442k | latest_order_hint = hint; | 433 | 442k | } | 434 | 1.96M | } | 435 | 245k | if (ref >= 0) { | 436 | 148k | ref_frame_idx[ref_frame - AV1_REF_FRAME_LAST] = ref; | 437 | 148k | used_frame[ref] = 1; | 438 | 148k | } | 439 | 245k | } | 440 | 482k | } | 441 | | | 442 | 96.4k | ref = AV1_REF_FRAME_NONE; | 443 | 868k | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 444 | 771k | int hint = shifted_order_hints[i]; | 445 | 771k | if (ref < 0 || hint < earliest_order_hint) { | 446 | 141k | ref = i; | 447 | 141k | earliest_order_hint = hint; | 448 | 141k | } | 449 | 771k | } | 450 | 768k | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { | 451 | 672k | if (ref_frame_idx[i] < 0) | 452 | 97.1k | ref_frame_idx[i] = ref; | 453 | 672k | infer(ref_frame_idx[i], ref_frame_idx[i]); | 454 | 672k | } | 455 | | | 456 | 95.8k | return 0; | 457 | 96.4k | } |
|
458 | | |
459 | | static int FUNC(superres_params)(CodedBitstreamContext *ctx, RWContext *rw, |
460 | | AV1RawFrameHeader *current) |
461 | 2.28M | { |
462 | 2.28M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
463 | 2.28M | const AV1RawSequenceHeader *seq = priv->sequence_header; |
464 | 2.28M | int denom, err; |
465 | | |
466 | 2.28M | if (seq->enable_superres) |
467 | 2.28M | flag(use_superres); |
468 | 1.33M | else |
469 | 1.33M | infer(use_superres, 0); |
470 | | |
471 | 2.27M | if (current->use_superres) { |
472 | 304k | fb(3, coded_denom); |
473 | 296k | denom = current->coded_denom + AV1_SUPERRES_DENOM_MIN; |
474 | 1.96M | } else { |
475 | 1.96M | denom = AV1_SUPERRES_NUM; |
476 | 1.96M | } |
477 | | |
478 | 2.26M | priv->upscaled_width = priv->frame_width; |
479 | 2.26M | priv->frame_width = (priv->upscaled_width * AV1_SUPERRES_NUM + |
480 | 2.26M | denom / 2) / denom; |
481 | | |
482 | 2.26M | return 0; |
483 | 2.27M | } cbs_av1.c:cbs_av1_read_superres_params Line | Count | Source | 461 | 1.97M | { | 462 | 1.97M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 463 | 1.97M | const AV1RawSequenceHeader *seq = priv->sequence_header; | 464 | 1.97M | int denom, err; | 465 | | | 466 | 1.97M | if (seq->enable_superres) | 467 | 1.97M | flag(use_superres); | 468 | 1.14M | else | 469 | 1.14M | infer(use_superres, 0); | 470 | | | 471 | 1.97M | if (current->use_superres) { | 472 | 284k | fb(3, coded_denom); | 473 | 277k | denom = current->coded_denom + AV1_SUPERRES_DENOM_MIN; | 474 | 1.68M | } else { | 475 | 1.68M | denom = AV1_SUPERRES_NUM; | 476 | 1.68M | } | 477 | | | 478 | 1.96M | priv->upscaled_width = priv->frame_width; | 479 | 1.96M | priv->frame_width = (priv->upscaled_width * AV1_SUPERRES_NUM + | 480 | 1.96M | denom / 2) / denom; | 481 | | | 482 | 1.96M | return 0; | 483 | 1.97M | } |
cbs_av1.c:cbs_av1_write_superres_params Line | Count | Source | 461 | 302k | { | 462 | 302k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 463 | 302k | const AV1RawSequenceHeader *seq = priv->sequence_header; | 464 | 302k | int denom, err; | 465 | | | 466 | 302k | if (seq->enable_superres) | 467 | 302k | flag(use_superres); | 468 | 187k | else | 469 | 187k | infer(use_superres, 0); | 470 | | | 471 | 301k | if (current->use_superres) { | 472 | 19.4k | fb(3, coded_denom); | 473 | 19.4k | denom = current->coded_denom + AV1_SUPERRES_DENOM_MIN; | 474 | 281k | } else { | 475 | 281k | denom = AV1_SUPERRES_NUM; | 476 | 281k | } | 477 | | | 478 | 301k | priv->upscaled_width = priv->frame_width; | 479 | 301k | priv->frame_width = (priv->upscaled_width * AV1_SUPERRES_NUM + | 480 | 301k | denom / 2) / denom; | 481 | | | 482 | 301k | return 0; | 483 | 301k | } |
|
484 | | |
485 | | static int FUNC(frame_size)(CodedBitstreamContext *ctx, RWContext *rw, |
486 | | AV1RawFrameHeader *current) |
487 | 2.19M | { |
488 | 2.19M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
489 | 2.19M | const AV1RawSequenceHeader *seq = priv->sequence_header; |
490 | 2.19M | int err; |
491 | | |
492 | 2.19M | if (current->frame_size_override_flag) { |
493 | 401k | fb(seq->frame_width_bits_minus_1 + 1, frame_width_minus_1); |
494 | 385k | fb(seq->frame_height_bits_minus_1 + 1, frame_height_minus_1); |
495 | 1.79M | } else { |
496 | 1.79M | infer(frame_width_minus_1, seq->max_frame_width_minus_1); |
497 | 1.79M | infer(frame_height_minus_1, seq->max_frame_height_minus_1); |
498 | 254k | } |
499 | | |
500 | 2.16M | priv->frame_width = current->frame_width_minus_1 + 1; |
501 | 2.16M | priv->frame_height = current->frame_height_minus_1 + 1; |
502 | | |
503 | 2.16M | CHECK(FUNC(superres_params)(ctx, rw, current)); |
504 | | |
505 | 2.15M | return 0; |
506 | 2.16M | } cbs_av1.c:cbs_av1_read_frame_size Line | Count | Source | 487 | 1.91M | { | 488 | 1.91M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 489 | 1.91M | const AV1RawSequenceHeader *seq = priv->sequence_header; | 490 | 1.91M | int err; | 491 | | | 492 | 1.91M | if (current->frame_size_override_flag) { | 493 | 374k | fb(seq->frame_width_bits_minus_1 + 1, frame_width_minus_1); | 494 | 359k | fb(seq->frame_height_bits_minus_1 + 1, frame_height_minus_1); | 495 | 1.53M | } else { | 496 | 1.53M | infer(frame_width_minus_1, seq->max_frame_width_minus_1); | 497 | 1.53M | infer(frame_height_minus_1, seq->max_frame_height_minus_1); | 498 | 1.53M | } | 499 | | | 500 | 1.88M | priv->frame_width = current->frame_width_minus_1 + 1; | 501 | 1.88M | priv->frame_height = current->frame_height_minus_1 + 1; | 502 | | | 503 | 1.88M | CHECK(FUNC(superres_params)(ctx, rw, current)); | 504 | | | 505 | 1.87M | return 0; | 506 | 1.88M | } |
cbs_av1.c:cbs_av1_write_frame_size Line | Count | Source | 487 | 283k | { | 488 | 283k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 489 | 283k | const AV1RawSequenceHeader *seq = priv->sequence_header; | 490 | 283k | int err; | 491 | | | 492 | 283k | if (current->frame_size_override_flag) { | 493 | 27.4k | fb(seq->frame_width_bits_minus_1 + 1, frame_width_minus_1); | 494 | 26.8k | fb(seq->frame_height_bits_minus_1 + 1, frame_height_minus_1); | 495 | 255k | } else { | 496 | 255k | infer(frame_width_minus_1, seq->max_frame_width_minus_1); | 497 | 254k | infer(frame_height_minus_1, seq->max_frame_height_minus_1); | 498 | 254k | } | 499 | | | 500 | 280k | priv->frame_width = current->frame_width_minus_1 + 1; | 501 | 280k | priv->frame_height = current->frame_height_minus_1 + 1; | 502 | | | 503 | 280k | CHECK(FUNC(superres_params)(ctx, rw, current)); | 504 | | | 505 | 279k | return 0; | 506 | 280k | } |
|
507 | | |
508 | | static int FUNC(render_size)(CodedBitstreamContext *ctx, RWContext *rw, |
509 | | AV1RawFrameHeader *current) |
510 | 2.15M | { |
511 | 2.15M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
512 | 2.15M | int err; |
513 | | |
514 | 2.15M | flag(render_and_frame_size_different); |
515 | | |
516 | 2.14M | if (current->render_and_frame_size_different) { |
517 | 748k | fb(16, render_width_minus_1); |
518 | 720k | fb(16, render_height_minus_1); |
519 | 1.39M | } else { |
520 | 1.39M | infer(render_width_minus_1, current->frame_width_minus_1); |
521 | 1.39M | infer(render_height_minus_1, current->frame_height_minus_1); |
522 | 184k | } |
523 | | |
524 | 2.09M | priv->render_width = current->render_width_minus_1 + 1; |
525 | 2.09M | priv->render_height = current->render_height_minus_1 + 1; |
526 | | |
527 | 2.09M | return 0; |
528 | 2.14M | } cbs_av1.c:cbs_av1_read_render_size Line | Count | Source | 510 | 1.87M | { | 511 | 1.87M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 512 | 1.87M | int err; | 513 | | | 514 | 1.87M | flag(render_and_frame_size_different); | 515 | | | 516 | 1.86M | if (current->render_and_frame_size_different) { | 517 | 653k | fb(16, render_width_minus_1); | 518 | 625k | fb(16, render_height_minus_1); | 519 | 1.21M | } else { | 520 | 1.21M | infer(render_width_minus_1, current->frame_width_minus_1); | 521 | 1.21M | infer(render_height_minus_1, current->frame_height_minus_1); | 522 | 1.21M | } | 523 | | | 524 | 1.81M | priv->render_width = current->render_width_minus_1 + 1; | 525 | 1.81M | priv->render_height = current->render_height_minus_1 + 1; | 526 | | | 527 | 1.81M | return 0; | 528 | 1.86M | } |
cbs_av1.c:cbs_av1_write_render_size Line | Count | Source | 510 | 279k | { | 511 | 279k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 512 | 279k | int err; | 513 | | | 514 | 279k | flag(render_and_frame_size_different); | 515 | | | 516 | 279k | if (current->render_and_frame_size_different) { | 517 | 95.3k | fb(16, render_width_minus_1); | 518 | 95.3k | fb(16, render_height_minus_1); | 519 | 184k | } else { | 520 | 184k | infer(render_width_minus_1, current->frame_width_minus_1); | 521 | 184k | infer(render_height_minus_1, current->frame_height_minus_1); | 522 | 184k | } | 523 | | | 524 | 279k | priv->render_width = current->render_width_minus_1 + 1; | 525 | 279k | priv->render_height = current->render_height_minus_1 + 1; | 526 | | | 527 | 279k | return 0; | 528 | 279k | } |
|
529 | | |
530 | | static int FUNC(frame_size_with_refs)(CodedBitstreamContext *ctx, RWContext *rw, |
531 | | AV1RawFrameHeader *current) |
532 | 229k | { |
533 | 229k | CodedBitstreamAV1Context *priv = ctx->priv_data; |
534 | 229k | int i, err; |
535 | | |
536 | 852k | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { |
537 | 791k | flags(found_ref[i], 1, i); |
538 | 779k | if (current->found_ref[i]) { |
539 | 157k | AV1ReferenceFrameState *ref = |
540 | 157k | &priv->ref[current->ref_frame_idx[i]]; |
541 | | |
542 | 157k | if (!ref->valid) { |
543 | 38.9k | av_log(ctx->log_ctx, AV_LOG_ERROR, |
544 | 38.9k | "Missing reference frame needed for frame size " |
545 | 38.9k | "(ref = %d, ref_frame_idx = %d).\n", |
546 | 38.9k | i, current->ref_frame_idx[i]); |
547 | 38.9k | return AVERROR_INVALIDDATA; |
548 | 38.9k | } |
549 | | |
550 | 118k | infer(frame_width_minus_1, ref->upscaled_width - 1); |
551 | 117k | infer(frame_height_minus_1, ref->frame_height - 1); |
552 | 117k | infer(render_width_minus_1, ref->render_width - 1); |
553 | 116k | infer(render_height_minus_1, ref->render_height - 1); |
554 | | |
555 | 22.0k | priv->upscaled_width = ref->upscaled_width; |
556 | 22.0k | priv->frame_width = priv->upscaled_width; |
557 | 22.0k | priv->frame_height = ref->frame_height; |
558 | 22.0k | priv->render_width = ref->render_width; |
559 | 22.0k | priv->render_height = ref->render_height; |
560 | 22.0k | break; |
561 | 22.5k | } |
562 | 779k | } |
563 | | |
564 | 177k | if (i >= AV1_REFS_PER_FRAME) { |
565 | 61.4k | CHECK(FUNC(frame_size)(ctx, rw, current)); |
566 | 50.4k | CHECK(FUNC(render_size)(ctx, rw, current)); |
567 | 116k | } else { |
568 | 116k | CHECK(FUNC(superres_params)(ctx, rw, current)); |
569 | 116k | } |
570 | | |
571 | 153k | return 0; |
572 | 177k | } cbs_av1.c:cbs_av1_read_frame_size_with_refs Line | Count | Source | 532 | 199k | { | 533 | 199k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 534 | 199k | int i, err; | 535 | | | 536 | 761k | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { | 537 | 705k | flags(found_ref[i], 1, i); | 538 | 694k | if (current->found_ref[i]) { | 539 | 132k | AV1ReferenceFrameState *ref = | 540 | 132k | &priv->ref[current->ref_frame_idx[i]]; | 541 | | | 542 | 132k | if (!ref->valid) { | 543 | 38.5k | av_log(ctx->log_ctx, AV_LOG_ERROR, | 544 | 38.5k | "Missing reference frame needed for frame size " | 545 | 38.5k | "(ref = %d, ref_frame_idx = %d).\n", | 546 | 38.5k | i, current->ref_frame_idx[i]); | 547 | 38.5k | return AVERROR_INVALIDDATA; | 548 | 38.5k | } | 549 | | | 550 | 94.3k | infer(frame_width_minus_1, ref->upscaled_width - 1); | 551 | 94.3k | infer(frame_height_minus_1, ref->frame_height - 1); | 552 | 94.3k | infer(render_width_minus_1, ref->render_width - 1); | 553 | 94.3k | infer(render_height_minus_1, ref->render_height - 1); | 554 | | | 555 | 94.3k | priv->upscaled_width = ref->upscaled_width; | 556 | 94.3k | priv->frame_width = priv->upscaled_width; | 557 | 94.3k | priv->frame_height = ref->frame_height; | 558 | 94.3k | priv->render_width = ref->render_width; | 559 | 94.3k | priv->render_height = ref->render_height; | 560 | 94.3k | break; | 561 | 132k | } | 562 | 694k | } | 563 | | | 564 | 149k | if (i >= AV1_REFS_PER_FRAME) { | 565 | 55.3k | CHECK(FUNC(frame_size)(ctx, rw, current)); | 566 | 44.7k | CHECK(FUNC(render_size)(ctx, rw, current)); | 567 | 94.3k | } else { | 568 | 94.3k | CHECK(FUNC(superres_params)(ctx, rw, current)); | 569 | 94.3k | } | 570 | | | 571 | 125k | return 0; | 572 | 149k | } |
cbs_av1.c:cbs_av1_write_frame_size_with_refs Line | Count | Source | 532 | 30.3k | { | 533 | 30.3k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 534 | 30.3k | int i, err; | 535 | | | 536 | 91.4k | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { | 537 | 85.3k | flags(found_ref[i], 1, i); | 538 | 85.3k | if (current->found_ref[i]) { | 539 | 24.2k | AV1ReferenceFrameState *ref = | 540 | 24.2k | &priv->ref[current->ref_frame_idx[i]]; | 541 | | | 542 | 24.2k | if (!ref->valid) { | 543 | 421 | av_log(ctx->log_ctx, AV_LOG_ERROR, | 544 | 421 | "Missing reference frame needed for frame size " | 545 | 421 | "(ref = %d, ref_frame_idx = %d).\n", | 546 | 421 | i, current->ref_frame_idx[i]); | 547 | 421 | return AVERROR_INVALIDDATA; | 548 | 421 | } | 549 | | | 550 | 23.8k | infer(frame_width_minus_1, ref->upscaled_width - 1); | 551 | 23.4k | infer(frame_height_minus_1, ref->frame_height - 1); | 552 | 22.9k | infer(render_width_minus_1, ref->render_width - 1); | 553 | 22.5k | infer(render_height_minus_1, ref->render_height - 1); | 554 | | | 555 | 22.0k | priv->upscaled_width = ref->upscaled_width; | 556 | 22.0k | priv->frame_width = priv->upscaled_width; | 557 | 22.0k | priv->frame_height = ref->frame_height; | 558 | 22.0k | priv->render_width = ref->render_width; | 559 | 22.0k | priv->render_height = ref->render_height; | 560 | 22.0k | break; | 561 | 22.5k | } | 562 | 85.3k | } | 563 | | | 564 | 28.1k | if (i >= AV1_REFS_PER_FRAME) { | 565 | 6.06k | CHECK(FUNC(frame_size)(ctx, rw, current)); | 566 | 5.62k | CHECK(FUNC(render_size)(ctx, rw, current)); | 567 | 22.0k | } else { | 568 | 22.0k | CHECK(FUNC(superres_params)(ctx, rw, current)); | 569 | 22.0k | } | 570 | | | 571 | 27.2k | return 0; | 572 | 28.1k | } |
|
573 | | |
574 | | static int FUNC(interpolation_filter)(CodedBitstreamContext *ctx, RWContext *rw, |
575 | | AV1RawFrameHeader *current) |
576 | 1.12M | { |
577 | 1.12M | int err; |
578 | | |
579 | 1.12M | flag(is_filter_switchable); |
580 | 1.11M | if (current->is_filter_switchable) |
581 | 321k | infer(interpolation_filter, |
582 | 1.11M | AV1_INTERPOLATION_FILTER_SWITCHABLE); |
583 | 797k | else |
584 | 797k | fb(2, interpolation_filter); |
585 | | |
586 | 1.11M | return 0; |
587 | 1.11M | } cbs_av1.c:cbs_av1_read_interpolation_filter Line | Count | Source | 576 | 997k | { | 577 | 997k | int err; | 578 | | | 579 | 997k | flag(is_filter_switchable); | 580 | 989k | if (current->is_filter_switchable) | 581 | 283k | infer(interpolation_filter, | 582 | 989k | AV1_INTERPOLATION_FILTER_SWITCHABLE); | 583 | 706k | else | 584 | 706k | fb(2, interpolation_filter); | 585 | | | 586 | 982k | return 0; | 587 | 989k | } |
cbs_av1.c:cbs_av1_write_interpolation_filter Line | Count | Source | 576 | 129k | { | 577 | 129k | int err; | 578 | | | 579 | 129k | flag(is_filter_switchable); | 580 | 129k | if (current->is_filter_switchable) | 581 | 37.8k | infer(interpolation_filter, | 582 | 129k | AV1_INTERPOLATION_FILTER_SWITCHABLE); | 583 | 91.7k | else | 584 | 91.7k | fb(2, interpolation_filter); | 585 | | | 586 | 129k | return 0; | 587 | 129k | } |
|
588 | | |
589 | | static int FUNC(tile_info)(CodedBitstreamContext *ctx, RWContext *rw, |
590 | | AV1RawFrameHeader *current) |
591 | 2.15M | { |
592 | 2.15M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
593 | 2.15M | const AV1RawSequenceHeader *seq = priv->sequence_header; |
594 | 2.15M | int mi_cols, mi_rows, sb_cols, sb_rows, sb_shift, sb_size; |
595 | 2.15M | int max_tile_width_sb, max_tile_height_sb, max_tile_area_sb; |
596 | 2.15M | int min_log2_tile_cols, max_log2_tile_cols, max_log2_tile_rows; |
597 | 2.15M | int min_log2_tiles, min_log2_tile_rows; |
598 | 2.15M | int err; |
599 | | |
600 | 2.15M | mi_cols = 2 * ((priv->frame_width + 7) >> 3); |
601 | 2.15M | mi_rows = 2 * ((priv->frame_height + 7) >> 3); |
602 | | |
603 | 2.15M | sb_cols = seq->use_128x128_superblock ? ((mi_cols + 31) >> 5) |
604 | 2.15M | : ((mi_cols + 15) >> 4); |
605 | 2.15M | sb_rows = seq->use_128x128_superblock ? ((mi_rows + 31) >> 5) |
606 | 2.15M | : ((mi_rows + 15) >> 4); |
607 | | |
608 | 2.15M | sb_shift = seq->use_128x128_superblock ? 5 : 4; |
609 | 2.15M | sb_size = sb_shift + 2; |
610 | | |
611 | 2.15M | max_tile_width_sb = AV1_MAX_TILE_WIDTH >> sb_size; |
612 | 2.15M | max_tile_area_sb = AV1_MAX_TILE_AREA >> (2 * sb_size); |
613 | | |
614 | 2.15M | min_log2_tile_cols = cbs_av1_tile_log2(max_tile_width_sb, sb_cols); |
615 | 2.15M | max_log2_tile_cols = cbs_av1_tile_log2(1, FFMIN(sb_cols, AV1_MAX_TILE_COLS)); |
616 | 2.15M | max_log2_tile_rows = cbs_av1_tile_log2(1, FFMIN(sb_rows, AV1_MAX_TILE_ROWS)); |
617 | 2.15M | min_log2_tiles = FFMAX(min_log2_tile_cols, |
618 | 2.15M | cbs_av1_tile_log2(max_tile_area_sb, sb_rows * sb_cols)); |
619 | | |
620 | 2.15M | flag(uniform_tile_spacing_flag); |
621 | | |
622 | 2.13M | if (current->uniform_tile_spacing_flag) { |
623 | 619k | int tile_width_sb, tile_height_sb; |
624 | | |
625 | 619k | increment(tile_cols_log2, min_log2_tile_cols, max_log2_tile_cols); |
626 | | |
627 | 615k | tile_width_sb = (sb_cols + (1 << current->tile_cols_log2) - 1) >> |
628 | 615k | current->tile_cols_log2; |
629 | | |
630 | 2.59M | for (int off = 0, j = 0; off < sb_cols; off += tile_width_sb) |
631 | 1.98M | current->tile_start_col_sb[j++] = off; |
632 | | |
633 | 615k | current->tile_cols = (sb_cols + tile_width_sb - 1) / tile_width_sb; |
634 | | |
635 | 615k | min_log2_tile_rows = FFMAX(min_log2_tiles - current->tile_cols_log2, 0); |
636 | | |
637 | 615k | increment(tile_rows_log2, min_log2_tile_rows, max_log2_tile_rows); |
638 | | |
639 | 611k | tile_height_sb = (sb_rows + (1 << current->tile_rows_log2) - 1) >> |
640 | 611k | current->tile_rows_log2; |
641 | | |
642 | 2.25M | for (int off = 0, j = 0; off < sb_rows; off += tile_height_sb) |
643 | 1.64M | current->tile_start_row_sb[j++] = off; |
644 | | |
645 | 611k | current->tile_rows = (sb_rows + tile_height_sb - 1) / tile_height_sb; |
646 | | |
647 | 611k | int i; |
648 | 1.93M | for (i = 0; i < current->tile_cols - 1; i++) |
649 | 1.32M | infer(width_in_sbs_minus_1[i], tile_width_sb - 1); |
650 | 610k | infer(width_in_sbs_minus_1[i], |
651 | 78.6k | sb_cols - (current->tile_cols - 1) * tile_width_sb - 1); |
652 | 1.63M | for (i = 0; i < current->tile_rows - 1; i++) |
653 | 1.02M | infer(height_in_sbs_minus_1[i], tile_height_sb - 1); |
654 | 609k | infer(height_in_sbs_minus_1[i], |
655 | 77.7k | sb_rows - (current->tile_rows - 1) * tile_height_sb - 1); |
656 | | |
657 | 1.52M | } else { |
658 | 1.52M | int widest_tile_sb, start_sb, size_sb, max_width, max_height, i; |
659 | | |
660 | 1.52M | widest_tile_sb = 0; |
661 | | |
662 | 1.52M | start_sb = 0; |
663 | 4.94M | for (i = 0; start_sb < sb_cols && i < AV1_MAX_TILE_COLS; i++) { |
664 | 3.45M | current->tile_start_col_sb[i] = start_sb; |
665 | 3.45M | max_width = FFMIN(sb_cols - start_sb, max_tile_width_sb); |
666 | 3.45M | ns(max_width, width_in_sbs_minus_1[i], 1, i); |
667 | 3.42M | size_sb = current->width_in_sbs_minus_1[i] + 1; |
668 | 3.42M | widest_tile_sb = FFMAX(size_sb, widest_tile_sb); |
669 | 3.42M | start_sb += size_sb; |
670 | 3.42M | } |
671 | 1.48M | current->tile_cols_log2 = cbs_av1_tile_log2(1, i); |
672 | 1.48M | current->tile_cols = i; |
673 | | |
674 | 1.48M | if (min_log2_tiles > 0) |
675 | 86.9k | max_tile_area_sb = (sb_rows * sb_cols) >> (min_log2_tiles + 1); |
676 | 1.39M | else |
677 | 1.39M | max_tile_area_sb = sb_rows * sb_cols; |
678 | 1.48M | max_tile_height_sb = FFMAX(max_tile_area_sb / widest_tile_sb, 1); |
679 | | |
680 | 1.48M | start_sb = 0; |
681 | 4.52M | for (i = 0; start_sb < sb_rows && i < AV1_MAX_TILE_ROWS; i++) { |
682 | 3.06M | current->tile_start_row_sb[i] = start_sb; |
683 | 3.06M | max_height = FFMIN(sb_rows - start_sb, max_tile_height_sb); |
684 | 3.06M | ns(max_height, height_in_sbs_minus_1[i], 1, i); |
685 | 3.03M | size_sb = current->height_in_sbs_minus_1[i] + 1; |
686 | 3.03M | start_sb += size_sb; |
687 | 3.03M | } |
688 | 1.46M | current->tile_rows_log2 = cbs_av1_tile_log2(1, i); |
689 | 1.46M | current->tile_rows = i; |
690 | 1.46M | } |
691 | | |
692 | 2.07M | if (current->tile_cols_log2 > 0 || |
693 | 1.79M | current->tile_rows_log2 > 0) { |
694 | 460k | fb(current->tile_cols_log2 + current->tile_rows_log2, |
695 | 460k | context_update_tile_id); |
696 | 452k | fb(2, tile_size_bytes_minus1); |
697 | 1.60M | } else { |
698 | 1.60M | infer(context_update_tile_id, 0); |
699 | 1.60M | } |
700 | | |
701 | 2.05M | priv->tile_cols = current->tile_cols; |
702 | 2.05M | priv->tile_rows = current->tile_rows; |
703 | | |
704 | 2.05M | return 0; |
705 | 2.07M | } cbs_av1.c:cbs_av1_read_tile_info Line | Count | Source | 591 | 1.85M | { | 592 | 1.85M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 593 | 1.85M | const AV1RawSequenceHeader *seq = priv->sequence_header; | 594 | 1.85M | int mi_cols, mi_rows, sb_cols, sb_rows, sb_shift, sb_size; | 595 | 1.85M | int max_tile_width_sb, max_tile_height_sb, max_tile_area_sb; | 596 | 1.85M | int min_log2_tile_cols, max_log2_tile_cols, max_log2_tile_rows; | 597 | 1.85M | int min_log2_tiles, min_log2_tile_rows; | 598 | 1.85M | int err; | 599 | | | 600 | 1.85M | mi_cols = 2 * ((priv->frame_width + 7) >> 3); | 601 | 1.85M | mi_rows = 2 * ((priv->frame_height + 7) >> 3); | 602 | | | 603 | 1.85M | sb_cols = seq->use_128x128_superblock ? ((mi_cols + 31) >> 5) | 604 | 1.85M | : ((mi_cols + 15) >> 4); | 605 | 1.85M | sb_rows = seq->use_128x128_superblock ? ((mi_rows + 31) >> 5) | 606 | 1.85M | : ((mi_rows + 15) >> 4); | 607 | | | 608 | 1.85M | sb_shift = seq->use_128x128_superblock ? 5 : 4; | 609 | 1.85M | sb_size = sb_shift + 2; | 610 | | | 611 | 1.85M | max_tile_width_sb = AV1_MAX_TILE_WIDTH >> sb_size; | 612 | 1.85M | max_tile_area_sb = AV1_MAX_TILE_AREA >> (2 * sb_size); | 613 | | | 614 | 1.85M | min_log2_tile_cols = cbs_av1_tile_log2(max_tile_width_sb, sb_cols); | 615 | 1.85M | max_log2_tile_cols = cbs_av1_tile_log2(1, FFMIN(sb_cols, AV1_MAX_TILE_COLS)); | 616 | 1.85M | max_log2_tile_rows = cbs_av1_tile_log2(1, FFMIN(sb_rows, AV1_MAX_TILE_ROWS)); | 617 | 1.85M | min_log2_tiles = FFMAX(min_log2_tile_cols, | 618 | 1.85M | cbs_av1_tile_log2(max_tile_area_sb, sb_rows * sb_cols)); | 619 | | | 620 | 1.85M | flag(uniform_tile_spacing_flag); | 621 | | | 622 | 1.83M | if (current->uniform_tile_spacing_flag) { | 623 | 539k | int tile_width_sb, tile_height_sb; | 624 | | | 625 | 539k | increment(tile_cols_log2, min_log2_tile_cols, max_log2_tile_cols); | 626 | | | 627 | 535k | tile_width_sb = (sb_cols + (1 << current->tile_cols_log2) - 1) >> | 628 | 535k | current->tile_cols_log2; | 629 | | | 630 | 2.34M | for (int off = 0, j = 0; off < sb_cols; off += tile_width_sb) | 631 | 1.80M | current->tile_start_col_sb[j++] = off; | 632 | | | 633 | 535k | current->tile_cols = (sb_cols + tile_width_sb - 1) / tile_width_sb; | 634 | | | 635 | 535k | min_log2_tile_rows = FFMAX(min_log2_tiles - current->tile_cols_log2, 0); | 636 | | | 637 | 535k | increment(tile_rows_log2, min_log2_tile_rows, max_log2_tile_rows); | 638 | | | 639 | 531k | tile_height_sb = (sb_rows + (1 << current->tile_rows_log2) - 1) >> | 640 | 531k | current->tile_rows_log2; | 641 | | | 642 | 2.01M | for (int off = 0, j = 0; off < sb_rows; off += tile_height_sb) | 643 | 1.48M | current->tile_start_row_sb[j++] = off; | 644 | | | 645 | 531k | current->tile_rows = (sb_rows + tile_height_sb - 1) / tile_height_sb; | 646 | | | 647 | 531k | int i; | 648 | 1.77M | for (i = 0; i < current->tile_cols - 1; i++) | 649 | 1.24M | infer(width_in_sbs_minus_1[i], tile_width_sb - 1); | 650 | 531k | infer(width_in_sbs_minus_1[i], | 651 | 531k | sb_cols - (current->tile_cols - 1) * tile_width_sb - 1); | 652 | 1.48M | for (i = 0; i < current->tile_rows - 1; i++) | 653 | 951k | infer(height_in_sbs_minus_1[i], tile_height_sb - 1); | 654 | 531k | infer(height_in_sbs_minus_1[i], | 655 | 531k | sb_rows - (current->tile_rows - 1) * tile_height_sb - 1); | 656 | | | 657 | 1.30M | } else { | 658 | 1.30M | int widest_tile_sb, start_sb, size_sb, max_width, max_height, i; | 659 | | | 660 | 1.30M | widest_tile_sb = 0; | 661 | | | 662 | 1.30M | start_sb = 0; | 663 | 4.46M | for (i = 0; start_sb < sb_cols && i < AV1_MAX_TILE_COLS; i++) { | 664 | 3.19M | current->tile_start_col_sb[i] = start_sb; | 665 | 3.19M | max_width = FFMIN(sb_cols - start_sb, max_tile_width_sb); | 666 | 3.19M | ns(max_width, width_in_sbs_minus_1[i], 1, i); | 667 | 3.16M | size_sb = current->width_in_sbs_minus_1[i] + 1; | 668 | 3.16M | widest_tile_sb = FFMAX(size_sb, widest_tile_sb); | 669 | 3.16M | start_sb += size_sb; | 670 | 3.16M | } | 671 | 1.26M | current->tile_cols_log2 = cbs_av1_tile_log2(1, i); | 672 | 1.26M | current->tile_cols = i; | 673 | | | 674 | 1.26M | if (min_log2_tiles > 0) | 675 | 84.6k | max_tile_area_sb = (sb_rows * sb_cols) >> (min_log2_tiles + 1); | 676 | 1.18M | else | 677 | 1.18M | max_tile_area_sb = sb_rows * sb_cols; | 678 | 1.26M | max_tile_height_sb = FFMAX(max_tile_area_sb / widest_tile_sb, 1); | 679 | | | 680 | 1.26M | start_sb = 0; | 681 | 4.03M | for (i = 0; start_sb < sb_rows && i < AV1_MAX_TILE_ROWS; i++) { | 682 | 2.79M | current->tile_start_row_sb[i] = start_sb; | 683 | 2.79M | max_height = FFMIN(sb_rows - start_sb, max_tile_height_sb); | 684 | 2.79M | ns(max_height, height_in_sbs_minus_1[i], 1, i); | 685 | 2.77M | size_sb = current->height_in_sbs_minus_1[i] + 1; | 686 | 2.77M | start_sb += size_sb; | 687 | 2.77M | } | 688 | 1.24M | current->tile_rows_log2 = cbs_av1_tile_log2(1, i); | 689 | 1.24M | current->tile_rows = i; | 690 | 1.24M | } | 691 | | | 692 | 1.77M | if (current->tile_cols_log2 > 0 || | 693 | 1.50M | current->tile_rows_log2 > 0) { | 694 | 437k | fb(current->tile_cols_log2 + current->tile_rows_log2, | 695 | 437k | context_update_tile_id); | 696 | 429k | fb(2, tile_size_bytes_minus1); | 697 | 1.33M | } else { | 698 | 1.33M | infer(context_update_tile_id, 0); | 699 | 1.33M | } | 700 | | | 701 | 1.75M | priv->tile_cols = current->tile_cols; | 702 | 1.75M | priv->tile_rows = current->tile_rows; | 703 | | | 704 | 1.75M | return 0; | 705 | 1.77M | } |
cbs_av1.c:cbs_av1_write_tile_info Line | Count | Source | 591 | 300k | { | 592 | 300k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 593 | 300k | const AV1RawSequenceHeader *seq = priv->sequence_header; | 594 | 300k | int mi_cols, mi_rows, sb_cols, sb_rows, sb_shift, sb_size; | 595 | 300k | int max_tile_width_sb, max_tile_height_sb, max_tile_area_sb; | 596 | 300k | int min_log2_tile_cols, max_log2_tile_cols, max_log2_tile_rows; | 597 | 300k | int min_log2_tiles, min_log2_tile_rows; | 598 | 300k | int err; | 599 | | | 600 | 300k | mi_cols = 2 * ((priv->frame_width + 7) >> 3); | 601 | 300k | mi_rows = 2 * ((priv->frame_height + 7) >> 3); | 602 | | | 603 | 300k | sb_cols = seq->use_128x128_superblock ? ((mi_cols + 31) >> 5) | 604 | 300k | : ((mi_cols + 15) >> 4); | 605 | 300k | sb_rows = seq->use_128x128_superblock ? ((mi_rows + 31) >> 5) | 606 | 300k | : ((mi_rows + 15) >> 4); | 607 | | | 608 | 300k | sb_shift = seq->use_128x128_superblock ? 5 : 4; | 609 | 300k | sb_size = sb_shift + 2; | 610 | | | 611 | 300k | max_tile_width_sb = AV1_MAX_TILE_WIDTH >> sb_size; | 612 | 300k | max_tile_area_sb = AV1_MAX_TILE_AREA >> (2 * sb_size); | 613 | | | 614 | 300k | min_log2_tile_cols = cbs_av1_tile_log2(max_tile_width_sb, sb_cols); | 615 | 300k | max_log2_tile_cols = cbs_av1_tile_log2(1, FFMIN(sb_cols, AV1_MAX_TILE_COLS)); | 616 | 300k | max_log2_tile_rows = cbs_av1_tile_log2(1, FFMIN(sb_rows, AV1_MAX_TILE_ROWS)); | 617 | 300k | min_log2_tiles = FFMAX(min_log2_tile_cols, | 618 | 300k | cbs_av1_tile_log2(max_tile_area_sb, sb_rows * sb_cols)); | 619 | | | 620 | 300k | flag(uniform_tile_spacing_flag); | 621 | | | 622 | 300k | if (current->uniform_tile_spacing_flag) { | 623 | 79.8k | int tile_width_sb, tile_height_sb; | 624 | | | 625 | 79.8k | increment(tile_cols_log2, min_log2_tile_cols, max_log2_tile_cols); | 626 | | | 627 | 79.4k | tile_width_sb = (sb_cols + (1 << current->tile_cols_log2) - 1) >> | 628 | 79.4k | current->tile_cols_log2; | 629 | | | 630 | 255k | for (int off = 0, j = 0; off < sb_cols; off += tile_width_sb) | 631 | 176k | current->tile_start_col_sb[j++] = off; | 632 | | | 633 | 79.4k | current->tile_cols = (sb_cols + tile_width_sb - 1) / tile_width_sb; | 634 | | | 635 | 79.4k | min_log2_tile_rows = FFMAX(min_log2_tiles - current->tile_cols_log2, 0); | 636 | | | 637 | 79.4k | increment(tile_rows_log2, min_log2_tile_rows, max_log2_tile_rows); | 638 | | | 639 | 79.0k | tile_height_sb = (sb_rows + (1 << current->tile_rows_log2) - 1) >> | 640 | 79.0k | current->tile_rows_log2; | 641 | | | 642 | 241k | for (int off = 0, j = 0; off < sb_rows; off += tile_height_sb) | 643 | 162k | current->tile_start_row_sb[j++] = off; | 644 | | | 645 | 79.0k | current->tile_rows = (sb_rows + tile_height_sb - 1) / tile_height_sb; | 646 | | | 647 | 79.0k | int i; | 648 | 158k | for (i = 0; i < current->tile_cols - 1; i++) | 649 | 79.7k | infer(width_in_sbs_minus_1[i], tile_width_sb - 1); | 650 | 78.6k | infer(width_in_sbs_minus_1[i], | 651 | 78.6k | sb_cols - (current->tile_cols - 1) * tile_width_sb - 1); | 652 | 156k | for (i = 0; i < current->tile_rows - 1; i++) | 653 | 78.7k | infer(height_in_sbs_minus_1[i], tile_height_sb - 1); | 654 | 77.7k | infer(height_in_sbs_minus_1[i], | 655 | 77.7k | sb_rows - (current->tile_rows - 1) * tile_height_sb - 1); | 656 | | | 657 | 220k | } else { | 658 | 220k | int widest_tile_sb, start_sb, size_sb, max_width, max_height, i; | 659 | | | 660 | 220k | widest_tile_sb = 0; | 661 | | | 662 | 220k | start_sb = 0; | 663 | 483k | for (i = 0; start_sb < sb_cols && i < AV1_MAX_TILE_COLS; i++) { | 664 | 262k | current->tile_start_col_sb[i] = start_sb; | 665 | 262k | max_width = FFMIN(sb_cols - start_sb, max_tile_width_sb); | 666 | 262k | ns(max_width, width_in_sbs_minus_1[i], 1, i); | 667 | 262k | size_sb = current->width_in_sbs_minus_1[i] + 1; | 668 | 262k | widest_tile_sb = FFMAX(size_sb, widest_tile_sb); | 669 | 262k | start_sb += size_sb; | 670 | 262k | } | 671 | 220k | current->tile_cols_log2 = cbs_av1_tile_log2(1, i); | 672 | 220k | current->tile_cols = i; | 673 | | | 674 | 220k | if (min_log2_tiles > 0) | 675 | 2.30k | max_tile_area_sb = (sb_rows * sb_cols) >> (min_log2_tiles + 1); | 676 | 218k | else | 677 | 218k | max_tile_area_sb = sb_rows * sb_cols; | 678 | 220k | max_tile_height_sb = FFMAX(max_tile_area_sb / widest_tile_sb, 1); | 679 | | | 680 | 220k | start_sb = 0; | 681 | 481k | for (i = 0; start_sb < sb_rows && i < AV1_MAX_TILE_ROWS; i++) { | 682 | 262k | current->tile_start_row_sb[i] = start_sb; | 683 | 262k | max_height = FFMIN(sb_rows - start_sb, max_tile_height_sb); | 684 | 262k | ns(max_height, height_in_sbs_minus_1[i], 1, i); | 685 | 261k | size_sb = current->height_in_sbs_minus_1[i] + 1; | 686 | 261k | start_sb += size_sb; | 687 | 261k | } | 688 | 219k | current->tile_rows_log2 = cbs_av1_tile_log2(1, i); | 689 | 219k | current->tile_rows = i; | 690 | 219k | } | 691 | | | 692 | 297k | if (current->tile_cols_log2 > 0 || | 693 | 286k | current->tile_rows_log2 > 0) { | 694 | 22.9k | fb(current->tile_cols_log2 + current->tile_rows_log2, | 695 | 22.9k | context_update_tile_id); | 696 | 22.5k | fb(2, tile_size_bytes_minus1); | 697 | 274k | } else { | 698 | 274k | infer(context_update_tile_id, 0); | 699 | 274k | } | 700 | | | 701 | 296k | priv->tile_cols = current->tile_cols; | 702 | 296k | priv->tile_rows = current->tile_rows; | 703 | | | 704 | 296k | return 0; | 705 | 297k | } |
|
706 | | |
707 | | static int FUNC(quantization_params)(CodedBitstreamContext *ctx, RWContext *rw, |
708 | | AV1RawFrameHeader *current) |
709 | 2.05M | { |
710 | 2.05M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
711 | 2.05M | const AV1RawSequenceHeader *seq = priv->sequence_header; |
712 | 2.05M | int err; |
713 | | |
714 | 2.05M | fb(8, base_q_idx); |
715 | | |
716 | 2.01M | delta_q(delta_q_y_dc); |
717 | | |
718 | 1.99M | if (priv->num_planes > 1) { |
719 | 1.52M | if (seq->color_config.separate_uv_delta_q) |
720 | 1.52M | flag(diff_uv_delta); |
721 | 912k | else |
722 | 912k | infer(diff_uv_delta, 0); |
723 | | |
724 | 1.52M | delta_q(delta_q_u_dc); |
725 | 1.50M | delta_q(delta_q_u_ac); |
726 | | |
727 | 1.48M | if (current->diff_uv_delta) { |
728 | 188k | delta_q(delta_q_v_dc); |
729 | 179k | delta_q(delta_q_v_ac); |
730 | 1.29M | } else { |
731 | 1.29M | infer(delta_q_v_dc, current->delta_q_u_dc); |
732 | 1.29M | infer(delta_q_v_ac, current->delta_q_u_ac); |
733 | 210k | } |
734 | 1.48M | } else { |
735 | 462k | infer(delta_q_u_dc, 0); |
736 | 462k | infer(delta_q_u_ac, 0); |
737 | 461k | infer(delta_q_v_dc, 0); |
738 | 461k | infer(delta_q_v_ac, 0); |
739 | 65.5k | } |
740 | | |
741 | 1.92M | flag(using_qmatrix); |
742 | 1.91M | if (current->using_qmatrix) { |
743 | 742k | fb(4, qm_y); |
744 | 733k | fb(4, qm_u); |
745 | 721k | if (seq->color_config.separate_uv_delta_q) |
746 | 173k | fb(4, qm_v); |
747 | 548k | else |
748 | 548k | infer(qm_v, current->qm_u); |
749 | 721k | } |
750 | | |
751 | 1.88M | return 0; |
752 | 1.91M | } cbs_av1.c:cbs_av1_read_quantization_params Line | Count | Source | 709 | 1.75M | { | 710 | 1.75M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 711 | 1.75M | const AV1RawSequenceHeader *seq = priv->sequence_header; | 712 | 1.75M | int err; | 713 | | | 714 | 1.75M | fb(8, base_q_idx); | 715 | | | 716 | 1.72M | delta_q(delta_q_y_dc); | 717 | | | 718 | 1.69M | if (priv->num_planes > 1) { | 719 | 1.29M | if (seq->color_config.separate_uv_delta_q) | 720 | 1.29M | flag(diff_uv_delta); | 721 | 768k | else | 722 | 768k | infer(diff_uv_delta, 0); | 723 | | | 724 | 1.29M | delta_q(delta_q_u_dc); | 725 | 1.27M | delta_q(delta_q_u_ac); | 726 | | | 727 | 1.25M | if (current->diff_uv_delta) { | 728 | 169k | delta_q(delta_q_v_dc); | 729 | 160k | delta_q(delta_q_v_ac); | 730 | 1.08M | } else { | 731 | 1.08M | infer(delta_q_v_dc, current->delta_q_u_dc); | 732 | 1.08M | infer(delta_q_v_ac, current->delta_q_u_ac); | 733 | 1.08M | } | 734 | 1.25M | } else { | 735 | 395k | infer(delta_q_u_dc, 0); | 736 | 395k | infer(delta_q_u_ac, 0); | 737 | 395k | infer(delta_q_v_dc, 0); | 738 | 395k | infer(delta_q_v_ac, 0); | 739 | 395k | } | 740 | | | 741 | 1.63M | flag(using_qmatrix); | 742 | 1.61M | if (current->using_qmatrix) { | 743 | 636k | fb(4, qm_y); | 744 | 627k | fb(4, qm_u); | 745 | 615k | if (seq->color_config.separate_uv_delta_q) | 746 | 158k | fb(4, qm_v); | 747 | 456k | else | 748 | 456k | infer(qm_v, current->qm_u); | 749 | 615k | } | 750 | | | 751 | 1.59M | return 0; | 752 | 1.61M | } |
cbs_av1.c:cbs_av1_write_quantization_params Line | Count | Source | 709 | 296k | { | 710 | 296k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 711 | 296k | const AV1RawSequenceHeader *seq = priv->sequence_header; | 712 | 296k | int err; | 713 | | | 714 | 296k | fb(8, base_q_idx); | 715 | | | 716 | 296k | delta_q(delta_q_y_dc); | 717 | | | 718 | 296k | if (priv->num_planes > 1) { | 719 | 229k | if (seq->color_config.separate_uv_delta_q) | 720 | 229k | flag(diff_uv_delta); | 721 | 144k | else | 722 | 144k | infer(diff_uv_delta, 0); | 723 | | | 724 | 229k | delta_q(delta_q_u_dc); | 725 | 229k | delta_q(delta_q_u_ac); | 726 | | | 727 | 229k | if (current->diff_uv_delta) { | 728 | 19.2k | delta_q(delta_q_v_dc); | 729 | 19.2k | delta_q(delta_q_v_ac); | 730 | 210k | } else { | 731 | 210k | infer(delta_q_v_dc, current->delta_q_u_dc); | 732 | 210k | infer(delta_q_v_ac, current->delta_q_u_ac); | 733 | 210k | } | 734 | 229k | } else { | 735 | 66.8k | infer(delta_q_u_dc, 0); | 736 | 66.3k | infer(delta_q_u_ac, 0); | 737 | 65.9k | infer(delta_q_v_dc, 0); | 738 | 65.5k | infer(delta_q_v_ac, 0); | 739 | 65.5k | } | 740 | | | 741 | 294k | flag(using_qmatrix); | 742 | 294k | if (current->using_qmatrix) { | 743 | 106k | fb(4, qm_y); | 744 | 106k | fb(4, qm_u); | 745 | 106k | if (seq->color_config.separate_uv_delta_q) | 746 | 14.7k | fb(4, qm_v); | 747 | 91.4k | else | 748 | 91.4k | infer(qm_v, current->qm_u); | 749 | 106k | } | 750 | | | 751 | 293k | return 0; | 752 | 294k | } |
|
753 | | |
754 | | static int FUNC(segmentation_params)(CodedBitstreamContext *ctx, RWContext *rw, |
755 | | AV1RawFrameHeader *current) |
756 | 1.88M | { |
757 | 1.88M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
758 | 1.88M | static const uint8_t bits[AV1_SEG_LVL_MAX] = { 8, 6, 6, 6, 6, 3, 0, 0 }; |
759 | 1.88M | static const uint8_t sign[AV1_SEG_LVL_MAX] = { 1, 1, 1, 1, 1, 0, 0, 0 }; |
760 | 1.88M | static const uint8_t default_feature_enabled[AV1_SEG_LVL_MAX] = { 0 }; |
761 | 1.88M | static const int16_t default_feature_value[AV1_SEG_LVL_MAX] = { 0 }; |
762 | 1.88M | int i, j, err; |
763 | | |
764 | 1.88M | flag(segmentation_enabled); |
765 | | |
766 | 1.87M | if (current->segmentation_enabled) { |
767 | 525k | if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { |
768 | 189k | infer(segmentation_update_map, 1); |
769 | 189k | infer(segmentation_temporal_update, 0); |
770 | 189k | infer(segmentation_update_data, 1); |
771 | 335k | } else { |
772 | 335k | flag(segmentation_update_map); |
773 | 330k | if (current->segmentation_update_map) |
774 | 330k | flag(segmentation_temporal_update); |
775 | 260k | else |
776 | 260k | infer(segmentation_temporal_update, 0); |
777 | 327k | flag(segmentation_update_data); |
778 | 327k | } |
779 | | |
780 | 4.11M | for (i = 0; i < AV1_MAX_SEGMENTS; i++) { |
781 | 3.69M | const uint8_t *ref_feature_enabled; |
782 | 3.69M | const int16_t *ref_feature_value; |
783 | | |
784 | 3.69M | if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { |
785 | 1.20M | ref_feature_enabled = default_feature_enabled; |
786 | 1.20M | ref_feature_value = default_feature_value; |
787 | 2.49M | } else { |
788 | 2.49M | ref_feature_enabled = |
789 | 2.49M | priv->ref[current->ref_frame_idx[current->primary_ref_frame]].feature_enabled[i]; |
790 | 2.49M | ref_feature_value = |
791 | 2.49M | priv->ref[current->ref_frame_idx[current->primary_ref_frame]].feature_value[i]; |
792 | 2.49M | } |
793 | | |
794 | 32.7M | for (j = 0; j < AV1_SEG_LVL_MAX; j++) { |
795 | 29.1M | if (current->segmentation_update_data) { |
796 | 10.4M | flags(feature_enabled[i][j], 2, i, j); |
797 | | |
798 | 10.4M | if (current->feature_enabled[i][j] && bits[j] > 0) { |
799 | 2.00M | if (sign[j]) |
800 | 2.00M | sus(1 + bits[j], feature_value[i][j], 2, i, j); |
801 | 308k | else |
802 | 2.00M | fbs(bits[j], feature_value[i][j], 2, i, j); |
803 | 8.44M | } else { |
804 | 8.44M | infer(feature_value[i][j], 0); |
805 | 8.44M | } |
806 | 18.6M | } else { |
807 | 18.6M | infer(feature_enabled[i][j], ref_feature_enabled[j]); |
808 | 18.6M | infer(feature_value[i][j], ref_feature_value[j]); |
809 | 3.29M | } |
810 | 29.1M | } |
811 | 3.69M | } |
812 | 1.34M | } else { |
813 | 12.1M | for (i = 0; i < AV1_MAX_SEGMENTS; i++) { |
814 | 97.1M | for (j = 0; j < AV1_SEG_LVL_MAX; j++) { |
815 | 86.3M | infer(feature_enabled[i][j], 0); |
816 | 86.3M | infer(feature_value[i][j], 0); |
817 | 14.4M | } |
818 | 10.7M | } |
819 | 1.34M | } |
820 | | |
821 | 1.77M | return 0; |
822 | 1.87M | } cbs_av1.c:cbs_av1_read_segmentation_params Line | Count | Source | 756 | 1.59M | { | 757 | 1.59M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 758 | 1.59M | static const uint8_t bits[AV1_SEG_LVL_MAX] = { 8, 6, 6, 6, 6, 3, 0, 0 }; | 759 | 1.59M | static const uint8_t sign[AV1_SEG_LVL_MAX] = { 1, 1, 1, 1, 1, 0, 0, 0 }; | 760 | 1.59M | static const uint8_t default_feature_enabled[AV1_SEG_LVL_MAX] = { 0 }; | 761 | 1.59M | static const int16_t default_feature_value[AV1_SEG_LVL_MAX] = { 0 }; | 762 | 1.59M | int i, j, err; | 763 | | | 764 | 1.59M | flag(segmentation_enabled); | 765 | | | 766 | 1.57M | if (current->segmentation_enabled) { | 767 | 457k | if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { | 768 | 174k | infer(segmentation_update_map, 1); | 769 | 174k | infer(segmentation_temporal_update, 0); | 770 | 174k | infer(segmentation_update_data, 1); | 771 | 282k | } else { | 772 | 282k | flag(segmentation_update_map); | 773 | 277k | if (current->segmentation_update_map) | 774 | 277k | flag(segmentation_temporal_update); | 775 | 212k | else | 776 | 212k | infer(segmentation_temporal_update, 0); | 777 | 274k | flag(segmentation_update_data); | 778 | 274k | } | 779 | | | 780 | 3.51M | for (i = 0; i < AV1_MAX_SEGMENTS; i++) { | 781 | 3.15M | const uint8_t *ref_feature_enabled; | 782 | 3.15M | const int16_t *ref_feature_value; | 783 | | | 784 | 3.15M | if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { | 785 | 1.08M | ref_feature_enabled = default_feature_enabled; | 786 | 1.08M | ref_feature_value = default_feature_value; | 787 | 2.07M | } else { | 788 | 2.07M | ref_feature_enabled = | 789 | 2.07M | priv->ref[current->ref_frame_idx[current->primary_ref_frame]].feature_enabled[i]; | 790 | 2.07M | ref_feature_value = | 791 | 2.07M | priv->ref[current->ref_frame_idx[current->primary_ref_frame]].feature_value[i]; | 792 | 2.07M | } | 793 | | | 794 | 27.9M | for (j = 0; j < AV1_SEG_LVL_MAX; j++) { | 795 | 24.8M | if (current->segmentation_update_data) { | 796 | 9.49M | flags(feature_enabled[i][j], 2, i, j); | 797 | | | 798 | 9.45M | if (current->feature_enabled[i][j] && bits[j] > 0) { | 799 | 1.85M | if (sign[j]) | 800 | 1.85M | sus(1 + bits[j], feature_value[i][j], 2, i, j); | 801 | 289k | else | 802 | 1.85M | fbs(bits[j], feature_value[i][j], 2, i, j); | 803 | 7.60M | } else { | 804 | 7.60M | infer(feature_value[i][j], 0); | 805 | 7.60M | } | 806 | 15.3M | } else { | 807 | 15.3M | infer(feature_enabled[i][j], ref_feature_enabled[j]); | 808 | 15.3M | infer(feature_value[i][j], ref_feature_value[j]); | 809 | 15.3M | } | 810 | 24.8M | } | 811 | 3.15M | } | 812 | 1.12M | } else { | 813 | 10.1M | for (i = 0; i < AV1_MAX_SEGMENTS; i++) { | 814 | 80.8M | for (j = 0; j < AV1_SEG_LVL_MAX; j++) { | 815 | 71.8M | infer(feature_enabled[i][j], 0); | 816 | 71.8M | infer(feature_value[i][j], 0); | 817 | 71.8M | } | 818 | 8.98M | } | 819 | 1.12M | } | 820 | | | 821 | 1.48M | return 0; | 822 | 1.57M | } |
cbs_av1.c:cbs_av1_write_segmentation_params Line | Count | Source | 756 | 293k | { | 757 | 293k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 758 | 293k | static const uint8_t bits[AV1_SEG_LVL_MAX] = { 8, 6, 6, 6, 6, 3, 0, 0 }; | 759 | 293k | static const uint8_t sign[AV1_SEG_LVL_MAX] = { 1, 1, 1, 1, 1, 0, 0, 0 }; | 760 | 293k | static const uint8_t default_feature_enabled[AV1_SEG_LVL_MAX] = { 0 }; | 761 | 293k | static const int16_t default_feature_value[AV1_SEG_LVL_MAX] = { 0 }; | 762 | 293k | int i, j, err; | 763 | | | 764 | 293k | flag(segmentation_enabled); | 765 | | | 766 | 293k | if (current->segmentation_enabled) { | 767 | 67.8k | if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { | 768 | 14.6k | infer(segmentation_update_map, 1); | 769 | 14.6k | infer(segmentation_temporal_update, 0); | 770 | 14.6k | infer(segmentation_update_data, 1); | 771 | 53.1k | } else { | 772 | 53.1k | flag(segmentation_update_map); | 773 | 53.1k | if (current->segmentation_update_map) | 774 | 53.1k | flag(segmentation_temporal_update); | 775 | 48.4k | else | 776 | 48.4k | infer(segmentation_temporal_update, 0); | 777 | 53.1k | flag(segmentation_update_data); | 778 | 53.1k | } | 779 | | | 780 | 604k | for (i = 0; i < AV1_MAX_SEGMENTS; i++) { | 781 | 537k | const uint8_t *ref_feature_enabled; | 782 | 537k | const int16_t *ref_feature_value; | 783 | | | 784 | 537k | if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { | 785 | 117k | ref_feature_enabled = default_feature_enabled; | 786 | 117k | ref_feature_value = default_feature_value; | 787 | 419k | } else { | 788 | 419k | ref_feature_enabled = | 789 | 419k | priv->ref[current->ref_frame_idx[current->primary_ref_frame]].feature_enabled[i]; | 790 | 419k | ref_feature_value = | 791 | 419k | priv->ref[current->ref_frame_idx[current->primary_ref_frame]].feature_value[i]; | 792 | 419k | } | 793 | | | 794 | 4.82M | for (j = 0; j < AV1_SEG_LVL_MAX; j++) { | 795 | 4.29M | if (current->segmentation_update_data) { | 796 | 991k | flags(feature_enabled[i][j], 2, i, j); | 797 | | | 798 | 991k | if (current->feature_enabled[i][j] && bits[j] > 0) { | 799 | 151k | if (sign[j]) | 800 | 151k | sus(1 + bits[j], feature_value[i][j], 2, i, j); | 801 | 19.2k | else | 802 | 151k | fbs(bits[j], feature_value[i][j], 2, i, j); | 803 | 840k | } else { | 804 | 840k | infer(feature_value[i][j], 0); | 805 | 840k | } | 806 | 3.30M | } else { | 807 | 3.30M | infer(feature_enabled[i][j], ref_feature_enabled[j]); | 808 | 3.29M | infer(feature_value[i][j], ref_feature_value[j]); | 809 | 3.29M | } | 810 | 4.29M | } | 811 | 537k | } | 812 | 226k | } else { | 813 | 2.03M | for (i = 0; i < AV1_MAX_SEGMENTS; i++) { | 814 | 16.2M | for (j = 0; j < AV1_SEG_LVL_MAX; j++) { | 815 | 14.4M | infer(feature_enabled[i][j], 0); | 816 | 14.4M | infer(feature_value[i][j], 0); | 817 | 14.4M | } | 818 | 1.80M | } | 819 | 226k | } | 820 | | | 821 | 293k | return 0; | 822 | 293k | } |
|
823 | | |
824 | | static int FUNC(delta_q_params)(CodedBitstreamContext *ctx, RWContext *rw, |
825 | | AV1RawFrameHeader *current) |
826 | 1.77M | { |
827 | 1.77M | int err; |
828 | | |
829 | 1.77M | if (current->base_q_idx > 0) |
830 | 1.77M | flag(delta_q_present); |
831 | 475k | else |
832 | 475k | infer(delta_q_present, 0); |
833 | | |
834 | 1.76M | if (current->delta_q_present) |
835 | 266k | fb(2, delta_q_res); |
836 | | |
837 | 1.76M | return 0; |
838 | 1.76M | } cbs_av1.c:cbs_av1_read_delta_q_params Line | Count | Source | 826 | 1.48M | { | 827 | 1.48M | int err; | 828 | | | 829 | 1.48M | if (current->base_q_idx > 0) | 830 | 1.48M | flag(delta_q_present); | 831 | 355k | else | 832 | 355k | infer(delta_q_present, 0); | 833 | | | 834 | 1.47M | if (current->delta_q_present) | 835 | 248k | fb(2, delta_q_res); | 836 | | | 837 | 1.46M | return 0; | 838 | 1.47M | } |
cbs_av1.c:cbs_av1_write_delta_q_params Line | Count | Source | 826 | 293k | { | 827 | 293k | int err; | 828 | | | 829 | 293k | if (current->base_q_idx > 0) | 830 | 293k | flag(delta_q_present); | 831 | 120k | else | 832 | 120k | infer(delta_q_present, 0); | 833 | | | 834 | 293k | if (current->delta_q_present) | 835 | 17.8k | fb(2, delta_q_res); | 836 | | | 837 | 293k | return 0; | 838 | 293k | } |
|
839 | | |
840 | | static int FUNC(delta_lf_params)(CodedBitstreamContext *ctx, RWContext *rw, |
841 | | AV1RawFrameHeader *current) |
842 | 1.76M | { |
843 | 1.76M | int err; |
844 | | |
845 | 1.76M | if (current->delta_q_present) { |
846 | 261k | if (!current->allow_intrabc) |
847 | 261k | flag(delta_lf_present); |
848 | 23.5k | else |
849 | 23.5k | infer(delta_lf_present, 0); |
850 | 255k | if (current->delta_lf_present) { |
851 | 83.8k | fb(2, delta_lf_res); |
852 | 79.4k | flag(delta_lf_multi); |
853 | 171k | } else { |
854 | 171k | infer(delta_lf_res, 0); |
855 | 171k | infer(delta_lf_multi, 0); |
856 | 12.4k | } |
857 | 1.50M | } else { |
858 | 1.50M | infer(delta_lf_present, 0); |
859 | 1.50M | infer(delta_lf_res, 0); |
860 | 1.50M | infer(delta_lf_multi, 0); |
861 | 275k | } |
862 | | |
863 | 1.74M | return 0; |
864 | 1.76M | } cbs_av1.c:cbs_av1_read_delta_lf_params Line | Count | Source | 842 | 1.46M | { | 843 | 1.46M | int err; | 844 | | | 845 | 1.46M | if (current->delta_q_present) { | 846 | 243k | if (!current->allow_intrabc) | 847 | 243k | flag(delta_lf_present); | 848 | 17.2k | else | 849 | 17.2k | infer(delta_lf_present, 0); | 850 | 237k | if (current->delta_lf_present) { | 851 | 78.4k | fb(2, delta_lf_res); | 852 | 74.0k | flag(delta_lf_multi); | 853 | 158k | } else { | 854 | 158k | infer(delta_lf_res, 0); | 855 | 158k | infer(delta_lf_multi, 0); | 856 | 158k | } | 857 | 1.22M | } else { | 858 | 1.22M | infer(delta_lf_present, 0); | 859 | 1.22M | infer(delta_lf_res, 0); | 860 | 1.22M | infer(delta_lf_multi, 0); | 861 | 1.22M | } | 862 | | | 863 | 1.45M | return 0; | 864 | 1.46M | } |
cbs_av1.c:cbs_av1_write_delta_lf_params Line | Count | Source | 842 | 293k | { | 843 | 293k | int err; | 844 | | | 845 | 293k | if (current->delta_q_present) { | 846 | 17.8k | if (!current->allow_intrabc) | 847 | 17.8k | flag(delta_lf_present); | 848 | 6.36k | else | 849 | 6.36k | infer(delta_lf_present, 0); | 850 | 17.8k | if (current->delta_lf_present) { | 851 | 5.40k | fb(2, delta_lf_res); | 852 | 5.40k | flag(delta_lf_multi); | 853 | 12.4k | } else { | 854 | 12.4k | infer(delta_lf_res, 0); | 855 | 12.4k | infer(delta_lf_multi, 0); | 856 | 12.4k | } | 857 | 275k | } else { | 858 | 275k | infer(delta_lf_present, 0); | 859 | 275k | infer(delta_lf_res, 0); | 860 | 275k | infer(delta_lf_multi, 0); | 861 | 275k | } | 862 | | | 863 | 293k | return 0; | 864 | 293k | } |
|
865 | | |
866 | | static int FUNC(loop_filter_params)(CodedBitstreamContext *ctx, RWContext *rw, |
867 | | AV1RawFrameHeader *current) |
868 | 1.74M | { |
869 | 1.74M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
870 | 1.74M | static const int8_t default_loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME] = |
871 | 1.74M | { 1, 0, 0, 0, -1, 0, -1, -1 }; |
872 | 1.74M | static const int8_t default_loop_filter_mode_deltas[2] = { 0, 0 }; |
873 | 1.74M | int i, err; |
874 | | |
875 | 1.74M | if (priv->coded_lossless || current->allow_intrabc) { |
876 | 482k | infer(loop_filter_level[0], 0); |
877 | 482k | infer(loop_filter_level[1], 0); |
878 | 482k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_INTRA], 1); |
879 | 482k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST], 0); |
880 | 482k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST2], 0); |
881 | 482k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST3], 0); |
882 | 482k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_BWDREF], 0); |
883 | 482k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_GOLDEN], -1); |
884 | 482k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF], -1); |
885 | 482k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF2], -1); |
886 | 1.44M | for (i = 0; i < 2; i++) |
887 | 965k | infer(loop_filter_mode_deltas[i], 0); |
888 | 123k | return 0; |
889 | 123k | } |
890 | | |
891 | 1.26M | fb(6, loop_filter_level[0]); |
892 | 1.23M | fb(6, loop_filter_level[1]); |
893 | | |
894 | 1.21M | if (priv->num_planes > 1) { |
895 | 952k | if (current->loop_filter_level[0] || |
896 | 792k | current->loop_filter_level[1]) { |
897 | 792k | fb(6, loop_filter_level[2]); |
898 | 775k | fb(6, loop_filter_level[3]); |
899 | 775k | } |
900 | 952k | } |
901 | | |
902 | 1.18M | fb(3, loop_filter_sharpness); |
903 | | |
904 | 1.17M | flag(loop_filter_delta_enabled); |
905 | 1.16M | if (current->loop_filter_delta_enabled) { |
906 | 497k | const int8_t *ref_loop_filter_ref_deltas, *ref_loop_filter_mode_deltas; |
907 | | |
908 | 497k | if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { |
909 | 199k | ref_loop_filter_ref_deltas = default_loop_filter_ref_deltas; |
910 | 199k | ref_loop_filter_mode_deltas = default_loop_filter_mode_deltas; |
911 | 298k | } else { |
912 | 298k | ref_loop_filter_ref_deltas = |
913 | 298k | priv->ref[current->ref_frame_idx[current->primary_ref_frame]].loop_filter_ref_deltas; |
914 | 298k | ref_loop_filter_mode_deltas = |
915 | 298k | priv->ref[current->ref_frame_idx[current->primary_ref_frame]].loop_filter_mode_deltas; |
916 | 298k | } |
917 | | |
918 | 497k | flag(loop_filter_delta_update); |
919 | 4.30M | for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) { |
920 | 3.83M | if (current->loop_filter_delta_update) |
921 | 3.83M | flags(update_ref_delta[i], 1, i); |
922 | 1.09M | else |
923 | 1.09M | infer(update_ref_delta[i], 0); |
924 | 3.83M | if (current->update_ref_delta[i]) |
925 | 3.83M | sus(1 + 6, loop_filter_ref_deltas[i], 1, i); |
926 | 2.97M | else |
927 | 2.97M | infer(loop_filter_ref_deltas[i], ref_loop_filter_ref_deltas[i]); |
928 | 3.83M | } |
929 | 1.37M | for (i = 0; i < 2; i++) { |
930 | 920k | if (current->loop_filter_delta_update) |
931 | 920k | flags(update_mode_delta[i], 1, i); |
932 | 274k | else |
933 | 274k | infer(update_mode_delta[i], 0); |
934 | 916k | if (current->update_mode_delta[i]) |
935 | 916k | sus(1 + 6, loop_filter_mode_deltas[i], 1, i); |
936 | 434k | else |
937 | 434k | infer(loop_filter_mode_deltas[i], ref_loop_filter_mode_deltas[i]); |
938 | 916k | } |
939 | 666k | } else { |
940 | 5.99M | for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) |
941 | 5.32M | infer(loop_filter_ref_deltas[i], default_loop_filter_ref_deltas[i]); |
942 | 1.99M | for (i = 0; i < 2; i++) |
943 | 1.33M | infer(loop_filter_mode_deltas[i], default_loop_filter_mode_deltas[i]); |
944 | 86.9k | } |
945 | | |
946 | 1.11M | return 0; |
947 | 1.16M | } cbs_av1.c:cbs_av1_read_loop_filter_params Line | Count | Source | 868 | 1.45M | { | 869 | 1.45M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 870 | 1.45M | static const int8_t default_loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME] = | 871 | 1.45M | { 1, 0, 0, 0, -1, 0, -1, -1 }; | 872 | 1.45M | static const int8_t default_loop_filter_mode_deltas[2] = { 0, 0 }; | 873 | 1.45M | int i, err; | 874 | | | 875 | 1.45M | if (priv->coded_lossless || current->allow_intrabc) { | 876 | 359k | infer(loop_filter_level[0], 0); | 877 | 359k | infer(loop_filter_level[1], 0); | 878 | 359k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_INTRA], 1); | 879 | 359k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST], 0); | 880 | 359k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST2], 0); | 881 | 359k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST3], 0); | 882 | 359k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_BWDREF], 0); | 883 | 359k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_GOLDEN], -1); | 884 | 359k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF], -1); | 885 | 359k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF2], -1); | 886 | 1.07M | for (i = 0; i < 2; i++) | 887 | 718k | infer(loop_filter_mode_deltas[i], 0); | 888 | 359k | return 0; | 889 | 359k | } | 890 | | | 891 | 1.09M | fb(6, loop_filter_level[0]); | 892 | 1.06M | fb(6, loop_filter_level[1]); | 893 | | | 894 | 1.04M | if (priv->num_planes > 1) { | 895 | 814k | if (current->loop_filter_level[0] || | 896 | 685k | current->loop_filter_level[1]) { | 897 | 685k | fb(6, loop_filter_level[2]); | 898 | 668k | fb(6, loop_filter_level[3]); | 899 | 668k | } | 900 | 814k | } | 901 | | | 902 | 1.01M | fb(3, loop_filter_sharpness); | 903 | | | 904 | 1.00M | flag(loop_filter_delta_enabled); | 905 | 993k | if (current->loop_filter_delta_enabled) { | 906 | 414k | const int8_t *ref_loop_filter_ref_deltas, *ref_loop_filter_mode_deltas; | 907 | | | 908 | 414k | if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { | 909 | 169k | ref_loop_filter_ref_deltas = default_loop_filter_ref_deltas; | 910 | 169k | ref_loop_filter_mode_deltas = default_loop_filter_mode_deltas; | 911 | 245k | } else { | 912 | 245k | ref_loop_filter_ref_deltas = | 913 | 245k | priv->ref[current->ref_frame_idx[current->primary_ref_frame]].loop_filter_ref_deltas; | 914 | 245k | ref_loop_filter_mode_deltas = | 915 | 245k | priv->ref[current->ref_frame_idx[current->primary_ref_frame]].loop_filter_mode_deltas; | 916 | 245k | } | 917 | | | 918 | 414k | flag(loop_filter_delta_update); | 919 | 3.56M | for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) { | 920 | 3.18M | if (current->loop_filter_delta_update) | 921 | 3.18M | flags(update_ref_delta[i], 1, i); | 922 | 978k | else | 923 | 978k | infer(update_ref_delta[i], 0); | 924 | 3.17M | if (current->update_ref_delta[i]) | 925 | 3.17M | sus(1 + 6, loop_filter_ref_deltas[i], 1, i); | 926 | 2.46M | else | 927 | 2.46M | infer(loop_filter_ref_deltas[i], ref_loop_filter_ref_deltas[i]); | 928 | 3.17M | } | 929 | 1.12M | for (i = 0; i < 2; i++) { | 930 | 756k | if (current->loop_filter_delta_update) | 931 | 756k | flags(update_mode_delta[i], 1, i); | 932 | 244k | else | 933 | 244k | infer(update_mode_delta[i], 0); | 934 | 752k | if (current->update_mode_delta[i]) | 935 | 752k | sus(1 + 6, loop_filter_mode_deltas[i], 1, i); | 936 | 372k | else | 937 | 372k | infer(loop_filter_mode_deltas[i], ref_loop_filter_mode_deltas[i]); | 938 | 752k | } | 939 | 579k | } else { | 940 | 5.21M | for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) | 941 | 4.63M | infer(loop_filter_ref_deltas[i], default_loop_filter_ref_deltas[i]); | 942 | 1.73M | for (i = 0; i < 2; i++) | 943 | 1.15M | infer(loop_filter_mode_deltas[i], default_loop_filter_mode_deltas[i]); | 944 | 579k | } | 945 | | | 946 | 949k | return 0; | 947 | 993k | } |
cbs_av1.c:cbs_av1_write_loop_filter_params Line | Count | Source | 868 | 293k | { | 869 | 293k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 870 | 293k | static const int8_t default_loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME] = | 871 | 293k | { 1, 0, 0, 0, -1, 0, -1, -1 }; | 872 | 293k | static const int8_t default_loop_filter_mode_deltas[2] = { 0, 0 }; | 873 | 293k | int i, err; | 874 | | | 875 | 293k | if (priv->coded_lossless || current->allow_intrabc) { | 876 | 123k | infer(loop_filter_level[0], 0); | 877 | 123k | infer(loop_filter_level[1], 0); | 878 | 123k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_INTRA], 1); | 879 | 123k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST], 0); | 880 | 123k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST2], 0); | 881 | 123k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_LAST3], 0); | 882 | 123k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_BWDREF], 0); | 883 | 123k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_GOLDEN], -1); | 884 | 123k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF], -1); | 885 | 123k | infer(loop_filter_ref_deltas[AV1_REF_FRAME_ALTREF2], -1); | 886 | 370k | for (i = 0; i < 2; i++) | 887 | 247k | infer(loop_filter_mode_deltas[i], 0); | 888 | 123k | return 0; | 889 | 123k | } | 890 | | | 891 | 169k | fb(6, loop_filter_level[0]); | 892 | 169k | fb(6, loop_filter_level[1]); | 893 | | | 894 | 169k | if (priv->num_planes > 1) { | 895 | 137k | if (current->loop_filter_level[0] || | 896 | 106k | current->loop_filter_level[1]) { | 897 | 106k | fb(6, loop_filter_level[2]); | 898 | 106k | fb(6, loop_filter_level[3]); | 899 | 106k | } | 900 | 137k | } | 901 | | | 902 | 169k | fb(3, loop_filter_sharpness); | 903 | | | 904 | 169k | flag(loop_filter_delta_enabled); | 905 | 169k | if (current->loop_filter_delta_enabled) { | 906 | 82.5k | const int8_t *ref_loop_filter_ref_deltas, *ref_loop_filter_mode_deltas; | 907 | | | 908 | 82.5k | if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { | 909 | 29.5k | ref_loop_filter_ref_deltas = default_loop_filter_ref_deltas; | 910 | 29.5k | ref_loop_filter_mode_deltas = default_loop_filter_mode_deltas; | 911 | 53.0k | } else { | 912 | 53.0k | ref_loop_filter_ref_deltas = | 913 | 53.0k | priv->ref[current->ref_frame_idx[current->primary_ref_frame]].loop_filter_ref_deltas; | 914 | 53.0k | ref_loop_filter_mode_deltas = | 915 | 53.0k | priv->ref[current->ref_frame_idx[current->primary_ref_frame]].loop_filter_mode_deltas; | 916 | 53.0k | } | 917 | | | 918 | 82.5k | flag(loop_filter_delta_update); | 919 | 739k | for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) { | 920 | 657k | if (current->loop_filter_delta_update) | 921 | 657k | flags(update_ref_delta[i], 1, i); | 922 | 121k | else | 923 | 121k | infer(update_ref_delta[i], 0); | 924 | 657k | if (current->update_ref_delta[i]) | 925 | 657k | sus(1 + 6, loop_filter_ref_deltas[i], 1, i); | 926 | 513k | else | 927 | 513k | infer(loop_filter_ref_deltas[i], ref_loop_filter_ref_deltas[i]); | 928 | 657k | } | 929 | 245k | for (i = 0; i < 2; i++) { | 930 | 163k | if (current->loop_filter_delta_update) | 931 | 163k | flags(update_mode_delta[i], 1, i); | 932 | 30.2k | else | 933 | 30.2k | infer(update_mode_delta[i], 0); | 934 | 163k | if (current->update_mode_delta[i]) | 935 | 163k | sus(1 + 6, loop_filter_mode_deltas[i], 1, i); | 936 | 61.8k | else | 937 | 61.8k | infer(loop_filter_mode_deltas[i], ref_loop_filter_mode_deltas[i]); | 938 | 163k | } | 939 | 86.9k | } else { | 940 | 782k | for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) | 941 | 695k | infer(loop_filter_ref_deltas[i], default_loop_filter_ref_deltas[i]); | 942 | 260k | for (i = 0; i < 2; i++) | 943 | 173k | infer(loop_filter_mode_deltas[i], default_loop_filter_mode_deltas[i]); | 944 | 86.9k | } | 945 | | | 946 | 168k | return 0; | 947 | 169k | } |
|
948 | | |
949 | | static int FUNC(cdef_params)(CodedBitstreamContext *ctx, RWContext *rw, |
950 | | AV1RawFrameHeader *current) |
951 | 1.60M | { |
952 | 1.60M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
953 | 1.60M | const AV1RawSequenceHeader *seq = priv->sequence_header; |
954 | 1.60M | int i, err; |
955 | | |
956 | 1.60M | if (priv->coded_lossless || current->allow_intrabc || |
957 | 1.11M | !seq->enable_cdef) { |
958 | 1.10M | infer(cdef_damping_minus_3, 0); |
959 | 1.10M | infer(cdef_bits, 0); |
960 | 1.10M | infer(cdef_y_pri_strength[0], 0); |
961 | 1.10M | infer(cdef_y_sec_strength[0], 0); |
962 | 1.10M | infer(cdef_uv_pri_strength[0], 0); |
963 | 1.10M | infer(cdef_uv_sec_strength[0], 0); |
964 | | |
965 | 219k | return 0; |
966 | 219k | } |
967 | | |
968 | 494k | fb(2, cdef_damping_minus_3); |
969 | 489k | fb(2, cdef_bits); |
970 | | |
971 | 1.27M | for (i = 0; i < (1 << current->cdef_bits); i++) { |
972 | 829k | fbs(4, cdef_y_pri_strength[i], 1, i); |
973 | 812k | fbs(2, cdef_y_sec_strength[i], 1, i); |
974 | | |
975 | 804k | if (priv->num_planes > 1) { |
976 | 599k | fbs(4, cdef_uv_pri_strength[i], 1, i); |
977 | 591k | fbs(2, cdef_uv_sec_strength[i], 1, i); |
978 | 591k | } |
979 | 804k | } |
980 | | |
981 | 440k | return 0; |
982 | 482k | } cbs_av1.c:cbs_av1_read_cdef_params Line | Count | Source | 951 | 1.30M | { | 952 | 1.30M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 953 | 1.30M | const AV1RawSequenceHeader *seq = priv->sequence_header; | 954 | 1.30M | int i, err; | 955 | | | 956 | 1.30M | if (priv->coded_lossless || current->allow_intrabc || | 957 | 949k | !seq->enable_cdef) { | 958 | 884k | infer(cdef_damping_minus_3, 0); | 959 | 884k | infer(cdef_bits, 0); | 960 | 884k | infer(cdef_y_pri_strength[0], 0); | 961 | 884k | infer(cdef_y_sec_strength[0], 0); | 962 | 884k | infer(cdef_uv_pri_strength[0], 0); | 963 | 884k | infer(cdef_uv_sec_strength[0], 0); | 964 | | | 965 | 884k | return 0; | 966 | 884k | } | 967 | | | 968 | 424k | fb(2, cdef_damping_minus_3); | 969 | 419k | fb(2, cdef_bits); | 970 | | | 971 | 1.11M | for (i = 0; i < (1 << current->cdef_bits); i++) { | 972 | 745k | fbs(4, cdef_y_pri_strength[i], 1, i); | 973 | 727k | fbs(2, cdef_y_sec_strength[i], 1, i); | 974 | | | 975 | 719k | if (priv->num_planes > 1) { | 976 | 529k | fbs(4, cdef_uv_pri_strength[i], 1, i); | 977 | 520k | fbs(2, cdef_uv_sec_strength[i], 1, i); | 978 | 520k | } | 979 | 719k | } | 980 | | | 981 | 370k | return 0; | 982 | 412k | } |
cbs_av1.c:cbs_av1_write_cdef_params Line | Count | Source | 951 | 292k | { | 952 | 292k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 953 | 292k | const AV1RawSequenceHeader *seq = priv->sequence_header; | 954 | 292k | int i, err; | 955 | | | 956 | 292k | if (priv->coded_lossless || current->allow_intrabc || | 957 | 221k | !seq->enable_cdef) { | 958 | 221k | infer(cdef_damping_minus_3, 0); | 959 | 221k | infer(cdef_bits, 0); | 960 | 221k | infer(cdef_y_pri_strength[0], 0); | 961 | 220k | infer(cdef_y_sec_strength[0], 0); | 962 | 220k | infer(cdef_uv_pri_strength[0], 0); | 963 | 219k | infer(cdef_uv_sec_strength[0], 0); | 964 | | | 965 | 219k | return 0; | 966 | 219k | } | 967 | | | 968 | 70.2k | fb(2, cdef_damping_minus_3); | 969 | 70.2k | fb(2, cdef_bits); | 970 | | | 971 | 154k | for (i = 0; i < (1 << current->cdef_bits); i++) { | 972 | 84.2k | fbs(4, cdef_y_pri_strength[i], 1, i); | 973 | 84.2k | fbs(2, cdef_y_sec_strength[i], 1, i); | 974 | | | 975 | 84.2k | if (priv->num_planes > 1) { | 976 | 70.5k | fbs(4, cdef_uv_pri_strength[i], 1, i); | 977 | 70.5k | fbs(2, cdef_uv_sec_strength[i], 1, i); | 978 | 70.5k | } | 979 | 84.2k | } | 980 | | | 981 | 70.2k | return 0; | 982 | 70.2k | } |
|
983 | | |
984 | | static int FUNC(lr_params)(CodedBitstreamContext *ctx, RWContext *rw, |
985 | | AV1RawFrameHeader *current) |
986 | 1.54M | { |
987 | 1.54M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
988 | 1.54M | const AV1RawSequenceHeader *seq = priv->sequence_header; |
989 | 1.54M | int uses_lr, uses_chroma_lr; |
990 | 1.54M | int i, err; |
991 | | |
992 | 1.54M | if (priv->all_lossless || current->allow_intrabc || |
993 | 1.08M | !seq->enable_restoration) { |
994 | 941k | return 0; |
995 | 941k | } |
996 | | |
997 | 602k | uses_lr = uses_chroma_lr = 0; |
998 | 2.14M | for (i = 0; i < priv->num_planes; i++) { |
999 | 1.56M | fbs(2, lr_type[i], 1, i); |
1000 | | |
1001 | 1.54M | if (current->lr_type[i] != AV1_RESTORE_NONE) { |
1002 | 675k | uses_lr = 1; |
1003 | 675k | if (i > 0) |
1004 | 279k | uses_chroma_lr = 1; |
1005 | 675k | } |
1006 | 1.54M | } |
1007 | | |
1008 | 588k | if (uses_lr) { |
1009 | 464k | if (seq->use_128x128_superblock) |
1010 | 310k | increment(lr_unit_shift, 1, 2); |
1011 | 154k | else |
1012 | 154k | increment(lr_unit_shift, 0, 2); |
1013 | | |
1014 | 454k | if(seq->color_config.subsampling_x && |
1015 | 189k | seq->color_config.subsampling_y && uses_chroma_lr) { |
1016 | 57.5k | fb(1, lr_uv_shift); |
1017 | 397k | } else { |
1018 | 397k | infer(lr_uv_shift, 0); |
1019 | 397k | } |
1020 | 454k | } |
1021 | | |
1022 | 575k | return 0; |
1023 | 588k | } cbs_av1.c:cbs_av1_read_lr_params Line | Count | Source | 986 | 1.25M | { | 987 | 1.25M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 988 | 1.25M | const AV1RawSequenceHeader *seq = priv->sequence_header; | 989 | 1.25M | int uses_lr, uses_chroma_lr; | 990 | 1.25M | int i, err; | 991 | | | 992 | 1.25M | if (priv->all_lossless || current->allow_intrabc || | 993 | 913k | !seq->enable_restoration) { | 994 | 738k | return 0; | 995 | 738k | } | 996 | | | 997 | 516k | uses_lr = uses_chroma_lr = 0; | 998 | 1.82M | for (i = 0; i < priv->num_planes; i++) { | 999 | 1.32M | fbs(2, lr_type[i], 1, i); | 1000 | | | 1001 | 1.31M | if (current->lr_type[i] != AV1_RESTORE_NONE) { | 1002 | 588k | uses_lr = 1; | 1003 | 588k | if (i > 0) | 1004 | 253k | uses_chroma_lr = 1; | 1005 | 588k | } | 1006 | 1.31M | } | 1007 | | | 1008 | 502k | if (uses_lr) { | 1009 | 394k | if (seq->use_128x128_superblock) | 1010 | 257k | increment(lr_unit_shift, 1, 2); | 1011 | 137k | else | 1012 | 137k | increment(lr_unit_shift, 0, 2); | 1013 | | | 1014 | 385k | if(seq->color_config.subsampling_x && | 1015 | 171k | seq->color_config.subsampling_y && uses_chroma_lr) { | 1016 | 50.3k | fb(1, lr_uv_shift); | 1017 | 335k | } else { | 1018 | 335k | infer(lr_uv_shift, 0); | 1019 | 335k | } | 1020 | 385k | } | 1021 | | | 1022 | 490k | return 0; | 1023 | 502k | } |
cbs_av1.c:cbs_av1_write_lr_params Line | Count | Source | 986 | 289k | { | 987 | 289k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 988 | 289k | const AV1RawSequenceHeader *seq = priv->sequence_header; | 989 | 289k | int uses_lr, uses_chroma_lr; | 990 | 289k | int i, err; | 991 | | | 992 | 289k | if (priv->all_lossless || current->allow_intrabc || | 993 | 203k | !seq->enable_restoration) { | 994 | 203k | return 0; | 995 | 203k | } | 996 | | | 997 | 86.5k | uses_lr = uses_chroma_lr = 0; | 998 | 322k | for (i = 0; i < priv->num_planes; i++) { | 999 | 236k | fbs(2, lr_type[i], 1, i); | 1000 | | | 1001 | 236k | if (current->lr_type[i] != AV1_RESTORE_NONE) { | 1002 | 87.5k | uses_lr = 1; | 1003 | 87.5k | if (i > 0) | 1004 | 25.8k | uses_chroma_lr = 1; | 1005 | 87.5k | } | 1006 | 236k | } | 1007 | | | 1008 | 86.5k | if (uses_lr) { | 1009 | 69.7k | if (seq->use_128x128_superblock) | 1010 | 53.1k | increment(lr_unit_shift, 1, 2); | 1011 | 16.5k | else | 1012 | 16.5k | increment(lr_unit_shift, 0, 2); | 1013 | | | 1014 | 69.2k | if(seq->color_config.subsampling_x && | 1015 | 17.9k | seq->color_config.subsampling_y && uses_chroma_lr) { | 1016 | 7.16k | fb(1, lr_uv_shift); | 1017 | 62.1k | } else { | 1018 | 62.1k | infer(lr_uv_shift, 0); | 1019 | 62.1k | } | 1020 | 69.2k | } | 1021 | | | 1022 | 85.7k | return 0; | 1023 | 86.5k | } |
|
1024 | | |
1025 | | static int FUNC(read_tx_mode)(CodedBitstreamContext *ctx, RWContext *rw, |
1026 | | AV1RawFrameHeader *current) |
1027 | 1.51M | { |
1028 | 1.51M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
1029 | 1.51M | int err; |
1030 | | |
1031 | 1.51M | if (priv->coded_lossless) |
1032 | 387k | infer(tx_mode, AV1_ONLY_4X4); |
1033 | 1.12M | else |
1034 | 1.12M | increment(tx_mode, AV1_TX_MODE_LARGEST, AV1_TX_MODE_SELECT); |
1035 | | |
1036 | 1.50M | return 0; |
1037 | 1.51M | } cbs_av1.c:cbs_av1_read_read_tx_mode Line | Count | Source | 1027 | 1.22M | { | 1028 | 1.22M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1029 | 1.22M | int err; | 1030 | | | 1031 | 1.22M | if (priv->coded_lossless) | 1032 | 288k | infer(tx_mode, AV1_ONLY_4X4); | 1033 | 939k | else | 1034 | 939k | increment(tx_mode, AV1_TX_MODE_LARGEST, AV1_TX_MODE_SELECT); | 1035 | | | 1036 | 1.22M | return 0; | 1037 | 1.22M | } |
cbs_av1.c:cbs_av1_write_read_tx_mode Line | Count | Source | 1027 | 288k | { | 1028 | 288k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1029 | 288k | int err; | 1030 | | | 1031 | 288k | if (priv->coded_lossless) | 1032 | 98.8k | infer(tx_mode, AV1_ONLY_4X4); | 1033 | 189k | else | 1034 | 189k | increment(tx_mode, AV1_TX_MODE_LARGEST, AV1_TX_MODE_SELECT); | 1035 | | | 1036 | 288k | return 0; | 1037 | 288k | } |
|
1038 | | |
1039 | | static int FUNC(frame_reference_mode)(CodedBitstreamContext *ctx, RWContext *rw, |
1040 | | AV1RawFrameHeader *current) |
1041 | 1.50M | { |
1042 | 1.50M | int err; |
1043 | | |
1044 | 1.50M | if (current->frame_type == AV1_FRAME_INTRA_ONLY || |
1045 | 1.46M | current->frame_type == AV1_FRAME_KEY) |
1046 | 756k | infer(reference_select, 0); |
1047 | 753k | else |
1048 | 1.50M | flag(reference_select); |
1049 | | |
1050 | 1.50M | return 0; |
1051 | 1.50M | } cbs_av1.c:cbs_av1_read_frame_reference_mode Line | Count | Source | 1041 | 1.22M | { | 1042 | 1.22M | int err; | 1043 | | | 1044 | 1.22M | if (current->frame_type == AV1_FRAME_INTRA_ONLY || | 1045 | 1.18M | current->frame_type == AV1_FRAME_KEY) | 1046 | 590k | infer(reference_select, 0); | 1047 | 630k | else | 1048 | 1.22M | flag(reference_select); | 1049 | | | 1050 | 1.21M | return 0; | 1051 | 1.22M | } |
cbs_av1.c:cbs_av1_write_frame_reference_mode Line | Count | Source | 1041 | 288k | { | 1042 | 288k | int err; | 1043 | | | 1044 | 288k | if (current->frame_type == AV1_FRAME_INTRA_ONLY || | 1045 | 284k | current->frame_type == AV1_FRAME_KEY) | 1046 | 165k | infer(reference_select, 0); | 1047 | 122k | else | 1048 | 288k | flag(reference_select); | 1049 | | | 1050 | 288k | return 0; | 1051 | 288k | } |
|
1052 | | |
1053 | | static int FUNC(skip_mode_params)(CodedBitstreamContext *ctx, RWContext *rw, |
1054 | | AV1RawFrameHeader *current) |
1055 | 1.50M | { |
1056 | 1.50M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
1057 | 1.50M | const AV1RawSequenceHeader *seq = priv->sequence_header; |
1058 | 1.50M | int skip_mode_allowed; |
1059 | 1.50M | int err; |
1060 | | |
1061 | 1.50M | if (current->frame_type == AV1_FRAME_KEY || |
1062 | 790k | current->frame_type == AV1_FRAME_INTRA_ONLY || |
1063 | 1.14M | !current->reference_select || !seq->enable_order_hint) { |
1064 | 1.14M | skip_mode_allowed = 0; |
1065 | 1.14M | } else { |
1066 | 358k | int forward_idx, backward_idx; |
1067 | 358k | int forward_hint, backward_hint; |
1068 | 358k | int ref_hint, dist, i; |
1069 | | |
1070 | 358k | forward_idx = -1; |
1071 | 358k | backward_idx = -1; |
1072 | 2.87M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { |
1073 | 2.51M | ref_hint = priv->ref[current->ref_frame_idx[i]].order_hint; |
1074 | 2.51M | dist = cbs_av1_get_relative_dist(seq, ref_hint, |
1075 | 2.51M | priv->order_hint); |
1076 | 2.51M | if (dist < 0) { |
1077 | 1.03M | if (forward_idx < 0 || |
1078 | 802k | cbs_av1_get_relative_dist(seq, ref_hint, |
1079 | 802k | forward_hint) > 0) { |
1080 | 257k | forward_idx = i; |
1081 | 257k | forward_hint = ref_hint; |
1082 | 257k | } |
1083 | 1.48M | } else if (dist > 0) { |
1084 | 385k | if (backward_idx < 0 || |
1085 | 263k | cbs_av1_get_relative_dist(seq, ref_hint, |
1086 | 263k | backward_hint) < 0) { |
1087 | 133k | backward_idx = i; |
1088 | 133k | backward_hint = ref_hint; |
1089 | 133k | } |
1090 | 385k | } |
1091 | 2.51M | } |
1092 | | |
1093 | 358k | if (forward_idx < 0) { |
1094 | 129k | skip_mode_allowed = 0; |
1095 | 229k | } else if (backward_idx >= 0) { |
1096 | 32.5k | skip_mode_allowed = 1; |
1097 | | // Frames for skip mode are forward_idx and backward_idx. |
1098 | 196k | } else { |
1099 | 196k | int second_forward_idx; |
1100 | 196k | int second_forward_hint; |
1101 | | |
1102 | 196k | second_forward_idx = -1; |
1103 | 1.57M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { |
1104 | 1.37M | ref_hint = priv->ref[current->ref_frame_idx[i]].order_hint; |
1105 | 1.37M | if (cbs_av1_get_relative_dist(seq, ref_hint, |
1106 | 1.37M | forward_hint) < 0) { |
1107 | 174k | if (second_forward_idx < 0 || |
1108 | 120k | cbs_av1_get_relative_dist(seq, ref_hint, |
1109 | 120k | second_forward_hint) > 0) { |
1110 | 64.6k | second_forward_idx = i; |
1111 | 64.6k | second_forward_hint = ref_hint; |
1112 | 64.6k | } |
1113 | 174k | } |
1114 | 1.37M | } |
1115 | | |
1116 | 196k | if (second_forward_idx < 0) { |
1117 | 143k | skip_mode_allowed = 0; |
1118 | 143k | } else { |
1119 | 53.2k | skip_mode_allowed = 1; |
1120 | | // Frames for skip mode are forward_idx and second_forward_idx. |
1121 | 53.2k | } |
1122 | 196k | } |
1123 | 358k | } |
1124 | | |
1125 | 1.50M | if (skip_mode_allowed) |
1126 | 1.50M | flag(skip_mode_present); |
1127 | 1.41M | else |
1128 | 1.41M | infer(skip_mode_present, 0); |
1129 | | |
1130 | 1.50M | return 0; |
1131 | 1.50M | } cbs_av1.c:cbs_av1_read_skip_mode_params Line | Count | Source | 1055 | 1.21M | { | 1056 | 1.21M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1057 | 1.21M | const AV1RawSequenceHeader *seq = priv->sequence_header; | 1058 | 1.21M | int skip_mode_allowed; | 1059 | 1.21M | int err; | 1060 | | | 1061 | 1.21M | if (current->frame_type == AV1_FRAME_KEY || | 1062 | 663k | current->frame_type == AV1_FRAME_INTRA_ONLY || | 1063 | 931k | !current->reference_select || !seq->enable_order_hint) { | 1064 | 931k | skip_mode_allowed = 0; | 1065 | 931k | } else { | 1066 | 283k | int forward_idx, backward_idx; | 1067 | 283k | int forward_hint, backward_hint; | 1068 | 283k | int ref_hint, dist, i; | 1069 | | | 1070 | 283k | forward_idx = -1; | 1071 | 283k | backward_idx = -1; | 1072 | 2.27M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { | 1073 | 1.98M | ref_hint = priv->ref[current->ref_frame_idx[i]].order_hint; | 1074 | 1.98M | dist = cbs_av1_get_relative_dist(seq, ref_hint, | 1075 | 1.98M | priv->order_hint); | 1076 | 1.98M | if (dist < 0) { | 1077 | 847k | if (forward_idx < 0 || | 1078 | 659k | cbs_av1_get_relative_dist(seq, ref_hint, | 1079 | 659k | forward_hint) > 0) { | 1080 | 210k | forward_idx = i; | 1081 | 210k | forward_hint = ref_hint; | 1082 | 210k | } | 1083 | 1.13M | } else if (dist > 0) { | 1084 | 299k | if (backward_idx < 0 || | 1085 | 207k | cbs_av1_get_relative_dist(seq, ref_hint, | 1086 | 207k | backward_hint) < 0) { | 1087 | 101k | backward_idx = i; | 1088 | 101k | backward_hint = ref_hint; | 1089 | 101k | } | 1090 | 299k | } | 1091 | 1.98M | } | 1092 | | | 1093 | 283k | if (forward_idx < 0) { | 1094 | 96.1k | skip_mode_allowed = 0; | 1095 | 187k | } else if (backward_idx >= 0) { | 1096 | 25.7k | skip_mode_allowed = 1; | 1097 | | // Frames for skip mode are forward_idx and backward_idx. | 1098 | 161k | } else { | 1099 | 161k | int second_forward_idx; | 1100 | 161k | int second_forward_hint; | 1101 | | | 1102 | 161k | second_forward_idx = -1; | 1103 | 1.29M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { | 1104 | 1.13M | ref_hint = priv->ref[current->ref_frame_idx[i]].order_hint; | 1105 | 1.13M | if (cbs_av1_get_relative_dist(seq, ref_hint, | 1106 | 1.13M | forward_hint) < 0) { | 1107 | 145k | if (second_forward_idx < 0 || | 1108 | 101k | cbs_av1_get_relative_dist(seq, ref_hint, | 1109 | 101k | second_forward_hint) > 0) { | 1110 | 52.9k | second_forward_idx = i; | 1111 | 52.9k | second_forward_hint = ref_hint; | 1112 | 52.9k | } | 1113 | 145k | } | 1114 | 1.13M | } | 1115 | | | 1116 | 161k | if (second_forward_idx < 0) { | 1117 | 118k | skip_mode_allowed = 0; | 1118 | 118k | } else { | 1119 | 43.6k | skip_mode_allowed = 1; | 1120 | | // Frames for skip mode are forward_idx and second_forward_idx. | 1121 | 43.6k | } | 1122 | 161k | } | 1123 | 283k | } | 1124 | | | 1125 | 1.21M | if (skip_mode_allowed) | 1126 | 1.21M | flag(skip_mode_present); | 1127 | 1.14M | else | 1128 | 1.14M | infer(skip_mode_present, 0); | 1129 | | | 1130 | 1.21M | return 0; | 1131 | 1.21M | } |
cbs_av1.c:cbs_av1_write_skip_mode_params Line | Count | Source | 1055 | 288k | { | 1056 | 288k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1057 | 288k | const AV1RawSequenceHeader *seq = priv->sequence_header; | 1058 | 288k | int skip_mode_allowed; | 1059 | 288k | int err; | 1060 | | | 1061 | 288k | if (current->frame_type == AV1_FRAME_KEY || | 1062 | 126k | current->frame_type == AV1_FRAME_INTRA_ONLY || | 1063 | 213k | !current->reference_select || !seq->enable_order_hint) { | 1064 | 213k | skip_mode_allowed = 0; | 1065 | 213k | } else { | 1066 | 75.0k | int forward_idx, backward_idx; | 1067 | 75.0k | int forward_hint, backward_hint; | 1068 | 75.0k | int ref_hint, dist, i; | 1069 | | | 1070 | 75.0k | forward_idx = -1; | 1071 | 75.0k | backward_idx = -1; | 1072 | 600k | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { | 1073 | 525k | ref_hint = priv->ref[current->ref_frame_idx[i]].order_hint; | 1074 | 525k | dist = cbs_av1_get_relative_dist(seq, ref_hint, | 1075 | 525k | priv->order_hint); | 1076 | 525k | if (dist < 0) { | 1077 | 184k | if (forward_idx < 0 || | 1078 | 142k | cbs_av1_get_relative_dist(seq, ref_hint, | 1079 | 142k | forward_hint) > 0) { | 1080 | 46.9k | forward_idx = i; | 1081 | 46.9k | forward_hint = ref_hint; | 1082 | 46.9k | } | 1083 | 340k | } else if (dist > 0) { | 1084 | 86.1k | if (backward_idx < 0 || | 1085 | 55.6k | cbs_av1_get_relative_dist(seq, ref_hint, | 1086 | 55.6k | backward_hint) < 0) { | 1087 | 32.2k | backward_idx = i; | 1088 | 32.2k | backward_hint = ref_hint; | 1089 | 32.2k | } | 1090 | 86.1k | } | 1091 | 525k | } | 1092 | | | 1093 | 75.0k | if (forward_idx < 0) { | 1094 | 33.2k | skip_mode_allowed = 0; | 1095 | 41.7k | } else if (backward_idx >= 0) { | 1096 | 6.82k | skip_mode_allowed = 1; | 1097 | | // Frames for skip mode are forward_idx and backward_idx. | 1098 | 34.9k | } else { | 1099 | 34.9k | int second_forward_idx; | 1100 | 34.9k | int second_forward_hint; | 1101 | | | 1102 | 34.9k | second_forward_idx = -1; | 1103 | 279k | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { | 1104 | 244k | ref_hint = priv->ref[current->ref_frame_idx[i]].order_hint; | 1105 | 244k | if (cbs_av1_get_relative_dist(seq, ref_hint, | 1106 | 244k | forward_hint) < 0) { | 1107 | 28.7k | if (second_forward_idx < 0 || | 1108 | 19.0k | cbs_av1_get_relative_dist(seq, ref_hint, | 1109 | 19.0k | second_forward_hint) > 0) { | 1110 | 11.6k | second_forward_idx = i; | 1111 | 11.6k | second_forward_hint = ref_hint; | 1112 | 11.6k | } | 1113 | 28.7k | } | 1114 | 244k | } | 1115 | | | 1116 | 34.9k | if (second_forward_idx < 0) { | 1117 | 25.2k | skip_mode_allowed = 0; | 1118 | 25.2k | } else { | 1119 | 9.65k | skip_mode_allowed = 1; | 1120 | | // Frames for skip mode are forward_idx and second_forward_idx. | 1121 | 9.65k | } | 1122 | 34.9k | } | 1123 | 75.0k | } | 1124 | | | 1125 | 288k | if (skip_mode_allowed) | 1126 | 288k | flag(skip_mode_present); | 1127 | 272k | else | 1128 | 272k | infer(skip_mode_present, 0); | 1129 | | | 1130 | 288k | return 0; | 1131 | 288k | } |
|
1132 | | |
1133 | | static int FUNC(global_motion_param)(CodedBitstreamContext *ctx, RWContext *rw, |
1134 | | AV1RawFrameHeader *current, |
1135 | | int type, int ref, int idx) |
1136 | 2.91M | { |
1137 | 2.91M | uint32_t abs_bits, prec_bits, num_syms; |
1138 | 2.91M | int err; |
1139 | | |
1140 | 2.91M | if (idx < 2) { |
1141 | 1.38M | if (type == AV1_WARP_MODEL_TRANSLATION) { |
1142 | 263k | abs_bits = AV1_GM_ABS_TRANS_ONLY_BITS - !current->allow_high_precision_mv; |
1143 | 263k | prec_bits = AV1_GM_TRANS_ONLY_PREC_BITS - !current->allow_high_precision_mv; |
1144 | 1.12M | } else { |
1145 | 1.12M | abs_bits = AV1_GM_ABS_TRANS_BITS; |
1146 | 1.12M | prec_bits = AV1_GM_TRANS_PREC_BITS; |
1147 | 1.12M | } |
1148 | 1.52M | } else { |
1149 | 1.52M | abs_bits = AV1_GM_ABS_ALPHA_BITS; |
1150 | 1.52M | prec_bits = AV1_GM_ALPHA_PREC_BITS; |
1151 | 1.52M | } |
1152 | | |
1153 | 2.91M | num_syms = 2 * (1 << abs_bits) + 1; |
1154 | 2.91M | subexp(gm_params[ref][idx], num_syms, 2, ref, idx); |
1155 | | |
1156 | | // Actual gm_params value is not reconstructed here. |
1157 | 2.80M | (void)prec_bits; |
1158 | | |
1159 | 2.80M | return 0; |
1160 | 2.91M | } cbs_av1.c:cbs_av1_read_global_motion_param Line | Count | Source | 1136 | 2.50M | { | 1137 | 2.50M | uint32_t abs_bits, prec_bits, num_syms; | 1138 | 2.50M | int err; | 1139 | | | 1140 | 2.50M | if (idx < 2) { | 1141 | 1.18M | if (type == AV1_WARP_MODEL_TRANSLATION) { | 1142 | 224k | abs_bits = AV1_GM_ABS_TRANS_ONLY_BITS - !current->allow_high_precision_mv; | 1143 | 224k | prec_bits = AV1_GM_TRANS_ONLY_PREC_BITS - !current->allow_high_precision_mv; | 1144 | 959k | } else { | 1145 | 959k | abs_bits = AV1_GM_ABS_TRANS_BITS; | 1146 | 959k | prec_bits = AV1_GM_TRANS_PREC_BITS; | 1147 | 959k | } | 1148 | 1.32M | } else { | 1149 | 1.32M | abs_bits = AV1_GM_ABS_ALPHA_BITS; | 1150 | 1.32M | prec_bits = AV1_GM_ALPHA_PREC_BITS; | 1151 | 1.32M | } | 1152 | | | 1153 | 2.50M | num_syms = 2 * (1 << abs_bits) + 1; | 1154 | 2.50M | subexp(gm_params[ref][idx], num_syms, 2, ref, idx); | 1155 | | | 1156 | | // Actual gm_params value is not reconstructed here. | 1157 | 2.40M | (void)prec_bits; | 1158 | | | 1159 | 2.40M | return 0; | 1160 | 2.50M | } |
cbs_av1.c:cbs_av1_write_global_motion_param Line | Count | Source | 1136 | 401k | { | 1137 | 401k | uint32_t abs_bits, prec_bits, num_syms; | 1138 | 401k | int err; | 1139 | | | 1140 | 401k | if (idx < 2) { | 1141 | 204k | if (type == AV1_WARP_MODEL_TRANSLATION) { | 1142 | 39.0k | abs_bits = AV1_GM_ABS_TRANS_ONLY_BITS - !current->allow_high_precision_mv; | 1143 | 39.0k | prec_bits = AV1_GM_TRANS_ONLY_PREC_BITS - !current->allow_high_precision_mv; | 1144 | 165k | } else { | 1145 | 165k | abs_bits = AV1_GM_ABS_TRANS_BITS; | 1146 | 165k | prec_bits = AV1_GM_TRANS_PREC_BITS; | 1147 | 165k | } | 1148 | 204k | } else { | 1149 | 196k | abs_bits = AV1_GM_ABS_ALPHA_BITS; | 1150 | 196k | prec_bits = AV1_GM_ALPHA_PREC_BITS; | 1151 | 196k | } | 1152 | | | 1153 | 401k | num_syms = 2 * (1 << abs_bits) + 1; | 1154 | 401k | subexp(gm_params[ref][idx], num_syms, 2, ref, idx); | 1155 | | | 1156 | | // Actual gm_params value is not reconstructed here. | 1157 | 401k | (void)prec_bits; | 1158 | | | 1159 | 401k | return 0; | 1160 | 401k | } |
|
1161 | | |
1162 | | static int FUNC(global_motion_params)(CodedBitstreamContext *ctx, RWContext *rw, |
1163 | | AV1RawFrameHeader *current) |
1164 | 1.48M | { |
1165 | 1.48M | int ref, type; |
1166 | 1.48M | int err; |
1167 | | |
1168 | 1.48M | if (current->frame_type == AV1_FRAME_KEY || |
1169 | 776k | current->frame_type == AV1_FRAME_INTRA_ONLY) |
1170 | 752k | return 0; |
1171 | | |
1172 | 5.14M | for (ref = AV1_REF_FRAME_LAST; ref <= AV1_REF_FRAME_ALTREF; ref++) { |
1173 | 4.55M | flags(is_global[ref], 1, ref); |
1174 | 4.52M | if (current->is_global[ref]) { |
1175 | 777k | flags(is_rot_zoom[ref], 1, ref); |
1176 | 770k | if (current->is_rot_zoom[ref]) { |
1177 | 470k | type = AV1_WARP_MODEL_ROTZOOM; |
1178 | 470k | } else { |
1179 | 299k | flags(is_translation[ref], 1, ref); |
1180 | 295k | type = current->is_translation[ref] ? AV1_WARP_MODEL_TRANSLATION |
1181 | 295k | : AV1_WARP_MODEL_AFFINE; |
1182 | 295k | } |
1183 | 3.74M | } else { |
1184 | 3.74M | type = AV1_WARP_MODEL_IDENTITY; |
1185 | 3.74M | } |
1186 | | |
1187 | 4.51M | if (type >= AV1_WARP_MODEL_ROTZOOM) { |
1188 | 631k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 2)); |
1189 | 612k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 3)); |
1190 | 585k | if (type == AV1_WARP_MODEL_AFFINE) { |
1191 | 142k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 4)); |
1192 | 135k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 5)); |
1193 | 442k | } else { |
1194 | | // gm_params[ref][4] = -gm_params[ref][3] |
1195 | | // gm_params[ref][5] = gm_params[ref][2] |
1196 | 442k | } |
1197 | 585k | } |
1198 | 4.45M | if (type >= AV1_WARP_MODEL_TRANSLATION) { |
1199 | 703k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 0)); |
1200 | 685k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 1)); |
1201 | 685k | } |
1202 | 4.45M | } |
1203 | | |
1204 | 591k | return 0; |
1205 | 734k | } cbs_av1.c:cbs_av1_read_global_motion_params Line | Count | Source | 1164 | 1.19M | { | 1165 | 1.19M | int ref, type; | 1166 | 1.19M | int err; | 1167 | | | 1168 | 1.19M | if (current->frame_type == AV1_FRAME_KEY || | 1169 | 650k | current->frame_type == AV1_FRAME_INTRA_ONLY) | 1170 | 586k | return 0; | 1171 | | | 1172 | 4.16M | for (ref = AV1_REF_FRAME_LAST; ref <= AV1_REF_FRAME_ALTREF; ref++) { | 1173 | 3.69M | flags(is_global[ref], 1, ref); | 1174 | 3.67M | if (current->is_global[ref]) { | 1175 | 675k | flags(is_rot_zoom[ref], 1, ref); | 1176 | 667k | if (current->is_rot_zoom[ref]) { | 1177 | 402k | type = AV1_WARP_MODEL_ROTZOOM; | 1178 | 402k | } else { | 1179 | 265k | flags(is_translation[ref], 1, ref); | 1180 | 260k | type = current->is_translation[ref] ? AV1_WARP_MODEL_TRANSLATION | 1181 | 260k | : AV1_WARP_MODEL_AFFINE; | 1182 | 260k | } | 1183 | 2.99M | } else { | 1184 | 2.99M | type = AV1_WARP_MODEL_IDENTITY; | 1185 | 2.99M | } | 1186 | | | 1187 | 3.65M | if (type >= AV1_WARP_MODEL_ROTZOOM) { | 1188 | 548k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 2)); | 1189 | 529k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 3)); | 1190 | 502k | if (type == AV1_WARP_MODEL_AFFINE) { | 1191 | 127k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 4)); | 1192 | 120k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 5)); | 1193 | 375k | } else { | 1194 | | // gm_params[ref][4] = -gm_params[ref][3] | 1195 | | // gm_params[ref][5] = gm_params[ref][2] | 1196 | 375k | } | 1197 | 502k | } | 1198 | 3.59M | if (type >= AV1_WARP_MODEL_TRANSLATION) { | 1199 | 601k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 0)); | 1200 | 582k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 1)); | 1201 | 582k | } | 1202 | 3.59M | } | 1203 | | | 1204 | 469k | return 0; | 1205 | 612k | } |
cbs_av1.c:cbs_av1_write_global_motion_params Line | Count | Source | 1164 | 287k | { | 1165 | 287k | int ref, type; | 1166 | 287k | int err; | 1167 | | | 1168 | 287k | if (current->frame_type == AV1_FRAME_KEY || | 1169 | 126k | current->frame_type == AV1_FRAME_INTRA_ONLY) | 1170 | 165k | return 0; | 1171 | | | 1172 | 976k | for (ref = AV1_REF_FRAME_LAST; ref <= AV1_REF_FRAME_ALTREF; ref++) { | 1173 | 854k | flags(is_global[ref], 1, ref); | 1174 | 854k | if (current->is_global[ref]) { | 1175 | 102k | flags(is_rot_zoom[ref], 1, ref); | 1176 | 102k | if (current->is_rot_zoom[ref]) { | 1177 | 67.3k | type = AV1_WARP_MODEL_ROTZOOM; | 1178 | 67.3k | } else { | 1179 | 34.9k | flags(is_translation[ref], 1, ref); | 1180 | 34.9k | type = current->is_translation[ref] ? AV1_WARP_MODEL_TRANSLATION | 1181 | 34.9k | : AV1_WARP_MODEL_AFFINE; | 1182 | 34.9k | } | 1183 | 751k | } else { | 1184 | 751k | type = AV1_WARP_MODEL_IDENTITY; | 1185 | 751k | } | 1186 | | | 1187 | 854k | if (type >= AV1_WARP_MODEL_ROTZOOM) { | 1188 | 82.7k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 2)); | 1189 | 82.7k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 3)); | 1190 | 82.7k | if (type == AV1_WARP_MODEL_AFFINE) { | 1191 | 15.4k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 4)); | 1192 | 15.4k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 5)); | 1193 | 67.3k | } else { | 1194 | | // gm_params[ref][4] = -gm_params[ref][3] | 1195 | | // gm_params[ref][5] = gm_params[ref][2] | 1196 | 67.3k | } | 1197 | 82.7k | } | 1198 | 854k | if (type >= AV1_WARP_MODEL_TRANSLATION) { | 1199 | 102k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 0)); | 1200 | 102k | CHECK(FUNC(global_motion_param)(ctx, rw, current, type, ref, 1)); | 1201 | 102k | } | 1202 | 854k | } | 1203 | | | 1204 | 122k | return 0; | 1205 | 122k | } |
|
1206 | | |
1207 | | static int FUNC(film_grain_params)(CodedBitstreamContext *ctx, RWContext *rw, |
1208 | | AV1RawFilmGrainParams *current, |
1209 | | AV1RawFrameHeader *frame_header) |
1210 | 1.34M | { |
1211 | 1.34M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
1212 | 1.34M | const AV1RawSequenceHeader *seq = priv->sequence_header; |
1213 | 1.34M | int num_pos_luma, num_pos_chroma; |
1214 | 1.34M | int i, err; |
1215 | | |
1216 | 1.34M | if (!seq->film_grain_params_present || |
1217 | 864k | (!frame_header->show_frame && !frame_header->showable_frame)) |
1218 | 521k | return 0; |
1219 | | |
1220 | 822k | flag(apply_grain); |
1221 | | |
1222 | 813k | if (!current->apply_grain) |
1223 | 492k | return 0; |
1224 | | |
1225 | 320k | fb(16, grain_seed); |
1226 | | |
1227 | 308k | if (frame_header->frame_type == AV1_FRAME_INTER) |
1228 | 308k | flag(update_grain); |
1229 | 262k | else |
1230 | 262k | infer(update_grain, 1); |
1231 | | |
1232 | 305k | if (!current->update_grain) { |
1233 | 23.3k | fb(3, film_grain_params_ref_idx); |
1234 | 20.2k | return 0; |
1235 | 23.3k | } |
1236 | | |
1237 | 282k | fc(4, num_y_points, 0, 14); |
1238 | 462k | for (i = 0; i < current->num_y_points; i++) { |
1239 | 234k | fcs(8, point_y_value[i], |
1240 | 194k | i ? current->point_y_value[i - 1] + 1 : 0, |
1241 | 194k | MAX_UINT_BITS(8) - (current->num_y_points - i - 1), |
1242 | 194k | 1, i); |
1243 | 194k | fbs(8, point_y_scaling[i], 1, i); |
1244 | 194k | } |
1245 | | |
1246 | 228k | if (seq->color_config.mono_chrome) |
1247 | 21.9k | infer(chroma_scaling_from_luma, 0); |
1248 | 206k | else |
1249 | 228k | flag(chroma_scaling_from_luma); |
1250 | | |
1251 | 223k | if (seq->color_config.mono_chrome || |
1252 | 201k | current->chroma_scaling_from_luma || |
1253 | 171k | (seq->color_config.subsampling_x == 1 && |
1254 | 112k | seq->color_config.subsampling_y == 1 && |
1255 | 66.0k | current->num_y_points == 0)) { |
1256 | 66.0k | infer(num_cb_points, 0); |
1257 | 65.6k | infer(num_cr_points, 0); |
1258 | 157k | } else { |
1259 | 157k | fc(4, num_cb_points, 0, 10); |
1260 | 211k | for (i = 0; i < current->num_cb_points; i++) { |
1261 | 95.4k | fcs(8, point_cb_value[i], |
1262 | 83.1k | i ? current->point_cb_value[i - 1] + 1 : 0, |
1263 | 83.1k | MAX_UINT_BITS(8) - (current->num_cb_points - i - 1), |
1264 | 83.1k | 1, i); |
1265 | 83.1k | fbs(8, point_cb_scaling[i], 1, i); |
1266 | 83.1k | } |
1267 | 115k | fc(4, num_cr_points, 0, 10); |
1268 | 182k | for (i = 0; i < current->num_cr_points; i++) { |
1269 | 84.9k | fcs(8, point_cr_value[i], |
1270 | 76.8k | i ? current->point_cr_value[i - 1] + 1 : 0, |
1271 | 76.8k | MAX_UINT_BITS(8) - (current->num_cr_points - i - 1), |
1272 | 76.8k | 1, i); |
1273 | 76.8k | fbs(8, point_cr_scaling[i], 1, i); |
1274 | 76.8k | } |
1275 | 111k | } |
1276 | | |
1277 | 163k | fb(2, grain_scaling_minus_8); |
1278 | 158k | fb(2, ar_coeff_lag); |
1279 | 154k | num_pos_luma = 2 * current->ar_coeff_lag * (current->ar_coeff_lag + 1); |
1280 | 154k | if (current->num_y_points) { |
1281 | 75.4k | num_pos_chroma = num_pos_luma + 1; |
1282 | 250k | for (i = 0; i < num_pos_luma; i++) |
1283 | 181k | fbs(8, ar_coeffs_y_plus_128[i], 1, i); |
1284 | 78.9k | } else { |
1285 | 78.9k | num_pos_chroma = num_pos_luma; |
1286 | 78.9k | } |
1287 | 148k | if (current->chroma_scaling_from_luma || current->num_cb_points) { |
1288 | 217k | for (i = 0; i < num_pos_chroma; i++) |
1289 | 170k | fbs(8, ar_coeffs_cb_plus_128[i], 1, i); |
1290 | 52.7k | } |
1291 | 142k | if (current->chroma_scaling_from_luma || current->num_cr_points) { |
1292 | 214k | for (i = 0; i < num_pos_chroma; i++) |
1293 | 168k | fbs(8, ar_coeffs_cr_plus_128[i], 1, i); |
1294 | 52.8k | } |
1295 | 135k | fb(2, ar_coeff_shift_minus_6); |
1296 | 132k | fb(2, grain_scale_shift); |
1297 | 128k | if (current->num_cb_points) { |
1298 | 26.4k | fb(8, cb_mult); |
1299 | 23.6k | fb(8, cb_luma_mult); |
1300 | 18.9k | fb(9, cb_offset); |
1301 | 18.9k | } |
1302 | 114k | if (current->num_cr_points) { |
1303 | 25.8k | fb(8, cr_mult); |
1304 | 21.9k | fb(8, cr_luma_mult); |
1305 | 17.4k | fb(9, cr_offset); |
1306 | 17.4k | } |
1307 | | |
1308 | 102k | flag(overlap_flag); |
1309 | 94.7k | flag(clip_to_restricted_range); |
1310 | | |
1311 | 90.2k | return 0; |
1312 | 94.7k | } cbs_av1.c:cbs_av1_read_film_grain_params Line | Count | Source | 1210 | 1.05M | { | 1211 | 1.05M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1212 | 1.05M | const AV1RawSequenceHeader *seq = priv->sequence_header; | 1213 | 1.05M | int num_pos_luma, num_pos_chroma; | 1214 | 1.05M | int i, err; | 1215 | | | 1216 | 1.05M | if (!seq->film_grain_params_present || | 1217 | 706k | (!frame_header->show_frame && !frame_header->showable_frame)) | 1218 | 382k | return 0; | 1219 | | | 1220 | 673k | flag(apply_grain); | 1221 | | | 1222 | 665k | if (!current->apply_grain) | 1223 | 374k | return 0; | 1224 | | | 1225 | 290k | fb(16, grain_seed); | 1226 | | | 1227 | 278k | if (frame_header->frame_type == AV1_FRAME_INTER) | 1228 | 278k | flag(update_grain); | 1229 | 239k | else | 1230 | 239k | infer(update_grain, 1); | 1231 | | | 1232 | 275k | if (!current->update_grain) { | 1233 | 17.5k | fb(3, film_grain_params_ref_idx); | 1234 | 14.3k | return 0; | 1235 | 17.5k | } | 1236 | | | 1237 | 257k | fc(4, num_y_points, 0, 14); | 1238 | 417k | for (i = 0; i < current->num_y_points; i++) { | 1239 | 213k | fcs(8, point_y_value[i], | 1240 | 174k | i ? current->point_y_value[i - 1] + 1 : 0, | 1241 | 174k | MAX_UINT_BITS(8) - (current->num_y_points - i - 1), | 1242 | 174k | 1, i); | 1243 | 174k | fbs(8, point_y_scaling[i], 1, i); | 1244 | 174k | } | 1245 | | | 1246 | 203k | if (seq->color_config.mono_chrome) | 1247 | 19.5k | infer(chroma_scaling_from_luma, 0); | 1248 | 184k | else | 1249 | 203k | flag(chroma_scaling_from_luma); | 1250 | | | 1251 | 198k | if (seq->color_config.mono_chrome || | 1252 | 179k | current->chroma_scaling_from_luma || | 1253 | 151k | (seq->color_config.subsampling_x == 1 && | 1254 | 95.0k | seq->color_config.subsampling_y == 1 && | 1255 | 58.8k | current->num_y_points == 0)) { | 1256 | 58.8k | infer(num_cb_points, 0); | 1257 | 58.8k | infer(num_cr_points, 0); | 1258 | 139k | } else { | 1259 | 139k | fc(4, num_cb_points, 0, 10); | 1260 | 188k | for (i = 0; i < current->num_cb_points; i++) { | 1261 | 89.7k | fcs(8, point_cb_value[i], | 1262 | 77.5k | i ? current->point_cb_value[i - 1] + 1 : 0, | 1263 | 77.5k | MAX_UINT_BITS(8) - (current->num_cb_points - i - 1), | 1264 | 77.5k | 1, i); | 1265 | 77.5k | fbs(8, point_cb_scaling[i], 1, i); | 1266 | 77.5k | } | 1267 | 98.4k | fc(4, num_cr_points, 0, 10); | 1268 | 159k | for (i = 0; i < current->num_cr_points; i++) { | 1269 | 78.9k | fcs(8, point_cr_value[i], | 1270 | 70.7k | i ? current->point_cr_value[i - 1] + 1 : 0, | 1271 | 70.7k | MAX_UINT_BITS(8) - (current->num_cr_points - i - 1), | 1272 | 70.7k | 1, i); | 1273 | 70.7k | fbs(8, point_cr_scaling[i], 1, i); | 1274 | 70.7k | } | 1275 | 94.0k | } | 1276 | | | 1277 | 139k | fb(2, grain_scaling_minus_8); | 1278 | 134k | fb(2, ar_coeff_lag); | 1279 | 130k | num_pos_luma = 2 * current->ar_coeff_lag * (current->ar_coeff_lag + 1); | 1280 | 130k | if (current->num_y_points) { | 1281 | 59.3k | num_pos_chroma = num_pos_luma + 1; | 1282 | 215k | for (i = 0; i < num_pos_luma; i++) | 1283 | 162k | fbs(8, ar_coeffs_y_plus_128[i], 1, i); | 1284 | 71.3k | } else { | 1285 | 71.3k | num_pos_chroma = num_pos_luma; | 1286 | 71.3k | } | 1287 | 124k | if (current->chroma_scaling_from_luma || current->num_cb_points) { | 1288 | 201k | for (i = 0; i < num_pos_chroma; i++) | 1289 | 160k | fbs(8, ar_coeffs_cb_plus_128[i], 1, i); | 1290 | 47.1k | } | 1291 | 118k | if (current->chroma_scaling_from_luma || current->num_cr_points) { | 1292 | 198k | for (i = 0; i < num_pos_chroma; i++) | 1293 | 157k | fbs(8, ar_coeffs_cr_plus_128[i], 1, i); | 1294 | 47.7k | } | 1295 | 112k | fb(2, ar_coeff_shift_minus_6); | 1296 | 109k | fb(2, grain_scale_shift); | 1297 | 104k | if (current->num_cb_points) { | 1298 | 23.7k | fb(8, cb_mult); | 1299 | 20.9k | fb(8, cb_luma_mult); | 1300 | 16.2k | fb(9, cb_offset); | 1301 | 16.2k | } | 1302 | 91.1k | if (current->num_cr_points) { | 1303 | 23.6k | fb(8, cr_mult); | 1304 | 19.7k | fb(8, cr_luma_mult); | 1305 | 15.2k | fb(9, cr_offset); | 1306 | 15.2k | } | 1307 | | | 1308 | 78.4k | flag(overlap_flag); | 1309 | 71.0k | flag(clip_to_restricted_range); | 1310 | | | 1311 | 66.5k | return 0; | 1312 | 71.0k | } |
cbs_av1.c:cbs_av1_write_film_grain_params Line | Count | Source | 1210 | 287k | { | 1211 | 287k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1212 | 287k | const AV1RawSequenceHeader *seq = priv->sequence_header; | 1213 | 287k | int num_pos_luma, num_pos_chroma; | 1214 | 287k | int i, err; | 1215 | | | 1216 | 287k | if (!seq->film_grain_params_present || | 1217 | 157k | (!frame_header->show_frame && !frame_header->showable_frame)) | 1218 | 139k | return 0; | 1219 | | | 1220 | 148k | flag(apply_grain); | 1221 | | | 1222 | 148k | if (!current->apply_grain) | 1223 | 118k | return 0; | 1224 | | | 1225 | 30.7k | fb(16, grain_seed); | 1226 | | | 1227 | 30.7k | if (frame_header->frame_type == AV1_FRAME_INTER) | 1228 | 30.7k | flag(update_grain); | 1229 | 23.5k | else | 1230 | 23.5k | infer(update_grain, 1); | 1231 | | | 1232 | 30.7k | if (!current->update_grain) { | 1233 | 5.82k | fb(3, film_grain_params_ref_idx); | 1234 | 5.82k | return 0; | 1235 | 5.82k | } | 1236 | | | 1237 | 24.8k | fc(4, num_y_points, 0, 14); | 1238 | 45.4k | for (i = 0; i < current->num_y_points; i++) { | 1239 | 20.5k | fcs(8, point_y_value[i], | 1240 | 20.5k | i ? current->point_y_value[i - 1] + 1 : 0, | 1241 | 20.5k | MAX_UINT_BITS(8) - (current->num_y_points - i - 1), | 1242 | 20.5k | 1, i); | 1243 | 20.5k | fbs(8, point_y_scaling[i], 1, i); | 1244 | 20.5k | } | 1245 | | | 1246 | 24.8k | if (seq->color_config.mono_chrome) | 1247 | 2.41k | infer(chroma_scaling_from_luma, 0); | 1248 | 22.4k | else | 1249 | 24.8k | flag(chroma_scaling_from_luma); | 1250 | | | 1251 | 24.4k | if (seq->color_config.mono_chrome || | 1252 | 22.4k | current->chroma_scaling_from_luma || | 1253 | 19.5k | (seq->color_config.subsampling_x == 1 && | 1254 | 17.7k | seq->color_config.subsampling_y == 1 && | 1255 | 15.1k | current->num_y_points == 0)) { | 1256 | 7.20k | infer(num_cb_points, 0); | 1257 | 6.80k | infer(num_cr_points, 0); | 1258 | 17.2k | } else { | 1259 | 17.2k | fc(4, num_cb_points, 0, 10); | 1260 | 22.9k | for (i = 0; i < current->num_cb_points; i++) { | 1261 | 5.65k | fcs(8, point_cb_value[i], | 1262 | 5.65k | i ? current->point_cb_value[i - 1] + 1 : 0, | 1263 | 5.65k | MAX_UINT_BITS(8) - (current->num_cb_points - i - 1), | 1264 | 5.65k | 1, i); | 1265 | 5.65k | fbs(8, point_cb_scaling[i], 1, i); | 1266 | 5.65k | } | 1267 | 17.2k | fc(4, num_cr_points, 0, 10); | 1268 | 23.3k | for (i = 0; i < current->num_cr_points; i++) { | 1269 | 6.06k | fcs(8, point_cr_value[i], | 1270 | 6.06k | i ? current->point_cr_value[i - 1] + 1 : 0, | 1271 | 6.06k | MAX_UINT_BITS(8) - (current->num_cr_points - i - 1), | 1272 | 6.06k | 1, i); | 1273 | 6.06k | fbs(8, point_cr_scaling[i], 1, i); | 1274 | 6.06k | } | 1275 | 17.2k | } | 1276 | | | 1277 | 23.6k | fb(2, grain_scaling_minus_8); | 1278 | 23.6k | fb(2, ar_coeff_lag); | 1279 | 23.6k | num_pos_luma = 2 * current->ar_coeff_lag * (current->ar_coeff_lag + 1); | 1280 | 23.6k | if (current->num_y_points) { | 1281 | 16.0k | num_pos_chroma = num_pos_luma + 1; | 1282 | 34.9k | for (i = 0; i < num_pos_luma; i++) | 1283 | 18.8k | fbs(8, ar_coeffs_y_plus_128[i], 1, i); | 1284 | 16.0k | } else { | 1285 | 7.61k | num_pos_chroma = num_pos_luma; | 1286 | 7.61k | } | 1287 | 23.6k | if (current->chroma_scaling_from_luma || current->num_cb_points) { | 1288 | 15.2k | for (i = 0; i < num_pos_chroma; i++) | 1289 | 9.63k | fbs(8, ar_coeffs_cb_plus_128[i], 1, i); | 1290 | 5.56k | } | 1291 | 23.6k | if (current->chroma_scaling_from_luma || current->num_cr_points) { | 1292 | 15.9k | for (i = 0; i < num_pos_chroma; i++) | 1293 | 10.8k | fbs(8, ar_coeffs_cr_plus_128[i], 1, i); | 1294 | 5.10k | } | 1295 | 23.6k | fb(2, ar_coeff_shift_minus_6); | 1296 | 23.6k | fb(2, grain_scale_shift); | 1297 | 23.6k | if (current->num_cb_points) { | 1298 | 2.64k | fb(8, cb_mult); | 1299 | 2.64k | fb(8, cb_luma_mult); | 1300 | 2.64k | fb(9, cb_offset); | 1301 | 2.64k | } | 1302 | 23.6k | if (current->num_cr_points) { | 1303 | 2.19k | fb(8, cr_mult); | 1304 | 2.19k | fb(8, cr_luma_mult); | 1305 | 2.19k | fb(9, cr_offset); | 1306 | 2.19k | } | 1307 | | | 1308 | 23.6k | flag(overlap_flag); | 1309 | 23.6k | flag(clip_to_restricted_range); | 1310 | | | 1311 | 23.6k | return 0; | 1312 | 23.6k | } |
|
1313 | | |
1314 | | static int FUNC(uncompressed_header)(CodedBitstreamContext *ctx, RWContext *rw, |
1315 | | AV1RawFrameHeader *current) |
1316 | 3.10M | { |
1317 | 3.10M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
1318 | 3.10M | const AV1RawSequenceHeader *seq; |
1319 | 3.10M | int id_len, diff_len, all_frames, frame_is_intra, order_hint_bits; |
1320 | 3.10M | int i, err; |
1321 | | |
1322 | 3.10M | if (!priv->sequence_header) { |
1323 | 202k | av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: " |
1324 | 202k | "unable to decode frame header.\n"); |
1325 | 202k | return AVERROR_INVALIDDATA; |
1326 | 202k | } |
1327 | 2.90M | seq = priv->sequence_header; |
1328 | | |
1329 | 2.90M | id_len = seq->additional_frame_id_length_minus_1 + |
1330 | 2.90M | seq->delta_frame_id_length_minus_2 + 3; |
1331 | 2.90M | all_frames = (1 << AV1_NUM_REF_FRAMES) - 1; |
1332 | | |
1333 | 2.90M | if (seq->reduced_still_picture_header) { |
1334 | 604k | infer(show_existing_frame, 0); |
1335 | 603k | infer(frame_type, AV1_FRAME_KEY); |
1336 | 603k | infer(show_frame, 1); |
1337 | 603k | infer(showable_frame, 0); |
1338 | 104k | frame_is_intra = 1; |
1339 | | |
1340 | 2.29M | } else { |
1341 | 2.29M | flag(show_existing_frame); |
1342 | | |
1343 | 2.28M | if (current->show_existing_frame) { |
1344 | 321k | AV1ReferenceFrameState *ref; |
1345 | | |
1346 | 321k | fb(3, frame_to_show_map_idx); |
1347 | 321k | ref = &priv->ref[current->frame_to_show_map_idx]; |
1348 | | |
1349 | 321k | if (!ref->valid) { |
1350 | 23.2k | av_log(ctx->log_ctx, AV_LOG_ERROR, "Missing reference frame needed for " |
1351 | 23.2k | "show_existing_frame (frame_to_show_map_idx = %d).\n", |
1352 | 23.2k | current->frame_to_show_map_idx); |
1353 | 23.2k | return AVERROR_INVALIDDATA; |
1354 | 23.2k | } |
1355 | | |
1356 | 298k | if (seq->decoder_model_info_present_flag && |
1357 | 34.0k | !seq->timing_info.equal_picture_interval) { |
1358 | 24.9k | fb(seq->decoder_model_info.frame_presentation_time_length_minus_1 + 1, |
1359 | 24.9k | frame_presentation_time); |
1360 | 24.9k | } |
1361 | | |
1362 | 295k | if (seq->frame_id_numbers_present_flag) |
1363 | 34.1k | fb(id_len, display_frame_id); |
1364 | | |
1365 | 291k | infer(frame_type, ref->frame_type); |
1366 | 290k | if (current->frame_type == AV1_FRAME_KEY) { |
1367 | 254k | infer(refresh_frame_flags, all_frames); |
1368 | | |
1369 | | // Section 7.21 |
1370 | 254k | infer(current_frame_id, ref->frame_id); |
1371 | 4.54k | priv->upscaled_width = ref->upscaled_width; |
1372 | 4.54k | priv->frame_width = ref->frame_width; |
1373 | 4.54k | priv->frame_height = ref->frame_height; |
1374 | 4.54k | priv->render_width = ref->render_width; |
1375 | 4.54k | priv->render_height = ref->render_height; |
1376 | 4.54k | priv->bit_depth = ref->bit_depth; |
1377 | 4.54k | priv->order_hint = ref->order_hint; |
1378 | | |
1379 | 4.54k | memcpy(priv->loop_filter_ref_deltas, ref->loop_filter_ref_deltas, |
1380 | 4.54k | sizeof(ref->loop_filter_ref_deltas)); |
1381 | 4.54k | memcpy(priv->loop_filter_mode_deltas, ref->loop_filter_mode_deltas, |
1382 | 4.54k | sizeof(ref->loop_filter_mode_deltas)); |
1383 | 4.54k | memcpy(priv->feature_enabled, ref->feature_enabled, |
1384 | 4.54k | sizeof(ref->feature_enabled)); |
1385 | 4.54k | memcpy(priv->feature_value, ref->feature_value, |
1386 | 4.54k | sizeof(ref->feature_value)); |
1387 | 4.54k | } else |
1388 | 36.3k | infer(refresh_frame_flags, 0); |
1389 | | |
1390 | 290k | infer(frame_width_minus_1, ref->upscaled_width - 1); |
1391 | 289k | infer(frame_height_minus_1, ref->frame_height - 1); |
1392 | 289k | infer(render_width_minus_1, ref->render_width - 1); |
1393 | 288k | infer(render_height_minus_1, ref->render_height - 1); |
1394 | | |
1395 | | // Section 7.20 |
1396 | 8.48k | goto update_refs; |
1397 | 8.96k | } |
1398 | | |
1399 | 1.96M | fb(2, frame_type); |
1400 | 1.96M | frame_is_intra = (current->frame_type == AV1_FRAME_INTRA_ONLY || |
1401 | 1.88M | current->frame_type == AV1_FRAME_KEY); |
1402 | | |
1403 | 1.96M | flag(show_frame); |
1404 | 1.96M | if (current->show_frame && |
1405 | 1.51M | seq->decoder_model_info_present_flag && |
1406 | 651k | !seq->timing_info.equal_picture_interval) { |
1407 | 502k | fb(seq->decoder_model_info.frame_presentation_time_length_minus_1 + 1, |
1408 | 502k | frame_presentation_time); |
1409 | 502k | } |
1410 | 1.95M | if (current->show_frame) |
1411 | 1.50M | infer(showable_frame, current->frame_type != AV1_FRAME_KEY); |
1412 | 454k | else |
1413 | 1.95M | flag(showable_frame); |
1414 | | |
1415 | 1.95M | if (current->frame_type == AV1_FRAME_SWITCH || |
1416 | 1.77M | (current->frame_type == AV1_FRAME_KEY && current->show_frame)) |
1417 | 465k | infer(error_resilient_mode, 1); |
1418 | 1.49M | else |
1419 | 1.95M | flag(error_resilient_mode); |
1420 | 1.95M | } |
1421 | | |
1422 | 2.55M | if (current->frame_type == AV1_FRAME_KEY && current->show_frame) { |
1423 | 7.97M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { |
1424 | 7.08M | priv->ref[i].valid = 0; |
1425 | 7.08M | priv->ref[i].order_hint = 0; |
1426 | 7.08M | } |
1427 | 7.08M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) |
1428 | 6.20M | priv->order_hints[i + AV1_REF_FRAME_LAST] = 0; |
1429 | 885k | } |
1430 | | |
1431 | 2.55M | flag(disable_cdf_update); |
1432 | | |
1433 | 2.54M | if (seq->seq_force_screen_content_tools == |
1434 | 2.54M | AV1_SELECT_SCREEN_CONTENT_TOOLS) { |
1435 | 1.35M | flag(allow_screen_content_tools); |
1436 | 1.35M | } else { |
1437 | 1.19M | infer(allow_screen_content_tools, |
1438 | 1.19M | seq->seq_force_screen_content_tools); |
1439 | 1.19M | } |
1440 | 2.54M | if (current->allow_screen_content_tools) { |
1441 | 897k | if (seq->seq_force_integer_mv == AV1_SELECT_INTEGER_MV) |
1442 | 897k | flag(force_integer_mv); |
1443 | 497k | else |
1444 | 497k | infer(force_integer_mv, seq->seq_force_integer_mv); |
1445 | 1.64M | } else { |
1446 | 1.64M | infer(force_integer_mv, 0); |
1447 | 1.64M | } |
1448 | | |
1449 | 2.53M | if (seq->frame_id_numbers_present_flag) { |
1450 | 676k | fb(id_len, current_frame_id); |
1451 | | |
1452 | 662k | diff_len = seq->delta_frame_id_length_minus_2 + 2; |
1453 | 5.96M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { |
1454 | 5.30M | if (current->current_frame_id > (1 << diff_len)) { |
1455 | 3.32M | if (priv->ref[i].frame_id > current->current_frame_id || |
1456 | 3.01M | priv->ref[i].frame_id < (current->current_frame_id - |
1457 | 3.01M | (1 << diff_len))) |
1458 | 2.56M | priv->ref[i].valid = 0; |
1459 | 3.32M | } else { |
1460 | 1.97M | if (priv->ref[i].frame_id > current->current_frame_id && |
1461 | 456k | priv->ref[i].frame_id < ((1 << id_len) + |
1462 | 456k | current->current_frame_id - |
1463 | 456k | (1 << diff_len))) |
1464 | 330k | priv->ref[i].valid = 0; |
1465 | 1.97M | } |
1466 | 5.30M | } |
1467 | 1.86M | } else { |
1468 | 1.86M | infer(current_frame_id, 0); |
1469 | 1.86M | } |
1470 | | |
1471 | 2.52M | if (current->frame_type == AV1_FRAME_SWITCH) |
1472 | 178k | infer(frame_size_override_flag, 1); |
1473 | 2.34M | else if(seq->reduced_still_picture_header) |
1474 | 597k | infer(frame_size_override_flag, 0); |
1475 | 1.74M | else |
1476 | 1.74M | flag(frame_size_override_flag); |
1477 | | |
1478 | 2.51M | order_hint_bits = |
1479 | 2.51M | seq->enable_order_hint ? seq->order_hint_bits_minus_1 + 1 : 0; |
1480 | 2.51M | if (order_hint_bits > 0) |
1481 | 1.11M | fb(order_hint_bits, order_hint); |
1482 | 1.40M | else |
1483 | 1.40M | infer(order_hint, 0); |
1484 | 2.51M | priv->order_hint = current->order_hint; |
1485 | | |
1486 | 2.51M | if (frame_is_intra || current->error_resilient_mode) |
1487 | 1.44M | infer(primary_ref_frame, AV1_PRIMARY_REF_NONE); |
1488 | 1.06M | else |
1489 | 1.06M | fb(3, primary_ref_frame); |
1490 | | |
1491 | 2.50M | if (seq->decoder_model_info_present_flag) { |
1492 | 696k | flag(buffer_removal_time_present_flag); |
1493 | 691k | if (current->buffer_removal_time_present_flag) { |
1494 | 2.81M | for (i = 0; i <= seq->operating_points_cnt_minus_1; i++) { |
1495 | 2.56M | if (seq->decoder_model_present_for_this_op[i]) { |
1496 | 856k | int op_pt_idc = seq->operating_point_idc[i]; |
1497 | 856k | int in_temporal_layer = (op_pt_idc >> priv->temporal_id ) & 1; |
1498 | 856k | int in_spatial_layer = (op_pt_idc >> (priv->spatial_id + 8)) & 1; |
1499 | 856k | if (seq->operating_point_idc[i] == 0 || |
1500 | 733k | (in_temporal_layer && in_spatial_layer)) { |
1501 | 372k | fbs(seq->decoder_model_info.buffer_removal_time_length_minus_1 + 1, |
1502 | 372k | buffer_removal_time[i], 1, i); |
1503 | 372k | } |
1504 | 856k | } |
1505 | 2.56M | } |
1506 | 257k | } |
1507 | 691k | } |
1508 | | |
1509 | 2.48M | if (current->frame_type == AV1_FRAME_SWITCH || |
1510 | 2.31M | (current->frame_type == AV1_FRAME_KEY && current->show_frame)) |
1511 | 1.04M | infer(refresh_frame_flags, all_frames); |
1512 | 1.44M | else |
1513 | 1.44M | fb(8, refresh_frame_flags); |
1514 | | |
1515 | 2.46M | if (!frame_is_intra || current->refresh_frame_flags != all_frames) { |
1516 | 1.59M | if (seq->enable_order_hint) { |
1517 | 8.76M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { |
1518 | 7.79M | if (current->error_resilient_mode) |
1519 | 7.79M | fbs(order_hint_bits, ref_order_hint[i], 1, i); |
1520 | 6.30M | else |
1521 | 6.30M | infer(ref_order_hint[i], priv->ref[i].order_hint); |
1522 | 7.78M | if (current->ref_order_hint[i] != priv->ref[i].order_hint) |
1523 | 1.12M | priv->ref[i].valid = 0; |
1524 | 7.78M | } |
1525 | 978k | } |
1526 | 1.59M | } |
1527 | | |
1528 | 2.45M | if (current->frame_type == AV1_FRAME_KEY || |
1529 | 1.41M | current->frame_type == AV1_FRAME_INTRA_ONLY) { |
1530 | 1.11M | CHECK(FUNC(frame_size)(ctx, rw, current)); |
1531 | 1.09M | CHECK(FUNC(render_size)(ctx, rw, current)); |
1532 | | |
1533 | 1.06M | if (current->allow_screen_content_tools && |
1534 | 267k | priv->upscaled_width == priv->frame_width) |
1535 | 1.06M | flag(allow_intrabc); |
1536 | 844k | else |
1537 | 844k | infer(allow_intrabc, 0); |
1538 | | |
1539 | 1.34M | } else { |
1540 | 1.34M | if (!seq->enable_order_hint) { |
1541 | 498k | infer(frame_refs_short_signaling, 0); |
1542 | 846k | } else { |
1543 | 846k | flag(frame_refs_short_signaling); |
1544 | 842k | if (current->frame_refs_short_signaling) { |
1545 | 577k | fb(3, last_frame_idx); |
1546 | 572k | fb(3, golden_frame_idx); |
1547 | 568k | CHECK(FUNC(set_frame_refs)(ctx, rw, current)); |
1548 | 568k | } |
1549 | 842k | } |
1550 | | |
1551 | 10.2M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { |
1552 | 9.04M | if (!current->frame_refs_short_signaling) |
1553 | 9.04M | fbs(3, ref_frame_idx[i], 1, i); |
1554 | 9.00M | if (seq->frame_id_numbers_present_flag) { |
1555 | 2.62M | fbs(seq->delta_frame_id_length_minus_2 + 2, |
1556 | 2.62M | delta_frame_id_minus1[i], 1, i); |
1557 | 2.62M | } |
1558 | 9.00M | } |
1559 | | |
1560 | 1.25M | if (current->frame_size_override_flag && |
1561 | 441k | !current->error_resilient_mode) { |
1562 | 229k | CHECK(FUNC(frame_size_with_refs)(ctx, rw, current)); |
1563 | 1.02M | } else { |
1564 | 1.02M | CHECK(FUNC(frame_size)(ctx, rw, current)); |
1565 | 1.00M | CHECK(FUNC(render_size)(ctx, rw, current)); |
1566 | 1.00M | } |
1567 | | |
1568 | 1.13M | if (current->force_integer_mv) |
1569 | 182k | infer(allow_high_precision_mv, 0); |
1570 | 952k | else |
1571 | 1.13M | flag(allow_high_precision_mv); |
1572 | | |
1573 | 1.12M | CHECK(FUNC(interpolation_filter)(ctx, rw, current)); |
1574 | | |
1575 | 1.11M | flag(is_motion_mode_switchable); |
1576 | | |
1577 | 1.10M | if (current->error_resilient_mode || |
1578 | 849k | !seq->enable_ref_frame_mvs) |
1579 | 859k | infer(use_ref_frame_mvs, 0); |
1580 | 241k | else |
1581 | 1.10M | flag(use_ref_frame_mvs); |
1582 | | |
1583 | 8.77M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { |
1584 | 7.67M | int ref_frame = AV1_REF_FRAME_LAST + i; |
1585 | 7.67M | int hint = priv->ref[current->ref_frame_idx[i]].order_hint; |
1586 | 7.67M | priv->order_hints[ref_frame] = hint; |
1587 | 7.67M | if (!seq->enable_order_hint) { |
1588 | 2.74M | priv->ref_frame_sign_bias[ref_frame] = 0; |
1589 | 4.93M | } else { |
1590 | 4.93M | priv->ref_frame_sign_bias[ref_frame] = |
1591 | 4.93M | cbs_av1_get_relative_dist(seq, hint, |
1592 | 4.93M | current->order_hint) > 0; |
1593 | 4.93M | } |
1594 | 7.67M | } |
1595 | | |
1596 | 1.09M | infer(allow_intrabc, 0); |
1597 | 1.09M | } |
1598 | | |
1599 | 2.16M | if (seq->reduced_still_picture_header || current->disable_cdf_update) |
1600 | 999k | infer(disable_frame_end_update_cdf, 1); |
1601 | 1.16M | else |
1602 | 2.16M | flag(disable_frame_end_update_cdf); |
1603 | | |
1604 | 2.15M | if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { |
1605 | | // Init non-coeff CDFs. |
1606 | | // Setup past independence. |
1607 | 1.37M | } else { |
1608 | | // Load CDF tables from previous frame. |
1609 | | // Load params from previous frame. |
1610 | 781k | } |
1611 | | |
1612 | 2.15M | if (current->use_ref_frame_mvs) { |
1613 | | // Perform motion field estimation process. |
1614 | 84.0k | } |
1615 | | |
1616 | 2.15M | CHECK(FUNC(tile_info)(ctx, rw, current)); |
1617 | | |
1618 | 2.05M | CHECK(FUNC(quantization_params)(ctx, rw, current)); |
1619 | | |
1620 | 1.88M | CHECK(FUNC(segmentation_params)(ctx, rw, current)); |
1621 | | |
1622 | 1.77M | CHECK(FUNC(delta_q_params)(ctx, rw, current)); |
1623 | | |
1624 | 1.76M | CHECK(FUNC(delta_lf_params)(ctx, rw, current)); |
1625 | | |
1626 | | // Init coeff CDFs / load previous segments. |
1627 | | |
1628 | 1.74M | priv->coded_lossless = 1; |
1629 | 15.7M | for (i = 0; i < AV1_MAX_SEGMENTS; i++) { |
1630 | 13.9M | int qindex; |
1631 | 13.9M | if (current->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) { |
1632 | 274k | qindex = (current->base_q_idx + |
1633 | 274k | current->feature_value[i][AV1_SEG_LVL_ALT_Q]); |
1634 | 13.7M | } else { |
1635 | 13.7M | qindex = current->base_q_idx; |
1636 | 13.7M | } |
1637 | 13.9M | qindex = av_clip_uintp2(qindex, 8); |
1638 | | |
1639 | 13.9M | if (qindex || current->delta_q_y_dc || |
1640 | 3.57M | current->delta_q_u_ac || current->delta_q_u_dc || |
1641 | 10.8M | current->delta_q_v_ac || current->delta_q_v_dc) { |
1642 | 10.8M | priv->coded_lossless = 0; |
1643 | 10.8M | } |
1644 | 13.9M | } |
1645 | 1.74M | priv->all_lossless = priv->coded_lossless && |
1646 | 388k | priv->frame_width == priv->upscaled_width; |
1647 | | |
1648 | 1.74M | CHECK(FUNC(loop_filter_params)(ctx, rw, current)); |
1649 | | |
1650 | 1.60M | CHECK(FUNC(cdef_params)(ctx, rw, current)); |
1651 | | |
1652 | 1.54M | CHECK(FUNC(lr_params)(ctx, rw, current)); |
1653 | | |
1654 | 1.51M | CHECK(FUNC(read_tx_mode)(ctx, rw, current)); |
1655 | | |
1656 | 1.50M | CHECK(FUNC(frame_reference_mode)(ctx, rw, current)); |
1657 | | |
1658 | 1.50M | CHECK(FUNC(skip_mode_params)(ctx, rw, current)); |
1659 | | |
1660 | 1.50M | if (frame_is_intra || current->error_resilient_mode || |
1661 | 595k | !seq->enable_warped_motion) |
1662 | 1.13M | infer(allow_warped_motion, 0); |
1663 | 365k | else |
1664 | 1.50M | flag(allow_warped_motion); |
1665 | | |
1666 | 1.49M | flag(reduced_tx_set); |
1667 | | |
1668 | 1.48M | CHECK(FUNC(global_motion_params)(ctx, rw, current)); |
1669 | | |
1670 | 1.34M | CHECK(FUNC(film_grain_params)(ctx, rw, ¤t->film_grain, current)); |
1671 | | |
1672 | 1.12M | av_log(ctx->log_ctx, AV_LOG_DEBUG, "Frame %d: size %dx%d " |
1673 | 1.12M | "upscaled %d render %dx%d subsample %dx%d " |
1674 | 1.12M | "bitdepth %d tiles %dx%d.\n", priv->order_hint, |
1675 | 1.12M | priv->frame_width, priv->frame_height, priv->upscaled_width, |
1676 | 1.12M | priv->render_width, priv->render_height, |
1677 | 1.12M | seq->color_config.subsampling_x + 1, |
1678 | 1.12M | seq->color_config.subsampling_y + 1, priv->bit_depth, |
1679 | 1.12M | priv->tile_rows, priv->tile_cols); |
1680 | | |
1681 | 1.41M | update_refs: |
1682 | 12.7M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { |
1683 | 11.3M | if (current->refresh_frame_flags & (1 << i)) { |
1684 | 7.71M | priv->ref[i] = (AV1ReferenceFrameState) { |
1685 | 7.71M | .valid = 1, |
1686 | 7.71M | .frame_id = current->current_frame_id, |
1687 | 7.71M | .upscaled_width = priv->upscaled_width, |
1688 | 7.71M | .frame_width = priv->frame_width, |
1689 | 7.71M | .frame_height = priv->frame_height, |
1690 | 7.71M | .render_width = priv->render_width, |
1691 | 7.71M | .render_height = priv->render_height, |
1692 | 7.71M | .frame_type = current->frame_type, |
1693 | 7.71M | .subsampling_x = seq->color_config.subsampling_x, |
1694 | 7.71M | .subsampling_y = seq->color_config.subsampling_y, |
1695 | 7.71M | .bit_depth = priv->bit_depth, |
1696 | 7.71M | .order_hint = priv->order_hint, |
1697 | 7.71M | }; |
1698 | | |
1699 | 61.6M | for (int j = 0; j < AV1_REFS_PER_FRAME; j++) { |
1700 | 53.9M | priv->ref[i].saved_order_hints[j + AV1_REF_FRAME_LAST] = |
1701 | 53.9M | priv->order_hints[j + AV1_REF_FRAME_LAST]; |
1702 | 53.9M | } |
1703 | | |
1704 | 7.71M | if (current->show_existing_frame) { |
1705 | 2.02M | memcpy(priv->ref[i].loop_filter_ref_deltas, priv->loop_filter_ref_deltas, |
1706 | 2.02M | sizeof(priv->loop_filter_ref_deltas)); |
1707 | 2.02M | memcpy(priv->ref[i].loop_filter_mode_deltas, priv->loop_filter_mode_deltas, |
1708 | 2.02M | sizeof(priv->loop_filter_mode_deltas)); |
1709 | 2.02M | memcpy(priv->ref[i].feature_enabled, priv->feature_enabled, |
1710 | 2.02M | sizeof(priv->feature_enabled)); |
1711 | 2.02M | memcpy(priv->ref[i].feature_value, priv->feature_value, |
1712 | 2.02M | sizeof(priv->feature_value)); |
1713 | 5.68M | } else { |
1714 | 5.68M | memcpy(priv->ref[i].loop_filter_ref_deltas, current->loop_filter_ref_deltas, |
1715 | 5.68M | sizeof(current->loop_filter_ref_deltas)); |
1716 | 5.68M | memcpy(priv->ref[i].loop_filter_mode_deltas, current->loop_filter_mode_deltas, |
1717 | 5.68M | sizeof(current->loop_filter_mode_deltas)); |
1718 | 5.68M | memcpy(priv->ref[i].feature_enabled, current->feature_enabled, |
1719 | 5.68M | sizeof(current->feature_enabled)); |
1720 | 5.68M | memcpy(priv->ref[i].feature_value, current->feature_value, |
1721 | 5.68M | sizeof(current->feature_value)); |
1722 | 5.68M | } |
1723 | 7.71M | } |
1724 | 11.3M | } |
1725 | | |
1726 | 1.41M | return 0; |
1727 | 1.12M | } cbs_av1.c:cbs_av1_read_uncompressed_header Line | Count | Source | 1316 | 2.77M | { | 1317 | 2.77M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1318 | 2.77M | const AV1RawSequenceHeader *seq; | 1319 | 2.77M | int id_len, diff_len, all_frames, frame_is_intra, order_hint_bits; | 1320 | 2.77M | int i, err; | 1321 | | | 1322 | 2.77M | if (!priv->sequence_header) { | 1323 | 200k | av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: " | 1324 | 200k | "unable to decode frame header.\n"); | 1325 | 200k | return AVERROR_INVALIDDATA; | 1326 | 200k | } | 1327 | 2.57M | seq = priv->sequence_header; | 1328 | | | 1329 | 2.57M | id_len = seq->additional_frame_id_length_minus_1 + | 1330 | 2.57M | seq->delta_frame_id_length_minus_2 + 3; | 1331 | 2.57M | all_frames = (1 << AV1_NUM_REF_FRAMES) - 1; | 1332 | | | 1333 | 2.57M | if (seq->reduced_still_picture_header) { | 1334 | 498k | infer(show_existing_frame, 0); | 1335 | 498k | infer(frame_type, AV1_FRAME_KEY); | 1336 | 498k | infer(show_frame, 1); | 1337 | 498k | infer(showable_frame, 0); | 1338 | 498k | frame_is_intra = 1; | 1339 | | | 1340 | 2.07M | } else { | 1341 | 2.07M | flag(show_existing_frame); | 1342 | | | 1343 | 2.06M | if (current->show_existing_frame) { | 1344 | 308k | AV1ReferenceFrameState *ref; | 1345 | | | 1346 | 308k | fb(3, frame_to_show_map_idx); | 1347 | 308k | ref = &priv->ref[current->frame_to_show_map_idx]; | 1348 | | | 1349 | 308k | if (!ref->valid) { | 1350 | 22.7k | av_log(ctx->log_ctx, AV_LOG_ERROR, "Missing reference frame needed for " | 1351 | 22.7k | "show_existing_frame (frame_to_show_map_idx = %d).\n", | 1352 | 22.7k | current->frame_to_show_map_idx); | 1353 | 22.7k | return AVERROR_INVALIDDATA; | 1354 | 22.7k | } | 1355 | | | 1356 | 286k | if (seq->decoder_model_info_present_flag && | 1357 | 29.5k | !seq->timing_info.equal_picture_interval) { | 1358 | 21.7k | fb(seq->decoder_model_info.frame_presentation_time_length_minus_1 + 1, | 1359 | 21.7k | frame_presentation_time); | 1360 | 21.7k | } | 1361 | | | 1362 | 283k | if (seq->frame_id_numbers_present_flag) | 1363 | 28.8k | fb(id_len, display_frame_id); | 1364 | | | 1365 | 279k | infer(frame_type, ref->frame_type); | 1366 | 279k | if (current->frame_type == AV1_FRAME_KEY) { | 1367 | 249k | infer(refresh_frame_flags, all_frames); | 1368 | | | 1369 | | // Section 7.21 | 1370 | 249k | infer(current_frame_id, ref->frame_id); | 1371 | 249k | priv->upscaled_width = ref->upscaled_width; | 1372 | 249k | priv->frame_width = ref->frame_width; | 1373 | 249k | priv->frame_height = ref->frame_height; | 1374 | 249k | priv->render_width = ref->render_width; | 1375 | 249k | priv->render_height = ref->render_height; | 1376 | 249k | priv->bit_depth = ref->bit_depth; | 1377 | 249k | priv->order_hint = ref->order_hint; | 1378 | | | 1379 | 249k | memcpy(priv->loop_filter_ref_deltas, ref->loop_filter_ref_deltas, | 1380 | 249k | sizeof(ref->loop_filter_ref_deltas)); | 1381 | 249k | memcpy(priv->loop_filter_mode_deltas, ref->loop_filter_mode_deltas, | 1382 | 249k | sizeof(ref->loop_filter_mode_deltas)); | 1383 | 249k | memcpy(priv->feature_enabled, ref->feature_enabled, | 1384 | 249k | sizeof(ref->feature_enabled)); | 1385 | 249k | memcpy(priv->feature_value, ref->feature_value, | 1386 | 249k | sizeof(ref->feature_value)); | 1387 | 249k | } else | 1388 | 30.4k | infer(refresh_frame_flags, 0); | 1389 | | | 1390 | 279k | infer(frame_width_minus_1, ref->upscaled_width - 1); | 1391 | 279k | infer(frame_height_minus_1, ref->frame_height - 1); | 1392 | 279k | infer(render_width_minus_1, ref->render_width - 1); | 1393 | 279k | infer(render_height_minus_1, ref->render_height - 1); | 1394 | | | 1395 | | // Section 7.20 | 1396 | 279k | goto update_refs; | 1397 | 283k | } | 1398 | | | 1399 | 1.75M | fb(2, frame_type); | 1400 | 1.75M | frame_is_intra = (current->frame_type == AV1_FRAME_INTRA_ONLY || | 1401 | 1.68M | current->frame_type == AV1_FRAME_KEY); | 1402 | | | 1403 | 1.75M | flag(show_frame); | 1404 | 1.75M | if (current->show_frame && | 1405 | 1.36M | seq->decoder_model_info_present_flag && | 1406 | 590k | !seq->timing_info.equal_picture_interval) { | 1407 | 445k | fb(seq->decoder_model_info.frame_presentation_time_length_minus_1 + 1, | 1408 | 445k | frame_presentation_time); | 1409 | 445k | } | 1410 | 1.75M | if (current->show_frame) | 1411 | 1.36M | infer(showable_frame, current->frame_type != AV1_FRAME_KEY); | 1412 | 387k | else | 1413 | 1.75M | flag(showable_frame); | 1414 | | | 1415 | 1.75M | if (current->frame_type == AV1_FRAME_SWITCH || | 1416 | 1.57M | (current->frame_type == AV1_FRAME_KEY && current->show_frame)) | 1417 | 424k | infer(error_resilient_mode, 1); | 1418 | 1.32M | else | 1419 | 1.75M | flag(error_resilient_mode); | 1420 | 1.75M | } | 1421 | | | 1422 | 2.24M | if (current->frame_type == AV1_FRAME_KEY && current->show_frame) { | 1423 | 6.73M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 1424 | 5.98M | priv->ref[i].valid = 0; | 1425 | 5.98M | priv->ref[i].order_hint = 0; | 1426 | 5.98M | } | 1427 | 5.98M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) | 1428 | 5.23M | priv->order_hints[i + AV1_REF_FRAME_LAST] = 0; | 1429 | 747k | } | 1430 | | | 1431 | 2.24M | flag(disable_cdf_update); | 1432 | | | 1433 | 2.23M | if (seq->seq_force_screen_content_tools == | 1434 | 2.23M | AV1_SELECT_SCREEN_CONTENT_TOOLS) { | 1435 | 1.17M | flag(allow_screen_content_tools); | 1436 | 1.17M | } else { | 1437 | 1.05M | infer(allow_screen_content_tools, | 1438 | 1.05M | seq->seq_force_screen_content_tools); | 1439 | 1.05M | } | 1440 | 2.23M | if (current->allow_screen_content_tools) { | 1441 | 778k | if (seq->seq_force_integer_mv == AV1_SELECT_INTEGER_MV) | 1442 | 778k | flag(force_integer_mv); | 1443 | 422k | else | 1444 | 422k | infer(force_integer_mv, seq->seq_force_integer_mv); | 1445 | 1.45M | } else { | 1446 | 1.45M | infer(force_integer_mv, 0); | 1447 | 1.45M | } | 1448 | | | 1449 | 2.22M | if (seq->frame_id_numbers_present_flag) { | 1450 | 610k | fb(id_len, current_frame_id); | 1451 | | | 1452 | 596k | diff_len = seq->delta_frame_id_length_minus_2 + 2; | 1453 | 5.36M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 1454 | 4.77M | if (current->current_frame_id > (1 << diff_len)) { | 1455 | 3.10M | if (priv->ref[i].frame_id > current->current_frame_id || | 1456 | 2.80M | priv->ref[i].frame_id < (current->current_frame_id - | 1457 | 2.80M | (1 << diff_len))) | 1458 | 2.48M | priv->ref[i].valid = 0; | 1459 | 3.10M | } else { | 1460 | 1.67M | if (priv->ref[i].frame_id > current->current_frame_id && | 1461 | 353k | priv->ref[i].frame_id < ((1 << id_len) + | 1462 | 353k | current->current_frame_id - | 1463 | 353k | (1 << diff_len))) | 1464 | 252k | priv->ref[i].valid = 0; | 1465 | 1.67M | } | 1466 | 4.77M | } | 1467 | 1.61M | } else { | 1468 | 1.61M | infer(current_frame_id, 0); | 1469 | 1.61M | } | 1470 | | | 1471 | 2.21M | if (current->frame_type == AV1_FRAME_SWITCH) | 1472 | 170k | infer(frame_size_override_flag, 1); | 1473 | 2.04M | else if(seq->reduced_still_picture_header) | 1474 | 492k | infer(frame_size_override_flag, 0); | 1475 | 1.55M | else | 1476 | 1.55M | flag(frame_size_override_flag); | 1477 | | | 1478 | 2.20M | order_hint_bits = | 1479 | 2.20M | seq->enable_order_hint ? seq->order_hint_bits_minus_1 + 1 : 0; | 1480 | 2.20M | if (order_hint_bits > 0) | 1481 | 959k | fb(order_hint_bits, order_hint); | 1482 | 1.24M | else | 1483 | 1.24M | infer(order_hint, 0); | 1484 | 2.20M | priv->order_hint = current->order_hint; | 1485 | | | 1486 | 2.20M | if (frame_is_intra || current->error_resilient_mode) | 1487 | 1.24M | infer(primary_ref_frame, AV1_PRIMARY_REF_NONE); | 1488 | 951k | else | 1489 | 951k | fb(3, primary_ref_frame); | 1490 | | | 1491 | 2.19M | if (seq->decoder_model_info_present_flag) { | 1492 | 632k | flag(buffer_removal_time_present_flag); | 1493 | 627k | if (current->buffer_removal_time_present_flag) { | 1494 | 2.76M | for (i = 0; i <= seq->operating_points_cnt_minus_1; i++) { | 1495 | 2.52M | if (seq->decoder_model_present_for_this_op[i]) { | 1496 | 836k | int op_pt_idc = seq->operating_point_idc[i]; | 1497 | 836k | int in_temporal_layer = (op_pt_idc >> priv->temporal_id ) & 1; | 1498 | 836k | int in_spatial_layer = (op_pt_idc >> (priv->spatial_id + 8)) & 1; | 1499 | 836k | if (seq->operating_point_idc[i] == 0 || | 1500 | 716k | (in_temporal_layer && in_spatial_layer)) { | 1501 | 361k | fbs(seq->decoder_model_info.buffer_removal_time_length_minus_1 + 1, | 1502 | 361k | buffer_removal_time[i], 1, i); | 1503 | 361k | } | 1504 | 836k | } | 1505 | 2.52M | } | 1506 | 247k | } | 1507 | 627k | } | 1508 | | | 1509 | 2.17M | if (current->frame_type == AV1_FRAME_SWITCH || | 1510 | 2.01M | (current->frame_type == AV1_FRAME_KEY && current->show_frame)) | 1511 | 896k | infer(refresh_frame_flags, all_frames); | 1512 | 1.28M | else | 1513 | 1.28M | fb(8, refresh_frame_flags); | 1514 | | | 1515 | 2.15M | if (!frame_is_intra || current->refresh_frame_flags != all_frames) { | 1516 | 1.42M | if (seq->enable_order_hint) { | 1517 | 7.54M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 1518 | 6.71M | if (current->error_resilient_mode) | 1519 | 6.71M | fbs(order_hint_bits, ref_order_hint[i], 1, i); | 1520 | 5.36M | else | 1521 | 5.36M | infer(ref_order_hint[i], priv->ref[i].order_hint); | 1522 | 6.70M | if (current->ref_order_hint[i] != priv->ref[i].order_hint) | 1523 | 1.04M | priv->ref[i].valid = 0; | 1524 | 6.70M | } | 1525 | 842k | } | 1526 | 1.42M | } | 1527 | | | 1528 | 2.14M | if (current->frame_type == AV1_FRAME_KEY || | 1529 | 1.27M | current->frame_type == AV1_FRAME_INTRA_ONLY) { | 1530 | 937k | CHECK(FUNC(frame_size)(ctx, rw, current)); | 1531 | 922k | CHECK(FUNC(render_size)(ctx, rw, current)); | 1532 | | | 1533 | 896k | if (current->allow_screen_content_tools && | 1534 | 230k | priv->upscaled_width == priv->frame_width) | 1535 | 896k | flag(allow_intrabc); | 1536 | 706k | else | 1537 | 706k | infer(allow_intrabc, 0); | 1538 | | | 1539 | 1.21M | } else { | 1540 | 1.21M | if (!seq->enable_order_hint) { | 1541 | 476k | infer(frame_refs_short_signaling, 0); | 1542 | 733k | } else { | 1543 | 733k | flag(frame_refs_short_signaling); | 1544 | 729k | if (current->frame_refs_short_signaling) { | 1545 | 480k | fb(3, last_frame_idx); | 1546 | 476k | fb(3, golden_frame_idx); | 1547 | 472k | CHECK(FUNC(set_frame_refs)(ctx, rw, current)); | 1548 | 472k | } | 1549 | 729k | } | 1550 | | | 1551 | 9.22M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { | 1552 | 8.10M | if (!current->frame_refs_short_signaling) | 1553 | 8.10M | fbs(3, ref_frame_idx[i], 1, i); | 1554 | 8.06M | if (seq->frame_id_numbers_present_flag) { | 1555 | 2.46M | fbs(seq->delta_frame_id_length_minus_2 + 2, | 1556 | 2.46M | delta_frame_id_minus1[i], 1, i); | 1557 | 2.46M | } | 1558 | 8.06M | } | 1559 | | | 1560 | 1.11M | if (current->frame_size_override_flag && | 1561 | 400k | !current->error_resilient_mode) { | 1562 | 199k | CHECK(FUNC(frame_size_with_refs)(ctx, rw, current)); | 1563 | 917k | } else { | 1564 | 917k | CHECK(FUNC(frame_size)(ctx, rw, current)); | 1565 | 906k | CHECK(FUNC(render_size)(ctx, rw, current)); | 1566 | 906k | } | 1567 | | | 1568 | 1.00M | if (current->force_integer_mv) | 1569 | 159k | infer(allow_high_precision_mv, 0); | 1570 | 846k | else | 1571 | 1.00M | flag(allow_high_precision_mv); | 1572 | | | 1573 | 997k | CHECK(FUNC(interpolation_filter)(ctx, rw, current)); | 1574 | | | 1575 | 982k | flag(is_motion_mode_switchable); | 1576 | | | 1577 | 972k | if (current->error_resilient_mode || | 1578 | 739k | !seq->enable_ref_frame_mvs) | 1579 | 766k | infer(use_ref_frame_mvs, 0); | 1580 | 205k | else | 1581 | 972k | flag(use_ref_frame_mvs); | 1582 | | | 1583 | 7.74M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { | 1584 | 6.77M | int ref_frame = AV1_REF_FRAME_LAST + i; | 1585 | 6.77M | int hint = priv->ref[current->ref_frame_idx[i]].order_hint; | 1586 | 6.77M | priv->order_hints[ref_frame] = hint; | 1587 | 6.77M | if (!seq->enable_order_hint) { | 1588 | 2.60M | priv->ref_frame_sign_bias[ref_frame] = 0; | 1589 | 4.16M | } else { | 1590 | 4.16M | priv->ref_frame_sign_bias[ref_frame] = | 1591 | 4.16M | cbs_av1_get_relative_dist(seq, hint, | 1592 | 4.16M | current->order_hint) > 0; | 1593 | 4.16M | } | 1594 | 6.77M | } | 1595 | | | 1596 | 967k | infer(allow_intrabc, 0); | 1597 | 967k | } | 1598 | | | 1599 | 1.86M | if (seq->reduced_still_picture_header || current->disable_cdf_update) | 1600 | 852k | infer(disable_frame_end_update_cdf, 1); | 1601 | 1.00M | else | 1602 | 1.86M | flag(disable_frame_end_update_cdf); | 1603 | | | 1604 | 1.85M | if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { | 1605 | | // Init non-coeff CDFs. | 1606 | | // Setup past independence. | 1607 | 1.17M | } else { | 1608 | | // Load CDF tables from previous frame. | 1609 | | // Load params from previous frame. | 1610 | 680k | } | 1611 | | | 1612 | 1.85M | if (current->use_ref_frame_mvs) { | 1613 | | // Perform motion field estimation process. | 1614 | 68.1k | } | 1615 | | | 1616 | 1.85M | CHECK(FUNC(tile_info)(ctx, rw, current)); | 1617 | | | 1618 | 1.75M | CHECK(FUNC(quantization_params)(ctx, rw, current)); | 1619 | | | 1620 | 1.59M | CHECK(FUNC(segmentation_params)(ctx, rw, current)); | 1621 | | | 1622 | 1.48M | CHECK(FUNC(delta_q_params)(ctx, rw, current)); | 1623 | | | 1624 | 1.46M | CHECK(FUNC(delta_lf_params)(ctx, rw, current)); | 1625 | | | 1626 | | // Init coeff CDFs / load previous segments. | 1627 | | | 1628 | 1.45M | priv->coded_lossless = 1; | 1629 | 13.0M | for (i = 0; i < AV1_MAX_SEGMENTS; i++) { | 1630 | 11.6M | int qindex; | 1631 | 11.6M | if (current->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) { | 1632 | 242k | qindex = (current->base_q_idx + | 1633 | 242k | current->feature_value[i][AV1_SEG_LVL_ALT_Q]); | 1634 | 11.3M | } else { | 1635 | 11.3M | qindex = current->base_q_idx; | 1636 | 11.3M | } | 1637 | 11.6M | qindex = av_clip_uintp2(qindex, 8); | 1638 | | | 1639 | 11.6M | if (qindex || current->delta_q_y_dc || | 1640 | 2.67M | current->delta_q_u_ac || current->delta_q_u_dc || | 1641 | 9.27M | current->delta_q_v_ac || current->delta_q_v_dc) { | 1642 | 9.27M | priv->coded_lossless = 0; | 1643 | 9.27M | } | 1644 | 11.6M | } | 1645 | 1.45M | priv->all_lossless = priv->coded_lossless && | 1646 | 289k | priv->frame_width == priv->upscaled_width; | 1647 | | | 1648 | 1.45M | CHECK(FUNC(loop_filter_params)(ctx, rw, current)); | 1649 | | | 1650 | 1.30M | CHECK(FUNC(cdef_params)(ctx, rw, current)); | 1651 | | | 1652 | 1.25M | CHECK(FUNC(lr_params)(ctx, rw, current)); | 1653 | | | 1654 | 1.22M | CHECK(FUNC(read_tx_mode)(ctx, rw, current)); | 1655 | | | 1656 | 1.22M | CHECK(FUNC(frame_reference_mode)(ctx, rw, current)); | 1657 | | | 1658 | 1.21M | CHECK(FUNC(skip_mode_params)(ctx, rw, current)); | 1659 | | | 1660 | 1.21M | if (frame_is_intra || current->error_resilient_mode || | 1661 | 488k | !seq->enable_warped_motion) | 1662 | 921k | infer(allow_warped_motion, 0); | 1663 | 290k | else | 1664 | 1.21M | flag(allow_warped_motion); | 1665 | | | 1666 | 1.20M | flag(reduced_tx_set); | 1667 | | | 1668 | 1.19M | CHECK(FUNC(global_motion_params)(ctx, rw, current)); | 1669 | | | 1670 | 1.05M | CHECK(FUNC(film_grain_params)(ctx, rw, ¤t->film_grain, current)); | 1671 | | | 1672 | 838k | av_log(ctx->log_ctx, AV_LOG_DEBUG, "Frame %d: size %dx%d " | 1673 | 838k | "upscaled %d render %dx%d subsample %dx%d " | 1674 | 838k | "bitdepth %d tiles %dx%d.\n", priv->order_hint, | 1675 | 838k | priv->frame_width, priv->frame_height, priv->upscaled_width, | 1676 | 838k | priv->render_width, priv->render_height, | 1677 | 838k | seq->color_config.subsampling_x + 1, | 1678 | 838k | seq->color_config.subsampling_y + 1, priv->bit_depth, | 1679 | 838k | priv->tile_rows, priv->tile_cols); | 1680 | | | 1681 | 1.11M | update_refs: | 1682 | 10.0M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 1683 | 8.94M | if (current->refresh_frame_flags & (1 << i)) { | 1684 | 6.13M | priv->ref[i] = (AV1ReferenceFrameState) { | 1685 | 6.13M | .valid = 1, | 1686 | 6.13M | .frame_id = current->current_frame_id, | 1687 | 6.13M | .upscaled_width = priv->upscaled_width, | 1688 | 6.13M | .frame_width = priv->frame_width, | 1689 | 6.13M | .frame_height = priv->frame_height, | 1690 | 6.13M | .render_width = priv->render_width, | 1691 | 6.13M | .render_height = priv->render_height, | 1692 | 6.13M | .frame_type = current->frame_type, | 1693 | 6.13M | .subsampling_x = seq->color_config.subsampling_x, | 1694 | 6.13M | .subsampling_y = seq->color_config.subsampling_y, | 1695 | 6.13M | .bit_depth = priv->bit_depth, | 1696 | 6.13M | .order_hint = priv->order_hint, | 1697 | 6.13M | }; | 1698 | | | 1699 | 49.0M | for (int j = 0; j < AV1_REFS_PER_FRAME; j++) { | 1700 | 42.9M | priv->ref[i].saved_order_hints[j + AV1_REF_FRAME_LAST] = | 1701 | 42.9M | priv->order_hints[j + AV1_REF_FRAME_LAST]; | 1702 | 42.9M | } | 1703 | | | 1704 | 6.13M | if (current->show_existing_frame) { | 1705 | 1.99M | memcpy(priv->ref[i].loop_filter_ref_deltas, priv->loop_filter_ref_deltas, | 1706 | 1.99M | sizeof(priv->loop_filter_ref_deltas)); | 1707 | 1.99M | memcpy(priv->ref[i].loop_filter_mode_deltas, priv->loop_filter_mode_deltas, | 1708 | 1.99M | sizeof(priv->loop_filter_mode_deltas)); | 1709 | 1.99M | memcpy(priv->ref[i].feature_enabled, priv->feature_enabled, | 1710 | 1.99M | sizeof(priv->feature_enabled)); | 1711 | 1.99M | memcpy(priv->ref[i].feature_value, priv->feature_value, | 1712 | 1.99M | sizeof(priv->feature_value)); | 1713 | 4.14M | } else { | 1714 | 4.14M | memcpy(priv->ref[i].loop_filter_ref_deltas, current->loop_filter_ref_deltas, | 1715 | 4.14M | sizeof(current->loop_filter_ref_deltas)); | 1716 | 4.14M | memcpy(priv->ref[i].loop_filter_mode_deltas, current->loop_filter_mode_deltas, | 1717 | 4.14M | sizeof(current->loop_filter_mode_deltas)); | 1718 | 4.14M | memcpy(priv->ref[i].feature_enabled, current->feature_enabled, | 1719 | 4.14M | sizeof(current->feature_enabled)); | 1720 | 4.14M | memcpy(priv->ref[i].feature_value, current->feature_value, | 1721 | 4.14M | sizeof(current->feature_value)); | 1722 | 4.14M | } | 1723 | 6.13M | } | 1724 | 8.94M | } | 1725 | | | 1726 | 1.11M | return 0; | 1727 | 838k | } |
cbs_av1.c:cbs_av1_write_uncompressed_header Line | Count | Source | 1316 | 331k | { | 1317 | 331k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1318 | 331k | const AV1RawSequenceHeader *seq; | 1319 | 331k | int id_len, diff_len, all_frames, frame_is_intra, order_hint_bits; | 1320 | 331k | int i, err; | 1321 | | | 1322 | 331k | if (!priv->sequence_header) { | 1323 | 2.49k | av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: " | 1324 | 2.49k | "unable to decode frame header.\n"); | 1325 | 2.49k | return AVERROR_INVALIDDATA; | 1326 | 2.49k | } | 1327 | 328k | seq = priv->sequence_header; | 1328 | | | 1329 | 328k | id_len = seq->additional_frame_id_length_minus_1 + | 1330 | 328k | seq->delta_frame_id_length_minus_2 + 3; | 1331 | 328k | all_frames = (1 << AV1_NUM_REF_FRAMES) - 1; | 1332 | | | 1333 | 328k | if (seq->reduced_still_picture_header) { | 1334 | 106k | infer(show_existing_frame, 0); | 1335 | 105k | infer(frame_type, AV1_FRAME_KEY); | 1336 | 105k | infer(show_frame, 1); | 1337 | 104k | infer(showable_frame, 0); | 1338 | 104k | frame_is_intra = 1; | 1339 | | | 1340 | 222k | } else { | 1341 | 222k | flag(show_existing_frame); | 1342 | | | 1343 | 222k | if (current->show_existing_frame) { | 1344 | 12.8k | AV1ReferenceFrameState *ref; | 1345 | | | 1346 | 12.8k | fb(3, frame_to_show_map_idx); | 1347 | 12.8k | ref = &priv->ref[current->frame_to_show_map_idx]; | 1348 | | | 1349 | 12.8k | if (!ref->valid) { | 1350 | 472 | av_log(ctx->log_ctx, AV_LOG_ERROR, "Missing reference frame needed for " | 1351 | 472 | "show_existing_frame (frame_to_show_map_idx = %d).\n", | 1352 | 472 | current->frame_to_show_map_idx); | 1353 | 472 | return AVERROR_INVALIDDATA; | 1354 | 472 | } | 1355 | | | 1356 | 12.3k | if (seq->decoder_model_info_present_flag && | 1357 | 4.50k | !seq->timing_info.equal_picture_interval) { | 1358 | 3.20k | fb(seq->decoder_model_info.frame_presentation_time_length_minus_1 + 1, | 1359 | 3.20k | frame_presentation_time); | 1360 | 3.20k | } | 1361 | | | 1362 | 11.8k | if (seq->frame_id_numbers_present_flag) | 1363 | 5.32k | fb(id_len, display_frame_id); | 1364 | | | 1365 | 11.3k | infer(frame_type, ref->frame_type); | 1366 | 10.9k | if (current->frame_type == AV1_FRAME_KEY) { | 1367 | 5.06k | infer(refresh_frame_flags, all_frames); | 1368 | | | 1369 | | // Section 7.21 | 1370 | 5.06k | infer(current_frame_id, ref->frame_id); | 1371 | 4.54k | priv->upscaled_width = ref->upscaled_width; | 1372 | 4.54k | priv->frame_width = ref->frame_width; | 1373 | 4.54k | priv->frame_height = ref->frame_height; | 1374 | 4.54k | priv->render_width = ref->render_width; | 1375 | 4.54k | priv->render_height = ref->render_height; | 1376 | 4.54k | priv->bit_depth = ref->bit_depth; | 1377 | 4.54k | priv->order_hint = ref->order_hint; | 1378 | | | 1379 | 4.54k | memcpy(priv->loop_filter_ref_deltas, ref->loop_filter_ref_deltas, | 1380 | 4.54k | sizeof(ref->loop_filter_ref_deltas)); | 1381 | 4.54k | memcpy(priv->loop_filter_mode_deltas, ref->loop_filter_mode_deltas, | 1382 | 4.54k | sizeof(ref->loop_filter_mode_deltas)); | 1383 | 4.54k | memcpy(priv->feature_enabled, ref->feature_enabled, | 1384 | 4.54k | sizeof(ref->feature_enabled)); | 1385 | 4.54k | memcpy(priv->feature_value, ref->feature_value, | 1386 | 4.54k | sizeof(ref->feature_value)); | 1387 | 4.54k | } else | 1388 | 5.86k | infer(refresh_frame_flags, 0); | 1389 | | | 1390 | 10.4k | infer(frame_width_minus_1, ref->upscaled_width - 1); | 1391 | 9.90k | infer(frame_height_minus_1, ref->frame_height - 1); | 1392 | 9.45k | infer(render_width_minus_1, ref->render_width - 1); | 1393 | 8.96k | infer(render_height_minus_1, ref->render_height - 1); | 1394 | | | 1395 | | // Section 7.20 | 1396 | 8.48k | goto update_refs; | 1397 | 8.96k | } | 1398 | | | 1399 | 209k | fb(2, frame_type); | 1400 | 209k | frame_is_intra = (current->frame_type == AV1_FRAME_INTRA_ONLY || | 1401 | 200k | current->frame_type == AV1_FRAME_KEY); | 1402 | | | 1403 | 209k | flag(show_frame); | 1404 | 209k | if (current->show_frame && | 1405 | 142k | seq->decoder_model_info_present_flag && | 1406 | 60.9k | !seq->timing_info.equal_picture_interval) { | 1407 | 57.2k | fb(seq->decoder_model_info.frame_presentation_time_length_minus_1 + 1, | 1408 | 57.2k | frame_presentation_time); | 1409 | 57.2k | } | 1410 | 208k | if (current->show_frame) | 1411 | 142k | infer(showable_frame, current->frame_type != AV1_FRAME_KEY); | 1412 | 66.6k | else | 1413 | 208k | flag(showable_frame); | 1414 | | | 1415 | 208k | if (current->frame_type == AV1_FRAME_SWITCH || | 1416 | 200k | (current->frame_type == AV1_FRAME_KEY && current->show_frame)) | 1417 | 41.9k | infer(error_resilient_mode, 1); | 1418 | 166k | else | 1419 | 208k | flag(error_resilient_mode); | 1420 | 208k | } | 1421 | | | 1422 | 313k | if (current->frame_type == AV1_FRAME_KEY && current->show_frame) { | 1423 | 1.24M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 1424 | 1.10M | priv->ref[i].valid = 0; | 1425 | 1.10M | priv->ref[i].order_hint = 0; | 1426 | 1.10M | } | 1427 | 1.10M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) | 1428 | 965k | priv->order_hints[i + AV1_REF_FRAME_LAST] = 0; | 1429 | 137k | } | 1430 | | | 1431 | 313k | flag(disable_cdf_update); | 1432 | | | 1433 | 313k | if (seq->seq_force_screen_content_tools == | 1434 | 313k | AV1_SELECT_SCREEN_CONTENT_TOOLS) { | 1435 | 173k | flag(allow_screen_content_tools); | 1436 | 173k | } else { | 1437 | 140k | infer(allow_screen_content_tools, | 1438 | 140k | seq->seq_force_screen_content_tools); | 1439 | 140k | } | 1440 | 312k | if (current->allow_screen_content_tools) { | 1441 | 118k | if (seq->seq_force_integer_mv == AV1_SELECT_INTEGER_MV) | 1442 | 118k | flag(force_integer_mv); | 1443 | 74.4k | else | 1444 | 74.4k | infer(force_integer_mv, seq->seq_force_integer_mv); | 1445 | 193k | } else { | 1446 | 193k | infer(force_integer_mv, 0); | 1447 | 193k | } | 1448 | | | 1449 | 312k | if (seq->frame_id_numbers_present_flag) { | 1450 | 66.2k | fb(id_len, current_frame_id); | 1451 | | | 1452 | 65.8k | diff_len = seq->delta_frame_id_length_minus_2 + 2; | 1453 | 592k | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 1454 | 527k | if (current->current_frame_id > (1 << diff_len)) { | 1455 | 219k | if (priv->ref[i].frame_id > current->current_frame_id || | 1456 | 204k | priv->ref[i].frame_id < (current->current_frame_id - | 1457 | 204k | (1 << diff_len))) | 1458 | 81.4k | priv->ref[i].valid = 0; | 1459 | 307k | } else { | 1460 | 307k | if (priv->ref[i].frame_id > current->current_frame_id && | 1461 | 103k | priv->ref[i].frame_id < ((1 << id_len) + | 1462 | 103k | current->current_frame_id - | 1463 | 103k | (1 << diff_len))) | 1464 | 78.2k | priv->ref[i].valid = 0; | 1465 | 307k | } | 1466 | 527k | } | 1467 | 246k | } else { | 1468 | 246k | infer(current_frame_id, 0); | 1469 | 246k | } | 1470 | | | 1471 | 311k | if (current->frame_type == AV1_FRAME_SWITCH) | 1472 | 8.33k | infer(frame_size_override_flag, 1); | 1473 | 303k | else if(seq->reduced_still_picture_header) | 1474 | 104k | infer(frame_size_override_flag, 0); | 1475 | 198k | else | 1476 | 198k | flag(frame_size_override_flag); | 1477 | | | 1478 | 311k | order_hint_bits = | 1479 | 311k | seq->enable_order_hint ? seq->order_hint_bits_minus_1 + 1 : 0; | 1480 | 311k | if (order_hint_bits > 0) | 1481 | 159k | fb(order_hint_bits, order_hint); | 1482 | 151k | else | 1483 | 151k | infer(order_hint, 0); | 1484 | 310k | priv->order_hint = current->order_hint; | 1485 | | | 1486 | 310k | if (frame_is_intra || current->error_resilient_mode) | 1487 | 195k | infer(primary_ref_frame, AV1_PRIMARY_REF_NONE); | 1488 | 114k | else | 1489 | 114k | fb(3, primary_ref_frame); | 1490 | | | 1491 | 310k | if (seq->decoder_model_info_present_flag) { | 1492 | 64.2k | flag(buffer_removal_time_present_flag); | 1493 | 64.2k | if (current->buffer_removal_time_present_flag) { | 1494 | 51.5k | for (i = 0; i <= seq->operating_points_cnt_minus_1; i++) { | 1495 | 41.9k | if (seq->decoder_model_present_for_this_op[i]) { | 1496 | 19.6k | int op_pt_idc = seq->operating_point_idc[i]; | 1497 | 19.6k | int in_temporal_layer = (op_pt_idc >> priv->temporal_id ) & 1; | 1498 | 19.6k | int in_spatial_layer = (op_pt_idc >> (priv->spatial_id + 8)) & 1; | 1499 | 19.6k | if (seq->operating_point_idc[i] == 0 || | 1500 | 17.5k | (in_temporal_layer && in_spatial_layer)) { | 1501 | 11.3k | fbs(seq->decoder_model_info.buffer_removal_time_length_minus_1 + 1, | 1502 | 11.3k | buffer_removal_time[i], 1, i); | 1503 | 11.3k | } | 1504 | 19.6k | } | 1505 | 41.9k | } | 1506 | 9.92k | } | 1507 | 64.2k | } | 1508 | | | 1509 | 309k | if (current->frame_type == AV1_FRAME_SWITCH || | 1510 | 301k | (current->frame_type == AV1_FRAME_KEY && current->show_frame)) | 1511 | 144k | infer(refresh_frame_flags, all_frames); | 1512 | 165k | else | 1513 | 165k | fb(8, refresh_frame_flags); | 1514 | | | 1515 | 309k | if (!frame_is_intra || current->refresh_frame_flags != all_frames) { | 1516 | 172k | if (seq->enable_order_hint) { | 1517 | 1.21M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 1518 | 1.08M | if (current->error_resilient_mode) | 1519 | 1.08M | fbs(order_hint_bits, ref_order_hint[i], 1, i); | 1520 | 944k | else | 1521 | 944k | infer(ref_order_hint[i], priv->ref[i].order_hint); | 1522 | 1.08M | if (current->ref_order_hint[i] != priv->ref[i].order_hint) | 1523 | 80.2k | priv->ref[i].valid = 0; | 1524 | 1.08M | } | 1525 | 136k | } | 1526 | 172k | } | 1527 | | | 1528 | 308k | if (current->frame_type == AV1_FRAME_KEY || | 1529 | 174k | current->frame_type == AV1_FRAME_INTRA_ONLY) { | 1530 | 174k | CHECK(FUNC(frame_size)(ctx, rw, current)); | 1531 | 171k | CHECK(FUNC(render_size)(ctx, rw, current)); | 1532 | | | 1533 | 171k | if (current->allow_screen_content_tools && | 1534 | 37.0k | priv->upscaled_width == priv->frame_width) | 1535 | 171k | flag(allow_intrabc); | 1536 | 138k | else | 1537 | 138k | infer(allow_intrabc, 0); | 1538 | | | 1539 | 171k | } else { | 1540 | 134k | if (!seq->enable_order_hint) { | 1541 | 21.8k | infer(frame_refs_short_signaling, 0); | 1542 | 112k | } else { | 1543 | 112k | flag(frame_refs_short_signaling); | 1544 | 112k | if (current->frame_refs_short_signaling) { | 1545 | 96.4k | fb(3, last_frame_idx); | 1546 | 96.4k | fb(3, golden_frame_idx); | 1547 | 96.4k | CHECK(FUNC(set_frame_refs)(ctx, rw, current)); | 1548 | 96.4k | } | 1549 | 112k | } | 1550 | | | 1551 | 1.06M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { | 1552 | 933k | if (!current->frame_refs_short_signaling) | 1553 | 933k | fbs(3, ref_frame_idx[i], 1, i); | 1554 | 933k | if (seq->frame_id_numbers_present_flag) { | 1555 | 154k | fbs(seq->delta_frame_id_length_minus_2 + 2, | 1556 | 154k | delta_frame_id_minus1[i], 1, i); | 1557 | 154k | } | 1558 | 933k | } | 1559 | | | 1560 | 133k | if (current->frame_size_override_flag && | 1561 | 40.3k | !current->error_resilient_mode) { | 1562 | 30.3k | CHECK(FUNC(frame_size_with_refs)(ctx, rw, current)); | 1563 | 102k | } else { | 1564 | 102k | CHECK(FUNC(frame_size)(ctx, rw, current)); | 1565 | 102k | CHECK(FUNC(render_size)(ctx, rw, current)); | 1566 | 102k | } | 1567 | | | 1568 | 129k | if (current->force_integer_mv) | 1569 | 23.2k | infer(allow_high_precision_mv, 0); | 1570 | 106k | else | 1571 | 129k | flag(allow_high_precision_mv); | 1572 | | | 1573 | 129k | CHECK(FUNC(interpolation_filter)(ctx, rw, current)); | 1574 | | | 1575 | 129k | flag(is_motion_mode_switchable); | 1576 | | | 1577 | 129k | if (current->error_resilient_mode || | 1578 | 110k | !seq->enable_ref_frame_mvs) | 1579 | 93.0k | infer(use_ref_frame_mvs, 0); | 1580 | 36.5k | else | 1581 | 129k | flag(use_ref_frame_mvs); | 1582 | | | 1583 | 1.03M | for (i = 0; i < AV1_REFS_PER_FRAME; i++) { | 1584 | 904k | int ref_frame = AV1_REF_FRAME_LAST + i; | 1585 | 904k | int hint = priv->ref[current->ref_frame_idx[i]].order_hint; | 1586 | 904k | priv->order_hints[ref_frame] = hint; | 1587 | 904k | if (!seq->enable_order_hint) { | 1588 | 132k | priv->ref_frame_sign_bias[ref_frame] = 0; | 1589 | 771k | } else { | 1590 | 771k | priv->ref_frame_sign_bias[ref_frame] = | 1591 | 771k | cbs_av1_get_relative_dist(seq, hint, | 1592 | 771k | current->order_hint) > 0; | 1593 | 771k | } | 1594 | 904k | } | 1595 | | | 1596 | 129k | infer(allow_intrabc, 0); | 1597 | 129k | } | 1598 | | | 1599 | 301k | if (seq->reduced_still_picture_header || current->disable_cdf_update) | 1600 | 147k | infer(disable_frame_end_update_cdf, 1); | 1601 | 153k | else | 1602 | 301k | flag(disable_frame_end_update_cdf); | 1603 | | | 1604 | 300k | if (current->primary_ref_frame == AV1_PRIMARY_REF_NONE) { | 1605 | | // Init non-coeff CDFs. | 1606 | | // Setup past independence. | 1607 | 200k | } else { | 1608 | | // Load CDF tables from previous frame. | 1609 | | // Load params from previous frame. | 1610 | 100k | } | 1611 | | | 1612 | 300k | if (current->use_ref_frame_mvs) { | 1613 | | // Perform motion field estimation process. | 1614 | 15.8k | } | 1615 | | | 1616 | 300k | CHECK(FUNC(tile_info)(ctx, rw, current)); | 1617 | | | 1618 | 296k | CHECK(FUNC(quantization_params)(ctx, rw, current)); | 1619 | | | 1620 | 293k | CHECK(FUNC(segmentation_params)(ctx, rw, current)); | 1621 | | | 1622 | 293k | CHECK(FUNC(delta_q_params)(ctx, rw, current)); | 1623 | | | 1624 | 293k | CHECK(FUNC(delta_lf_params)(ctx, rw, current)); | 1625 | | | 1626 | | // Init coeff CDFs / load previous segments. | 1627 | | | 1628 | 293k | priv->coded_lossless = 1; | 1629 | 2.63M | for (i = 0; i < AV1_MAX_SEGMENTS; i++) { | 1630 | 2.34M | int qindex; | 1631 | 2.34M | if (current->feature_enabled[i][AV1_SEG_LVL_ALT_Q]) { | 1632 | 32.1k | qindex = (current->base_q_idx + | 1633 | 32.1k | current->feature_value[i][AV1_SEG_LVL_ALT_Q]); | 1634 | 2.31M | } else { | 1635 | 2.31M | qindex = current->base_q_idx; | 1636 | 2.31M | } | 1637 | 2.34M | qindex = av_clip_uintp2(qindex, 8); | 1638 | | | 1639 | 2.34M | if (qindex || current->delta_q_y_dc || | 1640 | 899k | current->delta_q_u_ac || current->delta_q_u_dc || | 1641 | 1.55M | current->delta_q_v_ac || current->delta_q_v_dc) { | 1642 | 1.55M | priv->coded_lossless = 0; | 1643 | 1.55M | } | 1644 | 2.34M | } | 1645 | 293k | priv->all_lossless = priv->coded_lossless && | 1646 | 98.8k | priv->frame_width == priv->upscaled_width; | 1647 | | | 1648 | 293k | CHECK(FUNC(loop_filter_params)(ctx, rw, current)); | 1649 | | | 1650 | 292k | CHECK(FUNC(cdef_params)(ctx, rw, current)); | 1651 | | | 1652 | 289k | CHECK(FUNC(lr_params)(ctx, rw, current)); | 1653 | | | 1654 | 288k | CHECK(FUNC(read_tx_mode)(ctx, rw, current)); | 1655 | | | 1656 | 288k | CHECK(FUNC(frame_reference_mode)(ctx, rw, current)); | 1657 | | | 1658 | 288k | CHECK(FUNC(skip_mode_params)(ctx, rw, current)); | 1659 | | | 1660 | 288k | if (frame_is_intra || current->error_resilient_mode || | 1661 | 106k | !seq->enable_warped_motion) | 1662 | 213k | infer(allow_warped_motion, 0); | 1663 | 75.0k | else | 1664 | 288k | flag(allow_warped_motion); | 1665 | | | 1666 | 287k | flag(reduced_tx_set); | 1667 | | | 1668 | 287k | CHECK(FUNC(global_motion_params)(ctx, rw, current)); | 1669 | | | 1670 | 287k | CHECK(FUNC(film_grain_params)(ctx, rw, ¤t->film_grain, current)); | 1671 | | | 1672 | 286k | av_log(ctx->log_ctx, AV_LOG_DEBUG, "Frame %d: size %dx%d " | 1673 | 286k | "upscaled %d render %dx%d subsample %dx%d " | 1674 | 286k | "bitdepth %d tiles %dx%d.\n", priv->order_hint, | 1675 | 286k | priv->frame_width, priv->frame_height, priv->upscaled_width, | 1676 | 286k | priv->render_width, priv->render_height, | 1677 | 286k | seq->color_config.subsampling_x + 1, | 1678 | 286k | seq->color_config.subsampling_y + 1, priv->bit_depth, | 1679 | 286k | priv->tile_rows, priv->tile_cols); | 1680 | | | 1681 | 295k | update_refs: | 1682 | 2.65M | for (i = 0; i < AV1_NUM_REF_FRAMES; i++) { | 1683 | 2.36M | if (current->refresh_frame_flags & (1 << i)) { | 1684 | 1.57M | priv->ref[i] = (AV1ReferenceFrameState) { | 1685 | 1.57M | .valid = 1, | 1686 | 1.57M | .frame_id = current->current_frame_id, | 1687 | 1.57M | .upscaled_width = priv->upscaled_width, | 1688 | 1.57M | .frame_width = priv->frame_width, | 1689 | 1.57M | .frame_height = priv->frame_height, | 1690 | 1.57M | .render_width = priv->render_width, | 1691 | 1.57M | .render_height = priv->render_height, | 1692 | 1.57M | .frame_type = current->frame_type, | 1693 | 1.57M | .subsampling_x = seq->color_config.subsampling_x, | 1694 | 1.57M | .subsampling_y = seq->color_config.subsampling_y, | 1695 | 1.57M | .bit_depth = priv->bit_depth, | 1696 | 1.57M | .order_hint = priv->order_hint, | 1697 | 1.57M | }; | 1698 | | | 1699 | 12.5M | for (int j = 0; j < AV1_REFS_PER_FRAME; j++) { | 1700 | 11.0M | priv->ref[i].saved_order_hints[j + AV1_REF_FRAME_LAST] = | 1701 | 11.0M | priv->order_hints[j + AV1_REF_FRAME_LAST]; | 1702 | 11.0M | } | 1703 | | | 1704 | 1.57M | if (current->show_existing_frame) { | 1705 | 35.0k | memcpy(priv->ref[i].loop_filter_ref_deltas, priv->loop_filter_ref_deltas, | 1706 | 35.0k | sizeof(priv->loop_filter_ref_deltas)); | 1707 | 35.0k | memcpy(priv->ref[i].loop_filter_mode_deltas, priv->loop_filter_mode_deltas, | 1708 | 35.0k | sizeof(priv->loop_filter_mode_deltas)); | 1709 | 35.0k | memcpy(priv->ref[i].feature_enabled, priv->feature_enabled, | 1710 | 35.0k | sizeof(priv->feature_enabled)); | 1711 | 35.0k | memcpy(priv->ref[i].feature_value, priv->feature_value, | 1712 | 35.0k | sizeof(priv->feature_value)); | 1713 | 1.53M | } else { | 1714 | 1.53M | memcpy(priv->ref[i].loop_filter_ref_deltas, current->loop_filter_ref_deltas, | 1715 | 1.53M | sizeof(current->loop_filter_ref_deltas)); | 1716 | 1.53M | memcpy(priv->ref[i].loop_filter_mode_deltas, current->loop_filter_mode_deltas, | 1717 | 1.53M | sizeof(current->loop_filter_mode_deltas)); | 1718 | 1.53M | memcpy(priv->ref[i].feature_enabled, current->feature_enabled, | 1719 | 1.53M | sizeof(current->feature_enabled)); | 1720 | 1.53M | memcpy(priv->ref[i].feature_value, current->feature_value, | 1721 | 1.53M | sizeof(current->feature_value)); | 1722 | 1.53M | } | 1723 | 1.57M | } | 1724 | 2.36M | } | 1725 | | | 1726 | 295k | return 0; | 1727 | 286k | } |
|
1728 | | |
1729 | | static int FUNC(frame_header_obu)(CodedBitstreamContext *ctx, RWContext *rw, |
1730 | | AV1RawFrameHeader *current, int redundant, |
1731 | | AVBufferRef *rw_buffer_ref) |
1732 | 3.49M | { |
1733 | 3.49M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
1734 | 3.49M | int start_pos, fh_bits, fh_bytes, err; |
1735 | 3.49M | uint8_t *fh_start; |
1736 | | |
1737 | 3.49M | if (priv->seen_frame_header) { |
1738 | 388k | if (!redundant) { |
1739 | 369k | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid repeated " |
1740 | 369k | "frame header OBU.\n"); |
1741 | 369k | return AVERROR_INVALIDDATA; |
1742 | 369k | } else { |
1743 | 18.6k | GetBitContext fh; |
1744 | 18.6k | size_t i, b; |
1745 | 18.6k | uint32_t val; |
1746 | | |
1747 | 18.6k | HEADER("Redundant Frame Header"); |
1748 | | |
1749 | 18.6k | av_assert0(priv->frame_header_ref && priv->frame_header); |
1750 | | |
1751 | 18.6k | init_get_bits(&fh, priv->frame_header, |
1752 | 18.6k | priv->frame_header_size); |
1753 | 139k | for (i = 0; i < priv->frame_header_size; i += 8) { |
1754 | 133k | b = FFMIN(priv->frame_header_size - i, 8); |
1755 | 133k | val = get_bits(&fh, b); |
1756 | 133k | xf(b, frame_header_copy[i], |
1757 | 133k | val, val, val, 1, i / 8); |
1758 | 133k | } |
1759 | 18.6k | } |
1760 | 3.10M | } else { |
1761 | 3.10M | if (redundant) |
1762 | | #ifdef READ |
1763 | 25.7k | HEADER("Redundant Frame Header (used as Frame Header)"); |
1764 | | #else |
1765 | 494 | { |
1766 | 494 | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid redundant " |
1767 | 494 | "frame header OBU.\n"); |
1768 | 494 | return AVERROR_INVALIDDATA; |
1769 | 494 | } |
1770 | 331k | #endif |
1771 | 331k | else |
1772 | 3.07M | HEADER("Frame Header"); |
1773 | | |
1774 | | #ifdef READ |
1775 | | start_pos = get_bits_count(rw); |
1776 | | #else |
1777 | 331k | start_pos = put_bits_count(rw); |
1778 | 331k | #endif |
1779 | | |
1780 | 3.10M | CHECK(FUNC(uncompressed_header)(ctx, rw, current)); |
1781 | | |
1782 | 1.41M | priv->tile_num = 0; |
1783 | | |
1784 | 1.41M | if (current->show_existing_frame) { |
1785 | 288k | priv->seen_frame_header = 0; |
1786 | 1.12M | } else { |
1787 | 1.12M | priv->seen_frame_header = 1; |
1788 | | |
1789 | 1.12M | av_buffer_unref(&priv->frame_header_ref); |
1790 | | |
1791 | | #ifdef READ |
1792 | | fh_bits = get_bits_count(rw) - start_pos; |
1793 | | fh_start = (uint8_t*)rw->buffer + start_pos / 8; |
1794 | | #else |
1795 | | // Need to flush the bitwriter so that we can copy its output, |
1796 | | // but use a copy so we don't affect the caller's structure. |
1797 | | { |
1798 | | PutBitContext tmp = *rw; |
1799 | | flush_put_bits(&tmp); |
1800 | | } |
1801 | | |
1802 | | fh_bits = put_bits_count(rw) - start_pos; |
1803 | | fh_start = rw->buf + start_pos / 8; |
1804 | | #endif |
1805 | 1.12M | fh_bytes = (fh_bits + 7) / 8; |
1806 | | |
1807 | 1.12M | priv->frame_header_size = fh_bits; |
1808 | | |
1809 | 1.12M | if (rw_buffer_ref) { |
1810 | 838k | priv->frame_header_ref = av_buffer_ref(rw_buffer_ref); |
1811 | 838k | if (!priv->frame_header_ref) |
1812 | 0 | return AVERROR(ENOMEM); |
1813 | 838k | priv->frame_header = fh_start; |
1814 | 838k | } else { |
1815 | 286k | priv->frame_header_ref = |
1816 | 286k | av_buffer_alloc(fh_bytes + AV_INPUT_BUFFER_PADDING_SIZE); |
1817 | 286k | if (!priv->frame_header_ref) |
1818 | 0 | return AVERROR(ENOMEM); |
1819 | 286k | priv->frame_header = priv->frame_header_ref->data; |
1820 | 286k | memcpy(priv->frame_header, fh_start, fh_bytes); |
1821 | 286k | } |
1822 | 1.12M | } |
1823 | 1.41M | } |
1824 | | |
1825 | 1.41M | return 0; |
1826 | 3.49M | } cbs_av1.c:cbs_av1_read_frame_header_obu Line | Count | Source | 1732 | 3.15M | { | 1733 | 3.15M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1734 | 3.15M | int start_pos, fh_bits, fh_bytes, err; | 1735 | 3.15M | uint8_t *fh_start; | 1736 | | | 1737 | 3.15M | if (priv->seen_frame_header) { | 1738 | 387k | if (!redundant) { | 1739 | 369k | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid repeated " | 1740 | 369k | "frame header OBU.\n"); | 1741 | 369k | return AVERROR_INVALIDDATA; | 1742 | 369k | } else { | 1743 | 17.9k | GetBitContext fh; | 1744 | 17.9k | size_t i, b; | 1745 | 17.9k | uint32_t val; | 1746 | | | 1747 | 17.9k | HEADER("Redundant Frame Header"); | 1748 | | | 1749 | 17.9k | av_assert0(priv->frame_header_ref && priv->frame_header); | 1750 | | | 1751 | 17.9k | init_get_bits(&fh, priv->frame_header, | 1752 | 17.9k | priv->frame_header_size); | 1753 | 105k | for (i = 0; i < priv->frame_header_size; i += 8) { | 1754 | 100k | b = FFMIN(priv->frame_header_size - i, 8); | 1755 | 100k | val = get_bits(&fh, b); | 1756 | 100k | xf(b, frame_header_copy[i], | 1757 | 100k | val, val, val, 1, i / 8); | 1758 | 100k | } | 1759 | 17.9k | } | 1760 | 2.77M | } else { | 1761 | 2.77M | if (redundant) | 1762 | 25.7k | #ifdef READ | 1763 | 25.7k | HEADER("Redundant Frame Header (used as Frame Header)"); | 1764 | | #else | 1765 | | { | 1766 | | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid redundant " | 1767 | | "frame header OBU.\n"); | 1768 | | return AVERROR_INVALIDDATA; | 1769 | | } | 1770 | | #endif | 1771 | 2.74M | else | 1772 | 2.74M | HEADER("Frame Header"); | 1773 | | | 1774 | 2.77M | #ifdef READ | 1775 | 2.77M | start_pos = get_bits_count(rw); | 1776 | | #else | 1777 | | start_pos = put_bits_count(rw); | 1778 | | #endif | 1779 | | | 1780 | 2.77M | CHECK(FUNC(uncompressed_header)(ctx, rw, current)); | 1781 | | | 1782 | 1.11M | priv->tile_num = 0; | 1783 | | | 1784 | 1.11M | if (current->show_existing_frame) { | 1785 | 279k | priv->seen_frame_header = 0; | 1786 | 838k | } else { | 1787 | 838k | priv->seen_frame_header = 1; | 1788 | | | 1789 | 838k | av_buffer_unref(&priv->frame_header_ref); | 1790 | | | 1791 | 838k | #ifdef READ | 1792 | 838k | fh_bits = get_bits_count(rw) - start_pos; | 1793 | 838k | fh_start = (uint8_t*)rw->buffer + start_pos / 8; | 1794 | | #else | 1795 | | // Need to flush the bitwriter so that we can copy its output, | 1796 | | // but use a copy so we don't affect the caller's structure. | 1797 | | { | 1798 | | PutBitContext tmp = *rw; | 1799 | | flush_put_bits(&tmp); | 1800 | | } | 1801 | | | 1802 | | fh_bits = put_bits_count(rw) - start_pos; | 1803 | | fh_start = rw->buf + start_pos / 8; | 1804 | | #endif | 1805 | 838k | fh_bytes = (fh_bits + 7) / 8; | 1806 | | | 1807 | 838k | priv->frame_header_size = fh_bits; | 1808 | | | 1809 | 838k | if (rw_buffer_ref) { | 1810 | 838k | priv->frame_header_ref = av_buffer_ref(rw_buffer_ref); | 1811 | 838k | if (!priv->frame_header_ref) | 1812 | 0 | return AVERROR(ENOMEM); | 1813 | 838k | priv->frame_header = fh_start; | 1814 | 838k | } else { | 1815 | 0 | priv->frame_header_ref = | 1816 | 0 | av_buffer_alloc(fh_bytes + AV_INPUT_BUFFER_PADDING_SIZE); | 1817 | 0 | if (!priv->frame_header_ref) | 1818 | 0 | return AVERROR(ENOMEM); | 1819 | 0 | priv->frame_header = priv->frame_header_ref->data; | 1820 | 0 | memcpy(priv->frame_header, fh_start, fh_bytes); | 1821 | 0 | } | 1822 | 838k | } | 1823 | 1.11M | } | 1824 | | | 1825 | 1.12M | return 0; | 1826 | 3.15M | } |
cbs_av1.c:cbs_av1_write_frame_header_obu Line | Count | Source | 1732 | 332k | { | 1733 | 332k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1734 | 332k | int start_pos, fh_bits, fh_bytes, err; | 1735 | 332k | uint8_t *fh_start; | 1736 | | | 1737 | 332k | if (priv->seen_frame_header) { | 1738 | 1.27k | if (!redundant) { | 1739 | 506 | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid repeated " | 1740 | 506 | "frame header OBU.\n"); | 1741 | 506 | return AVERROR_INVALIDDATA; | 1742 | 764 | } else { | 1743 | 764 | GetBitContext fh; | 1744 | 764 | size_t i, b; | 1745 | 764 | uint32_t val; | 1746 | | | 1747 | 764 | HEADER("Redundant Frame Header"); | 1748 | | | 1749 | 764 | av_assert0(priv->frame_header_ref && priv->frame_header); | 1750 | | | 1751 | 764 | init_get_bits(&fh, priv->frame_header, | 1752 | 764 | priv->frame_header_size); | 1753 | 33.9k | for (i = 0; i < priv->frame_header_size; i += 8) { | 1754 | 33.2k | b = FFMIN(priv->frame_header_size - i, 8); | 1755 | 33.2k | val = get_bits(&fh, b); | 1756 | 33.2k | xf(b, frame_header_copy[i], | 1757 | 33.2k | val, val, val, 1, i / 8); | 1758 | 33.2k | } | 1759 | 764 | } | 1760 | 331k | } else { | 1761 | 331k | if (redundant) | 1762 | | #ifdef READ | 1763 | | HEADER("Redundant Frame Header (used as Frame Header)"); | 1764 | | #else | 1765 | 494 | { | 1766 | 494 | av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid redundant " | 1767 | 494 | "frame header OBU.\n"); | 1768 | 494 | return AVERROR_INVALIDDATA; | 1769 | 494 | } | 1770 | 331k | #endif | 1771 | 331k | else | 1772 | 331k | HEADER("Frame Header"); | 1773 | | | 1774 | | #ifdef READ | 1775 | | start_pos = get_bits_count(rw); | 1776 | | #else | 1777 | 331k | start_pos = put_bits_count(rw); | 1778 | 331k | #endif | 1779 | | | 1780 | 331k | CHECK(FUNC(uncompressed_header)(ctx, rw, current)); | 1781 | | | 1782 | 295k | priv->tile_num = 0; | 1783 | | | 1784 | 295k | if (current->show_existing_frame) { | 1785 | 8.48k | priv->seen_frame_header = 0; | 1786 | 286k | } else { | 1787 | 286k | priv->seen_frame_header = 1; | 1788 | | | 1789 | 286k | av_buffer_unref(&priv->frame_header_ref); | 1790 | | | 1791 | | #ifdef READ | 1792 | | fh_bits = get_bits_count(rw) - start_pos; | 1793 | | fh_start = (uint8_t*)rw->buffer + start_pos / 8; | 1794 | | #else | 1795 | | // Need to flush the bitwriter so that we can copy its output, | 1796 | | // but use a copy so we don't affect the caller's structure. | 1797 | 286k | { | 1798 | 286k | PutBitContext tmp = *rw; | 1799 | 286k | flush_put_bits(&tmp); | 1800 | 286k | } | 1801 | | | 1802 | 286k | fh_bits = put_bits_count(rw) - start_pos; | 1803 | 286k | fh_start = rw->buf + start_pos / 8; | 1804 | 286k | #endif | 1805 | 286k | fh_bytes = (fh_bits + 7) / 8; | 1806 | | | 1807 | 286k | priv->frame_header_size = fh_bits; | 1808 | | | 1809 | 286k | if (rw_buffer_ref) { | 1810 | 0 | priv->frame_header_ref = av_buffer_ref(rw_buffer_ref); | 1811 | 0 | if (!priv->frame_header_ref) | 1812 | 0 | return AVERROR(ENOMEM); | 1813 | 0 | priv->frame_header = fh_start; | 1814 | 286k | } else { | 1815 | 286k | priv->frame_header_ref = | 1816 | 286k | av_buffer_alloc(fh_bytes + AV_INPUT_BUFFER_PADDING_SIZE); | 1817 | 286k | if (!priv->frame_header_ref) | 1818 | 0 | return AVERROR(ENOMEM); | 1819 | 286k | priv->frame_header = priv->frame_header_ref->data; | 1820 | 286k | memcpy(priv->frame_header, fh_start, fh_bytes); | 1821 | 286k | } | 1822 | 286k | } | 1823 | 295k | } | 1824 | | | 1825 | 296k | return 0; | 1826 | 332k | } |
|
1827 | | |
1828 | | static int FUNC(tile_group_obu)(CodedBitstreamContext *ctx, RWContext *rw, |
1829 | | AV1RawTileGroup *current) |
1830 | 1.66M | { |
1831 | 1.66M | CodedBitstreamAV1Context *priv = ctx->priv_data; |
1832 | 1.66M | int num_tiles, tile_bits; |
1833 | 1.66M | int err; |
1834 | | |
1835 | 1.66M | HEADER("Tile Group"); |
1836 | | |
1837 | 1.66M | num_tiles = priv->tile_cols * priv->tile_rows; |
1838 | 1.66M | if (num_tiles > 1) |
1839 | 1.66M | flag(tile_start_and_end_present_flag); |
1840 | 1.52M | else |
1841 | 1.52M | infer(tile_start_and_end_present_flag, 0); |
1842 | | |
1843 | 1.66M | if (num_tiles == 1 || !current->tile_start_and_end_present_flag) { |
1844 | 1.63M | infer(tg_start, 0); |
1845 | 1.63M | infer(tg_end, num_tiles - 1); |
1846 | 437k | } else { |
1847 | 34.9k | tile_bits = cbs_av1_tile_log2(1, priv->tile_cols) + |
1848 | 34.9k | cbs_av1_tile_log2(1, priv->tile_rows); |
1849 | 34.9k | fc(tile_bits, tg_start, priv->tile_num, num_tiles - 1); |
1850 | 26.7k | fc(tile_bits, tg_end, current->tg_start, num_tiles - 1); |
1851 | 26.7k | } |
1852 | | |
1853 | 1.65M | priv->tile_num = current->tg_end + 1; |
1854 | | |
1855 | 1.65M | CHECK(FUNC(byte_alignment)(ctx, rw)); |
1856 | | |
1857 | | // Reset header for next frame. |
1858 | 1.62M | if (current->tg_end == num_tiles - 1) |
1859 | 1.58M | priv->seen_frame_header = 0; |
1860 | | |
1861 | | // Tile data follows. |
1862 | | |
1863 | 1.62M | return 0; |
1864 | 1.65M | } cbs_av1.c:cbs_av1_read_tile_group_obu Line | Count | Source | 1830 | 1.22M | { | 1831 | 1.22M | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1832 | 1.22M | int num_tiles, tile_bits; | 1833 | 1.22M | int err; | 1834 | | | 1835 | 1.22M | HEADER("Tile Group"); | 1836 | | | 1837 | 1.22M | num_tiles = priv->tile_cols * priv->tile_rows; | 1838 | 1.22M | if (num_tiles > 1) | 1839 | 1.22M | flag(tile_start_and_end_present_flag); | 1840 | 1.10M | else | 1841 | 1.10M | infer(tile_start_and_end_present_flag, 0); | 1842 | | | 1843 | 1.22M | if (num_tiles == 1 || !current->tile_start_and_end_present_flag) { | 1844 | 1.19M | infer(tg_start, 0); | 1845 | 1.19M | infer(tg_end, num_tiles - 1); | 1846 | 1.19M | } else { | 1847 | 30.5k | tile_bits = cbs_av1_tile_log2(1, priv->tile_cols) + | 1848 | 30.5k | cbs_av1_tile_log2(1, priv->tile_rows); | 1849 | 30.5k | fc(tile_bits, tg_start, priv->tile_num, num_tiles - 1); | 1850 | 22.9k | fc(tile_bits, tg_end, current->tg_start, num_tiles - 1); | 1851 | 22.9k | } | 1852 | | | 1853 | 1.21M | priv->tile_num = current->tg_end + 1; | 1854 | | | 1855 | 1.21M | CHECK(FUNC(byte_alignment)(ctx, rw)); | 1856 | | | 1857 | | // Reset header for next frame. | 1858 | 1.18M | if (current->tg_end == num_tiles - 1) | 1859 | 1.15M | priv->seen_frame_header = 0; | 1860 | | | 1861 | | // Tile data follows. | 1862 | | | 1863 | 1.18M | return 0; | 1864 | 1.21M | } |
cbs_av1.c:cbs_av1_write_tile_group_obu Line | Count | Source | 1830 | 442k | { | 1831 | 442k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1832 | 442k | int num_tiles, tile_bits; | 1833 | 442k | int err; | 1834 | | | 1835 | 442k | HEADER("Tile Group"); | 1836 | | | 1837 | 442k | num_tiles = priv->tile_cols * priv->tile_rows; | 1838 | 442k | if (num_tiles > 1) | 1839 | 442k | flag(tile_start_and_end_present_flag); | 1840 | 422k | else | 1841 | 422k | infer(tile_start_and_end_present_flag, 0); | 1842 | | | 1843 | 441k | if (num_tiles == 1 || !current->tile_start_and_end_present_flag) { | 1844 | 437k | infer(tg_start, 0); | 1845 | 437k | infer(tg_end, num_tiles - 1); | 1846 | 437k | } else { | 1847 | 4.43k | tile_bits = cbs_av1_tile_log2(1, priv->tile_cols) + | 1848 | 4.43k | cbs_av1_tile_log2(1, priv->tile_rows); | 1849 | 4.43k | fc(tile_bits, tg_start, priv->tile_num, num_tiles - 1); | 1850 | 3.85k | fc(tile_bits, tg_end, current->tg_start, num_tiles - 1); | 1851 | 3.85k | } | 1852 | | | 1853 | 439k | priv->tile_num = current->tg_end + 1; | 1854 | | | 1855 | 439k | CHECK(FUNC(byte_alignment)(ctx, rw)); | 1856 | | | 1857 | | // Reset header for next frame. | 1858 | 439k | if (current->tg_end == num_tiles - 1) | 1859 | 436k | priv->seen_frame_header = 0; | 1860 | | | 1861 | | // Tile data follows. | 1862 | | | 1863 | 439k | return 0; | 1864 | 439k | } |
|
1865 | | |
1866 | | static int FUNC(frame_obu)(CodedBitstreamContext *ctx, RWContext *rw, |
1867 | | AV1RawFrame *current, |
1868 | | AVBufferRef *rw_buffer_ref) |
1869 | 2.83M | { |
1870 | 2.83M | int err; |
1871 | | |
1872 | 2.83M | CHECK(FUNC(frame_header_obu)(ctx, rw, ¤t->header, |
1873 | 2.83M | 0, rw_buffer_ref)); |
1874 | | |
1875 | 1.12M | CHECK(FUNC(byte_alignment)(ctx, rw)); |
1876 | | |
1877 | 1.07M | return 0; |
1878 | 1.12M | } cbs_av1.c:cbs_av1_read_frame_obu Line | Count | Source | 1869 | 2.52M | { | 1870 | 2.52M | int err; | 1871 | | | 1872 | 2.52M | CHECK(FUNC(frame_header_obu)(ctx, rw, ¤t->header, | 1873 | 2.52M | 0, rw_buffer_ref)); | 1874 | | | 1875 | 846k | CHECK(FUNC(byte_alignment)(ctx, rw)); | 1876 | | | 1877 | 791k | return 0; | 1878 | 846k | } |
cbs_av1.c:cbs_av1_write_frame_obu Line | Count | Source | 1869 | 313k | { | 1870 | 313k | int err; | 1871 | | | 1872 | 313k | CHECK(FUNC(frame_header_obu)(ctx, rw, ¤t->header, | 1873 | 313k | 0, rw_buffer_ref)); | 1874 | | | 1875 | 280k | CHECK(FUNC(byte_alignment)(ctx, rw)); | 1876 | | | 1877 | 280k | return 0; | 1878 | 280k | } |
|
1879 | | |
1880 | | #if CBS_AV1_OBU_TILE_LIST |
1881 | | static int FUNC(tile_list_obu)(CodedBitstreamContext *ctx, RWContext *rw, |
1882 | | AV1RawTileList *current) |
1883 | 202k | { |
1884 | 202k | int err; |
1885 | | |
1886 | 202k | fb(8, output_frame_width_in_tiles_minus_1); |
1887 | 200k | fb(8, output_frame_height_in_tiles_minus_1); |
1888 | | |
1889 | 194k | fb(16, tile_count_minus_1); |
1890 | | |
1891 | | // Tile data follows. |
1892 | | |
1893 | 193k | return 0; |
1894 | 194k | } cbs_av1.c:cbs_av1_read_tile_list_obu Line | Count | Source | 1883 | 122k | { | 1884 | 122k | int err; | 1885 | | | 1886 | 122k | fb(8, output_frame_width_in_tiles_minus_1); | 1887 | 120k | fb(8, output_frame_height_in_tiles_minus_1); | 1888 | | | 1889 | 114k | fb(16, tile_count_minus_1); | 1890 | | | 1891 | | // Tile data follows. | 1892 | | | 1893 | 113k | return 0; | 1894 | 114k | } |
cbs_av1.c:cbs_av1_write_tile_list_obu Line | Count | Source | 1883 | 80.1k | { | 1884 | 80.1k | int err; | 1885 | | | 1886 | 80.1k | fb(8, output_frame_width_in_tiles_minus_1); | 1887 | 80.1k | fb(8, output_frame_height_in_tiles_minus_1); | 1888 | | | 1889 | 80.1k | fb(16, tile_count_minus_1); | 1890 | | | 1891 | | // Tile data follows. | 1892 | | | 1893 | 80.1k | return 0; | 1894 | 80.1k | } |
|
1895 | | #endif |
1896 | | |
1897 | | #if CBS_AV1_OBU_METADATA |
1898 | | static int FUNC(metadata_hdr_cll)(CodedBitstreamContext *ctx, RWContext *rw, |
1899 | | AV1RawMetadataHDRCLL *current) |
1900 | 24.1k | { |
1901 | 24.1k | int err; |
1902 | | |
1903 | 24.1k | HEADER("HDR CLL Metadata"); |
1904 | | |
1905 | 24.1k | fb(16, max_cll); |
1906 | 16.1k | fb(16, max_fall); |
1907 | | |
1908 | 5.07k | return 0; |
1909 | 16.1k | } cbs_av1.c:cbs_av1_read_metadata_hdr_cll Line | Count | Source | 1900 | 23.3k | { | 1901 | 23.3k | int err; | 1902 | | | 1903 | 23.3k | HEADER("HDR CLL Metadata"); | 1904 | | | 1905 | 23.3k | fb(16, max_cll); | 1906 | 15.3k | fb(16, max_fall); | 1907 | | | 1908 | 4.26k | return 0; | 1909 | 15.3k | } |
cbs_av1.c:cbs_av1_write_metadata_hdr_cll Line | Count | Source | 1900 | 806 | { | 1901 | 806 | int err; | 1902 | | | 1903 | 806 | HEADER("HDR CLL Metadata"); | 1904 | | | 1905 | 806 | fb(16, max_cll); | 1906 | 806 | fb(16, max_fall); | 1907 | | | 1908 | 806 | return 0; | 1909 | 806 | } |
|
1910 | | |
1911 | | static int FUNC(metadata_hdr_mdcv)(CodedBitstreamContext *ctx, RWContext *rw, |
1912 | | AV1RawMetadataHDRMDCV *current) |
1913 | 20.4k | { |
1914 | 20.4k | int err, i; |
1915 | | |
1916 | 20.4k | HEADER("HDR MDCV Metadata"); |
1917 | | |
1918 | 69.1k | for (i = 0; i < 3; i++) { |
1919 | 53.6k | fbs(16, primary_chromaticity_x[i], 1, i); |
1920 | 50.2k | fbs(16, primary_chromaticity_y[i], 1, i); |
1921 | 50.2k | } |
1922 | | |
1923 | 15.4k | fb(16, white_point_chromaticity_x); |
1924 | 13.7k | fb(16, white_point_chromaticity_y); |
1925 | | |
1926 | 12.0k | fb(32, luminance_max); |
1927 | 9.45k | fb(32, luminance_min); |
1928 | | |
1929 | 8.05k | return 0; |
1930 | 9.45k | } cbs_av1.c:cbs_av1_read_metadata_hdr_mdcv Line | Count | Source | 1913 | 19.5k | { | 1914 | 19.5k | int err, i; | 1915 | | | 1916 | 19.5k | HEADER("HDR MDCV Metadata"); | 1917 | | | 1918 | 65.3k | for (i = 0; i < 3; i++) { | 1919 | 50.8k | fbs(16, primary_chromaticity_x[i], 1, i); | 1920 | 47.4k | fbs(16, primary_chromaticity_y[i], 1, i); | 1921 | 47.4k | } | 1922 | | | 1923 | 14.4k | fb(16, white_point_chromaticity_x); | 1924 | 12.7k | fb(16, white_point_chromaticity_y); | 1925 | | | 1926 | 11.1k | fb(32, luminance_max); | 1927 | 8.50k | fb(32, luminance_min); | 1928 | | | 1929 | 7.11k | return 0; | 1930 | 8.50k | } |
cbs_av1.c:cbs_av1_write_metadata_hdr_mdcv Line | Count | Source | 1913 | 942 | { | 1914 | 942 | int err, i; | 1915 | | | 1916 | 942 | HEADER("HDR MDCV Metadata"); | 1917 | | | 1918 | 3.76k | for (i = 0; i < 3; i++) { | 1919 | 2.82k | fbs(16, primary_chromaticity_x[i], 1, i); | 1920 | 2.82k | fbs(16, primary_chromaticity_y[i], 1, i); | 1921 | 2.82k | } | 1922 | | | 1923 | 942 | fb(16, white_point_chromaticity_x); | 1924 | 942 | fb(16, white_point_chromaticity_y); | 1925 | | | 1926 | 942 | fb(32, luminance_max); | 1927 | 942 | fb(32, luminance_min); | 1928 | | | 1929 | 942 | return 0; | 1930 | 942 | } |
|
1931 | | |
1932 | | static int FUNC(scalability_structure)(CodedBitstreamContext *ctx, RWContext *rw, |
1933 | | AV1RawMetadataScalability *current) |
1934 | 37.7k | { |
1935 | 37.7k | CodedBitstreamAV1Context *priv = ctx->priv_data; |
1936 | 37.7k | const AV1RawSequenceHeader *seq; |
1937 | 37.7k | int err, i, j; |
1938 | | |
1939 | 37.7k | if (!priv->sequence_header) { |
1940 | 2.09k | av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: " |
1941 | 2.09k | "unable to parse scalability metadata.\n"); |
1942 | 2.09k | return AVERROR_INVALIDDATA; |
1943 | 2.09k | } |
1944 | 35.6k | seq = priv->sequence_header; |
1945 | | |
1946 | 35.6k | fb(2, spatial_layers_cnt_minus_1); |
1947 | 34.8k | flag(spatial_layer_dimensions_present_flag); |
1948 | 34.8k | flag(spatial_layer_description_present_flag); |
1949 | 34.8k | flag(temporal_group_description_present_flag); |
1950 | 34.8k | fc(3, scalability_structure_reserved_3bits, 0, 0); |
1951 | 33.0k | if (current->spatial_layer_dimensions_present_flag) { |
1952 | 44.6k | for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++) { |
1953 | 35.3k | fcs(16, spatial_layer_max_width[i], |
1954 | 28.6k | 0, seq->max_frame_width_minus_1 + 1, 1, i); |
1955 | 28.6k | fcs(16, spatial_layer_max_height[i], |
1956 | 28.6k | 0, seq->max_frame_height_minus_1 + 1, 1, i); |
1957 | 28.6k | } |
1958 | 18.7k | } |
1959 | 23.5k | if (current->spatial_layer_description_present_flag) { |
1960 | 41.7k | for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++) |
1961 | 30.3k | fbs(8, spatial_layer_ref_id[i], 1, i); |
1962 | 12.6k | } |
1963 | 22.2k | if (current->temporal_group_description_present_flag) { |
1964 | 17.8k | fb(8, temporal_group_size); |
1965 | 89.8k | for (i = 0; i < current->temporal_group_size; i++) { |
1966 | 77.7k | fbs(3, temporal_group_temporal_id[i], 1, i); |
1967 | 76.1k | flags(temporal_group_temporal_switching_up_point_flag[i], 1, i); |
1968 | 76.1k | flags(temporal_group_spatial_switching_up_point_flag[i], 1, i); |
1969 | 76.1k | fbs(3, temporal_group_ref_cnt[i], 1, i); |
1970 | 170k | for (j = 0; j < current->temporal_group_ref_cnt[i]; j++) { |
1971 | 96.7k | fbs(8, temporal_group_ref_pic_diff[i][j], 2, i, j); |
1972 | 96.7k | } |
1973 | 76.1k | } |
1974 | 15.7k | } |
1975 | | |
1976 | 16.4k | return 0; |
1977 | 22.2k | } cbs_av1.c:cbs_av1_read_scalability_structure Line | Count | Source | 1934 | 32.6k | { | 1935 | 32.6k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1936 | 32.6k | const AV1RawSequenceHeader *seq; | 1937 | 32.6k | int err, i, j; | 1938 | | | 1939 | 32.6k | if (!priv->sequence_header) { | 1940 | 1.49k | av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: " | 1941 | 1.49k | "unable to parse scalability metadata.\n"); | 1942 | 1.49k | return AVERROR_INVALIDDATA; | 1943 | 1.49k | } | 1944 | 31.1k | seq = priv->sequence_header; | 1945 | | | 1946 | 31.1k | fb(2, spatial_layers_cnt_minus_1); | 1947 | 30.3k | flag(spatial_layer_dimensions_present_flag); | 1948 | 30.3k | flag(spatial_layer_description_present_flag); | 1949 | 30.3k | flag(temporal_group_description_present_flag); | 1950 | 30.3k | fc(3, scalability_structure_reserved_3bits, 0, 0); | 1951 | 28.4k | if (current->spatial_layer_dimensions_present_flag) { | 1952 | 39.9k | for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++) { | 1953 | 31.7k | fcs(16, spatial_layer_max_width[i], | 1954 | 25.4k | 0, seq->max_frame_width_minus_1 + 1, 1, i); | 1955 | 25.4k | fcs(16, spatial_layer_max_height[i], | 1956 | 25.4k | 0, seq->max_frame_height_minus_1 + 1, 1, i); | 1957 | 25.4k | } | 1958 | 16.8k | } | 1959 | 19.7k | if (current->spatial_layer_description_present_flag) { | 1960 | 36.2k | for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++) | 1961 | 26.4k | fbs(8, spatial_layer_ref_id[i], 1, i); | 1962 | 11.0k | } | 1963 | 18.4k | if (current->temporal_group_description_present_flag) { | 1964 | 15.2k | fb(8, temporal_group_size); | 1965 | 75.4k | for (i = 0; i < current->temporal_group_size; i++) { | 1966 | 66.0k | fbs(3, temporal_group_temporal_id[i], 1, i); | 1967 | 64.3k | flags(temporal_group_temporal_switching_up_point_flag[i], 1, i); | 1968 | 64.3k | flags(temporal_group_spatial_switching_up_point_flag[i], 1, i); | 1969 | 64.3k | fbs(3, temporal_group_ref_cnt[i], 1, i); | 1970 | 150k | for (j = 0; j < current->temporal_group_ref_cnt[i]; j++) { | 1971 | 87.8k | fbs(8, temporal_group_ref_pic_diff[i][j], 2, i, j); | 1972 | 87.8k | } | 1973 | 64.3k | } | 1974 | 13.1k | } | 1975 | | | 1976 | 12.6k | return 0; | 1977 | 18.4k | } |
cbs_av1.c:cbs_av1_write_scalability_structure Line | Count | Source | 1934 | 5.17k | { | 1935 | 5.17k | CodedBitstreamAV1Context *priv = ctx->priv_data; | 1936 | 5.17k | const AV1RawSequenceHeader *seq; | 1937 | 5.17k | int err, i, j; | 1938 | | | 1939 | 5.17k | if (!priv->sequence_header) { | 1940 | 604 | av_log(ctx->log_ctx, AV_LOG_ERROR, "No sequence header available: " | 1941 | 604 | "unable to parse scalability metadata.\n"); | 1942 | 604 | return AVERROR_INVALIDDATA; | 1943 | 604 | } | 1944 | 4.57k | seq = priv->sequence_header; | 1945 | | | 1946 | 4.57k | fb(2, spatial_layers_cnt_minus_1); | 1947 | 4.57k | flag(spatial_layer_dimensions_present_flag); | 1948 | 4.57k | flag(spatial_layer_description_present_flag); | 1949 | 4.57k | flag(temporal_group_description_present_flag); | 1950 | 4.57k | fc(3, scalability_structure_reserved_3bits, 0, 0); | 1951 | 4.57k | if (current->spatial_layer_dimensions_present_flag) { | 1952 | 4.67k | for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++) { | 1953 | 3.54k | fcs(16, spatial_layer_max_width[i], | 1954 | 3.14k | 0, seq->max_frame_width_minus_1 + 1, 1, i); | 1955 | 3.14k | fcs(16, spatial_layer_max_height[i], | 1956 | 3.14k | 0, seq->max_frame_height_minus_1 + 1, 1, i); | 1957 | 3.14k | } | 1958 | 1.93k | } | 1959 | 3.76k | if (current->spatial_layer_description_present_flag) { | 1960 | 5.48k | for (i = 0; i <= current->spatial_layers_cnt_minus_1; i++) | 1961 | 3.90k | fbs(8, spatial_layer_ref_id[i], 1, i); | 1962 | 1.58k | } | 1963 | 3.76k | if (current->temporal_group_description_present_flag) { | 1964 | 2.61k | fb(8, temporal_group_size); | 1965 | 14.3k | for (i = 0; i < current->temporal_group_size; i++) { | 1966 | 11.7k | fbs(3, temporal_group_temporal_id[i], 1, i); | 1967 | 11.7k | flags(temporal_group_temporal_switching_up_point_flag[i], 1, i); | 1968 | 11.7k | flags(temporal_group_spatial_switching_up_point_flag[i], 1, i); | 1969 | 11.7k | fbs(3, temporal_group_ref_cnt[i], 1, i); | 1970 | 20.6k | for (j = 0; j < current->temporal_group_ref_cnt[i]; j++) { | 1971 | 8.91k | fbs(8, temporal_group_ref_pic_diff[i][j], 2, i, j); | 1972 | 8.91k | } | 1973 | 11.7k | } | 1974 | 2.61k | } | 1975 | | | 1976 | 3.76k | return 0; | 1977 | 3.76k | } |
|
1978 | | |
1979 | | static int FUNC(metadata_scalability)(CodedBitstreamContext *ctx, RWContext *rw, |
1980 | | AV1RawMetadataScalability *current) |
1981 | 43.4k | { |
1982 | 43.4k | int err; |
1983 | | |
1984 | 43.4k | HEADER("Scalability Metadata"); |
1985 | | |
1986 | 43.4k | fb(8, scalability_mode_idc); |
1987 | | |
1988 | 42.4k | if (current->scalability_mode_idc == AV1_SCALABILITY_SS) |
1989 | 37.7k | CHECK(FUNC(scalability_structure)(ctx, rw, current)); |
1990 | | |
1991 | 21.1k | return 0; |
1992 | 42.4k | } cbs_av1.c:cbs_av1_read_metadata_scalability Line | Count | Source | 1981 | 37.4k | { | 1982 | 37.4k | int err; | 1983 | | | 1984 | 37.4k | HEADER("Scalability Metadata"); | 1985 | | | 1986 | 37.4k | fb(8, scalability_mode_idc); | 1987 | | | 1988 | 36.4k | if (current->scalability_mode_idc == AV1_SCALABILITY_SS) | 1989 | 32.6k | CHECK(FUNC(scalability_structure)(ctx, rw, current)); | 1990 | | | 1991 | 16.5k | return 0; | 1992 | 36.4k | } |
cbs_av1.c:cbs_av1_write_metadata_scalability Line | Count | Source | 1981 | 6.02k | { | 1982 | 6.02k | int err; | 1983 | | | 1984 | 6.02k | HEADER("Scalability Metadata"); | 1985 | | | 1986 | 6.02k | fb(8, scalability_mode_idc); | 1987 | | | 1988 | 6.02k | if (current->scalability_mode_idc == AV1_SCALABILITY_SS) | 1989 | 5.17k | CHECK(FUNC(scalability_structure)(ctx, rw, current)); | 1990 | | | 1991 | 4.61k | return 0; | 1992 | 6.02k | } |
|
1993 | | |
1994 | | static int FUNC(metadata_itut_t35)(CodedBitstreamContext *ctx, RWContext *rw, |
1995 | | AV1RawMetadataITUTT35 *current) |
1996 | 34.5k | { |
1997 | 34.5k | int err; |
1998 | 34.5k | size_t i; |
1999 | | |
2000 | 34.5k | HEADER("ITU-T T.35 Metadata"); |
2001 | | |
2002 | 34.5k | fb(8, itu_t_t35_country_code); |
2003 | 33.2k | if (current->itu_t_t35_country_code == 0xff) |
2004 | 7.40k | fb(8, itu_t_t35_country_code_extension_byte); |
2005 | | |
2006 | | #ifdef READ |
2007 | | // The payload runs up to the start of the trailing bits, but there might |
2008 | | // be arbitrarily many trailing zeroes so we need to read through twice. |
2009 | 28.9k | current->payload_size = cbs_av1_get_payload_bytes_left(rw); |
2010 | | |
2011 | 28.9k | current->payload_ref = av_buffer_alloc(current->payload_size); |
2012 | 28.9k | if (!current->payload_ref) |
2013 | 0 | return AVERROR(ENOMEM); |
2014 | 28.9k | current->payload = current->payload_ref->data; |
2015 | 28.9k | #endif |
2016 | | |
2017 | 10.9M | for (i = 0; i < current->payload_size; i++) |
2018 | 10.9M | xf(8, itu_t_t35_payload_bytes[i], current->payload[i], |
2019 | 3.01k | 0x00, 0xff, 1, i); |
2020 | | |
2021 | 31.9k | return 0; |
2022 | 3.01k | } cbs_av1.c:cbs_av1_read_metadata_itut_t35 Line | Count | Source | 1996 | 31.5k | { | 1997 | 31.5k | int err; | 1998 | 31.5k | size_t i; | 1999 | | | 2000 | 31.5k | HEADER("ITU-T T.35 Metadata"); | 2001 | | | 2002 | 31.5k | fb(8, itu_t_t35_country_code); | 2003 | 30.1k | if (current->itu_t_t35_country_code == 0xff) | 2004 | 5.95k | fb(8, itu_t_t35_country_code_extension_byte); | 2005 | | | 2006 | 28.9k | #ifdef READ | 2007 | | // The payload runs up to the start of the trailing bits, but there might | 2008 | | // be arbitrarily many trailing zeroes so we need to read through twice. | 2009 | 28.9k | current->payload_size = cbs_av1_get_payload_bytes_left(rw); | 2010 | | | 2011 | 28.9k | current->payload_ref = av_buffer_alloc(current->payload_size); | 2012 | 28.9k | if (!current->payload_ref) | 2013 | 0 | return AVERROR(ENOMEM); | 2014 | 28.9k | current->payload = current->payload_ref->data; | 2015 | 28.9k | #endif | 2016 | | | 2017 | 9.32M | for (i = 0; i < current->payload_size; i++) | 2018 | 9.29M | xf(8, itu_t_t35_payload_bytes[i], current->payload[i], | 2019 | 28.9k | 0x00, 0xff, 1, i); | 2020 | | | 2021 | 28.9k | return 0; | 2022 | 28.9k | } |
cbs_av1.c:cbs_av1_write_metadata_itut_t35 Line | Count | Source | 1996 | 3.01k | { | 1997 | 3.01k | int err; | 1998 | 3.01k | size_t i; | 1999 | | | 2000 | 3.01k | HEADER("ITU-T T.35 Metadata"); | 2001 | | | 2002 | 3.01k | fb(8, itu_t_t35_country_code); | 2003 | 3.01k | if (current->itu_t_t35_country_code == 0xff) | 2004 | 1.45k | fb(8, itu_t_t35_country_code_extension_byte); | 2005 | | | 2006 | | #ifdef READ | 2007 | | // The payload runs up to the start of the trailing bits, but there might | 2008 | | // be arbitrarily many trailing zeroes so we need to read through twice. | 2009 | | current->payload_size = cbs_av1_get_payload_bytes_left(rw); | 2010 | | | 2011 | | current->payload_ref = av_buffer_alloc(current->payload_size); | 2012 | | if (!current->payload_ref) | 2013 | | return AVERROR(ENOMEM); | 2014 | | current->payload = current->payload_ref->data; | 2015 | | #endif | 2016 | | | 2017 | 1.62M | for (i = 0; i < current->payload_size; i++) | 2018 | 1.62M | xf(8, itu_t_t35_payload_bytes[i], current->payload[i], | 2019 | 3.01k | 0x00, 0xff, 1, i); | 2020 | | | 2021 | 3.01k | return 0; | 2022 | 3.01k | } |
|
2023 | | |
2024 | | static int FUNC(metadata_timecode)(CodedBitstreamContext *ctx, RWContext *rw, |
2025 | | AV1RawMetadataTimecode *current) |
2026 | 55.0k | { |
2027 | 55.0k | int err; |
2028 | | |
2029 | 55.0k | HEADER("Timecode Metadata"); |
2030 | | |
2031 | 55.0k | fb(5, counting_type); |
2032 | 50.7k | flag(full_timestamp_flag); |
2033 | 50.7k | flag(discontinuity_flag); |
2034 | 50.7k | flag(cnt_dropped_flag); |
2035 | 50.7k | fb(9, n_frames); |
2036 | | |
2037 | 49.6k | if (current->full_timestamp_flag) { |
2038 | 14.0k | fc(6, seconds_value, 0, 59); |
2039 | 10.3k | fc(6, minutes_value, 0, 59); |
2040 | 8.32k | fc(5, hours_value, 0, 23); |
2041 | 35.5k | } else { |
2042 | 35.5k | flag(seconds_flag); |
2043 | 35.5k | if (current->seconds_flag) { |
2044 | 30.7k | fc(6, seconds_value, 0, 59); |
2045 | 26.2k | flag(minutes_flag); |
2046 | 23.8k | if (current->minutes_flag) { |
2047 | 17.8k | fc(6, minutes_value, 0, 59); |
2048 | 15.4k | flag(hours_flag); |
2049 | 15.4k | if (current->hours_flag) |
2050 | 15.4k | fc(5, hours_value, 0, 23); |
2051 | 15.4k | } |
2052 | 23.8k | } |
2053 | 35.5k | } |
2054 | | |
2055 | 30.6k | fb(5, time_offset_length); |
2056 | 22.3k | if (current->time_offset_length > 0) |
2057 | 15.6k | fb(current->time_offset_length, time_offset_value); |
2058 | 6.74k | else |
2059 | 6.74k | infer(time_offset_length, 0); |
2060 | | |
2061 | 19.0k | return 0; |
2062 | 22.3k | } cbs_av1.c:cbs_av1_read_metadata_timecode Line | Count | Source | 2026 | 51.0k | { | 2027 | 51.0k | int err; | 2028 | | | 2029 | 51.0k | HEADER("Timecode Metadata"); | 2030 | | | 2031 | 51.0k | fb(5, counting_type); | 2032 | 46.6k | flag(full_timestamp_flag); | 2033 | 46.6k | flag(discontinuity_flag); | 2034 | 46.6k | flag(cnt_dropped_flag); | 2035 | 46.6k | fb(9, n_frames); | 2036 | | | 2037 | 45.6k | if (current->full_timestamp_flag) { | 2038 | 13.4k | fc(6, seconds_value, 0, 59); | 2039 | 9.70k | fc(6, minutes_value, 0, 59); | 2040 | 7.67k | fc(5, hours_value, 0, 23); | 2041 | 32.1k | } else { | 2042 | 32.1k | flag(seconds_flag); | 2043 | 32.1k | if (current->seconds_flag) { | 2044 | 27.9k | fc(6, seconds_value, 0, 59); | 2045 | 23.4k | flag(minutes_flag); | 2046 | 21.0k | if (current->minutes_flag) { | 2047 | 16.1k | fc(6, minutes_value, 0, 59); | 2048 | 13.7k | flag(hours_flag); | 2049 | 13.7k | if (current->hours_flag) | 2050 | 13.7k | fc(5, hours_value, 0, 23); | 2051 | 13.7k | } | 2052 | 21.0k | } | 2053 | 32.1k | } | 2054 | | | 2055 | 26.5k | fb(5, time_offset_length); | 2056 | 18.3k | if (current->time_offset_length > 0) | 2057 | 13.3k | fb(current->time_offset_length, time_offset_value); | 2058 | 4.94k | else | 2059 | 4.94k | infer(time_offset_length, 0); | 2060 | | | 2061 | 14.9k | return 0; | 2062 | 18.3k | } |
cbs_av1.c:cbs_av1_write_metadata_timecode Line | Count | Source | 2026 | 4.07k | { | 2027 | 4.07k | int err; | 2028 | | | 2029 | 4.07k | HEADER("Timecode Metadata"); | 2030 | | | 2031 | 4.07k | fb(5, counting_type); | 2032 | 4.07k | flag(full_timestamp_flag); | 2033 | 4.07k | flag(discontinuity_flag); | 2034 | 4.07k | flag(cnt_dropped_flag); | 2035 | 4.07k | fb(9, n_frames); | 2036 | | | 2037 | 4.07k | if (current->full_timestamp_flag) { | 2038 | 645 | fc(6, seconds_value, 0, 59); | 2039 | 645 | fc(6, minutes_value, 0, 59); | 2040 | 645 | fc(5, hours_value, 0, 23); | 2041 | 3.43k | } else { | 2042 | 3.43k | flag(seconds_flag); | 2043 | 3.43k | if (current->seconds_flag) { | 2044 | 2.71k | fc(6, seconds_value, 0, 59); | 2045 | 2.71k | flag(minutes_flag); | 2046 | 2.71k | if (current->minutes_flag) { | 2047 | 1.69k | fc(6, minutes_value, 0, 59); | 2048 | 1.69k | flag(hours_flag); | 2049 | 1.69k | if (current->hours_flag) | 2050 | 1.69k | fc(5, hours_value, 0, 23); | 2051 | 1.69k | } | 2052 | 2.71k | } | 2053 | 3.43k | } | 2054 | | | 2055 | 4.07k | fb(5, time_offset_length); | 2056 | 4.07k | if (current->time_offset_length > 0) | 2057 | 2.28k | fb(current->time_offset_length, time_offset_value); | 2058 | 1.79k | else | 2059 | 1.79k | infer(time_offset_length, 0); | 2060 | | | 2061 | 4.07k | return 0; | 2062 | 4.07k | } |
|
2063 | | |
2064 | | static int FUNC(metadata_unknown)(CodedBitstreamContext *ctx, RWContext *rw, |
2065 | | AV1RawMetadataUnknown *current) |
2066 | 33.5k | { |
2067 | 33.5k | int err; |
2068 | 33.5k | size_t i; |
2069 | | |
2070 | 33.5k | HEADER("Unknown Metadata"); |
2071 | | |
2072 | | #ifdef READ |
2073 | | current->payload_size = cbs_av1_get_payload_bytes_left(rw); |
2074 | | |
2075 | | current->payload_ref = av_buffer_alloc(current->payload_size); |
2076 | 29.3k | if (!current->payload_ref) |
2077 | 0 | return AVERROR(ENOMEM); |
2078 | 29.3k | current->payload = current->payload_ref->data; |
2079 | 29.3k | #endif |
2080 | | |
2081 | 50.0M | for (i = 0; i < current->payload_size; i++) |
2082 | 50.0M | fbs(8, payload[i], 1, i); |
2083 | | |
2084 | 33.5k | return 0; |
2085 | 29.3k | } cbs_av1.c:cbs_av1_read_metadata_unknown Line | Count | Source | 2066 | 29.3k | { | 2067 | 29.3k | int err; | 2068 | 29.3k | size_t i; | 2069 | | | 2070 | 29.3k | HEADER("Unknown Metadata"); | 2071 | | | 2072 | 29.3k | #ifdef READ | 2073 | 29.3k | current->payload_size = cbs_av1_get_payload_bytes_left(rw); | 2074 | | | 2075 | 29.3k | current->payload_ref = av_buffer_alloc(current->payload_size); | 2076 | 29.3k | if (!current->payload_ref) | 2077 | 0 | return AVERROR(ENOMEM); | 2078 | 29.3k | current->payload = current->payload_ref->data; | 2079 | 29.3k | #endif | 2080 | | | 2081 | 30.8M | for (i = 0; i < current->payload_size; i++) | 2082 | 30.8M | fbs(8, payload[i], 1, i); | 2083 | | | 2084 | 29.3k | return 0; | 2085 | 29.3k | } |
cbs_av1.c:cbs_av1_write_metadata_unknown Line | Count | Source | 2066 | 4.24k | { | 2067 | 4.24k | int err; | 2068 | 4.24k | size_t i; | 2069 | | | 2070 | 4.24k | HEADER("Unknown Metadata"); | 2071 | | | 2072 | | #ifdef READ | 2073 | | current->payload_size = cbs_av1_get_payload_bytes_left(rw); | 2074 | | | 2075 | | current->payload_ref = av_buffer_alloc(current->payload_size); | 2076 | | if (!current->payload_ref) | 2077 | | return AVERROR(ENOMEM); | 2078 | | current->payload = current->payload_ref->data; | 2079 | | #endif | 2080 | | | 2081 | 19.2M | for (i = 0; i < current->payload_size; i++) | 2082 | 19.2M | fbs(8, payload[i], 1, i); | 2083 | | | 2084 | 4.24k | return 0; | 2085 | 4.24k | } |
|
2086 | | |
2087 | | static int FUNC(metadata_obu)(CodedBitstreamContext *ctx, RWContext *rw, |
2088 | | AV1RawMetadata *current) |
2089 | 217k | { |
2090 | 217k | int err; |
2091 | | |
2092 | 217k | leb128(metadata_type); |
2093 | | |
2094 | 211k | switch (current->metadata_type) { |
2095 | 24.1k | case AV1_METADATA_TYPE_HDR_CLL: |
2096 | 24.1k | CHECK(FUNC(metadata_hdr_cll)(ctx, rw, ¤t->metadata.hdr_cll)); |
2097 | 5.07k | break; |
2098 | 20.4k | case AV1_METADATA_TYPE_HDR_MDCV: |
2099 | 20.4k | CHECK(FUNC(metadata_hdr_mdcv)(ctx, rw, ¤t->metadata.hdr_mdcv)); |
2100 | 8.05k | break; |
2101 | 43.4k | case AV1_METADATA_TYPE_SCALABILITY: |
2102 | 43.4k | CHECK(FUNC(metadata_scalability)(ctx, rw, ¤t->metadata.scalability)); |
2103 | 21.1k | break; |
2104 | 34.5k | case AV1_METADATA_TYPE_ITUT_T35: |
2105 | 34.5k | CHECK(FUNC(metadata_itut_t35)(ctx, rw, ¤t->metadata.itut_t35)); |
2106 | 31.9k | break; |
2107 | 55.0k | case AV1_METADATA_TYPE_TIMECODE: |
2108 | 55.0k | CHECK(FUNC(metadata_timecode)(ctx, rw, ¤t->metadata.timecode)); |
2109 | 19.0k | break; |
2110 | 33.5k | default: |
2111 | 33.5k | CHECK(FUNC(metadata_unknown)(ctx, rw, ¤t->metadata.unknown)); |
2112 | 211k | } |
2113 | | |
2114 | 118k | return 0; |
2115 | 211k | } cbs_av1.c:cbs_av1_read_metadata_obu Line | Count | Source | 2089 | 198k | { | 2090 | 198k | int err; | 2091 | | | 2092 | 198k | leb128(metadata_type); | 2093 | | | 2094 | 192k | switch (current->metadata_type) { | 2095 | 23.3k | case AV1_METADATA_TYPE_HDR_CLL: | 2096 | 23.3k | CHECK(FUNC(metadata_hdr_cll)(ctx, rw, ¤t->metadata.hdr_cll)); | 2097 | 4.26k | break; | 2098 | 19.5k | case AV1_METADATA_TYPE_HDR_MDCV: | 2099 | 19.5k | CHECK(FUNC(metadata_hdr_mdcv)(ctx, rw, ¤t->metadata.hdr_mdcv)); | 2100 | 7.11k | break; | 2101 | 37.4k | case AV1_METADATA_TYPE_SCALABILITY: | 2102 | 37.4k | CHECK(FUNC(metadata_scalability)(ctx, rw, ¤t->metadata.scalability)); | 2103 | 16.5k | break; | 2104 | 31.5k | case AV1_METADATA_TYPE_ITUT_T35: | 2105 | 31.5k | CHECK(FUNC(metadata_itut_t35)(ctx, rw, ¤t->metadata.itut_t35)); | 2106 | 28.9k | break; | 2107 | 51.0k | case AV1_METADATA_TYPE_TIMECODE: | 2108 | 51.0k | CHECK(FUNC(metadata_timecode)(ctx, rw, ¤t->metadata.timecode)); | 2109 | 14.9k | break; | 2110 | 29.3k | default: | 2111 | 29.3k | CHECK(FUNC(metadata_unknown)(ctx, rw, ¤t->metadata.unknown)); | 2112 | 192k | } | 2113 | | | 2114 | 101k | return 0; | 2115 | 192k | } |
cbs_av1.c:cbs_av1_write_metadata_obu Line | Count | Source | 2089 | 19.1k | { | 2090 | 19.1k | int err; | 2091 | | | 2092 | 19.1k | leb128(metadata_type); | 2093 | | | 2094 | 19.1k | switch (current->metadata_type) { | 2095 | 806 | case AV1_METADATA_TYPE_HDR_CLL: | 2096 | 806 | CHECK(FUNC(metadata_hdr_cll)(ctx, rw, ¤t->metadata.hdr_cll)); | 2097 | 806 | break; | 2098 | 942 | case AV1_METADATA_TYPE_HDR_MDCV: | 2099 | 942 | CHECK(FUNC(metadata_hdr_mdcv)(ctx, rw, ¤t->metadata.hdr_mdcv)); | 2100 | 942 | break; | 2101 | 6.02k | case AV1_METADATA_TYPE_SCALABILITY: | 2102 | 6.02k | CHECK(FUNC(metadata_scalability)(ctx, rw, ¤t->metadata.scalability)); | 2103 | 4.61k | break; | 2104 | 4.61k | case AV1_METADATA_TYPE_ITUT_T35: | 2105 | 3.01k | CHECK(FUNC(metadata_itut_t35)(ctx, rw, ¤t->metadata.itut_t35)); | 2106 | 3.01k | break; | 2107 | 4.07k | case AV1_METADATA_TYPE_TIMECODE: | 2108 | 4.07k | CHECK(FUNC(metadata_timecode)(ctx, rw, ¤t->metadata.timecode)); | 2109 | 4.07k | break; | 2110 | 4.24k | default: | 2111 | 4.24k | CHECK(FUNC(metadata_unknown)(ctx, rw, ¤t->metadata.unknown)); | 2112 | 19.1k | } | 2113 | | | 2114 | 17.6k | return 0; | 2115 | 19.1k | } |
|
2116 | | #endif |
2117 | | |
2118 | | #if CBS_AV1_OBU_PADDING |
2119 | | static int FUNC(padding_obu)(CodedBitstreamContext *ctx, RWContext *rw, |
2120 | | AV1RawPadding *current) |
2121 | 4.10M | { |
2122 | 4.10M | int i, err; |
2123 | | |
2124 | 4.10M | HEADER("Padding"); |
2125 | | |
2126 | | #ifdef READ |
2127 | | // The payload runs up to the start of the trailing bits, but there might |
2128 | | // be arbitrarily many trailing zeroes so we need to read through twice. |
2129 | | current->payload_size = cbs_av1_get_payload_bytes_left(rw); |
2130 | | |
2131 | | current->payload_ref = av_buffer_alloc(current->payload_size); |
2132 | 2.08M | if (!current->payload_ref) |
2133 | 0 | return AVERROR(ENOMEM); |
2134 | 2.08M | current->payload = current->payload_ref->data; |
2135 | 2.08M | #endif |
2136 | | |
2137 | 32.8M | for (i = 0; i < current->payload_size; i++) |
2138 | 28.7M | xf(8, obu_padding_byte[i], current->payload[i], 0x00, 0xff, 1, i); |
2139 | | |
2140 | 4.10M | return 0; |
2141 | 2.08M | } cbs_av1.c:cbs_av1_read_padding_obu Line | Count | Source | 2121 | 2.08M | { | 2122 | 2.08M | int i, err; | 2123 | | | 2124 | 2.08M | HEADER("Padding"); | 2125 | | | 2126 | 2.08M | #ifdef READ | 2127 | | // The payload runs up to the start of the trailing bits, but there might | 2128 | | // be arbitrarily many trailing zeroes so we need to read through twice. | 2129 | 2.08M | current->payload_size = cbs_av1_get_payload_bytes_left(rw); | 2130 | | | 2131 | 2.08M | current->payload_ref = av_buffer_alloc(current->payload_size); | 2132 | 2.08M | if (!current->payload_ref) | 2133 | 0 | return AVERROR(ENOMEM); | 2134 | 2.08M | current->payload = current->payload_ref->data; | 2135 | 2.08M | #endif | 2136 | | | 2137 | 20.0M | for (i = 0; i < current->payload_size; i++) | 2138 | 17.9M | xf(8, obu_padding_byte[i], current->payload[i], 0x00, 0xff, 1, i); | 2139 | | | 2140 | 2.08M | return 0; | 2141 | 2.08M | } |
cbs_av1.c:cbs_av1_write_padding_obu Line | Count | Source | 2121 | 2.02M | { | 2122 | 2.02M | int i, err; | 2123 | | | 2124 | 2.02M | HEADER("Padding"); | 2125 | | | 2126 | | #ifdef READ | 2127 | | // The payload runs up to the start of the trailing bits, but there might | 2128 | | // be arbitrarily many trailing zeroes so we need to read through twice. | 2129 | | current->payload_size = cbs_av1_get_payload_bytes_left(rw); | 2130 | | | 2131 | | current->payload_ref = av_buffer_alloc(current->payload_size); | 2132 | | if (!current->payload_ref) | 2133 | | return AVERROR(ENOMEM); | 2134 | | current->payload = current->payload_ref->data; | 2135 | | #endif | 2136 | | | 2137 | 12.8M | for (i = 0; i < current->payload_size; i++) | 2138 | 10.7M | xf(8, obu_padding_byte[i], current->payload[i], 0x00, 0xff, 1, i); | 2139 | | | 2140 | 2.02M | return 0; | 2141 | 2.02M | } |
|
2142 | | #endif |