Mercurial > libavcodec.hg
annotate h263.c @ 301:d7f71eb89558 libavcodec
divx5-gmc bug workaround
| author | michaelni |
|---|---|
| date | Fri, 29 Mar 2002 05:15:49 +0000 |
| parents | 6622b0fd036c |
| children | 8cf5507e6ca5 |
| 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. | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
20 * |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
21 * ac prediction encoding by Michael Niedermayer <michaelni@gmx.at> |
| 0 | 22 */ |
| 23 #include "common.h" | |
| 24 #include "dsputil.h" | |
| 25 #include "avcodec.h" | |
| 26 #include "mpegvideo.h" | |
| 27 #include "h263data.h" | |
| 28 #include "mpeg4data.h" | |
| 29 | |
| 255 | 30 //rounded divison & shift |
| 31 #define RDIV(a,b) ((a) > 0 ? ((a)+((b)>>1))/(b) : ((a)-((b)>>1))/(b)) | |
| 32 #define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b)) | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
33 #define ABS(a) (((a)>=0)?(a):(-(a))) |
| 290 | 34 #define MAX(a,b) ((a) > (b) ? (a) : (b)) |
| 35 #define MIN(a,b) ((a) < (b) ? (a) : (b)) | |
| 255 | 36 |
| 0 | 37 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, |
| 38 int n); | |
| 39 static void h263_encode_motion(MpegEncContext * s, int val); | |
| 78 | 40 static void h263p_encode_umotion(MpegEncContext * s, int val); |
| 0 | 41 static void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
42 int n, int dc, UINT8 *scan_table); |
| 262 | 43 static int h263_decode_motion(MpegEncContext * s, int pred, int fcode); |
| 78 | 44 static int h263p_decode_umotion(MpegEncContext * s, int pred); |
| 0 | 45 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
| 46 int n, int coded); | |
| 47 static int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | |
| 48 int n, int coded); | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
49 static inline int mpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
50 static void mpeg4_inv_pred_ac(MpegEncContext * s, INT16 *block, int n, |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
51 int dir); |
| 290 | 52 static void mpeg4_decode_sprite_trajectory(MpegEncContext * s); |
| 53 | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
54 extern UINT32 inverse[256]; |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
55 |
|
292
73a9ce3d9715
fcode_tables where too small, found by Klaas-Pieter Vlieg <vlieg@eurescom.de>
michaelni
parents:
291
diff
changeset
|
56 static UINT16 mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
57 static UINT8 fcode_tab[MAX_MV*2+1]; |
| 287 | 58 static UINT8 umv_fcode_tab[MAX_MV*2+1]; |
| 0 | 59 |
| 293 | 60 static UINT16 uni_DCtab_lum [512][2]; |
| 61 static UINT16 uni_DCtab_chrom[512][2]; | |
| 62 | |
| 0 | 63 int h263_get_picture_format(int width, int height) |
| 64 { | |
| 65 int format; | |
| 66 | |
| 67 if (width == 128 && height == 96) | |
| 68 format = 1; | |
| 69 else if (width == 176 && height == 144) | |
| 70 format = 2; | |
| 71 else if (width == 352 && height == 288) | |
| 72 format = 3; | |
| 73 else if (width == 704 && height == 576) | |
| 74 format = 4; | |
| 75 else if (width == 1408 && height == 1152) | |
| 76 format = 5; | |
| 77 else | |
| 78 format = 7; | |
| 79 return format; | |
| 80 } | |
| 81 | |
| 82 void h263_encode_picture_header(MpegEncContext * s, int picture_number) | |
| 83 { | |
| 78 | 84 int format; |
| 0 | 85 |
| 86 align_put_bits(&s->pb); | |
| 231 | 87 |
| 88 /* 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
|
89 s->ptr_lastgob = pbBufPtr(&s->pb); |
| 231 | 90 s->gob_number = 0; |
| 91 | |
| 92 put_bits(&s->pb, 22, 0x20); /* PSC */ | |
| 241 | 93 put_bits(&s->pb, 8, (((INT64)s->picture_number * 30 * FRAME_RATE_BASE) / |
| 0 | 94 s->frame_rate) & 0xff); |
| 95 | |
| 96 put_bits(&s->pb, 1, 1); /* marker */ | |
| 97 put_bits(&s->pb, 1, 0); /* h263 id */ | |
| 98 put_bits(&s->pb, 1, 0); /* split screen off */ | |
| 99 put_bits(&s->pb, 1, 0); /* camera off */ | |
| 100 put_bits(&s->pb, 1, 0); /* freeze picture release off */ | |
| 78 | 101 |
| 102 format = h263_get_picture_format(s->width, s->height); | |
| 0 | 103 if (!s->h263_plus) { |
| 104 /* H.263v1 */ | |
| 105 put_bits(&s->pb, 3, format); | |
| 106 put_bits(&s->pb, 1, (s->pict_type == P_TYPE)); | |
| 107 /* By now UMV IS DISABLED ON H.263v1, since the restrictions | |
| 108 of H.263v1 UMV implies to check the predicted MV after | |
| 109 calculation of the current MB to see if we're on the limits */ | |
| 110 put_bits(&s->pb, 1, 0); /* unrestricted motion vector: off */ | |
| 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); /* not PB frame */ | |
| 114 put_bits(&s->pb, 5, s->qscale); | |
| 115 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ | |
| 116 } else { | |
| 117 /* H.263v2 */ | |
| 118 /* H.263 Plus PTYPE */ | |
| 119 put_bits(&s->pb, 3, 7); | |
| 120 put_bits(&s->pb,3,1); /* Update Full Extended PTYPE */ | |
| 78 | 121 if (format == 7) |
| 122 put_bits(&s->pb,3,6); /* Custom Source Format */ | |
| 123 else | |
| 124 put_bits(&s->pb, 3, format); | |
| 125 | |
| 0 | 126 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
|
127 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
|
128 put_bits(&s->pb, 1, s->umvplus); /* Unrestricted Motion Vector */ |
| 0 | 129 put_bits(&s->pb,1,0); /* SAC: off */ |
| 130 put_bits(&s->pb,1,0); /* Advanced Prediction Mode: off */ | |
| 131 put_bits(&s->pb,1,0); /* Advanced Intra Coding: off */ | |
| 132 put_bits(&s->pb,1,0); /* Deblocking Filter: off */ | |
| 133 put_bits(&s->pb,1,0); /* Slice Structured: off */ | |
| 134 put_bits(&s->pb,1,0); /* Reference Picture Selection: off */ | |
| 135 put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */ | |
| 136 put_bits(&s->pb,1,0); /* Alternative Inter VLC: off */ | |
| 137 put_bits(&s->pb,1,0); /* Modified Quantization: off */ | |
| 138 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
| 139 put_bits(&s->pb,3,0); /* Reserved */ | |
| 140 | |
| 141 put_bits(&s->pb, 3, s->pict_type == P_TYPE); | |
| 142 | |
| 143 put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */ | |
| 144 put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */ | |
| 145 put_bits(&s->pb,1,0); /* Rounding Type */ | |
| 146 put_bits(&s->pb,2,0); /* Reserved */ | |
| 147 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
| 148 | |
| 149 /* This should be here if PLUSPTYPE */ | |
| 150 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ | |
| 151 | |
| 78 | 152 if (format == 7) { |
| 153 /* Custom Picture Format (CPFMT) */ | |
| 0 | 154 |
| 78 | 155 put_bits(&s->pb,4,2); /* Aspect ratio: CIF 12:11 (4:3) picture */ |
| 156 put_bits(&s->pb,9,(s->width >> 2) - 1); | |
| 157 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
| 158 put_bits(&s->pb,9,(s->height >> 2)); | |
| 159 } | |
| 160 | |
| 0 | 161 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
162 if (s->umvplus) |
| 0 | 163 put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ |
| 164 put_bits(&s->pb, 5, s->qscale); | |
| 165 } | |
| 166 | |
| 167 put_bits(&s->pb, 1, 0); /* no PEI */ | |
| 168 } | |
| 169 | |
| 162 | 170 int h263_encode_gob_header(MpegEncContext * s, int mb_line) |
| 171 { | |
| 172 int pdif=0; | |
| 173 | |
| 174 /* Check to see if we need to put a new GBSC */ | |
| 175 /* for RTP packetization */ | |
| 176 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
|
177 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
| 162 | 178 if (pdif >= s->rtp_payload_size) { |
| 179 /* Bad luck, packet must be cut before */ | |
| 180 align_put_bits(&s->pb); | |
| 231 | 181 flush_put_bits(&s->pb); |
| 182 /* Call the RTP callback to send the last GOB */ | |
| 183 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
|
184 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
| 231 | 185 s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); |
| 186 } | |
|
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
|
187 s->ptr_lastgob = pbBufPtr(&s->pb); |
| 162 | 188 put_bits(&s->pb, 17, 1); /* GBSC */ |
| 231 | 189 s->gob_number = mb_line / s->gob_index; |
| 162 | 190 put_bits(&s->pb, 5, s->gob_number); /* GN */ |
| 231 | 191 put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */ |
| 162 | 192 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ |
| 231 | 193 //fprintf(stderr,"\nGOB: %2d size: %d", s->gob_number - 1, pdif); |
| 162 | 194 return pdif; |
| 195 } else if (pdif + s->mb_line_avgsize >= s->rtp_payload_size) { | |
| 196 /* Cut the packet before we can't */ | |
| 197 align_put_bits(&s->pb); | |
| 231 | 198 flush_put_bits(&s->pb); |
| 199 /* Call the RTP callback to send the last GOB */ | |
| 200 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
|
201 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
| 231 | 202 s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); |
| 203 } | |
|
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
231
diff
changeset
|
204 s->ptr_lastgob = pbBufPtr(&s->pb); |
| 162 | 205 put_bits(&s->pb, 17, 1); /* GBSC */ |
| 231 | 206 s->gob_number = mb_line / s->gob_index; |
| 162 | 207 put_bits(&s->pb, 5, s->gob_number); /* GN */ |
| 231 | 208 put_bits(&s->pb, 2, s->pict_type == I_TYPE); /* GFID */ |
| 162 | 209 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ |
| 231 | 210 //fprintf(stderr,"\nGOB: %2d size: %d", s->gob_number - 1, pdif); |
| 162 | 211 return pdif; |
| 212 } | |
| 213 } | |
| 214 return 0; | |
| 215 } | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
216 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
217 static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], int dir[6]) |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
218 { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
219 int score0=0, score1=0; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
220 int i, n; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
221 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
222 for(n=0; n<6; n++){ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
223 INT16 *ac_val, *ac_val1; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
224 |
| 266 | 225 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
226 ac_val1= ac_val; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
227 if(dir[n]){ |
| 266 | 228 ac_val-= s->block_wrap[n]*16; |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
229 for(i=1; i<8; i++){ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
230 const int level= block[n][block_permute_op(i )]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
231 score0+= ABS(level); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
232 score1+= ABS(level - ac_val[i+8]); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
233 ac_val1[i ]= block[n][block_permute_op(i<<3)]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
234 ac_val1[i+8]= level; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
235 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
236 }else{ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
237 ac_val-= 16; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
238 for(i=1; i<8; i++){ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
239 const int level= block[n][block_permute_op(i<<3)]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
240 score0+= ABS(level); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
241 score1+= ABS(level - ac_val[i]); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
242 ac_val1[i ]= level; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
243 ac_val1[i+8]= block[n][block_permute_op(i )]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
244 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
245 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
246 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
247 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
248 return score0 > score1 ? 1 : 0; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
249 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
250 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
251 void mpeg4_encode_mb(MpegEncContext * s, |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
252 DCTELEM block[6][64], |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
253 int motion_x, int motion_y) |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
254 { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
255 int cbpc, cbpy, i, cbp, pred_x, pred_y; |
| 286 | 256 int bits; |
| 162 | 257 |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
258 // printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
259 if (!s->mb_intra) { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
260 /* compute cbp */ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
261 cbp = 0; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
262 for (i = 0; i < 6; i++) { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
263 if (s->block_last_index[i] >= 0) |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
264 cbp |= 1 << (5 - i); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
265 } |
| 295 | 266 if ((cbp | motion_x | motion_y) == 0 && s->mv_type==MV_TYPE_16X16) { |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
267 /* skip macroblock */ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
268 put_bits(&s->pb, 1, 1); |
| 286 | 269 s->misc_bits++; |
| 270 s->last_bits++; | |
| 271 s->skip_count++; | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
272 return; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
273 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
274 put_bits(&s->pb, 1, 0); /* mb coded */ |
| 295 | 275 if(s->mv_type==MV_TYPE_16X16){ |
| 276 cbpc = cbp & 3; | |
| 277 put_bits(&s->pb, | |
| 278 inter_MCBPC_bits[cbpc], | |
| 279 inter_MCBPC_code[cbpc]); | |
| 280 cbpy = cbp >> 2; | |
| 281 cbpy ^= 0xf; | |
| 282 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | |
| 283 | |
| 284 bits= get_bit_count(&s->pb); | |
| 285 s->misc_bits+= bits - s->last_bits; | |
| 286 s->last_bits=bits; | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
287 |
| 295 | 288 /* motion vectors: 16x16 mode */ |
| 289 h263_pred_motion(s, 0, &pred_x, &pred_y); | |
| 290 | |
| 291 h263_encode_motion(s, motion_x - pred_x); | |
| 292 h263_encode_motion(s, motion_y - pred_y); | |
| 293 }else{ | |
| 294 cbpc = (cbp & 3)+16; | |
| 295 put_bits(&s->pb, | |
| 296 inter_MCBPC_bits[cbpc], | |
| 297 inter_MCBPC_code[cbpc]); | |
| 298 cbpy = cbp >> 2; | |
| 299 cbpy ^= 0xf; | |
| 300 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
301 |
| 295 | 302 bits= get_bit_count(&s->pb); |
| 303 s->misc_bits+= bits - s->last_bits; | |
| 304 s->last_bits=bits; | |
| 305 | |
| 306 for(i=0; i<4; i++){ | |
| 307 /* motion vectors: 8x8 mode*/ | |
| 308 h263_pred_motion(s, i, &pred_x, &pred_y); | |
| 309 | |
| 310 h263_encode_motion(s, s->motion_val[ s->block_index[i] ][0] - pred_x); | |
| 311 h263_encode_motion(s, s->motion_val[ s->block_index[i] ][1] - pred_y); | |
| 312 } | |
| 313 } | |
| 286 | 314 bits= get_bit_count(&s->pb); |
| 315 s->mv_bits+= bits - s->last_bits; | |
| 316 s->last_bits=bits; | |
| 317 | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
318 /* encode each block */ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
319 for (i = 0; i < 6; i++) { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
320 mpeg4_encode_block(s, block[i], i, 0, zigzag_direct); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
321 } |
| 286 | 322 bits= get_bit_count(&s->pb); |
| 323 s->p_tex_bits+= bits - s->last_bits; | |
| 324 s->last_bits=bits; | |
| 325 s->p_count++; | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
326 } else { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
327 int dc_diff[6]; //dc values with the dc prediction subtracted |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
328 int dir[6]; //prediction direction |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
329 int zigzag_last_index[6]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
330 UINT8 *scan_table[6]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
331 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
332 for(i=0; i<6; i++){ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
333 const int level= block[i][0]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
334 UINT16 *dc_ptr; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
335 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
336 dc_diff[i]= level - mpeg4_pred_dc(s, i, &dc_ptr, &dir[i]); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
337 if (i < 4) { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
338 *dc_ptr = level * s->y_dc_scale; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
339 } else { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
340 *dc_ptr = level * s->c_dc_scale; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
341 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
342 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
343 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
344 s->ac_pred= decide_ac_pred(s, block, dir); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
345 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
346 if(s->ac_pred){ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
347 for(i=0; i<6; i++){ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
348 UINT8 *st; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
349 int last_index; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
350 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
351 mpeg4_inv_pred_ac(s, block[i], i, dir[i]); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
352 if (dir[i]==0) st = ff_alternate_vertical_scan; /* left */ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
353 else st = ff_alternate_horizontal_scan; /* top */ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
354 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
355 for(last_index=63; last_index>=0; last_index--) //FIXME optimize |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
356 if(block[i][st[last_index]]) break; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
357 zigzag_last_index[i]= s->block_last_index[i]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
358 s->block_last_index[i]= last_index; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
359 scan_table[i]= st; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
360 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
361 }else{ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
362 for(i=0; i<6; i++) |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
363 scan_table[i]= zigzag_direct; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
364 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
365 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
366 /* compute cbp */ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
367 cbp = 0; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
368 for (i = 0; i < 6; i++) { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
369 if (s->block_last_index[i] >= 1) |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
370 cbp |= 1 << (5 - i); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
371 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
372 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
373 cbpc = cbp & 3; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
374 if (s->pict_type == I_TYPE) { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
375 put_bits(&s->pb, |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
376 intra_MCBPC_bits[cbpc], |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
377 intra_MCBPC_code[cbpc]); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
378 } else { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
379 put_bits(&s->pb, 1, 0); /* mb coded */ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
380 put_bits(&s->pb, |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
381 inter_MCBPC_bits[cbpc + 4], |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
382 inter_MCBPC_code[cbpc + 4]); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
383 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
384 put_bits(&s->pb, 1, s->ac_pred); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
385 cbpy = cbp >> 2; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
386 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
387 |
| 286 | 388 bits= get_bit_count(&s->pb); |
| 389 s->misc_bits+= bits - s->last_bits; | |
| 390 s->last_bits=bits; | |
| 391 | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
392 /* encode each block */ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
393 for (i = 0; i < 6; i++) { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
394 mpeg4_encode_block(s, block[i], i, dc_diff[i], scan_table[i]); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
395 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
396 |
| 286 | 397 bits= get_bit_count(&s->pb); |
| 398 s->i_tex_bits+= bits - s->last_bits; | |
| 399 s->last_bits=bits; | |
| 400 s->i_count++; | |
| 401 | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
402 /* restore ac coeffs & last_index stuff if we messed them up with the prediction */ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
403 if(s->ac_pred){ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
404 for(i=0; i<6; i++){ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
405 int j; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
406 INT16 *ac_val; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
407 |
| 266 | 408 ac_val = s->ac_val[0][0] + s->block_index[i] * 16; |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
409 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
410 if(dir[i]){ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
411 for(j=1; j<8; j++) |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
412 block[i][block_permute_op(j )]= ac_val[j+8]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
413 }else{ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
414 for(j=1; j<8; j++) |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
415 block[i][block_permute_op(j<<3)]= ac_val[j ]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
416 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
417 s->block_last_index[i]= zigzag_last_index[i]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
418 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
419 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
420 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
421 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
422 |
| 0 | 423 void h263_encode_mb(MpegEncContext * s, |
| 424 DCTELEM block[6][64], | |
| 425 int motion_x, int motion_y) | |
| 426 { | |
| 427 int cbpc, cbpy, i, cbp, pred_x, pred_y; | |
| 162 | 428 |
| 0 | 429 // printf("**mb x=%d y=%d\n", s->mb_x, s->mb_y); |
| 78 | 430 if (!s->mb_intra) { |
| 431 /* compute cbp */ | |
| 432 cbp = 0; | |
| 433 for (i = 0; i < 6; i++) { | |
| 434 if (s->block_last_index[i] >= 0) | |
| 435 cbp |= 1 << (5 - i); | |
| 436 } | |
| 437 if ((cbp | motion_x | motion_y) == 0) { | |
| 438 /* skip macroblock */ | |
| 439 put_bits(&s->pb, 1, 1); | |
| 440 return; | |
| 441 } | |
| 442 put_bits(&s->pb, 1, 0); /* mb coded */ | |
| 443 cbpc = cbp & 3; | |
| 444 put_bits(&s->pb, | |
| 445 inter_MCBPC_bits[cbpc], | |
| 446 inter_MCBPC_code[cbpc]); | |
| 447 cbpy = cbp >> 2; | |
| 448 cbpy ^= 0xf; | |
| 449 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | |
| 0 | 450 |
| 78 | 451 /* motion vectors: 16x16 mode only now */ |
| 452 h263_pred_motion(s, 0, &pred_x, &pred_y); | |
| 453 | |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
454 if (!s->umvplus) { |
| 78 | 455 h263_encode_motion(s, motion_x - pred_x); |
| 456 h263_encode_motion(s, motion_y - pred_y); | |
| 457 } | |
| 458 else { | |
| 459 h263p_encode_umotion(s, motion_x - pred_x); | |
| 460 h263p_encode_umotion(s, motion_y - pred_y); | |
| 461 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) | |
| 462 /* To prevent Start Code emulation */ | |
| 463 put_bits(&s->pb,1,1); | |
| 464 } | |
| 465 } else { | |
| 0 | 466 /* compute cbp */ |
| 467 cbp = 0; | |
| 468 for (i = 0; i < 6; i++) { | |
| 469 if (s->block_last_index[i] >= 1) | |
| 470 cbp |= 1 << (5 - i); | |
| 471 } | |
| 472 | |
| 473 cbpc = cbp & 3; | |
| 474 if (s->pict_type == I_TYPE) { | |
| 475 put_bits(&s->pb, | |
| 476 intra_MCBPC_bits[cbpc], | |
| 477 intra_MCBPC_code[cbpc]); | |
| 478 } else { | |
| 479 put_bits(&s->pb, 1, 0); /* mb coded */ | |
| 480 put_bits(&s->pb, | |
| 481 inter_MCBPC_bits[cbpc + 4], | |
| 482 inter_MCBPC_code[cbpc + 4]); | |
| 483 } | |
| 484 if (s->h263_pred) { | |
| 485 /* XXX: currently, we do not try to use ac prediction */ | |
| 486 put_bits(&s->pb, 1, 0); /* no ac prediction */ | |
| 487 } | |
| 488 cbpy = cbp >> 2; | |
| 489 put_bits(&s->pb, cbpy_tab[cbpy][1], cbpy_tab[cbpy][0]); | |
| 490 } | |
| 491 | |
| 492 /* encode each block */ | |
| 294 | 493 for (i = 0; i < 6; i++) { |
| 494 h263_encode_block(s, block[i], i); | |
| 0 | 495 } |
| 496 } | |
| 497 | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
498 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
|
499 { |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
500 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
|
501 INT16 *dc_val, *ac_val, *ac_val1; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
502 |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
503 /* find prediction */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
504 if (n < 4) { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
505 x = 2 * s->mb_x + 1 + (n & 1); |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
506 y = 2 * s->mb_y + 1 + ((n & 2) >> 1); |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
507 wrap = s->mb_width * 2 + 2; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
508 dc_val = s->dc_val[0]; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
509 ac_val = s->ac_val[0][0]; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
510 scale = s->y_dc_scale; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
511 } else { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
512 x = s->mb_x + 1; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
513 y = s->mb_y + 1; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
514 wrap = s->mb_width + 2; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
515 dc_val = s->dc_val[n - 4 + 1]; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
516 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
|
517 scale = s->c_dc_scale; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
518 } |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
519 |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
520 ac_val += ((y) * wrap + (x)) * 16; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
521 ac_val1 = ac_val; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
522 |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
523 /* B C |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
524 * A X |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
525 */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
526 a = dc_val[(x - 1) + (y) * wrap]; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
527 c = dc_val[(x) + (y - 1) * wrap]; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
528 |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
529 pred_dc = 1024; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
530 if (s->ac_pred) { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
531 if (s->h263_aic_dir) { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
532 /* left prediction */ |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
533 if (a != 1024) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
534 ac_val -= 16; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
535 for(i=1;i<8;i++) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
536 block[block_permute_op(i*8)] += ac_val[i]; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
537 } |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
538 pred_dc = a; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
539 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
540 } else { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
541 /* top prediction */ |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
542 if (c != 1024) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
543 ac_val -= 16 * wrap; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
544 for(i=1;i<8;i++) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
545 block[block_permute_op(i)] += ac_val[i + 8]; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
546 } |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
547 pred_dc = c; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
548 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
549 } |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
550 } else { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
551 /* just DC prediction */ |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
552 if (a != 1024 && c != 1024) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
553 pred_dc = (a + c) >> 1; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
554 else if (a != 1024) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
555 pred_dc = a; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
556 else |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
557 pred_dc = c; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
558 } |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
559 |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
560 /* we assume pred is positive */ |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
561 block[0]=block[0]*scale + pred_dc; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
562 |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
563 if (block[0] < 0) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
564 block[0] = 0; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
565 else if (!(block[0] & 1)) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
566 block[0]++; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
567 |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
568 /* Update AC/DC tables */ |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
569 dc_val[(x) + (y) * wrap] = block[0]; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
570 |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
571 /* left copy */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
572 for(i=1;i<8;i++) |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
573 ac_val1[i] = block[block_permute_op(i * 8)]; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
574 /* top copy */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
575 for(i=1;i<8;i++) |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
576 ac_val1[8 + i] = block[block_permute_op(i)]; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
577 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
578 |
| 0 | 579 INT16 *h263_pred_motion(MpegEncContext * s, int block, |
| 580 int *px, int *py) | |
| 581 { | |
| 266 | 582 int xy, wrap; |
| 0 | 583 INT16 *A, *B, *C, *mot_val; |
|
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
584 static const int off[4]= {2, 1, 1, -1}; |
| 0 | 585 |
| 266 | 586 wrap = s->block_wrap[0]; |
| 587 xy = s->block_index[block]; | |
| 0 | 588 |
| 245 | 589 mot_val = s->motion_val[xy]; |
| 0 | 590 |
| 591 /* special case for first line */ | |
| 272 | 592 if ((s->mb_y == 0 || s->first_slice_line || s->first_gob_line) && block<2) { |
| 245 | 593 A = s->motion_val[xy - 1]; |
| 0 | 594 *px = A[0]; |
| 595 *py = A[1]; | |
| 596 } else { | |
|
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
597 A = s->motion_val[xy - 1]; |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
598 B = s->motion_val[xy - wrap]; |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
599 C = s->motion_val[xy + off[block] - wrap]; |
| 0 | 600 *px = mid_pred(A[0], B[0], C[0]); |
| 601 *py = mid_pred(A[1], B[1], C[1]); | |
| 602 } | |
| 603 return mot_val; | |
| 604 } | |
| 605 | |
| 606 static void h263_encode_motion(MpegEncContext * s, int val) | |
| 607 { | |
| 608 int range, l, m, bit_size, sign, code, bits; | |
| 609 | |
| 610 if (val == 0) { | |
| 611 /* zero vector */ | |
| 612 code = 0; | |
| 613 put_bits(&s->pb, mvtab[code][1], mvtab[code][0]); | |
| 614 } else { | |
| 615 bit_size = s->f_code - 1; | |
| 616 range = 1 << bit_size; | |
| 617 /* modulo encoding */ | |
| 618 l = range * 32; | |
| 619 m = 2 * l; | |
| 620 if (val < -l) { | |
| 621 val += m; | |
| 622 } else if (val >= l) { | |
| 623 val -= m; | |
| 624 } | |
| 625 | |
| 626 if (val >= 0) { | |
| 627 val--; | |
| 628 code = (val >> bit_size) + 1; | |
| 629 bits = val & (range - 1); | |
| 630 sign = 0; | |
| 631 } else { | |
| 632 val = -val; | |
| 633 val--; | |
| 634 code = (val >> bit_size) + 1; | |
| 635 bits = val & (range - 1); | |
| 636 sign = 1; | |
| 637 } | |
| 638 | |
| 639 put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); | |
| 640 if (bit_size > 0) { | |
| 641 put_bits(&s->pb, bit_size, bits); | |
| 642 } | |
| 643 } | |
| 644 } | |
| 645 | |
| 78 | 646 /* Encode MV differences on H.263+ with Unrestricted MV mode */ |
| 647 static void h263p_encode_umotion(MpegEncContext * s, int val) | |
| 648 { | |
| 649 short sval = 0; | |
| 650 short i = 0; | |
| 651 short n_bits = 0; | |
| 652 short temp_val; | |
| 653 int code = 0; | |
| 654 int tcode; | |
| 655 | |
| 656 if ( val == 0) | |
| 657 put_bits(&s->pb, 1, 1); | |
| 658 else if (val == 1) | |
| 659 put_bits(&s->pb, 3, 0); | |
| 660 else if (val == -1) | |
| 661 put_bits(&s->pb, 3, 2); | |
| 662 else { | |
| 663 | |
| 664 sval = ((val < 0) ? (short)(-val):(short)val); | |
| 665 temp_val = sval; | |
| 666 | |
| 667 while (temp_val != 0) { | |
| 668 temp_val = temp_val >> 1; | |
| 669 n_bits++; | |
| 670 } | |
| 671 | |
| 672 i = n_bits - 1; | |
| 673 while (i > 0) { | |
| 674 tcode = (sval & (1 << (i-1))) >> (i-1); | |
| 675 tcode = (tcode << 1) | 1; | |
| 676 code = (code << 2) | tcode; | |
| 677 i--; | |
| 678 } | |
| 679 code = ((code << 1) | (val < 0)) << 1; | |
| 680 put_bits(&s->pb, (2*n_bits)+1, code); | |
| 681 //printf("\nVal = %d\tCode = %d", sval, code); | |
| 682 } | |
| 683 } | |
| 684 | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
685 static void init_mv_penalty_and_fcode(MpegEncContext *s) |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
686 { |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
687 int f_code; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
688 int mv; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
689 for(f_code=1; f_code<=MAX_FCODE; f_code++){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
690 for(mv=-MAX_MV; mv<=MAX_MV; mv++){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
691 int len; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
692 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
693 if(mv==0) len= mvtab[0][1]; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
694 else{ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
695 int val, bit_size, range, code; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
696 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
697 bit_size = s->f_code - 1; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
698 range = 1 << bit_size; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
699 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
700 val=mv; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
701 if (val < 0) |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
702 val = -val; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
703 val--; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
704 code = (val >> bit_size) + 1; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
705 if(code<33){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
706 len= mvtab[code][1] + 1 + bit_size; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
707 }else{ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
708 len= mvtab[32][1] + 2 + bit_size; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
709 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
710 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
711 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
712 mv_penalty[f_code][mv+MAX_MV]= len; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
713 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
714 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
715 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
716 for(f_code=MAX_FCODE; f_code>0; f_code--){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
717 for(mv=-(16<<f_code); mv<(16<<f_code); mv++){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
718 fcode_tab[mv+MAX_MV]= f_code; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
719 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
720 } |
| 287 | 721 |
| 722 for(mv=0; mv<MAX_MV*2+1; mv++){ | |
| 723 umv_fcode_tab[mv]= 1; | |
| 724 } | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
725 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
726 |
| 293 | 727 static void init_uni_dc_tab() |
| 728 { | |
| 729 int level, uni_code, uni_len; | |
| 730 | |
| 731 for(level=-255; level<256; level++){ | |
| 732 int size, v, l; | |
| 733 /* find number of bits */ | |
| 734 size = 0; | |
| 735 v = abs(level); | |
| 736 while (v) { | |
| 737 v >>= 1; | |
| 738 size++; | |
| 739 } | |
| 740 | |
| 741 if (level < 0) | |
| 742 l= (-level) ^ ((1 << size) - 1); | |
| 743 else | |
| 744 l= level; | |
| 745 | |
| 746 /* luminance */ | |
| 747 uni_code= DCtab_lum[size][0]; | |
| 748 uni_len = DCtab_lum[size][1]; | |
| 749 | |
| 750 if (size > 0) { | |
| 751 uni_code<<=size; uni_code|=l; | |
| 752 uni_len+=size; | |
| 753 if (size > 8){ | |
| 754 uni_code<<=1; uni_code|=1; | |
| 755 uni_len++; | |
| 756 } | |
| 757 } | |
| 758 uni_DCtab_lum[level+256][0]= uni_code; | |
| 759 uni_DCtab_lum[level+256][1]= uni_len; | |
| 760 | |
| 761 /* chrominance */ | |
| 762 uni_code= DCtab_chrom[size][0]; | |
| 763 uni_len = DCtab_chrom[size][1]; | |
| 764 | |
| 765 if (size > 0) { | |
| 766 uni_code<<=size; uni_code|=l; | |
| 767 uni_len+=size; | |
| 768 if (size > 8){ | |
| 769 uni_code<<=1; uni_code|=1; | |
| 770 uni_len++; | |
| 771 } | |
| 772 } | |
| 773 uni_DCtab_chrom[level+256][0]= uni_code; | |
| 774 uni_DCtab_chrom[level+256][1]= uni_len; | |
| 775 | |
| 776 } | |
| 777 } | |
| 778 | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
779 void h263_encode_init(MpegEncContext *s) |
| 0 | 780 { |
| 781 static int done = 0; | |
| 782 | |
| 783 if (!done) { | |
| 784 done = 1; | |
| 293 | 785 |
| 786 init_uni_dc_tab(); | |
| 787 | |
| 0 | 788 init_rl(&rl_inter); |
| 789 init_rl(&rl_intra); | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
790 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
791 init_mv_penalty_and_fcode(s); |
| 0 | 792 } |
| 287 | 793 s->mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
794 |
| 287 | 795 // use fcodes >1 only for mpeg4 & h263 & h263p FIXME |
| 294 | 796 if(s->h263_plus) s->fcode_tab= umv_fcode_tab; |
| 797 else if(s->h263_pred && !s->h263_msmpeg4) s->fcode_tab= fcode_tab; | |
| 0 | 798 } |
| 799 | |
| 800 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n) | |
| 801 { | |
| 802 int level, run, last, i, j, last_index, last_non_zero, sign, slevel; | |
| 803 int code; | |
| 804 RLTable *rl = &rl_inter; | |
| 805 | |
| 806 if (s->mb_intra) { | |
| 231 | 807 /* DC coef */ |
| 808 level = block[0]; | |
| 0 | 809 /* 255 cannot be represented, so we clamp */ |
| 810 if (level > 254) { | |
| 811 level = 254; | |
| 812 block[0] = 254; | |
| 813 } | |
| 231 | 814 /* 0 cannot be represented also */ |
| 815 else if (!level) { | |
| 816 level = 1; | |
| 817 block[0] = 1; | |
| 818 } | |
| 819 if (level == 128) | |
| 820 put_bits(&s->pb, 8, 0xff); | |
| 821 else | |
| 822 put_bits(&s->pb, 8, level & 0xff); | |
| 823 i = 1; | |
| 0 | 824 } else { |
| 231 | 825 i = 0; |
| 0 | 826 } |
| 827 | |
| 828 /* AC coefs */ | |
| 829 last_index = s->block_last_index[n]; | |
| 830 last_non_zero = i - 1; | |
| 831 for (; i <= last_index; i++) { | |
| 832 j = zigzag_direct[i]; | |
| 833 level = block[j]; | |
| 834 if (level) { | |
| 835 run = i - last_non_zero - 1; | |
| 836 last = (i == last_index); | |
| 837 sign = 0; | |
| 838 slevel = level; | |
| 839 if (level < 0) { | |
| 840 sign = 1; | |
| 841 level = -level; | |
| 842 } | |
| 843 code = get_rl_index(rl, last, run, level); | |
| 844 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
| 845 if (code == rl->n) { | |
| 846 put_bits(&s->pb, 1, last); | |
| 847 put_bits(&s->pb, 6, run); | |
| 848 put_bits(&s->pb, 8, slevel & 0xff); | |
| 849 } else { | |
| 850 put_bits(&s->pb, 1, sign); | |
| 851 } | |
| 852 last_non_zero = i; | |
| 853 } | |
| 854 } | |
| 855 } | |
| 856 | |
| 857 /***************************************************/ | |
| 858 | |
| 262 | 859 static void mpeg4_stuffing(PutBitContext * pbc) |
| 860 { | |
| 861 int length; | |
| 862 put_bits(pbc, 1, 0); | |
| 863 length= (-get_bit_count(pbc))&7; | |
| 864 put_bits(pbc, length, (1<<length)-1); | |
| 865 } | |
| 866 | |
| 867 static void put_string(PutBitContext * pbc, char *s) | |
| 868 { | |
| 869 while(*s){ | |
| 870 put_bits(pbc, 8, *s); | |
| 871 s++; | |
| 872 } | |
| 873 put_bits(pbc, 8, 0); | |
| 874 } | |
| 875 | |
| 263 | 876 static void mpeg4_encode_vol_header(MpegEncContext * s) |
| 0 | 877 { |
| 263 | 878 int vo_ver_id=1; //must be 2 if we want GMC or q-pel |
| 879 | |
| 880 if(get_bit_count(&s->pb)!=0) mpeg4_stuffing(&s->pb); | |
| 881 put_bits(&s->pb, 16, 0); | |
| 882 put_bits(&s->pb, 16, 0x100); /* video obj */ | |
| 883 put_bits(&s->pb, 16, 0); | |
| 884 put_bits(&s->pb, 16, 0x120); /* video obj layer */ | |
| 885 | |
| 886 put_bits(&s->pb, 1, 0); /* random access vol */ | |
| 887 put_bits(&s->pb, 8, 1); /* video obj type indication= simple obj */ | |
| 888 put_bits(&s->pb, 1, 1); /* is obj layer id= yes */ | |
| 889 put_bits(&s->pb, 4, vo_ver_id); /* is obj layer ver id */ | |
| 890 put_bits(&s->pb, 3, 1); /* is obj layer priority */ | |
|
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
891 if(s->aspect_ratio_info) |
|
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
892 put_bits(&s->pb, 4, s->aspect_ratio_info);/* aspect ratio info */ |
|
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
893 else |
|
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
894 put_bits(&s->pb, 4, 1); /* aspect ratio info= sqare pixel */ |
| 263 | 895 put_bits(&s->pb, 1, 0); /* vol control parameters= no */ |
| 896 put_bits(&s->pb, 2, RECT_SHAPE); /* vol shape= rectangle */ | |
| 897 put_bits(&s->pb, 1, 1); /* marker bit */ | |
| 898 put_bits(&s->pb, 16, s->time_increment_resolution=30000); | |
| 899 s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1; | |
| 900 if (s->time_increment_bits < 1) | |
| 901 s->time_increment_bits = 1; | |
| 902 put_bits(&s->pb, 1, 1); /* marker bit */ | |
| 903 put_bits(&s->pb, 1, 0); /* fixed vop rate=no */ | |
| 904 put_bits(&s->pb, 1, 1); /* marker bit */ | |
| 905 put_bits(&s->pb, 13, s->width); /* vol width */ | |
| 906 put_bits(&s->pb, 1, 1); /* marker bit */ | |
| 907 put_bits(&s->pb, 13, s->height); /* vol height */ | |
| 908 put_bits(&s->pb, 1, 1); /* marker bit */ | |
| 909 put_bits(&s->pb, 1, 0); /* interlace */ | |
| 910 put_bits(&s->pb, 1, 1); /* obmc disable */ | |
| 911 if (vo_ver_id == 1) { | |
| 912 put_bits(&s->pb, 1, s->vol_sprite_usage=0); /* sprite enable */ | |
| 913 }else{ /* vo_ver_id == 2 */ | |
| 914 put_bits(&s->pb, 2, s->vol_sprite_usage=0); /* sprite enable */ | |
| 915 } | |
| 916 put_bits(&s->pb, 1, 0); /* not 8 bit */ | |
| 917 put_bits(&s->pb, 1, 0); /* quant type= h263 style*/ | |
| 918 if (vo_ver_id != 1) | |
| 919 put_bits(&s->pb, 1, s->quarter_sample=0); | |
| 920 put_bits(&s->pb, 1, 1); /* complexity estimation disable */ | |
| 921 put_bits(&s->pb, 1, 1); /* resync marker disable */ | |
| 922 put_bits(&s->pb, 1, 0); /* data partitioned */ | |
| 923 if (vo_ver_id != 1){ | |
| 924 put_bits(&s->pb, 1, 0); /* newpred */ | |
| 925 put_bits(&s->pb, 1, 0); /* reduced res vop */ | |
| 926 } | |
| 927 put_bits(&s->pb, 1, 0); /* scalability */ | |
| 928 | |
| 262 | 929 mpeg4_stuffing(&s->pb); |
| 930 put_bits(&s->pb, 16, 0); | |
| 931 put_bits(&s->pb, 16, 0x1B2); /* user_data */ | |
| 932 put_string(&s->pb, "ffmpeg"); //FIXME append some version ... | |
|
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
933 |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
934 s->no_rounding = 0; |
| 263 | 935 } |
| 936 | |
| 937 /* write mpeg4 VOP header */ | |
| 938 void mpeg4_encode_picture_header(MpegEncContext * s, int picture_number) | |
| 939 { | |
| 940 if(s->pict_type==I_TYPE) mpeg4_encode_vol_header(s); | |
| 941 | |
| 942 if(get_bit_count(&s->pb)!=0) mpeg4_stuffing(&s->pb); | |
|
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
|
943 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
|
944 put_bits(&s->pb, 16, 0x1B6); /* vop header */ |
| 0 | 945 put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */ |
| 946 /* XXX: time base + 1 not always correct */ | |
| 947 put_bits(&s->pb, 1, 1); | |
| 948 put_bits(&s->pb, 1, 0); | |
| 949 | |
| 950 put_bits(&s->pb, 1, 1); /* marker */ | |
| 263 | 951 put_bits(&s->pb, s->time_increment_bits, 1); /* XXX: correct time increment */ |
| 0 | 952 put_bits(&s->pb, 1, 1); /* marker */ |
| 953 put_bits(&s->pb, 1, 1); /* vop coded */ | |
| 263 | 954 if ( s->pict_type == P_TYPE |
| 955 || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) { | |
| 956 s->no_rounding ^= 1; | |
| 0 | 957 put_bits(&s->pb, 1, s->no_rounding); /* rounding type */ |
| 958 } | |
| 959 put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */ | |
| 263 | 960 //FIXME sprite stuff |
| 0 | 961 |
| 962 put_bits(&s->pb, 5, s->qscale); | |
| 963 | |
| 964 if (s->pict_type != I_TYPE) | |
| 965 put_bits(&s->pb, 3, s->f_code); /* fcode_for */ | |
| 263 | 966 if (s->pict_type == B_TYPE) |
| 967 put_bits(&s->pb, 3, s->b_code); /* fcode_back */ | |
| 0 | 968 // printf("****frame %d\n", picture_number); |
| 969 } | |
| 970 | |
| 971 void h263_dc_scale(MpegEncContext * s) | |
| 972 { | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
973 #if 1 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
974 const static UINT8 y_tab[32]={ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
975 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
976 0, 8, 8, 8, 8,10,12,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,34,36,38,40,42,44,46 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
977 }; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
978 const static UINT8 c_tab[32]={ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
979 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
980 0, 8, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,20,21,22,23,24,25 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
981 }; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
982 s->y_dc_scale = y_tab[s->qscale]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
983 s->c_dc_scale = c_tab[s->qscale]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
984 #else |
| 0 | 985 int quant; |
| 986 quant = s->qscale; | |
| 987 /* luminance */ | |
| 988 if (quant < 5) | |
| 989 s->y_dc_scale = 8; | |
| 990 else if (quant > 4 && quant < 9) | |
| 991 s->y_dc_scale = (2 * quant); | |
| 992 else if (quant > 8 && quant < 25) | |
| 993 s->y_dc_scale = (quant + 8); | |
| 994 else | |
| 995 s->y_dc_scale = (2 * quant - 16); | |
| 996 /* chrominance */ | |
| 997 if (quant < 5) | |
| 998 s->c_dc_scale = 8; | |
| 999 else if (quant > 4 && quant < 25) | |
| 1000 s->c_dc_scale = ((quant + 13) / 2); | |
| 1001 else | |
| 1002 s->c_dc_scale = (quant - 6); | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1003 #endif |
| 0 | 1004 } |
| 1005 | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1006 static inline int mpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr) |
| 0 | 1007 { |
| 266 | 1008 int a, b, c, wrap, pred, scale; |
| 0 | 1009 UINT16 *dc_val; |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1010 int dummy; |
| 0 | 1011 |
| 1012 /* find prediction */ | |
| 1013 if (n < 4) { | |
| 1014 scale = s->y_dc_scale; | |
| 1015 } else { | |
| 1016 scale = s->c_dc_scale; | |
| 1017 } | |
| 266 | 1018 wrap= s->block_wrap[n]; |
| 1019 dc_val = s->dc_val[0] + s->block_index[n]; | |
| 0 | 1020 |
| 1021 /* B C | |
| 1022 * A X | |
| 1023 */ | |
| 266 | 1024 a = dc_val[ - 1]; |
| 1025 b = dc_val[ - 1 - wrap]; | |
| 1026 c = dc_val[ - wrap]; | |
| 0 | 1027 |
| 1028 if (abs(a - b) < abs(b - c)) { | |
| 1029 pred = c; | |
| 1030 *dir_ptr = 1; /* top */ | |
| 1031 } else { | |
| 1032 pred = a; | |
| 1033 *dir_ptr = 0; /* left */ | |
| 1034 } | |
| 1035 /* we assume pred is positive */ | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1036 #ifdef ARCH_X86 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1037 asm volatile ( |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1038 "xorl %%edx, %%edx \n\t" |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1039 "mul %%ecx \n\t" |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1040 : "=d" (pred), "=a"(dummy) |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1041 : "a" (pred + (scale >> 1)), "c" (inverse[scale]) |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1042 ); |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1043 #else |
| 0 | 1044 pred = (pred + (scale >> 1)) / scale; |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1045 #endif |
| 0 | 1046 |
| 1047 /* prepare address for prediction update */ | |
| 266 | 1048 *dc_val_ptr = &dc_val[0]; |
| 0 | 1049 |
| 1050 return pred; | |
| 1051 } | |
| 1052 | |
|
174
ac5075a55488
new IDCT code by Michael Niedermayer (michaelni@gmx.at) - #define SIMPLE_IDCT to enable
arpi_esp
parents:
162
diff
changeset
|
1053 void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n, |
| 0 | 1054 int dir) |
| 1055 { | |
| 266 | 1056 int i; |
| 0 | 1057 INT16 *ac_val, *ac_val1; |
| 1058 | |
| 1059 /* find prediction */ | |
| 266 | 1060 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
| 0 | 1061 ac_val1 = ac_val; |
| 1062 if (s->ac_pred) { | |
| 1063 if (dir == 0) { | |
| 1064 /* left prediction */ | |
| 1065 ac_val -= 16; | |
| 1066 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
|
1067 block[block_permute_op(i*8)] += ac_val[i]; |
| 0 | 1068 } |
| 1069 } else { | |
| 1070 /* top prediction */ | |
| 266 | 1071 ac_val -= 16 * s->block_wrap[n]; |
| 0 | 1072 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
|
1073 block[block_permute_op(i)] += ac_val[i + 8]; |
| 0 | 1074 } |
| 1075 } | |
| 1076 } | |
| 1077 /* left copy */ | |
| 1078 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
|
1079 ac_val1[i] = block[block_permute_op(i * 8)]; |
| 0 | 1080 /* top copy */ |
| 1081 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
|
1082 ac_val1[8 + i] = block[block_permute_op(i)]; |
| 0 | 1083 } |
| 1084 | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1085 static void mpeg4_inv_pred_ac(MpegEncContext * s, INT16 *block, int n, |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1086 int dir) |
| 0 | 1087 { |
| 266 | 1088 int i; |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1089 INT16 *ac_val; |
| 0 | 1090 |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1091 /* find prediction */ |
| 266 | 1092 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1093 |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1094 if (dir == 0) { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1095 /* left prediction */ |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1096 ac_val -= 16; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1097 for(i=1;i<8;i++) { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1098 block[block_permute_op(i*8)] -= ac_val[i]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1099 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1100 } else { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1101 /* top prediction */ |
| 266 | 1102 ac_val -= 16 * s->block_wrap[n]; |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1103 for(i=1;i<8;i++) { |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1104 block[block_permute_op(i)] -= ac_val[i + 8]; |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1105 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1106 } |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1107 } |
| 0 | 1108 |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1109 static inline void mpeg4_encode_dc(MpegEncContext * s, int level, int n) |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1110 { |
| 293 | 1111 #if 1 |
| 1112 level+=256; | |
| 1113 if (n < 4) { | |
| 1114 /* luminance */ | |
| 1115 put_bits(&s->pb, uni_DCtab_lum[level][1], uni_DCtab_lum[level][0]); | |
| 1116 } else { | |
| 1117 /* chrominance */ | |
| 1118 put_bits(&s->pb, uni_DCtab_chrom[level][1], uni_DCtab_chrom[level][0]); | |
| 1119 } | |
| 1120 #else | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1121 int size, v; |
| 0 | 1122 /* find number of bits */ |
| 1123 size = 0; | |
| 1124 v = abs(level); | |
| 1125 while (v) { | |
| 1126 v >>= 1; | |
| 1127 size++; | |
| 1128 } | |
| 1129 | |
| 1130 if (n < 4) { | |
| 1131 /* luminance */ | |
| 1132 put_bits(&s->pb, DCtab_lum[size][1], DCtab_lum[size][0]); | |
| 1133 } else { | |
| 1134 /* chrominance */ | |
| 1135 put_bits(&s->pb, DCtab_chrom[size][1], DCtab_chrom[size][0]); | |
| 1136 } | |
| 1137 | |
| 1138 /* encode remaining bits */ | |
| 1139 if (size > 0) { | |
| 1140 if (level < 0) | |
| 1141 level = (-level) ^ ((1 << size) - 1); | |
| 1142 put_bits(&s->pb, size, level); | |
| 1143 if (size > 8) | |
| 1144 put_bits(&s->pb, 1, 1); | |
| 1145 } | |
| 293 | 1146 #endif |
| 0 | 1147 } |
| 1148 | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1149 static void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, UINT8 *scan_table) |
| 0 | 1150 { |
| 1151 int level, run, last, i, j, last_index, last_non_zero, sign, slevel; | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1152 int code; |
| 0 | 1153 const RLTable *rl; |
| 1154 | |
| 1155 if (s->mb_intra) { | |
| 1156 /* mpeg4 based DC predictor */ | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1157 mpeg4_encode_dc(s, intra_dc, n); |
| 0 | 1158 i = 1; |
| 1159 rl = &rl_intra; | |
| 1160 } else { | |
| 1161 i = 0; | |
| 1162 rl = &rl_inter; | |
| 1163 } | |
| 1164 | |
| 1165 /* AC coefs */ | |
| 1166 last_index = s->block_last_index[n]; | |
| 1167 last_non_zero = i - 1; | |
| 1168 for (; i <= last_index; i++) { | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1169 j = scan_table[i]; |
| 0 | 1170 level = block[j]; |
| 1171 if (level) { | |
| 1172 run = i - last_non_zero - 1; | |
| 1173 last = (i == last_index); | |
| 1174 sign = 0; | |
| 1175 slevel = level; | |
| 1176 if (level < 0) { | |
| 1177 sign = 1; | |
| 1178 level = -level; | |
| 1179 } | |
| 1180 code = get_rl_index(rl, last, run, level); | |
| 1181 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
| 1182 if (code == rl->n) { | |
| 1183 int level1, run1; | |
| 1184 level1 = level - rl->max_level[last][run]; | |
| 1185 if (level1 < 1) | |
| 1186 goto esc2; | |
| 1187 code = get_rl_index(rl, last, run, level1); | |
| 1188 if (code == rl->n) { | |
| 1189 esc2: | |
| 1190 put_bits(&s->pb, 1, 1); | |
| 1191 if (level > MAX_LEVEL) | |
| 1192 goto esc3; | |
| 1193 run1 = run - rl->max_run[last][level] - 1; | |
| 1194 if (run1 < 0) | |
| 1195 goto esc3; | |
| 1196 code = get_rl_index(rl, last, run1, level); | |
| 1197 if (code == rl->n) { | |
| 1198 esc3: | |
| 1199 /* third escape */ | |
| 1200 put_bits(&s->pb, 1, 1); | |
| 1201 put_bits(&s->pb, 1, last); | |
| 1202 put_bits(&s->pb, 6, run); | |
| 1203 put_bits(&s->pb, 1, 1); | |
| 1204 put_bits(&s->pb, 12, slevel & 0xfff); | |
| 1205 put_bits(&s->pb, 1, 1); | |
| 1206 } else { | |
| 1207 /* second escape */ | |
| 1208 put_bits(&s->pb, 1, 0); | |
| 1209 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
| 1210 put_bits(&s->pb, 1, sign); | |
| 1211 } | |
| 1212 } else { | |
| 1213 /* first escape */ | |
| 1214 put_bits(&s->pb, 1, 0); | |
| 1215 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); | |
| 1216 put_bits(&s->pb, 1, sign); | |
| 1217 } | |
| 1218 } else { | |
| 1219 put_bits(&s->pb, 1, sign); | |
| 1220 } | |
| 1221 last_non_zero = i; | |
| 1222 } | |
| 1223 } | |
| 1224 } | |
| 1225 | |
| 1226 | |
| 1227 | |
| 1228 /***********************************************/ | |
| 1229 /* decoding */ | |
| 1230 | |
| 1231 static VLC intra_MCBPC_vlc; | |
| 1232 static VLC inter_MCBPC_vlc; | |
| 1233 static VLC cbpy_vlc; | |
| 1234 static VLC mv_vlc; | |
| 1235 static VLC dc_lum, dc_chrom; | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1236 static VLC sprite_trajectory; |
| 262 | 1237 static VLC mb_type_b_vlc; |
| 0 | 1238 |
| 1239 void init_rl(RLTable *rl) | |
| 1240 { | |
| 1241 INT8 max_level[MAX_RUN+1], max_run[MAX_LEVEL+1]; | |
| 1242 UINT8 index_run[MAX_RUN+1]; | |
| 1243 int last, run, level, start, end, i; | |
| 1244 | |
| 1245 /* compute max_level[], max_run[] and index_run[] */ | |
| 1246 for(last=0;last<2;last++) { | |
| 1247 if (last == 0) { | |
| 1248 start = 0; | |
| 1249 end = rl->last; | |
| 1250 } else { | |
| 1251 start = rl->last; | |
| 1252 end = rl->n; | |
| 1253 } | |
| 1254 | |
| 1255 memset(max_level, 0, MAX_RUN + 1); | |
| 1256 memset(max_run, 0, MAX_LEVEL + 1); | |
| 1257 memset(index_run, rl->n, MAX_RUN + 1); | |
| 1258 for(i=start;i<end;i++) { | |
| 1259 run = rl->table_run[i]; | |
| 1260 level = rl->table_level[i]; | |
| 1261 if (index_run[run] == rl->n) | |
| 1262 index_run[run] = i; | |
| 1263 if (level > max_level[run]) | |
| 1264 max_level[run] = level; | |
| 1265 if (run > max_run[level]) | |
| 1266 max_run[level] = run; | |
| 1267 } | |
| 1268 rl->max_level[last] = malloc(MAX_RUN + 1); | |
| 1269 memcpy(rl->max_level[last], max_level, MAX_RUN + 1); | |
| 1270 rl->max_run[last] = malloc(MAX_LEVEL + 1); | |
| 1271 memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1); | |
| 1272 rl->index_run[last] = malloc(MAX_RUN + 1); | |
| 1273 memcpy(rl->index_run[last], index_run, MAX_RUN + 1); | |
| 1274 } | |
| 1275 } | |
| 1276 | |
| 1277 void init_vlc_rl(RLTable *rl) | |
| 1278 { | |
| 1279 init_vlc(&rl->vlc, 9, rl->n + 1, | |
| 1280 &rl->table_vlc[0][1], 4, 2, | |
| 1281 &rl->table_vlc[0][0], 4, 2); | |
| 1282 } | |
| 1283 | |
| 1284 /* init vlcs */ | |
| 1285 | |
| 1286 /* XXX: find a better solution to handle static init */ | |
| 1287 void h263_decode_init_vlc(MpegEncContext *s) | |
| 1288 { | |
| 1289 static int done = 0; | |
| 1290 | |
| 1291 if (!done) { | |
| 1292 done = 1; | |
| 1293 | |
| 1294 init_vlc(&intra_MCBPC_vlc, 6, 8, | |
| 1295 intra_MCBPC_bits, 1, 1, | |
| 1296 intra_MCBPC_code, 1, 1); | |
| 161 | 1297 init_vlc(&inter_MCBPC_vlc, 9, 25, |
| 0 | 1298 inter_MCBPC_bits, 1, 1, |
| 1299 inter_MCBPC_code, 1, 1); | |
| 1300 init_vlc(&cbpy_vlc, 6, 16, | |
| 1301 &cbpy_tab[0][1], 2, 1, | |
| 1302 &cbpy_tab[0][0], 2, 1); | |
| 1303 init_vlc(&mv_vlc, 9, 33, | |
| 1304 &mvtab[0][1], 2, 1, | |
| 1305 &mvtab[0][0], 2, 1); | |
| 1306 init_rl(&rl_inter); | |
| 1307 init_rl(&rl_intra); | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1308 init_rl(&rl_intra_aic); |
| 0 | 1309 init_vlc_rl(&rl_inter); |
| 1310 init_vlc_rl(&rl_intra); | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1311 init_vlc_rl(&rl_intra_aic); |
| 0 | 1312 init_vlc(&dc_lum, 9, 13, |
| 1313 &DCtab_lum[0][1], 2, 1, | |
| 1314 &DCtab_lum[0][0], 2, 1); | |
| 1315 init_vlc(&dc_chrom, 9, 13, | |
| 1316 &DCtab_chrom[0][1], 2, 1, | |
| 1317 &DCtab_chrom[0][0], 2, 1); | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1318 init_vlc(&sprite_trajectory, 9, 15, |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1319 &sprite_trajectory_tab[0][1], 4, 2, |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1320 &sprite_trajectory_tab[0][0], 4, 2); |
| 262 | 1321 init_vlc(&mb_type_b_vlc, 4, 4, |
| 1322 &mb_type_b_tab[0][1], 2, 1, | |
| 1323 &mb_type_b_tab[0][0], 2, 1); | |
| 0 | 1324 } |
| 1325 } | |
| 1326 | |
| 162 | 1327 int h263_decode_gob_header(MpegEncContext *s) |
| 1328 { | |
| 1329 unsigned int val, gfid; | |
| 1330 | |
| 1331 /* Check for GOB Start Code */ | |
| 1332 val = show_bits(&s->gb, 16); | |
| 1333 if (val == 0) { | |
| 1334 /* We have a GBSC probably with GSTUFF */ | |
| 1335 skip_bits(&s->gb, 16); /* Drop the zeros */ | |
| 1336 while (get_bits1(&s->gb) == 0); /* Seek the '1' bit */ | |
| 1337 #ifdef DEBUG | |
| 1338 fprintf(stderr,"\nGOB Start Code at MB %d\n", (s->mb_y * s->mb_width) + s->mb_x); | |
| 1339 #endif | |
| 1340 s->gob_number = get_bits(&s->gb, 5); /* GN */ | |
| 1341 gfid = get_bits(&s->gb, 2); /* GFID */ | |
| 1342 s->qscale = get_bits(&s->gb, 5); /* GQUANT */ | |
| 1343 #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
|
1344 fprintf(stderr, "\nGN: %u GFID: %u Quant: %u\n", s->gob_number, gfid, s->qscale); |
| 162 | 1345 #endif |
| 1346 return 1; | |
| 1347 } | |
| 1348 return 0; | |
| 1349 | |
| 1350 } | |
| 1351 | |
| 290 | 1352 static inline void memsetw(short *tab, int val, int n) |
| 1353 { | |
| 1354 int i; | |
| 1355 for(i=0;i<n;i++) | |
| 1356 tab[i] = val; | |
| 1357 } | |
| 1358 | |
| 1359 static int mpeg4_resync(MpegEncContext *s) | |
| 1360 { | |
| 1361 int state, v, bits; | |
| 1362 int mb_num_bits= av_log2(s->mb_num - 1) + 1; | |
| 1363 int header_extension=0, mb_num; | |
| 1364 int c_wrap, c_xy, l_wrap, l_xy; | |
| 1365 //printf("resync at %d %d\n", s->mb_x, s->mb_y); | |
| 1366 //printf("%X\n", show_bits(&s->gb, 24)); | |
| 1367 | |
| 1368 if( get_bits_count(&s->gb) > s->gb.size*8-32) | |
| 1369 return 0; | |
| 1370 | |
| 1371 align_get_bits(&s->gb); | |
| 1372 state = 0xff; | |
| 1373 for(;;) { | |
| 1374 v = get_bits(&s->gb, 8); | |
| 1375 //printf("%X ", v); | |
| 1376 state = ((state << 8) | v) & 0xffff; | |
| 1377 if (state == 0) break; | |
| 1378 if( get_bits_count(&s->gb) > s->gb.size*8-32){ | |
| 1379 printf("resync failed\n"); | |
| 1380 return -1; | |
| 1381 } | |
| 1382 } | |
| 1383 //printf("%X\n", show_bits(&s->gb, 24)); | |
| 1384 bits=0; | |
| 1385 while(!get_bits1(&s->gb) && bits<30) bits++; | |
| 1386 if(s->pict_type == P_TYPE && bits != s->f_code-1) | |
| 1387 printf("marker does not match f_code\n"); | |
| 1388 //FIXME check bits for B-framess | |
| 1389 //printf("%X\n", show_bits(&s->gb, 24)); | |
| 1390 | |
| 1391 if(s->shape != RECT_SHAPE){ | |
| 1392 header_extension= get_bits1(&s->gb); | |
| 1393 //FIXME more stuff here | |
| 1394 } | |
| 1395 | |
| 1396 mb_num= get_bits(&s->gb, mb_num_bits); | |
| 1397 if(mb_num != s->mb_x + s->mb_y*s->mb_width){ | |
| 1398 printf("MB-num change not supported %d %d\n", mb_num, s->mb_x + s->mb_y*s->mb_width); | |
| 1399 // s->mb_x= mb_num % s->mb_width; | |
| 1400 // s->mb_y= mb_num / s->mb_width; | |
| 1401 //FIXME many vars are wrong now | |
| 1402 } | |
| 1403 | |
| 1404 if(s->shape != BIN_ONLY_SHAPE){ | |
| 1405 s->qscale= get_bits(&s->gb, 5); | |
| 1406 h263_dc_scale(s); | |
| 1407 } | |
| 1408 | |
| 1409 if(s->shape == RECT_SHAPE){ | |
| 1410 header_extension= get_bits1(&s->gb); | |
| 1411 } | |
| 1412 if(header_extension){ | |
| 1413 int time_incr=0; | |
| 1414 printf("header extension not really supported\n"); | |
| 1415 while (get_bits1(&s->gb) != 0) | |
| 1416 time_incr++; | |
| 1417 | |
| 1418 check_marker(&s->gb, "before time_increment in video packed header"); | |
| 1419 s->time_increment= get_bits(&s->gb, s->time_increment_bits); | |
| 1420 if(s->pict_type!=B_TYPE){ | |
| 1421 s->time_base+= time_incr; | |
| 1422 s->last_non_b_time[1]= s->last_non_b_time[0]; | |
| 1423 s->last_non_b_time[0]= s->time_base*s->time_increment_resolution + s->time_increment; | |
| 1424 }else{ | |
| 1425 s->time= (s->last_non_b_time[1]/s->time_increment_resolution + time_incr)*s->time_increment_resolution; | |
| 1426 s->time+= s->time_increment; | |
| 1427 } | |
| 1428 check_marker(&s->gb, "before vop_coding_type in video packed header"); | |
| 1429 | |
| 1430 skip_bits(&s->gb, 2); /* vop coding type */ | |
| 1431 //FIXME not rect stuff here | |
| 1432 | |
| 1433 if(s->shape != BIN_ONLY_SHAPE){ | |
| 1434 skip_bits(&s->gb, 3); /* intra dc vlc threshold */ | |
| 1435 | |
| 1436 if(s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE && s->num_sprite_warping_points){ | |
| 1437 mpeg4_decode_sprite_trajectory(s); | |
| 1438 } | |
| 1439 | |
| 1440 //FIXME reduced res stuff here | |
| 1441 | |
| 1442 if (s->pict_type != I_TYPE) { | |
| 1443 s->f_code = get_bits(&s->gb, 3); /* fcode_for */ | |
| 1444 if(s->f_code==0){ | |
| 1445 printf("Error, video packet header damaged or not MPEG4 header (f_code=0)\n"); | |
| 1446 return -1; // makes no sense to continue, as the MV decoding will break very quickly | |
| 1447 } | |
| 1448 } | |
| 1449 if (s->pict_type == B_TYPE) { | |
| 1450 s->b_code = get_bits(&s->gb, 3); | |
| 1451 } | |
| 1452 } | |
| 1453 | |
| 1454 } | |
| 1455 //FIXME new-pred stuff | |
| 1456 | |
| 1457 l_wrap= s->block_wrap[0]; | |
| 1458 l_xy= s->mb_y*l_wrap*2; | |
| 1459 c_wrap= s->block_wrap[4]; | |
| 1460 c_xy= s->mb_y*c_wrap; | |
| 1461 | |
| 1462 /* clean DC */ | |
| 1463 memsetw(s->dc_val[0] + l_xy, 1024, l_wrap*3); | |
| 1464 memsetw(s->dc_val[1] + c_xy, 1024, c_wrap*2); | |
| 1465 memsetw(s->dc_val[2] + c_xy, 1024, c_wrap*2); | |
| 1466 | |
| 1467 /* clean AC */ | |
| 1468 memset(s->ac_val[0] + l_xy, 0, l_wrap*3*16*sizeof(INT16)); | |
| 1469 memset(s->ac_val[1] + c_xy, 0, c_wrap*2*16*sizeof(INT16)); | |
| 1470 memset(s->ac_val[2] + c_xy, 0, c_wrap*2*16*sizeof(INT16)); | |
| 1471 | |
| 1472 /* clean MV */ | |
| 1473 memset(s->motion_val + l_xy, 0, l_wrap*3*2*sizeof(INT16)); | |
| 1474 // memset(s->motion_val, 0, 2*sizeof(INT16)*(2 + s->mb_width*2)*(2 + s->mb_height*2)); | |
| 1475 s->resync_x_pos= s->mb_x; | |
| 1476 s->first_slice_line=1; | |
| 1477 | |
| 1478 return 0; | |
| 1479 } | |
| 1480 | |
| 0 | 1481 int h263_decode_mb(MpegEncContext *s, |
| 1482 DCTELEM block[6][64]) | |
| 1483 { | |
| 1484 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; | |
| 1485 INT16 *mot_val; | |
| 110 | 1486 static INT8 quant_tab[4] = { -1, -2, 1, 2 }; |
|
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
1487 |
| 290 | 1488 if(s->resync_marker){ |
| 1489 if( s->resync_x_pos == s->mb_x+1 | |
| 1490 || s->resync_x_pos == s->mb_x){ | |
| 1491 /* f*ck mpeg4 | |
| 1492 this is here so we dont need to slowdown h263_pred_motion with it */ | |
| 1493 if(s->resync_x_pos == s->mb_x+1 && s->mb_x==0){ | |
| 1494 int xy= s->block_index[0] - s->block_wrap[0]; | |
| 1495 s->motion_val[xy][0]= s->motion_val[xy+2][0]; | |
| 1496 s->motion_val[xy][1]= s->motion_val[xy+2][1]; | |
| 1497 } | |
| 1498 | |
| 1499 s->first_slice_line=0; | |
| 1500 s->resync_x_pos=0; // isnt needed but for cleanness sake ;) | |
| 1501 } | |
| 1502 | |
| 1503 if(show_aligned_bits(&s->gb, 1, 16) == 0){ | |
| 1504 if( mpeg4_resync(s) < 0 ) return -1; | |
| 1505 | |
| 1506 } | |
| 1507 } | |
| 1508 | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1509 if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) { |
| 21 | 1510 if (get_bits1(&s->gb)) { |
| 0 | 1511 /* skip mb */ |
| 1512 s->mb_intra = 0; | |
| 1513 for(i=0;i<6;i++) | |
| 1514 s->block_last_index[i] = -1; | |
| 1515 s->mv_dir = MV_DIR_FORWARD; | |
| 1516 s->mv_type = MV_TYPE_16X16; | |
| 255 | 1517 if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ |
| 1518 const int a= s->sprite_warping_accuracy; | |
| 1519 // int l = (1 << (s->f_code - 1)) * 32; | |
| 1520 | |
| 1521 s->mcsel=1; | |
| 301 | 1522 if(s->divx_version==500 && s->divx_build==413){ |
| 1523 s->mv[0][0][0] = s->sprite_offset[0][0] / (1<<(a-s->quarter_sample)); | |
| 1524 s->mv[0][0][1] = s->sprite_offset[0][1] / (1<<(a-s->quarter_sample)); | |
| 1525 }else{ | |
| 1526 s->mv[0][0][0] = RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); | |
| 1527 s->mv[0][0][1] = RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); | |
| 1528 } | |
| 255 | 1529 /* if (s->mv[0][0][0] < -l) s->mv[0][0][0]= -l; |
| 1530 else if (s->mv[0][0][0] >= l) s->mv[0][0][0]= l-1; | |
| 1531 if (s->mv[0][0][1] < -l) s->mv[0][0][1]= -l; | |
| 1532 else if (s->mv[0][0][1] >= l) s->mv[0][0][1]= l-1;*/ | |
| 1533 | |
| 1534 s->mb_skiped = 0; | |
| 1535 }else{ | |
| 1536 s->mcsel=0; | |
| 1537 s->mv[0][0][0] = 0; | |
| 1538 s->mv[0][0][1] = 0; | |
| 1539 s->mb_skiped = 1; | |
| 1540 } | |
| 0 | 1541 return 0; |
| 1542 } | |
| 1543 cbpc = get_vlc(&s->gb, &inter_MCBPC_vlc); | |
| 144 | 1544 //fprintf(stderr, "\tCBPC: %d", cbpc); |
| 0 | 1545 if (cbpc < 0) |
| 1546 return -1; | |
| 161 | 1547 if (cbpc > 20) |
| 1548 cbpc+=3; | |
| 1549 else if (cbpc == 20) | |
| 1550 fprintf(stderr, "Stuffing !"); | |
| 144 | 1551 |
| 0 | 1552 dquant = cbpc & 8; |
| 1553 s->mb_intra = ((cbpc & 4) != 0); | |
| 262 | 1554 if (s->mb_intra) goto intra; |
| 1555 | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1556 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
|
1557 s->mcsel= get_bits1(&s->gb); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
1558 else s->mcsel= 0; |
| 0 | 1559 cbpy = get_vlc(&s->gb, &cbpy_vlc); |
| 1560 cbp = (cbpc & 3) | ((cbpy ^ 0xf) << 2); | |
| 1561 if (dquant) { | |
| 1562 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
| 1563 if (s->qscale < 1) | |
| 1564 s->qscale = 1; | |
| 1565 else if (s->qscale > 31) | |
| 1566 s->qscale = 31; | |
| 290 | 1567 h263_dc_scale(s); |
| 0 | 1568 } |
| 1569 s->mv_dir = MV_DIR_FORWARD; | |
| 1570 if ((cbpc & 16) == 0) { | |
| 1571 /* 16x16 motion prediction */ | |
| 1572 s->mv_type = MV_TYPE_16X16; | |
| 1573 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
|
1574 if (s->umvplus_dec) |
| 78 | 1575 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
|
1576 else if(!s->mcsel) |
| 262 | 1577 mx = h263_decode_motion(s, pred_x, s->f_code); |
| 255 | 1578 else { |
| 1579 const int a= s->sprite_warping_accuracy; | |
| 1580 // int l = (1 << (s->f_code - 1)) * 32; | |
| 301 | 1581 if(s->divx_version==500 && s->divx_build==413){ |
| 1582 mx = s->sprite_offset[0][0] / (1<<(a-s->quarter_sample)); | |
| 1583 }else{ | |
| 1584 mx = RSHIFT(s->sprite_offset[0][0], a-s->quarter_sample); | |
| 1585 } | |
| 1586 // if (mx < -l) mx= -l, printf("C"); | |
| 1587 // else if (mx >= l) mx= l-1, printf("C"); | |
| 255 | 1588 } |
| 0 | 1589 if (mx >= 0xffff) |
| 1590 return -1; | |
| 78 | 1591 |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1592 if (s->umvplus_dec) |
| 78 | 1593 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
|
1594 else if(!s->mcsel) |
| 262 | 1595 my = h263_decode_motion(s, pred_y, s->f_code); |
| 255 | 1596 else{ |
| 1597 const int a= s->sprite_warping_accuracy; | |
| 1598 // int l = (1 << (s->f_code - 1)) * 32; | |
| 301 | 1599 if(s->divx_version==500 && s->divx_build==413){ |
| 1600 my = s->sprite_offset[0][1] / (1<<(a-s->quarter_sample)); | |
| 1601 }else{ | |
| 1602 my = RSHIFT(s->sprite_offset[0][1], a-s->quarter_sample); | |
| 1603 } | |
| 1604 // if (my < -l) my= -l, printf("C"); | |
| 1605 // else if (my >= l) my= l-1, printf("C"); | |
| 255 | 1606 } |
| 0 | 1607 if (my >= 0xffff) |
| 1608 return -1; | |
| 1609 s->mv[0][0][0] = mx; | |
| 1610 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
|
1611 /*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
|
1612 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
|
1613 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
|
1614 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) |
| 78 | 1615 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
| 1616 | |
| 0 | 1617 } else { |
| 1618 s->mv_type = MV_TYPE_8X8; | |
| 1619 for(i=0;i<4;i++) { | |
| 1620 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
|
1621 if (s->umvplus_dec) |
| 78 | 1622 mx = h263p_decode_umotion(s, pred_x); |
| 1623 else | |
| 262 | 1624 mx = h263_decode_motion(s, pred_x, s->f_code); |
| 0 | 1625 if (mx >= 0xffff) |
| 1626 return -1; | |
| 78 | 1627 |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1628 if (s->umvplus_dec) |
| 78 | 1629 my = h263p_decode_umotion(s, pred_y); |
| 1630 else | |
| 262 | 1631 my = h263_decode_motion(s, pred_y, s->f_code); |
| 0 | 1632 if (my >= 0xffff) |
| 1633 return -1; | |
| 1634 s->mv[0][i][0] = mx; | |
| 1635 s->mv[0][i][1] = my; | |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1636 if (s->umvplus_dec && (mx - pred_x) == 1 && (my - pred_y) == 1) |
| 78 | 1637 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
| 0 | 1638 mot_val[0] = mx; |
| 1639 mot_val[1] = my; | |
| 1640 } | |
| 1641 } | |
| 262 | 1642 } else if(s->pict_type==B_TYPE) { |
| 1643 int modb1; // first bit of modb | |
| 1644 int modb2; // second bit of modb | |
| 1645 int mb_type; | |
| 1646 int time_pp; | |
| 1647 int time_pb; | |
| 1648 int xy; | |
| 1649 | |
| 1650 s->mb_intra = 0; //B-frames never contain intra blocks | |
| 1651 s->mcsel=0; // ... true gmc blocks | |
| 1652 | |
| 1653 if(s->mb_x==0){ | |
| 1654 s->last_mv[0][0][0]= | |
| 1655 s->last_mv[0][0][1]= | |
| 1656 s->last_mv[1][0][0]= | |
| 1657 s->last_mv[1][0][1]= 0; | |
| 1658 } | |
| 1659 | |
| 1660 /* if we skipped it in the future P Frame than skip it now too */ | |
| 1661 s->mb_skiped= s->mbskip_table[s->mb_y * s->mb_width + s->mb_x]; // Note, skiptab=0 if last was GMC | |
| 1662 | |
| 1663 if(s->mb_skiped){ | |
| 1664 /* skip mb */ | |
| 1665 for(i=0;i<6;i++) | |
| 1666 s->block_last_index[i] = -1; | |
| 1667 | |
| 1668 s->mv_dir = MV_DIR_FORWARD; | |
| 1669 s->mv_type = MV_TYPE_16X16; | |
| 1670 s->mv[0][0][0] = 0; | |
| 1671 s->mv[0][0][1] = 0; | |
| 1672 s->mv[1][0][0] = 0; | |
| 1673 s->mv[1][0][1] = 0; | |
| 291 | 1674 //FIXME is this correct? |
| 1675 /* s->last_mv[0][0][0]= | |
| 1676 s->last_mv[0][0][1]=0;*/ | |
| 262 | 1677 s->mb_skiped = 1; |
| 1678 return 0; | |
| 1679 } | |
| 1680 | |
| 1681 modb1= get_bits1(&s->gb); | |
| 1682 if(modb1==0){ | |
| 1683 modb2= get_bits1(&s->gb); | |
| 1684 mb_type= get_vlc(&s->gb, &mb_type_b_vlc); | |
| 1685 if(modb2==0) cbp= get_bits(&s->gb, 6); | |
| 1686 else cbp=0; | |
| 1687 if (mb_type && cbp) { | |
| 1688 if(get_bits1(&s->gb)){ | |
| 1689 s->qscale +=get_bits1(&s->gb)*4 - 2; | |
| 1690 if (s->qscale < 1) | |
| 1691 s->qscale = 1; | |
| 1692 else if (s->qscale > 31) | |
| 1693 s->qscale = 31; | |
| 290 | 1694 h263_dc_scale(s); |
| 262 | 1695 } |
| 1696 } | |
| 1697 }else{ | |
| 1698 mb_type=4; //like 0 but no vectors coded | |
| 1699 cbp=0; | |
| 1700 } | |
| 1701 s->mv_type = MV_TYPE_16X16; // we'll switch to 8x8 only if the last P frame had 8x8 for this MB and mb_type=0 here | |
| 1702 mx=my=0; //for case 4, we could put this to the mb_type=4 but than gcc compains about uninitalized mx/my | |
| 1703 switch(mb_type) | |
| 1704 { | |
| 1705 case 0: | |
| 1706 mx = h263_decode_motion(s, 0, 1); | |
| 1707 my = h263_decode_motion(s, 0, 1); | |
| 1708 case 4: | |
| 1709 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
| 266 | 1710 xy= s->block_index[0]; |
| 262 | 1711 time_pp= s->last_non_b_time[0] - s->last_non_b_time[1]; |
| 1712 time_pb= s->time - s->last_non_b_time[1]; | |
| 1713 //if(time_pp>3000 )printf("%d %d ", time_pp, time_pb); | |
| 1714 //FIXME 4MV | |
| 1715 //FIXME avoid divides | |
| 1716 s->mv[0][0][0] = s->motion_val[xy][0]*time_pb/time_pp + mx; | |
| 1717 s->mv[0][0][1] = s->motion_val[xy][1]*time_pb/time_pp + my; | |
| 1718 s->mv[1][0][0] = mx ? s->mv[0][0][0] - s->motion_val[xy][0] | |
| 1719 : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp + mx; | |
| 1720 s->mv[1][0][1] = my ? s->mv[0][0][1] - s->motion_val[xy][1] | |
| 1721 : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp + my; | |
| 1722 /* s->mv[0][0][0] = | |
| 1723 s->mv[0][0][1] = | |
| 1724 s->mv[1][0][0] = | |
| 1725 s->mv[1][0][1] = 1000;*/ | |
| 1726 break; | |
| 1727 case 1: | |
| 1728 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
| 1729 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); | |
| 1730 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); | |
| 1731 s->last_mv[0][0][0]= s->mv[0][0][0] = mx; | |
| 1732 s->last_mv[0][0][1]= s->mv[0][0][1] = my; | |
| 1733 | |
| 1734 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); | |
| 1735 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); | |
| 1736 s->last_mv[1][0][0]= s->mv[1][0][0] = mx; | |
| 1737 s->last_mv[1][0][1]= s->mv[1][0][1] = my; | |
| 1738 break; | |
| 1739 case 2: | |
| 1740 s->mv_dir = MV_DIR_BACKWARD; | |
| 1741 mx = h263_decode_motion(s, s->last_mv[1][0][0], s->b_code); | |
| 1742 my = h263_decode_motion(s, s->last_mv[1][0][1], s->b_code); | |
| 1743 s->last_mv[1][0][0]= s->mv[1][0][0] = mx; | |
| 1744 s->last_mv[1][0][1]= s->mv[1][0][1] = my; | |
| 1745 break; | |
| 1746 case 3: | |
| 1747 s->mv_dir = MV_DIR_FORWARD; | |
| 1748 mx = h263_decode_motion(s, s->last_mv[0][0][0], s->f_code); | |
| 1749 my = h263_decode_motion(s, s->last_mv[0][0][1], s->f_code); | |
| 1750 s->last_mv[0][0][0]= s->mv[0][0][0] = mx; | |
| 1751 s->last_mv[0][0][1]= s->mv[0][0][1] = my; | |
| 1752 break; | |
| 1753 default: return -1; | |
| 1754 } | |
| 1755 } else { /* I-Frame */ | |
| 1756 cbpc = get_vlc(&s->gb, &intra_MCBPC_vlc); | |
| 1757 if (cbpc < 0) | |
| 1758 return -1; | |
| 1759 dquant = cbpc & 4; | |
| 1760 s->mb_intra = 1; | |
| 1761 intra: | |
| 0 | 1762 s->ac_pred = 0; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1763 if (s->h263_pred || s->h263_aic) { |
| 21 | 1764 s->ac_pred = get_bits1(&s->gb); |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1765 if (s->ac_pred && s->h263_aic) |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1766 s->h263_aic_dir = get_bits1(&s->gb); |
| 0 | 1767 } |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1768 if (s->h263_aic) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1769 s->y_dc_scale = 2 * s->qscale; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1770 s->c_dc_scale = 2 * s->qscale; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1771 } |
| 0 | 1772 cbpy = get_vlc(&s->gb, &cbpy_vlc); |
| 1773 cbp = (cbpc & 3) | (cbpy << 2); | |
| 1774 if (dquant) { | |
| 1775 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
| 1776 if (s->qscale < 1) | |
| 1777 s->qscale = 1; | |
| 1778 else if (s->qscale > 31) | |
| 1779 s->qscale = 31; | |
| 290 | 1780 h263_dc_scale(s); |
| 0 | 1781 } |
| 1782 } | |
| 1783 | |
| 1784 /* decode each block */ | |
| 1785 if (s->h263_pred) { | |
| 1786 for (i = 0; i < 6; i++) { | |
| 1787 if (mpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) | |
| 1788 return -1; | |
| 1789 } | |
| 1790 } else { | |
| 1791 for (i = 0; i < 6; i++) { | |
| 1792 if (h263_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1) < 0) | |
| 1793 return -1; | |
| 1794 } | |
| 1795 } | |
| 1796 return 0; | |
| 1797 } | |
| 1798 | |
| 262 | 1799 static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) |
| 0 | 1800 { |
| 1801 int code, val, sign, shift, l, m; | |
| 1802 | |
| 1803 code = get_vlc(&s->gb, &mv_vlc); | |
| 1804 if (code < 0) | |
| 1805 return 0xffff; | |
| 1806 | |
| 1807 if (code == 0) | |
| 1808 return pred; | |
| 21 | 1809 sign = get_bits1(&s->gb); |
| 262 | 1810 shift = f_code - 1; |
| 0 | 1811 val = (code - 1) << shift; |
| 1812 if (shift > 0) | |
| 1813 val |= get_bits(&s->gb, shift); | |
| 1814 val++; | |
| 1815 if (sign) | |
| 1816 val = -val; | |
| 1817 val += pred; | |
| 1818 | |
| 1819 /* modulo decoding */ | |
| 1820 if (!s->h263_long_vectors) { | |
| 262 | 1821 l = (1 << (f_code - 1)) * 32; |
| 0 | 1822 m = 2 * l; |
| 1823 if (val < -l) { | |
| 1824 val += m; | |
| 1825 } else if (val >= l) { | |
| 1826 val -= m; | |
| 1827 } | |
| 1828 } else { | |
| 1829 /* horrible h263 long vector mode */ | |
| 1830 if (pred < -31 && val < -63) | |
| 1831 val += 64; | |
| 1832 if (pred > 32 && val > 63) | |
| 1833 val -= 64; | |
|
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
1834 |
| 0 | 1835 } |
| 1836 return val; | |
| 1837 } | |
| 1838 | |
| 78 | 1839 /* Decodes RVLC of H.263+ UMV */ |
| 1840 static int h263p_decode_umotion(MpegEncContext * s, int pred) | |
| 1841 { | |
| 1842 int code = 0, sign; | |
| 1843 | |
| 1844 if (get_bits1(&s->gb)) /* Motion difference = 0 */ | |
| 1845 return pred; | |
| 1846 | |
| 1847 code = 2 + get_bits1(&s->gb); | |
| 1848 | |
| 1849 while (get_bits1(&s->gb)) | |
| 1850 { | |
| 1851 code <<= 1; | |
| 1852 code += get_bits1(&s->gb); | |
| 1853 } | |
| 1854 sign = code & 1; | |
| 1855 code >>= 1; | |
| 1856 | |
| 1857 code = (sign) ? (pred - code) : (pred + code); | |
| 1858 #ifdef DEBUG | |
| 1859 fprintf(stderr,"H.263+ UMV Motion = %d\n", code); | |
| 1860 #endif | |
| 1861 return code; | |
| 1862 | |
| 1863 } | |
| 1864 | |
| 0 | 1865 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
| 1866 int n, int coded) | |
| 1867 { | |
| 1868 int code, level, i, j, last, run; | |
| 1869 RLTable *rl = &rl_inter; | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1870 const UINT8 *scan_table; |
| 0 | 1871 |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1872 scan_table = zigzag_direct; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1873 if (s->h263_aic && s->mb_intra) { |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1874 rl = &rl_intra_aic; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1875 i = 0; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1876 if (s->ac_pred) { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1877 if (s->h263_aic_dir) |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1878 scan_table = ff_alternate_vertical_scan; /* left */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1879 else |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1880 scan_table = ff_alternate_horizontal_scan; /* top */ |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1881 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1882 } else if (s->mb_intra) { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1883 /* DC coef */ |
| 0 | 1884 if (s->h263_rv10 && s->rv10_version == 3 && s->pict_type == I_TYPE) { |
| 1885 int component, diff; | |
| 1886 component = (n <= 3 ? 0 : n - 4 + 1); | |
| 1887 level = s->last_dc[component]; | |
| 1888 if (s->rv10_first_dc_coded[component]) { | |
| 1889 diff = rv_decode_dc(s, n); | |
| 1890 if (diff == 0xffff) | |
| 1891 return -1; | |
| 1892 level += diff; | |
| 1893 level = level & 0xff; /* handle wrap round */ | |
| 1894 s->last_dc[component] = level; | |
| 1895 } else { | |
| 1896 s->rv10_first_dc_coded[component] = 1; | |
| 1897 } | |
| 1898 } else { | |
| 1899 level = get_bits(&s->gb, 8); | |
| 1900 if (level == 255) | |
| 1901 level = 128; | |
| 1902 } | |
| 1903 block[0] = level; | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1904 i = 1; |
| 0 | 1905 } else { |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1906 i = 0; |
| 0 | 1907 } |
| 1908 if (!coded) { | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1909 if (s->mb_intra && s->h263_aic) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1910 goto not_coded; |
| 0 | 1911 s->block_last_index[n] = i - 1; |
| 1912 return 0; | |
| 1913 } | |
| 1914 | |
| 1915 for(;;) { | |
| 1916 code = get_vlc(&s->gb, &rl->vlc); | |
| 1917 if (code < 0) | |
| 1918 return -1; | |
| 1919 if (code == rl->n) { | |
| 1920 /* escape */ | |
| 21 | 1921 last = get_bits1(&s->gb); |
| 0 | 1922 run = get_bits(&s->gb, 6); |
| 1923 level = (INT8)get_bits(&s->gb, 8); | |
| 1924 if (s->h263_rv10 && level == -128) { | |
| 1925 /* XXX: should patch encoder too */ | |
| 1926 level = get_bits(&s->gb, 12); | |
| 1927 level = (level << 20) >> 20; | |
| 1928 } | |
| 1929 } else { | |
| 1930 run = rl->table_run[code]; | |
| 1931 level = rl->table_level[code]; | |
| 1932 last = code >= rl->last; | |
| 21 | 1933 if (get_bits1(&s->gb)) |
| 0 | 1934 level = -level; |
| 1935 } | |
| 1936 i += run; | |
| 1937 if (i >= 64) | |
| 1938 return -1; | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1939 j = scan_table[i]; |
| 0 | 1940 block[j] = level; |
| 1941 if (last) | |
| 1942 break; | |
| 1943 i++; | |
| 1944 } | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1945 not_coded: |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1946 if (s->mb_intra && s->h263_aic) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1947 h263_pred_acdc(s, block, n); |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
1948 i = 63; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
1949 } |
| 0 | 1950 s->block_last_index[n] = i; |
| 1951 return 0; | |
| 1952 } | |
| 1953 | |
| 1954 static int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) | |
| 1955 { | |
| 1956 int level, pred, code; | |
| 1957 UINT16 *dc_val; | |
| 1958 | |
| 1959 if (n < 4) | |
| 1960 code = get_vlc(&s->gb, &dc_lum); | |
| 1961 else | |
| 1962 code = get_vlc(&s->gb, &dc_chrom); | |
| 1963 if (code < 0) | |
| 1964 return -1; | |
| 1965 if (code == 0) { | |
| 1966 level = 0; | |
| 1967 } else { | |
| 1968 level = get_bits(&s->gb, code); | |
| 1969 if ((level >> (code - 1)) == 0) /* if MSB not set it is negative*/ | |
| 1970 level = - (level ^ ((1 << code) - 1)); | |
| 1971 if (code > 8) | |
| 21 | 1972 skip_bits1(&s->gb); /* marker */ |
| 0 | 1973 } |
| 1974 | |
| 1975 pred = mpeg4_pred_dc(s, n, &dc_val, dir_ptr); | |
| 1976 level += pred; | |
| 1977 if (level < 0) | |
| 1978 level = 0; | |
| 1979 if (n < 4) { | |
| 1980 *dc_val = level * s->y_dc_scale; | |
| 1981 } else { | |
| 1982 *dc_val = level * s->c_dc_scale; | |
| 1983 } | |
| 1984 return level; | |
| 1985 } | |
| 1986 | |
| 1987 static int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, | |
| 1988 int n, int coded) | |
| 1989 { | |
| 1990 int code, level, i, j, last, run; | |
| 1991 int dc_pred_dir; | |
| 1992 RLTable *rl; | |
| 1993 const UINT8 *scan_table; | |
| 1994 | |
| 1995 if (s->mb_intra) { | |
| 1996 /* DC coef */ | |
| 1997 level = mpeg4_decode_dc(s, n, &dc_pred_dir); | |
| 1998 if (level < 0) | |
| 1999 return -1; | |
| 2000 block[0] = level; | |
| 2001 i = 1; | |
| 2002 if (!coded) | |
| 2003 goto not_coded; | |
| 2004 rl = &rl_intra; | |
| 2005 if (s->ac_pred) { | |
| 2006 if (dc_pred_dir == 0) | |
| 2007 scan_table = ff_alternate_vertical_scan; /* left */ | |
| 2008 else | |
| 2009 scan_table = ff_alternate_horizontal_scan; /* top */ | |
| 2010 } else { | |
| 2011 scan_table = zigzag_direct; | |
| 2012 } | |
| 2013 } else { | |
| 2014 i = 0; | |
| 2015 if (!coded) { | |
| 2016 s->block_last_index[n] = i - 1; | |
| 2017 return 0; | |
| 2018 } | |
| 2019 rl = &rl_inter; | |
| 2020 scan_table = zigzag_direct; | |
| 2021 } | |
| 2022 | |
| 2023 for(;;) { | |
| 2024 code = get_vlc(&s->gb, &rl->vlc); | |
| 2025 if (code < 0) | |
| 2026 return -1; | |
| 2027 if (code == rl->n) { | |
| 2028 /* escape */ | |
| 21 | 2029 if (get_bits1(&s->gb) != 0) { |
| 2030 if (get_bits1(&s->gb) != 0) { | |
| 0 | 2031 /* third escape */ |
| 21 | 2032 last = get_bits1(&s->gb); |
| 0 | 2033 run = get_bits(&s->gb, 6); |
| 21 | 2034 get_bits1(&s->gb); /* marker */ |
| 0 | 2035 level = get_bits(&s->gb, 12); |
| 2036 level = (level << 20) >> 20; /* sign extend */ | |
| 21 | 2037 skip_bits1(&s->gb); /* marker */ |
| 0 | 2038 } else { |
| 2039 /* second escape */ | |
| 2040 code = get_vlc(&s->gb, &rl->vlc); | |
| 2041 if (code < 0 || code >= rl->n) | |
| 2042 return -1; | |
| 2043 run = rl->table_run[code]; | |
| 2044 level = rl->table_level[code]; | |
| 2045 last = code >= rl->last; | |
| 2046 run += rl->max_run[last][level] + 1; | |
| 21 | 2047 if (get_bits1(&s->gb)) |
| 0 | 2048 level = -level; |
| 2049 } | |
| 2050 } else { | |
| 2051 /* first escape */ | |
| 2052 code = get_vlc(&s->gb, &rl->vlc); | |
| 2053 if (code < 0 || code >= rl->n) | |
| 2054 return -1; | |
| 2055 run = rl->table_run[code]; | |
| 2056 level = rl->table_level[code]; | |
| 2057 last = code >= rl->last; | |
| 2058 level += rl->max_level[last][run]; | |
| 21 | 2059 if (get_bits1(&s->gb)) |
| 0 | 2060 level = -level; |
| 2061 } | |
| 2062 } else { | |
| 2063 run = rl->table_run[code]; | |
| 2064 level = rl->table_level[code]; | |
| 2065 last = code >= rl->last; | |
| 21 | 2066 if (get_bits1(&s->gb)) |
| 0 | 2067 level = -level; |
| 2068 } | |
| 2069 i += run; | |
| 2070 if (i >= 64) | |
| 2071 return -1; | |
| 2072 j = scan_table[i]; | |
| 2073 block[j] = level; | |
| 2074 i++; | |
| 2075 if (last) | |
| 2076 break; | |
| 2077 } | |
| 2078 not_coded: | |
| 2079 if (s->mb_intra) { | |
| 2080 mpeg4_pred_ac(s, block, n, dc_pred_dir); | |
| 2081 if (s->ac_pred) { | |
| 2082 i = 64; /* XXX: not optimal */ | |
| 2083 } | |
| 2084 } | |
| 2085 s->block_last_index[n] = i - 1; | |
| 2086 return 0; | |
| 2087 } | |
| 2088 | |
| 2089 /* most is hardcoded. should extend to handle all h263 streams */ | |
| 2090 int h263_decode_picture_header(MpegEncContext *s) | |
| 2091 { | |
| 2092 int format, width, height; | |
| 2093 | |
| 2094 /* picture header */ | |
| 2095 if (get_bits(&s->gb, 22) != 0x20) | |
| 2096 return -1; | |
| 231 | 2097 s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ |
| 2098 | |
| 21 | 2099 if (get_bits1(&s->gb) != 1) |
| 0 | 2100 return -1; /* marker */ |
| 21 | 2101 if (get_bits1(&s->gb) != 0) |
| 0 | 2102 return -1; /* h263 id */ |
| 21 | 2103 skip_bits1(&s->gb); /* split screen off */ |
| 2104 skip_bits1(&s->gb); /* camera off */ | |
| 2105 skip_bits1(&s->gb); /* freeze picture release off */ | |
| 0 | 2106 |
|
155
3c3449bce692
- Bug fix on MV prediction for MPEG4 caused by new H.263 GOB code.
pulento
parents:
154
diff
changeset
|
2107 /* Reset GOB number */ |
|
154
f914f710b8d0
- Fixed a bug on H.263 MV prediction for MB on GOBs limits.
pulento
parents:
144
diff
changeset
|
2108 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
|
2109 |
| 0 | 2110 format = get_bits(&s->gb, 3); |
| 2111 | |
| 161 | 2112 if (format != 7 && format != 6) { |
| 0 | 2113 s->h263_plus = 0; |
| 2114 /* H.263v1 */ | |
| 2115 width = h263_format[format][0]; | |
| 2116 height = h263_format[format][1]; | |
| 2117 if (!width) | |
| 2118 return -1; | |
| 161 | 2119 |
| 2120 s->width = width; | |
| 2121 s->height = height; | |
| 21 | 2122 s->pict_type = I_TYPE + get_bits1(&s->gb); |
| 0 | 2123 |
| 21 | 2124 s->unrestricted_mv = get_bits1(&s->gb); |
| 0 | 2125 s->h263_long_vectors = s->unrestricted_mv; |
| 2126 | |
| 21 | 2127 if (get_bits1(&s->gb) != 0) |
| 0 | 2128 return -1; /* SAC: off */ |
| 161 | 2129 if (get_bits1(&s->gb) != 0) { |
| 2130 s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */ | |
| 2131 } | |
| 2132 | |
| 21 | 2133 if (get_bits1(&s->gb) != 0) |
| 0 | 2134 return -1; /* not PB frame */ |
| 2135 | |
| 2136 s->qscale = get_bits(&s->gb, 5); | |
| 21 | 2137 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
| 0 | 2138 } else { |
| 161 | 2139 int ufep; |
| 2140 | |
| 0 | 2141 /* H.263v2 */ |
| 161 | 2142 s->h263_plus = 1; |
| 2143 ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */ | |
| 2144 | |
| 2145 if (ufep == 1) { | |
| 2146 /* OPPTYPE */ | |
| 2147 format = get_bits(&s->gb, 3); | |
| 2148 skip_bits(&s->gb,1); /* Custom PCF */ | |
| 2149 s->umvplus_dec = get_bits(&s->gb, 1); /* Unrestricted Motion Vector */ | |
| 2150 skip_bits1(&s->gb); /* Syntax-based Arithmetic Coding (SAC) */ | |
| 2151 if (get_bits1(&s->gb) != 0) { | |
| 2152 s->mv_type = MV_TYPE_8X8; /* Advanced prediction mode */ | |
| 2153 } | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2154 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
|
2155 s->h263_aic = 1; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2156 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
2157 skip_bits(&s->gb, 7); |
| 161 | 2158 skip_bits(&s->gb, 3); /* Reserved */ |
| 2159 } else if (ufep != 0) | |
| 0 | 2160 return -1; |
| 161 | 2161 |
| 78 | 2162 /* MPPTYPE */ |
| 0 | 2163 s->pict_type = get_bits(&s->gb, 3) + 1; |
| 2164 if (s->pict_type != I_TYPE && | |
| 2165 s->pict_type != P_TYPE) | |
| 2166 return -1; | |
|
250
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
2167 skip_bits(&s->gb, 2); |
|
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
2168 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
|
2169 //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
|
2170 skip_bits(&s->gb, 4); |
| 78 | 2171 |
| 2172 /* Get the picture dimensions */ | |
| 161 | 2173 if (ufep) { |
| 2174 if (format == 6) { | |
| 2175 /* Custom Picture Format (CPFMT) */ | |
| 2176 skip_bits(&s->gb, 4); /* aspect ratio */ | |
| 2177 width = (get_bits(&s->gb, 9) + 1) * 4; | |
| 2178 skip_bits1(&s->gb); | |
| 2179 height = get_bits(&s->gb, 9) * 4; | |
| 78 | 2180 #ifdef DEBUG |
| 161 | 2181 fprintf(stderr,"\nH.263+ Custom picture: %dx%d\n",width,height); |
| 78 | 2182 #endif |
| 161 | 2183 } |
| 2184 else { | |
| 2185 width = h263_format[format][0]; | |
| 2186 height = h263_format[format][1]; | |
| 2187 } | |
| 2188 if ((width == 0) || (height == 0)) | |
| 2189 return -1; | |
| 2190 s->width = width; | |
| 2191 s->height = height; | |
| 2192 if (s->umvplus_dec) { | |
| 2193 skip_bits1(&s->gb); /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | |
| 2194 } | |
| 78 | 2195 } |
| 2196 | |
| 0 | 2197 s->qscale = get_bits(&s->gb, 5); |
| 2198 } | |
| 2199 /* PEI */ | |
| 21 | 2200 while (get_bits1(&s->gb) != 0) { |
| 2201 skip_bits(&s->gb, 8); | |
| 0 | 2202 } |
| 2203 s->f_code = 1; | |
| 2204 return 0; | |
| 2205 } | |
| 2206 | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2207 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
|
2208 { |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2209 int i; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2210 int a= 2<<s->sprite_warping_accuracy; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2211 int rho= 3-s->sprite_warping_accuracy; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2212 int r=16/a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2213 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
|
2214 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
|
2215 int sprite_ref[4][2]; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2216 int virtual_ref[2][2]; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2217 int w2, h2; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2218 int alpha=0, beta=0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2219 int w= s->width; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2220 int h= s->height; |
| 255 | 2221 //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
|
2222 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
|
2223 int length; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2224 int x=0, y=0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2225 |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2226 length= get_vlc(&s->gb, &sprite_trajectory); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2227 if(length){ |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2228 x= get_bits(&s->gb, length); |
| 255 | 2229 //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
|
2230 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
|
2231 x = - (x ^ ((1 << length) - 1)); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2232 } |
| 255 | 2233 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
|
2234 |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2235 length= get_vlc(&s->gb, &sprite_trajectory); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2236 if(length){ |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2237 y=get_bits(&s->gb, length); |
| 255 | 2238 //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
|
2239 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
|
2240 y = - (y ^ ((1 << length) - 1)); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2241 } |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2242 skip_bits1(&s->gb); /* marker bit */ |
| 255 | 2243 //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
|
2244 //if(i>0 && (x!=0 || y!=0)) printf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"); |
| 255 | 2245 //x=y=0; |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2246 d[i][0]= x; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2247 d[i][1]= y; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2248 } |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2249 |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2250 while((1<<alpha)<w) alpha++; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2251 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
|
2252 w2= 1<<alpha; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2253 h2= 1<<beta; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2254 |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2255 // Note, the 4th point isnt used for GMC |
| 262 | 2256 if(s->divx_version==500 && s->divx_build==413){ |
| 2257 sprite_ref[0][0]= a*vop_ref[0][0] + d[0][0]; | |
| 2258 sprite_ref[0][1]= a*vop_ref[0][1] + d[0][1]; | |
| 2259 sprite_ref[1][0]= a*vop_ref[1][0] + d[0][0] + d[1][0]; | |
| 2260 sprite_ref[1][1]= a*vop_ref[1][1] + d[0][1] + d[1][1]; | |
| 2261 sprite_ref[2][0]= a*vop_ref[2][0] + d[0][0] + d[2][0]; | |
| 2262 sprite_ref[2][1]= a*vop_ref[2][1] + d[0][1] + d[2][1]; | |
| 2263 } else { | |
| 2264 sprite_ref[0][0]= (a>>1)*(2*vop_ref[0][0] + d[0][0]); | |
| 2265 sprite_ref[0][1]= (a>>1)*(2*vop_ref[0][1] + d[0][1]); | |
| 2266 sprite_ref[1][0]= (a>>1)*(2*vop_ref[1][0] + d[0][0] + d[1][0]); | |
| 2267 sprite_ref[1][1]= (a>>1)*(2*vop_ref[1][1] + d[0][1] + d[1][1]); | |
| 2268 sprite_ref[2][0]= (a>>1)*(2*vop_ref[2][0] + d[0][0] + d[2][0]); | |
| 2269 sprite_ref[2][1]= (a>>1)*(2*vop_ref[2][1] + d[0][1] + d[2][1]); | |
| 2270 } | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2271 /* 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
|
2272 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
|
2273 |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2274 // 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
|
2275 // 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
|
2276 // 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
|
2277 // 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
|
2278 virtual_ref[0][0]= 16*(vop_ref[0][0] + w2) |
| 255 | 2279 + 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
|
2280 virtual_ref[0][1]= 16*vop_ref[0][1] |
| 255 | 2281 + 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
|
2282 virtual_ref[1][0]= 16*vop_ref[0][0] |
| 255 | 2283 + 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
|
2284 virtual_ref[1][1]= 16*(vop_ref[0][1] + h2) |
| 255 | 2285 + 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
|
2286 |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2287 switch(s->num_sprite_warping_points) |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2288 { |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2289 case 0: |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2290 s->sprite_offset[0][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2291 s->sprite_offset[0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2292 s->sprite_offset[1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2293 s->sprite_offset[1][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2294 s->sprite_delta[0][0][0]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2295 s->sprite_delta[0][0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2296 s->sprite_delta[0][1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2297 s->sprite_delta[0][1][1]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2298 s->sprite_delta[1][0][0]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2299 s->sprite_delta[1][0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2300 s->sprite_delta[1][1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2301 s->sprite_delta[1][1][1]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2302 s->sprite_shift[0][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2303 s->sprite_shift[0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2304 s->sprite_shift[1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2305 s->sprite_shift[1][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2306 break; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2307 case 1: //GMC only |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2308 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
|
2309 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
|
2310 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
|
2311 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
|
2312 s->sprite_delta[0][0][0]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2313 s->sprite_delta[0][0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2314 s->sprite_delta[0][1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2315 s->sprite_delta[0][1][1]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2316 s->sprite_delta[1][0][0]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2317 s->sprite_delta[1][0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2318 s->sprite_delta[1][1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2319 s->sprite_delta[1][1][1]= a; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2320 s->sprite_shift[0][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2321 s->sprite_shift[0][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2322 s->sprite_shift[1][0]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2323 s->sprite_shift[1][1]= 0; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2324 break; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2325 case 2: |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2326 case 3: //FIXME |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2327 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
|
2328 + ((-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
|
2329 +( 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
|
2330 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
|
2331 + ((-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
|
2332 +(-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
|
2333 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
|
2334 +( 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
|
2335 +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
|
2336 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
|
2337 +(-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
|
2338 +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
|
2339 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
|
2340 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
|
2341 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
|
2342 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
|
2343 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
|
2344 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
|
2345 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
|
2346 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
|
2347 s->sprite_shift[0][0]= alpha+rho; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2348 s->sprite_shift[0][1]= alpha+rho; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2349 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
|
2350 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
|
2351 break; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2352 // case 3: |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2353 break; |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2354 } |
| 255 | 2355 /*printf("%d %d\n", s->sprite_delta[0][0][0], a<<s->sprite_shift[0][0]); |
| 2356 printf("%d %d\n", s->sprite_delta[0][0][1], 0); | |
| 2357 printf("%d %d\n", s->sprite_delta[0][1][0], 0); | |
| 2358 printf("%d %d\n", s->sprite_delta[0][1][1], a<<s->sprite_shift[0][1]); | |
| 2359 printf("%d %d\n", s->sprite_delta[1][0][0], a<<s->sprite_shift[1][0]); | |
| 2360 printf("%d %d\n", s->sprite_delta[1][0][1], 0); | |
| 2361 printf("%d %d\n", s->sprite_delta[1][1][0], 0); | |
| 2362 printf("%d %d\n", s->sprite_delta[1][1][1], a<<s->sprite_shift[1][1]);*/ | |
| 2363 /* try to simplify the situation */ | |
| 2364 if( s->sprite_delta[0][0][0] == a<<s->sprite_shift[0][0] | |
| 2365 && s->sprite_delta[0][0][1] == 0 | |
| 2366 && s->sprite_delta[0][1][0] == 0 | |
| 2367 && s->sprite_delta[0][1][1] == a<<s->sprite_shift[0][1] | |
| 2368 && s->sprite_delta[1][0][0] == a<<s->sprite_shift[1][0] | |
| 2369 && s->sprite_delta[1][0][1] == 0 | |
| 2370 && s->sprite_delta[1][1][0] == 0 | |
| 2371 && s->sprite_delta[1][1][1] == a<<s->sprite_shift[1][1]) | |
| 2372 { | |
| 2373 s->sprite_offset[0][0]>>=s->sprite_shift[0][0]; | |
| 2374 s->sprite_offset[0][1]>>=s->sprite_shift[0][1]; | |
| 2375 s->sprite_offset[1][0]>>=s->sprite_shift[1][0]; | |
| 2376 s->sprite_offset[1][1]>>=s->sprite_shift[1][1]; | |
| 2377 s->sprite_delta[0][0][0]= a; | |
| 2378 s->sprite_delta[0][0][1]= 0; | |
| 2379 s->sprite_delta[0][1][0]= 0; | |
| 2380 s->sprite_delta[0][1][1]= a; | |
| 2381 s->sprite_delta[1][0][0]= a; | |
| 2382 s->sprite_delta[1][0][1]= 0; | |
| 2383 s->sprite_delta[1][1][0]= 0; | |
| 2384 s->sprite_delta[1][1][1]= a; | |
| 2385 s->sprite_shift[0][0]= 0; | |
| 2386 s->sprite_shift[0][1]= 0; | |
| 2387 s->sprite_shift[1][0]= 0; | |
| 2388 s->sprite_shift[1][1]= 0; | |
| 2389 s->real_sprite_warping_points=1; | |
| 2390 } | |
| 2391 else | |
| 2392 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
|
2393 |
| 301 | 2394 //printf("%d %d %d %d\n", d[0][0], d[0][1], s->sprite_offset[0][0], s->sprite_offset[0][1]); |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2395 } |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2396 |
| 0 | 2397 /* decode mpeg4 VOP header */ |
| 2398 int mpeg4_decode_picture_header(MpegEncContext * s) | |
| 2399 { | |
| 2400 int time_incr, startcode, state, v; | |
| 2401 | |
| 2402 redo: | |
| 2403 /* search next start code */ | |
| 2404 align_get_bits(&s->gb); | |
| 2405 state = 0xff; | |
| 2406 for(;;) { | |
| 2407 v = get_bits(&s->gb, 8); | |
| 2408 if (state == 0x000001) { | |
| 2409 state = ((state << 8) | v) & 0xffffff; | |
| 2410 startcode = state; | |
| 2411 break; | |
| 2412 } | |
| 2413 state = ((state << 8) | v) & 0xffffff; | |
| 278 | 2414 if( get_bits_count(&s->gb) > s->gb.size*8-32){ |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2415 printf("no VOP startcode found\n"); |
| 0 | 2416 return -1; |
| 263 | 2417 } |
| 0 | 2418 } |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2419 //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
|
2420 if (startcode == 0x120) { // Video Object Layer |
| 262 | 2421 int width, height, vo_ver_id; |
| 0 | 2422 |
| 2423 /* vol header */ | |
| 21 | 2424 skip_bits(&s->gb, 1); /* random access */ |
| 2425 skip_bits(&s->gb, 8); /* vo_type */ | |
| 63 | 2426 if (get_bits1(&s->gb) != 0) { /* is_ol_id */ |
| 2427 vo_ver_id = get_bits(&s->gb, 4); /* vo_ver_id */ | |
| 2428 skip_bits(&s->gb, 3); /* vo_priority */ | |
| 2429 } else { | |
| 2430 vo_ver_id = 1; | |
| 2431 } | |
| 0 | 2432 |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2433 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
|
2434 if(s->aspect_ratio_info == EXTENDET_PAR){ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2435 skip_bits(&s->gb, 8); //par_width |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2436 skip_bits(&s->gb, 8); // par_height |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2437 } |
|
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
278
diff
changeset
|
2438 |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2439 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
|
2440 printf("vol control parameter not supported\n"); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2441 return -1; |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2442 } |
| 63 | 2443 s->shape = get_bits(&s->gb, 2); /* vol shape */ |
|
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2444 if(s->shape != RECT_SHAPE) printf("only rectangular vol supported\n"); |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2445 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
|
2446 printf("Gray shape not supported\n"); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2447 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
|
2448 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2449 |
| 21 | 2450 skip_bits1(&s->gb); /* marker */ |
| 0 | 2451 |
| 262 | 2452 s->time_increment_resolution = get_bits(&s->gb, 16); |
| 2453 s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1; | |
| 63 | 2454 if (s->time_increment_bits < 1) |
| 2455 s->time_increment_bits = 1; | |
| 21 | 2456 skip_bits1(&s->gb); /* marker */ |
| 0 | 2457 |
| 63 | 2458 if (get_bits1(&s->gb) != 0) { /* fixed_vop_rate */ |
| 2459 skip_bits(&s->gb, s->time_increment_bits); | |
| 2460 } | |
| 0 | 2461 |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2462 if (s->shape != BIN_ONLY_SHAPE) { |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2463 if (s->shape == RECT_SHAPE) { |
| 63 | 2464 skip_bits1(&s->gb); /* marker */ |
| 2465 width = get_bits(&s->gb, 13); | |
| 2466 skip_bits1(&s->gb); /* marker */ | |
| 2467 height = get_bits(&s->gb, 13); | |
| 2468 skip_bits1(&s->gb); /* marker */ | |
|
274
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
2469 if(width && height){ /* they should be non zero but who knows ... */ |
|
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
2470 s->width = width; |
|
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
2471 s->height = height; |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
2472 // printf("%d %d\n", width, height); |
|
274
d0c186bcf075
use the width & height from the mpeg4 header ... in the case that its complete
michaelni
parents:
272
diff
changeset
|
2473 } |
| 63 | 2474 } |
| 2475 | |
|
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2476 if(get_bits1(&s->gb)) printf("interlaced not supported\n"); /* interlaced */ |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2477 if(!get_bits1(&s->gb)) printf("OBMC not supported\n"); /* OBMC Disable */ |
| 63 | 2478 if (vo_ver_id == 1) { |
| 2479 s->vol_sprite_usage = get_bits1(&s->gb); /* vol_sprite_usage */ | |
| 2480 } else { | |
| 2481 s->vol_sprite_usage = get_bits(&s->gb, 2); /* vol_sprite_usage */ | |
| 2482 } | |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2483 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
|
2484 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
|
2485 if(s->vol_sprite_usage==STATIC_SPRITE){ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2486 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
|
2487 skip_bits1(&s->gb); /* marker */ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2488 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
|
2489 skip_bits1(&s->gb); /* marker */ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2490 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
|
2491 skip_bits1(&s->gb); /* marker */ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2492 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
|
2493 skip_bits1(&s->gb); /* marker */ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2494 } |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2495 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
|
2496 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
|
2497 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
|
2498 if(s->vol_sprite_usage==STATIC_SPRITE) |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2499 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
|
2500 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2501 // 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
|
2502 |
| 63 | 2503 if (get_bits1(&s->gb) == 1) { /* not_8_bit */ |
| 2504 s->quant_precision = get_bits(&s->gb, 4); /* quant_precision */ | |
|
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2505 if(get_bits(&s->gb, 4)!=8) printf("N-bit not supported\n"); /* bits_per_pixel */ |
| 290 | 2506 if(s->quant_precision!=5) printf("quant precission %d\n", s->quant_precision); |
| 63 | 2507 } else { |
| 2508 s->quant_precision = 5; | |
| 2509 } | |
| 2510 | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2511 // FIXME a bunch of grayscale shape things |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2512 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
|
2513 if(vo_ver_id != 1) |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2514 s->quarter_sample= get_bits1(&s->gb); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2515 else s->quarter_sample=0; |
|
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2516 |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2517 if(!get_bits1(&s->gb)) printf("Complexity estimation not supported\n"); |
| 290 | 2518 |
| 2519 s->resync_marker= !get_bits1(&s->gb); /* resync_marker_disabled */ | |
| 2520 | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2521 s->data_partioning= get_bits1(&s->gb); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2522 if(s->data_partioning){ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2523 printf("data partitioning not supported\n"); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2524 skip_bits1(&s->gb); // reversible vlc |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2525 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2526 |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2527 if(vo_ver_id != 1) { |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2528 s->new_pred= get_bits1(&s->gb); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2529 if(s->new_pred){ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2530 printf("new pred not supported\n"); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2531 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
|
2532 skip_bits1(&s->gb); /* newpred segment type */ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2533 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2534 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
|
2535 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
|
2536 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2537 else{ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2538 s->new_pred=0; |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2539 s->reduced_res_vop= 0; |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2540 } |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2541 |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2542 s->scalability= get_bits1(&s->gb); |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2543 if (s->scalability) { |
| 285 | 2544 printf("scalability not supported\n"); |
| 63 | 2545 } |
| 2546 } | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2547 //printf("end Data %X %d\n", show_bits(&s->gb, 32), get_bits_count(&s->gb)&0x7); |
| 0 | 2548 goto redo; |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2549 } else if (startcode == 0x1b2) { //userdata |
| 255 | 2550 char buf[256]; |
| 2551 int i; | |
| 2552 int e; | |
| 2553 int ver, build; | |
| 2554 | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2555 //printf("user Data %X\n", show_bits(&s->gb, 32)); |
| 255 | 2556 buf[0]= show_bits(&s->gb, 8); |
| 2557 for(i=1; i<256; i++){ | |
| 2558 buf[i]= show_bits(&s->gb, 16)&0xFF; | |
| 2559 if(buf[i]==0) break; | |
| 2560 skip_bits(&s->gb, 8); | |
| 2561 } | |
| 2562 buf[255]=0; | |
| 2563 e=sscanf(buf, "DivX%dBuild%d", &ver, &build); | |
| 2564 if(e==2){ | |
| 2565 s->divx_version= ver; | |
| 2566 s->divx_build= build; | |
| 2567 if(s->picture_number==0){ | |
| 2568 printf("This file was encoded with DivX%d Build%d\n", ver, build); | |
| 2569 if(ver==500 && build==413){ //most likely all version are indeed totally buggy but i dunno for sure ... | |
| 2570 printf("WARNING: this version of DivX is not MPEG4 compatible, trying to workaround these bugs...\n"); | |
| 2571 }else{ | |
| 2572 printf("hmm, i havnt seen that version of divx yet, lets assume they fixed these bugs ...\n" | |
| 2573 "using mpeg4 decoder, if it fails contact the developers (of ffmpeg)\n"); | |
| 2574 } | |
| 2575 } | |
| 2576 } | |
| 2577 //printf("User Data: %s\n", buf); | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2578 goto redo; |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2579 } else if (startcode != 0x1b6) { //VOP |
| 0 | 2580 goto redo; |
| 2581 } | |
| 2582 | |
| 2583 s->pict_type = get_bits(&s->gb, 2) + 1; /* pict type: I = 0 , P = 1 */ | |
| 291 | 2584 //printf("pic: %d, qpel:%d\n", s->pict_type, s->quarter_sample); |
| 262 | 2585 time_incr=0; |
| 21 | 2586 while (get_bits1(&s->gb) != 0) |
| 0 | 2587 time_incr++; |
| 2588 | |
|
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2589 check_marker(&s->gb, "before time_increment"); |
| 262 | 2590 s->time_increment= get_bits(&s->gb, s->time_increment_bits); |
| 2591 if(s->pict_type!=B_TYPE){ | |
| 2592 s->time_base+= time_incr; | |
| 2593 s->last_non_b_time[1]= s->last_non_b_time[0]; | |
| 2594 s->last_non_b_time[0]= s->time_base*s->time_increment_resolution + s->time_increment; | |
| 2595 }else{ | |
| 2596 s->time= (s->last_non_b_time[1]/s->time_increment_resolution + time_incr)*s->time_increment_resolution; | |
| 2597 s->time+= s->time_increment; | |
| 2598 } | |
|
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2599 |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2600 if(check_marker(&s->gb, "before vop_coded")==0 && s->picture_number==0){ |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2601 printf("hmm, seems the headers arnt complete, trying to guess time_increment_bits\n"); |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2602 for(s->time_increment_bits++ ;s->time_increment_bits<16; s->time_increment_bits++){ |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2603 if(get_bits1(&s->gb)) break; |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2604 } |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2605 printf("my guess is %d bits ;)\n",s->time_increment_bits); |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2606 } |
| 0 | 2607 /* vop coded */ |
| 21 | 2608 if (get_bits1(&s->gb) != 1) |
| 63 | 2609 goto redo; |
| 262 | 2610 //printf("time %d %d %d || %d %d %d\n", s->time_increment_bits, s->time_increment, s->time_base, |
| 2611 //s->time, s->last_non_b_time[0], s->last_non_b_time[1]); | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2612 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
|
2613 || (s->pict_type == S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) { |
| 0 | 2614 /* rounding type for motion estimation */ |
| 21 | 2615 s->no_rounding = get_bits1(&s->gb); |
| 63 | 2616 } else { |
| 2617 s->no_rounding = 0; | |
| 0 | 2618 } |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2619 //FIXME reduced res stuff |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2620 |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2621 if (s->shape != RECT_SHAPE) { |
| 63 | 2622 if (s->vol_sprite_usage != 1 || s->pict_type != I_TYPE) { |
| 2623 int width, height, hor_spat_ref, ver_spat_ref; | |
| 2624 | |
| 2625 width = get_bits(&s->gb, 13); | |
| 2626 skip_bits1(&s->gb); /* marker */ | |
| 2627 height = get_bits(&s->gb, 13); | |
| 2628 skip_bits1(&s->gb); /* marker */ | |
| 2629 hor_spat_ref = get_bits(&s->gb, 13); /* hor_spat_ref */ | |
| 2630 skip_bits1(&s->gb); /* marker */ | |
| 2631 ver_spat_ref = get_bits(&s->gb, 13); /* ver_spat_ref */ | |
| 2632 } | |
| 2633 skip_bits1(&s->gb); /* change_CR_disable */ | |
| 2634 | |
| 2635 if (get_bits1(&s->gb) != 0) { | |
| 2636 skip_bits(&s->gb, 8); /* constant_alpha_value */ | |
| 2637 } | |
| 2638 } | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2639 //FIXME complexity estimation stuff |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2640 |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2641 if (s->shape != BIN_ONLY_SHAPE) { |
| 290 | 2642 int t; |
| 2643 t=get_bits(&s->gb, 3); /* intra dc VLC threshold */ | |
| 2644 //printf("threshold %d\n", t); | |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2645 //FIXME interlaced specific bits |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2646 } |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2647 |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2648 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
|
2649 if(s->num_sprite_warping_points){ |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2650 mpeg4_decode_sprite_trajectory(s); |
|
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2651 } |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2652 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
|
2653 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
|
2654 } |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2655 |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2656 if (s->shape != BIN_ONLY_SHAPE) { |
| 63 | 2657 /* note: we do not use quant_precision to avoid problem if no |
| 2658 MPEG4 vol header as it is found on some old opendivx | |
| 2659 movies */ | |
| 2660 s->qscale = get_bits(&s->gb, 5); | |
|
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2661 if(s->qscale==0){ |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2662 printf("Error, header damaged or not MPEG4 header (qscale=0)\n"); |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2663 return -1; // makes no sense to continue, as there is nothing left from the image then |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2664 } |
| 63 | 2665 |
| 2666 if (s->pict_type != I_TYPE) { | |
| 2667 s->f_code = get_bits(&s->gb, 3); /* fcode_for */ | |
|
264
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2668 if(s->f_code==0){ |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2669 printf("Error, header damaged or not MPEG4 header (f_code=0)\n"); |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2670 return -1; // makes no sense to continue, as the MV decoding will break very quickly |
|
28c5c62b1c4c
support decoding (with mplayer) of 3 .mp4 files from mphq
michaelni
parents:
263
diff
changeset
|
2671 } |
| 63 | 2672 } |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2673 if (s->pict_type == B_TYPE) { |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2674 s->b_code = get_bits(&s->gb, 3); |
| 262 | 2675 //printf("b-code %d\n", s->b_code); |
|
253
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2676 } |
|
254
b4fed8b24e3a
gmc bitstream decoding support (the real motion compensation isnt implemnted yet)
michaelni
parents:
253
diff
changeset
|
2677 //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
|
2678 if(!s->scalability){ |
|
4448dd55d415
parsing more of the mpeg4 header & print some "not supported" stuff
michaelni
parents:
250
diff
changeset
|
2679 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
|
2680 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
|
2681 } |
| 63 | 2682 } |
| 2683 } | |
| 255 | 2684 s->picture_number++; // better than pic number==0 allways ;) |
| 63 | 2685 return 0; |
| 0 | 2686 } |
| 2687 | |
| 2688 /* don't understand why they choose a different header ! */ | |
| 2689 int intel_h263_decode_picture_header(MpegEncContext *s) | |
| 2690 { | |
| 2691 int format; | |
| 2692 | |
| 2693 /* picture header */ | |
| 2694 if (get_bits(&s->gb, 22) != 0x20) | |
| 2695 return -1; | |
| 21 | 2696 skip_bits(&s->gb, 8); /* picture timestamp */ |
| 0 | 2697 |
| 21 | 2698 if (get_bits1(&s->gb) != 1) |
| 0 | 2699 return -1; /* marker */ |
| 21 | 2700 if (get_bits1(&s->gb) != 0) |
| 0 | 2701 return -1; /* h263 id */ |
| 21 | 2702 skip_bits1(&s->gb); /* split screen off */ |
| 2703 skip_bits1(&s->gb); /* camera off */ | |
| 2704 skip_bits1(&s->gb); /* freeze picture release off */ | |
| 0 | 2705 |
| 2706 format = get_bits(&s->gb, 3); | |
| 2707 if (format != 7) | |
| 2708 return -1; | |
| 2709 | |
| 2710 s->h263_plus = 0; | |
| 2711 | |
| 21 | 2712 s->pict_type = I_TYPE + get_bits1(&s->gb); |
| 0 | 2713 |
| 21 | 2714 s->unrestricted_mv = get_bits1(&s->gb); |
| 0 | 2715 s->h263_long_vectors = s->unrestricted_mv; |
| 2716 | |
| 21 | 2717 if (get_bits1(&s->gb) != 0) |
| 0 | 2718 return -1; /* SAC: off */ |
| 21 | 2719 if (get_bits1(&s->gb) != 0) |
| 0 | 2720 return -1; /* advanced prediction mode: off */ |
| 21 | 2721 if (get_bits1(&s->gb) != 0) |
| 0 | 2722 return -1; /* not PB frame */ |
| 2723 | |
| 2724 /* skip unknown header garbage */ | |
| 21 | 2725 skip_bits(&s->gb, 41); |
| 0 | 2726 |
| 2727 s->qscale = get_bits(&s->gb, 5); | |
| 21 | 2728 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
| 0 | 2729 |
| 2730 /* PEI */ | |
| 21 | 2731 while (get_bits1(&s->gb) != 0) { |
| 2732 skip_bits(&s->gb, 8); | |
| 0 | 2733 } |
| 2734 s->f_code = 1; | |
| 2735 return 0; | |
| 2736 } | |
| 144 | 2737 |
