Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (C) 2007 Marco Gerards <marco@gnu.org> | ||
3 | * Copyright (C) 2009 David Conrad | ||
4 | * Copyright (C) 2011 Jordi Ortiz | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | /** | ||
24 | * @file | ||
25 | * Dirac Decoder | ||
26 | * @author Marco Gerards <marco@gnu.org>, David Conrad, Jordi Ortiz <nenjordi@gmail.com> | ||
27 | */ | ||
28 | |||
29 | #include "config.h" | ||
30 | |||
31 | #include "libavutil/mem.h" | ||
32 | #include "libavutil/pixdesc.h" | ||
33 | |||
34 | #include "dirac.h" | ||
35 | #include "get_bits.h" | ||
36 | #include "golomb.h" | ||
37 | #include "mpeg12data.h" | ||
38 | |||
39 | #if CONFIG_DIRAC_PARSE | ||
40 | |||
41 | typedef struct dirac_source_params { | ||
42 | unsigned width; | ||
43 | unsigned height; | ||
44 | uint8_t chroma_format; ///< 0: 444 1: 422 2: 420 | ||
45 | |||
46 | uint8_t interlaced; | ||
47 | uint8_t top_field_first; | ||
48 | |||
49 | uint8_t frame_rate_index; ///< index into dirac_frame_rate[] | ||
50 | uint8_t aspect_ratio_index; ///< index into dirac_aspect_ratio[] | ||
51 | |||
52 | uint16_t clean_width; | ||
53 | uint16_t clean_height; | ||
54 | uint16_t clean_left_offset; | ||
55 | uint16_t clean_right_offset; | ||
56 | |||
57 | uint8_t pixel_range_index; ///< index into dirac_pixel_range_presets[] | ||
58 | uint8_t color_spec_index; ///< index into dirac_color_spec_presets[] | ||
59 | } dirac_source_params; | ||
60 | |||
61 | /* defaults for source parameters */ | ||
62 | static const dirac_source_params dirac_source_parameters_defaults[] = { | ||
63 | { 640, 480, 2, 0, 0, 1, 1, 640, 480, 0, 0, 1, 0 }, | ||
64 | { 176, 120, 2, 0, 0, 9, 2, 176, 120, 0, 0, 1, 1 }, | ||
65 | { 176, 144, 2, 0, 1, 10, 3, 176, 144, 0, 0, 1, 2 }, | ||
66 | { 352, 240, 2, 0, 0, 9, 2, 352, 240, 0, 0, 1, 1 }, | ||
67 | { 352, 288, 2, 0, 1, 10, 3, 352, 288, 0, 0, 1, 2 }, | ||
68 | { 704, 480, 2, 0, 0, 9, 2, 704, 480, 0, 0, 1, 1 }, | ||
69 | { 704, 576, 2, 0, 1, 10, 3, 704, 576, 0, 0, 1, 2 }, | ||
70 | { 720, 480, 1, 1, 0, 4, 2, 704, 480, 8, 0, 3, 1 }, | ||
71 | { 720, 576, 1, 1, 1, 3, 3, 704, 576, 8, 0, 3, 2 }, | ||
72 | |||
73 | { 1280, 720, 1, 0, 1, 7, 1, 1280, 720, 0, 0, 3, 3 }, | ||
74 | { 1280, 720, 1, 0, 1, 6, 1, 1280, 720, 0, 0, 3, 3 }, | ||
75 | { 1920, 1080, 1, 1, 1, 4, 1, 1920, 1080, 0, 0, 3, 3 }, | ||
76 | { 1920, 1080, 1, 1, 1, 3, 1, 1920, 1080, 0, 0, 3, 3 }, | ||
77 | { 1920, 1080, 1, 0, 1, 7, 1, 1920, 1080, 0, 0, 3, 3 }, | ||
78 | { 1920, 1080, 1, 0, 1, 6, 1, 1920, 1080, 0, 0, 3, 3 }, | ||
79 | { 2048, 1080, 0, 0, 1, 2, 1, 2048, 1080, 0, 0, 4, 4 }, | ||
80 | { 4096, 2160, 0, 0, 1, 2, 1, 4096, 2160, 0, 0, 4, 4 }, | ||
81 | |||
82 | { 3840, 2160, 1, 0, 1, 7, 1, 3840, 2160, 0, 0, 3, 3 }, | ||
83 | { 3840, 2160, 1, 0, 1, 6, 1, 3840, 2160, 0, 0, 3, 3 }, | ||
84 | { 7680, 4320, 1, 0, 1, 7, 1, 3840, 2160, 0, 0, 3, 3 }, | ||
85 | { 7680, 4320, 1, 0, 1, 6, 1, 3840, 2160, 0, 0, 3, 3 }, | ||
86 | }; | ||
87 | |||
88 | /* [DIRAC_STD] Table 10.4 - Available preset pixel aspect ratio values */ | ||
89 | static const AVRational dirac_preset_aspect_ratios[] = { | ||
90 | { 1, 1 }, | ||
91 | { 10, 11 }, | ||
92 | { 12, 11 }, | ||
93 | { 40, 33 }, | ||
94 | { 16, 11 }, | ||
95 | { 4, 3 }, | ||
96 | }; | ||
97 | |||
98 | /* [DIRAC_STD] Values 9,10 of 10.3.5 Frame Rate. | ||
99 | * Table 10.3 Available preset frame rate values | ||
100 | */ | ||
101 | static const AVRational dirac_frame_rate[] = { | ||
102 | { 15000, 1001 }, | ||
103 | { 25, 2 }, | ||
104 | }; | ||
105 | |||
106 | /* [DIRAC_STD] This should be equivalent to Table 10.5 Available signal | ||
107 | * range presets */ | ||
108 | static const struct { | ||
109 | uint8_t bitdepth; | ||
110 | enum AVColorRange color_range; | ||
111 | } pixel_range_presets[] = { | ||
112 | { 8, AVCOL_RANGE_JPEG }, | ||
113 | { 8, AVCOL_RANGE_MPEG }, | ||
114 | { 10, AVCOL_RANGE_MPEG }, | ||
115 | { 12, AVCOL_RANGE_MPEG }, | ||
116 | }; | ||
117 | |||
118 | static const enum AVColorPrimaries dirac_primaries[] = { | ||
119 | AVCOL_PRI_BT709, | ||
120 | AVCOL_PRI_SMPTE170M, | ||
121 | AVCOL_PRI_BT470BG, | ||
122 | }; | ||
123 | |||
124 | static const struct { | ||
125 | enum AVColorPrimaries color_primaries; | ||
126 | enum AVColorSpace colorspace; | ||
127 | enum AVColorTransferCharacteristic color_trc; | ||
128 | } dirac_color_presets[] = { | ||
129 | { AVCOL_PRI_BT709, AVCOL_SPC_BT709, AVCOL_TRC_BT709 }, | ||
130 | { AVCOL_PRI_SMPTE170M, AVCOL_SPC_BT470BG, AVCOL_TRC_BT709 }, | ||
131 | { AVCOL_PRI_BT470BG, AVCOL_SPC_BT470BG, AVCOL_TRC_BT709 }, | ||
132 | { AVCOL_PRI_BT709, AVCOL_SPC_BT709, AVCOL_TRC_BT709 }, | ||
133 | { AVCOL_PRI_BT709, AVCOL_SPC_BT709, AVCOL_TRC_UNSPECIFIED /* DCinema */ }, | ||
134 | }; | ||
135 | |||
136 | /* [DIRAC_STD] Table 10.2 Supported chroma sampling formats */ | ||
137 | static const enum AVPixelFormat dirac_pix_fmt[][3] = { | ||
138 | {AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV444P10, AV_PIX_FMT_YUV444P12}, | ||
139 | {AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV422P12}, | ||
140 | {AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV420P12}, | ||
141 | }; | ||
142 | |||
143 | /* [DIRAC_STD] 10.3 Parse Source Parameters. | ||
144 | * source_parameters(base_video_format) */ | ||
145 | 70 | static int parse_source_parameters(AVDiracSeqHeader *dsh, GetBitContext *gb, | |
146 | void *log_ctx) | ||
147 | { | ||
148 | 70 | AVRational frame_rate = { 0, 0 }; | |
149 | 70 | unsigned luma_depth = 8, luma_offset = 16; | |
150 | int idx; | ||
151 | int chroma_x_shift, chroma_y_shift; | ||
152 | int ret; | ||
153 | |||
154 | /* [DIRAC_STD] 10.3.2 Frame size. frame_size(video_params) */ | ||
155 | /* [DIRAC_STD] custom_dimensions_flag */ | ||
156 |
1/2✓ Branch 1 taken 70 times.
✗ Branch 2 not taken.
|
70 | if (get_bits1(gb)) { |
157 | 70 | dsh->width = get_interleaved_ue_golomb(gb); /* [DIRAC_STD] FRAME_WIDTH */ | |
158 | 70 | dsh->height = get_interleaved_ue_golomb(gb); /* [DIRAC_STD] FRAME_HEIGHT */ | |
159 | } | ||
160 | |||
161 | /* [DIRAC_STD] 10.3.3 Chroma Sampling Format. | ||
162 | * chroma_sampling_format(video_params) */ | ||
163 | /* [DIRAC_STD] custom_chroma_format_flag */ | ||
164 |
1/2✓ Branch 1 taken 70 times.
✗ Branch 2 not taken.
|
70 | if (get_bits1(gb)) |
165 | /* [DIRAC_STD] CHROMA_FORMAT_INDEX */ | ||
166 | 70 | dsh->chroma_format = get_interleaved_ue_golomb(gb); | |
167 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (dsh->chroma_format > 2U) { |
168 | ✗ | if (log_ctx) | |
169 | ✗ | av_log(log_ctx, AV_LOG_ERROR, "Unknown chroma format %d\n", | |
170 | ✗ | dsh->chroma_format); | |
171 | ✗ | return AVERROR_INVALIDDATA; | |
172 | } | ||
173 | |||
174 | /* [DIRAC_STD] 10.3.4 Scan Format. scan_format(video_params) */ | ||
175 | /* [DIRAC_STD] custom_scan_format_flag */ | ||
176 |
1/2✓ Branch 1 taken 70 times.
✗ Branch 2 not taken.
|
70 | if (get_bits1(gb)) |
177 | /* [DIRAC_STD] SOURCE_SAMPLING */ | ||
178 | 70 | dsh->interlaced = get_interleaved_ue_golomb(gb); | |
179 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (dsh->interlaced > 1U) |
180 | ✗ | return AVERROR_INVALIDDATA; | |
181 | |||
182 | /* [DIRAC_STD] 10.3.5 Frame Rate. frame_rate(video_params) */ | ||
183 |
1/2✓ Branch 1 taken 70 times.
✗ Branch 2 not taken.
|
70 | if (get_bits1(gb)) { /* [DIRAC_STD] custom_frame_rate_flag */ |
184 | 70 | dsh->frame_rate_index = get_interleaved_ue_golomb(gb); | |
185 | |||
186 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (dsh->frame_rate_index > 10U) |
187 | ✗ | return AVERROR_INVALIDDATA; | |
188 | |||
189 |
2/2✓ Branch 0 taken 66 times.
✓ Branch 1 taken 4 times.
|
70 | if (!dsh->frame_rate_index) { |
190 | /* [DIRAC_STD] FRAME_RATE_NUMER */ | ||
191 | 66 | frame_rate.num = get_interleaved_ue_golomb(gb); | |
192 | /* [DIRAC_STD] FRAME_RATE_DENOM */ | ||
193 | 66 | frame_rate.den = get_interleaved_ue_golomb(gb); | |
194 | } | ||
195 | } | ||
196 | /* [DIRAC_STD] preset_frame_rate(video_params, index) */ | ||
197 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 66 times.
|
70 | if (dsh->frame_rate_index > 0) { |
198 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | if (dsh->frame_rate_index <= 8) |
199 | 4 | frame_rate = ff_mpeg12_frame_rate_tab[dsh->frame_rate_index]; | |
200 | else | ||
201 | /* [DIRAC_STD] Table 10.3 values 9-10 */ | ||
202 | ✗ | frame_rate = dirac_frame_rate[dsh->frame_rate_index - 9]; | |
203 | } | ||
204 | 70 | dsh->framerate = frame_rate; | |
205 | |||
206 | /* [DIRAC_STD] 10.3.6 Pixel Aspect Ratio. | ||
207 | * pixel_aspect_ratio(video_params) */ | ||
208 |
1/2✓ Branch 1 taken 70 times.
✗ Branch 2 not taken.
|
70 | if (get_bits1(gb)) { /* [DIRAC_STD] custom_pixel_aspect_ratio_flag */ |
209 | /* [DIRAC_STD] index */ | ||
210 | 70 | dsh->aspect_ratio_index = get_interleaved_ue_golomb(gb); | |
211 | |||
212 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (dsh->aspect_ratio_index > 6U) |
213 | ✗ | return AVERROR_INVALIDDATA; | |
214 | |||
215 |
2/2✓ Branch 0 taken 66 times.
✓ Branch 1 taken 4 times.
|
70 | if (!dsh->aspect_ratio_index) { |
216 | 66 | dsh->sample_aspect_ratio.num = get_interleaved_ue_golomb(gb); | |
217 | 66 | dsh->sample_aspect_ratio.den = get_interleaved_ue_golomb(gb); | |
218 | } | ||
219 | } | ||
220 | /* [DIRAC_STD] Take value from Table 10.4 Available preset pixel | ||
221 | * aspect ratio values */ | ||
222 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 66 times.
|
70 | if (dsh->aspect_ratio_index > 0) |
223 | 4 | dsh->sample_aspect_ratio = | |
224 | 4 | dirac_preset_aspect_ratios[dsh->aspect_ratio_index - 1]; | |
225 | |||
226 | /* [DIRAC_STD] 10.3.7 Clean area. clean_area(video_params) */ | ||
227 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 66 times.
|
70 | if (get_bits1(gb)) { /* [DIRAC_STD] custom_clean_area_flag */ |
228 | /* [DIRAC_STD] CLEAN_WIDTH */ | ||
229 | 4 | dsh->clean_width = get_interleaved_ue_golomb(gb); | |
230 | /* [DIRAC_STD] CLEAN_HEIGHT */ | ||
231 | 4 | dsh->clean_height = get_interleaved_ue_golomb(gb); | |
232 | /* [DIRAC_STD] CLEAN_LEFT_OFFSET */ | ||
233 | 4 | dsh->clean_left_offset = get_interleaved_ue_golomb(gb); | |
234 | /* [DIRAC_STD] CLEAN_RIGHT_OFFSET */ | ||
235 | 4 | dsh->clean_right_offset = get_interleaved_ue_golomb(gb); | |
236 | } | ||
237 | |||
238 | /* [DIRAC_STD] 10.3.8 Signal range. signal_range(video_params) | ||
239 | * WARNING: Some adaptation seems to be done using the | ||
240 | * AVCOL_RANGE_MPEG/JPEG values */ | ||
241 |
1/2✓ Branch 1 taken 70 times.
✗ Branch 2 not taken.
|
70 | if (get_bits1(gb)) { /* [DIRAC_STD] custom_signal_range_flag */ |
242 | /* [DIRAC_STD] index */ | ||
243 | 70 | dsh->pixel_range_index = get_interleaved_ue_golomb(gb); | |
244 | |||
245 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (dsh->pixel_range_index > 4U) |
246 | ✗ | return AVERROR_INVALIDDATA; | |
247 | |||
248 | /* This assumes either fullrange or MPEG levels only */ | ||
249 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (!dsh->pixel_range_index) { |
250 | ✗ | luma_offset = get_interleaved_ue_golomb(gb); | |
251 | ✗ | luma_depth = av_log2(get_interleaved_ue_golomb(gb)) + 1; | |
252 | ✗ | get_interleaved_ue_golomb(gb); /* chroma offset */ | |
253 | ✗ | get_interleaved_ue_golomb(gb); /* chroma excursion */ | |
254 | ✗ | dsh->color_range = luma_offset ? AVCOL_RANGE_MPEG | |
255 | ✗ | : AVCOL_RANGE_JPEG; | |
256 | } | ||
257 | } | ||
258 | /* [DIRAC_STD] Table 10.5 | ||
259 | * Available signal range presets <--> pixel_range_presets */ | ||
260 |
1/2✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 | if (dsh->pixel_range_index > 0) { |
261 | 70 | idx = dsh->pixel_range_index - 1; | |
262 | 70 | luma_depth = pixel_range_presets[idx].bitdepth; | |
263 | 70 | dsh->color_range = pixel_range_presets[idx].color_range; | |
264 | } | ||
265 | |||
266 | 70 | dsh->bit_depth = luma_depth; | |
267 | |||
268 | /* Full range 8 bts uses the same pix_fmts as limited range 8 bits */ | ||
269 | 70 | dsh->pixel_range_index += dsh->pixel_range_index == 1; | |
270 | |||
271 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (dsh->pixel_range_index < 2U) |
272 | ✗ | return AVERROR_INVALIDDATA; | |
273 | |||
274 | 70 | dsh->pix_fmt = dirac_pix_fmt[dsh->chroma_format][dsh->pixel_range_index-2]; | |
275 | 70 | ret = av_pix_fmt_get_chroma_sub_sample(dsh->pix_fmt, &chroma_x_shift, &chroma_y_shift); | |
276 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (ret) |
277 | ✗ | return ret; | |
278 | |||
279 |
2/4✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 70 times.
|
70 | if ((dsh->width % (1<<chroma_x_shift)) || (dsh->height % (1<<chroma_y_shift))) { |
280 | ✗ | if (log_ctx) | |
281 | ✗ | av_log(log_ctx, AV_LOG_ERROR, "Dimensions must be an integer multiple of the chroma subsampling\n"); | |
282 | ✗ | return AVERROR_INVALIDDATA; | |
283 | } | ||
284 | |||
285 | /* [DIRAC_STD] 10.3.9 Colour specification. colour_spec(video_params) */ | ||
286 |
1/2✓ Branch 1 taken 70 times.
✗ Branch 2 not taken.
|
70 | if (get_bits1(gb)) { /* [DIRAC_STD] custom_colour_spec_flag */ |
287 | /* [DIRAC_STD] index */ | ||
288 | 70 | idx = dsh->color_spec_index = get_interleaved_ue_golomb(gb); | |
289 | |||
290 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (dsh->color_spec_index > 4U) |
291 | ✗ | return AVERROR_INVALIDDATA; | |
292 | |||
293 | 70 | dsh->color_primaries = dirac_color_presets[idx].color_primaries; | |
294 | 70 | dsh->colorspace = dirac_color_presets[idx].colorspace; | |
295 | 70 | dsh->color_trc = dirac_color_presets[idx].color_trc; | |
296 | |||
297 |
2/2✓ Branch 0 taken 66 times.
✓ Branch 1 taken 4 times.
|
70 | if (!dsh->color_spec_index) { |
298 | /* [DIRAC_STD] 10.3.9.1 Colour primaries */ | ||
299 |
1/2✓ Branch 1 taken 66 times.
✗ Branch 2 not taken.
|
66 | if (get_bits1(gb)) { |
300 | 66 | idx = get_interleaved_ue_golomb(gb); | |
301 |
1/2✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
|
66 | if (idx < 3U) |
302 | 66 | dsh->color_primaries = dirac_primaries[idx]; | |
303 | } | ||
304 | /* [DIRAC_STD] 10.3.9.2 Colour matrix */ | ||
305 |
1/2✓ Branch 1 taken 66 times.
✗ Branch 2 not taken.
|
66 | if (get_bits1(gb)) { |
306 | 66 | idx = get_interleaved_ue_golomb(gb); | |
307 |
1/2✓ Branch 0 taken 66 times.
✗ Branch 1 not taken.
|
66 | if (!idx) |
308 | 66 | dsh->colorspace = AVCOL_SPC_BT709; | |
309 | ✗ | else if (idx == 1) | |
310 | ✗ | dsh->colorspace = AVCOL_SPC_BT470BG; | |
311 | } | ||
312 | /* [DIRAC_STD] 10.3.9.3 Transfer function */ | ||
313 |
2/4✓ Branch 1 taken 66 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 66 times.
✗ Branch 5 not taken.
|
66 | if (get_bits1(gb) && !get_interleaved_ue_golomb(gb)) |
314 | 66 | dsh->color_trc = AVCOL_TRC_BT709; | |
315 | } | ||
316 | } else { | ||
317 | ✗ | idx = dsh->color_spec_index; | |
318 | ✗ | dsh->color_primaries = dirac_color_presets[idx].color_primaries; | |
319 | ✗ | dsh->colorspace = dirac_color_presets[idx].colorspace; | |
320 | ✗ | dsh->color_trc = dirac_color_presets[idx].color_trc; | |
321 | } | ||
322 | |||
323 | 70 | return 0; | |
324 | } | ||
325 | |||
326 | /* [DIRAC_STD] 10. Sequence Header. sequence_header() */ | ||
327 | 70 | int av_dirac_parse_sequence_header(AVDiracSeqHeader **pdsh, | |
328 | const uint8_t *buf, size_t buf_size, | ||
329 | void *log_ctx) | ||
330 | { | ||
331 | AVDiracSeqHeader *dsh; | ||
332 | GetBitContext gb; | ||
333 | unsigned video_format, picture_coding_mode; | ||
334 | int ret; | ||
335 | |||
336 | 70 | dsh = av_mallocz(sizeof(*dsh)); | |
337 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (!dsh) |
338 | ✗ | return AVERROR(ENOMEM); | |
339 | |||
340 | 70 | ret = init_get_bits8(&gb, buf, buf_size); | |
341 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (ret < 0) |
342 | ✗ | goto fail; | |
343 | |||
344 | /* [DIRAC_SPEC] 10.1 Parse Parameters. parse_parameters() */ | ||
345 | 70 | dsh->version.major = get_interleaved_ue_golomb(&gb); | |
346 | 70 | dsh->version.minor = get_interleaved_ue_golomb(&gb); | |
347 | 70 | dsh->profile = get_interleaved_ue_golomb(&gb); | |
348 | 70 | dsh->level = get_interleaved_ue_golomb(&gb); | |
349 | /* [DIRAC_SPEC] sequence_header() -> base_video_format as defined in | ||
350 | * 10.2 Base Video Format, table 10.1 Dirac predefined video formats */ | ||
351 | 70 | video_format = get_interleaved_ue_golomb(&gb); | |
352 | |||
353 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
70 | if (dsh->version.major < 2 && log_ctx) |
354 | ✗ | av_log(log_ctx, AV_LOG_WARNING, "Stream is old and may not work\n"); | |
355 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
70 | else if (dsh->version.major > 2 && log_ctx) |
356 | ✗ | av_log(log_ctx, AV_LOG_WARNING, "Stream may have unhandled features\n"); | |
357 | |||
358 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (video_format > 20U) { |
359 | ✗ | ret = AVERROR_INVALIDDATA; | |
360 | ✗ | goto fail; | |
361 | } | ||
362 | |||
363 | /* Fill in defaults for the source parameters. */ | ||
364 | 70 | dsh->width = dirac_source_parameters_defaults[video_format].width; | |
365 | 70 | dsh->height = dirac_source_parameters_defaults[video_format].height; | |
366 | 70 | dsh->chroma_format = dirac_source_parameters_defaults[video_format].chroma_format; | |
367 | 70 | dsh->interlaced = dirac_source_parameters_defaults[video_format].interlaced; | |
368 | 70 | dsh->top_field_first = dirac_source_parameters_defaults[video_format].top_field_first; | |
369 | 70 | dsh->frame_rate_index = dirac_source_parameters_defaults[video_format].frame_rate_index; | |
370 | 70 | dsh->aspect_ratio_index = dirac_source_parameters_defaults[video_format].aspect_ratio_index; | |
371 | 70 | dsh->clean_width = dirac_source_parameters_defaults[video_format].clean_width; | |
372 | 70 | dsh->clean_height = dirac_source_parameters_defaults[video_format].clean_height; | |
373 | 70 | dsh->clean_left_offset = dirac_source_parameters_defaults[video_format].clean_left_offset; | |
374 | 70 | dsh->clean_right_offset = dirac_source_parameters_defaults[video_format].clean_right_offset; | |
375 | 70 | dsh->pixel_range_index = dirac_source_parameters_defaults[video_format].pixel_range_index; | |
376 | 70 | dsh->color_spec_index = dirac_source_parameters_defaults[video_format].color_spec_index; | |
377 | |||
378 | /* [DIRAC_STD] 10.3 Source Parameters | ||
379 | * Override the defaults. */ | ||
380 | 70 | ret = parse_source_parameters(dsh, &gb, log_ctx); | |
381 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (ret < 0) |
382 | ✗ | goto fail; | |
383 | |||
384 | /* [DIRAC_STD] picture_coding_mode shall be 0 for fields and 1 for frames | ||
385 | * currently only used to signal field coding */ | ||
386 | 70 | picture_coding_mode = get_interleaved_ue_golomb(&gb); | |
387 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 70 times.
|
70 | if (picture_coding_mode != 0) { |
388 | ✗ | if (log_ctx) { | |
389 | ✗ | av_log(log_ctx, AV_LOG_ERROR, "Unsupported picture coding mode %d", | |
390 | picture_coding_mode); | ||
391 | } | ||
392 | ✗ | ret = AVERROR_INVALIDDATA; | |
393 | ✗ | goto fail; | |
394 | } | ||
395 | |||
396 | 70 | *pdsh = dsh; | |
397 | 70 | return 0; | |
398 | ✗ | fail: | |
399 | ✗ | av_freep(&dsh); | |
400 | ✗ | *pdsh = NULL; | |
401 | ✗ | return ret; | |
402 | } | ||
403 | #else | ||
404 | int av_dirac_parse_sequence_header(AVDiracSeqHeader **pdsh, | ||
405 | const uint8_t *buf, size_t buf_size, | ||
406 | void *log_ctx) | ||
407 | { | ||
408 | return AVERROR(ENOSYS); | ||
409 | } | ||
410 | #endif | ||
411 |