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