annotate libmpeg2/header.c @ 31315:ad274a5b093b

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