annotate libmpeg2/header.c @ 11379:7f02819e58e0

-sws 0 && -ssf chs fixed
author michael
date Tue, 04 Nov 2003 13:52:12 +0000
parents d9d24093db2e
children 55b9c352d019
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 /*
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
2 * header.c
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
3 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
7 * See http://libmpeg2.sourceforge.net/ for updates.
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 * mpeg2dec is free software; you can redistribute it and/or modify
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 * (at your option) any later version.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 * mpeg2dec is distributed in the hope that it will be useful,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 * GNU General Public License for more details.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 #include "config.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 #include <inttypes.h>
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
27 #include <stdlib.h> /* defines NULL */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
28 #include <string.h> /* memcmp */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
30 #include "mpeg2.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 #include "mpeg2_internal.h"
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
32 #include "convert.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 #include "attributes.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
35 #define SEQ_EXT 2
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
36 #define SEQ_DISPLAY_EXT 4
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
37 #define QUANT_MATRIX_EXT 8
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
38 #define COPYRIGHT_EXT 0x10
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
39 #define PIC_DISPLAY_EXT 0x80
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
40 #define PIC_CODING_EXT 0x100
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
41
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
42 /* default intra quant matrix, in zig-zag order */
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
43 static const uint8_t default_intra_quantizer_matrix[64] ATTR_ALIGN(16) = {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 8,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 16, 16,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 19, 16, 19,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 22, 22, 22, 22,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 22, 22, 26, 24, 26,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 27, 27, 27, 26, 26, 26,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 26, 27, 27, 27, 29, 29, 29,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 34, 34, 34, 29, 29, 29, 27, 27,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 29, 29, 32, 32, 34, 34, 37,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 38, 37, 35, 35, 34, 35,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 38, 38, 40, 40, 40,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 48, 48, 46, 46,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 56, 56, 58,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 69, 69,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 83
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
61 uint8_t mpeg2_scan_norm[64] ATTR_ALIGN(16) = {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
62 /* Zig-Zag scan pattern */
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
63 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
64 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
65 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
66 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
67 };
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
68
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
69 uint8_t mpeg2_scan_alt[64] ATTR_ALIGN(16) = {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
70 /* Alternate scan pattern */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
71 0, 8, 16, 24, 1, 9, 2, 10, 17, 25, 32, 40, 48, 56, 57, 49,
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
72 41, 33, 26, 18, 3, 11, 4, 12, 19, 27, 34, 42, 50, 58, 35, 43,
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
73 51, 59, 20, 28, 5, 13, 6, 14, 21, 29, 36, 44, 52, 60, 37, 45,
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
74 53, 61, 22, 30, 7, 15, 23, 31, 38, 46, 54, 62, 39, 47, 55, 63
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
77 void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 {
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
79 mpeg2dec->decoder.scan = mpeg2_scan_norm;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
80 mpeg2dec->picture = mpeg2dec->pictures;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
81 mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[0].fbuf;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
82 mpeg2dec->fbuf[1] = &mpeg2dec->fbuf_alloc[1].fbuf;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
83 mpeg2dec->fbuf[2] = &mpeg2dec->fbuf_alloc[2].fbuf;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
84 mpeg2dec->first = 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
85 mpeg2dec->alloc_index = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
86 mpeg2dec->alloc_index_user = 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
89 static void reset_info (mpeg2_info_t * info)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 {
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
91 info->current_picture = info->current_picture_2nd = NULL;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
92 info->display_picture = info->display_picture_2nd = NULL;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
93 info->current_fbuf = info->display_fbuf = info->discard_fbuf = NULL;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
94 info->user_data = NULL; info->user_data_len = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
95 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
96
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
97 int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
98 {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
99 uint8_t * buffer = mpeg2dec->chunk_start;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
100 sequence_t * sequence = &(mpeg2dec->new_sequence);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
101 decoder_t * decoder = &(mpeg2dec->decoder);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
102 static unsigned int frame_period[9] = {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
103 0, 1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
104 };
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
105 int width, height;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
108 if ((buffer[6] & 0x20) != 0x20) /* missing marker_bit */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
109 return 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
111 i = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
112 sequence->display_width = sequence->picture_width = width = i >> 12;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
113 sequence->display_height = sequence->picture_height = height = i & 0xfff;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
114 decoder->width = sequence->width = width = (width + 15) & ~15;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
115 decoder->height = sequence->height = height = (height + 15) & ~15;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
116 decoder->vertical_position_extension = (height > 2800);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
117 sequence->chroma_width = width >> 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
118 sequence->chroma_height = height >> 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
120 sequence->flags = SEQ_FLAG_PROGRESSIVE_SEQUENCE;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
121
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
122 sequence->pixel_width = buffer[3] >> 4; /* aspect ratio */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
123 sequence->frame_period = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
124 if ((buffer[3] & 15) < 9)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
125 sequence->frame_period = frame_period[buffer[3] & 15];
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
126
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
127 sequence->byte_rate = (buffer[4]<<10) | (buffer[5]<<2) | (buffer[6]>>6);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
128
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
129 sequence->vbv_buffer_size = ((buffer[6]<<16)|(buffer[7]<<8))&0x1ff800;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
130
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
131 if (buffer[7] & 4)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
132 sequence->flags |= SEQ_FLAG_CONSTRAINED_PARAMETERS;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 if (buffer[7] & 2) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 for (i = 0; i < 64; i++)
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
136 decoder->intra_quantizer_matrix[mpeg2_scan_norm[i]] =
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 (buffer[i+7] << 7) | (buffer[i+8] >> 1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 buffer += 64;
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
139 } else
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
140 for (i = 0; i < 64; i++)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
141 decoder->intra_quantizer_matrix[mpeg2_scan_norm[i]] =
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
142 default_intra_quantizer_matrix [i];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
143
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
144 if (buffer[7] & 1)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
145 for (i = 0; i < 64; i++)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
146 decoder->non_intra_quantizer_matrix[mpeg2_scan_norm[i]] =
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
147 buffer[i+8];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
148 else
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 for (i = 0; i < 64; i++)
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
150 decoder->non_intra_quantizer_matrix[i] = 16;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
151
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
152 sequence->profile_level_id = 0x80;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
153 sequence->colour_primaries = 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
154 sequence->transfer_characteristics = 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
155 sequence->matrix_coefficients = 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
156
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
157 decoder->mpeg1 = 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
158 decoder->intra_dc_precision = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
159 decoder->frame_pred_frame_dct = 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
160 decoder->q_scale_type = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
161 decoder->concealment_motion_vectors = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
162 decoder->scan = mpeg2_scan_norm;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
163 decoder->picture_structure = FRAME_PICTURE;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
164
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
165 mpeg2dec->ext_state = SEQ_EXT;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
166 mpeg2dec->state = STATE_SEQUENCE;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
167 mpeg2dec->display_offset_x = mpeg2dec->display_offset_y = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
168
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
169 reset_info (&(mpeg2dec->info));
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
170 return 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
171 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
172
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
173 static int sequence_ext (mpeg2dec_t * mpeg2dec)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
174 {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
175 uint8_t * buffer = mpeg2dec->chunk_start;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
176 sequence_t * sequence = &(mpeg2dec->new_sequence);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
177 decoder_t * decoder = &(mpeg2dec->decoder);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
178 int width, height;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
179 uint32_t flags;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
180
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
181 if (!(buffer[3] & 1))
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
182 return 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
183
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
184 sequence->profile_level_id = (buffer[0] << 4) | (buffer[1] >> 4);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
185
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
186 width = sequence->display_width = sequence->picture_width +=
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
187 ((buffer[1] << 13) | (buffer[2] << 5)) & 0x3000;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
188 height = sequence->display_height = sequence->picture_height +=
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
189 (buffer[2] << 7) & 0x3000;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
190 decoder->vertical_position_extension = (height > 2800);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
191 flags = sequence->flags | SEQ_FLAG_MPEG2;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
192 if (!(buffer[1] & 8)) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
193 flags &= ~SEQ_FLAG_PROGRESSIVE_SEQUENCE;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
194 height = (height + 31) & ~31;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
195 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
196 if (buffer[5] & 0x80)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
197 flags |= SEQ_FLAG_LOW_DELAY;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
198 sequence->flags = flags;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
199 decoder->width = sequence->width = width = (width + 15) & ~15;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
200 decoder->height = sequence->height = height = (height + 15) & ~15;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
201 switch (buffer[1] & 6) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
202 case 0: /* invalid */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
203 return 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
204 case 2: /* 4:2:0 */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
205 height >>= 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
206 case 4: /* 4:2:2 */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
207 width >>= 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
208 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
209 sequence->chroma_width = width;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
210 sequence->chroma_height = height;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
211
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
212 sequence->byte_rate += ((buffer[2]<<25) | (buffer[3]<<17)) & 0x3ffc0000;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
213
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
214 sequence->vbv_buffer_size |= buffer[4] << 21;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
215
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
216 sequence->frame_period =
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
217 sequence->frame_period * ((buffer[5]&31)+1) / (((buffer[5]>>2)&3)+1);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
218
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
219 decoder->mpeg1 = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
220
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
221 mpeg2dec->ext_state = SEQ_DISPLAY_EXT;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
222
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
223 return 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
224 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
225
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
226 static int sequence_display_ext (mpeg2dec_t * mpeg2dec)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
227 {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
228 uint8_t * buffer = mpeg2dec->chunk_start;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
229 sequence_t * sequence = &(mpeg2dec->new_sequence);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
230 uint32_t flags;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
231
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
232 flags = ((sequence->flags & ~SEQ_MASK_VIDEO_FORMAT) |
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
233 ((buffer[0]<<4) & SEQ_MASK_VIDEO_FORMAT));
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
234 if (buffer[0] & 1) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
235 flags |= SEQ_FLAG_COLOUR_DESCRIPTION;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
236 sequence->colour_primaries = buffer[1];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
237 sequence->transfer_characteristics = buffer[2];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
238 sequence->matrix_coefficients = buffer[3];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
239 buffer += 3;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
242 if (!(buffer[2] & 2)) /* missing marker_bit */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
243 return 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
245 sequence->display_width = (buffer[1] << 6) | (buffer[2] >> 2);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
246 sequence->display_height =
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
247 ((buffer[2]& 1 ) << 13) | (buffer[3] << 5) | (buffer[4] >> 3);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
252 static inline void finalize_sequence (sequence_t * sequence)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 {
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
254 int width;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
255 int height;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
256
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
257 sequence->byte_rate *= 50;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
258
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
259 if (sequence->flags & SEQ_FLAG_MPEG2) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
260 switch (sequence->pixel_width) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
261 case 1: /* square pixels */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
262 sequence->pixel_width = sequence->pixel_height = 1; return;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
263 case 2: /* 4:3 aspect ratio */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
264 width = 4; height = 3; break;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
265 case 3: /* 16:9 aspect ratio */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
266 width = 16; height = 9; break;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
267 case 4: /* 2.21:1 aspect ratio */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
268 width = 221; height = 100; break;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
269 default: /* illegal */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
270 sequence->pixel_width = sequence->pixel_height = 0; return;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
271 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
272 width *= sequence->display_height;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
273 height *= sequence->display_width;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
274
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
275 } else {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
276 if (sequence->byte_rate == 50 * 0x3ffff)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
277 sequence->byte_rate = 0; /* mpeg-1 VBR */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
279 switch (sequence->pixel_width) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
280 case 0: case 15: /* illegal */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
281 sequence->pixel_width = sequence->pixel_height = 0; return;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
282 case 1: /* square pixels */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
283 sequence->pixel_width = sequence->pixel_height = 1; return;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
284 case 3: /* 720x576 16:9 */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
285 sequence->pixel_width = 64; sequence->pixel_height = 45; return;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
286 case 6: /* 720x480 16:9 */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
287 sequence->pixel_width = 32; sequence->pixel_height = 27; return;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
288 case 12: /* 720*480 4:3 */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
289 sequence->pixel_width = 8; sequence->pixel_height = 9; return;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
290 default:
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
291 height = 88 * sequence->pixel_width + 1171;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
292 width = 2000;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
293 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
294 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
296 sequence->pixel_width = width;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
297 sequence->pixel_height = height;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
298 while (width) { /* find greatest common divisor */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
299 int tmp = width;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
300 width = height % tmp;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
301 height = tmp;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
302 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
303 sequence->pixel_width /= height;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
304 sequence->pixel_height /= height;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
305 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
306
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
307 void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
308 {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
309 sequence_t * sequence = &(mpeg2dec->new_sequence);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
310
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
311 finalize_sequence (sequence);
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
312
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
313 /*
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
314 * according to 6.1.1.6, repeat sequence headers should be
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
315 * identical to the original. However some DVDs dont respect that
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
316 * and have different bitrates in the repeat sequence headers. So
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
317 * we'll ignore that in the comparison and still consider these as
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
318 * repeat sequence headers.
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
319 */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
320 mpeg2dec->sequence.byte_rate = sequence->byte_rate;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
321 if (!memcmp (&(mpeg2dec->sequence), sequence, sizeof (sequence_t)))
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
322 mpeg2dec->state = STATE_SEQUENCE_REPEATED;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
323 mpeg2dec->sequence = *sequence;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
324
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
325 mpeg2dec->info.sequence = &(mpeg2dec->sequence);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
326 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
327
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
328 int mpeg2_header_gop (mpeg2dec_t * mpeg2dec)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
329 {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
330 mpeg2dec->state = STATE_GOP;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
331 reset_info (&(mpeg2dec->info));
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
332 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
333 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
334
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
335 void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int coding_type)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
336 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
337 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
338
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
339 for (i = 0; i < 3; i++)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
340 if (mpeg2dec->fbuf[1] != &mpeg2dec->fbuf_alloc[i].fbuf &&
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
341 mpeg2dec->fbuf[2] != &mpeg2dec->fbuf_alloc[i].fbuf) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
342 mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[i].fbuf;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
343 mpeg2dec->info.current_fbuf = mpeg2dec->fbuf[0];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
344 if ((coding_type == B_TYPE) ||
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
345 (mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY)) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
346 if ((coding_type == B_TYPE) || (mpeg2dec->convert_start))
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
347 mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[0];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
348 mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[0];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
349 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
350 break;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
351 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
352 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
353
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
354 int mpeg2_header_picture_start (mpeg2dec_t * mpeg2dec)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
355 {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
356 decoder_t * decoder = &(mpeg2dec->decoder);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
357 picture_t * picture;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
358
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
359 if (mpeg2dec->state != STATE_SLICE_1ST) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
360 mpeg2dec->state = STATE_PICTURE;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
361 picture = mpeg2dec->pictures;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
362 if ((decoder->coding_type != PIC_FLAG_CODING_TYPE_B) ^
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
363 (mpeg2dec->picture >= mpeg2dec->pictures + 2))
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
364 picture += 2;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
365 } else {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
366 mpeg2dec->state = STATE_PICTURE_2ND;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
367 picture = mpeg2dec->picture + 1; /* second field picture */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
368 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
369 mpeg2dec->picture = picture;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
370 picture->flags = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
371 if (mpeg2dec->num_pts) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
372 if (mpeg2dec->bytes_since_pts >= 4) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
373 mpeg2dec->num_pts = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
374 picture->pts = mpeg2dec->pts_current;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
375 picture->flags = PIC_FLAG_PTS;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
376 } else if (mpeg2dec->num_pts > 1) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
377 mpeg2dec->num_pts = 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
378 picture->pts = mpeg2dec->pts_previous;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
379 picture->flags = PIC_FLAG_PTS;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
380 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
381 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
382 picture->display_offset[0].x = picture->display_offset[1].x =
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
383 picture->display_offset[2].x = mpeg2dec->display_offset_x;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
384 picture->display_offset[0].y = picture->display_offset[1].y =
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
385 picture->display_offset[2].y = mpeg2dec->display_offset_y;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
386 return mpeg2_parse_header (mpeg2dec);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
387 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
388
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
389 int mpeg2_header_picture (mpeg2dec_t * mpeg2dec)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
390 {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
391 uint8_t * buffer = mpeg2dec->chunk_start;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
392 picture_t * picture = mpeg2dec->picture;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
393 decoder_t * decoder = &(mpeg2dec->decoder);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
394 int type;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
395 int low_delay;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
396
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
397 type = (buffer [1] >> 3) & 7;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
398 low_delay = mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
399
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
400 if (mpeg2dec->state == STATE_PICTURE) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
401 picture_t * other;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
402
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
403 decoder->second_field = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
404 other = mpeg2dec->pictures;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
405 if (other == picture)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
406 other += 2;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
407 if (decoder->coding_type != PIC_FLAG_CODING_TYPE_B) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
408 mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
409 mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
410 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
411 mpeg2dec->fbuf[0] = NULL;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
412 reset_info (&(mpeg2dec->info));
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
413 mpeg2dec->info.current_picture = picture;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
414 mpeg2dec->info.display_picture = picture;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
415 if (type != PIC_FLAG_CODING_TYPE_B) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
416 if (!low_delay) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
417 if (mpeg2dec->first) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
418 mpeg2dec->info.display_picture = NULL;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
419 mpeg2dec->first = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
420 } else {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
421 mpeg2dec->info.display_picture = other;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
422 if (other->nb_fields == 1)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
423 mpeg2dec->info.display_picture_2nd = other + 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
424 mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[1];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
425 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
426 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
427 if (!low_delay + !mpeg2dec->convert_start)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
428 mpeg2dec->info.discard_fbuf =
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
429 mpeg2dec->fbuf[!low_delay + !mpeg2dec->convert_start];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
430 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
431 if (!mpeg2dec->custom_fbuf) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
432 while (mpeg2dec->alloc_index < 3) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
433 fbuf_t * fbuf;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
434
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
435 fbuf = &(mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
436 fbuf->id = NULL;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
437 if (mpeg2dec->convert_start) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
438 fbuf->buf[0] =
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
439 (uint8_t *) mpeg2_malloc (mpeg2dec->convert_size[0],
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
440 ALLOC_CONVERTED);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
441 fbuf->buf[1] = fbuf->buf[0] + mpeg2dec->convert_size[1];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
442 fbuf->buf[2] = fbuf->buf[0] + mpeg2dec->convert_size[2];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
443 } else {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
444 int size;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
445 size = mpeg2dec->decoder.width * mpeg2dec->decoder.height;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
446 fbuf->buf[0] = (uint8_t *) mpeg2_malloc (6 * size >> 2,
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
447 ALLOC_YUV);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
448 fbuf->buf[1] = fbuf->buf[0] + size;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
449 fbuf->buf[2] = fbuf->buf[1] + (size >> 2);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
450 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
451 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
452 mpeg2_set_fbuf (mpeg2dec, type);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
453 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
454 } else {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
455 decoder->second_field = 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
456 mpeg2dec->info.current_picture_2nd = picture;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
457 mpeg2dec->info.user_data = NULL; mpeg2dec->info.user_data_len = 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
458 if (low_delay || type == PIC_FLAG_CODING_TYPE_B)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
459 mpeg2dec->info.display_picture_2nd = picture;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
460 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
461 mpeg2dec->ext_state = PIC_CODING_EXT;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
462
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
463 picture->temporal_reference = (buffer[0] << 2) | (buffer[1] >> 6);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
464
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
465 decoder->coding_type = type;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
466 picture->flags |= type;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
467
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
468 if (type == PIC_FLAG_CODING_TYPE_P || type == PIC_FLAG_CODING_TYPE_B) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
469 /* forward_f_code and backward_f_code - used in mpeg1 only */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
470 decoder->f_motion.f_code[1] = (buffer[3] >> 2) & 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
471 decoder->f_motion.f_code[0] =
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
472 (((buffer[3] << 1) | (buffer[4] >> 7)) & 7) - 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
473 decoder->b_motion.f_code[1] = (buffer[4] >> 6) & 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
474 decoder->b_motion.f_code[0] = ((buffer[4] >> 3) & 7) - 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
475 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
476
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
477 /* XXXXXX decode extra_information_picture as well */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
478
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
479 picture->nb_fields = 2;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
480
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
481 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
482 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
483
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
484 static int picture_coding_ext (mpeg2dec_t * mpeg2dec)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
485 {
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
486 uint8_t * buffer = mpeg2dec->chunk_start;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
487 picture_t * picture = mpeg2dec->picture;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
488 decoder_t * decoder = &(mpeg2dec->decoder);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
489 uint32_t flags;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
490
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
491 /* pre subtract 1 for use later in compute_motion_vector */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
492 decoder->f_motion.f_code[0] = (buffer[0] & 15) - 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
493 decoder->f_motion.f_code[1] = (buffer[1] >> 4) - 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
494 decoder->b_motion.f_code[0] = (buffer[1] & 15) - 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
495 decoder->b_motion.f_code[1] = (buffer[2] >> 4) - 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
496
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
497 flags = picture->flags;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
498 decoder->intra_dc_precision = (buffer[2] >> 2) & 3;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
499 decoder->picture_structure = buffer[2] & 3;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
500 switch (decoder->picture_structure) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
501 case TOP_FIELD:
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
502 flags |= PIC_FLAG_TOP_FIELD_FIRST;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
503 case BOTTOM_FIELD:
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
504 picture->nb_fields = 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
505 break;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
506 case FRAME_PICTURE:
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
507 if (!(mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
508 picture->nb_fields = (buffer[3] & 2) ? 3 : 2;
10509
d9d24093db2e Export flags needed for softpulldown filter.
ranma
parents: 9858
diff changeset
509 flags |= (buffer[3] & 128) ? PIC_FLAG_TOP_FIELD_FIRST : 0;
d9d24093db2e Export flags needed for softpulldown filter.
ranma
parents: 9858
diff changeset
510 flags |= (buffer[3] & 2) ? PIC_FLAG_REPEAT_FIRST_FIELD : 0;
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
511 } else
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
512 picture->nb_fields = (buffer[3]&2) ? ((buffer[3]&128) ? 6 : 4) : 2;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
513 break;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
514 default:
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
515 return 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
516 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
517 decoder->top_field_first = buffer[3] >> 7;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
518 decoder->frame_pred_frame_dct = (buffer[3] >> 6) & 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
519 decoder->concealment_motion_vectors = (buffer[3] >> 5) & 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
520 decoder->q_scale_type = (buffer[3] >> 4) & 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
521 decoder->intra_vlc_format = (buffer[3] >> 3) & 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
522 decoder->scan = (buffer[3] & 4) ? mpeg2_scan_alt : mpeg2_scan_norm;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
523 flags |= (buffer[4] & 0x80) ? PIC_FLAG_PROGRESSIVE_FRAME : 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
524 if (buffer[4] & 0x40)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
525 flags |= (((buffer[4]<<26) | (buffer[5]<<18) | (buffer[6]<<10)) &
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
526 PIC_MASK_COMPOSITE_DISPLAY) | PIC_FLAG_COMPOSITE_DISPLAY;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
527 picture->flags = flags;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
528
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
529 mpeg2dec->ext_state = PIC_DISPLAY_EXT | COPYRIGHT_EXT | QUANT_MATRIX_EXT;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
530
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
531 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
532 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
533
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
534 static int picture_display_ext (mpeg2dec_t * mpeg2dec)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
535 {
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
536 uint8_t * buffer = mpeg2dec->chunk_start;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
537 picture_t * picture = mpeg2dec->picture;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
538 int i, nb_pos;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
539
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
540 nb_pos = picture->nb_fields;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
541 if (mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
542 nb_pos >>= 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
543
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
544 for (i = 0; i < nb_pos; i++) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
545 int x, y;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
546
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
547 x = ((buffer[4*i] << 24) | (buffer[4*i+1] << 16) |
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
548 (buffer[4*i+2] << 8) | buffer[4*i+3]) >> (11-2*i);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
549 y = ((buffer[4*i+2] << 24) | (buffer[4*i+3] << 16) |
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
550 (buffer[4*i+4] << 8) | buffer[4*i+5]) >> (10-2*i);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
551 if (! (x & y & 1))
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
552 return 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
553 picture->display_offset[i].x = mpeg2dec->display_offset_x = x >> 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
554 picture->display_offset[i].y = mpeg2dec->display_offset_y = y >> 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
555 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
556 for (; i < 3; i++) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
557 picture->display_offset[i].x = mpeg2dec->display_offset_x;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
558 picture->display_offset[i].y = mpeg2dec->display_offset_y;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
559 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
560 return 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
561 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
562
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
563 static int copyright_ext (mpeg2dec_t * mpeg2dec)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
564 {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
565 return 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
566 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
567
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
568 static int quant_matrix_ext (mpeg2dec_t * mpeg2dec)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
569 {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
570 uint8_t * buffer = mpeg2dec->chunk_start;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
571 decoder_t * decoder = &(mpeg2dec->decoder);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
572 int i;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
573
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
574 if (buffer[0] & 8) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
575 for (i = 0; i < 64; i++)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
576 decoder->intra_quantizer_matrix[mpeg2_scan_norm[i]] =
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
577 (buffer[i] << 5) | (buffer[i+1] >> 3);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
578 buffer += 64;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
579 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
580
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
581 if (buffer[0] & 4)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
582 for (i = 0; i < 64; i++)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
583 decoder->non_intra_quantizer_matrix[mpeg2_scan_norm[i]] =
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
584 (buffer[i] << 6) | (buffer[i+1] >> 2);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
585
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
586 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
587 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
588
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
589 int mpeg2_header_extension (mpeg2dec_t * mpeg2dec)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
590 {
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
591 static int (* parser[]) (mpeg2dec_t *) = {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
592 0, sequence_ext, sequence_display_ext, quant_matrix_ext,
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
593 copyright_ext, 0, 0, picture_display_ext, picture_coding_ext
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
594 };
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
595 int ext, ext_bit;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
596
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
597 ext = mpeg2dec->chunk_start[0] >> 4;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
598 ext_bit = 1 << ext;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
599
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
600 if (!(mpeg2dec->ext_state & ext_bit))
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
601 return 0; /* ignore illegal extensions */
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
602 mpeg2dec->ext_state &= ~ext_bit;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
603 return parser[ext] (mpeg2dec);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
604 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
605
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
606 int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
607 {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
608 if (!mpeg2dec->info.user_data_len)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
609 mpeg2dec->info.user_data = mpeg2dec->chunk_start;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
610 else
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
611 mpeg2dec->info.user_data_len += 3;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
612 mpeg2dec->info.user_data_len += (mpeg2dec->chunk_ptr - 4 -
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
613 mpeg2dec->chunk_start);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
614 mpeg2dec->chunk_start = mpeg2dec->chunk_ptr - 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
615
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
616 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
617 }
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
618
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
619 int mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
620 {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
621 mpeg2dec->state = ((mpeg2dec->picture->nb_fields > 1 ||
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
622 mpeg2dec->state == STATE_PICTURE_2ND) ?
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
623 STATE_SLICE : STATE_SLICE_1ST);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
624
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
625 if (!(mpeg2dec->nb_decode_slices))
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
626 mpeg2dec->picture->flags |= PIC_FLAG_SKIP;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
627 else if (mpeg2dec->convert_start) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
628 int flags;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
629
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
630 switch (mpeg2dec->decoder.picture_structure) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
631 case TOP_FIELD: flags = CONVERT_TOP_FIELD; break;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
632 case BOTTOM_FIELD: flags = CONVERT_BOTTOM_FIELD; break;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
633 default:
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
634 flags =
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
635 ((mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE) ?
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
636 CONVERT_FRAME : CONVERT_BOTH_FIELDS);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
637 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
638 mpeg2dec->convert_start (mpeg2dec->convert_id,
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
639 mpeg2dec->fbuf[0]->buf, flags);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
640
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
641 mpeg2dec->decoder.convert = mpeg2dec->convert_copy;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
642 mpeg2dec->decoder.fbuf_id = mpeg2dec->convert_id;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
643
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
644 if (mpeg2dec->decoder.coding_type == B_TYPE)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
645 mpeg2_init_fbuf (&(mpeg2dec->decoder), mpeg2dec->yuv_buf[2],
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
646 mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1],
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
647 mpeg2dec->yuv_buf[mpeg2dec->yuv_index]);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
648 else {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
649 mpeg2_init_fbuf (&(mpeg2dec->decoder),
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
650 mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1],
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
651 mpeg2dec->yuv_buf[mpeg2dec->yuv_index],
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
652 mpeg2dec->yuv_buf[mpeg2dec->yuv_index]);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
653 if (mpeg2dec->state == STATE_SLICE)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
654 mpeg2dec->yuv_index ^= 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
655 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
656 } else {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
657 int b_type;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
658
9858
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9852
diff changeset
659 //mpeg2dec->decoder.convert = NULL;
9852
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
660 b_type = (mpeg2dec->decoder.coding_type == B_TYPE);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
661 mpeg2_init_fbuf (&(mpeg2dec->decoder), mpeg2dec->fbuf[0]->buf,
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
662 mpeg2dec->fbuf[b_type + 1]->buf,
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
663 mpeg2dec->fbuf[b_type]->buf);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
664 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
665 mpeg2dec->action = NULL;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
666 return 0;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
667 }
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
668
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
669 int mpeg2_header_end (mpeg2dec_t * mpeg2dec)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
670 {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
671 picture_t * picture;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
672 int b_type;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
673
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
674 picture = mpeg2dec->pictures;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
675 if (mpeg2dec->picture < picture + 2)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
676 picture = mpeg2dec->pictures + 2;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
677
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
678 mpeg2dec->state = STATE_INVALID;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
679 reset_info (&(mpeg2dec->info));
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
680 b_type = (mpeg2dec->decoder.coding_type == B_TYPE);
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
681 if (!(mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY)) {
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
682 mpeg2dec->info.display_picture = picture;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
683 if (picture->nb_fields == 1)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
684 mpeg2dec->info.display_picture_2nd = picture + 1;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
685 mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[b_type];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
686 if (!mpeg2dec->convert_start)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
687 mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type + 1];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
688 } else if (!mpeg2dec->convert_start)
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
689 mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type];
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
690 mpeg2dec->action = mpeg2_seek_sequence;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
691 return STATE_END;
47984e3f54ce Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents: 3839
diff changeset
692 }