1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... SEI decoding
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * H.264 / AVC / MPEG-4 part10 SEI decoding.
25 * @author Michael Niedermayer <michaelni@gmx.at>
26 */
27
29 #include <stdio.h>
30 #include <string.h>
41
42 #define AVERROR_PS_NOT_FOUND FFERRTAG(0xF8,'?','P','S')
43
45 1, 1, 1, 2, 2, 3, 3, 2, 3
46 };
47
49 {
50 h->recovery_point.recovery_frame_cnt = -1;
51
52 h->picture_timing.dpb_output_delay = 0;
53 h->picture_timing.cpb_removal_delay = -1;
54
55 h->picture_timing.present = 0;
56 h->buffering_period.present = 0;
57 h->common.frame_packing.present = 0;
58 h->common.display_orientation.present = 0;
59 h->common.afd.present = 0;
60
62 }
63
65 void *logctx)
66 {
69
72
73 if (
sps->nal_hrd_parameters_present_flag ||
74 sps->vcl_hrd_parameters_present_flag) {
77 }
78 if (
sps->pic_struct_present_flag) {
79 unsigned int i, num_clock_ts;
80
83
86
89 for (
i = 0;
i < num_clock_ts;
i++) {
90 if (
get_bits(&gb, 1)) {
/* clock_timestamp_flag */
92 unsigned int full_timestamp_flag;
93 unsigned int counting_type, cnt_dropped_flag;
95 skip_bits(&gb, 1);
/* nuit_field_based_flag */
96 counting_type =
get_bits(&gb, 5);
/* counting_type */
97 full_timestamp_flag =
get_bits(&gb, 1);
98 skip_bits(&gb, 1);
/* discontinuity_flag */
99 cnt_dropped_flag =
get_bits(&gb, 1);
/* cnt_dropped_flag */
100 if (cnt_dropped_flag && counting_type > 1 && counting_type < 7)
103 if (full_timestamp_flag) {
108 } else {
110 if (
get_bits(&gb, 1)) {
/* seconds_flag */
112 if (
get_bits(&gb, 1)) {
/* minutes_flag */
114 if (
get_bits(&gb, 1))
/* hours_flag */
116 }
117 }
118 }
119
120 if (
sps->time_offset_length > 0)
122 sps->time_offset_length);
/* time_offset */
123 }
124 }
125
127 h->ct_type,
h->pic_struct);
128 }
129
130 return 0;
131 }
132
134 void *logctx)
135 {
137
138 if (
size >
sizeof(
h->payload)) {
141 }
143
144 h->payload_size_bytes =
size;
145
147 return 0;
148 }
149
151 {
153
155 av_log(logctx,
AV_LOG_ERROR,
"recovery_frame_cnt %u is out of range\n", recovery_frame_cnt);
157 }
158
159 h->recovery_frame_cnt = recovery_frame_cnt;
160 /* 1b exact_match_flag,
161 * 1b broken_link_flag,
162 * 2b changing_slice_group_idc */
164
165 return 0;
166 }
167
170 {
171 unsigned int sps_id;
172 int sched_sel_idx;
174
176 if (sps_id > 31 || !ps->
sps_list[sps_id]) {
178 "non-existing SPS %d referenced in buffering period\n", sps_id);
180 }
182
183 // NOTE: This is really so duplicated in the standard... See H.264, D.1.1
184 if (
sps->nal_hrd_parameters_present_flag) {
185 for (sched_sel_idx = 0; sched_sel_idx <
sps->cpb_cnt; sched_sel_idx++) {
186 h->initial_cpb_removal_delay[sched_sel_idx] =
188 // initial_cpb_removal_delay_offset
190 }
191 }
192 if (
sps->vcl_hrd_parameters_present_flag) {
193 for (sched_sel_idx = 0; sched_sel_idx <
sps->cpb_cnt; sched_sel_idx++) {
194 h->initial_cpb_removal_delay[sched_sel_idx] =
196 // initial_cpb_removal_delay_offset
198 }
199 }
200
202 return 0;
203 }
204
206 {
207 h->green_metadata_type = bytestream2_get_byte(gb);
208
209 if (
h->green_metadata_type == 0) {
210 h->period_type = bytestream2_get_byte(gb);
211
212 if (
h->period_type == 2)
213 h->num_seconds = bytestream2_get_be16(gb);
214 else if (
h->period_type == 3)
215 h->num_pictures = bytestream2_get_be16(gb);
216
217 h->percent_non_zero_macroblocks = bytestream2_get_byte(gb);
218 h->percent_intra_coded_macroblocks = bytestream2_get_byte(gb);
219 h->percent_six_tap_filtering = bytestream2_get_byte(gb);
220 h->percent_alpha_point_deblocking_instance = bytestream2_get_byte(gb);
221
222 }
else if (
h->green_metadata_type == 1) {
223 h->xsd_metric_type = bytestream2_get_byte(gb);
224 h->xsd_metric_value = bytestream2_get_be16(gb);
225 }
226
227 return 0;
228 }
229
232 {
234 int master_ret = 0;
235
239
246
247 do {
250 type += bytestream2_peek_byteu(&gbyte);
251 } while (bytestream2_get_byteu(&gbyte) == 255);
252
253 do {
256 size += bytestream2_peek_byteu(&gbyte);
257 } while (bytestream2_get_byteu(&gbyte) == 255);
258
263 }
264
269
273 break;
276 break;
279 break;
282 break;
283 default:
285 &gb_payload, &gbyte_payload, logctx);
288 }
293
297 }
298
300 }
301
302 return master_ret;
303 }
304
306 {
307 if (
h->arrangement_cancel_flag == 0) {
308 switch (
h->arrangement_type) {
310 if (
h->content_interpretation_type == 2)
311 return "checkerboard_rl";
312 else
313 return "checkerboard_lr";
315 if (
h->content_interpretation_type == 2)
316 return "col_interleaved_rl";
317 else
318 return "col_interleaved_lr";
320 if (
h->content_interpretation_type == 2)
321 return "row_interleaved_rl";
322 else
323 return "row_interleaved_lr";
325 if (
h->content_interpretation_type == 2)
326 return "right_left";
327 else
328 return "left_right";
330 if (
h->content_interpretation_type == 2)
331 return "bottom_top";
332 else
333 return "top_bottom";
335 if (
h->content_interpretation_type == 2)
336 return "block_rl";
337 else
338 return "block_lr";
340 default:
341 return "mono";
342 }
343 }
else if (
h->arrangement_cancel_flag == 1) {
344 return "mono";
345 } else {
347 }
348 }