annotate h263.c @ 10803:4605bd2fdb7f libavcodec

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