Mercurial > libavcodec.hg
annotate mpegvideo.c @ 3281:7fac25904a8b libavcodec
missmatch control for mpeg2 intra dequantization if bitexact=1
author | michael |
---|---|
date | Fri, 28 Apr 2006 17:03:52 +0000 |
parents | f7a9d8dd476b |
children | 30d412952107 |
rev | line source |
---|---|
0 | 1 /* |
2 * The simplest mpeg encoder (well, it was the simplest!) | |
429 | 3 * Copyright (c) 2000,2001 Fabrice Bellard. |
1739
07a484280a82
copyright year update of the files i touched and remembered, things look annoyingly unmaintained otherwise
michael
parents:
1729
diff
changeset
|
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> |
0 | 5 * |
429 | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Lesser General Public | |
8 * License as published by the Free Software Foundation; either | |
9 * version 2 of the License, or (at your option) any later version. | |
0 | 10 * |
429 | 11 * This library is distributed in the hope that it will be useful, |
0 | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 * Lesser General Public License for more details. | |
0 | 15 * |
429 | 16 * You should have received a copy of the GNU Lesser General Public |
17 * License along with this library; if not, write to the Free Software | |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
3011
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
295 | 19 * |
325 | 20 * 4MV & hq & b-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at> |
0 | 21 */ |
2967 | 22 |
1106 | 23 /** |
24 * @file mpegvideo.c | |
25 * The simplest mpeg encoder (well, it was the simplest!). | |
2967 | 26 */ |
27 | |
0 | 28 #include "avcodec.h" |
29 #include "dsputil.h" | |
30 #include "mpegvideo.h" | |
1557 | 31 #include "faandct.h" |
2024
f65d87bfdd5a
some of the warning fixes by (Michael Roitzsch <mroi at users dot sourceforge dot net>)
michael
parents:
2015
diff
changeset
|
32 #include <limits.h> |
0 | 33 |
17
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
34 #ifdef USE_FASTMEMCPY |
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
35 #include "fastmemcpy.h" |
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
36 #endif |
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
37 |
1422
efeed6e29f9b
oooooops, having 2 Eterms open and doing cvs diff in one and cvs commit in the other sucks, especially if they are in different directories (MPlayer/main/libavcodec vs. ffmpeg/libavcodec)
michaelni
parents:
1421
diff
changeset
|
38 //#undef NDEBUG |
efeed6e29f9b
oooooops, having 2 Eterms open and doing cvs diff in one and cvs commit in the other sucks, especially if they are in different directories (MPlayer/main/libavcodec vs. ffmpeg/libavcodec)
michaelni
parents:
1421
diff
changeset
|
39 //#include <assert.h> |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
40 |
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
|
41 #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
|
42 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
|
43 #endif //CONFIG_ENCODERS |
2967 | 44 static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, |
1689 | 45 DCTELEM *block, int n, int qscale); |
2967 | 46 static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s, |
1689 | 47 DCTELEM *block, int n, int qscale); |
48 static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s, | |
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
|
49 DCTELEM *block, int n, int qscale); |
3281
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
50 static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s, |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
51 DCTELEM *block, int n, int qscale); |
1689 | 52 static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s, |
325 | 53 DCTELEM *block, int n, int qscale); |
2967 | 54 static void dct_unquantize_h263_intra_c(MpegEncContext *s, |
1689 | 55 DCTELEM *block, int n, int qscale); |
2967 | 56 static void dct_unquantize_h263_inter_c(MpegEncContext *s, |
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
|
57 DCTELEM *block, int n, int qscale); |
1064 | 58 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
|
59 #ifdef CONFIG_ENCODERS |
344 | 60 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); |
945 | 61 static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); |
1777 | 62 static int dct_quantize_refine(MpegEncContext *s, DCTELEM *block, int16_t *weight, DCTELEM *orig, int n, int qscale); |
1389 | 63 static int sse_mb(MpegEncContext *s); |
1719 | 64 static void denoise_dct_c(MpegEncContext *s, DCTELEM *block); |
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
|
65 #endif //CONFIG_ENCODERS |
206 | 66 |
1381 | 67 #ifdef HAVE_XVMC |
68 extern int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx); | |
69 extern void XVMC_field_end(MpegEncContext *s); | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1579
diff
changeset
|
70 extern void XVMC_decode_mb(MpegEncContext *s); |
1381 | 71 #endif |
72 | |
1064 | 73 void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w)= draw_edges_c; |
206 | 74 |
0 | 75 |
76 /* enable all paranoid tests for rounding, overflows, etc... */ | |
77 //#define PARANOID | |
78 | |
79 //#define DEBUG | |
80 | |
321 | 81 |
0 | 82 /* for jpeg fast DCT */ |
83 #define CONST_BITS 14 | |
84 | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
85 static const uint16_t aanscales[64] = { |
0 | 86 /* precomputed values scaled up by 14 bits */ |
87 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
88 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, | |
89 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, | |
90 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, | |
91 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
92 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | |
936 | 93 8867 , 12299, 11585, 10426, 8867, 6967, 4799, 2446, |
94 4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247 | |
0 | 95 }; |
96 | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
97 static const uint8_t h263_chroma_roundtab[16] = { |
1013 | 98 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
0 | 99 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, |
100 }; | |
101 | |
1644 | 102 static const uint8_t ff_default_chroma_qscale_table[32]={ |
103 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
104 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 | |
105 }; | |
106 | |
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
|
107 #ifdef CONFIG_ENCODERS |
1162 | 108 static uint8_t (*default_mv_penalty)[MAX_MV*2+1]=NULL; |
1064 | 109 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
|
110 |
998 | 111 enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1}; |
112 | |
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
113 static void convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64], |
2385
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
114 const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra) |
0 | 115 { |
344 | 116 int qscale; |
2385
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
117 int shift=0; |
0 | 118 |
709
afeff6ccb7f5
convert only needed matrixes in convert_matrix() (mjpeg calls it for every frame)
michaelni
parents:
706
diff
changeset
|
119 for(qscale=qmin; qscale<=qmax; qscale++){ |
344 | 120 int i; |
2967 | 121 if (dsp->fdct == ff_jpeg_fdct_islow |
1562
bf452704100f
optionally merge postscale into quantization table for the float aan dct
michael
parents:
1557
diff
changeset
|
122 #ifdef FAAN_POSTSCALE |
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
123 || dsp->fdct == ff_faandct |
1562
bf452704100f
optionally merge postscale into quantization table for the float aan dct
michael
parents:
1557
diff
changeset
|
124 #endif |
bf452704100f
optionally merge postscale into quantization table for the float aan dct
michael
parents:
1557
diff
changeset
|
125 ) { |
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
|
126 for(i=0;i<64;i++) { |
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
127 const int j= 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
|
128 /* 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
|
129 /* 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
|
130 /* (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
|
131 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ |
2967 | 132 |
133 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
|
134 (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
|
135 } |
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
136 } else if (dsp->fdct == fdct_ifast |
1562
bf452704100f
optionally merge postscale into quantization table for the float aan dct
michael
parents:
1557
diff
changeset
|
137 #ifndef FAAN_POSTSCALE |
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
138 || dsp->fdct == ff_faandct |
1562
bf452704100f
optionally merge postscale into quantization table for the float aan dct
michael
parents:
1557
diff
changeset
|
139 #endif |
bf452704100f
optionally merge postscale into quantization table for the float aan dct
michael
parents:
1557
diff
changeset
|
140 ) { |
344 | 141 for(i=0;i<64;i++) { |
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
142 const int j= dsp->idct_permutation[i]; |
344 | 143 /* 16 <= qscale * quant_matrix[i] <= 7905 */ |
144 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ | |
145 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ | |
146 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ | |
2967 | 147 |
148 qmat[qscale][i] = (int)((uint64_t_C(1) << (QMAT_SHIFT + 14)) / | |
344 | 149 (aanscales[i] * qscale * quant_matrix[j])); |
150 } | |
151 } else { | |
152 for(i=0;i<64;i++) { | |
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
153 const int j= dsp->idct_permutation[i]; |
344 | 154 /* We can safely suppose that 16 <= quant_matrix[i] <= 255 |
155 So 16 <= qscale * quant_matrix[i] <= 7905 | |
156 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 | |
157 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 | |
158 */ | |
1064 | 159 qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); |
945 | 160 // qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); |
1554
d736e24bf303
move mmx quantizer matrixes out of MpegEncContext (23k -> 7k) (no meassureable slowdown)
michael
parents:
1553
diff
changeset
|
161 qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); |
d736e24bf303
move mmx quantizer matrixes out of MpegEncContext (23k -> 7k) (no meassureable slowdown)
michael
parents:
1553
diff
changeset
|
162 |
d736e24bf303
move mmx quantizer matrixes out of MpegEncContext (23k -> 7k) (no meassureable slowdown)
michael
parents:
1553
diff
changeset
|
163 if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1; |
d736e24bf303
move mmx quantizer matrixes out of MpegEncContext (23k -> 7k) (no meassureable slowdown)
michael
parents:
1553
diff
changeset
|
164 qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); |
344 | 165 } |
0 | 166 } |
2967 | 167 |
2385
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
168 for(i=intra; i<64; i++){ |
2390 | 169 int64_t max= 8191; |
170 if (dsp->fdct == fdct_ifast | |
171 #ifndef FAAN_POSTSCALE | |
172 || dsp->fdct == ff_faandct | |
173 #endif | |
174 ) { | |
175 max= (8191LL*aanscales[i]) >> 14; | |
176 } | |
2967 | 177 while(((max * qmat[qscale][i]) >> shift) > INT_MAX){ |
2385
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
178 shift++; |
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
179 } |
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
180 } |
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
181 } |
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
182 if(shift){ |
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
183 av_log(NULL, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger then %d, overflows possible\n", QMAT_SHIFT - shift); |
0 | 184 } |
185 } | |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
186 |
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
187 static inline void update_qscale(MpegEncContext *s){ |
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
188 s->qscale= (s->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); |
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
189 s->qscale= clip(s->qscale, s->avctx->qmin, s->avctx->qmax); |
2967 | 190 |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
191 s->lambda2= (s->lambda*s->lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; |
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
192 } |
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
|
193 #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
|
194 |
1273 | 195 void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){ |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
196 int i; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
197 int end; |
2967 | 198 |
764 | 199 st->scantable= src_scantable; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
200 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
201 for(i=0; i<64; i++){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
202 int j; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
203 j = src_scantable[i]; |
1273 | 204 st->permutated[i] = permutation[j]; |
828
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
205 #ifdef ARCH_POWERPC |
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
206 st->inverse[j] = i; |
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
207 #endif |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
208 } |
2967 | 209 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
210 end=-1; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
211 for(i=0; i<64; i++){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
212 int j; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
213 j = st->permutated[i]; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
214 if(j>end) end=j; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
215 st->raster_end[i]= end; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
216 } |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
217 } |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
218 |
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1523
diff
changeset
|
219 #ifdef CONFIG_ENCODERS |
1411 | 220 void ff_write_quant_matrix(PutBitContext *pb, int16_t *matrix){ |
221 int i; | |
222 | |
223 if(matrix){ | |
224 put_bits(pb, 1, 1); | |
225 for(i=0;i<64;i++) { | |
226 put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]); | |
227 } | |
228 }else | |
229 put_bits(pb, 1, 0); | |
230 } | |
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1523
diff
changeset
|
231 #endif //CONFIG_ENCODERS |
1411 | 232 |
3086 | 233 const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){ |
234 int i; | |
235 | |
3092 | 236 assert(p<=end); |
237 if(p>=end) | |
238 return end; | |
239 | |
3086 | 240 for(i=0; i<3; i++){ |
241 uint32_t tmp= *state << 8; | |
242 *state= tmp + *(p++); | |
243 if(tmp == 0x100 || p==end) | |
244 return p; | |
245 } | |
246 | |
247 while(p<end){ | |
3087 | 248 if (p[-1] > 1 ) p+= 3; |
249 else if(p[-2] ) p+= 2; | |
250 else if(p[-3]|(p[-1]-1)) p++; | |
3086 | 251 else{ |
252 p++; | |
253 break; | |
254 } | |
255 } | |
256 | |
3087 | 257 p= FFMIN(p, end)-4; |
3086 | 258 *state= be2me_32(unaligned32(p)); |
259 | |
260 return p+4; | |
261 } | |
262 | |
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
|
263 /* 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
|
264 int DCT_common_init(MpegEncContext *s) |
0 | 265 { |
1689 | 266 s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c; |
267 s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c; | |
268 s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c; | |
269 s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c; | |
270 s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c; | |
3281
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
271 if(s->flags & CODEC_FLAG_BITEXACT) |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
272 s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact; |
1689 | 273 s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c; |
1092 | 274 |
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
|
275 #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
|
276 s->dct_quantize= dct_quantize_c; |
1719 | 277 s->denoise_dct= denoise_dct_c; |
2616
ba6530ae8e34
remove superfluous CONFIG_ENCODERS (entire function is already wrapped)
melanson
parents:
2584
diff
changeset
|
278 #endif //CONFIG_ENCODERS |
2967 | 279 |
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
|
280 #ifdef HAVE_MMX |
1422
efeed6e29f9b
oooooops, having 2 Eterms open and doing cvs diff in one and cvs commit in the other sucks, especially if they are in different directories (MPlayer/main/libavcodec vs. ffmpeg/libavcodec)
michaelni
parents:
1421
diff
changeset
|
281 MPV_common_init_mmx(s); |
8 | 282 #endif |
514
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M«©ns Rullg«©rd
mellum
parents:
506
diff
changeset
|
283 #ifdef ARCH_ALPHA |
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M«©ns Rullg«©rd
mellum
parents:
506
diff
changeset
|
284 MPV_common_init_axp(s); |
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M«©ns Rullg«©rd
mellum
parents:
506
diff
changeset
|
285 #endif |
628
f596db4aa871
sun solaris compilation bugfix, patch by (Martin Olschewski <olschewski at zpr dot uni-koeln dot de>)
michaelni
parents:
625
diff
changeset
|
286 #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
|
287 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
|
288 #endif |
721
71f669e9f633
ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
michaelni
parents:
717
diff
changeset
|
289 #ifdef HAVE_MMI |
71f669e9f633
ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
michaelni
parents:
717
diff
changeset
|
290 MPV_common_init_mmi(s); |
71f669e9f633
ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
michaelni
parents:
717
diff
changeset
|
291 #endif |
730 | 292 #ifdef ARCH_ARMV4L |
874 | 293 MPV_common_init_armv4l(s); |
730 | 294 #endif |
828
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
295 #ifdef ARCH_POWERPC |
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
296 MPV_common_init_ppc(s); |
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
297 #endif |
730 | 298 |
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
|
299 #ifdef CONFIG_ENCODERS |
1007 | 300 s->fast_dct_quantize= s->dct_quantize; |
301 | |
945 | 302 if(s->flags&CODEC_FLAG_TRELLIS_QUANT){ |
303 s->dct_quantize= dct_quantize_trellis_c; //move before MPV_common_init_* | |
304 } | |
305 | |
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
|
306 #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
|
307 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
308 /* load & permutate scantables |
2967 | 309 note: only wmv uses different ones |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
310 */ |
1708 | 311 if(s->alternate_scan){ |
312 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan); | |
313 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan); | |
314 }else{ | |
315 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct); | |
316 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct); | |
317 } | |
1273 | 318 ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan); |
319 ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan); | |
591 | 320 |
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
|
321 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
|
322 } |
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
323 |
1539
14d01ccc0081
picture buffer cleanup, this fixes a assertion failure (if assertion checking was manualy enabled for utils.c) and a memleak at least
michael
parents:
1530
diff
changeset
|
324 static void copy_picture(Picture *dst, Picture *src){ |
14d01ccc0081
picture buffer cleanup, this fixes a assertion failure (if assertion checking was manualy enabled for utils.c) and a memleak at least
michael
parents:
1530
diff
changeset
|
325 *dst = *src; |
14d01ccc0081
picture buffer cleanup, this fixes a assertion failure (if assertion checking was manualy enabled for utils.c) and a memleak at least
michael
parents:
1530
diff
changeset
|
326 dst->type= FF_BUFFER_TYPE_COPY; |
14d01ccc0081
picture buffer cleanup, this fixes a assertion failure (if assertion checking was manualy enabled for utils.c) and a memleak at least
michael
parents:
1530
diff
changeset
|
327 } |
14d01ccc0081
picture buffer cleanup, this fixes a assertion failure (if assertion checking was manualy enabled for utils.c) and a memleak at least
michael
parents:
1530
diff
changeset
|
328 |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
329 static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){ |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
330 int i; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
331 |
1702 | 332 dst->pict_type = src->pict_type; |
333 dst->quality = src->quality; | |
334 dst->coded_picture_number = src->coded_picture_number; | |
335 dst->display_picture_number = src->display_picture_number; | |
336 // dst->reference = src->reference; | |
337 dst->pts = src->pts; | |
338 dst->interlaced_frame = src->interlaced_frame; | |
339 dst->top_field_first = src->top_field_first; | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
340 |
1945
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
341 if(s->avctx->me_threshold){ |
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
342 if(!src->motion_val[0]) |
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
343 av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_val not set!\n"); |
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
344 if(!src->mb_type) |
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
345 av_log(s->avctx, AV_LOG_ERROR, "AVFrame.mb_type not set!\n"); |
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
346 if(!src->ref_index[0]) |
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
347 av_log(s->avctx, AV_LOG_ERROR, "AVFrame.ref_index not set!\n"); |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
348 if(src->motion_subsample_log2 != dst->motion_subsample_log2) |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
349 av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n", |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1948
diff
changeset
|
350 src->motion_subsample_log2, dst->motion_subsample_log2); |
1945
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
351 |
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
352 memcpy(dst->mb_type, src->mb_type, s->mb_stride * s->mb_height * sizeof(dst->mb_type[0])); |
2967 | 353 |
1945
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
354 for(i=0; i<2; i++){ |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
355 int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
356 int height= ((16*s->mb_height)>>src->motion_subsample_log2); |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
357 |
1945
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
358 if(src->motion_val[i] && src->motion_val[i] != dst->motion_val[i]){ |
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
359 memcpy(dst->motion_val[i], src->motion_val[i], 2*stride*height*sizeof(int16_t)); |
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
360 } |
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
361 if(src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]){ |
1948 | 362 memcpy(dst->ref_index[i], src->ref_index[i], s->b8_stride*2*s->mb_height*sizeof(int8_t)); |
1945
32f68745c431
passing AVFrame instead of AVPicture around in ffmpeg, that way stuff like motion vectors can be passed from the decoder to the encoder
michael
parents:
1944
diff
changeset
|
363 } |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
364 } |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
365 } |
1702 | 366 } |
367 | |
903 | 368 /** |
924 | 369 * allocates a Picture |
370 * The pixels are allocated/set by calling get_buffer() if shared=0 | |
903 | 371 */ |
924 | 372 static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
373 const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) doesnt sig11 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
374 const int mb_array_size= s->mb_stride*s->mb_height; |
1655 | 375 const int b8_array_size= s->b8_stride*s->mb_height*2; |
376 const int b4_array_size= s->b4_stride*s->mb_height*4; | |
1168 | 377 int i; |
2967 | 378 |
924 | 379 if(shared){ |
380 assert(pic->data[0]); | |
381 assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED); | |
382 pic->type= FF_BUFFER_TYPE_SHARED; | |
383 }else{ | |
384 int r; | |
2967 | 385 |
924 | 386 assert(!pic->data[0]); |
2967 | 387 |
925 | 388 r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic); |
2967 | 389 |
924 | 390 if(r<0 || !pic->age || !pic->type || !pic->data[0]){ |
2979 | 391 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]); |
924 | 392 return -1; |
393 } | |
394 | |
395 if(s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
396 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n"); |
924 | 397 return -1; |
398 } | |
399 | |
400 if(pic->linesize[1] != pic->linesize[2]){ | |
2764 | 401 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n"); |
924 | 402 return -1; |
403 } | |
404 | |
405 s->linesize = pic->linesize[0]; | |
406 s->uvlinesize= pic->linesize[1]; | |
903 | 407 } |
2967 | 408 |
924 | 409 if(pic->qscale_table==NULL){ |
2967 | 410 if (s->encoding) { |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
411 CHECKED_ALLOCZ(pic->mb_var , mb_array_size * sizeof(int16_t)) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
412 CHECKED_ALLOCZ(pic->mc_mb_var, mb_array_size * sizeof(int16_t)) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
413 CHECKED_ALLOCZ(pic->mb_mean , mb_array_size * sizeof(int8_t)) |
924 | 414 } |
415 | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
416 CHECKED_ALLOCZ(pic->mbskip_table , mb_array_size * sizeof(uint8_t)+2) //the +2 is for the slice end check |
1422
efeed6e29f9b
oooooops, having 2 Eterms open and doing cvs diff in one and cvs commit in the other sucks, especially if they are in different directories (MPlayer/main/libavcodec vs. ffmpeg/libavcodec)
michaelni
parents:
1421
diff
changeset
|
417 CHECKED_ALLOCZ(pic->qscale_table , mb_array_size * sizeof(uint8_t)) |
1742 | 418 CHECKED_ALLOCZ(pic->mb_type_base , big_mb_num * sizeof(uint32_t)) |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
419 pic->mb_type= pic->mb_type_base + s->mb_stride+1; |
1168 | 420 if(s->out_format == FMT_H264){ |
421 for(i=0; i<2; i++){ | |
2570 | 422 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b4_array_size+4) * sizeof(int16_t)) |
423 pic->motion_val[i]= pic->motion_val_base[i]+4; | |
1948 | 424 CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t)) |
1655 | 425 } |
1669 | 426 pic->motion_subsample_log2= 2; |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
427 }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){ |
1655 | 428 for(i=0; i<2; i++){ |
2570 | 429 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+4) * sizeof(int16_t)) |
430 pic->motion_val[i]= pic->motion_val_base[i]+4; | |
1948 | 431 CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t)) |
1168 | 432 } |
1669 | 433 pic->motion_subsample_log2= 3; |
1168 | 434 } |
1833
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
435 if(s->avctx->debug&FF_DEBUG_DCT_COEFF) { |
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
436 CHECKED_ALLOCZ(pic->dct_coeff, 64 * mb_array_size * sizeof(DCTELEM)*6) |
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
437 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
438 pic->qstride= s->mb_stride; |
1546 | 439 CHECKED_ALLOCZ(pic->pan_scan , 1 * sizeof(AVPanScan)) |
924 | 440 } |
1168 | 441 |
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
442 //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
|
443 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
|
444 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
|
445 if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == B_TYPE) |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2627
diff
changeset
|
446 pic->age= INT_MAX; // skipped MBs in b frames are quite rare in mpeg1/2 and its a bit tricky to skip them anyway |
2967 | 447 |
903 | 448 return 0; |
449 fail: //for the CHECKED_ALLOCZ macro | |
450 return -1; | |
451 } | |
452 | |
924 | 453 /** |
454 * deallocates a picture | |
455 */ | |
903 | 456 static void free_picture(MpegEncContext *s, Picture *pic){ |
457 int i; | |
924 | 458 |
459 if(pic->data[0] && pic->type!=FF_BUFFER_TYPE_SHARED){ | |
925 | 460 s->avctx->release_buffer(s->avctx, (AVFrame*)pic); |
924 | 461 } |
462 | |
903 | 463 av_freep(&pic->mb_var); |
464 av_freep(&pic->mc_mb_var); | |
465 av_freep(&pic->mb_mean); | |
466 av_freep(&pic->mbskip_table); | |
467 av_freep(&pic->qscale_table); | |
1168 | 468 av_freep(&pic->mb_type_base); |
1833
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
469 av_freep(&pic->dct_coeff); |
1546 | 470 av_freep(&pic->pan_scan); |
1168 | 471 pic->mb_type= NULL; |
472 for(i=0; i<2; i++){ | |
1655 | 473 av_freep(&pic->motion_val_base[i]); |
1168 | 474 av_freep(&pic->ref_index[i]); |
475 } | |
2967 | 476 |
1214 | 477 if(pic->type == FF_BUFFER_TYPE_SHARED){ |
924 | 478 for(i=0; i<4; i++){ |
479 pic->base[i]= | |
480 pic->data[i]= NULL; | |
481 } | |
2967 | 482 pic->type= 0; |
903 | 483 } |
484 } | |
485 | |
1799 | 486 static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){ |
487 int i; | |
488 | |
2967 | 489 // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264) |
1799 | 490 CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, (s->width+64)*2*17*2); //(width + edge + align)*interlaced*MBsize*tolerance |
491 s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*17; | |
492 | |
493 //FIXME should be linesize instead of s->width*2 but that isnt known before get_buffer() | |
2967 | 494 CHECKED_ALLOCZ(s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t)) |
1799 | 495 s->rd_scratchpad= s->me.scratchpad; |
496 s->b_scratchpad= s->me.scratchpad; | |
497 s->obmc_scratchpad= s->me.scratchpad + 16; | |
498 if (s->encoding) { | |
499 CHECKED_ALLOCZ(s->me.map , ME_MAP_SIZE*sizeof(uint32_t)) | |
500 CHECKED_ALLOCZ(s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t)) | |
501 if(s->avctx->noise_reduction){ | |
502 CHECKED_ALLOCZ(s->dct_error_sum, 2 * 64 * sizeof(int)) | |
503 } | |
2967 | 504 } |
1848
c72589baee53
initial chroma_format changes,xvmc tweaks and codec_cap
iive
parents:
1846
diff
changeset
|
505 CHECKED_ALLOCZ(s->blocks, 64*12*2 * sizeof(DCTELEM)) |
1799 | 506 s->block= s->blocks[0]; |
507 | |
508 for(i=0;i<12;i++){ | |
509 s->pblocks[i] = (short *)(&s->block[i]); | |
510 } | |
511 return 0; | |
512 fail: | |
513 return -1; //free() through MPV_common_end() | |
514 } | |
515 | |
516 static void free_duplicate_context(MpegEncContext *s){ | |
517 if(s==NULL) return; | |
518 | |
519 av_freep(&s->allocated_edge_emu_buffer); s->edge_emu_buffer= NULL; | |
520 av_freep(&s->me.scratchpad); | |
2967 | 521 s->rd_scratchpad= |
522 s->b_scratchpad= | |
1799 | 523 s->obmc_scratchpad= NULL; |
2967 | 524 |
1799 | 525 av_freep(&s->dct_error_sum); |
526 av_freep(&s->me.map); | |
527 av_freep(&s->me.score_map); | |
528 av_freep(&s->blocks); | |
529 s->block= NULL; | |
530 } | |
531 | |
532 static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src){ | |
533 #define COPY(a) bak->a= src->a | |
534 COPY(allocated_edge_emu_buffer); | |
535 COPY(edge_emu_buffer); | |
536 COPY(me.scratchpad); | |
537 COPY(rd_scratchpad); | |
538 COPY(b_scratchpad); | |
539 COPY(obmc_scratchpad); | |
540 COPY(me.map); | |
541 COPY(me.score_map); | |
542 COPY(blocks); | |
543 COPY(block); | |
544 COPY(start_mb_y); | |
545 COPY(end_mb_y); | |
546 COPY(me.map_generation); | |
547 COPY(pb); | |
548 COPY(dct_error_sum); | |
1810 | 549 COPY(dct_count[0]); |
550 COPY(dct_count[1]); | |
1799 | 551 #undef COPY |
552 } | |
553 | |
1827 | 554 void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src){ |
1799 | 555 MpegEncContext bak; |
1827 | 556 int i; |
1799 | 557 //FIXME copy only needed parts |
558 //START_TIMER | |
559 backup_duplicate_context(&bak, dst); | |
560 memcpy(dst, src, sizeof(MpegEncContext)); | |
561 backup_duplicate_context(dst, &bak); | |
1827 | 562 for(i=0;i<12;i++){ |
563 dst->pblocks[i] = (short *)(&dst->block[i]); | |
564 } | |
1799 | 565 //STOP_TIMER("update_duplicate_context") //about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads |
566 } | |
567 | |
568 static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src){ | |
569 #define COPY(a) dst->a= src->a | |
570 COPY(pict_type); | |
571 COPY(current_picture); | |
572 COPY(f_code); | |
573 COPY(b_code); | |
574 COPY(qscale); | |
575 COPY(lambda); | |
576 COPY(lambda2); | |
577 COPY(picture_in_gop_number); | |
578 COPY(gop_picture_number); | |
2764 | 579 COPY(frame_pred_frame_dct); //FIXME don't set in encode_header |
580 COPY(progressive_frame); //FIXME don't set in encode_header | |
581 COPY(partitioned_frame); //FIXME don't set in encode_header | |
1799 | 582 #undef COPY |
583 } | |
584 | |
1892 | 585 /** |
586 * sets the given MpegEncContext to common defaults (same for encoding and decoding). | |
587 * the changed fields will not depend upon the prior state of the MpegEncContext. | |
588 */ | |
589 static void MPV_common_defaults(MpegEncContext *s){ | |
590 s->y_dc_scale_table= | |
591 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
592 s->chroma_qscale_table= ff_default_chroma_qscale_table; | |
593 s->progressive_frame= 1; | |
594 s->progressive_sequence= 1; | |
595 s->picture_structure= PICT_FRAME; | |
596 | |
597 s->coded_picture_number = 0; | |
598 s->picture_number = 0; | |
599 s->input_picture_number = 0; | |
600 | |
601 s->picture_in_gop_number = 0; | |
1894 | 602 |
603 s->f_code = 1; | |
604 s->b_code = 1; | |
1892 | 605 } |
606 | |
607 /** | |
608 * sets the given MpegEncContext to defaults for decoding. | |
609 * the changed fields will not depend upon the prior state of the MpegEncContext. | |
610 */ | |
611 void MPV_decode_defaults(MpegEncContext *s){ | |
612 MPV_common_defaults(s); | |
613 } | |
614 | |
615 /** | |
616 * sets the given MpegEncContext to defaults for encoding. | |
617 * the changed fields will not depend upon the prior state of the MpegEncContext. | |
618 */ | |
1902
a5588762c4fa
Compile fix by (Chip <szarlada at freemail dot hu>)
michael
parents:
1894
diff
changeset
|
619 |
a5588762c4fa
Compile fix by (Chip <szarlada at freemail dot hu>)
michael
parents:
1894
diff
changeset
|
620 #ifdef CONFIG_ENCODERS |
2024
f65d87bfdd5a
some of the warning fixes by (Michael Roitzsch <mroi at users dot sourceforge dot net>)
michael
parents:
2015
diff
changeset
|
621 static void MPV_encode_defaults(MpegEncContext *s){ |
1892 | 622 static int done=0; |
2967 | 623 |
1892 | 624 MPV_common_defaults(s); |
2967 | 625 |
1892 | 626 if(!done){ |
627 int i; | |
628 done=1; | |
629 | |
630 default_mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) ); | |
631 memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1)); | |
632 | |
633 for(i=-16; i<16; i++){ | |
634 default_fcode_tab[i + MAX_MV]= 1; | |
635 } | |
636 } | |
637 s->me.mv_penalty= default_mv_penalty; | |
638 s->fcode_tab= default_fcode_tab; | |
639 } | |
1902
a5588762c4fa
Compile fix by (Chip <szarlada at freemail dot hu>)
michael
parents:
1894
diff
changeset
|
640 #endif //CONFIG_ENCODERS |
1892 | 641 |
2967 | 642 /** |
1892 | 643 * init common structure for both encoder and decoder. |
644 * this assumes that some variables like width/height are already set | |
645 */ | |
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
|
646 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
|
647 { |
1708 | 648 int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y; |
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
|
649 |
3070 | 650 s->mb_height = (s->height + 15) / 16; |
651 | |
652 if(s->avctx->thread_count > MAX_THREADS || (s->avctx->thread_count > s->mb_height && s->mb_height)){ | |
1989 | 653 av_log(s->avctx, AV_LOG_ERROR, "too many threads\n"); |
654 return -1; | |
655 } | |
656 | |
2422 | 657 if((s->width || s->height) && avcodec_check_dimensions(s->avctx, s->width, s->height)) |
658 return -1; | |
659 | |
1092 | 660 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
|
661 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
|
662 |
754 | 663 s->flags= s->avctx->flags; |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
664 s->flags2= s->avctx->flags2; |
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
|
665 |
903 | 666 s->mb_width = (s->width + 15) / 16; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
667 s->mb_stride = s->mb_width + 1; |
1655 | 668 s->b8_stride = s->mb_width*2 + 1; |
669 s->b4_stride = s->mb_width*4 + 1; | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
670 mb_array_size= s->mb_height * s->mb_stride; |
1708 | 671 mv_table_size= (s->mb_height+2) * s->mb_stride + 1; |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
672 |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
673 /* set chroma shifts */ |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
674 avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift), |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
675 &(s->chroma_y_shift) ); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
676 |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
677 /* 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
|
678 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
|
679 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
|
680 |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
681 s->mb_num = s->mb_width * s->mb_height; |
2967 | 682 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
683 s->block_wrap[0]= |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
684 s->block_wrap[1]= |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
685 s->block_wrap[2]= |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
686 s->block_wrap[3]= s->b8_stride; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
687 s->block_wrap[4]= |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
688 s->block_wrap[5]= s->mb_stride; |
2967 | 689 |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
690 y_size = s->b8_stride * (2 * s->mb_height + 1); |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
691 c_size = s->mb_stride * (s->mb_height + 1); |
756 | 692 yc_size = y_size + 2 * c_size; |
2967 | 693 |
701 | 694 /* convert fourcc to upper case */ |
2967 | 695 s->avctx->codec_tag= toupper( s->avctx->codec_tag &0xFF) |
1116 | 696 + (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 ) |
2967 | 697 + (toupper((s->avctx->codec_tag>>16)&0xFF)<<16) |
1116 | 698 + (toupper((s->avctx->codec_tag>>24)&0xFF)<<24); |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
699 |
2967 | 700 s->avctx->stream_codec_tag= toupper( s->avctx->stream_codec_tag &0xFF) |
1458
40b69d238beb
AVI stream header FCC / more reliable detection of old xvid files
michaelni
parents:
1451
diff
changeset
|
701 + (toupper((s->avctx->stream_codec_tag>>8 )&0xFF)<<8 ) |
2967 | 702 + (toupper((s->avctx->stream_codec_tag>>16)&0xFF)<<16) |
1458
40b69d238beb
AVI stream header FCC / more reliable detection of old xvid files
michaelni
parents:
1451
diff
changeset
|
703 + (toupper((s->avctx->stream_codec_tag>>24)&0xFF)<<24); |
40b69d238beb
AVI stream header FCC / more reliable detection of old xvid files
michaelni
parents:
1451
diff
changeset
|
704 |
925 | 705 s->avctx->coded_frame= (AVFrame*)&s->current_picture; |
903 | 706 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
707 CHECKED_ALLOCZ(s->mb_index2xy, (s->mb_num+1)*sizeof(int)) //error ressilience code looks cleaner with this |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
708 for(y=0; y<s->mb_height; y++){ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
709 for(x=0; x<s->mb_width; x++){ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
710 s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
711 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
712 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
713 s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width; //FIXME really needed? |
2967 | 714 |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
715 if (s->encoding) { |
324 | 716 /* Allocate MV tables */ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
717 CHECKED_ALLOCZ(s->p_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
718 CHECKED_ALLOCZ(s->b_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
719 CHECKED_ALLOCZ(s->b_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
720 CHECKED_ALLOCZ(s->b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
721 CHECKED_ALLOCZ(s->b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
722 CHECKED_ALLOCZ(s->b_direct_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
723 s->p_mv_table = s->p_mv_table_base + s->mb_stride + 1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
724 s->b_forw_mv_table = s->b_forw_mv_table_base + s->mb_stride + 1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
725 s->b_back_mv_table = s->b_back_mv_table_base + s->mb_stride + 1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
726 s->b_bidir_forw_mv_table= s->b_bidir_forw_mv_table_base + s->mb_stride + 1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
727 s->b_bidir_back_mv_table= s->b_bidir_back_mv_table_base + s->mb_stride + 1; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
728 s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1; |
324 | 729 |
650
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
730 if(s->msmpeg4_version){ |
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
731 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
|
732 } |
612 | 733 CHECKED_ALLOCZ(s->avctx->stats_out, 256); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
734 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
735 /* Allocate MB type table */ |
1708 | 736 CHECKED_ALLOCZ(s->mb_type , mb_array_size * sizeof(uint16_t)) //needed for encoding |
2967 | 737 |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
738 CHECKED_ALLOCZ(s->lambda_table, mb_array_size * sizeof(int)) |
2967 | 739 |
1553
541681146f83
move q_*_matrix out of MpegEncContext (40k ->23k) dct_quantize() is even slightly faster now, dont ask my why ...
michael
parents:
1552
diff
changeset
|
740 CHECKED_ALLOCZ(s->q_intra_matrix, 64*32 * sizeof(int)) |
541681146f83
move q_*_matrix out of MpegEncContext (40k ->23k) dct_quantize() is even slightly faster now, dont ask my why ...
michael
parents:
1552
diff
changeset
|
741 CHECKED_ALLOCZ(s->q_inter_matrix, 64*32 * sizeof(int)) |
1554
d736e24bf303
move mmx quantizer matrixes out of MpegEncContext (23k -> 7k) (no meassureable slowdown)
michael
parents:
1553
diff
changeset
|
742 CHECKED_ALLOCZ(s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t)) |
d736e24bf303
move mmx quantizer matrixes out of MpegEncContext (23k -> 7k) (no meassureable slowdown)
michael
parents:
1553
diff
changeset
|
743 CHECKED_ALLOCZ(s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t)) |
1556 | 744 CHECKED_ALLOCZ(s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*)) |
745 CHECKED_ALLOCZ(s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*)) | |
2967 | 746 |
1597 | 747 if(s->avctx->noise_reduction){ |
748 CHECKED_ALLOCZ(s->dct_offset, 2 * 64 * sizeof(uint16_t)) | |
749 } | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
750 } |
1552
26c6ecba99a1
dynamic alloc of picture structs instead of putting them in MpegEncContext
michael
parents:
1546
diff
changeset
|
751 CHECKED_ALLOCZ(s->picture, MAX_PICTURE_COUNT * sizeof(Picture)) |
26c6ecba99a1
dynamic alloc of picture structs instead of putting them in MpegEncContext
michael
parents:
1546
diff
changeset
|
752 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
753 CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t)) |
2967 | 754 |
1708 | 755 if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
756 /* interlaced direct mode decoding tables */ |
1708 | 757 for(i=0; i<2; i++){ |
758 int j, k; | |
759 for(j=0; j<2; j++){ | |
760 for(k=0; k<2; k++){ | |
761 CHECKED_ALLOCZ(s->b_field_mv_table_base[i][j][k] , mv_table_size * 2 * sizeof(int16_t)) | |
762 s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] + s->mb_stride + 1; | |
763 } | |
764 CHECKED_ALLOCZ(s->b_field_select_table[i][j] , mb_array_size * 2 * sizeof(uint8_t)) | |
765 CHECKED_ALLOCZ(s->p_field_mv_table_base[i][j] , mv_table_size * 2 * sizeof(int16_t)) | |
766 s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j] + s->mb_stride + 1; | |
767 } | |
768 CHECKED_ALLOCZ(s->p_field_select_table[i] , mb_array_size * 2 * sizeof(uint8_t)) | |
769 } | |
0 | 770 } |
767 | 771 if (s->out_format == FMT_H263) { |
0 | 772 /* ac values */ |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
773 CHECKED_ALLOCZ(s->ac_val_base, yc_size * sizeof(int16_t) * 16); |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
774 s->ac_val[0] = s->ac_val_base + s->b8_stride + 1; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
775 s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1; |
0 | 776 s->ac_val[2] = s->ac_val[1] + c_size; |
2967 | 777 |
0 | 778 /* cbp values */ |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
779 CHECKED_ALLOCZ(s->coded_block_base, y_size); |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
780 s->coded_block= s->coded_block_base + s->b8_stride + 1; |
2967 | 781 |
456 | 782 /* cbp, ac_pred, pred_dir */ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
783 CHECKED_ALLOCZ(s->cbp_table , mb_array_size * sizeof(uint8_t)) |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
784 CHECKED_ALLOCZ(s->pred_dir_table, mb_array_size * 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
|
785 } |
2967 | 786 |
756 | 787 if (s->h263_pred || s->h263_plus || !s->encoding) { |
788 /* dc values */ | |
789 //MN: we need these for error resilience of intra-frames | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
790 CHECKED_ALLOCZ(s->dc_val_base, yc_size * sizeof(int16_t)); |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
791 s->dc_val[0] = s->dc_val_base + s->b8_stride + 1; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
792 s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1; |
756 | 793 s->dc_val[2] = s->dc_val[1] + c_size; |
794 for(i=0;i<yc_size;i++) | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
795 s->dc_val_base[i] = 1024; |
756 | 796 } |
797 | |
611
3214d3f4519e
error concealment needs the mbintra_table so it should allways be allocated
michaelni
parents:
608
diff
changeset
|
798 /* which mb is a intra block */ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
799 CHECKED_ALLOCZ(s->mbintra_table, mb_array_size); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
800 memset(s->mbintra_table, 1, mb_array_size); |
2967 | 801 |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
802 /* init macroblock skip table */ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
803 CHECKED_ALLOCZ(s->mbskip_table, mb_array_size+2); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
804 //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
|
805 CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE); |
2967 | 806 |
842
e460775adb38
cleanup (breaks compatibility, requested by fabrice)
michaelni
parents:
828
diff
changeset
|
807 s->parse_context.state= -1; |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
808 if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
809 s->visualization_buffer[0] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
810 s->visualization_buffer[1] = av_malloc((s->mb_width*8 + EDGE_WIDTH) * s->mb_height*8 + EDGE_WIDTH); |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
811 s->visualization_buffer[2] = av_malloc((s->mb_width*8 + EDGE_WIDTH) * s->mb_height*8 + EDGE_WIDTH); |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
812 } |
842
e460775adb38
cleanup (breaks compatibility, requested by fabrice)
michaelni
parents:
828
diff
changeset
|
813 |
0 | 814 s->context_initialized = 1; |
1799 | 815 |
816 s->thread_context[0]= s; | |
817 for(i=1; i<s->avctx->thread_count; i++){ | |
818 s->thread_context[i]= av_malloc(sizeof(MpegEncContext)); | |
819 memcpy(s->thread_context[i], s, sizeof(MpegEncContext)); | |
820 } | |
821 | |
822 for(i=0; i<s->avctx->thread_count; i++){ | |
823 if(init_duplicate_context(s->thread_context[i], s) < 0) | |
824 goto fail; | |
825 s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count; | |
826 s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count/2) / s->avctx->thread_count; | |
827 } | |
828 | |
0 | 829 return 0; |
830 fail: | |
244 | 831 MPV_common_end(s); |
832 return -1; | |
833 } | |
834 | |
835 /* init common structure for both encoder and decoder */ | |
836 void MPV_common_end(MpegEncContext *s) | |
837 { | |
1708 | 838 int i, j, k; |
244 | 839 |
1799 | 840 for(i=0; i<s->avctx->thread_count; i++){ |
841 free_duplicate_context(s->thread_context[i]); | |
842 } | |
843 for(i=1; i<s->avctx->thread_count; i++){ | |
844 av_freep(&s->thread_context[i]); | |
845 } | |
846 | |
1344
447b88b784ee
memleak fix by (Jake Page <jake at CS dot Stanford dot EDU>)
michaelni
parents:
1339
diff
changeset
|
847 av_freep(&s->parse_context.buffer); |
447b88b784ee
memleak fix by (Jake Page <jake at CS dot Stanford dot EDU>)
michaelni
parents:
1339
diff
changeset
|
848 s->parse_context.buffer_size=0; |
447b88b784ee
memleak fix by (Jake Page <jake at CS dot Stanford dot EDU>)
michaelni
parents:
1339
diff
changeset
|
849 |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
850 av_freep(&s->mb_type); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
851 av_freep(&s->p_mv_table_base); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
852 av_freep(&s->b_forw_mv_table_base); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
853 av_freep(&s->b_back_mv_table_base); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
854 av_freep(&s->b_bidir_forw_mv_table_base); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
855 av_freep(&s->b_bidir_back_mv_table_base); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
856 av_freep(&s->b_direct_mv_table_base); |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
857 s->p_mv_table= NULL; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
858 s->b_forw_mv_table= NULL; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
859 s->b_back_mv_table= NULL; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
860 s->b_bidir_forw_mv_table= NULL; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
861 s->b_bidir_back_mv_table= NULL; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
862 s->b_direct_mv_table= NULL; |
1708 | 863 for(i=0; i<2; i++){ |
864 for(j=0; j<2; j++){ | |
865 for(k=0; k<2; k++){ | |
866 av_freep(&s->b_field_mv_table_base[i][j][k]); | |
867 s->b_field_mv_table[i][j][k]=NULL; | |
868 } | |
869 av_freep(&s->b_field_select_table[i][j]); | |
870 av_freep(&s->p_field_mv_table_base[i][j]); | |
871 s->p_field_mv_table[i][j]=NULL; | |
872 } | |
873 av_freep(&s->p_field_select_table[i]); | |
874 } | |
2967 | 875 |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
876 av_freep(&s->dc_val_base); |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
877 av_freep(&s->ac_val_base); |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
878 av_freep(&s->coded_block_base); |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
879 av_freep(&s->mbintra_table); |
456 | 880 av_freep(&s->cbp_table); |
881 av_freep(&s->pred_dir_table); | |
2967 | 882 |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
883 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
|
884 av_freep(&s->prev_pict_types); |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
885 av_freep(&s->bitstream_buffer); |
2422 | 886 s->allocated_bitstream_buffer_size=0; |
887 | |
612 | 888 av_freep(&s->avctx->stats_out); |
650
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
889 av_freep(&s->ac_stats); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
890 av_freep(&s->error_status_table); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
891 av_freep(&s->mb_index2xy); |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
892 av_freep(&s->lambda_table); |
1553
541681146f83
move q_*_matrix out of MpegEncContext (40k ->23k) dct_quantize() is even slightly faster now, dont ask my why ...
michael
parents:
1552
diff
changeset
|
893 av_freep(&s->q_intra_matrix); |
541681146f83
move q_*_matrix out of MpegEncContext (40k ->23k) dct_quantize() is even slightly faster now, dont ask my why ...
michael
parents:
1552
diff
changeset
|
894 av_freep(&s->q_inter_matrix); |
1554
d736e24bf303
move mmx quantizer matrixes out of MpegEncContext (23k -> 7k) (no meassureable slowdown)
michael
parents:
1553
diff
changeset
|
895 av_freep(&s->q_intra_matrix16); |
d736e24bf303
move mmx quantizer matrixes out of MpegEncContext (23k -> 7k) (no meassureable slowdown)
michael
parents:
1553
diff
changeset
|
896 av_freep(&s->q_inter_matrix16); |
1556 | 897 av_freep(&s->input_picture); |
898 av_freep(&s->reordered_input_picture); | |
1597 | 899 av_freep(&s->dct_offset); |
903 | 900 |
1573 | 901 if(s->picture){ |
902 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
903 free_picture(s, &s->picture[i]); | |
904 } | |
0 | 905 } |
1552
26c6ecba99a1
dynamic alloc of picture structs instead of putting them in MpegEncContext
michael
parents:
1546
diff
changeset
|
906 av_freep(&s->picture); |
0 | 907 s->context_initialized = 0; |
1523 | 908 s->last_picture_ptr= |
909 s->next_picture_ptr= | |
910 s->current_picture_ptr= NULL; | |
2231 | 911 s->linesize= s->uvlinesize= 0; |
1918
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
912 |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
913 for(i=0; i<3; i++) |
1918
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
914 av_freep(&s->visualization_buffer[i]); |
2231 | 915 |
916 avcodec_default_free_buffers(s->avctx); | |
0 | 917 } |
918 | |
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
|
919 #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
|
920 |
0 | 921 /* init video encoder */ |
922 int MPV_encode_init(AVCodecContext *avctx) | |
923 { | |
924 MpegEncContext *s = avctx->priv_data; | |
2834 | 925 int i; |
1315
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
926 int chroma_h_shift, chroma_v_shift; |
2967 | 927 |
1892 | 928 MPV_encode_defaults(s); |
315 | 929 |
2442 | 930 if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUV420P){ |
931 av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n"); | |
932 return -1; | |
933 } | |
934 | |
935 if(avctx->codec_id == CODEC_ID_MJPEG || avctx->codec_id == CODEC_ID_LJPEG){ | |
2658
d1609cfeb1d0
#defines for strict_std_compliance and split between inofficial extensions and non standarized things
michael
parents:
2654
diff
changeset
|
936 if(avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL && avctx->pix_fmt != PIX_FMT_YUVJ420P){ |
2442 | 937 av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n"); |
938 return -1; | |
939 } | |
940 }else{ | |
2658
d1609cfeb1d0
#defines for strict_std_compliance and split between inofficial extensions and non standarized things
michael
parents:
2654
diff
changeset
|
941 if(avctx->strict_std_compliance>FF_COMPLIANCE_INOFFICIAL && avctx->pix_fmt != PIX_FMT_YUV420P){ |
2442 | 942 av_log(avctx, AV_LOG_ERROR, "colorspace not supported\n"); |
943 return -1; | |
944 } | |
945 } | |
1402
f662e9c86cf2
* fixing a regression in mpeg encoder (not setting pix_fmt),
romansh
parents:
1397
diff
changeset
|
946 |
0 | 947 s->bit_rate = avctx->bit_rate; |
948 s->width = avctx->width; | |
949 s->height = avctx->height; | |
456 | 950 if(avctx->gop_size > 600){ |
2979 | 951 av_log(avctx, AV_LOG_ERROR, "Warning keyframe interval too large! reducing it ...\n"); |
456 | 952 avctx->gop_size=600; |
953 } | |
0 | 954 s->gop_size = avctx->gop_size; |
194
27d1773552c9
mpeg4 encoder fix by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
191
diff
changeset
|
955 s->avctx = avctx; |
294 | 956 s->flags= avctx->flags; |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
957 s->flags2= avctx->flags2; |
324 | 958 s->max_b_frames= avctx->max_b_frames; |
344 | 959 s->codec_id= avctx->codec->id; |
456 | 960 s->luma_elim_threshold = avctx->luma_elim_threshold; |
961 s->chroma_elim_threshold= avctx->chroma_elim_threshold; | |
962 s->strict_std_compliance= avctx->strict_std_compliance; | |
963 s->data_partitioning= avctx->flags & CODEC_FLAG_PART; | |
936 | 964 s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0; |
599 | 965 s->mpeg_quant= avctx->mpeg_quant; |
1661 | 966 s->rtp_mode= !!avctx->rtp_payload_size; |
1992 | 967 s->intra_dc_precision= avctx->intra_dc_precision; |
2243
b8bad8bbbc64
check if the user specified timestamps are strictly monotone
michael
parents:
2235
diff
changeset
|
968 s->user_specified_pts = AV_NOPTS_VALUE; |
1422
efeed6e29f9b
oooooops, having 2 Eterms open and doing cvs diff in one and cvs commit in the other sucks, especially if they are in different directories (MPlayer/main/libavcodec vs. ffmpeg/libavcodec)
michaelni
parents:
1421
diff
changeset
|
969 |
0 | 970 if (s->gop_size <= 1) { |
971 s->intra_only = 1; | |
972 s->gop_size = 12; | |
973 } else { | |
974 s->intra_only = 0; | |
975 } | |
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
976 |
936 | 977 s->me_method = avctx->me_method; |
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
978 |
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
979 /* Fixed QSCALE */ |
1708 | 980 s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE); |
2967 | 981 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
982 s->adaptive_quant= ( s->avctx->lumi_masking |
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
983 || s->avctx->dark_masking |
2967 | 984 || s->avctx->temporal_cplx_masking |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
985 || s->avctx->spatial_cplx_masking |
1616 | 986 || s->avctx->p_masking |
2493
258120c61eea
Border processing adaptive quant patch by (Christophe Massiot |cmassiot freebox fr)
michael
parents:
2492
diff
changeset
|
987 || s->avctx->border_masking |
1616 | 988 || (s->flags&CODEC_FLAG_QP_RD)) |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
989 && !s->fixed_qscale; |
2967 | 990 |
1708 | 991 s->obmc= !!(s->flags & CODEC_FLAG_OBMC); |
992 s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER); | |
993 s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN); | |
1633 | 994 |
1711 | 995 if(avctx->rc_max_rate && !avctx->rc_buffer_size){ |
996 av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n"); | |
997 return -1; | |
2967 | 998 } |
1711 | 999 |
1000 if(avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate){ | |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
1001 av_log(avctx, AV_LOG_INFO, "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n"); |
1907 | 1002 } |
2967 | 1003 |
2063 | 1004 if(avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate){ |
1005 av_log(avctx, AV_LOG_INFO, "bitrate below min bitrate\n"); | |
1006 return -1; | |
1007 } | |
2967 | 1008 |
2063 | 1009 if(avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate){ |
1010 av_log(avctx, AV_LOG_INFO, "bitrate above max bitrate\n"); | |
1011 return -1; | |
1012 } | |
2967 | 1013 |
1014 if( s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate | |
1907 | 1015 && (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO) |
1016 && 90000LL * (avctx->rc_buffer_size-1) > s->avctx->rc_max_rate*0xFFFFLL){ | |
2967 | 1017 |
1907 | 1018 av_log(avctx, AV_LOG_INFO, "Warning vbv_delay will be set to 0xFFFF (=VBR) as the specified vbv buffer is too large for the given bitrate!\n"); |
1019 } | |
2967 | 1020 |
1021 if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4 | |
1790 | 1022 && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P && s->codec_id != CODEC_ID_FLV1){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1023 av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n"); |
1188 | 1024 return -1; |
1025 } | |
2967 | 1026 |
1633 | 1027 if(s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE){ |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
1028 av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with simple mb decision\n"); |
1633 | 1029 return -1; |
1030 } | |
2967 | 1031 |
1644 | 1032 if(s->obmc && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){ |
1033 av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n"); | |
1034 return -1; | |
1035 } | |
2967 | 1036 |
1188 | 1037 if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1038 av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n"); |
1188 | 1039 return -1; |
1040 } | |
1041 | |
1042 if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){ | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1043 av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n"); |
1188 | 1044 return -1; |
1045 } | |
2967 | 1046 |
1421 | 1047 if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1048 av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n"); |
1188 | 1049 return -1; |
1050 } | |
1958 | 1051 |
2967 | 1052 if((s->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN)) |
1958 | 1053 && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO){ |
1054 av_log(avctx, AV_LOG_ERROR, "interlacing not supported by codec\n"); | |
1055 return -1; | |
1056 } | |
2967 | 1057 |
1188 | 1058 if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
1059 av_log(avctx, AV_LOG_ERROR, "mpeg2 style quantization not supported by codec\n"); |
1188 | 1060 return -1; |
1061 } | |
2967 | 1062 |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
1063 if((s->flags & CODEC_FLAG_CBP_RD) && !(s->flags & CODEC_FLAG_TRELLIS_QUANT)){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1064 av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n"); |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
1065 return -1; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
1066 } |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
1067 |
1622 | 1068 if((s->flags & CODEC_FLAG_QP_RD) && s->avctx->mb_decision != FF_MB_DECISION_RD){ |
1069 av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n"); | |
1070 return -1; | |
1071 } | |
2967 | 1072 |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
1073 if(s->avctx->scenechange_threshold < 1000000000 && (s->flags & CODEC_FLAG_CLOSED_GOP)){ |
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
1074 av_log(avctx, AV_LOG_ERROR, "closed gop with scene change detection arent supported yet\n"); |
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
1075 return -1; |
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
1076 } |
2967 | 1077 |
1078 if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4 | |
1079 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO | |
1799 | 1080 && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){ |
1081 av_log(avctx, AV_LOG_ERROR, "multi threaded encoding not supported by codec\n"); | |
1082 return -1; | |
1083 } | |
2967 | 1084 |
1799 | 1085 if(s->avctx->thread_count > 1) |
1086 s->rtp_mode= 1; | |
1760 | 1087 |
2637 | 1088 if(!avctx->time_base.den || !avctx->time_base.num){ |
2450 | 1089 av_log(avctx, AV_LOG_ERROR, "framerate not set\n"); |
1090 return -1; | |
1091 } | |
2967 | 1092 |
2576
e237d9bd0f8c
check mb/me_threshold range, fixes assertion failure
michael
parents:
2570
diff
changeset
|
1093 i= (INT_MAX/2+128)>>8; |
e237d9bd0f8c
check mb/me_threshold range, fixes assertion failure
michael
parents:
2570
diff
changeset
|
1094 if(avctx->me_threshold >= i){ |
e237d9bd0f8c
check mb/me_threshold range, fixes assertion failure
michael
parents:
2570
diff
changeset
|
1095 av_log(avctx, AV_LOG_ERROR, "me_threshold too large, max is %d\n", i - 1); |
e237d9bd0f8c
check mb/me_threshold range, fixes assertion failure
michael
parents:
2570
diff
changeset
|
1096 return -1; |
e237d9bd0f8c
check mb/me_threshold range, fixes assertion failure
michael
parents:
2570
diff
changeset
|
1097 } |
e237d9bd0f8c
check mb/me_threshold range, fixes assertion failure
michael
parents:
2570
diff
changeset
|
1098 if(avctx->mb_threshold >= i){ |
e237d9bd0f8c
check mb/me_threshold range, fixes assertion failure
michael
parents:
2570
diff
changeset
|
1099 av_log(avctx, AV_LOG_ERROR, "mb_threshold too large, max is %d\n", i - 1); |
e237d9bd0f8c
check mb/me_threshold range, fixes assertion failure
michael
parents:
2570
diff
changeset
|
1100 return -1; |
e237d9bd0f8c
check mb/me_threshold range, fixes assertion failure
michael
parents:
2570
diff
changeset
|
1101 } |
2967 | 1102 |
2668 | 1103 if(avctx->b_frame_strategy && (avctx->flags&CODEC_FLAG_PASS2)){ |
3069 | 1104 av_log(avctx, AV_LOG_ERROR, "b_frame_strategy must be 0 on the second pass\n"); |
2668 | 1105 return -1; |
1106 } | |
1107 | |
2637 | 1108 i= ff_gcd(avctx->time_base.den, avctx->time_base.num); |
1760 | 1109 if(i > 1){ |
1110 av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n"); | |
2637 | 1111 avctx->time_base.den /= i; |
1112 avctx->time_base.num /= i; | |
1760 | 1113 // return -1; |
1114 } | |
2967 | 1115 |
1150 | 1116 if(s->codec_id==CODEC_ID_MJPEG){ |
1117 s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x | |
1118 s->inter_quant_bias= 0; | |
1421 | 1119 }else if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO){ |
1150 | 1120 s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x |
1121 s->inter_quant_bias= 0; | |
1122 }else{ | |
1123 s->intra_quant_bias=0; | |
1124 s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x | |
1125 } | |
2967 | 1126 |
1150 | 1127 if(avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS) |
1128 s->intra_quant_bias= avctx->intra_quant_bias; | |
1129 if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS) | |
1130 s->inter_quant_bias= avctx->inter_quant_bias; | |
2967 | 1131 |
1315
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
1132 avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift); |
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
1133 |
2653
2515af7d3238
complain about mpeg4 limits only if codec_id == MPEG4
michael
parents:
2639
diff
changeset
|
1134 if(avctx->codec_id == CODEC_ID_MPEG4 && s->avctx->time_base.den > (1<<16)-1){ |
2637 | 1135 av_log(avctx, AV_LOG_ERROR, "timebase not supported by mpeg 4 standard\n"); |
2967 | 1136 return -1; |
2637 | 1137 } |
1138 s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1; | |
1424 | 1139 |
0 | 1140 switch(avctx->codec->id) { |
1141 case CODEC_ID_MPEG1VIDEO: | |
1142 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
|
1143 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
|
1144 avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); |
0 | 1145 break; |
1421 | 1146 case CODEC_ID_MPEG2VIDEO: |
1147 s->out_format = FMT_MPEG1; | |
1148 s->low_delay= 0; //s->max_b_frames ? 0 : 1; | |
1149 avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); | |
1661 | 1150 s->rtp_mode= 1; |
1421 | 1151 break; |
1315
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
1152 case CODEC_ID_LJPEG: |
2973 | 1153 case CODEC_ID_JPEGLS: |
0 | 1154 case CODEC_ID_MJPEG: |
1155 s->out_format = FMT_MJPEG; | |
1156 s->intra_only = 1; /* force intra only for jpeg */ | |
2973 | 1157 s->mjpeg_write_tables = avctx->codec->id != CODEC_ID_JPEGLS; |
2979 | 1158 s->mjpeg_data_only_frames = 0; /* write all the needed headers */ |
1315
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
1159 s->mjpeg_vsample[0] = 1<<chroma_v_shift; |
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
1160 s->mjpeg_vsample[1] = 1; |
2967 | 1161 s->mjpeg_vsample[2] = 1; |
1315
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
1162 s->mjpeg_hsample[0] = 1<<chroma_h_shift; |
2967 | 1163 s->mjpeg_hsample[1] = 1; |
1164 s->mjpeg_hsample[2] = 1; | |
0 | 1165 if (mjpeg_init(s) < 0) |
1166 return -1; | |
336 | 1167 avctx->delay=0; |
924 | 1168 s->low_delay=1; |
0 | 1169 break; |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
1170 case CODEC_ID_H261: |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
1171 s->out_format = FMT_H261; |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
1172 avctx->delay=0; |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
1173 s->low_delay=1; |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
1174 break; |
0 | 1175 case CODEC_ID_H263: |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1176 if (h263_get_picture_format(s->width, s->height) == 7) { |
3011 | 1177 av_log(avctx, AV_LOG_INFO, "The specified picture size of %dx%d is not valid for the H.263 codec.\nValid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152. Try H.263+.\n", s->width, s->height); |
0 | 1178 return -1; |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1179 } |
0 | 1180 s->out_format = FMT_H263; |
2979 | 1181 s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0; |
336 | 1182 avctx->delay=0; |
924 | 1183 s->low_delay=1; |
0 | 1184 break; |
1185 case CODEC_ID_H263P: | |
1186 s->out_format = FMT_H263; | |
1187 s->h263_plus = 1; | |
2979 | 1188 /* Fx */ |
1644 | 1189 s->umvplus = (avctx->flags & CODEC_FLAG_H263P_UMV) ? 1:0; |
2979 | 1190 s->h263_aic= (avctx->flags & CODEC_FLAG_H263P_AIC) ? 1:0; |
1191 s->modified_quant= s->h263_aic; | |
1192 s->alt_inter_vlc= (avctx->flags & CODEC_FLAG_H263P_AIV) ? 1:0; | |
1193 s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0; | |
1194 s->loop_filter= (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1:0; | |
1195 s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus; | |
1661 | 1196 s->h263_slice_structured= (s->flags & CODEC_FLAG_H263P_SLICE_STRUCT) ? 1:0; |
1644 | 1197 |
2979 | 1198 /* /Fx */ |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1199 /* These are just to be sure */ |
336 | 1200 avctx->delay=0; |
924 | 1201 s->low_delay=1; |
0 | 1202 break; |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1203 case CODEC_ID_FLV1: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1204 s->out_format = FMT_H263; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1205 s->h263_flv = 2; /* format = 1; 11-bit codes */ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1206 s->unrestricted_mv = 1; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1207 s->rtp_mode=0; /* don't allow GOB */ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1208 avctx->delay=0; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1209 s->low_delay=1; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1210 break; |
0 | 1211 case CODEC_ID_RV10: |
1212 s->out_format = FMT_H263; | |
336 | 1213 avctx->delay=0; |
924 | 1214 s->low_delay=1; |
0 | 1215 break; |
2380 | 1216 case CODEC_ID_RV20: |
1217 s->out_format = FMT_H263; | |
1218 avctx->delay=0; | |
1219 s->low_delay=1; | |
1220 s->modified_quant=1; | |
1221 s->h263_aic=1; | |
1222 s->h263_plus=1; | |
1223 s->loop_filter=1; | |
1224 s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus; | |
1225 break; | |
71 | 1226 case CODEC_ID_MPEG4: |
0 | 1227 s->out_format = FMT_H263; |
1228 s->h263_pred = 1; | |
1229 s->unrestricted_mv = 1; | |
924 | 1230 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
|
1231 avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); |
0 | 1232 break; |
307 | 1233 case CODEC_ID_MSMPEG4V1: |
0 | 1234 s->out_format = FMT_H263; |
1235 s->h263_msmpeg4 = 1; | |
1236 s->h263_pred = 1; | |
1237 s->unrestricted_mv = 1; | |
307 | 1238 s->msmpeg4_version= 1; |
336 | 1239 avctx->delay=0; |
924 | 1240 s->low_delay=1; |
307 | 1241 break; |
1242 case CODEC_ID_MSMPEG4V2: | |
1243 s->out_format = FMT_H263; | |
1244 s->h263_msmpeg4 = 1; | |
1245 s->h263_pred = 1; | |
1246 s->unrestricted_mv = 1; | |
1247 s->msmpeg4_version= 2; | |
336 | 1248 avctx->delay=0; |
924 | 1249 s->low_delay=1; |
307 | 1250 break; |
1251 case CODEC_ID_MSMPEG4V3: | |
1252 s->out_format = FMT_H263; | |
1253 s->h263_msmpeg4 = 1; | |
1254 s->h263_pred = 1; | |
1255 s->unrestricted_mv = 1; | |
1256 s->msmpeg4_version= 3; | |
1163 | 1257 s->flipflop_rounding=1; |
336 | 1258 avctx->delay=0; |
924 | 1259 s->low_delay=1; |
0 | 1260 break; |
499 | 1261 case CODEC_ID_WMV1: |
1262 s->out_format = FMT_H263; | |
1263 s->h263_msmpeg4 = 1; | |
1264 s->h263_pred = 1; | |
1265 s->unrestricted_mv = 1; | |
1266 s->msmpeg4_version= 4; | |
1163 | 1267 s->flipflop_rounding=1; |
499 | 1268 avctx->delay=0; |
924 | 1269 s->low_delay=1; |
499 | 1270 break; |
1271 case CODEC_ID_WMV2: | |
1272 s->out_format = FMT_H263; | |
1273 s->h263_msmpeg4 = 1; | |
1274 s->h263_pred = 1; | |
1275 s->unrestricted_mv = 1; | |
1276 s->msmpeg4_version= 5; | |
1163 | 1277 s->flipflop_rounding=1; |
499 | 1278 avctx->delay=0; |
924 | 1279 s->low_delay=1; |
499 | 1280 break; |
0 | 1281 default: |
1282 return -1; | |
1283 } | |
2967 | 1284 |
2042 | 1285 avctx->has_b_frames= !s->low_delay; |
1749
7b11032507e2
removing broken framerate conversation hack in mpeg1/2
michael
parents:
1742
diff
changeset
|
1286 |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1287 s->encoding = 1; |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1288 |
0 | 1289 /* init */ |
1290 if (MPV_common_init(s) < 0) | |
1291 return -1; | |
1678 | 1292 |
1293 if(s->modified_quant) | |
1294 s->chroma_qscale_table= ff_h263_chroma_qscale_table; | |
2967 | 1295 s->progressive_frame= |
1708 | 1296 s->progressive_sequence= !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)); |
1799 | 1297 s->quant_precision=5; |
2967 | 1298 |
1729 | 1299 ff_set_cmp(&s->dsp, s->dsp.ildct_cmp, s->avctx->ildct_cmp); |
2382 | 1300 ff_set_cmp(&s->dsp, s->dsp.frame_skip_cmp, s->avctx->frame_skip_cmp); |
2967 | 1301 |
2639 | 1302 #ifdef CONFIG_H261_ENCODER |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
1303 if (s->out_format == FMT_H261) |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
1304 ff_h261_encode_init(s); |
2639 | 1305 #endif |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1306 if (s->out_format == FMT_H263) |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1307 h263_encode_init(s); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1308 if(s->msmpeg4_version) |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1309 ff_msmpeg4_encode_init(s); |
1042 | 1310 if (s->out_format == FMT_MPEG1) |
1311 ff_mpeg1_encode_init(s); | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1312 |
1892 | 1313 /* init q matrix */ |
60 | 1314 for(i=0;i<64;i++) { |
1092 | 1315 int j= s->dsp.idct_permutation[i]; |
599 | 1316 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
|
1317 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
|
1318 s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i]; |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
1319 }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){ |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1320 s->intra_matrix[j] = |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1321 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; |
1042 | 1322 }else |
1421 | 1323 { /* mpeg1/2 */ |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1324 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
|
1325 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; |
599 | 1326 } |
1411 | 1327 if(s->avctx->intra_matrix) |
1328 s->intra_matrix[j] = s->avctx->intra_matrix[i]; | |
1329 if(s->avctx->inter_matrix) | |
1330 s->inter_matrix[j] = s->avctx->inter_matrix[i]; | |
344 | 1331 } |
1332 | |
1333 /* precompute matrix */ | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
1334 /* for mjpeg, we do include qscale in the matrix */ |
344 | 1335 if (s->out_format != FMT_MJPEG) { |
2967 | 1336 convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, |
2385
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
1337 s->intra_matrix, s->intra_quant_bias, avctx->qmin, 31, 1); |
2967 | 1338 convert_matrix(&s->dsp, s->q_inter_matrix, s->q_inter_matrix16, |
2385
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
1339 s->inter_matrix, s->inter_quant_bias, avctx->qmin, 31, 0); |
60 | 1340 } |
1341 | |
329 | 1342 if(ff_rate_control_init(s) < 0) |
1343 return -1; | |
2967 | 1344 |
0 | 1345 return 0; |
1346 } | |
1347 | |
1348 int MPV_encode_end(AVCodecContext *avctx) | |
1349 { | |
1350 MpegEncContext *s = avctx->priv_data; | |
1351 | |
1352 #ifdef STATS | |
1353 print_stats(); | |
1354 #endif | |
329 | 1355 |
1356 ff_rate_control_uninit(s); | |
1357 | |
0 | 1358 MPV_common_end(s); |
1359 if (s->out_format == FMT_MJPEG) | |
1360 mjpeg_close(s); | |
1458
40b69d238beb
AVI stream header FCC / more reliable detection of old xvid files
michaelni
parents:
1451
diff
changeset
|
1361 |
1424 | 1362 av_freep(&avctx->extradata); |
2967 | 1363 |
0 | 1364 return 0; |
1365 } | |
1366 | |
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
|
1367 #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
|
1368 |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1369 void init_rl(RLTable *rl, int use_static) |
1042 | 1370 { |
1064 | 1371 int8_t max_level[MAX_RUN+1], max_run[MAX_LEVEL+1]; |
1372 uint8_t index_run[MAX_RUN+1]; | |
1042 | 1373 int last, run, level, start, end, i; |
1374 | |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1375 /* If table is static, we can quit if rl->max_level[0] is not NULL */ |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1376 if(use_static && rl->max_level[0]) |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1377 return; |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1378 |
1042 | 1379 /* compute max_level[], max_run[] and index_run[] */ |
1380 for(last=0;last<2;last++) { | |
1381 if (last == 0) { | |
1382 start = 0; | |
1383 end = rl->last; | |
1384 } else { | |
1385 start = rl->last; | |
1386 end = rl->n; | |
1387 } | |
1388 | |
1389 memset(max_level, 0, MAX_RUN + 1); | |
1390 memset(max_run, 0, MAX_LEVEL + 1); | |
1391 memset(index_run, rl->n, MAX_RUN + 1); | |
1392 for(i=start;i<end;i++) { | |
1393 run = rl->table_run[i]; | |
1394 level = rl->table_level[i]; | |
1395 if (index_run[run] == rl->n) | |
1396 index_run[run] = i; | |
1397 if (level > max_level[run]) | |
1398 max_level[run] = level; | |
1399 if (run > max_run[level]) | |
1400 max_run[level] = run; | |
1401 } | |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1402 if(use_static) |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1403 rl->max_level[last] = av_mallocz_static(MAX_RUN + 1); |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1404 else |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1405 rl->max_level[last] = av_malloc(MAX_RUN + 1); |
1042 | 1406 memcpy(rl->max_level[last], max_level, MAX_RUN + 1); |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1407 if(use_static) |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1408 rl->max_run[last] = av_mallocz_static(MAX_LEVEL + 1); |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1409 else |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1410 rl->max_run[last] = av_malloc(MAX_LEVEL + 1); |
1042 | 1411 memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1); |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1412 if(use_static) |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1413 rl->index_run[last] = av_mallocz_static(MAX_RUN + 1); |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1414 else |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1415 rl->index_run[last] = av_malloc(MAX_RUN + 1); |
1042 | 1416 memcpy(rl->index_run[last], index_run, MAX_RUN + 1); |
1417 } | |
1418 } | |
1419 | |
0 | 1420 /* 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
|
1421 //FIXME check that this is ok for mpeg4 interlaced |
1064 | 1422 static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w) |
0 | 1423 { |
1064 | 1424 uint8_t *ptr, *last_line; |
0 | 1425 int i; |
1426 | |
1427 last_line = buf + (height - 1) * wrap; | |
1428 for(i=0;i<w;i++) { | |
1429 /* top and bottom */ | |
1430 memcpy(buf - (i + 1) * wrap, buf, width); | |
1431 memcpy(last_line + (i + 1) * wrap, last_line, width); | |
1432 } | |
1433 /* left and right */ | |
1434 ptr = buf; | |
1435 for(i=0;i<height;i++) { | |
1436 memset(ptr - w, ptr[0], w); | |
1437 memset(ptr + width, ptr[width-1], w); | |
1438 ptr += wrap; | |
1439 } | |
1440 /* corners */ | |
1441 for(i=0;i<w;i++) { | |
1442 memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */ | |
1443 memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */ | |
1444 memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */ | |
1445 memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */ | |
1446 } | |
1447 } | |
1448 | |
1586 | 1449 int ff_find_unused_picture(MpegEncContext *s, int shared){ |
924 | 1450 int i; |
2967 | 1451 |
924 | 1452 if(shared){ |
1453 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
1586 | 1454 if(s->picture[i].data[0]==NULL && s->picture[i].type==0) return i; |
924 | 1455 } |
1456 }else{ | |
1457 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
1586 | 1458 if(s->picture[i].data[0]==NULL && s->picture[i].type!=0) return i; //FIXME |
924 | 1459 } |
1460 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
1586 | 1461 if(s->picture[i].data[0]==NULL) return i; |
924 | 1462 } |
1463 } | |
1464 | |
1586 | 1465 assert(0); |
1466 return -1; | |
924 | 1467 } |
1468 | |
1597 | 1469 static void update_noise_reduction(MpegEncContext *s){ |
1470 int intra, i; | |
1471 | |
1472 for(intra=0; intra<2; intra++){ | |
1473 if(s->dct_count[intra] > (1<<16)){ | |
1474 for(i=0; i<64; i++){ | |
1475 s->dct_error_sum[intra][i] >>=1; | |
1476 } | |
1477 s->dct_count[intra] >>= 1; | |
1478 } | |
2967 | 1479 |
1597 | 1480 for(i=0; i<64; i++){ |
1481 s->dct_offset[intra][i]= (s->avctx->noise_reduction * s->dct_count[intra] + s->dct_error_sum[intra][i]/2) / (s->dct_error_sum[intra][i]+1); | |
1482 } | |
1483 } | |
1484 } | |
1485 | |
1586 | 1486 /** |
1487 * generic function for encode/decode called after coding/decoding the header and before a frame is coded/decoded | |
1488 */ | |
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
1489 int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) |
0 | 1490 { |
924 | 1491 int i; |
925 | 1492 AVFrame *pic; |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2627
diff
changeset
|
1493 s->mb_skipped = 0; |
1168 | 1494 |
1234 | 1495 assert(s->last_picture_ptr==NULL || s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3); |
1228 | 1496 |
903 | 1497 /* mark&release old frames */ |
1944 | 1498 if (s->pict_type != B_TYPE && s->last_picture_ptr && s->last_picture_ptr != s->next_picture_ptr && s->last_picture_ptr->data[0]) { |
1138 | 1499 avctx->release_buffer(avctx, (AVFrame*)s->last_picture_ptr); |
903 | 1500 |
1501 /* release forgotten pictures */ | |
1502 /* if(mpeg124/h263) */ | |
1503 if(!s->encoding){ | |
1504 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
1138 | 1505 if(s->picture[i].data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1506 av_log(avctx, AV_LOG_ERROR, "releasing zombie picture\n"); |
2967 | 1507 avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]); |
903 | 1508 } |
1509 } | |
1510 } | |
1511 } | |
910
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
1512 alloc: |
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
1513 if(!s->encoding){ |
2764 | 1514 /* release non reference frames */ |
1228 | 1515 for(i=0; i<MAX_PICTURE_COUNT; i++){ |
1516 if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){ | |
1517 s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]); | |
1518 } | |
1519 } | |
1520 | |
1586 | 1521 if(s->current_picture_ptr && s->current_picture_ptr->data[0]==NULL) |
1522 pic= (AVFrame*)s->current_picture_ptr; //we allready have a unused image (maybe it was set before reading the header) | |
1523 else{ | |
1524 i= ff_find_unused_picture(s, 0); | |
1525 pic= (AVFrame*)&s->picture[i]; | |
1526 } | |
1527 | |
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2534
diff
changeset
|
1528 pic->reference= (s->pict_type != B_TYPE || s->codec_id == CODEC_ID_H264) |
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2534
diff
changeset
|
1529 && !s->dropable ? 3 : 0; |
1138 | 1530 |
1705 | 1531 pic->coded_picture_number= s->coded_picture_number++; |
2967 | 1532 |
1384 | 1533 if( alloc_picture(s, (Picture*)pic, 0) < 0) |
1534 return -1; | |
903 | 1535 |
1586 | 1536 s->current_picture_ptr= (Picture*)pic; |
1658 | 1537 s->current_picture_ptr->top_field_first= s->top_field_first; //FIXME use only the vars from current_pic |
1659 | 1538 s->current_picture_ptr->interlaced_frame= !s->progressive_frame && !s->progressive_sequence; |
903 | 1539 } |
456 | 1540 |
1173 | 1541 s->current_picture_ptr->pict_type= s->pict_type; |
2967 | 1542 // if(s->flags && CODEC_FLAG_QSCALE) |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
1543 // s->current_picture_ptr->quality= s->new_picture_ptr->quality; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1544 s->current_picture_ptr->key_frame= s->pict_type == I_TYPE; |
1173 | 1545 |
1539
14d01ccc0081
picture buffer cleanup, this fixes a assertion failure (if assertion checking was manualy enabled for utils.c) and a memleak at least
michael
parents:
1530
diff
changeset
|
1546 copy_picture(&s->current_picture, s->current_picture_ptr); |
2967 | 1547 |
1234 | 1548 if(s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3){ |
903 | 1549 if (s->pict_type != B_TYPE) { |
1138 | 1550 s->last_picture_ptr= s->next_picture_ptr; |
1944 | 1551 if(!s->dropable) |
1552 s->next_picture_ptr= s->current_picture_ptr; | |
1553 } | |
1554 /* av_log(s->avctx, AV_LOG_DEBUG, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n", s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr, | |
2967 | 1555 s->last_picture_ptr ? s->last_picture_ptr->data[0] : NULL, |
1556 s->next_picture_ptr ? s->next_picture_ptr->data[0] : NULL, | |
1944 | 1557 s->current_picture_ptr ? s->current_picture_ptr->data[0] : NULL, |
1558 s->pict_type, s->dropable);*/ | |
2967 | 1559 |
1539
14d01ccc0081
picture buffer cleanup, this fixes a assertion failure (if assertion checking was manualy enabled for utils.c) and a memleak at least
michael
parents:
1530
diff
changeset
|
1560 if(s->last_picture_ptr) copy_picture(&s->last_picture, s->last_picture_ptr); |
14d01ccc0081
picture buffer cleanup, this fixes a assertion failure (if assertion checking was manualy enabled for utils.c) and a memleak at least
michael
parents:
1530
diff
changeset
|
1561 if(s->next_picture_ptr) copy_picture(&s->next_picture, s->next_picture_ptr); |
2967 | 1562 |
1539
14d01ccc0081
picture buffer cleanup, this fixes a assertion failure (if assertion checking was manualy enabled for utils.c) and a memleak at least
michael
parents:
1530
diff
changeset
|
1563 if(s->pict_type != I_TYPE && (s->last_picture_ptr==NULL || s->last_picture_ptr->data[0]==NULL)){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1564 av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n"); |
2764 | 1565 assert(s->pict_type != B_TYPE); //these should have been dropped if we don't have a reference |
1393 | 1566 goto alloc; |
1567 } | |
1568 | |
1569 assert(s->pict_type == I_TYPE || (s->last_picture_ptr && s->last_picture_ptr->data[0])); | |
1570 | |
1138 | 1571 if(s->picture_structure!=PICT_FRAME){ |
1572 int i; | |
1573 for(i=0; i<4; i++){ | |
1574 if(s->picture_structure == PICT_BOTTOM_FIELD){ | |
1575 s->current_picture.data[i] += s->current_picture.linesize[i]; | |
2967 | 1576 } |
1138 | 1577 s->current_picture.linesize[i] *= 2; |
1578 s->last_picture.linesize[i] *=2; | |
1579 s->next_picture.linesize[i] *=2; | |
1580 } | |
553 | 1581 } |
1168 | 1582 } |
2967 | 1583 |
910
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
1584 s->hurry_up= s->avctx->hurry_up; |
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
1585 s->error_resilience= avctx->error_resilience; |
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
1586 |
2764 | 1587 /* set dequantizer, we can't do it during init as it might change for mpeg4 |
1588 and we can't do it in the header decode as init isnt called for mpeg4 there yet */ | |
1689 | 1589 if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO){ |
1590 s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra; | |
1591 s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter; | |
2345 | 1592 }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){ |
1689 | 1593 s->dct_unquantize_intra = s->dct_unquantize_h263_intra; |
1594 s->dct_unquantize_inter = s->dct_unquantize_h263_inter; | |
1595 }else{ | |
1596 s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra; | |
1597 s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter; | |
1598 } | |
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
1599 |
1597 | 1600 if(s->dct_error_sum){ |
1601 assert(s->avctx->noise_reduction && s->encoding); | |
1602 | |
1603 update_noise_reduction(s); | |
1604 } | |
2967 | 1605 |
1381 | 1606 #ifdef HAVE_XVMC |
1607 if(s->avctx->xvmc_acceleration) | |
1608 return XVMC_field_start(s, avctx); | |
1609 #endif | |
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
1610 return 0; |
0 | 1611 } |
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
|
1612 |
0 | 1613 /* generic function for encode/decode called after a frame has been coded/decoded */ |
1614 void MPV_frame_end(MpegEncContext *s) | |
1615 { | |
903 | 1616 int i; |
0 | 1617 /* draw edge for correct motion prediction if outside */ |
1381 | 1618 #ifdef HAVE_XVMC |
1619 //just to make sure that all data is rendered. | |
1620 if(s->avctx->xvmc_acceleration){ | |
1621 XVMC_field_end(s); | |
1622 }else | |
1623 #endif | |
2537
14fef0f3f532
H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents:
2534
diff
changeset
|
1624 if(s->unrestricted_mv && s->current_picture.reference && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) { |
903 | 1625 draw_edges(s->current_picture.data[0], s->linesize , s->h_edge_pos , s->v_edge_pos , EDGE_WIDTH ); |
1626 draw_edges(s->current_picture.data[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); | |
1627 draw_edges(s->current_picture.data[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); | |
0 | 1628 } |
207 | 1629 emms_c(); |
2967 | 1630 |
612 | 1631 s->last_pict_type = s->pict_type; |
2997
188f4ef688f2
second try of improved lambda/qp guessing for motion estimation RD in first pass
michael
parents:
2990
diff
changeset
|
1632 s->last_lambda_for[s->pict_type]= s->current_picture_ptr->quality; |
329 | 1633 if(s->pict_type!=B_TYPE){ |
1634 s->last_non_b_pict_type= s->pict_type; | |
1635 } | |
1138 | 1636 #if 0 |
1637 /* copy back current_picture variables */ | |
903 | 1638 for(i=0; i<MAX_PICTURE_COUNT; i++){ |
1639 if(s->picture[i].data[0] == s->current_picture.data[0]){ | |
1640 s->picture[i]= s->current_picture; | |
1641 break; | |
2967 | 1642 } |
903 | 1643 } |
1644 assert(i<MAX_PICTURE_COUNT); | |
2967 | 1645 #endif |
903 | 1646 |
1228 | 1647 if(s->encoding){ |
2764 | 1648 /* release non-reference frames */ |
1228 | 1649 for(i=0; i<MAX_PICTURE_COUNT; i++){ |
1650 if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){ | |
1651 s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]); | |
1652 } | |
1653 } | |
324 | 1654 } |
1138 | 1655 // clear copies, to avoid confusion |
1656 #if 0 | |
1657 memset(&s->last_picture, 0, sizeof(Picture)); | |
1658 memset(&s->next_picture, 0, sizeof(Picture)); | |
1659 memset(&s->current_picture, 0, sizeof(Picture)); | |
1660 #endif | |
2213 | 1661 s->avctx->coded_frame= (AVFrame*)s->current_picture_ptr; |
903 | 1662 } |
1663 | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1664 /** |
1285 | 1665 * draws an line from (ex, ey) -> (sx, sy). |
1666 * @param w width of the image | |
1667 * @param h height of the image | |
1668 * @param stride stride/linesize of the image | |
1669 * @param color color of the arrow | |
1670 */ | |
1671 static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){ | |
1918
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1672 int t, x, y, fr, f; |
2967 | 1673 |
1285 | 1674 sx= clip(sx, 0, w-1); |
1675 sy= clip(sy, 0, h-1); | |
1676 ex= clip(ex, 0, w-1); | |
1677 ey= clip(ey, 0, h-1); | |
2967 | 1678 |
1285 | 1679 buf[sy*stride + sx]+= color; |
2967 | 1680 |
1285 | 1681 if(ABS(ex - sx) > ABS(ey - sy)){ |
1682 if(sx > ex){ | |
1683 t=sx; sx=ex; ex=t; | |
1684 t=sy; sy=ey; ey=t; | |
1685 } | |
1686 buf+= sx + sy*stride; | |
1687 ex-= sx; | |
1688 f= ((ey-sy)<<16)/ex; | |
1689 for(x= 0; x <= ex; x++){ | |
1918
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1690 y = (x*f)>>16; |
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1691 fr= (x*f)&0xFFFF; |
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1692 buf[ y *stride + x]+= (color*(0x10000-fr))>>16; |
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1693 buf[(y+1)*stride + x]+= (color* fr )>>16; |
1285 | 1694 } |
1695 }else{ | |
1696 if(sy > ey){ | |
1697 t=sx; sx=ex; ex=t; | |
1698 t=sy; sy=ey; ey=t; | |
1699 } | |
1700 buf+= sx + sy*stride; | |
1701 ey-= sy; | |
1702 if(ey) f= ((ex-sx)<<16)/ey; | |
1703 else f= 0; | |
1704 for(y= 0; y <= ey; y++){ | |
1918
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1705 x = (y*f)>>16; |
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1706 fr= (y*f)&0xFFFF; |
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1707 buf[y*stride + x ]+= (color*(0x10000-fr))>>16;; |
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1708 buf[y*stride + x+1]+= (color* fr )>>16;; |
1285 | 1709 } |
1710 } | |
1711 } | |
1712 | |
1713 /** | |
1714 * draws an arrow from (ex, ey) -> (sx, sy). | |
1715 * @param w width of the image | |
1716 * @param h height of the image | |
1717 * @param stride stride/linesize of the image | |
1718 * @param color color of the arrow | |
1719 */ | |
2967 | 1720 static void draw_arrow(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){ |
1285 | 1721 int dx,dy; |
1722 | |
1723 sx= clip(sx, -100, w+100); | |
1724 sy= clip(sy, -100, h+100); | |
1725 ex= clip(ex, -100, w+100); | |
1726 ey= clip(ey, -100, h+100); | |
2967 | 1727 |
1285 | 1728 dx= ex - sx; |
1729 dy= ey - sy; | |
2967 | 1730 |
1285 | 1731 if(dx*dx + dy*dy > 3*3){ |
1732 int rx= dx + dy; | |
1733 int ry= -dx + dy; | |
1734 int length= ff_sqrt((rx*rx + ry*ry)<<8); | |
2967 | 1735 |
1285 | 1736 //FIXME subpixel accuracy |
1737 rx= ROUNDED_DIV(rx*3<<4, length); | |
1738 ry= ROUNDED_DIV(ry*3<<4, length); | |
2967 | 1739 |
1285 | 1740 draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color); |
1741 draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color); | |
1742 } | |
1743 draw_line(buf, sx, sy, ex, ey, w, h, stride, color); | |
1744 } | |
1745 | |
1746 /** | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1747 * prints debuging info for the given picture. |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1748 */ |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1749 void ff_print_debug_info(MpegEncContext *s, AVFrame *pict){ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1750 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1751 if(!pict || !pict->mb_type) return; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1752 |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1753 if(s->avctx->debug&(FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)){ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1754 int x,y; |
2967 | 1755 |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1756 av_log(s->avctx,AV_LOG_DEBUG,"New frame, type: "); |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1757 switch (pict->pict_type) { |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1758 case FF_I_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"I\n"); break; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1759 case FF_P_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"P\n"); break; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1760 case FF_B_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"B\n"); break; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1761 case FF_S_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"S\n"); break; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1762 case FF_SI_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SI\n"); break; |
2967 | 1763 case FF_SP_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SP\n"); break; |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1764 } |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1765 for(y=0; y<s->mb_height; y++){ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1766 for(x=0; x<s->mb_width; x++){ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1767 if(s->avctx->debug&FF_DEBUG_SKIP){ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1768 int count= s->mbskip_table[x + y*s->mb_stride]; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1769 if(count>9) count=9; |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1770 av_log(s->avctx, AV_LOG_DEBUG, "%1d", count); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1771 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1772 if(s->avctx->debug&FF_DEBUG_QP){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1773 av_log(s->avctx, AV_LOG_DEBUG, "%2d", pict->qscale_table[x + y*s->mb_stride]); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1774 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1775 if(s->avctx->debug&FF_DEBUG_MB_TYPE){ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1776 int mb_type= pict->mb_type[x + y*s->mb_stride]; |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1777 //Type & MV direction |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1778 if(IS_PCM(mb_type)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1779 av_log(s->avctx, AV_LOG_DEBUG, "P"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1780 else if(IS_INTRA(mb_type) && IS_ACPRED(mb_type)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1781 av_log(s->avctx, AV_LOG_DEBUG, "A"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1782 else if(IS_INTRA4x4(mb_type)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1783 av_log(s->avctx, AV_LOG_DEBUG, "i"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1784 else if(IS_INTRA16x16(mb_type)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1785 av_log(s->avctx, AV_LOG_DEBUG, "I"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1786 else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1787 av_log(s->avctx, AV_LOG_DEBUG, "d"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1788 else if(IS_DIRECT(mb_type)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1789 av_log(s->avctx, AV_LOG_DEBUG, "D"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1790 else if(IS_GMC(mb_type) && IS_SKIP(mb_type)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1791 av_log(s->avctx, AV_LOG_DEBUG, "g"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1792 else if(IS_GMC(mb_type)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1793 av_log(s->avctx, AV_LOG_DEBUG, "G"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1794 else if(IS_SKIP(mb_type)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1795 av_log(s->avctx, AV_LOG_DEBUG, "S"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1796 else if(!USES_LIST(mb_type, 1)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1797 av_log(s->avctx, AV_LOG_DEBUG, ">"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1798 else if(!USES_LIST(mb_type, 0)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1799 av_log(s->avctx, AV_LOG_DEBUG, "<"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1800 else{ |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1801 assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1)); |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1802 av_log(s->avctx, AV_LOG_DEBUG, "X"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1803 } |
2967 | 1804 |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1805 //segmentation |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1806 if(IS_8X8(mb_type)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1807 av_log(s->avctx, AV_LOG_DEBUG, "+"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1808 else if(IS_16X8(mb_type)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1809 av_log(s->avctx, AV_LOG_DEBUG, "-"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1810 else if(IS_8X16(mb_type)) |
2677 | 1811 av_log(s->avctx, AV_LOG_DEBUG, "|"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1812 else if(IS_INTRA(mb_type) || IS_16X16(mb_type)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1813 av_log(s->avctx, AV_LOG_DEBUG, " "); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1814 else |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1815 av_log(s->avctx, AV_LOG_DEBUG, "?"); |
2967 | 1816 |
1817 | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1818 if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1819 av_log(s->avctx, AV_LOG_DEBUG, "="); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1820 else |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1821 av_log(s->avctx, AV_LOG_DEBUG, " "); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1822 } |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1823 // av_log(s->avctx, AV_LOG_DEBUG, " "); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1824 } |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1825 av_log(s->avctx, AV_LOG_DEBUG, "\n"); |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1826 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
1827 } |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
1828 |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1829 if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ |
1285 | 1830 const int shift= 1 + s->quarter_sample; |
1831 int mb_y; | |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1832 uint8_t *ptr; |
1707 | 1833 int i; |
1723
033d889d7c2c
non YV12 vissualization fix by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1722
diff
changeset
|
1834 int h_chroma_shift, v_chroma_shift; |
2266
514949de5d15
set AVCodecContext.width/height to the picture width/height instead of the one stored in the bitstream (that only matters if lowres!=0)
michael
parents:
2265
diff
changeset
|
1835 const int width = s->avctx->width; |
514949de5d15
set AVCodecContext.width/height to the picture width/height instead of the one stored in the bitstream (that only matters if lowres!=0)
michael
parents:
2265
diff
changeset
|
1836 const int height= s->avctx->height; |
2395 | 1837 const int mv_sample_log2= 4 - pict->motion_subsample_log2; |
3268 | 1838 const int mv_stride= (s->mb_width << mv_sample_log2) + (s->codec_id == CODEC_ID_H264 ? 0 : 1); |
1285 | 1839 s->low_delay=0; //needed to see the vectors without trashing the buffers |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1840 |
1723
033d889d7c2c
non YV12 vissualization fix by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1722
diff
changeset
|
1841 avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1842 for(i=0; i<3; i++){ |
2266
514949de5d15
set AVCodecContext.width/height to the picture width/height instead of the one stored in the bitstream (that only matters if lowres!=0)
michael
parents:
2265
diff
changeset
|
1843 memcpy(s->visualization_buffer[i], pict->data[i], (i==0) ? pict->linesize[i]*height:pict->linesize[i]*height >> v_chroma_shift); |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1844 pict->data[i]= s->visualization_buffer[i]; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1845 } |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1846 pict->type= FF_BUFFER_TYPE_COPY; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1847 ptr= pict->data[0]; |
1285 | 1848 |
1849 for(mb_y=0; mb_y<s->mb_height; mb_y++){ | |
1850 int mb_x; | |
1851 for(mb_x=0; mb_x<s->mb_width; mb_x++){ | |
1852 const int mb_index= mb_x + mb_y*s->mb_stride; | |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1853 if((s->avctx->debug_mv) && pict->motion_val){ |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1854 int type; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1855 for(type=0; type<3; type++){ |
2024
f65d87bfdd5a
some of the warning fixes by (Michael Roitzsch <mroi at users dot sourceforge dot net>)
michael
parents:
2015
diff
changeset
|
1856 int direction = 0; |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1857 switch (type) { |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1858 case 0: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_P_FOR)) || (pict->pict_type!=FF_P_TYPE)) |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1859 continue; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1860 direction = 0; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1861 break; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1862 case 1: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_B_FOR)) || (pict->pict_type!=FF_B_TYPE)) |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1863 continue; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1864 direction = 0; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1865 break; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1866 case 2: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_B_BACK)) || (pict->pict_type!=FF_B_TYPE)) |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1867 continue; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1868 direction = 1; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1869 break; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1870 } |
1712 | 1871 if(!USES_LIST(pict->mb_type[mb_index], direction)) |
1872 continue; | |
1873 | |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1874 if(IS_8X8(pict->mb_type[mb_index])){ |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1875 int i; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1876 for(i=0; i<4; i++){ |
1285 | 1877 int sx= mb_x*16 + 4 + 8*(i&1); |
1878 int sy= mb_y*16 + 4 + 8*(i>>1); | |
2522
e25782262d7d
kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents:
2514
diff
changeset
|
1879 int xy= (mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*mv_stride) << (mv_sample_log2-1); |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1880 int mx= (pict->motion_val[direction][xy][0]>>shift) + sx; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1881 int my= (pict->motion_val[direction][xy][1]>>shift) + sy; |
2266
514949de5d15
set AVCodecContext.width/height to the picture width/height instead of the one stored in the bitstream (that only matters if lowres!=0)
michael
parents:
2265
diff
changeset
|
1882 draw_arrow(ptr, sx, sy, mx, my, width, height, s->linesize, 100); |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1883 } |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1884 }else if(IS_16X8(pict->mb_type[mb_index])){ |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1885 int i; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1886 for(i=0; i<2; i++){ |
1629
74685a0ec851
16x8 MV vissualization by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1628
diff
changeset
|
1887 int sx=mb_x*16 + 8; |
74685a0ec851
16x8 MV vissualization by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1628
diff
changeset
|
1888 int sy=mb_y*16 + 4 + 8*i; |
2522
e25782262d7d
kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents:
2514
diff
changeset
|
1889 int xy= (mb_x*2 + (mb_y*2 + i)*mv_stride) << (mv_sample_log2-1); |
2395 | 1890 int mx=(pict->motion_val[direction][xy][0]>>shift); |
1891 int my=(pict->motion_val[direction][xy][1]>>shift); | |
2967 | 1892 |
2395 | 1893 if(IS_INTERLACED(pict->mb_type[mb_index])) |
1894 my*=2; | |
2967 | 1895 |
2395 | 1896 draw_arrow(ptr, sx, sy, mx+sx, my+sy, width, height, s->linesize, 100); |
1897 } | |
1898 }else if(IS_8X16(pict->mb_type[mb_index])){ | |
1899 int i; | |
1900 for(i=0; i<2; i++){ | |
1901 int sx=mb_x*16 + 4 + 8*i; | |
1902 int sy=mb_y*16 + 8; | |
2522
e25782262d7d
kill warnings patch by (M«©ns Rullg«©rd <mru inprovide com>)
michael
parents:
2514
diff
changeset
|
1903 int xy= (mb_x*2 + i + mb_y*2*mv_stride) << (mv_sample_log2-1); |
1947
b306574523ad
fix y scale of mv vissualization of interlaced MVs
michael
parents:
1945
diff
changeset
|
1904 int mx=(pict->motion_val[direction][xy][0]>>shift); |
b306574523ad
fix y scale of mv vissualization of interlaced MVs
michael
parents:
1945
diff
changeset
|
1905 int my=(pict->motion_val[direction][xy][1]>>shift); |
2967 | 1906 |
1947
b306574523ad
fix y scale of mv vissualization of interlaced MVs
michael
parents:
1945
diff
changeset
|
1907 if(IS_INTERLACED(pict->mb_type[mb_index])) |
b306574523ad
fix y scale of mv vissualization of interlaced MVs
michael
parents:
1945
diff
changeset
|
1908 my*=2; |
2967 | 1909 |
2266
514949de5d15
set AVCodecContext.width/height to the picture width/height instead of the one stored in the bitstream (that only matters if lowres!=0)
michael
parents:
2265
diff
changeset
|
1910 draw_arrow(ptr, sx, sy, mx+sx, my+sy, width, height, s->linesize, 100); |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1911 } |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1912 }else{ |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1913 int sx= mb_x*16 + 8; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1914 int sy= mb_y*16 + 8; |
2395 | 1915 int xy= (mb_x + mb_y*mv_stride) << mv_sample_log2; |
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1916 int mx= (pict->motion_val[direction][xy][0]>>shift) + sx; |
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1917 int my= (pict->motion_val[direction][xy][1]>>shift) + sy; |
2266
514949de5d15
set AVCodecContext.width/height to the picture width/height instead of the one stored in the bitstream (that only matters if lowres!=0)
michael
parents:
2265
diff
changeset
|
1918 draw_arrow(ptr, sx, sy, mx, my, width, height, s->linesize, 100); |
1629
74685a0ec851
16x8 MV vissualization by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1628
diff
changeset
|
1919 } |
2967 | 1920 } |
1685 | 1921 } |
1922 if((s->avctx->debug&FF_DEBUG_VIS_QP) && pict->motion_val){ | |
1923 uint64_t c= (pict->qscale_table[mb_index]*128/31) * 0x0101010101010101ULL; | |
1924 int y; | |
1925 for(y=0; y<8; y++){ | |
1926 *(uint64_t*)(pict->data[1] + 8*mb_x + (8*mb_y + y)*pict->linesize[1])= c; | |
1927 *(uint64_t*)(pict->data[2] + 8*mb_x + (8*mb_y + y)*pict->linesize[2])= c; | |
1928 } | |
1929 } | |
1930 if((s->avctx->debug&FF_DEBUG_VIS_MB_TYPE) && pict->motion_val){ | |
1931 int mb_type= pict->mb_type[mb_index]; | |
1932 uint64_t u,v; | |
1933 int y; | |
1934 #define COLOR(theta, r)\ | |
1935 u= (int)(128 + r*cos(theta*3.141592/180));\ | |
1936 v= (int)(128 + r*sin(theta*3.141592/180)); | |
1937 | |
2967 | 1938 |
1685 | 1939 u=v=128; |
1940 if(IS_PCM(mb_type)){ | |
1941 COLOR(120,48) | |
1942 }else if((IS_INTRA(mb_type) && IS_ACPRED(mb_type)) || IS_INTRA16x16(mb_type)){ | |
1943 COLOR(30,48) | |
1944 }else if(IS_INTRA4x4(mb_type)){ | |
1945 COLOR(90,48) | |
1946 }else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type)){ | |
1947 // COLOR(120,48) | |
1948 }else if(IS_DIRECT(mb_type)){ | |
1949 COLOR(150,48) | |
1950 }else if(IS_GMC(mb_type) && IS_SKIP(mb_type)){ | |
1951 COLOR(170,48) | |
1952 }else if(IS_GMC(mb_type)){ | |
1953 COLOR(190,48) | |
1954 }else if(IS_SKIP(mb_type)){ | |
1955 // COLOR(180,48) | |
1956 }else if(!USES_LIST(mb_type, 1)){ | |
1957 COLOR(240,48) | |
1958 }else if(!USES_LIST(mb_type, 0)){ | |
1959 COLOR(0,48) | |
1960 }else{ | |
1961 assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1)); | |
1962 COLOR(300,48) | |
1963 } | |
1964 | |
1965 u*= 0x0101010101010101ULL; | |
1966 v*= 0x0101010101010101ULL; | |
1967 for(y=0; y<8; y++){ | |
1968 *(uint64_t*)(pict->data[1] + 8*mb_x + (8*mb_y + y)*pict->linesize[1])= u; | |
1969 *(uint64_t*)(pict->data[2] + 8*mb_x + (8*mb_y + y)*pict->linesize[2])= v; | |
1970 } | |
1971 | |
1972 //segmentation | |
1973 if(IS_8X8(mb_type) || IS_16X8(mb_type)){ | |
1974 *(uint64_t*)(pict->data[0] + 16*mb_x + 0 + (16*mb_y + 8)*pict->linesize[0])^= 0x8080808080808080ULL; | |
1975 *(uint64_t*)(pict->data[0] + 16*mb_x + 8 + (16*mb_y + 8)*pict->linesize[0])^= 0x8080808080808080ULL; | |
1976 } | |
1977 if(IS_8X8(mb_type) || IS_8X16(mb_type)){ | |
1978 for(y=0; y<16; y++) | |
1979 pict->data[0][16*mb_x + 8 + (16*mb_y + y)*pict->linesize[0]]^= 0x80; | |
1980 } | |
2534 | 1981 if(IS_8X8(mb_type) && mv_sample_log2 >= 2){ |
1982 int dm= 1 << (mv_sample_log2-2); | |
1983 for(i=0; i<4; i++){ | |
1984 int sx= mb_x*16 + 8*(i&1); | |
1985 int sy= mb_y*16 + 8*(i>>1); | |
1986 int xy= (mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*mv_stride) << (mv_sample_log2-1); | |
1987 //FIXME bidir | |
1988 int32_t *mv = (int32_t*)&pict->motion_val[0][xy]; | |
1989 if(mv[0] != mv[dm] || mv[dm*mv_stride] != mv[dm*(mv_stride+1)]) | |
1990 for(y=0; y<8; y++) | |
1991 pict->data[0][sx + 4 + (sy + y)*pict->linesize[0]]^= 0x80; | |
1992 if(mv[0] != mv[dm*mv_stride] || mv[dm] != mv[dm*(mv_stride+1)]) | |
1993 *(uint64_t*)(pict->data[0] + sx + (sy + 4)*pict->linesize[0])^= 0x8080808080808080ULL; | |
1994 } | |
1995 } | |
2967 | 1996 |
1685 | 1997 if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264){ |
1998 // hmm | |
1999 } | |
1285 | 2000 } |
2001 s->mbskip_table[mb_index]=0; | |
2002 } | |
2003 } | |
2004 } | |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
2005 } |
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
2006 |
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
|
2007 #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
|
2008 |
915 | 2009 static int get_sae(uint8_t *src, int ref, int stride){ |
2010 int x,y; | |
2011 int acc=0; | |
2967 | 2012 |
915 | 2013 for(y=0; y<16; y++){ |
2014 for(x=0; x<16; x++){ | |
2015 acc+= ABS(src[x+y*stride] - ref); | |
2016 } | |
2017 } | |
2967 | 2018 |
915 | 2019 return acc; |
2020 } | |
2021 | |
2022 static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride){ | |
2023 int x, y, w, h; | |
2024 int acc=0; | |
2967 | 2025 |
915 | 2026 w= s->width &~15; |
2027 h= s->height&~15; | |
2967 | 2028 |
915 | 2029 for(y=0; y<h; y+=16){ |
2030 for(x=0; x<w; x+=16){ | |
2031 int offset= x + y*stride; | |
1708 | 2032 int sad = s->dsp.sad[0](NULL, src + offset, ref + offset, stride, 16); |
915 | 2033 int mean= (s->dsp.pix_sum(src + offset, stride) + 128)>>8; |
2034 int sae = get_sae(src + offset, mean, stride); | |
2967 | 2035 |
915 | 2036 acc+= sae + 500 < sad; |
2037 } | |
2038 } | |
2039 return acc; | |
2040 } | |
2041 | |
924 | 2042 |
925 | 2043 static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){ |
1373 | 2044 AVFrame *pic=NULL; |
2427 | 2045 int64_t pts; |
924 | 2046 int i; |
903 | 2047 const int encoding_delay= s->max_b_frames; |
924 | 2048 int direct=1; |
2967 | 2049 |
2419 | 2050 if(pic_arg){ |
2427 | 2051 pts= pic_arg->pts; |
2052 pic_arg->display_picture_number= s->input_picture_number++; | |
2053 | |
2967 | 2054 if(pts != AV_NOPTS_VALUE){ |
2419 | 2055 if(s->user_specified_pts != AV_NOPTS_VALUE){ |
2637 | 2056 int64_t time= pts; |
2057 int64_t last= s->user_specified_pts; | |
2967 | 2058 |
2059 if(time <= last){ | |
2962 | 2060 av_log(s->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%"PRId64", last=%"PRId64"\n", pts, s->user_specified_pts); |
2419 | 2061 return -1; |
2062 } | |
2063 } | |
2427 | 2064 s->user_specified_pts= pts; |
2419 | 2065 }else{ |
2066 if(s->user_specified_pts != AV_NOPTS_VALUE){ | |
2967 | 2067 s->user_specified_pts= |
2637 | 2068 pts= s->user_specified_pts + 1; |
2962 | 2069 av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts); |
2419 | 2070 }else{ |
2637 | 2071 pts= pic_arg->display_picture_number; |
2419 | 2072 } |
2073 } | |
2074 } | |
2075 | |
1373 | 2076 if(pic_arg){ |
924 | 2077 if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0; |
2078 if(pic_arg->linesize[0] != s->linesize) direct=0; | |
2079 if(pic_arg->linesize[1] != s->uvlinesize) direct=0; | |
2080 if(pic_arg->linesize[2] != s->uvlinesize) direct=0; | |
2967 | 2081 |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
2082 // av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize); |
2967 | 2083 |
924 | 2084 if(direct){ |
1586 | 2085 i= ff_find_unused_picture(s, 1); |
924 | 2086 |
925 | 2087 pic= (AVFrame*)&s->picture[i]; |
1168 | 2088 pic->reference= 3; |
2967 | 2089 |
924 | 2090 for(i=0; i<4; i++){ |
2091 pic->data[i]= pic_arg->data[i]; | |
2092 pic->linesize[i]= pic_arg->linesize[i]; | |
2093 } | |
2094 alloc_picture(s, (Picture*)pic, 1); | |
2095 }else{ | |
1586 | 2096 i= ff_find_unused_picture(s, 0); |
924 | 2097 |
925 | 2098 pic= (AVFrame*)&s->picture[i]; |
1168 | 2099 pic->reference= 3; |
924 | 2100 |
2101 alloc_picture(s, (Picture*)pic, 0); | |
1539
14d01ccc0081
picture buffer cleanup, this fixes a assertion failure (if assertion checking was manualy enabled for utils.c) and a memleak at least
michael
parents:
1530
diff
changeset
|
2102 |
3068 | 2103 if( pic->data[0] + INPLACE_OFFSET == pic_arg->data[0] |
2104 && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1] | |
2105 && pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]){ | |
924 | 2106 // empty |
2107 }else{ | |
2108 int h_chroma_shift, v_chroma_shift; | |
2109 avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); | |
2967 | 2110 |
924 | 2111 for(i=0; i<3; i++){ |
2112 int src_stride= pic_arg->linesize[i]; | |
2113 int dst_stride= i ? s->uvlinesize : s->linesize; | |
2114 int h_shift= i ? h_chroma_shift : 0; | |
2115 int v_shift= i ? v_chroma_shift : 0; | |
2116 int w= s->width >>h_shift; | |
2117 int h= s->height>>v_shift; | |
2118 uint8_t *src= pic_arg->data[i]; | |
3068 | 2119 uint8_t *dst= pic->data[i] + INPLACE_OFFSET; |
2967 | 2120 |
924 | 2121 if(src_stride==dst_stride) |
2122 memcpy(dst, src, src_stride*h); | |
2123 else{ | |
2124 while(h--){ | |
2125 memcpy(dst, src, w); | |
2126 dst += dst_stride; | |
2127 src += src_stride; | |
2128 } | |
2129 } | |
2130 } | |
2131 } | |
324 | 2132 } |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
2133 copy_picture_attributes(s, pic, pic_arg); |
2427 | 2134 pic->pts= pts; //we set this here to avoid modifiying pic_arg |
1373 | 2135 } |
2967 | 2136 |
903 | 2137 /* shift buffer entries */ |
2138 for(i=1; i<MAX_PICTURE_COUNT /*s->encoding_delay+1*/; i++) | |
2139 s->input_picture[i-1]= s->input_picture[i]; | |
2967 | 2140 |
903 | 2141 s->input_picture[encoding_delay]= (Picture*)pic; |
2142 | |
2143 return 0; | |
2144 } | |
2145 | |
2381 | 2146 static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){ |
2147 int x, y, plane; | |
2148 int score=0; | |
2382 | 2149 int64_t score64=0; |
2381 | 2150 |
2151 for(plane=0; plane<3; plane++){ | |
2152 const int stride= p->linesize[plane]; | |
2153 const int bw= plane ? 1 : 2; | |
2154 for(y=0; y<s->mb_height*bw; y++){ | |
2155 for(x=0; x<s->mb_width*bw; x++){ | |
2931 | 2156 int off= p->type == FF_BUFFER_TYPE_SHARED ? 0: 16; |
2157 int v= s->dsp.frame_skip_cmp[1](s, p->data[plane] + 8*(x + y*stride)+off, ref->data[plane] + 8*(x + y*stride), stride, 8); | |
2967 | 2158 |
2382 | 2159 switch(s->avctx->frame_skip_exp){ |
2160 case 0: score= FFMAX(score, v); break; | |
2161 case 1: score+= ABS(v);break; | |
2162 case 2: score+= v*v;break; | |
2163 case 3: score64+= ABS(v*v*(int64_t)v);break; | |
2164 case 4: score64+= v*v*(int64_t)(v*v);break; | |
2165 } | |
2381 | 2166 } |
2167 } | |
2168 } | |
2967 | 2169 |
2382 | 2170 if(score) score64= score; |
2171 | |
2172 if(score64 < s->avctx->frame_skip_threshold) | |
2381 | 2173 return 1; |
2382 | 2174 if(score64 < ((s->avctx->frame_skip_factor * (int64_t)s->lambda)>>8)) |
2381 | 2175 return 1; |
2176 return 0; | |
2177 } | |
2178 | |
2988 | 2179 static int estimate_best_b_count(MpegEncContext *s){ |
2180 AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id); | |
2181 AVCodecContext *c= avcodec_alloc_context(); | |
2182 AVFrame input[FF_MAX_B_FRAMES+2]; | |
2990
0300c2647bc3
support downscaling frames for dynamic b frame decission
michael
parents:
2988
diff
changeset
|
2183 const int scale= s->avctx->brd_scale; |
3068 | 2184 int i, j, out_size, p_lambda, b_lambda, lambda2; |
2990
0300c2647bc3
support downscaling frames for dynamic b frame decission
michael
parents:
2988
diff
changeset
|
2185 int outbuf_size= s->width * s->height; //FIXME |
2988 | 2186 uint8_t *outbuf= av_malloc(outbuf_size); |
2187 int64_t best_rd= INT64_MAX; | |
2188 int best_b_count= -1; | |
3068 | 2189 |
3245 | 2190 assert(scale>=0 && scale <=3); |
2191 | |
3068 | 2192 // emms_c(); |
2193 p_lambda= s->last_lambda_for[P_TYPE]; //s->next_picture_ptr->quality; | |
2194 b_lambda= s->last_lambda_for[B_TYPE]; //p_lambda *ABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset; | |
2195 if(!b_lambda) b_lambda= p_lambda; //FIXME we should do this somewhere else | |
2196 lambda2= (b_lambda*b_lambda + (1<<FF_LAMBDA_SHIFT)/2 ) >> FF_LAMBDA_SHIFT; | |
2988 | 2197 |
2198 c->width = s->width >> scale; | |
2199 c->height= s->height>> scale; | |
2200 c->flags= CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | CODEC_FLAG_INPUT_PRESERVED /*| CODEC_FLAG_EMU_EDGE*/; | |
2201 c->flags|= s->avctx->flags & CODEC_FLAG_QPEL; | |
2202 c->mb_decision= s->avctx->mb_decision; | |
2203 c->me_cmp= s->avctx->me_cmp; | |
2204 c->mb_cmp= s->avctx->mb_cmp; | |
2205 c->me_sub_cmp= s->avctx->me_sub_cmp; | |
2206 c->pix_fmt = PIX_FMT_YUV420P; | |
2207 c->time_base= s->avctx->time_base; | |
2208 c->max_b_frames= s->max_b_frames; | |
2209 | |
2210 if (avcodec_open(c, codec) < 0) | |
2211 return -1; | |
2212 | |
2213 for(i=0; i<s->max_b_frames+2; i++){ | |
2214 int ysize= c->width*c->height; | |
2215 int csize= (c->width/2)*(c->height/2); | |
3068 | 2216 Picture pre_input, *pre_input_ptr= i ? s->input_picture[i-1] : s->next_picture_ptr; |
2217 | |
2218 if(pre_input_ptr) | |
2219 pre_input= *pre_input_ptr; | |
2220 | |
2221 if(pre_input.type != FF_BUFFER_TYPE_SHARED && i){ | |
2222 pre_input.data[0]+=INPLACE_OFFSET; | |
2223 pre_input.data[1]+=INPLACE_OFFSET; | |
2224 pre_input.data[2]+=INPLACE_OFFSET; | |
2225 } | |
2988 | 2226 |
2227 avcodec_get_frame_defaults(&input[i]); | |
2228 input[i].data[0]= av_malloc(ysize + 2*csize); | |
2229 input[i].data[1]= input[i].data[0] + ysize; | |
2230 input[i].data[2]= input[i].data[1] + csize; | |
2231 input[i].linesize[0]= c->width; | |
2232 input[i].linesize[1]= | |
2233 input[i].linesize[2]= c->width/2; | |
2234 | |
3245 | 2235 if(!i || s->input_picture[i-1]){ |
2236 s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0], pre_input.data[0], pre_input.linesize[0], c->width, c->height); | |
2237 s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1], pre_input.data[1], pre_input.linesize[1], c->width>>1, c->height>>1); | |
2238 s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2], pre_input.data[2], pre_input.linesize[2], c->width>>1, c->height>>1); | |
2239 } | |
2988 | 2240 } |
2241 | |
2242 for(j=0; j<s->max_b_frames+1; j++){ | |
2243 int64_t rd=0; | |
2244 | |
2245 if(!s->input_picture[j]) | |
2246 break; | |
2247 | |
2248 c->error[0]= c->error[1]= c->error[2]= 0; | |
2249 | |
2250 input[0].pict_type= I_TYPE; | |
3068 | 2251 input[0].quality= 1 * FF_QP2LAMBDA; |
2988 | 2252 out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[0]); |
3068 | 2253 // rd += (out_size * lambda2) >> FF_LAMBDA_SHIFT; |
2988 | 2254 |
2255 for(i=0; i<s->max_b_frames+1; i++){ | |
2256 int is_p= i % (j+1) == j || i==s->max_b_frames; | |
2257 | |
2258 input[i+1].pict_type= is_p ? P_TYPE : B_TYPE; | |
3068 | 2259 input[i+1].quality= is_p ? p_lambda : b_lambda; |
2988 | 2260 out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[i+1]); |
3068 | 2261 rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3); |
2988 | 2262 } |
2263 | |
2264 /* get the delayed frames */ | |
2265 while(out_size){ | |
2266 out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL); | |
3068 | 2267 rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3); |
2988 | 2268 } |
2269 | |
2270 rd += c->error[0] + c->error[1] + c->error[2]; | |
2271 | |
2272 if(rd < best_rd){ | |
2273 best_rd= rd; | |
2274 best_b_count= j; | |
2275 } | |
2276 } | |
2277 | |
2278 av_freep(&outbuf); | |
2279 avcodec_close(c); | |
2280 av_freep(&c); | |
2281 | |
2282 for(i=0; i<s->max_b_frames+2; i++){ | |
2283 av_freep(&input[i].data[0]); | |
2284 } | |
2285 | |
2286 return best_b_count; | |
2287 } | |
2288 | |
903 | 2289 static void select_input_picture(MpegEncContext *s){ |
2290 int i; | |
924 | 2291 |
903 | 2292 for(i=1; i<MAX_PICTURE_COUNT; i++) |
2293 s->reordered_input_picture[i-1]= s->reordered_input_picture[i]; | |
2294 s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL; | |
2295 | |
2764 | 2296 /* set next picture type & ordering */ |
903 | 2297 if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){ |
1138 | 2298 if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture_ptr==NULL || s->intra_only){ |
915 | 2299 s->reordered_input_picture[0]= s->input_picture[0]; |
2300 s->reordered_input_picture[0]->pict_type= I_TYPE; | |
1705 | 2301 s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; |
915 | 2302 }else{ |
2303 int b_frames; | |
2381 | 2304 |
2305 if(s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor){ | |
2931 | 2306 if(s->picture_in_gop_number < s->gop_size && skip_check(s, s->input_picture[0], s->next_picture_ptr)){ |
2307 //FIXME check that te gop check above is +-1 correct | |
2381 | 2308 //av_log(NULL, AV_LOG_DEBUG, "skip %p %Ld\n", s->input_picture[0]->data[0], s->input_picture[0]->pts); |
2967 | 2309 |
2381 | 2310 if(s->input_picture[0]->type == FF_BUFFER_TYPE_SHARED){ |
2311 for(i=0; i<4; i++) | |
2312 s->input_picture[0]->data[i]= NULL; | |
2967 | 2313 s->input_picture[0]->type= 0; |
2381 | 2314 }else{ |
2967 | 2315 assert( s->input_picture[0]->type==FF_BUFFER_TYPE_USER |
2381 | 2316 || s->input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); |
2967 | 2317 |
2381 | 2318 s->avctx->release_buffer(s->avctx, (AVFrame*)s->input_picture[0]); |
2319 } | |
2967 | 2320 |
2931 | 2321 emms_c(); |
2322 ff_vbv_update(s, 0); | |
2381 | 2323 |
2324 goto no_output_pic; | |
2325 } | |
2326 } | |
2327 | |
915 | 2328 if(s->flags&CODEC_FLAG_PASS2){ |
2329 for(i=0; i<s->max_b_frames+1; i++){ | |
2330 int pict_num= s->input_picture[0]->display_picture_number + i; | |
2364
f8a229dfa2e8
check num_entries too to avoid reading over the array end and dont check i>0 it must be >0 there
michael
parents:
2363
diff
changeset
|
2331 |
2967 | 2332 if(pict_num >= s->rc_context.num_entries) |
2364
f8a229dfa2e8
check num_entries too to avoid reading over the array end and dont check i>0 it must be >0 there
michael
parents:
2363
diff
changeset
|
2333 break; |
2363
e0bda0b8359a
Fixes a segfault when flushing delayed B-frames on the 2nd pass. patch by (Loren Merritt <lorenm.u@washington@edu>)
michael
parents:
2345
diff
changeset
|
2334 if(!s->input_picture[i]){ |
2364
f8a229dfa2e8
check num_entries too to avoid reading over the array end and dont check i>0 it must be >0 there
michael
parents:
2363
diff
changeset
|
2335 s->rc_context.entry[pict_num-1].new_pict_type = P_TYPE; |
2363
e0bda0b8359a
Fixes a segfault when flushing delayed B-frames on the 2nd pass. patch by (Loren Merritt <lorenm.u@washington@edu>)
michael
parents:
2345
diff
changeset
|
2336 break; |
e0bda0b8359a
Fixes a segfault when flushing delayed B-frames on the 2nd pass. patch by (Loren Merritt <lorenm.u@washington@edu>)
michael
parents:
2345
diff
changeset
|
2337 } |
2364
f8a229dfa2e8
check num_entries too to avoid reading over the array end and dont check i>0 it must be >0 there
michael
parents:
2363
diff
changeset
|
2338 |
2967 | 2339 s->input_picture[i]->pict_type= |
2364
f8a229dfa2e8
check num_entries too to avoid reading over the array end and dont check i>0 it must be >0 there
michael
parents:
2363
diff
changeset
|
2340 s->rc_context.entry[pict_num].new_pict_type; |
915 | 2341 } |
2342 } | |
924 | 2343 |
2297 | 2344 if(s->avctx->b_frame_strategy==0){ |
915 | 2345 b_frames= s->max_b_frames; |
1373 | 2346 while(b_frames && !s->input_picture[b_frames]) b_frames--; |
1687 | 2347 }else if(s->avctx->b_frame_strategy==1){ |
915 | 2348 for(i=1; i<s->max_b_frames+1; i++){ |
1373 | 2349 if(s->input_picture[i] && s->input_picture[i]->b_frame_score==0){ |
2967 | 2350 s->input_picture[i]->b_frame_score= |
2351 get_intra_count(s, s->input_picture[i ]->data[0], | |
924 | 2352 s->input_picture[i-1]->data[0], s->linesize) + 1; |
915 | 2353 } |
2354 } | |
2728 | 2355 for(i=0; i<s->max_b_frames+1; i++){ |
1373 | 2356 if(s->input_picture[i]==NULL || s->input_picture[i]->b_frame_score - 1 > s->mb_num/40) break; |
915 | 2357 } |
2967 | 2358 |
915 | 2359 b_frames= FFMAX(0, i-1); |
2967 | 2360 |
915 | 2361 /* reset scores */ |
2362 for(i=0; i<b_frames+1; i++){ | |
2363 s->input_picture[i]->b_frame_score=0; | |
2364 } | |
2988 | 2365 }else if(s->avctx->b_frame_strategy==2){ |
2366 b_frames= estimate_best_b_count(s); | |
915 | 2367 }else{ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
2368 av_log(s->avctx, AV_LOG_ERROR, "illegal b frame strategy\n"); |
915 | 2369 b_frames=0; |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2370 } |
915 | 2371 |
2372 emms_c(); | |
2373 //static int b_count=0; | |
2374 //b_count+= b_frames; | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
2375 //av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count); |
2297 | 2376 |
2377 for(i= b_frames - 1; i>=0; i--){ | |
2378 int type= s->input_picture[i]->pict_type; | |
2379 if(type && type != B_TYPE) | |
2380 b_frames= i; | |
2381 } | |
2382 if(s->input_picture[b_frames]->pict_type == B_TYPE && b_frames == s->max_b_frames){ | |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
2383 av_log(s->avctx, AV_LOG_ERROR, "warning, too many b frames in a row\n"); |
2297 | 2384 } |
2385 | |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2386 if(s->picture_in_gop_number + b_frames >= s->gop_size){ |
2298 | 2387 if((s->flags2 & CODEC_FLAG2_STRICT_GOP) && s->gop_size > s->picture_in_gop_number){ |
2388 b_frames= s->gop_size - s->picture_in_gop_number - 1; | |
2389 }else{ | |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2390 if(s->flags & CODEC_FLAG_CLOSED_GOP) |
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2391 b_frames=0; |
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2392 s->input_picture[b_frames]->pict_type= I_TYPE; |
2298 | 2393 } |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2394 } |
2967 | 2395 |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2396 if( (s->flags & CODEC_FLAG_CLOSED_GOP) |
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2397 && b_frames |
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2398 && s->input_picture[b_frames]->pict_type== I_TYPE) |
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2399 b_frames--; |
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2400 |
915 | 2401 s->reordered_input_picture[0]= s->input_picture[b_frames]; |
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2402 if(s->reordered_input_picture[0]->pict_type != I_TYPE) |
915 | 2403 s->reordered_input_picture[0]->pict_type= P_TYPE; |
1705 | 2404 s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; |
915 | 2405 for(i=0; i<b_frames; i++){ |
2406 s->reordered_input_picture[i+1]= s->input_picture[i]; | |
2407 s->reordered_input_picture[i+1]->pict_type= B_TYPE; | |
1705 | 2408 s->reordered_input_picture[i+1]->coded_picture_number= s->coded_picture_number++; |
903 | 2409 } |
324 | 2410 } |
2411 } | |
2381 | 2412 no_output_pic: |
903 | 2413 if(s->reordered_input_picture[0]){ |
1168 | 2414 s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=B_TYPE ? 3 : 0; |
1138 | 2415 |
1539
14d01ccc0081
picture buffer cleanup, this fixes a assertion failure (if assertion checking was manualy enabled for utils.c) and a memleak at least
michael
parents:
1530
diff
changeset
|
2416 copy_picture(&s->new_picture, s->reordered_input_picture[0]); |
924 | 2417 |
2418 if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_SHARED){ | |
2764 | 2419 // input is a shared pix, so we can't modifiy it -> alloc a new one & ensure that the shared one is reuseable |
2967 | 2420 |
1586 | 2421 int i= ff_find_unused_picture(s, 0); |
924 | 2422 Picture *pic= &s->picture[i]; |
2423 | |
2424 /* mark us unused / free shared pic */ | |
2425 for(i=0; i<4; i++) | |
2426 s->reordered_input_picture[0]->data[i]= NULL; | |
2427 s->reordered_input_picture[0]->type= 0; | |
2967 | 2428 |
1702 | 2429 pic->reference = s->reordered_input_picture[0]->reference; |
2967 | 2430 |
924 | 2431 alloc_picture(s, pic, 0); |
2432 | |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1948
diff
changeset
|
2433 copy_picture_attributes(s, (AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]); |
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1948
diff
changeset
|
2434 |
1138 | 2435 s->current_picture_ptr= pic; |
924 | 2436 }else{ |
1138 | 2437 // input is not a shared pix -> reuse buffer for current_pix |
2438 | |
2967 | 2439 assert( s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_USER |
924 | 2440 || s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); |
2967 | 2441 |
1138 | 2442 s->current_picture_ptr= s->reordered_input_picture[0]; |
924 | 2443 for(i=0; i<4; i++){ |
3068 | 2444 s->new_picture.data[i]+= INPLACE_OFFSET; |
924 | 2445 } |
903 | 2446 } |
1539
14d01ccc0081
picture buffer cleanup, this fixes a assertion failure (if assertion checking was manualy enabled for utils.c) and a memleak at least
michael
parents:
1530
diff
changeset
|
2447 copy_picture(&s->current_picture, s->current_picture_ptr); |
2967 | 2448 |
903 | 2449 s->picture_number= s->new_picture.display_picture_number; |
2450 //printf("dpn:%d\n", s->picture_number); | |
2451 }else{ | |
2452 memset(&s->new_picture, 0, sizeof(Picture)); | |
324 | 2453 } |
2454 } | |
2455 | |
0 | 2456 int MPV_encode_picture(AVCodecContext *avctx, |
2457 unsigned char *buf, int buf_size, void *data) | |
2458 { | |
2459 MpegEncContext *s = avctx->priv_data; | |
925 | 2460 AVFrame *pic_arg = data; |
1684 | 2461 int i, stuffing_count; |
0 | 2462 |
2442 | 2463 if(avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUVJ420P){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
2464 av_log(avctx, AV_LOG_ERROR, "this codec supports only YUV420P\n"); |
1397 | 2465 return -1; |
2466 } | |
2967 | 2467 |
1799 | 2468 for(i=0; i<avctx->thread_count; i++){ |
1838 | 2469 int start_y= s->thread_context[i]->start_mb_y; |
2470 int end_y= s->thread_context[i]-> end_mb_y; | |
1799 | 2471 int h= s->mb_height; |
2807
3137aae854c9
Fix for overflow issue in mpegvideo.c patch by (Martin Boehme: boehme, inb uni-luebeck de)
michael
parents:
2792
diff
changeset
|
2472 uint8_t *start= buf + (size_t)(((int64_t) buf_size)*start_y/h); |
3137aae854c9
Fix for overflow issue in mpegvideo.c patch by (Martin Boehme: boehme, inb uni-luebeck de)
michael
parents:
2792
diff
changeset
|
2473 uint8_t *end = buf + (size_t)(((int64_t) buf_size)* end_y/h); |
1799 | 2474 |
2475 init_put_bits(&s->thread_context[i]->pb, start, end - start); | |
2476 } | |
0 | 2477 |
903 | 2478 s->picture_in_gop_number++; |
2479 | |
2243
b8bad8bbbc64
check if the user specified timestamps are strictly monotone
michael
parents:
2235
diff
changeset
|
2480 if(load_input_picture(s, pic_arg) < 0) |
b8bad8bbbc64
check if the user specified timestamps are strictly monotone
michael
parents:
2235
diff
changeset
|
2481 return -1; |
2967 | 2482 |
903 | 2483 select_input_picture(s); |
2967 | 2484 |
324 | 2485 /* output? */ |
903 | 2486 if(s->new_picture.data[0]){ |
2487 s->pict_type= s->new_picture.pict_type; | |
2488 //emms_c(); | |
2489 //printf("qs:%f %f %d\n", s->new_picture.quality, s->current_picture.quality, s->qscale); | |
553 | 2490 MPV_frame_start(s, avctx); |
286 | 2491 |
324 | 2492 encode_picture(s, s->picture_number); |
2967 | 2493 |
376 | 2494 avctx->real_pict_num = s->picture_number; |
324 | 2495 avctx->header_bits = s->header_bits; |
2496 avctx->mv_bits = s->mv_bits; | |
2497 avctx->misc_bits = s->misc_bits; | |
2498 avctx->i_tex_bits = s->i_tex_bits; | |
2499 avctx->p_tex_bits = s->p_tex_bits; | |
2500 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
|
2501 avctx->p_count = s->mb_num - s->i_count - s->skip_count; //FIXME f/b_count in avctx |
324 | 2502 avctx->skip_count = s->skip_count; |
0 | 2503 |
324 | 2504 MPV_frame_end(s); |
2505 | |
2506 if (s->out_format == FMT_MJPEG) | |
2507 mjpeg_picture_trailer(s); | |
2967 | 2508 |
329 | 2509 if(s->flags&CODEC_FLAG_PASS1) |
2510 ff_write_pass1_stats(s); | |
1138 | 2511 |
2512 for(i=0; i<4; i++){ | |
2955 | 2513 s->current_picture_ptr->error[i]= s->current_picture.error[i]; |
1138 | 2514 avctx->error[i] += s->current_picture_ptr->error[i]; |
2515 } | |
1766 | 2516 |
2428
548c87c06dbb
assertion about bits statistic and minor bits stat fix
michael
parents:
2427
diff
changeset
|
2517 if(s->flags&CODEC_FLAG_PASS1) |
548c87c06dbb
assertion about bits statistic and minor bits stat fix
michael
parents:
2427
diff
changeset
|
2518 assert(avctx->header_bits + avctx->mv_bits + avctx->misc_bits + avctx->i_tex_bits + avctx->p_tex_bits == put_bits_count(&s->pb)); |
1684 | 2519 flush_put_bits(&s->pb); |
1801
3f26dfb3eba4
replace a few pbBufPtr() by put_bits_count(), one of them was actually wrong
michael
parents:
1799
diff
changeset
|
2520 s->frame_bits = put_bits_count(&s->pb); |
1766 | 2521 |
2522 stuffing_count= ff_vbv_update(s, s->frame_bits); | |
2523 if(stuffing_count){ | |
2422 | 2524 if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < stuffing_count + 50){ |
2525 av_log(s->avctx, AV_LOG_ERROR, "stuffing too large\n"); | |
2526 return -1; | |
2527 } | |
2528 | |
1766 | 2529 switch(s->codec_id){ |
2530 case CODEC_ID_MPEG1VIDEO: | |
2531 case CODEC_ID_MPEG2VIDEO: | |
2532 while(stuffing_count--){ | |
2533 put_bits(&s->pb, 8, 0); | |
2534 } | |
2535 break; | |
2536 case CODEC_ID_MPEG4: | |
2537 put_bits(&s->pb, 16, 0); | |
2538 put_bits(&s->pb, 16, 0x1C3); | |
2539 stuffing_count -= 4; | |
2540 while(stuffing_count--){ | |
2541 put_bits(&s->pb, 8, 0xFF); | |
2542 } | |
2543 break; | |
2544 default: | |
2545 av_log(s->avctx, AV_LOG_ERROR, "vbv buffer overflow\n"); | |
2546 } | |
2547 flush_put_bits(&s->pb); | |
1801
3f26dfb3eba4
replace a few pbBufPtr() by put_bits_count(), one of them was actually wrong
michael
parents:
1799
diff
changeset
|
2548 s->frame_bits = put_bits_count(&s->pb); |
1766 | 2549 } |
2550 | |
2967 | 2551 /* update mpeg1/2 vbv_delay for CBR */ |
1907 | 2552 if(s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate && s->out_format == FMT_MPEG1 |
2553 && 90000LL * (avctx->rc_buffer_size-1) <= s->avctx->rc_max_rate*0xFFFFLL){ | |
1766 | 2554 int vbv_delay; |
2555 | |
2556 assert(s->repeat_first_field==0); | |
2967 | 2557 |
1766 | 2558 vbv_delay= lrintf(90000 * s->rc_context.buffer_index / s->avctx->rc_max_rate); |
2559 assert(vbv_delay < 0xFFFF); | |
2560 | |
2561 s->vbv_delay_ptr[0] &= 0xF8; | |
2562 s->vbv_delay_ptr[0] |= vbv_delay>>13; | |
2563 s->vbv_delay_ptr[1] = vbv_delay>>5; | |
2564 s->vbv_delay_ptr[2] &= 0x07; | |
2565 s->vbv_delay_ptr[2] |= vbv_delay<<3; | |
2566 } | |
2567 s->total_bits += s->frame_bits; | |
2568 avctx->frame_bits = s->frame_bits; | |
2569 }else{ | |
2570 assert((pbBufPtr(&s->pb) == s->pb.buf)); | |
2571 s->frame_bits=0; | |
1684 | 2572 } |
1766 | 2573 assert((s->frame_bits&7)==0); |
2967 | 2574 |
1684 | 2575 return s->frame_bits/8; |
0 | 2576 } |
2577 | |
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
|
2578 #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
|
2579 |
255 | 2580 static inline void gmc1_motion(MpegEncContext *s, |
1064 | 2581 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2582 uint8_t **ref_picture) |
255 | 2583 { |
1064 | 2584 uint8_t *ptr; |
556 | 2585 int offset, src_x, src_y, linesize, uvlinesize; |
255 | 2586 int motion_x, motion_y; |
566 | 2587 int emu=0; |
255 | 2588 |
2589 motion_x= s->sprite_offset[0][0]; | |
2590 motion_y= s->sprite_offset[0][1]; | |
2591 src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
2592 src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
2593 motion_x<<=(3-s->sprite_warping_accuracy); | |
2594 motion_y<<=(3-s->sprite_warping_accuracy); | |
2595 src_x = clip(src_x, -16, s->width); | |
2596 if (src_x == s->width) | |
2597 motion_x =0; | |
2598 src_y = clip(src_y, -16, s->height); | |
2599 if (src_y == s->height) | |
2600 motion_y =0; | |
753 | 2601 |
255 | 2602 linesize = s->linesize; |
556 | 2603 uvlinesize = s->uvlinesize; |
2967 | 2604 |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2605 ptr = ref_picture[0] + (src_y * linesize) + src_x; |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2606 |
566 | 2607 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
1542
576861d6343a
emu_edge checks simplification and avoid redundant checks for mpeg1/2 if emu_edge is set
michael
parents:
1539
diff
changeset
|
2608 if( (unsigned)src_x >= s->h_edge_pos - 17 |
576861d6343a
emu_edge checks simplification and avoid redundant checks for mpeg1/2 if emu_edge is set
michael
parents:
1539
diff
changeset
|
2609 || (unsigned)src_y >= s->v_edge_pos - 17){ |
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2610 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos); |
566 | 2611 ptr= s->edge_emu_buffer; |
2612 } | |
2613 } | |
2967 | 2614 |
753 | 2615 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
|
2616 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
|
2617 s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); |
753 | 2618 }else{ |
2619 int dxy; | |
2967 | 2620 |
753 | 2621 dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2); |
2622 if (s->no_rounding){ | |
2979 | 2623 s->dsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16); |
753 | 2624 }else{ |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2625 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
|
2626 } |
753 | 2627 } |
2967 | 2628 |
753 | 2629 if(s->flags&CODEC_FLAG_GRAY) return; |
255 | 2630 |
2631 motion_x= s->sprite_offset[1][0]; | |
2632 motion_y= s->sprite_offset[1][1]; | |
2633 src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
2634 src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
2635 motion_x<<=(3-s->sprite_warping_accuracy); | |
2636 motion_y<<=(3-s->sprite_warping_accuracy); | |
2637 src_x = clip(src_x, -8, s->width>>1); | |
2638 if (src_x == s->width>>1) | |
2639 motion_x =0; | |
2640 src_y = clip(src_y, -8, s->height>>1); | |
2641 if (src_y == s->height>>1) | |
2642 motion_y =0; | |
2643 | |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2644 offset = (src_y * uvlinesize) + src_x; |
255 | 2645 ptr = ref_picture[1] + offset; |
1002 | 2646 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
1542
576861d6343a
emu_edge checks simplification and avoid redundant checks for mpeg1/2 if emu_edge is set
michael
parents:
1539
diff
changeset
|
2647 if( (unsigned)src_x >= (s->h_edge_pos>>1) - 9 |
576861d6343a
emu_edge checks simplification and avoid redundant checks for mpeg1/2 if emu_edge is set
michael
parents:
1539
diff
changeset
|
2648 || (unsigned)src_y >= (s->v_edge_pos>>1) - 9){ |
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2649 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
1002 | 2650 ptr= s->edge_emu_buffer; |
2651 emu=1; | |
2652 } | |
566 | 2653 } |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2654 s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); |
2967 | 2655 |
255 | 2656 ptr = ref_picture[2] + offset; |
566 | 2657 if(emu){ |
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2658 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
566 | 2659 ptr= s->edge_emu_buffer; |
2660 } | |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2661 s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); |
2967 | 2662 |
255 | 2663 return; |
2664 } | |
2665 | |
753 | 2666 static inline void gmc_motion(MpegEncContext *s, |
1064 | 2667 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2668 uint8_t **ref_picture) |
753 | 2669 { |
1064 | 2670 uint8_t *ptr; |
753 | 2671 int linesize, uvlinesize; |
2672 const int a= s->sprite_warping_accuracy; | |
2673 int ox, oy; | |
2674 | |
2675 linesize = s->linesize; | |
2676 uvlinesize = s->uvlinesize; | |
2677 | |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2678 ptr = ref_picture[0]; |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2679 |
753 | 2680 ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16; |
2681 oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16; | |
2682 | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2683 s->dsp.gmc(dest_y, ptr, linesize, 16, |
2967 | 2684 ox, |
2685 oy, | |
753 | 2686 s->sprite_delta[0][0], s->sprite_delta[0][1], |
2967 | 2687 s->sprite_delta[1][0], s->sprite_delta[1][1], |
753 | 2688 a+1, (1<<(2*a+1)) - s->no_rounding, |
2689 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
|
2690 s->dsp.gmc(dest_y+8, ptr, linesize, 16, |
2967 | 2691 ox + s->sprite_delta[0][0]*8, |
2692 oy + s->sprite_delta[1][0]*8, | |
753 | 2693 s->sprite_delta[0][0], s->sprite_delta[0][1], |
2967 | 2694 s->sprite_delta[1][0], s->sprite_delta[1][1], |
753 | 2695 a+1, (1<<(2*a+1)) - s->no_rounding, |
2696 s->h_edge_pos, s->v_edge_pos); | |
2697 | |
2698 if(s->flags&CODEC_FLAG_GRAY) return; | |
2699 | |
2700 ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8; | |
2701 oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8; | |
2702 | |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2703 ptr = ref_picture[1]; |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2704 s->dsp.gmc(dest_cb, ptr, uvlinesize, 8, |
2967 | 2705 ox, |
2706 oy, | |
753 | 2707 s->sprite_delta[0][0], s->sprite_delta[0][1], |
2967 | 2708 s->sprite_delta[1][0], s->sprite_delta[1][1], |
753 | 2709 a+1, (1<<(2*a+1)) - s->no_rounding, |
2710 s->h_edge_pos>>1, s->v_edge_pos>>1); | |
2967 | 2711 |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2712 ptr = ref_picture[2]; |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2713 s->dsp.gmc(dest_cr, ptr, uvlinesize, 8, |
2967 | 2714 ox, |
2715 oy, | |
753 | 2716 s->sprite_delta[0][0], s->sprite_delta[0][1], |
2967 | 2717 s->sprite_delta[1][0], s->sprite_delta[1][1], |
753 | 2718 a+1, (1<<(2*a+1)) - s->no_rounding, |
2719 s->h_edge_pos>>1, s->v_edge_pos>>1); | |
2720 } | |
2721 | |
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2722 /** |
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2723 * Copies a rectangular area of samples to a temporary buffer and replicates the boarder samples. |
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2724 * @param buf destination buffer |
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2725 * @param src source buffer |
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2726 * @param linesize number of bytes between 2 vertically adjacent samples in both the source and destination buffers |
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2727 * @param block_w width of block |
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2728 * @param block_h height of block |
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2729 * @param src_x x coordinate of the top left sample of the block in the source buffer |
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2730 * @param src_y y coordinate of the top left sample of the block in the source buffer |
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2731 * @param w width of the source buffer |
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2732 * @param h height of the source buffer |
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2733 */ |
2967 | 2734 void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h, |
553 | 2735 int src_x, int src_y, int w, int h){ |
2736 int x, y; | |
2737 int start_y, start_x, end_y, end_x; | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2738 |
553 | 2739 if(src_y>= h){ |
2740 src+= (h-1-src_y)*linesize; | |
2741 src_y=h-1; | |
554 | 2742 }else if(src_y<=-block_h){ |
2743 src+= (1-block_h-src_y)*linesize; | |
2744 src_y=1-block_h; | |
553 | 2745 } |
2746 if(src_x>= w){ | |
2747 src+= (w-1-src_x); | |
2748 src_x=w-1; | |
554 | 2749 }else if(src_x<=-block_w){ |
2750 src+= (1-block_w-src_x); | |
2751 src_x=1-block_w; | |
553 | 2752 } |
2753 | |
847 | 2754 start_y= FFMAX(0, -src_y); |
2755 start_x= FFMAX(0, -src_x); | |
2756 end_y= FFMIN(block_h, h-src_y); | |
2757 end_x= FFMIN(block_w, w-src_x); | |
566 | 2758 |
553 | 2759 // copy existing part |
2760 for(y=start_y; y<end_y; y++){ | |
2761 for(x=start_x; x<end_x; x++){ | |
2762 buf[x + y*linesize]= src[x + y*linesize]; | |
2763 } | |
2764 } | |
2765 | |
2766 //top | |
2767 for(y=0; y<start_y; y++){ | |
2768 for(x=start_x; x<end_x; x++){ | |
2769 buf[x + y*linesize]= buf[x + start_y*linesize]; | |
2770 } | |
2771 } | |
2772 | |
2773 //bottom | |
2774 for(y=end_y; y<block_h; y++){ | |
2775 for(x=start_x; x<end_x; x++){ | |
2776 buf[x + y*linesize]= buf[x + (end_y-1)*linesize]; | |
2777 } | |
2778 } | |
2967 | 2779 |
553 | 2780 for(y=0; y<block_h; y++){ |
2781 //left | |
2782 for(x=0; x<start_x; x++){ | |
2783 buf[x + y*linesize]= buf[start_x + y*linesize]; | |
2784 } | |
2967 | 2785 |
553 | 2786 //right |
2787 for(x=end_x; x<block_w; x++){ | |
2788 buf[x + y*linesize]= buf[end_x - 1 + y*linesize]; | |
2789 } | |
2790 } | |
2791 } | |
2792 | |
2967 | 2793 static inline int hpel_motion(MpegEncContext *s, |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2794 uint8_t *dest, uint8_t *src, |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2795 int field_based, int field_select, |
1633 | 2796 int src_x, int src_y, |
2797 int width, int height, int stride, | |
2798 int h_edge_pos, int v_edge_pos, | |
2799 int w, int h, op_pixels_func *pix_op, | |
2800 int motion_x, int motion_y) | |
2801 { | |
2802 int dxy; | |
2803 int emu=0; | |
2804 | |
2805 dxy = ((motion_y & 1) << 1) | (motion_x & 1); | |
2806 src_x += motion_x >> 1; | |
2807 src_y += motion_y >> 1; | |
2967 | 2808 |
1633 | 2809 /* WARNING: do no forget half pels */ |
2810 src_x = clip(src_x, -16, width); //FIXME unneeded for emu? | |
2811 if (src_x == width) | |
2812 dxy &= ~1; | |
2813 src_y = clip(src_y, -16, height); | |
2814 if (src_y == height) | |
2815 dxy &= ~2; | |
2816 src += src_y * stride + src_x; | |
2817 | |
2818 if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){ | |
2819 if( (unsigned)src_x > h_edge_pos - (motion_x&1) - w | |
2820 || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){ | |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2821 ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based, |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2822 src_x, src_y<<field_based, h_edge_pos, s->v_edge_pos); |
1633 | 2823 src= s->edge_emu_buffer; |
2824 emu=1; | |
2825 } | |
2826 } | |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2827 if(field_select) |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2828 src += s->linesize; |
1633 | 2829 pix_op[dxy](dest, src, stride, h); |
2830 return emu; | |
2831 } | |
553 | 2832 |
2967 | 2833 static inline int hpel_motion_lowres(MpegEncContext *s, |
2292 | 2834 uint8_t *dest, uint8_t *src, |
2835 int field_based, int field_select, | |
2836 int src_x, int src_y, | |
2837 int width, int height, int stride, | |
2838 int h_edge_pos, int v_edge_pos, | |
2839 int w, int h, h264_chroma_mc_func *pix_op, | |
2840 int motion_x, int motion_y) | |
2841 { | |
2842 const int lowres= s->avctx->lowres; | |
2843 const int s_mask= (2<<lowres)-1; | |
2844 int emu=0; | |
2845 int sx, sy; | |
2846 | |
2847 if(s->quarter_sample){ | |
2848 motion_x/=2; | |
2849 motion_y/=2; | |
2850 } | |
2851 | |
2852 sx= motion_x & s_mask; | |
2853 sy= motion_y & s_mask; | |
2854 src_x += motion_x >> (lowres+1); | |
2855 src_y += motion_y >> (lowres+1); | |
2967 | 2856 |
2292 | 2857 src += src_y * stride + src_x; |
2858 | |
2859 if( (unsigned)src_x > h_edge_pos - (!!sx) - w | |
2860 || (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){ | |
2861 ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based, | |
2862 src_x, src_y<<field_based, h_edge_pos, v_edge_pos); | |
2863 src= s->edge_emu_buffer; | |
2864 emu=1; | |
2865 } | |
2866 | |
2867 sx <<= 2 - lowres; | |
2868 sy <<= 2 - lowres; | |
2869 if(field_select) | |
2870 src += s->linesize; | |
2871 pix_op[lowres](dest, src, stride, h, sx, sy); | |
2872 return emu; | |
2873 } | |
2874 | |
0 | 2875 /* apply one mpeg motion vector to the three components */ |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2876 static always_inline void mpeg_motion(MpegEncContext *s, |
1064 | 2877 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2878 int field_based, int bottom_field, int field_select, |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2879 uint8_t **ref_picture, op_pixels_func (*pix_op)[4], |
0 | 2880 int motion_x, int motion_y, int h) |
2881 { | |
1846 | 2882 uint8_t *ptr_y, *ptr_cb, *ptr_cr; |
2883 int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize; | |
2967 | 2884 |
2885 #if 0 | |
255 | 2886 if(s->quarter_sample) |
2887 { | |
2888 motion_x>>=1; | |
2889 motion_y>>=1; | |
2890 } | |
651 | 2891 #endif |
1633 | 2892 |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
2893 v_edge_pos = s->v_edge_pos >> field_based; |
1846 | 2894 linesize = s->current_picture.linesize[0] << field_based; |
1138 | 2895 uvlinesize = s->current_picture.linesize[1] << field_based; |
1633 | 2896 |
1846 | 2897 dxy = ((motion_y & 1) << 1) | (motion_x & 1); |
2898 src_x = s->mb_x* 16 + (motion_x >> 1); | |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2899 src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1); |
485 | 2900 |
0 | 2901 if (s->out_format == FMT_H263) { |
1916 | 2902 if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){ |
2903 mx = (motion_x>>1)|(motion_x&1); | |
2904 my = motion_y >>1; | |
2905 uvdxy = ((my & 1) << 1) | (mx & 1); | |
2906 uvsrc_x = s->mb_x* 8 + (mx >> 1); | |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2907 uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1); |
1916 | 2908 }else{ |
2909 uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1); | |
2910 uvsrc_x = src_x>>1; | |
2911 uvsrc_y = src_y>>1; | |
2912 } | |
2044
b6f2add2511e
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
2042
diff
changeset
|
2913 }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261 |
b6f2add2511e
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
2042
diff
changeset
|
2914 mx = motion_x / 4; |
b6f2add2511e
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
2042
diff
changeset
|
2915 my = motion_y / 4; |
b6f2add2511e
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
2042
diff
changeset
|
2916 uvdxy = 0; |
b6f2add2511e
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
2042
diff
changeset
|
2917 uvsrc_x = s->mb_x*8 + mx; |
b6f2add2511e
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
2042
diff
changeset
|
2918 uvsrc_y = s->mb_y*8 + my; |
0 | 2919 } else { |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2920 if(s->chroma_y_shift){ |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2921 mx = motion_x / 2; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2922 my = motion_y / 2; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2923 uvdxy = ((my & 1) << 1) | (mx & 1); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2924 uvsrc_x = s->mb_x* 8 + (mx >> 1); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2925 uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2926 } else { |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2927 if(s->chroma_x_shift){ |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2928 //Chroma422 |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2929 mx = motion_x / 2; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2930 uvdxy = ((motion_y & 1) << 1) | (mx & 1); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2931 uvsrc_x = s->mb_x* 8 + (mx >> 1); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2932 uvsrc_y = src_y; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2933 } else { |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2934 //Chroma444 |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2935 uvdxy = dxy; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2936 uvsrc_x = src_x; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2937 uvsrc_y = src_y; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2938 } |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2939 } |
1846 | 2940 } |
2941 | |
2942 ptr_y = ref_picture[0] + src_y * linesize + src_x; | |
2943 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; | |
2944 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; | |
2945 | |
2946 if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16 | |
2947 || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){ | |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2948 if(s->codec_id == CODEC_ID_MPEG2VIDEO || |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2949 s->codec_id == CODEC_ID_MPEG1VIDEO){ |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2950 av_log(s->avctx,AV_LOG_DEBUG,"MPEG motion vector out of boundary\n"); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2951 return ; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2952 } |
1846 | 2953 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, |
2954 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); | |
2955 ptr_y = s->edge_emu_buffer; | |
2956 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
1874 | 2957 uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; |
2967 | 2958 ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based, |
1846 | 2959 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); |
2967 | 2960 ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based, |
1846 | 2961 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); |
2962 ptr_cb= uvbuf; | |
2963 ptr_cr= uvbuf+16; | |
2964 } | |
2965 } | |
2966 | |
2967 if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data | |
2968 dest_y += s->linesize; | |
2969 dest_cb+= s->uvlinesize; | |
2970 dest_cr+= s->uvlinesize; | |
2971 } | |
2972 | |
2973 if(field_select){ | |
2974 ptr_y += s->linesize; | |
2975 ptr_cb+= s->uvlinesize; | |
2976 ptr_cr+= s->uvlinesize; | |
2977 } | |
2978 | |
2979 pix_op[0][dxy](dest_y, ptr_y, linesize, h); | |
2967 | 2980 |
1846 | 2981 if(!(s->flags&CODEC_FLAG_GRAY)){ |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2982 pix_op[s->chroma_x_shift][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2983 pix_op[s->chroma_x_shift][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift); |
1846 | 2984 } |
2639 | 2985 #if defined(CONFIG_H261_ENCODER) || defined(CONFIG_H261_DECODER) |
2291 | 2986 if(s->out_format == FMT_H261){ |
2987 ff_h261_loop_filter(s); | |
2988 } | |
2639 | 2989 #endif |
0 | 2990 } |
2256 | 2991 |
2992 /* apply one mpeg motion vector to the three components */ | |
2993 static always_inline void mpeg_motion_lowres(MpegEncContext *s, | |
2994 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | |
2995 int field_based, int bottom_field, int field_select, | |
2996 uint8_t **ref_picture, h264_chroma_mc_func *pix_op, | |
2997 int motion_x, int motion_y, int h) | |
2998 { | |
2999 uint8_t *ptr_y, *ptr_cb, *ptr_cr; | |
3000 int mx, my, src_x, src_y, uvsrc_x, uvsrc_y, uvlinesize, linesize, sx, sy, uvsx, uvsy; | |
3001 const int lowres= s->avctx->lowres; | |
3002 const int block_s= 8>>lowres; | |
3003 const int s_mask= (2<<lowres)-1; | |
3004 const int h_edge_pos = s->h_edge_pos >> lowres; | |
3005 const int v_edge_pos = s->v_edge_pos >> lowres; | |
3006 linesize = s->current_picture.linesize[0] << field_based; | |
3007 uvlinesize = s->current_picture.linesize[1] << field_based; | |
3008 | |
2260 | 3009 if(s->quarter_sample){ //FIXME obviously not perfect but qpel wont work in lowres anyway |
3010 motion_x/=2; | |
3011 motion_y/=2; | |
3012 } | |
2967 | 3013 |
2260 | 3014 if(field_based){ |
3015 motion_y += (bottom_field - field_select)*((1<<lowres)-1); | |
3016 } | |
3017 | |
2256 | 3018 sx= motion_x & s_mask; |
3019 sy= motion_y & s_mask; | |
3020 src_x = s->mb_x*2*block_s + (motion_x >> (lowres+1)); | |
2260 | 3021 src_y =(s->mb_y*2*block_s>>field_based) + (motion_y >> (lowres+1)); |
2967 | 3022 |
2256 | 3023 if (s->out_format == FMT_H263) { |
2265 | 3024 uvsx = ((motion_x>>1) & s_mask) | (sx&1); |
3025 uvsy = ((motion_y>>1) & s_mask) | (sy&1); | |
2256 | 3026 uvsrc_x = src_x>>1; |
3027 uvsrc_y = src_y>>1; | |
3028 }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261 | |
3029 mx = motion_x / 4; | |
3030 my = motion_y / 4; | |
3031 uvsx = (2*mx) & s_mask; | |
3032 uvsy = (2*my) & s_mask; | |
3033 uvsrc_x = s->mb_x*block_s + (mx >> lowres); | |
3034 uvsrc_y = s->mb_y*block_s + (my >> lowres); | |
3035 } else { | |
3036 mx = motion_x / 2; | |
3037 my = motion_y / 2; | |
3038 uvsx = mx & s_mask; | |
3039 uvsy = my & s_mask; | |
3040 uvsrc_x = s->mb_x*block_s + (mx >> (lowres+1)); | |
2260 | 3041 uvsrc_y =(s->mb_y*block_s>>field_based) + (my >> (lowres+1)); |
2256 | 3042 } |
3043 | |
3044 ptr_y = ref_picture[0] + src_y * linesize + src_x; | |
3045 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; | |
3046 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; | |
3047 | |
3048 if( (unsigned)src_x > h_edge_pos - (!!sx) - 2*block_s | |
3049 || (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){ | |
3050 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, | |
3051 src_x, src_y<<field_based, h_edge_pos, v_edge_pos); | |
3052 ptr_y = s->edge_emu_buffer; | |
3053 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
3054 uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; | |
2967 | 3055 ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based, |
2256 | 3056 uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1); |
2967 | 3057 ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based, |
2256 | 3058 uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1); |
3059 ptr_cb= uvbuf; | |
3060 ptr_cr= uvbuf+16; | |
3061 } | |
3062 } | |
3063 | |
2260 | 3064 if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data |
3065 dest_y += s->linesize; | |
3066 dest_cb+= s->uvlinesize; | |
3067 dest_cr+= s->uvlinesize; | |
3068 } | |
3069 | |
3070 if(field_select){ | |
3071 ptr_y += s->linesize; | |
3072 ptr_cb+= s->uvlinesize; | |
3073 ptr_cr+= s->uvlinesize; | |
3074 } | |
3075 | |
2256 | 3076 sx <<= 2 - lowres; |
3077 sy <<= 2 - lowres; | |
3078 pix_op[lowres-1](dest_y, ptr_y, linesize, h, sx, sy); | |
2967 | 3079 |
2256 | 3080 if(!(s->flags&CODEC_FLAG_GRAY)){ |
3081 uvsx <<= 2 - lowres; | |
3082 uvsy <<= 2 - lowres; | |
3083 pix_op[lowres](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); | |
3084 pix_op[lowres](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); | |
3085 } | |
2291 | 3086 //FIXME h261 lowres loop filter |
2256 | 3087 } |
3088 | |
1633 | 3089 //FIXME move to dsputil, avg variant, 16x16 version |
3090 static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){ | |
3091 int x; | |
3092 uint8_t * const top = src[1]; | |
3093 uint8_t * const left = src[2]; | |
3094 uint8_t * const mid = src[0]; | |
3095 uint8_t * const right = src[3]; | |
3096 uint8_t * const bottom= src[4]; | |
3097 #define OBMC_FILTER(x, t, l, m, r, b)\ | |
3098 dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3 | |
3099 #define OBMC_FILTER4(x, t, l, m, r, b)\ | |
3100 OBMC_FILTER(x , t, l, m, r, b);\ | |
3101 OBMC_FILTER(x+1 , t, l, m, r, b);\ | |
3102 OBMC_FILTER(x +stride, t, l, m, r, b);\ | |
3103 OBMC_FILTER(x+1+stride, t, l, m, r, b); | |
2967 | 3104 |
1633 | 3105 x=0; |
3106 OBMC_FILTER (x , 2, 2, 4, 0, 0); | |
3107 OBMC_FILTER (x+1, 2, 1, 5, 0, 0); | |
3108 OBMC_FILTER4(x+2, 2, 1, 5, 0, 0); | |
3109 OBMC_FILTER4(x+4, 2, 0, 5, 1, 0); | |
3110 OBMC_FILTER (x+6, 2, 0, 5, 1, 0); | |
3111 OBMC_FILTER (x+7, 2, 0, 4, 2, 0); | |
3112 x+= stride; | |
3113 OBMC_FILTER (x , 1, 2, 5, 0, 0); | |
3114 OBMC_FILTER (x+1, 1, 2, 5, 0, 0); | |
3115 OBMC_FILTER (x+6, 1, 0, 5, 2, 0); | |
3116 OBMC_FILTER (x+7, 1, 0, 5, 2, 0); | |
3117 x+= stride; | |
3118 OBMC_FILTER4(x , 1, 2, 5, 0, 0); | |
3119 OBMC_FILTER4(x+2, 1, 1, 6, 0, 0); | |
3120 OBMC_FILTER4(x+4, 1, 0, 6, 1, 0); | |
3121 OBMC_FILTER4(x+6, 1, 0, 5, 2, 0); | |
3122 x+= 2*stride; | |
3123 OBMC_FILTER4(x , 0, 2, 5, 0, 1); | |
3124 OBMC_FILTER4(x+2, 0, 1, 6, 0, 1); | |
3125 OBMC_FILTER4(x+4, 0, 0, 6, 1, 1); | |
3126 OBMC_FILTER4(x+6, 0, 0, 5, 2, 1); | |
3127 x+= 2*stride; | |
3128 OBMC_FILTER (x , 0, 2, 5, 0, 1); | |
3129 OBMC_FILTER (x+1, 0, 2, 5, 0, 1); | |
3130 OBMC_FILTER4(x+2, 0, 1, 5, 0, 2); | |
3131 OBMC_FILTER4(x+4, 0, 0, 5, 1, 2); | |
3132 OBMC_FILTER (x+6, 0, 0, 5, 2, 1); | |
3133 OBMC_FILTER (x+7, 0, 0, 5, 2, 1); | |
3134 x+= stride; | |
3135 OBMC_FILTER (x , 0, 2, 4, 0, 2); | |
3136 OBMC_FILTER (x+1, 0, 1, 5, 0, 2); | |
3137 OBMC_FILTER (x+6, 0, 0, 5, 1, 2); | |
3138 OBMC_FILTER (x+7, 0, 0, 4, 2, 2); | |
3139 } | |
3140 | |
3141 /* obmc for 1 8x8 luma block */ | |
3142 static inline void obmc_motion(MpegEncContext *s, | |
3143 uint8_t *dest, uint8_t *src, | |
3144 int src_x, int src_y, | |
3145 op_pixels_func *pix_op, | |
3146 int16_t mv[5][2]/* mid top left right bottom*/) | |
3147 #define MID 0 | |
3148 { | |
3149 int i; | |
3150 uint8_t *ptr[5]; | |
2967 | 3151 |
1633 | 3152 assert(s->quarter_sample==0); |
2967 | 3153 |
1633 | 3154 for(i=0; i<5; i++){ |
3155 if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){ | |
3156 ptr[i]= ptr[MID]; | |
3157 }else{ | |
1799 | 3158 ptr[i]= s->obmc_scratchpad + 8*(i&1) + s->linesize*8*(i>>1); |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3159 hpel_motion(s, ptr[i], src, 0, 0, |
1633 | 3160 src_x, src_y, |
3161 s->width, s->height, s->linesize, | |
3162 s->h_edge_pos, s->v_edge_pos, | |
3163 8, 8, pix_op, | |
3164 mv[i][0], mv[i][1]); | |
3165 } | |
3166 } | |
3167 | |
2967 | 3168 put_obmc(dest, ptr, s->linesize); |
1633 | 3169 } |
0 | 3170 |
255 | 3171 static inline void qpel_motion(MpegEncContext *s, |
1064 | 3172 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3173 int field_based, int bottom_field, int field_select, |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3174 uint8_t **ref_picture, op_pixels_func (*pix_op)[4], |
651 | 3175 qpel_mc_func (*qpix_op)[16], |
255 | 3176 int motion_x, int motion_y, int h) |
3177 { | |
1846 | 3178 uint8_t *ptr_y, *ptr_cb, *ptr_cr; |
3179 int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, linesize, uvlinesize; | |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3180 |
255 | 3181 dxy = ((motion_y & 3) << 2) | (motion_x & 3); |
1846 | 3182 src_x = s->mb_x * 16 + (motion_x >> 2); |
255 | 3183 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); |
3184 | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
3185 v_edge_pos = s->v_edge_pos >> field_based; |
255 | 3186 linesize = s->linesize << field_based; |
671 | 3187 uvlinesize = s->uvlinesize << field_based; |
2967 | 3188 |
671 | 3189 if(field_based){ |
3190 mx= motion_x/2; | |
3191 my= motion_y>>1; | |
1048 | 3192 }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){ |
3193 static const int rtab[8]= {0,0,1,1,0,0,0,1}; | |
3194 mx= (motion_x>>1) + rtab[motion_x&7]; | |
3195 my= (motion_y>>1) + rtab[motion_y&7]; | |
760 | 3196 }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){ |
671 | 3197 mx= (motion_x>>1)|(motion_x&1); |
3198 my= (motion_y>>1)|(motion_y&1); | |
3199 }else{ | |
3200 mx= motion_x/2; | |
3201 my= motion_y/2; | |
3202 } | |
3203 mx= (mx>>1)|(mx&1); | |
3204 my= (my>>1)|(my&1); | |
1048 | 3205 |
1846 | 3206 uvdxy= (mx&1) | ((my&1)<<1); |
671 | 3207 mx>>=1; |
3208 my>>=1; | |
255 | 3209 |
1846 | 3210 uvsrc_x = s->mb_x * 8 + mx; |
3211 uvsrc_y = s->mb_y * (8 >> field_based) + my; | |
3212 | |
3213 ptr_y = ref_picture[0] + src_y * linesize + src_x; | |
3214 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; | |
3215 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; | |
3216 | |
2967 | 3217 if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16 |
1846 | 3218 || (unsigned)src_y > v_edge_pos - (motion_y&3) - h ){ |
2967 | 3219 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, |
1846 | 3220 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); |
3221 ptr_y= s->edge_emu_buffer; | |
3222 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
1874 | 3223 uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize; |
2967 | 3224 ff_emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, 9, 9 + field_based, |
1846 | 3225 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); |
2967 | 3226 ff_emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, 9, 9 + field_based, |
1846 | 3227 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); |
3228 ptr_cb= uvbuf; | |
3229 ptr_cr= uvbuf + 16; | |
3230 } | |
3231 } | |
3232 | |
3233 if(!field_based) | |
3234 qpix_op[0][dxy](dest_y, ptr_y, linesize); | |
3235 else{ | |
3236 if(bottom_field){ | |
3237 dest_y += s->linesize; | |
3238 dest_cb+= s->uvlinesize; | |
3239 dest_cr+= s->uvlinesize; | |
3240 } | |
3241 | |
3242 if(field_select){ | |
3243 ptr_y += s->linesize; | |
3244 ptr_cb += s->uvlinesize; | |
3245 ptr_cr += s->uvlinesize; | |
3246 } | |
3247 //damn interlaced mode | |
3248 //FIXME boundary mirroring is not exactly correct here | |
3249 qpix_op[1][dxy](dest_y , ptr_y , linesize); | |
3250 qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize); | |
3251 } | |
3252 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
3253 pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1); | |
3254 pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1); | |
3255 } | |
255 | 3256 } |
3257 | |
1013 | 3258 inline int ff_h263_round_chroma(int x){ |
3259 if (x >= 0) | |
3260 return (h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1)); | |
3261 else { | |
3262 x = -x; | |
3263 return -(h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1)); | |
3264 } | |
3265 } | |
255 | 3266 |
1225 | 3267 /** |
1633 | 3268 * h263 chorma 4mv motion compensation. |
3269 */ | |
3270 static inline void chroma_4mv_motion(MpegEncContext *s, | |
3271 uint8_t *dest_cb, uint8_t *dest_cr, | |
3272 uint8_t **ref_picture, | |
3273 op_pixels_func *pix_op, | |
3274 int mx, int my){ | |
3275 int dxy, emu=0, src_x, src_y, offset; | |
3276 uint8_t *ptr; | |
2967 | 3277 |
1633 | 3278 /* In case of 8X8, we construct a single chroma motion vector |
3279 with a special rounding */ | |
3280 mx= ff_h263_round_chroma(mx); | |
3281 my= ff_h263_round_chroma(my); | |
2967 | 3282 |
1633 | 3283 dxy = ((my & 1) << 1) | (mx & 1); |
3284 mx >>= 1; | |
3285 my >>= 1; | |
3286 | |
3287 src_x = s->mb_x * 8 + mx; | |
3288 src_y = s->mb_y * 8 + my; | |
3289 src_x = clip(src_x, -8, s->width/2); | |
3290 if (src_x == s->width/2) | |
3291 dxy &= ~1; | |
3292 src_y = clip(src_y, -8, s->height/2); | |
3293 if (src_y == s->height/2) | |
3294 dxy &= ~2; | |
2967 | 3295 |
1633 | 3296 offset = (src_y * (s->uvlinesize)) + src_x; |
3297 ptr = ref_picture[1] + offset; | |
3298 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
3299 if( (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8 | |
3300 || (unsigned)src_y > (s->v_edge_pos>>1) - (dxy>>1) - 8){ | |
3301 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
3302 ptr= s->edge_emu_buffer; | |
3303 emu=1; | |
3304 } | |
3305 } | |
3306 pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8); | |
3307 | |
3308 ptr = ref_picture[2] + offset; | |
3309 if(emu){ | |
3310 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
3311 ptr= s->edge_emu_buffer; | |
3312 } | |
3313 pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); | |
3314 } | |
3315 | |
2292 | 3316 static inline void chroma_4mv_motion_lowres(MpegEncContext *s, |
3317 uint8_t *dest_cb, uint8_t *dest_cr, | |
3318 uint8_t **ref_picture, | |
3319 h264_chroma_mc_func *pix_op, | |
3320 int mx, int my){ | |
3321 const int lowres= s->avctx->lowres; | |
3322 const int block_s= 8>>lowres; | |
3323 const int s_mask= (2<<lowres)-1; | |
3324 const int h_edge_pos = s->h_edge_pos >> (lowres+1); | |
3325 const int v_edge_pos = s->v_edge_pos >> (lowres+1); | |
3326 int emu=0, src_x, src_y, offset, sx, sy; | |
3327 uint8_t *ptr; | |
2967 | 3328 |
2292 | 3329 if(s->quarter_sample){ |
3330 mx/=2; | |
3331 my/=2; | |
3332 } | |
3333 | |
3334 /* In case of 8X8, we construct a single chroma motion vector | |
3335 with a special rounding */ | |
3336 mx= ff_h263_round_chroma(mx); | |
3337 my= ff_h263_round_chroma(my); | |
2967 | 3338 |
2292 | 3339 sx= mx & s_mask; |
3340 sy= my & s_mask; | |
3341 src_x = s->mb_x*block_s + (mx >> (lowres+1)); | |
3342 src_y = s->mb_y*block_s + (my >> (lowres+1)); | |
2967 | 3343 |
2292 | 3344 offset = src_y * s->uvlinesize + src_x; |
3345 ptr = ref_picture[1] + offset; | |
3346 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
3347 if( (unsigned)src_x > h_edge_pos - (!!sx) - block_s | |
3348 || (unsigned)src_y > v_edge_pos - (!!sy) - block_s){ | |
3349 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos); | |
3350 ptr= s->edge_emu_buffer; | |
3351 emu=1; | |
3352 } | |
2967 | 3353 } |
2292 | 3354 sx <<= 2 - lowres; |
3355 sy <<= 2 - lowres; | |
3356 pix_op[lowres](dest_cb, ptr, s->uvlinesize, block_s, sx, sy); | |
2967 | 3357 |
2292 | 3358 ptr = ref_picture[2] + offset; |
3359 if(emu){ | |
3360 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos); | |
3361 ptr= s->edge_emu_buffer; | |
3362 } | |
3363 pix_op[lowres](dest_cr, ptr, s->uvlinesize, block_s, sx, sy); | |
3364 } | |
3365 | |
3216
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3366 static inline void prefetch_motion(MpegEncContext *s, uint8_t **pix, int dir){ |
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3367 /* fetch pixels for estimated mv 4 macroblocks ahead |
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3368 * optimized for 64byte cache lines */ |
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3369 const int shift = s->quarter_sample ? 2 : 1; |
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3370 const int mx= (s->mv[dir][0][0]>>shift) + 16*s->mb_x + 8; |
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3371 const int my= (s->mv[dir][0][1]>>shift) + 16*s->mb_y; |
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3372 int off= mx + (my + (s->mb_x&3)*4)*s->linesize + 64; |
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3373 s->dsp.prefetch(pix[0]+off, s->linesize, 4); |
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3374 off= (mx>>1) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + 64; |
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3375 s->dsp.prefetch(pix[1]+off, pix[2]-pix[1], 2); |
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3376 } |
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3377 |
1633 | 3378 /** |
2764 | 3379 * motion compensation of a single macroblock |
1225 | 3380 * @param s context |
3381 * @param dest_y luma destination pointer | |
3382 * @param dest_cb chroma cb/u destination pointer | |
3383 * @param dest_cr chroma cr/v destination pointer | |
3384 * @param dir direction (0->forward, 1->backward) | |
3385 * @param ref_picture array[3] of pointers to the 3 planes of the reference picture | |
3386 * @param pic_op halfpel motion compensation function (average or put normally) | |
3387 * @param pic_op qpel motion compensation function (average or put normally) | |
3388 * the motion vectors are taken from s->mv and the MV type from s->mv_type | |
3389 */ | |
2967 | 3390 static inline void MPV_motion(MpegEncContext *s, |
1064 | 3391 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
2967 | 3392 int dir, uint8_t **ref_picture, |
651 | 3393 op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16]) |
0 | 3394 { |
1633 | 3395 int dxy, mx, my, src_x, src_y, motion_x, motion_y; |
0 | 3396 int mb_x, mb_y, i; |
1064 | 3397 uint8_t *ptr, *dest; |
0 | 3398 |
3399 mb_x = s->mb_x; | |
3400 mb_y = s->mb_y; | |
3401 | |
3216
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3402 prefetch_motion(s, ref_picture, dir); |
4186eb8d29a1
prefetch pixels for future motion compensation. 4-10% faster mpeg1/2/4 decoding (on an athlon-xp).
lorenm
parents:
3145
diff
changeset
|
3403 |
1655 | 3404 if(s->obmc && s->pict_type != B_TYPE){ |
1633 | 3405 int16_t mv_cache[4][4][2]; |
3406 const int xy= s->mb_x + s->mb_y*s->mb_stride; | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
3407 const int mot_stride= s->b8_stride; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
3408 const int mot_xy= mb_x*2 + mb_y*2*mot_stride; |
1633 | 3409 |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2627
diff
changeset
|
3410 assert(!s->mb_skipped); |
2967 | 3411 |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
3412 memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4); |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
3413 memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4); |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
3414 memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4); |
1633 | 3415 |
3416 if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){ | |
3417 memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4); | |
3418 }else{ | |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
3419 memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4); |
1633 | 3420 } |
3421 | |
3422 if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){ | |
3423 *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1]; | |
3424 *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1]; | |
3425 }else{ | |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
3426 *(int32_t*)mv_cache[1][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
3427 *(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride]; |
1633 | 3428 } |
3429 | |
3430 if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){ | |
3431 *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2]; | |
3432 *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2]; | |
3433 }else{ | |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
3434 *(int32_t*)mv_cache[1][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
3435 *(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride]; |
1633 | 3436 } |
2967 | 3437 |
1633 | 3438 mx = 0; |
3439 my = 0; | |
3440 for(i=0;i<4;i++) { | |
3441 const int x= (i&1)+1; | |
3442 const int y= (i>>1)+1; | |
3443 int16_t mv[5][2]= { | |
3444 {mv_cache[y][x ][0], mv_cache[y][x ][1]}, | |
3445 {mv_cache[y-1][x][0], mv_cache[y-1][x][1]}, | |
3446 {mv_cache[y][x-1][0], mv_cache[y][x-1][1]}, | |
3447 {mv_cache[y][x+1][0], mv_cache[y][x+1][1]}, | |
3448 {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}}; | |
3449 //FIXME cleanup | |
3450 obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, | |
3451 ref_picture[0], | |
3452 mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8, | |
3453 pix_op[1], | |
3454 mv); | |
3455 | |
3456 mx += mv[0][0]; | |
3457 my += mv[0][1]; | |
3458 } | |
3459 if(!(s->flags&CODEC_FLAG_GRAY)) | |
3460 chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); | |
3461 | |
3462 return; | |
3463 } | |
2967 | 3464 |
0 | 3465 switch(s->mv_type) { |
3466 case MV_TYPE_16X16: | |
255 | 3467 if(s->mcsel){ |
753 | 3468 if(s->real_sprite_warping_points==1){ |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3469 gmc1_motion(s, dest_y, dest_cb, dest_cr, |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3470 ref_picture); |
753 | 3471 }else{ |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3472 gmc_motion(s, dest_y, dest_cb, dest_cr, |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3473 ref_picture); |
753 | 3474 } |
651 | 3475 }else if(s->quarter_sample){ |
2967 | 3476 qpel_motion(s, dest_y, dest_cb, dest_cr, |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3477 0, 0, 0, |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3478 ref_picture, pix_op, qpix_op, |
255 | 3479 s->mv[dir][0][0], s->mv[dir][0][1], 16); |
936 | 3480 }else if(s->mspel){ |
3481 ff_mspel_motion(s, dest_y, dest_cb, dest_cr, | |
3482 ref_picture, pix_op, | |
3483 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
1042 | 3484 }else |
3485 { | |
2967 | 3486 mpeg_motion(s, dest_y, dest_cb, dest_cr, |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3487 0, 0, 0, |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3488 ref_picture, pix_op, |
255 | 3489 s->mv[dir][0][0], s->mv[dir][0][1], 16); |
2967 | 3490 } |
0 | 3491 break; |
3492 case MV_TYPE_8X8: | |
673 | 3493 mx = 0; |
3494 my = 0; | |
3495 if(s->quarter_sample){ | |
3496 for(i=0;i<4;i++) { | |
3497 motion_x = s->mv[dir][i][0]; | |
3498 motion_y = s->mv[dir][i][1]; | |
0 | 3499 |
673 | 3500 dxy = ((motion_y & 3) << 2) | (motion_x & 3); |
3501 src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8; | |
3502 src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8; | |
2967 | 3503 |
673 | 3504 /* WARNING: do no forget half pels */ |
3505 src_x = clip(src_x, -16, s->width); | |
3506 if (src_x == s->width) | |
3507 dxy &= ~3; | |
3508 src_y = clip(src_y, -16, s->height); | |
3509 if (src_y == s->height) | |
3510 dxy &= ~12; | |
2967 | 3511 |
673 | 3512 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); |
3513 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
2967 | 3514 if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8 |
1542
576861d6343a
emu_edge checks simplification and avoid redundant checks for mpeg1/2 if emu_edge is set
michael
parents:
1539
diff
changeset
|
3515 || (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 8 ){ |
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
3516 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos); |
673 | 3517 ptr= s->edge_emu_buffer; |
3518 } | |
3519 } | |
3520 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; | |
3521 qpix_op[1][dxy](dest, ptr, s->linesize); | |
3522 | |
3523 mx += s->mv[dir][i][0]/2; | |
3524 my += s->mv[dir][i][1]/2; | |
3525 } | |
3526 }else{ | |
3527 for(i=0;i<4;i++) { | |
1633 | 3528 hpel_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3529 ref_picture[0], 0, 0, |
1633 | 3530 mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8, |
3531 s->width, s->height, s->linesize, | |
3532 s->h_edge_pos, s->v_edge_pos, | |
3533 8, 8, pix_op[1], | |
3534 s->mv[dir][i][0], s->mv[dir][i][1]); | |
673 | 3535 |
3536 mx += s->mv[dir][i][0]; | |
3537 my += s->mv[dir][i][1]; | |
554 | 3538 } |
0 | 3539 } |
673 | 3540 |
1633 | 3541 if(!(s->flags&CODEC_FLAG_GRAY)) |
3542 chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); | |
0 | 3543 break; |
3544 case MV_TYPE_FIELD: | |
3545 if (s->picture_structure == PICT_FRAME) { | |
671 | 3546 if(s->quarter_sample){ |
1843 | 3547 for(i=0; i<2; i++){ |
3548 qpel_motion(s, dest_y, dest_cb, dest_cr, | |
3549 1, i, s->field_select[dir][i], | |
3550 ref_picture, pix_op, qpix_op, | |
3551 s->mv[dir][i][0], s->mv[dir][i][1], 8); | |
3552 } | |
671 | 3553 }else{ |
2967 | 3554 /* top field */ |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3555 mpeg_motion(s, dest_y, dest_cb, dest_cr, |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3556 1, 0, s->field_select[dir][0], |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3557 ref_picture, pix_op, |
671 | 3558 s->mv[dir][0][0], s->mv[dir][0][1], 8); |
3559 /* bottom field */ | |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3560 mpeg_motion(s, dest_y, dest_cb, dest_cr, |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3561 1, 1, s->field_select[dir][1], |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3562 ref_picture, pix_op, |
671 | 3563 s->mv[dir][1][0], s->mv[dir][1][1], 8); |
3564 } | |
0 | 3565 } else { |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3566 if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){ |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3567 ref_picture= s->current_picture_ptr->data; |
2967 | 3568 } |
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
|
3569 |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3570 mpeg_motion(s, dest_y, dest_cb, dest_cr, |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3571 0, 0, s->field_select[dir][0], |
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3572 ref_picture, pix_op, |
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
|
3573 s->mv[dir][0][0], s->mv[dir][0][1], 16); |
0 | 3574 } |
3575 break; | |
1843 | 3576 case MV_TYPE_16X8: |
3577 for(i=0; i<2; i++){ | |
3578 uint8_t ** ref2picture; | |
3579 | |
3580 if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){ | |
1339
338a2f6e6402
Mpeg2 16x8 Patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1328
diff
changeset
|
3581 ref2picture= ref_picture; |
338a2f6e6402
Mpeg2 16x8 Patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1328
diff
changeset
|
3582 }else{ |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3583 ref2picture= s->current_picture_ptr->data; |
2967 | 3584 } |
3585 | |
3586 mpeg_motion(s, dest_y, dest_cb, dest_cr, | |
1843 | 3587 0, 0, s->field_select[dir][i], |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3588 ref2picture, pix_op, |
1843 | 3589 s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8); |
2967 | 3590 |
1843 | 3591 dest_y += 16*s->linesize; |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3592 dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3593 dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize; |
2967 | 3594 } |
1339
338a2f6e6402
Mpeg2 16x8 Patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1328
diff
changeset
|
3595 break; |
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1317
diff
changeset
|
3596 case MV_TYPE_DMV: |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1317
diff
changeset
|
3597 if(s->picture_structure == PICT_FRAME){ |
1843 | 3598 for(i=0; i<2; i++){ |
3599 int j; | |
3600 for(j=0; j<2; j++){ | |
3601 mpeg_motion(s, dest_y, dest_cb, dest_cr, | |
3602 1, j, j^i, | |
3603 ref_picture, pix_op, | |
3604 s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8); | |
3605 } | |
2967 | 3606 pix_op = s->dsp.avg_pixels_tab; |
1843 | 3607 } |
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1317
diff
changeset
|
3608 }else{ |
1843 | 3609 for(i=0; i<2; i++){ |
2967 | 3610 mpeg_motion(s, dest_y, dest_cb, dest_cr, |
1843 | 3611 0, 0, s->picture_structure != i+1, |
3612 ref_picture, pix_op, | |
3613 s->mv[dir][2*i][0],s->mv[dir][2*i][1],16); | |
3614 | |
3615 // after put we make avg of the same block | |
2967 | 3616 pix_op=s->dsp.avg_pixels_tab; |
1843 | 3617 |
3618 //opposite parity is always in the same frame if this is second field | |
3619 if(!s->first_field){ | |
2967 | 3620 ref_picture = s->current_picture_ptr->data; |
1843 | 3621 } |
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3622 } |
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1317
diff
changeset
|
3623 } |
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1317
diff
changeset
|
3624 break; |
1633 | 3625 default: assert(0); |
0 | 3626 } |
3627 } | |
3628 | |
2256 | 3629 /** |
2764 | 3630 * motion compensation of a single macroblock |
2256 | 3631 * @param s context |
3632 * @param dest_y luma destination pointer | |
3633 * @param dest_cb chroma cb/u destination pointer | |
3634 * @param dest_cr chroma cr/v destination pointer | |
3635 * @param dir direction (0->forward, 1->backward) | |
3636 * @param ref_picture array[3] of pointers to the 3 planes of the reference picture | |
3637 * @param pic_op halfpel motion compensation function (average or put normally) | |
3638 * the motion vectors are taken from s->mv and the MV type from s->mv_type | |
3639 */ | |
2967 | 3640 static inline void MPV_motion_lowres(MpegEncContext *s, |
2256 | 3641 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
2967 | 3642 int dir, uint8_t **ref_picture, |
2256 | 3643 h264_chroma_mc_func *pix_op) |
3644 { | |
2292 | 3645 int mx, my; |
2260 | 3646 int mb_x, mb_y, i; |
3647 const int lowres= s->avctx->lowres; | |
2967 | 3648 const int block_s= 8>>lowres; |
2260 | 3649 |
3650 mb_x = s->mb_x; | |
3651 mb_y = s->mb_y; | |
3652 | |
3653 switch(s->mv_type) { | |
3654 case MV_TYPE_16X16: | |
2967 | 3655 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, |
2260 | 3656 0, 0, 0, |
3657 ref_picture, pix_op, | |
3658 s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s); | |
3659 break; | |
2292 | 3660 case MV_TYPE_8X8: |
2260 | 3661 mx = 0; |
3662 my = 0; | |
3663 for(i=0;i<4;i++) { | |
2292 | 3664 hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * s->linesize)*block_s, |
2260 | 3665 ref_picture[0], 0, 0, |
2292 | 3666 (2*mb_x + (i & 1))*block_s, (2*mb_y + (i >>1))*block_s, |
2260 | 3667 s->width, s->height, s->linesize, |
2292 | 3668 s->h_edge_pos >> lowres, s->v_edge_pos >> lowres, |
3669 block_s, block_s, pix_op, | |
2260 | 3670 s->mv[dir][i][0], s->mv[dir][i][1]); |
3671 | |
3672 mx += s->mv[dir][i][0]; | |
3673 my += s->mv[dir][i][1]; | |
3674 } | |
3675 | |
3676 if(!(s->flags&CODEC_FLAG_GRAY)) | |
2292 | 3677 chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, pix_op, mx, my); |
3678 break; | |
2260 | 3679 case MV_TYPE_FIELD: |
3680 if (s->picture_structure == PICT_FRAME) { | |
2967 | 3681 /* top field */ |
2260 | 3682 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, |
3683 1, 0, s->field_select[dir][0], | |
3684 ref_picture, pix_op, | |
3685 s->mv[dir][0][0], s->mv[dir][0][1], block_s); | |
3686 /* bottom field */ | |
3687 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
3688 1, 1, s->field_select[dir][1], | |
3689 ref_picture, pix_op, | |
3690 s->mv[dir][1][0], s->mv[dir][1][1], block_s); | |
3691 } else { | |
3692 if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){ | |
3693 ref_picture= s->current_picture_ptr->data; | |
2967 | 3694 } |
2260 | 3695 |
3696 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
3697 0, 0, s->field_select[dir][0], | |
3698 ref_picture, pix_op, | |
3699 s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s); | |
3700 } | |
3701 break; | |
3702 case MV_TYPE_16X8: | |
3703 for(i=0; i<2; i++){ | |
3704 uint8_t ** ref2picture; | |
3705 | |
3706 if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){ | |
3707 ref2picture= ref_picture; | |
3708 }else{ | |
3709 ref2picture= s->current_picture_ptr->data; | |
2967 | 3710 } |
3711 | |
3712 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
2260 | 3713 0, 0, s->field_select[dir][i], |
3714 ref2picture, pix_op, | |
3715 s->mv[dir][i][0], s->mv[dir][i][1] + 2*block_s*i, block_s); | |
2967 | 3716 |
2260 | 3717 dest_y += 2*block_s*s->linesize; |
3718 dest_cb+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize; | |
3719 dest_cr+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize; | |
2967 | 3720 } |
2260 | 3721 break; |
3722 case MV_TYPE_DMV: | |
3723 if(s->picture_structure == PICT_FRAME){ | |
3724 for(i=0; i<2; i++){ | |
3725 int j; | |
3726 for(j=0; j<2; j++){ | |
3727 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
3728 1, j, j^i, | |
3729 ref_picture, pix_op, | |
3730 s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], block_s); | |
3731 } | |
3732 pix_op = s->dsp.avg_h264_chroma_pixels_tab; | |
3733 } | |
3734 }else{ | |
3735 for(i=0; i<2; i++){ | |
2967 | 3736 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, |
2260 | 3737 0, 0, s->picture_structure != i+1, |
3738 ref_picture, pix_op, | |
3739 s->mv[dir][2*i][0],s->mv[dir][2*i][1],2*block_s); | |
3740 | |
3741 // after put we make avg of the same block | |
3742 pix_op = s->dsp.avg_h264_chroma_pixels_tab; | |
3743 | |
3744 //opposite parity is always in the same frame if this is second field | |
3745 if(!s->first_field){ | |
2967 | 3746 ref_picture = s->current_picture_ptr->data; |
2260 | 3747 } |
3748 } | |
3749 } | |
3750 break; | |
3751 default: assert(0); | |
3752 } | |
2256 | 3753 } |
0 | 3754 |
3755 /* put block[] to dest[] */ | |
2967 | 3756 static inline void put_dct(MpegEncContext *s, |
1651 | 3757 DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale) |
0 | 3758 { |
1689 | 3759 s->dct_unquantize_intra(s, block, i, qscale); |
1092 | 3760 s->dsp.idct_put (dest, line_size, block); |
0 | 3761 } |
3762 | |
3763 /* add block[] to dest[] */ | |
2967 | 3764 static inline void add_dct(MpegEncContext *s, |
1064 | 3765 DCTELEM *block, int i, uint8_t *dest, int line_size) |
0 | 3766 { |
3767 if (s->block_last_index[i] >= 0) { | |
1092 | 3768 s->dsp.idct_add (dest, line_size, block); |
481 | 3769 } |
3770 } | |
3771 | |
2967 | 3772 static inline void add_dequant_dct(MpegEncContext *s, |
1644 | 3773 DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale) |
481 | 3774 { |
3775 if (s->block_last_index[i] >= 0) { | |
1689 | 3776 s->dct_unquantize_inter(s, block, i, qscale); |
324 | 3777 |
1092 | 3778 s->dsp.idct_add (dest, line_size, block); |
0 | 3779 } |
3780 } | |
3781 | |
456 | 3782 /** |
3783 * cleans dc, ac, coded_block for the current non intra MB | |
3784 */ | |
3785 void ff_clean_intra_table_entries(MpegEncContext *s) | |
3786 { | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
3787 int wrap = s->b8_stride; |
456 | 3788 int xy = s->block_index[0]; |
2967 | 3789 |
3790 s->dc_val[0][xy ] = | |
3791 s->dc_val[0][xy + 1 ] = | |
456 | 3792 s->dc_val[0][xy + wrap] = |
3793 s->dc_val[0][xy + 1 + wrap] = 1024; | |
3794 /* ac pred */ | |
1064 | 3795 memset(s->ac_val[0][xy ], 0, 32 * sizeof(int16_t)); |
3796 memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(int16_t)); | |
456 | 3797 if (s->msmpeg4_version>=3) { |
3798 s->coded_block[xy ] = | |
3799 s->coded_block[xy + 1 ] = | |
3800 s->coded_block[xy + wrap] = | |
3801 s->coded_block[xy + 1 + wrap] = 0; | |
3802 } | |
3803 /* chroma */ | |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
3804 wrap = s->mb_stride; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
3805 xy = s->mb_x + s->mb_y * wrap; |
456 | 3806 s->dc_val[1][xy] = |
3807 s->dc_val[2][xy] = 1024; | |
3808 /* ac pred */ | |
1064 | 3809 memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t)); |
3810 memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t)); | |
2967 | 3811 |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
3812 s->mbintra_table[xy]= 0; |
456 | 3813 } |
3814 | |
0 | 3815 /* generic function called after a macroblock has been parsed by the |
3816 decoder or after it has been encoded by the encoder. | |
3817 | |
3818 Important variables used: | |
3819 s->mb_intra : true if intra macroblock | |
3820 s->mv_dir : motion vector direction | |
3821 s->mv_type : motion vector type | |
3822 s->mv : motion vector | |
3823 s->interlaced_dct : true if interlaced dct used (mpeg2) | |
3824 */ | |
2256 | 3825 static always_inline void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], int lowres_flag) |
0 | 3826 { |
244 | 3827 int mb_x, mb_y; |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
3828 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; |
1381 | 3829 #ifdef HAVE_XVMC |
3830 if(s->avctx->xvmc_acceleration){ | |
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1579
diff
changeset
|
3831 XVMC_decode_mb(s);//xvmc uses pblocks |
1381 | 3832 return; |
3833 } | |
3834 #endif | |
0 | 3835 |
3836 mb_x = s->mb_x; | |
3837 mb_y = s->mb_y; | |
3838 | |
1833
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3839 if(s->avctx->debug&FF_DEBUG_DCT_COEFF) { |
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3840 /* save DCT coefficients */ |
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3841 int i,j; |
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3842 DCTELEM *dct = &s->current_picture.dct_coeff[mb_xy*64*6]; |
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3843 for(i=0; i<6; i++) |
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3844 for(j=0; j<64; j++) |
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3845 *dct++ = block[i][s->dsp.idct_permutation[j]]; |
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3846 } |
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3847 |
903 | 3848 s->current_picture.qscale_table[mb_xy]= s->qscale; |
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
3849 |
0 | 3850 /* update DC predictors for P macroblocks */ |
3851 if (!s->mb_intra) { | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3852 if (s->h263_pred || s->h263_aic) { |
481 | 3853 if(s->mbintra_table[mb_xy]) |
456 | 3854 ff_clean_intra_table_entries(s); |
0 | 3855 } else { |
456 | 3856 s->last_dc[0] = |
3857 s->last_dc[1] = | |
0 | 3858 s->last_dc[2] = 128 << s->intra_dc_precision; |
3859 } | |
3860 } | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3861 else if (s->h263_pred || s->h263_aic) |
481 | 3862 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
|
3863 |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3864 if ((s->flags&CODEC_FLAG_PSNR) || !(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { //FIXME precalc |
1064 | 3865 uint8_t *dest_y, *dest_cb, *dest_cr; |
481 | 3866 int dct_linesize, dct_offset; |
651 | 3867 op_pixels_func (*op_pix)[4]; |
3868 qpel_mc_func (*op_qpix)[16]; | |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
3869 const int linesize= s->current_picture.linesize[0]; //not s->linesize as this would be wrong for field pics |
1138 | 3870 const int uvlinesize= s->current_picture.linesize[1]; |
2256 | 3871 const int readable= s->pict_type != B_TYPE || s->encoding || s->avctx->draw_horiz_band || lowres_flag; |
3872 const int block_size= lowres_flag ? 8>>s->avctx->lowres : 8; | |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
3873 |
903 | 3874 /* avoid copy if macroblock skipped in last frame too */ |
3875 /* skip only during decoding as we might trash the buffers during encoding a bit */ | |
3876 if(!s->encoding){ | |
1064 | 3877 uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy]; |
903 | 3878 const int age= s->current_picture.age; |
3879 | |
3880 assert(age); | |
3881 | |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2627
diff
changeset
|
3882 if (s->mb_skipped) { |
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2627
diff
changeset
|
3883 s->mb_skipped= 0; |
903 | 3884 assert(s->pict_type!=I_TYPE); |
2967 | 3885 |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2627
diff
changeset
|
3886 (*mbskip_ptr) ++; /* indicate that this time we skipped it */ |
556 | 3887 if(*mbskip_ptr >99) *mbskip_ptr= 99; |
3888 | |
903 | 3889 /* 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
|
3890 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
|
3891 return; |
903 | 3892 } |
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
3893 } 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
|
3894 (*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
|
3895 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
|
3896 } else{ |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
3897 *mbskip_ptr = 0; /* not skipped */ |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
3898 } |
717 | 3899 } |
2967 | 3900 |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3901 dct_linesize = linesize << s->interlaced_dct; |
2256 | 3902 dct_offset =(s->interlaced_dct)? linesize : linesize*block_size; |
2967 | 3903 |
1632 | 3904 if(readable){ |
3905 dest_y= s->dest[0]; | |
3906 dest_cb= s->dest[1]; | |
3907 dest_cr= s->dest[2]; | |
3908 }else{ | |
1799 | 3909 dest_y = s->b_scratchpad; |
1834 | 3910 dest_cb= s->b_scratchpad+16*linesize; |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3911 dest_cr= s->b_scratchpad+32*linesize; |
1632 | 3912 } |
2256 | 3913 |
0 | 3914 if (!s->mb_intra) { |
3915 /* motion handling */ | |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
3916 /* decoding or more than one mb_type (MC was already done otherwise) */ |
1389 | 3917 if(!s->encoding){ |
2256 | 3918 if(lowres_flag){ |
3919 h264_chroma_mc_func *op_pix = s->dsp.put_h264_chroma_pixels_tab; | |
3920 | |
3921 if (s->mv_dir & MV_DIR_FORWARD) { | |
3922 MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix); | |
3923 op_pix = s->dsp.avg_h264_chroma_pixels_tab; | |
3924 } | |
3925 if (s->mv_dir & MV_DIR_BACKWARD) { | |
3926 MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix); | |
3927 } | |
324 | 3928 }else{ |
2967 | 3929 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
2256 | 3930 op_pix = s->dsp.put_pixels_tab; |
3931 op_qpix= s->dsp.put_qpel_pixels_tab; | |
3932 }else{ | |
3933 op_pix = s->dsp.put_no_rnd_pixels_tab; | |
3934 op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab; | |
3935 } | |
3936 if (s->mv_dir & MV_DIR_FORWARD) { | |
3937 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix); | |
3938 op_pix = s->dsp.avg_pixels_tab; | |
3939 op_qpix= s->dsp.avg_qpel_pixels_tab; | |
3940 } | |
3941 if (s->mv_dir & MV_DIR_BACKWARD) { | |
3942 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix); | |
3943 } | |
324 | 3944 } |
0 | 3945 } |
3946 | |
481 | 3947 /* skip dequant / idct if we are really late ;) */ |
2792 | 3948 if(s->hurry_up>1) goto skip_idct; |
3949 if(s->avctx->skip_idct){ | |
3950 if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == B_TYPE) | |
3951 ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != I_TYPE) | |
3952 || s->avctx->skip_idct >= AVDISCARD_ALL) | |
3953 goto skip_idct; | |
3954 } | |
481 | 3955 |
0 | 3956 /* add dct residue */ |
1421 | 3957 if(s->encoding || !( s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO |
711 | 3958 || (s->codec_id==CODEC_ID_MPEG4 && !s->mpeg_quant))){ |
2256 | 3959 add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); |
3960 add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); | |
3961 add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); | |
3962 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); | |
0 | 3963 |
485 | 3964 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1644 | 3965 add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); |
3966 add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); | |
485 | 3967 } |
936 | 3968 } else if(s->codec_id != CODEC_ID_WMV2){ |
2256 | 3969 add_dct(s, block[0], 0, dest_y , dct_linesize); |
3970 add_dct(s, block[1], 1, dest_y + block_size, dct_linesize); | |
3971 add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize); | |
3972 add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize); | |
481 | 3973 |
485 | 3974 if(!(s->flags&CODEC_FLAG_GRAY)){ |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3975 if(s->chroma_y_shift){//Chroma420 |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3976 add_dct(s, block[4], 4, dest_cb, uvlinesize); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3977 add_dct(s, block[5], 5, dest_cr, uvlinesize); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3978 }else{ |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3979 //chroma422 |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3980 dct_linesize = uvlinesize << s->interlaced_dct; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3981 dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3982 |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3983 add_dct(s, block[4], 4, dest_cb, dct_linesize); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3984 add_dct(s, block[5], 5, dest_cr, dct_linesize); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3985 add_dct(s, block[6], 6, dest_cb+dct_offset, dct_linesize); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3986 add_dct(s, block[7], 7, dest_cr+dct_offset, dct_linesize); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3987 if(!s->chroma_x_shift){//Chroma444 |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3988 add_dct(s, block[8], 8, dest_cb+8, dct_linesize); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3989 add_dct(s, block[9], 9, dest_cr+8, dct_linesize); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3990 add_dct(s, block[10], 10, dest_cb+8+dct_offset, dct_linesize); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3991 add_dct(s, block[11], 11, dest_cr+8+dct_offset, dct_linesize); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3992 } |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3993 } |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3994 }//fi gray |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3995 } |
1042 | 3996 else{ |
936 | 3997 ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr); |
481 | 3998 } |
0 | 3999 } else { |
4000 /* dct only in intra block */ | |
1421 | 4001 if(s->encoding || !(s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO)){ |
2256 | 4002 put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); |
4003 put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); | |
4004 put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); | |
4005 put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); | |
0 | 4006 |
711 | 4007 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1651 | 4008 put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); |
4009 put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); | |
711 | 4010 } |
4011 }else{ | |
2256 | 4012 s->dsp.idct_put(dest_y , dct_linesize, block[0]); |
4013 s->dsp.idct_put(dest_y + block_size, dct_linesize, block[1]); | |
4014 s->dsp.idct_put(dest_y + dct_offset , dct_linesize, block[2]); | |
4015 s->dsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]); | |
711 | 4016 |
4017 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4018 if(s->chroma_y_shift){ |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4019 s->dsp.idct_put(dest_cb, uvlinesize, block[4]); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4020 s->dsp.idct_put(dest_cr, uvlinesize, block[5]); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4021 }else{ |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4022 |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4023 dct_linesize = uvlinesize << s->interlaced_dct; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4024 dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8; |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4025 |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4026 s->dsp.idct_put(dest_cb, dct_linesize, block[4]); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4027 s->dsp.idct_put(dest_cr, dct_linesize, block[5]); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4028 s->dsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4029 s->dsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4030 if(!s->chroma_x_shift){//Chroma444 |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4031 s->dsp.idct_put(dest_cb + 8, dct_linesize, block[8]); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4032 s->dsp.idct_put(dest_cr + 8, dct_linesize, block[9]); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4033 s->dsp.idct_put(dest_cb + 8 + dct_offset, dct_linesize, block[10]); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4034 s->dsp.idct_put(dest_cr + 8 + dct_offset, dct_linesize, block[11]); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4035 } |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4036 } |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4037 }//gray |
485 | 4038 } |
0 | 4039 } |
2792 | 4040 skip_idct: |
1632 | 4041 if(!readable){ |
4042 s->dsp.put_pixels_tab[0][0](s->dest[0], dest_y , linesize,16); | |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4043 s->dsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[1], dest_cb, uvlinesize,16 >> s->chroma_y_shift); |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4044 s->dsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[2], dest_cr, uvlinesize,16 >> s->chroma_y_shift); |
1632 | 4045 } |
0 | 4046 } |
294 | 4047 } |
4048 | |
2256 | 4049 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]){ |
4050 if(s->avctx->lowres) MPV_decode_mb_internal(s, block, 1); | |
4051 else MPV_decode_mb_internal(s, block, 0); | |
4052 } | |
4053 | |
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
|
4054 #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
|
4055 |
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
4056 static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold) |
456 | 4057 { |
4058 static const char tab[64]= | |
4059 {3,2,2,1,1,1,1,1, | |
4060 1,1,1,1,1,1,1,1, | |
4061 1,1,1,1,1,1,1,1, | |
4062 0,0,0,0,0,0,0,0, | |
4063 0,0,0,0,0,0,0,0, | |
4064 0,0,0,0,0,0,0,0, | |
4065 0,0,0,0,0,0,0,0, | |
4066 0,0,0,0,0,0,0,0}; | |
4067 int score=0; | |
4068 int run=0; | |
4069 int i; | |
4070 DCTELEM *block= s->block[n]; | |
4071 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
|
4072 int skip_dc; |
456 | 4073 |
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
|
4074 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
|
4075 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
|
4076 threshold= -threshold; |
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
4077 }else |
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
4078 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
|
4079 |
456 | 4080 /* are all which we could set to zero are allready zero? */ |
4081 if(last_index<=skip_dc - 1) return; | |
4082 | |
4083 for(i=0; i<=last_index; i++){ | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
4084 const int j = s->intra_scantable.permutated[i]; |
456 | 4085 const int level = ABS(block[j]); |
4086 if(level==1){ | |
4087 if(skip_dc && i==0) continue; | |
4088 score+= tab[run]; | |
4089 run=0; | |
4090 }else if(level>1){ | |
4091 return; | |
4092 }else{ | |
4093 run++; | |
4094 } | |
4095 } | |
4096 if(score >= threshold) return; | |
4097 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
|
4098 const int j = s->intra_scantable.permutated[i]; |
456 | 4099 block[j]=0; |
4100 } | |
4101 if(block[0]) s->block_last_index[n]= 0; | |
4102 else s->block_last_index[n]= -1; | |
4103 } | |
4104 | |
344 | 4105 static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) |
4106 { | |
4107 int i; | |
4108 const int maxlevel= s->max_qcoeff; | |
4109 const int minlevel= s->min_qcoeff; | |
1722
7e040c2a86e4
warn the user if we had to clip some dct coefficient due to a crappy format which doenst support the whole needed range (msmpeg4/wmv mostly but mpeg1 too to a lesser extend)
michael
parents:
1719
diff
changeset
|
4110 int overflow=0; |
2967 | 4111 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
4112 if(s->mb_intra){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
4113 i=1; //skip clipping of intra dc |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
4114 }else |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
4115 i=0; |
2967 | 4116 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
4117 for(;i<=last_index; i++){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
4118 const int j= s->intra_scantable.permutated[i]; |
344 | 4119 int level = block[j]; |
2967 | 4120 |
1722
7e040c2a86e4
warn the user if we had to clip some dct coefficient due to a crappy format which doenst support the whole needed range (msmpeg4/wmv mostly but mpeg1 too to a lesser extend)
michael
parents:
1719
diff
changeset
|
4121 if (level>maxlevel){ |
7e040c2a86e4
warn the user if we had to clip some dct coefficient due to a crappy format which doenst support the whole needed range (msmpeg4/wmv mostly but mpeg1 too to a lesser extend)
michael
parents:
1719
diff
changeset
|
4122 level=maxlevel; |
7e040c2a86e4
warn the user if we had to clip some dct coefficient due to a crappy format which doenst support the whole needed range (msmpeg4/wmv mostly but mpeg1 too to a lesser extend)
michael
parents:
1719
diff
changeset
|
4123 overflow++; |
7e040c2a86e4
warn the user if we had to clip some dct coefficient due to a crappy format which doenst support the whole needed range (msmpeg4/wmv mostly but mpeg1 too to a lesser extend)
michael
parents:
1719
diff
changeset
|
4124 }else if(level<minlevel){ |
7e040c2a86e4
warn the user if we had to clip some dct coefficient due to a crappy format which doenst support the whole needed range (msmpeg4/wmv mostly but mpeg1 too to a lesser extend)
michael
parents:
1719
diff
changeset
|
4125 level=minlevel; |
7e040c2a86e4
warn the user if we had to clip some dct coefficient due to a crappy format which doenst support the whole needed range (msmpeg4/wmv mostly but mpeg1 too to a lesser extend)
michael
parents:
1719
diff
changeset
|
4126 overflow++; |
7e040c2a86e4
warn the user if we had to clip some dct coefficient due to a crappy format which doenst support the whole needed range (msmpeg4/wmv mostly but mpeg1 too to a lesser extend)
michael
parents:
1719
diff
changeset
|
4127 } |
2967 | 4128 |
344 | 4129 block[j]= level; |
4130 } | |
2967 | 4131 |
1722
7e040c2a86e4
warn the user if we had to clip some dct coefficient due to a crappy format which doenst support the whole needed range (msmpeg4/wmv mostly but mpeg1 too to a lesser extend)
michael
parents:
1719
diff
changeset
|
4132 if(overflow && s->avctx->mb_decision == FF_MB_DECISION_SIMPLE) |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
4133 av_log(s->avctx, AV_LOG_INFO, "warning, clipping %d dct coefficients to %d..%d\n", overflow, minlevel, maxlevel); |
344 | 4134 } |
324 | 4135 |
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
|
4136 #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
|
4137 |
1098
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
4138 /** |
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
4139 * |
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
4140 * @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
|
4141 */ |
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
4142 void ff_draw_horiz_band(MpegEncContext *s, int y, int h){ |
1368 | 4143 if (s->avctx->draw_horiz_band) { |
1370 | 4144 AVFrame *src; |
1368 | 4145 int offset[4]; |
2967 | 4146 |
1370 | 4147 if(s->picture_structure != PICT_FRAME){ |
4148 h <<= 1; | |
4149 y <<= 1; | |
4150 if(s->first_field && !(s->avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return; | |
4151 } | |
4152 | |
2266
514949de5d15
set AVCodecContext.width/height to the picture width/height instead of the one stored in the bitstream (that only matters if lowres!=0)
michael
parents:
2265
diff
changeset
|
4153 h= FFMIN(h, s->avctx->height - y); |
1098
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
4154 |
2967 | 4155 if(s->pict_type==B_TYPE || s->low_delay || (s->avctx->slice_flags&SLICE_FLAG_CODED_ORDER)) |
1370 | 4156 src= (AVFrame*)s->current_picture_ptr; |
4157 else if(s->last_picture_ptr) | |
4158 src= (AVFrame*)s->last_picture_ptr; | |
4159 else | |
4160 return; | |
2967 | 4161 |
1369 | 4162 if(s->pict_type==B_TYPE && s->picture_structure == PICT_FRAME && s->out_format != FMT_H264){ |
1368 | 4163 offset[0]= |
4164 offset[1]= | |
4165 offset[2]= | |
4166 offset[3]= 0; | |
4167 }else{ | |
4168 offset[0]= y * s->linesize;; | |
2967 | 4169 offset[1]= |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4170 offset[2]= (y >> s->chroma_y_shift) * s->uvlinesize; |
1368 | 4171 offset[3]= 0; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4172 } |
1368 | 4173 |
813 | 4174 emms_c(); |
4175 | |
1370 | 4176 s->avctx->draw_horiz_band(s->avctx, src, offset, |
4177 y, s->picture_structure, h); | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4178 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4179 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4180 |
1389 | 4181 void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename |
2764 | 4182 const int linesize= s->current_picture.linesize[0]; //not s->linesize as this would be wrong for field pics |
1389 | 4183 const int uvlinesize= s->current_picture.linesize[1]; |
2256 | 4184 const int mb_size= 4 - s->avctx->lowres; |
2967 | 4185 |
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
4186 s->block_index[0]= s->b8_stride*(s->mb_y*2 ) - 2 + s->mb_x*2; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
4187 s->block_index[1]= s->b8_stride*(s->mb_y*2 ) - 1 + s->mb_x*2; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
4188 s->block_index[2]= s->b8_stride*(s->mb_y*2 + 1) - 2 + s->mb_x*2; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
4189 s->block_index[3]= s->b8_stride*(s->mb_y*2 + 1) - 1 + s->mb_x*2; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
4190 s->block_index[4]= s->mb_stride*(s->mb_y + 1) + s->b8_stride*s->mb_height*2 + s->mb_x - 1; |
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
4191 s->block_index[5]= s->mb_stride*(s->mb_y + s->mb_height + 2) + s->b8_stride*s->mb_height*2 + s->mb_x - 1; |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4192 //block_index is not used by mpeg2, so it is not affected by chroma_format |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4193 |
2256 | 4194 s->dest[0] = s->current_picture.data[0] + ((s->mb_x - 1) << mb_size); |
4195 s->dest[1] = s->current_picture.data[1] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift)); | |
4196 s->dest[2] = s->current_picture.data[2] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift)); | |
2168 | 4197 |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4198 if(!(s->pict_type==B_TYPE && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME)) |
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4199 { |
2256 | 4200 s->dest[0] += s->mb_y * linesize << mb_size; |
4201 s->dest[1] += s->mb_y * uvlinesize << (mb_size - s->chroma_y_shift); | |
4202 s->dest[2] += s->mb_y * uvlinesize << (mb_size - s->chroma_y_shift); | |
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
4203 } |
1389 | 4204 } |
4205 | |
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
|
4206 #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
|
4207 |
1777 | 4208 static void get_vissual_weight(int16_t *weight, uint8_t *ptr, int stride){ |
4209 int x, y; | |
4210 //FIXME optimize | |
4211 for(y=0; y<8; y++){ | |
4212 for(x=0; x<8; x++){ | |
4213 int x2, y2; | |
4214 int sum=0; | |
4215 int sqr=0; | |
4216 int count=0; | |
4217 | |
4218 for(y2= FFMAX(y-1, 0); y2 < FFMIN(8, y+2); y2++){ | |
4219 for(x2= FFMAX(x-1, 0); x2 < FFMIN(8, x+2); x2++){ | |
4220 int v= ptr[x2 + y2*stride]; | |
4221 sum += v; | |
4222 sqr += v*v; | |
4223 count++; | |
4224 } | |
4225 } | |
4226 weight[x + 8*y]= (36*ff_sqrt(count*sqr - sum*sum)) / count; | |
4227 } | |
4228 } | |
4229 } | |
4230 | |
324 | 4231 static void encode_mb(MpegEncContext *s, int motion_x, int motion_y) |
294 | 4232 { |
1777 | 4233 int16_t weight[6][64]; |
4234 DCTELEM orig[6][64]; | |
294 | 4235 const int mb_x= s->mb_x; |
4236 const int mb_y= s->mb_y; | |
4237 int i; | |
456 | 4238 int skip_dct[6]; |
697 | 4239 int dct_offset = s->linesize*8; //default for progressive frames |
1778 | 4240 uint8_t *ptr_y, *ptr_cb, *ptr_cr; |
4241 int wrap_y, wrap_c; | |
2967 | 4242 |
456 | 4243 for(i=0; i<6; i++) skip_dct[i]=0; |
2967 | 4244 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
4245 if(s->adaptive_quant){ |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
4246 const int last_qp= s->qscale; |
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
4247 const int mb_xy= mb_x + mb_y*s->mb_stride; |
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
4248 |
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
4249 s->lambda= s->lambda_table[mb_xy]; |
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
4250 update_qscale(s); |
2967 | 4251 |
1616 | 4252 if(!(s->flags&CODEC_FLAG_QP_RD)){ |
4253 s->dquant= s->qscale - last_qp; | |
4254 | |
1805
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4255 if(s->out_format==FMT_H263){ |
1616 | 4256 s->dquant= clip(s->dquant, -2, 2); //FIXME RD |
2967 | 4257 |
4258 if(s->codec_id==CODEC_ID_MPEG4){ | |
1805
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4259 if(!s->mb_intra){ |
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4260 if(s->pict_type == B_TYPE){ |
2967 | 4261 if(s->dquant&1) |
1805
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4262 s->dquant= (s->dquant/2)*2; |
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4263 if(s->mv_dir&MV_DIRECT) |
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4264 s->dquant= 0; |
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4265 } |
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4266 if(s->mv_type==MV_TYPE_8X8) |
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4267 s->dquant=0; |
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4268 } |
1616 | 4269 } |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
4270 } |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
4271 } |
1652 | 4272 ff_set_qscale(s, last_qp + s->dquant); |
2054 | 4273 }else if(s->flags&CODEC_FLAG_QP_RD) |
4274 ff_set_qscale(s, s->qscale + s->dquant); | |
294 | 4275 |
1778 | 4276 wrap_y = s->linesize; |
4277 wrap_c = s->uvlinesize; | |
4278 ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16; | |
4279 ptr_cb = s->new_picture.data[1] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
4280 ptr_cr = s->new_picture.data[2] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
4281 | |
4282 if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ | |
2165
5ca07515a309
10l (dont store 2 different things at the same place ...)
michael
parents:
2132
diff
changeset
|
4283 uint8_t *ebuf= s->edge_emu_buffer + 32; |
5ca07515a309
10l (dont store 2 different things at the same place ...)
michael
parents:
2132
diff
changeset
|
4284 ff_emulated_edge_mc(ebuf , ptr_y , wrap_y,16,16,mb_x*16,mb_y*16, s->width , s->height); |
5ca07515a309
10l (dont store 2 different things at the same place ...)
michael
parents:
2132
diff
changeset
|
4285 ptr_y= ebuf; |
5ca07515a309
10l (dont store 2 different things at the same place ...)
michael
parents:
2132
diff
changeset
|
4286 ff_emulated_edge_mc(ebuf+18*wrap_y , ptr_cb, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
5ca07515a309
10l (dont store 2 different things at the same place ...)
michael
parents:
2132
diff
changeset
|
4287 ptr_cb= ebuf+18*wrap_y; |
5ca07515a309
10l (dont store 2 different things at the same place ...)
michael
parents:
2132
diff
changeset
|
4288 ff_emulated_edge_mc(ebuf+18*wrap_y+8, ptr_cr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
5ca07515a309
10l (dont store 2 different things at the same place ...)
michael
parents:
2132
diff
changeset
|
4289 ptr_cr= ebuf+18*wrap_y+8; |
1778 | 4290 } |
4291 | |
324 | 4292 if (s->mb_intra) { |
697 | 4293 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ |
4294 int progressive_score, interlaced_score; | |
1708 | 4295 |
1729 | 4296 s->interlaced_dct=0; |
2967 | 4297 progressive_score= s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y, 8) |
1777 | 4298 +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y*8, NULL, wrap_y, 8) - 400; |
1729 | 4299 |
4300 if(progressive_score > 0){ | |
2967 | 4301 interlaced_score = s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y*2, 8) |
1777 | 4302 +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y , NULL, wrap_y*2, 8); |
1729 | 4303 if(progressive_score > interlaced_score){ |
4304 s->interlaced_dct=1; | |
2967 | 4305 |
1729 | 4306 dct_offset= wrap_y; |
4307 wrap_y<<=1; | |
4308 } | |
4309 } | |
697 | 4310 } |
2967 | 4311 |
2979 | 4312 s->dsp.get_pixels(s->block[0], ptr_y , wrap_y); |
1777 | 4313 s->dsp.get_pixels(s->block[1], ptr_y + 8, wrap_y); |
4314 s->dsp.get_pixels(s->block[2], ptr_y + dct_offset , wrap_y); | |
4315 s->dsp.get_pixels(s->block[3], ptr_y + dct_offset + 8, wrap_y); | |
294 | 4316 |
487 | 4317 if(s->flags&CODEC_FLAG_GRAY){ |
4318 skip_dct[4]= 1; | |
4319 skip_dct[5]= 1; | |
4320 }else{ | |
2979 | 4321 s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c); |
1777 | 4322 s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c); |
4323 } | |
324 | 4324 }else{ |
651 | 4325 op_pixels_func (*op_pix)[4]; |
4326 qpel_mc_func (*op_qpix)[16]; | |
1064 | 4327 uint8_t *dest_y, *dest_cb, *dest_cr; |
294 | 4328 |
1389 | 4329 dest_y = s->dest[0]; |
4330 dest_cb = s->dest[1]; | |
4331 dest_cr = s->dest[2]; | |
324 | 4332 |
327 | 4333 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
2979 | 4334 op_pix = s->dsp.put_pixels_tab; |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
4335 op_qpix= s->dsp.put_qpel_pixels_tab; |
295 | 4336 }else{ |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
4337 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
|
4338 op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab; |
324 | 4339 } |
295 | 4340 |
324 | 4341 if (s->mv_dir & MV_DIR_FORWARD) { |
903 | 4342 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
|
4343 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
|
4344 op_qpix= s->dsp.avg_qpel_pixels_tab; |
324 | 4345 } |
4346 if (s->mv_dir & MV_DIR_BACKWARD) { | |
903 | 4347 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix); |
324 | 4348 } |
295 | 4349 |
697 | 4350 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ |
4351 int progressive_score, interlaced_score; | |
1729 | 4352 |
4353 s->interlaced_dct=0; | |
2967 | 4354 progressive_score= s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y, 8) |
1729 | 4355 +s->dsp.ildct_cmp[0](s, dest_y + wrap_y*8, ptr_y + wrap_y*8, wrap_y, 8) - 400; |
2967 | 4356 |
1729 | 4357 if(s->avctx->ildct_cmp == FF_CMP_VSSE) progressive_score -= 400; |
4358 | |
4359 if(progressive_score>0){ | |
2967 | 4360 interlaced_score = s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y*2, 8) |
1729 | 4361 +s->dsp.ildct_cmp[0](s, dest_y + wrap_y , ptr_y + wrap_y , wrap_y*2, 8); |
2967 | 4362 |
1729 | 4363 if(progressive_score > interlaced_score){ |
4364 s->interlaced_dct=1; | |
2967 | 4365 |
1729 | 4366 dct_offset= wrap_y; |
4367 wrap_y<<=1; | |
4368 } | |
4369 } | |
697 | 4370 } |
2967 | 4371 |
2979 | 4372 s->dsp.diff_pixels(s->block[0], ptr_y , dest_y , wrap_y); |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
4373 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
|
4374 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
|
4375 s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y); |
2967 | 4376 |
487 | 4377 if(s->flags&CODEC_FLAG_GRAY){ |
4378 skip_dct[4]= 1; | |
4379 skip_dct[5]= 1; | |
4380 }else{ | |
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
4381 s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c); |
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
4382 s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); |
487 | 4383 } |
2967 | 4384 /* pre quantization */ |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
4385 if(s->current_picture.mc_mb_var[s->mb_stride*mb_y+ mb_x]<2*s->qscale*s->qscale){ |
697 | 4386 //FIXME optimize |
2979 | 4387 if(s->dsp.sad[1](NULL, ptr_y , dest_y , wrap_y, 8) < 20*s->qscale) skip_dct[0]= 1; |
1708 | 4388 if(s->dsp.sad[1](NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20*s->qscale) skip_dct[1]= 1; |
4389 if(s->dsp.sad[1](NULL, ptr_y +dct_offset , dest_y +dct_offset , wrap_y, 8) < 20*s->qscale) skip_dct[2]= 1; | |
4390 if(s->dsp.sad[1](NULL, ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y, 8) < 20*s->qscale) skip_dct[3]= 1; | |
4391 if(s->dsp.sad[1](NULL, ptr_cb , dest_cb , wrap_c, 8) < 20*s->qscale) skip_dct[4]= 1; | |
4392 if(s->dsp.sad[1](NULL, ptr_cr , dest_cr , wrap_c, 8) < 20*s->qscale) skip_dct[5]= 1; | |
456 | 4393 } |
1778 | 4394 } |
4395 | |
4396 if(s->avctx->quantizer_noise_shaping){ | |
4397 if(!skip_dct[0]) get_vissual_weight(weight[0], ptr_y , wrap_y); | |
4398 if(!skip_dct[1]) get_vissual_weight(weight[1], ptr_y + 8, wrap_y); | |
4399 if(!skip_dct[2]) get_vissual_weight(weight[2], ptr_y + dct_offset , wrap_y); | |
4400 if(!skip_dct[3]) get_vissual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y); | |
4401 if(!skip_dct[4]) get_vissual_weight(weight[4], ptr_cb , wrap_c); | |
4402 if(!skip_dct[5]) get_vissual_weight(weight[5], ptr_cr , wrap_c); | |
4403 memcpy(orig[0], s->block[0], sizeof(DCTELEM)*64*6); | |
294 | 4404 } |
2967 | 4405 |
294 | 4406 /* DCT & quantize */ |
1778 | 4407 assert(s->out_format!=FMT_MJPEG || s->qscale==8); |
4408 { | |
344 | 4409 for(i=0;i<6;i++) { |
456 | 4410 if(!skip_dct[i]){ |
4411 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
|
4412 s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); |
344 | 4413 // 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
|
4414 // 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
|
4415 // of improve it. Just INTRADC clipping deserves changes in quantizer |
456 | 4416 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
4417 }else | |
4418 s->block_last_index[i]= -1; | |
344 | 4419 } |
1777 | 4420 if(s->avctx->quantizer_noise_shaping){ |
4421 for(i=0;i<6;i++) { | |
4422 if(!skip_dct[i]){ | |
4423 s->block_last_index[i] = dct_quantize_refine(s, s->block[i], weight[i], orig[i], i, s->qscale); | |
4424 } | |
4425 } | |
4426 } | |
2967 | 4427 |
456 | 4428 if(s->luma_elim_threshold && !s->mb_intra) |
4429 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
|
4430 dct_single_coeff_elimination(s, i, s->luma_elim_threshold); |
456 | 4431 if(s->chroma_elim_threshold && !s->mb_intra) |
4432 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
|
4433 dct_single_coeff_elimination(s, i, s->chroma_elim_threshold); |
1497 | 4434 |
4435 if(s->flags & CODEC_FLAG_CBP_RD){ | |
4436 for(i=0;i<6;i++) { | |
4437 if(s->block_last_index[i] == -1) | |
4438 s->coded_score[i]= INT_MAX/256; | |
4439 } | |
4440 } | |
294 | 4441 } |
4442 | |
487 | 4443 if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){ |
4444 s->block_last_index[4]= | |
4445 s->block_last_index[5]= 0; | |
4446 s->block[4][0]= | |
1011 | 4447 s->block[5][0]= (1024 + s->c_dc_scale/2)/ s->c_dc_scale; |
487 | 4448 } |
4449 | |
1708 | 4450 //non c quantize code returns incorrect block_last_index FIXME |
4451 if(s->alternate_scan && s->dct_quantize != dct_quantize_c){ | |
4452 for(i=0; i<6; i++){ | |
4453 int j; | |
4454 if(s->block_last_index[i]>0){ | |
4455 for(j=63; j>0; j--){ | |
4456 if(s->block[i][ s->intra_scantable.permutated[j] ]) break; | |
4457 } | |
4458 s->block_last_index[i]= j; | |
4459 } | |
4460 } | |
4461 } | |
4462 | |
294 | 4463 /* huffman encode */ |
936 | 4464 switch(s->codec_id){ //FIXME funct ptr could be slightly faster |
4465 case CODEC_ID_MPEG1VIDEO: | |
1421 | 4466 case CODEC_ID_MPEG2VIDEO: |
936 | 4467 mpeg1_encode_mb(s, s->block, motion_x, motion_y); break; |
4468 case CODEC_ID_MPEG4: | |
4469 mpeg4_encode_mb(s, s->block, motion_x, motion_y); break; | |
4470 case CODEC_ID_MSMPEG4V2: | |
4471 case CODEC_ID_MSMPEG4V3: | |
4472 case CODEC_ID_WMV1: | |
4473 msmpeg4_encode_mb(s, s->block, motion_x, motion_y); break; | |
4474 case CODEC_ID_WMV2: | |
4475 ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); break; | |
2639 | 4476 #ifdef CONFIG_H261_ENCODER |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
4477 case CODEC_ID_H261: |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
4478 ff_h261_encode_mb(s, s->block, motion_x, motion_y); break; |
2639 | 4479 #endif |
936 | 4480 case CODEC_ID_H263: |
4481 case CODEC_ID_H263P: | |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4482 case CODEC_ID_FLV1: |
936 | 4483 case CODEC_ID_RV10: |
2380 | 4484 case CODEC_ID_RV20: |
936 | 4485 h263_encode_mb(s, s->block, motion_x, motion_y); break; |
1042 | 4486 case CODEC_ID_MJPEG: |
4487 mjpeg_encode_mb(s, s->block); break; | |
936 | 4488 default: |
4489 assert(0); | |
294 | 4490 } |
4491 } | |
4492 | |
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
|
4493 #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
|
4494 |
1368 | 4495 void ff_mpeg_flush(AVCodecContext *avctx){ |
4496 int i; | |
4497 MpegEncContext *s = avctx->priv_data; | |
2967 | 4498 |
4499 if(s==NULL || s->picture==NULL) | |
1751 | 4500 return; |
2967 | 4501 |
1368 | 4502 for(i=0; i<MAX_PICTURE_COUNT; i++){ |
4503 if(s->picture[i].data[0] && ( s->picture[i].type == FF_BUFFER_TYPE_INTERNAL | |
4504 || s->picture[i].type == FF_BUFFER_TYPE_USER)) | |
4505 avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]); | |
4506 } | |
1601 | 4507 s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL; |
2967 | 4508 |
2380 | 4509 s->mb_x= s->mb_y= 0; |
2967 | 4510 |
1395 | 4511 s->parse_context.state= -1; |
4512 s->parse_context.frame_start_found= 0; | |
4513 s->parse_context.overread= 0; | |
4514 s->parse_context.overread_index= 0; | |
4515 s->parse_context.index= 0; | |
4516 s->parse_context.last_index= 0; | |
1851 | 4517 s->bitstream_buffer_size=0; |
1368 | 4518 } |
4519 | |
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
|
4520 #ifdef CONFIG_ENCODERS |
1064 | 4521 void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length) |
294 | 4522 { |
1810 | 4523 const uint16_t *srcw= (uint16_t*)src; |
1799 | 4524 int words= length>>4; |
326 | 4525 int bits= length&15; |
4526 int i; | |
4527 | |
456 | 4528 if(length==0) return; |
2967 | 4529 |
1803 | 4530 if(words < 16){ |
4531 for(i=0; i<words; i++) put_bits(pb, 16, be2me_16(srcw[i])); | |
4532 }else if(put_bits_count(pb)&7){ | |
4533 for(i=0; i<words; i++) put_bits(pb, 16, be2me_16(srcw[i])); | |
1802
e91dbb5b1a8d
activate the memcpy special case for the byte aligned case in ff_copy_bits(), wasnt working before because of a incorrectly used pbBufPtr()
michael
parents:
1801
diff
changeset
|
4534 }else{ |
1803 | 4535 for(i=0; put_bits_count(pb)&31; i++) |
4536 put_bits(pb, 8, src[i]); | |
1799 | 4537 flush_put_bits(pb); |
1803 | 4538 memcpy(pbBufPtr(pb), src+i, 2*words-i); |
4539 skip_put_bytes(pb, 2*words-i); | |
1802
e91dbb5b1a8d
activate the memcpy special case for the byte aligned case in ff_copy_bits(), wasnt working before because of a incorrectly used pbBufPtr()
michael
parents:
1801
diff
changeset
|
4540 } |
2967 | 4541 |
1803 | 4542 put_bits(pb, bits, be2me_16(srcw[words])>>(16-bits)); |
0 | 4543 } |
4544 | |
456 | 4545 static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
326 | 4546 int i; |
4547 | |
4548 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
4549 | |
4550 /* mpeg1 */ | |
1160 | 4551 d->mb_skip_run= s->mb_skip_run; |
326 | 4552 for(i=0; i<3; i++) |
4553 d->last_dc[i]= s->last_dc[i]; | |
2967 | 4554 |
326 | 4555 /* statistics */ |
4556 d->mv_bits= s->mv_bits; | |
4557 d->i_tex_bits= s->i_tex_bits; | |
4558 d->p_tex_bits= s->p_tex_bits; | |
4559 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
|
4560 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
|
4561 d->b_count= s->b_count; |
326 | 4562 d->skip_count= s->skip_count; |
4563 d->misc_bits= s->misc_bits; | |
329 | 4564 d->last_bits= 0; |
327 | 4565 |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2627
diff
changeset
|
4566 d->mb_skipped= 0; |
912 | 4567 d->qscale= s->qscale; |
1616 | 4568 d->dquant= s->dquant; |
326 | 4569 } |
4570 | |
456 | 4571 static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
326 | 4572 int i; |
4573 | |
2967 | 4574 memcpy(d->mv, s->mv, 2*4*2*sizeof(int)); |
326 | 4575 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? |
2967 | 4576 |
326 | 4577 /* mpeg1 */ |
1160 | 4578 d->mb_skip_run= s->mb_skip_run; |
326 | 4579 for(i=0; i<3; i++) |
4580 d->last_dc[i]= s->last_dc[i]; | |
2967 | 4581 |
326 | 4582 /* statistics */ |
4583 d->mv_bits= s->mv_bits; | |
4584 d->i_tex_bits= s->i_tex_bits; | |
4585 d->p_tex_bits= s->p_tex_bits; | |
4586 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
|
4587 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
|
4588 d->b_count= s->b_count; |
326 | 4589 d->skip_count= s->skip_count; |
4590 d->misc_bits= s->misc_bits; | |
4591 | |
4592 d->mb_intra= s->mb_intra; | |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2627
diff
changeset
|
4593 d->mb_skipped= s->mb_skipped; |
326 | 4594 d->mv_type= s->mv_type; |
4595 d->mv_dir= s->mv_dir; | |
4596 d->pb= s->pb; | |
456 | 4597 if(s->data_partitioning){ |
4598 d->pb2= s->pb2; | |
4599 d->tex_pb= s->tex_pb; | |
4600 } | |
326 | 4601 d->block= s->block; |
4602 for(i=0; i<6; i++) | |
4603 d->block_last_index[i]= s->block_last_index[i]; | |
755 | 4604 d->interlaced_dct= s->interlaced_dct; |
912 | 4605 d->qscale= s->qscale; |
326 | 4606 } |
4607 | |
2967 | 4608 static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type, |
456 | 4609 PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2], |
4610 int *dmin, int *next_block, int motion_x, int motion_y) | |
4611 { | |
1389 | 4612 int score; |
4613 uint8_t *dest_backup[3]; | |
2967 | 4614 |
456 | 4615 copy_context_before_encode(s, backup, type); |
4616 | |
4617 s->block= s->blocks[*next_block]; | |
4618 s->pb= pb[*next_block]; | |
4619 if(s->data_partitioning){ | |
4620 s->pb2 = pb2 [*next_block]; | |
4621 s->tex_pb= tex_pb[*next_block]; | |
4622 } | |
2967 | 4623 |
1389 | 4624 if(*next_block){ |
4625 memcpy(dest_backup, s->dest, sizeof(s->dest)); | |
1799 | 4626 s->dest[0] = s->rd_scratchpad; |
4627 s->dest[1] = s->rd_scratchpad + 16*s->linesize; | |
4628 s->dest[2] = s->rd_scratchpad + 16*s->linesize + 8; | |
4629 assert(s->linesize >= 32); //FIXME | |
1389 | 4630 } |
456 | 4631 |
4632 encode_mb(s, motion_x, motion_y); | |
2967 | 4633 |
1786 | 4634 score= put_bits_count(&s->pb); |
456 | 4635 if(s->data_partitioning){ |
1786 | 4636 score+= put_bits_count(&s->pb2); |
4637 score+= put_bits_count(&s->tex_pb); | |
456 | 4638 } |
2967 | 4639 |
1389 | 4640 if(s->avctx->mb_decision == FF_MB_DECISION_RD){ |
4641 MPV_decode_mb(s, s->block); | |
4642 | |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
4643 score *= s->lambda2; |
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
4644 score += sse_mb(s) << FF_LAMBDA_SHIFT; |
1389 | 4645 } |
2967 | 4646 |
1389 | 4647 if(*next_block){ |
4648 memcpy(s->dest, dest_backup, sizeof(s->dest)); | |
4649 } | |
4650 | |
4651 if(score<*dmin){ | |
4652 *dmin= score; | |
456 | 4653 *next_block^=1; |
4654 | |
4655 copy_context_after_encode(best, s, type); | |
4656 } | |
4657 } | |
2967 | 4658 |
1389 | 4659 static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride){ |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4660 uint32_t *sq = squareTbl + 256; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4661 int acc=0; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4662 int x,y; |
2967 | 4663 |
4664 if(w==16 && h==16) | |
1708 | 4665 return s->dsp.sse[0](NULL, src1, src2, stride, 16); |
936 | 4666 else if(w==8 && h==8) |
1708 | 4667 return s->dsp.sse[1](NULL, src1, src2, stride, 8); |
2967 | 4668 |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4669 for(y=0; y<h; y++){ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4670 for(x=0; x<w; x++){ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4671 acc+= sq[src1[x + y*stride] - src2[x + y*stride]]; |
2967 | 4672 } |
4673 } | |
4674 | |
936 | 4675 assert(acc>=0); |
2967 | 4676 |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4677 return acc; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4678 } |
326 | 4679 |
1389 | 4680 static int sse_mb(MpegEncContext *s){ |
4681 int w= 16; | |
4682 int h= 16; | |
4683 | |
4684 if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16; | |
4685 if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; | |
4686 | |
4687 if(w==16 && h==16) | |
2065
9e4bebc39ade
noise preserving sum of squares comparission function
michael
parents:
2063
diff
changeset
|
4688 if(s->avctx->mb_cmp == FF_CMP_NSSE){ |
2066 | 4689 return s->dsp.nsse[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16) |
4690 +s->dsp.nsse[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8) | |
4691 +s->dsp.nsse[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8); | |
2065
9e4bebc39ade
noise preserving sum of squares comparission function
michael
parents:
2063
diff
changeset
|
4692 }else{ |
1708 | 4693 return s->dsp.sse[0](NULL, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16) |
4694 +s->dsp.sse[1](NULL, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8) | |
4695 +s->dsp.sse[1](NULL, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8); | |
2065
9e4bebc39ade
noise preserving sum of squares comparission function
michael
parents:
2063
diff
changeset
|
4696 } |
1389 | 4697 else |
4698 return sse(s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, s->linesize) | |
4699 +sse(s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], w>>1, h>>1, s->uvlinesize) | |
4700 +sse(s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], w>>1, h>>1, s->uvlinesize); | |
4701 } | |
4702 | |
1799 | 4703 static int pre_estimate_motion_thread(AVCodecContext *c, void *arg){ |
4704 MpegEncContext *s= arg; | |
4705 | |
2967 | 4706 |
1799 | 4707 s->me.pre_pass=1; |
4708 s->me.dia_size= s->avctx->pre_dia_size; | |
4709 s->first_slice_line=1; | |
4710 for(s->mb_y= s->end_mb_y-1; s->mb_y >= s->start_mb_y; s->mb_y--) { | |
4711 for(s->mb_x=s->mb_width-1; s->mb_x >=0 ;s->mb_x--) { | |
4712 ff_pre_estimate_p_frame_motion(s, s->mb_x, s->mb_y); | |
4713 } | |
4714 s->first_slice_line=0; | |
4715 } | |
2967 | 4716 |
1799 | 4717 s->me.pre_pass=0; |
2967 | 4718 |
1799 | 4719 return 0; |
4720 } | |
4721 | |
4722 static int estimate_motion_thread(AVCodecContext *c, void *arg){ | |
4723 MpegEncContext *s= arg; | |
4724 | |
4725 s->me.dia_size= s->avctx->dia_size; | |
4726 s->first_slice_line=1; | |
4727 for(s->mb_y= s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { | |
4728 s->mb_x=0; //for block init below | |
4729 ff_init_block_index(s); | |
4730 for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) { | |
4731 s->block_index[0]+=2; | |
4732 s->block_index[1]+=2; | |
4733 s->block_index[2]+=2; | |
4734 s->block_index[3]+=2; | |
2967 | 4735 |
1799 | 4736 /* compute motion vector & mb_type and store in context */ |
4737 if(s->pict_type==B_TYPE) | |
4738 ff_estimate_b_frame_motion(s, s->mb_x, s->mb_y); | |
4739 else | |
4740 ff_estimate_p_frame_motion(s, s->mb_x, s->mb_y); | |
4741 } | |
4742 s->first_slice_line=0; | |
4743 } | |
4744 return 0; | |
4745 } | |
4746 | |
1804
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4747 static int mb_var_thread(AVCodecContext *c, void *arg){ |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4748 MpegEncContext *s= arg; |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4749 int mb_x, mb_y; |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4750 |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4751 for(mb_y=s->start_mb_y; mb_y < s->end_mb_y; mb_y++) { |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4752 for(mb_x=0; mb_x < s->mb_width; mb_x++) { |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4753 int xx = mb_x * 16; |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4754 int yy = mb_y * 16; |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4755 uint8_t *pix = s->new_picture.data[0] + (yy * s->linesize) + xx; |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4756 int varc; |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4757 int sum = s->dsp.pix_sum(pix, s->linesize); |
2967 | 4758 |
1804
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4759 varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8; |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4760 |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4761 s->current_picture.mb_var [s->mb_stride * mb_y + mb_x] = varc; |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4762 s->current_picture.mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8; |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
4763 s->me.mb_var_sum_temp += varc; |
1804
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4764 } |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4765 } |
1805
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4766 return 0; |
1804
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4767 } |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4768 |
1799 | 4769 static void write_slice_end(MpegEncContext *s){ |
4770 if(s->codec_id==CODEC_ID_MPEG4){ | |
4771 if(s->partitioned_frame){ | |
4772 ff_mpeg4_merge_partitions(s); | |
4773 } | |
2967 | 4774 |
1799 | 4775 ff_mpeg4_stuffing(&s->pb); |
4776 }else if(s->out_format == FMT_MJPEG){ | |
4777 ff_mjpeg_stuffing(&s->pb); | |
4778 } | |
4779 | |
4780 align_put_bits(&s->pb); | |
4781 flush_put_bits(&s->pb); | |
2967 | 4782 |
2428
548c87c06dbb
assertion about bits statistic and minor bits stat fix
michael
parents:
2427
diff
changeset
|
4783 if((s->flags&CODEC_FLAG_PASS1) && !s->partitioned_frame) |
548c87c06dbb
assertion about bits statistic and minor bits stat fix
michael
parents:
2427
diff
changeset
|
4784 s->misc_bits+= get_bits_diff(s); |
1799 | 4785 } |
4786 | |
4787 static int encode_thread(AVCodecContext *c, void *arg){ | |
4788 MpegEncContext *s= arg; | |
766 | 4789 int mb_x, mb_y, pdif = 0; |
1708 | 4790 int i, j; |
326 | 4791 MpegEncContext best_s, backup_s; |
2422 | 4792 uint8_t bit_buf[2][MAX_MB_BYTES]; |
4793 uint8_t bit_buf2[2][MAX_MB_BYTES]; | |
4794 uint8_t bit_buf_tex[2][MAX_MB_BYTES]; | |
456 | 4795 PutBitContext pb[2], pb2[2], tex_pb[2]; |
1799 | 4796 //printf("%d->%d\n", s->resync_mb_y, s->end_mb_y); |
456 | 4797 |
4798 for(i=0; i<2; i++){ | |
2422 | 4799 init_put_bits(&pb [i], bit_buf [i], MAX_MB_BYTES); |
4800 init_put_bits(&pb2 [i], bit_buf2 [i], MAX_MB_BYTES); | |
4801 init_put_bits(&tex_pb[i], bit_buf_tex[i], MAX_MB_BYTES); | |
456 | 4802 } |
0 | 4803 |
1786 | 4804 s->last_bits= put_bits_count(&s->pb); |
286 | 4805 s->mv_bits=0; |
4806 s->misc_bits=0; | |
4807 s->i_tex_bits=0; | |
4808 s->p_tex_bits=0; | |
4809 s->i_count=0; | |
656
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
4810 s->f_count=0; |
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
4811 s->b_count=0; |
286 | 4812 s->skip_count=0; |
4813 | |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4814 for(i=0; i<3; i++){ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4815 /* init last dc values */ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4816 /* note: quant matrix value (8) is implied here */ |
1992 | 4817 s->last_dc[i] = 128 << s->intra_dc_precision; |
2967 | 4818 |
2955 | 4819 s->current_picture.error[i] = 0; |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4820 } |
1160 | 4821 s->mb_skip_run = 0; |
1708 | 4822 memset(s->last_mv, 0, sizeof(s->last_mv)); |
2967 | 4823 |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
4824 s->last_mv_dir = 0; |
0 | 4825 |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4826 switch(s->codec_id){ |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4827 case CODEC_ID_H263: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4828 case CODEC_ID_H263P: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4829 case CODEC_ID_FLV1: |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4830 s->gob_index = ff_h263_get_gob_height(s); |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4831 break; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4832 case CODEC_ID_MPEG4: |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4833 if(s->partitioned_frame) |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4834 ff_mpeg4_init_partitions(s); |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4835 break; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4836 } |
456 | 4837 |
4838 s->resync_mb_x=0; | |
2967 | 4839 s->resync_mb_y=0; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4840 s->first_slice_line = 1; |
766 | 4841 s->ptr_lastgob = s->pb.buf; |
1799 | 4842 for(mb_y= s->start_mb_y; mb_y < s->end_mb_y; mb_y++) { |
4843 // printf("row %d at %X\n", s->mb_y, (int)s); | |
1389 | 4844 s->mb_x=0; |
4845 s->mb_y= mb_y; | |
4846 | |
1652 | 4847 ff_set_qscale(s, s->qscale); |
1389 | 4848 ff_init_block_index(s); |
2967 | 4849 |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
4850 for(mb_x=0; mb_x < s->mb_width; mb_x++) { |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
4851 int xy= mb_y*s->mb_stride + mb_x; // removed const, H261 needs to adjust this |
1177
fea03d2c4946
simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents:
1173
diff
changeset
|
4852 int mb_type= s->mb_type[xy]; |
456 | 4853 // int d; |
1389 | 4854 int dmin= INT_MAX; |
1708 | 4855 int dir; |
0 | 4856 |
2422 | 4857 if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < MAX_MB_BYTES){ |
4858 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); | |
4859 return -1; | |
4860 } | |
4861 if(s->data_partitioning){ | |
4862 if( s->pb2 .buf_end - s->pb2 .buf - (put_bits_count(&s-> pb2)>>3) < MAX_MB_BYTES | |
4863 || s->tex_pb.buf_end - s->tex_pb.buf - (put_bits_count(&s->tex_pb )>>3) < MAX_MB_BYTES){ | |
4864 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); | |
4865 return -1; | |
4866 } | |
4867 } | |
4868 | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
4869 s->mb_x = mb_x; |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
4870 s->mb_y = mb_y; // moved into loop, can get changed by H.261 |
1389 | 4871 ff_update_block_index(s); |
456 | 4872 |
2639 | 4873 #ifdef CONFIG_H261_ENCODER |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
4874 if(s->codec_id == CODEC_ID_H261){ |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
4875 ff_h261_reorder_mb_index(s); |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
4876 xy= s->mb_y*s->mb_stride + s->mb_x; |
2345 | 4877 mb_type= s->mb_type[xy]; |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
4878 } |
2639 | 4879 #endif |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
4880 |
766 | 4881 /* write gob / video packet header */ |
1661 | 4882 if(s->rtp_mode){ |
766 | 4883 int current_packet_size, is_gob_start; |
2967 | 4884 |
1801
3f26dfb3eba4
replace a few pbBufPtr() by put_bits_count(), one of them was actually wrong
michael
parents:
1799
diff
changeset
|
4885 current_packet_size= ((put_bits_count(&s->pb)+7)>>3) - (s->ptr_lastgob - s->pb.buf); |
2967 | 4886 |
4887 is_gob_start= s->avctx->rtp_payload_size && current_packet_size >= s->avctx->rtp_payload_size && mb_y + mb_x>0; | |
4888 | |
1799 | 4889 if(s->start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1; |
2967 | 4890 |
1661 | 4891 switch(s->codec_id){ |
4892 case CODEC_ID_H263: | |
4893 case CODEC_ID_H263P: | |
4894 if(!s->h263_slice_structured) | |
4895 if(s->mb_x || s->mb_y%s->gob_index) is_gob_start=0; | |
4896 break; | |
4897 case CODEC_ID_MPEG2VIDEO: | |
4898 if(s->mb_x==0 && s->mb_y!=0) is_gob_start=1; | |
4899 case CODEC_ID_MPEG1VIDEO: | |
4900 if(s->mb_skip_run) is_gob_start=0; | |
4901 break; | |
4902 } | |
1799 | 4903 |
1661 | 4904 if(is_gob_start){ |
1799 | 4905 if(s->start_mb_y != mb_y || mb_x!=0){ |
4906 write_slice_end(s); | |
4907 | |
4908 if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame){ | |
4909 ff_mpeg4_init_partitions(s); | |
4910 } | |
1661 | 4911 } |
2967 | 4912 |
1786 | 4913 assert((put_bits_count(&s->pb)&7) == 0); |
1661 | 4914 current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob; |
2967 | 4915 |
1688 | 4916 if(s->avctx->error_rate && s->resync_mb_x + s->resync_mb_y > 0){ |
2371 | 4917 int r= put_bits_count(&s->pb)/8 + s->picture_number + 16 + s->mb_x + s->mb_y; |
1688 | 4918 int d= 100 / s->avctx->error_rate; |
4919 if(r % d == 0){ | |
4920 current_packet_size=0; | |
4921 #ifndef ALT_BITSTREAM_WRITER | |
4922 s->pb.buf_ptr= s->ptr_lastgob; | |
4923 #endif | |
4924 assert(pbBufPtr(&s->pb) == s->ptr_lastgob); | |
4925 } | |
4926 } | |
2492
57ba17bd3924
rtp_callback: send number of mb patch by (Johan Bilien {jobi via.ecp fr)
michael
parents:
2450
diff
changeset
|
4927 |
57ba17bd3924
rtp_callback: send number of mb patch by (Johan Bilien {jobi via.ecp fr)
michael
parents:
2450
diff
changeset
|
4928 if (s->avctx->rtp_callback){ |
57ba17bd3924
rtp_callback: send number of mb patch by (Johan Bilien {jobi via.ecp fr)
michael
parents:
2450
diff
changeset
|
4929 int number_mb = (mb_y - s->resync_mb_y)*s->mb_width + mb_x - s->resync_mb_x; |
57ba17bd3924
rtp_callback: send number of mb patch by (Johan Bilien {jobi via.ecp fr)
michael
parents:
2450
diff
changeset
|
4930 s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, current_packet_size, number_mb); |
57ba17bd3924
rtp_callback: send number of mb patch by (Johan Bilien {jobi via.ecp fr)
michael
parents:
2450
diff
changeset
|
4931 } |
2967 | 4932 |
1661 | 4933 switch(s->codec_id){ |
4934 case CODEC_ID_MPEG4: | |
456 | 4935 ff_mpeg4_encode_video_packet_header(s); |
4936 ff_mpeg4_clean_buffers(s); | |
1661 | 4937 break; |
4938 case CODEC_ID_MPEG1VIDEO: | |
4939 case CODEC_ID_MPEG2VIDEO: | |
1421 | 4940 ff_mpeg1_encode_slice_header(s); |
4941 ff_mpeg1_clean_buffers(s); | |
1661 | 4942 break; |
4943 case CODEC_ID_H263: | |
4944 case CODEC_ID_H263P: | |
2967 | 4945 h263_encode_gob_header(s, mb_y); |
1661 | 4946 break; |
1160 | 4947 } |
1661 | 4948 |
4949 if(s->flags&CODEC_FLAG_PASS1){ | |
1786 | 4950 int bits= put_bits_count(&s->pb); |
1661 | 4951 s->misc_bits+= bits - s->last_bits; |
4952 s->last_bits= bits; | |
766 | 4953 } |
2967 | 4954 |
1662 | 4955 s->ptr_lastgob += current_packet_size; |
456 | 4956 s->first_slice_line=1; |
4957 s->resync_mb_x=mb_x; | |
4958 s->resync_mb_y=mb_y; | |
4959 } | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4960 } |
456 | 4961 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4962 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
|
4963 && s->resync_mb_y+1 == s->mb_y){ |
2967 | 4964 s->first_slice_line=0; |
456 | 4965 } |
4966 | |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2627
diff
changeset
|
4967 s->mb_skipped=0; |
1616 | 4968 s->dquant=0; //only for QP_RD |
4969 | |
2230 | 4970 if(mb_type & (mb_type-1) || (s->flags & CODEC_FLAG_QP_RD)){ // more than 1 MB type possible or CODEC_FLAG_QP_RD |
327 | 4971 int next_block=0; |
456 | 4972 int pb_bits_count, pb2_bits_count, tex_pb_bits_count; |
326 | 4973 |
4974 copy_context_before_encode(&backup_s, s, -1); | |
456 | 4975 backup_s.pb= s->pb; |
4976 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
|
4977 best_s.partitioned_frame= s->partitioned_frame; |
456 | 4978 if(s->data_partitioning){ |
4979 backup_s.pb2= s->pb2; | |
4980 backup_s.tex_pb= s->tex_pb; | |
4981 } | |
326 | 4982 |
1708 | 4983 if(mb_type&CANDIDATE_MB_TYPE_INTER){ |
327 | 4984 s->mv_dir = MV_DIR_FORWARD; |
295 | 4985 s->mv_type = MV_TYPE_16X16; |
294 | 4986 s->mb_intra= 0; |
324 | 4987 s->mv[0][0][0] = s->p_mv_table[xy][0]; |
4988 s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
2967 | 4989 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb, |
456 | 4990 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); |
0 | 4991 } |
2967 | 4992 if(mb_type&CANDIDATE_MB_TYPE_INTER_I){ |
1708 | 4993 s->mv_dir = MV_DIR_FORWARD; |
4994 s->mv_type = MV_TYPE_FIELD; | |
4995 s->mb_intra= 0; | |
4996 for(i=0; i<2; i++){ | |
4997 j= s->field_select[0][i] = s->p_field_select_table[i][xy]; | |
4998 s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; | |
4999 s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; | |
5000 } | |
2967 | 5001 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb, |
1708 | 5002 &dmin, &next_block, 0, 0); |
5003 } | |
2628
511e3afc43e1
Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents:
2627
diff
changeset
|
5004 if(mb_type&CANDIDATE_MB_TYPE_SKIPPED){ |
1494
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1490
diff
changeset
|
5005 s->mv_dir = MV_DIR_FORWARD; |
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1490
diff
changeset
|
5006 s->mv_type = MV_TYPE_16X16; |
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1490
diff
changeset
|
5007 s->mb_intra= 0; |
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1490
diff
changeset
|
5008 s->mv[0][0][0] = 0; |
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1490
diff
changeset
|
5009 s->mv[0][0][1] = 0; |
2967 | 5010 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_SKIPPED, pb, pb2, tex_pb, |
1494
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1490
diff
changeset
|
5011 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); |
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1490
diff
changeset
|
5012 } |
2967 | 5013 if(mb_type&CANDIDATE_MB_TYPE_INTER4V){ |
327 | 5014 s->mv_dir = MV_DIR_FORWARD; |
295 | 5015 s->mv_type = MV_TYPE_8X8; |
5016 s->mb_intra= 0; | |
5017 for(i=0; i<4; i++){ | |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
5018 s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
5019 s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; |
295 | 5020 } |
2967 | 5021 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb, |
456 | 5022 &dmin, &next_block, 0, 0); |
327 | 5023 } |
1708 | 5024 if(mb_type&CANDIDATE_MB_TYPE_FORWARD){ |
327 | 5025 s->mv_dir = MV_DIR_FORWARD; |
5026 s->mv_type = MV_TYPE_16X16; | |
5027 s->mb_intra= 0; | |
5028 s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
5029 s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
2967 | 5030 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb, |
456 | 5031 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); |
327 | 5032 } |
1708 | 5033 if(mb_type&CANDIDATE_MB_TYPE_BACKWARD){ |
327 | 5034 s->mv_dir = MV_DIR_BACKWARD; |
5035 s->mv_type = MV_TYPE_16X16; | |
5036 s->mb_intra= 0; | |
5037 s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
5038 s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
2967 | 5039 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb, |
456 | 5040 &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); |
327 | 5041 } |
1708 | 5042 if(mb_type&CANDIDATE_MB_TYPE_BIDIR){ |
327 | 5043 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; |
5044 s->mv_type = MV_TYPE_16X16; | |
5045 s->mb_intra= 0; | |
5046 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
5047 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
5048 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
5049 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
2967 | 5050 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb, |
456 | 5051 &dmin, &next_block, 0, 0); |
327 | 5052 } |
1708 | 5053 if(mb_type&CANDIDATE_MB_TYPE_DIRECT){ |
936 | 5054 int mx= s->b_direct_mv_table[xy][0]; |
5055 int my= s->b_direct_mv_table[xy][1]; | |
2967 | 5056 |
327 | 5057 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
5058 s->mb_intra= 0; | |
936 | 5059 ff_mpeg4_set_direct_mv(s, mx, my); |
2967 | 5060 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb, |
936 | 5061 &dmin, &next_block, mx, my); |
295 | 5062 } |
2967 | 5063 if(mb_type&CANDIDATE_MB_TYPE_FORWARD_I){ |
1708 | 5064 s->mv_dir = MV_DIR_FORWARD; |
5065 s->mv_type = MV_TYPE_FIELD; | |
5066 s->mb_intra= 0; | |
5067 for(i=0; i<2; i++){ | |
5068 j= s->field_select[0][i] = s->b_field_select_table[0][i][xy]; | |
5069 s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0]; | |
5070 s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1]; | |
5071 } | |
2967 | 5072 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD_I, pb, pb2, tex_pb, |
1708 | 5073 &dmin, &next_block, 0, 0); |
5074 } | |
2967 | 5075 if(mb_type&CANDIDATE_MB_TYPE_BACKWARD_I){ |
1708 | 5076 s->mv_dir = MV_DIR_BACKWARD; |
5077 s->mv_type = MV_TYPE_FIELD; | |
5078 s->mb_intra= 0; | |
5079 for(i=0; i<2; i++){ | |
5080 j= s->field_select[1][i] = s->b_field_select_table[1][i][xy]; | |
5081 s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0]; | |
5082 s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1]; | |
5083 } | |
2967 | 5084 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD_I, pb, pb2, tex_pb, |
1708 | 5085 &dmin, &next_block, 0, 0); |
5086 } | |
2967 | 5087 if(mb_type&CANDIDATE_MB_TYPE_BIDIR_I){ |
1708 | 5088 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; |
5089 s->mv_type = MV_TYPE_FIELD; | |
5090 s->mb_intra= 0; | |
5091 for(dir=0; dir<2; dir++){ | |
5092 for(i=0; i<2; i++){ | |
5093 j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy]; | |
5094 s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0]; | |
5095 s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1]; | |
5096 } | |
5097 } | |
2967 | 5098 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR_I, pb, pb2, tex_pb, |
1708 | 5099 &dmin, &next_block, 0, 0); |
5100 } | |
5101 if(mb_type&CANDIDATE_MB_TYPE_INTRA){ | |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
5102 s->mv_dir = 0; |
295 | 5103 s->mv_type = MV_TYPE_16X16; |
294 | 5104 s->mb_intra= 1; |
5105 s->mv[0][0][0] = 0; | |
5106 s->mv[0][0][1] = 0; | |
2967 | 5107 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTRA, pb, pb2, tex_pb, |
456 | 5108 &dmin, &next_block, 0, 0); |
1389 | 5109 if(s->h263_pred || s->h263_aic){ |
5110 if(best_s.mb_intra) | |
5111 s->mbintra_table[mb_x + mb_y*s->mb_stride]=1; | |
5112 else | |
5113 ff_clean_intra_table_entries(s); //old mode? | |
5114 } | |
295 | 5115 } |
1616 | 5116 |
5117 if(s->flags & CODEC_FLAG_QP_RD){ | |
5118 if(best_s.mv_type==MV_TYPE_16X16 && !(best_s.mv_dir&MV_DIRECT)){ | |
5119 const int last_qp= backup_s.qscale; | |
5120 int dquant, dir, qp, dc[6]; | |
1617 | 5121 DCTELEM ac[6][16]; |
1623 | 5122 const int mvdir= (best_s.mv_dir&MV_DIR_BACKWARD) ? 1 : 0; |
2967 | 5123 |
1616 | 5124 assert(backup_s.dquant == 0); |
5125 | |
5126 //FIXME intra | |
5127 s->mv_dir= best_s.mv_dir; | |
5128 s->mv_type = MV_TYPE_16X16; | |
5129 s->mb_intra= best_s.mb_intra; | |
5130 s->mv[0][0][0] = best_s.mv[0][0][0]; | |
5131 s->mv[0][0][1] = best_s.mv[0][0][1]; | |
5132 s->mv[1][0][0] = best_s.mv[1][0][0]; | |
5133 s->mv[1][0][1] = best_s.mv[1][0][1]; | |
2967 | 5134 |
1616 | 5135 dir= s->pict_type == B_TYPE ? 2 : 1; |
1623 | 5136 if(last_qp + dir > s->avctx->qmax) dir= -dir; |
1616 | 5137 for(dquant= dir; dquant<=2 && dquant>=-2; dquant += dir){ |
5138 qp= last_qp + dquant; | |
5139 if(qp < s->avctx->qmin || qp > s->avctx->qmax) | |
5140 break; | |
5141 backup_s.dquant= dquant; | |
2229 | 5142 if(s->mb_intra && s->dc_val[0]){ |
1617 | 5143 for(i=0; i<6; i++){ |
5144 dc[i]= s->dc_val[0][ s->block_index[i] ]; | |
5145 memcpy(ac[i], s->ac_val[0][s->block_index[i]], sizeof(DCTELEM)*16); | |
5146 } | |
1616 | 5147 } |
1617 | 5148 |
2967 | 5149 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_pb, |
1623 | 5150 &dmin, &next_block, s->mv[mvdir][0][0], s->mv[mvdir][0][1]); |
1616 | 5151 if(best_s.qscale != qp){ |
2229 | 5152 if(s->mb_intra && s->dc_val[0]){ |
1617 | 5153 for(i=0; i<6; i++){ |
5154 s->dc_val[0][ s->block_index[i] ]= dc[i]; | |
5155 memcpy(s->ac_val[0][s->block_index[i]], ac[i], sizeof(DCTELEM)*16); | |
5156 } | |
1616 | 5157 } |
5158 if(dir > 0 && dquant==dir){ | |
5159 dquant= 0; | |
5160 dir= -dir; | |
5161 }else | |
5162 break; | |
5163 } | |
5164 } | |
5165 qp= best_s.qscale; | |
5166 s->current_picture.qscale_table[xy]= qp; | |
5167 } | |
5168 } | |
5169 | |
326 | 5170 copy_context_after_encode(s, &best_s, -1); |
2967 | 5171 |
1786 | 5172 pb_bits_count= put_bits_count(&s->pb); |
456 | 5173 flush_put_bits(&s->pb); |
5174 ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); | |
5175 s->pb= backup_s.pb; | |
2967 | 5176 |
456 | 5177 if(s->data_partitioning){ |
1786 | 5178 pb2_bits_count= put_bits_count(&s->pb2); |
456 | 5179 flush_put_bits(&s->pb2); |
5180 ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); | |
5181 s->pb2= backup_s.pb2; | |
2967 | 5182 |
1786 | 5183 tex_pb_bits_count= put_bits_count(&s->tex_pb); |
456 | 5184 flush_put_bits(&s->tex_pb); |
5185 ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); | |
5186 s->tex_pb= backup_s.tex_pb; | |
5187 } | |
1786 | 5188 s->last_bits= put_bits_count(&s->pb); |
2967 | 5189 |
1389 | 5190 if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE) |
5191 ff_h263_update_motion_val(s); | |
2967 | 5192 |
1799 | 5193 if(next_block==0){ //FIXME 16 vs linesize16 |
5194 s->dsp.put_pixels_tab[0][0](s->dest[0], s->rd_scratchpad , s->linesize ,16); | |
5195 s->dsp.put_pixels_tab[1][0](s->dest[1], s->rd_scratchpad + 16*s->linesize , s->uvlinesize, 8); | |
5196 s->dsp.put_pixels_tab[1][0](s->dest[2], s->rd_scratchpad + 16*s->linesize + 8, s->uvlinesize, 8); | |
1389 | 5197 } |
5198 | |
5199 if(s->avctx->mb_decision == FF_MB_DECISION_BITS) | |
5200 MPV_decode_mb(s, s->block); | |
294 | 5201 } else { |
324 | 5202 int motion_x, motion_y; |
5203 s->mv_type=MV_TYPE_16X16; | |
294 | 5204 // only one MB-Type possible |
2967 | 5205 |
327 | 5206 switch(mb_type){ |
1708 | 5207 case CANDIDATE_MB_TYPE_INTRA: |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
5208 s->mv_dir = 0; |
294 | 5209 s->mb_intra= 1; |
324 | 5210 motion_x= s->mv[0][0][0] = 0; |
5211 motion_y= s->mv[0][0][1] = 0; | |
327 | 5212 break; |
1708 | 5213 case CANDIDATE_MB_TYPE_INTER: |
324 | 5214 s->mv_dir = MV_DIR_FORWARD; |
5215 s->mb_intra= 0; | |
5216 motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; | |
5217 motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
327 | 5218 break; |
1708 | 5219 case CANDIDATE_MB_TYPE_INTER_I: |
5220 s->mv_dir = MV_DIR_FORWARD; | |
5221 s->mv_type = MV_TYPE_FIELD; | |
5222 s->mb_intra= 0; | |
5223 for(i=0; i<2; i++){ | |
5224 j= s->field_select[0][i] = s->p_field_select_table[i][xy]; | |
5225 s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; | |
5226 s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; | |
5227 } | |
5228 motion_x = motion_y = 0; | |
5229 break; | |
5230 case CANDIDATE_MB_TYPE_INTER4V: | |
456 | 5231 s->mv_dir = MV_DIR_FORWARD; |
5232 s->mv_type = MV_TYPE_8X8; | |
5233 s->mb_intra= 0; | |
5234 for(i=0; i<4; i++){ | |
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
5235 s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; |
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
5236 s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; |
456 | 5237 } |
5238 motion_x= motion_y= 0; | |
5239 break; | |
1708 | 5240 case CANDIDATE_MB_TYPE_DIRECT: |
324 | 5241 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
5242 s->mb_intra= 0; | |
327 | 5243 motion_x=s->b_direct_mv_table[xy][0]; |
5244 motion_y=s->b_direct_mv_table[xy][1]; | |
936 | 5245 ff_mpeg4_set_direct_mv(s, motion_x, motion_y); |
327 | 5246 break; |
1708 | 5247 case CANDIDATE_MB_TYPE_BIDIR: |
324 | 5248 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; |
294 | 5249 s->mb_intra= 0; |
324 | 5250 motion_x=0; |
5251 motion_y=0; | |
5252 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
5253 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
5254 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
5255 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
327 | 5256 break; |
1708 | 5257 case CANDIDATE_MB_TYPE_BACKWARD: |
324 | 5258 s->mv_dir = MV_DIR_BACKWARD; |
5259 s->mb_intra= 0; | |
5260 motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
5261 motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
327 | 5262 break; |
1708 | 5263 case CANDIDATE_MB_TYPE_FORWARD: |
324 | 5264 s->mv_dir = MV_DIR_FORWARD; |
5265 s->mb_intra= 0; | |
5266 motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
5267 motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
5268 // printf(" %d %d ", motion_x, motion_y); | |
327 | 5269 break; |
1708 | 5270 case CANDIDATE_MB_TYPE_FORWARD_I: |
5271 s->mv_dir = MV_DIR_FORWARD; | |
5272 s->mv_type = MV_TYPE_FIELD; | |
5273 s->mb_intra= 0; | |
5274 for(i=0; i<2; i++){ | |
5275 j= s->field_select[0][i] = s->b_field_select_table[0][i][xy]; | |
5276 s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0]; | |
5277 s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1]; | |
5278 } | |
5279 motion_x=motion_y=0; | |
5280 break; | |
5281 case CANDIDATE_MB_TYPE_BACKWARD_I: | |
5282 s->mv_dir = MV_DIR_BACKWARD; | |
5283 s->mv_type = MV_TYPE_FIELD; | |
5284 s->mb_intra= 0; | |
5285 for(i=0; i<2; i++){ | |
5286 j= s->field_select[1][i] = s->b_field_select_table[1][i][xy]; | |
5287 s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0]; | |
5288 s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1]; | |
5289 } | |
5290 motion_x=motion_y=0; | |
5291 break; | |
5292 case CANDIDATE_MB_TYPE_BIDIR_I: | |
5293 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
5294 s->mv_type = MV_TYPE_FIELD; | |
5295 s->mb_intra= 0; | |
5296 for(dir=0; dir<2; dir++){ | |
5297 for(i=0; i<2; i++){ | |
5298 j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy]; | |
5299 s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0]; | |
5300 s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1]; | |
5301 } | |
5302 } | |
5303 motion_x=motion_y=0; | |
5304 break; | |
327 | 5305 default: |
324 | 5306 motion_x=motion_y=0; //gcc warning fix |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
5307 av_log(s->avctx, AV_LOG_ERROR, "illegal MB type\n"); |
294 | 5308 } |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
5309 |
324 | 5310 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
|
5311 |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
5312 // RAL: Update last macroblock type |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
5313 s->last_mv_dir = s->mv_dir; |
2967 | 5314 |
1389 | 5315 if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE) |
5316 ff_h263_update_motion_val(s); | |
2967 | 5317 |
1389 | 5318 MPV_decode_mb(s, s->block); |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
5319 } |
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha«³l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
5320 |
327 | 5321 /* clean the MV table in IPS frames for direct mode in B frames */ |
5322 if(s->mb_intra /* && I,P,S_TYPE */){ | |
5323 s->p_mv_table[xy][0]=0; | |
5324 s->p_mv_table[xy][1]=0; | |
5325 } | |
2967 | 5326 |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
5327 if(s->flags&CODEC_FLAG_PSNR){ |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
5328 int w= 16; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
5329 int h= 16; |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
5330 |
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
5331 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
|
5332 if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; |
936 | 5333 |
2955 | 5334 s->current_picture.error[0] += sse( |
1389 | 5335 s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, |
5336 s->dest[0], w, h, s->linesize); | |
2955 | 5337 s->current_picture.error[1] += sse( |
1389 | 5338 s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, |
5339 s->dest[1], w>>1, h>>1, s->uvlinesize); | |
2955 | 5340 s->current_picture.error[2] += sse( |
1389 | 5341 s, s->new_picture .data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, |
5342 s->dest[2], w>>1, h>>1, s->uvlinesize); | |
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
5343 } |
2345 | 5344 if(s->loop_filter){ |
5345 if(s->out_format == FMT_H263) | |
5346 ff_h263_loop_filter(s); | |
5347 } | |
1786 | 5348 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_stride, put_bits_count(&s->pb)); |
0 | 5349 } |
5350 } | |
286 | 5351 |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
5352 //not beautiful here but we must write it before flushing so it has to be here |
456 | 5353 if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE) |
208 | 5354 msmpeg4_encode_ext_header(s); |
456 | 5355 |
1799 | 5356 write_slice_end(s); |
5357 | |
2967 | 5358 /* Send the last GOB if RTP */ |
1661 | 5359 if (s->avctx->rtp_callback) { |
2492
57ba17bd3924
rtp_callback: send number of mb patch by (Johan Bilien {jobi via.ecp fr)
michael
parents:
2450
diff
changeset
|
5360 int number_mb = (mb_y - s->resync_mb_y)*s->mb_width - s->resync_mb_x; |
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
|
5361 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
231 | 5362 /* Call the RTP callback to send the last GOB */ |
1799 | 5363 emms_c(); |
2492
57ba17bd3924
rtp_callback: send number of mb patch by (Johan Bilien {jobi via.ecp fr)
michael
parents:
2450
diff
changeset
|
5364 s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, pdif, number_mb); |
231 | 5365 } |
1799 | 5366 |
5367 return 0; | |
5368 } | |
5369 | |
5370 #define MERGE(field) dst->field += src->field; src->field=0 | |
5371 static void merge_context_after_me(MpegEncContext *dst, MpegEncContext *src){ | |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5372 MERGE(me.scene_change_score); |
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5373 MERGE(me.mc_mb_var_sum_temp); |
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5374 MERGE(me.mb_var_sum_temp); |
1799 | 5375 } |
5376 | |
5377 static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src){ | |
5378 int i; | |
5379 | |
5380 MERGE(dct_count[0]); //note, the other dct vars are not part of the context | |
5381 MERGE(dct_count[1]); | |
5382 MERGE(mv_bits); | |
5383 MERGE(i_tex_bits); | |
5384 MERGE(p_tex_bits); | |
5385 MERGE(i_count); | |
5386 MERGE(f_count); | |
5387 MERGE(b_count); | |
5388 MERGE(skip_count); | |
5389 MERGE(misc_bits); | |
5390 MERGE(error_count); | |
5391 MERGE(padding_bug_score); | |
2955 | 5392 MERGE(current_picture.error[0]); |
5393 MERGE(current_picture.error[1]); | |
5394 MERGE(current_picture.error[2]); | |
1799 | 5395 |
5396 if(dst->avctx->noise_reduction){ | |
5397 for(i=0; i<64; i++){ | |
5398 MERGE(dct_error_sum[0][i]); | |
5399 MERGE(dct_error_sum[1][i]); | |
5400 } | |
5401 } | |
2967 | 5402 |
1799 | 5403 assert(put_bits_count(&src->pb) % 8 ==0); |
5404 assert(put_bits_count(&dst->pb) % 8 ==0); | |
5405 ff_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb)); | |
5406 flush_put_bits(&dst->pb); | |
5407 } | |
5408 | |
2974 | 5409 static void estimate_qp(MpegEncContext *s, int dry_run){ |
5410 if (!s->fixed_qscale) | |
5411 s->current_picture_ptr->quality= | |
5412 s->current_picture.quality = ff_rate_estimate_qscale(s, dry_run); | |
5413 | |
5414 if(s->adaptive_quant){ | |
5415 switch(s->codec_id){ | |
5416 case CODEC_ID_MPEG4: | |
5417 ff_clean_mpeg4_qscales(s); | |
5418 break; | |
5419 case CODEC_ID_H263: | |
5420 case CODEC_ID_H263P: | |
5421 case CODEC_ID_FLV1: | |
5422 ff_clean_h263_qscales(s); | |
5423 break; | |
5424 } | |
5425 | |
5426 s->lambda= s->lambda_table[0]; | |
5427 //FIXME broken | |
5428 }else | |
5429 s->lambda= s->current_picture.quality; | |
5430 //printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality); | |
5431 update_qscale(s); | |
5432 } | |
5433 | |
1799 | 5434 static void encode_picture(MpegEncContext *s, int picture_number) |
5435 { | |
2024
f65d87bfdd5a
some of the warning fixes by (Michael Roitzsch <mroi at users dot sourceforge dot net>)
michael
parents:
2015
diff
changeset
|
5436 int i; |
1799 | 5437 int bits; |
5438 | |
5439 s->picture_number = picture_number; | |
2967 | 5440 |
1799 | 5441 /* Reset the average MB variance */ |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5442 s->me.mb_var_sum_temp = |
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5443 s->me.mc_mb_var_sum_temp = 0; |
1799 | 5444 |
5445 /* we need to initialize some time vars before we can encode b-frames */ | |
5446 // RAL: Condition added for MPEG1VIDEO | |
5447 if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4)) | |
1834 | 5448 ff_set_mpeg4_time(s, s->picture_number); //FIXME rename and use has_b_frames or similar |
2967 | 5449 |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5450 s->me.scene_change_score=0; |
2967 | 5451 |
2053 | 5452 // s->lambda= s->current_picture_ptr->quality; //FIXME qscale / ... stuff for ME ratedistoration |
2967 | 5453 |
1799 | 5454 if(s->pict_type==I_TYPE){ |
5455 if(s->msmpeg4_version >= 3) s->no_rounding=1; | |
5456 else s->no_rounding=0; | |
5457 }else if(s->pict_type!=B_TYPE){ | |
5458 if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4) | |
2967 | 5459 s->no_rounding ^= 1; |
5460 } | |
5461 | |
2981 | 5462 if(s->flags & CODEC_FLAG_PASS2){ |
2974 | 5463 estimate_qp(s, 1); |
2981 | 5464 ff_get_2pass_fcode(s); |
5465 }else if(!(s->flags & CODEC_FLAG_QSCALE)){ | |
2980
529163f99474
improved lambda/qp guessing for motion estimation RD in first pass
michael
parents:
2979
diff
changeset
|
5466 if(s->pict_type==B_TYPE) |
2997
188f4ef688f2
second try of improved lambda/qp guessing for motion estimation RD in first pass
michael
parents:
2990
diff
changeset
|
5467 s->lambda= s->last_lambda_for[s->pict_type]; |
2980
529163f99474
improved lambda/qp guessing for motion estimation RD in first pass
michael
parents:
2979
diff
changeset
|
5468 else |
2997
188f4ef688f2
second try of improved lambda/qp guessing for motion estimation RD in first pass
michael
parents:
2990
diff
changeset
|
5469 s->lambda= s->last_lambda_for[s->last_non_b_pict_type]; |
2980
529163f99474
improved lambda/qp guessing for motion estimation RD in first pass
michael
parents:
2979
diff
changeset
|
5470 update_qscale(s); |
529163f99474
improved lambda/qp guessing for motion estimation RD in first pass
michael
parents:
2979
diff
changeset
|
5471 } |
2974 | 5472 |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
5473 s->mb_intra=0; //for the rate distortion & bit compare functions |
1799 | 5474 for(i=1; i<s->avctx->thread_count; i++){ |
1827 | 5475 ff_update_duplicate_context(s->thread_context[i], s); |
1799 | 5476 } |
1962 | 5477 |
5478 ff_init_me(s); | |
5479 | |
1799 | 5480 /* Estimate motion for every MB */ |
5481 if(s->pict_type != I_TYPE){ | |
2584 | 5482 s->lambda = (s->lambda * s->avctx->me_penalty_compensation + 128)>>8; |
5483 s->lambda2= (s->lambda2* s->avctx->me_penalty_compensation + 128)>>8; | |
1955
5dafb10e0252
reuse motion vectors/mb types/field select values of the source video, if the SSE for a macroblock which is predicted with these values is below me_threshold
michael
parents:
1948
diff
changeset
|
5484 if(s->pict_type != B_TYPE && s->avctx->me_threshold==0){ |
1799 | 5485 if((s->avctx->pre_me && s->last_non_b_pict_type==I_TYPE) || s->avctx->pre_me==2){ |
5486 s->avctx->execute(s->avctx, pre_estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); | |
5487 } | |
5488 } | |
5489 | |
5490 s->avctx->execute(s->avctx, estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); | |
5491 }else /* if(s->pict_type == I_TYPE) */{ | |
5492 /* I-Frame */ | |
5493 for(i=0; i<s->mb_stride*s->mb_height; i++) | |
5494 s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; | |
2967 | 5495 |
1799 | 5496 if(!s->fixed_qscale){ |
5497 /* finding spatial complexity for I-frame rate control */ | |
1804
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
5498 s->avctx->execute(s->avctx, mb_var_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); |
1799 | 5499 } |
5500 } | |
1804
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
5501 for(i=1; i<s->avctx->thread_count; i++){ |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
5502 merge_context_after_me(s, s->thread_context[i]); |
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
5503 } |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5504 s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp; |
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5505 s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp; |
1799 | 5506 emms_c(); |
5507 | |
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5508 if(s->me.scene_change_score > s->avctx->scenechange_threshold && s->pict_type == P_TYPE){ |
1799 | 5509 s->pict_type= I_TYPE; |
5510 for(i=0; i<s->mb_stride*s->mb_height; i++) | |
5511 s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; | |
5512 //printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum); | |
5513 } | |
5514 | |
5515 if(!s->umvplus){ | |
5516 if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) { | |
5517 s->f_code= ff_get_best_fcode(s, s->p_mv_table, CANDIDATE_MB_TYPE_INTER); | |
5518 | |
5519 if(s->flags & CODEC_FLAG_INTERLACED_ME){ | |
5520 int a,b; | |
5521 a= ff_get_best_fcode(s, s->p_field_mv_table[0][0], CANDIDATE_MB_TYPE_INTER_I); //FIXME field_select | |
5522 b= ff_get_best_fcode(s, s->p_field_mv_table[1][1], CANDIDATE_MB_TYPE_INTER_I); | |
5523 s->f_code= FFMAX(s->f_code, FFMAX(a,b)); | |
5524 } | |
2967 | 5525 |
1799 | 5526 ff_fix_long_p_mvs(s); |
5527 ff_fix_long_mvs(s, NULL, 0, s->p_mv_table, s->f_code, CANDIDATE_MB_TYPE_INTER, 0); | |
5528 if(s->flags & CODEC_FLAG_INTERLACED_ME){ | |
2024
f65d87bfdd5a
some of the warning fixes by (Michael Roitzsch <mroi at users dot sourceforge dot net>)
michael
parents:
2015
diff
changeset
|
5529 int j; |
1799 | 5530 for(i=0; i<2; i++){ |
5531 for(j=0; j<2; j++) | |
2967 | 5532 ff_fix_long_mvs(s, s->p_field_select_table[i], j, |
1799 | 5533 s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, 0); |
5534 } | |
5535 } | |
5536 } | |
5537 | |
5538 if(s->pict_type==B_TYPE){ | |
5539 int a, b; | |
5540 | |
5541 a = ff_get_best_fcode(s, s->b_forw_mv_table, CANDIDATE_MB_TYPE_FORWARD); | |
5542 b = ff_get_best_fcode(s, s->b_bidir_forw_mv_table, CANDIDATE_MB_TYPE_BIDIR); | |
5543 s->f_code = FFMAX(a, b); | |
5544 | |
5545 a = ff_get_best_fcode(s, s->b_back_mv_table, CANDIDATE_MB_TYPE_BACKWARD); | |
5546 b = ff_get_best_fcode(s, s->b_bidir_back_mv_table, CANDIDATE_MB_TYPE_BIDIR); | |
5547 s->b_code = FFMAX(a, b); | |
5548 | |
5549 ff_fix_long_mvs(s, NULL, 0, s->b_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_FORWARD, 1); | |
5550 ff_fix_long_mvs(s, NULL, 0, s->b_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BACKWARD, 1); | |
5551 ff_fix_long_mvs(s, NULL, 0, s->b_bidir_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_BIDIR, 1); | |
5552 ff_fix_long_mvs(s, NULL, 0, s->b_bidir_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BIDIR, 1); | |
5553 if(s->flags & CODEC_FLAG_INTERLACED_ME){ | |
2024
f65d87bfdd5a
some of the warning fixes by (Michael Roitzsch <mroi at users dot sourceforge dot net>)
michael
parents:
2015
diff
changeset
|
5554 int dir, j; |
1799 | 5555 for(dir=0; dir<2; dir++){ |
5556 for(i=0; i<2; i++){ | |
5557 for(j=0; j<2; j++){ | |
2967 | 5558 int type= dir ? (CANDIDATE_MB_TYPE_BACKWARD_I|CANDIDATE_MB_TYPE_BIDIR_I) |
1799 | 5559 : (CANDIDATE_MB_TYPE_FORWARD_I |CANDIDATE_MB_TYPE_BIDIR_I); |
2967 | 5560 ff_fix_long_mvs(s, s->b_field_select_table[dir][i], j, |
1799 | 5561 s->b_field_mv_table[dir][i][j], dir ? s->b_code : s->f_code, type, 1); |
5562 } | |
5563 } | |
5564 } | |
5565 } | |
5566 } | |
5567 } | |
5568 | |
2974 | 5569 estimate_qp(s, 0); |
2967 | 5570 |
5571 if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==I_TYPE && !(s->flags & CODEC_FLAG_QSCALE)) | |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
5572 s->qscale= 3; //reduce clipping problems |
2967 | 5573 |
1799 | 5574 if (s->out_format == FMT_MJPEG) { |
5575 /* for mjpeg, we do include qscale in the matrix */ | |
5576 s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; | |
5577 for(i=1;i<64;i++){ | |
5578 int j= s->dsp.idct_permutation[i]; | |
5579 | |
2654 | 5580 s->intra_matrix[j] = clip_uint8((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3) & 0xFF; |
1799 | 5581 } |
2967 | 5582 convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, |
2385
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
5583 s->intra_matrix, s->intra_quant_bias, 8, 8, 1); |
1799 | 5584 s->qscale= 8; |
5585 } | |
2967 | 5586 |
1799 | 5587 //FIXME var duplication |
2235
0c04463f79d8
10l (scene change pict_type was wrong after coded_frame fix) patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2231
diff
changeset
|
5588 s->current_picture_ptr->key_frame= |
1799 | 5589 s->current_picture.key_frame= s->pict_type == I_TYPE; //FIXME pic_ptr |
2235
0c04463f79d8
10l (scene change pict_type was wrong after coded_frame fix) patch by (Loren Merritt <lorenm at u dot washington dot edu>)
michael
parents:
2231
diff
changeset
|
5590 s->current_picture_ptr->pict_type= |
1799 | 5591 s->current_picture.pict_type= s->pict_type; |
5592 | |
5593 if(s->current_picture.key_frame) | |
5594 s->picture_in_gop_number=0; | |
5595 | |
5596 s->last_bits= put_bits_count(&s->pb); | |
5597 switch(s->out_format) { | |
5598 case FMT_MJPEG: | |
5599 mjpeg_picture_header(s); | |
5600 break; | |
2639 | 5601 #ifdef CONFIG_H261_ENCODER |
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
5602 case FMT_H261: |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
5603 ff_h261_encode_picture_header(s, picture_number); |
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
5604 break; |
2639 | 5605 #endif |
1799 | 5606 case FMT_H263: |
2967 | 5607 if (s->codec_id == CODEC_ID_WMV2) |
1799 | 5608 ff_wmv2_encode_picture_header(s, picture_number); |
2967 | 5609 else if (s->h263_msmpeg4) |
1799 | 5610 msmpeg4_encode_picture_header(s, picture_number); |
5611 else if (s->h263_pred) | |
5612 mpeg4_encode_picture_header(s, picture_number); | |
2639 | 5613 #ifdef CONFIG_RV10_ENCODER |
2967 | 5614 else if (s->codec_id == CODEC_ID_RV10) |
1799 | 5615 rv10_encode_picture_header(s, picture_number); |
2639 | 5616 #endif |
5617 #ifdef CONFIG_RV20_ENCODER | |
2967 | 5618 else if (s->codec_id == CODEC_ID_RV20) |
2380 | 5619 rv20_encode_picture_header(s, picture_number); |
2639 | 5620 #endif |
1799 | 5621 else if (s->codec_id == CODEC_ID_FLV1) |
5622 ff_flv_encode_picture_header(s, picture_number); | |
5623 else | |
5624 h263_encode_picture_header(s, picture_number); | |
5625 break; | |
5626 case FMT_MPEG1: | |
5627 mpeg1_encode_picture_header(s, picture_number); | |
5628 break; | |
5629 case FMT_H264: | |
5630 break; | |
5631 default: | |
5632 assert(0); | |
5633 } | |
5634 bits= put_bits_count(&s->pb); | |
5635 s->header_bits= bits - s->last_bits; | |
2967 | 5636 |
1799 | 5637 for(i=1; i<s->avctx->thread_count; i++){ |
5638 update_duplicate_context_after_me(s->thread_context[i], s); | |
5639 } | |
5640 s->avctx->execute(s->avctx, encode_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); | |
5641 for(i=1; i<s->avctx->thread_count; i++){ | |
5642 merge_context_after_encode(s, s->thread_context[i]); | |
5643 } | |
5644 emms_c(); | |
0 | 5645 } |
5646 | |
1686
68abbec33289
Here are juste two added #ifdef CONFIG_ENCODERS to allow
michael
parents:
1685
diff
changeset
|
5647 #endif //CONFIG_ENCODERS |
68abbec33289
Here are juste two added #ifdef CONFIG_ENCODERS to allow
michael
parents:
1685
diff
changeset
|
5648 |
1719 | 5649 static void denoise_dct_c(MpegEncContext *s, DCTELEM *block){ |
1597 | 5650 const int intra= s->mb_intra; |
5651 int i; | |
5652 | |
1599 | 5653 s->dct_count[intra]++; |
5654 | |
1597 | 5655 for(i=0; i<64; i++){ |
5656 int level= block[i]; | |
5657 | |
5658 if(level){ | |
5659 if(level>0){ | |
5660 s->dct_error_sum[intra][i] += level; | |
5661 level -= s->dct_offset[intra][i]; | |
5662 if(level<0) level=0; | |
5663 }else{ | |
5664 s->dct_error_sum[intra][i] -= level; | |
5665 level += s->dct_offset[intra][i]; | |
5666 if(level>0) level=0; | |
5667 } | |
5668 block[i]= level; | |
5669 } | |
5670 } | |
5671 } | |
5672 | |
1686
68abbec33289
Here are juste two added #ifdef CONFIG_ENCODERS to allow
michael
parents:
1685
diff
changeset
|
5673 #ifdef CONFIG_ENCODERS |
68abbec33289
Here are juste two added #ifdef CONFIG_ENCODERS to allow
michael
parents:
1685
diff
changeset
|
5674 |
2967 | 5675 static int dct_quantize_trellis_c(MpegEncContext *s, |
945 | 5676 DCTELEM *block, int n, |
5677 int qscale, int *overflow){ | |
5678 const int *qmat; | |
1064 | 5679 const uint8_t *scantable= s->intra_scantable.scantable; |
1718 | 5680 const uint8_t *perm_scantable= s->intra_scantable.permutated; |
945 | 5681 int max=0; |
5682 unsigned int threshold1, threshold2; | |
5683 int bias=0; | |
5684 int run_tab[65]; | |
5685 int level_tab[65]; | |
5686 int score_tab[65]; | |
1718 | 5687 int survivor[65]; |
5688 int survivor_count; | |
946 | 5689 int last_run=0; |
5690 int last_level=0; | |
5691 int last_score= 0; | |
1718 | 5692 int last_i; |
1715 | 5693 int coeff[2][64]; |
945 | 5694 int coeff_count[64]; |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
5695 int qmul, qadd, start_i, last_non_zero, i, dc; |
945 | 5696 const int esc_length= s->ac_esc_length; |
5697 uint8_t * length; | |
5698 uint8_t * last_length; | |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
5699 const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); |
2967 | 5700 |
1092 | 5701 s->dsp.fdct (block); |
2967 | 5702 |
1597 | 5703 if(s->dct_error_sum) |
1719 | 5704 s->denoise_dct(s, block); |
945 | 5705 qmul= qscale*16; |
5706 qadd= ((qscale-1)|1)*8; | |
946 | 5707 |
945 | 5708 if (s->mb_intra) { |
5709 int q; | |
5710 if (!s->h263_aic) { | |
5711 if (n < 4) | |
5712 q = s->y_dc_scale; | |
5713 else | |
5714 q = s->c_dc_scale; | |
5715 q = q << 3; | |
5716 } else{ | |
5717 /* For AIC we skip quant/dequant of INTRADC */ | |
5718 q = 1 << 3; | |
5719 qadd=0; | |
5720 } | |
2967 | 5721 |
945 | 5722 /* note: block[0] is assumed to be positive */ |
5723 block[0] = (block[0] + (q >> 1)) / q; | |
5724 start_i = 1; | |
5725 last_non_zero = 0; | |
5726 qmat = s->q_intra_matrix[qscale]; | |
1422
efeed6e29f9b
oooooops, having 2 Eterms open and doing cvs diff in one and cvs commit in the other sucks, especially if they are in different directories (MPlayer/main/libavcodec vs. ffmpeg/libavcodec)
michaelni
parents:
1421
diff
changeset
|
5727 if(s->mpeg_quant || s->out_format == FMT_MPEG1) |
945 | 5728 bias= 1<<(QMAT_SHIFT-1); |
5729 length = s->intra_ac_vlc_length; | |
5730 last_length= s->intra_ac_vlc_last_length; | |
5731 } else { | |
5732 start_i = 0; | |
5733 last_non_zero = -1; | |
5734 qmat = s->q_inter_matrix[qscale]; | |
5735 length = s->inter_ac_vlc_length; | |
5736 last_length= s->inter_ac_vlc_last_length; | |
5737 } | |
1718 | 5738 last_i= start_i; |
945 | 5739 |
5740 threshold1= (1<<QMAT_SHIFT) - bias - 1; | |
5741 threshold2= (threshold1<<1); | |
946 | 5742 |
1715 | 5743 for(i=63; i>=start_i; i--) { |
5744 const int j = scantable[i]; | |
5745 int level = block[j] * qmat[j]; | |
5746 | |
5747 if(((unsigned)(level+threshold1))>threshold2){ | |
5748 last_non_zero = i; | |
5749 break; | |
5750 } | |
5751 } | |
5752 | |
5753 for(i=start_i; i<=last_non_zero; i++) { | |
945 | 5754 const int j = scantable[i]; |
1715 | 5755 int level = block[j] * qmat[j]; |
945 | 5756 |
5757 // if( bias+level >= (1<<(QMAT_SHIFT - 3)) | |
5758 // || bias-level >= (1<<(QMAT_SHIFT - 3))){ | |
5759 if(((unsigned)(level+threshold1))>threshold2){ | |
5760 if(level>0){ | |
5761 level= (bias + level)>>QMAT_SHIFT; | |
1718 | 5762 coeff[0][i]= level; |
5763 coeff[1][i]= level-1; | |
946 | 5764 // coeff[2][k]= level-2; |
945 | 5765 }else{ |
5766 level= (bias - level)>>QMAT_SHIFT; | |
1718 | 5767 coeff[0][i]= -level; |
5768 coeff[1][i]= -level+1; | |
946 | 5769 // coeff[2][k]= -level+2; |
945 | 5770 } |
1718 | 5771 coeff_count[i]= FFMIN(level, 2); |
5772 assert(coeff_count[i]); | |
945 | 5773 max |=level; |
5774 }else{ | |
1718 | 5775 coeff[0][i]= (level>>31)|1; |
5776 coeff_count[i]= 1; | |
945 | 5777 } |
5778 } | |
2967 | 5779 |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
5780 *overflow= s->max_qcoeff < max; //overflow might have happened |
2967 | 5781 |
945 | 5782 if(last_non_zero < start_i){ |
5783 memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); | |
5784 return last_non_zero; | |
5785 } | |
5786 | |
1718 | 5787 score_tab[start_i]= 0; |
5788 survivor[0]= start_i; | |
5789 survivor_count= 1; | |
2967 | 5790 |
1718 | 5791 for(i=start_i; i<=last_non_zero; i++){ |
5792 int level_index, j; | |
5793 const int dct_coeff= ABS(block[ scantable[i] ]); | |
945 | 5794 const int zero_distoration= dct_coeff*dct_coeff; |
946 | 5795 int best_score=256*256*256*120; |
945 | 5796 for(level_index=0; level_index < coeff_count[i]; level_index++){ |
5797 int distoration; | |
5798 int level= coeff[level_index][i]; | |
1716 | 5799 const int alevel= ABS(level); |
945 | 5800 int unquant_coeff; |
2967 | 5801 |
945 | 5802 assert(level); |
5803 | |
5804 if(s->out_format == FMT_H263){ | |
1716 | 5805 unquant_coeff= alevel*qmul + qadd; |
947 | 5806 }else{ //MPEG1 |
1718 | 5807 j= s->dsp.idct_permutation[ scantable[i] ]; //FIXME optimize |
947 | 5808 if(s->mb_intra){ |
1716 | 5809 unquant_coeff = (int)( alevel * qscale * s->intra_matrix[j]) >> 3; |
947 | 5810 unquant_coeff = (unquant_coeff - 1) | 1; |
5811 }else{ | |
1716 | 5812 unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4; |
947 | 5813 unquant_coeff = (unquant_coeff - 1) | 1; |
5814 } | |
5815 unquant_coeff<<= 3; | |
5816 } | |
946 | 5817 |
1715 | 5818 distoration= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distoration; |
945 | 5819 level+=64; |
5820 if((level&(~127)) == 0){ | |
1718 | 5821 for(j=survivor_count-1; j>=0; j--){ |
5822 int run= i - survivor[j]; | |
947 | 5823 int score= distoration + length[UNI_AC_ENC_INDEX(run, level)]*lambda; |
945 | 5824 score += score_tab[i-run]; |
2967 | 5825 |
945 | 5826 if(score < best_score){ |
1718 | 5827 best_score= score; |
945 | 5828 run_tab[i+1]= run; |
5829 level_tab[i+1]= level-64; | |
5830 } | |
5831 } | |
5832 | |
5833 if(s->out_format == FMT_H263){ | |
1718 | 5834 for(j=survivor_count-1; j>=0; j--){ |
5835 int run= i - survivor[j]; | |
947 | 5836 int score= distoration + last_length[UNI_AC_ENC_INDEX(run, level)]*lambda; |
945 | 5837 score += score_tab[i-run]; |
946 | 5838 if(score < last_score){ |
5839 last_score= score; | |
5840 last_run= run; | |
5841 last_level= level-64; | |
5842 last_i= i+1; | |
945 | 5843 } |
5844 } | |
5845 } | |
5846 }else{ | |
5847 distoration += esc_length*lambda; | |
1718 | 5848 for(j=survivor_count-1; j>=0; j--){ |
5849 int run= i - survivor[j]; | |
945 | 5850 int score= distoration + score_tab[i-run]; |
2967 | 5851 |
945 | 5852 if(score < best_score){ |
1718 | 5853 best_score= score; |
945 | 5854 run_tab[i+1]= run; |
5855 level_tab[i+1]= level-64; | |
5856 } | |
5857 } | |
5858 | |
5859 if(s->out_format == FMT_H263){ | |
1718 | 5860 for(j=survivor_count-1; j>=0; j--){ |
5861 int run= i - survivor[j]; | |
945 | 5862 int score= distoration + score_tab[i-run]; |
946 | 5863 if(score < last_score){ |
5864 last_score= score; | |
5865 last_run= run; | |
5866 last_level= level-64; | |
5867 last_i= i+1; | |
945 | 5868 } |
5869 } | |
5870 } | |
5871 } | |
5872 } | |
2967 | 5873 |
1718 | 5874 score_tab[i+1]= best_score; |
5875 | |
946 | 5876 //Note: there is a vlc code in mpeg4 which is 1 bit shorter then another one with a shorter run and the same level |
1718 | 5877 if(last_non_zero <= 27){ |
5878 for(; survivor_count; survivor_count--){ | |
5879 if(score_tab[ survivor[survivor_count-1] ] <= best_score) | |
5880 break; | |
5881 } | |
5882 }else{ | |
5883 for(; survivor_count; survivor_count--){ | |
5884 if(score_tab[ survivor[survivor_count-1] ] <= best_score + lambda) | |
5885 break; | |
5886 } | |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1497
diff
changeset
|
5887 } |
1718 | 5888 |
5889 survivor[ survivor_count++ ]= i+1; | |
945 | 5890 } |
946 | 5891 |
945 | 5892 if(s->out_format != FMT_H263){ |
946 | 5893 last_score= 256*256*256*120; |
1718 | 5894 for(i= survivor[0]; i<=last_non_zero + 1; i++){ |
946 | 5895 int score= score_tab[i]; |
947 | 5896 if(i) score += lambda*2; //FIXME exacter? |
5897 | |
946 | 5898 if(score < last_score){ |
5899 last_score= score; | |
5900 last_i= i; | |
5901 last_level= level_tab[i]; | |
5902 last_run= run_tab[i]; | |
5903 } | |
945 | 5904 } |
5905 } | |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5906 |
1715 | 5907 s->coded_score[n] = last_score; |
2967 | 5908 |
1716 | 5909 dc= ABS(block[0]); |
1718 | 5910 last_non_zero= last_i - 1; |
945 | 5911 memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); |
2967 | 5912 |
945 | 5913 if(last_non_zero < start_i) |
5914 return last_non_zero; | |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5915 |
1480
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5916 if(last_non_zero == 0 && start_i == 0){ |
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5917 int best_level= 0; |
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5918 int best_score= dc * dc; |
2967 | 5919 |
1480
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5920 for(i=0; i<coeff_count[0]; i++){ |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5921 int level= coeff[i][0]; |
1716 | 5922 int alevel= ABS(level); |
5923 int unquant_coeff, score, distortion; | |
1480
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5924 |
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5925 if(s->out_format == FMT_H263){ |
1716 | 5926 unquant_coeff= (alevel*qmul + qadd)>>3; |
1480
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5927 }else{ //MPEG1 |
1716 | 5928 unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[0])) >> 4; |
5929 unquant_coeff = (unquant_coeff - 1) | 1; | |
1480
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5930 } |
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5931 unquant_coeff = (unquant_coeff + 4) >> 3; |
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5932 unquant_coeff<<= 3 + 3; |
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5933 |
1716 | 5934 distortion= (unquant_coeff - dc) * (unquant_coeff - dc); |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5935 level+=64; |
1716 | 5936 if((level&(~127)) == 0) score= distortion + last_length[UNI_AC_ENC_INDEX(0, level)]*lambda; |
5937 else score= distortion + esc_length*lambda; | |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5938 |
1480
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5939 if(score < best_score){ |
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5940 best_score= score; |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5941 best_level= level - 64; |
1480
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5942 } |
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5943 } |
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5944 block[0]= best_level; |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5945 s->coded_score[n] = best_score - dc*dc; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5946 if(best_level == 0) return -1; |
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5947 else return last_non_zero; |
1480
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5948 } |
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5949 |
946 | 5950 i= last_i; |
5951 assert(last_level); | |
1718 | 5952 |
5953 block[ perm_scantable[last_non_zero] ]= last_level; | |
946 | 5954 i -= last_run + 1; |
2967 | 5955 |
1718 | 5956 for(; i>start_i; i -= run_tab[i] + 1){ |
5957 block[ perm_scantable[i-1] ]= level_tab[i]; | |
945 | 5958 } |
5959 | |
5960 return last_non_zero; | |
5961 } | |
5962 | |
1777 | 5963 //#define REFINE_STATS 1 |
5964 static int16_t basis[64][64]; | |
5965 | |
5966 static void build_basis(uint8_t *perm){ | |
5967 int i, j, x, y; | |
5968 emms_c(); | |
5969 for(i=0; i<8; i++){ | |
5970 for(j=0; j<8; j++){ | |
5971 for(y=0; y<8; y++){ | |
5972 for(x=0; x<8; x++){ | |
5973 double s= 0.25*(1<<BASIS_SHIFT); | |
5974 int index= 8*i + j; | |
5975 int perm_index= perm[index]; | |
5976 if(i==0) s*= sqrt(0.5); | |
5977 if(j==0) s*= sqrt(0.5); | |
5978 basis[perm_index][8*x + y]= lrintf(s * cos((M_PI/8.0)*i*(x+0.5)) * cos((M_PI/8.0)*j*(y+0.5))); | |
5979 } | |
5980 } | |
5981 } | |
5982 } | |
5983 } | |
5984 | |
5985 static int dct_quantize_refine(MpegEncContext *s, //FIXME breaks denoise? | |
5986 DCTELEM *block, int16_t *weight, DCTELEM *orig, | |
5987 int n, int qscale){ | |
5988 int16_t rem[64]; | |
3089 | 5989 DECLARE_ALIGNED_16(DCTELEM, d1[64]); |
1777 | 5990 const int *qmat; |
5991 const uint8_t *scantable= s->intra_scantable.scantable; | |
5992 const uint8_t *perm_scantable= s->intra_scantable.permutated; | |
5993 // unsigned int threshold1, threshold2; | |
5994 // int bias=0; | |
5995 int run_tab[65]; | |
5996 int prev_run=0; | |
5997 int prev_level=0; | |
5998 int qmul, qadd, start_i, last_non_zero, i, dc; | |
5999 uint8_t * length; | |
6000 uint8_t * last_length; | |
6001 int lambda; | |
6002 int rle_index, run, q, sum; | |
6003 #ifdef REFINE_STATS | |
6004 static int count=0; | |
6005 static int after_last=0; | |
6006 static int to_zero=0; | |
6007 static int from_zero=0; | |
6008 static int raise=0; | |
6009 static int lower=0; | |
6010 static int messed_sign=0; | |
6011 #endif | |
6012 | |
6013 if(basis[0][0] == 0) | |
6014 build_basis(s->dsp.idct_permutation); | |
2967 | 6015 |
1777 | 6016 qmul= qscale*2; |
6017 qadd= (qscale-1)|1; | |
6018 if (s->mb_intra) { | |
6019 if (!s->h263_aic) { | |
6020 if (n < 4) | |
6021 q = s->y_dc_scale; | |
6022 else | |
6023 q = s->c_dc_scale; | |
6024 } else{ | |
6025 /* For AIC we skip quant/dequant of INTRADC */ | |
6026 q = 1; | |
6027 qadd=0; | |
6028 } | |
6029 q <<= RECON_SHIFT-3; | |
6030 /* note: block[0] is assumed to be positive */ | |
6031 dc= block[0]*q; | |
6032 // block[0] = (block[0] + (q >> 1)) / q; | |
6033 start_i = 1; | |
6034 qmat = s->q_intra_matrix[qscale]; | |
6035 // if(s->mpeg_quant || s->out_format == FMT_MPEG1) | |
6036 // bias= 1<<(QMAT_SHIFT-1); | |
6037 length = s->intra_ac_vlc_length; | |
6038 last_length= s->intra_ac_vlc_last_length; | |
6039 } else { | |
6040 dc= 0; | |
6041 start_i = 0; | |
6042 qmat = s->q_inter_matrix[qscale]; | |
6043 length = s->inter_ac_vlc_length; | |
6044 last_length= s->inter_ac_vlc_last_length; | |
6045 } | |
6046 last_non_zero = s->block_last_index[n]; | |
6047 | |
6048 #ifdef REFINE_STATS | |
6049 {START_TIMER | |
6050 #endif | |
1784 | 6051 dc += (1<<(RECON_SHIFT-1)); |
6052 for(i=0; i<64; i++){ | |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
6053 rem[i]= dc - (orig[i]<<RECON_SHIFT); //FIXME use orig dirrectly instead of copying to rem[] |
1777 | 6054 } |
6055 #ifdef REFINE_STATS | |
6056 STOP_TIMER("memset rem[]")} | |
6057 #endif | |
6058 sum=0; | |
6059 for(i=0; i<64; i++){ | |
6060 int one= 36; | |
6061 int qns=4; | |
6062 int w; | |
6063 | |
6064 w= ABS(weight[i]) + qns*one; | |
6065 w= 15 + (48*qns*one + w/2)/w; // 16 .. 63 | |
6066 | |
6067 weight[i] = w; | |
6068 // w=weight[i] = (63*qns + (w/2)) / w; | |
2967 | 6069 |
1777 | 6070 assert(w>0); |
6071 assert(w<(1<<6)); | |
6072 sum += w*w; | |
6073 } | |
6074 lambda= sum*(uint64_t)s->lambda2 >> (FF_LAMBDA_SHIFT - 6 + 6 + 6 + 6); | |
6075 #ifdef REFINE_STATS | |
6076 {START_TIMER | |
6077 #endif | |
6078 run=0; | |
6079 rle_index=0; | |
6080 for(i=start_i; i<=last_non_zero; i++){ | |
6081 int j= perm_scantable[i]; | |
6082 const int level= block[j]; | |
6083 int coeff; | |
2967 | 6084 |
1777 | 6085 if(level){ |
6086 if(level<0) coeff= qmul*level - qadd; | |
6087 else coeff= qmul*level + qadd; | |
6088 run_tab[rle_index++]=run; | |
6089 run=0; | |
6090 | |
1784 | 6091 s->dsp.add_8x8basis(rem, basis[j], coeff); |
1777 | 6092 }else{ |
6093 run++; | |
6094 } | |
6095 } | |
6096 #ifdef REFINE_STATS | |
6097 if(last_non_zero>0){ | |
6098 STOP_TIMER("init rem[]") | |
6099 } | |
6100 } | |
6101 | |
6102 {START_TIMER | |
6103 #endif | |
6104 for(;;){ | |
1784 | 6105 int best_score=s->dsp.try_8x8basis(rem, weight, basis[0], 0); |
1777 | 6106 int best_coeff=0; |
6107 int best_change=0; | |
2024
f65d87bfdd5a
some of the warning fixes by (Michael Roitzsch <mroi at users dot sourceforge dot net>)
michael
parents:
2015
diff
changeset
|
6108 int run2, best_unquant_change=0, analyze_gradient; |
1785
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6109 #ifdef REFINE_STATS |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6110 {START_TIMER |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6111 #endif |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6112 analyze_gradient = last_non_zero > 2 || s->avctx->quantizer_noise_shaping >= 3; |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6113 |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6114 if(analyze_gradient){ |
1777 | 6115 #ifdef REFINE_STATS |
6116 {START_TIMER | |
6117 #endif | |
1785
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6118 for(i=0; i<64; i++){ |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6119 int w= weight[i]; |
2967 | 6120 |
1785
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6121 d1[i] = (rem[i]*w*w + (1<<(RECON_SHIFT+12-1)))>>(RECON_SHIFT+12); |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6122 } |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6123 #ifdef REFINE_STATS |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6124 STOP_TIMER("rem*w*w")} |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6125 {START_TIMER |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6126 #endif |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6127 s->dsp.fdct(d1); |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6128 #ifdef REFINE_STATS |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6129 STOP_TIMER("dct")} |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6130 #endif |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6131 } |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6132 |
1777 | 6133 if(start_i){ |
6134 const int level= block[0]; | |
6135 int change, old_coeff; | |
6136 | |
6137 assert(s->mb_intra); | |
2967 | 6138 |
1777 | 6139 old_coeff= q*level; |
2967 | 6140 |
1777 | 6141 for(change=-1; change<=1; change+=2){ |
6142 int new_level= level + change; | |
6143 int score, new_coeff; | |
2967 | 6144 |
1777 | 6145 new_coeff= q*new_level; |
6146 if(new_coeff >= 2048 || new_coeff < 0) | |
6147 continue; | |
6148 | |
1784 | 6149 score= s->dsp.try_8x8basis(rem, weight, basis[0], new_coeff - old_coeff); |
1777 | 6150 if(score<best_score){ |
6151 best_score= score; | |
6152 best_coeff= 0; | |
6153 best_change= change; | |
6154 best_unquant_change= new_coeff - old_coeff; | |
6155 } | |
6156 } | |
6157 } | |
2967 | 6158 |
1777 | 6159 run=0; |
6160 rle_index=0; | |
6161 run2= run_tab[rle_index++]; | |
6162 prev_level=0; | |
6163 prev_run=0; | |
6164 | |
6165 for(i=start_i; i<64; i++){ | |
6166 int j= perm_scantable[i]; | |
6167 const int level= block[j]; | |
6168 int change, old_coeff; | |
6169 | |
6170 if(s->avctx->quantizer_noise_shaping < 3 && i > last_non_zero + 1) | |
6171 break; | |
6172 | |
6173 if(level){ | |
6174 if(level<0) old_coeff= qmul*level - qadd; | |
6175 else old_coeff= qmul*level + qadd; | |
6176 run2= run_tab[rle_index++]; //FIXME ! maybe after last | |
6177 }else{ | |
6178 old_coeff=0; | |
6179 run2--; | |
6180 assert(run2>=0 || i >= last_non_zero ); | |
6181 } | |
2967 | 6182 |
1777 | 6183 for(change=-1; change<=1; change+=2){ |
6184 int new_level= level + change; | |
6185 int score, new_coeff, unquant_change; | |
2967 | 6186 |
1777 | 6187 score=0; |
6188 if(s->avctx->quantizer_noise_shaping < 2 && ABS(new_level) > ABS(level)) | |
6189 continue; | |
6190 | |
6191 if(new_level){ | |
6192 if(new_level<0) new_coeff= qmul*new_level - qadd; | |
6193 else new_coeff= qmul*new_level + qadd; | |
6194 if(new_coeff >= 2048 || new_coeff <= -2048) | |
6195 continue; | |
6196 //FIXME check for overflow | |
2967 | 6197 |
1777 | 6198 if(level){ |
6199 if(level < 63 && level > -63){ | |
6200 if(i < last_non_zero) | |
6201 score += length[UNI_AC_ENC_INDEX(run, new_level+64)] | |
6202 - length[UNI_AC_ENC_INDEX(run, level+64)]; | |
6203 else | |
6204 score += last_length[UNI_AC_ENC_INDEX(run, new_level+64)] | |
6205 - last_length[UNI_AC_ENC_INDEX(run, level+64)]; | |
6206 } | |
6207 }else{ | |
6208 assert(ABS(new_level)==1); | |
2967 | 6209 |
1785
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6210 if(analyze_gradient){ |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6211 int g= d1[ scantable[i] ]; |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6212 if(g && (g^new_level) >= 0) |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6213 continue; |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6214 } |
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
6215 |
1777 | 6216 if(i < last_non_zero){ |
6217 int next_i= i + run2 + 1; | |
6218 int next_level= block[ perm_scantable[next_i] ] + 64; | |
2967 | 6219 |
1777 | 6220 if(next_level&(~127)) |
6221 next_level= 0; | |
6222 | |
6223 if(next_i < last_non_zero) | |
6224 score += length[UNI_AC_ENC_INDEX(run, 65)] | |
6225 + length[UNI_AC_ENC_INDEX(run2, next_level)] | |
6226 - length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)]; | |
6227 else | |
6228 score += length[UNI_AC_ENC_INDEX(run, 65)] | |
6229 + last_length[UNI_AC_ENC_INDEX(run2, next_level)] | |
6230 - last_length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)]; | |
6231 }else{ | |
6232 score += last_length[UNI_AC_ENC_INDEX(run, 65)]; | |
6233 if(prev_level){ | |
6234 score += length[UNI_AC_ENC_INDEX(prev_run, prev_level)] | |
6235 - last_length[UNI_AC_ENC_INDEX(prev_run, prev_level)]; | |
6236 } | |
6237 } | |
6238 } | |
6239 }else{ | |
6240 new_coeff=0; | |
6241 assert(ABS(level)==1); | |
6242 | |
6243 if(i < last_non_zero){ | |
6244 int next_i= i + run2 + 1; | |
6245 int next_level= block[ perm_scantable[next_i] ] + 64; | |
2967 | 6246 |
1777 | 6247 if(next_level&(~127)) |
6248 next_level= 0; | |
6249 | |
6250 if(next_i < last_non_zero) | |
6251 score += length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)] | |
6252 - length[UNI_AC_ENC_INDEX(run2, next_level)] | |
6253 - length[UNI_AC_ENC_INDEX(run, 65)]; | |
6254 else | |
6255 score += last_length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)] | |
6256 - last_length[UNI_AC_ENC_INDEX(run2, next_level)] | |
6257 - length[UNI_AC_ENC_INDEX(run, 65)]; | |
6258 }else{ | |
6259 score += -last_length[UNI_AC_ENC_INDEX(run, 65)]; | |
6260 if(prev_level){ | |
6261 score += last_length[UNI_AC_ENC_INDEX(prev_run, prev_level)] | |
6262 - length[UNI_AC_ENC_INDEX(prev_run, prev_level)]; | |
6263 } | |
6264 } | |
6265 } | |
2967 | 6266 |
1777 | 6267 score *= lambda; |
6268 | |
6269 unquant_change= new_coeff - old_coeff; | |
6270 assert((score < 100*lambda && score > -100*lambda) || lambda==0); | |
2967 | 6271 |
1784 | 6272 score+= s->dsp.try_8x8basis(rem, weight, basis[j], unquant_change); |
1777 | 6273 if(score<best_score){ |
6274 best_score= score; | |
6275 best_coeff= i; | |
6276 best_change= change; | |
6277 best_unquant_change= unquant_change; | |
6278 } | |
6279 } | |
6280 if(level){ | |
6281 prev_level= level + 64; | |
6282 if(prev_level&(~127)) | |
6283 prev_level= 0; | |
6284 prev_run= run; | |
6285 run=0; | |
6286 }else{ | |
6287 run++; | |
6288 } | |
6289 } | |
6290 #ifdef REFINE_STATS | |
6291 STOP_TIMER("iterative step")} | |
6292 #endif | |
6293 | |
6294 if(best_change){ | |
6295 int j= perm_scantable[ best_coeff ]; | |
2967 | 6296 |
1777 | 6297 block[j] += best_change; |
2967 | 6298 |
1777 | 6299 if(best_coeff > last_non_zero){ |
6300 last_non_zero= best_coeff; | |
6301 assert(block[j]); | |
6302 #ifdef REFINE_STATS | |
6303 after_last++; | |
6304 #endif | |
6305 }else{ | |
6306 #ifdef REFINE_STATS | |
6307 if(block[j]){ | |
6308 if(block[j] - best_change){ | |
6309 if(ABS(block[j]) > ABS(block[j] - best_change)){ | |
6310 raise++; | |
6311 }else{ | |
6312 lower++; | |
6313 } | |
6314 }else{ | |
6315 from_zero++; | |
6316 } | |
6317 }else{ | |
6318 to_zero++; | |
6319 } | |
6320 #endif | |
6321 for(; last_non_zero>=start_i; last_non_zero--){ | |
6322 if(block[perm_scantable[last_non_zero]]) | |
6323 break; | |
6324 } | |
6325 } | |
6326 #ifdef REFINE_STATS | |
6327 count++; | |
6328 if(256*256*256*64 % count == 0){ | |
6329 printf("after_last:%d to_zero:%d from_zero:%d raise:%d lower:%d sign:%d xyp:%d/%d/%d\n", after_last, to_zero, from_zero, raise, lower, messed_sign, s->mb_x, s->mb_y, s->picture_number); | |
6330 } | |
6331 #endif | |
6332 run=0; | |
6333 rle_index=0; | |
6334 for(i=start_i; i<=last_non_zero; i++){ | |
6335 int j= perm_scantable[i]; | |
6336 const int level= block[j]; | |
2967 | 6337 |
1777 | 6338 if(level){ |
6339 run_tab[rle_index++]=run; | |
6340 run=0; | |
6341 }else{ | |
6342 run++; | |
6343 } | |
6344 } | |
2967 | 6345 |
1784 | 6346 s->dsp.add_8x8basis(rem, basis[j], best_unquant_change); |
1777 | 6347 }else{ |
6348 break; | |
6349 } | |
6350 } | |
6351 #ifdef REFINE_STATS | |
6352 if(last_non_zero>0){ | |
6353 STOP_TIMER("iterative search") | |
6354 } | |
6355 } | |
6356 #endif | |
6357 | |
6358 return last_non_zero; | |
6359 } | |
6360 | |
2967 | 6361 static int dct_quantize_c(MpegEncContext *s, |
0 | 6362 DCTELEM *block, int n, |
344 | 6363 int qscale, int *overflow) |
0 | 6364 { |
1715 | 6365 int i, j, level, last_non_zero, q, start_i; |
0 | 6366 const int *qmat; |
1064 | 6367 const uint8_t *scantable= s->intra_scantable.scantable; |
344 | 6368 int bias; |
6369 int max=0; | |
6370 unsigned int threshold1, threshold2; | |
828
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
6371 |
1092 | 6372 s->dsp.fdct (block); |
0 | 6373 |
1597 | 6374 if(s->dct_error_sum) |
1719 | 6375 s->denoise_dct(s, block); |
1597 | 6376 |
0 | 6377 if (s->mb_intra) { |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6378 if (!s->h263_aic) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6379 if (n < 4) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6380 q = s->y_dc_scale; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6381 else |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6382 q = s->c_dc_scale; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6383 q = q << 3; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6384 } else |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6385 /* 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
|
6386 q = 1 << 3; |
2967 | 6387 |
0 | 6388 /* note: block[0] is assumed to be positive */ |
6389 block[0] = (block[0] + (q >> 1)) / q; | |
1715 | 6390 start_i = 1; |
0 | 6391 last_non_zero = 0; |
344 | 6392 qmat = s->q_intra_matrix[qscale]; |
635 | 6393 bias= s->intra_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); |
0 | 6394 } else { |
1715 | 6395 start_i = 0; |
0 | 6396 last_non_zero = -1; |
344 | 6397 qmat = s->q_inter_matrix[qscale]; |
635 | 6398 bias= s->inter_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); |
0 | 6399 } |
635 | 6400 threshold1= (1<<QMAT_SHIFT) - bias - 1; |
6401 threshold2= (threshold1<<1); | |
1715 | 6402 for(i=63;i>=start_i;i--) { |
764 | 6403 j = scantable[i]; |
1715 | 6404 level = block[j] * qmat[j]; |
6405 | |
6406 if(((unsigned)(level+threshold1))>threshold2){ | |
6407 last_non_zero = i; | |
6408 break; | |
6409 }else{ | |
6410 block[j]=0; | |
6411 } | |
6412 } | |
6413 for(i=start_i; i<=last_non_zero; i++) { | |
6414 j = scantable[i]; | |
6415 level = block[j] * qmat[j]; | |
344 | 6416 |
1215 | 6417 // if( bias+level >= (1<<QMAT_SHIFT) |
6418 // || bias-level >= (1<<QMAT_SHIFT)){ | |
344 | 6419 if(((unsigned)(level+threshold1))>threshold2){ |
6420 if(level>0){ | |
635 | 6421 level= (bias + level)>>QMAT_SHIFT; |
344 | 6422 block[j]= level; |
6423 }else{ | |
635 | 6424 level= (bias - level)>>QMAT_SHIFT; |
344 | 6425 block[j]= -level; |
0 | 6426 } |
344 | 6427 max |=level; |
6428 }else{ | |
6429 block[j]=0; | |
0 | 6430 } |
6431 } | |
2627
bf158d23bbcc
Spelling errors patch by (Kevin Baragona | kevinmb500 gawab com)
michael
parents:
2620
diff
changeset
|
6432 *overflow= s->max_qcoeff < max; //overflow might have happened |
2967 | 6433 |
764 | 6434 /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */ |
1092 | 6435 if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM) |
2979 | 6436 ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero); |
764 | 6437 |
0 | 6438 return last_non_zero; |
6439 } | |
6440 | |
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
|
6441 #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
|
6442 |
2967 | 6443 static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, |
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
|
6444 DCTELEM *block, int n, int qscale) |
0 | 6445 { |
200 | 6446 int i, level, nCoeffs; |
1064 | 6447 const uint16_t *quant_matrix; |
0 | 6448 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6449 nCoeffs= s->block_last_index[n]; |
2967 | 6450 |
6451 if (n < 4) | |
1689 | 6452 block[0] = block[0] * s->y_dc_scale; |
6453 else | |
6454 block[0] = block[0] * s->c_dc_scale; | |
6455 /* XXX: only mpeg1 */ | |
6456 quant_matrix = s->intra_matrix; | |
6457 for(i=1;i<=nCoeffs;i++) { | |
6458 int j= s->intra_scantable.permutated[i]; | |
6459 level = block[j]; | |
6460 if (level) { | |
6461 if (level < 0) { | |
6462 level = -level; | |
6463 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
6464 level = (level - 1) | 1; | |
6465 level = -level; | |
6466 } else { | |
6467 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
6468 level = (level - 1) | 1; | |
0 | 6469 } |
1689 | 6470 block[j] = level; |
0 | 6471 } |
6472 } | |
6473 } | |
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
|
6474 |
2967 | 6475 static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s, |
1689 | 6476 DCTELEM *block, int n, int qscale) |
6477 { | |
6478 int i, level, nCoeffs; | |
6479 const uint16_t *quant_matrix; | |
6480 | |
6481 nCoeffs= s->block_last_index[n]; | |
2967 | 6482 |
1689 | 6483 quant_matrix = s->inter_matrix; |
6484 for(i=0; i<=nCoeffs; i++) { | |
6485 int j= s->intra_scantable.permutated[i]; | |
6486 level = block[j]; | |
6487 if (level) { | |
6488 if (level < 0) { | |
6489 level = -level; | |
6490 level = (((level << 1) + 1) * qscale * | |
6491 ((int) (quant_matrix[j]))) >> 4; | |
6492 level = (level - 1) | 1; | |
6493 level = -level; | |
6494 } else { | |
6495 level = (((level << 1) + 1) * qscale * | |
6496 ((int) (quant_matrix[j]))) >> 4; | |
6497 level = (level - 1) | 1; | |
6498 } | |
6499 block[j] = level; | |
6500 } | |
6501 } | |
6502 } | |
6503 | |
2967 | 6504 static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s, |
325 | 6505 DCTELEM *block, int n, int qscale) |
6506 { | |
6507 int i, level, nCoeffs; | |
1064 | 6508 const uint16_t *quant_matrix; |
325 | 6509 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6510 if(s->alternate_scan) nCoeffs= 63; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6511 else nCoeffs= s->block_last_index[n]; |
2967 | 6512 |
6513 if (n < 4) | |
1689 | 6514 block[0] = block[0] * s->y_dc_scale; |
6515 else | |
6516 block[0] = block[0] * s->c_dc_scale; | |
6517 quant_matrix = s->intra_matrix; | |
6518 for(i=1;i<=nCoeffs;i++) { | |
6519 int j= s->intra_scantable.permutated[i]; | |
6520 level = block[j]; | |
6521 if (level) { | |
6522 if (level < 0) { | |
6523 level = -level; | |
6524 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
6525 level = -level; | |
6526 } else { | |
6527 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
6528 } | |
6529 block[j] = level; | |
6530 } | |
6531 } | |
6532 } | |
6533 | |
3281
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6534 static void dct_unquantize_mpeg2_intra_bitexact(MpegEncContext *s, |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6535 DCTELEM *block, int n, int qscale) |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6536 { |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6537 int i, level, nCoeffs; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6538 const uint16_t *quant_matrix; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6539 int sum=-1; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6540 |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6541 if(s->alternate_scan) nCoeffs= 63; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6542 else nCoeffs= s->block_last_index[n]; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6543 |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6544 if (n < 4) |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6545 block[0] = block[0] * s->y_dc_scale; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6546 else |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6547 block[0] = block[0] * s->c_dc_scale; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6548 quant_matrix = s->intra_matrix; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6549 for(i=1;i<=nCoeffs;i++) { |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6550 int j= s->intra_scantable.permutated[i]; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6551 level = block[j]; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6552 if (level) { |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6553 if (level < 0) { |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6554 level = -level; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6555 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6556 level = -level; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6557 } else { |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6558 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6559 } |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6560 block[j] = level; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6561 sum+=level; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6562 } |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6563 } |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6564 block[63]^=sum&1; |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6565 } |
7fac25904a8b
missmatch control for mpeg2 intra dequantization if bitexact=1
michael
parents:
3268
diff
changeset
|
6566 |
2967 | 6567 static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s, |
1689 | 6568 DCTELEM *block, int n, int qscale) |
6569 { | |
6570 int i, level, nCoeffs; | |
6571 const uint16_t *quant_matrix; | |
6572 int sum=-1; | |
6573 | |
6574 if(s->alternate_scan) nCoeffs= 63; | |
6575 else nCoeffs= s->block_last_index[n]; | |
2967 | 6576 |
1689 | 6577 quant_matrix = s->inter_matrix; |
6578 for(i=0; i<=nCoeffs; i++) { | |
6579 int j= s->intra_scantable.permutated[i]; | |
6580 level = block[j]; | |
6581 if (level) { | |
6582 if (level < 0) { | |
6583 level = -level; | |
6584 level = (((level << 1) + 1) * qscale * | |
6585 ((int) (quant_matrix[j]))) >> 4; | |
6586 level = -level; | |
6587 } else { | |
6588 level = (((level << 1) + 1) * qscale * | |
6589 ((int) (quant_matrix[j]))) >> 4; | |
6590 } | |
6591 block[j] = level; | |
6592 sum+=level; | |
6593 } | |
6594 } | |
6595 block[63]^=sum&1; | |
6596 } | |
6597 | |
2967 | 6598 static void dct_unquantize_h263_intra_c(MpegEncContext *s, |
1689 | 6599 DCTELEM *block, int n, int qscale) |
6600 { | |
6601 int i, level, qmul, qadd; | |
6602 int nCoeffs; | |
2967 | 6603 |
1689 | 6604 assert(s->block_last_index[n]>=0); |
2967 | 6605 |
1689 | 6606 qmul = qscale << 1; |
2967 | 6607 |
1689 | 6608 if (!s->h263_aic) { |
2967 | 6609 if (n < 4) |
325 | 6610 block[0] = block[0] * s->y_dc_scale; |
6611 else | |
6612 block[0] = block[0] * s->c_dc_scale; | |
1689 | 6613 qadd = (qscale - 1) | 1; |
6614 }else{ | |
6615 qadd = 0; | |
6616 } | |
6617 if(s->ac_pred) | |
6618 nCoeffs=63; | |
6619 else | |
6620 nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ]; | |
6621 | |
6622 for(i=1; i<=nCoeffs; i++) { | |
6623 level = block[i]; | |
6624 if (level) { | |
6625 if (level < 0) { | |
6626 level = level * qmul - qadd; | |
6627 } else { | |
6628 level = level * qmul + qadd; | |
325 | 6629 } |
1689 | 6630 block[i] = level; |
325 | 6631 } |
6632 } | |
6633 } | |
6634 | |
2967 | 6635 static void dct_unquantize_h263_inter_c(MpegEncContext *s, |
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
|
6636 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
|
6637 { |
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
|
6638 int i, level, qmul, qadd; |
200 | 6639 int nCoeffs; |
2967 | 6640 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6641 assert(s->block_last_index[n]>=0); |
2967 | 6642 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6643 qadd = (qscale - 1) | 1; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6644 qmul = qscale << 1; |
2967 | 6645 |
1689 | 6646 nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ]; |
6647 | |
6648 for(i=0; 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
|
6649 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
|
6650 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
|
6651 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
|
6652 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
|
6653 } 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
|
6654 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
|
6655 } |
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
|
6656 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
|
6657 } |
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
|
6658 } |
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
|
6659 } |
0 | 6660 |
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
|
6661 #ifdef CONFIG_ENCODERS |
0 | 6662 AVCodec h263_encoder = { |
6663 "h263", | |
6664 CODEC_TYPE_VIDEO, | |
6665 CODEC_ID_H263, | |
6666 sizeof(MpegEncContext), | |
6667 MPV_encode_init, | |
6668 MPV_encode_picture, | |
6669 MPV_encode_end, | |
2524 | 6670 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, |
0 | 6671 }; |
6672 | |
6673 AVCodec h263p_encoder = { | |
6674 "h263p", | |
6675 CODEC_TYPE_VIDEO, | |
6676 CODEC_ID_H263P, | |
6677 sizeof(MpegEncContext), | |
6678 MPV_encode_init, | |
6679 MPV_encode_picture, | |
6680 MPV_encode_end, | |
2524 | 6681 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, |
0 | 6682 }; |
6683 | |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6684 AVCodec flv_encoder = { |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6685 "flv", |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6686 CODEC_TYPE_VIDEO, |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6687 CODEC_ID_FLV1, |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6688 sizeof(MpegEncContext), |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6689 MPV_encode_init, |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6690 MPV_encode_picture, |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6691 MPV_encode_end, |
2524 | 6692 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, |
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6693 }; |
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6694 |
0 | 6695 AVCodec rv10_encoder = { |
6696 "rv10", | |
6697 CODEC_TYPE_VIDEO, | |
6698 CODEC_ID_RV10, | |
6699 sizeof(MpegEncContext), | |
6700 MPV_encode_init, | |
6701 MPV_encode_picture, | |
6702 MPV_encode_end, | |
2524 | 6703 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, |
0 | 6704 }; |
6705 | |
2380 | 6706 AVCodec rv20_encoder = { |
6707 "rv20", | |
6708 CODEC_TYPE_VIDEO, | |
6709 CODEC_ID_RV20, | |
6710 sizeof(MpegEncContext), | |
6711 MPV_encode_init, | |
6712 MPV_encode_picture, | |
6713 MPV_encode_end, | |
2524 | 6714 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, |
2380 | 6715 }; |
6716 | |
71 | 6717 AVCodec mpeg4_encoder = { |
6718 "mpeg4", | |
0 | 6719 CODEC_TYPE_VIDEO, |
71 | 6720 CODEC_ID_MPEG4, |
0 | 6721 sizeof(MpegEncContext), |
6722 MPV_encode_init, | |
6723 MPV_encode_picture, | |
6724 MPV_encode_end, | |
2524 | 6725 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, |
2111 | 6726 .capabilities= CODEC_CAP_DELAY, |
0 | 6727 }; |
6728 | |
307 | 6729 AVCodec msmpeg4v1_encoder = { |
6730 "msmpeg4v1", | |
0 | 6731 CODEC_TYPE_VIDEO, |
307 | 6732 CODEC_ID_MSMPEG4V1, |
0 | 6733 sizeof(MpegEncContext), |
6734 MPV_encode_init, | |
6735 MPV_encode_picture, | |
6736 MPV_encode_end, | |
2524 | 6737 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, |
0 | 6738 }; |
307 | 6739 |
6740 AVCodec msmpeg4v2_encoder = { | |
6741 "msmpeg4v2", | |
6742 CODEC_TYPE_VIDEO, | |
6743 CODEC_ID_MSMPEG4V2, | |
6744 sizeof(MpegEncContext), | |
6745 MPV_encode_init, | |
6746 MPV_encode_picture, | |
6747 MPV_encode_end, | |
2524 | 6748 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, |
307 | 6749 }; |
6750 | |
6751 AVCodec msmpeg4v3_encoder = { | |
6752 "msmpeg4", | |
6753 CODEC_TYPE_VIDEO, | |
6754 CODEC_ID_MSMPEG4V3, | |
6755 sizeof(MpegEncContext), | |
6756 MPV_encode_init, | |
6757 MPV_encode_picture, | |
6758 MPV_encode_end, | |
2524 | 6759 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, |
307 | 6760 }; |
499 | 6761 |
6762 AVCodec wmv1_encoder = { | |
6763 "wmv1", | |
6764 CODEC_TYPE_VIDEO, | |
6765 CODEC_ID_WMV1, | |
6766 sizeof(MpegEncContext), | |
6767 MPV_encode_init, | |
6768 MPV_encode_picture, | |
6769 MPV_encode_end, | |
2524 | 6770 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUV420P, -1}, |
499 | 6771 }; |
6772 | |
1042 | 6773 AVCodec mjpeg_encoder = { |
6774 "mjpeg", | |
6775 CODEC_TYPE_VIDEO, | |
6776 CODEC_ID_MJPEG, | |
6777 sizeof(MpegEncContext), | |
6778 MPV_encode_init, | |
6779 MPV_encode_picture, | |
6780 MPV_encode_end, | |
2524 | 6781 .pix_fmts= (enum PixelFormat[]){PIX_FMT_YUVJ420P, -1}, |
1042 | 6782 }; |
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
|
6783 |
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
|
6784 #endif //CONFIG_ENCODERS |