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