annotate libmpeg2/header.c @ 8447:9c64428179b6

added local copy of Ville Syrj¸«£l¸«£'s directfb for matrox howto
author attila
date Sat, 14 Dec 2002 11:32:09 +0000
parents b608086bf84e
children 47984e3f54ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 * slice.c
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
3 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 * mpeg2dec is free software; you can redistribute it and/or modify
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 * (at your option) any later version.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 * mpeg2dec is distributed in the hope that it will be useful,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 * GNU General Public License for more details.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 *
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 #include "config.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 #include <inttypes.h>
3839
b608086bf84e warning fixes
pl
parents: 2562
diff changeset
25 #include <stdio.h>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 #include "mpeg2_internal.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 #include "attributes.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
30 /* default intra quant matrix, in zig-zag order */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 static uint8_t default_intra_quantizer_matrix[64] ATTR_ALIGN(16) = {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 8,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 16, 16,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 19, 16, 19,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 22, 22, 22, 22,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 22, 22, 26, 24, 26,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 27, 27, 27, 26, 26, 26,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 26, 27, 27, 27, 29, 29, 29,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 34, 34, 34, 29, 29, 29, 27, 27,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 29, 29, 32, 32, 34, 34, 37,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 38, 37, 35, 35, 34, 35,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 38, 38, 40, 40, 40,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 48, 48, 46, 46,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 56, 56, 58,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 69, 69,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 83
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 uint8_t scan_norm[64] ATTR_ALIGN(16) =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
51 /* Zig-Zag scan pattern */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 0, 1, 8,16, 9, 2, 3,10,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 17,24,32,25,18,11, 4, 5,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 12,19,26,33,40,48,41,34,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 27,20,13, 6, 7,14,21,28,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 35,42,49,56,57,50,43,36,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 29,22,15,23,30,37,44,51,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 58,59,52,45,38,31,39,46,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 53,60,61,54,47,55,62,63
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 uint8_t scan_alt[64] ATTR_ALIGN(16) =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
64 /* Alternate scan pattern */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 53,61,22,30,7,15,23,31,38,46,54,62,39,47,55,63
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 void header_state_init (picture_t * picture)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 picture->scan = scan_norm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 int header_process_sequence_header (picture_t * picture, uint8_t * buffer)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
78 int width, height;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80
1622
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
81 if ((buffer[6] & 0x20) != 0x20){
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
82 printf("missing marker bit!\n");
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
83 return 1; /* missing marker_bit */
1622
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
84 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
86 height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
88 picture->display_picture_width = (height >> 12);
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
89 picture->display_picture_height = (height & 0xfff);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
91 width = ((height >> 12) + 15) & ~15;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
92 height = ((height & 0xfff) + 15) & ~15;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93
1622
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
94 if ((width > 768) || (height > 576)){
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
95 printf("size restrictions for MP@ML or MPEG1 exceeded! (%dx%d)\n",width,height);
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
96 // return 1; /* size restrictions for MP@ML or MPEG1 */
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
97 }
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
98
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
99 picture->coded_picture_width = width;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
100 picture->coded_picture_height = height;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
101
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
102 /* this is not used by the decoder */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 picture->aspect_ratio_information = buffer[3] >> 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 picture->frame_rate_code = buffer[3] & 15;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 if (buffer[7] & 2) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 for (i = 0; i < 64; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 picture->intra_quantizer_matrix[scan_norm[i]] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 (buffer[i+7] << 7) | (buffer[i+8] >> 1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 buffer += 64;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 for (i = 0; i < 64; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 picture->intra_quantizer_matrix[scan_norm[i]] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 default_intra_quantizer_matrix [i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 if (buffer[7] & 1) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 for (i = 0; i < 64; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 picture->non_intra_quantizer_matrix[scan_norm[i]] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 buffer[i+8];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 for (i = 0; i < 64; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 picture->non_intra_quantizer_matrix[i] = 16;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
127 /* MPEG1 - for testing only */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 picture->mpeg1 = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 picture->intra_dc_precision = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 picture->frame_pred_frame_dct = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 picture->q_scale_type = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 picture->concealment_motion_vectors = 0;
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
133 /* picture->alternate_scan = 0; */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 picture->picture_structure = FRAME_PICTURE;
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
135 /* picture->second_field = 0; */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 static int header_process_sequence_extension (picture_t * picture,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 uint8_t * buffer)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
143 /* check chroma format, size extensions, marker bit */
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
144 if (((buffer[1] & 0x07) != 0x02) || (buffer[2] & 0xe0) ||
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
145 ((buffer[3] & 0x01) != 0x01))
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
146 return 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
148 /* this is not used by the decoder */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 picture->progressive_sequence = (buffer[1] >> 3) & 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 if (picture->progressive_sequence)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 picture->coded_picture_height =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 (picture->coded_picture_height + 31) & ~31;
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
154
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
155 /* MPEG1 - for testing only */
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
156 picture->mpeg1 = 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 static int header_process_quant_matrix_extension (picture_t * picture,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 uint8_t * buffer)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 if (buffer[0] & 8) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 for (i = 0; i < 64; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 picture->intra_quantizer_matrix[scan_norm[i]] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 (buffer[i] << 5) | (buffer[i+1] >> 3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 buffer += 64;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 if (buffer[0] & 4) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 for (i = 0; i < 64; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 picture->non_intra_quantizer_matrix[scan_norm[i]] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 (buffer[i] << 6) | (buffer[i+1] >> 2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 static int header_process_picture_coding_extension (picture_t * picture, uint8_t * buffer)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
184 /* pre subtract 1 for use later in compute_motion_vector */
49
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
185 picture->f_motion.f_code[0] = (buffer[0] & 15) - 1;
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
186 picture->f_motion.f_code[1] = (buffer[1] >> 4) - 1;
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
187 picture->b_motion.f_code[0] = (buffer[1] & 15) - 1;
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
188 picture->b_motion.f_code[1] = (buffer[2] >> 4) - 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 picture->intra_dc_precision = (buffer[2] >> 2) & 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 picture->picture_structure = buffer[2] & 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 picture->frame_pred_frame_dct = (buffer[3] >> 6) & 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 picture->concealment_motion_vectors = (buffer[3] >> 5) & 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 picture->q_scale_type = (buffer[3] >> 4) & 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 picture->intra_vlc_format = (buffer[3] >> 3) & 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
197 if (buffer[3] & 4) /* alternate_scan */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 picture->scan = scan_alt;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 picture->scan = scan_norm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
202 /* these are not used by the decoder */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 picture->top_field_first = buffer[3] >> 7;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 picture->repeat_first_field = (buffer[3] >> 1) & 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 picture->progressive_frame = buffer[4] >> 7;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 // repeat_first implementation by A'rpi/ESP-team, based on libmpeg3:
2426
4122de6622b2 switch back to old timing code until new is bugfixed
arpi
parents: 2196
diff changeset
208 picture->display_time=100;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 if(picture->repeat_first_field){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 if(picture->progressive_sequence){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 if(picture->top_field_first)
2426
4122de6622b2 switch back to old timing code until new is bugfixed
arpi
parents: 2196
diff changeset
212 picture->display_time+=200;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 else
2426
4122de6622b2 switch back to old timing code until new is bugfixed
arpi
parents: 2196
diff changeset
214 picture->display_time+=100;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 if(picture->progressive_frame){
2426
4122de6622b2 switch back to old timing code until new is bugfixed
arpi
parents: 2196
diff changeset
217 picture->display_time+=50;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 }
2562
4b0db52f5de9 arpi's display_time + interlace hack
iive
parents: 2527
diff changeset
220 //temopral hack. We calc time on every field, so if we have 2 fields
4b0db52f5de9 arpi's display_time + interlace hack
iive
parents: 2527
diff changeset
221 // interlaced we'll end with double time for 1 frame
4b0db52f5de9 arpi's display_time + interlace hack
iive
parents: 2527
diff changeset
222 if( picture->picture_structure!=3 ) picture->display_time/=2;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226 int header_process_extension (picture_t * picture, uint8_t * buffer)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 switch (buffer[0] & 0xf0) {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
229 case 0x10: /* sequence extension */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 return header_process_sequence_extension (picture, buffer);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
232 case 0x30: /* quant matrix extension */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 return header_process_quant_matrix_extension (picture, buffer);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
235 case 0x80: /* picture coding extension */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 return header_process_picture_coding_extension (picture, buffer);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 int header_process_picture_header (picture_t *picture, uint8_t * buffer)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 picture->picture_coding_type = (buffer [1] >> 3) & 7;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
246 /* forward_f_code and backward_f_code - used in mpeg1 only */
49
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
247 picture->f_motion.f_code[1] = (buffer[3] >> 2) & 1;
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
248 picture->f_motion.f_code[0] =
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 (((buffer[3] << 1) | (buffer[4] >> 7)) & 7) - 1;
49
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
250 picture->b_motion.f_code[1] = (buffer[4] >> 6) & 1;
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
251 picture->b_motion.f_code[0] = ((buffer[4] >> 3) & 7) - 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
253 /* move in header_process_picture_header */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 picture->second_field =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 (picture->picture_structure != FRAME_PICTURE) &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 !(picture->second_field);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 }