1 /*
2 * MSMPEG4 backend for encoder and decoder
3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 /**
26 * @file
27 * MSMPEG4 backend for encoder and decoder
28 */
29
30 #include "config.h"
31
33 #if ARCH_X86
35 #endif
36
44
45 /*
46 * You can also call this codec: MPEG-4 with a twist!
47 *
48 * TODO:
49 * - (encoding) select best mv table (two choices)
50 * - (encoding) select best vlc/dc table
51 */
52
53 /* This table is practically identical to the one from H.263
54 * except that it is inverted. */
56 {
58 int uni_code, uni_len;
60 /* find number of bits */
63 while (v) {
64 v >>= 1;
66 }
67
70 else
72
73 /* luminance H.263 */
76 uni_code ^= (1 << uni_len) - 1; //M$ does not like compatibility
77
79 uni_code <<=
size; uni_code |= l;
82 uni_code <<= 1; uni_code |= 1;
83 uni_len++;
84 }
85 }
88
89 /* chrominance H.263 */
92 uni_code ^= (1 << uni_len) - 1; //M$ does not like compatibility
93
95 uni_code <<=
size; uni_code |= l;
98 uni_code <<= 1; uni_code |= 1;
99 uni_len++;
100 }
101 }
104 }
105 }
106
108 {
110
113
115 }
116
118 {
120
121 switch(
s->msmpeg4_version){
122 case MSMP4_V1:
123 case MSMP4_V2:
124 // Correct *_dc_scale_tables (ff_mpeg1_dc_scale_table) is the default
125 break;
126 case MSMP4_V3:
127 if(
s->workaround_bugs){
130 } else{
133 }
134 break;
135 case MSMP4_WMV1:
136 case MSMP4_WMV2:
139 break;
140 }
141
142 if (
s->msmpeg4_version >= MSMP4_WMV1) {
146 s->idsp.idct_permutation);
148 s->idsp.idct_permutation);
149 }
150 //Note the default tables are set in common_init in mpegvideo.c
151
153 }
154
155 /* predict coded block */
157 {
159
160 xy =
s->block_index[n];
162
163 /* B C
164 * A X
165 */
166 a =
s->coded_block[xy - 1 ];
167 b =
s->coded_block[xy - 1 -
wrap];
168 c =
s->coded_block[xy -
wrap];
169
172 } else {
174 }
175
176 /* store value */
177 *coded_block_ptr = &
s->coded_block[xy];
178
180 }
181
183 {
184 int y;
185 int sum=0;
186 for(y=0; y<block_size; y++){
187 int x;
188 for(x=0; x<block_size; x++){
190 }
191 }
193 }
194
195 /* dir = 0: left, dir = 1: top prediction */
197 int16_t **dc_val_ptr, int *dir_ptr)
198 {
200 int16_t *dc_val;
201
202 /* find prediction */
203 if (n < 4) {
205 } else {
207 }
208
209 wrap =
s->block_wrap[n];
210 dc_val=
s->dc_val[0] +
s->block_index[n];
211
212 /* B C
213 * A X
214 */
216 b = dc_val[ - 1 -
wrap];
218
219 if (
s->first_slice_line && !(n & 2) &&
s->msmpeg4_version < MSMP4_WMV1)
221
222 /* XXX: the following solution consumes divisions, but it does not
223 necessitate to modify mpegvideo.c. The problem comes from the
224 fact they decided to store the quantized DC (which would lead
225 to problems if Q could vary !) */
226 #if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE
228 "movl %3, %%eax \n\t"
229 "shrl 1,ドル %%eax \n\t"
230 "addl %%eax, %2 \n\t"
231 "addl %%eax, %1 \n\t"
232 "addl %0, %%eax \n\t"
233 "imull %4 \n\t"
234 "movl %%edx, %0 \n\t"
235 "movl %1, %%eax \n\t"
236 "imull %4 \n\t"
237 "movl %%edx, %1 \n\t"
238 "movl %2, %%eax \n\t"
239 "imull %4 \n\t"
240 "movl %%edx, %2 \n\t"
241 :
"+b" (
a),
"+c" (
b),
"+D" (
c)
243 : "%eax", "%edx"
244 );
245 #else
246 /* Divisions are costly everywhere; optimize the most common case. */
248 a = (
a + (8 >> 1)) / 8;
249 b = (
b + (8 >> 1)) / 8;
250 c = (
c + (8 >> 1)) / 8;
251 } else {
255 }
256 #endif
257 /* XXX: WARNING: they did not choose the same test as MPEG-4. This
258 is very important ! */
259 if (
s->msmpeg4_version > MSMP4_V3) {
260 if(
s->inter_intra_pred){
261 uint8_t *dest;
263
264 if(n==1){
266 *dir_ptr = 0;
267 }else if(n==2){
269 *dir_ptr = 1;
270 }else if(n==3){
273 *dir_ptr = 1;
274 } else {
276 *dir_ptr = 0;
277 }
278 }else{
279 int bs = 8 >>
s->avctx->lowres;
280 if(n<4){
282 dest =
s->cur_pic.data[0] + (((n >> 1) + 2*
s->mb_y) * bs*
wrap ) + ((n & 1) + 2*
s->mb_x) * bs;
283 }else{
285 dest =
s->cur_pic.data[n - 3] + (
s->mb_y * bs *
wrap) +
s->mb_x * bs;
286 }
291
292 if (
s->h263_aic_dir==0) {
294 *dir_ptr = 0;
295 }
else if (
s->h263_aic_dir==1) {
296 if(n==0){
298 *dir_ptr = 1;
299 }else{
301 *dir_ptr = 0;
302 }
303 }
else if (
s->h263_aic_dir==2) {
304 if(n==0){
306 *dir_ptr = 0;
307 }else{
309 *dir_ptr = 1;
310 }
311 } else {
313 *dir_ptr = 1;
314 }
315 }
316 }else{
319 *dir_ptr = 1;
320 } else {
322 *dir_ptr = 0;
323 }
324 }
325 }else{
328 *dir_ptr = 1;
329 } else {
331 *dir_ptr = 0;
332 }
333 }
334
335 /* update predictor */
336 *dc_val_ptr = &dc_val[0];
338 }
339