Mercurial > libavcodec.hg
annotate h263.c @ 255:db20b987c32d libavcodec
divx5-gmc support
q-pel mc support
neither is totally bugfree yet though :(
| author | michaelni |
|---|---|
| date | Sat, 09 Mar 2002 13:01:16 +0000 |
| parents | b4fed8b24e3a |
| children | 7d941b8c4e84 |
| rev | line source |
|---|---|
| 0 | 1 /* |
| 2 * H263/MPEG4 backend for ffmpeg encoder and decoder | |
| 3 * Copyright (c) 2000,2001 Gerard Lantau. | |
| 78 | 4 * H263+ support. |
| 0 | 5 * Copyright (c) 2001 Juan J. Sierralta P. |
| 6 * | |
| 7 * This program is free software; you can redistribute it and/or modify | |
| 8 * it under the terms of the GNU General Public License as published by | |
| 9 * the Free Software Foundation; either version 2 of the License, or | |
| 10 * (at your option) any later version. | |
| 11 * | |
| 12 * This program is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 * GNU General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU General Public License | |
| 18 * along with this program; if not, write to the Free Software | |
| 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 20 */ | |
| 21 #include "common.h" | |
| 22 #include "dsputil.h" | |
| 23 #include "avcodec.h" | |
| 24 #include "mpegvideo.h" | |
| 25 #include "h263data.h" | |
| 26 #include "mpeg4data.h" | |
| 27 | |
| 255 | 28 //rounded divison & shift |
| 29 #define RDIV(a,b) ((a) > 0 ? ((a)+((b)>>1))/(b) : ((a)-((b)>>1))/(b)) | |
| 30 #define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b)) | |
| 31 | |
| 0 | 32 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, |
| 33 int n); | |
| 34 static void h263_encode_motion(MpegEncContext * s, int val); | |
| 78 | 35 static void h263p_encode_umotion(MpegEncContext * s, int val); |
| 0 | 36 static void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, |
| 37 int n); | |
| 38 static int h263_decode_motion(MpegEncContext * s, int pred); | |
| 78 | 39 static int h263p_decode_umotion(MpegEncContext * s, int pred); |
| 0 | 40 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
| 41 int n, int coded); | |
| 42 static int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | |
| 43 int n, int coded); | |
| 44 | |
| 45 int h263_get_picture_format(int width, int height) | |
| 46 { | |
| 47 int format; | |
| 48 | |
| 49 if (width == 128 && height == 96) | |
| 50 format = 1; | |
| 51 else if (width == 176 && height == 144) | |
| 52 format = 2; | |
| 53 else if (width == 352 && height == 288) | |
| 54 format = 3; | |
| 55 else if (width == 704 && height == 576) | |
| 56 format = 4; | |
| 57 else if (width == 1408 && height == 1152) | |
| 58 format = 5; | |
| 59 else | |
| 60 format = 7; | |
| 61 return format; | |
| 62 } | |
| 63 | |
| 64 void h263_encode_picture_header(MpegEncContext * s, int picture_number) | |
| 65 { | |
| 78 | 66 int format; |
| 0 | 67 |
| 68 align_put_bits(&s->pb); | |
| 231 | 69 |
| 70 /* 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
|
71 s->ptr_lastgob = pbBufPtr(&s->pb); |
| 231 | 72 s->gob_number = 0; |
| 73 | |
| 74 put_bits(&s->pb, 22, 0x20); /* PSC */ | |
| 241 | 75 put_bits(&s->pb, 8, (((INT64)s->picture_number * 30 * FRAME_RATE_BASE) / |
| 0 | 76 s->frame_rate) & 0xff); |
| 77 | |
| 78 put_bits(&s->pb, 1, 1); /* marker */ | |
| 79 put_bits(&s->pb, 1, 0); /* h263 id */ | |
| 80 put_bits(&s->pb, 1, 0); /* split screen off */ | |
| 81 put_bits(&s->pb, 1, 0); /* camera off */ | |
| 82 put_bits(&s->pb, 1, 0); /* freeze picture release off */ | |
| 78 | 83 |
| 84 format = h263_get_picture_format(s->width, s->height); | |
| 0 | 85 if (!s->h263_plus) { |
| 86 /* H.263v1 */ | |
| 87 put_bits(&s->pb, 3, format); | |
| 88 put_bits(&s->pb, 1, (s->pict_type == P_TYPE)); | |
| 89 /* By now UMV IS DISABLED ON H.263v1, since the restrictions | |
| 90 of H.263v1 UMV implies to check the predicted MV after | |
| 91 calculation of the current MB to see if we're on the limits */ | |
| 92 put_bits(&s->pb, 1, 0); /* unrestricted motion vector: off */ | |
| 93 put_bits(&s->pb, 1, 0); /* SAC: off */ | |
| 94 put_bits(&s->pb, 1, 0); /* advanced prediction mode: off */ | |
| 95 put_bits(&s->pb, 1, 0); /* not PB frame */ | |
| 96 put_bits(&s->pb, 5, s->qscale); | |
| 97 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ | |
| 98 } else { | |
| 99 /* H.263v2 */ | |
| 100 /* H.263 Plus PTYPE */ | |
| 101 put_bits(&s->pb, 3, 7); | |
| 102 put_bits(&s->pb,3,1); /* Update Full Extended PTYPE */ | |
| 78 | 103 if (format == 7) |
| 104 put_bits(&s->pb,3,6); /* Custom Source Format */ | |
| 105 else | |
| 106 put_bits(&s->pb, 3, format); | |
| 107 | |
| 0 | 108 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
|
109 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
|
110 put_bits(&s->pb, 1, s->umvplus); /* Unrestricted Motion Vector */ |
| 0 | 111 put_bits(&s->pb,1,0); /* SAC: off */ |
| 112 put_bits(&s->pb,1,0); /* Advanced Prediction Mode: off */ | |
| 113 put_bits(&s->pb,1,0); /* Advanced Intra Coding: off */ | |
| 114 put_bits(&s->pb,1,0); /* Deblocking Filter: off */ | |
| 115 put_bits(&s->pb,1,0); /* Slice Structured: off */ | |
| 116 put_bits(&s->pb,1,0); /* Reference Picture Selection: off */ | |
| 117 put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */ | |
| 118 put_bits(&s->pb,1,0); /* Alternative Inter VLC: off */ | |
| 119 put_bits(&s->pb,1,0); /* Modified Quantization: off */ | |
| 120 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
| 121 put_bits(&s->pb,3,0); /* Reserved */ | |
| 122 | |
| 123 put_bits(&s->pb, 3, s->pict_type == P_TYPE); | |
| 124 | |
| 125 put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */ | |
| 126 put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */ | |
| 127 put_bits(&s->pb,1,0); /* Rounding Type */ | |
| 128 put_bits(&s->pb,2,0); /* Reserved */ | |
| 129 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
| 130 | |
| 131 /* This should be here if PLUSPTYPE */ | |
| 132 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ | |
| 133 | |
| 78 | 134 if (format == 7) { |
| 135 /* Custom Picture Format (CPFMT) */ | |
| 0 | 136 |
| 78 | 137 put_bits(&s->pb,4,2); /* Aspect ratio: CIF 12:11 (4:3) picture */ |
| 138 put_bits(&s->pb,9,(s->width >> 2) - 1); | |
| 139 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
| 140 put_bits(&s->pb,9,(s->height >> 2)); | |
| 141 } | |
| 142 | |
| 0 | 143 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
144 if (s->umvplus) |
| 0 | 145 put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ |
| 146 put_bits(&s->pb, 5, s->qscale); | |
| 147 } | |
| 148 | |
| 149 put_bits(&s->pb, 1, 0); /* no PEI */ | |
| 150 } | |
| 151 | |
| 162 | 152 int h263_encode_gob_header(MpegEncContext * s, int mb_line) |
| 153 { | |
| 154 int pdif=0; | |
| 155 | |
| 156 /* Check to see if we need to put a new GBSC */ | |
| 157 /* for RTP packetization */ | |
| 158 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
|
159 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
| 162 | 160 if (pdif >= s->rtp_payload_size) { |
| 161 /* Bad luck, packet must be cut before */ | |
| 162 align_put_bits(&s->pb); | |
| 231 | 163 flush_put_bits(&s->pb); |
| 164 /* Call the RTP callback to send the last GOB */ | |
| 165 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
|
166 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
| 231 | 167 s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); |
| 168 } | |
|
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
|
169 s->ptr_lastgob = pbBufPtr(&s->pb); |
| 162 | 170 put_bits(&s->pb, 17, 1); /* GBSC */ |
| 231 | 171 s->gob_number = mb_line / s->gob_index; |
| 162 | 172 put_bits(&s->pb, 5, s->gob_number); /* GN */ |
| 231 | 173 put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */ |
| 162 | 174 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ |
| 231 | 175 //fprintf(stderr,"\nGOB: %2d size: %d", s->gob_number - 1, pdif); |
| 162 | 176 return pdif; |
| 177 } else if (pdif + s->mb_line_avgsize >= s->rtp_payload_size) { | |
| 178 /* Cut the packet before we can't */ | |
| 179 align_put_bits(&s->pb); | |
| 231 | 180 flush_put_bits(&s->pb); |
| 181 /* Call the RTP callback to send the last GOB */ | |
| 182 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
|
183 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
| 231 | 184 s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); |
| 185 } | |
|
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
|
186 s->ptr_lastgob = pbBufPtr(&s->pb); |
| 162 | 187 put_bits(&s->pb, 17, 1); /* GBSC */ |
| 231 | 188 s->gob_number = mb_line / s->gob_index; |
| 162 | 189 put_bits(&s->pb, 5, s->gob_number); /* GN */ |
| 231 | 190 put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */ |
| 162 | 191 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ |
| 231 | 192 //fprintf(stderr,"\nGOB: %2d size: %d", s->gob_number - 1, pdif); |
| 162 | 193 return pdif; |
| 194 } | |
| 195 } | |
| 196 return 0; | |
| 197 } | |
| 198 | |
| 0 | 199 void h263_encode_mb(MpegEncContext * s, |
| 200 DCTELEM block[6][64], | |
| 201 int motion_x, int motion_y) | |
| 202 { | |
| 203 int cbpc, cbpy, i, cbp, pred_x, pred_y; | |
| 162 | 204 |
| 0 | 205 // printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); |
| 78 | 206 if (!s->mb_intra) { |
| 207 /* compute cbp */ | |
| 208 cbp = 0; | |
| 209 for (i = 0; i < 6; i++) { | |
| 210 if (s->block_last_index[i] >= 0) | |
| 211 cbp |= 1 << (5 - i); | |
| 212 } | |
| 213 if ((cbp | motion_x | motion_y) == 0) { | |
| 214 /* skip macroblock */ | |
| 215 put_bits(&s->pb, 1, 1); | |
| 216 return; | |
| 217 } | |
| 218 put_bits(&s->pb, 1, 0); /* mb coded */ | |
| 219 cbpc = cbp & 3; | |
| 220 put_bits(&s->pb, | |
| 221 inter_MCBPC_bits[cbpc], | |
| 222 inter_MCBPC_code[cbpc]); | |
| 223 cbpy = cbp >> 2; | |
| 224 cbpy ^= 0xf; | |
| 225 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | |
| 0 | 226 |
| 78 | 227 /* motion vectors: 16x16 mode only now */ |
| 228 h263_pred_motion(s, 0, &pred_x, &pred_y); | |
| 229 | |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
230 if (!s->umvplus) { |
| 78 | 231 h263_encode_motion(s, motion_x - pred_x); |
| 232 h263_encode_motion(s, motion_y - pred_y); | |
| 233 } | |
| 234 else { | |
| 235 h263p_encode_umotion(s, motion_x - pred_x); | |
| 236 h263p_encode_umotion(s, motion_y - pred_y); | |
| 237 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) | |
| 238 /* To prevent Start Code emulation */ | |
| 239 put_bits(&s->pb,1,1); | |
| 240 } | |
| 241 } else { | |
| 0 | 242 /* compute cbp */ |
| 243 cbp = 0; | |
| 244 for (i = 0; i < 6; i++) { | |
| 245 if (s->block_last_index[i] >= 1) | |
| 246 cbp |= 1 << (5 - i); | |
| 247 } | |
| 248 | |
| 249 cbpc = cbp & 3; | |
| 250 if (s->pict_type == I_TYPE) { | |
| 251 put_bits(&s->pb, | |
| 252 intra_MCBPC_bits[cbpc], | |
| 253 intra_MCBPC_code[cbpc]); | |
| 254 } else { | |
| 255 put_bits(&s->pb, 1, 0); /* mb coded */ | |
| 256 put_bits(&s->pb, | |
| 257 inter_MCBPC_bits[cbpc + 4], | |
| 258 inter_MCBPC_code[cbpc + 4]); | |
| 259 } | |
| 260 if (s->h263_pred) { | |
| 261 /* XXX: currently, we do not try to use ac prediction */ | |
| 262 put_bits(&s->pb, 1, 0); /* no ac prediction */ | |
| 263 } | |
| 264 cbpy = cbp >> 2; | |
| 265 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | |
| 266 } | |
| 267 | |
| 268 /* encode each block */ | |
| 269 if (s->h263_pred) { | |
| 270 for (i = 0; i < 6; i++) { | |
| 271 mpeg4_encode_block(s, block[i], i); | |
| 272 } | |
| 273 } else { | |
| 274 for (i = 0; i < 6; i++) { | |
| 275 h263_encode_block(s, block[i], i); | |
| 276 } | |
| 277 } | |
| 278 } | |
| 279 | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
280 |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
281 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
|
282 { |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
283 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
|
284 INT16 *dc_val, *ac_val, *ac_val1; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
285 |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
286 /* find prediction */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
287 if (n < 4) { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
288 x = 2 * s->mb_x + 1 + (n & 1); |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
289 y = 2 * s->mb_y + 1 + ((n & 2) >> 1); |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
290 wrap = s->mb_width * 2 + 2; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
291 dc_val = s->dc_val[0]; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
292 ac_val = s->ac_val[0][0]; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
293 scale = s->y_dc_scale; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
294 } else { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
295 x = s->mb_x + 1; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
296 y = s->mb_y + 1; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
297 wrap = s->mb_width + 2; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
298 dc_val = s->dc_val[n - 4 + 1]; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
299 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
|
300 scale = s->c_dc_scale; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
301 } |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
302 |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
303 ac_val += ((y) * wrap + (x)) * 16; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
304 ac_val1 = ac_val; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
305 |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
306 /* B C |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
307 * A X |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
308 */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
309 a = dc_val[(x - 1) + (y) * wrap]; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
310 c = dc_val[(x) + (y - 1) * wrap]; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
311 |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
312 pred_dc = 1024; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
313 if (s->ac_pred) { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
314 if (s->h263_aic_dir) { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
315 /* left prediction */ |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
316 if (a != 1024) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
317 ac_val -= 16; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
318 for(i=1;i<8;i++) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
319 block[block_permute_op(i*8)] += ac_val[i]; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
320 } |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
321 pred_dc = a; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
322 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
323 } else { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
324 /* top prediction */ |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
325 if (c != 1024) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
326 ac_val -= 16 * wrap; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
327 for(i=1;i<8;i++) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
328 block[block_permute_op(i)] += ac_val[i + 8]; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
329 } |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
330 pred_dc = c; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
331 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
332 } |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
333 } else { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
334 /* just DC prediction */ |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
335 if (a != 1024 && c != 1024) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
336 pred_dc = (a + c) >> 1; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
337 else if (a != 1024) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
338 pred_dc = a; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
339 else |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
340 pred_dc = c; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
341 } |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
342 |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
343 /* we assume pred is positive */ |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
344 block[0]=block[0]*scale + pred_dc; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
345 |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
346 if (block[0] < 0) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
347 block[0] = 0; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
348 else if (!(block[0] & 1)) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
349 block[0]++; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
350 |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
351 /* Update AC/DC tables */ |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
352 dc_val[(x) + (y) * wrap] = block[0]; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
353 |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
354 /* left copy */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
355 for(i=1;i<8;i++) |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
356 ac_val1[i] = block[block_permute_op(i * 8)]; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
357 /* top copy */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
358 for(i=1;i<8;i++) |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
359 ac_val1[8 + i] = block[block_permute_op(i)]; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
360 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
361 |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
362 |
| 0 | 363 static inline int mid_pred(int a, int b, int c) |
| 364 { | |
| 365 int vmin, vmax; | |
| 245 | 366 vmax = vmin = a; |
| 0 | 367 if (b < vmin) |
| 368 vmin = b; | |
| 245 | 369 else |
| 370 vmax = b; | |
| 371 | |
| 0 | 372 if (c < vmin) |
| 373 vmin = c; | |
| 245 | 374 else if (c > vmax) |
| 0 | 375 vmax = c; |
| 376 | |
| 377 return a + b + c - vmin - vmax; | |
| 378 } | |
| 379 | |
| 380 INT16 *h263_pred_motion(MpegEncContext * s, int block, | |
| 381 int *px, int *py) | |
| 382 { | |
| 245 | 383 int xy, y, wrap; |
| 0 | 384 INT16 *A, *B, *C, *mot_val; |
| 385 | |
| 386 wrap = 2 * s->mb_width + 2; | |
| 245 | 387 y = xy = 2 * s->mb_y + 1 + ((block >> 1) & 1); // y |
| 388 xy *= wrap; // y * wrap | |
| 389 xy += 2 * s->mb_x + 1 + (block & 1); // x + y * wrap | |
| 0 | 390 |
| 245 | 391 mot_val = s->motion_val[xy]; |
| 0 | 392 |
| 393 /* special case for first line */ | |
|
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
394 if (y == 1 || s->first_slice_line || s->first_gob_line) { |
| 245 | 395 A = s->motion_val[xy - 1]; |
| 0 | 396 *px = A[0]; |
| 397 *py = A[1]; | |
| 398 } else { | |
| 399 switch(block) { | |
| 400 default: | |
| 401 case 0: | |
| 245 | 402 A = s->motion_val[xy - 1]; |
| 403 B = s->motion_val[xy - wrap]; | |
| 404 C = s->motion_val[xy + 2 - wrap]; | |
| 0 | 405 break; |
| 406 case 1: | |
| 407 case 2: | |
| 245 | 408 A = s->motion_val[xy - 1]; |
| 409 B = s->motion_val[xy - wrap]; | |
| 410 C = s->motion_val[xy + 1 - wrap]; | |
| 0 | 411 break; |
| 412 case 3: | |
| 245 | 413 A = s->motion_val[xy - 1]; |
| 414 B = s->motion_val[xy - 1 - wrap]; | |
| 415 C = s->motion_val[xy - wrap]; | |
| 0 | 416 break; |
| 417 } | |
| 418 *px = mid_pred(A[0], B[0], C[0]); | |
| 419 *py = mid_pred(A[1], B[1], C[1]); | |
| 420 } | |
| 421 return mot_val; | |
| 422 } | |
| 423 | |
| 424 | |
| 425 static void h263_encode_motion(MpegEncContext * s, int val) | |
| 426 { | |
| 427 int range, l, m, bit_size, sign, code, bits; | |
| 428 | |
| 429 if (val == 0) { | |
| 430 /* zero vector */ | |
| 431 code = 0; | |
| 432 put_bits(&s->pb, mvtab[code][1], mvtab[code][0]); | |
| 433 } else { | |
| 434 bit_size = s->f_code - 1; | |
| 435 range = 1 << bit_size; | |
| 436 /* modulo encoding */ | |
| 437 l = range * 32; | |
| 438 m = 2 * l; | |
| 439 if (val < -l) { | |
| 440 val += m; | |
| 441 } else if (val >= l) { | |
| 442 val -= m; | |
| 443 } | |
| 444 | |
| 445 if (val >= 0) { | |
| 446 val--; | |
| 447 code = (val >> bit_size) + 1; | |
| 448 bits = val & (range - 1); | |
| 449 sign = 0; | |
| 450 } else { | |
| 451 val = -val; | |
| 452 val--; | |
| 453 code = (val >> bit_size) + 1; | |
| 454 bits = val & (range - 1); | |
| 455 sign = 1; | |
| 456 } | |
| 457 | |
| 458 put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); | |
| 459 if (bit_size > 0) { | |
| 460 put_bits(&s->pb, bit_size, bits); | |
| 461 } | |
| 462 } | |
| 463 } | |
| 464 | |
| 78 | 465 /* Encode MV differences on H.263+ with Unrestricted MV mode */ |
| 466 static void h263p_encode_umotion(MpegEncContext * s, int val) | |
| 467 { | |
| 468 short sval = 0; | |
| 469 short i = 0; | |
| 470 short n_bits = 0; | |
| 471 short temp_val; | |
| 472 int code = 0; | |
| 473 int tcode; | |
| 474 | |
| 475 if ( val == 0) | |
| 476 put_bits(&s->pb, 1, 1); | |
| 477 else if (val == 1) | |
| 478 put_bits(&s->pb, 3, 0); | |
| 479 else if (val == -1) | |
| 480 put_bits(&s->pb, 3, 2); | |
| 481 else { | |
| 482 | |
| 483 sval = ((val < 0) ? (short)(-val):(short)val); | |
| 484 temp_val = sval; | |
| 485 | |
| 486 while (temp_val != 0) { | |
| 487 temp_val = temp_val >> 1; | |
| 488 n_bits++; | |
| 489 } | |
| 490 | |
| 491 i = n_bits - 1; | |
| 492 while (i > 0) { | |
| 493 tcode = (sval & (1 << (i-1))) >> (i-1); | |
| 494 tcode = (tcode << 1) | 1; | |
| 495 code = (code << 2) | tcode; | |
| 496 i--; | |
| 497 } | |
| 498 code = ((code << 1) | (val < 0)) << 1; | |
| 499 put_bits(&s->pb, (2*n_bits)+1, code); | |
| 500 //printf("\nVal = %d\tCode = %d", sval, code); | |
| 501 } | |
| 502 } | |
| 503 | |
| 0 | 504 void h263_encode_init_vlc(MpegEncContext *s) |
| 505 { | |
| 506 static int done = 0; | |
| 507 | |
| 508 if (!done) { | |
| 509 done = 1; | |
| 510 init_rl(&rl_inter); | |
| 511 init_rl(&rl_intra); | |
| 512 } | |
| 513 } | |
| 514 | |
| 515 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n) | |
| 516 { | |
| 517 int level, run, last, i, j, last_index, last_non_zero, sign, slevel; | |
| 518 int code; | |
| 519 RLTable *rl = &rl_inter; | |
| 520 | |
| 521 if (s->mb_intra) { | |
| 231 | 522 /* DC coef */ |
| 523 level = block[0]; | |
| 0 | 524 /* 255 cannot be represented, so we clamp */ |
| 525 if (level > 254) { | |
| 526 level = 254; | |
| 527 block[0] = 254; | |
| 528 } | |
| 231 | 529 /* 0 cannot be represented also */ |
| 530 else if (!level) { | |
| 531 level = 1; | |
| 532 block[0] = 1; | |
| 533 } | |
| 534 if (level == 128) | |
| 535 put_bits(&s->pb, 8, 0xff); | |
| 536 else | |
| 537 put_bits(&s->pb, 8, level & 0xff); | |
| 538 i = 1; | |
| 0 | 539 } else { |
| 231 | 540 i = 0; |
| 0 | 541 } |
| 542 | |
| 543 /* AC coefs */ | |
| 544 last_index = s->block_last_index[n]; | |
| 545 last_non_zero = i - 1; | |
| 546 for (; i <= last_index; i++) { | |
| 547 j = zigzag_direct[i]; | |
| 548 level = block[j]; | |
| 549 if (level) { | |
| 550 run = i - last_non_zero - 1; | |
| 551 last = (i == last_index); | |
| 552 sign = 0; | |
| 553 slevel = level; | |
| 554 if (level < 0) { | |
| 555 sign = 1; | |
| 556 level = -level; | |
| 557 } | |
| 558 code = get_rl_index(rl, last, run, level); | |
| 559 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
| 560 if (code == rl->n) { | |
| 561 put_bits(&s->pb, 1, last); | |
| 562 put_bits(&s->pb, 6, run); | |
| 563 put_bits(&s->pb, 8, slevel & 0xff); | |
| 564 } else { | |
| 565 put_bits(&s->pb, 1, sign); | |
| 566 } | |
| 567 last_non_zero = i; | |
| 568 } | |
| 569 } | |
| 570 } | |
| 571 | |
| 572 /***************************************************/ | |
| 573 | |
| 574 /* write mpeg4 VOP header */ | |
| 575 void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) | |
| 576 { | |
| 577 align_put_bits(&s->pb); | |
| 578 | |
|
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
|
579 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
|
580 put_bits(&s->pb, 16, 0x1B6); /* vop header */ |
| 0 | 581 put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */ |
| 582 /* XXX: time base + 1 not always correct */ | |
| 583 put_bits(&s->pb, 1, 1); | |
| 584 put_bits(&s->pb, 1, 0); | |
| 585 | |
| 586 put_bits(&s->pb, 1, 1); /* marker */ | |
| 587 put_bits(&s->pb, 4, 1); /* XXX: correct time increment */ | |
| 588 put_bits(&s->pb, 1, 1); /* marker */ | |
| 589 put_bits(&s->pb, 1, 1); /* vop coded */ | |
| 590 if (s->pict_type == P_TYPE) { | |
| 591 s->no_rounding = 0; | |
| 592 put_bits(&s->pb, 1, s->no_rounding); /* rounding type */ | |
| 593 } | |
| 594 put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */ | |
| 595 | |
| 596 put_bits(&s->pb, 5, s->qscale); | |
| 597 | |
| 598 if (s->pict_type != I_TYPE) | |
| 599 put_bits(&s->pb, 3, s->f_code); /* fcode_for */ | |
| 600 // printf("****frame %d\n", picture_number); | |
| 601 } | |
| 602 | |
| 603 void h263_dc_scale(MpegEncContext * s) | |
| 604 { | |
| 605 int quant; | |
| 606 | |
| 607 quant = s->qscale; | |
| 608 /* luminance */ | |
| 609 if (quant < 5) | |
| 610 s->y_dc_scale = 8; | |
| 611 else if (quant > 4 && quant < 9) | |
| 612 s->y_dc_scale = (2 * quant); | |
| 613 else if (quant > 8 && quant < 25) | |
| 614 s->y_dc_scale = (quant + 8); | |
| 615 else | |
| 616 s->y_dc_scale = (2 * quant - 16); | |
| 617 /* chrominance */ | |
| 618 if (quant < 5) | |
| 619 s->c_dc_scale = 8; | |
| 620 else if (quant > 4 && quant < 25) | |
| 621 s->c_dc_scale = ((quant + 13) / 2); | |
| 622 else | |
| 623 s->c_dc_scale = (quant - 6); | |
| 624 } | |
| 625 | |
| 626 static int mpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr) | |
| 627 { | |
| 245 | 628 int a, b, c, xy, wrap, pred, scale; |
| 0 | 629 UINT16 *dc_val; |
| 630 | |
| 631 /* find prediction */ | |
| 632 if (n < 4) { | |
| 633 wrap = s->mb_width * 2 + 2; | |
| 245 | 634 xy = 2 * s->mb_y + 1 + ((n & 2) >> 1); |
| 635 xy *= wrap; | |
| 636 xy += 2 * s->mb_x + 1 + (n & 1); | |
| 0 | 637 dc_val = s->dc_val[0]; |
| 638 scale = s->y_dc_scale; | |
| 639 } else { | |
| 640 wrap = s->mb_width + 2; | |
| 245 | 641 xy = s->mb_y + 1; |
| 642 xy *= wrap; | |
| 643 xy += s->mb_x + 1; | |
| 0 | 644 dc_val = s->dc_val[n - 4 + 1]; |
| 645 scale = s->c_dc_scale; | |
| 646 } | |
| 647 | |
| 648 /* B C | |
| 649 * A X | |
| 650 */ | |
| 245 | 651 a = dc_val[xy - 1]; |
| 652 b = dc_val[xy - 1 - wrap]; | |
| 653 c = dc_val[xy - wrap]; | |
| 0 | 654 |
| 655 if (abs(a - b) < abs(b - c)) { | |
| 656 pred = c; | |
| 657 *dir_ptr = 1; /* top */ | |
| 658 } else { | |
| 659 pred = a; | |
| 660 *dir_ptr = 0; /* left */ | |
| 661 } | |
| 662 /* we assume pred is positive */ | |
| 663 pred = (pred + (scale >> 1)) / scale; | |
| 664 | |
| 665 /* prepare address for prediction update */ | |
| 245 | 666 *dc_val_ptr = &dc_val[xy]; |
| 0 | 667 |
| 668 return pred; | |
| 669 } | |
| 670 | |
|
174
ac5075a55488
new IDCT code by Michael Niedermayer (michaelni@gmx.at) - #define SIMPLE_IDCT to enable
arpi_esp
parents:
162
diff
changeset
|
671 void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n, |
| 0 | 672 int dir) |
| 673 { | |
| 674 int x, y, wrap, i; | |
| 675 INT16 *ac_val, *ac_val1; | |
| 676 | |
| 677 /* find prediction */ | |
| 678 if (n < 4) { | |
| 679 x = 2 * s->mb_x + 1 + (n & 1); | |
| 680 y = 2 * s->mb_y + 1 + ((n & 2) >> 1); | |
| 681 wrap = s->mb_width * 2 + 2; | |
| 682 ac_val = s->ac_val[0][0]; | |
| 683 } else { | |
| 684 x = s->mb_x + 1; | |
| 685 y = s->mb_y + 1; | |
| 686 wrap = s->mb_width + 2; | |
| 687 ac_val = s->ac_val[n - 4 + 1][0]; | |
| 688 } | |
| 689 ac_val += ((y) * wrap + (x)) * 16; | |
| 690 ac_val1 = ac_val; | |
| 691 if (s->ac_pred) { | |
| 692 if (dir == 0) { | |
| 693 /* left prediction */ | |
| 694 ac_val -= 16; | |
| 695 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
|
696 block[block_permute_op(i*8)] += ac_val[i]; |
| 0 | 697 } |
| 698 } else { | |
| 699 /* top prediction */ | |
| 700 ac_val -= 16 * wrap; | |
| 701 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
|
702 block[block_permute_op(i)] += ac_val[i + 8]; |
| 0 | 703 } |
| 704 } | |
| 705 } | |
| 706 /* left copy */ | |
| 707 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
|
708 ac_val1[i] = block[block_permute_op(i * 8)]; |
| 0 | 709 /* top copy */ |
| 710 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
|
711 ac_val1[8 + i] = block[block_permute_op(i)]; |
| 0 | 712 } |
| 713 | |
| 714 static inline void mpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr) | |
| 715 { | |
| 716 int size, v, pred; | |
| 717 UINT16 *dc_val; | |
| 718 | |
| 719 pred = mpeg4_pred_dc(s, n, &dc_val, dir_ptr); | |
| 720 if (n < 4) { | |
| 721 *dc_val = level * s->y_dc_scale; | |
| 722 } else { | |
| 723 *dc_val = level * s->c_dc_scale; | |
| 724 } | |
| 725 | |
| 726 /* do the prediction */ | |
| 727 level -= pred; | |
| 728 /* find number of bits */ | |
| 729 size = 0; | |
| 730 v = abs(level); | |
| 731 while (v) { | |
| 732 v >>= 1; | |
| 733 size++; | |
| 734 } | |
| 735 | |
| 736 if (n < 4) { | |
| 737 /* luminance */ | |
| 738 put_bits(&s->pb, DCtab_lum[size][1], DCtab_lum[size][0]); | |
| 739 } else { | |
| 740 /* chrominance */ | |
| 741 put_bits(&s->pb, DCtab_chrom[size][1], DCtab_chrom[size][0]); | |
| 742 } | |
| 743 | |
| 744 /* encode remaining bits */ | |
| 745 if (size > 0) { | |
| 746 if (level < 0) | |
| 747 level = (-level) ^ ((1 << size) - 1); | |
| 748 put_bits(&s->pb, size, level); | |
| 749 if (size > 8) | |
| 750 put_bits(&s->pb, 1, 1); | |
| 751 } | |
| 752 } | |
| 753 | |
| 754 static void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n) | |
| 755 { | |
| 756 int level, run, last, i, j, last_index, last_non_zero, sign, slevel; | |
| 757 int code, dc_pred_dir; | |
| 758 const RLTable *rl; | |
| 759 | |
| 760 if (s->mb_intra) { | |
| 761 /* mpeg4 based DC predictor */ | |
| 762 mpeg4_encode_dc(s, block[0], n, &dc_pred_dir); | |
| 763 i = 1; | |
| 764 rl = &rl_intra; | |
| 765 } else { | |
| 766 i = 0; | |
| 767 rl = &rl_inter; | |
| 768 } | |
| 769 | |
| 770 /* AC coefs */ | |
| 771 last_index = s->block_last_index[n]; | |
| 772 last_non_zero = i - 1; | |
| 773 for (; i <= last_index; i++) { | |
| 774 j = zigzag_direct[i]; | |
| 775 level = block[j]; | |
| 776 if (level) { | |
| 777 run = i - last_non_zero - 1; | |
| 778 last = (i == last_index); | |
| 779 sign = 0; | |
| 780 slevel = level; | |
| 781 if (level < 0) { | |
| 782 sign = 1; | |
| 783 level = -level; | |
| 784 } | |
| 785 code = get_rl_index(rl, last, run, level); | |
| 786 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
| 787 if (code == rl->n) { | |
| 788 int level1, run1; | |
| 789 level1 = level - rl->max_level[last][run]; | |
| 790 if (level1 < 1) | |
| 791 goto esc2; | |
| 792 code = get_rl_index(rl, last, run, level1); | |
| 793 if (code == rl->n) { | |
| 794 esc2: | |
| 795 put_bits(&s->pb, 1, 1); | |
| 796 if (level > MAX_LEVEL) | |
| 797 goto esc3; | |
| 798 run1 = run - rl->max_run[last][level] - 1; | |
| 799 if (run1 < 0) | |
| 800 goto esc3; | |
| 801 code = get_rl_index(rl, last, run1, level); | |
| 802 if (code == rl->n) { | |
| 803 esc3: | |
| 804 /* third escape */ | |
| 805 put_bits(&s->pb, 1, 1); | |
| 806 put_bits(&s->pb, 1, last); | |
| 807 put_bits(&s->pb, 6, run); | |
| 808 put_bits(&s->pb, 1, 1); | |
| 809 put_bits(&s->pb, 12, slevel & 0xfff); | |
| 810 put_bits(&s->pb, 1, 1); | |
| 811 } else { | |
| 812 /* second escape */ | |
| 813 put_bits(&s->pb, 1, 0); | |
| 814 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
| 815 put_bits(&s->pb, 1, sign); | |
| 816 } | |
| 817 } else { | |
| 818 /* first escape */ | |
| 819 put_bits(&s->pb, 1, 0); | |
| 820 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
| 821 put_bits(&s->pb, 1, sign); | |
| 822 } | |
| 823 } else { | |
| 824 put_bits(&s->pb, 1, sign); | |
| 825 } | |
| 826 last_non_zero = i; | |
| 827 } | |
| 828 } | |
| 829 } | |
| 830 | |
| 831 | |
| 832 | |
| 833 /***********************************************/ | |
| 834 /* decoding */ | |
| 835 | |
| 836 static VLC intra_MCBPC_vlc; | |
| 837 static VLC inter_MCBPC_vlc; | |
| 838 static VLC cbpy_vlc; | |
| 839 static VLC mv_vlc; | |
| 840 static VLC dc_lum, dc_chrom; | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
841 static VLC sprite_trajectory; |
| 0 | 842 |
| 843 void init_rl(RLTable *rl) | |
| 844 { | |
| 845 INT8 max_level[MAX_RUN+1], max_run[MAX_LEVEL+1]; | |
| 846 UINT8 index_run[MAX_RUN+1]; | |
| 847 int last, run, level, start, end, i; | |
| 848 | |
| 849 /* compute max_level[], max_run[] and index_run[] */ | |
| 850 for(last=0;last<2;last++) { | |
| 851 if (last == 0) { | |
| 852 start = 0; | |
| 853 end = rl->last; | |
| 854 } else { | |
| 855 start = rl->last; | |
| 856 end = rl->n; | |
| 857 } | |
| 858 | |
| 859 memset(max_level, 0, MAX_RUN + 1); | |
| 860 memset(max_run, 0, MAX_LEVEL + 1); | |
| 861 memset(index_run, rl->n, MAX_RUN + 1); | |
| 862 for(i=start;i<end;i++) { | |
| 863 run = rl->table_run[i]; | |
| 864 level = rl->table_level[i]; | |
| 865 if (index_run[run] == rl->n) | |
| 866 index_run[run] = i; | |
| 867 if (level > max_level[run]) | |
| 868 max_level[run] = level; | |
| 869 if (run > max_run[level]) | |
| 870 max_run[level] = run; | |
| 871 } | |
| 872 rl->max_level[last] = malloc(MAX_RUN + 1); | |
| 873 memcpy(rl->max_level[last], max_level, MAX_RUN + 1); | |
| 874 rl->max_run[last] = malloc(MAX_LEVEL + 1); | |
| 875 memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1); | |
| 876 rl->index_run[last] = malloc(MAX_RUN + 1); | |
| 877 memcpy(rl->index_run[last], index_run, MAX_RUN + 1); | |
| 878 } | |
| 879 } | |
| 880 | |
| 881 void init_vlc_rl(RLTable *rl) | |
| 882 { | |
| 883 init_vlc(&rl->vlc, 9, rl->n + 1, | |
| 884 &rl->table_vlc[0][1], 4, 2, | |
| 885 &rl->table_vlc[0][0], 4, 2); | |
| 886 } | |
| 887 | |
| 888 /* init vlcs */ | |
| 889 | |
| 890 /* XXX: find a better solution to handle static init */ | |
| 891 void h263_decode_init_vlc(MpegEncContext *s) | |
| 892 { | |
| 893 static int done = 0; | |
| 894 | |
| 895 if (!done) { | |
| 896 done = 1; | |
| 897 | |
| 898 init_vlc(&intra_MCBPC_vlc, 6, 8, | |
| 899 intra_MCBPC_bits, 1, 1, | |
| 900 intra_MCBPC_code, 1, 1); | |
| 161 | 901 init_vlc(&inter_MCBPC_vlc, 9, 25, |
| 0 | 902 inter_MCBPC_bits, 1, 1, |
| 903 inter_MCBPC_code, 1, 1); | |
| 904 init_vlc(&cbpy_vlc, 6, 16, | |
| 905 &cbpy_tab[0][1], 2, 1, | |
| 906 &cbpy_tab[0][0], 2, 1); | |
| 907 init_vlc(&mv_vlc, 9, 33, | |
| 908 &mvtab[0][1], 2, 1, | |
| 909 &mvtab[0][0], 2, 1); | |
| 910 init_rl(&rl_inter); | |
| 911 init_rl(&rl_intra); | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
912 init_rl(&rl_intra_aic); |
| 0 | 913 init_vlc_rl(&rl_inter); |
| 914 init_vlc_rl(&rl_intra); | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
915 init_vlc_rl(&rl_intra_aic); |
| 0 | 916 init_vlc(&dc_lum, 9, 13, |
| 917 &DCtab_lum[0][1], 2, 1, | |
| 918 &DCtab_lum[0][0], 2, 1); | |
| 919 init_vlc(&dc_chrom, 9, 13, | |
| 920 &DCtab_chrom[0][1], 2, 1, | |
| 921 &DCtab_chrom[0][0], 2, 1); | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
922 init_vlc(&sprite_trajectory, 9, 15, |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
923 &sprite_trajectory_tab[0][1], 4, 2, |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
924 &sprite_trajectory_tab[0][0], 4, 2); |
| 0 | 925 } |
| 926 } | |
| 927 | |
| 162 | 928 int h263_decode_gob_header(MpegEncContext *s) |
| 929 { | |
| 930 unsigned int val, gfid; | |
| 931 | |
| 932 /* Check for GOB Start Code */ | |
| 933 val = show_bits(&s->gb, 16); | |
| 934 if (val == 0) { | |
| 935 /* We have a GBSC probably with GSTUFF */ | |
| 936 skip_bits(&s->gb, 16); /* Drop the zeros */ | |
| 937 while (get_bits1(&s->gb) == 0); /* Seek the '1' bit */ | |
| 938 #ifdef DEBUG | |
| 939 fprintf(stderr,"\nGOB Start Code at MB %d\n", (s->mb_y * s->mb_width) + s->mb_x); | |
| 940 #endif | |
| 941 s->gob_number = get_bits(&s->gb, 5); /* GN */ | |
| 942 gfid = get_bits(&s->gb, 2); /* GFID */ | |
| 943 s->qscale = get_bits(&s->gb, 5); /* GQUANT */ | |
| 944 #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
|
945 fprintf(stderr, "\nGN: %u GFID: %u Quant: %u\n", s->gob_number, gfid, s->qscale); |
| 162 | 946 #endif |
| 947 return 1; | |
| 948 } | |
| 949 return 0; | |
| 950 | |
| 951 } | |
| 952 | |
| 0 | 953 int h263_decode_mb(MpegEncContext *s, |
| 954 DCTELEM block[6][64]) | |
| 955 { | |
| 956 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; | |
| 957 INT16 *mot_val; | |
| 110 | 958 static INT8 quant_tab[4] = { -1, -2, 1, 2 }; |
|
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
959 |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
960 if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) { |
| 21 | 961 if (get_bits1(&s->gb)) { |
| 0 | 962 /* skip mb */ |
| 963 s->mb_intra = 0; | |
| 964 for(i=0;i<6;i++) | |
| 965 s->block_last_index[i] = -1; | |
| 966 s->mv_dir = MV_DIR_FORWARD; | |
| 967 s->mv_type = MV_TYPE_16X16; | |
| 255 | 968 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ |
| 969 const int a= s->sprite_warping_accuracy; | |
| 970 // int l = (1 << (s->f_code - 1)) * 32; | |
| 971 | |
| 972 s->mcsel=1; | |
| 973 s->mv[0][0][0] = RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); | |
| 974 s->mv[0][0][1] = RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); | |
| 975 /* if (s->mv[0][0][0] < -l) s->mv[0][0][0]= -l; | |
| 976 else if (s->mv[0][0][0] >= l) s->mv[0][0][0]= l-1; | |
| 977 if (s->mv[0][0][1] < -l) s->mv[0][0][1]= -l; | |
| 978 else if (s->mv[0][0][1] >= l) s->mv[0][0][1]= l-1;*/ | |
| 979 | |
| 980 s->mb_skiped = 0; | |
| 981 }else{ | |
| 982 s->mcsel=0; | |
| 983 s->mv[0][0][0] = 0; | |
| 984 s->mv[0][0][1] = 0; | |
| 985 s->mb_skiped = 1; | |
| 986 } | |
| 0 | 987 return 0; |
| 988 } | |
| 989 cbpc = get_vlc(&s->gb, &inter_MCBPC_vlc); | |
| 144 | 990 //fprintf(stderr, "\tCBPC: %d", cbpc); |
| 0 | 991 if (cbpc < 0) |
| 992 return -1; | |
| 161 | 993 if (cbpc > 20) |
| 994 cbpc+=3; | |
| 995 else if (cbpc == 20) | |
| 996 fprintf(stderr, "Stuffing !"); | |
| 144 | 997 |
| 0 | 998 dquant = cbpc & 8; |
| 999 s->mb_intra = ((cbpc & 4) != 0); | |
| 1000 } else { | |
| 1001 cbpc = get_vlc(&s->gb, &intra_MCBPC_vlc); | |
| 1002 if (cbpc < 0) | |
| 1003 return -1; | |
| 1004 dquant = cbpc & 4; | |
| 1005 s->mb_intra = 1; | |
| 1006 } | |
| 1007 | |
| 1008 if (!s->mb_intra) { | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1009 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
|
1010 s->mcsel= get_bits1(&s->gb); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1011 else s->mcsel= 0; |
| 0 | 1012 cbpy = get_vlc(&s->gb, &cbpy_vlc); |
| 1013 cbp = (cbpc & 3) | ((cbpy ^ 0xf) << 2); | |
| 1014 if (dquant) { | |
| 1015 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
| 1016 if (s->qscale < 1) | |
| 1017 s->qscale = 1; | |
| 1018 else if (s->qscale > 31) | |
| 1019 s->qscale = 31; | |
| 1020 } | |
| 1021 s->mv_dir = MV_DIR_FORWARD; | |
| 1022 if ((cbpc & 16) == 0) { | |
| 1023 /* 16x16 motion prediction */ | |
| 1024 s->mv_type = MV_TYPE_16X16; | |
| 1025 h263_pred_motion(s, 0, &pred_x, &pred_y); | |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1026 if (s->umvplus_dec) |
| 78 | 1027 mx = h263p_decode_umotion(s, pred_x); |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1028 else if(!s->mcsel) |
| 78 | 1029 mx = h263_decode_motion(s, pred_x); |
| 255 | 1030 else { |
| 1031 const int a= s->sprite_warping_accuracy; | |
| 1032 // int l = (1 << (s->f_code - 1)) * 32; | |
| 1033 mx= RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); | |
| 1034 // if (mx < -l) mx= -l; | |
| 1035 // else if (mx >= l) mx= l-1; | |
| 1036 } | |
| 0 | 1037 if (mx >= 0xffff) |
| 1038 return -1; | |
| 78 | 1039 |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1040 if (s->umvplus_dec) |
| 78 | 1041 my = h263p_decode_umotion(s, pred_y); |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1042 else if(!s->mcsel) |
| 78 | 1043 my = h263_decode_motion(s, pred_y); |
| 255 | 1044 else{ |
| 1045 const int a= s->sprite_warping_accuracy; | |
| 1046 // int l = (1 << (s->f_code - 1)) * 32; | |
| 1047 my= RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); | |
| 1048 // if (my < -l) my= -l; | |
| 1049 // else if (my >= l) my= l-1; | |
| 1050 } | |
| 0 | 1051 if (my >= 0xffff) |
| 1052 return -1; | |
| 1053 s->mv[0][0][0] = mx; | |
| 1054 s->mv[0][0][1] = my; | |
|
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
1055 /*fprintf(stderr, "\n MB %d", (s->mb_y * s->mb_width) + s->mb_x); |
|
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
1056 fprintf(stderr, "\n\tmvx: %d\t\tpredx: %d", mx, pred_x); |
|
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
1057 fprintf(stderr, "\n\tmvy: %d\t\tpredy: %d", my, pred_y);*/ |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1058 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) |
| 78 | 1059 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
| 1060 | |
| 0 | 1061 } else { |
| 1062 s->mv_type = MV_TYPE_8X8; | |
| 1063 for(i=0;i<4;i++) { | |
| 1064 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
|
1065 if (s->umvplus_dec) |
| 78 | 1066 mx = h263p_decode_umotion(s, pred_x); |
| 1067 else | |
| 1068 mx = h263_decode_motion(s, pred_x); | |
| 0 | 1069 if (mx >= 0xffff) |
| 1070 return -1; | |
| 78 | 1071 |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1072 if (s->umvplus_dec) |
| 78 | 1073 my = h263p_decode_umotion(s, pred_y); |
| 1074 else | |
| 1075 my = h263_decode_motion(s, pred_y); | |
| 0 | 1076 if (my >= 0xffff) |
| 1077 return -1; | |
| 1078 s->mv[0][i][0] = mx; | |
| 1079 s->mv[0][i][1] = my; | |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1080 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) |
| 78 | 1081 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
| 0 | 1082 mot_val[0] = mx; |
| 1083 mot_val[1] = my; | |
| 1084 } | |
| 1085 } | |
| 1086 } else { | |
| 1087 s->ac_pred = 0; | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1088 if (s->h263_pred || s->h263_aic) { |
| 21 | 1089 s->ac_pred = get_bits1(&s->gb); |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1090 if (s->ac_pred && s->h263_aic) |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1091 s->h263_aic_dir = get_bits1(&s->gb); |
| 0 | 1092 } |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1093 if (s->h263_aic) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1094 s->y_dc_scale = 2 * s->qscale; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1095 s->c_dc_scale = 2 * s->qscale; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1096 } |
| 0 | 1097 cbpy = get_vlc(&s->gb, &cbpy_vlc); |
| 1098 cbp = (cbpc & 3) | (cbpy << 2); | |
| 1099 if (dquant) { | |
| 1100 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
| 1101 if (s->qscale < 1) | |
| 1102 s->qscale = 1; | |
| 1103 else if (s->qscale > 31) | |
| 1104 s->qscale = 31; | |
| 1105 } | |
| 1106 } | |
| 1107 | |
| 1108 /* decode each block */ | |
| 1109 if (s->h263_pred) { | |
| 1110 for (i = 0; i < 6; i++) { | |
| 1111 if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) | |
| 1112 return -1; | |
| 1113 } | |
| 1114 } else { | |
| 1115 for (i = 0; i < 6; i++) { | |
| 1116 if (h263_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) | |
| 1117 return -1; | |
| 1118 } | |
| 1119 } | |
| 1120 return 0; | |
| 1121 } | |
| 1122 | |
| 1123 static int h263_decode_motion(MpegEncContext * s, int pred) | |
| 1124 { | |
| 1125 int code, val, sign, shift, l, m; | |
| 1126 | |
| 1127 code = get_vlc(&s->gb, &mv_vlc); | |
| 1128 if (code < 0) | |
| 1129 return 0xffff; | |
| 1130 | |
| 1131 if (code == 0) | |
| 1132 return pred; | |
| 21 | 1133 sign = get_bits1(&s->gb); |
| 0 | 1134 shift = s->f_code - 1; |
| 1135 val = (code - 1) << shift; | |
| 1136 if (shift > 0) | |
| 1137 val |= get_bits(&s->gb, shift); | |
| 1138 val++; | |
| 1139 if (sign) | |
| 1140 val = -val; | |
| 1141 val += pred; | |
| 1142 | |
| 1143 /* modulo decoding */ | |
| 1144 if (!s->h263_long_vectors) { | |
| 1145 l = (1 << (s->f_code - 1)) * 32; | |
| 1146 m = 2 * l; | |
| 1147 if (val < -l) { | |
| 1148 val += m; | |
| 1149 } else if (val >= l) { | |
| 1150 val -= m; | |
| 1151 } | |
| 1152 } else { | |
| 1153 /* horrible h263 long vector mode */ | |
| 1154 if (pred < -31 && val < -63) | |
| 1155 val += 64; | |
| 1156 if (pred > 32 && val > 63) | |
| 1157 val -= 64; | |
|
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
1158 |
| 0 | 1159 } |
| 1160 return val; | |
| 1161 } | |
| 1162 | |
| 78 | 1163 /* Decodes RVLC of H.263+ UMV */ |
| 1164 static int h263p_decode_umotion(MpegEncContext * s, int pred) | |
| 1165 { | |
| 1166 int code = 0, sign; | |
| 1167 | |
| 1168 if (get_bits1(&s->gb)) /* Motion difference = 0 */ | |
| 1169 return pred; | |
| 1170 | |
| 1171 code = 2 + get_bits1(&s->gb); | |
| 1172 | |
| 1173 while (get_bits1(&s->gb)) | |
| 1174 { | |
| 1175 code <<= 1; | |
| 1176 code += get_bits1(&s->gb); | |
| 1177 } | |
| 1178 sign = code & 1; | |
| 1179 code >>= 1; | |
| 1180 | |
| 1181 code = (sign) ? (pred - code) : (pred + code); | |
| 1182 #ifdef DEBUG | |
| 1183 fprintf(stderr,"H.263+ UMV Motion = %d\n", code); | |
| 1184 #endif | |
| 1185 return code; | |
| 1186 | |
| 1187 } | |
| 1188 | |
| 0 | 1189 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
| 1190 int n, int coded) | |
| 1191 { | |
| 1192 int code, level, i, j, last, run; | |
| 1193 RLTable *rl = &rl_inter; | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1194 const UINT8 *scan_table; |
| 0 | 1195 |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1196 scan_table = zigzag_direct; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1197 if (s->h263_aic && s->mb_intra) { |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1198 rl = &rl_intra_aic; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1199 i = 0; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1200 if (s->ac_pred) { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1201 if (s->h263_aic_dir) |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1202 scan_table = ff_alternate_vertical_scan; /* left */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1203 else |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1204 scan_table = ff_alternate_horizontal_scan; /* top */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1205 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1206 } else if (s->mb_intra) { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1207 /* DC coef */ |
| 0 | 1208 if (s->h263_rv10 && s->rv10_version == 3 && s->pict_type == I_TYPE) { |
| 1209 int component, diff; | |
| 1210 component = (n <= 3 ? 0 : n - 4 + 1); | |
| 1211 level = s->last_dc[component]; | |
| 1212 if (s->rv10_first_dc_coded[component]) { | |
| 1213 diff = rv_decode_dc(s, n); | |
| 1214 if (diff == 0xffff) | |
| 1215 return -1; | |
| 1216 level += diff; | |
| 1217 level = level & 0xff; /* handle wrap round */ | |
| 1218 s->last_dc[component] = level; | |
| 1219 } else { | |
| 1220 s->rv10_first_dc_coded[component] = 1; | |
| 1221 } | |
| 1222 } else { | |
| 1223 level = get_bits(&s->gb, 8); | |
| 1224 if (level == 255) | |
| 1225 level = 128; | |
| 1226 } | |
| 1227 block[0] = level; | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1228 i = 1; |
| 0 | 1229 } else { |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1230 i = 0; |
| 0 | 1231 } |
| 1232 if (!coded) { | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1233 if (s->mb_intra && s->h263_aic) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1234 goto not_coded; |
| 0 | 1235 s->block_last_index[n] = i - 1; |
| 1236 return 0; | |
| 1237 } | |
| 1238 | |
| 1239 for(;;) { | |
| 1240 code = get_vlc(&s->gb, &rl->vlc); | |
| 1241 if (code < 0) | |
| 1242 return -1; | |
| 1243 if (code == rl->n) { | |
| 1244 /* escape */ | |
| 21 | 1245 last = get_bits1(&s->gb); |
| 0 | 1246 run = get_bits(&s->gb, 6); |
| 1247 level = (INT8)get_bits(&s->gb, 8); | |
| 1248 if (s->h263_rv10 && level == -128) { | |
| 1249 /* XXX: should patch encoder too */ | |
| 1250 level = get_bits(&s->gb, 12); | |
| 1251 level = (level << 20) >> 20; | |
| 1252 } | |
| 1253 } else { | |
| 1254 run = rl->table_run[code]; | |
| 1255 level = rl->table_level[code]; | |
| 1256 last = code >= rl->last; | |
| 21 | 1257 if (get_bits1(&s->gb)) |
| 0 | 1258 level = -level; |
| 1259 } | |
| 1260 i += run; | |
| 1261 if (i >= 64) | |
| 1262 return -1; | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1263 j = scan_table[i]; |
| 0 | 1264 block[j] = level; |
| 1265 if (last) | |
| 1266 break; | |
| 1267 i++; | |
| 1268 } | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1269 not_coded: |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1270 if (s->mb_intra && s->h263_aic) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1271 h263_pred_acdc(s, block, n); |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1272 i = 64; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1273 } |
| 0 | 1274 s->block_last_index[n] = i; |
| 1275 return 0; | |
| 1276 } | |
| 1277 | |
| 1278 static int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) | |
| 1279 { | |
| 1280 int level, pred, code; | |
| 1281 UINT16 *dc_val; | |
| 1282 | |
| 1283 if (n < 4) | |
| 1284 code = get_vlc(&s->gb, &dc_lum); | |
| 1285 else | |
| 1286 code = get_vlc(&s->gb, &dc_chrom); | |
| 1287 if (code < 0) | |
| 1288 return -1; | |
| 1289 if (code == 0) { | |
| 1290 level = 0; | |
| 1291 } else { | |
| 1292 level = get_bits(&s->gb, code); | |
| 1293 if ((level >> (code - 1)) == 0) /* if MSB not set it is negative*/ | |
| 1294 level = - (level ^ ((1 << code) - 1)); | |
| 1295 if (code > 8) | |
| 21 | 1296 skip_bits1(&s->gb); /* marker */ |
| 0 | 1297 } |
| 1298 | |
| 1299 pred = mpeg4_pred_dc(s, n, &dc_val, dir_ptr); | |
| 1300 level += pred; | |
| 1301 if (level < 0) | |
| 1302 level = 0; | |
| 1303 if (n < 4) { | |
| 1304 *dc_val = level * s->y_dc_scale; | |
| 1305 } else { | |
| 1306 *dc_val = level * s->c_dc_scale; | |
| 1307 } | |
| 1308 return level; | |
| 1309 } | |
| 1310 | |
| 1311 static int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | |
| 1312 int n, int coded) | |
| 1313 { | |
| 1314 int code, level, i, j, last, run; | |
| 1315 int dc_pred_dir; | |
| 1316 RLTable *rl; | |
| 1317 const UINT8 *scan_table; | |
| 1318 | |
| 1319 if (s->mb_intra) { | |
| 1320 /* DC coef */ | |
| 1321 level = mpeg4_decode_dc(s, n, &dc_pred_dir); | |
| 1322 if (level < 0) | |
| 1323 return -1; | |
| 1324 block[0] = level; | |
| 1325 i = 1; | |
| 1326 if (!coded) | |
| 1327 goto not_coded; | |
| 1328 rl = &rl_intra; | |
| 1329 if (s->ac_pred) { | |
| 1330 if (dc_pred_dir == 0) | |
| 1331 scan_table = ff_alternate_vertical_scan; /* left */ | |
| 1332 else | |
| 1333 scan_table = ff_alternate_horizontal_scan; /* top */ | |
| 1334 } else { | |
| 1335 scan_table = zigzag_direct; | |
| 1336 } | |
| 1337 } else { | |
| 1338 i = 0; | |
| 1339 if (!coded) { | |
| 1340 s->block_last_index[n] = i - 1; | |
| 1341 return 0; | |
| 1342 } | |
| 1343 rl = &rl_inter; | |
| 1344 scan_table = zigzag_direct; | |
| 1345 } | |
| 1346 | |
| 1347 for(;;) { | |
| 1348 code = get_vlc(&s->gb, &rl->vlc); | |
| 1349 if (code < 0) | |
| 1350 return -1; | |
| 1351 if (code == rl->n) { | |
| 1352 /* escape */ | |
| 21 | 1353 if (get_bits1(&s->gb) != 0) { |
| 1354 if (get_bits1(&s->gb) != 0) { | |
| 0 | 1355 /* third escape */ |
| 21 | 1356 last = get_bits1(&s->gb); |
| 0 | 1357 run = get_bits(&s->gb, 6); |
| 21 | 1358 get_bits1(&s->gb); /* marker */ |
| 0 | 1359 level = get_bits(&s->gb, 12); |
| 1360 level = (level << 20) >> 20; /* sign extend */ | |
| 21 | 1361 skip_bits1(&s->gb); /* marker */ |
| 0 | 1362 } else { |
| 1363 /* second escape */ | |
| 1364 code = get_vlc(&s->gb, &rl->vlc); | |
| 1365 if (code < 0 || code >= rl->n) | |
| 1366 return -1; | |
| 1367 run = rl->table_run[code]; | |
| 1368 level = rl->table_level[code]; | |
| 1369 last = code >= rl->last; | |
| 1370 run += rl->max_run[last][level] + 1; | |
| 21 | 1371 if (get_bits1(&s->gb)) |
| 0 | 1372 level = -level; |
| 1373 } | |
| 1374 } else { | |
| 1375 /* first escape */ | |
| 1376 code = get_vlc(&s->gb, &rl->vlc); | |
| 1377 if (code < 0 || code >= rl->n) | |
| 1378 return -1; | |
| 1379 run = rl->table_run[code]; | |
| 1380 level = rl->table_level[code]; | |
| 1381 last = code >= rl->last; | |
| 1382 level += rl->max_level[last][run]; | |
| 21 | 1383 if (get_bits1(&s->gb)) |
| 0 | 1384 level = -level; |
| 1385 } | |
| 1386 } else { | |
| 1387 run = rl->table_run[code]; | |
| 1388 level = rl->table_level[code]; | |
| 1389 last = code >= rl->last; | |
| 21 | 1390 if (get_bits1(&s->gb)) |
| 0 | 1391 level = -level; |
| 1392 } | |
| 1393 i += run; | |
| 1394 if (i >= 64) | |
| 1395 return -1; | |
| 1396 j = scan_table[i]; | |
| 1397 block[j] = level; | |
| 1398 i++; | |
| 1399 if (last) | |
| 1400 break; | |
| 1401 } | |
| 1402 not_coded: | |
| 1403 if (s->mb_intra) { | |
| 1404 mpeg4_pred_ac(s, block, n, dc_pred_dir); | |
| 1405 if (s->ac_pred) { | |
| 1406 i = 64; /* XXX: not optimal */ | |
| 1407 } | |
| 1408 } | |
| 1409 s->block_last_index[n] = i - 1; | |
| 1410 return 0; | |
| 1411 } | |
| 1412 | |
| 1413 /* most is hardcoded. should extend to handle all h263 streams */ | |
| 1414 int h263_decode_picture_header(MpegEncContext *s) | |
| 1415 { | |
| 1416 int format, width, height; | |
| 1417 | |
| 1418 /* picture header */ | |
| 1419 if (get_bits(&s->gb, 22) != 0x20) | |
| 1420 return -1; | |
| 231 | 1421 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ |
| 1422 | |
| 21 | 1423 if (get_bits1(&s->gb) != 1) |
| 0 | 1424 return -1; /* marker */ |
| 21 | 1425 if (get_bits1(&s->gb) != 0) |
| 0 | 1426 return -1; /* h263 id */ |
| 21 | 1427 skip_bits1(&s->gb); /* split screen off */ |
| 1428 skip_bits1(&s->gb); /* camera off */ | |
| 1429 skip_bits1(&s->gb); /* freeze picture release off */ | |
| 0 | 1430 |
|
155
3c3449bce692
- Bug fix on MV prediction for MPEG4 caused by new H.263 GOB code.
pulento
parents:
154
diff
changeset
|
1431 /* Reset GOB number */ |
|
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
1432 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
|
1433 |
| 0 | 1434 format = get_bits(&s->gb, 3); |
| 1435 | |
| 161 | 1436 if (format != 7 && format != 6) { |
| 0 | 1437 s->h263_plus = 0; |
| 1438 /* H.263v1 */ | |
| 1439 width = h263_format[format][0]; | |
| 1440 height = h263_format[format][1]; | |
| 1441 if (!width) | |
| 1442 return -1; | |
| 161 | 1443 |
| 1444 s->width = width; | |
| 1445 s->height = height; | |
| 21 | 1446 s->pict_type = I_TYPE + get_bits1(&s->gb); |
| 0 | 1447 |
| 21 | 1448 s->unrestricted_mv = get_bits1(&s->gb); |
| 0 | 1449 s->h263_long_vectors = s->unrestricted_mv; |
| 1450 | |
| 21 | 1451 if (get_bits1(&s->gb) != 0) |
| 0 | 1452 return -1; /* SAC: off */ |
| 161 | 1453 if (get_bits1(&s->gb) != 0) { |
| 1454 s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */ | |
| 1455 } | |
| 1456 | |
| 21 | 1457 if (get_bits1(&s->gb) != 0) |
| 0 | 1458 return -1; /* not PB frame */ |
| 1459 | |
| 1460 s->qscale = get_bits(&s->gb, 5); | |
| 21 | 1461 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
| 0 | 1462 } else { |
| 161 | 1463 int ufep; |
| 1464 | |
| 0 | 1465 /* H.263v2 */ |
| 161 | 1466 s->h263_plus = 1; |
| 1467 ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */ | |
| 1468 | |
| 1469 if (ufep == 1) { | |
| 1470 /* OPPTYPE */ | |
| 1471 format = get_bits(&s->gb, 3); | |
| 1472 skip_bits(&s->gb,1); /* Custom PCF */ | |
| 1473 s->umvplus_dec = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */ | |
| 1474 skip_bits1(&s->gb); /* Syntax-based Arithmetic Coding (SAC) */ | |
| 1475 if (get_bits1(&s->gb) != 0) { | |
| 1476 s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */ | |
| 1477 } | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1478 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
|
1479 s->h263_aic = 1; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1480 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1481 skip_bits(&s->gb, 7); |
| 161 | 1482 skip_bits(&s->gb, 3); /* Reserved */ |
| 1483 } else if (ufep != 0) | |
| 0 | 1484 return -1; |
| 161 | 1485 |
| 78 | 1486 /* MPPTYPE */ |
| 0 | 1487 s->pict_type = get_bits(&s->gb, 3) + 1; |
| 1488 if (s->pict_type != I_TYPE && | |
| 1489 s->pict_type != P_TYPE) | |
| 1490 return -1; | |
|
250
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
1491 skip_bits(&s->gb, 2); |
|
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
1492 s->no_rounding = get_bits1(&s->gb); |
|
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
1493 //fprintf(stderr, "\nRTYPE: %d", s->no_rounding); |
|
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
1494 skip_bits(&s->gb, 4); |
| 78 | 1495 |
| 1496 /* Get the picture dimensions */ | |
| 161 | 1497 if (ufep) { |
| 1498 if (format == 6) { | |
| 1499 /* Custom Picture Format (CPFMT) */ | |
| 1500 skip_bits(&s->gb, 4); /* aspect ratio */ | |
| 1501 width = (get_bits(&s->gb, 9) + 1) * 4; | |
| 1502 skip_bits1(&s->gb); | |
| 1503 height = get_bits(&s->gb, 9) * 4; | |
| 78 | 1504 #ifdef DEBUG |
| 161 | 1505 fprintf(stderr,"\nH.263+ Custom picture: %dx%d\n",width,height); |
| 78 | 1506 #endif |
| 161 | 1507 } |
| 1508 else { | |
| 1509 width = h263_format[format][0]; | |
| 1510 height = h263_format[format][1]; | |
| 1511 } | |
| 1512 if ((width == 0) || (height == 0)) | |
| 1513 return -1; | |
| 1514 s->width = width; | |
| 1515 s->height = height; | |
| 1516 if (s->umvplus_dec) { | |
| 1517 skip_bits1(&s->gb); /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | |
| 1518 } | |
| 78 | 1519 } |
| 1520 | |
| 0 | 1521 s->qscale = get_bits(&s->gb, 5); |
| 1522 } | |
| 1523 /* PEI */ | |
| 21 | 1524 while (get_bits1(&s->gb) != 0) { |
| 1525 skip_bits(&s->gb, 8); | |
| 0 | 1526 } |
| 1527 s->f_code = 1; | |
| 1528 return 0; | |
| 1529 } | |
| 1530 | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1531 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
|
1532 { |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1533 int i; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1534 int a= 2<<s->sprite_warping_accuracy; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1535 int rho= 3-s->sprite_warping_accuracy; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1536 int r=16/a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1537 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
|
1538 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
|
1539 int sprite_ref[4][2]; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1540 int virtual_ref[2][2]; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1541 int w2, h2; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1542 int alpha=0, beta=0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1543 int w= s->width; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1544 int h= s->height; |
| 255 | 1545 //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
|
1546 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
|
1547 int length; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1548 int x=0, y=0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1549 |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1550 length= get_vlc(&s->gb, &sprite_trajectory); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1551 if(length){ |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1552 x= get_bits(&s->gb, length); |
| 255 | 1553 //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
|
1554 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
|
1555 x = - (x ^ ((1 << length) - 1)); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1556 } |
| 255 | 1557 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
|
1558 |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1559 length= get_vlc(&s->gb, &sprite_trajectory); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1560 if(length){ |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1561 y=get_bits(&s->gb, length); |
| 255 | 1562 //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
|
1563 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
|
1564 y = - (y ^ ((1 << length) - 1)); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1565 } |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1566 skip_bits1(&s->gb); /* marker bit */ |
| 255 | 1567 //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
|
1568 //if(i>0 && (x!=0 || y!=0)) printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); |
| 255 | 1569 //x=y=0; |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1570 d[i][0]= x; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1571 d[i][1]= y; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1572 } |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1573 |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1574 while((1<<alpha)<w) alpha++; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1575 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
|
1576 w2= 1<<alpha; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1577 h2= 1<<beta; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1578 |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1579 // Note, the 4th point isnt used for GMC |
| 255 | 1580 /* |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1581 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1582 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1583 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1584 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1585 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1586 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]); |
| 255 | 1587 */ |
| 1588 //FIXME DIVX5 vs. mpeg4 ? | |
| 1589 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0]; | |
| 1590 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1]; | |
| 1591 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0]; | |
| 1592 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1]; | |
| 1593 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0]; | |
| 1594 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1]; | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1595 /* 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
|
1596 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
|
1597 |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1598 // 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
|
1599 // 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
|
1600 // 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
|
1601 // 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
|
1602 virtual_ref[0][0]= 16*(vop_ref[0][0] + w2) |
| 255 | 1603 + RDIV(((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
|
1604 virtual_ref[0][1]= 16*vop_ref[0][1] |
| 255 | 1605 + RDIV(((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
|
1606 virtual_ref[1][0]= 16*vop_ref[0][0] |
| 255 | 1607 + RDIV(((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
|
1608 virtual_ref[1][1]= 16*(vop_ref[0][1] + h2) |
| 255 | 1609 + RDIV(((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
|
1610 |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1611 switch(s->num_sprite_warping_points) |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1612 { |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1613 case 0: |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1614 s->sprite_offset[0][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1615 s->sprite_offset[0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1616 s->sprite_offset[1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1617 s->sprite_offset[1][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1618 s->sprite_delta[0][0][0]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1619 s->sprite_delta[0][0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1620 s->sprite_delta[0][1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1621 s->sprite_delta[0][1][1]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1622 s->sprite_delta[1][0][0]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1623 s->sprite_delta[1][0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1624 s->sprite_delta[1][1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1625 s->sprite_delta[1][1][1]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1626 s->sprite_shift[0][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1627 s->sprite_shift[0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1628 s->sprite_shift[1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1629 s->sprite_shift[1][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1630 break; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1631 case 1: //GMC only |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1632 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
|
1633 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
|
1634 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
|
1635 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
|
1636 s->sprite_delta[0][0][0]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1637 s->sprite_delta[0][0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1638 s->sprite_delta[0][1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1639 s->sprite_delta[0][1][1]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1640 s->sprite_delta[1][0][0]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1641 s->sprite_delta[1][0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1642 s->sprite_delta[1][1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1643 s->sprite_delta[1][1][1]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1644 s->sprite_shift[0][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1645 s->sprite_shift[0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1646 s->sprite_shift[1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1647 s->sprite_shift[1][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1648 break; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1649 case 2: |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1650 case 3: //FIXME |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1651 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
|
1652 + ((-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
|
1653 +( 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
|
1654 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
|
1655 + ((-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
|
1656 +(-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
|
1657 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
|
1658 +( 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
|
1659 +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
|
1660 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
|
1661 +(-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
|
1662 +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
|
1663 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
|
1664 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
|
1665 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
|
1666 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
|
1667 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
|
1668 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
|
1669 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
|
1670 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
|
1671 s->sprite_shift[0][0]= alpha+rho; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1672 s->sprite_shift[0][1]= alpha+rho; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1673 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
|
1674 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
|
1675 break; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1676 // case 3: |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1677 break; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1678 } |
| 255 | 1679 /*printf("%d %d\n", s->sprite_delta[0][0][0], a<<s->sprite_shift[0][0]); |
| 1680 printf("%d %d\n", s->sprite_delta[0][0][1], 0); | |
| 1681 printf("%d %d\n", s->sprite_delta[0][1][0], 0); | |
| 1682 printf("%d %d\n", s->sprite_delta[0][1][1], a<<s->sprite_shift[0][1]); | |
| 1683 printf("%d %d\n", s->sprite_delta[1][0][0], a<<s->sprite_shift[1][0]); | |
| 1684 printf("%d %d\n", s->sprite_delta[1][0][1], 0); | |
| 1685 printf("%d %d\n", s->sprite_delta[1][1][0], 0); | |
| 1686 printf("%d %d\n", s->sprite_delta[1][1][1], a<<s->sprite_shift[1][1]);*/ | |
| 1687 /* try to simplify the situation */ | |
| 1688 if( s->sprite_delta[0][0][0] == a<<s->sprite_shift[0][0] | |
| 1689 && s->sprite_delta[0][0][1] == 0 | |
| 1690 && s->sprite_delta[0][1][0] == 0 | |
| 1691 && s->sprite_delta[0][1][1] == a<<s->sprite_shift[0][1] | |
| 1692 && s->sprite_delta[1][0][0] == a<<s->sprite_shift[1][0] | |
| 1693 && s->sprite_delta[1][0][1] == 0 | |
| 1694 && s->sprite_delta[1][1][0] == 0 | |
| 1695 && s->sprite_delta[1][1][1] == a<<s->sprite_shift[1][1]) | |
| 1696 { | |
| 1697 s->sprite_offset[0][0]>>=s->sprite_shift[0][0]; | |
| 1698 s->sprite_offset[0][1]>>=s->sprite_shift[0][1]; | |
| 1699 s->sprite_offset[1][0]>>=s->sprite_shift[1][0]; | |
| 1700 s->sprite_offset[1][1]>>=s->sprite_shift[1][1]; | |
| 1701 s->sprite_delta[0][0][0]= a; | |
| 1702 s->sprite_delta[0][0][1]= 0; | |
| 1703 s->sprite_delta[0][1][0]= 0; | |
| 1704 s->sprite_delta[0][1][1]= a; | |
| 1705 s->sprite_delta[1][0][0]= a; | |
| 1706 s->sprite_delta[1][0][1]= 0; | |
| 1707 s->sprite_delta[1][1][0]= 0; | |
| 1708 s->sprite_delta[1][1][1]= a; | |
| 1709 s->sprite_shift[0][0]= 0; | |
| 1710 s->sprite_shift[0][1]= 0; | |
| 1711 s->sprite_shift[1][0]= 0; | |
| 1712 s->sprite_shift[1][1]= 0; | |
| 1713 s->real_sprite_warping_points=1; | |
| 1714 } | |
| 1715 else | |
| 1716 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
|
1717 |
| 255 | 1718 //FIXME convert stuff if accurace != 3 |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1719 } |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1720 |
| 0 | 1721 /* decode mpeg4 VOP header */ |
| 1722 int mpeg4_decode_picture_header(MpegEncContext * s) | |
| 1723 { | |
| 1724 int time_incr, startcode, state, v; | |
| 1725 | |
| 1726 redo: | |
| 1727 /* search next start code */ | |
| 1728 align_get_bits(&s->gb); | |
| 1729 state = 0xff; | |
| 1730 for(;;) { | |
| 1731 v = get_bits(&s->gb, 8); | |
| 1732 if (state == 0x000001) { | |
| 1733 state = ((state << 8) | v) & 0xffffff; | |
| 1734 startcode = state; | |
| 1735 break; | |
| 1736 } | |
| 1737 state = ((state << 8) | v) & 0xffffff; | |
| 1738 /* XXX: really detect end of frame */ | |
| 1739 if (state == 0) | |
| 1740 return -1; | |
| 1741 } | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1742 //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
|
1743 if (startcode == 0x120) { // Video Object Layer |
| 63 | 1744 int time_increment_resolution, width, height, vo_ver_id; |
| 0 | 1745 |
| 1746 /* vol header */ | |
| 21 | 1747 skip_bits(&s->gb, 1); /* random access */ |
| 1748 skip_bits(&s->gb, 8); /* vo_type */ | |
| 63 | 1749 if (get_bits1(&s->gb) != 0) { /* is_ol_id */ |
| 1750 vo_ver_id = get_bits(&s->gb, 4); /* vo_ver_id */ | |
| 1751 skip_bits(&s->gb, 3); /* vo_priority */ | |
| 1752 } else { | |
| 1753 vo_ver_id = 1; | |
| 1754 } | |
| 0 | 1755 |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1756 s->aspect_ratio_info= get_bits(&s->gb, 4); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1757 if(s->aspect_ratio_info == EXTENDET_PAR){ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1758 skip_bits(&s->gb, 8); //par_width |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1759 skip_bits(&s->gb, 8); // par_height |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1760 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1761 if(get_bits1(&s->gb)){ /* vol control parameter */ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1762 printf("vol control parameter not supported\n"); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1763 return -1; |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1764 } |
| 63 | 1765 s->shape = get_bits(&s->gb, 2); /* vol shape */ |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1766 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
|
1767 printf("Gray shape not supported\n"); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1768 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
|
1769 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1770 |
| 21 | 1771 skip_bits1(&s->gb); /* marker */ |
| 0 | 1772 |
| 1773 time_increment_resolution = get_bits(&s->gb, 16); | |
| 70 | 1774 s->time_increment_bits = av_log2(time_increment_resolution - 1) + 1; |
| 63 | 1775 if (s->time_increment_bits < 1) |
| 1776 s->time_increment_bits = 1; | |
| 21 | 1777 skip_bits1(&s->gb); /* marker */ |
| 0 | 1778 |
| 63 | 1779 if (get_bits1(&s->gb) != 0) { /* fixed_vop_rate */ |
| 1780 skip_bits(&s->gb, s->time_increment_bits); | |
| 1781 } | |
| 0 | 1782 |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1783 if (s->shape != BIN_ONLY_SHAPE) { |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1784 if (s->shape == RECT_SHAPE) { |
| 63 | 1785 skip_bits1(&s->gb); /* marker */ |
| 1786 width = get_bits(&s->gb, 13); | |
| 1787 skip_bits1(&s->gb); /* marker */ | |
| 1788 height = get_bits(&s->gb, 13); | |
| 1789 skip_bits1(&s->gb); /* marker */ | |
| 1790 } | |
| 1791 | |
| 1792 skip_bits1(&s->gb); /* interlaced */ | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1793 if(!get_bits1(&s->gb)) printf("OBMC not supported\n"); /* OBMC Disable */ |
| 63 | 1794 if (vo_ver_id == 1) { |
| 1795 s->vol_sprite_usage = get_bits1(&s->gb); /* vol_sprite_usage */ | |
| 1796 } else { | |
| 1797 s->vol_sprite_usage = get_bits(&s->gb, 2); /* vol_sprite_usage */ | |
| 1798 } | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1799 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
|
1800 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
|
1801 if(s->vol_sprite_usage==STATIC_SPRITE){ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1802 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
|
1803 skip_bits1(&s->gb); /* marker */ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1804 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
|
1805 skip_bits1(&s->gb); /* marker */ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1806 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
|
1807 skip_bits1(&s->gb); /* marker */ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1808 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
|
1809 skip_bits1(&s->gb); /* marker */ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1810 } |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1811 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
|
1812 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
|
1813 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
|
1814 if(s->vol_sprite_usage==STATIC_SPRITE) |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1815 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
|
1816 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1817 // 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
|
1818 |
| 63 | 1819 if (get_bits1(&s->gb) == 1) { /* not_8_bit */ |
| 1820 s->quant_precision = get_bits(&s->gb, 4); /* quant_precision */ | |
| 1821 skip_bits(&s->gb, 4); /* bits_per_pixel */ | |
| 1822 } else { | |
| 1823 s->quant_precision = 5; | |
| 1824 } | |
| 1825 | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1826 // FIXME a bunch of grayscale shape things |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1827 if(get_bits1(&s->gb)) printf("Quant-Type not supported\n"); /* vol_quant_type */ //FIXME |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1828 if(vo_ver_id != 1) |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1829 s->quarter_sample= get_bits1(&s->gb); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1830 else s->quarter_sample=0; |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1831 #if 0 |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1832 if(get_bits1(&s->gb)) printf("Complexity est disabled\n"); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1833 if(get_bits1(&s->gb)) printf("resync disable\n"); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1834 #else |
| 63 | 1835 skip_bits1(&s->gb); /* complexity_estimation_disabled */ |
| 1836 skip_bits1(&s->gb); /* resync_marker_disabled */ | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1837 #endif |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1838 s->data_partioning= get_bits1(&s->gb); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1839 if(s->data_partioning){ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1840 printf("data partitioning not supported\n"); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1841 skip_bits1(&s->gb); // reversible vlc |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1842 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1843 |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1844 if(vo_ver_id != 1) { |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1845 s->new_pred= get_bits1(&s->gb); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1846 if(s->new_pred){ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1847 printf("new pred not supported\n"); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1848 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
|
1849 skip_bits1(&s->gb); /* newpred segment type */ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1850 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1851 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
|
1852 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
|
1853 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1854 else{ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1855 s->new_pred=0; |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1856 s->reduced_res_vop= 0; |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1857 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1858 |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1859 s->scalability= get_bits1(&s->gb); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1860 if (s->scalability) { |
| 63 | 1861 printf("bad scalability!!!\n"); |
| 1862 return -1; | |
| 1863 } | |
| 1864 } | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1865 //printf("end Data %X %d\n", show_bits(&s->gb, 32), get_bits_count(&s->gb)&0x7); |
| 0 | 1866 goto redo; |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1867 } else if (startcode == 0x1b2) { //userdata |
| 255 | 1868 char buf[256]; |
| 1869 int i; | |
| 1870 int e; | |
| 1871 int ver, build; | |
| 1872 | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1873 //printf("user Data %X\n", show_bits(&s->gb, 32)); |
| 255 | 1874 buf[0]= show_bits(&s->gb, 8); |
| 1875 for(i=1; i<256; i++){ | |
| 1876 buf[i]= show_bits(&s->gb, 16)&0xFF; | |
| 1877 if(buf[i]==0) break; | |
| 1878 skip_bits(&s->gb, 8); | |
| 1879 } | |
| 1880 buf[255]=0; | |
| 1881 e=sscanf(buf, "DivX%dBuild%d", &ver, &build); | |
| 1882 if(e==2){ | |
| 1883 s->divx_version= ver; | |
| 1884 s->divx_build= build; | |
| 1885 if(s->picture_number==0){ | |
| 1886 printf("This file was encoded with DivX%d Build%d\n", ver, build); | |
| 1887 if(ver==500 && build==413){ //most likely all version are indeed totally buggy but i dunno for sure ... | |
| 1888 printf("WARNING: this version of DivX is not MPEG4 compatible, trying to workaround these bugs...\n"); | |
| 1889 }else{ | |
| 1890 printf("hmm, i havnt seen that version of divx yet, lets assume they fixed these bugs ...\n" | |
| 1891 "using mpeg4 decoder, if it fails contact the developers (of ffmpeg)\n"); | |
| 1892 } | |
| 1893 } | |
| 1894 } | |
| 1895 //printf("User Data: %s\n", buf); | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1896 goto redo; |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1897 } else if (startcode != 0x1b6) { //VOP |
| 0 | 1898 goto redo; |
| 1899 } | |
| 1900 | |
| 1901 s->pict_type = get_bits(&s->gb, 2) + 1; /* pict type: I = 0 , P = 1 */ | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1902 if(s->pict_type == B_TYPE) |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1903 { |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1904 printf("B-VOP\n"); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1905 return -1; |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1906 } |
| 255 | 1907 |
| 0 | 1908 /* XXX: parse time base */ |
| 1909 time_incr = 0; | |
| 21 | 1910 while (get_bits1(&s->gb) != 0) |
| 0 | 1911 time_incr++; |
| 1912 | |
| 21 | 1913 skip_bits1(&s->gb); /* marker */ |
| 1914 skip_bits(&s->gb, s->time_increment_bits); | |
| 1915 skip_bits1(&s->gb); /* marker */ | |
| 0 | 1916 /* vop coded */ |
| 21 | 1917 if (get_bits1(&s->gb) != 1) |
| 63 | 1918 goto redo; |
| 0 | 1919 |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1920 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
|
1921 || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) { |
| 0 | 1922 /* rounding type for motion estimation */ |
| 21 | 1923 s->no_rounding = get_bits1(&s->gb); |
| 63 | 1924 } else { |
| 1925 s->no_rounding = 0; | |
| 0 | 1926 } |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1927 //FIXME reduced res stuff |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1928 |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1929 if (s->shape != RECT_SHAPE) { |
| 63 | 1930 if (s->vol_sprite_usage != 1 || s->pict_type != I_TYPE) { |
| 1931 int width, height, hor_spat_ref, ver_spat_ref; | |
| 1932 | |
| 1933 width = get_bits(&s->gb, 13); | |
| 1934 skip_bits1(&s->gb); /* marker */ | |
| 1935 height = get_bits(&s->gb, 13); | |
| 1936 skip_bits1(&s->gb); /* marker */ | |
| 1937 hor_spat_ref = get_bits(&s->gb, 13); /* hor_spat_ref */ | |
| 1938 skip_bits1(&s->gb); /* marker */ | |
| 1939 ver_spat_ref = get_bits(&s->gb, 13); /* ver_spat_ref */ | |
| 1940 } | |
| 1941 skip_bits1(&s->gb); /* change_CR_disable */ | |
| 1942 | |
| 1943 if (get_bits1(&s->gb) != 0) { | |
| 1944 skip_bits(&s->gb, 8); /* constant_alpha_value */ | |
| 1945 } | |
| 1946 } | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1947 //FIXME complexity estimation stuff |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1948 |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1949 if (s->shape != BIN_ONLY_SHAPE) { |
| 63 | 1950 skip_bits(&s->gb, 3); /* intra dc VLC threshold */ |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1951 //FIXME interlaced specific bits |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1952 } |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1953 |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1954 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
|
1955 if(s->num_sprite_warping_points){ |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1956 mpeg4_decode_sprite_trajectory(s); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1957 } |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1958 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
|
1959 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
|
1960 } |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1961 |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1962 if (s->shape != BIN_ONLY_SHAPE) { |
| 63 | 1963 /* note: we do not use quant_precision to avoid problem if no |
| 1964 MPEG4 vol header as it is found on some old opendivx | |
| 1965 movies */ | |
| 1966 s->qscale = get_bits(&s->gb, 5); | |
| 1967 | |
| 1968 if (s->pict_type != I_TYPE) { | |
| 1969 s->f_code = get_bits(&s->gb, 3); /* fcode_for */ | |
| 1970 } | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1971 if (s->pict_type == B_TYPE) { |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1972 s->b_code = get_bits(&s->gb, 3); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1973 } |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1974 //printf("quant:%d fcode:%d\n", s->qscale, s->f_code); |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1975 if(!s->scalability){ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1976 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
|
1977 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
|
1978 } |
| 63 | 1979 } |
| 1980 } | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
1981 //printf("end Data %X %d\n", show_bits(&s->gb, 32), get_bits_count(&s->gb)&0x7); |
| 255 | 1982 s->picture_number++; // better than pic number==0 allways ;) |
| 63 | 1983 return 0; |
| 0 | 1984 } |
| 1985 | |
| 1986 /* don't understand why they choose a different header ! */ | |
| 1987 int intel_h263_decode_picture_header(MpegEncContext *s) | |
| 1988 { | |
| 1989 int format; | |
| 1990 | |
| 1991 /* picture header */ | |
| 1992 if (get_bits(&s->gb, 22) != 0x20) | |
| 1993 return -1; | |
| 21 | 1994 skip_bits(&s->gb, 8); /* picture timestamp */ |
| 0 | 1995 |
| 21 | 1996 if (get_bits1(&s->gb) != 1) |
| 0 | 1997 return -1; /* marker */ |
| 21 | 1998 if (get_bits1(&s->gb) != 0) |
| 0 | 1999 return -1; /* h263 id */ |
| 21 | 2000 skip_bits1(&s->gb); /* split screen off */ |
| 2001 skip_bits1(&s->gb); /* camera off */ | |
| 2002 skip_bits1(&s->gb); /* freeze picture release off */ | |
| 0 | 2003 |
| 2004 format = get_bits(&s->gb, 3); | |
| 2005 if (format != 7) | |
| 2006 return -1; | |
| 2007 | |
| 2008 s->h263_plus = 0; | |
| 2009 | |
| 21 | 2010 s->pict_type = I_TYPE + get_bits1(&s->gb); |
| 0 | 2011 |
| 21 | 2012 s->unrestricted_mv = get_bits1(&s->gb); |
| 0 | 2013 s->h263_long_vectors = s->unrestricted_mv; |
| 2014 | |
| 21 | 2015 if (get_bits1(&s->gb) != 0) |
| 0 | 2016 return -1; /* SAC: off */ |
| 21 | 2017 if (get_bits1(&s->gb) != 0) |
| 0 | 2018 return -1; /* advanced prediction mode: off */ |
| 21 | 2019 if (get_bits1(&s->gb) != 0) |
| 0 | 2020 return -1; /* not PB frame */ |
| 2021 | |
| 2022 /* skip unknown header garbage */ | |
| 21 | 2023 skip_bits(&s->gb, 41); |
| 0 | 2024 |
| 2025 s->qscale = get_bits(&s->gb, 5); | |
| 21 | 2026 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
| 0 | 2027 |
| 2028 /* PEI */ | |
| 21 | 2029 while (get_bits1(&s->gb) != 0) { |
| 2030 skip_bits(&s->gb, 8); | |
| 0 | 2031 } |
| 2032 s->f_code = 1; | |
| 2033 return 0; | |
| 2034 } | |
| 144 | 2035 |
