Mercurial > libavcodec.hg
annotate mpegvideo.c @ 1148:a325999e92b5 libavcodec
10l
author | michaelni |
---|---|
date | Sat, 22 Mar 2003 00:00:53 +0000 |
parents | 6d6003cf89c2 |
children | dde68a430ba9 |
rev | line source |
---|---|
0 | 1 /* |
2 * The simplest mpeg encoder (well, it was the simplest!) | |
429 | 3 * Copyright (c) 2000,2001 Fabrice Bellard. |
0 | 4 * |
429 | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
0 | 9 * |
429 | 10 * This library is distributed in the hope that it will be useful, |
0 | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Lesser General Public License for more details. | |
0 | 14 * |
429 | 15 * You should have received a copy of the GNU Lesser General Public |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
295 | 18 * |
325 | 19 * 4MV & hq & b-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at> |
0 | 20 */ |
701 | 21 |
1106 | 22 /** |
23 * @file mpegvideo.c | |
24 * The simplest mpeg encoder (well, it was the simplest!). | |
25 */ | |
26 | |
701 | 27 #include <ctype.h> |
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
28 #include <limits.h> |
0 | 29 #include "avcodec.h" |
30 #include "dsputil.h" | |
31 #include "mpegvideo.h" | |
32 | |
17
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
33 #ifdef USE_FASTMEMCPY |
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
34 #include "fastmemcpy.h" |
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
35 #endif |
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
36 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
37 //#undef NDEBUG |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
38 //#include <assert.h> |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
39 |
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:
1064
diff
changeset
|
40 #ifdef CONFIG_ENCODERS |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
41 static void encode_picture(MpegEncContext *s, int picture_number); |
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:
1064
diff
changeset
|
42 #endif //CONFIG_ENCODERS |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
43 static void dct_unquantize_mpeg1_c(MpegEncContext *s, |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
44 DCTELEM *block, int n, int qscale); |
325 | 45 static void dct_unquantize_mpeg2_c(MpegEncContext *s, |
46 DCTELEM *block, int n, int qscale); | |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
47 static void dct_unquantize_h263_c(MpegEncContext *s, |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
48 DCTELEM *block, int n, int qscale); |
1064 | 49 static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w); |
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:
1064
diff
changeset
|
50 #ifdef CONFIG_ENCODERS |
344 | 51 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); |
945 | 52 static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); |
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:
1064
diff
changeset
|
53 #endif //CONFIG_ENCODERS |
206 | 54 |
1064 | 55 void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w)= draw_edges_c; |
206 | 56 |
0 | 57 |
58 /* enable all paranoid tests for rounding, overflows, etc... */ | |
59 //#define PARANOID | |
60 | |
61 //#define DEBUG | |
62 | |
321 | 63 |
0 | 64 /* for jpeg fast DCT */ |
65 #define CONST_BITS 14 | |
66 | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
67 static const uint16_t aanscales[64] = { |
0 | 68 /* precomputed values scaled up by 14 bits */ |
69 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
70 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, | |
71 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, | |
72 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, | |
73 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
74 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | |
936 | 75 8867 , 12299, 11585, 10426, 8867, 6967, 4799, 2446, |
76 4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247 | |
0 | 77 }; |
78 | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
79 static const uint8_t h263_chroma_roundtab[16] = { |
1013 | 80 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
0 | 81 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, |
82 }; | |
83 | |
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:
1064
diff
changeset
|
84 #ifdef CONFIG_ENCODERS |
1064 | 85 static uint16_t (*default_mv_penalty)[MAX_MV*2+1]=NULL; |
86 static uint8_t default_fcode_tab[MAX_MV*2+1]; | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
87 |
998 | 88 enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1}; |
89 | |
625
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
90 static void convert_matrix(MpegEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64], |
1064 | 91 const uint16_t *quant_matrix, int bias, int qmin, int qmax) |
0 | 92 { |
344 | 93 int qscale; |
0 | 94 |
709
afeff6ccb7f5
convert only needed matrixes in convert_matrix() (mjpeg calls it for every frame)
michaelni
parents:
706
diff
changeset
|
95 for(qscale=qmin; qscale<=qmax; qscale++){ |
344 | 96 int i; |
1092 | 97 if (s->dsp.fdct == ff_jpeg_fdct_islow) { |
625
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
98 for(i=0;i<64;i++) { |
1092 | 99 const int j= s->dsp.idct_permutation[i]; |
625
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
100 /* 16 <= qscale * quant_matrix[i] <= 7905 */ |
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
101 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ |
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
102 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ |
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
103 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ |
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
104 |
1064 | 105 qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) / |
625
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
106 (qscale * quant_matrix[j])); |
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
107 } |
1092 | 108 } else if (s->dsp.fdct == fdct_ifast) { |
344 | 109 for(i=0;i<64;i++) { |
1092 | 110 const int j= s->dsp.idct_permutation[i]; |
344 | 111 /* 16 <= qscale * quant_matrix[i] <= 7905 */ |
112 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ | |
113 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ | |
114 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ | |
115 | |
1064 | 116 qmat[qscale][i] = (int)((uint64_t_C(1) << (QMAT_SHIFT + 14)) / |
344 | 117 (aanscales[i] * qscale * quant_matrix[j])); |
118 } | |
119 } else { | |
120 for(i=0;i<64;i++) { | |
1092 | 121 const int j= s->dsp.idct_permutation[i]; |
344 | 122 /* We can safely suppose that 16 <= quant_matrix[i] <= 255 |
123 So 16 <= qscale * quant_matrix[i] <= 7905 | |
124 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 | |
125 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 | |
126 */ | |
1064 | 127 qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); |
945 | 128 // qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
129 qmat16[qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); |
344 | 130 |
131 if(qmat16[qscale][i]==0 || qmat16[qscale][i]==128*256) qmat16[qscale][i]=128*256-1; | |
132 qmat16_bias[qscale][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][i]); | |
133 } | |
0 | 134 } |
135 } | |
136 } | |
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:
1064
diff
changeset
|
137 #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:
1064
diff
changeset
|
138 |
456 | 139 // move into common.c perhaps |
140 #define CHECKED_ALLOCZ(p, size)\ | |
141 {\ | |
142 p= av_mallocz(size);\ | |
143 if(p==NULL){\ | |
144 perror("malloc");\ | |
145 goto fail;\ | |
146 }\ | |
147 } | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
148 |
1064 | 149 void ff_init_scantable(MpegEncContext *s, ScanTable *st, const uint8_t *src_scantable){ |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
150 int i; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
151 int end; |
764 | 152 |
153 st->scantable= src_scantable; | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
154 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
155 for(i=0; i<64; i++){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
156 int j; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
157 j = src_scantable[i]; |
1092 | 158 st->permutated[i] = s->dsp.idct_permutation[j]; |
828
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
159 #ifdef ARCH_POWERPC |
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
160 st->inverse[j] = i; |
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
161 #endif |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
162 } |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
163 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
164 end=-1; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
165 for(i=0; i<64; i++){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
166 int j; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
167 j = st->permutated[i]; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
168 if(j>end) end=j; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
169 st->raster_end[i]= end; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
170 } |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
171 } |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
172 |
726
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
173 /* init common dct for both encoder and decoder */ |
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
174 int DCT_common_init(MpegEncContext *s) |
0 | 175 { |
312 | 176 s->dct_unquantize_h263 = dct_unquantize_h263_c; |
325 | 177 s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_c; |
178 s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_c; | |
1092 | 179 |
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:
1064
diff
changeset
|
180 #ifdef CONFIG_ENCODERS |
625
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
181 s->dct_quantize= dct_quantize_c; |
1092 | 182 #endif |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
183 |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
184 #ifdef HAVE_MMX |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
185 MPV_common_init_mmx(s); |
8 | 186 #endif |
514
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M«©ns Rullg«©rd
mellum
parents:
506
diff
changeset
|
187 #ifdef ARCH_ALPHA |
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M«©ns Rullg«©rd
mellum
parents:
506
diff
changeset
|
188 MPV_common_init_axp(s); |
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M«©ns Rullg«©rd
mellum
parents:
506
diff
changeset
|
189 #endif |
628
f596db4aa871
sun solaris compilation bugfix, patch by (Martin Olschewski <olschewski at zpr dot uni-koeln dot de>)
michaelni
parents:
625
diff
changeset
|
190 #ifdef HAVE_MLIB |
f596db4aa871
sun solaris compilation bugfix, patch by (Martin Olschewski <olschewski at zpr dot uni-koeln dot de>)
michaelni
parents:
625
diff
changeset
|
191 MPV_common_init_mlib(s); |
f596db4aa871
sun solaris compilation bugfix, patch by (Martin Olschewski <olschewski at zpr dot uni-koeln dot de>)
michaelni
parents:
625
diff
changeset
|
192 #endif |
721
71f669e9f633
ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
michaelni
parents:
717
diff
changeset
|
193 #ifdef HAVE_MMI |
71f669e9f633
ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
michaelni
parents:
717
diff
changeset
|
194 MPV_common_init_mmi(s); |
71f669e9f633
ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
michaelni
parents:
717
diff
changeset
|
195 #endif |
730 | 196 #ifdef ARCH_ARMV4L |
874 | 197 MPV_common_init_armv4l(s); |
730 | 198 #endif |
828
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
199 #ifdef ARCH_POWERPC |
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
200 MPV_common_init_ppc(s); |
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
201 #endif |
730 | 202 |
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:
1064
diff
changeset
|
203 #ifdef CONFIG_ENCODERS |
1007 | 204 s->fast_dct_quantize= s->dct_quantize; |
205 | |
945 | 206 if(s->flags&CODEC_FLAG_TRELLIS_QUANT){ |
207 s->dct_quantize= dct_quantize_trellis_c; //move before MPV_common_init_* | |
208 } | |
209 | |
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:
1064
diff
changeset
|
210 #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:
1064
diff
changeset
|
211 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
212 /* load & permutate scantables |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
213 note: only wmv uses differnt ones |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
214 */ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
215 ff_init_scantable(s, &s->inter_scantable , ff_zigzag_direct); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
216 ff_init_scantable(s, &s->intra_scantable , ff_zigzag_direct); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
217 ff_init_scantable(s, &s->intra_h_scantable, ff_alternate_horizontal_scan); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
218 ff_init_scantable(s, &s->intra_v_scantable, ff_alternate_vertical_scan); |
591 | 219 |
1096
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
220 s->picture_structure= PICT_FRAME; |
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
221 |
726
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
222 return 0; |
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
223 } |
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
224 |
903 | 225 /** |
924 | 226 * allocates a Picture |
227 * The pixels are allocated/set by calling get_buffer() if shared=0 | |
903 | 228 */ |
924 | 229 static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){ |
230 | |
231 if(shared){ | |
232 assert(pic->data[0]); | |
233 assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED); | |
234 pic->type= FF_BUFFER_TYPE_SHARED; | |
235 }else{ | |
236 int r; | |
237 | |
238 assert(!pic->data[0]); | |
239 | |
925 | 240 r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic); |
924 | 241 |
242 if(r<0 || !pic->age || !pic->type || !pic->data[0]){ | |
1014
48349e11c9b2
C99 initializers and kill warnings patch by (mru at users dot sourceforge dot net (M«©ns Rullg«©rd))
michaelni
parents:
1013
diff
changeset
|
243 fprintf(stderr, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]); |
924 | 244 return -1; |
245 } | |
246 | |
247 if(s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])){ | |
248 fprintf(stderr, "get_buffer() failed (stride changed)\n"); | |
249 return -1; | |
250 } | |
251 | |
252 if(pic->linesize[1] != pic->linesize[2]){ | |
253 fprintf(stderr, "get_buffer() failed (uv stride missmatch)\n"); | |
254 return -1; | |
255 } | |
256 | |
257 s->linesize = pic->linesize[0]; | |
258 s->uvlinesize= pic->linesize[1]; | |
903 | 259 } |
924 | 260 |
261 if(pic->qscale_table==NULL){ | |
262 if (s->encoding) { | |
1064 | 263 CHECKED_ALLOCZ(pic->mb_var , s->mb_num * sizeof(int16_t)) |
264 CHECKED_ALLOCZ(pic->mc_mb_var, s->mb_num * sizeof(int16_t)) | |
265 CHECKED_ALLOCZ(pic->mb_mean , s->mb_num * sizeof(int8_t)) | |
1013 | 266 CHECKED_ALLOCZ(pic->mb_cmp_score, s->mb_num * sizeof(int32_t)) |
924 | 267 } |
268 | |
1064 | 269 CHECKED_ALLOCZ(pic->mbskip_table , s->mb_num * sizeof(uint8_t)+1) //the +1 is for the slice end check |
270 CHECKED_ALLOCZ(pic->qscale_table , s->mb_num * sizeof(uint8_t)) | |
924 | 271 pic->qstride= s->mb_width; |
272 } | |
903 | 273 |
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
274 //it might be nicer if the application would keep track of these but it would require a API change |
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
275 memmove(s->prev_pict_types+1, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE-1); |
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
276 s->prev_pict_types[0]= s->pict_type; |
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
277 if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == B_TYPE) |
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
278 pic->age= INT_MAX; // skiped MBs in b frames are quite rare in mpeg1/2 and its a bit tricky to skip them anyway |
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
279 |
903 | 280 return 0; |
281 fail: //for the CHECKED_ALLOCZ macro | |
282 return -1; | |
283 } | |
284 | |
924 | 285 /** |
286 * deallocates a picture | |
287 */ | |
903 | 288 static void free_picture(MpegEncContext *s, Picture *pic){ |
289 int i; | |
924 | 290 |
291 if(pic->data[0] && pic->type!=FF_BUFFER_TYPE_SHARED){ | |
925 | 292 s->avctx->release_buffer(s->avctx, (AVFrame*)pic); |
924 | 293 } |
294 | |
903 | 295 av_freep(&pic->mb_var); |
296 av_freep(&pic->mc_mb_var); | |
297 av_freep(&pic->mb_mean); | |
1013 | 298 av_freep(&pic->mb_cmp_score); |
903 | 299 av_freep(&pic->mbskip_table); |
300 av_freep(&pic->qscale_table); | |
301 | |
924 | 302 if(pic->type == FF_BUFFER_TYPE_INTERNAL){ |
903 | 303 for(i=0; i<4; i++){ |
304 av_freep(&pic->base[i]); | |
305 pic->data[i]= NULL; | |
306 } | |
307 av_freep(&pic->opaque); | |
924 | 308 pic->type= 0; |
309 }else if(pic->type == FF_BUFFER_TYPE_SHARED){ | |
310 for(i=0; i<4; i++){ | |
311 pic->base[i]= | |
312 pic->data[i]= NULL; | |
313 } | |
314 pic->type= 0; | |
903 | 315 } |
316 } | |
317 | |
726
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
318 /* init common structure for both encoder and decoder */ |
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
319 int MPV_common_init(MpegEncContext *s) |
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
320 { |
756 | 321 int y_size, c_size, yc_size, i; |
726
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
322 |
1092 | 323 dsputil_init(&s->dsp, s->avctx); |
726
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
324 DCT_common_init(s); |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
325 |
754 | 326 s->flags= s->avctx->flags; |
726
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
327 |
903 | 328 s->mb_width = (s->width + 15) / 16; |
0 | 329 s->mb_height = (s->height + 15) / 16; |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
330 |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
331 /* set default edge pos, will be overriden in decode_header if needed */ |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
332 s->h_edge_pos= s->mb_width*16; |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
333 s->v_edge_pos= s->mb_height*16; |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
334 |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
335 s->mb_num = s->mb_width * s->mb_height; |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
336 |
756 | 337 y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); |
338 c_size = (s->mb_width + 2) * (s->mb_height + 2); | |
339 yc_size = y_size + 2 * c_size; | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
340 |
701 | 341 /* convert fourcc to upper case */ |
1116 | 342 s->avctx->codec_tag= toupper( s->avctx->codec_tag &0xFF) |
343 + (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 ) | |
344 + (toupper((s->avctx->codec_tag>>16)&0xFF)<<16) | |
345 + (toupper((s->avctx->codec_tag>>24)&0xFF)<<24); | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
346 |
956
45bd748e305f
negative linesize support (so mplayer -flip works)
michaelni
parents:
955
diff
changeset
|
347 CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, (s->width+64)*2*17*2); //(width + edge + align)*interlaced*MBsize*tolerance |
45bd748e305f
negative linesize support (so mplayer -flip works)
michaelni
parents:
955
diff
changeset
|
348 s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*17; |
903 | 349 |
925 | 350 s->avctx->coded_frame= (AVFrame*)&s->current_picture; |
903 | 351 |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
352 if (s->encoding) { |
324 | 353 int mv_table_size= (s->mb_width+2)*(s->mb_height+2); |
354 | |
355 /* Allocate MV tables */ | |
1064 | 356 CHECKED_ALLOCZ(s->p_mv_table , mv_table_size * 2 * sizeof(int16_t)) |
357 CHECKED_ALLOCZ(s->b_forw_mv_table , mv_table_size * 2 * sizeof(int16_t)) | |
358 CHECKED_ALLOCZ(s->b_back_mv_table , mv_table_size * 2 * sizeof(int16_t)) | |
359 CHECKED_ALLOCZ(s->b_bidir_forw_mv_table , mv_table_size * 2 * sizeof(int16_t)) | |
360 CHECKED_ALLOCZ(s->b_bidir_back_mv_table , mv_table_size * 2 * sizeof(int16_t)) | |
361 CHECKED_ALLOCZ(s->b_direct_mv_table , mv_table_size * 2 * sizeof(int16_t)) | |
324 | 362 |
903 | 363 //FIXME should be linesize instead of s->width*2 but that isnt known before get_buffer() |
936 | 364 CHECKED_ALLOCZ(s->me.scratchpad, s->width*2*16*3*sizeof(uint8_t)) |
456 | 365 |
936 | 366 CHECKED_ALLOCZ(s->me.map , ME_MAP_SIZE*sizeof(uint32_t)) |
367 CHECKED_ALLOCZ(s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t)) | |
327 | 368 |
456 | 369 if(s->codec_id==CODEC_ID_MPEG4){ |
370 CHECKED_ALLOCZ(s->tex_pb_buffer, PB_BUFFER_SIZE); | |
371 CHECKED_ALLOCZ( s->pb2_buffer, PB_BUFFER_SIZE); | |
372 } | |
612 | 373 |
650
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
374 if(s->msmpeg4_version){ |
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
375 CHECKED_ALLOCZ(s->ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int)); |
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
376 } |
612 | 377 CHECKED_ALLOCZ(s->avctx->stats_out, 256); |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
378 } |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
379 |
1064 | 380 CHECKED_ALLOCZ(s->error_status_table, s->mb_num*sizeof(uint8_t)) |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
381 |
288 | 382 if (s->out_format == FMT_H263 || s->encoding) { |
0 | 383 int size; |
456 | 384 /* Allocate MB type table */ |
1064 | 385 CHECKED_ALLOCZ(s->mb_type , s->mb_num * sizeof(uint8_t)) |
456 | 386 |
0 | 387 /* MV prediction */ |
388 size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | |
1064 | 389 CHECKED_ALLOCZ(s->motion_val, size * 2 * sizeof(int16_t)); |
664 | 390 } |
391 | |
392 if(s->codec_id==CODEC_ID_MPEG4){ | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
393 /* interlaced direct mode decoding tables */ |
1064 | 394 CHECKED_ALLOCZ(s->field_mv_table, s->mb_num*2*2 * sizeof(int16_t)) |
395 CHECKED_ALLOCZ(s->field_select_table, s->mb_num*2* sizeof(int8_t)) | |
0 | 396 } |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
397 /* 4mv b frame decoding table */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
398 //note this is needed for h263 without b frames too (segfault on damaged streams otherwise) |
1064 | 399 CHECKED_ALLOCZ(s->co_located_type_table, s->mb_num * sizeof(uint8_t)) |
767 | 400 if (s->out_format == FMT_H263) { |
0 | 401 /* ac values */ |
1064 | 402 CHECKED_ALLOCZ(s->ac_val[0], yc_size * sizeof(int16_t) * 16); |
0 | 403 s->ac_val[1] = s->ac_val[0] + y_size; |
404 s->ac_val[2] = s->ac_val[1] + c_size; | |
405 | |
406 /* cbp values */ | |
456 | 407 CHECKED_ALLOCZ(s->coded_block, y_size); |
333 | 408 |
409 /* divx501 bitstream reorder buffer */ | |
456 | 410 CHECKED_ALLOCZ(s->bitstream_buffer, BITSTREAM_BUFFER_SIZE); |
843 | 411 |
456 | 412 /* cbp, ac_pred, pred_dir */ |
1064 | 413 CHECKED_ALLOCZ(s->cbp_table , s->mb_num * sizeof(uint8_t)) |
414 CHECKED_ALLOCZ(s->pred_dir_table, s->mb_num * sizeof(uint8_t)) | |
197
21abf1b20016
different fix, s->mbintra_table used only if h263_pred set. - patch by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
196
diff
changeset
|
415 } |
756 | 416 |
417 if (s->h263_pred || s->h263_plus || !s->encoding) { | |
418 /* dc values */ | |
419 //MN: we need these for error resilience of intra-frames | |
1064 | 420 CHECKED_ALLOCZ(s->dc_val[0], yc_size * sizeof(int16_t)); |
756 | 421 s->dc_val[1] = s->dc_val[0] + y_size; |
422 s->dc_val[2] = s->dc_val[1] + c_size; | |
423 for(i=0;i<yc_size;i++) | |
424 s->dc_val[0][i] = 1024; | |
425 } | |
426 | |
611
3214d3f4519e
error concealment needs the mbintra_table so it should allways be allocated
michaelni
parents:
608
diff
changeset
|
427 /* which mb is a intra block */ |
3214d3f4519e
error concealment needs the mbintra_table so it should allways be allocated
michaelni
parents:
608
diff
changeset
|
428 CHECKED_ALLOCZ(s->mbintra_table, s->mb_num); |
3214d3f4519e
error concealment needs the mbintra_table so it should allways be allocated
michaelni
parents:
608
diff
changeset
|
429 memset(s->mbintra_table, 1, s->mb_num); |
3214d3f4519e
error concealment needs the mbintra_table so it should allways be allocated
michaelni
parents:
608
diff
changeset
|
430 |
0 | 431 /* default structure is frame */ |
432 s->picture_structure = PICT_FRAME; | |
553 | 433 |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
434 /* init macroblock skip table */ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
435 CHECKED_ALLOCZ(s->mbskip_table, s->mb_num+1); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
436 //Note the +1 is for a quicker mpeg4 slice_end detection |
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
437 CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE); |
294 | 438 |
327 | 439 s->block= s->blocks[0]; |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
440 |
842
e460775adb38
cleanup (breaks compatibility, requested by fabrice)
michaelni
parents:
828
diff
changeset
|
441 s->parse_context.state= -1; |
e460775adb38
cleanup (breaks compatibility, requested by fabrice)
michaelni
parents:
828
diff
changeset
|
442 |
0 | 443 s->context_initialized = 1; |
444 return 0; | |
445 fail: | |
244 | 446 MPV_common_end(s); |
447 return -1; | |
448 } | |
449 | |
456 | 450 |
451 //extern int sads; | |
452 | |
244 | 453 /* init common structure for both encoder and decoder */ |
454 void MPV_common_end(MpegEncContext *s) | |
455 { | |
456 int i; | |
457 | |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
458 av_freep(&s->mb_type); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
459 av_freep(&s->p_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
460 av_freep(&s->b_forw_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
461 av_freep(&s->b_back_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
462 av_freep(&s->b_bidir_forw_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
463 av_freep(&s->b_bidir_back_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
464 av_freep(&s->b_direct_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
465 av_freep(&s->motion_val); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
466 av_freep(&s->dc_val[0]); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
467 av_freep(&s->ac_val[0]); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
468 av_freep(&s->coded_block); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
469 av_freep(&s->mbintra_table); |
456 | 470 av_freep(&s->cbp_table); |
471 av_freep(&s->pred_dir_table); | |
936 | 472 av_freep(&s->me.scratchpad); |
473 av_freep(&s->me.map); | |
474 av_freep(&s->me.score_map); | |
456 | 475 |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
476 av_freep(&s->mbskip_table); |
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
477 av_freep(&s->prev_pict_types); |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
478 av_freep(&s->bitstream_buffer); |
456 | 479 av_freep(&s->tex_pb_buffer); |
480 av_freep(&s->pb2_buffer); | |
956
45bd748e305f
negative linesize support (so mplayer -flip works)
michaelni
parents:
955
diff
changeset
|
481 av_freep(&s->allocated_edge_emu_buffer); s->edge_emu_buffer= NULL; |
664 | 482 av_freep(&s->co_located_type_table); |
483 av_freep(&s->field_mv_table); | |
484 av_freep(&s->field_select_table); | |
612 | 485 av_freep(&s->avctx->stats_out); |
650
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
486 av_freep(&s->ac_stats); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
487 av_freep(&s->error_status_table); |
903 | 488 |
489 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
490 free_picture(s, &s->picture[i]); | |
0 | 491 } |
492 s->context_initialized = 0; | |
493 } | |
494 | |
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:
1064
diff
changeset
|
495 #ifdef 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:
1064
diff
changeset
|
496 |
0 | 497 /* init video encoder */ |
498 int MPV_encode_init(AVCodecContext *avctx) | |
499 { | |
500 MpegEncContext *s = avctx->priv_data; | |
60 | 501 int i; |
0 | 502 |
315 | 503 avctx->pix_fmt = PIX_FMT_YUV420P; |
504 | |
0 | 505 s->bit_rate = avctx->bit_rate; |
268 | 506 s->bit_rate_tolerance = avctx->bit_rate_tolerance; |
0 | 507 s->width = avctx->width; |
508 s->height = avctx->height; | |
456 | 509 if(avctx->gop_size > 600){ |
462
3fdd0627f6bd
typo (found by Bohdan Horst <nexus at hoth.amu.edu.pl>)
michaelni
parents:
461
diff
changeset
|
510 fprintf(stderr, "Warning keyframe interval too large! reducing it ...\n"); |
456 | 511 avctx->gop_size=600; |
512 } | |
0 | 513 s->gop_size = avctx->gop_size; |
162 | 514 s->rtp_mode = avctx->rtp_mode; |
515 s->rtp_payload_size = avctx->rtp_payload_size; | |
231 | 516 if (avctx->rtp_callback) |
517 s->rtp_callback = avctx->rtp_callback; | |
268 | 518 s->max_qdiff= avctx->max_qdiff; |
519 s->qcompress= avctx->qcompress; | |
520 s->qblur= avctx->qblur; | |
194
27d1773552c9
mpeg4 encoder fix by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
191
diff
changeset
|
521 s->avctx = avctx; |
294 | 522 s->flags= avctx->flags; |
324 | 523 s->max_b_frames= avctx->max_b_frames; |
329 | 524 s->b_frame_strategy= avctx->b_frame_strategy; |
344 | 525 s->codec_id= avctx->codec->id; |
456 | 526 s->luma_elim_threshold = avctx->luma_elim_threshold; |
527 s->chroma_elim_threshold= avctx->chroma_elim_threshold; | |
528 s->strict_std_compliance= avctx->strict_std_compliance; | |
529 s->data_partitioning= avctx->flags & CODEC_FLAG_PART; | |
936 | 530 s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0; |
599 | 531 s->mpeg_quant= avctx->mpeg_quant; |
344 | 532 |
0 | 533 if (s->gop_size <= 1) { |
534 s->intra_only = 1; | |
535 s->gop_size = 12; | |
536 } else { | |
537 s->intra_only = 0; | |
538 } | |
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
539 |
936 | 540 s->me_method = avctx->me_method; |
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
541 |
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
542 /* Fixed QSCALE */ |
0 | 543 s->fixed_qscale = (avctx->flags & CODEC_FLAG_QSCALE); |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
544 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
545 s->adaptive_quant= ( s->avctx->lumi_masking |
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
546 || s->avctx->dark_masking |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
547 || s->avctx->temporal_cplx_masking |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
548 || s->avctx->spatial_cplx_masking |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
549 || s->avctx->p_masking) |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
550 && !s->fixed_qscale; |
697 | 551 |
552 s->progressive_sequence= !(avctx->flags & CODEC_FLAG_INTERLACED_DCT); | |
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
553 |
0 | 554 switch(avctx->codec->id) { |
555 case CODEC_ID_MPEG1VIDEO: | |
556 s->out_format = FMT_MPEG1; | |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1124
diff
changeset
|
557 s->low_delay= 0; //s->max_b_frames ? 0 : 1; |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1124
diff
changeset
|
558 avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); |
0 | 559 break; |
560 case CODEC_ID_MJPEG: | |
561 s->out_format = FMT_MJPEG; | |
562 s->intra_only = 1; /* force intra only for jpeg */ | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
563 s->mjpeg_write_tables = 1; /* write all tables */ |
370
0eca28d16cbd
clamp intra matrix to 8bit for mjpeg (workaround for qscale>=25)
al3x
parents:
365
diff
changeset
|
564 s->mjpeg_data_only_frames = 0; /* write all the needed headers */ |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
565 s->mjpeg_vsample[0] = 2; /* set up default sampling factors */ |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
566 s->mjpeg_vsample[1] = 1; /* the only currently supported values */ |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
567 s->mjpeg_vsample[2] = 1; |
370
0eca28d16cbd
clamp intra matrix to 8bit for mjpeg (workaround for qscale>=25)
al3x
parents:
365
diff
changeset
|
568 s->mjpeg_hsample[0] = 2; |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
569 s->mjpeg_hsample[1] = 1; |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
570 s->mjpeg_hsample[2] = 1; |
0 | 571 if (mjpeg_init(s) < 0) |
572 return -1; | |
336 | 573 avctx->delay=0; |
924 | 574 s->low_delay=1; |
0 | 575 break; |
1042 | 576 #ifdef CONFIG_RISKY |
0 | 577 case CODEC_ID_H263: |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
578 if (h263_get_picture_format(s->width, s->height) == 7) { |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
579 printf("Input picture size isn't suitable for h263 codec! try h263+\n"); |
0 | 580 return -1; |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
581 } |
0 | 582 s->out_format = FMT_H263; |
336 | 583 avctx->delay=0; |
924 | 584 s->low_delay=1; |
0 | 585 break; |
586 case CODEC_ID_H263P: | |
587 s->out_format = FMT_H263; | |
588 s->h263_plus = 1; | |
1095
c7604e6291c5
extended option for h263+ patch by (fixounet at free dot fr) with some minor modifications
michaelni
parents:
1094
diff
changeset
|
589 /* Fx */ |
c7604e6291c5
extended option for h263+ patch by (fixounet at free dot fr) with some minor modifications
michaelni
parents:
1094
diff
changeset
|
590 s->unrestricted_mv=(avctx->flags & CODEC_FLAG_H263P_UMV) ? 1:0; |
c7604e6291c5
extended option for h263+ patch by (fixounet at free dot fr) with some minor modifications
michaelni
parents:
1094
diff
changeset
|
591 s->h263_aic= (avctx->flags & CODEC_FLAG_H263P_AIC) ? 1:0; |
c7604e6291c5
extended option for h263+ patch by (fixounet at free dot fr) with some minor modifications
michaelni
parents:
1094
diff
changeset
|
592 /* /Fx */ |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
593 /* These are just to be sure */ |
1089 | 594 s->umvplus = 1; |
336 | 595 avctx->delay=0; |
924 | 596 s->low_delay=1; |
0 | 597 break; |
598 case CODEC_ID_RV10: | |
599 s->out_format = FMT_H263; | |
600 s->h263_rv10 = 1; | |
336 | 601 avctx->delay=0; |
924 | 602 s->low_delay=1; |
0 | 603 break; |
71 | 604 case CODEC_ID_MPEG4: |
0 | 605 s->out_format = FMT_H263; |
606 s->h263_pred = 1; | |
607 s->unrestricted_mv = 1; | |
924 | 608 s->low_delay= s->max_b_frames ? 0 : 1; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
609 avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); |
0 | 610 break; |
307 | 611 case CODEC_ID_MSMPEG4V1: |
0 | 612 s->out_format = FMT_H263; |
613 s->h263_msmpeg4 = 1; | |
614 s->h263_pred = 1; | |
615 s->unrestricted_mv = 1; | |
307 | 616 s->msmpeg4_version= 1; |
336 | 617 avctx->delay=0; |
924 | 618 s->low_delay=1; |
307 | 619 break; |
620 case CODEC_ID_MSMPEG4V2: | |
621 s->out_format = FMT_H263; | |
622 s->h263_msmpeg4 = 1; | |
623 s->h263_pred = 1; | |
624 s->unrestricted_mv = 1; | |
625 s->msmpeg4_version= 2; | |
336 | 626 avctx->delay=0; |
924 | 627 s->low_delay=1; |
307 | 628 break; |
629 case CODEC_ID_MSMPEG4V3: | |
630 s->out_format = FMT_H263; | |
631 s->h263_msmpeg4 = 1; | |
632 s->h263_pred = 1; | |
633 s->unrestricted_mv = 1; | |
634 s->msmpeg4_version= 3; | |
336 | 635 avctx->delay=0; |
924 | 636 s->low_delay=1; |
0 | 637 break; |
499 | 638 case CODEC_ID_WMV1: |
639 s->out_format = FMT_H263; | |
640 s->h263_msmpeg4 = 1; | |
641 s->h263_pred = 1; | |
642 s->unrestricted_mv = 1; | |
643 s->msmpeg4_version= 4; | |
644 avctx->delay=0; | |
924 | 645 s->low_delay=1; |
499 | 646 break; |
647 case CODEC_ID_WMV2: | |
648 s->out_format = FMT_H263; | |
649 s->h263_msmpeg4 = 1; | |
650 s->h263_pred = 1; | |
651 s->unrestricted_mv = 1; | |
652 s->msmpeg4_version= 5; | |
653 avctx->delay=0; | |
924 | 654 s->low_delay=1; |
499 | 655 break; |
1042 | 656 #endif |
0 | 657 default: |
658 return -1; | |
659 } | |
295 | 660 |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
661 { /* set up some save defaults, some codecs might override them later */ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
662 static int done=0; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
663 if(!done){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
664 int i; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
665 done=1; |
815
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
814
diff
changeset
|
666 |
1064 | 667 default_mv_penalty= av_mallocz( sizeof(uint16_t)*(MAX_FCODE+1)*(2*MAX_MV+1) ); |
668 memset(default_mv_penalty, 0, sizeof(uint16_t)*(MAX_FCODE+1)*(2*MAX_MV+1)); | |
669 memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1)); | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
670 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
671 for(i=-16; i<16; i++){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
672 default_fcode_tab[i + MAX_MV]= 1; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
673 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
674 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
675 } |
936 | 676 s->me.mv_penalty= default_mv_penalty; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
677 s->fcode_tab= default_fcode_tab; |
506
b9ed0ae72d51
init dc_scale tables to defaults (fixes mjpeg sig11)
michaelni
parents:
499
diff
changeset
|
678 s->y_dc_scale_table= |
b9ed0ae72d51
init dc_scale tables to defaults (fixes mjpeg sig11)
michaelni
parents:
499
diff
changeset
|
679 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; |
b9ed0ae72d51
init dc_scale tables to defaults (fixes mjpeg sig11)
michaelni
parents:
499
diff
changeset
|
680 |
287 | 681 /* dont use mv_penalty table for crap MV as it would be confused */ |
936 | 682 //FIXME remove after fixing / removing old ME |
683 if (s->me_method < ME_EPZS) s->me.mv_penalty = default_mv_penalty; | |
287 | 684 |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
685 s->encoding = 1; |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
686 |
0 | 687 /* init */ |
688 if (MPV_common_init(s) < 0) | |
689 return -1; | |
690 | |
936 | 691 ff_init_me(s); |
692 | |
815
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
814
diff
changeset
|
693 #ifdef CONFIG_ENCODERS |
1042 | 694 #ifdef CONFIG_RISKY |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
695 if (s->out_format == FMT_H263) |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
696 h263_encode_init(s); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
697 if(s->msmpeg4_version) |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
698 ff_msmpeg4_encode_init(s); |
815
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
814
diff
changeset
|
699 #endif |
1042 | 700 if (s->out_format == FMT_MPEG1) |
701 ff_mpeg1_encode_init(s); | |
702 #endif | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
703 |
60 | 704 /* init default q matrix */ |
705 for(i=0;i<64;i++) { | |
1092 | 706 int j= s->dsp.idct_permutation[i]; |
1042 | 707 #ifdef CONFIG_RISKY |
599 | 708 if(s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){ |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
709 s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i]; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
710 s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i]; |
599 | 711 }else if(s->out_format == FMT_H263){ |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
712 s->intra_matrix[j] = |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
713 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; |
1042 | 714 }else |
715 #endif | |
716 { /* mpeg1 */ | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
717 s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i]; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
718 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; |
599 | 719 } |
344 | 720 } |
721 | |
722 /* precompute matrix */ | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
723 /* for mjpeg, we do include qscale in the matrix */ |
344 | 724 if (s->out_format != FMT_MJPEG) { |
625
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
725 convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias, |
709
afeff6ccb7f5
convert only needed matrixes in convert_matrix() (mjpeg calls it for every frame)
michaelni
parents:
706
diff
changeset
|
726 s->intra_matrix, s->intra_quant_bias, 1, 31); |
625
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
727 convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16, s->q_inter_matrix16_bias, |
709
afeff6ccb7f5
convert only needed matrixes in convert_matrix() (mjpeg calls it for every frame)
michaelni
parents:
706
diff
changeset
|
728 s->inter_matrix, s->inter_quant_bias, 1, 31); |
60 | 729 } |
730 | |
329 | 731 if(ff_rate_control_init(s) < 0) |
732 return -1; | |
0 | 733 |
734 s->picture_number = 0; | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
735 s->picture_in_gop_number = 0; |
0 | 736 s->fake_picture_number = 0; |
737 /* motion detector init */ | |
738 s->f_code = 1; | |
324 | 739 s->b_code = 1; |
0 | 740 |
741 return 0; | |
742 } | |
743 | |
744 int MPV_encode_end(AVCodecContext *avctx) | |
745 { | |
746 MpegEncContext *s = avctx->priv_data; | |
747 | |
748 #ifdef STATS | |
749 print_stats(); | |
750 #endif | |
329 | 751 |
752 ff_rate_control_uninit(s); | |
753 | |
0 | 754 MPV_common_end(s); |
755 if (s->out_format == FMT_MJPEG) | |
756 mjpeg_close(s); | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
757 |
0 | 758 return 0; |
759 } | |
760 | |
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:
1064
diff
changeset
|
761 #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:
1064
diff
changeset
|
762 |
1042 | 763 void init_rl(RLTable *rl) |
764 { | |
1064 | 765 int8_t max_level[MAX_RUN+1], max_run[MAX_LEVEL+1]; |
766 uint8_t index_run[MAX_RUN+1]; | |
1042 | 767 int last, run, level, start, end, i; |
768 | |
769 /* compute max_level[], max_run[] and index_run[] */ | |
770 for(last=0;last<2;last++) { | |
771 if (last == 0) { | |
772 start = 0; | |
773 end = rl->last; | |
774 } else { | |
775 start = rl->last; | |
776 end = rl->n; | |
777 } | |
778 | |
779 memset(max_level, 0, MAX_RUN + 1); | |
780 memset(max_run, 0, MAX_LEVEL + 1); | |
781 memset(index_run, rl->n, MAX_RUN + 1); | |
782 for(i=start;i<end;i++) { | |
783 run = rl->table_run[i]; | |
784 level = rl->table_level[i]; | |
785 if (index_run[run] == rl->n) | |
786 index_run[run] = i; | |
787 if (level > max_level[run]) | |
788 max_level[run] = level; | |
789 if (run > max_run[level]) | |
790 max_run[level] = run; | |
791 } | |
792 rl->max_level[last] = av_malloc(MAX_RUN + 1); | |
793 memcpy(rl->max_level[last], max_level, MAX_RUN + 1); | |
794 rl->max_run[last] = av_malloc(MAX_LEVEL + 1); | |
795 memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1); | |
796 rl->index_run[last] = av_malloc(MAX_RUN + 1); | |
797 memcpy(rl->index_run[last], index_run, MAX_RUN + 1); | |
798 } | |
799 } | |
800 | |
0 | 801 /* draw the edges of width 'w' of an image of size width, height */ |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
802 //FIXME check that this is ok for mpeg4 interlaced |
1064 | 803 static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w) |
0 | 804 { |
1064 | 805 uint8_t *ptr, *last_line; |
0 | 806 int i; |
807 | |
808 last_line = buf + (height - 1) * wrap; | |
809 for(i=0;i<w;i++) { | |
810 /* top and bottom */ | |
811 memcpy(buf - (i + 1) * wrap, buf, width); | |
812 memcpy(last_line + (i + 1) * wrap, last_line, width); | |
813 } | |
814 /* left and right */ | |
815 ptr = buf; | |
816 for(i=0;i<height;i++) { | |
817 memset(ptr - w, ptr[0], w); | |
818 memset(ptr + width, ptr[width-1], w); | |
819 ptr += wrap; | |
820 } | |
821 /* corners */ | |
822 for(i=0;i<w;i++) { | |
823 memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */ | |
824 memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */ | |
825 memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */ | |
826 memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */ | |
827 } | |
828 } | |
829 | |
924 | 830 static int find_unused_picture(MpegEncContext *s, int shared){ |
831 int i; | |
832 | |
833 if(shared){ | |
834 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
835 if(s->picture[i].data[0]==NULL && s->picture[i].type==0) break; | |
836 } | |
837 }else{ | |
838 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
839 if(s->picture[i].data[0]==NULL && s->picture[i].type!=0) break; | |
840 } | |
841 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
842 if(s->picture[i].data[0]==NULL) break; | |
843 } | |
844 } | |
845 | |
846 assert(i<MAX_PICTURE_COUNT); | |
847 return i; | |
848 } | |
849 | |
0 | 850 /* generic function for encode/decode called before a frame is coded/decoded */ |
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
851 int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) |
0 | 852 { |
924 | 853 int i; |
925 | 854 AVFrame *pic; |
0 | 855 |
46
931417475f5b
fixed mpeg1 first block bug (pb with black picture optimisation for B frames)
glantau
parents:
40
diff
changeset
|
856 s->mb_skiped = 0; |
903 | 857 |
858 /* mark&release old frames */ | |
1138 | 859 if (s->pict_type != B_TYPE && s->last_picture_ptr) { |
860 avctx->release_buffer(avctx, (AVFrame*)s->last_picture_ptr); | |
903 | 861 |
862 /* release forgotten pictures */ | |
863 /* if(mpeg124/h263) */ | |
864 if(!s->encoding){ | |
865 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
1138 | 866 if(s->picture[i].data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference){ |
903 | 867 fprintf(stderr, "releasing zombie picture\n"); |
925 | 868 avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]); |
903 | 869 } |
870 } | |
871 } | |
872 } | |
1138 | 873 |
910
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
874 alloc: |
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
875 if(!s->encoding){ |
924 | 876 i= find_unused_picture(s, 0); |
903 | 877 |
925 | 878 pic= (AVFrame*)&s->picture[i]; |
903 | 879 pic->reference= s->pict_type != B_TYPE; |
1138 | 880 |
881 if(s->current_picture_ptr) | |
882 pic->coded_picture_number= s->current_picture_ptr->coded_picture_number+1; | |
903 | 883 |
924 | 884 alloc_picture(s, (Picture*)pic, 0); |
903 | 885 |
1138 | 886 s->current_picture_ptr= &s->picture[i]; |
903 | 887 } |
456 | 888 |
903 | 889 if (s->pict_type != B_TYPE) { |
1138 | 890 s->last_picture_ptr= s->next_picture_ptr; |
891 s->next_picture_ptr= s->current_picture_ptr; | |
892 } | |
893 s->current_picture= *s->current_picture_ptr; | |
894 if(s->last_picture_ptr) s->last_picture= *s->last_picture_ptr; | |
895 if(s->next_picture_ptr) s->next_picture= *s->next_picture_ptr; | |
896 if(s->new_picture_ptr ) s->new_picture = *s->new_picture_ptr; | |
897 | |
898 if(s->picture_structure!=PICT_FRAME){ | |
899 int i; | |
900 for(i=0; i<4; i++){ | |
901 if(s->picture_structure == PICT_BOTTOM_FIELD){ | |
902 s->current_picture.data[i] += s->current_picture.linesize[i]; | |
903 } | |
904 s->current_picture.linesize[i] *= 2; | |
905 s->last_picture.linesize[i] *=2; | |
906 s->next_picture.linesize[i] *=2; | |
907 } | |
553 | 908 } |
910
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
909 |
1138 | 910 if(s->pict_type != I_TYPE && s->last_picture_ptr==NULL){ |
910
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
911 fprintf(stderr, "warning: first frame is no keyframe\n"); |
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
912 assert(s->pict_type != B_TYPE); //these should have been dropped if we dont have a reference |
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
913 goto alloc; |
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
914 } |
903 | 915 |
910
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
916 s->hurry_up= s->avctx->hurry_up; |
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
917 s->error_resilience= avctx->error_resilience; |
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
918 |
591 | 919 /* set dequantizer, we cant do it during init as it might change for mpeg4 |
920 and we cant do it in the header decode as init isnt called for mpeg4 there yet */ | |
921 if(s->out_format == FMT_H263){ | |
922 if(s->mpeg_quant) | |
923 s->dct_unquantize = s->dct_unquantize_mpeg2; | |
924 else | |
925 s->dct_unquantize = s->dct_unquantize_h263; | |
926 }else | |
927 s->dct_unquantize = s->dct_unquantize_mpeg1; | |
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
928 |
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
929 return 0; |
0 | 930 } |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
931 |
0 | 932 /* generic function for encode/decode called after a frame has been coded/decoded */ |
933 void MPV_frame_end(MpegEncContext *s) | |
934 { | |
903 | 935 int i; |
0 | 936 /* draw edge for correct motion prediction if outside */ |
903 | 937 if(s->codec_id!=CODEC_ID_SVQ1){ |
938 if (s->pict_type != B_TYPE && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) { | |
939 draw_edges(s->current_picture.data[0], s->linesize , s->h_edge_pos , s->v_edge_pos , EDGE_WIDTH ); | |
940 draw_edges(s->current_picture.data[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); | |
941 draw_edges(s->current_picture.data[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); | |
942 } | |
0 | 943 } |
207 | 944 emms_c(); |
329 | 945 |
612 | 946 s->last_pict_type = s->pict_type; |
329 | 947 if(s->pict_type!=B_TYPE){ |
948 s->last_non_b_pict_type= s->pict_type; | |
949 } | |
1138 | 950 #if 0 |
951 /* copy back current_picture variables */ | |
903 | 952 for(i=0; i<MAX_PICTURE_COUNT; i++){ |
953 if(s->picture[i].data[0] == s->current_picture.data[0]){ | |
954 s->picture[i]= s->current_picture; | |
955 break; | |
956 } | |
957 } | |
958 assert(i<MAX_PICTURE_COUNT); | |
1138 | 959 #endif |
960 s->current_picture_ptr->quality= s->qscale; //FIXME get average of qscale_table | |
961 s->current_picture_ptr->pict_type= s->pict_type; | |
962 s->current_picture_ptr->key_frame= s->pict_type == I_TYPE; | |
903 | 963 |
964 /* release non refernce frames */ | |
965 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
924 | 966 if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/) |
925 | 967 s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]); |
324 | 968 } |
936 | 969 if(s->avctx->debug&FF_DEBUG_SKIP){ |
970 int x,y; | |
971 for(y=0; y<s->mb_height; y++){ | |
972 for(x=0; x<s->mb_width; x++){ | |
973 int count= s->mbskip_table[x + y*s->mb_width]; | |
974 if(count>9) count=9; | |
975 printf(" %1d", count); | |
976 } | |
977 printf("\n"); | |
978 } | |
979 printf("pict type: %d\n", s->pict_type); | |
980 } | |
1138 | 981 |
982 // clear copies, to avoid confusion | |
983 #if 0 | |
984 memset(&s->last_picture, 0, sizeof(Picture)); | |
985 memset(&s->next_picture, 0, sizeof(Picture)); | |
986 memset(&s->current_picture, 0, sizeof(Picture)); | |
987 #endif | |
903 | 988 } |
989 | |
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:
1064
diff
changeset
|
990 #ifdef 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:
1064
diff
changeset
|
991 |
915 | 992 static int get_sae(uint8_t *src, int ref, int stride){ |
993 int x,y; | |
994 int acc=0; | |
995 | |
996 for(y=0; y<16; y++){ | |
997 for(x=0; x<16; x++){ | |
998 acc+= ABS(src[x+y*stride] - ref); | |
999 } | |
1000 } | |
1001 | |
1002 return acc; | |
1003 } | |
1004 | |
1005 static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride){ | |
1006 int x, y, w, h; | |
1007 int acc=0; | |
1008 | |
1009 w= s->width &~15; | |
1010 h= s->height&~15; | |
1011 | |
1012 for(y=0; y<h; y+=16){ | |
1013 for(x=0; x<w; x+=16){ | |
1014 int offset= x + y*stride; | |
1015 int sad = s->dsp.pix_abs16x16(src + offset, ref + offset, stride); | |
1016 int mean= (s->dsp.pix_sum(src + offset, stride) + 128)>>8; | |
1017 int sae = get_sae(src + offset, mean, stride); | |
1018 | |
1019 acc+= sae + 500 < sad; | |
1020 } | |
1021 } | |
1022 return acc; | |
1023 } | |
1024 | |
924 | 1025 |
925 | 1026 static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){ |
1027 AVFrame *pic; | |
924 | 1028 int i; |
903 | 1029 const int encoding_delay= s->max_b_frames; |
924 | 1030 int direct=1; |
1031 | |
1032 if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0; | |
1033 if(pic_arg->linesize[0] != s->linesize) direct=0; | |
1034 if(pic_arg->linesize[1] != s->uvlinesize) direct=0; | |
1035 if(pic_arg->linesize[2] != s->uvlinesize) direct=0; | |
1036 | |
1037 // printf("%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize); | |
1038 | |
1039 if(direct){ | |
1040 i= find_unused_picture(s, 1); | |
1041 | |
925 | 1042 pic= (AVFrame*)&s->picture[i]; |
924 | 1043 pic->reference= 1; |
903 | 1044 |
924 | 1045 for(i=0; i<4; i++){ |
1046 pic->data[i]= pic_arg->data[i]; | |
1047 pic->linesize[i]= pic_arg->linesize[i]; | |
1048 } | |
1049 alloc_picture(s, (Picture*)pic, 1); | |
1050 }else{ | |
1051 i= find_unused_picture(s, 0); | |
1052 | |
925 | 1053 pic= (AVFrame*)&s->picture[i]; |
924 | 1054 pic->reference= 1; |
1055 | |
1056 alloc_picture(s, (Picture*)pic, 0); | |
1138 | 1057 for(i=0; i<4; i++){ |
1058 /* the input will be 16 pixels to the right relative to the actual buffer start | |
1059 * and the current_pic, so the buffer can be reused, yes its not beatifull | |
1060 */ | |
1061 pic->data[i]+= 16; | |
1062 } | |
924 | 1063 |
1064 if( pic->data[0] == pic_arg->data[0] | |
1065 && pic->data[1] == pic_arg->data[1] | |
1066 && pic->data[2] == pic_arg->data[2]){ | |
1067 // empty | |
1068 }else{ | |
1069 int h_chroma_shift, v_chroma_shift; | |
1070 | |
1071 avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); | |
1072 | |
1073 for(i=0; i<3; i++){ | |
1074 int src_stride= pic_arg->linesize[i]; | |
1075 int dst_stride= i ? s->uvlinesize : s->linesize; | |
1076 int h_shift= i ? h_chroma_shift : 0; | |
1077 int v_shift= i ? v_chroma_shift : 0; | |
1078 int w= s->width >>h_shift; | |
1079 int h= s->height>>v_shift; | |
1080 uint8_t *src= pic_arg->data[i]; | |
1081 uint8_t *dst= pic->data[i]; | |
1082 | |
1083 if(src_stride==dst_stride) | |
1084 memcpy(dst, src, src_stride*h); | |
1085 else{ | |
1086 while(h--){ | |
1087 memcpy(dst, src, w); | |
1088 dst += dst_stride; | |
1089 src += src_stride; | |
1090 } | |
1091 } | |
1092 } | |
1093 } | |
324 | 1094 } |
924 | 1095 pic->quality= pic_arg->quality; |
1096 pic->pict_type= pic_arg->pict_type; | |
955
8f5d4c666806
pts encoding fix patch by (Thomas Jarosch <tomj at simonv dot com>)
michaelni
parents:
954
diff
changeset
|
1097 pic->pts = pic_arg->pts; |
903 | 1098 |
1099 if(s->input_picture[encoding_delay]) | |
1100 pic->display_picture_number= s->input_picture[encoding_delay]->display_picture_number + 1; | |
1101 | |
1102 /* shift buffer entries */ | |
1103 for(i=1; i<MAX_PICTURE_COUNT /*s->encoding_delay+1*/; i++) | |
1104 s->input_picture[i-1]= s->input_picture[i]; | |
1105 | |
1106 s->input_picture[encoding_delay]= (Picture*)pic; | |
1107 | |
1108 return 0; | |
1109 } | |
1110 | |
1111 static void select_input_picture(MpegEncContext *s){ | |
1112 int i; | |
1113 const int encoding_delay= s->max_b_frames; | |
1114 int coded_pic_num=0; | |
1115 | |
1116 if(s->reordered_input_picture[0]) | |
1117 coded_pic_num= s->reordered_input_picture[0]->coded_picture_number + 1; | |
924 | 1118 |
903 | 1119 for(i=1; i<MAX_PICTURE_COUNT; i++) |
1120 s->reordered_input_picture[i-1]= s->reordered_input_picture[i]; | |
1121 s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL; | |
1122 | |
1123 /* set next picture types & ordering */ | |
1124 if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){ | |
1138 | 1125 if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture_ptr==NULL || s->intra_only){ |
915 | 1126 s->reordered_input_picture[0]= s->input_picture[0]; |
1127 s->reordered_input_picture[0]->pict_type= I_TYPE; | |
1128 s->reordered_input_picture[0]->coded_picture_number= coded_pic_num; | |
1129 }else{ | |
1130 int b_frames; | |
1131 | |
1132 if(s->flags&CODEC_FLAG_PASS2){ | |
1133 for(i=0; i<s->max_b_frames+1; i++){ | |
1134 int pict_num= s->input_picture[0]->display_picture_number + i; | |
1135 int pict_type= s->rc_context.entry[pict_num].new_pict_type; | |
1136 s->input_picture[i]->pict_type= pict_type; | |
1137 | |
1138 if(i + 1 >= s->rc_context.num_entries) break; | |
1139 } | |
1140 } | |
924 | 1141 |
915 | 1142 if(s->input_picture[0]->pict_type){ |
1143 /* user selected pict_type */ | |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
1144 for(b_frames=0; b_frames<s->max_b_frames+1; b_frames++){ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
1145 if(s->input_picture[b_frames]->pict_type!=B_TYPE) break; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
1146 } |
915 | 1147 |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
1148 if(b_frames > s->max_b_frames){ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
1149 fprintf(stderr, "warning, too many bframes in a row\n"); |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
1150 b_frames = s->max_b_frames; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
1151 } |
915 | 1152 }else if(s->b_frame_strategy==0){ |
1153 b_frames= s->max_b_frames; | |
1154 }else if(s->b_frame_strategy==1){ | |
1155 for(i=1; i<s->max_b_frames+1; i++){ | |
1156 if(s->input_picture[i]->b_frame_score==0){ | |
1157 s->input_picture[i]->b_frame_score= | |
924 | 1158 get_intra_count(s, s->input_picture[i ]->data[0], |
1159 s->input_picture[i-1]->data[0], s->linesize) + 1; | |
915 | 1160 } |
1161 } | |
1162 for(i=0; i<s->max_b_frames; i++){ | |
1163 if(s->input_picture[i]->b_frame_score - 1 > s->mb_num/40) break; | |
1164 } | |
1165 | |
1166 b_frames= FFMAX(0, i-1); | |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
1167 |
915 | 1168 /* reset scores */ |
1169 for(i=0; i<b_frames+1; i++){ | |
1170 s->input_picture[i]->b_frame_score=0; | |
1171 } | |
1172 }else{ | |
1173 fprintf(stderr, "illegal b frame strategy\n"); | |
1174 b_frames=0; | |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
1175 } |
915 | 1176 |
1177 emms_c(); | |
1178 //static int b_count=0; | |
1179 //b_count+= b_frames; | |
1180 //printf("b_frames: %d\n", b_count); | |
1181 | |
1182 s->reordered_input_picture[0]= s->input_picture[b_frames]; | |
1183 if( s->picture_in_gop_number + b_frames >= s->gop_size | |
1184 || s->reordered_input_picture[0]->pict_type== I_TYPE) | |
903 | 1185 s->reordered_input_picture[0]->pict_type= I_TYPE; |
915 | 1186 else |
1187 s->reordered_input_picture[0]->pict_type= P_TYPE; | |
1188 s->reordered_input_picture[0]->coded_picture_number= coded_pic_num; | |
1189 for(i=0; i<b_frames; i++){ | |
1190 coded_pic_num++; | |
1191 s->reordered_input_picture[i+1]= s->input_picture[i]; | |
1192 s->reordered_input_picture[i+1]->pict_type= B_TYPE; | |
1193 s->reordered_input_picture[i+1]->coded_picture_number= coded_pic_num; | |
903 | 1194 } |
324 | 1195 } |
1196 } | |
903 | 1197 |
1198 if(s->reordered_input_picture[0]){ | |
1138 | 1199 s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=B_TYPE; |
1200 | |
1201 s->new_picture= *s->reordered_input_picture[0]; | |
924 | 1202 |
1203 if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_SHARED){ | |
1138 | 1204 // input is a shared pix, so we cant modifiy it -> alloc a new one & ensure that the shared one is reuseable |
1205 | |
924 | 1206 int i= find_unused_picture(s, 0); |
1207 Picture *pic= &s->picture[i]; | |
1208 | |
1209 /* mark us unused / free shared pic */ | |
1210 for(i=0; i<4; i++) | |
1211 s->reordered_input_picture[0]->data[i]= NULL; | |
1212 s->reordered_input_picture[0]->type= 0; | |
1213 | |
1138 | 1214 //FIXME bad, copy * except |
924 | 1215 pic->pict_type = s->reordered_input_picture[0]->pict_type; |
1216 pic->quality = s->reordered_input_picture[0]->quality; | |
1217 pic->coded_picture_number = s->reordered_input_picture[0]->coded_picture_number; | |
1218 pic->reference = s->reordered_input_picture[0]->reference; | |
1219 | |
1220 alloc_picture(s, pic, 0); | |
1221 | |
1138 | 1222 s->current_picture_ptr= pic; |
924 | 1223 }else{ |
1138 | 1224 // input is not a shared pix -> reuse buffer for current_pix |
1225 | |
924 | 1226 assert( s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_USER |
1227 || s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); | |
1228 | |
1138 | 1229 s->current_picture_ptr= s->reordered_input_picture[0]; |
924 | 1230 for(i=0; i<4; i++){ |
1138 | 1231 //reverse the +16 we did before storing the input |
1232 s->current_picture_ptr->data[i]-=16; | |
924 | 1233 } |
903 | 1234 } |
1138 | 1235 s->current_picture= *s->current_picture_ptr; |
903 | 1236 |
1237 s->picture_number= s->new_picture.display_picture_number; | |
1238 //printf("dpn:%d\n", s->picture_number); | |
1239 }else{ | |
1240 memset(&s->new_picture, 0, sizeof(Picture)); | |
324 | 1241 } |
1242 } | |
1243 | |
0 | 1244 int MPV_encode_picture(AVCodecContext *avctx, |
1245 unsigned char *buf, int buf_size, void *data) | |
1246 { | |
1247 MpegEncContext *s = avctx->priv_data; | |
925 | 1248 AVFrame *pic_arg = data; |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
1249 int i; |
0 | 1250 |
1251 init_put_bits(&s->pb, buf, buf_size, NULL, NULL); | |
1252 | |
903 | 1253 s->picture_in_gop_number++; |
1254 | |
1255 load_input_picture(s, pic_arg); | |
329 | 1256 |
903 | 1257 select_input_picture(s); |
324 | 1258 |
1259 /* output? */ | |
903 | 1260 if(s->new_picture.data[0]){ |
1261 | |
1262 s->pict_type= s->new_picture.pict_type; | |
1263 if (s->fixed_qscale){ /* the ratecontrol needs the last qscale so we dont touch it for CBR */ | |
1264 s->qscale= (int)(s->new_picture.quality+0.5); | |
1265 assert(s->qscale); | |
1266 } | |
1267 //emms_c(); | |
1268 //printf("qs:%f %f %d\n", s->new_picture.quality, s->current_picture.quality, s->qscale); | |
553 | 1269 MPV_frame_start(s, avctx); |
286 | 1270 |
324 | 1271 encode_picture(s, s->picture_number); |
652 | 1272 |
376 | 1273 avctx->real_pict_num = s->picture_number; |
324 | 1274 avctx->header_bits = s->header_bits; |
1275 avctx->mv_bits = s->mv_bits; | |
1276 avctx->misc_bits = s->misc_bits; | |
1277 avctx->i_tex_bits = s->i_tex_bits; | |
1278 avctx->p_tex_bits = s->p_tex_bits; | |
1279 avctx->i_count = s->i_count; | |
656
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
1280 avctx->p_count = s->mb_num - s->i_count - s->skip_count; //FIXME f/b_count in avctx |
324 | 1281 avctx->skip_count = s->skip_count; |
0 | 1282 |
324 | 1283 MPV_frame_end(s); |
1284 | |
1285 if (s->out_format == FMT_MJPEG) | |
1286 mjpeg_picture_trailer(s); | |
329 | 1287 |
1288 if(s->flags&CODEC_FLAG_PASS1) | |
1289 ff_write_pass1_stats(s); | |
1138 | 1290 |
1291 for(i=0; i<4; i++){ | |
1292 avctx->error[i] += s->current_picture_ptr->error[i]; | |
1293 } | |
324 | 1294 } |
1295 | |
1296 s->input_picture_number++; | |
0 | 1297 |
1298 flush_put_bits(&s->pb); | |
268 | 1299 s->frame_bits = (pbBufPtr(&s->pb) - s->pb.buf) * 8; |
612 | 1300 |
268 | 1301 s->total_bits += s->frame_bits; |
286 | 1302 avctx->frame_bits = s->frame_bits; |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
1303 |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
1304 return pbBufPtr(&s->pb) - s->pb.buf; |
0 | 1305 } |
1306 | |
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:
1064
diff
changeset
|
1307 #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:
1064
diff
changeset
|
1308 |
255 | 1309 static inline void gmc1_motion(MpegEncContext *s, |
1064 | 1310 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
255 | 1311 int dest_offset, |
1064 | 1312 uint8_t **ref_picture, int src_offset) |
255 | 1313 { |
1064 | 1314 uint8_t *ptr; |
556 | 1315 int offset, src_x, src_y, linesize, uvlinesize; |
255 | 1316 int motion_x, motion_y; |
566 | 1317 int emu=0; |
255 | 1318 |
1319 motion_x= s->sprite_offset[0][0]; | |
1320 motion_y= s->sprite_offset[0][1]; | |
1321 src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
1322 src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
1323 motion_x<<=(3-s->sprite_warping_accuracy); | |
1324 motion_y<<=(3-s->sprite_warping_accuracy); | |
1325 src_x = clip(src_x, -16, s->width); | |
1326 if (src_x == s->width) | |
1327 motion_x =0; | |
1328 src_y = clip(src_y, -16, s->height); | |
1329 if (src_y == s->height) | |
1330 motion_y =0; | |
753 | 1331 |
255 | 1332 linesize = s->linesize; |
556 | 1333 uvlinesize = s->uvlinesize; |
753 | 1334 |
255 | 1335 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; |
1336 | |
1337 dest_y+=dest_offset; | |
566 | 1338 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
1002 | 1339 if(src_x<0 || src_y<0 || src_x + 17 >= s->h_edge_pos |
1340 || src_y + 17 >= s->v_edge_pos){ | |
936 | 1341 ff_emulated_edge_mc(s, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos); |
566 | 1342 ptr= s->edge_emu_buffer; |
1343 } | |
1344 } | |
753 | 1345 |
1346 if((motion_x|motion_y)&7){ | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1347 s->dsp.gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1348 s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); |
753 | 1349 }else{ |
1350 int dxy; | |
1351 | |
1352 dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2); | |
1353 if (s->no_rounding){ | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1354 s->dsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16); |
753 | 1355 }else{ |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1356 s->dsp.put_pixels_tab [0][dxy](dest_y, ptr, linesize, 16); |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1357 } |
753 | 1358 } |
1359 | |
1360 if(s->flags&CODEC_FLAG_GRAY) return; | |
255 | 1361 |
1362 motion_x= s->sprite_offset[1][0]; | |
1363 motion_y= s->sprite_offset[1][1]; | |
1364 src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
1365 src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
1366 motion_x<<=(3-s->sprite_warping_accuracy); | |
1367 motion_y<<=(3-s->sprite_warping_accuracy); | |
1368 src_x = clip(src_x, -8, s->width>>1); | |
1369 if (src_x == s->width>>1) | |
1370 motion_x =0; | |
1371 src_y = clip(src_y, -8, s->height>>1); | |
1372 if (src_y == s->height>>1) | |
1373 motion_y =0; | |
1374 | |
556 | 1375 offset = (src_y * uvlinesize) + src_x + (src_offset>>1); |
255 | 1376 ptr = ref_picture[1] + offset; |
1002 | 1377 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
1378 if(src_x<0 || src_y<0 || src_x + 9 >= s->h_edge_pos>>1 | |
1379 || src_y + 9 >= s->v_edge_pos>>1){ | |
1380 ff_emulated_edge_mc(s, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
1381 ptr= s->edge_emu_buffer; | |
1382 emu=1; | |
1383 } | |
566 | 1384 } |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1385 s->dsp.gmc1(dest_cb + (dest_offset>>1), ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); |
566 | 1386 |
255 | 1387 ptr = ref_picture[2] + offset; |
566 | 1388 if(emu){ |
936 | 1389 ff_emulated_edge_mc(s, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
566 | 1390 ptr= s->edge_emu_buffer; |
1391 } | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1392 s->dsp.gmc1(dest_cr + (dest_offset>>1), ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); |
255 | 1393 |
1394 return; | |
1395 } | |
1396 | |
753 | 1397 static inline void gmc_motion(MpegEncContext *s, |
1064 | 1398 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
753 | 1399 int dest_offset, |
1064 | 1400 uint8_t **ref_picture, int src_offset) |
753 | 1401 { |
1064 | 1402 uint8_t *ptr; |
753 | 1403 int linesize, uvlinesize; |
1404 const int a= s->sprite_warping_accuracy; | |
1405 int ox, oy; | |
1406 | |
1407 linesize = s->linesize; | |
1408 uvlinesize = s->uvlinesize; | |
1409 | |
1410 ptr = ref_picture[0] + src_offset; | |
1411 | |
1412 dest_y+=dest_offset; | |
1413 | |
1414 ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16; | |
1415 oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16; | |
1416 | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1417 s->dsp.gmc(dest_y, ptr, linesize, 16, |
753 | 1418 ox, |
1419 oy, | |
1420 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
1421 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
1422 a+1, (1<<(2*a+1)) - s->no_rounding, | |
1423 s->h_edge_pos, s->v_edge_pos); | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1424 s->dsp.gmc(dest_y+8, ptr, linesize, 16, |
753 | 1425 ox + s->sprite_delta[0][0]*8, |
1426 oy + s->sprite_delta[1][0]*8, | |
1427 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
1428 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
1429 a+1, (1<<(2*a+1)) - s->no_rounding, | |
1430 s->h_edge_pos, s->v_edge_pos); | |
1431 | |
1432 if(s->flags&CODEC_FLAG_GRAY) return; | |
1433 | |
1434 | |
1435 dest_cb+=dest_offset>>1; | |
1436 dest_cr+=dest_offset>>1; | |
1437 | |
1438 ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8; | |
1439 oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8; | |
1440 | |
1441 ptr = ref_picture[1] + (src_offset>>1); | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1442 s->dsp.gmc(dest_cb, ptr, uvlinesize, 8, |
753 | 1443 ox, |
1444 oy, | |
1445 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
1446 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
1447 a+1, (1<<(2*a+1)) - s->no_rounding, | |
1448 s->h_edge_pos>>1, s->v_edge_pos>>1); | |
1449 | |
1450 ptr = ref_picture[2] + (src_offset>>1); | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1451 s->dsp.gmc(dest_cr, ptr, uvlinesize, 8, |
753 | 1452 ox, |
1453 oy, | |
1454 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
1455 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
1456 a+1, (1<<(2*a+1)) - s->no_rounding, | |
1457 s->h_edge_pos>>1, s->v_edge_pos>>1); | |
1458 } | |
1459 | |
1460 | |
1064 | 1461 void ff_emulated_edge_mc(MpegEncContext *s, uint8_t *src, int linesize, int block_w, int block_h, |
553 | 1462 int src_x, int src_y, int w, int h){ |
1463 int x, y; | |
1464 int start_y, start_x, end_y, end_x; | |
1064 | 1465 uint8_t *buf= s->edge_emu_buffer; |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
1466 |
553 | 1467 if(src_y>= h){ |
1468 src+= (h-1-src_y)*linesize; | |
1469 src_y=h-1; | |
554 | 1470 }else if(src_y<=-block_h){ |
1471 src+= (1-block_h-src_y)*linesize; | |
1472 src_y=1-block_h; | |
553 | 1473 } |
1474 if(src_x>= w){ | |
1475 src+= (w-1-src_x); | |
1476 src_x=w-1; | |
554 | 1477 }else if(src_x<=-block_w){ |
1478 src+= (1-block_w-src_x); | |
1479 src_x=1-block_w; | |
553 | 1480 } |
1481 | |
847 | 1482 start_y= FFMAX(0, -src_y); |
1483 start_x= FFMAX(0, -src_x); | |
1484 end_y= FFMIN(block_h, h-src_y); | |
1485 end_x= FFMIN(block_w, w-src_x); | |
566 | 1486 |
553 | 1487 // copy existing part |
1488 for(y=start_y; y<end_y; y++){ | |
1489 for(x=start_x; x<end_x; x++){ | |
1490 buf[x + y*linesize]= src[x + y*linesize]; | |
1491 } | |
1492 } | |
1493 | |
1494 //top | |
1495 for(y=0; y<start_y; y++){ | |
1496 for(x=start_x; x<end_x; x++){ | |
1497 buf[x + y*linesize]= buf[x + start_y*linesize]; | |
1498 } | |
1499 } | |
1500 | |
1501 //bottom | |
1502 for(y=end_y; y<block_h; y++){ | |
1503 for(x=start_x; x<end_x; x++){ | |
1504 buf[x + y*linesize]= buf[x + (end_y-1)*linesize]; | |
1505 } | |
1506 } | |
1507 | |
1508 for(y=0; y<block_h; y++){ | |
1509 //left | |
1510 for(x=0; x<start_x; x++){ | |
1511 buf[x + y*linesize]= buf[start_x + y*linesize]; | |
1512 } | |
1513 | |
1514 //right | |
1515 for(x=end_x; x<block_w; x++){ | |
1516 buf[x + y*linesize]= buf[end_x - 1 + y*linesize]; | |
1517 } | |
1518 } | |
1519 } | |
1520 | |
1521 | |
0 | 1522 /* apply one mpeg motion vector to the three components */ |
1523 static inline void mpeg_motion(MpegEncContext *s, | |
1064 | 1524 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
0 | 1525 int dest_offset, |
1064 | 1526 uint8_t **ref_picture, int src_offset, |
651 | 1527 int field_based, op_pixels_func (*pix_op)[4], |
0 | 1528 int motion_x, int motion_y, int h) |
1529 { | |
1064 | 1530 uint8_t *ptr; |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1531 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize; |
553 | 1532 int emu=0; |
651 | 1533 #if 0 |
255 | 1534 if(s->quarter_sample) |
1535 { | |
1536 motion_x>>=1; | |
1537 motion_y>>=1; | |
1538 } | |
651 | 1539 #endif |
0 | 1540 dxy = ((motion_y & 1) << 1) | (motion_x & 1); |
1541 src_x = s->mb_x * 16 + (motion_x >> 1); | |
1542 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1); | |
1543 | |
1544 /* WARNING: do no forget half pels */ | |
1545 height = s->height >> field_based; | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1546 v_edge_pos = s->v_edge_pos >> field_based; |
0 | 1547 src_x = clip(src_x, -16, s->width); |
1548 if (src_x == s->width) | |
1549 dxy &= ~1; | |
1550 src_y = clip(src_y, -16, height); | |
1551 if (src_y == height) | |
1552 dxy &= ~2; | |
1138 | 1553 linesize = s->current_picture.linesize[0] << field_based; |
1554 uvlinesize = s->current_picture.linesize[1] << field_based; | |
0 | 1555 ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset; |
1556 dest_y += dest_offset; | |
553 | 1557 |
1558 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1559 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 16 > s->h_edge_pos |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1560 || src_y + (motion_y&1) + h > v_edge_pos){ |
1138 | 1561 ff_emulated_edge_mc(s, ptr - src_offset, s->linesize, 17, 17+field_based, //FIXME linesize? and uv below |
763 | 1562 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); |
1563 ptr= s->edge_emu_buffer + src_offset; | |
553 | 1564 emu=1; |
1565 } | |
1566 } | |
651 | 1567 pix_op[0][dxy](dest_y, ptr, linesize, h); |
0 | 1568 |
485 | 1569 if(s->flags&CODEC_FLAG_GRAY) return; |
1570 | |
0 | 1571 if (s->out_format == FMT_H263) { |
1572 dxy = 0; | |
1573 if ((motion_x & 3) != 0) | |
1574 dxy |= 1; | |
1575 if ((motion_y & 3) != 0) | |
1576 dxy |= 2; | |
1577 mx = motion_x >> 2; | |
1578 my = motion_y >> 2; | |
1579 } else { | |
1580 mx = motion_x / 2; | |
1581 my = motion_y / 2; | |
1582 dxy = ((my & 1) << 1) | (mx & 1); | |
1583 mx >>= 1; | |
1584 my >>= 1; | |
1585 } | |
1586 | |
1587 src_x = s->mb_x * 8 + mx; | |
1588 src_y = s->mb_y * (8 >> field_based) + my; | |
1589 src_x = clip(src_x, -8, s->width >> 1); | |
1590 if (src_x == (s->width >> 1)) | |
1591 dxy &= ~1; | |
1592 src_y = clip(src_y, -8, height >> 1); | |
1593 if (src_y == (height >> 1)) | |
1594 dxy &= ~2; | |
565
44d744901ded
interlaced mpeg2 fix ... replacing linesize>>1 by uvlinesize brainlessly wasnt a good idea
michaelni
parents:
562
diff
changeset
|
1595 offset = (src_y * uvlinesize) + src_x + (src_offset >> 1); |
0 | 1596 ptr = ref_picture[1] + offset; |
553 | 1597 if(emu){ |
936 | 1598 ff_emulated_edge_mc(s, ptr - (src_offset >> 1), s->uvlinesize, 9, 9+field_based, |
763 | 1599 src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); |
1600 ptr= s->edge_emu_buffer + (src_offset >> 1); | |
553 | 1601 } |
651 | 1602 pix_op[1][dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
553 | 1603 |
0 | 1604 ptr = ref_picture[2] + offset; |
553 | 1605 if(emu){ |
936 | 1606 ff_emulated_edge_mc(s, ptr - (src_offset >> 1), s->uvlinesize, 9, 9+field_based, |
763 | 1607 src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); |
1608 ptr= s->edge_emu_buffer + (src_offset >> 1); | |
553 | 1609 } |
651 | 1610 pix_op[1][dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
0 | 1611 } |
1612 | |
255 | 1613 static inline void qpel_motion(MpegEncContext *s, |
1064 | 1614 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
255 | 1615 int dest_offset, |
1064 | 1616 uint8_t **ref_picture, int src_offset, |
651 | 1617 int field_based, op_pixels_func (*pix_op)[4], |
1618 qpel_mc_func (*qpix_op)[16], | |
255 | 1619 int motion_x, int motion_y, int h) |
1620 { | |
1064 | 1621 uint8_t *ptr; |
671 | 1622 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize; |
554 | 1623 int emu=0; |
255 | 1624 |
1625 dxy = ((motion_y & 3) << 2) | (motion_x & 3); | |
1626 src_x = s->mb_x * 16 + (motion_x >> 2); | |
1627 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); | |
1628 | |
1629 height = s->height >> field_based; | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1630 v_edge_pos = s->v_edge_pos >> field_based; |
255 | 1631 src_x = clip(src_x, -16, s->width); |
1632 if (src_x == s->width) | |
1633 dxy &= ~3; | |
1634 src_y = clip(src_y, -16, height); | |
1635 if (src_y == height) | |
1636 dxy &= ~12; | |
1637 linesize = s->linesize << field_based; | |
671 | 1638 uvlinesize = s->uvlinesize << field_based; |
255 | 1639 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; |
1640 dest_y += dest_offset; | |
1641 //printf("%d %d %d\n", src_x, src_y, dxy); | |
554 | 1642 |
1643 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1644 if(src_x<0 || src_y<0 || src_x + (motion_x&3) + 16 > s->h_edge_pos |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1645 || src_y + (motion_y&3) + h > v_edge_pos){ |
936 | 1646 ff_emulated_edge_mc(s, ptr - src_offset, s->linesize, 17, 17+field_based, |
763 | 1647 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); |
1648 ptr= s->edge_emu_buffer + src_offset; | |
554 | 1649 emu=1; |
1650 } | |
1651 } | |
671 | 1652 if(!field_based) |
1653 qpix_op[0][dxy](dest_y, ptr, linesize); | |
1654 else{ | |
1655 //damn interlaced mode | |
1656 //FIXME boundary mirroring is not exactly correct here | |
1657 qpix_op[1][dxy](dest_y , ptr , linesize); | |
1658 qpix_op[1][dxy](dest_y+8, ptr+8, linesize); | |
1659 } | |
651 | 1660 |
485 | 1661 if(s->flags&CODEC_FLAG_GRAY) return; |
1662 | |
671 | 1663 if(field_based){ |
1664 mx= motion_x/2; | |
1665 my= motion_y>>1; | |
1048 | 1666 }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){ |
1667 static const int rtab[8]= {0,0,1,1,0,0,0,1}; | |
1668 mx= (motion_x>>1) + rtab[motion_x&7]; | |
1669 my= (motion_y>>1) + rtab[motion_y&7]; | |
760 | 1670 }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){ |
671 | 1671 mx= (motion_x>>1)|(motion_x&1); |
1672 my= (motion_y>>1)|(motion_y&1); | |
1673 }else{ | |
1674 mx= motion_x/2; | |
1675 my= motion_y/2; | |
1676 } | |
1677 mx= (mx>>1)|(mx&1); | |
1678 my= (my>>1)|(my&1); | |
1048 | 1679 |
671 | 1680 dxy= (mx&1) | ((my&1)<<1); |
1681 mx>>=1; | |
1682 my>>=1; | |
255 | 1683 |
1684 src_x = s->mb_x * 8 + mx; | |
1685 src_y = s->mb_y * (8 >> field_based) + my; | |
1686 src_x = clip(src_x, -8, s->width >> 1); | |
1687 if (src_x == (s->width >> 1)) | |
1688 dxy &= ~1; | |
1689 src_y = clip(src_y, -8, height >> 1); | |
1690 if (src_y == (height >> 1)) | |
1691 dxy &= ~2; | |
1692 | |
671 | 1693 offset = (src_y * uvlinesize) + src_x + (src_offset >> 1); |
255 | 1694 ptr = ref_picture[1] + offset; |
554 | 1695 if(emu){ |
936 | 1696 ff_emulated_edge_mc(s, ptr - (src_offset >> 1), s->uvlinesize, 9, 9 + field_based, |
763 | 1697 src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); |
1698 ptr= s->edge_emu_buffer + (src_offset >> 1); | |
554 | 1699 } |
671 | 1700 pix_op[1][dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
554 | 1701 |
255 | 1702 ptr = ref_picture[2] + offset; |
554 | 1703 if(emu){ |
936 | 1704 ff_emulated_edge_mc(s, ptr - (src_offset >> 1), s->uvlinesize, 9, 9 + field_based, |
763 | 1705 src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); |
1706 ptr= s->edge_emu_buffer + (src_offset >> 1); | |
554 | 1707 } |
671 | 1708 pix_op[1][dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
255 | 1709 } |
1710 | |
1013 | 1711 inline int ff_h263_round_chroma(int x){ |
1712 if (x >= 0) | |
1713 return (h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1)); | |
1714 else { | |
1715 x = -x; | |
1716 return -(h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1)); | |
1717 } | |
1718 } | |
255 | 1719 |
0 | 1720 static inline void MPV_motion(MpegEncContext *s, |
1064 | 1721 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
1722 int dir, uint8_t **ref_picture, | |
651 | 1723 op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16]) |
0 | 1724 { |
1725 int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y; | |
1726 int mb_x, mb_y, i; | |
1064 | 1727 uint8_t *ptr, *dest; |
554 | 1728 int emu=0; |
0 | 1729 |
1730 mb_x = s->mb_x; | |
1731 mb_y = s->mb_y; | |
1732 | |
1733 switch(s->mv_type) { | |
1734 case MV_TYPE_16X16: | |
1042 | 1735 #ifdef CONFIG_RISKY |
255 | 1736 if(s->mcsel){ |
753 | 1737 if(s->real_sprite_warping_points==1){ |
1738 gmc1_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1739 ref_picture, 0); | |
1740 }else{ | |
1741 gmc_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1742 ref_picture, 0); | |
1743 } | |
651 | 1744 }else if(s->quarter_sample){ |
255 | 1745 qpel_motion(s, dest_y, dest_cb, dest_cr, 0, |
1746 ref_picture, 0, | |
1747 0, pix_op, qpix_op, | |
1748 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
936 | 1749 }else if(s->mspel){ |
1750 ff_mspel_motion(s, dest_y, dest_cb, dest_cr, | |
1751 ref_picture, pix_op, | |
1752 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
1042 | 1753 }else |
1754 #endif | |
1755 { | |
255 | 1756 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, |
1757 ref_picture, 0, | |
1758 0, pix_op, | |
1759 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
1760 } | |
0 | 1761 break; |
1762 case MV_TYPE_8X8: | |
673 | 1763 mx = 0; |
1764 my = 0; | |
1765 if(s->quarter_sample){ | |
1766 for(i=0;i<4;i++) { | |
1767 motion_x = s->mv[dir][i][0]; | |
1768 motion_y = s->mv[dir][i][1]; | |
0 | 1769 |
673 | 1770 dxy = ((motion_y & 3) << 2) | (motion_x & 3); |
1771 src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8; | |
1772 src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8; | |
1773 | |
1774 /* WARNING: do no forget half pels */ | |
1775 src_x = clip(src_x, -16, s->width); | |
1776 if (src_x == s->width) | |
1777 dxy &= ~3; | |
1778 src_y = clip(src_y, -16, s->height); | |
1779 if (src_y == s->height) | |
1780 dxy &= ~12; | |
0 | 1781 |
673 | 1782 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); |
1783 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
1784 if(src_x<0 || src_y<0 || src_x + (motion_x&3) + 8 > s->h_edge_pos | |
1785 || src_y + (motion_y&3) + 8 > s->v_edge_pos){ | |
936 | 1786 ff_emulated_edge_mc(s, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos); |
673 | 1787 ptr= s->edge_emu_buffer; |
1788 } | |
1789 } | |
1790 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; | |
1791 qpix_op[1][dxy](dest, ptr, s->linesize); | |
1792 | |
1793 mx += s->mv[dir][i][0]/2; | |
1794 my += s->mv[dir][i][1]/2; | |
1795 } | |
1796 }else{ | |
1797 for(i=0;i<4;i++) { | |
1798 motion_x = s->mv[dir][i][0]; | |
1799 motion_y = s->mv[dir][i][1]; | |
1800 | |
1801 dxy = ((motion_y & 1) << 1) | (motion_x & 1); | |
1802 src_x = mb_x * 16 + (motion_x >> 1) + (i & 1) * 8; | |
1803 src_y = mb_y * 16 + (motion_y >> 1) + (i >>1) * 8; | |
0 | 1804 |
673 | 1805 /* WARNING: do no forget half pels */ |
1806 src_x = clip(src_x, -16, s->width); | |
1807 if (src_x == s->width) | |
1808 dxy &= ~1; | |
1809 src_y = clip(src_y, -16, s->height); | |
1810 if (src_y == s->height) | |
1811 dxy &= ~2; | |
1812 | |
1813 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); | |
1814 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
1815 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 8 > s->h_edge_pos | |
1816 || src_y + (motion_y&1) + 8 > s->v_edge_pos){ | |
936 | 1817 ff_emulated_edge_mc(s, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos); |
673 | 1818 ptr= s->edge_emu_buffer; |
1819 } | |
554 | 1820 } |
673 | 1821 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; |
1822 pix_op[1][dxy](dest, ptr, s->linesize, 8); | |
1823 | |
1824 mx += s->mv[dir][i][0]; | |
1825 my += s->mv[dir][i][1]; | |
554 | 1826 } |
0 | 1827 } |
673 | 1828 |
485 | 1829 if(s->flags&CODEC_FLAG_GRAY) break; |
0 | 1830 /* In case of 8X8, we construct a single chroma motion vector |
1831 with a special rounding */ | |
1013 | 1832 mx= ff_h263_round_chroma(mx); |
1833 my= ff_h263_round_chroma(my); | |
0 | 1834 dxy = ((my & 1) << 1) | (mx & 1); |
1835 mx >>= 1; | |
1836 my >>= 1; | |
1837 | |
1838 src_x = mb_x * 8 + mx; | |
1839 src_y = mb_y * 8 + my; | |
1840 src_x = clip(src_x, -8, s->width/2); | |
1841 if (src_x == s->width/2) | |
1842 dxy &= ~1; | |
1843 src_y = clip(src_y, -8, s->height/2); | |
1844 if (src_y == s->height/2) | |
1845 dxy &= ~2; | |
1846 | |
556 | 1847 offset = (src_y * (s->uvlinesize)) + src_x; |
0 | 1848 ptr = ref_picture[1] + offset; |
554 | 1849 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1850 if(src_x<0 || src_y<0 || src_x + (dxy &1) + 8 > s->h_edge_pos>>1 |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1851 || src_y + (dxy>>1) + 8 > s->v_edge_pos>>1){ |
936 | 1852 ff_emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
554 | 1853 ptr= s->edge_emu_buffer; |
1854 emu=1; | |
1855 } | |
1856 } | |
651 | 1857 pix_op[1][dxy](dest_cb, ptr, s->uvlinesize, 8); |
554 | 1858 |
0 | 1859 ptr = ref_picture[2] + offset; |
554 | 1860 if(emu){ |
936 | 1861 ff_emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
554 | 1862 ptr= s->edge_emu_buffer; |
1863 } | |
651 | 1864 pix_op[1][dxy](dest_cr, ptr, s->uvlinesize, 8); |
0 | 1865 break; |
1866 case MV_TYPE_FIELD: | |
1867 if (s->picture_structure == PICT_FRAME) { | |
671 | 1868 if(s->quarter_sample){ |
1869 /* top field */ | |
1870 qpel_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1871 ref_picture, s->field_select[dir][0] ? s->linesize : 0, | |
1872 1, pix_op, qpix_op, | |
1873 s->mv[dir][0][0], s->mv[dir][0][1], 8); | |
1874 /* bottom field */ | |
1875 qpel_motion(s, dest_y, dest_cb, dest_cr, s->linesize, | |
1876 ref_picture, s->field_select[dir][1] ? s->linesize : 0, | |
1877 1, pix_op, qpix_op, | |
1878 s->mv[dir][1][0], s->mv[dir][1][1], 8); | |
1879 }else{ | |
1880 /* top field */ | |
1881 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1882 ref_picture, s->field_select[dir][0] ? s->linesize : 0, | |
1883 1, pix_op, | |
1884 s->mv[dir][0][0], s->mv[dir][0][1], 8); | |
1885 /* bottom field */ | |
1886 mpeg_motion(s, dest_y, dest_cb, dest_cr, s->linesize, | |
1887 ref_picture, s->field_select[dir][1] ? s->linesize : 0, | |
1888 1, pix_op, | |
1889 s->mv[dir][1][0], s->mv[dir][1][1], 8); | |
1890 } | |
0 | 1891 } else { |
1096
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
1892 int offset; |
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
1893 if(s->picture_structure == s->field_select[dir][0] + 1 || s->pict_type == B_TYPE || s->first_field){ |
1138 | 1894 offset= s->field_select[dir][0] ? s->linesize : 0; |
1096
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
1895 }else{ |
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
1896 ref_picture= s->current_picture.data; |
1138 | 1897 offset= s->field_select[dir][0] ? s->linesize : -s->linesize; |
1096
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
1898 } |
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
1899 |
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
1900 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, |
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
1901 ref_picture, offset, |
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
1902 0, pix_op, |
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
1903 s->mv[dir][0][0], s->mv[dir][0][1], 16); |
0 | 1904 } |
1905 break; | |
1906 } | |
1907 } | |
1908 | |
1909 | |
1910 /* put block[] to dest[] */ | |
1911 static inline void put_dct(MpegEncContext *s, | |
1064 | 1912 DCTELEM *block, int i, uint8_t *dest, int line_size) |
0 | 1913 { |
711 | 1914 s->dct_unquantize(s, block, i, s->qscale); |
1092 | 1915 s->dsp.idct_put (dest, line_size, block); |
0 | 1916 } |
1917 | |
1918 /* add block[] to dest[] */ | |
1919 static inline void add_dct(MpegEncContext *s, | |
1064 | 1920 DCTELEM *block, int i, uint8_t *dest, int line_size) |
0 | 1921 { |
1922 if (s->block_last_index[i] >= 0) { | |
1092 | 1923 s->dsp.idct_add (dest, line_size, block); |
481 | 1924 } |
1925 } | |
1926 | |
1927 static inline void add_dequant_dct(MpegEncContext *s, | |
1064 | 1928 DCTELEM *block, int i, uint8_t *dest, int line_size) |
481 | 1929 { |
1930 if (s->block_last_index[i] >= 0) { | |
1931 s->dct_unquantize(s, block, i, s->qscale); | |
324 | 1932 |
1092 | 1933 s->dsp.idct_add (dest, line_size, block); |
0 | 1934 } |
1935 } | |
1936 | |
456 | 1937 /** |
1938 * cleans dc, ac, coded_block for the current non intra MB | |
1939 */ | |
1940 void ff_clean_intra_table_entries(MpegEncContext *s) | |
1941 { | |
1942 int wrap = s->block_wrap[0]; | |
1943 int xy = s->block_index[0]; | |
1944 | |
1945 s->dc_val[0][xy ] = | |
1946 s->dc_val[0][xy + 1 ] = | |
1947 s->dc_val[0][xy + wrap] = | |
1948 s->dc_val[0][xy + 1 + wrap] = 1024; | |
1949 /* ac pred */ | |
1064 | 1950 memset(s->ac_val[0][xy ], 0, 32 * sizeof(int16_t)); |
1951 memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(int16_t)); | |
456 | 1952 if (s->msmpeg4_version>=3) { |
1953 s->coded_block[xy ] = | |
1954 s->coded_block[xy + 1 ] = | |
1955 s->coded_block[xy + wrap] = | |
1956 s->coded_block[xy + 1 + wrap] = 0; | |
1957 } | |
1958 /* chroma */ | |
1959 wrap = s->block_wrap[4]; | |
1960 xy = s->mb_x + 1 + (s->mb_y + 1) * wrap; | |
1961 s->dc_val[1][xy] = | |
1962 s->dc_val[2][xy] = 1024; | |
1963 /* ac pred */ | |
1064 | 1964 memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t)); |
1965 memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t)); | |
456 | 1966 |
1967 s->mbintra_table[s->mb_x + s->mb_y*s->mb_width]= 0; | |
1968 } | |
1969 | |
0 | 1970 /* generic function called after a macroblock has been parsed by the |
1971 decoder or after it has been encoded by the encoder. | |
1972 | |
1973 Important variables used: | |
1974 s->mb_intra : true if intra macroblock | |
1975 s->mv_dir : motion vector direction | |
1976 s->mv_type : motion vector type | |
1977 s->mv : motion vector | |
1978 s->interlaced_dct : true if interlaced dct used (mpeg2) | |
1979 */ | |
1980 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) | |
1981 { | |
244 | 1982 int mb_x, mb_y; |
481 | 1983 const int mb_xy = s->mb_y * s->mb_width + s->mb_x; |
0 | 1984 |
1985 mb_x = s->mb_x; | |
1986 mb_y = s->mb_y; | |
1987 | |
903 | 1988 s->current_picture.qscale_table[mb_xy]= s->qscale; |
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1989 |
0 | 1990 /* update DC predictors for P macroblocks */ |
1991 if (!s->mb_intra) { | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1992 if (s->h263_pred || s->h263_aic) { |
481 | 1993 if(s->mbintra_table[mb_xy]) |
456 | 1994 ff_clean_intra_table_entries(s); |
0 | 1995 } else { |
456 | 1996 s->last_dc[0] = |
1997 s->last_dc[1] = | |
0 | 1998 s->last_dc[2] = 128 << s->intra_dc_precision; |
1999 } | |
2000 } | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2001 else if (s->h263_pred || s->h263_aic) |
481 | 2002 s->mbintra_table[mb_xy]=1; |
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
2003 |
280 | 2004 /* update motion predictor, not for B-frames as they need the motion_val from the last P/S-Frame */ |
481 | 2005 if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE) { //FIXME move into h263.c if possible, format specific stuff shouldnt be here |
936 | 2006 //FIXME a lot of thet is only needed for !low_delay |
481 | 2007 const int wrap = s->block_wrap[0]; |
2008 const int xy = s->block_index[0]; | |
664 | 2009 const int mb_index= s->mb_x + s->mb_y*s->mb_width; |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2010 if(s->mv_type == MV_TYPE_8X8){ |
664 | 2011 s->co_located_type_table[mb_index]= CO_LOCATED_TYPE_4MV; |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2012 } else { |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2013 int motion_x, motion_y; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2014 if (s->mb_intra) { |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2015 motion_x = 0; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2016 motion_y = 0; |
664 | 2017 if(s->co_located_type_table) |
2018 s->co_located_type_table[mb_index]= 0; | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2019 } else if (s->mv_type == MV_TYPE_16X16) { |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2020 motion_x = s->mv[0][0][0]; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2021 motion_y = s->mv[0][0][1]; |
664 | 2022 if(s->co_located_type_table) |
2023 s->co_located_type_table[mb_index]= 0; | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2024 } else /*if (s->mv_type == MV_TYPE_FIELD)*/ { |
664 | 2025 int i; |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2026 motion_x = s->mv[0][0][0] + s->mv[0][1][0]; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2027 motion_y = s->mv[0][0][1] + s->mv[0][1][1]; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2028 motion_x = (motion_x>>1) | (motion_x&1); |
664 | 2029 for(i=0; i<2; i++){ |
2030 s->field_mv_table[mb_index][i][0]= s->mv[0][i][0]; | |
2031 s->field_mv_table[mb_index][i][1]= s->mv[0][i][1]; | |
2032 s->field_select_table[mb_index][i]= s->field_select[0][i]; | |
2033 } | |
2034 s->co_located_type_table[mb_index]= CO_LOCATED_TYPE_FIELDMV; | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
2035 } |
0 | 2036 /* no update if 8X8 because it has been done during parsing */ |
244 | 2037 s->motion_val[xy][0] = motion_x; |
2038 s->motion_val[xy][1] = motion_y; | |
2039 s->motion_val[xy + 1][0] = motion_x; | |
2040 s->motion_val[xy + 1][1] = motion_y; | |
2041 s->motion_val[xy + wrap][0] = motion_x; | |
2042 s->motion_val[xy + wrap][1] = motion_y; | |
2043 s->motion_val[xy + 1 + wrap][0] = motion_x; | |
2044 s->motion_val[xy + 1 + wrap][1] = motion_y; | |
0 | 2045 } |
2046 } | |
2047 | |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2048 if ((s->flags&CODEC_FLAG_PSNR) || !(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { //FIXME precalc |
1064 | 2049 uint8_t *dest_y, *dest_cb, *dest_cr; |
481 | 2050 int dct_linesize, dct_offset; |
651 | 2051 op_pixels_func (*op_pix)[4]; |
2052 qpel_mc_func (*op_qpix)[16]; | |
1138 | 2053 const int linesize= s->current_picture.linesize[0]; //not s->linesize as this woulnd be wrong for field pics |
2054 const int uvlinesize= s->current_picture.linesize[1]; | |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
2055 |
903 | 2056 /* avoid copy if macroblock skipped in last frame too */ |
324 | 2057 if (s->pict_type != B_TYPE) { |
903 | 2058 s->current_picture.mbskip_table[mb_xy]= s->mb_skiped; |
2059 } | |
2060 | |
2061 /* skip only during decoding as we might trash the buffers during encoding a bit */ | |
2062 if(!s->encoding){ | |
1064 | 2063 uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy]; |
903 | 2064 const int age= s->current_picture.age; |
2065 | |
2066 assert(age); | |
2067 | |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
2068 if (s->mb_skiped) { |
903 | 2069 s->mb_skiped= 0; |
2070 assert(s->pict_type!=I_TYPE); | |
2071 | |
556 | 2072 (*mbskip_ptr) ++; /* indicate that this time we skiped it */ |
2073 if(*mbskip_ptr >99) *mbskip_ptr= 99; | |
2074 | |
903 | 2075 /* if previous was skipped too, then nothing to do ! */ |
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
2076 if (*mbskip_ptr >= age && s->current_picture.reference){ |
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
2077 return; |
903 | 2078 } |
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
2079 } else if(!s->current_picture.reference){ |
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
2080 (*mbskip_ptr) ++; /* increase counter so the age can be compared cleanly */ |
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
2081 if(*mbskip_ptr >99) *mbskip_ptr= 99; |
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
2082 } else{ |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
2083 *mbskip_ptr = 0; /* not skipped */ |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
2084 } |
903 | 2085 }else |
2086 s->mb_skiped= 0; | |
0 | 2087 |
1098
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
2088 if(s->pict_type==B_TYPE && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME){ //FIXME precalc |
903 | 2089 dest_y = s->current_picture.data[0] + mb_x * 16; |
2090 dest_cb = s->current_picture.data[1] + mb_x * 8; | |
2091 dest_cr = s->current_picture.data[2] + mb_x * 8; | |
717 | 2092 }else{ |
1138 | 2093 dest_y = s->current_picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16; |
2094 dest_cb = s->current_picture.data[1] + (mb_y * 8 * uvlinesize) + mb_x * 8; | |
2095 dest_cr = s->current_picture.data[2] + (mb_y * 8 * uvlinesize) + mb_x * 8; | |
717 | 2096 } |
0 | 2097 |
2098 if (s->interlaced_dct) { | |
1138 | 2099 dct_linesize = linesize * 2; |
2100 dct_offset = linesize; | |
0 | 2101 } else { |
1138 | 2102 dct_linesize = linesize; |
2103 dct_offset = linesize * 8; | |
0 | 2104 } |
2105 | |
2106 if (!s->mb_intra) { | |
2107 /* motion handling */ | |
456 | 2108 /* decoding or more than one mb_type (MC was allready done otherwise) */ |
481 | 2109 if((!s->encoding) || (s->mb_type[mb_xy]&(s->mb_type[mb_xy]-1))){ |
327 | 2110 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2111 op_pix = s->dsp.put_pixels_tab; |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2112 op_qpix= s->dsp.put_qpel_pixels_tab; |
324 | 2113 }else{ |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2114 op_pix = s->dsp.put_no_rnd_pixels_tab; |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2115 op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab; |
324 | 2116 } |
0 | 2117 |
324 | 2118 if (s->mv_dir & MV_DIR_FORWARD) { |
903 | 2119 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix); |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2120 op_pix = s->dsp.avg_pixels_tab; |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2121 op_qpix= s->dsp.avg_qpel_pixels_tab; |
324 | 2122 } |
2123 if (s->mv_dir & MV_DIR_BACKWARD) { | |
903 | 2124 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix); |
324 | 2125 } |
0 | 2126 } |
2127 | |
481 | 2128 /* skip dequant / idct if we are really late ;) */ |
814 | 2129 if(s->hurry_up>1) return; |
481 | 2130 |
0 | 2131 /* add dct residue */ |
711 | 2132 if(s->encoding || !( s->mpeg2 || s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO |
2133 || (s->codec_id==CODEC_ID_MPEG4 && !s->mpeg_quant))){ | |
481 | 2134 add_dequant_dct(s, block[0], 0, dest_y, dct_linesize); |
2135 add_dequant_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
2136 add_dequant_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
2137 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
0 | 2138 |
485 | 2139 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1138 | 2140 add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize); |
2141 add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize); | |
485 | 2142 } |
936 | 2143 } else if(s->codec_id != CODEC_ID_WMV2){ |
481 | 2144 add_dct(s, block[0], 0, dest_y, dct_linesize); |
2145 add_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
2146 add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
2147 add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
2148 | |
485 | 2149 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1138 | 2150 add_dct(s, block[4], 4, dest_cb, uvlinesize); |
2151 add_dct(s, block[5], 5, dest_cr, uvlinesize); | |
485 | 2152 } |
1042 | 2153 } |
2154 #ifdef CONFIG_RISKY | |
2155 else{ | |
936 | 2156 ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr); |
481 | 2157 } |
1042 | 2158 #endif |
0 | 2159 } else { |
2160 /* dct only in intra block */ | |
711 | 2161 if(s->encoding || !(s->mpeg2 || s->codec_id==CODEC_ID_MPEG1VIDEO)){ |
2162 put_dct(s, block[0], 0, dest_y, dct_linesize); | |
2163 put_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
2164 put_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
2165 put_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
0 | 2166 |
711 | 2167 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1138 | 2168 put_dct(s, block[4], 4, dest_cb, uvlinesize); |
2169 put_dct(s, block[5], 5, dest_cr, uvlinesize); | |
711 | 2170 } |
2171 }else{ | |
1092 | 2172 s->dsp.idct_put(dest_y , dct_linesize, block[0]); |
2173 s->dsp.idct_put(dest_y + 8, dct_linesize, block[1]); | |
2174 s->dsp.idct_put(dest_y + dct_offset , dct_linesize, block[2]); | |
2175 s->dsp.idct_put(dest_y + dct_offset + 8, dct_linesize, block[3]); | |
711 | 2176 |
2177 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
1138 | 2178 s->dsp.idct_put(dest_cb, uvlinesize, block[4]); |
2179 s->dsp.idct_put(dest_cr, uvlinesize, block[5]); | |
711 | 2180 } |
485 | 2181 } |
0 | 2182 } |
2183 } | |
294 | 2184 } |
2185 | |
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:
1064
diff
changeset
|
2186 #ifdef 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:
1064
diff
changeset
|
2187 |
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
2188 static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold) |
456 | 2189 { |
2190 static const char tab[64]= | |
2191 {3,2,2,1,1,1,1,1, | |
2192 1,1,1,1,1,1,1,1, | |
2193 1,1,1,1,1,1,1,1, | |
2194 0,0,0,0,0,0,0,0, | |
2195 0,0,0,0,0,0,0,0, | |
2196 0,0,0,0,0,0,0,0, | |
2197 0,0,0,0,0,0,0,0, | |
2198 0,0,0,0,0,0,0,0}; | |
2199 int score=0; | |
2200 int run=0; | |
2201 int i; | |
2202 DCTELEM *block= s->block[n]; | |
2203 const int last_index= s->block_last_index[n]; | |
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
2204 int skip_dc; |
456 | 2205 |
604
4344cc8033bd
skip blocks with small chroma dc too (if the user wants it) needed to avoid IDCT(input coeffs !=0) == 0 problems which cause catastrophic error accumulation at qp=1
michaelni
parents:
599
diff
changeset
|
2206 if(threshold<0){ |
4344cc8033bd
skip blocks with small chroma dc too (if the user wants it) needed to avoid IDCT(input coeffs !=0) == 0 problems which cause catastrophic error accumulation at qp=1
michaelni
parents:
599
diff
changeset
|
2207 skip_dc=0; |
4344cc8033bd
skip blocks with small chroma dc too (if the user wants it) needed to avoid IDCT(input coeffs !=0) == 0 problems which cause catastrophic error accumulation at qp=1
michaelni
parents:
599
diff
changeset
|
2208 threshold= -threshold; |
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
2209 }else |
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
2210 skip_dc=1; |
604
4344cc8033bd
skip blocks with small chroma dc too (if the user wants it) needed to avoid IDCT(input coeffs !=0) == 0 problems which cause catastrophic error accumulation at qp=1
michaelni
parents:
599
diff
changeset
|
2211 |
456 | 2212 /* are all which we could set to zero are allready zero? */ |
2213 if(last_index<=skip_dc - 1) return; | |
2214 | |
2215 for(i=0; i<=last_index; i++){ | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2216 const int j = s->intra_scantable.permutated[i]; |
456 | 2217 const int level = ABS(block[j]); |
2218 if(level==1){ | |
2219 if(skip_dc && i==0) continue; | |
2220 score+= tab[run]; | |
2221 run=0; | |
2222 }else if(level>1){ | |
2223 return; | |
2224 }else{ | |
2225 run++; | |
2226 } | |
2227 } | |
2228 if(score >= threshold) return; | |
2229 for(i=skip_dc; i<=last_index; i++){ | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2230 const int j = s->intra_scantable.permutated[i]; |
456 | 2231 block[j]=0; |
2232 } | |
2233 if(block[0]) s->block_last_index[n]= 0; | |
2234 else s->block_last_index[n]= -1; | |
2235 } | |
2236 | |
344 | 2237 static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) |
2238 { | |
2239 int i; | |
2240 const int maxlevel= s->max_qcoeff; | |
2241 const int minlevel= s->min_qcoeff; | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2242 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2243 if(s->mb_intra){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2244 i=1; //skip clipping of intra dc |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2245 }else |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2246 i=0; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2247 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2248 for(;i<=last_index; i++){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2249 const int j= s->intra_scantable.permutated[i]; |
344 | 2250 int level = block[j]; |
2251 | |
2252 if (level>maxlevel) level=maxlevel; | |
2253 else if(level<minlevel) level=minlevel; | |
1099 | 2254 |
344 | 2255 block[j]= level; |
2256 } | |
2257 } | |
324 | 2258 |
697 | 2259 #if 0 |
1064 | 2260 static int pix_vcmp16x8(uint8_t *s, int stride){ //FIXME move to dsputil & optimize |
697 | 2261 int score=0; |
2262 int x,y; | |
2263 | |
2264 for(y=0; y<7; y++){ | |
2265 for(x=0; x<16; x+=4){ | |
2266 score+= ABS(s[x ] - s[x +stride]) + ABS(s[x+1] - s[x+1+stride]) | |
2267 +ABS(s[x+2] - s[x+2+stride]) + ABS(s[x+3] - s[x+3+stride]); | |
2268 } | |
2269 s+= stride; | |
2270 } | |
2271 | |
2272 return score; | |
2273 } | |
2274 | |
1064 | 2275 static int pix_diff_vcmp16x8(uint8_t *s1, uint8_t*s2, int stride){ //FIXME move to dsputil & optimize |
697 | 2276 int score=0; |
2277 int x,y; | |
2278 | |
2279 for(y=0; y<7; y++){ | |
2280 for(x=0; x<16; x++){ | |
2281 score+= ABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]); | |
2282 } | |
2283 s1+= stride; | |
2284 s2+= stride; | |
2285 } | |
2286 | |
2287 return score; | |
2288 } | |
2289 #else | |
2290 #define SQ(a) ((a)*(a)) | |
2291 | |
1064 | 2292 static int pix_vcmp16x8(uint8_t *s, int stride){ //FIXME move to dsputil & optimize |
697 | 2293 int score=0; |
2294 int x,y; | |
2295 | |
2296 for(y=0; y<7; y++){ | |
2297 for(x=0; x<16; x+=4){ | |
2298 score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride]) | |
2299 +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]); | |
2300 } | |
2301 s+= stride; | |
2302 } | |
2303 | |
2304 return score; | |
2305 } | |
2306 | |
1064 | 2307 static int pix_diff_vcmp16x8(uint8_t *s1, uint8_t*s2, int stride){ //FIXME move to dsputil & optimize |
697 | 2308 int score=0; |
2309 int x,y; | |
2310 | |
2311 for(y=0; y<7; y++){ | |
2312 for(x=0; x<16; x++){ | |
2313 score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]); | |
2314 } | |
2315 s1+= stride; | |
2316 s2+= stride; | |
2317 } | |
2318 | |
2319 return score; | |
2320 } | |
2321 | |
2322 #endif | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2323 |
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:
1064
diff
changeset
|
2324 #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:
1064
diff
changeset
|
2325 |
1098
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
2326 /** |
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
2327 * |
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
2328 * @param h is the normal height, this will be reduced automatically if needed for the last row |
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
2329 */ |
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
2330 void ff_draw_horiz_band(MpegEncContext *s, int y, int h){ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2331 if ( s->avctx->draw_horiz_band |
1138 | 2332 && (s->last_picture_ptr || s->low_delay) ) { |
1064 | 2333 uint8_t *src_ptr[3]; |
1098
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
2334 int offset; |
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
2335 h= FFMIN(h, s->height - y); |
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
2336 |
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
2337 if(s->pict_type==B_TYPE && s->picture_structure == PICT_FRAME) |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2338 offset = 0; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2339 else |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2340 offset = y * s->linesize; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2341 |
924 | 2342 if(s->pict_type==B_TYPE || s->low_delay){ |
903 | 2343 src_ptr[0] = s->current_picture.data[0] + offset; |
2344 src_ptr[1] = s->current_picture.data[1] + (offset >> 2); | |
2345 src_ptr[2] = s->current_picture.data[2] + (offset >> 2); | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2346 } else { |
903 | 2347 src_ptr[0] = s->last_picture.data[0] + offset; |
2348 src_ptr[1] = s->last_picture.data[1] + (offset >> 2); | |
2349 src_ptr[2] = s->last_picture.data[2] + (offset >> 2); | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2350 } |
813 | 2351 emms_c(); |
2352 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2353 s->avctx->draw_horiz_band(s->avctx, src_ptr, s->linesize, |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2354 y, s->width, h); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2355 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2356 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2357 |
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:
1064
diff
changeset
|
2358 #ifdef 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:
1064
diff
changeset
|
2359 |
324 | 2360 static void encode_mb(MpegEncContext *s, int motion_x, int motion_y) |
294 | 2361 { |
2362 const int mb_x= s->mb_x; | |
2363 const int mb_y= s->mb_y; | |
2364 int i; | |
456 | 2365 int skip_dct[6]; |
697 | 2366 int dct_offset = s->linesize*8; //default for progressive frames |
2367 | |
456 | 2368 for(i=0; i<6; i++) skip_dct[i]=0; |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2369 |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2370 if(s->adaptive_quant){ |
903 | 2371 s->dquant= s->current_picture.qscale_table[mb_x + mb_y*s->mb_width] - s->qscale; |
697 | 2372 |
2373 if(s->out_format==FMT_H263){ | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2374 if (s->dquant> 2) s->dquant= 2; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2375 else if(s->dquant<-2) s->dquant=-2; |
697 | 2376 } |
2377 | |
2378 if(s->codec_id==CODEC_ID_MPEG4){ | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2379 if(!s->mb_intra){ |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2380 assert(s->dquant==0 || s->mv_type!=MV_TYPE_8X8); |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2381 |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2382 if(s->mv_dir&MV_DIRECT) |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2383 s->dquant=0; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2384 } |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2385 } |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2386 s->qscale+= s->dquant; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2387 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2388 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2389 } |
294 | 2390 |
324 | 2391 if (s->mb_intra) { |
1064 | 2392 uint8_t *ptr; |
697 | 2393 int wrap_y; |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2394 int emu=0; |
294 | 2395 |
697 | 2396 wrap_y = s->linesize; |
903 | 2397 ptr = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16; |
697 | 2398 |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2399 if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ |
936 | 2400 ff_emulated_edge_mc(s, ptr, wrap_y, 16, 16, mb_x*16, mb_y*16, s->width, s->height); |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2401 ptr= s->edge_emu_buffer; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2402 emu=1; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2403 } |
697 | 2404 |
2405 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ | |
2406 int progressive_score, interlaced_score; | |
2407 | |
2408 progressive_score= pix_vcmp16x8(ptr, wrap_y ) + pix_vcmp16x8(ptr + wrap_y*8, wrap_y ); | |
2409 interlaced_score = pix_vcmp16x8(ptr, wrap_y*2) + pix_vcmp16x8(ptr + wrap_y , wrap_y*2); | |
2410 | |
2411 if(progressive_score > interlaced_score + 100){ | |
2412 s->interlaced_dct=1; | |
2413 | |
2414 dct_offset= wrap_y; | |
2415 wrap_y<<=1; | |
2416 }else | |
2417 s->interlaced_dct=0; | |
2418 } | |
2419 | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2420 s->dsp.get_pixels(s->block[0], ptr , wrap_y); |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2421 s->dsp.get_pixels(s->block[1], ptr + 8, wrap_y); |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2422 s->dsp.get_pixels(s->block[2], ptr + dct_offset , wrap_y); |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2423 s->dsp.get_pixels(s->block[3], ptr + dct_offset + 8, wrap_y); |
294 | 2424 |
487 | 2425 if(s->flags&CODEC_FLAG_GRAY){ |
2426 skip_dct[4]= 1; | |
2427 skip_dct[5]= 1; | |
2428 }else{ | |
697 | 2429 int wrap_c = s->uvlinesize; |
903 | 2430 ptr = s->new_picture.data[1] + (mb_y * 8 * wrap_c) + mb_x * 8; |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2431 if(emu){ |
936 | 2432 ff_emulated_edge_mc(s, ptr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2433 ptr= s->edge_emu_buffer; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2434 } |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2435 s->dsp.get_pixels(s->block[4], ptr, wrap_c); |
294 | 2436 |
903 | 2437 ptr = s->new_picture.data[2] + (mb_y * 8 * wrap_c) + mb_x * 8; |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2438 if(emu){ |
936 | 2439 ff_emulated_edge_mc(s, ptr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2440 ptr= s->edge_emu_buffer; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2441 } |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2442 s->dsp.get_pixels(s->block[5], ptr, wrap_c); |
487 | 2443 } |
324 | 2444 }else{ |
651 | 2445 op_pixels_func (*op_pix)[4]; |
2446 qpel_mc_func (*op_qpix)[16]; | |
1064 | 2447 uint8_t *dest_y, *dest_cb, *dest_cr; |
2448 uint8_t *ptr_y, *ptr_cb, *ptr_cr; | |
456 | 2449 int wrap_y, wrap_c; |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2450 int emu=0; |
294 | 2451 |
903 | 2452 dest_y = s->current_picture.data[0] + (mb_y * 16 * s->linesize ) + mb_x * 16; |
2453 dest_cb = s->current_picture.data[1] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; | |
2454 dest_cr = s->current_picture.data[2] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; | |
456 | 2455 wrap_y = s->linesize; |
697 | 2456 wrap_c = s->uvlinesize; |
903 | 2457 ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16; |
2458 ptr_cb = s->new_picture.data[1] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
2459 ptr_cr = s->new_picture.data[2] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
324 | 2460 |
327 | 2461 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2462 op_pix = s->dsp.put_pixels_tab; |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2463 op_qpix= s->dsp.put_qpel_pixels_tab; |
295 | 2464 }else{ |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2465 op_pix = s->dsp.put_no_rnd_pixels_tab; |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2466 op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab; |
324 | 2467 } |
295 | 2468 |
324 | 2469 if (s->mv_dir & MV_DIR_FORWARD) { |
903 | 2470 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix); |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2471 op_pix = s->dsp.avg_pixels_tab; |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2472 op_qpix= s->dsp.avg_qpel_pixels_tab; |
324 | 2473 } |
2474 if (s->mv_dir & MV_DIR_BACKWARD) { | |
903 | 2475 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix); |
324 | 2476 } |
295 | 2477 |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2478 if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ |
936 | 2479 ff_emulated_edge_mc(s, ptr_y, wrap_y, 16, 16, mb_x*16, mb_y*16, s->width, s->height); |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2480 ptr_y= s->edge_emu_buffer; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2481 emu=1; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2482 } |
697 | 2483 |
2484 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ | |
2485 int progressive_score, interlaced_score; | |
2486 | |
2487 progressive_score= pix_diff_vcmp16x8(ptr_y , dest_y , wrap_y ) | |
2488 + pix_diff_vcmp16x8(ptr_y + wrap_y*8, dest_y + wrap_y*8, wrap_y ); | |
2489 interlaced_score = pix_diff_vcmp16x8(ptr_y , dest_y , wrap_y*2) | |
2490 + pix_diff_vcmp16x8(ptr_y + wrap_y , dest_y + wrap_y , wrap_y*2); | |
2491 | |
2492 if(progressive_score > interlaced_score + 600){ | |
2493 s->interlaced_dct=1; | |
2494 | |
2495 dct_offset= wrap_y; | |
2496 wrap_y<<=1; | |
2497 }else | |
2498 s->interlaced_dct=0; | |
2499 } | |
2500 | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2501 s->dsp.diff_pixels(s->block[0], ptr_y , dest_y , wrap_y); |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2502 s->dsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y); |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2503 s->dsp.diff_pixels(s->block[2], ptr_y + dct_offset , dest_y + dct_offset , wrap_y); |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2504 s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y); |
487 | 2505 |
2506 if(s->flags&CODEC_FLAG_GRAY){ | |
2507 skip_dct[4]= 1; | |
2508 skip_dct[5]= 1; | |
2509 }else{ | |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2510 if(emu){ |
936 | 2511 ff_emulated_edge_mc(s, ptr_cb, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2512 ptr_cb= s->edge_emu_buffer; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2513 } |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2514 s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c); |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2515 if(emu){ |
936 | 2516 ff_emulated_edge_mc(s, ptr_cr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2517 ptr_cr= s->edge_emu_buffer; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2518 } |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2519 s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); |
487 | 2520 } |
456 | 2521 /* pre quantization */ |
903 | 2522 if(s->current_picture.mc_mb_var[s->mb_width*mb_y+ mb_x]<2*s->qscale*s->qscale){ |
697 | 2523 //FIXME optimize |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2524 if(s->dsp.pix_abs8x8(ptr_y , dest_y , wrap_y) < 20*s->qscale) skip_dct[0]= 1; |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2525 if(s->dsp.pix_abs8x8(ptr_y + 8, dest_y + 8, wrap_y) < 20*s->qscale) skip_dct[1]= 1; |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2526 if(s->dsp.pix_abs8x8(ptr_y +dct_offset , dest_y +dct_offset , wrap_y) < 20*s->qscale) skip_dct[2]= 1; |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2527 if(s->dsp.pix_abs8x8(ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y) < 20*s->qscale) skip_dct[3]= 1; |
899 | 2528 if(s->dsp.pix_abs8x8(ptr_cb , dest_cb , wrap_c) < 20*s->qscale) skip_dct[4]= 1; |
2529 if(s->dsp.pix_abs8x8(ptr_cr , dest_cr , wrap_c) < 20*s->qscale) skip_dct[5]= 1; | |
456 | 2530 #if 0 |
2531 { | |
2532 static int stat[7]; | |
2533 int num=0; | |
2534 for(i=0; i<6; i++) | |
2535 if(skip_dct[i]) num++; | |
2536 stat[num]++; | |
2537 | |
2538 if(s->mb_x==0 && s->mb_y==0){ | |
2539 for(i=0; i<7; i++){ | |
2540 printf("%6d %1d\n", stat[i], i); | |
2541 } | |
2542 } | |
2543 } | |
2544 #endif | |
2545 } | |
324 | 2546 |
294 | 2547 } |
2548 | |
2549 #if 0 | |
2550 { | |
2551 float adap_parm; | |
2552 | |
2553 adap_parm = ((s->avg_mb_var << 1) + s->mb_var[s->mb_width*mb_y+mb_x] + 1.0) / | |
2554 ((s->mb_var[s->mb_width*mb_y+mb_x] << 1) + s->avg_mb_var + 1.0); | |
2555 | |
2556 printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d", | |
2557 (s->mb_type[s->mb_width*mb_y+mb_x] > 0) ? 'I' : 'P', | |
2558 s->qscale, adap_parm, s->qscale*adap_parm, | |
2559 s->mb_var[s->mb_width*mb_y+mb_x], s->avg_mb_var); | |
2560 } | |
2561 #endif | |
2562 /* DCT & quantize */ | |
344 | 2563 if(s->out_format==FMT_MJPEG){ |
2564 for(i=0;i<6;i++) { | |
2565 int overflow; | |
625
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
2566 s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, 8, &overflow); |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2567 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
344 | 2568 } |
2569 }else{ | |
2570 for(i=0;i<6;i++) { | |
456 | 2571 if(!skip_dct[i]){ |
2572 int overflow; | |
625
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
2573 s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); |
344 | 2574 // FIXME we could decide to change to quantizer instead of clipping |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2575 // JS: I don't think that would be a good idea it could lower quality instead |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2576 // of improve it. Just INTRADC clipping deserves changes in quantizer |
456 | 2577 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
2578 }else | |
2579 s->block_last_index[i]= -1; | |
344 | 2580 } |
456 | 2581 if(s->luma_elim_threshold && !s->mb_intra) |
2582 for(i=0; i<4; i++) | |
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
2583 dct_single_coeff_elimination(s, i, s->luma_elim_threshold); |
456 | 2584 if(s->chroma_elim_threshold && !s->mb_intra) |
2585 for(i=4; i<6; i++) | |
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
2586 dct_single_coeff_elimination(s, i, s->chroma_elim_threshold); |
294 | 2587 } |
2588 | |
487 | 2589 if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){ |
2590 s->block_last_index[4]= | |
2591 s->block_last_index[5]= 0; | |
2592 s->block[4][0]= | |
1011 | 2593 s->block[5][0]= (1024 + s->c_dc_scale/2)/ s->c_dc_scale; |
487 | 2594 } |
2595 | |
294 | 2596 /* huffman encode */ |
936 | 2597 switch(s->codec_id){ //FIXME funct ptr could be slightly faster |
2598 case CODEC_ID_MPEG1VIDEO: | |
2599 mpeg1_encode_mb(s, s->block, motion_x, motion_y); break; | |
1042 | 2600 #ifdef CONFIG_RISKY |
936 | 2601 case CODEC_ID_MPEG4: |
2602 mpeg4_encode_mb(s, s->block, motion_x, motion_y); break; | |
2603 case CODEC_ID_MSMPEG4V2: | |
2604 case CODEC_ID_MSMPEG4V3: | |
2605 case CODEC_ID_WMV1: | |
2606 msmpeg4_encode_mb(s, s->block, motion_x, motion_y); break; | |
2607 case CODEC_ID_WMV2: | |
2608 ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); break; | |
2609 case CODEC_ID_H263: | |
2610 case CODEC_ID_H263P: | |
2611 case CODEC_ID_RV10: | |
2612 h263_encode_mb(s, s->block, motion_x, motion_y); break; | |
1042 | 2613 #endif |
2614 case CODEC_ID_MJPEG: | |
2615 mjpeg_encode_mb(s, s->block); break; | |
936 | 2616 default: |
2617 assert(0); | |
294 | 2618 } |
2619 } | |
2620 | |
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:
1064
diff
changeset
|
2621 #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:
1064
diff
changeset
|
2622 |
1026 | 2623 /** |
2624 * combines the (truncated) bitstream to a complete frame | |
2625 * @returns -1 if no complete frame could be created | |
2626 */ | |
2627 int ff_combine_frame( MpegEncContext *s, int next, uint8_t **buf, int *buf_size){ | |
2628 ParseContext *pc= &s->parse_context; | |
2629 | |
2630 pc->last_index= pc->index; | |
2631 | |
2632 if(next==-1){ | |
2633 pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); | |
2634 | |
2635 memcpy(&pc->buffer[pc->index], *buf, *buf_size); | |
2636 pc->index += *buf_size; | |
2637 return -1; | |
2638 } | |
2639 | |
2640 if(pc->index){ | |
2641 pc->buffer= av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); | |
2642 | |
2643 memcpy(&pc->buffer[pc->index], *buf, next + FF_INPUT_BUFFER_PADDING_SIZE ); | |
2644 pc->index = 0; | |
2645 *buf= pc->buffer; | |
2646 *buf_size= pc->last_index + next; | |
2647 } | |
2648 | |
2649 return 0; | |
2650 } | |
2651 | |
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:
1064
diff
changeset
|
2652 #ifdef CONFIG_ENCODERS |
1064 | 2653 void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length) |
294 | 2654 { |
326 | 2655 int bytes= length>>4; |
2656 int bits= length&15; | |
2657 int i; | |
2658 | |
456 | 2659 if(length==0) return; |
2660 | |
326 | 2661 for(i=0; i<bytes; i++) put_bits(pb, 16, be2me_16(((uint16_t*)src)[i])); |
2662 put_bits(pb, bits, be2me_16(((uint16_t*)src)[i])>>(16-bits)); | |
0 | 2663 } |
2664 | |
456 | 2665 static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
326 | 2666 int i; |
2667 | |
2668 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
2669 | |
2670 /* mpeg1 */ | |
2671 d->mb_incr= s->mb_incr; | |
2672 for(i=0; i<3; i++) | |
2673 d->last_dc[i]= s->last_dc[i]; | |
2674 | |
2675 /* statistics */ | |
2676 d->mv_bits= s->mv_bits; | |
2677 d->i_tex_bits= s->i_tex_bits; | |
2678 d->p_tex_bits= s->p_tex_bits; | |
2679 d->i_count= s->i_count; | |
656
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
2680 d->f_count= s->f_count; |
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
2681 d->b_count= s->b_count; |
326 | 2682 d->skip_count= s->skip_count; |
2683 d->misc_bits= s->misc_bits; | |
329 | 2684 d->last_bits= 0; |
327 | 2685 |
2686 d->mb_skiped= s->mb_skiped; | |
912 | 2687 d->qscale= s->qscale; |
326 | 2688 } |
2689 | |
456 | 2690 static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
326 | 2691 int i; |
2692 | |
2693 memcpy(d->mv, s->mv, 2*4*2*sizeof(int)); | |
2694 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
2695 | |
2696 /* mpeg1 */ | |
2697 d->mb_incr= s->mb_incr; | |
2698 for(i=0; i<3; i++) | |
2699 d->last_dc[i]= s->last_dc[i]; | |
2700 | |
2701 /* statistics */ | |
2702 d->mv_bits= s->mv_bits; | |
2703 d->i_tex_bits= s->i_tex_bits; | |
2704 d->p_tex_bits= s->p_tex_bits; | |
2705 d->i_count= s->i_count; | |
656
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
2706 d->f_count= s->f_count; |
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
2707 d->b_count= s->b_count; |
326 | 2708 d->skip_count= s->skip_count; |
2709 d->misc_bits= s->misc_bits; | |
2710 | |
2711 d->mb_intra= s->mb_intra; | |
327 | 2712 d->mb_skiped= s->mb_skiped; |
326 | 2713 d->mv_type= s->mv_type; |
2714 d->mv_dir= s->mv_dir; | |
2715 d->pb= s->pb; | |
456 | 2716 if(s->data_partitioning){ |
2717 d->pb2= s->pb2; | |
2718 d->tex_pb= s->tex_pb; | |
2719 } | |
326 | 2720 d->block= s->block; |
2721 for(i=0; i<6; i++) | |
2722 d->block_last_index[i]= s->block_last_index[i]; | |
755 | 2723 d->interlaced_dct= s->interlaced_dct; |
912 | 2724 d->qscale= s->qscale; |
326 | 2725 } |
2726 | |
456 | 2727 static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type, |
2728 PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2], | |
2729 int *dmin, int *next_block, int motion_x, int motion_y) | |
2730 { | |
2731 int bits_count; | |
2732 | |
2733 copy_context_before_encode(s, backup, type); | |
2734 | |
2735 s->block= s->blocks[*next_block]; | |
2736 s->pb= pb[*next_block]; | |
2737 if(s->data_partitioning){ | |
2738 s->pb2 = pb2 [*next_block]; | |
2739 s->tex_pb= tex_pb[*next_block]; | |
2740 } | |
2741 | |
2742 encode_mb(s, motion_x, motion_y); | |
2743 | |
2744 bits_count= get_bit_count(&s->pb); | |
2745 if(s->data_partitioning){ | |
2746 bits_count+= get_bit_count(&s->pb2); | |
2747 bits_count+= get_bit_count(&s->tex_pb); | |
2748 } | |
2749 | |
2750 if(bits_count<*dmin){ | |
2751 *dmin= bits_count; | |
2752 *next_block^=1; | |
2753 | |
2754 copy_context_after_encode(best, s, type); | |
2755 } | |
2756 } | |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2757 |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2758 static inline int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride){ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2759 uint32_t *sq = squareTbl + 256; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2760 int acc=0; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2761 int x,y; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2762 |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2763 if(w==16 && h==16) |
936 | 2764 return s->dsp.sse[0](NULL, src1, src2, stride); |
2765 else if(w==8 && h==8) | |
2766 return s->dsp.sse[1](NULL, src1, src2, stride); | |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2767 |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2768 for(y=0; y<h; y++){ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2769 for(x=0; x<w; x++){ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2770 acc+= sq[src1[x + y*stride] - src2[x + y*stride]]; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2771 } |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2772 } |
936 | 2773 |
2774 assert(acc>=0); | |
2775 | |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2776 return acc; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2777 } |
326 | 2778 |
0 | 2779 static void encode_picture(MpegEncContext *s, int picture_number) |
2780 { | |
766 | 2781 int mb_x, mb_y, pdif = 0; |
294 | 2782 int i; |
286 | 2783 int bits; |
326 | 2784 MpegEncContext best_s, backup_s; |
1064 | 2785 uint8_t bit_buf[2][3000]; |
2786 uint8_t bit_buf2[2][3000]; | |
2787 uint8_t bit_buf_tex[2][3000]; | |
456 | 2788 PutBitContext pb[2], pb2[2], tex_pb[2]; |
2789 | |
2790 for(i=0; i<2; i++){ | |
2791 init_put_bits(&pb [i], bit_buf [i], 3000, NULL, NULL); | |
2792 init_put_bits(&pb2 [i], bit_buf2 [i], 3000, NULL, NULL); | |
2793 init_put_bits(&tex_pb[i], bit_buf_tex[i], 3000, NULL, NULL); | |
2794 } | |
0 | 2795 |
2796 s->picture_number = picture_number; | |
268 | 2797 |
294 | 2798 s->block_wrap[0]= |
2799 s->block_wrap[1]= | |
2800 s->block_wrap[2]= | |
2801 s->block_wrap[3]= s->mb_width*2 + 2; | |
2802 s->block_wrap[4]= | |
2803 s->block_wrap[5]= s->mb_width + 2; | |
2804 | |
268 | 2805 /* Reset the average MB variance */ |
903 | 2806 s->current_picture.mb_var_sum = 0; |
2807 s->current_picture.mc_mb_var_sum = 0; | |
327 | 2808 |
1042 | 2809 #ifdef CONFIG_RISKY |
327 | 2810 /* we need to initialize some time vars before we can encode b-frames */ |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
2811 // RAL: Condition added for MPEG1VIDEO |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
2812 if (s->codec_id == CODEC_ID_MPEG1VIDEO || (s->h263_pred && !s->h263_msmpeg4)) |
327 | 2813 ff_set_mpeg4_time(s, s->picture_number); |
1042 | 2814 #endif |
2815 | |
608 | 2816 s->scene_change_score=0; |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2817 |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2818 s->qscale= (int)(s->frame_qscale + 0.5); //FIXME qscale / ... stuff for ME ratedistoration |
936 | 2819 |
1089 | 2820 if(s->pict_type==I_TYPE){ |
2821 if(s->msmpeg4_version) s->no_rounding=1; | |
2822 else s->no_rounding=0; | |
2823 }else if(s->pict_type!=B_TYPE){ | |
2824 if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4) | |
936 | 2825 s->no_rounding ^= 1; |
2826 } | |
1089 | 2827 |
268 | 2828 /* Estimate motion for every MB */ |
1013 | 2829 s->mb_intra=0; //for the rate distoration & bit compare functions |
324 | 2830 if(s->pict_type != I_TYPE){ |
951 | 2831 if(s->pict_type != B_TYPE){ |
2832 if((s->avctx->pre_me && s->last_non_b_pict_type==I_TYPE) || s->avctx->pre_me==2){ | |
952 | 2833 s->me.pre_pass=1; |
954 | 2834 s->me.dia_size= s->avctx->pre_dia_size; |
952 | 2835 |
951 | 2836 for(mb_y=s->mb_height-1; mb_y >=0 ; mb_y--) { |
2837 for(mb_x=s->mb_width-1; mb_x >=0 ; mb_x--) { | |
2838 s->mb_x = mb_x; | |
2839 s->mb_y = mb_y; | |
2840 ff_pre_estimate_p_frame_motion(s, mb_x, mb_y); | |
2841 } | |
2842 } | |
952 | 2843 s->me.pre_pass=0; |
951 | 2844 } |
2845 } | |
2846 | |
954 | 2847 s->me.dia_size= s->avctx->dia_size; |
294 | 2848 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
2849 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; | |
2850 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
2851 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
2852 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
2853 for(mb_x=0; mb_x < s->mb_width; mb_x++) { | |
2854 s->mb_x = mb_x; | |
2855 s->mb_y = mb_y; | |
2856 s->block_index[0]+=2; | |
2857 s->block_index[1]+=2; | |
2858 s->block_index[2]+=2; | |
2859 s->block_index[3]+=2; | |
954 | 2860 |
294 | 2861 /* compute motion vector & mb_type and store in context */ |
324 | 2862 if(s->pict_type==B_TYPE) |
2863 ff_estimate_b_frame_motion(s, mb_x, mb_y); | |
2864 else | |
2865 ff_estimate_p_frame_motion(s, mb_x, mb_y); | |
268 | 2866 } |
2867 } | |
456 | 2868 }else /* if(s->pict_type == I_TYPE) */{ |
294 | 2869 /* I-Frame */ |
2870 //FIXME do we need to zero them? | |
1064 | 2871 memset(s->motion_val[0], 0, sizeof(int16_t)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2); |
2872 memset(s->p_mv_table , 0, sizeof(int16_t)*(s->mb_width+2)*(s->mb_height+2)*2); | |
2873 memset(s->mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s->mb_width*s->mb_height); | |
612 | 2874 |
2875 if(!s->fixed_qscale){ | |
2876 /* finding spatial complexity for I-frame rate control */ | |
2877 for(mb_y=0; mb_y < s->mb_height; mb_y++) { | |
2878 for(mb_x=0; mb_x < s->mb_width; mb_x++) { | |
2879 int xx = mb_x * 16; | |
2880 int yy = mb_y * 16; | |
903 | 2881 uint8_t *pix = s->new_picture.data[0] + (yy * s->linesize) + xx; |
612 | 2882 int varc; |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2883 int sum = s->dsp.pix_sum(pix, s->linesize); |
612 | 2884 |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2885 varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8; |
612 | 2886 |
903 | 2887 s->current_picture.mb_var [s->mb_width * mb_y + mb_x] = varc; |
2888 s->current_picture.mb_mean[s->mb_width * mb_y + mb_x] = (sum+128)>>8; | |
2889 s->current_picture.mb_var_sum += varc; | |
612 | 2890 } |
2891 } | |
2892 } | |
268 | 2893 } |
814 | 2894 emms_c(); |
2895 | |
608 | 2896 if(s->scene_change_score > 0 && s->pict_type == P_TYPE){ |
271 | 2897 s->pict_type= I_TYPE; |
1064 | 2898 memset(s->mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s->mb_width*s->mb_height); |
903 | 2899 //printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum); |
271 | 2900 } |
903 | 2901 |
1089 | 2902 if(!s->umvplus){ |
1086 | 2903 if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) { |
2904 s->f_code= ff_get_best_fcode(s, s->p_mv_table, MB_TYPE_INTER); | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
2905 |
1086 | 2906 ff_fix_long_p_mvs(s); |
2907 } | |
2908 | |
2909 if(s->pict_type==B_TYPE){ | |
2910 int a, b; | |
2911 | |
2912 a = ff_get_best_fcode(s, s->b_forw_mv_table, MB_TYPE_FORWARD); | |
2913 b = ff_get_best_fcode(s, s->b_bidir_forw_mv_table, MB_TYPE_BIDIR); | |
2914 s->f_code = FFMAX(a, b); | |
2915 | |
2916 a = ff_get_best_fcode(s, s->b_back_mv_table, MB_TYPE_BACKWARD); | |
2917 b = ff_get_best_fcode(s, s->b_bidir_back_mv_table, MB_TYPE_BIDIR); | |
2918 s->b_code = FFMAX(a, b); | |
2919 | |
2920 ff_fix_long_b_mvs(s, s->b_forw_mv_table, s->f_code, MB_TYPE_FORWARD); | |
2921 ff_fix_long_b_mvs(s, s->b_back_mv_table, s->b_code, MB_TYPE_BACKWARD); | |
2922 ff_fix_long_b_mvs(s, s->b_bidir_forw_mv_table, s->f_code, MB_TYPE_BIDIR); | |
2923 ff_fix_long_b_mvs(s, s->b_bidir_back_mv_table, s->b_code, MB_TYPE_BIDIR); | |
2924 } | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
2925 } |
324 | 2926 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2927 if (s->fixed_qscale) |
903 | 2928 s->frame_qscale = s->current_picture.quality; |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2929 else |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2930 s->frame_qscale = ff_rate_estimate_qscale(s); |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
2931 |
695 | 2932 if(s->adaptive_quant){ |
1042 | 2933 #ifdef CONFIG_RISKY |
695 | 2934 switch(s->codec_id){ |
2935 case CODEC_ID_MPEG4: | |
2936 ff_clean_mpeg4_qscales(s); | |
2937 break; | |
2938 case CODEC_ID_H263: | |
2939 case CODEC_ID_H263P: | |
2940 ff_clean_h263_qscales(s); | |
2941 break; | |
2942 } | |
1042 | 2943 #endif |
695 | 2944 |
903 | 2945 s->qscale= s->current_picture.qscale_table[0]; |
695 | 2946 }else |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2947 s->qscale= (int)(s->frame_qscale + 0.5); |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2948 |
0 | 2949 if (s->out_format == FMT_MJPEG) { |
2950 /* for mjpeg, we do include qscale in the matrix */ | |
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
514
diff
changeset
|
2951 s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2952 for(i=1;i<64;i++){ |
1092 | 2953 int j= s->dsp.idct_permutation[i]; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2954 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2955 s->intra_matrix[j] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2956 } |
625
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
2957 convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, |
709
afeff6ccb7f5
convert only needed matrixes in convert_matrix() (mjpeg calls it for every frame)
michaelni
parents:
706
diff
changeset
|
2958 s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias, 8, 8); |
0 | 2959 } |
903 | 2960 |
2961 //FIXME var duplication | |
2962 s->current_picture.key_frame= s->pict_type == I_TYPE; | |
2963 s->current_picture.pict_type= s->pict_type; | |
2964 | |
2965 if(s->current_picture.key_frame) | |
2966 s->picture_in_gop_number=0; | |
0 | 2967 |
286 | 2968 s->last_bits= get_bit_count(&s->pb); |
0 | 2969 switch(s->out_format) { |
2970 case FMT_MJPEG: | |
2971 mjpeg_picture_header(s); | |
2972 break; | |
1042 | 2973 #ifdef CONFIG_RISKY |
0 | 2974 case FMT_H263: |
936 | 2975 if (s->codec_id == CODEC_ID_WMV2) |
2976 ff_wmv2_encode_picture_header(s, picture_number); | |
2977 else if (s->h263_msmpeg4) | |
0 | 2978 msmpeg4_encode_picture_header(s, picture_number); |
2979 else if (s->h263_pred) | |
2980 mpeg4_encode_picture_header(s, picture_number); | |
2981 else if (s->h263_rv10) | |
2982 rv10_encode_picture_header(s, picture_number); | |
2983 else | |
2984 h263_encode_picture_header(s, picture_number); | |
2985 break; | |
1042 | 2986 #endif |
0 | 2987 case FMT_MPEG1: |
2988 mpeg1_encode_picture_header(s, picture_number); | |
2989 break; | |
2990 } | |
286 | 2991 bits= get_bit_count(&s->pb); |
2992 s->header_bits= bits - s->last_bits; | |
2993 s->last_bits= bits; | |
2994 s->mv_bits=0; | |
2995 s->misc_bits=0; | |
2996 s->i_tex_bits=0; | |
2997 s->p_tex_bits=0; | |
2998 s->i_count=0; | |
656
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
2999 s->f_count=0; |
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
3000 s->b_count=0; |
286 | 3001 s->skip_count=0; |
3002 | |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3003 for(i=0; i<3; i++){ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3004 /* init last dc values */ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3005 /* note: quant matrix value (8) is implied here */ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3006 s->last_dc[i] = 128; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3007 |
1148 | 3008 s->current_picture_ptr->error[i] = 0; |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3009 } |
0 | 3010 s->mb_incr = 1; |
3011 s->last_mv[0][0][0] = 0; | |
3012 s->last_mv[0][0][1] = 0; | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
3013 s->last_mv[1][0][0] = 0; |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
3014 s->last_mv[1][0][1] = 0; |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
3015 |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
3016 s->last_mv_dir = 0; |
0 | 3017 |
1042 | 3018 #ifdef CONFIG_RISKY |
766 | 3019 if (s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P) |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3020 s->gob_index = ff_h263_get_gob_height(s); |
456 | 3021 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3022 if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame) |
456 | 3023 ff_mpeg4_init_partitions(s); |
1042 | 3024 #endif |
456 | 3025 |
3026 s->resync_mb_x=0; | |
3027 s->resync_mb_y=0; | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3028 s->first_slice_line = 1; |
766 | 3029 s->ptr_lastgob = s->pb.buf; |
3030 s->ptr_last_mb_line = s->pb.buf; | |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
3031 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
499 | 3032 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; |
3033 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; | |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
3034 |
266 | 3035 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; |
3036 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
3037 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
3038 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
3039 s->block_index[4]= s->block_wrap[4]*(mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2); | |
3040 s->block_index[5]= s->block_wrap[4]*(mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2); | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
3041 for(mb_x=0; mb_x < s->mb_width; mb_x++) { |
1013 | 3042 int mb_type= s->mb_type[mb_y * s->mb_width + mb_x]; |
327 | 3043 const int xy= (mb_y+1) * (s->mb_width+2) + mb_x + 1; |
456 | 3044 // int d; |
294 | 3045 int dmin=10000000; |
0 | 3046 |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
3047 s->mb_x = mb_x; |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
3048 s->mb_y = mb_y; |
266 | 3049 s->block_index[0]+=2; |
3050 s->block_index[1]+=2; | |
3051 s->block_index[2]+=2; | |
3052 s->block_index[3]+=2; | |
3053 s->block_index[4]++; | |
3054 s->block_index[5]++; | |
456 | 3055 |
766 | 3056 /* write gob / video packet header */ |
1042 | 3057 #ifdef CONFIG_RISKY |
766 | 3058 if(s->rtp_mode){ |
3059 int current_packet_size, is_gob_start; | |
3060 | |
3061 current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob; | |
3062 is_gob_start=0; | |
3063 | |
3064 if(s->codec_id==CODEC_ID_MPEG4){ | |
3065 if(current_packet_size + s->mb_line_avgsize/s->mb_width >= s->rtp_payload_size | |
3066 && s->mb_y + s->mb_x>0){ | |
3067 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3068 if(s->partitioned_frame){ |
456 | 3069 ff_mpeg4_merge_partitions(s); |
3070 ff_mpeg4_init_partitions(s); | |
3071 } | |
3072 ff_mpeg4_encode_video_packet_header(s); | |
3073 | |
3074 if(s->flags&CODEC_FLAG_PASS1){ | |
3075 int bits= get_bit_count(&s->pb); | |
3076 s->misc_bits+= bits - s->last_bits; | |
3077 s->last_bits= bits; | |
3078 } | |
3079 ff_mpeg4_clean_buffers(s); | |
766 | 3080 is_gob_start=1; |
456 | 3081 } |
766 | 3082 }else{ |
3083 if(current_packet_size + s->mb_line_avgsize*s->gob_index >= s->rtp_payload_size | |
3084 && s->mb_x==0 && s->mb_y>0 && s->mb_y%s->gob_index==0){ | |
3085 | |
3086 h263_encode_gob_header(s, mb_y); | |
3087 is_gob_start=1; | |
3088 } | |
3089 } | |
3090 | |
3091 if(is_gob_start){ | |
456 | 3092 s->ptr_lastgob = pbBufPtr(&s->pb); |
3093 s->first_slice_line=1; | |
3094 s->resync_mb_x=mb_x; | |
3095 s->resync_mb_y=mb_y; | |
3096 } | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3097 } |
1042 | 3098 #endif |
456 | 3099 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3100 if( (s->resync_mb_x == s->mb_x) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3101 && s->resync_mb_y+1 == s->mb_y){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3102 s->first_slice_line=0; |
456 | 3103 } |
3104 | |
294 | 3105 if(mb_type & (mb_type-1)){ // more than 1 MB type possible |
327 | 3106 int next_block=0; |
456 | 3107 int pb_bits_count, pb2_bits_count, tex_pb_bits_count; |
326 | 3108 |
3109 copy_context_before_encode(&backup_s, s, -1); | |
456 | 3110 backup_s.pb= s->pb; |
3111 best_s.data_partitioning= s->data_partitioning; | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3112 best_s.partitioned_frame= s->partitioned_frame; |
456 | 3113 if(s->data_partitioning){ |
3114 backup_s.pb2= s->pb2; | |
3115 backup_s.tex_pb= s->tex_pb; | |
3116 } | |
326 | 3117 |
294 | 3118 if(mb_type&MB_TYPE_INTER){ |
327 | 3119 s->mv_dir = MV_DIR_FORWARD; |
295 | 3120 s->mv_type = MV_TYPE_16X16; |
294 | 3121 s->mb_intra= 0; |
324 | 3122 s->mv[0][0][0] = s->p_mv_table[xy][0]; |
3123 s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
456 | 3124 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER, pb, pb2, tex_pb, |
3125 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); | |
0 | 3126 } |
326 | 3127 if(mb_type&MB_TYPE_INTER4V){ |
327 | 3128 s->mv_dir = MV_DIR_FORWARD; |
295 | 3129 s->mv_type = MV_TYPE_8X8; |
3130 s->mb_intra= 0; | |
3131 for(i=0; i<4; i++){ | |
3132 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; | |
3133 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; | |
3134 } | |
456 | 3135 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER4V, pb, pb2, tex_pb, |
3136 &dmin, &next_block, 0, 0); | |
327 | 3137 } |
3138 if(mb_type&MB_TYPE_FORWARD){ | |
3139 s->mv_dir = MV_DIR_FORWARD; | |
3140 s->mv_type = MV_TYPE_16X16; | |
3141 s->mb_intra= 0; | |
3142 s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
3143 s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
456 | 3144 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_FORWARD, pb, pb2, tex_pb, |
3145 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); | |
327 | 3146 } |
3147 if(mb_type&MB_TYPE_BACKWARD){ | |
3148 s->mv_dir = MV_DIR_BACKWARD; | |
3149 s->mv_type = MV_TYPE_16X16; | |
3150 s->mb_intra= 0; | |
3151 s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
3152 s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
456 | 3153 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BACKWARD, pb, pb2, tex_pb, |
3154 &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); | |
327 | 3155 } |
3156 if(mb_type&MB_TYPE_BIDIR){ | |
3157 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
3158 s->mv_type = MV_TYPE_16X16; | |
3159 s->mb_intra= 0; | |
3160 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
3161 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
3162 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
3163 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
456 | 3164 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BIDIR, pb, pb2, tex_pb, |
3165 &dmin, &next_block, 0, 0); | |
327 | 3166 } |
3167 if(mb_type&MB_TYPE_DIRECT){ | |
936 | 3168 int mx= s->b_direct_mv_table[xy][0]; |
3169 int my= s->b_direct_mv_table[xy][1]; | |
3170 | |
327 | 3171 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
3172 s->mb_intra= 0; | |
1042 | 3173 #ifdef CONFIG_RISKY |
936 | 3174 ff_mpeg4_set_direct_mv(s, mx, my); |
1042 | 3175 #endif |
456 | 3176 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_DIRECT, pb, pb2, tex_pb, |
936 | 3177 &dmin, &next_block, mx, my); |
295 | 3178 } |
294 | 3179 if(mb_type&MB_TYPE_INTRA){ |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
3180 s->mv_dir = 0; |
295 | 3181 s->mv_type = MV_TYPE_16X16; |
294 | 3182 s->mb_intra= 1; |
3183 s->mv[0][0][0] = 0; | |
3184 s->mv[0][0][1] = 0; | |
456 | 3185 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTRA, pb, pb2, tex_pb, |
3186 &dmin, &next_block, 0, 0); | |
326 | 3187 /* force cleaning of ac/dc pred stuff if needed ... */ |
3188 if(s->h263_pred || s->h263_aic) | |
3189 s->mbintra_table[mb_x + mb_y*s->mb_width]=1; | |
295 | 3190 } |
326 | 3191 copy_context_after_encode(s, &best_s, -1); |
456 | 3192 |
3193 pb_bits_count= get_bit_count(&s->pb); | |
3194 flush_put_bits(&s->pb); | |
3195 ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); | |
3196 s->pb= backup_s.pb; | |
3197 | |
3198 if(s->data_partitioning){ | |
3199 pb2_bits_count= get_bit_count(&s->pb2); | |
3200 flush_put_bits(&s->pb2); | |
3201 ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); | |
3202 s->pb2= backup_s.pb2; | |
3203 | |
3204 tex_pb_bits_count= get_bit_count(&s->tex_pb); | |
3205 flush_put_bits(&s->tex_pb); | |
3206 ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); | |
3207 s->tex_pb= backup_s.tex_pb; | |
3208 } | |
329 | 3209 s->last_bits= get_bit_count(&s->pb); |
294 | 3210 } else { |
324 | 3211 int motion_x, motion_y; |
1013 | 3212 int intra_score; |
3213 int inter_score= s->current_picture.mb_cmp_score[mb_x + mb_y*s->mb_width]; | |
3214 | |
3215 if(!(s->flags&CODEC_FLAG_HQ) && s->pict_type==P_TYPE){ | |
3216 /* get luma score */ | |
3217 if((s->avctx->mb_cmp&0xFF)==FF_CMP_SSE){ | |
3218 intra_score= (s->current_picture.mb_var[mb_x + mb_y*s->mb_width]<<8) - 500; //FIXME dont scale it down so we dont have to fix it | |
3219 }else{ | |
3220 uint8_t *dest_y; | |
3221 | |
3222 int mean= s->current_picture.mb_mean[mb_x + mb_y*s->mb_width]; //FIXME | |
3223 mean*= 0x01010101; | |
3224 | |
3225 dest_y = s->new_picture.data[0] + (mb_y * 16 * s->linesize ) + mb_x * 16; | |
3226 | |
3227 for(i=0; i<16; i++){ | |
3228 *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 0]) = mean; | |
3229 *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 4]) = mean; | |
3230 *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 8]) = mean; | |
3231 *(uint32_t*)(&s->me.scratchpad[i*s->linesize+12]) = mean; | |
3232 } | |
3233 | |
3234 s->mb_intra=1; | |
3235 intra_score= s->dsp.mb_cmp[0](s, s->me.scratchpad, dest_y, s->linesize); | |
3236 | |
3237 /* printf("intra:%7d inter:%7d var:%7d mc_var.%7d\n", intra_score>>8, inter_score>>8, | |
3238 s->current_picture.mb_var[mb_x + mb_y*s->mb_width], | |
3239 s->current_picture.mc_mb_var[mb_x + mb_y*s->mb_width]);*/ | |
3240 } | |
3241 | |
3242 /* get chroma score */ | |
3243 if(s->avctx->mb_cmp&FF_CMP_CHROMA){ | |
3244 int i; | |
3245 | |
3246 s->mb_intra=1; | |
3247 for(i=1; i<3; i++){ | |
3248 uint8_t *dest_c; | |
3249 int mean; | |
3250 | |
3251 if(s->out_format == FMT_H263){ | |
3252 mean= (s->dc_val[i][mb_x + (mb_y+1)*(s->mb_width+2)] + 4)>>3; //FIXME not exact but simple ;) | |
3253 }else{ | |
3254 mean= (s->last_dc[i] + 4)>>3; | |
3255 } | |
3256 dest_c = s->new_picture.data[i] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; | |
3257 | |
3258 mean*= 0x01010101; | |
3259 for(i=0; i<8; i++){ | |
3260 *(uint32_t*)(&s->me.scratchpad[i*s->uvlinesize+ 0]) = mean; | |
3261 *(uint32_t*)(&s->me.scratchpad[i*s->uvlinesize+ 4]) = mean; | |
3262 } | |
3263 | |
3264 intra_score+= s->dsp.mb_cmp[1](s, s->me.scratchpad, dest_c, s->uvlinesize); | |
3265 } | |
3266 } | |
3267 | |
3268 /* bias */ | |
3269 switch(s->avctx->mb_cmp&0xFF){ | |
3270 default: | |
3271 case FF_CMP_SAD: | |
3272 intra_score+= 32*s->qscale; | |
3273 break; | |
3274 case FF_CMP_SSE: | |
3275 intra_score+= 24*s->qscale*s->qscale; | |
3276 break; | |
3277 case FF_CMP_SATD: | |
3278 intra_score+= 96*s->qscale; | |
3279 break; | |
3280 case FF_CMP_DCT: | |
3281 intra_score+= 48*s->qscale; | |
3282 break; | |
3283 case FF_CMP_BIT: | |
3284 intra_score+= 16; | |
3285 break; | |
3286 case FF_CMP_PSNR: | |
3287 case FF_CMP_RD: | |
3288 intra_score+= (s->qscale*s->qscale*109*8 + 64)>>7; | |
3289 break; | |
3290 } | |
3291 | |
3292 if(intra_score < inter_score) | |
3293 mb_type= MB_TYPE_INTRA; | |
3294 } | |
3295 | |
324 | 3296 s->mv_type=MV_TYPE_16X16; |
294 | 3297 // only one MB-Type possible |
1013 | 3298 |
327 | 3299 switch(mb_type){ |
3300 case MB_TYPE_INTRA: | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
3301 s->mv_dir = 0; |
294 | 3302 s->mb_intra= 1; |
324 | 3303 motion_x= s->mv[0][0][0] = 0; |
3304 motion_y= s->mv[0][0][1] = 0; | |
327 | 3305 break; |
3306 case MB_TYPE_INTER: | |
324 | 3307 s->mv_dir = MV_DIR_FORWARD; |
3308 s->mb_intra= 0; | |
3309 motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; | |
3310 motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
327 | 3311 break; |
456 | 3312 case MB_TYPE_INTER4V: |
3313 s->mv_dir = MV_DIR_FORWARD; | |
3314 s->mv_type = MV_TYPE_8X8; | |
3315 s->mb_intra= 0; | |
3316 for(i=0; i<4; i++){ | |
3317 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; | |
3318 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; | |
3319 } | |
3320 motion_x= motion_y= 0; | |
3321 break; | |
327 | 3322 case MB_TYPE_DIRECT: |
324 | 3323 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
3324 s->mb_intra= 0; | |
327 | 3325 motion_x=s->b_direct_mv_table[xy][0]; |
3326 motion_y=s->b_direct_mv_table[xy][1]; | |
1042 | 3327 #ifdef CONFIG_RISKY |
936 | 3328 ff_mpeg4_set_direct_mv(s, motion_x, motion_y); |
1042 | 3329 #endif |
327 | 3330 break; |
3331 case MB_TYPE_BIDIR: | |
324 | 3332 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; |
294 | 3333 s->mb_intra= 0; |
324 | 3334 motion_x=0; |
3335 motion_y=0; | |
3336 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
3337 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
3338 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
3339 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
327 | 3340 break; |
3341 case MB_TYPE_BACKWARD: | |
324 | 3342 s->mv_dir = MV_DIR_BACKWARD; |
3343 s->mb_intra= 0; | |
3344 motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
3345 motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
327 | 3346 break; |
3347 case MB_TYPE_FORWARD: | |
324 | 3348 s->mv_dir = MV_DIR_FORWARD; |
3349 s->mb_intra= 0; | |
3350 motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
3351 motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
3352 // printf(" %d %d ", motion_x, motion_y); | |
327 | 3353 break; |
3354 default: | |
324 | 3355 motion_x=motion_y=0; //gcc warning fix |
3356 printf("illegal MB type\n"); | |
294 | 3357 } |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
3358 |
324 | 3359 encode_mb(s, motion_x, motion_y); |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
3360 |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
3361 // RAL: Update last macrobloc type |
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
3362 s->last_mv_dir = s->mv_dir; |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
3363 } |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
3364 |
327 | 3365 /* clean the MV table in IPS frames for direct mode in B frames */ |
3366 if(s->mb_intra /* && I,P,S_TYPE */){ | |
3367 s->p_mv_table[xy][0]=0; | |
3368 s->p_mv_table[xy][1]=0; | |
3369 } | |
0 | 3370 |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3371 MPV_decode_mb(s, s->block); |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3372 |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3373 if(s->flags&CODEC_FLAG_PSNR){ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3374 int w= 16; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3375 int h= 16; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3376 |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3377 if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3378 if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; |
936 | 3379 |
1148 | 3380 s->current_picture_ptr->error[0] += sse( |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3381 s, |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3382 s->new_picture .data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3383 s->current_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3384 w, h, s->linesize); |
1148 | 3385 s->current_picture_ptr->error[1] += sse( |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3386 s, |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3387 s->new_picture .data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3388 s->current_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3389 w>>1, h>>1, s->uvlinesize); |
1148 | 3390 s->current_picture_ptr->error[2] += sse( |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3391 s, |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3392 s->new_picture .data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3393 s->current_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3394 w>>1, h>>1, s->uvlinesize); |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3395 } |
456 | 3396 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_width, get_bit_count(&s->pb)); |
0 | 3397 } |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
3398 |
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
3399 |
766 | 3400 /* Obtain average mb_row size for RTP */ |
231 | 3401 if (s->rtp_mode) { |
766 | 3402 if (mb_y==0) |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
3403 s->mb_line_avgsize = pbBufPtr(&s->pb) - s->ptr_last_mb_line; |
766 | 3404 else { |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
3405 s->mb_line_avgsize = (s->mb_line_avgsize + pbBufPtr(&s->pb) - s->ptr_last_mb_line) >> 1; |
231 | 3406 } |
766 | 3407 s->ptr_last_mb_line = pbBufPtr(&s->pb); |
231 | 3408 } |
0 | 3409 } |
294 | 3410 emms_c(); |
286 | 3411 |
1042 | 3412 #ifdef CONFIG_RISKY |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3413 if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame) |
456 | 3414 ff_mpeg4_merge_partitions(s); |
3415 | |
3416 if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE) | |
208 | 3417 msmpeg4_encode_ext_header(s); |
3418 | |
456 | 3419 if(s->codec_id==CODEC_ID_MPEG4) |
3420 ff_mpeg4_stuffing(&s->pb); | |
1042 | 3421 #endif |
456 | 3422 |
162 | 3423 //if (s->gob_number) |
3424 // fprintf(stderr,"\nNumber of GOB: %d", s->gob_number); | |
231 | 3425 |
3426 /* Send the last GOB if RTP */ | |
3427 if (s->rtp_mode) { | |
3428 flush_put_bits(&s->pb); | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
3429 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
231 | 3430 /* Call the RTP callback to send the last GOB */ |
3431 if (s->rtp_callback) | |
3432 s->rtp_callback(s->ptr_lastgob, pdif, s->gob_number); | |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
3433 s->ptr_lastgob = pbBufPtr(&s->pb); |
231 | 3434 //fprintf(stderr,"\nGOB: %2d size: %d (last)", s->gob_number, pdif); |
3435 } | |
0 | 3436 } |
3437 | |
945 | 3438 static int dct_quantize_trellis_c(MpegEncContext *s, |
3439 DCTELEM *block, int n, | |
3440 int qscale, int *overflow){ | |
3441 const int *qmat; | |
1064 | 3442 const uint8_t *scantable= s->intra_scantable.scantable; |
945 | 3443 int max=0; |
3444 unsigned int threshold1, threshold2; | |
3445 int bias=0; | |
3446 int run_tab[65]; | |
3447 int level_tab[65]; | |
3448 int score_tab[65]; | |
946 | 3449 int last_run=0; |
3450 int last_level=0; | |
3451 int last_score= 0; | |
3452 int last_i= 0; | |
3453 int coeff[3][64]; | |
945 | 3454 int coeff_count[64]; |
946 | 3455 int lambda, qmul, qadd, start_i, last_non_zero, i; |
945 | 3456 const int esc_length= s->ac_esc_length; |
3457 uint8_t * length; | |
3458 uint8_t * last_length; | |
946 | 3459 int score_limit=0; |
3460 int left_limit= 0; | |
945 | 3461 |
1092 | 3462 s->dsp.fdct (block); |
945 | 3463 |
3464 qmul= qscale*16; | |
3465 qadd= ((qscale-1)|1)*8; | |
946 | 3466 |
945 | 3467 if (s->mb_intra) { |
3468 int q; | |
3469 if (!s->h263_aic) { | |
3470 if (n < 4) | |
3471 q = s->y_dc_scale; | |
3472 else | |
3473 q = s->c_dc_scale; | |
3474 q = q << 3; | |
3475 } else{ | |
3476 /* For AIC we skip quant/dequant of INTRADC */ | |
3477 q = 1 << 3; | |
3478 qadd=0; | |
3479 } | |
3480 | |
3481 /* note: block[0] is assumed to be positive */ | |
3482 block[0] = (block[0] + (q >> 1)) / q; | |
3483 start_i = 1; | |
3484 last_non_zero = 0; | |
3485 qmat = s->q_intra_matrix[qscale]; | |
947 | 3486 if(s->mpeg_quant || s->codec_id== CODEC_ID_MPEG1VIDEO) |
945 | 3487 bias= 1<<(QMAT_SHIFT-1); |
3488 length = s->intra_ac_vlc_length; | |
3489 last_length= s->intra_ac_vlc_last_length; | |
3490 } else { | |
3491 start_i = 0; | |
3492 last_non_zero = -1; | |
3493 qmat = s->q_inter_matrix[qscale]; | |
3494 length = s->inter_ac_vlc_length; | |
3495 last_length= s->inter_ac_vlc_last_length; | |
3496 } | |
3497 | |
3498 threshold1= (1<<QMAT_SHIFT) - bias - 1; | |
3499 threshold2= (threshold1<<1); | |
946 | 3500 |
945 | 3501 for(i=start_i; i<64; i++) { |
3502 const int j = scantable[i]; | |
3503 const int k= i-start_i; | |
3504 int level = block[j]; | |
3505 level = level * qmat[j]; | |
3506 | |
3507 // if( bias+level >= (1<<(QMAT_SHIFT - 3)) | |
3508 // || bias-level >= (1<<(QMAT_SHIFT - 3))){ | |
3509 if(((unsigned)(level+threshold1))>threshold2){ | |
3510 if(level>0){ | |
3511 level= (bias + level)>>QMAT_SHIFT; | |
3512 coeff[0][k]= level; | |
3513 coeff[1][k]= level-1; | |
946 | 3514 // coeff[2][k]= level-2; |
945 | 3515 }else{ |
3516 level= (bias - level)>>QMAT_SHIFT; | |
3517 coeff[0][k]= -level; | |
3518 coeff[1][k]= -level+1; | |
946 | 3519 // coeff[2][k]= -level+2; |
945 | 3520 } |
946 | 3521 coeff_count[k]= FFMIN(level, 2); |
945 | 3522 max |=level; |
3523 last_non_zero = i; | |
3524 }else{ | |
946 | 3525 coeff[0][k]= (level>>31)|1; |
945 | 3526 coeff_count[k]= 1; |
3527 } | |
3528 } | |
3529 | |
3530 *overflow= s->max_qcoeff < max; //overflow might have happend | |
3531 | |
3532 if(last_non_zero < start_i){ | |
3533 memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); | |
3534 return last_non_zero; | |
3535 } | |
3536 | |
1013 | 3537 lambda= (qscale*qscale*64*105 + 64)>>7; //FIXME finetune |
945 | 3538 |
946 | 3539 score_tab[0]= 0; |
945 | 3540 for(i=0; i<=last_non_zero - start_i; i++){ |
3541 int level_index, run, j; | |
3542 const int dct_coeff= block[ scantable[i + start_i] ]; | |
3543 const int zero_distoration= dct_coeff*dct_coeff; | |
946 | 3544 int best_score=256*256*256*120; |
3545 | |
3546 last_score += zero_distoration; | |
945 | 3547 for(level_index=0; level_index < coeff_count[i]; level_index++){ |
3548 int distoration; | |
3549 int level= coeff[level_index][i]; | |
3550 int unquant_coeff; | |
3551 | |
3552 assert(level); | |
3553 | |
3554 if(s->out_format == FMT_H263){ | |
3555 if(level>0){ | |
3556 unquant_coeff= level*qmul + qadd; | |
3557 }else{ | |
3558 unquant_coeff= level*qmul - qadd; | |
3559 } | |
947 | 3560 }else{ //MPEG1 |
1092 | 3561 j= s->dsp.idct_permutation[ scantable[i + start_i] ]; //FIXME optimize |
947 | 3562 if(s->mb_intra){ |
3563 if (level < 0) { | |
3564 unquant_coeff = (int)((-level) * qscale * s->intra_matrix[j]) >> 3; | |
3565 unquant_coeff = -((unquant_coeff - 1) | 1); | |
3566 } else { | |
3567 unquant_coeff = (int)( level * qscale * s->intra_matrix[j]) >> 3; | |
3568 unquant_coeff = (unquant_coeff - 1) | 1; | |
3569 } | |
3570 }else{ | |
3571 if (level < 0) { | |
3572 unquant_coeff = ((((-level) << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4; | |
3573 unquant_coeff = -((unquant_coeff - 1) | 1); | |
3574 } else { | |
3575 unquant_coeff = ((( level << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4; | |
3576 unquant_coeff = (unquant_coeff - 1) | 1; | |
3577 } | |
3578 } | |
3579 unquant_coeff<<= 3; | |
3580 } | |
946 | 3581 |
945 | 3582 distoration= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff); |
3583 level+=64; | |
3584 if((level&(~127)) == 0){ | |
946 | 3585 for(run=0; run<=i - left_limit; run++){ |
947 | 3586 int score= distoration + length[UNI_AC_ENC_INDEX(run, level)]*lambda; |
945 | 3587 score += score_tab[i-run]; |
3588 | |
3589 if(score < best_score){ | |
3590 best_score= | |
3591 score_tab[i+1]= score; | |
3592 run_tab[i+1]= run; | |
3593 level_tab[i+1]= level-64; | |
3594 } | |
3595 } | |
3596 | |
3597 if(s->out_format == FMT_H263){ | |
946 | 3598 for(run=0; run<=i - left_limit; run++){ |
947 | 3599 int score= distoration + last_length[UNI_AC_ENC_INDEX(run, level)]*lambda; |
945 | 3600 score += score_tab[i-run]; |
946 | 3601 if(score < last_score){ |
3602 last_score= score; | |
3603 last_run= run; | |
3604 last_level= level-64; | |
3605 last_i= i+1; | |
945 | 3606 } |
3607 } | |
3608 } | |
3609 }else{ | |
3610 distoration += esc_length*lambda; | |
946 | 3611 for(run=0; run<=i - left_limit; run++){ |
945 | 3612 int score= distoration + score_tab[i-run]; |
3613 | |
3614 if(score < best_score){ | |
3615 best_score= | |
3616 score_tab[i+1]= score; | |
3617 run_tab[i+1]= run; | |
3618 level_tab[i+1]= level-64; | |
3619 } | |
3620 } | |
3621 | |
3622 if(s->out_format == FMT_H263){ | |
946 | 3623 for(run=0; run<=i - left_limit; run++){ |
945 | 3624 int score= distoration + score_tab[i-run]; |
946 | 3625 if(score < last_score){ |
3626 last_score= score; | |
3627 last_run= run; | |
3628 last_level= level-64; | |
3629 last_i= i+1; | |
945 | 3630 } |
3631 } | |
3632 } | |
3633 } | |
3634 } | |
3635 | |
946 | 3636 for(j=left_limit; j<=i; j++){ |
945 | 3637 score_tab[j] += zero_distoration; |
3638 } | |
946 | 3639 score_limit+= zero_distoration; |
3640 if(score_tab[i+1] < score_limit) | |
3641 score_limit= score_tab[i+1]; | |
3642 | |
3643 //Note: there is a vlc code in mpeg4 which is 1 bit shorter then another one with a shorter run and the same level | |
3644 while(score_tab[ left_limit ] > score_limit + lambda) left_limit++; | |
945 | 3645 } |
946 | 3646 |
3647 //FIXME add some cbp penalty | |
3648 | |
945 | 3649 if(s->out_format != FMT_H263){ |
946 | 3650 last_score= 256*256*256*120; |
947 | 3651 for(i= left_limit; i<=last_non_zero - start_i + 1; i++){ |
946 | 3652 int score= score_tab[i]; |
947 | 3653 if(i) score += lambda*2; //FIXME exacter? |
3654 | |
946 | 3655 if(score < last_score){ |
3656 last_score= score; | |
3657 last_i= i; | |
3658 last_level= level_tab[i]; | |
3659 last_run= run_tab[i]; | |
3660 } | |
945 | 3661 } |
3662 } | |
3663 | |
946 | 3664 last_non_zero= last_i - 1 + start_i; |
945 | 3665 memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); |
3666 | |
3667 if(last_non_zero < start_i) | |
3668 return last_non_zero; | |
3669 | |
946 | 3670 i= last_i; |
3671 assert(last_level); | |
945 | 3672 //FIXME use permutated scantable |
1092 | 3673 block[ s->dsp.idct_permutation[ scantable[last_non_zero] ] ]= last_level; |
946 | 3674 i -= last_run + 1; |
945 | 3675 |
3676 for(;i>0 ; i -= run_tab[i] + 1){ | |
1092 | 3677 const int j= s->dsp.idct_permutation[ scantable[i - 1 + start_i] ]; |
945 | 3678 |
3679 block[j]= level_tab[i]; | |
3680 assert(block[j]); | |
3681 } | |
3682 | |
3683 return last_non_zero; | |
3684 } | |
3685 | |
220 | 3686 static int dct_quantize_c(MpegEncContext *s, |
0 | 3687 DCTELEM *block, int n, |
344 | 3688 int qscale, int *overflow) |
0 | 3689 { |
3690 int i, j, level, last_non_zero, q; | |
3691 const int *qmat; | |
1064 | 3692 const uint8_t *scantable= s->intra_scantable.scantable; |
344 | 3693 int bias; |
3694 int max=0; | |
3695 unsigned int threshold1, threshold2; | |
828
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
3696 |
1092 | 3697 s->dsp.fdct (block); |
0 | 3698 |
3699 if (s->mb_intra) { | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3700 if (!s->h263_aic) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3701 if (n < 4) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3702 q = s->y_dc_scale; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3703 else |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3704 q = s->c_dc_scale; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3705 q = q << 3; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3706 } else |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3707 /* For AIC we skip quant/dequant of INTRADC */ |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3708 q = 1 << 3; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3709 |
0 | 3710 /* note: block[0] is assumed to be positive */ |
3711 block[0] = (block[0] + (q >> 1)) / q; | |
3712 i = 1; | |
3713 last_non_zero = 0; | |
344 | 3714 qmat = s->q_intra_matrix[qscale]; |
635 | 3715 bias= s->intra_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); |
0 | 3716 } else { |
3717 i = 0; | |
3718 last_non_zero = -1; | |
344 | 3719 qmat = s->q_inter_matrix[qscale]; |
635 | 3720 bias= s->inter_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); |
0 | 3721 } |
635 | 3722 threshold1= (1<<QMAT_SHIFT) - bias - 1; |
3723 threshold2= (threshold1<<1); | |
0 | 3724 |
3725 for(;i<64;i++) { | |
764 | 3726 j = scantable[i]; |
0 | 3727 level = block[j]; |
3728 level = level * qmat[j]; | |
344 | 3729 |
3730 // if( bias+level >= (1<<(QMAT_SHIFT - 3)) | |
3731 // || bias-level >= (1<<(QMAT_SHIFT - 3))){ | |
3732 if(((unsigned)(level+threshold1))>threshold2){ | |
3733 if(level>0){ | |
635 | 3734 level= (bias + level)>>QMAT_SHIFT; |
344 | 3735 block[j]= level; |
3736 }else{ | |
635 | 3737 level= (bias - level)>>QMAT_SHIFT; |
344 | 3738 block[j]= -level; |
0 | 3739 } |
344 | 3740 max |=level; |
0 | 3741 last_non_zero = i; |
344 | 3742 }else{ |
3743 block[j]=0; | |
0 | 3744 } |
3745 } | |
344 | 3746 *overflow= s->max_qcoeff < max; //overflow might have happend |
3747 | |
764 | 3748 /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */ |
1092 | 3749 if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM) |
3750 ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero); | |
764 | 3751 |
0 | 3752 return last_non_zero; |
3753 } | |
3754 | |
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:
1064
diff
changeset
|
3755 #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:
1064
diff
changeset
|
3756 |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3757 static void dct_unquantize_mpeg1_c(MpegEncContext *s, |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3758 DCTELEM *block, int n, int qscale) |
0 | 3759 { |
200 | 3760 int i, level, nCoeffs; |
1064 | 3761 const uint16_t *quant_matrix; |
0 | 3762 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3763 nCoeffs= s->block_last_index[n]; |
200 | 3764 |
0 | 3765 if (s->mb_intra) { |
3766 if (n < 4) | |
3767 block[0] = block[0] * s->y_dc_scale; | |
3768 else | |
3769 block[0] = block[0] * s->c_dc_scale; | |
3770 /* XXX: only mpeg1 */ | |
3771 quant_matrix = s->intra_matrix; | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3772 for(i=1;i<=nCoeffs;i++) { |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3773 int j= s->intra_scantable.permutated[i]; |
200 | 3774 level = block[j]; |
0 | 3775 if (level) { |
3776 if (level < 0) { | |
3777 level = -level; | |
200 | 3778 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
0 | 3779 level = (level - 1) | 1; |
3780 level = -level; | |
3781 } else { | |
200 | 3782 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
0 | 3783 level = (level - 1) | 1; |
3784 } | |
3785 #ifdef PARANOID | |
3786 if (level < -2048 || level > 2047) | |
3787 fprintf(stderr, "unquant error %d %d\n", i, level); | |
3788 #endif | |
200 | 3789 block[j] = level; |
0 | 3790 } |
3791 } | |
3792 } else { | |
3793 i = 0; | |
344 | 3794 quant_matrix = s->inter_matrix; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3795 for(;i<=nCoeffs;i++) { |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3796 int j= s->intra_scantable.permutated[i]; |
200 | 3797 level = block[j]; |
0 | 3798 if (level) { |
3799 if (level < 0) { | |
3800 level = -level; | |
3801 level = (((level << 1) + 1) * qscale * | |
200 | 3802 ((int) (quant_matrix[j]))) >> 4; |
0 | 3803 level = (level - 1) | 1; |
3804 level = -level; | |
3805 } else { | |
3806 level = (((level << 1) + 1) * qscale * | |
200 | 3807 ((int) (quant_matrix[j]))) >> 4; |
0 | 3808 level = (level - 1) | 1; |
3809 } | |
3810 #ifdef PARANOID | |
3811 if (level < -2048 || level > 2047) | |
3812 fprintf(stderr, "unquant error %d %d\n", i, level); | |
3813 #endif | |
200 | 3814 block[j] = level; |
0 | 3815 } |
3816 } | |
3817 } | |
3818 } | |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3819 |
325 | 3820 static void dct_unquantize_mpeg2_c(MpegEncContext *s, |
3821 DCTELEM *block, int n, int qscale) | |
3822 { | |
3823 int i, level, nCoeffs; | |
1064 | 3824 const uint16_t *quant_matrix; |
325 | 3825 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3826 if(s->alternate_scan) nCoeffs= 63; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3827 else nCoeffs= s->block_last_index[n]; |
325 | 3828 |
3829 if (s->mb_intra) { | |
3830 if (n < 4) | |
3831 block[0] = block[0] * s->y_dc_scale; | |
3832 else | |
3833 block[0] = block[0] * s->c_dc_scale; | |
3834 quant_matrix = s->intra_matrix; | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3835 for(i=1;i<=nCoeffs;i++) { |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3836 int j= s->intra_scantable.permutated[i]; |
325 | 3837 level = block[j]; |
3838 if (level) { | |
3839 if (level < 0) { | |
3840 level = -level; | |
3841 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
3842 level = -level; | |
3843 } else { | |
3844 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
3845 } | |
3846 #ifdef PARANOID | |
3847 if (level < -2048 || level > 2047) | |
3848 fprintf(stderr, "unquant error %d %d\n", i, level); | |
3849 #endif | |
3850 block[j] = level; | |
3851 } | |
3852 } | |
3853 } else { | |
3854 int sum=-1; | |
3855 i = 0; | |
344 | 3856 quant_matrix = s->inter_matrix; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3857 for(;i<=nCoeffs;i++) { |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3858 int j= s->intra_scantable.permutated[i]; |
325 | 3859 level = block[j]; |
3860 if (level) { | |
3861 if (level < 0) { | |
3862 level = -level; | |
3863 level = (((level << 1) + 1) * qscale * | |
3864 ((int) (quant_matrix[j]))) >> 4; | |
3865 level = -level; | |
3866 } else { | |
3867 level = (((level << 1) + 1) * qscale * | |
3868 ((int) (quant_matrix[j]))) >> 4; | |
3869 } | |
3870 #ifdef PARANOID | |
3871 if (level < -2048 || level > 2047) | |
3872 fprintf(stderr, "unquant error %d %d\n", i, level); | |
3873 #endif | |
3874 block[j] = level; | |
3875 sum+=level; | |
3876 } | |
3877 } | |
3878 block[63]^=sum&1; | |
3879 } | |
3880 } | |
3881 | |
3882 | |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3883 static void dct_unquantize_h263_c(MpegEncContext *s, |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3884 DCTELEM *block, int n, int qscale) |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3885 { |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3886 int i, level, qmul, qadd; |
200 | 3887 int nCoeffs; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3888 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3889 assert(s->block_last_index[n]>=0); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3890 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3891 qadd = (qscale - 1) | 1; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3892 qmul = qscale << 1; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3893 |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3894 if (s->mb_intra) { |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3895 if (!s->h263_aic) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3896 if (n < 4) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3897 block[0] = block[0] * s->y_dc_scale; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3898 else |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3899 block[0] = block[0] * s->c_dc_scale; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3900 }else |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3901 qadd = 0; |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3902 i = 1; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3903 nCoeffs= 63; //does not allways use zigzag table |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3904 } else { |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3905 i = 0; |
1094 | 3906 nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ]; |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3907 } |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3908 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3909 for(;i<=nCoeffs;i++) { |
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3910 level = block[i]; |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3911 if (level) { |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3912 if (level < 0) { |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3913 level = level * qmul - qadd; |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3914 } else { |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3915 level = level * qmul + qadd; |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3916 } |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3917 #ifdef PARANOID |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3918 if (level < -2048 || level > 2047) |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3919 fprintf(stderr, "unquant error %d %d\n", i, level); |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3920 #endif |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3921 block[i] = level; |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3922 } |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3923 } |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
3924 } |
0 | 3925 |
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:
1064
diff
changeset
|
3926 |
930 | 3927 char ff_get_pict_type_char(int pict_type){ |
3928 switch(pict_type){ | |
3929 case I_TYPE: return 'I'; | |
3930 case P_TYPE: return 'P'; | |
3931 case B_TYPE: return 'B'; | |
3932 case S_TYPE: return 'S'; | |
936 | 3933 default: return '?'; |
930 | 3934 } |
3935 } | |
3936 | |
1059 | 3937 static const AVOption mpeg4_options[] = |
3938 { | |
3939 AVOPTION_CODEC_INT("bitrate", "desired video bitrate", bit_rate, 4, 240000000, 800000), | |
3940 AVOPTION_CODEC_FLAG("vhq", "very high quality", flags, CODEC_FLAG_HQ, 0), | |
3941 AVOPTION_CODEC_INT("ratetol", "number of bits the bitstream is allowed to diverge from the reference" | |
3942 "the reference can be CBR (for CBR pass1) or VBR (for pass2)", | |
3943 bit_rate_tolerance, 4, 240000000, 8000), | |
3944 AVOPTION_CODEC_INT("qmin", "minimum quantizer", qmin, 1, 31, 2), | |
3945 AVOPTION_CODEC_INT("qmax", "maximum quantizer", qmax, 1, 31, 31), | |
3946 AVOPTION_CODEC_STRING("rc_eq", "rate control equation", | |
3947 rc_eq, "tex^qComp,option1,options2", 0), | |
3948 AVOPTION_CODEC_INT("rc_minrate", "rate control minimum bitrate", | |
3949 rc_min_rate, 4, 24000000, 0), | |
3950 AVOPTION_CODEC_INT("rc_maxrate", "rate control maximum bitrate", | |
3951 rc_max_rate, 4, 24000000, 0), | |
1130 | 3952 AVOPTION_CODEC_DOUBLE("rc_buf_aggresivity", "rate control buffer aggresivity", |
3953 rc_buffer_aggressivity, 4, 24000000, 0), | |
3954 AVOPTION_CODEC_DOUBLE("rc_initial_cplx", "initial complexity for pass1 ratecontrol", | |
3955 rc_initial_cplx, 0., 9999999., 0), | |
3956 AVOPTION_CODEC_DOUBLE("i_quant_factor", "qscale factor between p and i frames", | |
3957 i_quant_factor, 0., 0., 0), | |
3958 AVOPTION_CODEC_DOUBLE("i_quant_offset", "qscale offset between p and i frames", | |
3959 i_quant_factor, -999999., 999999., 0), | |
3960 AVOPTION_CODEC_INT("dct_algo", "dct alghorithm", | |
3961 dct_algo, 0, 5, 0), // fixme - "Auto,FastInt,Int,MMX,MLib,Altivec" | |
3962 AVOPTION_CODEC_DOUBLE("lumi_masking", "luminance masking", | |
3963 lumi_masking, 0., 999999., 0), | |
3964 AVOPTION_CODEC_DOUBLE("temporal_cplx_masking", "temporary complexity masking", | |
3965 temporal_cplx_masking, 0., 999999., 0), | |
3966 AVOPTION_CODEC_DOUBLE("spatial_cplx_masking", "spatial complexity masking", | |
3967 spatial_cplx_masking, 0., 999999., 0), | |
3968 AVOPTION_CODEC_DOUBLE("p_masking", "p block masking", | |
3969 p_masking, 0., 999999., 0), | |
3970 AVOPTION_CODEC_DOUBLE("dark_masking", "darkness masking", | |
3971 dark_masking, 0., 999999., 0), | |
3972 AVOPTION_CODEC_INT("idct_algo", "idct alghorithm", | |
3973 idct_algo, 0, 8, 0), // fixme - "Auto,Int,Simple,SimpleMMX,LibMPEG2MMX,PS2,MLib,ARM,Altivec" | |
3974 | |
3975 AVOPTION_CODEC_INT("mb_qmin", "minimum MB quantizer", | |
3976 mb_qmin, 0, 8, 0), | |
3977 AVOPTION_CODEC_INT("mb_qmax", "maximum MB quantizer", | |
3978 mb_qmin, 0, 8, 0), | |
3979 | |
3980 AVOPTION_CODEC_INT("me_cmp", "ME compare function", | |
3981 me_cmp, 0, 24000000, 0), | |
3982 AVOPTION_CODEC_INT("me_sub_cmp", "subpixel ME compare function", | |
3983 me_sub_cmp, 0, 24000000, 0), | |
3984 | |
3985 | |
3986 AVOPTION_CODEC_INT("dia_size", "ME diamond size & shape", | |
3987 dia_size, 0, 24000000, 0), | |
3988 AVOPTION_CODEC_INT("last_predictor_count", "amount of previous MV predictors", | |
3989 last_predictor_count, 0, 24000000, 0), | |
3990 | |
3991 AVOPTION_CODEC_INT("pre_me", "pre pass for ME", | |
3992 pre_me, 0, 24000000, 0), | |
3993 AVOPTION_CODEC_INT("me_pre_cmp", "ME pre pass compare function", | |
3994 me_pre_cmp, 0, 24000000, 0), | |
3995 | |
3996 AVOPTION_CODEC_INT("me_range", "maximum ME search range", | |
3997 me_range, 0, 24000000, 0), | |
3998 AVOPTION_CODEC_INT("pre_dia_size", "ME pre pass diamod size & shape", | |
3999 pre_dia_size, 0, 24000000, 0), | |
4000 AVOPTION_CODEC_INT("me_subpel_quality", "subpel ME quality", | |
4001 me_subpel_quality, 0, 24000000, 0), | |
4002 AVOPTION_CODEC_INT("me_range", "maximum ME search range", | |
4003 me_range, 0, 24000000, 0), | |
1059 | 4004 AVOPTION_CODEC_FLAG("psnr", "calculate PSNR of compressed frames", |
4005 flags, CODEC_FLAG_PSNR, 0), | |
4006 AVOPTION_CODEC_RCOVERRIDE("rc_override", "ratecontrol override (=startframe,endframe,qscale,quality_factor)", | |
4007 rc_override), | |
1124
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1116
diff
changeset
|
4008 AVOPTION_SUB(avoptions_common), |
1059 | 4009 AVOPTION_END() |
4010 }; | |
4011 | |
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:
1064
diff
changeset
|
4012 #ifdef 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:
1064
diff
changeset
|
4013 |
0 | 4014 AVCodec mpeg1video_encoder = { |
4015 "mpeg1video", | |
4016 CODEC_TYPE_VIDEO, | |
4017 CODEC_ID_MPEG1VIDEO, | |
4018 sizeof(MpegEncContext), | |
4019 MPV_encode_init, | |
4020 MPV_encode_picture, | |
4021 MPV_encode_end, | |
4022 }; | |
4023 | |
1042 | 4024 #ifdef CONFIG_RISKY |
4025 | |
0 | 4026 AVCodec h263_encoder = { |
4027 "h263", | |
4028 CODEC_TYPE_VIDEO, | |
4029 CODEC_ID_H263, | |
4030 sizeof(MpegEncContext), | |
4031 MPV_encode_init, | |
4032 MPV_encode_picture, | |
4033 MPV_encode_end, | |
4034 }; | |
4035 | |
4036 AVCodec h263p_encoder = { | |
4037 "h263p", | |
4038 CODEC_TYPE_VIDEO, | |
4039 CODEC_ID_H263P, | |
4040 sizeof(MpegEncContext), | |
4041 MPV_encode_init, | |
4042 MPV_encode_picture, | |
4043 MPV_encode_end, | |
4044 }; | |
4045 | |
4046 AVCodec rv10_encoder = { | |
4047 "rv10", | |
4048 CODEC_TYPE_VIDEO, | |
4049 CODEC_ID_RV10, | |
4050 sizeof(MpegEncContext), | |
4051 MPV_encode_init, | |
4052 MPV_encode_picture, | |
4053 MPV_encode_end, | |
4054 }; | |
4055 | |
71 | 4056 AVCodec mpeg4_encoder = { |
4057 "mpeg4", | |
0 | 4058 CODEC_TYPE_VIDEO, |
71 | 4059 CODEC_ID_MPEG4, |
0 | 4060 sizeof(MpegEncContext), |
4061 MPV_encode_init, | |
4062 MPV_encode_picture, | |
4063 MPV_encode_end, | |
1059 | 4064 .options = mpeg4_options, |
0 | 4065 }; |
4066 | |
307 | 4067 AVCodec msmpeg4v1_encoder = { |
4068 "msmpeg4v1", | |
0 | 4069 CODEC_TYPE_VIDEO, |
307 | 4070 CODEC_ID_MSMPEG4V1, |
0 | 4071 sizeof(MpegEncContext), |
4072 MPV_encode_init, | |
4073 MPV_encode_picture, | |
4074 MPV_encode_end, | |
1130 | 4075 .options = mpeg4_options, |
0 | 4076 }; |
307 | 4077 |
4078 AVCodec msmpeg4v2_encoder = { | |
4079 "msmpeg4v2", | |
4080 CODEC_TYPE_VIDEO, | |
4081 CODEC_ID_MSMPEG4V2, | |
4082 sizeof(MpegEncContext), | |
4083 MPV_encode_init, | |
4084 MPV_encode_picture, | |
4085 MPV_encode_end, | |
1130 | 4086 .options = mpeg4_options, |
307 | 4087 }; |
4088 | |
4089 AVCodec msmpeg4v3_encoder = { | |
4090 "msmpeg4", | |
4091 CODEC_TYPE_VIDEO, | |
4092 CODEC_ID_MSMPEG4V3, | |
4093 sizeof(MpegEncContext), | |
4094 MPV_encode_init, | |
4095 MPV_encode_picture, | |
4096 MPV_encode_end, | |
1130 | 4097 .options = mpeg4_options, |
307 | 4098 }; |
499 | 4099 |
4100 AVCodec wmv1_encoder = { | |
4101 "wmv1", | |
4102 CODEC_TYPE_VIDEO, | |
4103 CODEC_ID_WMV1, | |
4104 sizeof(MpegEncContext), | |
4105 MPV_encode_init, | |
4106 MPV_encode_picture, | |
4107 MPV_encode_end, | |
1130 | 4108 .options = mpeg4_options, |
499 | 4109 }; |
4110 | |
1042 | 4111 #endif |
4112 | |
4113 AVCodec mjpeg_encoder = { | |
4114 "mjpeg", | |
4115 CODEC_TYPE_VIDEO, | |
4116 CODEC_ID_MJPEG, | |
4117 sizeof(MpegEncContext), | |
4118 MPV_encode_init, | |
4119 MPV_encode_picture, | |
4120 MPV_encode_end, | |
4121 }; | |
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:
1064
diff
changeset
|
4122 |
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:
1064
diff
changeset
|
4123 #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:
1064
diff
changeset
|
4124 |