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