annotate libmpeg2/decode.c @ 19707:e02a21075241

fix link to amigasoft.net
author kraymer
date Wed, 06 Sep 2006 12:41:27 +0000
parents 0783dd397f74
children 60a39d71e247
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
1 /*
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
2 * decode.c
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
5 *
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
6 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
7 * See http://libmpeg2.sourceforge.net/ for updates.
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
8 *
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
9 * mpeg2dec is free software; you can redistribute it and/or modify
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
12 * (at your option) any later version.
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
13 *
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
14 * mpeg2dec is distributed in the hope that it will be useful,
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
17 * GNU General Public License for more details.
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
18 *
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14732
1385ec491ffb Mark locally modified files as such to comply more closely with GPL 2a.
diego
parents: 12932
diff changeset
22 *
1385ec491ffb Mark locally modified files as such to comply more closely with GPL 2a.
diego
parents: 12932
diff changeset
23 * Modified for use with MPlayer, see libmpeg-0.4.0.diff for the exact changes.
18783
0783dd397f74 CVS --> Subversion in copyright notices
diego
parents: 14732
diff changeset
24 * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
14732
1385ec491ffb Mark locally modified files as such to comply more closely with GPL 2a.
diego
parents: 12932
diff changeset
25 * $Id$
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
26 */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
27
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
28 #include "config.h"
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
29
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
30 #include <string.h> /* memcmp/memset, try to remove */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
31 #include <stdlib.h>
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
32 #include <inttypes.h>
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
33
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
34 #include "mpeg2.h"
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
35 #include "attributes.h"
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
36 #include "mpeg2_internal.h"
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
37
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
38 static int mpeg2_accels = 0;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
39
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
40 #define BUFFER_SIZE (1194 * 1024)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
41
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
42 const mpeg2_info_t * mpeg2_info (mpeg2dec_t * mpeg2dec)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
43 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
44 return &(mpeg2dec->info);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
45 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
46
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
47 static inline int skip_chunk (mpeg2dec_t * mpeg2dec, int bytes)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
48 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
49 uint8_t * current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
50 uint32_t shift;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
51 uint8_t * limit;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
52 uint8_t byte;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
53
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
54 if (!bytes)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
55 return 0;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
56
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
57 current = mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
58 shift = mpeg2dec->shift;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
59 limit = current + bytes;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
60
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
61 do {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
62 byte = *current++;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
63 if (shift == 0x00000100) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
64 int skipped;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
65
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
66 mpeg2dec->shift = 0xffffff00;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
67 skipped = current - mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
68 mpeg2dec->buf_start = current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
69 return skipped;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
70 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
71 shift = (shift | byte) << 8;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
72 } while (current < limit);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
73
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
74 mpeg2dec->shift = shift;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
75 mpeg2dec->buf_start = current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
76 return 0;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
77 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
78
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
79 static inline int copy_chunk (mpeg2dec_t * mpeg2dec, int bytes)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
80 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
81 uint8_t * current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
82 uint32_t shift;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
83 uint8_t * chunk_ptr;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
84 uint8_t * limit;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
85 uint8_t byte;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
86
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
87 if (!bytes)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
88 return 0;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
89
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
90 current = mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
91 shift = mpeg2dec->shift;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
92 chunk_ptr = mpeg2dec->chunk_ptr;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
93 limit = current + bytes;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
94
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
95 do {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
96 byte = *current++;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
97 if (shift == 0x00000100) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
98 int copied;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
99
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
100 mpeg2dec->shift = 0xffffff00;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
101 mpeg2dec->chunk_ptr = chunk_ptr + 1;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
102 copied = current - mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
103 mpeg2dec->buf_start = current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
104 return copied;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
105 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
106 shift = (shift | byte) << 8;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
107 *chunk_ptr++ = byte;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
108 } while (current < limit);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
109
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
110 mpeg2dec->shift = shift;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
111 mpeg2dec->buf_start = current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
112 return 0;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
113 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
114
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
115 void mpeg2_buffer (mpeg2dec_t * mpeg2dec, uint8_t * start, uint8_t * end)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
116 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
117 mpeg2dec->buf_start = start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
118 mpeg2dec->buf_end = end;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
119 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
120
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
121 int mpeg2_getpos (mpeg2dec_t * mpeg2dec)
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
122 {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
123 return mpeg2dec->buf_end - mpeg2dec->buf_start;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
124 }
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
125
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
126 static inline mpeg2_state_t seek_chunk (mpeg2dec_t * mpeg2dec)
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
127 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
128 int size, skipped;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
129
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
130 size = mpeg2dec->buf_end - mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
131 skipped = skip_chunk (mpeg2dec, size);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
132 if (!skipped) {
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
133 mpeg2dec->bytes_since_tag += size;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
134 return STATE_BUFFER;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
135 }
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
136 mpeg2dec->bytes_since_tag += skipped;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
137 mpeg2dec->code = mpeg2dec->buf_start[-1];
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
138 return (mpeg2_state_t)-1;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
139 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
140
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
141 mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec)
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
142 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
143 while (mpeg2dec->code != 0xb3 &&
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
144 ((mpeg2dec->code != 0xb7 && mpeg2dec->code != 0xb8 &&
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
145 mpeg2dec->code) || mpeg2dec->sequence.width == (unsigned)-1))
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
146 if (seek_chunk (mpeg2dec) == STATE_BUFFER)
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
147 return STATE_BUFFER;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
148 mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
149 mpeg2dec->user_data_len = 0;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
150 return (mpeg2dec->code ? mpeg2_parse_header (mpeg2dec) :
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
151 mpeg2_header_picture_start (mpeg2dec));
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
152 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
153
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
154 #define RECEIVED(code,state) (((state) << 8) + (code))
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
155
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
156 mpeg2_state_t mpeg2_parse (mpeg2dec_t * mpeg2dec)
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
157 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
158 int size_buffer, size_chunk, copied;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
159
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
160 if (mpeg2dec->action) {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
161 mpeg2_state_t state;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
162
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
163 state = mpeg2dec->action (mpeg2dec);
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
164 if ((int)state >= 0)
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
165 return state;
9858
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
166 }
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
167
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
168 while (1) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
169 while ((unsigned) (mpeg2dec->code - mpeg2dec->first_decode_slice) <
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
170 mpeg2dec->nb_decode_slices) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
171 size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
172 size_chunk = (mpeg2dec->chunk_buffer + BUFFER_SIZE -
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
173 mpeg2dec->chunk_ptr);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
174 if (size_buffer <= size_chunk) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
175 copied = copy_chunk (mpeg2dec, size_buffer);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
176 if (!copied) {
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
177 mpeg2dec->bytes_since_tag += size_buffer;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
178 mpeg2dec->chunk_ptr += size_buffer;
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
179 return STATE_BUFFER;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
180 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
181 } else {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
182 copied = copy_chunk (mpeg2dec, size_chunk);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
183 if (!copied) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
184 /* filled the chunk buffer without finding a start code */
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
185 mpeg2dec->bytes_since_tag += size_chunk;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
186 mpeg2dec->action = seek_chunk;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
187 return STATE_INVALID;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
188 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
189 }
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
190 mpeg2dec->bytes_since_tag += copied;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
191
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
192 mpeg2_slice (&(mpeg2dec->decoder), mpeg2dec->code,
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
193 mpeg2dec->chunk_start);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
194 mpeg2dec->code = mpeg2dec->buf_start[-1];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
195 mpeg2dec->chunk_ptr = mpeg2dec->chunk_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
196 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
197 if ((unsigned) (mpeg2dec->code - 1) >= 0xb0 - 1)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
198 break;
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
199 if (seek_chunk (mpeg2dec) == STATE_BUFFER)
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
200 return STATE_BUFFER;
9858
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
201 }
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
202
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
203 switch (mpeg2dec->code) {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
204 case 0x00:
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
205 mpeg2dec->action = mpeg2_header_picture_start;
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
206 return mpeg2dec->state;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
207 case 0xb7:
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
208 mpeg2dec->action = mpeg2_header_end;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
209 break;
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
210 case 0xb3:
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
211 case 0xb8:
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
212 mpeg2dec->action = mpeg2_parse_header;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
213 break;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
214 default:
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
215 mpeg2dec->action = seek_chunk;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
216 return STATE_INVALID;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
217 }
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
218 return (mpeg2dec->state == STATE_SLICE) ? STATE_SLICE : STATE_INVALID;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
219 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
220
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
221 mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec)
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
222 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
223 static int (* process_header[]) (mpeg2dec_t * mpeg2dec) = {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
224 mpeg2_header_picture, mpeg2_header_extension, mpeg2_header_user_data,
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
225 mpeg2_header_sequence, NULL, NULL, NULL, NULL, mpeg2_header_gop
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
226 };
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
227 int size_buffer, size_chunk, copied;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
228
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
229 mpeg2dec->action = mpeg2_parse_header;
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
230 mpeg2dec->info.user_data = NULL; mpeg2dec->info.user_data_len = 0;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
231 while (1) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
232 size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
233 size_chunk = (mpeg2dec->chunk_buffer + BUFFER_SIZE -
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
234 mpeg2dec->chunk_ptr);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
235 if (size_buffer <= size_chunk) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
236 copied = copy_chunk (mpeg2dec, size_buffer);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
237 if (!copied) {
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
238 mpeg2dec->bytes_since_tag += size_buffer;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
239 mpeg2dec->chunk_ptr += size_buffer;
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
240 return STATE_BUFFER;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
241 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
242 } else {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
243 copied = copy_chunk (mpeg2dec, size_chunk);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
244 if (!copied) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
245 /* filled the chunk buffer without finding a start code */
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
246 mpeg2dec->bytes_since_tag += size_chunk;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
247 mpeg2dec->code = 0xb4;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
248 mpeg2dec->action = mpeg2_seek_header;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
249 return STATE_INVALID;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
250 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
251 }
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
252 mpeg2dec->bytes_since_tag += copied;
9858
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
253
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
254 if (process_header[mpeg2dec->code & 0x0b] (mpeg2dec)) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
255 mpeg2dec->code = mpeg2dec->buf_start[-1];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
256 mpeg2dec->action = mpeg2_seek_header;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
257 return STATE_INVALID;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
258 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
259
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
260 mpeg2dec->code = mpeg2dec->buf_start[-1];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
261 switch (RECEIVED (mpeg2dec->code, mpeg2dec->state)) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
262
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
263 /* state transition after a sequence header */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
264 case RECEIVED (0x00, STATE_SEQUENCE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
265 mpeg2dec->action = mpeg2_header_picture_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
266 case RECEIVED (0xb8, STATE_SEQUENCE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
267 mpeg2_header_sequence_finalize (mpeg2dec);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
268 break;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
269
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
270 /* other legal state transitions */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
271 case RECEIVED (0x00, STATE_GOP):
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
272 mpeg2_header_gop_finalize (mpeg2dec);
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
273 mpeg2dec->action = mpeg2_header_picture_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
274 break;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
275 case RECEIVED (0x01, STATE_PICTURE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
276 case RECEIVED (0x01, STATE_PICTURE_2ND):
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
277 mpeg2_header_picture_finalize (mpeg2dec, mpeg2_accels);
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
278 mpeg2dec->action = mpeg2_header_slice_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
279 break;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
280
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
281 /* legal headers within a given state */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
282 case RECEIVED (0xb2, STATE_SEQUENCE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
283 case RECEIVED (0xb2, STATE_GOP):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
284 case RECEIVED (0xb2, STATE_PICTURE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
285 case RECEIVED (0xb2, STATE_PICTURE_2ND):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
286 case RECEIVED (0xb5, STATE_SEQUENCE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
287 case RECEIVED (0xb5, STATE_PICTURE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
288 case RECEIVED (0xb5, STATE_PICTURE_2ND):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
289 mpeg2dec->chunk_ptr = mpeg2dec->chunk_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
290 continue;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
291
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
292 default:
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
293 mpeg2dec->action = mpeg2_seek_header;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
294 return STATE_INVALID;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
295 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
296
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
297 mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
298 mpeg2dec->user_data_len = 0;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
299 return mpeg2dec->state;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
300 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
301 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
302
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
303 int mpeg2_convert (mpeg2dec_t * mpeg2dec, mpeg2_convert_t convert, void * arg)
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
304 {
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
305 mpeg2_convert_init_t convert_init;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
306 int error;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
307
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
308 error = convert (MPEG2_CONVERT_SET, NULL, &(mpeg2dec->sequence), 0,
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
309 mpeg2_accels, arg, &convert_init);
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
310 if (!error) {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
311 mpeg2dec->convert = convert;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
312 mpeg2dec->convert_arg = arg;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
313 mpeg2dec->convert_id_size = convert_init.id_size;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
314 mpeg2dec->convert_stride = 0;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
315 }
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
316 return error;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
317 }
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
318
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
319 int mpeg2_stride (mpeg2dec_t * mpeg2dec, int stride)
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
320 {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
321 if (!mpeg2dec->convert) {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
322 if (stride < (int) mpeg2dec->sequence.width)
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
323 stride = mpeg2dec->sequence.width;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
324 mpeg2dec->decoder.stride_frame = stride;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
325 } else {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
326 mpeg2_convert_init_t convert_init;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
327
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
328 stride = mpeg2dec->convert (MPEG2_CONVERT_STRIDE, NULL,
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
329 &(mpeg2dec->sequence), stride,
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
330 mpeg2_accels, mpeg2dec->convert_arg,
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
331 &convert_init);
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
332 mpeg2dec->convert_id_size = convert_init.id_size;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
333 mpeg2dec->convert_stride = stride;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
334 }
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
335 return stride;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
336 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
337
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
338 void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[3], void * id)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
339 {
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
340 mpeg2_fbuf_t * fbuf;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
341
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
342 if (mpeg2dec->custom_fbuf) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
343 if (mpeg2dec->state == STATE_SEQUENCE) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
344 mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
345 mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
346 }
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
347 mpeg2_set_fbuf (mpeg2dec, (mpeg2dec->decoder.coding_type ==
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
348 PIC_FLAG_CODING_TYPE_B));
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
349 fbuf = mpeg2dec->fbuf[0];
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
350 } else {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
351 fbuf = &(mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index].fbuf);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
352 mpeg2dec->alloc_index_user = ++mpeg2dec->alloc_index;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
353 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
354 fbuf->buf[0] = buf[0];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
355 fbuf->buf[1] = buf[1];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
356 fbuf->buf[2] = buf[2];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
357 fbuf->id = id;
9858
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
358 // HACK! FIXME! At first I frame, copy pointers to prediction frame too!
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
359 if (mpeg2dec->custom_fbuf && !mpeg2dec->fbuf[1]->buf[0]){
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
360 mpeg2dec->fbuf[1]->buf[0]=buf[0];
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
361 mpeg2dec->fbuf[1]->buf[1]=buf[1];
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
362 mpeg2dec->fbuf[1]->buf[2]=buf[2];
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
363 mpeg2dec->fbuf[1]->id=NULL;
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
364 }
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
365 // printf("libmpeg2: FBUF 0:%p 1:%p 2:%p\n",
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
366 // mpeg2dec->fbuf[0]->buf[0],mpeg2dec->fbuf[1]->buf[0],mpeg2dec->fbuf[2]->buf[0]);
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
367 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
368
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
369 void mpeg2_custom_fbuf (mpeg2dec_t * mpeg2dec, int custom_fbuf)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
370 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
371 mpeg2dec->custom_fbuf = custom_fbuf;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
372 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
373
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
374 void mpeg2_skip (mpeg2dec_t * mpeg2dec, int skip)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
375 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
376 mpeg2dec->first_decode_slice = 1;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
377 mpeg2dec->nb_decode_slices = skip ? 0 : (0xb0 - 1);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
378 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
379
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
380 void mpeg2_slice_region (mpeg2dec_t * mpeg2dec, int start, int end)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
381 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
382 start = (start < 1) ? 1 : (start > 0xb0) ? 0xb0 : start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
383 end = (end < start) ? start : (end > 0xb0) ? 0xb0 : end;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
384 mpeg2dec->first_decode_slice = start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
385 mpeg2dec->nb_decode_slices = end - start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
386 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
387
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
388 void mpeg2_tag_picture (mpeg2dec_t * mpeg2dec, uint32_t tag, uint32_t tag2)
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
389 {
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
390 mpeg2dec->tag_previous = mpeg2dec->tag_current;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
391 mpeg2dec->tag2_previous = mpeg2dec->tag2_current;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
392 mpeg2dec->tag_current = tag;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
393 mpeg2dec->tag2_current = tag2;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
394 mpeg2dec->num_tags++;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
395 mpeg2dec->bytes_since_tag = 0;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
396 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
397
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
398 uint32_t mpeg2_accel (uint32_t accel)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
399 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
400 if (!mpeg2_accels) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
401 if (accel & MPEG2_ACCEL_DETECT)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
402 accel |= mpeg2_detect_accel ();
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
403 mpeg2_accels = accel |= MPEG2_ACCEL_DETECT;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
404 mpeg2_cpu_state_init (accel);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
405 mpeg2_idct_init (accel);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
406 mpeg2_mc_init (accel);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
407 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
408 return mpeg2_accels & ~MPEG2_ACCEL_DETECT;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
409 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
410
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
411 void mpeg2_reset (mpeg2dec_t * mpeg2dec, int full_reset)
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
412 {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
413 mpeg2dec->buf_start = mpeg2dec->buf_end = NULL;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
414 mpeg2dec->num_tags = 0;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
415 mpeg2dec->shift = 0xffffff00;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
416 mpeg2dec->code = 0xb4;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
417 mpeg2dec->action = mpeg2_seek_header;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
418 mpeg2dec->state = STATE_INVALID;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
419 mpeg2dec->first = 1;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
420
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
421 mpeg2_reset_info(&(mpeg2dec->info));
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
422 mpeg2dec->info.gop = NULL;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
423 mpeg2dec->info.user_data = NULL;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
424 mpeg2dec->info.user_data_len = 0;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
425 if (full_reset) {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
426 mpeg2dec->info.sequence = NULL;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
427 mpeg2_header_state_init (mpeg2dec);
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
428 }
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
429
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
430 }
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
431
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
432 mpeg2dec_t * mpeg2_init (void)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
433 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
434 mpeg2dec_t * mpeg2dec;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
435
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
436 mpeg2_accel (MPEG2_ACCEL_DETECT);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
437
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
438 mpeg2dec = (mpeg2dec_t *) mpeg2_malloc (sizeof (mpeg2dec_t),
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
439 MPEG2_ALLOC_MPEG2DEC);
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
440 if (mpeg2dec == NULL)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
441 return NULL;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
442
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
443 memset (mpeg2dec->decoder.DCTblock, 0, 64 * sizeof (int16_t));
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
444 memset (mpeg2dec->quantizer_matrix, 0, 4 * 64 * sizeof (uint8_t));
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
445
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
446 mpeg2dec->chunk_buffer = (uint8_t *) mpeg2_malloc (BUFFER_SIZE + 4,
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
447 MPEG2_ALLOC_CHUNK);
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
448
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
449 mpeg2dec->sequence.width = (unsigned)-1;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
450 mpeg2_reset (mpeg2dec, 1);
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
451
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
452 return mpeg2dec;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
453 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
454
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
455 void mpeg2_close (mpeg2dec_t * mpeg2dec)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
456 {
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 9858
diff changeset
457 mpeg2_header_state_init (mpeg2dec);
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
458 mpeg2_free (mpeg2dec->chunk_buffer);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
459 mpeg2_free (mpeg2dec);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
460 }