annotate libmpeg2/header.c @ 2155:b961f2f829e1

Similar to 1.9
author jaf
date Wed, 10 Oct 2001 18:04:03 +0000
parents a0d4fa6b9435
children d5a44e828ae4
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>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 #include "mpeg2_internal.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 #include "attributes.h"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
29 /* default intra quant matrix, in zig-zag order */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 static uint8_t default_intra_quantizer_matrix[64] ATTR_ALIGN(16) = {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 8,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 16, 16,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 19, 16, 19,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 22, 22, 22, 22,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 22, 22, 26, 24, 26,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 27, 27, 27, 26, 26, 26,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 26, 27, 27, 27, 29, 29, 29,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 34, 34, 34, 29, 29, 29, 27, 27,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 29, 29, 32, 32, 34, 34, 37,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 38, 37, 35, 35, 34, 35,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 38, 38, 40, 40, 40,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 48, 48, 46, 46,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 56, 56, 58,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 69, 69,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 83
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 uint8_t scan_norm[64] ATTR_ALIGN(16) =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
50 /* Zig-Zag scan pattern */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 0, 1, 8,16, 9, 2, 3,10,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 17,24,32,25,18,11, 4, 5,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 12,19,26,33,40,48,41,34,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 27,20,13, 6, 7,14,21,28,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 35,42,49,56,57,50,43,36,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 29,22,15,23,30,37,44,51,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 58,59,52,45,38,31,39,46,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 53,60,61,54,47,55,62,63
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 uint8_t scan_alt[64] ATTR_ALIGN(16) =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
63 /* Alternate scan pattern */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 53,61,22,30,7,15,23,31,38,46,54,62,39,47,55,63
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 void header_state_init (picture_t * picture)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 picture->scan = scan_norm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 int header_process_sequence_header (picture_t * picture, uint8_t * buffer)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
77 int width, height;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79
1622
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
80 if ((buffer[6] & 0x20) != 0x20){
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
81 printf("missing marker bit!\n");
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
82 return 1; /* missing marker_bit */
1622
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
83 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
85 height = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
87 picture->display_picture_width = (height >> 12);
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
88 picture->display_picture_height = (height & 0xfff);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
90 width = ((height >> 12) + 15) & ~15;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
91 height = ((height & 0xfff) + 15) & ~15;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92
1622
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
93 if ((width > 768) || (height > 576)){
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
94 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
95 // return 1; /* size restrictions for MP@ML or MPEG1 */
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
96 }
a0d4fa6b9435 printf added to seq. header error handlers
arpi
parents: 49
diff changeset
97
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
98 picture->coded_picture_width = width;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
99 picture->coded_picture_height = height;
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
100
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
101 /* this is not used by the decoder */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 picture->aspect_ratio_information = buffer[3] >> 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 picture->frame_rate_code = buffer[3] & 15;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 picture->bitrate = (buffer[4]<<10)|(buffer[5]<<2)|(buffer[6]>>6);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 if (buffer[7] & 2) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 for (i = 0; i < 64; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 picture->intra_quantizer_matrix[scan_norm[i]] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 (buffer[i+7] << 7) | (buffer[i+8] >> 1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 buffer += 64;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 for (i = 0; i < 64; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 picture->intra_quantizer_matrix[scan_norm[i]] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 default_intra_quantizer_matrix [i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 if (buffer[7] & 1) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 for (i = 0; i < 64; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 picture->non_intra_quantizer_matrix[scan_norm[i]] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 buffer[i+8];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122 for (i = 0; i < 64; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 picture->non_intra_quantizer_matrix[i] = 16;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
126 /* MPEG1 - for testing only */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 picture->mpeg1 = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 picture->intra_dc_precision = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 picture->frame_pred_frame_dct = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 picture->q_scale_type = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 picture->concealment_motion_vectors = 0;
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
132 /* picture->alternate_scan = 0; */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 picture->picture_structure = FRAME_PICTURE;
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
134 /* picture->second_field = 0; */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 static int header_process_sequence_extension (picture_t * picture,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 uint8_t * buffer)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
142 /* check chroma format, size extensions, marker bit */
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
143 if (((buffer[1] & 0x07) != 0x02) || (buffer[2] & 0xe0) ||
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
144 ((buffer[3] & 0x01) != 0x01))
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
145 return 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
147 /* this is not used by the decoder */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 picture->progressive_sequence = (buffer[1] >> 3) & 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 if (picture->progressive_sequence)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 picture->coded_picture_height =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 (picture->coded_picture_height + 31) & ~31;
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
153
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
154 /* MPEG1 - for testing only */
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
155 picture->mpeg1 = 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 static int header_process_quant_matrix_extension (picture_t * picture,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 uint8_t * buffer)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 if (buffer[0] & 8) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 for (i = 0; i < 64; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 picture->intra_quantizer_matrix[scan_norm[i]] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 (buffer[i] << 5) | (buffer[i+1] >> 3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 buffer += 64;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 if (buffer[0] & 4) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 for (i = 0; i < 64; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 picture->non_intra_quantizer_matrix[scan_norm[i]] =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 (buffer[i] << 6) | (buffer[i+1] >> 2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 static int header_process_picture_coding_extension (picture_t * picture, uint8_t * buffer)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
183 /* 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
184 picture->f_motion.f_code[0] = (buffer[0] & 15) - 1;
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
185 picture->f_motion.f_code[1] = (buffer[1] >> 4) - 1;
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
186 picture->b_motion.f_code[0] = (buffer[1] & 15) - 1;
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
187 picture->b_motion.f_code[1] = (buffer[2] >> 4) - 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 picture->intra_dc_precision = (buffer[2] >> 2) & 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 picture->picture_structure = buffer[2] & 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 picture->frame_pred_frame_dct = (buffer[3] >> 6) & 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 picture->concealment_motion_vectors = (buffer[3] >> 5) & 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 picture->q_scale_type = (buffer[3] >> 4) & 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 picture->intra_vlc_format = (buffer[3] >> 3) & 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
196 if (buffer[3] & 4) /* alternate_scan */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197 picture->scan = scan_alt;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 picture->scan = scan_norm;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
201 /* these are not used by the decoder */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 picture->top_field_first = buffer[3] >> 7;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 picture->repeat_first_field = (buffer[3] >> 1) & 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 picture->progressive_frame = buffer[4] >> 7;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 // repeat_first implementation by A'rpi/ESP-team, based on libmpeg3:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 if(picture->repeat_count>=100) picture->repeat_count=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 if(picture->repeat_first_field){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 if(picture->progressive_sequence){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 if(picture->top_field_first)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 picture->repeat_count+=200;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 picture->repeat_count+=100;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 if(picture->progressive_frame){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 picture->repeat_count+=50;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 int header_process_extension (picture_t * picture, uint8_t * buffer)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 switch (buffer[0] & 0xf0) {
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
226 case 0x10: /* sequence extension */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 return header_process_sequence_extension (picture, buffer);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
229 case 0x30: /* quant matrix extension */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 return header_process_quant_matrix_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 0x80: /* picture coding extension */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 return header_process_picture_coding_extension (picture, buffer);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 return 0;
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 int header_process_picture_header (picture_t *picture, uint8_t * buffer)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 picture->picture_coding_type = (buffer [1] >> 3) & 7;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
243 /* 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
244 picture->f_motion.f_code[1] = (buffer[3] >> 2) & 1;
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
245 picture->f_motion.f_code[0] =
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 (((buffer[3] << 1) | (buffer[4] >> 7)) & 7) - 1;
49
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
247 picture->b_motion.f_code[1] = (buffer[4] >> 6) & 1;
727b1337f951 updated to libmpeg2-0.2.1-CVS
arpi_esp
parents: 36
diff changeset
248 picture->b_motion.f_code[0] = ((buffer[4] >> 3) & 7) - 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249
36
846535ace7a2 libmpeg2-0.2.0 merge
arpi_esp
parents: 1
diff changeset
250 /* move in header_process_picture_header */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 picture->second_field =
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 (picture->picture_structure != FRAME_PICTURE) &&
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 !(picture->second_field);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 }