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