annotate libmpeg2/decode.c @ 11301:a8dfeb7180ff

optimize
author michael
date Tue, 28 Oct 2003 10:45:55 +0000
parents 9af61fc7955c
children d0a8810e155c
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
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
3 * Copyright (C) 2000-2002 Michel Lespinasse <walken@zoy.org>
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
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
22 */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
23
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
24 #include "config.h"
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
25
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
26 #include <string.h> /* memcmp/memset, try to remove */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
27 #include <stdlib.h>
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
28 #include <inttypes.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 "mpeg2.h"
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
31 #include "mpeg2_internal.h"
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
32 #include "convert.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 static int mpeg2_accels = 0;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
35
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
36 #define BUFFER_SIZE (1194 * 1024)
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 const mpeg2_info_t * mpeg2_info (mpeg2dec_t * mpeg2dec)
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 return &(mpeg2dec->info);
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
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
43 static inline int skip_chunk (mpeg2dec_t * mpeg2dec, int bytes)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
44 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
45 uint8_t * current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
46 uint32_t shift;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
47 uint8_t * chunk_ptr;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
48 uint8_t * limit;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
49 uint8_t byte;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
50
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
51 if (!bytes)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
52 return 0;
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 current = mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
55 shift = mpeg2dec->shift;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
56 chunk_ptr = mpeg2dec->chunk_ptr;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
57 limit = current + bytes;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
58
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
59 do {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
60 byte = *current++;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
61 if (shift == 0x00000100) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
62 int skipped;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
63
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
64 mpeg2dec->shift = 0xffffff00;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
65 skipped = current - mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
66 mpeg2dec->buf_start = current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
67 return skipped;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
68 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
69 shift = (shift | byte) << 8;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
70 } while (current < limit);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
71
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
72 mpeg2dec->shift = shift;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
73 mpeg2dec->buf_start = current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
74 return 0;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
75 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
76
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
77 static inline int copy_chunk (mpeg2dec_t * mpeg2dec, int bytes)
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 uint8_t * current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
80 uint32_t shift;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
81 uint8_t * chunk_ptr;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
82 uint8_t * limit;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
83 uint8_t byte;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
84
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
85 if (!bytes)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
86 return 0;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
87
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
88 current = mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
89 shift = mpeg2dec->shift;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
90 chunk_ptr = mpeg2dec->chunk_ptr;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
91 limit = current + bytes;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
92
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
93 do {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
94 byte = *current++;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
95 if (shift == 0x00000100) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
96 int copied;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
97
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
98 mpeg2dec->shift = 0xffffff00;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
99 mpeg2dec->chunk_ptr = chunk_ptr + 1;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
100 copied = current - mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
101 mpeg2dec->buf_start = current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
102 return copied;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
103 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
104 shift = (shift | byte) << 8;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
105 *chunk_ptr++ = byte;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
106 } while (current < limit);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
107
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
108 mpeg2dec->shift = shift;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
109 mpeg2dec->buf_start = current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
110 return 0;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
111 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
112
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
113 void mpeg2_buffer (mpeg2dec_t * mpeg2dec, uint8_t * start, uint8_t * end)
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 mpeg2dec->buf_start = start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
116 mpeg2dec->buf_end = end;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
117 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
118
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
119 static inline int seek_chunk (mpeg2dec_t * mpeg2dec)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
120 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
121 int size, skipped;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
122
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
123 size = mpeg2dec->buf_end - mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
124 skipped = skip_chunk (mpeg2dec, size);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
125 if (!skipped) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
126 mpeg2dec->bytes_since_pts += size;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
127 return -1;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
128 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
129 mpeg2dec->bytes_since_pts += skipped;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
130 mpeg2dec->code = mpeg2dec->buf_start[-1];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
131 return 0;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
132 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
133
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
134 int mpeg2_seek_header (mpeg2dec_t * mpeg2dec)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
135 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
136 while (mpeg2dec->code != 0xb3 &&
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
137 ((mpeg2dec->code != 0xb7 && mpeg2dec->code != 0xb8 &&
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
138 mpeg2dec->code) || mpeg2dec->sequence.width == -1))
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
139 if (seek_chunk (mpeg2dec))
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
140 return -1;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
141 mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
142 return mpeg2_parse_header (mpeg2dec);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
143 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
144
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
145 int mpeg2_seek_sequence (mpeg2dec_t * mpeg2dec)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
146 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
147 mpeg2dec->sequence.width = -1;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
148 return mpeg2_seek_header (mpeg2dec);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
149 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
150
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
151 #define RECEIVED(code,state) (((state) << 8) + (code))
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 int mpeg2_parse (mpeg2dec_t * mpeg2dec)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
154 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
155 int size_buffer, size_chunk, copied;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
156
9858
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
157 if(mpeg2dec->code==0xff){
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
158 // FIXME: we need to resync stream (esp. mpeg2dec-->code) as we
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
159 // left parser at 0x1FF last time at the end of prev. chunk.
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
160 // Why? mpeg2dec->action is set to mpeg2_header_picture_start, but
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
161 // it will call mpeg2_parse_header() too...
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
162 //
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
163 // following code copied from mpeg2_seek_header():
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
164 while (mpeg2dec->code != 0xb3 &&
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
165 ((mpeg2dec->code != 0xb7 && mpeg2dec->code != 0xb8 &&
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
166 mpeg2dec->code) || mpeg2dec->sequence.width == -1))
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
167 if (seek_chunk (mpeg2dec))
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
168 return -1;
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
169 mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
170 }
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
171
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
172 if (mpeg2dec->action) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
173 int state;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
174
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
175 state = mpeg2dec->action (mpeg2dec);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
176 if (state)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
177 return state;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
178 }
9858
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
179
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
180 while (1) {
9858
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
181 //printf("code=0x%X \n",mpeg2dec->code);
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
182 while ((unsigned) (mpeg2dec->code - mpeg2dec->first_decode_slice) <
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
183 mpeg2dec->nb_decode_slices) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
184 size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
185 size_chunk = (mpeg2dec->chunk_buffer + BUFFER_SIZE -
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
186 mpeg2dec->chunk_ptr);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
187 if (size_buffer <= size_chunk) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
188 copied = copy_chunk (mpeg2dec, size_buffer);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
189 if (!copied) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
190 mpeg2dec->bytes_since_pts += size_buffer;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
191 mpeg2dec->chunk_ptr += size_buffer;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
192 return -1;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
193 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
194 } else {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
195 copied = copy_chunk (mpeg2dec, size_chunk);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
196 if (!copied) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
197 /* filled the chunk buffer without finding a start code */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
198 mpeg2dec->bytes_since_pts += size_chunk;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
199 mpeg2dec->action = seek_chunk;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
200 return STATE_INVALID;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
201 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
202 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
203 mpeg2dec->bytes_since_pts += copied;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
204
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
205 mpeg2_slice (&(mpeg2dec->decoder), mpeg2dec->code,
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
206 mpeg2dec->chunk_start);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
207 mpeg2dec->code = mpeg2dec->buf_start[-1];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
208 mpeg2dec->chunk_ptr = mpeg2dec->chunk_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
209 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
210 if ((unsigned) (mpeg2dec->code - 1) >= 0xb0 - 1)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
211 break;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
212 if (seek_chunk (mpeg2dec))
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
213 return -1;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
214 }
9858
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
215
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
216 //printf("next_code=0x%X state=%d \n",mpeg2dec->code,mpeg2dec->state);
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
217
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
218 if(mpeg2dec->code==0xff){
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
219 mpeg2dec->action = mpeg2_header_picture_start; //mpeg2_seek_header;
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
220 return mpeg2dec->state;
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
221 }
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 switch (RECEIVED (mpeg2dec->code, mpeg2dec->state)) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
224 case RECEIVED (0x00, STATE_SLICE_1ST):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
225 case RECEIVED (0x00, STATE_SLICE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
226 mpeg2dec->action = mpeg2_header_picture_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
227 break;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
228 case RECEIVED (0xb7, STATE_SLICE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
229 mpeg2dec->action = mpeg2_header_end;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
230 break;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
231 case RECEIVED (0xb3, STATE_SLICE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
232 case RECEIVED (0xb8, STATE_SLICE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
233 mpeg2dec->action = mpeg2_parse_header;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
234 break;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
235 default:
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
236 mpeg2dec->action = mpeg2_seek_header;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
237 return STATE_INVALID;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
238 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
239 return mpeg2dec->state;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
240 }
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 int mpeg2_parse_header (mpeg2dec_t * mpeg2dec)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
243 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
244 static int (* process_header[]) (mpeg2dec_t * mpeg2dec) = {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
245 mpeg2_header_picture, mpeg2_header_extension, mpeg2_header_user_data,
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
246 mpeg2_header_sequence, NULL, NULL, NULL, NULL, mpeg2_header_gop
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
247 };
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
248 int size_buffer, size_chunk, copied;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
249
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
250 mpeg2dec->action = mpeg2_parse_header;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
251 while (1) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
252 size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
253 size_chunk = (mpeg2dec->chunk_buffer + BUFFER_SIZE -
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
254 mpeg2dec->chunk_ptr);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
255 if (size_buffer <= size_chunk) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
256 copied = copy_chunk (mpeg2dec, size_buffer);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
257 if (!copied) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
258 mpeg2dec->bytes_since_pts += size_buffer;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
259 mpeg2dec->chunk_ptr += size_buffer;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
260 return -1;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
261 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
262 } else {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
263 copied = copy_chunk (mpeg2dec, size_chunk);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
264 if (!copied) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
265 /* filled the chunk buffer without finding a start code */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
266 mpeg2dec->bytes_since_pts += size_chunk;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
267 mpeg2dec->code = 0xb4;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
268 mpeg2dec->action = mpeg2_seek_header;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
269 return STATE_INVALID;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
270 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
271 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
272 mpeg2dec->bytes_since_pts += copied;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
273
9858
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
274 //printf("header_code=0x%X state=%d \n",mpeg2dec->code,mpeg2dec->state);
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
275
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
276 // if(!mpeg2dec->code && mpeg2dec->state==7)
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
277
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
278
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
279 if (process_header[mpeg2dec->code & 0x0b] (mpeg2dec)) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
280 mpeg2dec->code = mpeg2dec->buf_start[-1];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
281 mpeg2dec->action = mpeg2_seek_header;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
282 return STATE_INVALID;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
283 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
284
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
285 mpeg2dec->code = mpeg2dec->buf_start[-1];
9858
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
286
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
287 //printf("next_header_code=0x%X state=%d \n",mpeg2dec->code,mpeg2dec->state);
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
288
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
289 switch (RECEIVED (mpeg2dec->code, mpeg2dec->state)) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
290
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
291 /* state transition after a sequence header */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
292 case RECEIVED (0x00, STATE_SEQUENCE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
293 mpeg2dec->action = mpeg2_header_picture_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
294 case RECEIVED (0xb8, STATE_SEQUENCE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
295 mpeg2_header_sequence_finalize (mpeg2dec);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
296 break;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
297
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
298 /* other legal state transitions */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
299 case RECEIVED (0x00, STATE_GOP):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
300 mpeg2dec->action = mpeg2_header_picture_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
301 break;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
302 case RECEIVED (0x01, STATE_PICTURE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
303 case RECEIVED (0x01, STATE_PICTURE_2ND):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
304 mpeg2dec->action = mpeg2_header_slice_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
305 break;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
306
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
307 /* legal headers within a given state */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
308 case RECEIVED (0xb2, STATE_SEQUENCE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
309 case RECEIVED (0xb2, STATE_GOP):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
310 case RECEIVED (0xb2, STATE_PICTURE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
311 case RECEIVED (0xb2, STATE_PICTURE_2ND):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
312 case RECEIVED (0xb5, STATE_SEQUENCE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
313 case RECEIVED (0xb5, STATE_PICTURE):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
314 case RECEIVED (0xb5, STATE_PICTURE_2ND):
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
315 mpeg2dec->chunk_ptr = mpeg2dec->chunk_start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
316 continue;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
317
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
318 default:
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
319 mpeg2dec->action = mpeg2_seek_header;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
320 return STATE_INVALID;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
321 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
322
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
323 mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
324 return mpeg2dec->state;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
325 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
326 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
327
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
328 void mpeg2_convert (mpeg2dec_t * mpeg2dec,
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
329 void (* convert) (int, int, uint32_t, void *,
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
330 struct convert_init_s *), void * arg)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
331 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
332 convert_init_t convert_init;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
333 int size;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
334
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
335 convert_init.id = NULL;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
336 convert (mpeg2dec->decoder.width, mpeg2dec->decoder.height,
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
337 mpeg2_accels, arg, &convert_init);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
338 if (convert_init.id_size) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
339 convert_init.id = mpeg2dec->convert_id =
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
340 mpeg2_malloc (convert_init.id_size, ALLOC_CONVERT_ID);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
341 convert (mpeg2dec->decoder.width, mpeg2dec->decoder.height,
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
342 mpeg2_accels, arg, &convert_init);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
343 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
344 mpeg2dec->convert_size[0] = size = convert_init.buf_size[0];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
345 mpeg2dec->convert_size[1] = size += convert_init.buf_size[1];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
346 mpeg2dec->convert_size[2] = size += convert_init.buf_size[2];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
347 mpeg2dec->convert_start = convert_init.start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
348 mpeg2dec->convert_copy = convert_init.copy;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
349
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
350 size = mpeg2dec->decoder.width * mpeg2dec->decoder.height >> 2;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
351 mpeg2dec->yuv_buf[0][0] = (uint8_t *) mpeg2_malloc (6 * size, ALLOC_YUV);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
352 mpeg2dec->yuv_buf[0][1] = mpeg2dec->yuv_buf[0][0] + 4 * size;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
353 mpeg2dec->yuv_buf[0][2] = mpeg2dec->yuv_buf[0][0] + 5 * size;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
354 mpeg2dec->yuv_buf[1][0] = (uint8_t *) mpeg2_malloc (6 * size, ALLOC_YUV);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
355 mpeg2dec->yuv_buf[1][1] = mpeg2dec->yuv_buf[1][0] + 4 * size;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
356 mpeg2dec->yuv_buf[1][2] = mpeg2dec->yuv_buf[1][0] + 5 * size;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
357 size = mpeg2dec->decoder.width * 8;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
358 mpeg2dec->yuv_buf[2][0] = (uint8_t *) mpeg2_malloc (6 * size, ALLOC_YUV);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
359 mpeg2dec->yuv_buf[2][1] = mpeg2dec->yuv_buf[2][0] + 4 * size;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
360 mpeg2dec->yuv_buf[2][2] = mpeg2dec->yuv_buf[2][0] + 5 * size;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
361 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
362
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
363 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
364 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
365 fbuf_t * fbuf;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
366
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
367 if (mpeg2dec->custom_fbuf) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
368 mpeg2_set_fbuf (mpeg2dec, mpeg2dec->decoder.coding_type);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
369 fbuf = mpeg2dec->fbuf[0];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
370 if (mpeg2dec->state == STATE_SEQUENCE) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
371 mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
372 mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0];
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 } else {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
375 fbuf = &(mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index].fbuf);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
376 mpeg2dec->alloc_index_user = ++mpeg2dec->alloc_index;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
377 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
378 fbuf->buf[0] = buf[0];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
379 fbuf->buf[1] = buf[1];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
380 fbuf->buf[2] = buf[2];
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
381 fbuf->id = id;
9858
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
382 // 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
383 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
384 mpeg2dec->fbuf[1]->buf[0]=buf[0];
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
385 mpeg2dec->fbuf[1]->buf[1]=buf[1];
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
386 mpeg2dec->fbuf[1]->buf[2]=buf[2];
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
387 mpeg2dec->fbuf[1]->id=NULL;
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
388 }
9af61fc7955c changed input and output buffer handling to be mplayer-compatible...
arpi
parents: 9857
diff changeset
389 // 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
390 // 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
391 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
392
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
393 void mpeg2_custom_fbuf (mpeg2dec_t * mpeg2dec, int custom_fbuf)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
394 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
395 mpeg2dec->custom_fbuf = custom_fbuf;
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 void mpeg2_skip (mpeg2dec_t * mpeg2dec, int skip)
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 mpeg2dec->first_decode_slice = 1;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
401 mpeg2dec->nb_decode_slices = skip ? 0 : (0xb0 - 1);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
402 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
403
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
404 void mpeg2_slice_region (mpeg2dec_t * mpeg2dec, int start, int end)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
405 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
406 start = (start < 1) ? 1 : (start > 0xb0) ? 0xb0 : start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
407 end = (end < start) ? start : (end > 0xb0) ? 0xb0 : end;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
408 mpeg2dec->first_decode_slice = start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
409 mpeg2dec->nb_decode_slices = end - start;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
410 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
411
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
412 void mpeg2_pts (mpeg2dec_t * mpeg2dec, uint32_t pts)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
413 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
414 mpeg2dec->pts_previous = mpeg2dec->pts_current;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
415 mpeg2dec->pts_current = pts;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
416 mpeg2dec->num_pts++;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
417 mpeg2dec->bytes_since_pts = 0;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
418 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
419
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
420 uint32_t mpeg2_accel (uint32_t accel)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
421 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
422 if (!mpeg2_accels) {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
423 if (accel & MPEG2_ACCEL_DETECT)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
424 accel |= mpeg2_detect_accel ();
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
425 mpeg2_accels = accel |= MPEG2_ACCEL_DETECT;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
426 mpeg2_cpu_state_init (accel);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
427 mpeg2_idct_init (accel);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
428 mpeg2_mc_init (accel);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
429 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
430 return mpeg2_accels & ~MPEG2_ACCEL_DETECT;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
431 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
432
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
433 mpeg2dec_t * mpeg2_init (void)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
434 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
435 mpeg2dec_t * mpeg2dec;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
436
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
437 mpeg2_accel (MPEG2_ACCEL_DETECT);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
438
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
439 mpeg2dec = (mpeg2dec_t *) mpeg2_malloc (sizeof (mpeg2dec_t),
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
440 ALLOC_MPEG2DEC);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
441 if (mpeg2dec == NULL)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
442 return NULL;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
443
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
444 memset (mpeg2dec, 0, sizeof (mpeg2dec_t));
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,
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
447 ALLOC_CHUNK);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
448
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
449 mpeg2dec->shift = 0xffffff00;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
450 mpeg2dec->action = mpeg2_seek_sequence;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
451 mpeg2dec->code = 0xb4;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
452 mpeg2dec->first_decode_slice = 1;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
453 mpeg2dec->nb_decode_slices = 0xb0 - 1;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
454 mpeg2dec->convert_id = NULL;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
455
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
456 /* initialize substructures */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
457 mpeg2_header_state_init (mpeg2dec);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
458
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
459 return mpeg2dec;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
460 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
461
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
462 void mpeg2_close (mpeg2dec_t * mpeg2dec)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
463 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
464 int i;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
465
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
466 /* static uint8_t finalizer[] = {0,0,1,0xb4}; */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
467 /* mpeg2_decode_data (mpeg2dec, finalizer, finalizer+4); */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
468
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
469 mpeg2_free (mpeg2dec->chunk_buffer);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
470 if (!mpeg2dec->custom_fbuf)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
471 for (i = mpeg2dec->alloc_index_user; i < mpeg2dec->alloc_index; i++)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
472 mpeg2_free (mpeg2dec->fbuf_alloc[i].fbuf.buf[0]);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
473 if (mpeg2dec->convert_start)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
474 for (i = 0; i < 3; i++)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
475 mpeg2_free (mpeg2dec->yuv_buf[i][0]);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
476 if (mpeg2dec->convert_id)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
477 mpeg2_free (mpeg2dec->convert_id);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
478 mpeg2_free (mpeg2dec);
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
479 }