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