1
|
1 /*
|
9852
|
2 * header.c
|
12932
|
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
|
|
4 * Copyright (C) 2003 Regis Duchesne <hpreg@zoy.org>
|
9852
|
5 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
1
|
6 *
|
|
7 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
|
9852
|
8 * See http://libmpeg2.sourceforge.net/ for updates.
|
1
|
9 *
|
|
10 * mpeg2dec is free software; you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU General Public License as published by
|
|
12 * the Free Software Foundation; either version 2 of the License, or
|
|
13 * (at your option) any later version.
|
|
14 *
|
|
15 * mpeg2dec is distributed in the hope that it will be useful,
|
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 * GNU General Public License for more details.
|
|
19 *
|
|
20 * You should have received a copy of the GNU General Public License
|
|
21 * along with this program; if not, write to the Free Software
|
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
23 */
|
|
24
|
|
25 #include "config.h"
|
|
26
|
|
27 #include <inttypes.h>
|
9852
|
28 #include <stdlib.h> /* defines NULL */
|
|
29 #include <string.h> /* memcmp */
|
1
|
30
|
9852
|
31 #include "mpeg2.h"
|
12932
|
32 #include "attributes.h"
|
1
|
33 #include "mpeg2_internal.h"
|
|
34
|
9852
|
35 #define SEQ_EXT 2
|
|
36 #define SEQ_DISPLAY_EXT 4
|
|
37 #define QUANT_MATRIX_EXT 8
|
|
38 #define COPYRIGHT_EXT 0x10
|
|
39 #define PIC_DISPLAY_EXT 0x80
|
|
40 #define PIC_CODING_EXT 0x100
|
|
41
|
36
|
42 /* default intra quant matrix, in zig-zag order */
|
9852
|
43 static const uint8_t default_intra_quantizer_matrix[64] ATTR_ALIGN(16) = {
|
1
|
44 8,
|
|
45 16, 16,
|
|
46 19, 16, 19,
|
|
47 22, 22, 22, 22,
|
|
48 22, 22, 26, 24, 26,
|
|
49 27, 27, 27, 26, 26, 26,
|
|
50 26, 27, 27, 27, 29, 29, 29,
|
|
51 34, 34, 34, 29, 29, 29, 27, 27,
|
|
52 29, 29, 32, 32, 34, 34, 37,
|
|
53 38, 37, 35, 35, 34, 35,
|
|
54 38, 38, 40, 40, 40,
|
|
55 48, 48, 46, 46,
|
|
56 56, 56, 58,
|
|
57 69, 69,
|
|
58 83
|
|
59 };
|
|
60
|
9852
|
61 uint8_t mpeg2_scan_norm[64] ATTR_ALIGN(16) = {
|
36
|
62 /* Zig-Zag scan pattern */
|
9852
|
63 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
|
|
64 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
|
|
65 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
|
|
66 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
|
|
67 };
|
|
68
|
|
69 uint8_t mpeg2_scan_alt[64] ATTR_ALIGN(16) = {
|
|
70 /* Alternate scan pattern */
|
|
71 0, 8, 16, 24, 1, 9, 2, 10, 17, 25, 32, 40, 48, 56, 57, 49,
|
|
72 41, 33, 26, 18, 3, 11, 4, 12, 19, 27, 34, 42, 50, 58, 35, 43,
|
|
73 51, 59, 20, 28, 5, 13, 6, 14, 21, 29, 36, 44, 52, 60, 37, 45,
|
|
74 53, 61, 22, 30, 7, 15, 23, 31, 38, 46, 54, 62, 39, 47, 55, 63
|
1
|
75 };
|
|
76
|
9852
|
77 void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec)
|
1
|
78 {
|
12932
|
79 if (mpeg2dec->sequence.width != (unsigned)-1) {
|
|
80 int i;
|
|
81
|
|
82 mpeg2dec->sequence.width = (unsigned)-1;
|
|
83 if (!mpeg2dec->custom_fbuf)
|
|
84 for (i = mpeg2dec->alloc_index_user;
|
|
85 i < mpeg2dec->alloc_index; i++) {
|
|
86 mpeg2_free (mpeg2dec->fbuf_alloc[i].fbuf.buf[0]);
|
|
87 mpeg2_free (mpeg2dec->fbuf_alloc[i].fbuf.buf[1]);
|
|
88 mpeg2_free (mpeg2dec->fbuf_alloc[i].fbuf.buf[2]);
|
|
89 }
|
|
90 if (mpeg2dec->convert_start)
|
|
91 for (i = 0; i < 3; i++) {
|
|
92 mpeg2_free (mpeg2dec->yuv_buf[i][0]);
|
|
93 mpeg2_free (mpeg2dec->yuv_buf[i][1]);
|
|
94 mpeg2_free (mpeg2dec->yuv_buf[i][2]);
|
|
95 }
|
|
96 if (mpeg2dec->decoder.convert_id)
|
|
97 mpeg2_free (mpeg2dec->decoder.convert_id);
|
|
98 }
|
|
99 mpeg2dec->decoder.coding_type = I_TYPE;
|
|
100 mpeg2dec->decoder.convert = NULL;
|
|
101 mpeg2dec->decoder.convert_id = NULL;
|
9852
|
102 mpeg2dec->picture = mpeg2dec->pictures;
|
12932
|
103 memset(&mpeg2dec->fbuf_alloc[0].fbuf, 0, sizeof(mpeg2_fbuf_t));
|
|
104 memset(&mpeg2dec->fbuf_alloc[1].fbuf, 0, sizeof(mpeg2_fbuf_t));
|
|
105 memset(&mpeg2dec->fbuf_alloc[2].fbuf, 0, sizeof(mpeg2_fbuf_t));
|
9852
|
106 mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[0].fbuf;
|
|
107 mpeg2dec->fbuf[1] = &mpeg2dec->fbuf_alloc[1].fbuf;
|
|
108 mpeg2dec->fbuf[2] = &mpeg2dec->fbuf_alloc[2].fbuf;
|
|
109 mpeg2dec->first = 1;
|
|
110 mpeg2dec->alloc_index = 0;
|
|
111 mpeg2dec->alloc_index_user = 0;
|
12932
|
112 mpeg2dec->first_decode_slice = 1;
|
|
113 mpeg2dec->nb_decode_slices = 0xb0 - 1;
|
|
114 mpeg2dec->convert = NULL;
|
|
115 mpeg2dec->convert_start = NULL;
|
|
116 mpeg2dec->custom_fbuf = 0;
|
|
117 mpeg2dec->yuv_index = 0;
|
1
|
118 }
|
|
119
|
12932
|
120 void mpeg2_reset_info (mpeg2_info_t * info)
|
1
|
121 {
|
9852
|
122 info->current_picture = info->current_picture_2nd = NULL;
|
|
123 info->display_picture = info->display_picture_2nd = NULL;
|
|
124 info->current_fbuf = info->display_fbuf = info->discard_fbuf = NULL;
|
12932
|
125 }
|
|
126
|
|
127 static void info_user_data (mpeg2dec_t * mpeg2dec)
|
|
128 {
|
|
129 if (mpeg2dec->user_data_len) {
|
|
130 mpeg2dec->info.user_data = mpeg2dec->chunk_buffer;
|
|
131 mpeg2dec->info.user_data_len = mpeg2dec->user_data_len - 3;
|
|
132 }
|
9852
|
133 }
|
|
134
|
|
135 int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec)
|
|
136 {
|
|
137 uint8_t * buffer = mpeg2dec->chunk_start;
|
12932
|
138 mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence);
|
|
139 static unsigned int frame_period[16] = {
|
|
140 0, 1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000,
|
|
141 /* unofficial: xing 15 fps */
|
|
142 1800000,
|
|
143 /* unofficial: libmpeg3 "Unofficial economy rates" 5/10/12/15 fps */
|
|
144 5400000, 2700000, 2250000, 1800000, 0, 0
|
9852
|
145 };
|
1
|
146 int i;
|
|
147
|
9852
|
148 if ((buffer[6] & 0x20) != 0x20) /* missing marker_bit */
|
|
149 return 1;
|
1
|
150
|
9852
|
151 i = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
|
12932
|
152 if (! (sequence->display_width = sequence->picture_width = i >> 12))
|
|
153 return 1;
|
|
154 if (! (sequence->display_height = sequence->picture_height = i & 0xfff))
|
|
155 return 1;
|
|
156 sequence->width = (sequence->picture_width + 15) & ~15;
|
|
157 sequence->height = (sequence->picture_height + 15) & ~15;
|
|
158 sequence->chroma_width = sequence->width >> 1;
|
|
159 sequence->chroma_height = sequence->height >> 1;
|
12617
|
160
|
12932
|
161 sequence->flags = (SEQ_FLAG_PROGRESSIVE_SEQUENCE |
|
|
162 SEQ_VIDEO_FORMAT_UNSPECIFIED);
|
9852
|
163
|
|
164 sequence->pixel_width = buffer[3] >> 4; /* aspect ratio */
|
12932
|
165 sequence->frame_period = frame_period[buffer[3] & 15];
|
36
|
166
|
9852
|
167 sequence->byte_rate = (buffer[4]<<10) | (buffer[5]<<2) | (buffer[6]>>6);
|
|
168
|
|
169 sequence->vbv_buffer_size = ((buffer[6]<<16)|(buffer[7]<<8))&0x1ff800;
|
|
170
|
|
171 if (buffer[7] & 4)
|
|
172 sequence->flags |= SEQ_FLAG_CONSTRAINED_PARAMETERS;
|
1
|
173
|
12932
|
174 mpeg2dec->copy_matrix = 3;
|
1
|
175 if (buffer[7] & 2) {
|
|
176 for (i = 0; i < 64; i++)
|
12932
|
177 mpeg2dec->new_quantizer_matrix[0][mpeg2_scan_norm[i]] =
|
1
|
178 (buffer[i+7] << 7) | (buffer[i+8] >> 1);
|
|
179 buffer += 64;
|
9852
|
180 } else
|
|
181 for (i = 0; i < 64; i++)
|
12932
|
182 mpeg2dec->new_quantizer_matrix[0][mpeg2_scan_norm[i]] =
|
|
183 default_intra_quantizer_matrix[i];
|
9852
|
184
|
|
185 if (buffer[7] & 1)
|
|
186 for (i = 0; i < 64; i++)
|
12932
|
187 mpeg2dec->new_quantizer_matrix[1][mpeg2_scan_norm[i]] =
|
9852
|
188 buffer[i+8];
|
|
189 else
|
12932
|
190 memset (mpeg2dec->new_quantizer_matrix[1], 16, 64);
|
9852
|
191
|
|
192 sequence->profile_level_id = 0x80;
|
12932
|
193 sequence->colour_primaries = 0;
|
|
194 sequence->transfer_characteristics = 0;
|
|
195 sequence->matrix_coefficients = 0;
|
9852
|
196
|
|
197 mpeg2dec->ext_state = SEQ_EXT;
|
|
198 mpeg2dec->state = STATE_SEQUENCE;
|
|
199 mpeg2dec->display_offset_x = mpeg2dec->display_offset_y = 0;
|
|
200
|
|
201 return 0;
|
|
202 }
|
|
203
|
|
204 static int sequence_ext (mpeg2dec_t * mpeg2dec)
|
|
205 {
|
|
206 uint8_t * buffer = mpeg2dec->chunk_start;
|
12932
|
207 mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence);
|
9852
|
208 uint32_t flags;
|
|
209
|
|
210 if (!(buffer[3] & 1))
|
|
211 return 1;
|
|
212
|
|
213 sequence->profile_level_id = (buffer[0] << 4) | (buffer[1] >> 4);
|
|
214
|
12932
|
215 sequence->display_width = sequence->picture_width +=
|
9852
|
216 ((buffer[1] << 13) | (buffer[2] << 5)) & 0x3000;
|
12932
|
217 sequence->display_height = sequence->picture_height +=
|
9852
|
218 (buffer[2] << 7) & 0x3000;
|
12932
|
219 sequence->width = (sequence->picture_width + 15) & ~15;
|
|
220 sequence->height = (sequence->picture_height + 15) & ~15;
|
9852
|
221 flags = sequence->flags | SEQ_FLAG_MPEG2;
|
|
222 if (!(buffer[1] & 8)) {
|
|
223 flags &= ~SEQ_FLAG_PROGRESSIVE_SEQUENCE;
|
12932
|
224 sequence->height = (sequence->height + 31) & ~31;
|
9852
|
225 }
|
|
226 if (buffer[5] & 0x80)
|
|
227 flags |= SEQ_FLAG_LOW_DELAY;
|
|
228 sequence->flags = flags;
|
12932
|
229 sequence->chroma_width = sequence->width;
|
|
230 sequence->chroma_height = sequence->height;
|
9852
|
231 switch (buffer[1] & 6) {
|
|
232 case 0: /* invalid */
|
|
233 return 1;
|
|
234 case 2: /* 4:2:0 */
|
12932
|
235 sequence->chroma_height >>= 1;
|
9852
|
236 case 4: /* 4:2:2 */
|
12932
|
237 sequence->chroma_width >>= 1;
|
9852
|
238 }
|
|
239
|
|
240 sequence->byte_rate += ((buffer[2]<<25) | (buffer[3]<<17)) & 0x3ffc0000;
|
|
241
|
|
242 sequence->vbv_buffer_size |= buffer[4] << 21;
|
|
243
|
|
244 sequence->frame_period =
|
|
245 sequence->frame_period * ((buffer[5]&31)+1) / (((buffer[5]>>2)&3)+1);
|
|
246
|
|
247 mpeg2dec->ext_state = SEQ_DISPLAY_EXT;
|
|
248
|
|
249 return 0;
|
|
250 }
|
|
251
|
|
252 static int sequence_display_ext (mpeg2dec_t * mpeg2dec)
|
|
253 {
|
|
254 uint8_t * buffer = mpeg2dec->chunk_start;
|
12932
|
255 mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence);
|
9852
|
256 uint32_t flags;
|
|
257
|
|
258 flags = ((sequence->flags & ~SEQ_MASK_VIDEO_FORMAT) |
|
|
259 ((buffer[0]<<4) & SEQ_MASK_VIDEO_FORMAT));
|
|
260 if (buffer[0] & 1) {
|
|
261 flags |= SEQ_FLAG_COLOUR_DESCRIPTION;
|
|
262 sequence->colour_primaries = buffer[1];
|
|
263 sequence->transfer_characteristics = buffer[2];
|
|
264 sequence->matrix_coefficients = buffer[3];
|
|
265 buffer += 3;
|
1
|
266 }
|
|
267
|
9852
|
268 if (!(buffer[2] & 2)) /* missing marker_bit */
|
|
269 return 1;
|
1
|
270
|
9852
|
271 sequence->display_width = (buffer[1] << 6) | (buffer[2] >> 2);
|
|
272 sequence->display_height =
|
|
273 ((buffer[2]& 1 ) << 13) | (buffer[3] << 5) | (buffer[4] >> 3);
|
1
|
274
|
|
275 return 0;
|
|
276 }
|
|
277
|
12932
|
278 static inline void finalize_sequence (mpeg2_sequence_t * sequence)
|
1
|
279 {
|
9852
|
280 int width;
|
|
281 int height;
|
|
282
|
|
283 sequence->byte_rate *= 50;
|
|
284
|
|
285 if (sequence->flags & SEQ_FLAG_MPEG2) {
|
|
286 switch (sequence->pixel_width) {
|
|
287 case 1: /* square pixels */
|
|
288 sequence->pixel_width = sequence->pixel_height = 1; return;
|
|
289 case 2: /* 4:3 aspect ratio */
|
|
290 width = 4; height = 3; break;
|
|
291 case 3: /* 16:9 aspect ratio */
|
|
292 width = 16; height = 9; break;
|
|
293 case 4: /* 2.21:1 aspect ratio */
|
|
294 width = 221; height = 100; break;
|
|
295 default: /* illegal */
|
|
296 sequence->pixel_width = sequence->pixel_height = 0; return;
|
|
297 }
|
|
298 width *= sequence->display_height;
|
|
299 height *= sequence->display_width;
|
|
300
|
|
301 } else {
|
|
302 if (sequence->byte_rate == 50 * 0x3ffff)
|
|
303 sequence->byte_rate = 0; /* mpeg-1 VBR */
|
1
|
304
|
9852
|
305 switch (sequence->pixel_width) {
|
|
306 case 0: case 15: /* illegal */
|
|
307 sequence->pixel_width = sequence->pixel_height = 0; return;
|
|
308 case 1: /* square pixels */
|
|
309 sequence->pixel_width = sequence->pixel_height = 1; return;
|
|
310 case 3: /* 720x576 16:9 */
|
|
311 sequence->pixel_width = 64; sequence->pixel_height = 45; return;
|
|
312 case 6: /* 720x480 16:9 */
|
|
313 sequence->pixel_width = 32; sequence->pixel_height = 27; return;
|
|
314 case 12: /* 720*480 4:3 */
|
|
315 sequence->pixel_width = 8; sequence->pixel_height = 9; return;
|
|
316 default:
|
|
317 height = 88 * sequence->pixel_width + 1171;
|
|
318 width = 2000;
|
|
319 }
|
|
320 }
|
1
|
321
|
9852
|
322 sequence->pixel_width = width;
|
|
323 sequence->pixel_height = height;
|
|
324 while (width) { /* find greatest common divisor */
|
|
325 int tmp = width;
|
|
326 width = height % tmp;
|
|
327 height = tmp;
|
|
328 }
|
|
329 sequence->pixel_width /= height;
|
|
330 sequence->pixel_height /= height;
|
|
331 }
|
|
332
|
12932
|
333 static void copy_matrix (mpeg2dec_t * mpeg2dec, int index)
|
|
334 {
|
|
335 if (memcmp (mpeg2dec->quantizer_matrix[index],
|
|
336 mpeg2dec->new_quantizer_matrix[index], 64)) {
|
|
337 memcpy (mpeg2dec->quantizer_matrix[index],
|
|
338 mpeg2dec->new_quantizer_matrix[index], 64);
|
|
339 mpeg2dec->scaled[index] = -1;
|
|
340 }
|
|
341 }
|
|
342
|
|
343 static void finalize_matrix (mpeg2dec_t * mpeg2dec)
|
|
344 {
|
|
345 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
|
|
346 int i;
|
|
347
|
|
348 for (i = 0; i < 2; i++) {
|
|
349 if (mpeg2dec->copy_matrix & (1 << i))
|
|
350 copy_matrix (mpeg2dec, i);
|
|
351 if ((mpeg2dec->copy_matrix & (4 << i)) &&
|
|
352 memcmp (mpeg2dec->quantizer_matrix[i],
|
|
353 mpeg2dec->new_quantizer_matrix[i+2], 64)) {
|
|
354 copy_matrix (mpeg2dec, i + 2);
|
|
355 decoder->chroma_quantizer[i] = decoder->quantizer_prescale[i+2];
|
|
356 } else if (mpeg2dec->copy_matrix & (5 << i))
|
|
357 decoder->chroma_quantizer[i] = decoder->quantizer_prescale[i];
|
|
358 }
|
|
359 }
|
|
360
|
|
361 static mpeg2_state_t invalid_end_action (mpeg2dec_t * mpeg2dec)
|
|
362 {
|
|
363 mpeg2_reset_info (&(mpeg2dec->info));
|
|
364 mpeg2dec->info.gop = NULL;
|
|
365 info_user_data (mpeg2dec);
|
|
366 mpeg2_header_state_init (mpeg2dec);
|
|
367 mpeg2dec->sequence = mpeg2dec->new_sequence;
|
|
368 mpeg2dec->action = mpeg2_seek_header;
|
|
369 mpeg2dec->state = STATE_SEQUENCE;
|
|
370 return STATE_SEQUENCE;
|
|
371 }
|
|
372
|
9852
|
373 void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec)
|
|
374 {
|
12932
|
375 mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence);
|
|
376 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
|
9852
|
377
|
|
378 finalize_sequence (sequence);
|
12932
|
379 finalize_matrix (mpeg2dec);
|
36
|
380
|
12932
|
381 decoder->mpeg1 = !(sequence->flags & SEQ_FLAG_MPEG2);
|
|
382 decoder->width = sequence->width;
|
|
383 decoder->height = sequence->height;
|
|
384 decoder->vertical_position_extension = (sequence->picture_height > 2800);
|
|
385 decoder->chroma_format = ((sequence->chroma_width == sequence->width) +
|
|
386 (sequence->chroma_height == sequence->height));
|
|
387
|
|
388 if (mpeg2dec->sequence.width != (unsigned)-1) {
|
|
389 unsigned int new_byte_rate;
|
|
390
|
|
391 /*
|
|
392 * According to 6.1.1.6, repeat sequence headers should be
|
|
393 * identical to the original. However some DVDs dont respect
|
|
394 * that and have different bitrates in the repeat sequence
|
|
395 * headers. So we'll ignore that in the comparison and still
|
|
396 * consider these as repeat sequence headers.
|
|
397 *
|
|
398 * However, be careful not to alter the current sequence when
|
|
399 * returning STATE_INVALID_END.
|
|
400 */
|
|
401 new_byte_rate = sequence->byte_rate;
|
|
402 sequence->byte_rate = mpeg2dec->sequence.byte_rate;
|
|
403 if (memcmp (&(mpeg2dec->sequence), sequence,
|
|
404 sizeof (mpeg2_sequence_t))) {
|
|
405 decoder->stride_frame = sequence->width;
|
|
406 sequence->byte_rate = new_byte_rate;
|
|
407 mpeg2_header_end (mpeg2dec);
|
|
408 mpeg2dec->action = invalid_end_action;
|
|
409 mpeg2dec->state = STATE_INVALID_END;
|
|
410 return;
|
|
411 }
|
|
412 sequence->byte_rate = new_byte_rate;
|
9852
|
413 mpeg2dec->state = STATE_SEQUENCE_REPEATED;
|
12932
|
414 } else
|
|
415 decoder->stride_frame = sequence->width;
|
9852
|
416 mpeg2dec->sequence = *sequence;
|
12932
|
417 mpeg2_reset_info (&(mpeg2dec->info));
|
9852
|
418 mpeg2dec->info.sequence = &(mpeg2dec->sequence);
|
12932
|
419 mpeg2dec->info.gop = NULL;
|
|
420 info_user_data (mpeg2dec);
|
9852
|
421 }
|
|
422
|
|
423 int mpeg2_header_gop (mpeg2dec_t * mpeg2dec)
|
|
424 {
|
12932
|
425 uint8_t * buffer = mpeg2dec->chunk_start;
|
|
426 mpeg2_gop_t * gop = &(mpeg2dec->new_gop);
|
|
427
|
|
428 if (! (buffer[1] & 8))
|
|
429 return 1;
|
|
430 gop->hours = (buffer[0] >> 2) & 31;
|
|
431 gop->minutes = ((buffer[0] << 4) | (buffer[1] >> 4)) & 63;
|
|
432 gop->seconds = ((buffer[1] << 3) | (buffer[2] >> 5)) & 63;
|
|
433 gop->pictures = ((buffer[2] << 1) | (buffer[3] >> 7)) & 63;
|
|
434 gop->flags = (buffer[0] >> 7) | ((buffer[3] >> 4) & 6);
|
9852
|
435 mpeg2dec->state = STATE_GOP;
|
1
|
436 return 0;
|
|
437 }
|
|
438
|
12932
|
439 void mpeg2_header_gop_finalize (mpeg2dec_t * mpeg2dec)
|
|
440 {
|
|
441 mpeg2dec->gop = mpeg2dec->new_gop;
|
|
442 mpeg2_reset_info (&(mpeg2dec->info));
|
|
443 mpeg2dec->info.gop = &(mpeg2dec->gop);
|
|
444 info_user_data (mpeg2dec);
|
|
445 }
|
|
446
|
|
447 void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type)
|
1
|
448 {
|
|
449 int i;
|
|
450
|
9852
|
451 for (i = 0; i < 3; i++)
|
|
452 if (mpeg2dec->fbuf[1] != &mpeg2dec->fbuf_alloc[i].fbuf &&
|
|
453 mpeg2dec->fbuf[2] != &mpeg2dec->fbuf_alloc[i].fbuf) {
|
|
454 mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[i].fbuf;
|
|
455 mpeg2dec->info.current_fbuf = mpeg2dec->fbuf[0];
|
12932
|
456 if (b_type || (mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY)) {
|
|
457 if (b_type || mpeg2dec->convert)
|
9852
|
458 mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[0];
|
|
459 mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[0];
|
|
460 }
|
|
461 break;
|
|
462 }
|
|
463 }
|
|
464
|
12932
|
465 mpeg2_state_t mpeg2_header_picture_start (mpeg2dec_t * mpeg2dec)
|
9852
|
466 {
|
12932
|
467 mpeg2_picture_t * picture = &(mpeg2dec->new_picture);
|
9852
|
468
|
12932
|
469 mpeg2dec->state = ((mpeg2dec->state != STATE_SLICE_1ST) ?
|
|
470 STATE_PICTURE : STATE_PICTURE_2ND);
|
9852
|
471 picture->flags = 0;
|
12932
|
472 picture->tag = picture->tag2 = 0;
|
|
473 if (mpeg2dec->num_tags) {
|
|
474 if (mpeg2dec->bytes_since_tag >= 4) {
|
|
475 mpeg2dec->num_tags = 0;
|
|
476 picture->tag = mpeg2dec->tag_current;
|
|
477 picture->tag2 = mpeg2dec->tag2_current;
|
|
478 picture->flags = PIC_FLAG_TAGS;
|
|
479 } else if (mpeg2dec->num_tags > 1) {
|
|
480 mpeg2dec->num_tags = 1;
|
|
481 picture->tag = mpeg2dec->tag_previous;
|
|
482 picture->tag2 = mpeg2dec->tag2_previous;
|
|
483 picture->flags = PIC_FLAG_TAGS;
|
9852
|
484 }
|
|
485 }
|
|
486 picture->display_offset[0].x = picture->display_offset[1].x =
|
|
487 picture->display_offset[2].x = mpeg2dec->display_offset_x;
|
|
488 picture->display_offset[0].y = picture->display_offset[1].y =
|
|
489 picture->display_offset[2].y = mpeg2dec->display_offset_y;
|
|
490 return mpeg2_parse_header (mpeg2dec);
|
|
491 }
|
|
492
|
|
493 int mpeg2_header_picture (mpeg2dec_t * mpeg2dec)
|
|
494 {
|
|
495 uint8_t * buffer = mpeg2dec->chunk_start;
|
12932
|
496 mpeg2_picture_t * picture = &(mpeg2dec->new_picture);
|
|
497 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
|
9852
|
498 int type;
|
|
499
|
|
500 type = (buffer [1] >> 3) & 7;
|
|
501 mpeg2dec->ext_state = PIC_CODING_EXT;
|
|
502
|
|
503 picture->temporal_reference = (buffer[0] << 2) | (buffer[1] >> 6);
|
|
504
|
|
505 picture->flags |= type;
|
|
506
|
|
507 if (type == PIC_FLAG_CODING_TYPE_P || type == PIC_FLAG_CODING_TYPE_B) {
|
|
508 /* forward_f_code and backward_f_code - used in mpeg1 only */
|
|
509 decoder->f_motion.f_code[1] = (buffer[3] >> 2) & 1;
|
|
510 decoder->f_motion.f_code[0] =
|
|
511 (((buffer[3] << 1) | (buffer[4] >> 7)) & 7) - 1;
|
|
512 decoder->b_motion.f_code[1] = (buffer[4] >> 6) & 1;
|
|
513 decoder->b_motion.f_code[0] = ((buffer[4] >> 3) & 7) - 1;
|
1
|
514 }
|
|
515
|
9852
|
516 /* XXXXXX decode extra_information_picture as well */
|
|
517
|
|
518 picture->nb_fields = 2;
|
1
|
519
|
12932
|
520 mpeg2dec->q_scale_type = 0;
|
|
521 decoder->intra_dc_precision = 7;
|
|
522 decoder->frame_pred_frame_dct = 1;
|
|
523 decoder->concealment_motion_vectors = 0;
|
|
524 decoder->scan = mpeg2_scan_norm;
|
|
525 decoder->picture_structure = FRAME_PICTURE;
|
|
526 mpeg2dec->copy_matrix = 0;
|
|
527
|
1
|
528 return 0;
|
|
529 }
|
|
530
|
9852
|
531 static int picture_coding_ext (mpeg2dec_t * mpeg2dec)
|
1
|
532 {
|
9852
|
533 uint8_t * buffer = mpeg2dec->chunk_start;
|
12932
|
534 mpeg2_picture_t * picture = &(mpeg2dec->new_picture);
|
|
535 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
|
9852
|
536 uint32_t flags;
|
1
|
537
|
9852
|
538 /* pre subtract 1 for use later in compute_motion_vector */
|
|
539 decoder->f_motion.f_code[0] = (buffer[0] & 15) - 1;
|
|
540 decoder->f_motion.f_code[1] = (buffer[1] >> 4) - 1;
|
|
541 decoder->b_motion.f_code[0] = (buffer[1] & 15) - 1;
|
|
542 decoder->b_motion.f_code[1] = (buffer[2] >> 4) - 1;
|
1
|
543
|
9852
|
544 flags = picture->flags;
|
12932
|
545 decoder->intra_dc_precision = 7 - ((buffer[2] >> 2) & 3);
|
9852
|
546 decoder->picture_structure = buffer[2] & 3;
|
|
547 switch (decoder->picture_structure) {
|
|
548 case TOP_FIELD:
|
|
549 flags |= PIC_FLAG_TOP_FIELD_FIRST;
|
|
550 case BOTTOM_FIELD:
|
|
551 picture->nb_fields = 1;
|
|
552 break;
|
|
553 case FRAME_PICTURE:
|
|
554 if (!(mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)) {
|
|
555 picture->nb_fields = (buffer[3] & 2) ? 3 : 2;
|
12932
|
556 flags |= (buffer[3] & 128) ? PIC_FLAG_TOP_FIELD_FIRST : 0;
|
10509
|
557 flags |= (buffer[3] & 2) ? PIC_FLAG_REPEAT_FIRST_FIELD : 0;
|
9852
|
558 } else
|
|
559 picture->nb_fields = (buffer[3]&2) ? ((buffer[3]&128) ? 6 : 4) : 2;
|
|
560 break;
|
|
561 default:
|
|
562 return 1;
|
|
563 }
|
|
564 decoder->top_field_first = buffer[3] >> 7;
|
|
565 decoder->frame_pred_frame_dct = (buffer[3] >> 6) & 1;
|
|
566 decoder->concealment_motion_vectors = (buffer[3] >> 5) & 1;
|
12932
|
567 mpeg2dec->q_scale_type = buffer[3] & 16;
|
9852
|
568 decoder->intra_vlc_format = (buffer[3] >> 3) & 1;
|
|
569 decoder->scan = (buffer[3] & 4) ? mpeg2_scan_alt : mpeg2_scan_norm;
|
|
570 flags |= (buffer[4] & 0x80) ? PIC_FLAG_PROGRESSIVE_FRAME : 0;
|
|
571 if (buffer[4] & 0x40)
|
|
572 flags |= (((buffer[4]<<26) | (buffer[5]<<18) | (buffer[6]<<10)) &
|
|
573 PIC_MASK_COMPOSITE_DISPLAY) | PIC_FLAG_COMPOSITE_DISPLAY;
|
|
574 picture->flags = flags;
|
1
|
575
|
9852
|
576 mpeg2dec->ext_state = PIC_DISPLAY_EXT | COPYRIGHT_EXT | QUANT_MATRIX_EXT;
|
|
577
|
1
|
578 return 0;
|
|
579 }
|
|
580
|
9852
|
581 static int picture_display_ext (mpeg2dec_t * mpeg2dec)
|
1
|
582 {
|
9852
|
583 uint8_t * buffer = mpeg2dec->chunk_start;
|
12932
|
584 mpeg2_picture_t * picture = &(mpeg2dec->new_picture);
|
9852
|
585 int i, nb_pos;
|
|
586
|
|
587 nb_pos = picture->nb_fields;
|
|
588 if (mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)
|
|
589 nb_pos >>= 1;
|
|
590
|
|
591 for (i = 0; i < nb_pos; i++) {
|
|
592 int x, y;
|
1
|
593
|
9852
|
594 x = ((buffer[4*i] << 24) | (buffer[4*i+1] << 16) |
|
|
595 (buffer[4*i+2] << 8) | buffer[4*i+3]) >> (11-2*i);
|
|
596 y = ((buffer[4*i+2] << 24) | (buffer[4*i+3] << 16) |
|
|
597 (buffer[4*i+4] << 8) | buffer[4*i+5]) >> (10-2*i);
|
|
598 if (! (x & y & 1))
|
|
599 return 1;
|
|
600 picture->display_offset[i].x = mpeg2dec->display_offset_x = x >> 1;
|
|
601 picture->display_offset[i].y = mpeg2dec->display_offset_y = y >> 1;
|
|
602 }
|
|
603 for (; i < 3; i++) {
|
|
604 picture->display_offset[i].x = mpeg2dec->display_offset_x;
|
|
605 picture->display_offset[i].y = mpeg2dec->display_offset_y;
|
|
606 }
|
|
607 return 0;
|
|
608 }
|
1
|
609
|
12932
|
610 void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec, uint32_t accels)
|
|
611 {
|
|
612 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
|
|
613 int old_type_b = (decoder->coding_type == B_TYPE);
|
|
614 int low_delay = mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY;
|
|
615
|
|
616 finalize_matrix (mpeg2dec);
|
|
617 decoder->coding_type = mpeg2dec->new_picture.flags & PIC_MASK_CODING_TYPE;
|
|
618
|
|
619 if (mpeg2dec->state == STATE_PICTURE) {
|
|
620 mpeg2_picture_t * picture;
|
|
621 mpeg2_picture_t * other;
|
|
622
|
|
623 decoder->second_field = 0;
|
|
624
|
|
625 picture = other = mpeg2dec->pictures;
|
|
626 if (old_type_b ^ (mpeg2dec->picture < mpeg2dec->pictures + 2))
|
|
627 picture += 2;
|
|
628 else
|
|
629 other += 2;
|
|
630 mpeg2dec->picture = picture;
|
|
631 *picture = mpeg2dec->new_picture;
|
|
632
|
|
633 if (!old_type_b) {
|
|
634 mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1];
|
|
635 mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0];
|
|
636 }
|
|
637 mpeg2dec->fbuf[0] = NULL;
|
|
638 mpeg2_reset_info (&(mpeg2dec->info));
|
|
639 mpeg2dec->info.current_picture = picture;
|
|
640 mpeg2dec->info.display_picture = picture;
|
|
641 if (decoder->coding_type != B_TYPE) {
|
|
642 if (!low_delay) {
|
|
643 if (mpeg2dec->first) {
|
|
644 mpeg2dec->info.display_picture = NULL;
|
|
645 mpeg2dec->first = 0;
|
|
646 } else {
|
|
647 mpeg2dec->info.display_picture = other;
|
|
648 if (other->nb_fields == 1)
|
|
649 mpeg2dec->info.display_picture_2nd = other + 1;
|
|
650 mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[1];
|
|
651 }
|
|
652 }
|
|
653 if (!low_delay + !mpeg2dec->convert)
|
|
654 mpeg2dec->info.discard_fbuf =
|
|
655 mpeg2dec->fbuf[!low_delay + !mpeg2dec->convert];
|
|
656 }
|
|
657 if (mpeg2dec->convert) {
|
|
658 mpeg2_convert_init_t convert_init;
|
|
659 if (!mpeg2dec->convert_start) {
|
|
660 int y_size, uv_size;
|
|
661
|
|
662 mpeg2dec->decoder.convert_id =
|
|
663 mpeg2_malloc (mpeg2dec->convert_id_size,
|
|
664 MPEG2_ALLOC_CONVERT_ID);
|
|
665 mpeg2dec->convert (MPEG2_CONVERT_START,
|
|
666 mpeg2dec->decoder.convert_id,
|
|
667 &(mpeg2dec->sequence),
|
|
668 mpeg2dec->convert_stride, accels,
|
|
669 mpeg2dec->convert_arg, &convert_init);
|
|
670 mpeg2dec->convert_start = convert_init.start;
|
|
671 mpeg2dec->decoder.convert = convert_init.copy;
|
|
672
|
|
673 y_size = decoder->stride_frame * mpeg2dec->sequence.height;
|
|
674 uv_size = y_size >> (2 - mpeg2dec->decoder.chroma_format);
|
|
675 mpeg2dec->yuv_buf[0][0] =
|
|
676 (uint8_t *) mpeg2_malloc (y_size, MPEG2_ALLOC_YUV);
|
|
677 mpeg2dec->yuv_buf[0][1] =
|
|
678 (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);
|
|
679 mpeg2dec->yuv_buf[0][2] =
|
|
680 (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);
|
|
681 mpeg2dec->yuv_buf[1][0] =
|
|
682 (uint8_t *) mpeg2_malloc (y_size, MPEG2_ALLOC_YUV);
|
|
683 mpeg2dec->yuv_buf[1][1] =
|
|
684 (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);
|
|
685 mpeg2dec->yuv_buf[1][2] =
|
|
686 (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);
|
|
687 y_size = decoder->stride_frame * 32;
|
|
688 uv_size = y_size >> (2 - mpeg2dec->decoder.chroma_format);
|
|
689 mpeg2dec->yuv_buf[2][0] =
|
|
690 (uint8_t *) mpeg2_malloc (y_size, MPEG2_ALLOC_YUV);
|
|
691 mpeg2dec->yuv_buf[2][1] =
|
|
692 (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);
|
|
693 mpeg2dec->yuv_buf[2][2] =
|
|
694 (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);
|
|
695 }
|
|
696 if (!mpeg2dec->custom_fbuf) {
|
|
697 while (mpeg2dec->alloc_index < 3) {
|
|
698 mpeg2_fbuf_t * fbuf;
|
|
699
|
|
700 fbuf = &mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf;
|
|
701 fbuf->id = NULL;
|
|
702 fbuf->buf[0] =
|
|
703 (uint8_t *) mpeg2_malloc (convert_init.buf_size[0],
|
|
704 MPEG2_ALLOC_CONVERTED);
|
|
705 fbuf->buf[1] =
|
|
706 (uint8_t *) mpeg2_malloc (convert_init.buf_size[1],
|
|
707 MPEG2_ALLOC_CONVERTED);
|
|
708 fbuf->buf[2] =
|
|
709 (uint8_t *) mpeg2_malloc (convert_init.buf_size[2],
|
|
710 MPEG2_ALLOC_CONVERTED);
|
|
711 }
|
|
712 mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE));
|
|
713 }
|
|
714 } else if (!mpeg2dec->custom_fbuf) {
|
|
715 while (mpeg2dec->alloc_index < 3) {
|
|
716 mpeg2_fbuf_t * fbuf;
|
|
717 int y_size, uv_size;
|
|
718
|
|
719 fbuf = &(mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf);
|
|
720 fbuf->id = NULL;
|
|
721 y_size = decoder->stride_frame * mpeg2dec->sequence.height;
|
|
722 uv_size = y_size >> (2 - decoder->chroma_format);
|
|
723 fbuf->buf[0] = (uint8_t *) mpeg2_malloc (y_size,
|
|
724 MPEG2_ALLOC_YUV);
|
|
725 fbuf->buf[1] = (uint8_t *) mpeg2_malloc (uv_size,
|
|
726 MPEG2_ALLOC_YUV);
|
|
727 fbuf->buf[2] = (uint8_t *) mpeg2_malloc (uv_size,
|
|
728 MPEG2_ALLOC_YUV);
|
|
729 }
|
|
730 mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE));
|
|
731 }
|
|
732 } else {
|
|
733 decoder->second_field = 1;
|
|
734 mpeg2dec->picture++; /* second field picture */
|
|
735 *(mpeg2dec->picture) = mpeg2dec->new_picture;
|
|
736 mpeg2dec->info.current_picture_2nd = mpeg2dec->picture;
|
|
737 if (low_delay || decoder->coding_type == B_TYPE)
|
|
738 mpeg2dec->info.display_picture_2nd = mpeg2dec->picture;
|
|
739 }
|
|
740
|
|
741 info_user_data (mpeg2dec);
|
|
742 }
|
|
743
|
9852
|
744 static int copyright_ext (mpeg2dec_t * mpeg2dec)
|
|
745 {
|
|
746 return 0;
|
|
747 }
|
|
748
|
|
749 static int quant_matrix_ext (mpeg2dec_t * mpeg2dec)
|
|
750 {
|
|
751 uint8_t * buffer = mpeg2dec->chunk_start;
|
12932
|
752 int i, j;
|
9852
|
753
|
12932
|
754 for (i = 0; i < 4; i++)
|
|
755 if (buffer[0] & (8 >> i)) {
|
|
756 for (j = 0; j < 64; j++)
|
|
757 mpeg2dec->new_quantizer_matrix[i][mpeg2_scan_norm[j]] =
|
|
758 (buffer[j] << (i+5)) | (buffer[j+1] >> (3-i));
|
|
759 mpeg2dec->copy_matrix |= 1 << i;
|
|
760 buffer += 64;
|
|
761 }
|
9852
|
762
|
1
|
763 return 0;
|
|
764 }
|
|
765
|
9852
|
766 int mpeg2_header_extension (mpeg2dec_t * mpeg2dec)
|
1
|
767 {
|
9852
|
768 static int (* parser[]) (mpeg2dec_t *) = {
|
|
769 0, sequence_ext, sequence_display_ext, quant_matrix_ext,
|
|
770 copyright_ext, 0, 0, picture_display_ext, picture_coding_ext
|
|
771 };
|
|
772 int ext, ext_bit;
|
|
773
|
|
774 ext = mpeg2dec->chunk_start[0] >> 4;
|
|
775 ext_bit = 1 << ext;
|
1
|
776
|
9852
|
777 if (!(mpeg2dec->ext_state & ext_bit))
|
|
778 return 0; /* ignore illegal extensions */
|
|
779 mpeg2dec->ext_state &= ~ext_bit;
|
|
780 return parser[ext] (mpeg2dec);
|
|
781 }
|
1
|
782
|
9852
|
783 int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec)
|
|
784 {
|
12932
|
785 mpeg2dec->user_data_len += mpeg2dec->chunk_ptr - 1 - mpeg2dec->chunk_start;
|
9852
|
786 mpeg2dec->chunk_start = mpeg2dec->chunk_ptr - 1;
|
|
787
|
1
|
788 return 0;
|
|
789 }
|
9852
|
790
|
12932
|
791 static void prescale (mpeg2dec_t * mpeg2dec, int index)
|
9852
|
792 {
|
12932
|
793 static int non_linear_scale [] = {
|
|
794 0, 1, 2, 3, 4, 5, 6, 7,
|
|
795 8, 10, 12, 14, 16, 18, 20, 22,
|
|
796 24, 28, 32, 36, 40, 44, 48, 52,
|
|
797 56, 64, 72, 80, 88, 96, 104, 112
|
|
798 };
|
|
799 int i, j, k;
|
|
800 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
|
|
801
|
|
802 if (mpeg2dec->scaled[index] != mpeg2dec->q_scale_type) {
|
|
803 mpeg2dec->scaled[index] = mpeg2dec->q_scale_type;
|
|
804 for (i = 0; i < 32; i++) {
|
|
805 k = mpeg2dec->q_scale_type ? non_linear_scale[i] : (i << 1);
|
13123
|
806 decoder->quantizer_scales[i] = k;
|
12932
|
807 for (j = 0; j < 64; j++)
|
|
808 decoder->quantizer_prescale[index][i][j] =
|
|
809 k * mpeg2dec->quantizer_matrix[index][j];
|
|
810 }
|
|
811 }
|
|
812 }
|
|
813
|
|
814 mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec)
|
|
815 {
|
|
816 mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
|
|
817
|
|
818 mpeg2dec->info.user_data = NULL; mpeg2dec->info.user_data_len = 0;
|
9852
|
819 mpeg2dec->state = ((mpeg2dec->picture->nb_fields > 1 ||
|
|
820 mpeg2dec->state == STATE_PICTURE_2ND) ?
|
|
821 STATE_SLICE : STATE_SLICE_1ST);
|
|
822
|
12932
|
823 if (mpeg2dec->decoder.coding_type != D_TYPE) {
|
|
824 prescale (mpeg2dec, 0);
|
|
825 if (decoder->chroma_quantizer[0] == decoder->quantizer_prescale[2])
|
|
826 prescale (mpeg2dec, 2);
|
|
827 if (mpeg2dec->decoder.coding_type != I_TYPE) {
|
|
828 prescale (mpeg2dec, 1);
|
|
829 if (decoder->chroma_quantizer[1] == decoder->quantizer_prescale[3])
|
|
830 prescale (mpeg2dec, 3);
|
|
831 }
|
|
832 }
|
|
833
|
9852
|
834 if (!(mpeg2dec->nb_decode_slices))
|
|
835 mpeg2dec->picture->flags |= PIC_FLAG_SKIP;
|
|
836 else if (mpeg2dec->convert_start) {
|
12932
|
837 mpeg2dec->convert_start (decoder->convert_id, mpeg2dec->fbuf[0],
|
|
838 mpeg2dec->picture, mpeg2dec->info.gop);
|
9852
|
839
|
|
840 if (mpeg2dec->decoder.coding_type == B_TYPE)
|
|
841 mpeg2_init_fbuf (&(mpeg2dec->decoder), mpeg2dec->yuv_buf[2],
|
|
842 mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1],
|
|
843 mpeg2dec->yuv_buf[mpeg2dec->yuv_index]);
|
|
844 else {
|
|
845 mpeg2_init_fbuf (&(mpeg2dec->decoder),
|
|
846 mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1],
|
|
847 mpeg2dec->yuv_buf[mpeg2dec->yuv_index],
|
|
848 mpeg2dec->yuv_buf[mpeg2dec->yuv_index]);
|
|
849 if (mpeg2dec->state == STATE_SLICE)
|
|
850 mpeg2dec->yuv_index ^= 1;
|
|
851 }
|
|
852 } else {
|
|
853 int b_type;
|
|
854
|
|
855 b_type = (mpeg2dec->decoder.coding_type == B_TYPE);
|
|
856 mpeg2_init_fbuf (&(mpeg2dec->decoder), mpeg2dec->fbuf[0]->buf,
|
|
857 mpeg2dec->fbuf[b_type + 1]->buf,
|
|
858 mpeg2dec->fbuf[b_type]->buf);
|
|
859 }
|
|
860 mpeg2dec->action = NULL;
|
12932
|
861 return (mpeg2_state_t)-1;
|
9852
|
862 }
|
|
863
|
12932
|
864 static mpeg2_state_t seek_sequence (mpeg2dec_t * mpeg2dec)
|
9852
|
865 {
|
12932
|
866 mpeg2_reset_info (&(mpeg2dec->info));
|
|
867 mpeg2dec->info.sequence = NULL;
|
|
868 mpeg2dec->info.gop = NULL;
|
|
869 mpeg2_header_state_init (mpeg2dec);
|
|
870 mpeg2dec->action = mpeg2_seek_header;
|
|
871 return mpeg2_seek_header (mpeg2dec);
|
|
872 }
|
|
873
|
|
874 mpeg2_state_t mpeg2_header_end (mpeg2dec_t * mpeg2dec)
|
|
875 {
|
|
876 mpeg2_picture_t * picture;
|
9852
|
877 int b_type;
|
|
878
|
12932
|
879 b_type = (mpeg2dec->decoder.coding_type == B_TYPE);
|
9852
|
880 picture = mpeg2dec->pictures;
|
12932
|
881 if ((mpeg2dec->picture >= picture + 2) ^ b_type)
|
9852
|
882 picture = mpeg2dec->pictures + 2;
|
|
883
|
12932
|
884 mpeg2_reset_info (&(mpeg2dec->info));
|
9852
|
885 if (!(mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY)) {
|
|
886 mpeg2dec->info.display_picture = picture;
|
|
887 if (picture->nb_fields == 1)
|
|
888 mpeg2dec->info.display_picture_2nd = picture + 1;
|
|
889 mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[b_type];
|
12932
|
890 if (!mpeg2dec->convert)
|
9852
|
891 mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type + 1];
|
12932
|
892 } else if (!mpeg2dec->convert)
|
9852
|
893 mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type];
|
12932
|
894 mpeg2dec->action = seek_sequence;
|
9852
|
895 return STATE_END;
|
|
896 }
|