Mercurial > libavcodec.hg
annotate h263.c @ 648:dddcff6841f2 libavcodec
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
author | michaelni |
---|---|
date | Sat, 07 Sep 2002 00:16:30 +0000 |
parents | 2be2cc8fd0a1 |
children | 850098147a3c |
rev | line source |
---|---|
0 | 1 /* |
2 * H263/MPEG4 backend for ffmpeg encoder and decoder | |
429 | 3 * Copyright (c) 2000,2001 Fabrice Bellard. |
78 | 4 * H263+ support. |
0 | 5 * Copyright (c) 2001 Juan J. Sierralta P. |
6 * | |
429 | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Lesser General Public | |
9 * License as published by the Free Software Foundation; either | |
10 * version 2 of the License, or (at your option) any later version. | |
0 | 11 * |
429 | 12 * This library is distributed in the hope that it will be useful, |
0 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Lesser General Public License for more details. | |
0 | 16 * |
429 | 17 * You should have received a copy of the GNU Lesser General Public |
18 * License along with this library; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
20 * |
327 | 21 * ac prediction encoding & b-frame support by Michael Niedermayer <michaelni@gmx.at> |
0 | 22 */ |
355 | 23 |
24 //#define DEBUG | |
0 | 25 #include "common.h" |
26 #include "dsputil.h" | |
27 #include "avcodec.h" | |
28 #include "mpegvideo.h" | |
29 #include "h263data.h" | |
30 #include "mpeg4data.h" | |
31 | |
255 | 32 //rounded divison & shift |
33 #define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b)) | |
34 | |
523 | 35 #define PRINT_MB_TYPE(a) {} |
36 //#define PRINT_MB_TYPE(a) printf(a) | |
359 | 37 |
544 | 38 #define INTRA_MCBPC_VLC_BITS 6 |
39 #define INTER_MCBPC_VLC_BITS 6 | |
40 #define CBPY_VLC_BITS 6 | |
41 #define MV_VLC_BITS 9 | |
42 #define DC_VLC_BITS 9 | |
43 #define SPRITE_TRAJ_VLC_BITS 6 | |
44 #define MB_TYPE_B_VLC_BITS 4 | |
45 #define TEX_VLC_BITS 9 | |
46 | |
0 | 47 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, |
48 int n); | |
324 | 49 static void h263_encode_motion(MpegEncContext * s, int val, int fcode); |
78 | 50 static void h263p_encode_umotion(MpegEncContext * s, int val); |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
51 static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, |
453 | 52 int n, int dc, UINT8 *scan_table, |
53 PutBitContext *dc_pb, PutBitContext *ac_pb); | |
262 | 54 static int h263_decode_motion(MpegEncContext * s, int pred, int fcode); |
78 | 55 static int h263p_decode_umotion(MpegEncContext * s, int pred); |
0 | 56 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
57 int n, int coded); | |
453 | 58 static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr); |
59 static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | |
575 | 60 int n, int coded, int intra); |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
61 static int h263_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr); |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
62 static void mpeg4_inv_pred_ac(MpegEncContext * s, INT16 *block, int n, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
63 int dir); |
290 | 64 static void mpeg4_decode_sprite_trajectory(MpegEncContext * s); |
65 | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
66 extern UINT32 inverse[256]; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
67 |
292
73a9ce3d9715
fcode_tables where too small, found by Klaas-Pieter Vlieg <vlieg@eurescom.de>
michaelni
parents:
291
diff
changeset
|
68 static UINT16 mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
69 static UINT8 fcode_tab[MAX_MV*2+1]; |
287 | 70 static UINT8 umv_fcode_tab[MAX_MV*2+1]; |
0 | 71 |
293 | 72 static UINT16 uni_DCtab_lum [512][2]; |
73 static UINT16 uni_DCtab_chrom[512][2]; | |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
74 static UINT32 uni_mpeg4_intra_rl_bits[64*64*2*2]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
75 static UINT8 uni_mpeg4_intra_rl_len [64*64*2*2]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
76 static UINT32 uni_mpeg4_inter_rl_bits[64*64*2*2]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
77 static UINT8 uni_mpeg4_inter_rl_len [64*64*2*2]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
78 #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level)) |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
79 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64) |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
80 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
81 /* mpeg4 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
82 inter |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
83 max level: 24/6 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
84 max run: 53/63 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
85 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
86 intra |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
87 max level: 53/16 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
88 max run: 29/41 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
89 */ |
293 | 90 |
0 | 91 int h263_get_picture_format(int width, int height) |
92 { | |
93 int format; | |
94 | |
95 if (width == 128 && height == 96) | |
355 | 96 format = 1; |
0 | 97 else if (width == 176 && height == 144) |
355 | 98 format = 2; |
0 | 99 else if (width == 352 && height == 288) |
355 | 100 format = 3; |
0 | 101 else if (width == 704 && height == 576) |
355 | 102 format = 4; |
0 | 103 else if (width == 1408 && height == 1152) |
355 | 104 format = 5; |
0 | 105 else |
106 format = 7; | |
107 return format; | |
108 } | |
109 | |
110 void h263_encode_picture_header(MpegEncContext * s, int picture_number) | |
111 { | |
78 | 112 int format; |
0 | 113 |
114 align_put_bits(&s->pb); | |
231 | 115 |
116 /* Update the pointer to last GOB */ | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
117 s->ptr_lastgob = pbBufPtr(&s->pb); |
231 | 118 s->gob_number = 0; |
119 | |
120 put_bits(&s->pb, 22, 0x20); /* PSC */ | |
241 | 121 put_bits(&s->pb, 8, (((INT64)s->picture_number * 30 * FRAME_RATE_BASE) / |
0 | 122 s->frame_rate) & 0xff); |
123 | |
124 put_bits(&s->pb, 1, 1); /* marker */ | |
125 put_bits(&s->pb, 1, 0); /* h263 id */ | |
126 put_bits(&s->pb, 1, 0); /* split screen off */ | |
127 put_bits(&s->pb, 1, 0); /* camera off */ | |
128 put_bits(&s->pb, 1, 0); /* freeze picture release off */ | |
78 | 129 |
130 format = h263_get_picture_format(s->width, s->height); | |
0 | 131 if (!s->h263_plus) { |
132 /* H.263v1 */ | |
133 put_bits(&s->pb, 3, format); | |
134 put_bits(&s->pb, 1, (s->pict_type == P_TYPE)); | |
135 /* By now UMV IS DISABLED ON H.263v1, since the restrictions | |
136 of H.263v1 UMV implies to check the predicted MV after | |
137 calculation of the current MB to see if we're on the limits */ | |
138 put_bits(&s->pb, 1, 0); /* unrestricted motion vector: off */ | |
139 put_bits(&s->pb, 1, 0); /* SAC: off */ | |
140 put_bits(&s->pb, 1, 0); /* advanced prediction mode: off */ | |
141 put_bits(&s->pb, 1, 0); /* not PB frame */ | |
142 put_bits(&s->pb, 5, s->qscale); | |
143 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ | |
144 } else { | |
145 /* H.263v2 */ | |
146 /* H.263 Plus PTYPE */ | |
147 put_bits(&s->pb, 3, 7); | |
148 put_bits(&s->pb,3,1); /* Update Full Extended PTYPE */ | |
78 | 149 if (format == 7) |
150 put_bits(&s->pb,3,6); /* Custom Source Format */ | |
151 else | |
152 put_bits(&s->pb, 3, format); | |
153 | |
0 | 154 put_bits(&s->pb,1,0); /* Custom PCF: off */ |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
155 s->umvplus = (s->pict_type == P_TYPE) && s->unrestricted_mv; |
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
156 put_bits(&s->pb, 1, s->umvplus); /* Unrestricted Motion Vector */ |
0 | 157 put_bits(&s->pb,1,0); /* SAC: off */ |
158 put_bits(&s->pb,1,0); /* Advanced Prediction Mode: off */ | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
159 put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */ |
0 | 160 put_bits(&s->pb,1,0); /* Deblocking Filter: off */ |
161 put_bits(&s->pb,1,0); /* Slice Structured: off */ | |
162 put_bits(&s->pb,1,0); /* Reference Picture Selection: off */ | |
163 put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */ | |
164 put_bits(&s->pb,1,0); /* Alternative Inter VLC: off */ | |
165 put_bits(&s->pb,1,0); /* Modified Quantization: off */ | |
166 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
167 put_bits(&s->pb,3,0); /* Reserved */ | |
168 | |
169 put_bits(&s->pb, 3, s->pict_type == P_TYPE); | |
170 | |
171 put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */ | |
172 put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */ | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
173 if (s->pict_type == I_TYPE) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
174 s->no_rounding = 0; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
175 else |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
176 s->no_rounding ^= 1; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
177 put_bits(&s->pb,1,s->no_rounding); /* Rounding Type */ |
0 | 178 put_bits(&s->pb,2,0); /* Reserved */ |
179 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
180 | |
181 /* This should be here if PLUSPTYPE */ | |
182 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ | |
183 | |
78 | 184 if (format == 7) { |
185 /* Custom Picture Format (CPFMT) */ | |
0 | 186 |
355 | 187 if (s->aspect_ratio_info) |
188 put_bits(&s->pb,4,s->aspect_ratio_info); | |
189 else | |
78 | 190 put_bits(&s->pb,4,2); /* Aspect ratio: CIF 12:11 (4:3) picture */ |
191 put_bits(&s->pb,9,(s->width >> 2) - 1); | |
192 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
193 put_bits(&s->pb,9,(s->height >> 2)); | |
194 } | |
195 | |
0 | 196 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
197 if (s->umvplus) |
0 | 198 put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ |
199 put_bits(&s->pb, 5, s->qscale); | |
200 } | |
201 | |
202 put_bits(&s->pb, 1, 0); /* no PEI */ | |
498 | 203 |
204 if(s->h263_aic){ | |
205 s->y_dc_scale_table= | |
206 s->c_dc_scale_table= h263_aic_dc_scale_table; | |
207 }else{ | |
208 s->y_dc_scale_table= | |
209 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
210 } | |
0 | 211 } |
212 | |
162 | 213 int h263_encode_gob_header(MpegEncContext * s, int mb_line) |
214 { | |
215 int pdif=0; | |
216 | |
217 /* Check to see if we need to put a new GBSC */ | |
218 /* for RTP packetization */ | |
219 if (s->rtp_mode) { | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
220 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
162 | 221 if (pdif >= s->rtp_payload_size) { |
222 /* Bad luck, packet must be cut before */ | |
223 align_put_bits(&s->pb); | |
231 | 224 flush_put_bits(&s->pb); |
225 /* Call the RTP callback to send the last GOB */ | |
226 if (s->rtp_callback) { | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
227 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
231 | 228 s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); |
229 } | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
230 s->ptr_lastgob = pbBufPtr(&s->pb); |
162 | 231 put_bits(&s->pb, 17, 1); /* GBSC */ |
231 | 232 s->gob_number = mb_line / s->gob_index; |
162 | 233 put_bits(&s->pb, 5, s->gob_number); /* GN */ |
231 | 234 put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */ |
162 | 235 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ |
231 | 236 //fprintf(stderr,"\nGOB: %2d size: %d", s->gob_number - 1, pdif); |
162 | 237 return pdif; |
238 } else if (pdif + s->mb_line_avgsize >= s->rtp_payload_size) { | |
239 /* Cut the packet before we can't */ | |
240 align_put_bits(&s->pb); | |
231 | 241 flush_put_bits(&s->pb); |
242 /* Call the RTP callback to send the last GOB */ | |
243 if (s->rtp_callback) { | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
244 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
231 | 245 s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); |
246 } | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
247 s->ptr_lastgob = pbBufPtr(&s->pb); |
162 | 248 put_bits(&s->pb, 17, 1); /* GBSC */ |
231 | 249 s->gob_number = mb_line / s->gob_index; |
162 | 250 put_bits(&s->pb, 5, s->gob_number); /* GN */ |
231 | 251 put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */ |
162 | 252 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ |
231 | 253 //fprintf(stderr,"\nGOB: %2d size: %d", s->gob_number - 1, pdif); |
162 | 254 return pdif; |
255 } | |
256 } | |
257 return 0; | |
258 } | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
259 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
260 static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], int dir[6]) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
261 { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
262 int score0=0, score1=0; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
263 int i, n; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
264 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
265 for(n=0; n<6; n++){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
266 INT16 *ac_val, *ac_val1; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
267 |
266 | 268 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
269 ac_val1= ac_val; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
270 if(dir[n]){ |
266 | 271 ac_val-= s->block_wrap[n]*16; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
272 for(i=1; i<8; i++){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
273 const int level= block[n][block_permute_op(i )]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
274 score0+= ABS(level); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
275 score1+= ABS(level - ac_val[i+8]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
276 ac_val1[i ]= block[n][block_permute_op(i<<3)]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
277 ac_val1[i+8]= level; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
278 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
279 }else{ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
280 ac_val-= 16; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
281 for(i=1; i<8; i++){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
282 const int level= block[n][block_permute_op(i<<3)]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
283 score0+= ABS(level); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
284 score1+= ABS(level - ac_val[i]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
285 ac_val1[i ]= level; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
286 ac_val1[i+8]= block[n][block_permute_op(i )]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
287 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
288 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
289 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
290 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
291 return score0 > score1 ? 1 : 0; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
292 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
293 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
294 void mpeg4_encode_mb(MpegEncContext * s, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
295 DCTELEM block[6][64], |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
296 int motion_x, int motion_y) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
297 { |
324 | 298 int cbpc, cbpy, i, pred_x, pred_y; |
286 | 299 int bits; |
453 | 300 PutBitContext * const pb2 = s->data_partitioning ? &s->pb2 : &s->pb; |
301 PutBitContext * const tex_pb = s->data_partitioning && s->pict_type!=B_TYPE ? &s->tex_pb : &s->pb; | |
302 PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=I_TYPE ? &s->pb2 : &s->pb; | |
303 const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1) && !s->data_partitioning ? 1 : 0; | |
162 | 304 |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
305 // printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
306 if (!s->mb_intra) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
307 /* compute cbp */ |
324 | 308 int cbp = 0; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
309 for (i = 0; i < 6; i++) { |
324 | 310 if (s->block_last_index[i] >= 0) |
311 cbp |= 1 << (5 - i); | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
312 } |
324 | 313 |
314 if(s->pict_type==B_TYPE){ | |
315 static const int mb_type_table[8]= {-1, 2, 3, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */ | |
316 int mb_type= mb_type_table[s->mv_dir]; | |
317 | |
318 if(s->mb_x==0){ | |
319 s->last_mv[0][0][0]= | |
320 s->last_mv[0][0][1]= | |
321 s->last_mv[1][0][0]= | |
322 s->last_mv[1][0][1]= 0; | |
323 } | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
324 |
324 | 325 /* nothing to do if this MB was skiped in the next P Frame */ |
326 if(s->mbskip_table[s->mb_y * s->mb_width + s->mb_x]){ | |
327 s->skip_count++; | |
328 s->mv[0][0][0]= | |
329 s->mv[0][0][1]= | |
330 s->mv[1][0][0]= | |
331 s->mv[1][0][1]= 0; | |
327 | 332 s->mv_dir= MV_DIR_FORWARD; //doesnt matter |
324 | 333 return; |
334 } | |
335 | |
336 if ((cbp | motion_x | motion_y | mb_type) ==0) { | |
337 /* direct MB with MV={0,0} */ | |
338 put_bits(&s->pb, 1, 1); /* mb not coded modb1=1 */ | |
453 | 339 |
340 if(interleaved_stats){ | |
341 s->misc_bits++; | |
342 s->last_bits++; | |
343 } | |
324 | 344 s->skip_count++; |
345 return; | |
346 } | |
347 put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */ | |
348 put_bits(&s->pb, 1, cbp ? 0 : 1); /* modb2 */ //FIXME merge | |
349 put_bits(&s->pb, mb_type+1, 1); // this table is so simple that we dont need it :) | |
350 if(cbp) put_bits(&s->pb, 6, cbp); | |
351 | |
352 if(cbp && mb_type) | |
353 put_bits(&s->pb, 1, 0); /* no q-scale change */ | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
354 |
453 | 355 if(interleaved_stats){ |
356 bits= get_bit_count(&s->pb); | |
357 s->misc_bits+= bits - s->last_bits; | |
358 s->last_bits=bits; | |
359 } | |
295 | 360 |
324 | 361 switch(mb_type) |
362 { | |
363 case 0: /* direct */ | |
364 h263_encode_motion(s, motion_x, 1); | |
365 h263_encode_motion(s, motion_y, 1); | |
366 break; | |
367 case 1: /* bidir */ | |
368 h263_encode_motion(s, s->mv[0][0][0] - s->last_mv[0][0][0], s->f_code); | |
369 h263_encode_motion(s, s->mv[0][0][1] - s->last_mv[0][0][1], s->f_code); | |
370 h263_encode_motion(s, s->mv[1][0][0] - s->last_mv[1][0][0], s->b_code); | |
371 h263_encode_motion(s, s->mv[1][0][1] - s->last_mv[1][0][1], s->b_code); | |
372 s->last_mv[0][0][0]= s->mv[0][0][0]; | |
373 s->last_mv[0][0][1]= s->mv[0][0][1]; | |
374 s->last_mv[1][0][0]= s->mv[1][0][0]; | |
375 s->last_mv[1][0][1]= s->mv[1][0][1]; | |
376 break; | |
377 case 2: /* backward */ | |
378 h263_encode_motion(s, motion_x - s->last_mv[1][0][0], s->b_code); | |
379 h263_encode_motion(s, motion_y - s->last_mv[1][0][1], s->b_code); | |
380 s->last_mv[1][0][0]= motion_x; | |
381 s->last_mv[1][0][1]= motion_y; | |
382 break; | |
383 case 3: /* forward */ | |
384 h263_encode_motion(s, motion_x - s->last_mv[0][0][0], s->f_code); | |
385 h263_encode_motion(s, motion_y - s->last_mv[0][0][1], s->f_code); | |
386 s->last_mv[0][0][0]= motion_x; | |
387 s->last_mv[0][0][1]= motion_y; | |
388 break; | |
327 | 389 default: |
390 printf("unknown mb type\n"); | |
324 | 391 return; |
392 } | |
453 | 393 |
394 if(interleaved_stats){ | |
395 bits= get_bit_count(&s->pb); | |
396 s->mv_bits+= bits - s->last_bits; | |
397 s->last_bits=bits; | |
398 } | |
295 | 399 |
324 | 400 /* encode each block */ |
401 for (i = 0; i < 6; i++) { | |
453 | 402 mpeg4_encode_block(s, block[i], i, 0, zigzag_direct, NULL, &s->pb); |
324 | 403 } |
453 | 404 |
405 if(interleaved_stats){ | |
406 bits= get_bit_count(&s->pb); | |
407 s->p_tex_bits+= bits - s->last_bits; | |
408 s->last_bits=bits; | |
409 } | |
324 | 410 }else{ /* s->pict_type==B_TYPE */ |
411 if ((cbp | motion_x | motion_y) == 0 && s->mv_type==MV_TYPE_16X16) { | |
331 | 412 /* check if the B frames can skip it too, as we must skip it if we skip here |
413 why didnt they just compress the skip-mb bits instead of reusing them ?! */ | |
414 if(s->max_b_frames>0){ | |
415 int i; | |
364
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
416 int x,y, offset; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
417 uint8_t *p_pic; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
418 |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
419 x= s->mb_x*16; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
420 y= s->mb_y*16; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
421 if(x+16 > s->width) x= s->width-16; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
422 if(y+16 > s->height) y= s->height-16; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
423 |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
424 offset= x + y*s->linesize; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
425 p_pic= s->new_picture[0] + offset; |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
426 |
331 | 427 s->mb_skiped=1; |
428 for(i=0; i<s->max_b_frames; i++){ | |
339 | 429 uint8_t *b_pic; |
430 int diff; | |
431 | |
432 if(s->coded_order[i+1].pict_type!=B_TYPE) break; | |
433 | |
434 b_pic= s->coded_order[i+1].picture[0] + offset; | |
435 diff= pix_abs16x16(p_pic, b_pic, s->linesize); | |
364
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
436 if(diff>s->qscale*70){ //FIXME check that 70 is optimal |
331 | 437 s->mb_skiped=0; |
438 break; | |
439 } | |
440 } | |
441 }else | |
442 s->mb_skiped=1; | |
443 | |
444 if(s->mb_skiped==1){ | |
445 /* skip macroblock */ | |
446 put_bits(&s->pb, 1, 1); | |
453 | 447 |
448 if(interleaved_stats){ | |
449 s->misc_bits++; | |
450 s->last_bits++; | |
451 } | |
331 | 452 s->skip_count++; |
453 return; | |
454 } | |
295 | 455 } |
364
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
456 |
324 | 457 put_bits(&s->pb, 1, 0); /* mb coded */ |
458 if(s->mv_type==MV_TYPE_16X16){ | |
459 cbpc = cbp & 3; | |
460 put_bits(&s->pb, | |
461 inter_MCBPC_bits[cbpc], | |
462 inter_MCBPC_code[cbpc]); | |
463 cbpy = cbp >> 2; | |
464 cbpy ^= 0xf; | |
453 | 465 put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
324 | 466 |
453 | 467 if(interleaved_stats){ |
468 bits= get_bit_count(&s->pb); | |
469 s->misc_bits+= bits - s->last_bits; | |
470 s->last_bits=bits; | |
471 } | |
324 | 472 |
473 /* motion vectors: 16x16 mode */ | |
474 h263_pred_motion(s, 0, &pred_x, &pred_y); | |
475 | |
476 h263_encode_motion(s, motion_x - pred_x, s->f_code); | |
477 h263_encode_motion(s, motion_y - pred_y, s->f_code); | |
478 }else{ | |
479 cbpc = (cbp & 3)+16; | |
480 put_bits(&s->pb, | |
481 inter_MCBPC_bits[cbpc], | |
482 inter_MCBPC_code[cbpc]); | |
483 cbpy = cbp >> 2; | |
484 cbpy ^= 0xf; | |
453 | 485 put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
486 | |
487 if(interleaved_stats){ | |
488 bits= get_bit_count(&s->pb); | |
489 s->misc_bits+= bits - s->last_bits; | |
490 s->last_bits=bits; | |
491 } | |
324 | 492 |
493 for(i=0; i<4; i++){ | |
494 /* motion vectors: 8x8 mode*/ | |
495 h263_pred_motion(s, i, &pred_x, &pred_y); | |
496 | |
497 h263_encode_motion(s, s->motion_val[ s->block_index[i] ][0] - pred_x, s->f_code); | |
498 h263_encode_motion(s, s->motion_val[ s->block_index[i] ][1] - pred_y, s->f_code); | |
499 } | |
500 } | |
453 | 501 |
502 if(interleaved_stats){ | |
503 bits= get_bit_count(&s->pb); | |
504 s->mv_bits+= bits - s->last_bits; | |
505 s->last_bits=bits; | |
506 } | |
324 | 507 |
508 /* encode each block */ | |
509 for (i = 0; i < 6; i++) { | |
453 | 510 mpeg4_encode_block(s, block[i], i, 0, zigzag_direct, NULL, tex_pb); |
324 | 511 } |
453 | 512 |
513 if(interleaved_stats){ | |
514 bits= get_bit_count(&s->pb); | |
515 s->p_tex_bits+= bits - s->last_bits; | |
516 s->last_bits=bits; | |
517 } | |
324 | 518 s->p_count++; |
295 | 519 } |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
520 } else { |
324 | 521 int cbp; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
522 int dc_diff[6]; //dc values with the dc prediction subtracted |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
523 int dir[6]; //prediction direction |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
524 int zigzag_last_index[6]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
525 UINT8 *scan_table[6]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
526 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
527 for(i=0; i<6; i++){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
528 const int level= block[i][0]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
529 UINT16 *dc_ptr; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
530 |
498 | 531 dc_diff[i]= level - ff_mpeg4_pred_dc(s, i, &dc_ptr, &dir[i]); |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
532 if (i < 4) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
533 *dc_ptr = level * s->y_dc_scale; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
534 } else { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
535 *dc_ptr = level * s->c_dc_scale; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
536 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
537 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
538 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
539 s->ac_pred= decide_ac_pred(s, block, dir); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
540 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
541 if(s->ac_pred){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
542 for(i=0; i<6; i++){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
543 UINT8 *st; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
544 int last_index; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
545 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
546 mpeg4_inv_pred_ac(s, block[i], i, dir[i]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
547 if (dir[i]==0) st = ff_alternate_vertical_scan; /* left */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
548 else st = ff_alternate_horizontal_scan; /* top */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
549 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
550 for(last_index=63; last_index>=0; last_index--) //FIXME optimize |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
551 if(block[i][st[last_index]]) break; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
552 zigzag_last_index[i]= s->block_last_index[i]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
553 s->block_last_index[i]= last_index; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
554 scan_table[i]= st; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
555 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
556 }else{ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
557 for(i=0; i<6; i++) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
558 scan_table[i]= zigzag_direct; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
559 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
560 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
561 /* compute cbp */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
562 cbp = 0; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
563 for (i = 0; i < 6; i++) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
564 if (s->block_last_index[i] >= 1) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
565 cbp |= 1 << (5 - i); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
566 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
567 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
568 cbpc = cbp & 3; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
569 if (s->pict_type == I_TYPE) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
570 put_bits(&s->pb, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
571 intra_MCBPC_bits[cbpc], |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
572 intra_MCBPC_code[cbpc]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
573 } else { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
574 put_bits(&s->pb, 1, 0); /* mb coded */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
575 put_bits(&s->pb, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
576 inter_MCBPC_bits[cbpc + 4], |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
577 inter_MCBPC_code[cbpc + 4]); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
578 } |
453 | 579 put_bits(pb2, 1, s->ac_pred); |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
580 cbpy = cbp >> 2; |
453 | 581 put_bits(pb2, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
582 | |
583 if(interleaved_stats){ | |
584 bits= get_bit_count(&s->pb); | |
585 s->misc_bits+= bits - s->last_bits; | |
586 s->last_bits=bits; | |
587 } | |
286 | 588 |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
589 /* encode each block */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
590 for (i = 0; i < 6; i++) { |
453 | 591 mpeg4_encode_block(s, block[i], i, dc_diff[i], scan_table[i], dc_pb, tex_pb); |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
592 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
593 |
453 | 594 if(interleaved_stats){ |
595 bits= get_bit_count(&s->pb); | |
596 s->i_tex_bits+= bits - s->last_bits; | |
597 s->last_bits=bits; | |
598 } | |
286 | 599 s->i_count++; |
600 | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
601 /* restore ac coeffs & last_index stuff if we messed them up with the prediction */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
602 if(s->ac_pred){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
603 for(i=0; i<6; i++){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
604 int j; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
605 INT16 *ac_val; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
606 |
266 | 607 ac_val = s->ac_val[0][0] + s->block_index[i] * 16; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
608 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
609 if(dir[i]){ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
610 for(j=1; j<8; j++) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
611 block[i][block_permute_op(j )]= ac_val[j+8]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
612 }else{ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
613 for(j=1; j<8; j++) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
614 block[i][block_permute_op(j<<3)]= ac_val[j ]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
615 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
616 s->block_last_index[i]= zigzag_last_index[i]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
617 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
618 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
619 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
620 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
621 |
0 | 622 void h263_encode_mb(MpegEncContext * s, |
623 DCTELEM block[6][64], | |
624 int motion_x, int motion_y) | |
625 { | |
626 int cbpc, cbpy, i, cbp, pred_x, pred_y; | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
627 INT16 pred_dc; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
628 INT16 rec_intradc[6]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
629 UINT16 *dc_ptr[6]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
630 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
631 //printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); |
324 | 632 if (!s->mb_intra) { |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
633 /* compute cbp */ |
324 | 634 cbp = 0; |
635 for (i = 0; i < 6; i++) { | |
636 if (s->block_last_index[i] >= 0) | |
637 cbp |= 1 << (5 - i); | |
638 } | |
639 if ((cbp | motion_x | motion_y) == 0) { | |
640 /* skip macroblock */ | |
641 put_bits(&s->pb, 1, 1); | |
642 return; | |
643 } | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
644 put_bits(&s->pb, 1, 0); /* mb coded */ |
324 | 645 cbpc = cbp & 3; |
646 put_bits(&s->pb, | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
647 inter_MCBPC_bits[cbpc], |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
648 inter_MCBPC_code[cbpc]); |
324 | 649 cbpy = cbp >> 2; |
650 cbpy ^= 0xf; | |
651 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | |
0 | 652 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
653 /* motion vectors: 16x16 mode only now */ |
324 | 654 h263_pred_motion(s, 0, &pred_x, &pred_y); |
78 | 655 |
324 | 656 if (!s->umvplus) { |
657 h263_encode_motion(s, motion_x - pred_x, s->f_code); | |
658 h263_encode_motion(s, motion_y - pred_y, s->f_code); | |
659 } | |
660 else { | |
661 h263p_encode_umotion(s, motion_x - pred_x); | |
662 h263p_encode_umotion(s, motion_y - pred_y); | |
663 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
664 /* To prevent Start Code emulation */ |
324 | 665 put_bits(&s->pb,1,1); |
666 } | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
667 } else { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
668 int li = s->h263_aic ? 0 : 1; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
669 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
670 cbp = 0; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
671 for(i=0; i<6; i++) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
672 /* Predict DC */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
673 if (s->h263_aic && s->mb_intra) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
674 INT16 level = block[i][0]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
675 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
676 pred_dc = h263_pred_dc(s, i, &dc_ptr[i]); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
677 level -= pred_dc; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
678 /* Quant */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
679 if (level < 0) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
680 level = (level + (s->qscale >> 1))/(s->y_dc_scale); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
681 else |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
682 level = (level - (s->qscale >> 1))/(s->y_dc_scale); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
683 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
684 /* AIC can change CBP */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
685 if (level == 0 && s->block_last_index[i] == 0) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
686 s->block_last_index[i] = -1; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
687 else if (level < -127) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
688 level = -127; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
689 else if (level > 127) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
690 level = 127; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
691 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
692 block[i][0] = level; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
693 /* Reconstruction */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
694 rec_intradc[i] = (s->y_dc_scale*level) + pred_dc; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
695 /* Oddify */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
696 rec_intradc[i] |= 1; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
697 //if ((rec_intradc[i] % 2) == 0) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
698 // rec_intradc[i]++; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
699 /* Clipping */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
700 if (rec_intradc[i] < 0) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
701 rec_intradc[i] = 0; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
702 else if (rec_intradc[i] > 2047) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
703 rec_intradc[i] = 2047; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
704 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
705 /* Update AC/DC tables */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
706 *dc_ptr[i] = rec_intradc[i]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
707 } |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
708 /* compute cbp */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
709 if (s->block_last_index[i] >= li) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
710 cbp |= 1 << (5 - i); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
711 } |
0 | 712 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
713 cbpc = cbp & 3; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
714 if (s->pict_type == I_TYPE) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
715 put_bits(&s->pb, |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
716 intra_MCBPC_bits[cbpc], |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
717 intra_MCBPC_code[cbpc]); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
718 } else { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
719 put_bits(&s->pb, 1, 0); /* mb coded */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
720 put_bits(&s->pb, |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
721 inter_MCBPC_bits[cbpc + 4], |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
722 inter_MCBPC_code[cbpc + 4]); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
723 } |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
724 if (s->h263_aic) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
725 /* XXX: currently, we do not try to use ac prediction */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
726 put_bits(&s->pb, 1, 0); /* no AC prediction */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
727 } |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
728 cbpy = cbp >> 2; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
729 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
0 | 730 } |
731 | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
732 for(i=0; i<6; i++) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
733 /* encode each block */ |
294 | 734 h263_encode_block(s, block[i], i); |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
735 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
736 /* Update INTRADC for decoding */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
737 if (s->h263_aic && s->mb_intra) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
738 block[i][0] = rec_intradc[i]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
739 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
740 } |
0 | 741 } |
742 } | |
743 | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
744 static int h263_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
745 { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
746 int x, y, wrap, a, c, pred_dc, scale; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
747 INT16 *dc_val, *ac_val; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
748 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
749 /* find prediction */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
750 if (n < 4) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
751 x = 2 * s->mb_x + 1 + (n & 1); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
752 y = 2 * s->mb_y + 1 + ((n & 2) >> 1); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
753 wrap = s->mb_width * 2 + 2; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
754 dc_val = s->dc_val[0]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
755 ac_val = s->ac_val[0][0]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
756 scale = s->y_dc_scale; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
757 } else { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
758 x = s->mb_x + 1; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
759 y = s->mb_y + 1; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
760 wrap = s->mb_width + 2; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
761 dc_val = s->dc_val[n - 4 + 1]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
762 ac_val = s->ac_val[n - 4 + 1][0]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
763 scale = s->c_dc_scale; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
764 } |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
765 /* B C |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
766 * A X |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
767 */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
768 a = dc_val[(x - 1) + (y) * wrap]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
769 c = dc_val[(x) + (y - 1) * wrap]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
770 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
771 /* No prediction outside GOB boundary */ |
453 | 772 if (s->first_slice_line && ((n < 2) || (n > 3))) |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
773 c = 1024; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
774 pred_dc = 1024; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
775 /* just DC prediction */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
776 if (a != 1024 && c != 1024) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
777 pred_dc = (a + c) >> 1; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
778 else if (a != 1024) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
779 pred_dc = a; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
780 else |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
781 pred_dc = c; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
782 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
783 /* we assume pred is positive */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
784 //pred_dc = (pred_dc + (scale >> 1)) / scale; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
785 *dc_val_ptr = &dc_val[x + y * wrap]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
786 return pred_dc; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
787 } |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
788 |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
789 |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
790 void h263_pred_acdc(MpegEncContext * s, INT16 *block, int n) |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
791 { |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
792 int x, y, wrap, a, c, pred_dc, scale, i; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
793 INT16 *dc_val, *ac_val, *ac_val1; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
794 |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
795 /* find prediction */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
796 if (n < 4) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
797 x = 2 * s->mb_x + 1 + (n & 1); |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
798 y = 2 * s->mb_y + 1 + ((n & 2) >> 1); |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
799 wrap = s->mb_width * 2 + 2; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
800 dc_val = s->dc_val[0]; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
801 ac_val = s->ac_val[0][0]; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
802 scale = s->y_dc_scale; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
803 } else { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
804 x = s->mb_x + 1; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
805 y = s->mb_y + 1; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
806 wrap = s->mb_width + 2; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
807 dc_val = s->dc_val[n - 4 + 1]; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
808 ac_val = s->ac_val[n - 4 + 1][0]; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
809 scale = s->c_dc_scale; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
810 } |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
811 |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
812 ac_val += ((y) * wrap + (x)) * 16; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
813 ac_val1 = ac_val; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
814 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
815 /* B C |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
816 * A X |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
817 */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
818 a = dc_val[(x - 1) + (y) * wrap]; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
819 c = dc_val[(x) + (y - 1) * wrap]; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
820 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
821 /* No prediction outside GOB boundary */ |
453 | 822 if (s->first_slice_line && ((n < 2) || (n > 3))) |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
823 c = 1024; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
824 pred_dc = 1024; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
825 if (s->ac_pred) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
826 if (s->h263_aic_dir) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
827 /* left prediction */ |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
828 if (a != 1024) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
829 ac_val -= 16; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
830 for(i=1;i<8;i++) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
831 block[block_permute_op(i*8)] += ac_val[i]; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
832 } |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
833 pred_dc = a; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
834 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
835 } else { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
836 /* top prediction */ |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
837 if (c != 1024) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
838 ac_val -= 16 * wrap; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
839 for(i=1;i<8;i++) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
840 block[block_permute_op(i)] += ac_val[i + 8]; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
841 } |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
842 pred_dc = c; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
843 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
844 } |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
845 } else { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
846 /* just DC prediction */ |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
847 if (a != 1024 && c != 1024) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
848 pred_dc = (a + c) >> 1; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
849 else if (a != 1024) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
850 pred_dc = a; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
851 else |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
852 pred_dc = c; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
853 } |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
854 |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
855 /* we assume pred is positive */ |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
856 block[0]=block[0]*scale + pred_dc; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
857 |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
858 if (block[0] < 0) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
859 block[0] = 0; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
860 else if (!(block[0] & 1)) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
861 block[0]++; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
862 |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
863 /* Update AC/DC tables */ |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
864 dc_val[(x) + (y) * wrap] = block[0]; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
865 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
866 /* left copy */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
867 for(i=1;i<8;i++) |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
868 ac_val1[i] = block[block_permute_op(i * 8)]; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
869 /* top copy */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
870 for(i=1;i<8;i++) |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
871 ac_val1[8 + i] = block[block_permute_op(i)]; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
872 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
873 |
0 | 874 INT16 *h263_pred_motion(MpegEncContext * s, int block, |
875 int *px, int *py) | |
876 { | |
266 | 877 int xy, wrap; |
0 | 878 INT16 *A, *B, *C, *mot_val; |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
879 static const int off[4]= {2, 1, 1, -1}; |
0 | 880 |
266 | 881 wrap = s->block_wrap[0]; |
882 xy = s->block_index[block]; | |
0 | 883 |
245 | 884 mot_val = s->motion_val[xy]; |
0 | 885 |
453 | 886 A = s->motion_val[xy - 1]; |
887 /* special case for first (slice) line */ | |
888 if ((s->mb_y == 0 || s->first_slice_line) && block<3) { | |
889 // we cant just change some MVs to simulate that as we need them for the B frames (and ME) | |
890 // and if we ever support non rectangular objects than we need to do a few ifs here anyway :( | |
891 if(block==0){ //most common case | |
892 if(s->mb_x == s->resync_mb_x){ //rare | |
893 *px= *py = 0; | |
894 }else if(s->mb_x + 1 == s->resync_mb_x){ //rare | |
895 C = s->motion_val[xy + off[block] - wrap]; | |
896 if(s->mb_x==0){ | |
897 *px = C[0]; | |
898 *py = C[1]; | |
899 }else{ | |
900 *px = mid_pred(A[0], 0, C[0]); | |
901 *py = mid_pred(A[1], 0, C[1]); | |
902 } | |
903 }else{ | |
904 *px = A[0]; | |
905 *py = A[1]; | |
906 } | |
907 }else if(block==1){ | |
908 if(s->mb_x + 1 == s->resync_mb_x){ //rare | |
909 C = s->motion_val[xy + off[block] - wrap]; | |
910 *px = mid_pred(A[0], 0, C[0]); | |
911 *py = mid_pred(A[1], 0, C[1]); | |
912 }else{ | |
913 *px = A[0]; | |
914 *py = A[1]; | |
915 } | |
916 }else{ /* block==2*/ | |
917 B = s->motion_val[xy - wrap]; | |
918 C = s->motion_val[xy + off[block] - wrap]; | |
919 if(s->mb_x == s->resync_mb_x) //rare | |
920 A[0]=A[1]=0; | |
921 | |
922 *px = mid_pred(A[0], B[0], C[0]); | |
923 *py = mid_pred(A[1], B[1], C[1]); | |
924 } | |
0 | 925 } else { |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
926 B = s->motion_val[xy - wrap]; |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
927 C = s->motion_val[xy + off[block] - wrap]; |
0 | 928 *px = mid_pred(A[0], B[0], C[0]); |
929 *py = mid_pred(A[1], B[1], C[1]); | |
930 } | |
931 return mot_val; | |
932 } | |
933 | |
324 | 934 static void h263_encode_motion(MpegEncContext * s, int val, int f_code) |
0 | 935 { |
936 int range, l, m, bit_size, sign, code, bits; | |
937 | |
938 if (val == 0) { | |
939 /* zero vector */ | |
940 code = 0; | |
941 put_bits(&s->pb, mvtab[code][1], mvtab[code][0]); | |
942 } else { | |
324 | 943 bit_size = f_code - 1; |
0 | 944 range = 1 << bit_size; |
945 /* modulo encoding */ | |
946 l = range * 32; | |
947 m = 2 * l; | |
948 if (val < -l) { | |
949 val += m; | |
950 } else if (val >= l) { | |
951 val -= m; | |
952 } | |
953 | |
954 if (val >= 0) { | |
955 sign = 0; | |
956 } else { | |
957 val = -val; | |
958 sign = 1; | |
959 } | |
312 | 960 val--; |
961 code = (val >> bit_size) + 1; | |
962 bits = val & (range - 1); | |
0 | 963 |
964 put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); | |
965 if (bit_size > 0) { | |
966 put_bits(&s->pb, bit_size, bits); | |
967 } | |
968 } | |
969 } | |
970 | |
78 | 971 /* Encode MV differences on H.263+ with Unrestricted MV mode */ |
972 static void h263p_encode_umotion(MpegEncContext * s, int val) | |
973 { | |
974 short sval = 0; | |
975 short i = 0; | |
976 short n_bits = 0; | |
977 short temp_val; | |
978 int code = 0; | |
979 int tcode; | |
980 | |
981 if ( val == 0) | |
982 put_bits(&s->pb, 1, 1); | |
983 else if (val == 1) | |
984 put_bits(&s->pb, 3, 0); | |
985 else if (val == -1) | |
986 put_bits(&s->pb, 3, 2); | |
987 else { | |
988 | |
989 sval = ((val < 0) ? (short)(-val):(short)val); | |
990 temp_val = sval; | |
991 | |
992 while (temp_val != 0) { | |
993 temp_val = temp_val >> 1; | |
994 n_bits++; | |
995 } | |
996 | |
997 i = n_bits - 1; | |
998 while (i > 0) { | |
999 tcode = (sval & (1 << (i-1))) >> (i-1); | |
1000 tcode = (tcode << 1) | 1; | |
1001 code = (code << 2) | tcode; | |
1002 i--; | |
1003 } | |
1004 code = ((code << 1) | (val < 0)) << 1; | |
1005 put_bits(&s->pb, (2*n_bits)+1, code); | |
1006 //printf("\nVal = %d\tCode = %d", sval, code); | |
1007 } | |
1008 } | |
1009 | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1010 static void init_mv_penalty_and_fcode(MpegEncContext *s) |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1011 { |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1012 int f_code; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1013 int mv; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1014 for(f_code=1; f_code<=MAX_FCODE; f_code++){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1015 for(mv=-MAX_MV; mv<=MAX_MV; mv++){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1016 int len; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1017 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1018 if(mv==0) len= mvtab[0][1]; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1019 else{ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1020 int val, bit_size, range, code; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1021 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1022 bit_size = s->f_code - 1; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1023 range = 1 << bit_size; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1024 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1025 val=mv; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1026 if (val < 0) |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1027 val = -val; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1028 val--; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1029 code = (val >> bit_size) + 1; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1030 if(code<33){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1031 len= mvtab[code][1] + 1 + bit_size; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1032 }else{ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1033 len= mvtab[32][1] + 2 + bit_size; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1034 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1035 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1036 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1037 mv_penalty[f_code][mv+MAX_MV]= len; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1038 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1039 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1040 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1041 for(f_code=MAX_FCODE; f_code>0; f_code--){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1042 for(mv=-(16<<f_code); mv<(16<<f_code); mv++){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1043 fcode_tab[mv+MAX_MV]= f_code; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1044 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1045 } |
287 | 1046 |
1047 for(mv=0; mv<MAX_MV*2+1; mv++){ | |
1048 umv_fcode_tab[mv]= 1; | |
1049 } | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1050 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1051 |
468 | 1052 static void init_uni_dc_tab(void) |
293 | 1053 { |
1054 int level, uni_code, uni_len; | |
1055 | |
312 | 1056 for(level=-256; level<256; level++){ |
293 | 1057 int size, v, l; |
1058 /* find number of bits */ | |
1059 size = 0; | |
1060 v = abs(level); | |
1061 while (v) { | |
1062 v >>= 1; | |
1063 size++; | |
1064 } | |
1065 | |
1066 if (level < 0) | |
1067 l= (-level) ^ ((1 << size) - 1); | |
1068 else | |
1069 l= level; | |
1070 | |
1071 /* luminance */ | |
1072 uni_code= DCtab_lum[size][0]; | |
1073 uni_len = DCtab_lum[size][1]; | |
1074 | |
1075 if (size > 0) { | |
1076 uni_code<<=size; uni_code|=l; | |
1077 uni_len+=size; | |
1078 if (size > 8){ | |
1079 uni_code<<=1; uni_code|=1; | |
1080 uni_len++; | |
1081 } | |
1082 } | |
1083 uni_DCtab_lum[level+256][0]= uni_code; | |
1084 uni_DCtab_lum[level+256][1]= uni_len; | |
1085 | |
1086 /* chrominance */ | |
1087 uni_code= DCtab_chrom[size][0]; | |
1088 uni_len = DCtab_chrom[size][1]; | |
1089 | |
1090 if (size > 0) { | |
1091 uni_code<<=size; uni_code|=l; | |
1092 uni_len+=size; | |
1093 if (size > 8){ | |
1094 uni_code<<=1; uni_code|=1; | |
1095 uni_len++; | |
1096 } | |
1097 } | |
1098 uni_DCtab_chrom[level+256][0]= uni_code; | |
1099 uni_DCtab_chrom[level+256][1]= uni_len; | |
1100 | |
1101 } | |
1102 } | |
1103 | |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1104 static void init_uni_mpeg4_rl_tab(RLTable *rl, UINT32 *bits_tab, UINT8 *len_tab){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1105 int slevel, run, last; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1106 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1107 assert(MAX_LEVEL >= 64); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1108 assert(MAX_RUN >= 63); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1109 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1110 for(slevel=-64; slevel<64; slevel++){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1111 if(slevel==0) continue; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1112 for(run=0; run<64; run++){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1113 for(last=0; last<=1; last++){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1114 const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1115 int level= slevel < 0 ? -slevel : slevel; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1116 int sign= slevel < 0 ? 1 : 0; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1117 int bits, len, code; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1118 int level1, run1; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1119 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1120 len_tab[index]= 100; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1121 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1122 /* ESC0 */ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1123 code= get_rl_index(rl, last, run, level); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1124 bits= rl->table_vlc[code][0]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1125 len= rl->table_vlc[code][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1126 bits=bits*2+sign; len++; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1127 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1128 if(code!=rl->n && len < len_tab[index]){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1129 bits_tab[index]= bits; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1130 len_tab [index]= len; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1131 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1132 #if 1 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1133 /* ESC1 */ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1134 bits= rl->table_vlc[rl->n][0]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1135 len= rl->table_vlc[rl->n][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1136 bits=bits*2; len++; //esc1 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1137 level1= level - rl->max_level[last][run]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1138 if(level1>0){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1139 code= get_rl_index(rl, last, run, level1); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1140 bits<<= rl->table_vlc[code][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1141 len += rl->table_vlc[code][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1142 bits += rl->table_vlc[code][0]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1143 bits=bits*2+sign; len++; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1144 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1145 if(code!=rl->n && len < len_tab[index]){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1146 bits_tab[index]= bits; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1147 len_tab [index]= len; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1148 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1149 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1150 #endif |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1151 #if 1 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1152 /* ESC2 */ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1153 bits= rl->table_vlc[rl->n][0]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1154 len= rl->table_vlc[rl->n][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1155 bits=bits*4+2; len+=2; //esc2 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1156 run1 = run - rl->max_run[last][level] - 1; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1157 if(run1>=0){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1158 code= get_rl_index(rl, last, run1, level); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1159 bits<<= rl->table_vlc[code][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1160 len += rl->table_vlc[code][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1161 bits += rl->table_vlc[code][0]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1162 bits=bits*2+sign; len++; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1163 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1164 if(code!=rl->n && len < len_tab[index]){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1165 bits_tab[index]= bits; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1166 len_tab [index]= len; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1167 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1168 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1169 #endif |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1170 /* ESC3 */ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1171 bits= rl->table_vlc[rl->n][0]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1172 len = rl->table_vlc[rl->n][1]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1173 bits=bits*4+3; len+=2; //esc3 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1174 bits=bits*2+last; len++; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1175 bits=bits*64+run; len+=6; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1176 bits=bits*2+1; len++; //marker |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1177 bits=bits*4096+(slevel&0xfff); len+=12; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1178 bits=bits*2+1; len++; //marker |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1179 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1180 if(len < len_tab[index]){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1181 bits_tab[index]= bits; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1182 len_tab [index]= len; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1183 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1184 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1185 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1186 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1187 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1188 |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1189 void h263_encode_init(MpegEncContext *s) |
0 | 1190 { |
1191 static int done = 0; | |
1192 | |
1193 if (!done) { | |
1194 done = 1; | |
293 | 1195 |
1196 init_uni_dc_tab(); | |
1197 | |
0 | 1198 init_rl(&rl_inter); |
1199 init_rl(&rl_intra); | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1200 init_rl(&rl_intra_aic); |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1201 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1202 init_uni_mpeg4_rl_tab(&rl_intra, uni_mpeg4_intra_rl_bits, uni_mpeg4_intra_rl_len); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1203 init_uni_mpeg4_rl_tab(&rl_inter, uni_mpeg4_inter_rl_bits, uni_mpeg4_inter_rl_len); |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1204 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1205 init_mv_penalty_and_fcode(s); |
0 | 1206 } |
287 | 1207 s->mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1208 |
287 | 1209 // use fcodes >1 only for mpeg4 & h263 & h263p FIXME |
344 | 1210 switch(s->codec_id){ |
1211 case CODEC_ID_MPEG4: | |
1212 s->fcode_tab= fcode_tab; | |
1213 s->min_qcoeff= -2048; | |
1214 s->max_qcoeff= 2047; | |
1215 break; | |
1216 case CODEC_ID_H263P: | |
1217 s->fcode_tab= umv_fcode_tab; | |
1218 s->min_qcoeff= -128; | |
1219 s->max_qcoeff= 127; | |
1220 break; | |
498 | 1221 //Note for mpeg4 & h263 the dc-scale table will be set per frame as needed later |
344 | 1222 default: //nothing needed default table allready set in mpegvideo.c |
1223 s->min_qcoeff= -128; | |
1224 s->max_qcoeff= 127; | |
498 | 1225 s->y_dc_scale_table= |
1226 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
344 | 1227 } |
1228 | |
599 | 1229 if(s->mpeg_quant){ |
1230 s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x | |
1231 s->inter_quant_bias= 0; | |
1232 }else{ | |
1233 s->intra_quant_bias=0; | |
1234 s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x | |
1235 } | |
0 | 1236 } |
1237 | |
1238 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n) | |
1239 { | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1240 int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1241 RLTable *rl; |
0 | 1242 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1243 rl = &rl_inter; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1244 if (s->mb_intra && !s->h263_aic) { |
231 | 1245 /* DC coef */ |
1246 level = block[0]; | |
0 | 1247 /* 255 cannot be represented, so we clamp */ |
1248 if (level > 254) { | |
1249 level = 254; | |
1250 block[0] = 254; | |
1251 } | |
231 | 1252 /* 0 cannot be represented also */ |
1253 else if (!level) { | |
1254 level = 1; | |
1255 block[0] = 1; | |
1256 } | |
1257 if (level == 128) | |
1258 put_bits(&s->pb, 8, 0xff); | |
1259 else | |
1260 put_bits(&s->pb, 8, level & 0xff); | |
1261 i = 1; | |
0 | 1262 } else { |
231 | 1263 i = 0; |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1264 if (s->h263_aic && s->mb_intra) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1265 rl = &rl_intra_aic; |
0 | 1266 } |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1267 |
0 | 1268 /* AC coefs */ |
1269 last_index = s->block_last_index[n]; | |
1270 last_non_zero = i - 1; | |
1271 for (; i <= last_index; i++) { | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1272 j = zigzag_direct[i]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1273 level = block[j]; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1274 if (level) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1275 run = i - last_non_zero - 1; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1276 last = (i == last_index); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1277 sign = 0; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1278 slevel = level; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1279 if (level < 0) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1280 sign = 1; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1281 level = -level; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1282 } |
0 | 1283 code = get_rl_index(rl, last, run, level); |
1284 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
1285 if (code == rl->n) { | |
1286 put_bits(&s->pb, 1, last); | |
1287 put_bits(&s->pb, 6, run); | |
1288 put_bits(&s->pb, 8, slevel & 0xff); | |
1289 } else { | |
1290 put_bits(&s->pb, 1, sign); | |
1291 } | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1292 last_non_zero = i; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
1293 } |
0 | 1294 } |
1295 } | |
1296 | |
1297 /***************************************************/ | |
1298 | |
453 | 1299 void ff_mpeg4_stuffing(PutBitContext * pbc) |
262 | 1300 { |
1301 int length; | |
1302 put_bits(pbc, 1, 0); | |
1303 length= (-get_bit_count(pbc))&7; | |
453 | 1304 if(length) put_bits(pbc, length, (1<<length)-1); |
262 | 1305 } |
1306 | |
327 | 1307 /* must be called before writing the header */ |
1308 void ff_set_mpeg4_time(MpegEncContext * s, int picture_number){ | |
1309 int time_div, time_mod; | |
1310 | |
1311 if(s->pict_type==I_TYPE){ //we will encode a vol header | |
1312 s->time_increment_resolution= s->frame_rate/ff_gcd(s->frame_rate, FRAME_RATE_BASE); | |
1313 if(s->time_increment_resolution>=256*256) s->time_increment_resolution= 256*128; | |
1314 | |
1315 s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1; | |
1316 } | |
1317 | |
429 | 1318 s->time= picture_number*(INT64)FRAME_RATE_BASE*s->time_increment_resolution/s->frame_rate; |
327 | 1319 time_div= s->time/s->time_increment_resolution; |
1320 time_mod= s->time%s->time_increment_resolution; | |
1321 | |
1322 if(s->pict_type==B_TYPE){ | |
1323 s->bp_time= s->last_non_b_time - s->time; | |
1324 }else{ | |
1325 s->last_time_base= s->time_base; | |
1326 s->time_base= time_div; | |
1327 s->pp_time= s->time - s->last_non_b_time; | |
1328 s->last_non_b_time= s->time; | |
1329 } | |
1330 } | |
1331 | |
263 | 1332 static void mpeg4_encode_vol_header(MpegEncContext * s) |
0 | 1333 { |
263 | 1334 int vo_ver_id=1; //must be 2 if we want GMC or q-pel |
322 | 1335 char buf[255]; |
336 | 1336 |
1337 s->vo_type= s->has_b_frames ? CORE_VO_TYPE : SIMPLE_VO_TYPE; | |
1338 | |
263 | 1339 put_bits(&s->pb, 16, 0); |
1340 put_bits(&s->pb, 16, 0x100); /* video obj */ | |
1341 put_bits(&s->pb, 16, 0); | |
1342 put_bits(&s->pb, 16, 0x120); /* video obj layer */ | |
1343 | |
1344 put_bits(&s->pb, 1, 0); /* random access vol */ | |
336 | 1345 put_bits(&s->pb, 8, s->vo_type); /* video obj type indication */ |
263 | 1346 put_bits(&s->pb, 1, 1); /* is obj layer id= yes */ |
1347 put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */ | |
1348 put_bits(&s->pb, 3, 1); /* is obj layer priority */ | |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
1349 if(s->aspect_ratio_info) |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
1350 put_bits(&s->pb, 4, s->aspect_ratio_info);/* aspect ratio info */ |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
1351 else |
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
1352 put_bits(&s->pb, 4, 1); /* aspect ratio info= sqare pixel */ |
336 | 1353 |
1354 if(s->low_delay){ | |
1355 put_bits(&s->pb, 1, 1); /* vol control parameters= yes */ | |
341 | 1356 put_bits(&s->pb, 2, 1); /* chroma format YUV 420/YV12 */ |
336 | 1357 put_bits(&s->pb, 1, s->low_delay); |
1358 put_bits(&s->pb, 1, 0); /* vbv parameters= no */ | |
1359 }else{ | |
1360 put_bits(&s->pb, 1, 0); /* vol control parameters= no */ | |
1361 } | |
1362 | |
263 | 1363 put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */ |
1364 put_bits(&s->pb, 1, 1); /* marker bit */ | |
324 | 1365 |
1366 put_bits(&s->pb, 16, s->time_increment_resolution); | |
263 | 1367 if (s->time_increment_bits < 1) |
1368 s->time_increment_bits = 1; | |
1369 put_bits(&s->pb, 1, 1); /* marker bit */ | |
1370 put_bits(&s->pb, 1, 0); /* fixed vop rate=no */ | |
1371 put_bits(&s->pb, 1, 1); /* marker bit */ | |
1372 put_bits(&s->pb, 13, s->width); /* vol width */ | |
1373 put_bits(&s->pb, 1, 1); /* marker bit */ | |
1374 put_bits(&s->pb, 13, s->height); /* vol height */ | |
1375 put_bits(&s->pb, 1, 1); /* marker bit */ | |
1376 put_bits(&s->pb, 1, 0); /* interlace */ | |
1377 put_bits(&s->pb, 1, 1); /* obmc disable */ | |
1378 if (vo_ver_id == 1) { | |
1379 put_bits(&s->pb, 1, s->vol_sprite_usage=0); /* sprite enable */ | |
1380 }else{ /* vo_ver_id == 2 */ | |
1381 put_bits(&s->pb, 2, s->vol_sprite_usage=0); /* sprite enable */ | |
1382 } | |
1383 put_bits(&s->pb, 1, 0); /* not 8 bit */ | |
599 | 1384 put_bits(&s->pb, 1, s->mpeg_quant); /* quant type= (0=h263 style)*/ |
1385 if(s->mpeg_quant) put_bits(&s->pb, 2, 0); /* no custom matrixes */ | |
1386 | |
263 | 1387 if (vo_ver_id != 1) |
1388 put_bits(&s->pb, 1, s->quarter_sample=0); | |
1389 put_bits(&s->pb, 1, 1); /* complexity estimation disable */ | |
453 | 1390 s->resync_marker= s->rtp_mode; |
1391 put_bits(&s->pb, 1, s->resync_marker ? 0 : 1);/* resync marker disable */ | |
1392 put_bits(&s->pb, 1, s->data_partitioning ? 1 : 0); | |
1393 if(s->data_partitioning){ | |
1394 put_bits(&s->pb, 1, 0); /* no rvlc */ | |
1395 } | |
1396 | |
263 | 1397 if (vo_ver_id != 1){ |
1398 put_bits(&s->pb, 1, 0); /* newpred */ | |
1399 put_bits(&s->pb, 1, 0); /* reduced res vop */ | |
1400 } | |
1401 put_bits(&s->pb, 1, 0); /* scalability */ | |
1402 | |
453 | 1403 ff_mpeg4_stuffing(&s->pb); |
262 | 1404 put_bits(&s->pb, 16, 0); |
1405 put_bits(&s->pb, 16, 0x1B2); /* user_data */ | |
360 | 1406 sprintf(buf, "FFmpeg%sb%s", FFMPEG_VERSION, LIBAVCODEC_BUILD_STR); |
322 | 1407 put_string(&s->pb, buf); |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
1408 |
453 | 1409 ff_mpeg4_stuffing(&s->pb); |
263 | 1410 } |
1411 | |
1412 /* write mpeg4 VOP header */ | |
1413 void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) | |
1414 { | |
324 | 1415 int time_incr; |
1416 int time_div, time_mod; | |
1417 | |
453 | 1418 if(s->pict_type==I_TYPE){ |
1419 s->no_rounding=0; | |
1420 if(picture_number==0 || !s->strict_std_compliance) | |
1421 mpeg4_encode_vol_header(s); | |
1422 } | |
324 | 1423 |
1424 //printf("num:%d rate:%d base:%d\n", s->picture_number, s->frame_rate, FRAME_RATE_BASE); | |
1425 | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
1426 put_bits(&s->pb, 16, 0); /* vop header */ |
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
1427 put_bits(&s->pb, 16, 0x1B6); /* vop header */ |
0 | 1428 put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */ |
324 | 1429 |
327 | 1430 time_div= s->time/s->time_increment_resolution; |
1431 time_mod= s->time%s->time_increment_resolution; | |
324 | 1432 time_incr= time_div - s->last_time_base; |
1433 while(time_incr--) | |
1434 put_bits(&s->pb, 1, 1); | |
1435 | |
0 | 1436 put_bits(&s->pb, 1, 0); |
1437 | |
1438 put_bits(&s->pb, 1, 1); /* marker */ | |
324 | 1439 put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */ |
0 | 1440 put_bits(&s->pb, 1, 1); /* marker */ |
1441 put_bits(&s->pb, 1, 1); /* vop coded */ | |
263 | 1442 if ( s->pict_type == P_TYPE |
1443 || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) { | |
1444 s->no_rounding ^= 1; | |
0 | 1445 put_bits(&s->pb, 1, s->no_rounding); /* rounding type */ |
1446 } | |
1447 put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */ | |
263 | 1448 //FIXME sprite stuff |
0 | 1449 |
1450 put_bits(&s->pb, 5, s->qscale); | |
1451 | |
1452 if (s->pict_type != I_TYPE) | |
1453 put_bits(&s->pb, 3, s->f_code); /* fcode_for */ | |
263 | 1454 if (s->pict_type == B_TYPE) |
1455 put_bits(&s->pb, 3, s->b_code); /* fcode_back */ | |
0 | 1456 // printf("****frame %d\n", picture_number); |
498 | 1457 |
1458 s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; //FIXME add short header support | |
1459 s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table; | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1460 s->h_edge_pos= s->width; |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1461 s->v_edge_pos= s->height; |
0 | 1462 } |
1463 | |
498 | 1464 static void h263_dc_scale(MpegEncContext * s) |
0 | 1465 { |
498 | 1466 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; |
1467 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; | |
0 | 1468 } |
1469 | |
498 | 1470 inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr) |
0 | 1471 { |
266 | 1472 int a, b, c, wrap, pred, scale; |
0 | 1473 UINT16 *dc_val; |
469 | 1474 int dummy; |
0 | 1475 |
1476 /* find prediction */ | |
1477 if (n < 4) { | |
1478 scale = s->y_dc_scale; | |
1479 } else { | |
1480 scale = s->c_dc_scale; | |
1481 } | |
266 | 1482 wrap= s->block_wrap[n]; |
1483 dc_val = s->dc_val[0] + s->block_index[n]; | |
0 | 1484 |
1485 /* B C | |
1486 * A X | |
1487 */ | |
266 | 1488 a = dc_val[ - 1]; |
1489 b = dc_val[ - 1 - wrap]; | |
1490 c = dc_val[ - wrap]; | |
0 | 1491 |
1492 if (abs(a - b) < abs(b - c)) { | |
1493 pred = c; | |
1494 *dir_ptr = 1; /* top */ | |
1495 } else { | |
1496 pred = a; | |
1497 *dir_ptr = 0; /* left */ | |
1498 } | |
1499 /* we assume pred is positive */ | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1500 #ifdef ARCH_X86 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1501 asm volatile ( |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1502 "xorl %%edx, %%edx \n\t" |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1503 "mul %%ecx \n\t" |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1504 : "=d" (pred), "=a"(dummy) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1505 : "a" (pred + (scale >> 1)), "c" (inverse[scale]) |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1506 ); |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1507 #else |
0 | 1508 pred = (pred + (scale >> 1)) / scale; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1509 #endif |
0 | 1510 |
1511 /* prepare address for prediction update */ | |
266 | 1512 *dc_val_ptr = &dc_val[0]; |
0 | 1513 |
1514 return pred; | |
1515 } | |
1516 | |
174
ac5075a55488
new IDCT code by Michael Niedermayer (michaelni@gmx.at) - #define SIMPLE_IDCT to enable
arpi_esp
parents:
162
diff
changeset
|
1517 void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n, |
0 | 1518 int dir) |
1519 { | |
266 | 1520 int i; |
0 | 1521 INT16 *ac_val, *ac_val1; |
1522 | |
1523 /* find prediction */ | |
266 | 1524 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
0 | 1525 ac_val1 = ac_val; |
1526 if (s->ac_pred) { | |
1527 if (dir == 0) { | |
575 | 1528 const int xy= s->mb_x-1 + s->mb_y*s->mb_width; |
0 | 1529 /* left prediction */ |
1530 ac_val -= 16; | |
575 | 1531 |
1532 if(s->mb_x==0 || s->qscale == s->qscale_table[xy] || n==1 || n==3){ | |
1533 /* same qscale */ | |
1534 for(i=1;i<8;i++) { | |
1535 block[block_permute_op(i*8)] += ac_val[i]; | |
1536 } | |
1537 }else{ | |
1538 /* different qscale, we must rescale */ | |
1539 for(i=1;i<8;i++) { | |
1540 block[block_permute_op(i*8)] += ROUNDED_DIV(ac_val[i]*s->qscale_table[xy], s->qscale); | |
1541 } | |
0 | 1542 } |
1543 } else { | |
575 | 1544 const int xy= s->mb_x + s->mb_y*s->mb_width - s->mb_width; |
0 | 1545 /* top prediction */ |
266 | 1546 ac_val -= 16 * s->block_wrap[n]; |
575 | 1547 |
1548 if(s->mb_y==0 || s->qscale == s->qscale_table[xy] || n==2 || n==3){ | |
1549 /* same qscale */ | |
1550 for(i=1;i<8;i++) { | |
1551 block[block_permute_op(i)] += ac_val[i + 8]; | |
1552 } | |
1553 }else{ | |
1554 /* different qscale, we must rescale */ | |
1555 for(i=1;i<8;i++) { | |
1556 block[block_permute_op(i)] += ROUNDED_DIV(ac_val[i + 8]*s->qscale_table[xy], s->qscale); | |
1557 } | |
0 | 1558 } |
1559 } | |
1560 } | |
1561 /* left copy */ | |
1562 for(i=1;i<8;i++) | |
174
ac5075a55488
new IDCT code by Michael Niedermayer (michaelni@gmx.at) - #define SIMPLE_IDCT to enable
arpi_esp
parents:
162
diff
changeset
|
1563 ac_val1[i] = block[block_permute_op(i * 8)]; |
591 | 1564 |
0 | 1565 /* top copy */ |
1566 for(i=1;i<8;i++) | |
174
ac5075a55488
new IDCT code by Michael Niedermayer (michaelni@gmx.at) - #define SIMPLE_IDCT to enable
arpi_esp
parents:
162
diff
changeset
|
1567 ac_val1[8 + i] = block[block_permute_op(i)]; |
591 | 1568 |
0 | 1569 } |
1570 | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1571 static void mpeg4_inv_pred_ac(MpegEncContext * s, INT16 *block, int n, |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1572 int dir) |
0 | 1573 { |
266 | 1574 int i; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1575 INT16 *ac_val; |
0 | 1576 |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1577 /* find prediction */ |
266 | 1578 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1579 |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1580 if (dir == 0) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1581 /* left prediction */ |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1582 ac_val -= 16; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1583 for(i=1;i<8;i++) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1584 block[block_permute_op(i*8)] -= ac_val[i]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1585 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1586 } else { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1587 /* top prediction */ |
266 | 1588 ac_val -= 16 * s->block_wrap[n]; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1589 for(i=1;i<8;i++) { |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1590 block[block_permute_op(i)] -= ac_val[i + 8]; |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1591 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1592 } |
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1593 } |
0 | 1594 |
453 | 1595 static inline void mpeg4_encode_dc(PutBitContext * s, int level, int n) |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1596 { |
293 | 1597 #if 1 |
453 | 1598 // if(level<-255 || level>255) printf("dc overflow\n"); |
293 | 1599 level+=256; |
1600 if (n < 4) { | |
1601 /* luminance */ | |
453 | 1602 put_bits(s, uni_DCtab_lum[level][1], uni_DCtab_lum[level][0]); |
293 | 1603 } else { |
1604 /* chrominance */ | |
453 | 1605 put_bits(s, uni_DCtab_chrom[level][1], uni_DCtab_chrom[level][0]); |
293 | 1606 } |
1607 #else | |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1608 int size, v; |
0 | 1609 /* find number of bits */ |
1610 size = 0; | |
1611 v = abs(level); | |
1612 while (v) { | |
1613 v >>= 1; | |
1614 size++; | |
1615 } | |
1616 | |
1617 if (n < 4) { | |
1618 /* luminance */ | |
1619 put_bits(&s->pb, DCtab_lum[size][1], DCtab_lum[size][0]); | |
1620 } else { | |
1621 /* chrominance */ | |
1622 put_bits(&s->pb, DCtab_chrom[size][1], DCtab_chrom[size][0]); | |
1623 } | |
1624 | |
1625 /* encode remaining bits */ | |
1626 if (size > 0) { | |
1627 if (level < 0) | |
1628 level = (-level) ^ ((1 << size) - 1); | |
1629 put_bits(&s->pb, size, level); | |
1630 if (size > 8) | |
1631 put_bits(&s->pb, 1, 1); | |
1632 } | |
293 | 1633 #endif |
0 | 1634 } |
1635 | |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1636 static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, |
453 | 1637 UINT8 *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb) |
0 | 1638 { |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1639 int last, i, last_non_zero, sign; |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1640 int code; |
0 | 1641 const RLTable *rl; |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1642 UINT32 *bits_tab; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1643 UINT8 *len_tab; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1644 const int last_index = s->block_last_index[n]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1645 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1646 if (s->mb_intra) { //Note gcc (3.2.1 at least) will optimize this away |
0 | 1647 /* mpeg4 based DC predictor */ |
453 | 1648 mpeg4_encode_dc(dc_pb, intra_dc, n); |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1649 if(last_index<1) return; |
0 | 1650 i = 1; |
1651 rl = &rl_intra; | |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1652 bits_tab= uni_mpeg4_intra_rl_bits; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1653 len_tab = uni_mpeg4_intra_rl_len; |
0 | 1654 } else { |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1655 if(last_index<0) return; |
0 | 1656 i = 0; |
1657 rl = &rl_inter; | |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1658 bits_tab= uni_mpeg4_inter_rl_bits; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1659 len_tab = uni_mpeg4_inter_rl_len; |
0 | 1660 } |
1661 | |
1662 /* AC coefs */ | |
1663 last_non_zero = i - 1; | |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1664 #if 1 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1665 for (; i < last_index; i++) { |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1666 int level = block[ scan_table[i] ]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1667 if (level) { |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1668 int run = i - last_non_zero - 1; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1669 level+=64; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1670 if((level&(~127)) == 0){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1671 const int index= UNI_MPEG4_ENC_INDEX(0, run, level); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1672 put_bits(ac_pb, len_tab[index], bits_tab[index]); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1673 }else{ //ESC3 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1674 put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(0<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1675 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1676 last_non_zero = i; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1677 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1678 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1679 /*if(i<=last_index)*/{ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1680 int level = block[ scan_table[i] ]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1681 int run = i - last_non_zero - 1; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1682 level+=64; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1683 if((level&(~127)) == 0){ |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1684 const int index= UNI_MPEG4_ENC_INDEX(1, run, level); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1685 put_bits(ac_pb, len_tab[index], bits_tab[index]); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1686 }else{ //ESC3 |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1687 put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(1<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1); |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1688 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1689 } |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1690 #else |
0 | 1691 for (; i <= last_index; i++) { |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1692 const int slevel = block[ scan_table[i] ]; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1693 if (slevel) { |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1694 int level; |
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1695 int run = i - last_non_zero - 1; |
0 | 1696 last = (i == last_index); |
1697 sign = 0; | |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1698 level = slevel; |
0 | 1699 if (level < 0) { |
1700 sign = 1; | |
1701 level = -level; | |
1702 } | |
1703 code = get_rl_index(rl, last, run, level); | |
453 | 1704 put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); |
0 | 1705 if (code == rl->n) { |
1706 int level1, run1; | |
1707 level1 = level - rl->max_level[last][run]; | |
1708 if (level1 < 1) | |
1709 goto esc2; | |
1710 code = get_rl_index(rl, last, run, level1); | |
1711 if (code == rl->n) { | |
1712 esc2: | |
453 | 1713 put_bits(ac_pb, 1, 1); |
0 | 1714 if (level > MAX_LEVEL) |
1715 goto esc3; | |
1716 run1 = run - rl->max_run[last][level] - 1; | |
1717 if (run1 < 0) | |
1718 goto esc3; | |
1719 code = get_rl_index(rl, last, run1, level); | |
1720 if (code == rl->n) { | |
1721 esc3: | |
1722 /* third escape */ | |
453 | 1723 put_bits(ac_pb, 1, 1); |
1724 put_bits(ac_pb, 1, last); | |
1725 put_bits(ac_pb, 6, run); | |
1726 put_bits(ac_pb, 1, 1); | |
1727 put_bits(ac_pb, 12, slevel & 0xfff); | |
1728 put_bits(ac_pb, 1, 1); | |
0 | 1729 } else { |
1730 /* second escape */ | |
453 | 1731 put_bits(ac_pb, 1, 0); |
1732 put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
1733 put_bits(ac_pb, 1, sign); | |
0 | 1734 } |
1735 } else { | |
1736 /* first escape */ | |
453 | 1737 put_bits(ac_pb, 1, 0); |
1738 put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
1739 put_bits(ac_pb, 1, sign); | |
0 | 1740 } |
1741 } else { | |
453 | 1742 put_bits(ac_pb, 1, sign); |
0 | 1743 } |
1744 last_non_zero = i; | |
1745 } | |
1746 } | |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
1747 #endif |
0 | 1748 } |
1749 | |
1750 | |
1751 | |
1752 /***********************************************/ | |
1753 /* decoding */ | |
1754 | |
1755 static VLC intra_MCBPC_vlc; | |
1756 static VLC inter_MCBPC_vlc; | |
1757 static VLC cbpy_vlc; | |
1758 static VLC mv_vlc; | |
1759 static VLC dc_lum, dc_chrom; | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1760 static VLC sprite_trajectory; |
262 | 1761 static VLC mb_type_b_vlc; |
0 | 1762 |
1763 void init_rl(RLTable *rl) | |
1764 { | |
1765 INT8 max_level[MAX_RUN+1], max_run[MAX_LEVEL+1]; | |
1766 UINT8 index_run[MAX_RUN+1]; | |
1767 int last, run, level, start, end, i; | |
1768 | |
1769 /* compute max_level[], max_run[] and index_run[] */ | |
1770 for(last=0;last<2;last++) { | |
1771 if (last == 0) { | |
1772 start = 0; | |
1773 end = rl->last; | |
1774 } else { | |
1775 start = rl->last; | |
1776 end = rl->n; | |
1777 } | |
1778 | |
1779 memset(max_level, 0, MAX_RUN + 1); | |
1780 memset(max_run, 0, MAX_LEVEL + 1); | |
1781 memset(index_run, rl->n, MAX_RUN + 1); | |
1782 for(i=start;i<end;i++) { | |
1783 run = rl->table_run[i]; | |
1784 level = rl->table_level[i]; | |
1785 if (index_run[run] == rl->n) | |
1786 index_run[run] = i; | |
1787 if (level > max_level[run]) | |
1788 max_level[run] = level; | |
1789 if (run > max_run[level]) | |
1790 max_run[level] = run; | |
1791 } | |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
365
diff
changeset
|
1792 rl->max_level[last] = av_malloc(MAX_RUN + 1); |
0 | 1793 memcpy(rl->max_level[last], max_level, MAX_RUN + 1); |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
365
diff
changeset
|
1794 rl->max_run[last] = av_malloc(MAX_LEVEL + 1); |
0 | 1795 memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1); |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
365
diff
changeset
|
1796 rl->index_run[last] = av_malloc(MAX_RUN + 1); |
0 | 1797 memcpy(rl->index_run[last], index_run, MAX_RUN + 1); |
1798 } | |
1799 } | |
1800 | |
1801 void init_vlc_rl(RLTable *rl) | |
1802 { | |
542 | 1803 int i, q; |
1804 | |
0 | 1805 init_vlc(&rl->vlc, 9, rl->n + 1, |
1806 &rl->table_vlc[0][1], 4, 2, | |
1807 &rl->table_vlc[0][0], 4, 2); | |
542 | 1808 |
1809 | |
1810 for(q=0; q<32; q++){ | |
1811 int qmul= q*2; | |
1812 int qadd= (q-1)|1; | |
1813 | |
1814 if(q==0){ | |
1815 qmul=1; | |
1816 qadd=0; | |
1817 } | |
1818 | |
1819 rl->rl_vlc[q]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM)); | |
1820 for(i=0; i<rl->vlc.table_size; i++){ | |
1821 int code= rl->vlc.table[i][0]; | |
1822 int len = rl->vlc.table[i][1]; | |
1823 int level, run; | |
1824 | |
1825 if(len==0){ // illegal code | |
563 | 1826 run= 66; |
542 | 1827 level= MAX_LEVEL; |
1828 }else if(len<0){ //more bits needed | |
1829 run= 0; | |
1830 level= code; | |
1831 }else{ | |
1832 if(code==rl->n){ //esc | |
563 | 1833 run= 66; |
542 | 1834 level= 0; |
1835 }else{ | |
1836 run= rl->table_run [code] + 1; | |
1837 level= rl->table_level[code] * qmul + qadd; | |
1838 if(code >= rl->last) run+=192; | |
1839 } | |
1840 } | |
1841 rl->rl_vlc[q][i].len= len; | |
1842 rl->rl_vlc[q][i].level= level; | |
1843 rl->rl_vlc[q][i].run= run; | |
1844 } | |
1845 } | |
0 | 1846 } |
1847 | |
1848 /* init vlcs */ | |
1849 | |
1850 /* XXX: find a better solution to handle static init */ | |
1851 void h263_decode_init_vlc(MpegEncContext *s) | |
1852 { | |
1853 static int done = 0; | |
1854 | |
1855 if (!done) { | |
1856 done = 1; | |
1857 | |
544 | 1858 init_vlc(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 8, |
0 | 1859 intra_MCBPC_bits, 1, 1, |
1860 intra_MCBPC_code, 1, 1); | |
544 | 1861 init_vlc(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 25, |
0 | 1862 inter_MCBPC_bits, 1, 1, |
1863 inter_MCBPC_code, 1, 1); | |
544 | 1864 init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16, |
0 | 1865 &cbpy_tab[0][1], 2, 1, |
1866 &cbpy_tab[0][0], 2, 1); | |
544 | 1867 init_vlc(&mv_vlc, MV_VLC_BITS, 33, |
0 | 1868 &mvtab[0][1], 2, 1, |
1869 &mvtab[0][0], 2, 1); | |
1870 init_rl(&rl_inter); | |
1871 init_rl(&rl_intra); | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1872 init_rl(&rl_intra_aic); |
0 | 1873 init_vlc_rl(&rl_inter); |
1874 init_vlc_rl(&rl_intra); | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1875 init_vlc_rl(&rl_intra_aic); |
549 | 1876 init_vlc(&dc_lum, DC_VLC_BITS, 10 /* 13 */, |
0 | 1877 &DCtab_lum[0][1], 2, 1, |
1878 &DCtab_lum[0][0], 2, 1); | |
549 | 1879 init_vlc(&dc_chrom, DC_VLC_BITS, 10 /* 13 */, |
0 | 1880 &DCtab_chrom[0][1], 2, 1, |
1881 &DCtab_chrom[0][0], 2, 1); | |
544 | 1882 init_vlc(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15, |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1883 &sprite_trajectory_tab[0][1], 4, 2, |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1884 &sprite_trajectory_tab[0][0], 4, 2); |
544 | 1885 init_vlc(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4, |
262 | 1886 &mb_type_b_tab[0][1], 2, 1, |
1887 &mb_type_b_tab[0][0], 2, 1); | |
0 | 1888 } |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
1889 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
1890 s->progressive_sequence=1; // set to most likely for the case of incomplete headers |
0 | 1891 } |
1892 | |
162 | 1893 int h263_decode_gob_header(MpegEncContext *s) |
1894 { | |
1895 unsigned int val, gfid; | |
1896 | |
1897 /* Check for GOB Start Code */ | |
1898 val = show_bits(&s->gb, 16); | |
1899 if (val == 0) { | |
1900 /* We have a GBSC probably with GSTUFF */ | |
1901 skip_bits(&s->gb, 16); /* Drop the zeros */ | |
1902 while (get_bits1(&s->gb) == 0); /* Seek the '1' bit */ | |
1903 #ifdef DEBUG | |
1904 fprintf(stderr,"\nGOB Start Code at MB %d\n", (s->mb_y * s->mb_width) + s->mb_x); | |
1905 #endif | |
1906 s->gob_number = get_bits(&s->gb, 5); /* GN */ | |
1907 gfid = get_bits(&s->gb, 2); /* GFID */ | |
1908 s->qscale = get_bits(&s->gb, 5); /* GQUANT */ | |
1909 #ifdef DEBUG | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
1910 fprintf(stderr, "\nGN: %u GFID: %u Quant: %u\n", s->gob_number, gfid, s->qscale); |
162 | 1911 #endif |
1912 return 1; | |
1913 } | |
1914 return 0; | |
1915 | |
1916 } | |
1917 | |
290 | 1918 static inline void memsetw(short *tab, int val, int n) |
1919 { | |
1920 int i; | |
1921 for(i=0;i<n;i++) | |
1922 tab[i] = val; | |
1923 } | |
1924 | |
453 | 1925 void ff_mpeg4_init_partitions(MpegEncContext *s) |
1926 { | |
1927 init_put_bits(&s->tex_pb, s->tex_pb_buffer, PB_BUFFER_SIZE, NULL, NULL); | |
1928 init_put_bits(&s->pb2 , s->pb2_buffer , PB_BUFFER_SIZE, NULL, NULL); | |
1929 } | |
1930 | |
1931 void ff_mpeg4_merge_partitions(MpegEncContext *s) | |
290 | 1932 { |
453 | 1933 const int pb2_len = get_bit_count(&s->pb2 ); |
1934 const int tex_pb_len= get_bit_count(&s->tex_pb); | |
1935 const int bits= get_bit_count(&s->pb); | |
1936 | |
1937 if(s->pict_type==I_TYPE){ | |
1938 put_bits(&s->pb, 19, DC_MARKER); | |
1939 s->misc_bits+=19 + pb2_len + bits - s->last_bits; | |
1940 s->i_tex_bits+= tex_pb_len; | |
1941 }else{ | |
1942 put_bits(&s->pb, 17, MOTION_MARKER); | |
1943 s->misc_bits+=17 + pb2_len;; | |
1944 s->mv_bits+= bits - s->last_bits; | |
1945 s->p_tex_bits+= tex_pb_len; | |
1946 } | |
1947 | |
1948 flush_put_bits(&s->pb2); | |
1949 flush_put_bits(&s->tex_pb); | |
1950 | |
1951 ff_copy_bits(&s->pb, s->pb2_buffer , pb2_len); | |
1952 ff_copy_bits(&s->pb, s->tex_pb_buffer, tex_pb_len); | |
1953 s->last_bits= get_bit_count(&s->pb); | |
1954 } | |
1955 | |
1956 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s) | |
1957 { | |
1958 int mb_num_bits= av_log2(s->mb_num - 1) + 1; | |
1959 | |
1960 ff_mpeg4_stuffing(&s->pb); | |
1961 if(s->pict_type==I_TYPE) | |
1962 put_bits(&s->pb, 16, 0); | |
1963 else if(s->pict_type==B_TYPE) | |
1964 put_bits(&s->pb, MAX(MAX(s->f_code, s->b_code)+15, 17), 0); | |
1965 else /* S/P_TYPE */ | |
1966 put_bits(&s->pb, s->f_code+15, 0); | |
1967 put_bits(&s->pb, 1, 1); | |
1968 | |
1969 put_bits(&s->pb, mb_num_bits, s->mb_x + s->mb_y*s->mb_width); | |
1970 put_bits(&s->pb, 5, s->qscale); | |
1971 put_bits(&s->pb, 1, 0); /* no HEC */ | |
1972 } | |
1973 | |
1974 /** | |
1975 * decodes the next video packet and sets s->next_qscale | |
1976 * returns mb_num of the next packet or <0 if something went wrong | |
1977 */ | |
1978 static int decode_video_packet_header(MpegEncContext *s, GetBitContext *gb) | |
1979 { | |
1980 int bits; | |
290 | 1981 int mb_num_bits= av_log2(s->mb_num - 1) + 1; |
1982 int header_extension=0, mb_num; | |
453 | 1983 //printf("%X\n", show_bits(&gb, 24)); |
1984 //printf("parse_video_packet_header\n"); | |
1985 // if(show_aligned_bits(gb, 1, 16) != 0) return -1; | |
1986 | |
1987 /* is there enough space left for a video packet + header */ | |
1988 if( get_bits_count(gb) > gb->size*8-20) return -1; | |
1989 | |
290 | 1990 //printf("resync at %d %d\n", s->mb_x, s->mb_y); |
453 | 1991 // skip_bits(gb, 1); |
1992 // align_get_bits(gb); | |
1993 if(get_bits(gb, 16)!=0){ | |
1994 printf("internal error while decoding video packet header\n"); | |
1995 } | |
1996 | |
1997 //printf("%X\n", show_bits(gb, 24)); | |
1998 bits=0; | |
1999 while(!get_bits1(gb) && bits<30) bits++; | |
2000 if((s->pict_type == P_TYPE || s->pict_type == S_TYPE) && bits != s->f_code-1){ | |
2001 printf("marker does not match f_code (is: %d should be: %d pos: %d end %d x: %d y: %d)\n", | |
2002 bits+1, s->f_code, get_bits_count(gb), gb->size*8, s->mb_x, s->mb_y); | |
2003 return -1; | |
2004 }else if(s->pict_type == I_TYPE && bits != 0){ | |
2005 printf("marker too long\n"); | |
2006 return -1; | |
2007 }else if(s->pict_type == B_TYPE && bits != MAX(MAX(s->f_code, s->b_code)-1, 1)){ | |
2008 printf("marker does not match f/b_code\n"); | |
2009 return -1; | |
2010 } | |
2011 //printf("%X\n", show_bits(gb, 24)); | |
2012 | |
2013 if(s->shape != RECT_SHAPE){ | |
2014 header_extension= get_bits1(gb); | |
2015 //FIXME more stuff here | |
2016 } | |
2017 | |
2018 mb_num= get_bits(gb, mb_num_bits); | |
2019 if(mb_num < s->mb_x + s->mb_y*s->mb_width || mb_num>=s->mb_num){ | |
2020 fprintf(stderr, "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_x + s->mb_y*s->mb_width); | |
2021 return -1; | |
2022 } | |
2023 | |
2024 if(s->shape != BIN_ONLY_SHAPE){ | |
2025 s->next_resync_qscale= get_bits(gb, 5); | |
2026 if(s->next_resync_qscale==0) | |
2027 s->next_resync_qscale= s->qscale; | |
2028 if(s->next_resync_qscale==0){ | |
2029 fprintf(stderr, "qscale==0\n"); | |
290 | 2030 return -1; |
2031 } | |
2032 } | |
2033 | |
2034 if(s->shape == RECT_SHAPE){ | |
453 | 2035 header_extension= get_bits1(gb); |
290 | 2036 } |
2037 if(header_extension){ | |
453 | 2038 int time_increment; |
290 | 2039 int time_incr=0; |
453 | 2040 printf("header extension not supported\n"); |
2041 return -1; | |
2042 | |
2043 while (get_bits1(gb) != 0) | |
290 | 2044 time_incr++; |
2045 | |
453 | 2046 check_marker(gb, "before time_increment in video packed header"); |
2047 time_increment= get_bits(gb, s->time_increment_bits); | |
290 | 2048 if(s->pict_type!=B_TYPE){ |
324 | 2049 s->last_time_base= s->time_base; |
290 | 2050 s->time_base+= time_incr; |
324 | 2051 s->time= s->time_base*s->time_increment_resolution + time_increment; |
2052 s->pp_time= s->time - s->last_non_b_time; | |
2053 s->last_non_b_time= s->time; | |
290 | 2054 }else{ |
324 | 2055 s->time= (s->last_time_base + time_incr)*s->time_increment_resolution + time_increment; |
2056 s->bp_time= s->last_non_b_time - s->time; | |
290 | 2057 } |
453 | 2058 check_marker(gb, "before vop_coding_type in video packed header"); |
290 | 2059 |
453 | 2060 skip_bits(gb, 2); /* vop coding type */ |
290 | 2061 //FIXME not rect stuff here |
2062 | |
2063 if(s->shape != BIN_ONLY_SHAPE){ | |
453 | 2064 skip_bits(gb, 3); /* intra dc vlc threshold */ |
290 | 2065 |
2066 if(s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE && s->num_sprite_warping_points){ | |
2067 mpeg4_decode_sprite_trajectory(s); | |
2068 } | |
2069 | |
2070 //FIXME reduced res stuff here | |
2071 | |
2072 if (s->pict_type != I_TYPE) { | |
453 | 2073 s->f_code = get_bits(gb, 3); /* fcode_for */ |
290 | 2074 if(s->f_code==0){ |
2075 printf("Error, video packet header damaged or not MPEG4 header (f_code=0)\n"); | |
2076 return -1; // makes no sense to continue, as the MV decoding will break very quickly | |
2077 } | |
2078 } | |
2079 if (s->pict_type == B_TYPE) { | |
453 | 2080 s->b_code = get_bits(gb, 3); |
290 | 2081 } |
2082 } | |
2083 } | |
2084 //FIXME new-pred stuff | |
453 | 2085 |
2086 //printf("parse ok %d %d %d %d\n", mb_num, s->mb_x + s->mb_y*s->mb_width, get_bits_count(gb), get_bits_count(&s->gb)); | |
2087 | |
2088 return mb_num; | |
2089 } | |
2090 | |
2091 void ff_mpeg4_clean_buffers(MpegEncContext *s) | |
2092 { | |
2093 int c_wrap, c_xy, l_wrap, l_xy; | |
290 | 2094 |
2095 l_wrap= s->block_wrap[0]; | |
453 | 2096 l_xy= s->mb_y*l_wrap*2 + s->mb_x*2; |
290 | 2097 c_wrap= s->block_wrap[4]; |
453 | 2098 c_xy= s->mb_y*c_wrap + s->mb_x; |
290 | 2099 |
2100 /* clean DC */ | |
453 | 2101 memsetw(s->dc_val[0] + l_xy, 1024, l_wrap*2+1); |
2102 memsetw(s->dc_val[1] + c_xy, 1024, c_wrap+1); | |
2103 memsetw(s->dc_val[2] + c_xy, 1024, c_wrap+1); | |
290 | 2104 |
2105 /* clean AC */ | |
453 | 2106 memset(s->ac_val[0] + l_xy, 0, (l_wrap*2+1)*16*sizeof(INT16)); |
2107 memset(s->ac_val[1] + c_xy, 0, (c_wrap +1)*16*sizeof(INT16)); | |
2108 memset(s->ac_val[2] + c_xy, 0, (c_wrap +1)*16*sizeof(INT16)); | |
290 | 2109 |
2110 /* clean MV */ | |
453 | 2111 // we cant clear the MVs as they might be needed by a b frame |
2112 // memset(s->motion_val + l_xy, 0, (l_wrap*2+1)*2*sizeof(INT16)); | |
290 | 2113 // memset(s->motion_val, 0, 2*sizeof(INT16)*(2 + s->mb_width*2)*(2 + s->mb_height*2)); |
453 | 2114 s->last_mv[0][0][0]= |
2115 s->last_mv[0][0][1]= | |
2116 s->last_mv[1][0][0]= | |
2117 s->last_mv[1][0][1]= 0; | |
2118 } | |
2119 | |
2120 /* searches for the next resync marker clears ac,dc,mc, and sets s->next_resync_gb, s->mb_num_left */ | |
2121 int ff_mpeg4_resync(MpegEncContext *s) | |
2122 { | |
2123 GetBitContext gb; | |
2124 | |
2125 /* search & parse next resync marker */ | |
2126 | |
2127 gb= s->next_resync_gb; | |
2128 align_get_bits(&gb); | |
2129 //printf("mpeg4_resync %d next:%d \n", get_bits_count(&gb), get_bits_count(&s->next_resync_gb)); | |
2130 for(;;) { | |
2131 int v= show_bits(&gb, 24); | |
2132 if( get_bits_count(&gb) >= gb.size*8-24 || v == 1 /* start-code */){ | |
2133 s->mb_num_left= s->mb_num - s->mb_x - s->mb_y*s->mb_width; | |
2134 //printf("mpeg4_resync end\n"); | |
2135 s->gb= s->next_resync_gb; //continue at the next resync marker | |
2136 return -1; | |
2137 }else if(v>>8 == 0){ | |
2138 int next; | |
2139 s->next_resync_pos= get_bits_count(&gb); | |
2140 | |
2141 next= decode_video_packet_header(s, &gb); | |
2142 if(next >= 0){ | |
2143 s->mb_num_left= next - s->mb_x - s->mb_y*s->mb_width; | |
2144 break; | |
2145 } | |
2146 | |
2147 align_get_bits(&gb); | |
2148 } | |
2149 skip_bits(&gb, 8); | |
2150 } | |
2151 s->next_resync_gb=gb; | |
2152 | |
2153 return 0; | |
2154 } | |
2155 | |
2156 static inline void init_block_index(MpegEncContext *s) | |
2157 { | |
2158 s->block_index[0]= s->block_wrap[0]*(s->mb_y*2 + 1) - 1 + s->mb_x*2; | |
2159 s->block_index[1]= s->block_wrap[0]*(s->mb_y*2 + 1) + s->mb_x*2; | |
2160 s->block_index[2]= s->block_wrap[0]*(s->mb_y*2 + 2) - 1 + s->mb_x*2; | |
2161 s->block_index[3]= s->block_wrap[0]*(s->mb_y*2 + 2) + s->mb_x*2; | |
2162 s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x; | |
2163 s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x; | |
2164 } | |
2165 | |
2166 static inline void update_block_index(MpegEncContext *s) | |
2167 { | |
2168 s->block_index[0]+=2; | |
2169 s->block_index[1]+=2; | |
2170 s->block_index[2]+=2; | |
2171 s->block_index[3]+=2; | |
2172 s->block_index[4]++; | |
2173 s->block_index[5]++; | |
2174 } | |
2175 | |
2176 /** | |
2177 * decodes the first & second partition | |
2178 * returns error type or 0 if no error | |
2179 */ | |
2180 int ff_mpeg4_decode_partitions(MpegEncContext *s) | |
2181 { | |
2182 static const INT8 quant_tab[4] = { -1, -2, 1, 2 }; | |
2183 int mb_num; | |
2184 | |
2185 /* decode first partition */ | |
2186 mb_num=0; | |
290 | 2187 s->first_slice_line=1; |
453 | 2188 s->mb_x= s->resync_mb_x; |
2189 for(s->mb_y= s->resync_mb_y; mb_num < s->mb_num_left; s->mb_y++){ | |
2190 init_block_index(s); | |
2191 for(; mb_num < s->mb_num_left && s->mb_x<s->mb_width; s->mb_x++){ | |
2192 const int xy= s->mb_x + s->mb_y*s->mb_width; | |
2193 int cbpc; | |
2194 int dir=0; | |
2195 | |
2196 mb_num++; | |
2197 update_block_index(s); | |
2198 if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1) | |
2199 s->first_slice_line=0; | |
2200 | |
2201 if(s->mb_x==0) PRINT_MB_TYPE("\n"); | |
2202 | |
2203 if(s->pict_type==I_TYPE){ | |
2204 int i; | |
2205 | |
2206 PRINT_MB_TYPE("I"); | |
544 | 2207 cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1); |
453 | 2208 if (cbpc < 0){ |
2209 fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); | |
2210 return DECODING_DESYNC; | |
2211 } | |
2212 s->cbp_table[xy]= cbpc & 3; | |
2213 s->mb_type[xy]= MB_TYPE_INTRA; | |
2214 s->mb_intra = 1; | |
2215 | |
2216 if(cbpc & 4) { | |
2217 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
2218 if (s->qscale < 1) | |
2219 s->qscale = 1; | |
2220 else if (s->qscale > 31) | |
2221 s->qscale = 31; | |
2222 h263_dc_scale(s); | |
2223 } | |
2224 s->qscale_table[xy]= s->qscale; | |
2225 | |
2226 s->mbintra_table[xy]= 1; | |
2227 for(i=0; i<6; i++){ | |
2228 int dc_pred_dir; | |
2229 int dc= mpeg4_decode_dc(s, i, &dc_pred_dir); | |
2230 if(dc < 0){ | |
2231 fprintf(stderr, "DC corrupted at %d %d\n", s->mb_x, s->mb_y); | |
2232 return DECODING_DESYNC; | |
2233 } | |
2234 dir<<=1; | |
2235 if(dc_pred_dir) dir|=1; | |
2236 } | |
2237 s->pred_dir_table[xy]= dir; | |
2238 }else{ /* P/S_TYPE */ | |
2239 int mx, my, pred_x, pred_y; | |
2240 INT16 * const mot_val= s->motion_val[s->block_index[0]]; | |
2241 const int stride= s->block_wrap[0]*2; | |
2242 | |
2243 if(get_bits1(&s->gb)){ | |
2244 /* skip mb */ | |
2245 s->mb_type[xy]= MB_TYPE_SKIPED; | |
2246 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ | |
2247 const int a= s->sprite_warping_accuracy; | |
2248 PRINT_MB_TYPE("G"); | |
2249 if(s->divx_version==500 && s->divx_build==413){ | |
2250 mx = s->sprite_offset[0][0] / (1<<(a-s->quarter_sample)); | |
2251 my = s->sprite_offset[0][1] / (1<<(a-s->quarter_sample)); | |
2252 }else{ | |
2253 mx = RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); | |
2254 my = RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); | |
2255 s->mb_type[xy]= MB_TYPE_GMC | MB_TYPE_SKIPED; | |
2256 } | |
2257 }else{ | |
2258 PRINT_MB_TYPE("S"); | |
2259 mx = 0; | |
2260 my = 0; | |
2261 } | |
2262 mot_val[0 ]= mot_val[2 ]= | |
2263 mot_val[0+stride]= mot_val[2+stride]= mx; | |
2264 mot_val[1 ]= mot_val[3 ]= | |
2265 mot_val[1+stride]= mot_val[3+stride]= my; | |
2266 | |
2267 if(s->mbintra_table[xy]) | |
2268 ff_clean_intra_table_entries(s); | |
2269 | |
2270 continue; | |
2271 } | |
544 | 2272 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); |
453 | 2273 if (cbpc < 0){ |
2274 fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); | |
2275 return DECODING_DESYNC; | |
2276 } | |
2277 if (cbpc > 20) | |
2278 cbpc+=3; | |
2279 else if (cbpc == 20) | |
2280 fprintf(stderr, "Stuffing !"); | |
2281 s->cbp_table[xy]= cbpc&(8+3); //8 is dquant | |
2282 | |
2283 s->mb_intra = ((cbpc & 4) != 0); | |
2284 | |
2285 if(s->mb_intra){ | |
2286 PRINT_MB_TYPE("I"); | |
2287 s->mbintra_table[xy]= 1; | |
2288 s->mb_type[xy]= MB_TYPE_INTRA; | |
2289 mot_val[0 ]= mot_val[2 ]= | |
2290 mot_val[0+stride]= mot_val[2+stride]= 0; | |
2291 mot_val[1 ]= mot_val[3 ]= | |
2292 mot_val[1+stride]= mot_val[3+stride]= 0; | |
2293 }else{ | |
2294 if(s->mbintra_table[xy]) | |
2295 ff_clean_intra_table_entries(s); | |
2296 | |
2297 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) | |
2298 s->mcsel= get_bits1(&s->gb); | |
2299 else s->mcsel= 0; | |
2300 | |
2301 if ((cbpc & 16) == 0) { | |
2302 PRINT_MB_TYPE("P"); | |
2303 /* 16x16 motion prediction */ | |
2304 s->mb_type[xy]= MB_TYPE_INTER; | |
2305 | |
2306 h263_pred_motion(s, 0, &pred_x, &pred_y); | |
2307 if(!s->mcsel) | |
2308 mx = h263_decode_motion(s, pred_x, s->f_code); | |
2309 else { | |
2310 const int a= s->sprite_warping_accuracy; | |
2311 if(s->divx_version==500 && s->divx_build==413){ | |
2312 mx = s->sprite_offset[0][0] / (1<<(a-s->quarter_sample)); | |
2313 }else{ | |
2314 mx = RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); | |
2315 } | |
2316 } | |
2317 if (mx >= 0xffff) | |
2318 return DECODING_DESYNC; | |
2319 | |
2320 if(!s->mcsel) | |
2321 my = h263_decode_motion(s, pred_y, s->f_code); | |
2322 else{ | |
2323 const int a= s->sprite_warping_accuracy; | |
2324 if(s->divx_version==500 && s->divx_build==413){ | |
2325 my = s->sprite_offset[0][1] / (1<<(a-s->quarter_sample)); | |
2326 }else{ | |
2327 my = RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); | |
2328 } | |
2329 } | |
2330 if (my >= 0xffff) | |
2331 return DECODING_DESYNC; | |
2332 mot_val[0 ]= mot_val[2 ] = | |
2333 mot_val[0+stride]= mot_val[2+stride]= mx; | |
2334 mot_val[1 ]= mot_val[3 ]= | |
2335 mot_val[1+stride]= mot_val[3+stride]= my; | |
2336 } else { | |
2337 int i; | |
2338 PRINT_MB_TYPE("4"); | |
2339 s->mb_type[xy]= MB_TYPE_INTER4V; | |
2340 for(i=0;i<4;i++) { | |
2341 INT16 *mot_val= h263_pred_motion(s, i, &pred_x, &pred_y); | |
2342 mx = h263_decode_motion(s, pred_x, s->f_code); | |
2343 if (mx >= 0xffff) | |
2344 return DECODING_DESYNC; | |
2345 | |
2346 my = h263_decode_motion(s, pred_y, s->f_code); | |
2347 if (my >= 0xffff) | |
2348 return DECODING_DESYNC; | |
2349 mot_val[0] = mx; | |
2350 mot_val[1] = my; | |
2351 } | |
2352 } | |
2353 } | |
2354 } | |
2355 } | |
2356 s->mb_x= 0; | |
2357 } | |
2358 | |
2359 if (s->pict_type==I_TYPE && get_bits(&s->gb, 19)!=DC_MARKER ) s->decoding_error= DECODING_DESYNC; | |
2360 else if(s->pict_type!=I_TYPE && get_bits(&s->gb, 17)!=MOTION_MARKER) s->decoding_error= DECODING_DESYNC; | |
2361 if(s->decoding_error== DECODING_DESYNC){ | |
2362 fprintf(stderr, "marker missing after first partition at %d %d\n", s->mb_x, s->mb_y); | |
2363 return DECODING_DESYNC; | |
2364 } | |
2365 | |
2366 /* decode second partition */ | |
2367 mb_num=0; | |
2368 s->mb_x= s->resync_mb_x; | |
2369 for(s->mb_y= s->resync_mb_y; mb_num < s->mb_num_left; s->mb_y++){ | |
2370 init_block_index(s); | |
2371 for(; mb_num < s->mb_num_left && s->mb_x<s->mb_width; s->mb_x++){ | |
2372 const int xy= s->mb_x + s->mb_y*s->mb_width; | |
2373 | |
2374 mb_num++; | |
2375 update_block_index(s); | |
2376 | |
2377 if(s->pict_type==I_TYPE){ | |
2378 int ac_pred= get_bits1(&s->gb); | |
544 | 2379 int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
453 | 2380 if(cbpy<0){ |
2381 fprintf(stderr, "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); | |
2382 return DECODING_AC_LOST; | |
2383 } | |
2384 | |
2385 s->cbp_table[xy]|= cbpy<<2; | |
2386 s->pred_dir_table[xy]|= ac_pred<<7; | |
2387 }else{ /* P || S_TYPE */ | |
2388 if(s->mb_type[xy]&MB_TYPE_INTRA){ | |
2389 int dir=0,i; | |
2390 int ac_pred = get_bits1(&s->gb); | |
544 | 2391 int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
453 | 2392 |
2393 if(cbpy<0){ | |
2394 fprintf(stderr, "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); | |
2395 return DECODING_ACDC_LOST; | |
2396 } | |
2397 | |
2398 if(s->cbp_table[xy] & 8) { | |
2399 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
2400 if (s->qscale < 1) | |
2401 s->qscale = 1; | |
2402 else if (s->qscale > 31) | |
2403 s->qscale = 31; | |
2404 h263_dc_scale(s); | |
2405 } | |
2406 s->qscale_table[xy]= s->qscale; | |
2407 | |
2408 for(i=0; i<6; i++){ | |
2409 int dc_pred_dir; | |
2410 int dc= mpeg4_decode_dc(s, i, &dc_pred_dir); | |
2411 if(dc < 0){ | |
2412 fprintf(stderr, "DC corrupted at %d %d\n", s->mb_x, s->mb_y); | |
2413 return DECODING_ACDC_LOST; | |
2414 } | |
2415 dir<<=1; | |
2416 if(dc_pred_dir) dir|=1; | |
2417 } | |
2418 s->cbp_table[xy]&= 3; //remove dquant | |
2419 s->cbp_table[xy]|= cbpy<<2; | |
2420 s->pred_dir_table[xy]= dir | (ac_pred<<7); | |
2421 }else if(s->mb_type[xy]&MB_TYPE_SKIPED){ | |
2422 s->qscale_table[xy]= s->qscale; | |
2423 s->cbp_table[xy]= 0; | |
2424 }else{ | |
544 | 2425 int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
453 | 2426 |
2427 if(cbpy<0){ | |
2428 fprintf(stderr, "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); | |
2429 return DECODING_ACDC_LOST; | |
2430 } | |
2431 | |
2432 if(s->cbp_table[xy] & 8) { | |
2433 //fprintf(stderr, "dquant\n"); | |
2434 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
2435 if (s->qscale < 1) | |
2436 s->qscale = 1; | |
2437 else if (s->qscale > 31) | |
2438 s->qscale = 31; | |
2439 h263_dc_scale(s); | |
2440 } | |
2441 s->qscale_table[xy]= s->qscale; | |
2442 | |
2443 s->cbp_table[xy]&= 3; //remove dquant | |
2444 s->cbp_table[xy]|= (cbpy^0xf)<<2; | |
2445 } | |
2446 } | |
2447 } | |
2448 s->mb_x= 0; | |
2449 } | |
2450 | |
2451 | |
2452 return 0; | |
2453 } | |
2454 | |
2455 static int mpeg4_decode_partitioned_mb(MpegEncContext *s, | |
2456 DCTELEM block[6][64]) | |
2457 { | |
2458 int cbp, mb_type; | |
2459 const int xy= s->mb_x + s->mb_y*s->mb_width; | |
2460 | |
2461 if(s->mb_x==s->resync_mb_x && s->mb_y==s->resync_mb_y){ //Note resync_mb_{x,y}==0 at the start | |
2462 int i; | |
2463 int block_index_backup[6]; | |
2464 int qscale= s->qscale; | |
2465 | |
2466 for(i=0; i<6; i++) block_index_backup[i]= s->block_index[i]; | |
2467 | |
2468 s->decoding_error= ff_mpeg4_decode_partitions(s); | |
2469 | |
2470 for(i=0; i<6; i++) s->block_index[i]= block_index_backup[i]; | |
2471 s->first_slice_line=1; | |
2472 s->mb_x= s->resync_mb_x; | |
2473 s->mb_y= s->resync_mb_y; | |
2474 s->qscale= qscale; | |
2475 h263_dc_scale(s); | |
2476 | |
2477 if(s->decoding_error==DECODING_DESYNC) return -1; | |
2478 } | |
2479 | |
2480 mb_type= s->mb_type[xy]; | |
2481 if(s->decoding_error) | |
2482 cbp=0; | |
2483 else | |
2484 cbp = s->cbp_table[xy]; | |
2485 | |
2486 if(s->decoding_error!=DECODING_ACDC_LOST && s->qscale_table[xy] != s->qscale){ | |
2487 s->qscale= s->qscale_table[xy]; | |
2488 h263_dc_scale(s); | |
2489 } | |
2490 | |
2491 if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) { | |
2492 int i; | |
2493 for(i=0; i<4; i++){ | |
2494 s->mv[0][i][0] = s->motion_val[ s->block_index[i] ][0]; | |
2495 s->mv[0][i][1] = s->motion_val[ s->block_index[i] ][1]; | |
2496 } | |
2497 s->mb_intra = mb_type&MB_TYPE_INTRA; | |
2498 | |
2499 if (mb_type&MB_TYPE_SKIPED) { | |
2500 /* skip mb */ | |
2501 for(i=0;i<6;i++) | |
2502 s->block_last_index[i] = -1; | |
2503 s->mv_dir = MV_DIR_FORWARD; | |
2504 s->mv_type = MV_TYPE_16X16; | |
2505 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ | |
2506 s->mcsel=1; | |
2507 s->mb_skiped = 0; | |
2508 }else{ | |
2509 s->mcsel=0; | |
2510 s->mb_skiped = 1; | |
2511 } | |
2512 return 0; | |
2513 }else if(s->mb_intra && s->decoding_error!=DECODING_ACDC_LOST){ | |
2514 s->ac_pred = s->pred_dir_table[xy]>>7; | |
2515 | |
2516 /* decode each block */ | |
2517 for (i = 0; i < 6; i++) { | |
575 | 2518 int ret= mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 1); |
453 | 2519 if(ret==DECODING_AC_LOST){ |
2520 fprintf(stderr, "texture corrupted at %d %d (trying to continue with mc/dc only)\n", s->mb_x, s->mb_y); | |
2521 s->decoding_error=DECODING_AC_LOST; | |
2522 cbp=0; | |
2523 }else if(ret==DECODING_ACDC_LOST){ | |
2524 fprintf(stderr, "dc corrupted at %d %d (trying to continue with mc only)\n", s->mb_x, s->mb_y); | |
2525 s->decoding_error=DECODING_ACDC_LOST; | |
2526 break; | |
2527 } | |
2528 } | |
2529 }else if(!s->mb_intra){ | |
2530 // s->mcsel= 0; //FIXME do we need to init that | |
2531 | |
2532 s->mv_dir = MV_DIR_FORWARD; | |
2533 if (mb_type&MB_TYPE_INTER4V) { | |
2534 s->mv_type = MV_TYPE_8X8; | |
2535 } else { | |
2536 s->mv_type = MV_TYPE_16X16; | |
2537 } | |
2538 if(s->decoding_error==0 && cbp){ | |
2539 /* decode each block */ | |
2540 for (i = 0; i < 6; i++) { | |
575 | 2541 int ret= mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 0); |
453 | 2542 if(ret==DECODING_AC_LOST){ |
2543 fprintf(stderr, "texture corrupted at %d %d (trying to continue with mc/dc only)\n", s->mb_x, s->mb_y); | |
2544 s->decoding_error=DECODING_AC_LOST; | |
2545 break; | |
2546 } | |
2547 } | |
2548 } | |
2549 } | |
2550 } else { /* I-Frame */ | |
2551 int i; | |
2552 s->mb_intra = 1; | |
2553 s->ac_pred = s->pred_dir_table[xy]>>7; | |
2554 | |
2555 /* decode each block */ | |
2556 for (i = 0; i < 6; i++) { | |
575 | 2557 int ret= mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 1); |
453 | 2558 if(ret==DECODING_AC_LOST){ |
2559 fprintf(stderr, "texture corrupted at %d %d (trying to continue with dc only)\n", s->mb_x, s->mb_y); | |
2560 s->decoding_error=DECODING_AC_LOST; | |
2561 cbp=0; | |
2562 }else if(ret==DECODING_ACDC_LOST){ | |
2563 fprintf(stderr, "dc corrupted at %d %d\n", s->mb_x, s->mb_y); | |
2564 return -1; | |
2565 } | |
2566 } | |
2567 } | |
290 | 2568 |
2569 return 0; | |
2570 } | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2571 #if 0 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2572 static inline void decode_interlaced_info(MpegEncContext *s, int cbp, int mb_type){ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2573 s->mv_type= 0; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2574 if(!s->progressive_sequence){ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2575 if(cbp || s->mb_intra) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2576 s->interlaced_dct= get_bits1(&s->gb); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2577 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2578 if(!s->mb_intra){ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2579 if( s->pict_type==P_TYPE //FIXME check that 4MV is forbidden |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2580 || (s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && !s->mcsel) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2581 || (s->pict_type==B_TYPE && mb_type!=0) ){ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2582 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2583 if(get_bits1(&s->gb)){ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2584 s->mv_type= MV_TYPE_FIELD; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2585 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2586 if( s->pict_type==P_TYPE |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2587 || (s->pict_type==B_TYPE && mb_type!=2)){ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2588 s->field_select[0][0]= get_bits1(&s->gb); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2589 s->field_select[0][1]= get_bits1(&s->gb); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2590 } |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2591 if(s->pict_type==B_TYPE && mb_type!=3){ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2592 s->field_select[1][0]= get_bits1(&s->gb); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2593 s->field_select[1][1]= get_bits1(&s->gb); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2594 } |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2595 }else |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2596 s->mv_type= 0; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2597 } |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2598 } |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2599 } |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2600 } |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2601 #endif |
453 | 2602 |
0 | 2603 int h263_decode_mb(MpegEncContext *s, |
2604 DCTELEM block[6][64]) | |
2605 { | |
2606 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; | |
2607 INT16 *mot_val; | |
110 | 2608 static INT8 quant_tab[4] = { -1, -2, 1, 2 }; |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2609 |
523 | 2610 if(s->mb_x==0) PRINT_MB_TYPE("\n"); |
359 | 2611 |
290 | 2612 if(s->resync_marker){ |
453 | 2613 if(s->resync_mb_x == s->mb_x && s->resync_mb_y+1 == s->mb_y){ |
290 | 2614 s->first_slice_line=0; |
2615 } | |
2616 } | |
2617 | |
453 | 2618 if(s->data_partitioning && s->pict_type!=B_TYPE) |
2619 return mpeg4_decode_partitioned_mb(s, block); | |
2620 | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2621 if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) { |
21 | 2622 if (get_bits1(&s->gb)) { |
0 | 2623 /* skip mb */ |
2624 s->mb_intra = 0; | |
2625 for(i=0;i<6;i++) | |
2626 s->block_last_index[i] = -1; | |
2627 s->mv_dir = MV_DIR_FORWARD; | |
2628 s->mv_type = MV_TYPE_16X16; | |
255 | 2629 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ |
2630 const int a= s->sprite_warping_accuracy; | |
2631 // int l = (1 << (s->f_code - 1)) * 32; | |
359 | 2632 PRINT_MB_TYPE("G"); |
255 | 2633 s->mcsel=1; |
301 | 2634 if(s->divx_version==500 && s->divx_build==413){ |
2635 s->mv[0][0][0] = s->sprite_offset[0][0] / (1<<(a-s->quarter_sample)); | |
2636 s->mv[0][0][1] = s->sprite_offset[0][1] / (1<<(a-s->quarter_sample)); | |
2637 }else{ | |
2638 s->mv[0][0][0] = RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); | |
2639 s->mv[0][0][1] = RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); | |
2640 } | |
255 | 2641 /* if (s->mv[0][0][0] < -l) s->mv[0][0][0]= -l; |
2642 else if (s->mv[0][0][0] >= l) s->mv[0][0][0]= l-1; | |
2643 if (s->mv[0][0][1] < -l) s->mv[0][0][1]= -l; | |
2644 else if (s->mv[0][0][1] >= l) s->mv[0][0][1]= l-1;*/ | |
2645 | |
2646 s->mb_skiped = 0; | |
2647 }else{ | |
359 | 2648 PRINT_MB_TYPE("S"); |
255 | 2649 s->mcsel=0; |
2650 s->mv[0][0][0] = 0; | |
2651 s->mv[0][0][1] = 0; | |
2652 s->mb_skiped = 1; | |
2653 } | |
0 | 2654 return 0; |
2655 } | |
544 | 2656 cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); |
144 | 2657 //fprintf(stderr, "\tCBPC: %d", cbpc); |
0 | 2658 if (cbpc < 0) |
2659 return -1; | |
161 | 2660 if (cbpc > 20) |
2661 cbpc+=3; | |
2662 else if (cbpc == 20) | |
2663 fprintf(stderr, "Stuffing !"); | |
144 | 2664 |
0 | 2665 dquant = cbpc & 8; |
2666 s->mb_intra = ((cbpc & 4) != 0); | |
262 | 2667 if (s->mb_intra) goto intra; |
2668 | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2669 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2670 s->mcsel= get_bits1(&s->gb); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2671 else s->mcsel= 0; |
544 | 2672 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
0 | 2673 cbp = (cbpc & 3) | ((cbpy ^ 0xf) << 2); |
2674 if (dquant) { | |
2675 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
2676 if (s->qscale < 1) | |
2677 s->qscale = 1; | |
2678 else if (s->qscale > 31) | |
2679 s->qscale = 31; | |
290 | 2680 h263_dc_scale(s); |
0 | 2681 } |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2682 if((!s->progressive_sequence) && (cbp || s->workaround_bugs==2)) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2683 s->interlaced_dct= get_bits1(&s->gb); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2684 |
0 | 2685 s->mv_dir = MV_DIR_FORWARD; |
2686 if ((cbpc & 16) == 0) { | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2687 if(s->mcsel){ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2688 const int a= s->sprite_warping_accuracy; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2689 PRINT_MB_TYPE("G"); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2690 /* 16x16 global motion prediction */ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2691 s->mv_type = MV_TYPE_16X16; |
255 | 2692 // int l = (1 << (s->f_code - 1)) * 32; |
301 | 2693 if(s->divx_version==500 && s->divx_build==413){ |
2694 mx = s->sprite_offset[0][0] / (1<<(a-s->quarter_sample)); | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2695 my = s->sprite_offset[0][1] / (1<<(a-s->quarter_sample)); |
301 | 2696 }else{ |
2697 mx = RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); | |
2698 my = RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); | |
2699 } | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2700 // int l = (1 << (s->f_code - 1)) * 32; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2701 s->mv[0][0][0] = mx; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2702 s->mv[0][0][1] = my; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2703 }else if((!s->progressive_sequence) && get_bits1(&s->gb)){ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2704 PRINT_MB_TYPE("f"); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2705 /* 16x8 field motion prediction */ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2706 s->mv_type= MV_TYPE_FIELD; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2707 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2708 s->field_select[0][0]= get_bits1(&s->gb); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2709 s->field_select[0][1]= get_bits1(&s->gb); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2710 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2711 h263_pred_motion(s, 0, &pred_x, &pred_y); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2712 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2713 for(i=0; i<2; i++){ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2714 mx = h263_decode_motion(s, pred_x, s->f_code); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2715 if (mx >= 0xffff) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2716 return -1; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2717 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2718 my = h263_decode_motion(s, pred_y/2, s->f_code); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2719 if (my >= 0xffff) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2720 return -1; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2721 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2722 s->mv[0][i][0] = mx; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2723 s->mv[0][i][1] = my*2; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2724 } |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2725 }else{ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2726 PRINT_MB_TYPE("P"); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2727 /* 16x16 motion prediction */ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2728 s->mv_type = MV_TYPE_16X16; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2729 h263_pred_motion(s, 0, &pred_x, &pred_y); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2730 if (s->umvplus_dec) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2731 mx = h263p_decode_umotion(s, pred_x); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2732 else |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2733 mx = h263_decode_motion(s, pred_x, s->f_code); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2734 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2735 if (mx >= 0xffff) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2736 return -1; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2737 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2738 if (s->umvplus_dec) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2739 my = h263p_decode_umotion(s, pred_y); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2740 else |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2741 my = h263_decode_motion(s, pred_y, s->f_code); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2742 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2743 if (my >= 0xffff) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2744 return -1; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2745 s->mv[0][0][0] = mx; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2746 s->mv[0][0][1] = my; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2747 |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2748 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2749 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
255 | 2750 } |
0 | 2751 } else { |
359 | 2752 PRINT_MB_TYPE("4"); |
0 | 2753 s->mv_type = MV_TYPE_8X8; |
2754 for(i=0;i<4;i++) { | |
2755 mot_val = h263_pred_motion(s, i, &pred_x, &pred_y); | |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
2756 if (s->umvplus_dec) |
78 | 2757 mx = h263p_decode_umotion(s, pred_x); |
2758 else | |
262 | 2759 mx = h263_decode_motion(s, pred_x, s->f_code); |
0 | 2760 if (mx >= 0xffff) |
2761 return -1; | |
78 | 2762 |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
2763 if (s->umvplus_dec) |
78 | 2764 my = h263p_decode_umotion(s, pred_y); |
2765 else | |
262 | 2766 my = h263_decode_motion(s, pred_y, s->f_code); |
0 | 2767 if (my >= 0xffff) |
2768 return -1; | |
2769 s->mv[0][i][0] = mx; | |
2770 s->mv[0][i][1] = my; | |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
2771 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) |
78 | 2772 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
0 | 2773 mot_val[0] = mx; |
2774 mot_val[1] = my; | |
2775 } | |
2776 } | |
262 | 2777 } else if(s->pict_type==B_TYPE) { |
2778 int modb1; // first bit of modb | |
2779 int modb2; // second bit of modb | |
2780 int mb_type; | |
324 | 2781 uint16_t time_pp; |
2782 uint16_t time_pb; | |
262 | 2783 int xy; |
2784 | |
2785 s->mb_intra = 0; //B-frames never contain intra blocks | |
2786 s->mcsel=0; // ... true gmc blocks | |
2787 | |
2788 if(s->mb_x==0){ | |
2789 s->last_mv[0][0][0]= | |
2790 s->last_mv[0][0][1]= | |
2791 s->last_mv[1][0][0]= | |
2792 s->last_mv[1][0][1]= 0; | |
2793 } | |
2794 | |
2795 /* if we skipped it in the future P Frame than skip it now too */ | |
2796 s->mb_skiped= s->mbskip_table[s->mb_y * s->mb_width + s->mb_x]; // Note, skiptab=0 if last was GMC | |
2797 | |
2798 if(s->mb_skiped){ | |
2799 /* skip mb */ | |
2800 for(i=0;i<6;i++) | |
2801 s->block_last_index[i] = -1; | |
2802 | |
2803 s->mv_dir = MV_DIR_FORWARD; | |
2804 s->mv_type = MV_TYPE_16X16; | |
2805 s->mv[0][0][0] = 0; | |
2806 s->mv[0][0][1] = 0; | |
2807 s->mv[1][0][0] = 0; | |
2808 s->mv[1][0][1] = 0; | |
523 | 2809 PRINT_MB_TYPE("s"); |
262 | 2810 return 0; |
2811 } | |
2812 | |
2813 modb1= get_bits1(&s->gb); | |
2814 if(modb1==0){ | |
2815 modb2= get_bits1(&s->gb); | |
544 | 2816 mb_type= get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1); |
262 | 2817 if(modb2==0) cbp= get_bits(&s->gb, 6); |
2818 else cbp=0; | |
2819 if (mb_type && cbp) { | |
2820 if(get_bits1(&s->gb)){ | |
2821 s->qscale +=get_bits1(&s->gb)*4 - 2; | |
2822 if (s->qscale < 1) | |
2823 s->qscale = 1; | |
2824 else if (s->qscale > 31) | |
2825 s->qscale = 31; | |
290 | 2826 h263_dc_scale(s); |
262 | 2827 } |
2828 } | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2829 // decode_interlaced_info(s, cbp, mb_type); |
262 | 2830 }else{ |
2831 mb_type=4; //like 0 but no vectors coded | |
2832 cbp=0; | |
2833 } | |
2834 s->mv_type = MV_TYPE_16X16; // we'll switch to 8x8 only if the last P frame had 8x8 for this MB and mb_type=0 here | |
2835 mx=my=0; //for case 4, we could put this to the mb_type=4 but than gcc compains about uninitalized mx/my | |
2836 switch(mb_type) | |
2837 { | |
324 | 2838 case 0: /* direct */ |
262 | 2839 mx = h263_decode_motion(s, 0, 1); |
2840 my = h263_decode_motion(s, 0, 1); | |
324 | 2841 case 4: /* direct with mx=my=0 */ |
262 | 2842 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
266 | 2843 xy= s->block_index[0]; |
324 | 2844 time_pp= s->pp_time; |
2845 time_pb= time_pp - s->bp_time; | |
262 | 2846 //if(time_pp>3000 )printf("%d %d ", time_pp, time_pb); |
2847 //FIXME avoid divides | |
2848 s->mv[0][0][0] = s->motion_val[xy][0]*time_pb/time_pp + mx; | |
2849 s->mv[0][0][1] = s->motion_val[xy][1]*time_pb/time_pp + my; | |
2850 s->mv[1][0][0] = mx ? s->mv[0][0][0] - s->motion_val[xy][0] | |
2851 : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp + mx; | |
2852 s->mv[1][0][1] = my ? s->mv[0][0][1] - s->motion_val[xy][1] | |
2853 : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp + my; | |
598 | 2854 if(s->non_b_mv4_table[xy]){ |
2855 int i; | |
2856 s->mv_type = MV_TYPE_8X8; | |
2857 for(i=1; i<4; i++){ | |
2858 xy= s->block_index[i]; | |
2859 s->mv[0][i][0] = s->motion_val[xy][0]*time_pb/time_pp + mx; | |
2860 s->mv[0][i][1] = s->motion_val[xy][1]*time_pb/time_pp + my; | |
2861 s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->motion_val[xy][0] | |
2862 : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp + mx; | |
2863 s->mv[1][i][1] = my ? s->mv[0][i][1] - s->motion_val[xy][1] | |
2864 : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp + my; | |
2865 } | |
2866 PRINT_MB_TYPE("4"); | |
2867 }else{ | |
2868 PRINT_MB_TYPE(mb_type==4 ? "D" : "S"); | |
2869 } | |
262 | 2870 /* s->mv[0][0][0] = |
2871 s->mv[0][0][1] = | |
2872 s->mv[1][0][0] = | |
2873 s->mv[1][0][1] = 1000;*/ | |
2874 break; | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2875 //FIXME additional MVs for interlaced stuff |
262 | 2876 case 1: |
2877 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
2878 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); | |
2879 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); | |
2880 s->last_mv[0][0][0]= s->mv[0][0][0] = mx; | |
2881 s->last_mv[0][0][1]= s->mv[0][0][1] = my; | |
2882 | |
2883 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); | |
2884 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); | |
2885 s->last_mv[1][0][0]= s->mv[1][0][0] = mx; | |
2886 s->last_mv[1][0][1]= s->mv[1][0][1] = my; | |
359 | 2887 PRINT_MB_TYPE("i"); |
262 | 2888 break; |
2889 case 2: | |
2890 s->mv_dir = MV_DIR_BACKWARD; | |
2891 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); | |
2892 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); | |
2893 s->last_mv[1][0][0]= s->mv[1][0][0] = mx; | |
2894 s->last_mv[1][0][1]= s->mv[1][0][1] = my; | |
359 | 2895 PRINT_MB_TYPE("B"); |
262 | 2896 break; |
2897 case 3: | |
2898 s->mv_dir = MV_DIR_FORWARD; | |
2899 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); | |
2900 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); | |
2901 s->last_mv[0][0][0]= s->mv[0][0][0] = mx; | |
2902 s->last_mv[0][0][1]= s->mv[0][0][1] = my; | |
359 | 2903 PRINT_MB_TYPE("F"); |
262 | 2904 break; |
364
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
2905 default: |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
2906 printf("illegal MB_type\n"); |
6b6332e7008a
segfault fix for b-frame encoding with height%16!=0
michaelni
parents:
360
diff
changeset
|
2907 return -1; |
262 | 2908 } |
2909 } else { /* I-Frame */ | |
544 | 2910 cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1); |
262 | 2911 if (cbpc < 0) |
2912 return -1; | |
2913 dquant = cbpc & 4; | |
2914 s->mb_intra = 1; | |
2915 intra: | |
0 | 2916 s->ac_pred = 0; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2917 if (s->h263_pred || s->h263_aic) { |
21 | 2918 s->ac_pred = get_bits1(&s->gb); |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2919 if (s->ac_pred && s->h263_aic) |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2920 s->h263_aic_dir = get_bits1(&s->gb); |
0 | 2921 } |
591 | 2922 PRINT_MB_TYPE(s->ac_pred ? "A" : "I"); |
2923 | |
544 | 2924 cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
453 | 2925 if(cbpy<0) return -1; |
0 | 2926 cbp = (cbpc & 3) | (cbpy << 2); |
2927 if (dquant) { | |
2928 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
2929 if (s->qscale < 1) | |
2930 s->qscale = 1; | |
2931 else if (s->qscale > 31) | |
2932 s->qscale = 31; | |
290 | 2933 h263_dc_scale(s); |
0 | 2934 } |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2935 if(!s->progressive_sequence) |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
2936 s->interlaced_dct= get_bits1(&s->gb); |
575 | 2937 |
2938 /* decode each block */ | |
2939 if (s->h263_pred) { | |
2940 for (i = 0; i < 6; i++) { | |
2941 if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 1) < 0) | |
2942 return -1; | |
2943 } | |
2944 } else { | |
2945 for (i = 0; i < 6; i++) { | |
2946 if (h263_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) | |
2947 return -1; | |
2948 } | |
2949 } | |
2950 return 0; | |
0 | 2951 } |
2952 | |
2953 /* decode each block */ | |
2954 if (s->h263_pred) { | |
575 | 2955 for (i = 0; i < 6; i++) { |
2956 if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, 0) < 0) | |
0 | 2957 return -1; |
575 | 2958 } |
0 | 2959 } else { |
575 | 2960 for (i = 0; i < 6; i++) { |
2961 if (h263_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) | |
0 | 2962 return -1; |
575 | 2963 } |
0 | 2964 } |
2965 return 0; | |
2966 } | |
2967 | |
262 | 2968 static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) |
0 | 2969 { |
2970 int code, val, sign, shift, l, m; | |
2971 | |
544 | 2972 code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); |
0 | 2973 if (code < 0) |
2974 return 0xffff; | |
2975 | |
2976 if (code == 0) | |
2977 return pred; | |
21 | 2978 sign = get_bits1(&s->gb); |
262 | 2979 shift = f_code - 1; |
0 | 2980 val = (code - 1) << shift; |
2981 if (shift > 0) | |
2982 val |= get_bits(&s->gb, shift); | |
2983 val++; | |
2984 if (sign) | |
2985 val = -val; | |
2986 val += pred; | |
475 | 2987 |
0 | 2988 /* modulo decoding */ |
2989 if (!s->h263_long_vectors) { | |
262 | 2990 l = (1 << (f_code - 1)) * 32; |
0 | 2991 m = 2 * l; |
2992 if (val < -l) { | |
2993 val += m; | |
2994 } else if (val >= l) { | |
2995 val -= m; | |
2996 } | |
2997 } else { | |
2998 /* horrible h263 long vector mode */ | |
2999 if (pred < -31 && val < -63) | |
3000 val += 64; | |
3001 if (pred > 32 && val > 63) | |
3002 val -= 64; | |
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
3003 |
0 | 3004 } |
3005 return val; | |
3006 } | |
3007 | |
78 | 3008 /* Decodes RVLC of H.263+ UMV */ |
3009 static int h263p_decode_umotion(MpegEncContext * s, int pred) | |
3010 { | |
3011 int code = 0, sign; | |
3012 | |
3013 if (get_bits1(&s->gb)) /* Motion difference = 0 */ | |
3014 return pred; | |
3015 | |
3016 code = 2 + get_bits1(&s->gb); | |
3017 | |
3018 while (get_bits1(&s->gb)) | |
3019 { | |
3020 code <<= 1; | |
3021 code += get_bits1(&s->gb); | |
3022 } | |
3023 sign = code & 1; | |
3024 code >>= 1; | |
3025 | |
3026 code = (sign) ? (pred - code) : (pred + code); | |
3027 #ifdef DEBUG | |
3028 fprintf(stderr,"H.263+ UMV Motion = %d\n", code); | |
3029 #endif | |
3030 return code; | |
3031 | |
3032 } | |
3033 | |
0 | 3034 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
3035 int n, int coded) | |
3036 { | |
3037 int code, level, i, j, last, run; | |
3038 RLTable *rl = &rl_inter; | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3039 const UINT8 *scan_table; |
0 | 3040 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3041 scan_table = zigzag_direct; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3042 if (s->h263_aic && s->mb_intra) { |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3043 rl = &rl_intra_aic; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3044 i = 0; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3045 if (s->ac_pred) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3046 if (s->h263_aic_dir) |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3047 scan_table = ff_alternate_vertical_scan; /* left */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3048 else |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3049 scan_table = ff_alternate_horizontal_scan; /* top */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3050 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3051 } else if (s->mb_intra) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3052 /* DC coef */ |
0 | 3053 if (s->h263_rv10 && s->rv10_version == 3 && s->pict_type == I_TYPE) { |
3054 int component, diff; | |
3055 component = (n <= 3 ? 0 : n - 4 + 1); | |
3056 level = s->last_dc[component]; | |
3057 if (s->rv10_first_dc_coded[component]) { | |
3058 diff = rv_decode_dc(s, n); | |
3059 if (diff == 0xffff) | |
3060 return -1; | |
3061 level += diff; | |
3062 level = level & 0xff; /* handle wrap round */ | |
3063 s->last_dc[component] = level; | |
3064 } else { | |
3065 s->rv10_first_dc_coded[component] = 1; | |
3066 } | |
3067 } else { | |
3068 level = get_bits(&s->gb, 8); | |
3069 if (level == 255) | |
3070 level = 128; | |
3071 } | |
3072 block[0] = level; | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3073 i = 1; |
0 | 3074 } else { |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3075 i = 0; |
0 | 3076 } |
3077 if (!coded) { | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3078 if (s->mb_intra && s->h263_aic) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3079 goto not_coded; |
0 | 3080 s->block_last_index[n] = i - 1; |
3081 return 0; | |
3082 } | |
3083 | |
3084 for(;;) { | |
544 | 3085 code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); |
0 | 3086 if (code < 0) |
3087 return -1; | |
3088 if (code == rl->n) { | |
3089 /* escape */ | |
21 | 3090 last = get_bits1(&s->gb); |
0 | 3091 run = get_bits(&s->gb, 6); |
3092 level = (INT8)get_bits(&s->gb, 8); | |
3093 if (s->h263_rv10 && level == -128) { | |
3094 /* XXX: should patch encoder too */ | |
3095 level = get_bits(&s->gb, 12); | |
617 | 3096 level= (level + ((-1)<<11)) ^ ((-1)<<11); //sign extension |
0 | 3097 } |
3098 } else { | |
3099 run = rl->table_run[code]; | |
3100 level = rl->table_level[code]; | |
3101 last = code >= rl->last; | |
21 | 3102 if (get_bits1(&s->gb)) |
0 | 3103 level = -level; |
3104 } | |
3105 i += run; | |
3106 if (i >= 64) | |
3107 return -1; | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3108 j = scan_table[i]; |
0 | 3109 block[j] = level; |
3110 if (last) | |
3111 break; | |
3112 i++; | |
3113 } | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3114 not_coded: |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3115 if (s->mb_intra && s->h263_aic) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3116 h263_pred_acdc(s, block, n); |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
3117 i = 63; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3118 } |
0 | 3119 s->block_last_index[n] = i; |
3120 return 0; | |
3121 } | |
3122 | |
453 | 3123 static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) |
0 | 3124 { |
3125 int level, pred, code; | |
3126 UINT16 *dc_val; | |
3127 | |
3128 if (n < 4) | |
544 | 3129 code = get_vlc2(&s->gb, dc_lum.table, DC_VLC_BITS, 1); |
0 | 3130 else |
544 | 3131 code = get_vlc2(&s->gb, dc_chrom.table, DC_VLC_BITS, 1); |
453 | 3132 if (code < 0 || code > 9 /* && s->nbit<9 */){ |
3133 fprintf(stderr, "illegal dc vlc\n"); | |
0 | 3134 return -1; |
453 | 3135 } |
0 | 3136 if (code == 0) { |
3137 level = 0; | |
3138 } else { | |
3139 level = get_bits(&s->gb, code); | |
3140 if ((level >> (code - 1)) == 0) /* if MSB not set it is negative*/ | |
3141 level = - (level ^ ((1 << code) - 1)); | |
453 | 3142 if (code > 8){ |
3143 if(get_bits1(&s->gb)==0){ /* marker */ | |
3144 fprintf(stderr, "dc marker bit missing\n"); | |
3145 return -1; | |
3146 } | |
3147 } | |
0 | 3148 } |
3149 | |
498 | 3150 pred = ff_mpeg4_pred_dc(s, n, &dc_val, dir_ptr); |
0 | 3151 level += pred; |
3152 if (level < 0) | |
3153 level = 0; | |
3154 if (n < 4) { | |
3155 *dc_val = level * s->y_dc_scale; | |
3156 } else { | |
3157 *dc_val = level * s->c_dc_scale; | |
3158 } | |
3159 return level; | |
3160 } | |
3161 | |
453 | 3162 /** |
3163 * decode a block | |
3164 * returns 0 if everything went ok | |
3165 * returns DECODING_AC_LOST if an error was detected during AC decoding | |
3166 * returns DECODING_ACDC_LOST if an error was detected during DC decoding | |
3167 */ | |
3168 static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | |
575 | 3169 int n, int coded, int intra) |
0 | 3170 { |
549 | 3171 int level, i, last, run; |
0 | 3172 int dc_pred_dir; |
575 | 3173 RLTable * rl; |
3174 RL_VLC_ELEM * rl_vlc; | |
3175 const UINT8 * scan_table; | |
549 | 3176 int qmul, qadd; |
0 | 3177 |
575 | 3178 if(intra) { |
0 | 3179 /* DC coef */ |
453 | 3180 if(s->data_partitioning && s->pict_type!=B_TYPE){ |
3181 level = s->dc_val[0][ s->block_index[n] ]; | |
3182 if(n<4) level= (level + (s->y_dc_scale>>1))/s->y_dc_scale; //FIXME optimizs | |
3183 else level= (level + (s->c_dc_scale>>1))/s->c_dc_scale; | |
3184 dc_pred_dir= (s->pred_dir_table[s->mb_x + s->mb_y*s->mb_width]<<n)&32; | |
3185 }else{ | |
3186 level = mpeg4_decode_dc(s, n, &dc_pred_dir); | |
3187 if (level < 0) | |
3188 return DECODING_ACDC_LOST; | |
3189 } | |
0 | 3190 block[0] = level; |
549 | 3191 i = 0; |
0 | 3192 if (!coded) |
3193 goto not_coded; | |
3194 rl = &rl_intra; | |
549 | 3195 rl_vlc = rl_intra.rl_vlc[0]; |
0 | 3196 if (s->ac_pred) { |
3197 if (dc_pred_dir == 0) | |
3198 scan_table = ff_alternate_vertical_scan; /* left */ | |
3199 else | |
3200 scan_table = ff_alternate_horizontal_scan; /* top */ | |
3201 } else { | |
3202 scan_table = zigzag_direct; | |
3203 } | |
549 | 3204 qmul=1; |
3205 qadd=0; | |
0 | 3206 } else { |
549 | 3207 i = -1; |
0 | 3208 if (!coded) { |
549 | 3209 s->block_last_index[n] = i; |
0 | 3210 return 0; |
3211 } | |
3212 rl = &rl_inter; | |
3213 scan_table = zigzag_direct; | |
591 | 3214 if(s->mpeg_quant){ |
3215 qmul=1; | |
3216 qadd=0; | |
3217 rl_vlc = rl_inter.rl_vlc[0]; | |
3218 }else{ | |
3219 qmul = s->qscale << 1; | |
3220 qadd = (s->qscale - 1) | 1; | |
3221 rl_vlc = rl_inter.rl_vlc[s->qscale]; | |
3222 } | |
0 | 3223 } |
549 | 3224 { |
3225 OPEN_READER(re, &s->gb); | |
0 | 3226 for(;;) { |
549 | 3227 UPDATE_CACHE(re, &s->gb); |
3228 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2); | |
3229 if (level==0) { | |
3230 int cache; | |
3231 cache= GET_CACHE(re, &s->gb); | |
0 | 3232 /* escape */ |
549 | 3233 if (cache&0x80000000) { |
3234 if (cache&0x40000000) { | |
0 | 3235 /* third escape */ |
549 | 3236 SKIP_CACHE(re, &s->gb, 2); |
3237 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); | |
3238 run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6); | |
3239 SKIP_COUNTER(re, &s->gb, 2+1+6); | |
3240 UPDATE_CACHE(re, &s->gb); | |
3241 | |
3242 if(SHOW_UBITS(re, &s->gb, 1)==0){ | |
453 | 3243 fprintf(stderr, "1. marker bit missing in 3. esc\n"); |
3244 return DECODING_AC_LOST; | |
549 | 3245 }; SKIP_CACHE(re, &s->gb, 1); |
3246 | |
3247 level= SHOW_SBITS(re, &s->gb, 12); SKIP_CACHE(re, &s->gb, 12); | |
3248 | |
3249 if(SHOW_UBITS(re, &s->gb, 1)==0){ | |
453 | 3250 fprintf(stderr, "2. marker bit missing in 3. esc\n"); |
3251 return DECODING_AC_LOST; | |
549 | 3252 }; LAST_SKIP_CACHE(re, &s->gb, 1); |
3253 | |
3254 SKIP_COUNTER(re, &s->gb, 1+12+1); | |
3255 | |
597 | 3256 if(level*s->qscale>1024 || level*s->qscale<-1024){ |
3257 fprintf(stderr, "|level| overflow in 3. esc, qp=%d\n", s->qscale); | |
453 | 3258 return DECODING_AC_LOST; |
3259 } | |
3260 #if 1 | |
3261 { | |
3262 const int abs_level= ABS(level); | |
3263 if(abs_level<=MAX_LEVEL && run<=MAX_RUN && s->error_resilience>=0){ | |
498 | 3264 const int run1= run - rl->max_run[last][abs_level] - 1; |
453 | 3265 if(abs_level <= rl->max_level[last][run]){ |
3266 fprintf(stderr, "illegal 3. esc, vlc encoding possible\n"); | |
3267 return DECODING_AC_LOST; | |
3268 } | |
3269 if(abs_level <= rl->max_level[last][run]*2){ | |
3270 fprintf(stderr, "illegal 3. esc, esc 1 encoding possible\n"); | |
3271 return DECODING_AC_LOST; | |
3272 } | |
475 | 3273 if(run1 >= 0 && abs_level <= rl->max_level[last][run1]){ |
453 | 3274 fprintf(stderr, "illegal 3. esc, esc 2 encoding possible\n"); |
3275 return DECODING_AC_LOST; | |
3276 } | |
3277 } | |
3278 } | |
3279 #endif | |
549 | 3280 if (level>0) level= level * qmul + qadd; |
3281 else level= level * qmul - qadd; | |
3282 | |
3283 i+= run + 1; | |
3284 if(last) i+=192; | |
0 | 3285 } else { |
3286 /* second escape */ | |
549 | 3287 #if MIN_CACHE_BITS < 20 |
3288 LAST_SKIP_BITS(re, &s->gb, 2); | |
3289 UPDATE_CACHE(re, &s->gb); | |
3290 #else | |
3291 SKIP_BITS(re, &s->gb, 2); | |
3292 #endif | |
3293 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2); | |
3294 i+= run + rl->max_run[run>>7][level/qmul] +1; //FIXME opt indexing | |
3295 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
3296 LAST_SKIP_BITS(re, &s->gb, 1); | |
0 | 3297 } |
3298 } else { | |
3299 /* first escape */ | |
549 | 3300 #if MIN_CACHE_BITS < 19 |
3301 LAST_SKIP_BITS(re, &s->gb, 1); | |
3302 UPDATE_CACHE(re, &s->gb); | |
3303 #else | |
3304 SKIP_BITS(re, &s->gb, 1); | |
3305 #endif | |
3306 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2); | |
3307 i+= run; | |
3308 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing | |
3309 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
3310 LAST_SKIP_BITS(re, &s->gb, 1); | |
0 | 3311 } |
3312 } else { | |
549 | 3313 i+= run; |
3314 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); | |
3315 LAST_SKIP_BITS(re, &s->gb, 1); | |
0 | 3316 } |
549 | 3317 if (i > 62){ |
3318 i-= 192; | |
3319 if(i&(~63)){ | |
3320 fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); | |
3321 return DECODING_AC_LOST; | |
3322 } | |
3323 | |
3324 block[scan_table[i]] = level; | |
0 | 3325 break; |
549 | 3326 } |
3327 | |
3328 block[scan_table[i]] = level; | |
0 | 3329 } |
549 | 3330 CLOSE_READER(re, &s->gb); |
3331 } | |
0 | 3332 not_coded: |
3333 if (s->mb_intra) { | |
3334 mpeg4_pred_ac(s, block, n, dc_pred_dir); | |
3335 if (s->ac_pred) { | |
549 | 3336 i = 63; /* XXX: not optimal */ |
0 | 3337 } |
3338 } | |
549 | 3339 s->block_last_index[n] = i; |
0 | 3340 return 0; |
3341 } | |
3342 | |
3343 /* most is hardcoded. should extend to handle all h263 streams */ | |
3344 int h263_decode_picture_header(MpegEncContext *s) | |
3345 { | |
3346 int format, width, height; | |
3347 | |
355 | 3348 /* picture start code */ |
3349 if (get_bits(&s->gb, 22) != 0x20) { | |
3350 fprintf(stderr, "Bad picture start code\n"); | |
0 | 3351 return -1; |
355 | 3352 } |
3353 /* temporal reference */ | |
231 | 3354 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ |
355 | 3355 |
3356 /* PTYPE starts here */ | |
3357 if (get_bits1(&s->gb) != 1) { | |
3358 /* marker */ | |
3359 fprintf(stderr, "Bad marker\n"); | |
3360 return -1; | |
3361 } | |
3362 if (get_bits1(&s->gb) != 0) { | |
3363 fprintf(stderr, "Bad H263 id\n"); | |
0 | 3364 return -1; /* h263 id */ |
355 | 3365 } |
21 | 3366 skip_bits1(&s->gb); /* split screen off */ |
3367 skip_bits1(&s->gb); /* camera off */ | |
3368 skip_bits1(&s->gb); /* freeze picture release off */ | |
0 | 3369 |
155
3c3449bce692
- Bug fix on MV prediction for MPEG4 caused by new H.263 GOB code.
pulento
parents:
154
diff
changeset
|
3370 /* Reset GOB number */ |
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
3371 s->gob_number = 0; |
155
3c3449bce692
- Bug fix on MV prediction for MPEG4 caused by new H.263 GOB code.
pulento
parents:
154
diff
changeset
|
3372 |
0 | 3373 format = get_bits(&s->gb, 3); |
355 | 3374 /* |
3375 0 forbidden | |
3376 1 sub-QCIF | |
3377 10 QCIF | |
3378 7 extended PTYPE (PLUSPTYPE) | |
3379 */ | |
0 | 3380 |
161 | 3381 if (format != 7 && format != 6) { |
0 | 3382 s->h263_plus = 0; |
3383 /* H.263v1 */ | |
3384 width = h263_format[format][0]; | |
3385 height = h263_format[format][1]; | |
3386 if (!width) | |
3387 return -1; | |
161 | 3388 |
3389 s->width = width; | |
3390 s->height = height; | |
21 | 3391 s->pict_type = I_TYPE + get_bits1(&s->gb); |
0 | 3392 |
21 | 3393 s->unrestricted_mv = get_bits1(&s->gb); |
0 | 3394 s->h263_long_vectors = s->unrestricted_mv; |
3395 | |
355 | 3396 if (get_bits1(&s->gb) != 0) { |
3397 fprintf(stderr, "H263 SAC not supported\n"); | |
0 | 3398 return -1; /* SAC: off */ |
355 | 3399 } |
161 | 3400 if (get_bits1(&s->gb) != 0) { |
3401 s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */ | |
3402 } | |
3403 | |
355 | 3404 if (get_bits1(&s->gb) != 0) { |
3405 fprintf(stderr, "H263 PB frame not supported\n"); | |
0 | 3406 return -1; /* not PB frame */ |
355 | 3407 } |
0 | 3408 s->qscale = get_bits(&s->gb, 5); |
21 | 3409 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
0 | 3410 } else { |
161 | 3411 int ufep; |
3412 | |
0 | 3413 /* H.263v2 */ |
161 | 3414 s->h263_plus = 1; |
3415 ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */ | |
355 | 3416 |
3417 /* ufep other than 0 and 1 are reserved */ | |
161 | 3418 if (ufep == 1) { |
3419 /* OPPTYPE */ | |
3420 format = get_bits(&s->gb, 3); | |
355 | 3421 dprintf("ufep=1, format: %d\n", format); |
161 | 3422 skip_bits(&s->gb,1); /* Custom PCF */ |
3423 s->umvplus_dec = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */ | |
3424 skip_bits1(&s->gb); /* Syntax-based Arithmetic Coding (SAC) */ | |
3425 if (get_bits1(&s->gb) != 0) { | |
3426 s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */ | |
3427 } | |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3428 if (get_bits1(&s->gb) != 0) { /* Advanced Intra Coding (AIC) */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3429 s->h263_aic = 1; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3430 } |
355 | 3431 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
3432 skip_bits(&s->gb, 7); |
355 | 3433 /* these are the 7 bits: (in order of appearence */ |
3434 /* Deblocking Filter */ | |
3435 /* Slice Structured */ | |
3436 /* Reference Picture Selection */ | |
3437 /* Independent Segment Decoding */ | |
3438 /* Alternative Inter VLC */ | |
3439 /* Modified Quantization */ | |
3440 /* Prevent start code emulation */ | |
3441 | |
161 | 3442 skip_bits(&s->gb, 3); /* Reserved */ |
355 | 3443 } else if (ufep != 0) { |
3444 fprintf(stderr, "Bad UFEP type (%d)\n", ufep); | |
0 | 3445 return -1; |
355 | 3446 } |
161 | 3447 |
78 | 3448 /* MPPTYPE */ |
355 | 3449 s->pict_type = get_bits(&s->gb, 3) + I_TYPE; |
3450 dprintf("pict_type: %d\n", s->pict_type); | |
0 | 3451 if (s->pict_type != I_TYPE && |
3452 s->pict_type != P_TYPE) | |
3453 return -1; | |
250
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
3454 skip_bits(&s->gb, 2); |
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
3455 s->no_rounding = get_bits1(&s->gb); |
355 | 3456 dprintf("RTYPE: %d\n", s->no_rounding); |
250
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
3457 skip_bits(&s->gb, 4); |
78 | 3458 |
3459 /* Get the picture dimensions */ | |
161 | 3460 if (ufep) { |
3461 if (format == 6) { | |
3462 /* Custom Picture Format (CPFMT) */ | |
355 | 3463 s->aspect_ratio_info = get_bits(&s->gb, 4); |
3464 dprintf("aspect: %d\n", s->aspect_ratio_info); | |
3465 /* aspect ratios: | |
3466 0 - forbidden | |
3467 1 - 1:1 | |
3468 2 - 12:11 (CIF 4:3) | |
3469 3 - 10:11 (525-type 4:3) | |
3470 4 - 16:11 (CIF 16:9) | |
3471 5 - 40:33 (525-type 16:9) | |
3472 6-14 - reserved | |
3473 */ | |
161 | 3474 width = (get_bits(&s->gb, 9) + 1) * 4; |
3475 skip_bits1(&s->gb); | |
3476 height = get_bits(&s->gb, 9) * 4; | |
355 | 3477 dprintf("\nH.263+ Custom picture: %dx%d\n",width,height); |
3478 if (s->aspect_ratio_info == EXTENDED_PAR) { | |
3479 /* aspected dimensions */ | |
3480 skip_bits(&s->gb, 8); /* width */ | |
3481 skip_bits(&s->gb, 8); /* height */ | |
3482 } | |
3483 } else { | |
161 | 3484 width = h263_format[format][0]; |
3485 height = h263_format[format][1]; | |
3486 } | |
3487 if ((width == 0) || (height == 0)) | |
3488 return -1; | |
3489 s->width = width; | |
3490 s->height = height; | |
3491 if (s->umvplus_dec) { | |
3492 skip_bits1(&s->gb); /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | |
3493 } | |
78 | 3494 } |
3495 | |
0 | 3496 s->qscale = get_bits(&s->gb, 5); |
3497 } | |
3498 /* PEI */ | |
21 | 3499 while (get_bits1(&s->gb) != 0) { |
3500 skip_bits(&s->gb, 8); | |
0 | 3501 } |
3502 s->f_code = 1; | |
498 | 3503 |
3504 if(s->h263_aic){ | |
3505 s->y_dc_scale_table= | |
3506 s->c_dc_scale_table= h263_aic_dc_scale_table; | |
3507 }else{ | |
3508 s->y_dc_scale_table= | |
3509 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
3510 } | |
3511 | |
0 | 3512 return 0; |
3513 } | |
3514 | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3515 static void mpeg4_decode_sprite_trajectory(MpegEncContext * s) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3516 { |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3517 int i; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3518 int a= 2<<s->sprite_warping_accuracy; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3519 int rho= 3-s->sprite_warping_accuracy; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3520 int r=16/a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3521 const int vop_ref[4][2]= {{0,0}, {s->width,0}, {0, s->height}, {s->width, s->height}}; // only true for rectangle shapes |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3522 int d[4][2]={{0,0}, {0,0}, {0,0}, {0,0}}; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3523 int sprite_ref[4][2]; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3524 int virtual_ref[2][2]; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3525 int w2, h2; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3526 int alpha=0, beta=0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3527 int w= s->width; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3528 int h= s->height; |
255 | 3529 //printf("SP %d\n", s->sprite_warping_accuracy); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3530 for(i=0; i<s->num_sprite_warping_points; i++){ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3531 int length; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3532 int x=0, y=0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3533 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3534 length= get_vlc(&s->gb, &sprite_trajectory); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3535 if(length){ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3536 x= get_bits(&s->gb, length); |
255 | 3537 //printf("lx %d %d\n", length, x); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3538 if ((x >> (length - 1)) == 0) /* if MSB not set it is negative*/ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3539 x = - (x ^ ((1 << length) - 1)); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3540 } |
255 | 3541 if(!(s->divx_version==500 && s->divx_build==413)) skip_bits1(&s->gb); /* marker bit */ |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3542 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3543 length= get_vlc(&s->gb, &sprite_trajectory); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3544 if(length){ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3545 y=get_bits(&s->gb, length); |
255 | 3546 //printf("ly %d %d\n", length, y); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3547 if ((y >> (length - 1)) == 0) /* if MSB not set it is negative*/ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3548 y = - (y ^ ((1 << length) - 1)); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3549 } |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3550 skip_bits1(&s->gb); /* marker bit */ |
255 | 3551 //printf("%d %d %d %d\n", x, y, i, s->sprite_warping_accuracy); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3552 //if(i>0 && (x!=0 || y!=0)) printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); |
255 | 3553 //x=y=0; |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3554 d[i][0]= x; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3555 d[i][1]= y; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3556 } |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3557 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3558 while((1<<alpha)<w) alpha++; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3559 while((1<<beta )<h) beta++; // there seems to be a typo in the mpeg4 std for the definition of w' and h' |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3560 w2= 1<<alpha; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3561 h2= 1<<beta; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3562 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3563 // Note, the 4th point isnt used for GMC |
262 | 3564 if(s->divx_version==500 && s->divx_build==413){ |
3565 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0]; | |
3566 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1]; | |
3567 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0]; | |
3568 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1]; | |
3569 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0]; | |
3570 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1]; | |
3571 } else { | |
3572 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]); | |
3573 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]); | |
3574 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]); | |
3575 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]); | |
3576 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]); | |
3577 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]); | |
3578 } | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3579 /* sprite_ref[3][0]= (a>>1)*(2*vop_ref[3][0] + d[0][0] + d[1][0] + d[2][0] + d[3][0]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3580 sprite_ref[3][1]= (a>>1)*(2*vop_ref[3][1] + d[0][1] + d[1][1] + d[2][1] + d[3][1]); */ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3581 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3582 // this is mostly identical to the mpeg4 std (and is totally unreadable because of that ...) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3583 // perhaps it should be reordered to be more readable ... |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3584 // the idea behind this virtual_ref mess is to be able to use shifts later per pixel instead of divides |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3585 // so the distance between points is converted from w&h based to w2&h2 based which are of the 2^x form |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3586 virtual_ref[0][0]= 16*(vop_ref[0][0] + w2) |
359 | 3587 + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + w2*(r*sprite_ref[1][0] - 16*vop_ref[1][0])),w); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3588 virtual_ref[0][1]= 16*vop_ref[0][1] |
359 | 3589 + ROUNDED_DIV(((w - w2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + w2*(r*sprite_ref[1][1] - 16*vop_ref[1][1])),w); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3590 virtual_ref[1][0]= 16*vop_ref[0][0] |
359 | 3591 + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][0] - 16*vop_ref[0][0]) + h2*(r*sprite_ref[2][0] - 16*vop_ref[2][0])),h); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3592 virtual_ref[1][1]= 16*(vop_ref[0][1] + h2) |
359 | 3593 + ROUNDED_DIV(((h - h2)*(r*sprite_ref[0][1] - 16*vop_ref[0][1]) + h2*(r*sprite_ref[2][1] - 16*vop_ref[2][1])),h); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3594 |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3595 switch(s->num_sprite_warping_points) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3596 { |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3597 case 0: |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3598 s->sprite_offset[0][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3599 s->sprite_offset[0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3600 s->sprite_offset[1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3601 s->sprite_offset[1][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3602 s->sprite_delta[0][0][0]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3603 s->sprite_delta[0][0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3604 s->sprite_delta[0][1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3605 s->sprite_delta[0][1][1]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3606 s->sprite_delta[1][0][0]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3607 s->sprite_delta[1][0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3608 s->sprite_delta[1][1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3609 s->sprite_delta[1][1][1]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3610 s->sprite_shift[0][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3611 s->sprite_shift[0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3612 s->sprite_shift[1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3613 s->sprite_shift[1][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3614 break; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3615 case 1: //GMC only |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3616 s->sprite_offset[0][0]= sprite_ref[0][0] - a*vop_ref[0][0]; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3617 s->sprite_offset[0][1]= sprite_ref[0][1] - a*vop_ref[0][1]; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3618 s->sprite_offset[1][0]= ((sprite_ref[0][0]>>1)|(sprite_ref[0][0]&1)) - a*(vop_ref[0][0]/2); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3619 s->sprite_offset[1][1]= ((sprite_ref[0][1]>>1)|(sprite_ref[0][1]&1)) - a*(vop_ref[0][1]/2); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3620 s->sprite_delta[0][0][0]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3621 s->sprite_delta[0][0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3622 s->sprite_delta[0][1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3623 s->sprite_delta[0][1][1]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3624 s->sprite_delta[1][0][0]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3625 s->sprite_delta[1][0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3626 s->sprite_delta[1][1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3627 s->sprite_delta[1][1][1]= a; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3628 s->sprite_shift[0][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3629 s->sprite_shift[0][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3630 s->sprite_shift[1][0]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3631 s->sprite_shift[1][1]= 0; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3632 break; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3633 case 2: |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3634 case 3: //FIXME |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3635 s->sprite_offset[0][0]= (sprite_ref[0][0]<<(alpha+rho)) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3636 + ((-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][0]) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3637 +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-vop_ref[0][1])); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3638 s->sprite_offset[0][1]= (sprite_ref[0][1]<<(alpha+rho)) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3639 + ((-r*sprite_ref[0][1] + virtual_ref[0][1])*(-vop_ref[0][0]) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3640 +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-vop_ref[0][1])); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3641 s->sprite_offset[1][0]= ((-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][0] + 1) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3642 +( r*sprite_ref[0][1] - virtual_ref[0][1])*(-2*vop_ref[0][1] + 1) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3643 +2*w2*r*sprite_ref[0][0] - 16*w2); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3644 s->sprite_offset[1][1]= ((-r*sprite_ref[0][1] + virtual_ref[0][1])*(-2*vop_ref[0][0] + 1) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3645 +(-r*sprite_ref[0][0] + virtual_ref[0][0])*(-2*vop_ref[0][1] + 1) |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3646 +2*w2*r*sprite_ref[0][1] - 16*w2); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3647 s->sprite_delta[0][0][0]= (-r*sprite_ref[0][0] + virtual_ref[0][0]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3648 s->sprite_delta[0][0][1]= ( r*sprite_ref[0][1] - virtual_ref[0][1]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3649 s->sprite_delta[0][1][0]= (-r*sprite_ref[0][1] + virtual_ref[0][1]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3650 s->sprite_delta[0][1][1]= (-r*sprite_ref[0][0] + virtual_ref[0][0]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3651 s->sprite_delta[1][0][0]= 4*(-r*sprite_ref[0][0] + virtual_ref[0][0]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3652 s->sprite_delta[1][0][1]= 4*( r*sprite_ref[0][1] - virtual_ref[0][1]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3653 s->sprite_delta[1][1][0]= 4*(-r*sprite_ref[0][1] + virtual_ref[0][1]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3654 s->sprite_delta[1][1][1]= 4*(-r*sprite_ref[0][0] + virtual_ref[0][0]); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3655 s->sprite_shift[0][0]= alpha+rho; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3656 s->sprite_shift[0][1]= alpha+rho; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3657 s->sprite_shift[1][0]= alpha+rho+2; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3658 s->sprite_shift[1][1]= alpha+rho+2; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3659 break; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3660 // case 3: |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3661 break; |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3662 } |
255 | 3663 /*printf("%d %d\n", s->sprite_delta[0][0][0], a<<s->sprite_shift[0][0]); |
3664 printf("%d %d\n", s->sprite_delta[0][0][1], 0); | |
3665 printf("%d %d\n", s->sprite_delta[0][1][0], 0); | |
3666 printf("%d %d\n", s->sprite_delta[0][1][1], a<<s->sprite_shift[0][1]); | |
3667 printf("%d %d\n", s->sprite_delta[1][0][0], a<<s->sprite_shift[1][0]); | |
3668 printf("%d %d\n", s->sprite_delta[1][0][1], 0); | |
3669 printf("%d %d\n", s->sprite_delta[1][1][0], 0); | |
3670 printf("%d %d\n", s->sprite_delta[1][1][1], a<<s->sprite_shift[1][1]);*/ | |
3671 /* try to simplify the situation */ | |
3672 if( s->sprite_delta[0][0][0] == a<<s->sprite_shift[0][0] | |
3673 && s->sprite_delta[0][0][1] == 0 | |
3674 && s->sprite_delta[0][1][0] == 0 | |
3675 && s->sprite_delta[0][1][1] == a<<s->sprite_shift[0][1] | |
3676 && s->sprite_delta[1][0][0] == a<<s->sprite_shift[1][0] | |
3677 && s->sprite_delta[1][0][1] == 0 | |
3678 && s->sprite_delta[1][1][0] == 0 | |
3679 && s->sprite_delta[1][1][1] == a<<s->sprite_shift[1][1]) | |
3680 { | |
3681 s->sprite_offset[0][0]>>=s->sprite_shift[0][0]; | |
3682 s->sprite_offset[0][1]>>=s->sprite_shift[0][1]; | |
3683 s->sprite_offset[1][0]>>=s->sprite_shift[1][0]; | |
3684 s->sprite_offset[1][1]>>=s->sprite_shift[1][1]; | |
3685 s->sprite_delta[0][0][0]= a; | |
3686 s->sprite_delta[0][0][1]= 0; | |
3687 s->sprite_delta[0][1][0]= 0; | |
3688 s->sprite_delta[0][1][1]= a; | |
3689 s->sprite_delta[1][0][0]= a; | |
3690 s->sprite_delta[1][0][1]= 0; | |
3691 s->sprite_delta[1][1][0]= 0; | |
3692 s->sprite_delta[1][1][1]= a; | |
3693 s->sprite_shift[0][0]= 0; | |
3694 s->sprite_shift[0][1]= 0; | |
3695 s->sprite_shift[1][0]= 0; | |
3696 s->sprite_shift[1][1]= 0; | |
3697 s->real_sprite_warping_points=1; | |
3698 } | |
3699 else | |
3700 s->real_sprite_warping_points= s->num_sprite_warping_points; | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3701 |
301 | 3702 //printf("%d %d %d %d\n", d[0][0], d[0][1], s->sprite_offset[0][0], s->sprite_offset[0][1]); |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3703 } |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3704 |
0 | 3705 /* decode mpeg4 VOP header */ |
3706 int mpeg4_decode_picture_header(MpegEncContext * s) | |
3707 { | |
3708 int time_incr, startcode, state, v; | |
324 | 3709 int time_increment; |
0 | 3710 |
3711 redo: | |
3712 /* search next start code */ | |
3713 align_get_bits(&s->gb); | |
3714 state = 0xff; | |
3715 for(;;) { | |
3716 v = get_bits(&s->gb, 8); | |
3717 if (state == 0x000001) { | |
3718 state = ((state << 8) | v) & 0xffffff; | |
3719 startcode = state; | |
3720 break; | |
3721 } | |
3722 state = ((state << 8) | v) & 0xffffff; | |
278 | 3723 if( get_bits_count(&s->gb) > s->gb.size*8-32){ |
333 | 3724 if(s->gb.size>50){ |
3725 printf("no VOP startcode found, frame size was=%d\n", s->gb.size); | |
3726 return -1; | |
3727 }else{ | |
3728 printf("frame skip\n"); | |
3729 return FRAME_SKIPED; | |
3730 } | |
263 | 3731 } |
0 | 3732 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3733 //printf("startcode %X %d\n", startcode, get_bits_count(&s->gb)); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3734 if (startcode == 0x120) { // Video Object Layer |
262 | 3735 int width, height, vo_ver_id; |
0 | 3736 |
3737 /* vol header */ | |
21 | 3738 skip_bits(&s->gb, 1); /* random access */ |
336 | 3739 s->vo_type= get_bits(&s->gb, 8); |
63 | 3740 if (get_bits1(&s->gb) != 0) { /* is_ol_id */ |
3741 vo_ver_id = get_bits(&s->gb, 4); /* vo_ver_id */ | |
3742 skip_bits(&s->gb, 3); /* vo_priority */ | |
3743 } else { | |
3744 vo_ver_id = 1; | |
3745 } | |
341 | 3746 //printf("vo type:%d\n",s->vo_type); |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3747 s->aspect_ratio_info= get_bits(&s->gb, 4); |
355 | 3748 if(s->aspect_ratio_info == EXTENDED_PAR){ |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3749 skip_bits(&s->gb, 8); //par_width |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3750 skip_bits(&s->gb, 8); // par_height |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3751 } |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
3752 |
365
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
364
diff
changeset
|
3753 if ((s->vol_control_parameters=get_bits1(&s->gb))) { /* vol control parameter */ |
336 | 3754 int chroma_format= get_bits(&s->gb, 2); |
3755 if(chroma_format!=1){ | |
3756 printf("illegal chroma format\n"); | |
3757 } | |
3758 s->low_delay= get_bits1(&s->gb); | |
3759 if(get_bits1(&s->gb)){ /* vbv parameters */ | |
3760 printf("vbv parameters not supported\n"); | |
3761 return -1; | |
3762 } | |
3763 }else{ | |
564 | 3764 // set low delay flag only once so the smart? low delay detection wont be overriden |
3765 if(s->picture_number==0) | |
3766 s->low_delay=0; | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3767 } |
336 | 3768 |
63 | 3769 s->shape = get_bits(&s->gb, 2); /* vol shape */ |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
3770 if(s->shape != RECT_SHAPE) printf("only rectangular vol supported\n"); |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3771 if(s->shape == GRAY_SHAPE && vo_ver_id != 1){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3772 printf("Gray shape not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3773 skip_bits(&s->gb, 4); //video_object_layer_shape_extension |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3774 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3775 |
21 | 3776 skip_bits1(&s->gb); /* marker */ |
0 | 3777 |
262 | 3778 s->time_increment_resolution = get_bits(&s->gb, 16); |
3779 s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1; | |
63 | 3780 if (s->time_increment_bits < 1) |
3781 s->time_increment_bits = 1; | |
21 | 3782 skip_bits1(&s->gb); /* marker */ |
0 | 3783 |
63 | 3784 if (get_bits1(&s->gb) != 0) { /* fixed_vop_rate */ |
3785 skip_bits(&s->gb, s->time_increment_bits); | |
3786 } | |
0 | 3787 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3788 if (s->shape != BIN_ONLY_SHAPE) { |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3789 if (s->shape == RECT_SHAPE) { |
63 | 3790 skip_bits1(&s->gb); /* marker */ |
3791 width = get_bits(&s->gb, 13); | |
3792 skip_bits1(&s->gb); /* marker */ | |
3793 height = get_bits(&s->gb, 13); | |
3794 skip_bits1(&s->gb); /* marker */ | |
274
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
3795 if(width && height){ /* they should be non zero but who knows ... */ |
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
3796 s->width = width; |
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
3797 s->height = height; |
331 | 3798 // printf("width/height: %d %d\n", width, height); |
274
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
3799 } |
63 | 3800 } |
3801 | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
3802 s->progressive_sequence= get_bits1(&s->gb)^1; |
453 | 3803 if(!get_bits1(&s->gb)) printf("OBMC not supported (very likely buggy encoder)\n"); /* OBMC Disable */ |
63 | 3804 if (vo_ver_id == 1) { |
3805 s->vol_sprite_usage = get_bits1(&s->gb); /* vol_sprite_usage */ | |
3806 } else { | |
3807 s->vol_sprite_usage = get_bits(&s->gb, 2); /* vol_sprite_usage */ | |
3808 } | |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3809 if(s->vol_sprite_usage==STATIC_SPRITE) printf("Static Sprites not supported\n"); |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3810 if(s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3811 if(s->vol_sprite_usage==STATIC_SPRITE){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3812 s->sprite_width = get_bits(&s->gb, 13); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3813 skip_bits1(&s->gb); /* marker */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3814 s->sprite_height= get_bits(&s->gb, 13); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3815 skip_bits1(&s->gb); /* marker */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3816 s->sprite_left = get_bits(&s->gb, 13); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3817 skip_bits1(&s->gb); /* marker */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3818 s->sprite_top = get_bits(&s->gb, 13); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3819 skip_bits1(&s->gb); /* marker */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3820 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
3821 s->num_sprite_warping_points= get_bits(&s->gb, 6); |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3822 s->sprite_warping_accuracy = get_bits(&s->gb, 2); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3823 s->sprite_brightness_change= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3824 if(s->vol_sprite_usage==STATIC_SPRITE) |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3825 s->low_latency_sprite= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3826 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3827 // FIXME sadct disable bit if verid!=1 && shape not rect |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3828 |
63 | 3829 if (get_bits1(&s->gb) == 1) { /* not_8_bit */ |
3830 s->quant_precision = get_bits(&s->gb, 4); /* quant_precision */ | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
3831 if(get_bits(&s->gb, 4)!=8) printf("N-bit not supported\n"); /* bits_per_pixel */ |
290 | 3832 if(s->quant_precision!=5) printf("quant precission %d\n", s->quant_precision); |
63 | 3833 } else { |
3834 s->quant_precision = 5; | |
3835 } | |
3836 | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3837 // FIXME a bunch of grayscale shape things |
312 | 3838 |
591 | 3839 if((s->mpeg_quant=get_bits1(&s->gb))){ /* vol_quant_type */ |
312 | 3840 int i, j, v; |
591 | 3841 |
312 | 3842 /* load default matrixes */ |
3843 for(i=0; i<64; i++){ | |
3844 v= ff_mpeg4_default_intra_matrix[i]; | |
3845 s->intra_matrix[i]= v; | |
3846 s->chroma_intra_matrix[i]= v; | |
3847 | |
3848 v= ff_mpeg4_default_non_intra_matrix[i]; | |
344 | 3849 s->inter_matrix[i]= v; |
3850 s->chroma_inter_matrix[i]= v; | |
312 | 3851 } |
3852 | |
3853 /* load custom intra matrix */ | |
3854 if(get_bits1(&s->gb)){ | |
3855 for(i=0; i<64; i++){ | |
3856 v= get_bits(&s->gb, 8); | |
3857 if(v==0) break; | |
3858 | |
3859 j= zigzag_direct[i]; | |
3860 s->intra_matrix[j]= v; | |
3861 s->chroma_intra_matrix[j]= v; | |
3862 } | |
3863 } | |
3864 | |
3865 /* load custom non intra matrix */ | |
3866 if(get_bits1(&s->gb)){ | |
3867 for(i=0; i<64; i++){ | |
3868 v= get_bits(&s->gb, 8); | |
3869 if(v==0) break; | |
3870 | |
3871 j= zigzag_direct[i]; | |
344 | 3872 s->inter_matrix[j]= v; |
3873 s->chroma_inter_matrix[j]= v; | |
312 | 3874 } |
3875 | |
3876 /* replicate last value */ | |
3877 for(; i<64; i++){ | |
3878 j= zigzag_direct[i]; | |
344 | 3879 s->inter_matrix[j]= v; |
3880 s->chroma_inter_matrix[j]= v; | |
312 | 3881 } |
3882 } | |
3883 | |
3884 // FIXME a bunch of grayscale shape things | |
591 | 3885 } |
312 | 3886 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3887 if(vo_ver_id != 1) |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3888 s->quarter_sample= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3889 else s->quarter_sample=0; |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
3890 |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
3891 if(!get_bits1(&s->gb)) printf("Complexity estimation not supported\n"); |
290 | 3892 |
3893 s->resync_marker= !get_bits1(&s->gb); /* resync_marker_disabled */ | |
3894 | |
453 | 3895 s->data_partitioning= get_bits1(&s->gb); |
3896 if(s->data_partitioning){ | |
3897 s->rvlc= get_bits1(&s->gb); | |
3898 if(s->rvlc){ | |
3899 printf("reversible vlc not supported\n"); | |
3900 } | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3901 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3902 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3903 if(vo_ver_id != 1) { |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3904 s->new_pred= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3905 if(s->new_pred){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3906 printf("new pred not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3907 skip_bits(&s->gb, 2); /* requested upstream message type */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3908 skip_bits1(&s->gb); /* newpred segment type */ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3909 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3910 s->reduced_res_vop= get_bits1(&s->gb); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3911 if(s->reduced_res_vop) printf("reduced resolution VOP not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3912 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3913 else{ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3914 s->new_pred=0; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3915 s->reduced_res_vop= 0; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3916 } |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3917 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3918 s->scalability= get_bits1(&s->gb); |
575 | 3919 if(s->workaround_bugs==1) s->scalability=0; |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3920 if (s->scalability) { |
575 | 3921 int dummy= s->hierachy_type= get_bits1(&s->gb); |
3922 int ref_layer_id= get_bits(&s->gb, 4); | |
3923 int ref_layer_sampling_dir= get_bits1(&s->gb); | |
3924 int h_sampling_factor_n= get_bits(&s->gb, 5); | |
3925 int h_sampling_factor_m= get_bits(&s->gb, 5); | |
3926 int v_sampling_factor_n= get_bits(&s->gb, 5); | |
3927 int v_sampling_factor_m= get_bits(&s->gb, 5); | |
3928 s->enhancement_type= get_bits1(&s->gb); | |
3929 // bin shape stuff FIXME | |
285 | 3930 printf("scalability not supported\n"); |
63 | 3931 } |
3932 } | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3933 //printf("end Data %X %d\n", show_bits(&s->gb, 32), get_bits_count(&s->gb)&0x7); |
0 | 3934 goto redo; |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3935 } else if (startcode == 0x1b2) { //userdata |
255 | 3936 char buf[256]; |
3937 int i; | |
3938 int e; | |
3939 int ver, build; | |
3940 | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3941 //printf("user Data %X\n", show_bits(&s->gb, 32)); |
255 | 3942 buf[0]= show_bits(&s->gb, 8); |
3943 for(i=1; i<256; i++){ | |
3944 buf[i]= show_bits(&s->gb, 16)&0xFF; | |
3945 if(buf[i]==0) break; | |
3946 skip_bits(&s->gb, 8); | |
3947 } | |
3948 buf[255]=0; | |
3949 e=sscanf(buf, "DivX%dBuild%d", &ver, &build); | |
333 | 3950 if(e!=2) |
3951 e=sscanf(buf, "DivX%db%d", &ver, &build); | |
255 | 3952 if(e==2){ |
3953 s->divx_version= ver; | |
3954 s->divx_build= build; | |
3955 if(s->picture_number==0){ | |
3956 printf("This file was encoded with DivX%d Build%d\n", ver, build); | |
333 | 3957 if(ver==500 && build==413){ |
255 | 3958 printf("WARNING: this version of DivX is not MPEG4 compatible, trying to workaround these bugs...\n"); |
3959 } | |
3960 } | |
3961 } | |
3962 //printf("User Data: %s\n", buf); | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3963 goto redo; |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
3964 } else if (startcode != 0x1b6) { //VOP |
0 | 3965 goto redo; |
3966 } | |
3967 | |
355 | 3968 s->pict_type = get_bits(&s->gb, 2) + I_TYPE; /* pict type: I = 0 , P = 1 */ |
453 | 3969 //if(s->pict_type!=I_TYPE) return FRAME_SKIPED; |
365
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
364
diff
changeset
|
3970 if(s->pict_type==B_TYPE && s->low_delay && s->vol_control_parameters==0){ |
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
364
diff
changeset
|
3971 printf("low_delay flag set, but shouldnt, clearing it\n"); |
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
364
diff
changeset
|
3972 s->low_delay=0; |
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
364
diff
changeset
|
3973 } |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
3974 // printf("pic: %d, qpel:%d part:%d resync:%d\n", s->pict_type, s->quarter_sample, s->data_partitioning, s->resync_marker); |
262 | 3975 time_incr=0; |
21 | 3976 while (get_bits1(&s->gb) != 0) |
0 | 3977 time_incr++; |
3978 | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
3979 check_marker(&s->gb, "before time_increment"); |
324 | 3980 time_increment= get_bits(&s->gb, s->time_increment_bits); |
3981 //printf(" type:%d incr:%d increment:%d\n", s->pict_type, time_incr, time_increment); | |
262 | 3982 if(s->pict_type!=B_TYPE){ |
324 | 3983 s->last_time_base= s->time_base; |
262 | 3984 s->time_base+= time_incr; |
324 | 3985 s->time= s->time_base*s->time_increment_resolution + time_increment; |
3986 s->pp_time= s->time - s->last_non_b_time; | |
3987 s->last_non_b_time= s->time; | |
262 | 3988 }else{ |
324 | 3989 s->time= (s->last_time_base + time_incr)*s->time_increment_resolution + time_increment; |
3990 s->bp_time= s->last_non_b_time - s->time; | |
335 | 3991 if(s->pp_time <=s->bp_time){ |
3992 // printf("messed up order, seeking?, skiping current b frame\n"); | |
3993 return FRAME_SKIPED; | |
3994 } | |
262 | 3995 } |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
3996 |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
3997 if(check_marker(&s->gb, "before vop_coded")==0 && s->picture_number==0){ |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
3998 printf("hmm, seems the headers arnt complete, trying to guess time_increment_bits\n"); |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
3999 for(s->time_increment_bits++ ;s->time_increment_bits<16; s->time_increment_bits++){ |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
4000 if(get_bits1(&s->gb)) break; |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
4001 } |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
4002 printf("my guess is %d bits ;)\n",s->time_increment_bits); |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
4003 } |
0 | 4004 /* vop coded */ |
21 | 4005 if (get_bits1(&s->gb) != 1) |
63 | 4006 goto redo; |
262 | 4007 //printf("time %d %d %d || %d %d %d\n", s->time_increment_bits, s->time_increment, s->time_base, |
4008 //s->time, s->last_non_b_time[0], s->last_non_b_time[1]); | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4009 if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == P_TYPE |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4010 || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) { |
0 | 4011 /* rounding type for motion estimation */ |
21 | 4012 s->no_rounding = get_bits1(&s->gb); |
63 | 4013 } else { |
4014 s->no_rounding = 0; | |
0 | 4015 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4016 //FIXME reduced res stuff |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4017 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4018 if (s->shape != RECT_SHAPE) { |
63 | 4019 if (s->vol_sprite_usage != 1 || s->pict_type != I_TYPE) { |
4020 int width, height, hor_spat_ref, ver_spat_ref; | |
4021 | |
4022 width = get_bits(&s->gb, 13); | |
4023 skip_bits1(&s->gb); /* marker */ | |
4024 height = get_bits(&s->gb, 13); | |
4025 skip_bits1(&s->gb); /* marker */ | |
4026 hor_spat_ref = get_bits(&s->gb, 13); /* hor_spat_ref */ | |
4027 skip_bits1(&s->gb); /* marker */ | |
4028 ver_spat_ref = get_bits(&s->gb, 13); /* ver_spat_ref */ | |
4029 } | |
4030 skip_bits1(&s->gb); /* change_CR_disable */ | |
4031 | |
4032 if (get_bits1(&s->gb) != 0) { | |
4033 skip_bits(&s->gb, 8); /* constant_alpha_value */ | |
4034 } | |
4035 } | |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4036 //FIXME complexity estimation stuff |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4037 |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4038 if (s->shape != BIN_ONLY_SHAPE) { |
290 | 4039 int t; |
4040 t=get_bits(&s->gb, 3); /* intra dc VLC threshold */ | |
4041 //printf("threshold %d\n", t); | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4042 if(!s->progressive_sequence){ |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4043 s->top_field_first= get_bits1(&s->gb); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4044 s->alternate_scan= get_bits1(&s->gb); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4045 //printf("top:%d alt:%d\n", s->top_field_first, s->alternate_scan); |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
617
diff
changeset
|
4046 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4047 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
4048 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4049 if(s->pict_type == S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){ |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
4050 if(s->num_sprite_warping_points){ |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
4051 mpeg4_decode_sprite_trajectory(s); |
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
4052 } |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4053 if(s->sprite_brightness_change) printf("sprite_brightness_change not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4054 if(s->vol_sprite_usage==STATIC_SPRITE) printf("static sprite not supported\n"); |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4055 } |
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
4056 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4057 if (s->shape != BIN_ONLY_SHAPE) { |
63 | 4058 /* note: we do not use quant_precision to avoid problem if no |
4059 MPEG4 vol header as it is found on some old opendivx | |
4060 movies */ | |
4061 s->qscale = get_bits(&s->gb, 5); | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
4062 if(s->qscale==0){ |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
4063 printf("Error, header damaged or not MPEG4 header (qscale=0)\n"); |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
4064 return -1; // makes no sense to continue, as there is nothing left from the image then |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
4065 } |
63 | 4066 |
4067 if (s->pict_type != I_TYPE) { | |
4068 s->f_code = get_bits(&s->gb, 3); /* fcode_for */ | |
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
4069 if(s->f_code==0){ |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
4070 printf("Error, header damaged or not MPEG4 header (f_code=0)\n"); |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
4071 return -1; // makes no sense to continue, as the MV decoding will break very quickly |
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
4072 } |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
4073 }else |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
4074 s->f_code=1; |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
4075 |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4076 if (s->pict_type == B_TYPE) { |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4077 s->b_code = get_bits(&s->gb, 3); |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
4078 }else |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
4079 s->b_code=1; |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
4080 |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
4081 //printf("quant:%d fcode:%d bcode:%d type:%d size:%d\n", s->qscale, s->f_code, s->b_code, s->pict_type, s->gb.size); |
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4082 if(!s->scalability){ |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4083 if (s->shape!=RECT_SHAPE && s->pict_type!=I_TYPE) { |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4084 skip_bits1(&s->gb); // vop shape coding type |
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
4085 } |
575 | 4086 }else{ |
4087 if(s->enhancement_type){ | |
4088 int load_backward_shape= get_bits1(&s->gb); | |
4089 if(load_backward_shape){ | |
4090 printf("load backward shape isnt supported\n"); | |
4091 } | |
4092 } | |
4093 skip_bits(&s->gb, 2); //ref_select_code | |
63 | 4094 } |
4095 } | |
346
c2f789fe4945
detecting xvid/divx4/opendivx and set low_delay flag
michaelni
parents:
344
diff
changeset
|
4096 /* detect buggy encoders which dont set the low_delay flag (divx4/xvid/opendivx)*/ |
c2f789fe4945
detecting xvid/divx4/opendivx and set low_delay flag
michaelni
parents:
344
diff
changeset
|
4097 // note we cannot detect divx5 without b-frames easyly (allthough its buggy too) |
365
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
364
diff
changeset
|
4098 if(s->vo_type==0 && s->vol_control_parameters==0 && s->divx_version==0 && s->picture_number==0){ |
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
364
diff
changeset
|
4099 printf("looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n"); |
346
c2f789fe4945
detecting xvid/divx4/opendivx and set low_delay flag
michaelni
parents:
344
diff
changeset
|
4100 s->low_delay=1; |
c2f789fe4945
detecting xvid/divx4/opendivx and set low_delay flag
michaelni
parents:
344
diff
changeset
|
4101 } |
c2f789fe4945
detecting xvid/divx4/opendivx and set low_delay flag
michaelni
parents:
344
diff
changeset
|
4102 |
255 | 4103 s->picture_number++; // better than pic number==0 allways ;) |
346
c2f789fe4945
detecting xvid/divx4/opendivx and set low_delay flag
michaelni
parents:
344
diff
changeset
|
4104 |
498 | 4105 s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; //FIXME add short header support |
4106 s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table; | |
4107 | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
4108 if(s->divx_version==0 || s->divx_version < 500){ |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
4109 s->h_edge_pos= s->width; |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
4110 s->v_edge_pos= s->height; |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
4111 } |
63 | 4112 return 0; |
0 | 4113 } |
4114 | |
4115 /* don't understand why they choose a different header ! */ | |
4116 int intel_h263_decode_picture_header(MpegEncContext *s) | |
4117 { | |
4118 int format; | |
4119 | |
4120 /* picture header */ | |
355 | 4121 if (get_bits(&s->gb, 22) != 0x20) { |
4122 fprintf(stderr, "Bad picture start code\n"); | |
0 | 4123 return -1; |
355 | 4124 } |
4125 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ | |
0 | 4126 |
355 | 4127 if (get_bits1(&s->gb) != 1) { |
4128 fprintf(stderr, "Bad marker\n"); | |
0 | 4129 return -1; /* marker */ |
355 | 4130 } |
4131 if (get_bits1(&s->gb) != 0) { | |
4132 fprintf(stderr, "Bad H263 id\n"); | |
0 | 4133 return -1; /* h263 id */ |
355 | 4134 } |
21 | 4135 skip_bits1(&s->gb); /* split screen off */ |
4136 skip_bits1(&s->gb); /* camera off */ | |
4137 skip_bits1(&s->gb); /* freeze picture release off */ | |
0 | 4138 |
4139 format = get_bits(&s->gb, 3); | |
355 | 4140 if (format != 7) { |
4141 fprintf(stderr, "Intel H263 free format not supported\n"); | |
0 | 4142 return -1; |
355 | 4143 } |
0 | 4144 s->h263_plus = 0; |
4145 | |
21 | 4146 s->pict_type = I_TYPE + get_bits1(&s->gb); |
0 | 4147 |
21 | 4148 s->unrestricted_mv = get_bits1(&s->gb); |
0 | 4149 s->h263_long_vectors = s->unrestricted_mv; |
4150 | |
355 | 4151 if (get_bits1(&s->gb) != 0) { |
4152 fprintf(stderr, "SAC not supported\n"); | |
0 | 4153 return -1; /* SAC: off */ |
355 | 4154 } |
4155 if (get_bits1(&s->gb) != 0) { | |
4156 fprintf(stderr, "Advanced Prediction Mode not supported\n"); | |
0 | 4157 return -1; /* advanced prediction mode: off */ |
355 | 4158 } |
4159 if (get_bits1(&s->gb) != 0) { | |
4160 fprintf(stderr, "PB frame mode no supported\n"); | |
4161 return -1; /* PB frame mode */ | |
4162 } | |
0 | 4163 |
4164 /* skip unknown header garbage */ | |
21 | 4165 skip_bits(&s->gb, 41); |
0 | 4166 |
4167 s->qscale = get_bits(&s->gb, 5); | |
21 | 4168 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
0 | 4169 |
4170 /* PEI */ | |
21 | 4171 while (get_bits1(&s->gb) != 0) { |
4172 skip_bits(&s->gb, 8); | |
0 | 4173 } |
4174 s->f_code = 1; | |
4175 return 0; | |
4176 } | |
144 | 4177 |