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