annotate msmpeg4.c @ 509:cab79946302f libavcodec

Implement put_pixels_clamped and add_pixels_clamped in Assembler. This allows better scheduling of the memory accesses, and is portable among all compilers.
author mellum
date Mon, 01 Jul 2002 04:26:07 +0000
parents 2241bce35bb9
children 55b4e2248a45
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
2 * MSMPEG4 backend for ffmpeg encoder and decoder
429
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
3 * Copyright (c) 2001 Fabrice Bellard.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
4 *
429
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
5 * This library is free software; you can redistribute it and/or
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
7 * License as published by the Free Software Foundation; either
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
8 * version 2 of the License, or (at your option) any later version.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
9 *
429
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
10 * This library is distributed in the hope that it will be useful,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
429
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
13 * Lesser General Public License for more details.
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
14 *
429
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
16 * License along with this library; if not, write to the Free Software
718a22dc121f license/copyright change
glantau
parents: 411
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
411
5c8b3a717929 workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents: 396
diff changeset
18 *
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
19 * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
20 */
396
fce0a2520551 removed useless header includes - use av memory functions
glantau
parents: 347
diff changeset
21 #include "avcodec.h"
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
22 #include "dsputil.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
23 #include "mpegvideo.h"
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
24 //#define PRINT_MB
411
5c8b3a717929 workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents: 396
diff changeset
25
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
26 /*
986e461dc072 Initial revision
glantau
parents:
diff changeset
27 * You can also call this codec : MPEG4 with a twist !
986e461dc072 Initial revision
glantau
parents:
diff changeset
28 *
986e461dc072 Initial revision
glantau
parents:
diff changeset
29 * TODO:
986e461dc072 Initial revision
glantau
parents:
diff changeset
30 * - (encoding) select best mv table (two choices)
986e461dc072 Initial revision
glantau
parents:
diff changeset
31 * - (encoding) select best vlc/dc table
986e461dc072 Initial revision
glantau
parents:
diff changeset
32 */
986e461dc072 Initial revision
glantau
parents:
diff changeset
33 //#define DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
34
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
35 static UINT32 v2_dc_lum_table[512][2];
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
36 static UINT32 v2_dc_chroma_table[512][2];
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
37
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
38 static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
39 static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
40 int n, int coded);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr);
986e461dc072 Initial revision
glantau
parents:
diff changeset
42 static int msmpeg4_decode_motion(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
43 int *mx_ptr, int *my_ptr);
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
44 static void msmpeg4v2_encode_motion(MpegEncContext * s, int val);
468
1e23eae32087 Minor warning cleanup.
mellum
parents: 457
diff changeset
45 static void init_h263_dc_for_msmpeg4(void);
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
46
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
47
225
ae145876789d use multiply instead of divides for DC prediction on X86
michaelni
parents: 221
diff changeset
48 extern UINT32 inverse[256];
ae145876789d use multiply instead of divides for DC prediction on X86
michaelni
parents: 221
diff changeset
49
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
50 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
51 int intra_count = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
52 int frame_count = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
53 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
54
986e461dc072 Initial revision
glantau
parents:
diff changeset
55 #include "msmpeg4data.h"
986e461dc072 Initial revision
glantau
parents:
diff changeset
56
986e461dc072 Initial revision
glantau
parents:
diff changeset
57 #ifdef STATS
986e461dc072 Initial revision
glantau
parents:
diff changeset
58
986e461dc072 Initial revision
glantau
parents:
diff changeset
59 const char *st_names[ST_NB] = {
986e461dc072 Initial revision
glantau
parents:
diff changeset
60 "unknown",
986e461dc072 Initial revision
glantau
parents:
diff changeset
61 "dc",
986e461dc072 Initial revision
glantau
parents:
diff changeset
62 "intra_ac",
986e461dc072 Initial revision
glantau
parents:
diff changeset
63 "inter_ac",
986e461dc072 Initial revision
glantau
parents:
diff changeset
64 "intra_mb",
986e461dc072 Initial revision
glantau
parents:
diff changeset
65 "inter_mb",
986e461dc072 Initial revision
glantau
parents:
diff changeset
66 "mv",
986e461dc072 Initial revision
glantau
parents:
diff changeset
67 };
986e461dc072 Initial revision
glantau
parents:
diff changeset
68
986e461dc072 Initial revision
glantau
parents:
diff changeset
69 int st_current_index = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
70 unsigned int st_bit_counts[ST_NB];
986e461dc072 Initial revision
glantau
parents:
diff changeset
71 unsigned int st_out_bit_counts[ST_NB];
986e461dc072 Initial revision
glantau
parents:
diff changeset
72
986e461dc072 Initial revision
glantau
parents:
diff changeset
73 #define set_stat(var) st_current_index = var;
986e461dc072 Initial revision
glantau
parents:
diff changeset
74
986e461dc072 Initial revision
glantau
parents:
diff changeset
75 void print_stats(void)
986e461dc072 Initial revision
glantau
parents:
diff changeset
76 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
77 unsigned int total;
986e461dc072 Initial revision
glantau
parents:
diff changeset
78 int i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
79
986e461dc072 Initial revision
glantau
parents:
diff changeset
80 printf("Input:\n");
986e461dc072 Initial revision
glantau
parents:
diff changeset
81 total = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
82 for(i=0;i<ST_NB;i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
83 total += st_bit_counts[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
84 if (total == 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
85 total = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
86 for(i=0;i<ST_NB;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
87 printf("%-10s : %10.1f %5.1f%%\n",
986e461dc072 Initial revision
glantau
parents:
diff changeset
88 st_names[i],
986e461dc072 Initial revision
glantau
parents:
diff changeset
89 (double)st_bit_counts[i] / 8.0,
986e461dc072 Initial revision
glantau
parents:
diff changeset
90 (double)st_bit_counts[i] * 100.0 / total);
986e461dc072 Initial revision
glantau
parents:
diff changeset
91 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
92 printf("%-10s : %10.1f %5.1f%%\n",
986e461dc072 Initial revision
glantau
parents:
diff changeset
93 "total",
986e461dc072 Initial revision
glantau
parents:
diff changeset
94 (double)total / 8.0,
986e461dc072 Initial revision
glantau
parents:
diff changeset
95 100.0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
96
986e461dc072 Initial revision
glantau
parents:
diff changeset
97 printf("Output:\n");
986e461dc072 Initial revision
glantau
parents:
diff changeset
98 total = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
99 for(i=0;i<ST_NB;i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
100 total += st_out_bit_counts[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
101 if (total == 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
102 total = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
103 for(i=0;i<ST_NB;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
104 printf("%-10s : %10.1f %5.1f%%\n",
986e461dc072 Initial revision
glantau
parents:
diff changeset
105 st_names[i],
986e461dc072 Initial revision
glantau
parents:
diff changeset
106 (double)st_out_bit_counts[i] / 8.0,
986e461dc072 Initial revision
glantau
parents:
diff changeset
107 (double)st_out_bit_counts[i] * 100.0 / total);
986e461dc072 Initial revision
glantau
parents:
diff changeset
108 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
109 printf("%-10s : %10.1f %5.1f%%\n",
986e461dc072 Initial revision
glantau
parents:
diff changeset
110 "total",
986e461dc072 Initial revision
glantau
parents:
diff changeset
111 (double)total / 8.0,
986e461dc072 Initial revision
glantau
parents:
diff changeset
112 100.0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
113 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
114
986e461dc072 Initial revision
glantau
parents:
diff changeset
115 #else
986e461dc072 Initial revision
glantau
parents:
diff changeset
116
986e461dc072 Initial revision
glantau
parents:
diff changeset
117 #define set_stat(var)
986e461dc072 Initial revision
glantau
parents:
diff changeset
118
986e461dc072 Initial revision
glantau
parents:
diff changeset
119 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
120
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
121 static void common_init(MpegEncContext * s)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
122 {
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
123 static int inited=0;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
124
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
125 switch(s->msmpeg4_version){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
126 case 1:
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
127 case 2:
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
128 s->y_dc_scale_table=
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
129 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
130 break;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
131 case 3:
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
132 if(s->workaround_bugs){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
133 s->y_dc_scale_table= old_ff_y_dc_scale_table;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
134 s->c_dc_scale_table= old_ff_c_dc_scale_table;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
135 } else{
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
136 s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
137 s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
138 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
139 break;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
140 case 4:
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
141 s->y_dc_scale_table= wmv1_y_dc_scale_table;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
142 s->c_dc_scale_table= wmv1_c_dc_scale_table;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
143 break;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
144 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
145
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
146 if(s->msmpeg4_version==4){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
147 s->intra_scantable = wmv1_scantable[1];
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
148 s->intra_h_scantable= wmv1_scantable[2];
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
149 s->intra_v_scantable= wmv1_scantable[3];
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
150 s->inter_scantable = wmv1_scantable[0];
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
151 }else{
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
152 s->intra_scantable = zigzag_direct;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
153 s->intra_h_scantable= ff_alternate_horizontal_scan;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
154 s->intra_v_scantable= ff_alternate_vertical_scan;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
155 s->inter_scantable = zigzag_direct;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
156 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
157
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
158 if(!inited){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
159 int i;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
160 inited=1;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
161
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
162 init_h263_dc_for_msmpeg4();
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
163
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
164 /* permute for IDCT */
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
165 for(i=0; i<WMV1_SCANTABLE_COUNT; i++){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
166 int k;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
167 for(k=0;k<64;k++) {
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
168 int j = wmv1_scantable[i][k];
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
169 wmv1_scantable[i][k]= block_permute_op(j);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
170 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
171 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
172
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
173 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
174 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
175
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
176 /* build the table which associate a (x,y) motion vector to a vlc */
986e461dc072 Initial revision
glantau
parents:
diff changeset
177 static void init_mv_table(MVTable *tab)
986e461dc072 Initial revision
glantau
parents:
diff changeset
178 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
179 int i, x, y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
180
396
fce0a2520551 removed useless header includes - use av memory functions
glantau
parents: 347
diff changeset
181 tab->table_mv_index = av_malloc(sizeof(UINT16) * 4096);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
182 /* mark all entries as not used */
986e461dc072 Initial revision
glantau
parents:
diff changeset
183 for(i=0;i<4096;i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
184 tab->table_mv_index[i] = tab->n;
986e461dc072 Initial revision
glantau
parents:
diff changeset
185
986e461dc072 Initial revision
glantau
parents:
diff changeset
186 for(i=0;i<tab->n;i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
187 x = tab->table_mvx[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
188 y = tab->table_mvy[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
189 tab->table_mv_index[(x << 6) | y] = i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
190 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
191 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
192
986e461dc072 Initial revision
glantau
parents:
diff changeset
193 static void code012(PutBitContext *pb, int n)
986e461dc072 Initial revision
glantau
parents:
diff changeset
194 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
195 if (n == 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
196 put_bits(pb, 1, 0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
197 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
198 put_bits(pb, 1, 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
199 put_bits(pb, 1, (n >= 2));
986e461dc072 Initial revision
glantau
parents:
diff changeset
200 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
201 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
202
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
203 void ff_msmpeg4_encode_init(MpegEncContext *s)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
204 {
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
205 static int init_done=0;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
206 int i;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
207
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
208 common_init(s);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
209 if(s->msmpeg4_version>=4){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
210 s->min_qcoeff= -255;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
211 s->max_qcoeff= 255;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
212 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
213
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
214 if (!init_done) {
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
215 /* init various encoding tables */
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
216 init_done = 1;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
217 init_mv_table(&mv_tables[0]);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
218 init_mv_table(&mv_tables[1]);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
219 for(i=0;i<NB_RL_TABLES;i++)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
220 init_rl(&rl_table[i]);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
221 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
222 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
223
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
224 static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
225 int size=0;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
226 int code;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
227 int run_diff= intra ? 0 : 1;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
228
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
229 code = get_rl_index(rl, last, run, level);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
230 size+= rl->table_vlc[code][1];
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
231 if (code == rl->n) {
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
232 int level1, run1;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
233
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
234 level1 = level - rl->max_level[last][run];
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
235 if (level1 < 1)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
236 goto esc2;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
237 code = get_rl_index(rl, last, run, level1);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
238 if (code == rl->n) {
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
239 esc2:
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
240 size++;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
241 if (level > MAX_LEVEL)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
242 goto esc3;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
243 run1 = run - rl->max_run[last][level] - run_diff;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
244 if (run1 < 0)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
245 goto esc3;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
246 code = get_rl_index(rl, last, run1, level);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
247 if (code == rl->n) {
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
248 esc3:
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
249 /* third escape */
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
250 size+=1+1+6+8;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
251 } else {
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
252 /* second escape */
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
253 size+= 1+1+ rl->table_vlc[code][1];
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
254 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
255 } else {
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
256 /* first escape */
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
257 size+= 1+1+ rl->table_vlc[code][1];
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
258 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
259 } else {
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
260 size++;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
261 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
262 return size;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
263 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
264
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
265 static void find_best_tables(MpegEncContext * s)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
266 {
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
267 int i;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
268 int best =-1, best_size =9999999;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
269 int chroma_best=-1, best_chroma_size=9999999;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
270 int last_size=0;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
271
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
272 for(i=0; i<3; i++){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
273 int level;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
274 int chroma_size=0;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
275 int size=0;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
276
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
277 if(i>0){// ;)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
278 size++;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
279 chroma_size++;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
280 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
281 for(level=0; level<=MAX_LEVEL; level++){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
282 int run;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
283 for(run=0; run<=MAX_RUN; run++){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
284 int last;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
285 for(last=0; last<2; last++){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
286 int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
287 int intra_luma_count = s->ac_stats[1][0][level][run][last];
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
288 int intra_chroma_count= s->ac_stats[1][1][level][run][last];
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
289
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
290 if(s->pict_type==I_TYPE){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
291 size += intra_luma_count *get_size_of_code(s, &rl_table[ i], last, run, level,1);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
292 chroma_size+= intra_chroma_count*get_size_of_code(s, &rl_table[3+i], last, run, level,1);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
293 }else{
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
294 size+= intra_luma_count *get_size_of_code(s, &rl_table[ i], last, run, level,1)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
295 +intra_chroma_count*get_size_of_code(s, &rl_table[3+i], last, run, level,1)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
296 +inter_count *get_size_of_code(s, &rl_table[3+i], last, run, level,0);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
297 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
298 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
299 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
300 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
301 if(size<best_size){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
302 best_size= size;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
303 best= i;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
304 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
305 if(chroma_size<best_chroma_size){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
306 best_chroma_size= chroma_size;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
307 chroma_best= i;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
308 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
309 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
310 // printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n",
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
311 // s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
312
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
313 if(s->pict_type==P_TYPE) chroma_best= best;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
314
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
315 memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
316
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
317 s->rl_table_index = best;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
318 s->rl_chroma_table_index= chroma_best;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
319
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
320 if(s->pict_type != s->last_non_b_pict_type){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
321 s->rl_table_index= 2;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
322 if(s->pict_type==I_TYPE)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
323 s->rl_chroma_table_index= 1;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
324 else
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
325 s->rl_chroma_table_index= 2;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
326 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
327
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
328 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
329
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
330 /* write MSMPEG4 compatible frame header */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
331 void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
986e461dc072 Initial revision
glantau
parents:
diff changeset
332 {
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
333 find_best_tables(s);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
334
986e461dc072 Initial revision
glantau
parents:
diff changeset
335 align_put_bits(&s->pb);
986e461dc072 Initial revision
glantau
parents:
diff changeset
336 put_bits(&s->pb, 2, s->pict_type - 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
337
986e461dc072 Initial revision
glantau
parents:
diff changeset
338 put_bits(&s->pb, 5, s->qscale);
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
339 if(s->msmpeg4_version<=2){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
340 s->rl_table_index = 2;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
341 s->rl_chroma_table_index = 2;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
342 }
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
343
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
344 s->dc_table_index = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
345 s->mv_table_index = 1; /* only if P frame */
986e461dc072 Initial revision
glantau
parents:
diff changeset
346 s->use_skip_mb_code = 1; /* only if P frame */
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
347 s->per_mb_rl_table = 0;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
348
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
349 if (s->pict_type == I_TYPE) {
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
350 s->no_rounding = 1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
351 put_bits(&s->pb, 5, 0x17); /* indicate only one "slice" */
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
352
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
353 if(s->msmpeg4_version==4){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
354 msmpeg4_encode_ext_header(s);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
355 put_bits(&s->pb, 1, s->per_mb_rl_table);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
356 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
357
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
358 if(s->msmpeg4_version>2){
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
359 if(!s->per_mb_rl_table){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
360 code012(&s->pb, s->rl_chroma_table_index);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
361 code012(&s->pb, s->rl_table_index);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
362 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
363
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
364 put_bits(&s->pb, 1, s->dc_table_index);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
365 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
366 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
367 put_bits(&s->pb, 1, s->use_skip_mb_code);
986e461dc072 Initial revision
glantau
parents:
diff changeset
368
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
369 if(s->msmpeg4_version==4)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
370 put_bits(&s->pb, 1, s->per_mb_rl_table);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
371
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
372 if(s->msmpeg4_version>2){
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
373 if(!s->per_mb_rl_table)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
374 code012(&s->pb, s->rl_table_index);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
375
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
376 put_bits(&s->pb, 1, s->dc_table_index);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
377
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
378 put_bits(&s->pb, 1, s->mv_table_index);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
379 }
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
380
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
381 if(s->flipflop_rounding){
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
382 s->no_rounding ^= 1;
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
383 }else{
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
384 s->no_rounding = 0;
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
385 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
386 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
387
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
388 s->esc3_level_length= 0;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
389 s->esc3_run_length= 0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
390
986e461dc072 Initial revision
glantau
parents:
diff changeset
391 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
392 intra_count = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
393 printf("*****frame %d:\n", frame_count++);
986e461dc072 Initial revision
glantau
parents:
diff changeset
394 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
395 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
396
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
397 void msmpeg4_encode_ext_header(MpegEncContext * s)
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
398 {
251
75091bfc577b fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
michaelni
parents: 246
diff changeset
399 put_bits(&s->pb, 5, s->frame_rate / FRAME_RATE_BASE); //yes 29.97 -> 29
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
400
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
401 put_bits(&s->pb, 11, MIN(s->bit_rate, 2047));
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
402
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
403 if(s->msmpeg4_version<3)
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
404 s->flipflop_rounding=0;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
405 else{
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
406 s->flipflop_rounding=1;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
407 put_bits(&s->pb, 1, s->flipflop_rounding);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
408 }
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
409 }
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
410
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
411 /* predict coded block */
986e461dc072 Initial revision
glantau
parents:
diff changeset
412 static inline int coded_block_pred(MpegEncContext * s, int n, UINT8 **coded_block_ptr)
986e461dc072 Initial revision
glantau
parents:
diff changeset
413 {
299
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
414 int xy, wrap, pred, a, b, c;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
415
299
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
416 xy = s->block_index[n];
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
417 wrap = s->block_wrap[0];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
418
986e461dc072 Initial revision
glantau
parents:
diff changeset
419 /* B C
986e461dc072 Initial revision
glantau
parents:
diff changeset
420 * A X
986e461dc072 Initial revision
glantau
parents:
diff changeset
421 */
299
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
422 a = s->coded_block[xy - 1 ];
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
423 b = s->coded_block[xy - 1 - wrap];
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
424 c = s->coded_block[xy - wrap];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
425
986e461dc072 Initial revision
glantau
parents:
diff changeset
426 if (b == c) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
427 pred = a;
986e461dc072 Initial revision
glantau
parents:
diff changeset
428 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
429 pred = c;
986e461dc072 Initial revision
glantau
parents:
diff changeset
430 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
431
986e461dc072 Initial revision
glantau
parents:
diff changeset
432 /* store value */
299
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
433 *coded_block_ptr = &s->coded_block[xy];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
434
986e461dc072 Initial revision
glantau
parents:
diff changeset
435 return pred;
986e461dc072 Initial revision
glantau
parents:
diff changeset
436 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
437
986e461dc072 Initial revision
glantau
parents:
diff changeset
438 static void msmpeg4_encode_motion(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
439 int mx, int my)
986e461dc072 Initial revision
glantau
parents:
diff changeset
440 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
441 int code;
986e461dc072 Initial revision
glantau
parents:
diff changeset
442 MVTable *mv;
986e461dc072 Initial revision
glantau
parents:
diff changeset
443
986e461dc072 Initial revision
glantau
parents:
diff changeset
444 /* modulo encoding */
986e461dc072 Initial revision
glantau
parents:
diff changeset
445 /* WARNING : you cannot reach all the MVs even with the modulo
986e461dc072 Initial revision
glantau
parents:
diff changeset
446 encoding. This is a somewhat strange compromise they took !!! */
986e461dc072 Initial revision
glantau
parents:
diff changeset
447 if (mx <= -64)
986e461dc072 Initial revision
glantau
parents:
diff changeset
448 mx += 64;
986e461dc072 Initial revision
glantau
parents:
diff changeset
449 else if (mx >= 64)
986e461dc072 Initial revision
glantau
parents:
diff changeset
450 mx -= 64;
986e461dc072 Initial revision
glantau
parents:
diff changeset
451 if (my <= -64)
986e461dc072 Initial revision
glantau
parents:
diff changeset
452 my += 64;
986e461dc072 Initial revision
glantau
parents:
diff changeset
453 else if (my >= 64)
986e461dc072 Initial revision
glantau
parents:
diff changeset
454 my -= 64;
986e461dc072 Initial revision
glantau
parents:
diff changeset
455
986e461dc072 Initial revision
glantau
parents:
diff changeset
456 mx += 32;
986e461dc072 Initial revision
glantau
parents:
diff changeset
457 my += 32;
986e461dc072 Initial revision
glantau
parents:
diff changeset
458 #if 0
986e461dc072 Initial revision
glantau
parents:
diff changeset
459 if ((unsigned)mx >= 64 ||
986e461dc072 Initial revision
glantau
parents:
diff changeset
460 (unsigned)my >= 64)
986e461dc072 Initial revision
glantau
parents:
diff changeset
461 fprintf(stderr, "error mx=%d my=%d\n", mx, my);
986e461dc072 Initial revision
glantau
parents:
diff changeset
462 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
463 mv = &mv_tables[s->mv_table_index];
986e461dc072 Initial revision
glantau
parents:
diff changeset
464
986e461dc072 Initial revision
glantau
parents:
diff changeset
465 code = mv->table_mv_index[(mx << 6) | my];
986e461dc072 Initial revision
glantau
parents:
diff changeset
466 set_stat(ST_MV);
986e461dc072 Initial revision
glantau
parents:
diff changeset
467 put_bits(&s->pb,
986e461dc072 Initial revision
glantau
parents:
diff changeset
468 mv->table_mv_bits[code],
986e461dc072 Initial revision
glantau
parents:
diff changeset
469 mv->table_mv_code[code]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
470 if (code == mv->n) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
471 /* escape : code litterally */
986e461dc072 Initial revision
glantau
parents:
diff changeset
472 put_bits(&s->pb, 6, mx);
986e461dc072 Initial revision
glantau
parents:
diff changeset
473 put_bits(&s->pb, 6, my);
986e461dc072 Initial revision
glantau
parents:
diff changeset
474 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
475 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
476
986e461dc072 Initial revision
glantau
parents:
diff changeset
477 void msmpeg4_encode_mb(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
478 DCTELEM block[6][64],
986e461dc072 Initial revision
glantau
parents:
diff changeset
479 int motion_x, int motion_y)
986e461dc072 Initial revision
glantau
parents:
diff changeset
480 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
481 int cbp, coded_cbp, i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
482 int pred_x, pred_y;
986e461dc072 Initial revision
glantau
parents:
diff changeset
483 UINT8 *coded_block;
986e461dc072 Initial revision
glantau
parents:
diff changeset
484
986e461dc072 Initial revision
glantau
parents:
diff changeset
485 if (!s->mb_intra) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
486 /* compute cbp */
986e461dc072 Initial revision
glantau
parents:
diff changeset
487 set_stat(ST_INTER_MB);
986e461dc072 Initial revision
glantau
parents:
diff changeset
488 cbp = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
489 for (i = 0; i < 6; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
490 if (s->block_last_index[i] >= 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
491 cbp |= 1 << (5 - i);
986e461dc072 Initial revision
glantau
parents:
diff changeset
492 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
493 if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
494 /* skip macroblock */
986e461dc072 Initial revision
glantau
parents:
diff changeset
495 put_bits(&s->pb, 1, 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
496 return;
986e461dc072 Initial revision
glantau
parents:
diff changeset
497 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
498 if (s->use_skip_mb_code)
986e461dc072 Initial revision
glantau
parents:
diff changeset
499 put_bits(&s->pb, 1, 0); /* mb coded */
986e461dc072 Initial revision
glantau
parents:
diff changeset
500
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
501 if(s->msmpeg4_version<=2){
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
502 put_bits(&s->pb,
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
503 v2_mb_type[cbp&3][1],
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
504 v2_mb_type[cbp&3][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
505 if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
506 else coded_cbp= cbp;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
507
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
508 put_bits(&s->pb,
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
509 cbpy_tab[coded_cbp>>2][1],
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
510 cbpy_tab[coded_cbp>>2][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
511
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
512 h263_pred_motion(s, 0, &pred_x, &pred_y);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
513 msmpeg4v2_encode_motion(s, motion_x - pred_x);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
514 msmpeg4v2_encode_motion(s, motion_y - pred_y);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
515 }else{
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
516 put_bits(&s->pb,
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
517 table_mb_non_intra[cbp + 64][1],
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
518 table_mb_non_intra[cbp + 64][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
519
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
520 /* motion vector */
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
521 h263_pred_motion(s, 0, &pred_x, &pred_y);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
522 msmpeg4_encode_motion(s, motion_x - pred_x,
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
523 motion_y - pred_y);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
524 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
525 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
526 /* compute cbp */
986e461dc072 Initial revision
glantau
parents:
diff changeset
527 cbp = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
528 coded_cbp = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
529 for (i = 0; i < 6; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
530 int val, pred;
986e461dc072 Initial revision
glantau
parents:
diff changeset
531 val = (s->block_last_index[i] >= 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
532 cbp |= val << (5 - i);
986e461dc072 Initial revision
glantau
parents:
diff changeset
533 if (i < 4) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
534 /* predict value for close blocks only for luma */
986e461dc072 Initial revision
glantau
parents:
diff changeset
535 pred = coded_block_pred(s, i, &coded_block);
986e461dc072 Initial revision
glantau
parents:
diff changeset
536 *coded_block = val;
986e461dc072 Initial revision
glantau
parents:
diff changeset
537 val = val ^ pred;
986e461dc072 Initial revision
glantau
parents:
diff changeset
538 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
539 coded_cbp |= val << (5 - i);
986e461dc072 Initial revision
glantau
parents:
diff changeset
540 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
541 #if 0
986e461dc072 Initial revision
glantau
parents:
diff changeset
542 if (coded_cbp)
986e461dc072 Initial revision
glantau
parents:
diff changeset
543 printf("cbp=%x %x\n", cbp, coded_cbp);
986e461dc072 Initial revision
glantau
parents:
diff changeset
544 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
545
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
546 if(s->msmpeg4_version<=2){
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
547 if (s->pict_type == I_TYPE) {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
548 put_bits(&s->pb,
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
549 v2_intra_cbpc[cbp&3][1], v2_intra_cbpc[cbp&3][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
550 } else {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
551 if (s->use_skip_mb_code)
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
552 put_bits(&s->pb, 1, 0); /* mb coded */
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
553 put_bits(&s->pb,
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
554 v2_mb_type[(cbp&3) + 4][1],
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
555 v2_mb_type[(cbp&3) + 4][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
556 }
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
557 put_bits(&s->pb, 1, 0); /* no AC prediction yet */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
558 put_bits(&s->pb,
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
559 cbpy_tab[cbp>>2][1],
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
560 cbpy_tab[cbp>>2][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
561 }else{
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
562 if (s->pict_type == I_TYPE) {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
563 set_stat(ST_INTRA_MB);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
564 put_bits(&s->pb,
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
565 table_mb_intra[coded_cbp][1], table_mb_intra[coded_cbp][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
566 } else {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
567 if (s->use_skip_mb_code)
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
568 put_bits(&s->pb, 1, 0); /* mb coded */
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
569 put_bits(&s->pb,
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
570 table_mb_non_intra[cbp][1],
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
571 table_mb_non_intra[cbp][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
572 }
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
573 set_stat(ST_INTRA_MB);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
574 put_bits(&s->pb, 1, 0); /* no AC prediction yet */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
575 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
576 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
577
986e461dc072 Initial revision
glantau
parents:
diff changeset
578 for (i = 0; i < 6; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
579 msmpeg4_encode_block(s, block[i], i);
986e461dc072 Initial revision
glantau
parents:
diff changeset
580 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
581 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
582
411
5c8b3a717929 workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents: 396
diff changeset
583 /* old ffmpeg msmpeg4v3 mode */
5c8b3a717929 workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents: 396
diff changeset
584 void ff_old_msmpeg4_dc_scale(MpegEncContext * s)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
585 {
411
5c8b3a717929 workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents: 396
diff changeset
586 if (s->qscale < 5){
195
92f726205082 s->c_dc_scale was 7 if s->qscale==2 but should be 8 (the bug is visible in deep red areas in high bitrate clips) - patch by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 186
diff changeset
587 s->y_dc_scale = 8;
92f726205082 s->c_dc_scale was 7 if s->qscale==2 but should be 8 (the bug is visible in deep red areas in high bitrate clips) - patch by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 186
diff changeset
588 s->c_dc_scale = 8;
92f726205082 s->c_dc_scale was 7 if s->qscale==2 but should be 8 (the bug is visible in deep red areas in high bitrate clips) - patch by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 186
diff changeset
589 }else if (s->qscale < 9){
92f726205082 s->c_dc_scale was 7 if s->qscale==2 but should be 8 (the bug is visible in deep red areas in high bitrate clips) - patch by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 186
diff changeset
590 s->y_dc_scale = 2 * s->qscale;
92f726205082 s->c_dc_scale was 7 if s->qscale==2 but should be 8 (the bug is visible in deep red areas in high bitrate clips) - patch by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 186
diff changeset
591 s->c_dc_scale = (s->qscale + 13)>>1;
411
5c8b3a717929 workaround dc_scale bug in old ffmpeg msmpeg4v3 encoder (set workaround_bugs=1 for this)
michaelni
parents: 396
diff changeset
592 }else{
195
92f726205082 s->c_dc_scale was 7 if s->qscale==2 but should be 8 (the bug is visible in deep red areas in high bitrate clips) - patch by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 186
diff changeset
593 s->y_dc_scale = s->qscale + 8;
92f726205082 s->c_dc_scale was 7 if s->qscale==2 but should be 8 (the bug is visible in deep red areas in high bitrate clips) - patch by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 186
diff changeset
594 s->c_dc_scale = (s->qscale + 13)>>1;
92f726205082 s->c_dc_scale was 7 if s->qscale==2 but should be 8 (the bug is visible in deep red areas in high bitrate clips) - patch by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents: 186
diff changeset
595 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
596 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
597
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
598 static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
599 INT32 **dc_val_ptr)
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
600 {
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
601 int i;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
602
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
603 if (n < 4) {
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
604 i= 0;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
605 } else {
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
606 i= n-3;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
607 }
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
608
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
609 *dc_val_ptr= &s->last_dc[i];
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
610 return s->last_dc[i];
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
611 }
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
612
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
613 /* dir = 0: left, dir = 1: top prediction */
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
614 static inline int msmpeg4_pred_dc(MpegEncContext * s, int n,
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
615 UINT16 **dc_val_ptr, int *dir_ptr)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
616 {
299
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
617 int a, b, c, wrap, pred, scale;
25
2f603eb2f23d types fix
glantau
parents: 21
diff changeset
618 INT16 *dc_val;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
619
986e461dc072 Initial revision
glantau
parents:
diff changeset
620 /* find prediction */
986e461dc072 Initial revision
glantau
parents:
diff changeset
621 if (n < 4) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
622 scale = s->y_dc_scale;
986e461dc072 Initial revision
glantau
parents:
diff changeset
623 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
624 scale = s->c_dc_scale;
986e461dc072 Initial revision
glantau
parents:
diff changeset
625 }
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
626
299
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
627 wrap = s->block_wrap[n];
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
628 dc_val= s->dc_val[0] + s->block_index[n];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
629
986e461dc072 Initial revision
glantau
parents:
diff changeset
630 /* B C
986e461dc072 Initial revision
glantau
parents:
diff changeset
631 * A X
986e461dc072 Initial revision
glantau
parents:
diff changeset
632 */
299
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
633 a = dc_val[ - 1];
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
634 b = dc_val[ - 1 - wrap];
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
635 c = dc_val[ - wrap];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
636
986e461dc072 Initial revision
glantau
parents:
diff changeset
637 /* XXX: the following solution consumes divisions, but it does not
986e461dc072 Initial revision
glantau
parents:
diff changeset
638 necessitate to modify mpegvideo.c. The problem comes from the
986e461dc072 Initial revision
glantau
parents:
diff changeset
639 fact they decided to store the quantized DC (which would lead
986e461dc072 Initial revision
glantau
parents:
diff changeset
640 to problems if Q could vary !) */
221
fe243b4aec02 * temporal solution for shared lib compilation
kabi
parents: 214
diff changeset
641 #if defined ARCH_X86 && !defined PIC
204
fceb435fae6b (commit by michael)
arpi_esp
parents: 201
diff changeset
642 asm volatile(
fceb435fae6b (commit by michael)
arpi_esp
parents: 201
diff changeset
643 "movl %3, %%eax \n\t"
fceb435fae6b (commit by michael)
arpi_esp
parents: 201
diff changeset
644 "shrl $1, %%eax \n\t"
fceb435fae6b (commit by michael)
arpi_esp
parents: 201
diff changeset
645 "addl %%eax, %2 \n\t"
fceb435fae6b (commit by michael)
arpi_esp
parents: 201
diff changeset
646 "addl %%eax, %1 \n\t"
fceb435fae6b (commit by michael)
arpi_esp
parents: 201
diff changeset
647 "addl %0, %%eax \n\t"
225
ae145876789d use multiply instead of divides for DC prediction on X86
michaelni
parents: 221
diff changeset
648 "mull %4 \n\t"
ae145876789d use multiply instead of divides for DC prediction on X86
michaelni
parents: 221
diff changeset
649 "movl %%edx, %0 \n\t"
204
fceb435fae6b (commit by michael)
arpi_esp
parents: 201
diff changeset
650 "movl %1, %%eax \n\t"
225
ae145876789d use multiply instead of divides for DC prediction on X86
michaelni
parents: 221
diff changeset
651 "mull %4 \n\t"
ae145876789d use multiply instead of divides for DC prediction on X86
michaelni
parents: 221
diff changeset
652 "movl %%edx, %1 \n\t"
204
fceb435fae6b (commit by michael)
arpi_esp
parents: 201
diff changeset
653 "movl %2, %%eax \n\t"
225
ae145876789d use multiply instead of divides for DC prediction on X86
michaelni
parents: 221
diff changeset
654 "mull %4 \n\t"
ae145876789d use multiply instead of divides for DC prediction on X86
michaelni
parents: 221
diff changeset
655 "movl %%edx, %2 \n\t"
228
3c2bad70a196 workaround gcc 2.95.2 bug
michaelni
parents: 225
diff changeset
656 : "+b" (a), "+c" (b), "+D" (c)
3c2bad70a196 workaround gcc 2.95.2 bug
michaelni
parents: 225
diff changeset
657 : "g" (scale), "S" (inverse[scale])
204
fceb435fae6b (commit by michael)
arpi_esp
parents: 201
diff changeset
658 : "%eax", "%edx"
fceb435fae6b (commit by michael)
arpi_esp
parents: 201
diff changeset
659 );
221
fe243b4aec02 * temporal solution for shared lib compilation
kabi
parents: 214
diff changeset
660 #else
fe243b4aec02 * temporal solution for shared lib compilation
kabi
parents: 214
diff changeset
661 /* #elif defined (ARCH_ALPHA) */
214
73df666cacc7 Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents: 208
diff changeset
662 /* Divisions are extremely costly on Alpha; optimize the most
221
fe243b4aec02 * temporal solution for shared lib compilation
kabi
parents: 214
diff changeset
663 common case. But they are costly everywhere...
fe243b4aec02 * temporal solution for shared lib compilation
kabi
parents: 214
diff changeset
664 */
214
73df666cacc7 Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents: 208
diff changeset
665 if (scale == 8) {
73df666cacc7 Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents: 208
diff changeset
666 a = (a + (8 >> 1)) / 8;
73df666cacc7 Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents: 208
diff changeset
667 b = (b + (8 >> 1)) / 8;
73df666cacc7 Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents: 208
diff changeset
668 c = (c + (8 >> 1)) / 8;
73df666cacc7 Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents: 208
diff changeset
669 } else {
73df666cacc7 Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents: 208
diff changeset
670 a = (a + (scale >> 1)) / scale;
73df666cacc7 Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents: 208
diff changeset
671 b = (b + (scale >> 1)) / scale;
73df666cacc7 Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents: 208
diff changeset
672 c = (c + (scale >> 1)) / scale;
73df666cacc7 Alpha optimizations by Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
nickols_k
parents: 208
diff changeset
673 }
204
fceb435fae6b (commit by michael)
arpi_esp
parents: 201
diff changeset
674 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
675 /* XXX: WARNING: they did not choose the same test as MPEG4. This
986e461dc072 Initial revision
glantau
parents:
diff changeset
676 is very important ! */
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
677 if(s->msmpeg4_version>3){
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
678 if (abs(a - b) < abs(b - c)) {
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
679 pred = c;
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
680 *dir_ptr = 1;
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
681 } else {
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
682 pred = a;
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
683 *dir_ptr = 0;
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
684 }
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
685 }else{
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
686 if (abs(a - b) <= abs(b - c)) {
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
687 pred = c;
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
688 *dir_ptr = 1;
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
689 } else {
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
690 pred = a;
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
691 *dir_ptr = 0;
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
692 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
693 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
694
986e461dc072 Initial revision
glantau
parents:
diff changeset
695 /* update predictor */
299
fb9e77674bd4 minor optimizations / simplifications
michaelni
parents: 251
diff changeset
696 *dc_val_ptr = &dc_val[0];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
697 return pred;
986e461dc072 Initial revision
glantau
parents:
diff changeset
698 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
699
986e461dc072 Initial revision
glantau
parents:
diff changeset
700 #define DC_MAX 119
986e461dc072 Initial revision
glantau
parents:
diff changeset
701
986e461dc072 Initial revision
glantau
parents:
diff changeset
702 static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
986e461dc072 Initial revision
glantau
parents:
diff changeset
703 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
704 int sign, code;
986e461dc072 Initial revision
glantau
parents:
diff changeset
705 int pred;
986e461dc072 Initial revision
glantau
parents:
diff changeset
706
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
707 if(s->msmpeg4_version==1){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
708 INT32 *dc_val;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
709 pred = msmpeg4v1_pred_dc(s, n, &dc_val);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
710
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
711 /* update predictor */
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
712 *dc_val= level;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
713 }else{
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
714 UINT16 *dc_val;
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
715 pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
716
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
717 /* update predictor */
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
718 if (n < 4) {
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
719 *dc_val = level * s->y_dc_scale;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
720 } else {
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
721 *dc_val = level * s->c_dc_scale;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
722 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
723 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
724
986e461dc072 Initial revision
glantau
parents:
diff changeset
725 /* do the prediction */
986e461dc072 Initial revision
glantau
parents:
diff changeset
726 level -= pred;
986e461dc072 Initial revision
glantau
parents:
diff changeset
727
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
728 if(s->msmpeg4_version<=2){
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
729 if (n < 4) {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
730 put_bits(&s->pb,
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
731 v2_dc_lum_table[level+256][1],
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
732 v2_dc_lum_table[level+256][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
733 }else{
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
734 put_bits(&s->pb,
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
735 v2_dc_chroma_table[level+256][1],
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
736 v2_dc_chroma_table[level+256][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
737 }
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
738 }else{
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
739 sign = 0;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
740 if (level < 0) {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
741 level = -level;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
742 sign = 1;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
743 }
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
744 code = level;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
745 if (code > DC_MAX)
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
746 code = DC_MAX;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
747
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
748 if (s->dc_table_index == 0) {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
749 if (n < 4) {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
750 put_bits(&s->pb, table0_dc_lum[code][1], table0_dc_lum[code][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
751 } else {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
752 put_bits(&s->pb, table0_dc_chroma[code][1], table0_dc_chroma[code][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
753 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
754 } else {
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
755 if (n < 4) {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
756 put_bits(&s->pb, table1_dc_lum[code][1], table1_dc_lum[code][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
757 } else {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
758 put_bits(&s->pb, table1_dc_chroma[code][1], table1_dc_chroma[code][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
759 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
760 }
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
761
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
762 if (code == DC_MAX)
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
763 put_bits(&s->pb, 8, level);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
764
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
765 if (level != 0) {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
766 put_bits(&s->pb, 1, sign);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
767 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
768 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
769 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
770
986e461dc072 Initial revision
glantau
parents:
diff changeset
771 /* Encoding of a block. Very similar to MPEG4 except for a different
986e461dc072 Initial revision
glantau
parents:
diff changeset
772 escape coding (same as H263) and more vlc tables.
986e461dc072 Initial revision
glantau
parents:
diff changeset
773 */
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
774 static inline void msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
775 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
776 int level, run, last, i, j, last_index;
986e461dc072 Initial revision
glantau
parents:
diff changeset
777 int last_non_zero, sign, slevel;
986e461dc072 Initial revision
glantau
parents:
diff changeset
778 int code, run_diff, dc_pred_dir;
986e461dc072 Initial revision
glantau
parents:
diff changeset
779 const RLTable *rl;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
780 const UINT8 *scantable;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
781
986e461dc072 Initial revision
glantau
parents:
diff changeset
782 if (s->mb_intra) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
783 set_stat(ST_DC);
986e461dc072 Initial revision
glantau
parents:
diff changeset
784 msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
986e461dc072 Initial revision
glantau
parents:
diff changeset
785 i = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
786 if (n < 4) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
787 rl = &rl_table[s->rl_table_index];
986e461dc072 Initial revision
glantau
parents:
diff changeset
788 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
789 rl = &rl_table[3 + s->rl_chroma_table_index];
986e461dc072 Initial revision
glantau
parents:
diff changeset
790 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
791 run_diff = 0;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
792 scantable= s->intra_scantable;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
793 set_stat(ST_INTRA_AC);
986e461dc072 Initial revision
glantau
parents:
diff changeset
794 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
795 i = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
796 rl = &rl_table[3 + s->rl_table_index];
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
797 if(s->msmpeg4_version<=2)
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
798 run_diff = 0;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
799 else
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
800 run_diff = 1;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
801 scantable= s->inter_scantable;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
802 set_stat(ST_INTER_AC);
986e461dc072 Initial revision
glantau
parents:
diff changeset
803 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
804
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
805 /* recalculate block_last_index for M$ wmv1 */
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
806 if(scantable!=zigzag_direct && s->block_last_index[n]>0){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
807 for(last_index=63; last_index>=0; last_index--){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
808 if(block[scantable[last_index]]) break;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
809 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
810 }else
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
811 last_index = s->block_last_index[n];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
812 /* AC coefs */
986e461dc072 Initial revision
glantau
parents:
diff changeset
813 last_non_zero = i - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
814 for (; i <= last_index; i++) {
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
815 j = scantable[i];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
816 level = block[j];
986e461dc072 Initial revision
glantau
parents:
diff changeset
817 if (level) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
818 run = i - last_non_zero - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
819 last = (i == last_index);
986e461dc072 Initial revision
glantau
parents:
diff changeset
820 sign = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
821 slevel = level;
986e461dc072 Initial revision
glantau
parents:
diff changeset
822 if (level < 0) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
823 sign = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
824 level = -level;
986e461dc072 Initial revision
glantau
parents:
diff changeset
825 }
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
826 if(level<=MAX_LEVEL && run<=MAX_RUN){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
827 s->ac_stats[s->mb_intra][n>3][level][run][last]++;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
828 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
829 #if 0
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
830 else
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
831 s->ac_stats[s->mb_intra][n>3][40][63][0]++; //esc3 like
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
832 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
833 code = get_rl_index(rl, last, run, level);
986e461dc072 Initial revision
glantau
parents:
diff changeset
834 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
835 if (code == rl->n) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
836 int level1, run1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
837
986e461dc072 Initial revision
glantau
parents:
diff changeset
838 level1 = level - rl->max_level[last][run];
986e461dc072 Initial revision
glantau
parents:
diff changeset
839 if (level1 < 1)
986e461dc072 Initial revision
glantau
parents:
diff changeset
840 goto esc2;
986e461dc072 Initial revision
glantau
parents:
diff changeset
841 code = get_rl_index(rl, last, run, level1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
842 if (code == rl->n) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
843 esc2:
986e461dc072 Initial revision
glantau
parents:
diff changeset
844 put_bits(&s->pb, 1, 0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
845 if (level > MAX_LEVEL)
986e461dc072 Initial revision
glantau
parents:
diff changeset
846 goto esc3;
986e461dc072 Initial revision
glantau
parents:
diff changeset
847 run1 = run - rl->max_run[last][level] - run_diff;
986e461dc072 Initial revision
glantau
parents:
diff changeset
848 if (run1 < 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
849 goto esc3;
986e461dc072 Initial revision
glantau
parents:
diff changeset
850 code = get_rl_index(rl, last, run1, level);
986e461dc072 Initial revision
glantau
parents:
diff changeset
851 if (code == rl->n) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
852 esc3:
986e461dc072 Initial revision
glantau
parents:
diff changeset
853 /* third escape */
986e461dc072 Initial revision
glantau
parents:
diff changeset
854 put_bits(&s->pb, 1, 0);
986e461dc072 Initial revision
glantau
parents:
diff changeset
855 put_bits(&s->pb, 1, last);
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
856 if(s->msmpeg4_version==4){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
857 if(s->esc3_level_length==0){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
858 s->esc3_level_length=8;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
859 s->esc3_run_length= 6;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
860 if(s->qscale<8)
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
861 put_bits(&s->pb, 6, 3);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
862 else
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
863 put_bits(&s->pb, 8, 3);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
864 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
865 put_bits(&s->pb, s->esc3_run_length, run);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
866 put_bits(&s->pb, 1, sign);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
867 put_bits(&s->pb, s->esc3_level_length, level);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
868 }else{
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
869 put_bits(&s->pb, 6, run);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
870 put_bits(&s->pb, 8, slevel & 0xff);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
871 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
872 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
873 /* second escape */
986e461dc072 Initial revision
glantau
parents:
diff changeset
874 put_bits(&s->pb, 1, 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
875 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
876 put_bits(&s->pb, 1, sign);
986e461dc072 Initial revision
glantau
parents:
diff changeset
877 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
878 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
879 /* first escape */
986e461dc072 Initial revision
glantau
parents:
diff changeset
880 put_bits(&s->pb, 1, 1);
986e461dc072 Initial revision
glantau
parents:
diff changeset
881 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
986e461dc072 Initial revision
glantau
parents:
diff changeset
882 put_bits(&s->pb, 1, sign);
986e461dc072 Initial revision
glantau
parents:
diff changeset
883 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
884 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
885 put_bits(&s->pb, 1, sign);
986e461dc072 Initial revision
glantau
parents:
diff changeset
886 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
887 last_non_zero = i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
888 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
889 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
890 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
891
986e461dc072 Initial revision
glantau
parents:
diff changeset
892 /****************************************/
986e461dc072 Initial revision
glantau
parents:
diff changeset
893 /* decoding stuff */
986e461dc072 Initial revision
glantau
parents:
diff changeset
894
986e461dc072 Initial revision
glantau
parents:
diff changeset
895 static VLC mb_non_intra_vlc;
986e461dc072 Initial revision
glantau
parents:
diff changeset
896 static VLC mb_intra_vlc;
986e461dc072 Initial revision
glantau
parents:
diff changeset
897 static VLC dc_lum_vlc[2];
986e461dc072 Initial revision
glantau
parents:
diff changeset
898 static VLC dc_chroma_vlc[2];
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
899 static VLC v2_dc_lum_vlc;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
900 static VLC v2_dc_chroma_vlc;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
901 static VLC cbpy_vlc;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
902 static VLC v2_intra_cbpc_vlc;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
903 static VLC v2_mb_type_vlc;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
904 static VLC v2_mv_vlc;
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
905 static VLC v1_intra_cbpc_vlc;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
906 static VLC v1_inter_cbpc_vlc;
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
907
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
908 /* this table is practically identical to the one from h263 except that its inverted */
468
1e23eae32087 Minor warning cleanup.
mellum
parents: 457
diff changeset
909 static void init_h263_dc_for_msmpeg4(void)
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
910 {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
911 int level, uni_code, uni_len;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
912
309
32485ad4cc4e fixing msmpeg4v2 bugs (is bugfree now afaik)
michaelni
parents: 307
diff changeset
913 for(level=-256; level<256; level++){
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
914 int size, v, l;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
915 /* find number of bits */
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
916 size = 0;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
917 v = abs(level);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
918 while (v) {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
919 v >>= 1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
920 size++;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
921 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
922
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
923 if (level < 0)
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
924 l= (-level) ^ ((1 << size) - 1);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
925 else
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
926 l= level;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
927
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
928 /* luminance h263 */
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
929 uni_code= DCtab_lum[size][0];
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
930 uni_len = DCtab_lum[size][1];
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
931 uni_code ^= (1<<uni_len)-1; //M$ doesnt like compatibility
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
932
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
933 if (size > 0) {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
934 uni_code<<=size; uni_code|=l;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
935 uni_len+=size;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
936 if (size > 8){
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
937 uni_code<<=1; uni_code|=1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
938 uni_len++;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
939 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
940 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
941 v2_dc_lum_table[level+256][0]= uni_code;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
942 v2_dc_lum_table[level+256][1]= uni_len;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
943
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
944 /* chrominance h263 */
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
945 uni_code= DCtab_chrom[size][0];
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
946 uni_len = DCtab_chrom[size][1];
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
947 uni_code ^= (1<<uni_len)-1; //M$ doesnt like compatibility
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
948
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
949 if (size > 0) {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
950 uni_code<<=size; uni_code|=l;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
951 uni_len+=size;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
952 if (size > 8){
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
953 uni_code<<=1; uni_code|=1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
954 uni_len++;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
955 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
956 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
957 v2_dc_chroma_table[level+256][0]= uni_code;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
958 v2_dc_chroma_table[level+256][1]= uni_len;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
959
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
960 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
961 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
962
986e461dc072 Initial revision
glantau
parents:
diff changeset
963 /* init all vlc decoding tables */
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
964 int ff_msmpeg4_decode_init(MpegEncContext *s)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
965 {
483
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
966 static int done = 0;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
967 int i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
968 MVTable *mv;
986e461dc072 Initial revision
glantau
parents:
diff changeset
969
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
970 common_init(s);
483
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
971
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
972 if (!done) {
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
973 done = 1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
974
483
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
975 for(i=0;i<NB_RL_TABLES;i++) {
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
976 init_rl(&rl_table[i]);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
977 init_vlc_rl(&rl_table[i]);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
978 }
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
979 for(i=0;i<2;i++) {
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
980 mv = &mv_tables[i];
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
981 init_vlc(&mv->vlc, 9, mv->n + 1,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
982 mv->table_mv_bits, 1, 1,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
983 mv->table_mv_code, 2, 2);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
984 }
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
985
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
986 init_vlc(&dc_lum_vlc[0], 9, 120,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
987 &table0_dc_lum[0][1], 8, 4,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
988 &table0_dc_lum[0][0], 8, 4);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
989 init_vlc(&dc_chroma_vlc[0], 9, 120,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
990 &table0_dc_chroma[0][1], 8, 4,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
991 &table0_dc_chroma[0][0], 8, 4);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
992 init_vlc(&dc_lum_vlc[1], 9, 120,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
993 &table1_dc_lum[0][1], 8, 4,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
994 &table1_dc_lum[0][0], 8, 4);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
995 init_vlc(&dc_chroma_vlc[1], 9, 120,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
996 &table1_dc_chroma[0][1], 8, 4,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
997 &table1_dc_chroma[0][0], 8, 4);
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
998
483
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
999 init_vlc(&v2_dc_lum_vlc, 9, 512,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1000 &v2_dc_lum_table[0][1], 8, 4,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1001 &v2_dc_lum_table[0][0], 8, 4);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1002 init_vlc(&v2_dc_chroma_vlc, 9, 512,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1003 &v2_dc_chroma_table[0][1], 8, 4,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1004 &v2_dc_chroma_table[0][0], 8, 4);
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1005
483
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1006 init_vlc(&cbpy_vlc, 6, 16,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1007 &cbpy_tab[0][1], 2, 1,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1008 &cbpy_tab[0][0], 2, 1);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1009 init_vlc(&v2_intra_cbpc_vlc, 3, 4,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1010 &v2_intra_cbpc[0][1], 2, 1,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1011 &v2_intra_cbpc[0][0], 2, 1);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1012 init_vlc(&v2_mb_type_vlc, 5, 8,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1013 &v2_mb_type[0][1], 2, 1,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1014 &v2_mb_type[0][0], 2, 1);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1015 init_vlc(&v2_mv_vlc, 9, 33,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1016 &mvtab[0][1], 2, 1,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1017 &mvtab[0][0], 2, 1);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1018
483
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1019 init_vlc(&mb_non_intra_vlc, 9, 128,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1020 &table_mb_non_intra[0][1], 8, 4,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1021 &table_mb_non_intra[0][0], 8, 4);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1022 init_vlc(&mb_intra_vlc, 9, 64,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1023 &table_mb_intra[0][1], 4, 2,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1024 &table_mb_intra[0][0], 4, 2);
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1025
483
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1026 init_vlc(&v1_intra_cbpc_vlc, 6, 8,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1027 intra_MCBPC_bits, 1, 1,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1028 intra_MCBPC_code, 1, 1);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1029 init_vlc(&v1_inter_cbpc_vlc, 6, 25,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1030 inter_MCBPC_bits, 1, 1,
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1031 inter_MCBPC_code, 1, 1);
97da217aed7f fixed multiple allocation bug
bellard
parents: 468
diff changeset
1032 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1033 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1034 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1035
986e461dc072 Initial revision
glantau
parents:
diff changeset
1036 static int decode012(GetBitContext *gb)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1037 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1038 int n;
21
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 7
diff changeset
1039 n = get_bits1(gb);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1040 if (n == 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1041 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1042 else
21
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 7
diff changeset
1043 return get_bits1(gb) + 1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1044 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1045
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1046 int msmpeg4_decode_picture_header(MpegEncContext * s)
300
d874359e58f1 msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents: 299
diff changeset
1047 {
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1048 int code;
300
d874359e58f1 msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents: 299
diff changeset
1049
311
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1050 #if 0
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1051 {
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1052 int i;
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1053 for(i=0; i<s->gb.size*8; i++)
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1054 printf("%d", get_bits1(&s->gb));
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1055 // get_bits1(&s->gb);
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1056 printf("END\n");
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1057 return -1;
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1058 }
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1059 #endif
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1060
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1061 if(s->msmpeg4_version==1){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1062 int start_code, num;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1063 start_code = (get_bits(&s->gb, 16)<<16) | get_bits(&s->gb, 16);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1064 if(start_code!=0x00000100){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1065 fprintf(stderr, "invalid startcode\n");
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1066 return -1;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1067 }
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1068
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1069 num= get_bits(&s->gb, 5); // frame number */
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1070 }
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1071
300
d874359e58f1 msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents: 299
diff changeset
1072 s->pict_type = get_bits(&s->gb, 2) + 1;
d874359e58f1 msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents: 299
diff changeset
1073 if (s->pict_type != I_TYPE &&
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1074 s->pict_type != P_TYPE){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1075 fprintf(stderr, "invalid picture type\n");
300
d874359e58f1 msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents: 299
diff changeset
1076 return -1;
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1077 }
300
d874359e58f1 msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents: 299
diff changeset
1078
d874359e58f1 msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents: 299
diff changeset
1079 s->qscale = get_bits(&s->gb, 5);
d874359e58f1 msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents: 299
diff changeset
1080
d874359e58f1 msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents: 299
diff changeset
1081 if (s->pict_type == I_TYPE) {
d874359e58f1 msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents: 299
diff changeset
1082 code = get_bits(&s->gb, 5);
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1083 if(s->msmpeg4_version==1){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1084 if(code==0 || code>s->mb_height){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1085 fprintf(stderr, "invalid slice height %d\n", code);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1086 return -1;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1087 }
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1088
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1089 s->slice_height = code;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1090 }else{
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1091 /* 0x17: one slice, 0x18: two slices, ... */
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1092 if (code < 0x17)
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1093 return -1;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1094
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1095 s->slice_height = s->mb_height / (code - 0x16);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1096 }
311
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1097
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1098 switch(s->msmpeg4_version){
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1099 case 1:
311
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1100 case 2:
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1101 s->rl_chroma_table_index = 2;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1102 s->rl_table_index = 2;
300
d874359e58f1 msmpeg4v2 header parser & some dump bits code behind #if 0
michaelni
parents: 299
diff changeset
1103
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1104 s->dc_table_index = 0; //not used
311
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1105 break;
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1106 case 3:
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1107 s->rl_chroma_table_index = decode012(&s->gb);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1108 s->rl_table_index = decode012(&s->gb);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1109
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1110 s->dc_table_index = get_bits1(&s->gb);
311
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1111 break;
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1112 case 4:
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1113 msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1114
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1115 s->per_mb_rl_table= get_bits1(&s->gb);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1116 if(!s->per_mb_rl_table){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1117 s->rl_chroma_table_index = decode012(&s->gb);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1118 s->rl_table_index = decode012(&s->gb);
311
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1119 }
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1120
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1121 s->dc_table_index = get_bits1(&s->gb);
311
ac677a84d5df wmv1 header parser (unfinished)
michaelni
parents: 310
diff changeset
1122 break;
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1123 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1124 s->no_rounding = 1;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1125 /* printf(" %d %d %d %d %d \n",
200
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1126 s->qscale,
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1127 s->rl_chroma_table_index,
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1128 s->rl_table_index,
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1129 s->dc_table_index,
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1130 s->per_mb_rl_table);*/
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1131 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1132
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1133 switch(s->msmpeg4_version){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1134 case 1:
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1135 case 2:
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1136 if(s->msmpeg4_version==1)
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1137 s->use_skip_mb_code = 1;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1138 else
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1139 s->use_skip_mb_code = get_bits1(&s->gb);
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1140 s->rl_table_index = 2;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1141 s->rl_chroma_table_index = s->rl_table_index;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1142 s->dc_table_index = 0; //not used
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1143 s->mv_table_index = 0;
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1144 break;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1145 case 3:
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1146 s->use_skip_mb_code = get_bits1(&s->gb);
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1147 s->rl_table_index = decode012(&s->gb);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1148 s->rl_chroma_table_index = s->rl_table_index;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1149
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1150 s->dc_table_index = get_bits1(&s->gb);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1151
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1152 s->mv_table_index = get_bits1(&s->gb);
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1153 break;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1154 case 4:
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1155 s->use_skip_mb_code = get_bits1(&s->gb);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1156 s->per_mb_rl_table= get_bits1(&s->gb);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1157 if(!s->per_mb_rl_table){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1158 s->rl_table_index = decode012(&s->gb);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1159 s->rl_chroma_table_index = s->rl_table_index;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1160 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1161
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1162 s->dc_table_index = get_bits1(&s->gb);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1163
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1164 s->mv_table_index = get_bits1(&s->gb);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1165 break;
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1166 }
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1167 /* printf(" %d %d %d %d %d %d \n",
200
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1168 s->use_skip_mb_code,
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1169 s->rl_table_index,
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1170 s->rl_chroma_table_index,
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1171 s->dc_table_index,
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1172 s->mv_table_index,
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1173 s->per_mb_rl_table);*/
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1174 if(s->flipflop_rounding){
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1175 s->no_rounding ^= 1;
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1176 }else{
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1177 s->no_rounding = 0;
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1178 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1179 }
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1180
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1181 s->esc3_level_length= 0;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1182 s->esc3_run_length= 0;
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1183
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1184 #ifdef DEBUG
986e461dc072 Initial revision
glantau
parents:
diff changeset
1185 printf("*****frame %d:\n", frame_count++);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1186 #endif
986e461dc072 Initial revision
glantau
parents:
diff changeset
1187 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1188 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1189
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1190 int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size)
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1191 {
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1192 int left= buf_size*8 - get_bits_count(&s->gb);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1193 int length= s->msmpeg4_version>=3 ? 17 : 16;
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1194 /* the alt_bitstream reader could read over the end so we need to check it */
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1195 if(left>=length && left<length+8)
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1196 {
251
75091bfc577b fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
michaelni
parents: 246
diff changeset
1197 int fps;
75091bfc577b fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
michaelni
parents: 246
diff changeset
1198
75091bfc577b fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
michaelni
parents: 246
diff changeset
1199 fps= get_bits(&s->gb, 5);
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1200 s->bit_rate= get_bits(&s->gb, 11);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1201 if(s->msmpeg4_version>=3)
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1202 s->flipflop_rounding= get_bits1(&s->gb);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1203 else
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1204 s->flipflop_rounding= 0;
251
75091bfc577b fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
michaelni
parents: 246
diff changeset
1205
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1206 // printf("fps:%2d bps:%2d roundingType:%1d\n", fps, s->bit_rate, s->flipflop_rounding);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1207 }
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1208 else if(left<length+8)
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1209 {
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1210 s->flipflop_rounding= 0;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1211 printf("ext header missing, %d left\n", left);
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1212 }
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1213 else
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1214 {
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1215 fprintf(stderr, "I frame too long, ignoring ext header\n");
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1216 }
251
75091bfc577b fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
michaelni
parents: 246
diff changeset
1217
208
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1218 return 0;
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1219 }
2eb04d6be309 (commit by michael)
arpi_esp
parents: 204
diff changeset
1220
440
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1221 static inline void msmpeg4_memsetw(short *tab, int val, int n)
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1222 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1223 int i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1224 for(i=0;i<n;i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1225 tab[i] = val;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1226 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1227
310
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1228 static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1229 {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1230 int range, bit_size, sign, code, bits;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1231
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1232 if (val == 0) {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1233 /* zero vector */
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1234 code = 0;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1235 put_bits(&s->pb, mvtab[code][1], mvtab[code][0]);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1236 } else {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1237 bit_size = s->f_code - 1;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1238 range = 1 << bit_size;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1239 if (val <= -64)
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1240 val += 64;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1241 else if (val >= 64)
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1242 val -= 64;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1243
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1244 if (val >= 0) {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1245 sign = 0;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1246 } else {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1247 val = -val;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1248 sign = 1;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1249 }
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1250 val--;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1251 code = (val >> bit_size) + 1;
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1252 bits = val & (range - 1);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1253
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1254 put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1255 if (bit_size > 0) {
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1256 put_bits(&s->pb, bit_size, bits);
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1257 }
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1258 }
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1259 }
49e73229a5e6 msmpeg4v2 encoding
michaelni
parents: 309
diff changeset
1260
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1261 /* this is identical to h263 except that its range is multiplied by 2 */
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1262 static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1263 {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1264 int code, val, sign, shift;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1265
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1266 code = get_vlc(&s->gb, &v2_mv_vlc);
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1267 // printf("MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred);
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1268 if (code < 0)
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1269 return 0xffff;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1270
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1271 if (code == 0)
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1272 return pred;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1273 sign = get_bits1(&s->gb);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1274 shift = f_code - 1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1275 val = (code - 1) << shift;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1276 if (shift > 0)
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1277 val |= get_bits(&s->gb, shift);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1278 val++;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1279 if (sign)
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1280 val = -val;
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1281
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1282 val += pred;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1283 if (val <= -64)
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1284 val += 64;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1285 else if (val >= 64)
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1286 val -= 64;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1287
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1288 return val;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1289 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1290
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1291
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1292 static int msmpeg4v12_decode_mb(MpegEncContext *s,
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1293 DCTELEM block[6][64])
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1294 {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1295 int cbp, code, i;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1296 if (s->pict_type == P_TYPE) {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1297 if (s->use_skip_mb_code) {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1298 if (get_bits1(&s->gb)) {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1299 /* skip mb */
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1300 s->mb_intra = 0;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1301 for(i=0;i<6;i++)
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1302 s->block_last_index[i] = -1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1303 s->mv_dir = MV_DIR_FORWARD;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1304 s->mv_type = MV_TYPE_16X16;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1305 s->mv[0][0][0] = 0;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1306 s->mv[0][0][1] = 0;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1307 s->mb_skiped = 1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1308 return 0;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1309 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1310 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1311
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1312 if(s->msmpeg4_version==2)
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1313 code = get_vlc(&s->gb, &v2_mb_type_vlc);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1314 else
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1315 code = get_vlc(&s->gb, &v1_inter_cbpc_vlc);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1316 if(code<0 || code>7){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1317 fprintf(stderr, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1318 return -1;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1319 }
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1320
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1321 s->mb_intra = code >>2;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1322
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1323 cbp = code & 0x3;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1324 } else {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1325 s->mb_intra = 1;
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1326 if(s->msmpeg4_version==2)
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1327 cbp= get_vlc(&s->gb, &v2_intra_cbpc_vlc);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1328 else
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1329 cbp= get_vlc(&s->gb, &v1_intra_cbpc_vlc);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1330 if(cbp<0 || cbp>3){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1331 fprintf(stderr, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1332 return -1;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1333 }
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1334 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1335
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1336 if (!s->mb_intra) {
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1337 int mx, my, cbpy;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1338
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1339 cbpy= get_vlc(&s->gb, &cbpy_vlc);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1340 if(cbpy<0){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1341 fprintf(stderr, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1342 return -1;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1343 }
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1344
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1345 cbp|= cbpy<<2;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1346 if(s->msmpeg4_version==1 || (cbp&3) != 3) cbp^= 0x3C;
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1347
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1348 h263_pred_motion(s, 0, &mx, &my);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1349 mx= msmpeg4v2_decode_motion(s, mx, 1);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1350 my= msmpeg4v2_decode_motion(s, my, 1);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1351
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1352 s->mv_dir = MV_DIR_FORWARD;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1353 s->mv_type = MV_TYPE_16X16;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1354 s->mv[0][0][0] = mx;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1355 s->mv[0][0][1] = my;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1356 } else {
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1357 if(s->msmpeg4_version==2){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1358 s->ac_pred = get_bits1(&s->gb);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1359 cbp|= get_vlc(&s->gb, &cbpy_vlc)<<2; //FIXME check errors
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1360 } else{
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1361 s->ac_pred = 0;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1362 cbp|= get_vlc(&s->gb, &cbpy_vlc)<<2; //FIXME check errors
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1363 if(s->pict_type==P_TYPE) cbp^=0x3C;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1364 }
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1365 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1366
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1367 for (i = 0; i < 6; i++) {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1368 if (msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0)
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1369 {
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1370 fprintf(stderr,"\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1371 return -1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1372 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1373 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1374 return 0;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1375 }
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1376
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1377 int msmpeg4_decode_mb(MpegEncContext *s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
1378 DCTELEM block[6][64])
986e461dc072 Initial revision
glantau
parents:
diff changeset
1379 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1380 int cbp, code, i;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1381 UINT8 *coded_val;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1382
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1383 #ifdef PRINT_MB
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1384 if(s->mb_x==0){
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1385 printf("\n");
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1386 if(s->mb_y==0) printf("\n");
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1387 }
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1388 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1389 /* special slice handling */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1390 if (s->mb_x == 0) {
122
56e34b70ef5d * prevent crash in decoder
kabi
parents: 48
diff changeset
1391 if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1392 int wrap;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1393 /* reset DC pred (set previous line to 1024) */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1394 wrap = 2 * s->mb_width + 2;
440
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1395 msmpeg4_memsetw(&s->dc_val[0][(1) + (2 * s->mb_y) * wrap],
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1396 1024, 2 * s->mb_width);
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1397 wrap = s->mb_width + 2;
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1398 msmpeg4_memsetw(&s->dc_val[1][(1) + (s->mb_y) * wrap],
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1399 1024, s->mb_width);
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1400 msmpeg4_memsetw(&s->dc_val[2][(1) + (s->mb_y) * wrap],
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1401 1024, s->mb_width);
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1402
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1403 /* reset AC pred (set previous line to 0) */
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1404 wrap = s->mb_width * 2 + 2;
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1405 msmpeg4_memsetw(s->ac_val[0][0] + (1 + (2 * s->mb_y) * wrap)*16,
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1406 0, 2 * s->mb_width*16);
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1407 wrap = s->mb_width + 2;
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1408 msmpeg4_memsetw(s->ac_val[1][0] + (1 + (s->mb_y) * wrap)*16,
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1409 0, s->mb_width*16);
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1410 msmpeg4_memsetw(s->ac_val[2][0] + (1 + (s->mb_y) * wrap)*16,
000aeeac27a2 * started to cleanup name clashes for onetime compilation
kabi
parents: 429
diff changeset
1411 0, s->mb_width*16);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1412
986e461dc072 Initial revision
glantau
parents:
diff changeset
1413 s->first_slice_line = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1414 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1415 s->first_slice_line = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1416 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1417 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1418
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1419 if(s->msmpeg4_version<=2) return msmpeg4v12_decode_mb(s, block); //FIXME export function & call from outside perhaps
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1420
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1421 if (s->pict_type == P_TYPE) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1422 set_stat(ST_INTER_MB);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1423 if (s->use_skip_mb_code) {
21
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 7
diff changeset
1424 if (get_bits1(&s->gb)) {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1425 /* skip mb */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1426 s->mb_intra = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1427 for(i=0;i<6;i++)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1428 s->block_last_index[i] = -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1429 s->mv_dir = MV_DIR_FORWARD;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1430 s->mv_type = MV_TYPE_16X16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1431 s->mv[0][0][0] = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1432 s->mv[0][0][1] = 0;
7
1d3ac9654178 added skip macroblock optimization (big perf win on black regions for example)
glantau
parents: 0
diff changeset
1433 s->mb_skiped = 1;
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1434 #ifdef PRINT_MB
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1435 printf("S ");
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1436 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1437 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1438 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1439 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1440
986e461dc072 Initial revision
glantau
parents:
diff changeset
1441 code = get_vlc(&s->gb, &mb_non_intra_vlc);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1442 if (code < 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1443 return -1;
246
214ac77c0948 * simplified indexing
kabi
parents: 228
diff changeset
1444 //s->mb_intra = (code & 0x40) ? 0 : 1;
214ac77c0948 * simplified indexing
kabi
parents: 228
diff changeset
1445 s->mb_intra = (~code & 0x40) >> 6;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1446
986e461dc072 Initial revision
glantau
parents:
diff changeset
1447 cbp = code & 0x3f;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1448 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1449 set_stat(ST_INTRA_MB);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1450 s->mb_intra = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1451 code = get_vlc(&s->gb, &mb_intra_vlc);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1452 if (code < 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1453 return -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1454 /* predict coded block pattern */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1455 cbp = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1456 for(i=0;i<6;i++) {
246
214ac77c0948 * simplified indexing
kabi
parents: 228
diff changeset
1457 int val = ((code >> (5 - i)) & 1);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1458 if (i < 4) {
246
214ac77c0948 * simplified indexing
kabi
parents: 228
diff changeset
1459 int pred = coded_block_pred(s, i, &coded_val);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1460 val = val ^ pred;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1461 *coded_val = val;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1462 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1463 cbp |= val << (5 - i);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1464 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1465 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1466
986e461dc072 Initial revision
glantau
parents:
diff changeset
1467 if (!s->mb_intra) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1468 int mx, my;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1469 //printf("P at %d %d\n", s->mb_x, s->mb_y);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1470 if(s->per_mb_rl_table && cbp){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1471 s->rl_table_index = decode012(&s->gb);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1472 s->rl_chroma_table_index = s->rl_table_index;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1473 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1474 set_stat(ST_MV);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1475 h263_pred_motion(s, 0, &mx, &my);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1476 if (msmpeg4_decode_motion(s, &mx, &my) < 0)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1477 return -1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1478 s->mv_dir = MV_DIR_FORWARD;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1479 s->mv_type = MV_TYPE_16X16;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1480 s->mv[0][0][0] = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1481 s->mv[0][0][1] = my;
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1482 #ifdef PRINT_MB
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1483 printf("P ");
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1484 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1485 } else {
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1486 //printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24));
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1487 set_stat(ST_INTRA_MB);
21
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 7
diff changeset
1488 s->ac_pred = get_bits1(&s->gb);
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1489 #ifdef PRINT_MB
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1490 printf("%c", s->ac_pred ? 'A' : 'I');
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1491 #endif
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1492 if(s->per_mb_rl_table && cbp){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1493 s->rl_table_index = decode012(&s->gb);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1494 s->rl_chroma_table_index = s->rl_table_index;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1495 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1496 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1497
986e461dc072 Initial revision
glantau
parents:
diff changeset
1498 for (i = 0; i < 6; i++) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1499 if (msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0)
246
214ac77c0948 * simplified indexing
kabi
parents: 228
diff changeset
1500 {
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1501 fprintf(stderr,"\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1502 return -1;
246
214ac77c0948 * simplified indexing
kabi
parents: 228
diff changeset
1503 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1504 }
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1505
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1506 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1507 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1508
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1509 static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1510 int n, int coded)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1511 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1512 int code, level, i, j, last, run, run_diff;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1513 int dc_pred_dir;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1514 RLTable *rl;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1515 const UINT8 *scan_table;
200
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1516 int qmul, qadd;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1517
986e461dc072 Initial revision
glantau
parents:
diff changeset
1518 if (s->mb_intra) {
200
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1519 qmul=1;
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1520 qadd=0;
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1521
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1522 /* DC coef */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1523 set_stat(ST_DC);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1524 level = msmpeg4_decode_dc(s, n, &dc_pred_dir);
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1525 #ifdef PRINT_MB
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1526 {
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1527 static int c;
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1528 if(n==0) c=0;
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1529 if(n==4) printf("%X", c);
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1530 c+= c +dc_pred_dir;
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1531 }
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1532 #endif
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1533 if (level < 0){
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1534 fprintf(stderr, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1535 return -1;
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1536 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1537 if (n < 4) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1538 rl = &rl_table[s->rl_table_index];
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1539 if(level > 256*s->y_dc_scale){
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1540 fprintf(stderr, "dc overflow+ L qscale: %d//\n", s->qscale);
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1541 return -1;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1542 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1543 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1544 rl = &rl_table[3 + s->rl_chroma_table_index];
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1545 if(level > 256*s->c_dc_scale){
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1546 fprintf(stderr, "dc overflow+ C qscale: %d//\n", s->qscale);
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1547 return -1;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1548 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1549 }
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1550 block[0] = level;
200
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1551
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1552 run_diff = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1553 i = 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1554 if (!coded) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1555 goto not_coded;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1556 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1557 if (s->ac_pred) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1558 if (dc_pred_dir == 0)
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1559 scan_table = s->intra_v_scantable; /* left */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1560 else
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1561 scan_table = s->intra_h_scantable; /* top */
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1562 } else {
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1563 scan_table = s->intra_scantable;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1564 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1565 set_stat(ST_INTRA_AC);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1566 } else {
200
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1567 qmul = s->qscale << 1;
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1568 qadd = (s->qscale - 1) | 1;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1569 i = 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1570 rl = &rl_table[3 + s->rl_table_index];
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1571
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1572 if(s->msmpeg4_version==2)
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1573 run_diff = 0;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1574 else
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1575 run_diff = 1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1576
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1577 if (!coded) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1578 s->block_last_index[n] = i - 1;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1579 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1580 }
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1581 scan_table = s->inter_scantable;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1582 set_stat(ST_INTER_AC);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1583 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1584
986e461dc072 Initial revision
glantau
parents:
diff changeset
1585 for(;;) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1586 code = get_vlc(&s->gb, &rl->vlc);
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1587 if (code < 0){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1588 fprintf(stderr, "illegal AC-VLC code at %d %d\n", s->mb_x, s->mb_y);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1589 return -1;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1590 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1591 if (code == rl->n) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1592 /* escape */
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1593 if (s->msmpeg4_version==1 || get_bits1(&s->gb) == 0) {
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1594 if (s->msmpeg4_version==1 || get_bits1(&s->gb) == 0) {
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1595 /* third escape */
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1596 if(s->msmpeg4_version<=3){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1597 last= get_bits1(&s->gb);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1598 run= get_bits(&s->gb, 6);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1599 level= get_bits(&s->gb, 8);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1600 level= ((int8_t)level);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1601 }else{
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1602 int sign;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1603 last= get_bits1(&s->gb);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1604 if(!s->esc3_level_length){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1605 int ll;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1606 //printf("ESC-3 %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1607 if(s->qscale<8){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1608 ll= get_bits(&s->gb, 3);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1609 if(ll==0){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1610 if(get_bits1(&s->gb)) printf("cool a new vlc code ,contact the ffmpeg developers and upload the file\n");
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1611 ll=8;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1612 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1613 }else{
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1614 ll=2;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1615 while(ll<8 && get_bits1(&s->gb)==0) ll++;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1616 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1617
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1618 s->esc3_level_length= ll;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1619 s->esc3_run_length= get_bits(&s->gb, 2) + 3;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1620 //printf("level length:%d, run length: %d\n", ll, s->esc3_run_length);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1621 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1622 run= get_bits(&s->gb, s->esc3_run_length);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1623 sign= get_bits1(&s->gb);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1624 level= get_bits(&s->gb, s->esc3_level_length);
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1625 if(sign) level= -level;
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1626 }
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1627 //printf("level: %d, run: %d at %d %d\n", level, run, s->mb_x, s->mb_y);
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1628 #if 0 // waste of time / this will detect very few errors
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1629 {
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1630 const int abs_level= ABS(level);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1631 const int run1= run - rl->max_run[last][abs_level] - run_diff;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1632 if(abs_level<=MAX_LEVEL && run<=MAX_RUN){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1633 if(abs_level <= rl->max_level[last][run]){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1634 fprintf(stderr, "illegal 3. esc, vlc encoding possible\n");
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1635 return DECODING_AC_LOST;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1636 }
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1637 if(abs_level <= rl->max_level[last][run]*2){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1638 fprintf(stderr, "illegal 3. esc, esc 1 encoding possible\n");
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1639 return DECODING_AC_LOST;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1640 }
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1641 if(run1>=0 && abs_level <= rl->max_level[last][run1]){
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1642 fprintf(stderr, "illegal 3. esc, esc 2 encoding possible\n");
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1643 return DECODING_AC_LOST;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1644 }
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1645 }
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1646 }
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1647 #endif
246
214ac77c0948 * simplified indexing
kabi
parents: 228
diff changeset
1648 //level = level * qmul + (level>0) * qadd - (level<=0) * qadd ;
214ac77c0948 * simplified indexing
kabi
parents: 228
diff changeset
1649 if (level>0) level= level * qmul + qadd;
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1650 else level= level * qmul - qadd;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1651 #if 0 // waste of time too :(
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1652 if(level>2048 || level<-2048){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1653 fprintf(stderr, "|level| overflow in 3. esc\n");
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1654 return DECODING_AC_LOST;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1655 }
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1656 #endif
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1657 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1658 /* second escape */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1659 code = get_vlc(&s->gb, &rl->vlc);
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1660 if (code < 0 || code >= rl->n){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1661 fprintf(stderr, "illegal ESC2-VLC code %d at %d %d\n", code, s->mb_x, s->mb_y);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1662 return -1;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1663 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1664 run = rl->table_run[code];
201
91ed656e7339 (commit by michael)
arpi_esp
parents: 200
diff changeset
1665 level = rl->table_level[code];
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1666 last = code >= rl->last;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1667 run += rl->max_run[last][level] + run_diff;
201
91ed656e7339 (commit by michael)
arpi_esp
parents: 200
diff changeset
1668 level= level * qmul + qadd;
21
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 7
diff changeset
1669 if (get_bits1(&s->gb))
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1670 level = -level;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1671 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1672 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1673 /* first escape */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1674 code = get_vlc(&s->gb, &rl->vlc);
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1675 if (code < 0 || code >= rl->n){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1676 fprintf(stderr, "illegal ESC2-VLC code %d at %d %d\n", code, s->mb_x, s->mb_y);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1677 return -1;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1678 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1679 run = rl->table_run[code];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1680 level = rl->table_level[code];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1681 last = code >= rl->last;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1682 level += rl->max_level[last][run];
200
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1683 level= level * qmul + qadd;
21
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 7
diff changeset
1684 if (get_bits1(&s->gb))
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1685 level = -level;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1686 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1687 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1688 run = rl->table_run[code];
200
6ab301aaa652 (commit by michael)
arpi_esp
parents: 195
diff changeset
1689 level = rl->table_level[code] * qmul + qadd;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1690 last = code >= rl->last;
21
20e680e7a490 get_bits() specialization, gives 4\speedup
arpi_esp
parents: 7
diff changeset
1691 if (get_bits1(&s->gb))
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1692 level = -level;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1693 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1694 i += run;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1695 if (i >= 64){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1696 fprintf(stderr, "run too long at %d %d\n", s->mb_x, s->mb_y);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1697 return -1;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1698 }
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1699
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1700 j = scan_table[i];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1701 block[j] = level;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1702 i++;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1703 if (last)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1704 break;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1705 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1706 not_coded:
986e461dc072 Initial revision
glantau
parents:
diff changeset
1707 if (s->mb_intra) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1708 mpeg4_pred_ac(s, block, n, dc_pred_dir);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1709 if (s->ac_pred) {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1710 i = 64; /* XXX: not optimal */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1711 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1712 }
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1713 if(s->msmpeg4_version==4 && i>1) i=64; //FIXME/XXX optimize
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1714 s->block_last_index[n] = i - 1;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1715
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1716 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1717 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1718
986e461dc072 Initial revision
glantau
parents:
diff changeset
1719 static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1720 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1721 int level, pred;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1722
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1723 if(s->msmpeg4_version<=2){
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1724 if (n < 4) {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1725 level = get_vlc(&s->gb, &v2_dc_lum_vlc);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1726 } else {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1727 level = get_vlc(&s->gb, &v2_dc_chroma_vlc);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1728 }
309
32485ad4cc4e fixing msmpeg4v2 bugs (is bugfree now afaik)
michaelni
parents: 307
diff changeset
1729 if (level < 0)
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1730 return -1;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1731 level-=256;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1732 }else{ //FIXME optimize use unified tables & index
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1733 if (n < 4) {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1734 level = get_vlc(&s->gb, &dc_lum_vlc[s->dc_table_index]);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1735 } else {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1736 level = get_vlc(&s->gb, &dc_chroma_vlc[s->dc_table_index]);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1737 }
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1738 if (level < 0){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1739 fprintf(stderr, "illegal dc vlc\n");
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1740 return -1;
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1741 }
307
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1742
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1743 if (level == DC_MAX) {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1744 level = get_bits(&s->gb, 8);
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1745 if (get_bits1(&s->gb))
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1746 level = -level;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1747 } else if (level != 0) {
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1748 if (get_bits1(&s->gb))
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1749 level = -level;
764aeec1320e msmpeg4v2 decoding (no encoding yet)
michaelni
parents: 300
diff changeset
1750 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1751 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1752
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1753 if(s->msmpeg4_version==1){
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1754 INT32 *dc_val;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1755 pred = msmpeg4v1_pred_dc(s, n, &dc_val);
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1756 level += pred;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1757
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1758 /* update predictor */
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1759 *dc_val= level;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1760 }else{
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1761 UINT16 *dc_val;
501
2241bce35bb9 fixing wmv1 bugs, it was foolish to belive that m$ would use the same dc prediction as mpeg4 just cuz they changed it a bit from msmpeg4v3
michaelni
parents: 499
diff changeset
1762 pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1763 level += pred;
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1764
457
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1765 /* update predictor */
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1766 if (n < 4) {
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1767 *dc_val = level * s->y_dc_scale;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1768 } else {
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1769 *dc_val = level * s->c_dc_scale;
583dcee270d2 msmpeg4v1 decoding
michaelni
parents: 440
diff changeset
1770 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1771 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1772
986e461dc072 Initial revision
glantau
parents:
diff changeset
1773 return level;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1774 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1775
986e461dc072 Initial revision
glantau
parents:
diff changeset
1776 static int msmpeg4_decode_motion(MpegEncContext * s,
986e461dc072 Initial revision
glantau
parents:
diff changeset
1777 int *mx_ptr, int *my_ptr)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1778 {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1779 MVTable *mv;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1780 int code, mx, my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1781
986e461dc072 Initial revision
glantau
parents:
diff changeset
1782 mv = &mv_tables[s->mv_table_index];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1783
986e461dc072 Initial revision
glantau
parents:
diff changeset
1784 code = get_vlc(&s->gb, &mv->vlc);
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1785 if (code < 0){
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1786 fprintf(stderr, "illegal MV code at %d %d\n", s->mb_x, s->mb_y);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1787 return -1;
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1788 }
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1789 if (code == mv->n) {
499
8b7a54d58549 wmv1 support
michaelni
parents: 483
diff changeset
1790 //printf("MV ESC %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
1791 mx = get_bits(&s->gb, 6);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1792 my = get_bits(&s->gb, 6);
986e461dc072 Initial revision
glantau
parents:
diff changeset
1793 } else {
986e461dc072 Initial revision
glantau
parents:
diff changeset
1794 mx = mv->table_mvx[code];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1795 my = mv->table_mvy[code];
986e461dc072 Initial revision
glantau
parents:
diff changeset
1796 }
986e461dc072 Initial revision
glantau
parents:
diff changeset
1797
986e461dc072 Initial revision
glantau
parents:
diff changeset
1798 mx += *mx_ptr - 32;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1799 my += *my_ptr - 32;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1800 /* WARNING : they do not do exactly modulo encoding */
986e461dc072 Initial revision
glantau
parents:
diff changeset
1801 if (mx <= -64)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1802 mx += 64;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1803 else if (mx >= 64)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1804 mx -= 64;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1805
986e461dc072 Initial revision
glantau
parents:
diff changeset
1806 if (my <= -64)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1807 my += 64;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1808 else if (my >= 64)
986e461dc072 Initial revision
glantau
parents:
diff changeset
1809 my -= 64;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1810 *mx_ptr = mx;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1811 *my_ptr = my;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1812 return 0;
986e461dc072 Initial revision
glantau
parents:
diff changeset
1813 }