Mercurial > libavcodec.hg
annotate h263.c @ 10824:82d006235248 libavcodec
Move 3 direct MV related functions that i left out from h263.c to mpeg4video.c.
author | michael |
---|---|
date | Fri, 08 Jan 2010 19:59:51 +0000 |
parents | 514dc1c87b2e |
children | d0657e337f91 |
rev | line source |
---|---|
0 | 1 /* |
2 * H263/MPEG4 backend for ffmpeg encoder and decoder | |
8629
04423b2f6e0b
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
8627
diff
changeset
|
3 * Copyright (c) 2000,2001 Fabrice Bellard |
78 | 4 * H263+ support. |
8629
04423b2f6e0b
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
8627
diff
changeset
|
5 * Copyright (c) 2001 Juan J. Sierralta P |
1739
07a484280a82
copyright year update of the files i touched and remembered, things look annoyingly unmaintained otherwise
michael
parents:
1708
diff
changeset
|
6 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> |
0 | 7 * |
5214 | 8 * ac prediction encoding, B-frame support, error resilience, optimizations, |
9 * qpel decoding, gmc decoding, interlaced decoding | |
10 * by Michael Niedermayer <michaelni@gmx.at> | |
11 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
12 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
13 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
14 * FFmpeg is free software; you can redistribute it and/or |
429 | 15 * modify it under the terms of the GNU Lesser General Public |
16 * License as published by the Free Software Foundation; either | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
17 * version 2.1 of the License, or (at your option) any later version. |
0 | 18 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
19 * FFmpeg is distributed in the hope that it will be useful, |
0 | 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
22 * Lesser General Public License for more details. | |
0 | 23 * |
429 | 24 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3791
diff
changeset
|
25 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
3024
diff
changeset
|
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 27 */ |
1034 | 28 |
29 /** | |
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
8691
diff
changeset
|
30 * @file libavcodec/h263.c |
1106 | 31 * h263/mpeg4 codec. |
1034 | 32 */ |
2967 | 33 |
355 | 34 //#define DEBUG |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
35 #include <limits.h> |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
36 |
0 | 37 #include "dsputil.h" |
38 #include "avcodec.h" | |
39 #include "mpegvideo.h" | |
10803 | 40 #include "h263.h" |
0 | 41 #include "h263data.h" |
8627
d6bab465b82c
moves mid_pred() into mathops.h (with arch specific code split by directory)
aurel
parents:
8612
diff
changeset
|
42 #include "mathops.h" |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
43 #include "unary.h" |
10787 | 44 #include "flv.h" |
10803 | 45 #include "mpeg4video.h" |
0 | 46 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
47 //#undef NDEBUG |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
48 //#include <assert.h> |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
49 |
10783 | 50 // The defines below define the number of bits that are read at once for |
51 // reading vlc values. Changing these may improve speed and data cache needs | |
52 // be aware though that decreasing them may need the number of stages that is | |
53 // passed to get_vlc* to be increased. | |
544 | 54 #define MV_VLC_BITS 9 |
1655 | 55 #define H263_MBTYPE_B_VLC_BITS 6 |
56 #define CBPC_B_VLC_BITS 3 | |
544 | 57 |
10803 | 58 |
8590 | 59 #if CONFIG_ENCODERS |
10784 | 60 /** |
61 * Table of number of bits a motion vector component needs. | |
62 */ | |
4655 | 63 static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; |
10784 | 64 |
65 /** | |
66 * Minimal fcode that a motion vector component would need. | |
67 */ | |
1064 | 68 static uint8_t fcode_tab[MAX_MV*2+1]; |
10784 | 69 |
70 /** | |
71 * Minimal fcode that a motion vector component would need in umv. | |
72 * All entries in this table are 1. | |
73 */ | |
1064 | 74 static uint8_t umv_fcode_tab[MAX_MV*2+1]; |
815
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
770
diff
changeset
|
75 |
10784 | 76 //unified encoding tables for run length encoding of coefficients |
77 //unified in the sense that the specification specifies the encoding in several steps. | |
2253 | 78 static uint8_t uni_h263_intra_aic_rl_len [64*64*2*2]; |
79 static uint8_t uni_h263_inter_rl_len [64*64*2*2]; | |
945 | 80 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128 + (run)*256 + (level)) |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
81 //#define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run) + (level)*64) |
945 | 82 #define UNI_MPEG4_ENC_INDEX(last,run,level) ((last)*128*64 + (run)*128 + (level)) |
648
dddcff6841f2
optimizing mpeg4_encode_block(), generates allso slightly shorter bitstream as some codes can be represented as esc1 and esc2 and esc2 is shorter for a few of them
michaelni
parents:
619
diff
changeset
|
83 |
815
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
770
diff
changeset
|
84 #endif |
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
770
diff
changeset
|
85 |
10803 | 86 static uint8_t static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; |
4672 | 87 |
293 | 88 |
0 | 89 int h263_get_picture_format(int width, int height) |
90 { | |
91 if (width == 128 && height == 96) | |
10782 | 92 return 1; |
0 | 93 else if (width == 176 && height == 144) |
10782 | 94 return 2; |
0 | 95 else if (width == 352 && height == 288) |
10782 | 96 return 3; |
0 | 97 else if (width == 704 && height == 576) |
10782 | 98 return 4; |
0 | 99 else if (width == 1408 && height == 1152) |
10782 | 100 return 5; |
0 | 101 else |
10782 | 102 return 7; |
0 | 103 } |
104 | |
10791 | 105 void ff_h263_show_pict_info(MpegEncContext *s){ |
10793
9b3ec3d1bdae
Factorize if() surrounding every ff_h263_show_pict_info() call.
michael
parents:
10791
diff
changeset
|
106 if(s->avctx->debug&FF_DEBUG_PICT_INFO){ |
5403 | 107 av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n", |
108 s->qscale, av_get_pict_type_char(s->pict_type), | |
109 s->gb.size_in_bits, 1-s->no_rounding, | |
110 s->obmc ? " AP" : "", | |
111 s->umvplus ? " UMV" : "", | |
112 s->h263_long_vectors ? " LONG" : "", | |
113 s->h263_plus ? " +" : "", | |
114 s->h263_aic ? " AIC" : "", | |
115 s->alt_inter_vlc ? " AIV" : "", | |
116 s->modified_quant ? " MQ" : "", | |
117 s->loop_filter ? " LOOP" : "", | |
118 s->h263_slice_structured ? " SS" : "", | |
119 s->avctx->time_base.den, s->avctx->time_base.num | |
120 ); | |
10793
9b3ec3d1bdae
Factorize if() surrounding every ff_h263_show_pict_info() call.
michael
parents:
10791
diff
changeset
|
121 } |
5403 | 122 } |
123 | |
8590 | 124 #if CONFIG_ENCODERS |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
125 |
10786 | 126 /** |
127 * Returns the 4 bit value that specifies the given aspect ratio. | |
128 * This may be one of the standard aspect ratios or it specifies | |
129 * that the aspect will be stored explicitly later. | |
130 */ | |
10803 | 131 av_const int ff_h263_aspect_to_info(AVRational aspect){ |
887 | 132 int i; |
133 | |
1548 | 134 if(aspect.num==0) aspect= (AVRational){1,1}; |
135 | |
887 | 136 for(i=1; i<6; i++){ |
10803 | 137 if(av_cmp_q(ff_h263_pixel_aspect[i], aspect) == 0){ |
10785 | 138 return i; |
887 | 139 } |
140 } | |
2967 | 141 |
10785 | 142 return FF_ASPECT_EXTENDED; |
880 | 143 } |
144 | |
1354 | 145 void h263_encode_picture_header(MpegEncContext * s, int picture_number) |
146 { | |
1872 | 147 int format, coded_frame_rate, coded_frame_rate_base, i, temp_ref; |
148 int best_clock_code=1; | |
149 int best_divisor=60; | |
150 int best_error= INT_MAX; | |
2967 | 151 |
1872 | 152 if(s->h263_plus){ |
153 for(i=0; i<2; i++){ | |
154 int div, error; | |
2637 | 155 div= (s->avctx->time_base.num*1800000LL + 500LL*s->avctx->time_base.den) / ((1000LL+i)*s->avctx->time_base.den); |
5075
33d50e0e1823
Correct the parameter order for the call to "av_clip".
takis
parents:
4984
diff
changeset
|
156 div= av_clip(div, 1, 127); |
4001 | 157 error= FFABS(s->avctx->time_base.num*1800000LL - (1000LL+i)*s->avctx->time_base.den*div); |
1872 | 158 if(error < best_error){ |
159 best_error= error; | |
160 best_divisor= div; | |
161 best_clock_code= i; | |
162 } | |
163 } | |
164 } | |
165 s->custom_pcf= best_clock_code!=1 || best_divisor!=60; | |
166 coded_frame_rate= 1800000; | |
167 coded_frame_rate_base= (1000+best_clock_code)*best_divisor; | |
1354 | 168 |
169 align_put_bits(&s->pb); | |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
170 |
231 | 171 /* Update the pointer to last GOB */ |
9431 | 172 s->ptr_lastgob = put_bits_ptr(&s->pb); |
231 | 173 put_bits(&s->pb, 22, 0x20); /* PSC */ |
2637 | 174 temp_ref= s->picture_number * (int64_t)coded_frame_rate * s->avctx->time_base.num / //FIXME use timestamp |
175 (coded_frame_rate_base * (int64_t)s->avctx->time_base.den); | |
7260
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
7098
diff
changeset
|
176 put_sbits(&s->pb, 8, temp_ref); /* TemporalReference */ |
0 | 177 |
2979 | 178 put_bits(&s->pb, 1, 1); /* marker */ |
179 put_bits(&s->pb, 1, 0); /* h263 id */ | |
180 put_bits(&s->pb, 1, 0); /* split screen off */ | |
181 put_bits(&s->pb, 1, 0); /* camera off */ | |
182 put_bits(&s->pb, 1, 0); /* freeze picture release off */ | |
2967 | 183 |
78 | 184 format = h263_get_picture_format(s->width, s->height); |
0 | 185 if (!s->h263_plus) { |
186 /* H.263v1 */ | |
187 put_bits(&s->pb, 3, format); | |
6481 | 188 put_bits(&s->pb, 1, (s->pict_type == FF_P_TYPE)); |
0 | 189 /* By now UMV IS DISABLED ON H.263v1, since the restrictions |
190 of H.263v1 UMV implies to check the predicted MV after | |
191 calculation of the current MB to see if we're on the limits */ | |
2979 | 192 put_bits(&s->pb, 1, 0); /* Unrestricted Motion Vector: off */ |
193 put_bits(&s->pb, 1, 0); /* SAC: off */ | |
194 put_bits(&s->pb, 1, s->obmc); /* Advanced Prediction */ | |
195 put_bits(&s->pb, 1, 0); /* only I/P frames, no PB frame */ | |
0 | 196 put_bits(&s->pb, 5, s->qscale); |
2979 | 197 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ |
0 | 198 } else { |
1872 | 199 int ufep=1; |
0 | 200 /* H.263v2 */ |
201 /* H.263 Plus PTYPE */ | |
2967 | 202 |
0 | 203 put_bits(&s->pb, 3, 7); |
1872 | 204 put_bits(&s->pb,3,ufep); /* Update Full Extended PTYPE */ |
78 | 205 if (format == 7) |
206 put_bits(&s->pb,3,6); /* Custom Source Format */ | |
207 else | |
208 put_bits(&s->pb, 3, format); | |
2967 | 209 |
1872 | 210 put_bits(&s->pb,1, s->custom_pcf); |
1661 | 211 put_bits(&s->pb,1, s->umvplus); /* Unrestricted Motion Vector */ |
0 | 212 put_bits(&s->pb,1,0); /* SAC: off */ |
1633 | 213 put_bits(&s->pb,1,s->obmc); /* Advanced Prediction Mode */ |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
214 put_bits(&s->pb,1,s->h263_aic); /* Advanced Intra Coding */ |
1644 | 215 put_bits(&s->pb,1,s->loop_filter); /* Deblocking Filter */ |
1661 | 216 put_bits(&s->pb,1,s->h263_slice_structured); /* Slice Structured */ |
0 | 217 put_bits(&s->pb,1,0); /* Reference Picture Selection: off */ |
218 put_bits(&s->pb,1,0); /* Independent Segment Decoding: off */ | |
1637 | 219 put_bits(&s->pb,1,s->alt_inter_vlc); /* Alternative Inter VLC */ |
1644 | 220 put_bits(&s->pb,1,s->modified_quant); /* Modified Quantization: */ |
0 | 221 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ |
222 put_bits(&s->pb,3,0); /* Reserved */ | |
2967 | 223 |
6481 | 224 put_bits(&s->pb, 3, s->pict_type == FF_P_TYPE); |
2967 | 225 |
0 | 226 put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */ |
227 put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */ | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
228 put_bits(&s->pb,1,s->no_rounding); /* Rounding Type */ |
0 | 229 put_bits(&s->pb,2,0); /* Reserved */ |
230 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
2967 | 231 |
0 | 232 /* This should be here if PLUSPTYPE */ |
2979 | 233 put_bits(&s->pb, 1, 0); /* Continuous Presence Multipoint mode: off */ |
234 | |
235 if (format == 7) { | |
78 | 236 /* Custom Picture Format (CPFMT) */ |
10803 | 237 s->aspect_ratio_info= ff_h263_aspect_to_info(s->avctx->sample_aspect_ratio); |
880 | 238 |
239 put_bits(&s->pb,4,s->aspect_ratio_info); | |
78 | 240 put_bits(&s->pb,9,(s->width >> 2) - 1); |
241 put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ | |
242 put_bits(&s->pb,9,(s->height >> 2)); | |
1548 | 243 if (s->aspect_ratio_info == FF_ASPECT_EXTENDED){ |
244 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.num); | |
245 put_bits(&s->pb, 8, s->avctx->sample_aspect_ratio.den); | |
2979 | 246 } |
78 | 247 } |
1872 | 248 if(s->custom_pcf){ |
249 if(ufep){ | |
250 put_bits(&s->pb, 1, best_clock_code); | |
251 put_bits(&s->pb, 7, best_divisor); | |
252 } | |
7260
3ec34b551aae
bitstream: move put_sbits() from flacenc.c to bitstream.h and use it
ramiro
parents:
7098
diff
changeset
|
253 put_sbits(&s->pb, 2, temp_ref>>8); |
1872 | 254 } |
2967 | 255 |
0 | 256 /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
257 if (s->umvplus) |
1089 | 258 // put_bits(&s->pb,1,1); /* Limited according tables of Annex D */ |
1644 | 259 //FIXME check actual requested range |
1089 | 260 put_bits(&s->pb,2,1); /* unlimited */ |
1661 | 261 if(s->h263_slice_structured) |
262 put_bits(&s->pb,2,0); /* no weird submodes */ | |
1089 | 263 |
0 | 264 put_bits(&s->pb, 5, s->qscale); |
265 } | |
266 | |
2979 | 267 put_bits(&s->pb, 1, 0); /* no PEI */ |
498 | 268 |
1670 | 269 if(s->h263_slice_structured){ |
270 put_bits(&s->pb, 1, 1); | |
2967 | 271 |
1670 | 272 assert(s->mb_x == 0 && s->mb_y == 0); |
273 ff_h263_encode_mba(s); | |
274 | |
275 put_bits(&s->pb, 1, 1); | |
276 } | |
277 | |
498 | 278 if(s->h263_aic){ |
2967 | 279 s->y_dc_scale_table= |
1639 | 280 s->c_dc_scale_table= ff_aic_dc_scale_table; |
498 | 281 }else{ |
282 s->y_dc_scale_table= | |
283 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
284 } | |
0 | 285 } |
286 | |
766 | 287 /** |
288 * Encodes a group of blocks header. | |
289 */ | |
1661 | 290 void h263_encode_gob_header(MpegEncContext * s, int mb_line) |
162 | 291 { |
1661 | 292 put_bits(&s->pb, 17, 1); /* GBSC */ |
293 | |
294 if(s->h263_slice_structured){ | |
295 put_bits(&s->pb, 1, 1); | |
296 | |
297 ff_h263_encode_mba(s); | |
298 | |
299 if(s->mb_num > 1583) | |
300 put_bits(&s->pb, 1, 1); | |
301 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ | |
302 put_bits(&s->pb, 1, 1); | |
6481 | 303 put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */ |
1661 | 304 }else{ |
305 int gob_number= mb_line / s->gob_index; | |
306 | |
307 put_bits(&s->pb, 5, gob_number); /* GN */ | |
6481 | 308 put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */ |
1661 | 309 put_bits(&s->pb, 5, s->qscale); /* GQUANT */ |
310 } | |
162 | 311 } |
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
264
diff
changeset
|
312 |
10795 | 313 /** |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
314 * modify qscale so that encoding is acually possible in h263 (limit difference to -2..2) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
315 */ |
695 | 316 void ff_clean_h263_qscales(MpegEncContext *s){ |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
317 int i; |
903 | 318 int8_t * const qscale_table= s->current_picture.qscale_table; |
2967 | 319 |
4316 | 320 ff_init_qscale_tab(s); |
321 | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
322 for(i=1; i<s->mb_num; i++){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
323 if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i-1] ] >2) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
324 qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i-1] ]+2; |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
325 } |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
326 for(i=s->mb_num-2; i>=0; i--){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
327 if(qscale_table[ s->mb_index2xy[i] ] - qscale_table[ s->mb_index2xy[i+1] ] >2) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
328 qscale_table[ s->mb_index2xy[i] ]= qscale_table[ s->mb_index2xy[i+1] ]+2; |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
676
diff
changeset
|
329 } |
1983 | 330 |
331 if(s->codec_id != CODEC_ID_H263P){ | |
332 for(i=1; i<s->mb_num; i++){ | |
333 int mb_xy= s->mb_index2xy[i]; | |
2967 | 334 |
1983 | 335 if(qscale_table[mb_xy] != qscale_table[s->mb_index2xy[i-1]] && (s->mb_type[mb_xy]&CANDIDATE_MB_TYPE_INTER4V)){ |
336 s->mb_type[mb_xy]|= CANDIDATE_MB_TYPE_INTER; | |
337 } | |
338 } | |
339 } | |
695 | 340 } |
341 | |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
342 #endif //CONFIG_ENCODERS |
3247 | 343 |
1389 | 344 void ff_h263_update_motion_val(MpegEncContext * s){ |
345 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; | |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
346 //FIXME a lot of that is only needed for !low_delay |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
347 const int wrap = s->b8_stride; |
1389 | 348 const int xy = s->block_index[0]; |
2967 | 349 |
350 s->current_picture.mbskip_table[mb_xy]= s->mb_skipped; | |
1389 | 351 |
352 if(s->mv_type != MV_TYPE_8X8){ | |
353 int motion_x, motion_y; | |
354 if (s->mb_intra) { | |
355 motion_x = 0; | |
356 motion_y = 0; | |
357 } else if (s->mv_type == MV_TYPE_16X16) { | |
358 motion_x = s->mv[0][0][0]; | |
359 motion_y = s->mv[0][0][1]; | |
360 } else /*if (s->mv_type == MV_TYPE_FIELD)*/ { | |
361 int i; | |
362 motion_x = s->mv[0][0][0] + s->mv[0][1][0]; | |
363 motion_y = s->mv[0][0][1] + s->mv[0][1][1]; | |
364 motion_x = (motion_x>>1) | (motion_x&1); | |
365 for(i=0; i<2; i++){ | |
1708 | 366 s->p_field_mv_table[i][0][mb_xy][0]= s->mv[0][i][0]; |
367 s->p_field_mv_table[i][0][mb_xy][1]= s->mv[0][i][1]; | |
1389 | 368 } |
1948 | 369 s->current_picture.ref_index[0][xy ]= |
370 s->current_picture.ref_index[0][xy + 1]= s->field_select[0][0]; | |
371 s->current_picture.ref_index[0][xy + wrap ]= | |
372 s->current_picture.ref_index[0][xy + wrap + 1]= s->field_select[0][1]; | |
1389 | 373 } |
1948 | 374 |
1389 | 375 /* no update if 8X8 because it has been done during parsing */ |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
376 s->current_picture.motion_val[0][xy][0] = motion_x; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
377 s->current_picture.motion_val[0][xy][1] = motion_y; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
378 s->current_picture.motion_val[0][xy + 1][0] = motion_x; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
379 s->current_picture.motion_val[0][xy + 1][1] = motion_y; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
380 s->current_picture.motion_val[0][xy + wrap][0] = motion_x; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
381 s->current_picture.motion_val[0][xy + wrap][1] = motion_y; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
382 s->current_picture.motion_val[0][xy + 1 + wrap][0] = motion_x; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
383 s->current_picture.motion_val[0][xy + 1 + wrap][1] = motion_y; |
1389 | 384 } |
385 | |
386 if(s->encoding){ //FIXME encoding MUST be cleaned up | |
2967 | 387 if (s->mv_type == MV_TYPE_8X8) |
1389 | 388 s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_8x8; |
1633 | 389 else if(s->mb_intra) |
390 s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA; | |
1389 | 391 else |
392 s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_16x16; | |
393 } | |
394 } | |
395 | |
8590 | 396 #if CONFIG_ENCODERS |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
397 |
8644 | 398 static const int dquant_code[5]= {1,0,9,2,3}; |
399 | |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
400 /** |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
401 * encodes a 8x8 block. |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
402 * @param block the 8x8 block |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
403 * @param n block index (0-3 are luma, 4-5 are chroma) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
404 */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
405 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
406 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
407 int level, run, last, i, j, last_index, last_non_zero, sign, slevel, code; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
408 RLTable *rl; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
409 |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
410 rl = &ff_h263_rl_inter; |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
411 if (s->mb_intra && !s->h263_aic) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
412 /* DC coef */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
413 level = block[0]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
414 /* 255 cannot be represented, so we clamp */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
415 if (level > 254) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
416 level = 254; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
417 block[0] = 254; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
418 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
419 /* 0 cannot be represented also */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
420 else if (level < 1) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
421 level = 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
422 block[0] = 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
423 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
424 if (level == 128) //FIXME check rv10 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
425 put_bits(&s->pb, 8, 0xff); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
426 else |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
427 put_bits(&s->pb, 8, level); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
428 i = 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
429 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
430 i = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
431 if (s->h263_aic && s->mb_intra) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
432 rl = &rl_intra_aic; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
433 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
434 if(s->alt_inter_vlc && !s->mb_intra){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
435 int aic_vlc_bits=0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
436 int inter_vlc_bits=0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
437 int wrong_pos=-1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
438 int aic_code; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
439 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
440 last_index = s->block_last_index[n]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
441 last_non_zero = i - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
442 for (; i <= last_index; i++) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
443 j = s->intra_scantable.permutated[i]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
444 level = block[j]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
445 if (level) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
446 run = i - last_non_zero - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
447 last = (i == last_index); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
448 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
449 if(level<0) level= -level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
450 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
451 code = get_rl_index(rl, last, run, level); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
452 aic_code = get_rl_index(&rl_intra_aic, last, run, level); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
453 inter_vlc_bits += rl->table_vlc[code][1]+1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
454 aic_vlc_bits += rl_intra_aic.table_vlc[aic_code][1]+1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
455 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
456 if (code == rl->n) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
457 inter_vlc_bits += 1+6+8-1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
458 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
459 if (aic_code == rl_intra_aic.n) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
460 aic_vlc_bits += 1+6+8-1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
461 wrong_pos += run + 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
462 }else |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
463 wrong_pos += wrong_run[aic_code]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
464 last_non_zero = i; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
465 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
466 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
467 i = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
468 if(aic_vlc_bits < inter_vlc_bits && wrong_pos > 63) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
469 rl = &rl_intra_aic; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
470 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
471 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
472 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
473 /* AC coefs */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
474 last_index = s->block_last_index[n]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
475 last_non_zero = i - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
476 for (; i <= last_index; i++) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
477 j = s->intra_scantable.permutated[i]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
478 level = block[j]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
479 if (level) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
480 run = i - last_non_zero - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
481 last = (i == last_index); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
482 sign = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
483 slevel = level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
484 if (level < 0) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
485 sign = 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
486 level = -level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
487 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
488 code = get_rl_index(rl, last, run, level); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
489 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
490 if (code == rl->n) { |
10787 | 491 if(!CONFIG_FLV_ENCODER || s->h263_flv <= 1){ |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
492 put_bits(&s->pb, 1, last); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
493 put_bits(&s->pb, 6, run); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
494 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
495 assert(slevel != 0); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
496 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
497 if(level < 128) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
498 put_sbits(&s->pb, 8, slevel); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
499 else{ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
500 put_bits(&s->pb, 8, 128); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
501 put_sbits(&s->pb, 5, slevel); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
502 put_sbits(&s->pb, 6, slevel>>5); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
503 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
504 }else{ |
10787 | 505 ff_flv2_encode_ac_esc(&s->pb, slevel, level, run, last); |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
506 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
507 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
508 put_bits(&s->pb, 1, sign); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
509 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
510 last_non_zero = i; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
511 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
512 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
513 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
514 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
515 /* Encode MV differences on H.263+ with Unrestricted MV mode */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
516 static void h263p_encode_umotion(MpegEncContext * s, int val) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
517 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
518 short sval = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
519 short i = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
520 short n_bits = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
521 short temp_val; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
522 int code = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
523 int tcode; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
524 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
525 if ( val == 0) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
526 put_bits(&s->pb, 1, 1); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
527 else if (val == 1) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
528 put_bits(&s->pb, 3, 0); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
529 else if (val == -1) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
530 put_bits(&s->pb, 3, 2); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
531 else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
532 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
533 sval = ((val < 0) ? (short)(-val):(short)val); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
534 temp_val = sval; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
535 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
536 while (temp_val != 0) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
537 temp_val = temp_val >> 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
538 n_bits++; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
539 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
540 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
541 i = n_bits - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
542 while (i > 0) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
543 tcode = (sval & (1 << (i-1))) >> (i-1); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
544 tcode = (tcode << 1) | 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
545 code = (code << 2) | tcode; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
546 i--; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
547 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
548 code = ((code << 1) | (val < 0)) << 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
549 put_bits(&s->pb, (2*n_bits)+1, code); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
550 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
551 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
552 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
553 static int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
554 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
555 int x, y, wrap, a, c, pred_dc; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
556 int16_t *dc_val; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
557 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
558 /* find prediction */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
559 if (n < 4) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
560 x = 2 * s->mb_x + (n & 1); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
561 y = 2 * s->mb_y + ((n & 2) >> 1); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
562 wrap = s->b8_stride; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
563 dc_val = s->dc_val[0]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
564 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
565 x = s->mb_x; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
566 y = s->mb_y; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
567 wrap = s->mb_stride; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
568 dc_val = s->dc_val[n - 4 + 1]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
569 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
570 /* B C |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
571 * A X |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
572 */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
573 a = dc_val[(x - 1) + (y) * wrap]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
574 c = dc_val[(x) + (y - 1) * wrap]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
575 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
576 /* No prediction outside GOB boundary */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
577 if(s->first_slice_line && n!=3){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
578 if(n!=2) c= 1024; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
579 if(n!=1 && s->mb_x == s->resync_mb_x) a= 1024; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
580 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
581 /* just DC prediction */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
582 if (a != 1024 && c != 1024) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
583 pred_dc = (a + c) >> 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
584 else if (a != 1024) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
585 pred_dc = a; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
586 else |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
587 pred_dc = c; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
588 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
589 /* we assume pred is positive */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
590 *dc_val_ptr = &dc_val[x + y * wrap]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
591 return pred_dc; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
592 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
593 |
0 | 594 void h263_encode_mb(MpegEncContext * s, |
2979 | 595 DCTELEM block[6][64], |
596 int motion_x, int motion_y) | |
0 | 597 { |
598 int cbpc, cbpy, i, cbp, pred_x, pred_y; | |
1064 | 599 int16_t pred_dc; |
600 int16_t rec_intradc[6]; | |
3781 | 601 int16_t *dc_ptr[6]; |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
602 const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1); |
2967 | 603 |
324 | 604 if (!s->mb_intra) { |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
605 /* compute cbp */ |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
606 cbp= get_p_cbp(s, block, motion_x, motion_y); |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1483
diff
changeset
|
607 |
1789 | 608 if ((cbp | motion_x | motion_y | s->dquant | (s->mv_type - MV_TYPE_16X16)) == 0) { |
324 | 609 /* skip macroblock */ |
610 put_bits(&s->pb, 1, 1); | |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
611 if(interleaved_stats){ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
612 s->misc_bits++; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
613 s->last_bits++; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
614 } |
1757
3906ddbaffec
optimization & bugfix extracted from the 4k line diff between ffmpeg 0.4.7 and http://www.alicestreet.com/ffh263.html
michael
parents:
1752
diff
changeset
|
615 s->skip_count++; |
3906ddbaffec
optimization & bugfix extracted from the 4k line diff between ffmpeg 0.4.7 and http://www.alicestreet.com/ffh263.html
michael
parents:
1752
diff
changeset
|
616 |
324 | 617 return; |
618 } | |
2979 | 619 put_bits(&s->pb, 1, 0); /* mb coded */ |
2967 | 620 |
324 | 621 cbpc = cbp & 3; |
1637 | 622 cbpy = cbp >> 2; |
623 if(s->alt_inter_vlc==0 || cbpc!=3) | |
624 cbpy ^= 0xF; | |
695 | 625 if(s->dquant) cbpc+= 8; |
1633 | 626 if(s->mv_type==MV_TYPE_16X16){ |
627 put_bits(&s->pb, | |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
628 ff_h263_inter_MCBPC_bits[cbpc], |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
629 ff_h263_inter_MCBPC_code[cbpc]); |
1633 | 630 |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
631 put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); |
1633 | 632 if(s->dquant) |
633 put_bits(&s->pb, 2, dquant_code[s->dquant+2]); | |
2967 | 634 |
1633 | 635 if(interleaved_stats){ |
636 s->misc_bits+= get_bits_diff(s); | |
637 } | |
638 | |
639 /* motion vectors: 16x16 mode */ | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
640 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
2967 | 641 |
642 if (!s->umvplus) { | |
2502 | 643 ff_h263_encode_motion_vector(s, motion_x - pred_x, |
644 motion_y - pred_y, 1); | |
1633 | 645 } |
646 else { | |
647 h263p_encode_umotion(s, motion_x - pred_x); | |
648 h263p_encode_umotion(s, motion_y - pred_y); | |
649 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) | |
650 /* To prevent Start Code emulation */ | |
651 put_bits(&s->pb,1,1); | |
652 } | |
653 }else{ | |
654 put_bits(&s->pb, | |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
655 ff_h263_inter_MCBPC_bits[cbpc+16], |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
656 ff_h263_inter_MCBPC_code[cbpc+16]); |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
657 put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); |
1633 | 658 if(s->dquant) |
659 put_bits(&s->pb, 2, dquant_code[s->dquant+2]); | |
660 | |
661 if(interleaved_stats){ | |
662 s->misc_bits+= get_bits_diff(s); | |
663 } | |
664 | |
665 for(i=0; i<4; i++){ | |
666 /* motion vectors: 8x8 mode*/ | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
667 h263_pred_motion(s, i, 0, &pred_x, &pred_y); |
1633 | 668 |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
669 motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
670 motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1]; |
2967 | 671 if (!s->umvplus) { |
2502 | 672 ff_h263_encode_motion_vector(s, motion_x - pred_x, |
673 motion_y - pred_y, 1); | |
1633 | 674 } |
675 else { | |
676 h263p_encode_umotion(s, motion_x - pred_x); | |
677 h263p_encode_umotion(s, motion_y - pred_y); | |
678 if (((motion_x - pred_x) == 1) && ((motion_y - pred_y) == 1)) | |
679 /* To prevent Start Code emulation */ | |
680 put_bits(&s->pb,1,1); | |
681 } | |
682 } | |
324 | 683 } |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
684 |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
685 if(interleaved_stats){ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
686 s->mv_bits+= get_bits_diff(s); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
687 } |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
688 } else { |
1639 | 689 assert(s->mb_intra); |
2967 | 690 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
691 cbp = 0; |
1666 | 692 if (s->h263_aic) { |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
693 /* Predict DC */ |
1666 | 694 for(i=0; i<6; i++) { |
1064 | 695 int16_t level = block[i][0]; |
1666 | 696 int scale; |
2967 | 697 |
1666 | 698 if(i<4) scale= s->y_dc_scale; |
699 else scale= s->c_dc_scale; | |
700 | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
701 pred_dc = h263_pred_dc(s, i, &dc_ptr[i]); |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
702 level -= pred_dc; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
703 /* Quant */ |
1666 | 704 if (level >= 0) |
705 level = (level + (scale>>1))/scale; | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
706 else |
1666 | 707 level = (level - (scale>>1))/scale; |
2967 | 708 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
709 /* AIC can change CBP */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
710 if (level == 0 && s->block_last_index[i] == 0) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
711 s->block_last_index[i] = -1; |
1666 | 712 |
713 if(!s->modified_quant){ | |
714 if (level < -127) | |
715 level = -127; | |
716 else if (level > 127) | |
717 level = 127; | |
718 } | |
719 | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
720 block[i][0] = level; |
2967 | 721 /* Reconstruction */ |
1666 | 722 rec_intradc[i] = scale*level + pred_dc; |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
723 /* Oddify */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
724 rec_intradc[i] |= 1; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
725 //if ((rec_intradc[i] % 2) == 0) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
726 // rec_intradc[i]++; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
727 /* Clipping */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
728 if (rec_intradc[i] < 0) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
729 rec_intradc[i] = 0; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
730 else if (rec_intradc[i] > 2047) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
731 rec_intradc[i] = 2047; |
2967 | 732 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
733 /* Update AC/DC tables */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
734 *dc_ptr[i] = rec_intradc[i]; |
1666 | 735 if (s->block_last_index[i] >= 0) |
736 cbp |= 1 << (5 - i); | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
737 } |
1666 | 738 }else{ |
739 for(i=0; i<6; i++) { | |
740 /* compute cbp */ | |
741 if (s->block_last_index[i] >= 1) | |
742 cbp |= 1 << (5 - i); | |
743 } | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
744 } |
0 | 745 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
746 cbpc = cbp & 3; |
6481 | 747 if (s->pict_type == FF_I_TYPE) { |
695 | 748 if(s->dquant) cbpc+=4; |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
749 put_bits(&s->pb, |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
750 ff_h263_intra_MCBPC_bits[cbpc], |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
751 ff_h263_intra_MCBPC_code[cbpc]); |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
752 } else { |
695 | 753 if(s->dquant) cbpc+=8; |
2979 | 754 put_bits(&s->pb, 1, 0); /* mb coded */ |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
755 put_bits(&s->pb, |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
756 ff_h263_inter_MCBPC_bits[cbpc + 4], |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
757 ff_h263_inter_MCBPC_code[cbpc + 4]); |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
758 } |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
759 if (s->h263_aic) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
760 /* XXX: currently, we do not try to use ac prediction */ |
2979 | 761 put_bits(&s->pb, 1, 0); /* no AC prediction */ |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
762 } |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
763 cbpy = cbp >> 2; |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
764 put_bits(&s->pb, ff_h263_cbpy_tab[cbpy][1], ff_h263_cbpy_tab[cbpy][0]); |
695 | 765 if(s->dquant) |
766 put_bits(&s->pb, 2, dquant_code[s->dquant+2]); | |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
767 |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
768 if(interleaved_stats){ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
769 s->misc_bits+= get_bits_diff(s); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
770 } |
0 | 771 } |
772 | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
773 for(i=0; i<6; i++) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
774 /* encode each block */ |
1354 | 775 h263_encode_block(s, block[i], i); |
2967 | 776 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
777 /* Update INTRADC for decoding */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
778 if (s->h263_aic && s->mb_intra) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
779 block[i][0] = rec_intradc[i]; |
2967 | 780 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
781 } |
0 | 782 } |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
783 |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
784 if(interleaved_stats){ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
785 if (!s->mb_intra) { |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
786 s->p_tex_bits+= get_bits_diff(s); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
787 s->f_count++; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
788 }else{ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
789 s->i_tex_bits+= get_bits_diff(s); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
790 s->i_count++; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
791 } |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
792 } |
0 | 793 } |
815
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
770
diff
changeset
|
794 #endif |
0 | 795 |
1656 | 796 void ff_h263_loop_filter(MpegEncContext * s){ |
1644 | 797 int qp_c; |
798 const int linesize = s->linesize; | |
799 const int uvlinesize= s->uvlinesize; | |
800 const int xy = s->mb_y * s->mb_stride + s->mb_x; | |
801 uint8_t *dest_y = s->dest[0]; | |
802 uint8_t *dest_cb= s->dest[1]; | |
803 uint8_t *dest_cr= s->dest[2]; | |
2967 | 804 |
6481 | 805 // if(s->pict_type==FF_B_TYPE && !s->readable) return; |
1644 | 806 |
807 /* | |
808 Diag Top | |
809 Left Center | |
810 */ | |
811 if(!IS_SKIP(s->current_picture.mb_type[xy])){ | |
812 qp_c= s->qscale; | |
813 s->dsp.h263_v_loop_filter(dest_y+8*linesize , linesize, qp_c); | |
814 s->dsp.h263_v_loop_filter(dest_y+8*linesize+8, linesize, qp_c); | |
815 }else | |
816 qp_c= 0; | |
817 | |
818 if(s->mb_y){ | |
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
819 int qp_dt, qp_tt, qp_tc; |
1644 | 820 |
821 if(IS_SKIP(s->current_picture.mb_type[xy-s->mb_stride])) | |
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
822 qp_tt=0; |
2967 | 823 else |
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
824 qp_tt= s->current_picture.qscale_table[xy-s->mb_stride]; |
1644 | 825 |
2967 | 826 if(qp_c) |
1644 | 827 qp_tc= qp_c; |
828 else | |
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
829 qp_tc= qp_tt; |
2967 | 830 |
1644 | 831 if(qp_tc){ |
832 const int chroma_qp= s->chroma_qscale_table[qp_tc]; | |
833 s->dsp.h263_v_loop_filter(dest_y , linesize, qp_tc); | |
834 s->dsp.h263_v_loop_filter(dest_y+8, linesize, qp_tc); | |
2967 | 835 |
1644 | 836 s->dsp.h263_v_loop_filter(dest_cb , uvlinesize, chroma_qp); |
837 s->dsp.h263_v_loop_filter(dest_cr , uvlinesize, chroma_qp); | |
838 } | |
2967 | 839 |
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
840 if(qp_tt) |
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
841 s->dsp.h263_h_loop_filter(dest_y-8*linesize+8 , linesize, qp_tt); |
2967 | 842 |
1644 | 843 if(s->mb_x){ |
8297
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
844 if(qp_tt || IS_SKIP(s->current_picture.mb_type[xy-1-s->mb_stride])) |
20e0f0809b27
s/qp_t/qp_tt/ to avoid bad examples that could lead to issues with reserved
michael
parents:
8288
diff
changeset
|
845 qp_dt= qp_tt; |
1644 | 846 else |
847 qp_dt= s->current_picture.qscale_table[xy-1-s->mb_stride]; | |
2967 | 848 |
1644 | 849 if(qp_dt){ |
850 const int chroma_qp= s->chroma_qscale_table[qp_dt]; | |
851 s->dsp.h263_h_loop_filter(dest_y -8*linesize , linesize, qp_dt); | |
852 s->dsp.h263_h_loop_filter(dest_cb-8*uvlinesize, uvlinesize, chroma_qp); | |
2178 | 853 s->dsp.h263_h_loop_filter(dest_cr-8*uvlinesize, uvlinesize, chroma_qp); |
1644 | 854 } |
855 } | |
856 } | |
857 | |
858 if(qp_c){ | |
859 s->dsp.h263_h_loop_filter(dest_y +8, linesize, qp_c); | |
860 if(s->mb_y + 1 == s->mb_height) | |
861 s->dsp.h263_h_loop_filter(dest_y+8*linesize+8, linesize, qp_c); | |
862 } | |
2967 | 863 |
1644 | 864 if(s->mb_x){ |
865 int qp_lc; | |
866 if(qp_c || IS_SKIP(s->current_picture.mb_type[xy-1])) | |
867 qp_lc= qp_c; | |
868 else | |
869 qp_lc= s->current_picture.qscale_table[xy-1]; | |
2967 | 870 |
1644 | 871 if(qp_lc){ |
872 s->dsp.h263_h_loop_filter(dest_y, linesize, qp_lc); | |
873 if(s->mb_y + 1 == s->mb_height){ | |
874 const int chroma_qp= s->chroma_qscale_table[qp_lc]; | |
875 s->dsp.h263_h_loop_filter(dest_y +8* linesize, linesize, qp_lc); | |
876 s->dsp.h263_h_loop_filter(dest_cb , uvlinesize, chroma_qp); | |
877 s->dsp.h263_h_loop_filter(dest_cr , uvlinesize, chroma_qp); | |
878 } | |
879 } | |
880 } | |
881 } | |
882 | |
1057 | 883 static void h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n) |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
884 { |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
885 int x, y, wrap, a, c, pred_dc, scale, i; |
3781 | 886 int16_t *dc_val, *ac_val, *ac_val1; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
887 |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
888 /* find prediction */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
889 if (n < 4) { |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
890 x = 2 * s->mb_x + (n & 1); |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
891 y = 2 * s->mb_y + (n>> 1); |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
892 wrap = s->b8_stride; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
893 dc_val = s->dc_val[0]; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
894 ac_val = s->ac_val[0][0]; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
895 scale = s->y_dc_scale; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
896 } else { |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
897 x = s->mb_x; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
898 y = s->mb_y; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
899 wrap = s->mb_stride; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
900 dc_val = s->dc_val[n - 4 + 1]; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
901 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
|
902 scale = s->c_dc_scale; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
903 } |
2967 | 904 |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
905 ac_val += ((y) * wrap + (x)) * 16; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
906 ac_val1 = ac_val; |
2967 | 907 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
908 /* B C |
2967 | 909 * A X |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
910 */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
911 a = dc_val[(x - 1) + (y) * wrap]; |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
912 c = dc_val[(x) + (y - 1) * wrap]; |
2967 | 913 |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
346
diff
changeset
|
914 /* No prediction outside GOB boundary */ |
1639 | 915 if(s->first_slice_line && n!=3){ |
916 if(n!=2) c= 1024; | |
917 if(n!=1 && s->mb_x == s->resync_mb_x) a= 1024; | |
918 } | |
2967 | 919 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
920 if (s->ac_pred) { |
1639 | 921 pred_dc = 1024; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
922 if (s->h263_aic_dir) { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
923 /* left prediction */ |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
924 if (a != 1024) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
925 ac_val -= 16; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
926 for(i=1;i<8;i++) { |
1092 | 927 block[s->dsp.idct_permutation[i<<3]] += ac_val[i]; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
928 } |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
929 pred_dc = a; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
930 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
931 } else { |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
932 /* top prediction */ |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
933 if (c != 1024) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
934 ac_val -= 16 * wrap; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
935 for(i=1;i<8;i++) { |
1092 | 936 block[s->dsp.idct_permutation[i ]] += ac_val[i + 8]; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
937 } |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
938 pred_dc = c; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
939 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
940 } |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
941 } else { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
942 /* just DC prediction */ |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
943 if (a != 1024 && c != 1024) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
944 pred_dc = (a + c) >> 1; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
945 else if (a != 1024) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
946 pred_dc = a; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
947 else |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
948 pred_dc = c; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
949 } |
2967 | 950 |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
951 /* we assume pred is positive */ |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
952 block[0]=block[0]*scale + pred_dc; |
2967 | 953 |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
954 if (block[0] < 0) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
955 block[0] = 0; |
2967 | 956 else |
1639 | 957 block[0] |= 1; |
2967 | 958 |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
959 /* Update AC/DC tables */ |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
960 dc_val[(x) + (y) * wrap] = block[0]; |
2967 | 961 |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
962 /* left copy */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
963 for(i=1;i<8;i++) |
1092 | 964 ac_val1[i ] = block[s->dsp.idct_permutation[i<<3]]; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
965 /* top copy */ |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
966 for(i=1;i<8;i++) |
1092 | 967 ac_val1[8 + i] = block[s->dsp.idct_permutation[i ]]; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
968 } |
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
245
diff
changeset
|
969 |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
970 int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir, |
0 | 971 int *px, int *py) |
972 { | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
973 int wrap; |
1655 | 974 int16_t *A, *B, *C, (*mot_val)[2]; |
975 static const int off[4]= {2, 1, 1, -1}; | |
976 | |
977 wrap = s->b8_stride; | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
978 mot_val = s->current_picture.motion_val[dir] + s->block_index[block]; |
1655 | 979 |
980 A = mot_val[ - 1]; | |
981 /* special case for first (slice) line */ | |
982 if (s->first_slice_line && block<3) { | |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
983 // we can't just change some MVs to simulate that as we need them for the B frames (and ME) |
1655 | 984 // and if we ever support non rectangular objects than we need to do a few ifs here anyway :( |
985 if(block==0){ //most common case | |
986 if(s->mb_x == s->resync_mb_x){ //rare | |
987 *px= *py = 0; | |
988 }else if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare | |
989 C = mot_val[off[block] - wrap]; | |
990 if(s->mb_x==0){ | |
991 *px = C[0]; | |
992 *py = C[1]; | |
993 }else{ | |
994 *px = mid_pred(A[0], 0, C[0]); | |
995 *py = mid_pred(A[1], 0, C[1]); | |
996 } | |
997 }else{ | |
998 *px = A[0]; | |
999 *py = A[1]; | |
1000 } | |
1001 }else if(block==1){ | |
1002 if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare | |
1003 C = mot_val[off[block] - wrap]; | |
1004 *px = mid_pred(A[0], 0, C[0]); | |
1005 *py = mid_pred(A[1], 0, C[1]); | |
1006 }else{ | |
1007 *px = A[0]; | |
1008 *py = A[1]; | |
1009 } | |
1010 }else{ /* block==2*/ | |
1011 B = mot_val[ - wrap]; | |
1012 C = mot_val[off[block] - wrap]; | |
1013 if(s->mb_x == s->resync_mb_x) //rare | |
1014 A[0]=A[1]=0; | |
2967 | 1015 |
1655 | 1016 *px = mid_pred(A[0], B[0], C[0]); |
1017 *py = mid_pred(A[1], B[1], C[1]); | |
1018 } | |
1019 } else { | |
1020 B = mot_val[ - wrap]; | |
1021 C = mot_val[off[block] - wrap]; | |
1022 *px = mid_pred(A[0], B[0], C[0]); | |
1023 *py = mid_pred(A[1], B[1], C[1]); | |
1024 } | |
1025 return *mot_val; | |
1026 } | |
1027 | |
8590 | 1028 #if CONFIG_ENCODERS |
10755
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
1029 |
465c9e1cad02
cosmetics: Move MPEG-4 encoding functions around to avoid forward declarations.
diego
parents:
10754
diff
changeset
|
1030 /***************************************************/ |
2017 | 1031 void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code) |
0 | 1032 { |
702 | 1033 int range, l, bit_size, sign, code, bits; |
0 | 1034 |
1035 if (val == 0) { | |
1036 /* zero vector */ | |
1037 code = 0; | |
1038 put_bits(&s->pb, mvtab[code][1], mvtab[code][0]); | |
1039 } else { | |
324 | 1040 bit_size = f_code - 1; |
0 | 1041 range = 1 << bit_size; |
1042 /* modulo encoding */ | |
2093 | 1043 l= INT_BIT - 6 - bit_size; |
1044 val = (val<<l)>>l; | |
702 | 1045 sign = val>>31; |
1046 val= (val^sign)-sign; | |
1047 sign&=1; | |
2093 | 1048 |
312 | 1049 val--; |
1050 code = (val >> bit_size) + 1; | |
1051 bits = val & (range - 1); | |
0 | 1052 |
2967 | 1053 put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); |
0 | 1054 if (bit_size > 0) { |
1055 put_bits(&s->pb, bit_size, bits); | |
1056 } | |
1057 } | |
1058 } | |
1059 | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1060 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
|
1061 { |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1062 int f_code; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1063 int mv; |
2967 | 1064 |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1065 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
|
1066 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
|
1067 int len; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1068 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1069 if(mv==0) len= mvtab[0][1]; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1070 else{ |
9465
9dcb191f1df3
Remove unused variable in init_mv_penalty_and_fcode() found by CSA.
michael
parents:
9458
diff
changeset
|
1071 int val, bit_size, code; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1072 |
1893
779bdf5063ce
1000000l (using uninitalized variable for initalizing bits per MV table)
michael
parents:
1873
diff
changeset
|
1073 bit_size = f_code - 1; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1074 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1075 val=mv; |
2967 | 1076 if (val < 0) |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1077 val = -val; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1078 val--; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1079 code = (val >> bit_size) + 1; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1080 if(code<33){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1081 len= mvtab[code][1] + 1 + bit_size; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1082 }else{ |
2985 | 1083 len= mvtab[32][1] + av_log2(code>>5) + 2 + bit_size; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1084 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1085 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1086 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1087 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
|
1088 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1089 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1090 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1091 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
|
1092 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
|
1093 fcode_tab[mv+MAX_MV]= f_code; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1094 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1095 } |
287 | 1096 |
1097 for(mv=0; mv<MAX_MV*2+1; mv++){ | |
1098 umv_fcode_tab[mv]= 1; | |
1099 } | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1100 } |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
1101 |
2253 | 1102 static void init_uni_h263_rl_tab(RLTable *rl, uint32_t *bits_tab, uint8_t *len_tab){ |
1103 int slevel, run, last; | |
2967 | 1104 |
2253 | 1105 assert(MAX_LEVEL >= 64); |
1106 assert(MAX_RUN >= 63); | |
1107 | |
1108 for(slevel=-64; slevel<64; slevel++){ | |
1109 if(slevel==0) continue; | |
1110 for(run=0; run<64; run++){ | |
1111 for(last=0; last<=1; last++){ | |
1112 const int index= UNI_MPEG4_ENC_INDEX(last, run, slevel+64); | |
1113 int level= slevel < 0 ? -slevel : slevel; | |
1114 int sign= slevel < 0 ? 1 : 0; | |
1115 int bits, len, code; | |
2967 | 1116 |
2253 | 1117 len_tab[index]= 100; |
2967 | 1118 |
2253 | 1119 /* ESC0 */ |
1120 code= get_rl_index(rl, last, run, level); | |
1121 bits= rl->table_vlc[code][0]; | |
1122 len= rl->table_vlc[code][1]; | |
1123 bits=bits*2+sign; len++; | |
2967 | 1124 |
2253 | 1125 if(code!=rl->n && len < len_tab[index]){ |
1126 if(bits_tab) bits_tab[index]= bits; | |
1127 len_tab [index]= len; | |
1128 } | |
1129 /* ESC */ | |
1130 bits= rl->table_vlc[rl->n][0]; | |
1131 len = rl->table_vlc[rl->n][1]; | |
1132 bits=bits*2+last; len++; | |
1133 bits=bits*64+run; len+=6; | |
1134 bits=bits*256+(level&0xff); len+=8; | |
2967 | 1135 |
2253 | 1136 if(len < len_tab[index]){ |
1137 if(bits_tab) bits_tab[index]= bits; | |
1138 len_tab [index]= len; | |
1139 } | |
1140 } | |
1141 } | |
1142 } | |
1143 } | |
1144 | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1145 void h263_encode_init(MpegEncContext *s) |
0 | 1146 { |
1147 static int done = 0; | |
1148 | |
1149 if (!done) { | |
1150 done = 1; | |
293 | 1151 |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1152 init_rl(&ff_h263_rl_inter, static_rl_table_store[0]); |
10803 | 1153 init_rl(&rl_intra_aic, static_rl_table_store[1]); |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1154 |
2253 | 1155 init_uni_h263_rl_tab(&rl_intra_aic, NULL, uni_h263_intra_aic_rl_len); |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1156 init_uni_h263_rl_tab(&ff_h263_rl_inter , NULL, uni_h263_inter_rl_len); |
2253 | 1157 |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
274
diff
changeset
|
1158 init_mv_penalty_and_fcode(s); |
0 | 1159 } |
936 | 1160 s->me.mv_penalty= mv_penalty; //FIXME exact table for msmpeg4 & h263p |
2967 | 1161 |
2253 | 1162 s->intra_ac_vlc_length =s->inter_ac_vlc_length = uni_h263_inter_rl_len; |
1163 s->intra_ac_vlc_last_length=s->inter_ac_vlc_last_length= uni_h263_inter_rl_len + 128*64; | |
1164 if(s->h263_aic){ | |
1165 s->intra_ac_vlc_length = uni_h263_intra_aic_rl_len; | |
1166 s->intra_ac_vlc_last_length= uni_h263_intra_aic_rl_len + 128*64; | |
1167 } | |
1168 s->ac_esc_length= 7+1+6+8; | |
1169 | |
287 | 1170 // use fcodes >1 only for mpeg4 & h263 & h263p FIXME |
344 | 1171 switch(s->codec_id){ |
1172 case CODEC_ID_MPEG4: | |
1173 s->fcode_tab= fcode_tab; | |
1174 break; | |
1175 case CODEC_ID_H263P: | |
1666 | 1176 if(s->umvplus) |
1177 s->fcode_tab= umv_fcode_tab; | |
1178 if(s->modified_quant){ | |
1179 s->min_qcoeff= -2047; | |
1180 s->max_qcoeff= 2047; | |
1181 }else{ | |
1182 s->min_qcoeff= -127; | |
1183 s->max_qcoeff= 127; | |
1184 } | |
344 | 1185 break; |
2967 | 1186 //Note for mpeg4 & h263 the dc-scale table will be set per frame as needed later |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1187 case CODEC_ID_FLV1: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1188 if (s->h263_flv > 1) { |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1189 s->min_qcoeff= -1023; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1190 s->max_qcoeff= 1023; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1191 } else { |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1192 s->min_qcoeff= -127; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1193 s->max_qcoeff= 127; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1194 } |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1195 s->y_dc_scale_table= |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1196 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1350
diff
changeset
|
1197 break; |
2646
c735e3e60ca7
Even More spelling errors. patch by (Kevin Baragona <kevinmb500 gawab com)
michael
parents:
2639
diff
changeset
|
1198 default: //nothing needed - default table already set in mpegvideo.c |
1089 | 1199 s->min_qcoeff= -127; |
344 | 1200 s->max_qcoeff= 127; |
498 | 1201 s->y_dc_scale_table= |
1202 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
344 | 1203 } |
0 | 1204 } |
1070
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
1205 #endif //CONFIG_ENCODERS |
6da5ae9ee199
more #ifdef CONFIG_ENCODERS patch by (Wolfgang Hesseler <qv at multimediaware dot com>) with modifications by me (s/WOLFGANG/CONFIG_ENCODERS/ and some other fixes)
michaelni
parents:
1068
diff
changeset
|
1206 |
0 | 1207 /***********************************************/ |
1208 /* decoding */ | |
1209 | |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1210 VLC ff_h263_intra_MCBPC_vlc; |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1211 VLC ff_h263_inter_MCBPC_vlc; |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1212 VLC ff_h263_cbpy_vlc; |
0 | 1213 static VLC mv_vlc; |
1655 | 1214 static VLC h263_mbtype_b_vlc; |
1215 static VLC cbpc_b_vlc; | |
0 | 1216 |
1217 /* init vlcs */ | |
1218 | |
1219 /* XXX: find a better solution to handle static init */ | |
1220 void h263_decode_init_vlc(MpegEncContext *s) | |
1221 { | |
1222 static int done = 0; | |
1223 | |
1224 if (!done) { | |
1225 done = 1; | |
1226 | |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1227 INIT_VLC_STATIC(&ff_h263_intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 9, |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1228 ff_h263_intra_MCBPC_bits, 1, 1, |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1229 ff_h263_intra_MCBPC_code, 1, 1, 72); |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1230 INIT_VLC_STATIC(&ff_h263_inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 28, |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1231 ff_h263_inter_MCBPC_bits, 1, 1, |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1232 ff_h263_inter_MCBPC_code, 1, 1, 198); |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1233 INIT_VLC_STATIC(&ff_h263_cbpy_vlc, CBPY_VLC_BITS, 16, |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1234 &ff_h263_cbpy_tab[0][1], 2, 1, |
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1235 &ff_h263_cbpy_tab[0][0], 2, 1, 64); |
7098 | 1236 INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 33, |
0 | 1237 &mvtab[0][1], 2, 1, |
7098 | 1238 &mvtab[0][0], 2, 1, 538); |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1239 init_rl(&ff_h263_rl_inter, static_rl_table_store[0]); |
10803 | 1240 init_rl(&rl_intra_aic, static_rl_table_store[1]); |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1241 INIT_VLC_RL(ff_h263_rl_inter, 554); |
6940
778ecab25dd8
Change init_vlc_rl() so it does not use *alloc_static() anymore.
michael
parents:
6918
diff
changeset
|
1242 INIT_VLC_RL(rl_intra_aic, 554); |
7098 | 1243 INIT_VLC_STATIC(&h263_mbtype_b_vlc, H263_MBTYPE_B_VLC_BITS, 15, |
1655 | 1244 &h263_mbtype_b_tab[0][1], 2, 1, |
7098 | 1245 &h263_mbtype_b_tab[0][0], 2, 1, 80); |
1246 INIT_VLC_STATIC(&cbpc_b_vlc, CBPC_B_VLC_BITS, 4, | |
1655 | 1247 &cbpc_b_tab[0][1], 2, 1, |
7098 | 1248 &cbpc_b_tab[0][0], 2, 1, 8); |
0 | 1249 } |
1250 } | |
1251 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1252 /** |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1253 * Get the GOB height based on picture height. |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1254 */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1255 int ff_h263_get_gob_height(MpegEncContext *s){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1256 if (s->height <= 400) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1257 return 1; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1258 else if (s->height <= 800) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1259 return 2; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1260 else |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1261 return 4; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1262 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1263 |
1661 | 1264 int ff_h263_decode_mba(MpegEncContext *s) |
1265 { | |
1266 int i, mb_pos; | |
1267 | |
1268 for(i=0; i<6; i++){ | |
1670 | 1269 if(s->mb_num-1 <= ff_mba_max[i]) break; |
1661 | 1270 } |
1271 mb_pos= get_bits(&s->gb, ff_mba_length[i]); | |
1272 s->mb_x= mb_pos % s->mb_width; | |
1273 s->mb_y= mb_pos / s->mb_width; | |
1274 | |
1275 return mb_pos; | |
1276 } | |
1277 | |
1278 void ff_h263_encode_mba(MpegEncContext *s) | |
1279 { | |
1280 int i, mb_pos; | |
1281 | |
1282 for(i=0; i<6; i++){ | |
1670 | 1283 if(s->mb_num-1 <= ff_mba_max[i]) break; |
1661 | 1284 } |
1285 mb_pos= s->mb_x + s->mb_width*s->mb_y; | |
1286 put_bits(&s->pb, ff_mba_length[i], mb_pos); | |
1287 } | |
1288 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1289 /** |
1661 | 1290 * decodes the group of blocks header or slice header. |
6524 | 1291 * @return <0 if an error occurred |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1292 */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1293 static int h263_decode_gob_header(MpegEncContext *s) |
162 | 1294 { |
1661 | 1295 unsigned int val, gfid, gob_number; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1296 int left; |
2967 | 1297 |
162 | 1298 /* Check for GOB Start Code */ |
1299 val = show_bits(&s->gb, 16); | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1300 if(val) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1301 return -1; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1302 |
162 | 1303 /* We have a GBSC probably with GSTUFF */ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1304 skip_bits(&s->gb, 16); /* Drop the zeros */ |
10535
95f3daa991a2
Use get_bits_left() instead of size_in_bits - get_bits_count().
rbultje
parents:
9999
diff
changeset
|
1305 left= get_bits_left(&s->gb); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1306 //MN: we must check the bits left or we might end in a infinite loop (or segfault) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1307 for(;left>13; left--){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1308 if(get_bits1(&s->gb)) break; /* Seek the '1' bit */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1309 } |
2967 | 1310 if(left<=13) |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1311 return -1; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1312 |
1661 | 1313 if(s->h263_slice_structured){ |
1314 if(get_bits1(&s->gb)==0) | |
1315 return -1; | |
1316 | |
1317 ff_h263_decode_mba(s); | |
1318 | |
1319 if(s->mb_num > 1583) | |
1320 if(get_bits1(&s->gb)==0) | |
1321 return -1; | |
2967 | 1322 |
1661 | 1323 s->qscale = get_bits(&s->gb, 5); /* SQUANT */ |
1324 if(get_bits1(&s->gb)==0) | |
1325 return -1; | |
1326 gfid = get_bits(&s->gb, 2); /* GFID */ | |
1327 }else{ | |
1328 gob_number = get_bits(&s->gb, 5); /* GN */ | |
1329 s->mb_x= 0; | |
1330 s->mb_y= s->gob_index* gob_number; | |
1331 gfid = get_bits(&s->gb, 2); /* GFID */ | |
1332 s->qscale = get_bits(&s->gb, 5); /* GQUANT */ | |
1333 } | |
2967 | 1334 |
1335 if(s->mb_y >= s->mb_height) | |
1661 | 1336 return -1; |
1337 | |
2967 | 1338 if(s->qscale==0) |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1339 return -1; |
1644 | 1340 |
162 | 1341 return 0; |
1342 } | |
1343 | |
290 | 1344 static inline void memsetw(short *tab, int val, int n) |
1345 { | |
1346 int i; | |
1347 for(i=0;i<n;i++) | |
1348 tab[i] = val; | |
1349 } | |
1350 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1351 /** |
9024
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1352 * finds the next resync_marker |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1353 * @param p pointer to buffer to scan |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1354 * @param end pointer to the end of the buffer |
10759
2bcd7a44350f
Remove residual use of the doxygen markup which is deprecated,
stefano
parents:
10755
diff
changeset
|
1355 * @return pointer to the next resync_marker, or end if none was found |
9024
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1356 */ |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1357 const uint8_t *ff_h263_find_resync_marker(const uint8_t *restrict p, const uint8_t * restrict end) |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1358 { |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1359 assert(p < end); |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1360 |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1361 end-=2; |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1362 p++; |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1363 for(;p<end; p+=2){ |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1364 if(!*p){ |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1365 if (!p[-1] && p[1]) return p - 1; |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1366 else if(!p[ 1] && p[2]) return p; |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1367 } |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1368 } |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1369 return end+2; |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1370 } |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1371 |
2bf694251330
Add ff_h263_find_resync_marker() to find the bit position of the next resync_marker, if any.
michael
parents:
9008
diff
changeset
|
1372 /** |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1373 * decodes the group of blocks / video packet header. |
8691
25aa5388fa97
Make ff_h263_resync() return the bit position of the resync_marker or
benoit
parents:
8690
diff
changeset
|
1374 * @return bit position of the resync_marker, or <0 if none was found |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1375 */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1376 int ff_h263_resync(MpegEncContext *s){ |
8691
25aa5388fa97
Make ff_h263_resync() return the bit position of the resync_marker or
benoit
parents:
8690
diff
changeset
|
1377 int left, pos, ret; |
2967 | 1378 |
1521 | 1379 if(s->codec_id==CODEC_ID_MPEG4){ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1380 skip_bits1(&s->gb); |
1521 | 1381 align_get_bits(&s->gb); |
1382 } | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1383 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1384 if(show_bits(&s->gb, 16)==0){ |
8691
25aa5388fa97
Make ff_h263_resync() return the bit position of the resync_marker or
benoit
parents:
8690
diff
changeset
|
1385 pos= get_bits_count(&s->gb); |
10804
c03a8c6c755b
Add a few CONFIG_MPEG4_DECODER that should be there.
michael
parents:
10803
diff
changeset
|
1386 if(CONFIG_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4) |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1387 ret= mpeg4_decode_video_packet_header(s); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1388 else |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1389 ret= h263_decode_gob_header(s); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1390 if(ret>=0) |
8691
25aa5388fa97
Make ff_h263_resync() return the bit position of the resync_marker or
benoit
parents:
8690
diff
changeset
|
1391 return pos; |
453 | 1392 } |
5129 | 1393 //OK, it's not where it is supposed to be ... |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1394 s->gb= s->last_resync_gb; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1395 align_get_bits(&s->gb); |
10535
95f3daa991a2
Use get_bits_left() instead of size_in_bits - get_bits_count().
rbultje
parents:
9999
diff
changeset
|
1396 left= get_bits_left(&s->gb); |
2967 | 1397 |
1398 for(;left>16+1+5+5; left-=8){ | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1399 if(show_bits(&s->gb, 16)==0){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1400 GetBitContext bak= s->gb; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1401 |
8691
25aa5388fa97
Make ff_h263_resync() return the bit position of the resync_marker or
benoit
parents:
8690
diff
changeset
|
1402 pos= get_bits_count(&s->gb); |
10804
c03a8c6c755b
Add a few CONFIG_MPEG4_DECODER that should be there.
michael
parents:
10803
diff
changeset
|
1403 if(CONFIG_MPEG4_DECODER && s->codec_id==CODEC_ID_MPEG4) |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1404 ret= mpeg4_decode_video_packet_header(s); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1405 else |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1406 ret= h263_decode_gob_header(s); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1407 if(ret>=0) |
8691
25aa5388fa97
Make ff_h263_resync() return the bit position of the resync_marker or
benoit
parents:
8690
diff
changeset
|
1408 return pos; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1409 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1410 s->gb= bak; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1411 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1412 skip_bits(&s->gb, 8); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1413 } |
2967 | 1414 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1415 return -1; |
453 | 1416 } |
1417 | |
10803 | 1418 int h263_decode_motion(MpegEncContext * s, int pred, int f_code) |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1419 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1420 int code, val, sign, shift, l; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1421 code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1422 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1423 if (code == 0) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1424 return pred; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1425 if (code < 0) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1426 return 0xffff; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1427 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1428 sign = get_bits1(&s->gb); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1429 shift = f_code - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1430 val = code; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1431 if (shift) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1432 val = (val - 1) << shift; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1433 val |= get_bits(&s->gb, shift); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1434 val++; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1435 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1436 if (sign) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1437 val = -val; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1438 val += pred; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1439 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1440 /* modulo decoding */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1441 if (!s->h263_long_vectors) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1442 l = INT_BIT - 5 - f_code; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1443 val = (val<<l)>>l; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1444 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1445 /* horrible h263 long vector mode */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1446 if (pred < -31 && val < -63) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1447 val += 64; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1448 if (pred > 32 && val > 63) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1449 val -= 64; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1450 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1451 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1452 return val; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1453 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1454 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1455 |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1456 /* Decodes RVLC of H.263+ UMV */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1457 static int h263p_decode_umotion(MpegEncContext * s, int pred) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1458 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1459 int code = 0, sign; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1460 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1461 if (get_bits1(&s->gb)) /* Motion difference = 0 */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1462 return pred; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1463 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1464 code = 2 + get_bits1(&s->gb); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1465 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1466 while (get_bits1(&s->gb)) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1467 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1468 code <<= 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1469 code += get_bits1(&s->gb); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1470 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1471 sign = code & 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1472 code >>= 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1473 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1474 code = (sign) ? (pred - code) : (pred + code); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1475 dprintf(s->avctx,"H.263+ UMV Motion = %d\n", code); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1476 return code; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1477 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1478 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1479 |
1633 | 1480 /** |
1481 * read the next MVs for OBMC. yes this is a ugly hack, feel free to send a patch :) | |
1482 */ | |
1483 static void preview_obmc(MpegEncContext *s){ | |
1484 GetBitContext gb= s->gb; | |
2967 | 1485 |
1633 | 1486 int cbpc, i, pred_x, pred_y, mx, my; |
1487 int16_t *mot_val; | |
1488 const int xy= s->mb_x + 1 + s->mb_y * s->mb_stride; | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
1489 const int stride= s->b8_stride*2; |
2967 | 1490 |
1633 | 1491 for(i=0; i<4; i++) |
1492 s->block_index[i]+= 2; | |
1493 for(i=4; i<6; i++) | |
1494 s->block_index[i]+= 1; | |
1495 s->mb_x++; | |
2967 | 1496 |
6481 | 1497 assert(s->pict_type == FF_P_TYPE); |
1633 | 1498 |
1499 do{ | |
1500 if (get_bits1(&s->gb)) { | |
1501 /* skip mb */ | |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1666
diff
changeset
|
1502 mot_val = s->current_picture.motion_val[0][ s->block_index[0] ]; |
2967 | 1503 mot_val[0 ]= mot_val[2 ]= |
1633 | 1504 mot_val[0+stride]= mot_val[2+stride]= 0; |
1505 mot_val[1 ]= mot_val[3 ]= | |
1506 mot_val[1+stride]= mot_val[3+stride]= 0; | |
2967 | 1507 |
1633 | 1508 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; |
1509 goto end; | |
1510 } | |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1511 cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); |
1633 | 1512 }while(cbpc == 20); |
2967 | 1513 |
1633 | 1514 if(cbpc & 4){ |
1515 s->current_picture.mb_type[xy]= MB_TYPE_INTRA; | |
1516 }else{ | |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1517 get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); |
1633 | 1518 if (cbpc & 8) { |
1656 | 1519 if(s->modified_quant){ |
1520 if(get_bits1(&s->gb)) skip_bits(&s->gb, 1); | |
1521 else skip_bits(&s->gb, 5); | |
1522 }else | |
1523 skip_bits(&s->gb, 2); | |
1633 | 1524 } |
2967 | 1525 |
1633 | 1526 if ((cbpc & 16) == 0) { |
2967 | 1527 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; |
1633 | 1528 /* 16x16 motion prediction */ |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
1529 mot_val= h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
1633 | 1530 if (s->umvplus) |
1531 mx = h263p_decode_umotion(s, pred_x); | |
1532 else | |
1655 | 1533 mx = h263_decode_motion(s, pred_x, 1); |
2967 | 1534 |
1633 | 1535 if (s->umvplus) |
1536 my = h263p_decode_umotion(s, pred_y); | |
1537 else | |
1655 | 1538 my = h263_decode_motion(s, pred_y, 1); |
2967 | 1539 |
1540 mot_val[0 ]= mot_val[2 ]= | |
1633 | 1541 mot_val[0+stride]= mot_val[2+stride]= mx; |
1542 mot_val[1 ]= mot_val[3 ]= | |
1543 mot_val[1+stride]= mot_val[3+stride]= my; | |
1544 } else { | |
2967 | 1545 s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; |
1633 | 1546 for(i=0;i<4;i++) { |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
1547 mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); |
1633 | 1548 if (s->umvplus) |
1549 mx = h263p_decode_umotion(s, pred_x); | |
1550 else | |
1655 | 1551 mx = h263_decode_motion(s, pred_x, 1); |
2967 | 1552 |
1633 | 1553 if (s->umvplus) |
1554 my = h263p_decode_umotion(s, pred_y); | |
2967 | 1555 else |
1655 | 1556 my = h263_decode_motion(s, pred_y, 1); |
1633 | 1557 if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
1558 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ | |
1559 mot_val[0] = mx; | |
1560 mot_val[1] = my; | |
1561 } | |
1562 } | |
1563 } | |
1564 end: | |
2967 | 1565 |
1633 | 1566 for(i=0; i<4; i++) |
1567 s->block_index[i]-= 2; | |
1568 for(i=4; i<6; i++) | |
1569 s->block_index[i]-= 1; | |
1570 s->mb_x--; | |
1571 | |
1572 s->gb= gb; | |
1573 } | |
1574 | |
1656 | 1575 static void h263_decode_dquant(MpegEncContext *s){ |
1576 static const int8_t quant_tab[4] = { -1, -2, 1, 2 }; | |
1577 | |
1578 if(s->modified_quant){ | |
1579 if(get_bits1(&s->gb)) | |
1580 s->qscale= modified_quant_tab[get_bits1(&s->gb)][ s->qscale ]; | |
1581 else | |
1582 s->qscale= get_bits(&s->gb, 5); | |
1583 }else | |
1584 s->qscale += quant_tab[get_bits(&s->gb, 2)]; | |
1585 ff_set_qscale(s, s->qscale); | |
1586 } | |
1587 | |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1588 static int h263_decode_block(MpegEncContext * s, DCTELEM * block, |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1589 int n, int coded) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1590 { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1591 int code, level, i, j, last, run; |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1592 RLTable *rl = &ff_h263_rl_inter; |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1593 const uint8_t *scan_table; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1594 GetBitContext gb= s->gb; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1595 |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1596 scan_table = s->intra_scantable.permutated; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1597 if (s->h263_aic && s->mb_intra) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1598 rl = &rl_intra_aic; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1599 i = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1600 if (s->ac_pred) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1601 if (s->h263_aic_dir) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1602 scan_table = s->intra_v_scantable.permutated; /* left */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1603 else |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1604 scan_table = s->intra_h_scantable.permutated; /* top */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1605 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1606 } else if (s->mb_intra) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1607 /* DC coef */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1608 if(s->codec_id == CODEC_ID_RV10){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1609 #if CONFIG_RV10_DECODER |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1610 if (s->rv10_version == 3 && s->pict_type == FF_I_TYPE) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1611 int component, diff; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1612 component = (n <= 3 ? 0 : n - 4 + 1); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1613 level = s->last_dc[component]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1614 if (s->rv10_first_dc_coded[component]) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1615 diff = rv_decode_dc(s, n); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1616 if (diff == 0xffff) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1617 return -1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1618 level += diff; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1619 level = level & 0xff; /* handle wrap round */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1620 s->last_dc[component] = level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1621 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1622 s->rv10_first_dc_coded[component] = 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1623 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1624 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1625 level = get_bits(&s->gb, 8); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1626 if (level == 255) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1627 level = 128; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1628 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1629 #endif |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1630 }else{ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1631 level = get_bits(&s->gb, 8); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1632 if((level&0x7F) == 0){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1633 av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1634 if(s->error_recognition >= FF_ER_COMPLIANT) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1635 return -1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1636 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1637 if (level == 255) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1638 level = 128; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1639 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1640 block[0] = level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1641 i = 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1642 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1643 i = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1644 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1645 if (!coded) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1646 if (s->mb_intra && s->h263_aic) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1647 goto not_coded; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1648 s->block_last_index[n] = i - 1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1649 return 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1650 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1651 retry: |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1652 for(;;) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1653 code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1654 if (code < 0){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1655 av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n", s->mb_x, s->mb_y); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1656 return -1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1657 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1658 if (code == rl->n) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1659 /* escape */ |
10788 | 1660 if (CONFIG_FLV_DECODER && s->h263_flv > 1) { |
1661 ff_flv2_decode_ac_esc(&s->gb, &level, &run, &last); | |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1662 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1663 last = get_bits1(&s->gb); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1664 run = get_bits(&s->gb, 6); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1665 level = (int8_t)get_bits(&s->gb, 8); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1666 if(level == -128){ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1667 if (s->codec_id == CODEC_ID_RV10) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1668 /* XXX: should patch encoder too */ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1669 level = get_sbits(&s->gb, 12); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1670 }else{ |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1671 level = get_bits(&s->gb, 5); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1672 level |= get_sbits(&s->gb, 6)<<5; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1673 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1674 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1675 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1676 } else { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1677 run = rl->table_run[code]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1678 level = rl->table_level[code]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1679 last = code >= rl->last; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1680 if (get_bits1(&s->gb)) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1681 level = -level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1682 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1683 i += run; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1684 if (i >= 64){ |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1685 if(s->alt_inter_vlc && rl == &ff_h263_rl_inter && !s->mb_intra){ |
10752
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1686 //Looks like a hack but no, it's the way it is supposed to work ... |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1687 rl = &rl_intra_aic; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1688 i = 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1689 s->gb= gb; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1690 s->dsp.clear_block(block); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1691 goto retry; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1692 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1693 av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d i:%d\n", s->mb_x, s->mb_y, s->mb_intra); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1694 return -1; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1695 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1696 j = scan_table[i]; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1697 block[j] = level; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1698 if (last) |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1699 break; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1700 i++; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1701 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1702 not_coded: |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1703 if (s->mb_intra && s->h263_aic) { |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1704 h263_pred_acdc(s, block, n); |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1705 i = 63; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1706 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1707 s->block_last_index[n] = i; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1708 return 0; |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1709 } |
56e57dc0fe19
cosmetics: Move H.263-related functions around to avoid forward declarations.
diego
parents:
10726
diff
changeset
|
1710 |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1711 static int h263_skip_b_part(MpegEncContext *s, int cbp) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1712 { |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1713 DECLARE_ALIGNED(16, DCTELEM, dblock[64]); |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1714 int i, mbi; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1715 |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1716 /* we have to set s->mb_intra to zero to decode B-part of PB-frame correctly |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1717 * but real value should be restored in order to be used later (in OBMC condition) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1718 */ |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1719 mbi = s->mb_intra; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1720 s->mb_intra = 0; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1721 for (i = 0; i < 6; i++) { |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1722 if (h263_decode_block(s, dblock, i, cbp&32) < 0) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1723 return -1; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1724 cbp+=cbp; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1725 } |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1726 s->mb_intra = mbi; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1727 return 0; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1728 } |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1729 |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1730 static int h263_get_modb(GetBitContext *gb, int pb_frame, int *cbpb) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1731 { |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1732 int c, mv = 1; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1733 |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1734 if (pb_frame < 3) { // h.263 Annex G and i263 PB-frame |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1735 c = get_bits1(gb); |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1736 if (pb_frame == 2 && c) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1737 mv = !get_bits1(gb); |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1738 } else { // h.263 Annex M improved PB-frame |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1739 mv = get_unary(gb, 0, 4) + 1; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1740 c = mv & 1; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1741 mv = !!(mv & 2); |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1742 } |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1743 if(c) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1744 *cbpb = get_bits(gb, 6); |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1745 return mv; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1746 } |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1747 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1748 int ff_h263_decode_mb(MpegEncContext *s, |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
718
diff
changeset
|
1749 DCTELEM block[6][64]) |
0 | 1750 { |
1751 int cbpc, cbpy, i, cbp, pred_x, pred_y, mx, my, dquant; | |
1064 | 1752 int16_t *mot_val; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
1753 const int xy= s->mb_x + s->mb_y * s->mb_stride; |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1754 int cbpb = 0, pb_mv_count = 0; |
2967 | 1755 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1756 assert(!s->h263_pred); |
2967 | 1757 |
6481 | 1758 if (s->pict_type == FF_P_TYPE) { |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1759 do{ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1760 if (get_bits1(&s->gb)) { |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1761 /* skip mb */ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1762 s->mb_intra = 0; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1763 for(i=0;i<6;i++) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1764 s->block_last_index[i] = -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1765 s->mv_dir = MV_DIR_FORWARD; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1766 s->mv_type = MV_TYPE_16X16; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1176
diff
changeset
|
1767 s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; |
255 | 1768 s->mv[0][0][0] = 0; |
1769 s->mv[0][0][1] = 0; | |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2615
diff
changeset
|
1770 s->mb_skipped = !(s->obmc | s->loop_filter); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1771 goto end; |
255 | 1772 } |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1773 cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1774 if (cbpc < 0){ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1775 av_log(s->avctx, AV_LOG_ERROR, "cbpc damaged at %d %d\n", s->mb_x, s->mb_y); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1776 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1777 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1778 }while(cbpc == 20); |
2967 | 1779 |
2632 | 1780 s->dsp.clear_blocks(s->block[0]); |
2967 | 1781 |
0 | 1782 dquant = cbpc & 8; |
1783 s->mb_intra = ((cbpc & 4) != 0); | |
262 | 1784 if (s->mb_intra) goto intra; |
2967 | 1785 |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1786 if(s->pb_frame && get_bits1(&s->gb)) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1787 pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1788 cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); |
2967 | 1789 |
1637 | 1790 if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) |
1791 cbpy ^= 0xF; | |
2967 | 1792 |
1637 | 1793 cbp = (cbpc & 3) | (cbpy << 2); |
0 | 1794 if (dquant) { |
1656 | 1795 h263_decode_dquant(s); |
0 | 1796 } |
2967 | 1797 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1798 s->mv_dir = MV_DIR_FORWARD; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1799 if ((cbpc & 16) == 0) { |
2967 | 1800 s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1801 /* 16x16 motion prediction */ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1802 s->mv_type = MV_TYPE_16X16; |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
1803 h263_pred_motion(s, 0, 0, &pred_x, &pred_y); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1804 if (s->umvplus) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1805 mx = h263p_decode_umotion(s, pred_x); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1806 else |
1655 | 1807 mx = h263_decode_motion(s, pred_x, 1); |
2967 | 1808 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1809 if (mx >= 0xffff) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1810 return -1; |
2967 | 1811 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1812 if (s->umvplus) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1813 my = h263p_decode_umotion(s, pred_y); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1814 else |
1655 | 1815 my = h263_decode_motion(s, pred_y, 1); |
2967 | 1816 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1817 if (my >= 0xffff) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1818 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1819 s->mv[0][0][0] = mx; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1820 s->mv[0][0][1] = my; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1821 |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1822 if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
2967 | 1823 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1824 } else { |
2967 | 1825 s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1826 s->mv_type = MV_TYPE_8X8; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1827 for(i=0;i<4;i++) { |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
1828 mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1829 if (s->umvplus) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1830 mx = h263p_decode_umotion(s, pred_x); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1831 else |
1655 | 1832 mx = h263_decode_motion(s, pred_x, 1); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1833 if (mx >= 0xffff) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1834 return -1; |
2967 | 1835 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1836 if (s->umvplus) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1837 my = h263p_decode_umotion(s, pred_y); |
2967 | 1838 else |
1655 | 1839 my = h263_decode_motion(s, pred_y, 1); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1840 if (my >= 0xffff) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1841 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1842 s->mv[0][i][0] = mx; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1843 s->mv[0][i][1] = my; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1844 if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1845 skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1846 mot_val[0] = mx; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1847 mot_val[1] = my; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1848 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1849 } |
6481 | 1850 } else if(s->pict_type==FF_B_TYPE) { |
1655 | 1851 int mb_type; |
1852 const int stride= s->b8_stride; | |
1701 | 1853 int16_t *mot_val0 = s->current_picture.motion_val[0][ 2*(s->mb_x + s->mb_y*stride) ]; |
1854 int16_t *mot_val1 = s->current_picture.motion_val[1][ 2*(s->mb_x + s->mb_y*stride) ]; | |
1655 | 1855 // const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride; |
1856 | |
2967 | 1857 //FIXME ugly |
1858 mot_val0[0 ]= mot_val0[2 ]= mot_val0[0+2*stride]= mot_val0[2+2*stride]= | |
1859 mot_val0[1 ]= mot_val0[3 ]= mot_val0[1+2*stride]= mot_val0[3+2*stride]= | |
1860 mot_val1[0 ]= mot_val1[2 ]= mot_val1[0+2*stride]= mot_val1[2+2*stride]= | |
1701 | 1861 mot_val1[1 ]= mot_val1[3 ]= mot_val1[1+2*stride]= mot_val1[3+2*stride]= 0; |
1655 | 1862 |
1863 do{ | |
1864 mb_type= get_vlc2(&s->gb, h263_mbtype_b_vlc.table, H263_MBTYPE_B_VLC_BITS, 2); | |
1865 if (mb_type < 0){ | |
1866 av_log(s->avctx, AV_LOG_ERROR, "b mb_type damaged at %d %d\n", s->mb_x, s->mb_y); | |
1867 return -1; | |
1868 } | |
1869 | |
1870 mb_type= h263_mb_type_b_map[ mb_type ]; | |
1871 }while(!mb_type); | |
1872 | |
1873 s->mb_intra = IS_INTRA(mb_type); | |
1874 if(HAS_CBP(mb_type)){ | |
2632 | 1875 s->dsp.clear_blocks(s->block[0]); |
1655 | 1876 cbpc = get_vlc2(&s->gb, cbpc_b_vlc.table, CBPC_B_VLC_BITS, 1); |
1877 if(s->mb_intra){ | |
1878 dquant = IS_QUANT(mb_type); | |
1879 goto intra; | |
1880 } | |
1881 | |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1882 cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); |
1655 | 1883 |
1884 if (cbpy < 0){ | |
1885 av_log(s->avctx, AV_LOG_ERROR, "b cbpy damaged at %d %d\n", s->mb_x, s->mb_y); | |
1886 return -1; | |
1887 } | |
2967 | 1888 |
1655 | 1889 if(s->alt_inter_vlc==0 || (cbpc & 3)!=3) |
1890 cbpy ^= 0xF; | |
2967 | 1891 |
1655 | 1892 cbp = (cbpc & 3) | (cbpy << 2); |
1893 }else | |
1894 cbp=0; | |
2967 | 1895 |
1655 | 1896 assert(!s->mb_intra); |
1897 | |
1898 if(IS_QUANT(mb_type)){ | |
1656 | 1899 h263_decode_dquant(s); |
1655 | 1900 } |
1901 | |
1902 if(IS_DIRECT(mb_type)){ | |
1903 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
1904 mb_type |= ff_mpeg4_set_direct_mv(s, 0, 0); | |
1905 }else{ | |
1906 s->mv_dir = 0; | |
1907 s->mv_type= MV_TYPE_16X16; | |
1908 //FIXME UMV | |
1909 | |
1910 if(USES_LIST(mb_type, 0)){ | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
1911 int16_t *mot_val= h263_pred_motion(s, 0, 0, &mx, &my); |
1655 | 1912 s->mv_dir = MV_DIR_FORWARD; |
1913 | |
1914 mx = h263_decode_motion(s, mx, 1); | |
1915 my = h263_decode_motion(s, my, 1); | |
2967 | 1916 |
1655 | 1917 s->mv[0][0][0] = mx; |
1918 s->mv[0][0][1] = my; | |
1701 | 1919 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; |
1920 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; | |
1655 | 1921 } |
2967 | 1922 |
1655 | 1923 if(USES_LIST(mb_type, 1)){ |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1936
diff
changeset
|
1924 int16_t *mot_val= h263_pred_motion(s, 0, 1, &mx, &my); |
1655 | 1925 s->mv_dir |= MV_DIR_BACKWARD; |
2967 | 1926 |
1655 | 1927 mx = h263_decode_motion(s, mx, 1); |
1928 my = h263_decode_motion(s, my, 1); | |
1701 | 1929 |
1655 | 1930 s->mv[1][0][0] = mx; |
1931 s->mv[1][0][1] = my; | |
1701 | 1932 mot_val[0 ]= mot_val[2 ]= mot_val[0+2*stride]= mot_val[2+2*stride]= mx; |
1933 mot_val[1 ]= mot_val[3 ]= mot_val[1+2*stride]= mot_val[3+2*stride]= my; | |
1655 | 1934 } |
1935 } | |
2967 | 1936 |
1655 | 1937 s->current_picture.mb_type[xy]= mb_type; |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1938 } else { /* I-Frame */ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1939 do{ |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1940 cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1941 if (cbpc < 0){ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1942 av_log(s->avctx, AV_LOG_ERROR, "I cbpc damaged at %d %d\n", s->mb_x, s->mb_y); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1943 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1944 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1945 }while(cbpc == 8); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1946 |
2632 | 1947 s->dsp.clear_blocks(s->block[0]); |
1948 | |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1949 dquant = cbpc & 4; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1950 s->mb_intra = 1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1951 intra: |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1952 s->current_picture.mb_type[xy]= MB_TYPE_INTRA; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1953 if (s->h263_aic) { |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1954 s->ac_pred = get_bits1(&s->gb); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1955 if(s->ac_pred){ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1956 s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED; |
2967 | 1957 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1958 s->h263_aic_dir = get_bits1(&s->gb); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1959 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1960 }else |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1961 s->ac_pred = 0; |
2967 | 1962 |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1963 if(s->pb_frame && get_bits1(&s->gb)) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1964 pb_mv_count = h263_get_modb(&s->gb, s->pb_frame, &cbpb); |
10818
514dc1c87b2e
Rename most non static h263 tables so their name contains h263.
michael
parents:
10804
diff
changeset
|
1965 cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1966 if(cbpy<0){ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1967 av_log(s->avctx, AV_LOG_ERROR, "I cbpy damaged at %d %d\n", s->mb_x, s->mb_y); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1968 return -1; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1969 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1970 cbp = (cbpc & 3) | (cbpy << 2); |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1971 if (dquant) { |
1656 | 1972 h263_decode_dquant(s); |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1973 } |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1974 |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1975 pb_mv_count += !!s->pb_frame; |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1976 } |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1977 |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1978 while(pb_mv_count--){ |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1979 h263_decode_motion(s, 0, 1); |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1980 h263_decode_motion(s, 0, 1); |
9093 | 1981 } |
1982 | |
1983 /* decode each block */ | |
1984 for (i = 0; i < 6; i++) { | |
1985 if (h263_decode_block(s, block[i], i, cbp&32) < 0) | |
1986 return -1; | |
1987 cbp+=cbp; | |
1988 } | |
1989 | |
9103
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1990 if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0) |
b626fed816d7
Add PB-frame decoding support for H.263/i263 (and enable it for i263)
kostya
parents:
9093
diff
changeset
|
1991 return -1; |
9093 | 1992 if(s->obmc && !s->mb_intra){ |
1993 if(s->pict_type == FF_P_TYPE && s->mb_x+1<s->mb_width && s->mb_num_left != 1) | |
1994 preview_obmc(s); | |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1995 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1996 end: |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1997 |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1998 /* per-MB end of slice check */ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
1999 { |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
2000 int v= show_bits(&s->gb, 16); |
2967 | 2001 |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
2002 if(get_bits_count(&s->gb) + 16 > s->gb.size_in_bits){ |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
2003 v>>= get_bits_count(&s->gb) + 16 - s->gb.size_in_bits; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
2004 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
2005 |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
2006 if(v==0) |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
2007 return SLICE_END; |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
2008 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
2009 |
2967 | 2010 return SLICE_OK; |
1649
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
2011 } |
e6a474a5b929
split ff_h263_decode_mb() into h263 and mpeg4 versions
michael
parents:
1646
diff
changeset
|
2012 |
0 | 2013 /* most is hardcoded. should extend to handle all h263 streams */ |
2014 int h263_decode_picture_header(MpegEncContext *s) | |
2015 { | |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2016 int format, width, height, i; |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2017 uint32_t startcode; |
2967 | 2018 |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2019 align_get_bits(&s->gb); |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2020 |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2021 startcode= get_bits(&s->gb, 22-8); |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2022 |
10535
95f3daa991a2
Use get_bits_left() instead of size_in_bits - get_bits_count().
rbultje
parents:
9999
diff
changeset
|
2023 for(i= get_bits_left(&s->gb); i>24; i-=8) { |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2024 startcode = ((startcode << 8) | get_bits(&s->gb, 8)) & 0x003FFFFF; |
2967 | 2025 |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2026 if(startcode == 0x20) |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2027 break; |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2028 } |
2967 | 2029 |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2030 if (startcode != 0x20) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
2031 av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); |
0 | 2032 return -1; |
355 | 2033 } |
2034 /* temporal reference */ | |
1865 | 2035 i = get_bits(&s->gb, 8); /* picture timestamp */ |
2036 if( (s->picture_number&~0xFF)+i < s->picture_number) | |
2037 i+= 256; | |
2886 | 2038 s->current_picture_ptr->pts= |
1865 | 2039 s->picture_number= (s->picture_number&~0xFF) + i; |
355 | 2040 |
2967 | 2041 /* PTYPE starts here */ |
355 | 2042 if (get_bits1(&s->gb) != 1) { |
2043 /* marker */ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
2044 av_log(s->avctx, AV_LOG_ERROR, "Bad marker\n"); |
355 | 2045 return -1; |
2046 } | |
2047 if (get_bits1(&s->gb) != 0) { | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
2048 av_log(s->avctx, AV_LOG_ERROR, "Bad H263 id\n"); |
2979 | 2049 return -1; /* h263 id */ |
2050 } | |
2051 skip_bits1(&s->gb); /* split screen off */ | |
2052 skip_bits1(&s->gb); /* camera off */ | |
2053 skip_bits1(&s->gb); /* freeze picture release off */ | |
0 | 2054 |
2055 format = get_bits(&s->gb, 3); | |
355 | 2056 /* |
2057 0 forbidden | |
2058 1 sub-QCIF | |
2059 10 QCIF | |
2979 | 2060 7 extended PTYPE (PLUSPTYPE) |
355 | 2061 */ |
0 | 2062 |
161 | 2063 if (format != 7 && format != 6) { |
0 | 2064 s->h263_plus = 0; |
2065 /* H.263v1 */ | |
2066 width = h263_format[format][0]; | |
2067 height = h263_format[format][1]; | |
2068 if (!width) | |
2069 return -1; | |
2967 | 2070 |
6481 | 2071 s->pict_type = FF_I_TYPE + get_bits1(&s->gb); |
0 | 2072 |
2967 | 2073 s->h263_long_vectors = get_bits1(&s->gb); |
0 | 2074 |
355 | 2075 if (get_bits1(&s->gb) != 0) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
2076 av_log(s->avctx, AV_LOG_ERROR, "H263 SAC not supported\n"); |
2979 | 2077 return -1; /* SAC: off */ |
355 | 2078 } |
1633 | 2079 s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */ |
2080 s->unrestricted_mv = s->h263_long_vectors || s->obmc; | |
2967 | 2081 |
9104 | 2082 s->pb_frame = get_bits1(&s->gb); |
1644 | 2083 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); |
2979 | 2084 skip_bits1(&s->gb); /* Continuous Presence Multipoint mode: off */ |
1393 | 2085 |
2086 s->width = width; | |
2087 s->height = height; | |
1865 | 2088 s->avctx->sample_aspect_ratio= (AVRational){12,11}; |
2637 | 2089 s->avctx->time_base= (AVRational){1001, 30000}; |
0 | 2090 } else { |
161 | 2091 int ufep; |
2967 | 2092 |
0 | 2093 /* H.263v2 */ |
161 | 2094 s->h263_plus = 1; |
2095 ufep = get_bits(&s->gb, 3); /* Update Full Extended PTYPE */ | |
355 | 2096 |
2967 | 2097 /* ufep other than 0 and 1 are reserved */ |
161 | 2098 if (ufep == 1) { |
2967 | 2099 /* OPPTYPE */ |
161 | 2100 format = get_bits(&s->gb, 3); |
4652 | 2101 dprintf(s->avctx, "ufep=1, format: %d\n", format); |
1872 | 2102 s->custom_pcf= get_bits1(&s->gb); |
5513 | 2103 s->umvplus = get_bits1(&s->gb); /* Unrestricted Motion Vector */ |
1644 | 2104 if (get_bits1(&s->gb) != 0) { |
2105 av_log(s->avctx, AV_LOG_ERROR, "Syntax-based Arithmetic Coding (SAC) not supported\n"); | |
2106 } | |
1633 | 2107 s->obmc= get_bits1(&s->gb); /* Advanced prediction mode */ |
2108 s->h263_aic = get_bits1(&s->gb); /* Advanced Intra Coding (AIC) */ | |
1644 | 2109 s->loop_filter= get_bits1(&s->gb); |
2110 s->unrestricted_mv = s->umvplus || s->obmc || s->loop_filter; | |
2967 | 2111 |
1661 | 2112 s->h263_slice_structured= get_bits1(&s->gb); |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2113 if (get_bits1(&s->gb) != 0) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
2114 av_log(s->avctx, AV_LOG_ERROR, "Reference Picture Selection not supported\n"); |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2115 } |
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2116 if (get_bits1(&s->gb) != 0) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
2117 av_log(s->avctx, AV_LOG_ERROR, "Independent Segment Decoding not supported\n"); |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2118 } |
1637 | 2119 s->alt_inter_vlc= get_bits1(&s->gb); |
1639 | 2120 s->modified_quant= get_bits1(&s->gb); |
1644 | 2121 if(s->modified_quant) |
2122 s->chroma_qscale_table= ff_h263_chroma_qscale_table; | |
2967 | 2123 |
1278
483db104bb7b
truncated h263 decoding support / H263-ES "demuxer"
michaelni
parents:
1273
diff
changeset
|
2124 skip_bits(&s->gb, 1); /* Prevent start code emulation */ |
355 | 2125 |
161 | 2126 skip_bits(&s->gb, 3); /* Reserved */ |
355 | 2127 } else if (ufep != 0) { |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
2128 av_log(s->avctx, AV_LOG_ERROR, "Bad UFEP type (%d)\n", ufep); |
0 | 2129 return -1; |
355 | 2130 } |
2967 | 2131 |
78 | 2132 /* MPPTYPE */ |
1655 | 2133 s->pict_type = get_bits(&s->gb, 3); |
2134 switch(s->pict_type){ | |
6481 | 2135 case 0: s->pict_type= FF_I_TYPE;break; |
2136 case 1: s->pict_type= FF_P_TYPE;break; | |
9104 | 2137 case 2: s->pict_type= FF_P_TYPE;s->pb_frame = 3;break; |
6481 | 2138 case 3: s->pict_type= FF_B_TYPE;break; |
2139 case 7: s->pict_type= FF_I_TYPE;break; //ZYGO | |
1655 | 2140 default: |
0 | 2141 return -1; |
1655 | 2142 } |
250
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
2143 skip_bits(&s->gb, 2); |
3449316664b5
- Bug fix on RTYPE (rounding type) not being honoured by H.263+ decoder.
pulento
parents:
249
diff
changeset
|
2144 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
|
2145 skip_bits(&s->gb, 4); |
2967 | 2146 |
78 | 2147 /* Get the picture dimensions */ |
161 | 2148 if (ufep) { |
2149 if (format == 6) { | |
2150 /* Custom Picture Format (CPFMT) */ | |
355 | 2151 s->aspect_ratio_info = get_bits(&s->gb, 4); |
4652 | 2152 dprintf(s->avctx, "aspect: %d\n", s->aspect_ratio_info); |
355 | 2153 /* aspect ratios: |
2154 0 - forbidden | |
2155 1 - 1:1 | |
2156 2 - 12:11 (CIF 4:3) | |
2157 3 - 10:11 (525-type 4:3) | |
2158 4 - 16:11 (CIF 16:9) | |
2159 5 - 40:33 (525-type 16:9) | |
2160 6-14 - reserved | |
2161 */ | |
161 | 2162 width = (get_bits(&s->gb, 9) + 1) * 4; |
2163 skip_bits1(&s->gb); | |
2164 height = get_bits(&s->gb, 9) * 4; | |
4652 | 2165 dprintf(s->avctx, "\nH.263+ Custom picture: %dx%d\n",width,height); |
669
b4bddbde44f3
aspect (ext. par too) support for h263 and mpeg4 (inc. build becouse of new vars)
al3x
parents:
667
diff
changeset
|
2166 if (s->aspect_ratio_info == FF_ASPECT_EXTENDED) { |
355 | 2167 /* aspected dimensions */ |
1548 | 2168 s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 8); |
2169 s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 8); | |
887 | 2170 }else{ |
10803 | 2171 s->avctx->sample_aspect_ratio= ff_h263_pixel_aspect[s->aspect_ratio_info]; |
355 | 2172 } |
2173 } else { | |
161 | 2174 width = h263_format[format][0]; |
2175 height = h263_format[format][1]; | |
1865 | 2176 s->avctx->sample_aspect_ratio= (AVRational){12,11}; |
161 | 2177 } |
2178 if ((width == 0) || (height == 0)) | |
2179 return -1; | |
2180 s->width = width; | |
2181 s->height = height; | |
1872 | 2182 |
2183 if(s->custom_pcf){ | |
2184 int gcd; | |
2637 | 2185 s->avctx->time_base.den= 1800000; |
2186 s->avctx->time_base.num= 1000 + get_bits1(&s->gb); | |
2187 s->avctx->time_base.num*= get_bits(&s->gb, 7); | |
2188 if(s->avctx->time_base.num == 0){ | |
1872 | 2189 av_log(s, AV_LOG_ERROR, "zero framerate\n"); |
2190 return -1; | |
2191 } | |
8611 | 2192 gcd= av_gcd(s->avctx->time_base.den, s->avctx->time_base.num); |
2637 | 2193 s->avctx->time_base.den /= gcd; |
2194 s->avctx->time_base.num /= gcd; | |
1872 | 2195 }else{ |
2637 | 2196 s->avctx->time_base= (AVRational){1001, 30000}; |
1872 | 2197 } |
2198 } | |
2967 | 2199 |
1872 | 2200 if(s->custom_pcf){ |
2201 skip_bits(&s->gb, 2); //extended Temporal reference | |
2202 } | |
2203 | |
2204 if (ufep) { | |
1089 | 2205 if (s->umvplus) { |
2206 if(get_bits1(&s->gb)==0) /* Unlimited Unrestricted Motion Vectors Indicator (UUI) */ | |
2967 | 2207 skip_bits1(&s->gb); |
161 | 2208 } |
1661 | 2209 if(s->h263_slice_structured){ |
2210 if (get_bits1(&s->gb) != 0) { | |
2211 av_log(s->avctx, AV_LOG_ERROR, "rectangular slices not supported\n"); | |
2212 } | |
2213 if (get_bits1(&s->gb) != 0) { | |
2214 av_log(s->avctx, AV_LOG_ERROR, "unordered slices not supported\n"); | |
2215 } | |
2216 } | |
78 | 2217 } |
2967 | 2218 |
0 | 2219 s->qscale = get_bits(&s->gb, 5); |
2220 } | |
1670 | 2221 |
1896
ef87d53ca87a
h.263 ssm + aic fix by (Maarten Daniels <maarten dot daniels at student dot luc dot ac dot be>)
michael
parents:
1893
diff
changeset
|
2222 s->mb_width = (s->width + 15) / 16; |
ef87d53ca87a
h.263 ssm + aic fix by (Maarten Daniels <maarten dot daniels at student dot luc dot ac dot be>)
michael
parents:
1893
diff
changeset
|
2223 s->mb_height = (s->height + 15) / 16; |
ef87d53ca87a
h.263 ssm + aic fix by (Maarten Daniels <maarten dot daniels at student dot luc dot ac dot be>)
michael
parents:
1893
diff
changeset
|
2224 s->mb_num = s->mb_width * s->mb_height; |
ef87d53ca87a
h.263 ssm + aic fix by (Maarten Daniels <maarten dot daniels at student dot luc dot ac dot be>)
michael
parents:
1893
diff
changeset
|
2225 |
9104 | 2226 if (s->pb_frame) { |
2227 skip_bits(&s->gb, 3); /* Temporal reference for B-pictures */ | |
2228 if (s->custom_pcf) | |
2229 skip_bits(&s->gb, 2); //extended Temporal reference | |
2230 skip_bits(&s->gb, 2); /* Quantization information for B-pictures */ | |
2231 } | |
2232 | |
0 | 2233 /* PEI */ |
21 | 2234 while (get_bits1(&s->gb) != 0) { |
2235 skip_bits(&s->gb, 8); | |
0 | 2236 } |
1896
ef87d53ca87a
h.263 ssm + aic fix by (Maarten Daniels <maarten dot daniels at student dot luc dot ac dot be>)
michael
parents:
1893
diff
changeset
|
2237 |
1670 | 2238 if(s->h263_slice_structured){ |
2239 if (get_bits1(&s->gb) != 1) { | |
2240 av_log(s->avctx, AV_LOG_ERROR, "SEPB1 marker missing\n"); | |
2241 return -1; | |
2242 } | |
2243 | |
2244 ff_h263_decode_mba(s); | |
2245 | |
2246 if (get_bits1(&s->gb) != 1) { | |
2247 av_log(s->avctx, AV_LOG_ERROR, "SEPB2 marker missing\n"); | |
2248 return -1; | |
2249 } | |
2250 } | |
0 | 2251 s->f_code = 1; |
2967 | 2252 |
498 | 2253 if(s->h263_aic){ |
2967 | 2254 s->y_dc_scale_table= |
1639 | 2255 s->c_dc_scale_table= ff_aic_dc_scale_table; |
498 | 2256 }else{ |
2257 s->y_dc_scale_table= | |
2258 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
2259 } | |
2260 | |
10791 | 2261 ff_h263_show_pict_info(s); |
8612 | 2262 if (s->pict_type == FF_I_TYPE && s->codec_tag == AV_RL32("ZYGO")){ |
1584
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
2263 int i,j; |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
2264 for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
2265 av_log(s->avctx, AV_LOG_DEBUG, "\n"); |
1584
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
2266 for(i=0; i<13; i++){ |
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
2267 for(j=0; j<3; j++){ |
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
2268 int v= get_bits(&s->gb, 8); |
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
2269 v |= get_sbits(&s->gb, 8)<<8; |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
2270 av_log(s->avctx, AV_LOG_DEBUG, " %5d", v); |
1584
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
2271 } |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
2272 av_log(s->avctx, AV_LOG_DEBUG, "\n"); |
1584
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
2273 } |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1586
diff
changeset
|
2274 for(i=0; i<50; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); |
1584
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
2275 } |
3615999a7284
dumping funny numbers from first zygo i frame header
michael
parents:
1583
diff
changeset
|
2276 |
0 | 2277 return 0; |
2278 } | |
2279 | |
942 | 2280 |