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