Diffstat (limited to 'core/multimedia/opieplayer/libmpeg3/video/slice.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/multimedia/opieplayer/libmpeg3/video/slice.h | 194 |
1 files changed, 194 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmpeg3/video/slice.h b/core/multimedia/opieplayer/libmpeg3/video/slice.h new file mode 100644 index 0000000..e36ffef --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/slice.h | |||
@@ -0,0 +1,194 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | #ifndef SLICE_H | ||
21 | #define SLICE_H | ||
22 | |||
23 | #ifndef _WIN32 | ||
24 | #include <pthread.h> | ||
25 | #endif | ||
26 | |||
27 | /* Array of these feeds the slice decoders */ | ||
28 | typedef struct | ||
29 | { | ||
30 | unsigned char *data; /* Buffer for holding the slice data */ | ||
31 | int buffer_size; /* Size of buffer */ | ||
32 | int buffer_allocation; /* Space allocated for buffer */ | ||
33 | int current_position; /* Position in buffer */ | ||
34 | unsigned MPEG3_INT32 bits; | ||
35 | int bits_size; | ||
36 | pthread_mutex_t completion_lock; /* Lock slice until completion */ | ||
37 | int done; /* Signal for slice decoder to skip */ | ||
38 | } mpeg3_slice_buffer_t; | ||
39 | |||
40 | /* Each slice decoder */ | ||
41 | typedef struct | ||
42 | { | ||
43 | struct mpeg3video_rec *video; | ||
44 | mpeg3_slice_buffer_t *slice_buffer; | ||
45 | |||
46 | int thread_number; /* Number of this thread */ | ||
47 | int current_buffer; /* Buffer this slice decoder is on */ | ||
48 | int buffer_step; /* Number of buffers to skip */ | ||
49 | int last_buffer; /* Last buffer this decoder should process */ | ||
50 | int fault; | ||
51 | int done; | ||
52 | int quant_scale; | ||
53 | int pri_brk; /* slice/macroblock */ | ||
54 | short block[12][64]; | ||
55 | int sparse[12]; | ||
56 | pthread_t tid; /* ID of thread */ | ||
57 | pthread_mutex_t input_lock, output_lock; | ||
58 | } mpeg3_slice_t; | ||
59 | |||
60 | #define mpeg3slice_fillbits(buffer, nbits) \ | ||
61 | while(((mpeg3_slice_buffer_t*)(buffer))->bits_size < (nbits)) \ | ||
62 | { \ | ||
63 | if(((mpeg3_slice_buffer_t*)(buffer))->current_position < ((mpeg3_slice_buffer_t*)(buffer))->buffer_size) \ | ||
64 | { \ | ||
65 | ((mpeg3_slice_buffer_t*)(buffer))->bits <<= 8; \ | ||
66 | ((mpeg3_slice_buffer_t*)(buffer))->bits |= ((mpeg3_slice_buffer_t*)(buffer))->data[((mpeg3_slice_buffer_t*)(buffer))->current_position++]; \ | ||
67 | } \ | ||
68 | ((mpeg3_slice_buffer_t*)(buffer))->bits_size += 8; \ | ||
69 | } | ||
70 | |||
71 | #define mpeg3slice_flushbits(buffer, nbits) \ | ||
72 | { \ | ||
73 | mpeg3slice_fillbits((buffer), (nbits)); \ | ||
74 | ((mpeg3_slice_buffer_t*)(buffer))->bits_size -= (nbits); \ | ||
75 | } | ||
76 | |||
77 | #define mpeg3slice_flushbit(buffer) \ | ||
78 | { \ | ||
79 | if(((mpeg3_slice_buffer_t*)(buffer))->bits_size) \ | ||
80 | ((mpeg3_slice_buffer_t*)(buffer))->bits_size--; \ | ||
81 | else \ | ||
82 | if(((mpeg3_slice_buffer_t*)(buffer))->current_position < ((mpeg3_slice_buffer_t*)(buffer))->buffer_size) \ | ||
83 | { \ | ||
84 | ((mpeg3_slice_buffer_t*)(buffer))->bits = \ | ||
85 | ((mpeg3_slice_buffer_t*)(buffer))->data[((mpeg3_slice_buffer_t*)(buffer))->current_position++]; \ | ||
86 | ((mpeg3_slice_buffer_t*)(buffer))->bits_size = 7; \ | ||
87 | } \ | ||
88 | } | ||
89 | |||
90 | extern inline unsigned int mpeg3slice_getbit(mpeg3_slice_buffer_t *buffer) | ||
91 | { | ||
92 | if(buffer->bits_size) | ||
93 | return (buffer->bits >> (--buffer->bits_size)) & 0x1; | ||
94 | else | ||
95 | if(buffer->current_position < buffer->buffer_size) | ||
96 | { | ||
97 | buffer->bits = buffer->data[buffer->current_position++]; | ||
98 | buffer->bits_size = 7; | ||
99 | return (buffer->bits >> 7) & 0x1; | ||
100 | } | ||
101 | return 0; // WWA - stop warn | ||
102 | } | ||
103 | |||
104 | extern inline unsigned int mpeg3slice_getbits2(mpeg3_slice_buffer_t *buffer) | ||
105 | { | ||
106 | if(buffer->bits_size >= 2) | ||
107 | return (buffer->bits >> (buffer->bits_size -= 2)) & 0x3; | ||
108 | else | ||
109 | if(buffer->current_position < buffer->buffer_size) | ||
110 | { | ||
111 | buffer->bits <<= 8; | ||
112 | buffer->bits |= buffer->data[buffer->current_position++]; | ||
113 | buffer->bits_size += 6; | ||
114 | return (buffer->bits >> buffer->bits_size) & 0x3; | ||
115 | } | ||
116 | return 0; // WWA - stop warn | ||
117 | } | ||
118 | |||
119 | extern inline unsigned int mpeg3slice_getbyte(mpeg3_slice_buffer_t *buffer) | ||
120 | { | ||
121 | if(buffer->bits_size >= 8) | ||
122 | return (buffer->bits >> (buffer->bits_size -= 8)) & 0xff; | ||
123 | else | ||
124 | if(buffer->current_position < buffer->buffer_size) | ||
125 | { | ||
126 | buffer->bits <<= 8; | ||
127 | buffer->bits |= buffer->data[buffer->current_position++]; | ||
128 | return (buffer->bits >> buffer->bits_size) & 0xff; | ||
129 | } | ||
130 | return 0; // WWA - stop warn | ||
131 | } | ||
132 | |||
133 | |||
134 | extern inline unsigned int mpeg3slice_getbits(mpeg3_slice_buffer_t *slice_buffer, int bits) | ||
135 | { | ||
136 | if(bits == 1) return mpeg3slice_getbit(slice_buffer); | ||
137 | mpeg3slice_fillbits(slice_buffer, bits); | ||
138 | return (slice_buffer->bits >> (slice_buffer->bits_size -= bits)) & (0xffffffff >> (32 - bits)); | ||
139 | } | ||
140 | |||
141 | extern inline unsigned int mpeg3slice_showbits16(mpeg3_slice_buffer_t *buffer) | ||
142 | { | ||
143 | if(buffer->bits_size >= 16) | ||
144 | return (buffer->bits >> (buffer->bits_size - 16)) & 0xffff; | ||
145 | else | ||
146 | if(buffer->current_position < buffer->buffer_size) | ||
147 | { | ||
148 | buffer->bits <<= 16; | ||
149 | buffer->bits_size += 16; | ||
150 | buffer->bits |= (unsigned int)buffer->data[buffer->current_position++] << 8; | ||
151 | buffer->bits |= buffer->data[buffer->current_position++]; | ||
152 | return (buffer->bits >> (buffer->bits_size - 16)) & 0xffff; | ||
153 | } | ||
154 | return 0; // WWA - stop warn | ||
155 | } | ||
156 | |||
157 | extern inline unsigned int mpeg3slice_showbits9(mpeg3_slice_buffer_t *buffer) | ||
158 | { | ||
159 | if(buffer->bits_size >= 9) | ||
160 | return (buffer->bits >> (buffer->bits_size - 9)) & 0x1ff; | ||
161 | else | ||
162 | if(buffer->current_position < buffer->buffer_size) | ||
163 | { | ||
164 | buffer->bits <<= 16; | ||
165 | buffer->bits_size += 16; | ||
166 | buffer->bits |= (unsigned int)buffer->data[buffer->current_position++] << 8; | ||
167 | buffer->bits |= buffer->data[buffer->current_position++]; | ||
168 | return (buffer->bits >> (buffer->bits_size - 9)) & 0x1ff; | ||
169 | } | ||
170 | return 0; // WWA - stop warn | ||
171 | } | ||
172 | |||
173 | extern inline unsigned int mpeg3slice_showbits5(mpeg3_slice_buffer_t *buffer) | ||
174 | { | ||
175 | if(buffer->bits_size >= 5) | ||
176 | return (buffer->bits >> (buffer->bits_size - 5)) & 0x1f; | ||
177 | else | ||
178 | if(buffer->current_position < buffer->buffer_size) | ||
179 | { | ||
180 | buffer->bits <<= 8; | ||
181 | buffer->bits_size += 8; | ||
182 | buffer->bits |= buffer->data[buffer->current_position++]; | ||
183 | return (buffer->bits >> (buffer->bits_size - 5)) & 0x1f; | ||
184 | } | ||
185 | return 0; // WWA - stop warn | ||
186 | } | ||
187 | |||
188 | extern inline unsigned int mpeg3slice_showbits(mpeg3_slice_buffer_t *slice_buffer, int bits) | ||
189 | { | ||
190 | mpeg3slice_fillbits(slice_buffer, bits); | ||
191 | return (slice_buffer->bits >> (slice_buffer->bits_size - bits)) & (0xffffffff >> (32 - bits)); | ||
192 | } | ||
193 | |||
194 | #endif | ||