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