Mercurial > libavcodec.hg
annotate mpegvideo.c @ 2428:548c87c06dbb libavcodec
assertion about bits statistic and minor bits stat fix
| author | michael |
|---|---|
| date | Fri, 14 Jan 2005 23:48:12 +0000 |
| parents | d1b1a6258930 |
| children | ba01b8552bd4 |
| 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 | |
| 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 295 | 19 * |
| 325 | 20 * 4MV & hq & b-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at> |
| 0 | 21 */ |
| 701 | 22 |
| 1106 | 23 /** |
| 24 * @file mpegvideo.c | |
| 25 * The simplest mpeg encoder (well, it was the simplest!). | |
| 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 |
| 1689 | 44 static void dct_unquantize_mpeg1_intra_c(MpegEncContext *s, |
| 45 DCTELEM *block, int n, int qscale); | |
| 46 static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s, | |
| 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); |
| 1689 | 50 static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s, |
| 325 | 51 DCTELEM *block, int n, int qscale); |
| 1689 | 52 static void dct_unquantize_h263_intra_c(MpegEncContext *s, |
| 53 DCTELEM *block, int n, int qscale); | |
| 54 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
|
55 DCTELEM *block, int n, int qscale); |
| 1064 | 56 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
|
57 #ifdef CONFIG_ENCODERS |
| 344 | 58 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); |
| 945 | 59 static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); |
| 1777 | 60 static int dct_quantize_refine(MpegEncContext *s, DCTELEM *block, int16_t *weight, DCTELEM *orig, int n, int qscale); |
| 1389 | 61 static int sse_mb(MpegEncContext *s); |
| 1719 | 62 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
|
63 #endif //CONFIG_ENCODERS |
| 206 | 64 |
| 1381 | 65 #ifdef HAVE_XVMC |
| 66 extern int XVMC_field_start(MpegEncContext*s, AVCodecContext *avctx); | |
| 67 extern void XVMC_field_end(MpegEncContext *s); | |
|
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1579
diff
changeset
|
68 extern void XVMC_decode_mb(MpegEncContext *s); |
| 1381 | 69 #endif |
| 70 | |
| 1064 | 71 void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w)= draw_edges_c; |
| 206 | 72 |
| 0 | 73 |
| 74 /* enable all paranoid tests for rounding, overflows, etc... */ | |
| 75 //#define PARANOID | |
| 76 | |
| 77 //#define DEBUG | |
| 78 | |
| 321 | 79 |
| 0 | 80 /* for jpeg fast DCT */ |
| 81 #define CONST_BITS 14 | |
| 82 | |
|
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
83 static const uint16_t aanscales[64] = { |
| 0 | 84 /* precomputed values scaled up by 14 bits */ |
| 85 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
| 86 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, | |
| 87 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, | |
| 88 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, | |
| 89 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
| 90 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | |
| 936 | 91 8867 , 12299, 11585, 10426, 8867, 6967, 4799, 2446, |
| 92 4520 , 6270, 5906, 5315, 4520, 3552, 2446, 1247 | |
| 0 | 93 }; |
| 94 | |
|
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
95 static const uint8_t h263_chroma_roundtab[16] = { |
| 1013 | 96 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
| 0 | 97 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, |
| 98 }; | |
| 99 | |
| 1644 | 100 static const uint8_t ff_default_chroma_qscale_table[32]={ |
| 101 // 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 | |
| 102 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 | |
| 103 }; | |
| 104 | |
|
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
|
105 #ifdef CONFIG_ENCODERS |
| 1162 | 106 static uint8_t (*default_mv_penalty)[MAX_MV*2+1]=NULL; |
| 1064 | 107 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
|
108 |
| 998 | 109 enum PixelFormat ff_yuv420p_list[2]= {PIX_FMT_YUV420P, -1}; |
| 110 | |
|
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
111 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
|
112 const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra) |
| 0 | 113 { |
| 344 | 114 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
|
115 int shift=0; |
| 0 | 116 |
|
709
afeff6ccb7f5
convert only needed matrixes in convert_matrix() (mjpeg calls it for every frame)
michaelni
parents:
706
diff
changeset
|
117 for(qscale=qmin; qscale<=qmax; qscale++){ |
| 344 | 118 int i; |
|
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
119 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
|
120 #ifdef FAAN_POSTSCALE |
|
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
121 || dsp->fdct == ff_faandct |
|
1562
bf452704100f
optionally merge postscale into quantization table for the float aan dct
michael
parents:
1557
diff
changeset
|
122 #endif |
|
bf452704100f
optionally merge postscale into quantization table for the float aan dct
michael
parents:
1557
diff
changeset
|
123 ) { |
|
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
|
124 for(i=0;i<64;i++) { |
|
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
125 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
|
126 /* 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
|
127 /* 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
|
128 /* (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
|
129 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ |
|
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
130 |
| 1064 | 131 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
|
132 (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
|
133 } |
|
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
134 } else if (dsp->fdct == fdct_ifast |
|
1562
bf452704100f
optionally merge postscale into quantization table for the float aan dct
michael
parents:
1557
diff
changeset
|
135 #ifndef FAAN_POSTSCALE |
|
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
136 || dsp->fdct == ff_faandct |
|
1562
bf452704100f
optionally merge postscale into quantization table for the float aan dct
michael
parents:
1557
diff
changeset
|
137 #endif |
|
bf452704100f
optionally merge postscale into quantization table for the float aan dct
michael
parents:
1557
diff
changeset
|
138 ) { |
| 344 | 139 for(i=0;i<64;i++) { |
|
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
140 const int j= dsp->idct_permutation[i]; |
| 344 | 141 /* 16 <= qscale * quant_matrix[i] <= 7905 */ |
| 142 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ | |
| 143 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ | |
| 144 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ | |
| 145 | |
| 1064 | 146 qmat[qscale][i] = (int)((uint64_t_C(1) << (QMAT_SHIFT + 14)) / |
| 344 | 147 (aanscales[i] * qscale * quant_matrix[j])); |
| 148 } | |
| 149 } else { | |
| 150 for(i=0;i<64;i++) { | |
|
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
151 const int j= dsp->idct_permutation[i]; |
| 344 | 152 /* We can safely suppose that 16 <= quant_matrix[i] <= 255 |
| 153 So 16 <= qscale * quant_matrix[i] <= 7905 | |
| 154 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 | |
| 155 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 | |
| 156 */ | |
| 1064 | 157 qmat[qscale][i] = (int)((uint64_t_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); |
| 945 | 158 // 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
|
159 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
|
160 |
|
d736e24bf303
move mmx quantizer matrixes out of MpegEncContext (23k -> 7k) (no meassureable slowdown)
michael
parents:
1553
diff
changeset
|
161 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
|
162 qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); |
| 344 | 163 } |
| 0 | 164 } |
|
2385
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
165 |
|
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
166 for(i=intra; i<64; i++){ |
| 2390 | 167 int64_t max= 8191; |
| 168 if (dsp->fdct == fdct_ifast | |
| 169 #ifndef FAAN_POSTSCALE | |
| 170 || dsp->fdct == ff_faandct | |
| 171 #endif | |
| 172 ) { | |
| 173 max= (8191LL*aanscales[i]) >> 14; | |
| 174 } | |
| 175 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
|
176 shift++; |
|
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
177 } |
|
4605a8b188c3
warn the user if the quantization code could overflow with the selected custom matrix and qp limits
michael
parents:
2382
diff
changeset
|
178 } |
|
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 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
|
181 av_log(NULL, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger then %d, overflows possible\n", QMAT_SHIFT - shift); |
| 0 | 182 } |
| 183 } | |
|
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
|
184 |
|
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
|
185 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
|
186 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
|
187 s->qscale= clip(s->qscale, s->avctx->qmin, s->avctx->qmax); |
|
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 |
|
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->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
|
190 } |
|
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
|
191 #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
|
192 |
| 1273 | 193 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
|
194 int i; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
195 int end; |
| 764 | 196 |
| 197 st->scantable= src_scantable; | |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
198 |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
199 for(i=0; i<64; i++){ |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
200 int j; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
201 j = src_scantable[i]; |
| 1273 | 202 st->permutated[i] = permutation[j]; |
|
828
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
203 #ifdef ARCH_POWERPC |
|
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
204 st->inverse[j] = i; |
|
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
205 #endif |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
206 } |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
207 |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
208 end=-1; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
209 for(i=0; i<64; i++){ |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
210 int j; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
211 j = st->permutated[i]; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
212 if(j>end) end=j; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
213 st->raster_end[i]= end; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
214 } |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
215 } |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
216 |
|
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1523
diff
changeset
|
217 #ifdef CONFIG_ENCODERS |
| 1411 | 218 void ff_write_quant_matrix(PutBitContext *pb, int16_t *matrix){ |
| 219 int i; | |
| 220 | |
| 221 if(matrix){ | |
| 222 put_bits(pb, 1, 1); | |
| 223 for(i=0;i<64;i++) { | |
| 224 put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]); | |
| 225 } | |
| 226 }else | |
| 227 put_bits(pb, 1, 0); | |
| 228 } | |
|
1530
3b31998fe22f
disable encoders where appropriate (patch courtesy of BERO
melanson
parents:
1523
diff
changeset
|
229 #endif //CONFIG_ENCODERS |
| 1411 | 230 |
|
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
|
231 /* 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
|
232 int DCT_common_init(MpegEncContext *s) |
| 0 | 233 { |
| 1689 | 234 s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c; |
| 235 s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c; | |
| 236 s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c; | |
| 237 s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c; | |
| 238 s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c; | |
| 239 s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c; | |
| 1092 | 240 |
|
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
|
241 #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
|
242 s->dct_quantize= dct_quantize_c; |
| 1719 | 243 s->denoise_dct= denoise_dct_c; |
| 1092 | 244 #endif |
|
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
245 |
|
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
|
246 #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
|
247 MPV_common_init_mmx(s); |
| 8 | 248 #endif |
|
514
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M?ns Rullg?rd
mellum
parents:
506
diff
changeset
|
249 #ifdef ARCH_ALPHA |
|
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M?ns Rullg?rd
mellum
parents:
506
diff
changeset
|
250 MPV_common_init_axp(s); |
|
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M?ns Rullg?rd
mellum
parents:
506
diff
changeset
|
251 #endif |
|
628
f596db4aa871
sun solaris compilation bugfix, patch by (Martin Olschewski <olschewski at zpr dot uni-koeln dot de>)
michaelni
parents:
625
diff
changeset
|
252 #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
|
253 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
|
254 #endif |
|
721
71f669e9f633
ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
michaelni
parents:
717
diff
changeset
|
255 #ifdef HAVE_MMI |
|
71f669e9f633
ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
michaelni
parents:
717
diff
changeset
|
256 MPV_common_init_mmi(s); |
|
71f669e9f633
ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
michaelni
parents:
717
diff
changeset
|
257 #endif |
| 730 | 258 #ifdef ARCH_ARMV4L |
| 874 | 259 MPV_common_init_armv4l(s); |
| 730 | 260 #endif |
|
828
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
261 #ifdef ARCH_POWERPC |
|
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
262 MPV_common_init_ppc(s); |
|
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
263 #endif |
| 730 | 264 |
|
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
|
265 #ifdef CONFIG_ENCODERS |
| 1007 | 266 s->fast_dct_quantize= s->dct_quantize; |
| 267 | |
| 945 | 268 if(s->flags&CODEC_FLAG_TRELLIS_QUANT){ |
| 269 s->dct_quantize= dct_quantize_trellis_c; //move before MPV_common_init_* | |
| 270 } | |
| 271 | |
|
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
|
272 #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
|
273 |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
274 /* load & permutate scantables |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
275 note: only wmv uses differnt ones |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
276 */ |
| 1708 | 277 if(s->alternate_scan){ |
| 278 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan); | |
| 279 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan); | |
| 280 }else{ | |
| 281 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct); | |
| 282 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct); | |
| 283 } | |
| 1273 | 284 ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, ff_alternate_horizontal_scan); |
| 285 ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan); | |
| 591 | 286 |
|
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
|
287 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
|
288 } |
|
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
289 |
|
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
|
290 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
|
291 *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
|
292 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
|
293 } |
|
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
|
294 |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
295 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
|
296 int i; |
|
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
297 |
| 1702 | 298 dst->pict_type = src->pict_type; |
| 299 dst->quality = src->quality; | |
| 300 dst->coded_picture_number = src->coded_picture_number; | |
| 301 dst->display_picture_number = src->display_picture_number; | |
| 302 // dst->reference = src->reference; | |
| 303 dst->pts = src->pts; | |
| 304 dst->interlaced_frame = src->interlaced_frame; | |
| 305 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
|
306 |
|
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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 if(src->motion_subsample_log2 != dst->motion_subsample_log2) |
|
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
|
315 av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesnt match! (%d!=%d)\n", |
|
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
|
316 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
|
317 |
|
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
|
318 memcpy(dst->mb_type, src->mb_type, s->mb_stride * s->mb_height * sizeof(dst->mb_type[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
|
319 |
|
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
|
320 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
|
321 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
|
322 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
|
323 |
|
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
|
324 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
|
325 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
|
326 } |
|
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
|
327 if(src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]){ |
| 1948 | 328 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
|
329 } |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
330 } |
|
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
331 } |
| 1702 | 332 } |
| 333 | |
| 903 | 334 /** |
| 924 | 335 * allocates a Picture |
| 336 * The pixels are allocated/set by calling get_buffer() if shared=0 | |
| 903 | 337 */ |
| 924 | 338 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
|
339 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
|
340 const int mb_array_size= s->mb_stride*s->mb_height; |
| 1655 | 341 const int b8_array_size= s->b8_stride*s->mb_height*2; |
| 342 const int b4_array_size= s->b4_stride*s->mb_height*4; | |
| 1168 | 343 int 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
|
344 |
| 924 | 345 if(shared){ |
| 346 assert(pic->data[0]); | |
| 347 assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED); | |
| 348 pic->type= FF_BUFFER_TYPE_SHARED; | |
| 349 }else{ | |
| 350 int r; | |
| 351 | |
| 352 assert(!pic->data[0]); | |
| 353 | |
| 925 | 354 r= s->avctx->get_buffer(s->avctx, (AVFrame*)pic); |
| 924 | 355 |
| 356 if(r<0 || !pic->age || !pic->type || !pic->data[0]){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
357 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]); |
| 924 | 358 return -1; |
| 359 } | |
| 360 | |
| 361 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
|
362 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n"); |
| 924 | 363 return -1; |
| 364 } | |
| 365 | |
| 366 if(pic->linesize[1] != pic->linesize[2]){ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
367 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride missmatch)\n"); |
| 924 | 368 return -1; |
| 369 } | |
| 370 | |
| 371 s->linesize = pic->linesize[0]; | |
| 372 s->uvlinesize= pic->linesize[1]; | |
| 903 | 373 } |
| 924 | 374 |
| 375 if(pic->qscale_table==NULL){ | |
| 376 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
|
377 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
|
378 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
|
379 CHECKED_ALLOCZ(pic->mb_mean , mb_array_size * sizeof(int8_t)) |
| 924 | 380 } |
| 381 | |
|
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
|
382 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
|
383 CHECKED_ALLOCZ(pic->qscale_table , mb_array_size * sizeof(uint8_t)) |
| 1742 | 384 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
|
385 pic->mb_type= pic->mb_type_base + s->mb_stride+1; |
| 1168 | 386 if(s->out_format == FMT_H264){ |
| 387 for(i=0; i<2; i++){ | |
| 1885 | 388 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b4_array_size+2) * sizeof(int16_t)) |
| 389 pic->motion_val[i]= pic->motion_val_base[i]+2; | |
| 1948 | 390 CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t)) |
| 1655 | 391 } |
| 1669 | 392 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
|
393 }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){ |
| 1655 | 394 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
|
395 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+2) * sizeof(int16_t)) |
| 1885 | 396 pic->motion_val[i]= pic->motion_val_base[i]+2; |
| 1948 | 397 CHECKED_ALLOCZ(pic->ref_index[i], b8_array_size * sizeof(uint8_t)) |
| 1168 | 398 } |
| 1669 | 399 pic->motion_subsample_log2= 3; |
| 1168 | 400 } |
|
1833
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
401 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
|
402 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
|
403 } |
|
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
|
404 pic->qstride= s->mb_stride; |
| 1546 | 405 CHECKED_ALLOCZ(pic->pan_scan , 1 * sizeof(AVPanScan)) |
| 924 | 406 } |
| 1168 | 407 |
|
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
408 //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
|
409 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
|
410 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
|
411 if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == B_TYPE) |
|
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
412 pic->age= INT_MAX; // skiped MBs in b frames are quite rare in mpeg1/2 and its a bit tricky to skip them anyway |
|
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
413 |
| 903 | 414 return 0; |
| 415 fail: //for the CHECKED_ALLOCZ macro | |
| 416 return -1; | |
| 417 } | |
| 418 | |
| 924 | 419 /** |
| 420 * deallocates a picture | |
| 421 */ | |
| 903 | 422 static void free_picture(MpegEncContext *s, Picture *pic){ |
| 423 int i; | |
| 924 | 424 |
| 425 if(pic->data[0] && pic->type!=FF_BUFFER_TYPE_SHARED){ | |
| 925 | 426 s->avctx->release_buffer(s->avctx, (AVFrame*)pic); |
| 924 | 427 } |
| 428 | |
| 903 | 429 av_freep(&pic->mb_var); |
| 430 av_freep(&pic->mc_mb_var); | |
| 431 av_freep(&pic->mb_mean); | |
| 432 av_freep(&pic->mbskip_table); | |
| 433 av_freep(&pic->qscale_table); | |
| 1168 | 434 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
|
435 av_freep(&pic->dct_coeff); |
| 1546 | 436 av_freep(&pic->pan_scan); |
| 1168 | 437 pic->mb_type= NULL; |
| 438 for(i=0; i<2; i++){ | |
| 1655 | 439 av_freep(&pic->motion_val_base[i]); |
| 1168 | 440 av_freep(&pic->ref_index[i]); |
| 441 } | |
| 1214 | 442 |
| 443 if(pic->type == FF_BUFFER_TYPE_SHARED){ | |
| 924 | 444 for(i=0; i<4; i++){ |
| 445 pic->base[i]= | |
| 446 pic->data[i]= NULL; | |
| 447 } | |
| 448 pic->type= 0; | |
| 903 | 449 } |
| 450 } | |
| 451 | |
| 1799 | 452 static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){ |
| 453 int i; | |
| 454 | |
| 1838 | 455 // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264) |
| 1799 | 456 CHECKED_ALLOCZ(s->allocated_edge_emu_buffer, (s->width+64)*2*17*2); //(width + edge + align)*interlaced*MBsize*tolerance |
| 457 s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*17; | |
| 458 | |
| 459 //FIXME should be linesize instead of s->width*2 but that isnt known before get_buffer() | |
|
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
460 CHECKED_ALLOCZ(s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t)) |
| 1799 | 461 s->rd_scratchpad= s->me.scratchpad; |
| 462 s->b_scratchpad= s->me.scratchpad; | |
| 463 s->obmc_scratchpad= s->me.scratchpad + 16; | |
| 464 if (s->encoding) { | |
| 465 CHECKED_ALLOCZ(s->me.map , ME_MAP_SIZE*sizeof(uint32_t)) | |
| 466 CHECKED_ALLOCZ(s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t)) | |
| 467 if(s->avctx->noise_reduction){ | |
| 468 CHECKED_ALLOCZ(s->dct_error_sum, 2 * 64 * sizeof(int)) | |
| 469 } | |
| 470 } | |
|
1848
c72589baee53
initial chroma_format changes,xvmc tweaks and codec_cap
iive
parents:
1846
diff
changeset
|
471 CHECKED_ALLOCZ(s->blocks, 64*12*2 * sizeof(DCTELEM)) |
| 1799 | 472 s->block= s->blocks[0]; |
| 473 | |
| 474 for(i=0;i<12;i++){ | |
| 475 s->pblocks[i] = (short *)(&s->block[i]); | |
| 476 } | |
| 477 return 0; | |
| 478 fail: | |
| 479 return -1; //free() through MPV_common_end() | |
| 480 } | |
| 481 | |
| 482 static void free_duplicate_context(MpegEncContext *s){ | |
| 483 if(s==NULL) return; | |
| 484 | |
| 485 av_freep(&s->allocated_edge_emu_buffer); s->edge_emu_buffer= NULL; | |
| 486 av_freep(&s->me.scratchpad); | |
| 487 s->rd_scratchpad= | |
| 488 s->b_scratchpad= | |
| 489 s->obmc_scratchpad= NULL; | |
| 490 | |
| 491 av_freep(&s->dct_error_sum); | |
| 492 av_freep(&s->me.map); | |
| 493 av_freep(&s->me.score_map); | |
| 494 av_freep(&s->blocks); | |
| 495 s->block= NULL; | |
| 496 } | |
| 497 | |
| 498 static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src){ | |
| 499 #define COPY(a) bak->a= src->a | |
| 500 COPY(allocated_edge_emu_buffer); | |
| 501 COPY(edge_emu_buffer); | |
| 502 COPY(me.scratchpad); | |
| 503 COPY(rd_scratchpad); | |
| 504 COPY(b_scratchpad); | |
| 505 COPY(obmc_scratchpad); | |
| 506 COPY(me.map); | |
| 507 COPY(me.score_map); | |
| 508 COPY(blocks); | |
| 509 COPY(block); | |
| 510 COPY(start_mb_y); | |
| 511 COPY(end_mb_y); | |
| 512 COPY(me.map_generation); | |
| 513 COPY(pb); | |
| 514 COPY(dct_error_sum); | |
| 1810 | 515 COPY(dct_count[0]); |
| 516 COPY(dct_count[1]); | |
| 1799 | 517 #undef COPY |
| 518 } | |
| 519 | |
| 1827 | 520 void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src){ |
| 1799 | 521 MpegEncContext bak; |
| 1827 | 522 int i; |
| 1799 | 523 //FIXME copy only needed parts |
| 524 //START_TIMER | |
| 525 backup_duplicate_context(&bak, dst); | |
| 526 memcpy(dst, src, sizeof(MpegEncContext)); | |
| 527 backup_duplicate_context(dst, &bak); | |
| 1827 | 528 for(i=0;i<12;i++){ |
| 529 dst->pblocks[i] = (short *)(&dst->block[i]); | |
| 530 } | |
| 1799 | 531 //STOP_TIMER("update_duplicate_context") //about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads |
| 532 } | |
| 533 | |
| 534 static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src){ | |
| 535 #define COPY(a) dst->a= src->a | |
| 536 COPY(pict_type); | |
| 537 COPY(current_picture); | |
| 538 COPY(f_code); | |
| 539 COPY(b_code); | |
| 540 COPY(qscale); | |
| 541 COPY(lambda); | |
| 542 COPY(lambda2); | |
| 543 COPY(picture_in_gop_number); | |
| 544 COPY(gop_picture_number); | |
| 545 COPY(frame_pred_frame_dct); //FIXME dont set in encode_header | |
| 546 COPY(progressive_frame); //FIXME dont set in encode_header | |
| 547 COPY(partitioned_frame); //FIXME dont set in encode_header | |
| 548 #undef COPY | |
| 549 } | |
| 550 | |
| 1892 | 551 /** |
| 552 * sets the given MpegEncContext to common defaults (same for encoding and decoding). | |
| 553 * the changed fields will not depend upon the prior state of the MpegEncContext. | |
| 554 */ | |
| 555 static void MPV_common_defaults(MpegEncContext *s){ | |
| 556 s->y_dc_scale_table= | |
| 557 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
| 558 s->chroma_qscale_table= ff_default_chroma_qscale_table; | |
| 559 s->progressive_frame= 1; | |
| 560 s->progressive_sequence= 1; | |
| 561 s->picture_structure= PICT_FRAME; | |
| 562 | |
| 563 s->coded_picture_number = 0; | |
| 564 s->picture_number = 0; | |
| 565 s->input_picture_number = 0; | |
| 566 | |
| 567 s->picture_in_gop_number = 0; | |
| 1894 | 568 |
| 569 s->f_code = 1; | |
| 570 s->b_code = 1; | |
| 1892 | 571 } |
| 572 | |
| 573 /** | |
| 574 * sets the given MpegEncContext to defaults for decoding. | |
| 575 * the changed fields will not depend upon the prior state of the MpegEncContext. | |
| 576 */ | |
| 577 void MPV_decode_defaults(MpegEncContext *s){ | |
| 578 MPV_common_defaults(s); | |
| 579 } | |
| 580 | |
| 581 /** | |
| 582 * sets the given MpegEncContext to defaults for encoding. | |
| 583 * the changed fields will not depend upon the prior state of the MpegEncContext. | |
| 584 */ | |
|
1902
a5588762c4fa
Compile fix by (Chip <szarlada at freemail dot hu>)
michael
parents:
1894
diff
changeset
|
585 |
|
a5588762c4fa
Compile fix by (Chip <szarlada at freemail dot hu>)
michael
parents:
1894
diff
changeset
|
586 #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
|
587 static void MPV_encode_defaults(MpegEncContext *s){ |
| 1892 | 588 static int done=0; |
| 589 | |
| 590 MPV_common_defaults(s); | |
| 591 | |
| 592 if(!done){ | |
| 593 int i; | |
| 594 done=1; | |
| 595 | |
| 596 default_mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) ); | |
| 597 memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1)); | |
| 598 | |
| 599 for(i=-16; i<16; i++){ | |
| 600 default_fcode_tab[i + MAX_MV]= 1; | |
| 601 } | |
| 602 } | |
| 603 s->me.mv_penalty= default_mv_penalty; | |
| 604 s->fcode_tab= default_fcode_tab; | |
| 605 } | |
|
1902
a5588762c4fa
Compile fix by (Chip <szarlada at freemail dot hu>)
michael
parents:
1894
diff
changeset
|
606 #endif //CONFIG_ENCODERS |
| 1892 | 607 |
| 608 /** | |
| 609 * init common structure for both encoder and decoder. | |
| 610 * this assumes that some variables like width/height are already set | |
| 611 */ | |
|
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
|
612 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
|
613 { |
| 1708 | 614 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
|
615 |
| 1991 | 616 if(s->avctx->thread_count > MAX_THREADS || (16*s->avctx->thread_count > s->height && s->height)){ |
| 1989 | 617 av_log(s->avctx, AV_LOG_ERROR, "too many threads\n"); |
| 618 return -1; | |
| 619 } | |
| 620 | |
| 2422 | 621 if((s->width || s->height) && avcodec_check_dimensions(s->avctx, s->width, s->height)) |
| 622 return -1; | |
| 623 | |
| 1092 | 624 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
|
625 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
|
626 |
| 754 | 627 s->flags= s->avctx->flags; |
|
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
628 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
|
629 |
| 903 | 630 s->mb_width = (s->width + 15) / 16; |
| 0 | 631 s->mb_height = (s->height + 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
|
632 s->mb_stride = s->mb_width + 1; |
| 1655 | 633 s->b8_stride = s->mb_width*2 + 1; |
| 634 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
|
635 mb_array_size= s->mb_height * s->mb_stride; |
| 1708 | 636 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
|
637 |
|
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
638 /* set chroma shifts */ |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
639 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
|
640 &(s->chroma_y_shift) ); |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
641 |
|
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
642 /* 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
|
643 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
|
644 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
|
645 |
|
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
646 s->mb_num = s->mb_width * s->mb_height; |
|
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
|
647 |
|
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
|
648 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
|
649 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
|
650 s->block_wrap[2]= |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
651 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
|
652 s->block_wrap[4]= |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
653 s->block_wrap[5]= s->mb_stride; |
| 1892 | 654 |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
655 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
|
656 c_size = s->mb_stride * (s->mb_height + 1); |
| 756 | 657 yc_size = y_size + 2 * c_size; |
| 1892 | 658 |
| 701 | 659 /* convert fourcc to upper case */ |
| 1116 | 660 s->avctx->codec_tag= toupper( s->avctx->codec_tag &0xFF) |
| 661 + (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 ) | |
| 662 + (toupper((s->avctx->codec_tag>>16)&0xFF)<<16) | |
| 663 + (toupper((s->avctx->codec_tag>>24)&0xFF)<<24); | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
664 |
|
1458
40b69d238beb
AVI stream header FCC / more reliable detection of old xvid files
michaelni
parents:
1451
diff
changeset
|
665 s->avctx->stream_codec_tag= toupper( s->avctx->stream_codec_tag &0xFF) |
|
40b69d238beb
AVI stream header FCC / more reliable detection of old xvid files
michaelni
parents:
1451
diff
changeset
|
666 + (toupper((s->avctx->stream_codec_tag>>8 )&0xFF)<<8 ) |
|
40b69d238beb
AVI stream header FCC / more reliable detection of old xvid files
michaelni
parents:
1451
diff
changeset
|
667 + (toupper((s->avctx->stream_codec_tag>>16)&0xFF)<<16) |
|
40b69d238beb
AVI stream header FCC / more reliable detection of old xvid files
michaelni
parents:
1451
diff
changeset
|
668 + (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
|
669 |
| 925 | 670 s->avctx->coded_frame= (AVFrame*)&s->current_picture; |
| 903 | 671 |
|
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
|
672 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
|
673 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
|
674 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
|
675 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
|
676 } |
|
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
|
677 } |
|
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
|
678 s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width; //FIXME really needed? |
|
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
|
679 |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
680 if (s->encoding) { |
| 324 | 681 /* 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
|
682 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
|
683 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
|
684 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
|
685 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
|
686 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
|
687 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
|
688 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
|
689 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
|
690 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
|
691 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
|
692 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
|
693 s->b_direct_mv_table = s->b_direct_mv_table_base + s->mb_stride + 1; |
| 324 | 694 |
|
650
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
695 if(s->msmpeg4_version){ |
|
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
696 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
|
697 } |
| 612 | 698 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
|
699 |
|
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
|
700 /* Allocate MB type table */ |
| 1708 | 701 CHECKED_ALLOCZ(s->mb_type , mb_array_size * sizeof(uint16_t)) //needed for encoding |
|
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
|
702 |
|
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
|
703 CHECKED_ALLOCZ(s->lambda_table, mb_array_size * sizeof(int)) |
|
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
|
704 |
|
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
|
705 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
|
706 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
|
707 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
|
708 CHECKED_ALLOCZ(s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t)) |
| 1556 | 709 CHECKED_ALLOCZ(s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*)) |
| 710 CHECKED_ALLOCZ(s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*)) | |
| 1597 | 711 |
| 712 if(s->avctx->noise_reduction){ | |
| 713 CHECKED_ALLOCZ(s->dct_offset, 2 * 64 * sizeof(uint16_t)) | |
| 714 } | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
715 } |
|
1552
26c6ecba99a1
dynamic alloc of picture structs instead of putting them in MpegEncContext
michael
parents:
1546
diff
changeset
|
716 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
|
717 |
|
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
|
718 CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t)) |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
719 |
| 1708 | 720 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
|
721 /* interlaced direct mode decoding tables */ |
| 1708 | 722 for(i=0; i<2; i++){ |
| 723 int j, k; | |
| 724 for(j=0; j<2; j++){ | |
| 725 for(k=0; k<2; k++){ | |
| 726 CHECKED_ALLOCZ(s->b_field_mv_table_base[i][j][k] , mv_table_size * 2 * sizeof(int16_t)) | |
| 727 s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] + s->mb_stride + 1; | |
| 728 } | |
| 729 CHECKED_ALLOCZ(s->b_field_select_table[i][j] , mb_array_size * 2 * sizeof(uint8_t)) | |
| 730 CHECKED_ALLOCZ(s->p_field_mv_table_base[i][j] , mv_table_size * 2 * sizeof(int16_t)) | |
| 731 s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j] + s->mb_stride + 1; | |
| 732 } | |
| 733 CHECKED_ALLOCZ(s->p_field_select_table[i] , mb_array_size * 2 * sizeof(uint8_t)) | |
| 734 } | |
| 0 | 735 } |
| 767 | 736 if (s->out_format == FMT_H263) { |
| 0 | 737 /* ac values */ |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
738 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
|
739 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
|
740 s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1; |
| 0 | 741 s->ac_val[2] = s->ac_val[1] + c_size; |
| 742 | |
| 743 /* cbp values */ | |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
744 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
|
745 s->coded_block= s->coded_block_base + s->b8_stride + 1; |
| 333 | 746 |
| 456 | 747 /* 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
|
748 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
|
749 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
|
750 } |
| 756 | 751 |
| 752 if (s->h263_pred || s->h263_plus || !s->encoding) { | |
| 753 /* dc values */ | |
| 754 //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
|
755 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
|
756 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
|
757 s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1; |
| 756 | 758 s->dc_val[2] = s->dc_val[1] + c_size; |
| 759 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
|
760 s->dc_val_base[i] = 1024; |
| 756 | 761 } |
| 762 | |
|
611
3214d3f4519e
error concealment needs the mbintra_table so it should allways be allocated
michaelni
parents:
608
diff
changeset
|
763 /* 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
|
764 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
|
765 memset(s->mbintra_table, 1, mb_array_size); |
|
611
3214d3f4519e
error concealment needs the mbintra_table so it should allways be allocated
michaelni
parents:
608
diff
changeset
|
766 |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
767 /* 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
|
768 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
|
769 //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
|
770 CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE); |
| 294 | 771 |
|
842
e460775adb38
cleanup (breaks compatibility, requested by fabrice)
michaelni
parents:
828
diff
changeset
|
772 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
|
773 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
|
774 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
|
775 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
|
776 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
|
777 } |
|
842
e460775adb38
cleanup (breaks compatibility, requested by fabrice)
michaelni
parents:
828
diff
changeset
|
778 |
| 0 | 779 s->context_initialized = 1; |
| 1799 | 780 |
| 781 s->thread_context[0]= s; | |
| 782 for(i=1; i<s->avctx->thread_count; i++){ | |
| 783 s->thread_context[i]= av_malloc(sizeof(MpegEncContext)); | |
| 784 memcpy(s->thread_context[i], s, sizeof(MpegEncContext)); | |
| 785 } | |
| 786 | |
| 787 for(i=0; i<s->avctx->thread_count; i++){ | |
| 788 if(init_duplicate_context(s->thread_context[i], s) < 0) | |
| 789 goto fail; | |
| 790 s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count; | |
| 791 s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count/2) / s->avctx->thread_count; | |
| 792 } | |
| 793 | |
| 0 | 794 return 0; |
| 795 fail: | |
| 244 | 796 MPV_common_end(s); |
| 797 return -1; | |
| 798 } | |
| 799 | |
| 800 /* init common structure for both encoder and decoder */ | |
| 801 void MPV_common_end(MpegEncContext *s) | |
| 802 { | |
| 1708 | 803 int i, j, k; |
| 244 | 804 |
| 1799 | 805 for(i=0; i<s->avctx->thread_count; i++){ |
| 806 free_duplicate_context(s->thread_context[i]); | |
| 807 } | |
| 808 for(i=1; i<s->avctx->thread_count; i++){ | |
| 809 av_freep(&s->thread_context[i]); | |
| 810 } | |
| 811 | |
|
1344
447b88b784ee
memleak fix by (Jake Page <jake at CS dot Stanford dot EDU>)
michaelni
parents:
1339
diff
changeset
|
812 av_freep(&s->parse_context.buffer); |
|
447b88b784ee
memleak fix by (Jake Page <jake at CS dot Stanford dot EDU>)
michaelni
parents:
1339
diff
changeset
|
813 s->parse_context.buffer_size=0; |
|
447b88b784ee
memleak fix by (Jake Page <jake at CS dot Stanford dot EDU>)
michaelni
parents:
1339
diff
changeset
|
814 |
|
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
815 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
|
816 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
|
817 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
|
818 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
|
819 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
|
820 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
|
821 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
|
822 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
|
823 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
|
824 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
|
825 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
|
826 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
|
827 s->b_direct_mv_table= NULL; |
| 1708 | 828 for(i=0; i<2; i++){ |
| 829 for(j=0; j<2; j++){ | |
| 830 for(k=0; k<2; k++){ | |
| 831 av_freep(&s->b_field_mv_table_base[i][j][k]); | |
| 832 s->b_field_mv_table[i][j][k]=NULL; | |
| 833 } | |
| 834 av_freep(&s->b_field_select_table[i][j]); | |
| 835 av_freep(&s->p_field_mv_table_base[i][j]); | |
| 836 s->p_field_mv_table[i][j]=NULL; | |
| 837 } | |
| 838 av_freep(&s->p_field_select_table[i]); | |
| 839 } | |
|
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
|
840 |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
841 av_freep(&s->dc_val_base); |
|
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
842 av_freep(&s->ac_val_base); |
|
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
843 av_freep(&s->coded_block_base); |
|
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
844 av_freep(&s->mbintra_table); |
| 456 | 845 av_freep(&s->cbp_table); |
| 846 av_freep(&s->pred_dir_table); | |
| 847 | |
|
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
848 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
|
849 av_freep(&s->prev_pict_types); |
|
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
850 av_freep(&s->bitstream_buffer); |
| 2422 | 851 s->allocated_bitstream_buffer_size=0; |
| 852 | |
| 612 | 853 av_freep(&s->avctx->stats_out); |
|
650
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
854 av_freep(&s->ac_stats); |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
855 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
|
856 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
|
857 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
|
858 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
|
859 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
|
860 av_freep(&s->q_intra_matrix16); |
|
d736e24bf303
move mmx quantizer matrixes out of MpegEncContext (23k -> 7k) (no meassureable slowdown)
michael
parents:
1553
diff
changeset
|
861 av_freep(&s->q_inter_matrix16); |
| 1556 | 862 av_freep(&s->input_picture); |
| 863 av_freep(&s->reordered_input_picture); | |
| 1597 | 864 av_freep(&s->dct_offset); |
| 903 | 865 |
| 1573 | 866 if(s->picture){ |
| 867 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
| 868 free_picture(s, &s->picture[i]); | |
| 869 } | |
| 0 | 870 } |
|
1552
26c6ecba99a1
dynamic alloc of picture structs instead of putting them in MpegEncContext
michael
parents:
1546
diff
changeset
|
871 av_freep(&s->picture); |
| 0 | 872 s->context_initialized = 0; |
| 1523 | 873 s->last_picture_ptr= |
| 874 s->next_picture_ptr= | |
| 875 s->current_picture_ptr= NULL; | |
| 2231 | 876 s->linesize= s->uvlinesize= 0; |
|
1918
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
877 |
|
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
878 for(i=0; i<3; i++) |
|
1918
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
879 av_freep(&s->visualization_buffer[i]); |
| 2231 | 880 |
| 881 avcodec_default_free_buffers(s->avctx); | |
| 0 | 882 } |
| 883 | |
|
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
|
884 #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
|
885 |
| 0 | 886 /* init video encoder */ |
| 887 int MPV_encode_init(AVCodecContext *avctx) | |
| 888 { | |
| 889 MpegEncContext *s = avctx->priv_data; | |
| 1424 | 890 int i, dummy; |
|
1315
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
891 int chroma_h_shift, chroma_v_shift; |
| 1892 | 892 |
| 893 MPV_encode_defaults(s); | |
| 315 | 894 |
|
1402
f662e9c86cf2
* fixing a regression in mpeg encoder (not setting pix_fmt),
romansh
parents:
1397
diff
changeset
|
895 avctx->pix_fmt = PIX_FMT_YUV420P; // FIXME |
|
f662e9c86cf2
* fixing a regression in mpeg encoder (not setting pix_fmt),
romansh
parents:
1397
diff
changeset
|
896 |
| 0 | 897 s->bit_rate = avctx->bit_rate; |
| 898 s->width = avctx->width; | |
| 899 s->height = avctx->height; | |
| 456 | 900 if(avctx->gop_size > 600){ |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
901 av_log(avctx, AV_LOG_ERROR, "Warning keyframe interval too large! reducing it ...\n"); |
| 456 | 902 avctx->gop_size=600; |
| 903 } | |
| 0 | 904 s->gop_size = avctx->gop_size; |
|
194
27d1773552c9
mpeg4 encoder fix by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
191
diff
changeset
|
905 s->avctx = avctx; |
| 294 | 906 s->flags= avctx->flags; |
|
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
907 s->flags2= avctx->flags2; |
| 324 | 908 s->max_b_frames= avctx->max_b_frames; |
| 344 | 909 s->codec_id= avctx->codec->id; |
| 456 | 910 s->luma_elim_threshold = avctx->luma_elim_threshold; |
| 911 s->chroma_elim_threshold= avctx->chroma_elim_threshold; | |
| 912 s->strict_std_compliance= avctx->strict_std_compliance; | |
| 913 s->data_partitioning= avctx->flags & CODEC_FLAG_PART; | |
| 936 | 914 s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0; |
| 599 | 915 s->mpeg_quant= avctx->mpeg_quant; |
| 1661 | 916 s->rtp_mode= !!avctx->rtp_payload_size; |
| 1992 | 917 s->intra_dc_precision= avctx->intra_dc_precision; |
|
2243
b8bad8bbbc64
check if the user specified timestamps are strictly monotone
michael
parents:
2235
diff
changeset
|
918 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
|
919 |
| 0 | 920 if (s->gop_size <= 1) { |
| 921 s->intra_only = 1; | |
| 922 s->gop_size = 12; | |
| 923 } else { | |
| 924 s->intra_only = 0; | |
| 925 } | |
|
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
926 |
| 936 | 927 s->me_method = avctx->me_method; |
|
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
928 |
|
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
929 /* Fixed QSCALE */ |
| 1708 | 930 s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE); |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
931 |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
932 s->adaptive_quant= ( s->avctx->lumi_masking |
|
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
933 || s->avctx->dark_masking |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
934 || s->avctx->temporal_cplx_masking |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
935 || s->avctx->spatial_cplx_masking |
| 1616 | 936 || s->avctx->p_masking |
| 937 || (s->flags&CODEC_FLAG_QP_RD)) | |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
938 && !s->fixed_qscale; |
| 697 | 939 |
| 1708 | 940 s->obmc= !!(s->flags & CODEC_FLAG_OBMC); |
| 941 s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER); | |
| 942 s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN); | |
| 1633 | 943 |
| 1711 | 944 if(avctx->rc_max_rate && !avctx->rc_buffer_size){ |
| 945 av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n"); | |
| 946 return -1; | |
| 947 } | |
| 948 | |
| 949 if(avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate){ | |
| 950 av_log(avctx, AV_LOG_INFO, "Warning min_rate > 0 but min_rate != max_rate isnt recommanded!\n"); | |
| 1907 | 951 } |
| 952 | |
| 2063 | 953 if(avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate){ |
| 954 av_log(avctx, AV_LOG_INFO, "bitrate below min bitrate\n"); | |
| 955 return -1; | |
| 956 } | |
| 957 | |
| 958 if(avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate){ | |
| 959 av_log(avctx, AV_LOG_INFO, "bitrate above max bitrate\n"); | |
| 960 return -1; | |
| 961 } | |
| 962 | |
| 1907 | 963 if( s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate |
| 964 && (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO) | |
| 965 && 90000LL * (avctx->rc_buffer_size-1) > s->avctx->rc_max_rate*0xFFFFLL){ | |
| 1711 | 966 |
| 1907 | 967 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"); |
| 968 } | |
| 969 | |
| 1633 | 970 if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4 |
| 1790 | 971 && 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
|
972 av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n"); |
| 1188 | 973 return -1; |
| 974 } | |
| 1711 | 975 |
| 1633 | 976 if(s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE){ |
| 977 av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with simple mb decission\n"); | |
| 978 return -1; | |
| 979 } | |
| 980 | |
| 1644 | 981 if(s->obmc && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){ |
| 982 av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n"); | |
| 983 return -1; | |
| 984 } | |
| 985 | |
| 1188 | 986 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
|
987 av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n"); |
| 1188 | 988 return -1; |
| 989 } | |
| 990 | |
| 991 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
|
992 av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n"); |
| 1188 | 993 return -1; |
| 994 } | |
| 995 | |
| 1421 | 996 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
|
997 av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n"); |
| 1188 | 998 return -1; |
| 999 } | |
| 1958 | 1000 |
| 1001 if((s->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN)) | |
| 1002 && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO){ | |
| 1003 av_log(avctx, AV_LOG_ERROR, "interlacing not supported by codec\n"); | |
| 1004 return -1; | |
| 1005 } | |
| 1006 | |
| 1188 | 1007 if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1008 av_log(avctx, AV_LOG_ERROR, "mpeg2 style quantization not supporetd by codec\n"); |
| 1188 | 1009 return -1; |
| 1010 } | |
|
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
|
1011 |
|
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
1012 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
|
1013 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
|
1014 return -1; |
|
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
1015 } |
|
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
1016 |
| 1622 | 1017 if((s->flags & CODEC_FLAG_QP_RD) && s->avctx->mb_decision != FF_MB_DECISION_RD){ |
| 1018 av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n"); | |
| 1019 return -1; | |
| 1020 } | |
| 1021 | |
|
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
1022 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
|
1023 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
|
1024 return -1; |
|
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
1025 } |
| 1799 | 1026 |
| 1027 if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4 | |
| 1028 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO | |
| 1029 && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){ | |
| 1030 av_log(avctx, AV_LOG_ERROR, "multi threaded encoding not supported by codec\n"); | |
| 1031 return -1; | |
| 1032 } | |
| 1033 | |
| 1034 if(s->avctx->thread_count > 1) | |
| 1035 s->rtp_mode= 1; | |
| 1760 | 1036 |
| 1037 i= ff_gcd(avctx->frame_rate, avctx->frame_rate_base); | |
| 1038 if(i > 1){ | |
| 1039 av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n"); | |
| 1040 avctx->frame_rate /= i; | |
| 1041 avctx->frame_rate_base /= i; | |
| 1042 // return -1; | |
| 1043 } | |
|
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
1044 |
| 1150 | 1045 if(s->codec_id==CODEC_ID_MJPEG){ |
| 1046 s->intra_quant_bias= 1<<(QUANT_BIAS_SHIFT-1); //(a + x/2)/x | |
| 1047 s->inter_quant_bias= 0; | |
| 1421 | 1048 }else if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO){ |
| 1150 | 1049 s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x |
| 1050 s->inter_quant_bias= 0; | |
| 1051 }else{ | |
| 1052 s->intra_quant_bias=0; | |
| 1053 s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x | |
| 1054 } | |
| 1055 | |
| 1056 if(avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS) | |
| 1057 s->intra_quant_bias= avctx->intra_quant_bias; | |
| 1058 if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS) | |
| 1059 s->inter_quant_bias= avctx->inter_quant_bias; | |
|
1315
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
1060 |
|
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
1061 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
|
1062 |
| 1424 | 1063 av_reduce(&s->time_increment_resolution, &dummy, s->avctx->frame_rate, s->avctx->frame_rate_base, (1<<16)-1); |
| 1064 s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1; | |
| 1065 | |
| 0 | 1066 switch(avctx->codec->id) { |
| 1067 case CODEC_ID_MPEG1VIDEO: | |
| 1068 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
|
1069 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
|
1070 avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); |
| 0 | 1071 break; |
| 1421 | 1072 case CODEC_ID_MPEG2VIDEO: |
| 1073 s->out_format = FMT_MPEG1; | |
| 1074 s->low_delay= 0; //s->max_b_frames ? 0 : 1; | |
| 1075 avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); | |
| 1661 | 1076 s->rtp_mode= 1; |
| 1421 | 1077 break; |
|
1315
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
1078 case CODEC_ID_LJPEG: |
| 0 | 1079 case CODEC_ID_MJPEG: |
| 1080 s->out_format = FMT_MJPEG; | |
| 1081 s->intra_only = 1; /* force intra only for jpeg */ | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1082 s->mjpeg_write_tables = 1; /* write all tables */ |
|
370
0eca28d16cbd
clamp intra matrix to 8bit for mjpeg (workaround for qscale>=25)
al3x
parents:
365
diff
changeset
|
1083 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
|
1084 s->mjpeg_vsample[0] = 1<<chroma_v_shift; |
|
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
1085 s->mjpeg_vsample[1] = 1; |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1086 s->mjpeg_vsample[2] = 1; |
|
1315
6696d3bf4ff2
lossless mjpeg encoding (planar yuv & RGB) and somerelated bugfixes
michaelni
parents:
1288
diff
changeset
|
1087 s->mjpeg_hsample[0] = 1<<chroma_h_shift; |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1088 s->mjpeg_hsample[1] = 1; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1089 s->mjpeg_hsample[2] = 1; |
| 0 | 1090 if (mjpeg_init(s) < 0) |
| 1091 return -1; | |
| 336 | 1092 avctx->delay=0; |
| 924 | 1093 s->low_delay=1; |
| 0 | 1094 break; |
| 1042 | 1095 #ifdef CONFIG_RISKY |
|
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
1096 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
|
1097 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
|
1098 avctx->delay=0; |
|
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
1099 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
|
1100 break; |
| 0 | 1101 case CODEC_ID_H263: |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1102 if (h263_get_picture_format(s->width, s->height) == 7) { |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1103 av_log(avctx, AV_LOG_INFO, "Input picture size isn't suitable for h263 codec! try h263+\n"); |
| 0 | 1104 return -1; |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1105 } |
| 0 | 1106 s->out_format = FMT_H263; |
| 1644 | 1107 s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0; |
| 336 | 1108 avctx->delay=0; |
| 924 | 1109 s->low_delay=1; |
| 0 | 1110 break; |
| 1111 case CODEC_ID_H263P: | |
| 1112 s->out_format = FMT_H263; | |
| 1113 s->h263_plus = 1; | |
|
1095
c7604e6291c5
extended option for h263+ patch by (fixounet at free dot fr) with some minor modifications
michaelni
parents:
1094
diff
changeset
|
1114 /* Fx */ |
| 1644 | 1115 s->umvplus = (avctx->flags & CODEC_FLAG_H263P_UMV) ? 1:0; |
|
1095
c7604e6291c5
extended option for h263+ patch by (fixounet at free dot fr) with some minor modifications
michaelni
parents:
1094
diff
changeset
|
1116 s->h263_aic= (avctx->flags & CODEC_FLAG_H263P_AIC) ? 1:0; |
| 1644 | 1117 s->modified_quant= s->h263_aic; |
| 1637 | 1118 s->alt_inter_vlc= (avctx->flags & CODEC_FLAG_H263P_AIV) ? 1:0; |
| 1644 | 1119 s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0; |
| 1120 s->loop_filter= (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1:0; | |
| 1121 s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus; | |
| 1661 | 1122 s->h263_slice_structured= (s->flags & CODEC_FLAG_H263P_SLICE_STRUCT) ? 1:0; |
| 1644 | 1123 |
|
1095
c7604e6291c5
extended option for h263+ patch by (fixounet at free dot fr) with some minor modifications
michaelni
parents:
1094
diff
changeset
|
1124 /* /Fx */ |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
1125 /* These are just to be sure */ |
| 336 | 1126 avctx->delay=0; |
| 924 | 1127 s->low_delay=1; |
| 0 | 1128 break; |
|
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1129 case CODEC_ID_FLV1: |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1130 s->out_format = FMT_H263; |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1131 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
|
1132 s->unrestricted_mv = 1; |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1133 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
|
1134 avctx->delay=0; |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1135 s->low_delay=1; |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
1136 break; |
| 0 | 1137 case CODEC_ID_RV10: |
| 1138 s->out_format = FMT_H263; | |
| 336 | 1139 avctx->delay=0; |
| 924 | 1140 s->low_delay=1; |
| 0 | 1141 break; |
| 2380 | 1142 case CODEC_ID_RV20: |
| 1143 s->out_format = FMT_H263; | |
| 1144 avctx->delay=0; | |
| 1145 s->low_delay=1; | |
| 1146 s->modified_quant=1; | |
| 1147 s->h263_aic=1; | |
| 1148 s->h263_plus=1; | |
| 1149 s->loop_filter=1; | |
| 1150 s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus; | |
| 1151 break; | |
| 71 | 1152 case CODEC_ID_MPEG4: |
| 0 | 1153 s->out_format = FMT_H263; |
| 1154 s->h263_pred = 1; | |
| 1155 s->unrestricted_mv = 1; | |
| 924 | 1156 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
|
1157 avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); |
| 0 | 1158 break; |
| 307 | 1159 case CODEC_ID_MSMPEG4V1: |
| 0 | 1160 s->out_format = FMT_H263; |
| 1161 s->h263_msmpeg4 = 1; | |
| 1162 s->h263_pred = 1; | |
| 1163 s->unrestricted_mv = 1; | |
| 307 | 1164 s->msmpeg4_version= 1; |
| 336 | 1165 avctx->delay=0; |
| 924 | 1166 s->low_delay=1; |
| 307 | 1167 break; |
| 1168 case CODEC_ID_MSMPEG4V2: | |
| 1169 s->out_format = FMT_H263; | |
| 1170 s->h263_msmpeg4 = 1; | |
| 1171 s->h263_pred = 1; | |
| 1172 s->unrestricted_mv = 1; | |
| 1173 s->msmpeg4_version= 2; | |
| 336 | 1174 avctx->delay=0; |
| 924 | 1175 s->low_delay=1; |
| 307 | 1176 break; |
| 1177 case CODEC_ID_MSMPEG4V3: | |
| 1178 s->out_format = FMT_H263; | |
| 1179 s->h263_msmpeg4 = 1; | |
| 1180 s->h263_pred = 1; | |
| 1181 s->unrestricted_mv = 1; | |
| 1182 s->msmpeg4_version= 3; | |
| 1163 | 1183 s->flipflop_rounding=1; |
| 336 | 1184 avctx->delay=0; |
| 924 | 1185 s->low_delay=1; |
| 0 | 1186 break; |
| 499 | 1187 case CODEC_ID_WMV1: |
| 1188 s->out_format = FMT_H263; | |
| 1189 s->h263_msmpeg4 = 1; | |
| 1190 s->h263_pred = 1; | |
| 1191 s->unrestricted_mv = 1; | |
| 1192 s->msmpeg4_version= 4; | |
| 1163 | 1193 s->flipflop_rounding=1; |
| 499 | 1194 avctx->delay=0; |
| 924 | 1195 s->low_delay=1; |
| 499 | 1196 break; |
| 1197 case CODEC_ID_WMV2: | |
| 1198 s->out_format = FMT_H263; | |
| 1199 s->h263_msmpeg4 = 1; | |
| 1200 s->h263_pred = 1; | |
| 1201 s->unrestricted_mv = 1; | |
| 1202 s->msmpeg4_version= 5; | |
| 1163 | 1203 s->flipflop_rounding=1; |
| 499 | 1204 avctx->delay=0; |
| 924 | 1205 s->low_delay=1; |
| 499 | 1206 break; |
| 1042 | 1207 #endif |
| 0 | 1208 default: |
| 1209 return -1; | |
| 1210 } | |
| 2042 | 1211 |
| 1212 avctx->has_b_frames= !s->low_delay; | |
|
1749
7b11032507e2
removing broken framerate conversation hack in mpeg1/2
michael
parents:
1742
diff
changeset
|
1213 |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1214 s->encoding = 1; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1215 |
| 0 | 1216 /* init */ |
| 1217 if (MPV_common_init(s) < 0) | |
| 1218 return -1; | |
| 1678 | 1219 |
| 1220 if(s->modified_quant) | |
| 1221 s->chroma_qscale_table= ff_h263_chroma_qscale_table; | |
| 1222 s->progressive_frame= | |
| 1708 | 1223 s->progressive_sequence= !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)); |
| 1799 | 1224 s->quant_precision=5; |
| 0 | 1225 |
| 1729 | 1226 ff_set_cmp(&s->dsp, s->dsp.ildct_cmp, s->avctx->ildct_cmp); |
| 2382 | 1227 ff_set_cmp(&s->dsp, s->dsp.frame_skip_cmp, s->avctx->frame_skip_cmp); |
| 1729 | 1228 |
|
815
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
814
diff
changeset
|
1229 #ifdef CONFIG_ENCODERS |
| 1042 | 1230 #ifdef CONFIG_RISKY |
|
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
1231 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
|
1232 ff_h261_encode_init(s); |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1233 if (s->out_format == FMT_H263) |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1234 h263_encode_init(s); |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1235 if(s->msmpeg4_version) |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1236 ff_msmpeg4_encode_init(s); |
|
815
78accc54493b
put a few large tables under #ifdef CONFIG_ENCODERS or dynamically allocate them
michaelni
parents:
814
diff
changeset
|
1237 #endif |
| 1042 | 1238 if (s->out_format == FMT_MPEG1) |
| 1239 ff_mpeg1_encode_init(s); | |
| 1240 #endif | |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1241 |
| 1892 | 1242 /* init q matrix */ |
| 60 | 1243 for(i=0;i<64;i++) { |
| 1092 | 1244 int j= s->dsp.idct_permutation[i]; |
| 1042 | 1245 #ifdef CONFIG_RISKY |
| 599 | 1246 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
|
1247 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
|
1248 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
|
1249 }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
|
1250 s->intra_matrix[j] = |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1251 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; |
| 1042 | 1252 }else |
| 1253 #endif | |
| 1421 | 1254 { /* mpeg1/2 */ |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1255 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
|
1256 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; |
| 599 | 1257 } |
| 1411 | 1258 if(s->avctx->intra_matrix) |
| 1259 s->intra_matrix[j] = s->avctx->intra_matrix[i]; | |
| 1260 if(s->avctx->inter_matrix) | |
| 1261 s->inter_matrix[j] = s->avctx->inter_matrix[i]; | |
| 344 | 1262 } |
| 1263 | |
| 1264 /* precompute matrix */ | |
|
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
1265 /* for mjpeg, we do include qscale in the matrix */ |
| 344 | 1266 if (s->out_format != FMT_MJPEG) { |
|
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
1267 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
|
1268 s->intra_matrix, s->intra_quant_bias, avctx->qmin, 31, 1); |
|
1579
039cb2296de2
make convert_matrix() independant of MpegEncContext
michael
parents:
1573
diff
changeset
|
1269 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
|
1270 s->inter_matrix, s->inter_quant_bias, avctx->qmin, 31, 0); |
| 60 | 1271 } |
| 1272 | |
| 329 | 1273 if(ff_rate_control_init(s) < 0) |
| 1274 return -1; | |
| 1892 | 1275 |
| 0 | 1276 return 0; |
| 1277 } | |
| 1278 | |
| 1279 int MPV_encode_end(AVCodecContext *avctx) | |
| 1280 { | |
| 1281 MpegEncContext *s = avctx->priv_data; | |
| 1282 | |
| 1283 #ifdef STATS | |
| 1284 print_stats(); | |
| 1285 #endif | |
| 329 | 1286 |
| 1287 ff_rate_control_uninit(s); | |
| 1288 | |
| 0 | 1289 MPV_common_end(s); |
| 1290 if (s->out_format == FMT_MJPEG) | |
| 1291 mjpeg_close(s); | |
|
1458
40b69d238beb
AVI stream header FCC / more reliable detection of old xvid files
michaelni
parents:
1451
diff
changeset
|
1292 |
| 1424 | 1293 av_freep(&avctx->extradata); |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1294 |
| 0 | 1295 return 0; |
| 1296 } | |
| 1297 | |
|
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
|
1298 #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
|
1299 |
|
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1300 void init_rl(RLTable *rl, int use_static) |
| 1042 | 1301 { |
| 1064 | 1302 int8_t max_level[MAX_RUN+1], max_run[MAX_LEVEL+1]; |
| 1303 uint8_t index_run[MAX_RUN+1]; | |
| 1042 | 1304 int last, run, level, start, end, i; |
| 1305 | |
|
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1306 /* 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
|
1307 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
|
1308 return; |
|
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1309 |
| 1042 | 1310 /* compute max_level[], max_run[] and index_run[] */ |
| 1311 for(last=0;last<2;last++) { | |
| 1312 if (last == 0) { | |
| 1313 start = 0; | |
| 1314 end = rl->last; | |
| 1315 } else { | |
| 1316 start = rl->last; | |
| 1317 end = rl->n; | |
| 1318 } | |
| 1319 | |
| 1320 memset(max_level, 0, MAX_RUN + 1); | |
| 1321 memset(max_run, 0, MAX_LEVEL + 1); | |
| 1322 memset(index_run, rl->n, MAX_RUN + 1); | |
| 1323 for(i=start;i<end;i++) { | |
| 1324 run = rl->table_run[i]; | |
| 1325 level = rl->table_level[i]; | |
| 1326 if (index_run[run] == rl->n) | |
| 1327 index_run[run] = i; | |
| 1328 if (level > max_level[run]) | |
| 1329 max_level[run] = level; | |
| 1330 if (run > max_run[level]) | |
| 1331 max_run[level] = run; | |
| 1332 } | |
|
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1333 if(use_static) |
|
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1334 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
|
1335 else |
|
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1336 rl->max_level[last] = av_malloc(MAX_RUN + 1); |
| 1042 | 1337 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
|
1338 if(use_static) |
|
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1339 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
|
1340 else |
|
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1341 rl->max_run[last] = av_malloc(MAX_LEVEL + 1); |
| 1042 | 1342 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
|
1343 if(use_static) |
|
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1344 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
|
1345 else |
|
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2364
diff
changeset
|
1346 rl->index_run[last] = av_malloc(MAX_RUN + 1); |
| 1042 | 1347 memcpy(rl->index_run[last], index_run, MAX_RUN + 1); |
| 1348 } | |
| 1349 } | |
| 1350 | |
| 0 | 1351 /* 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
|
1352 //FIXME check that this is ok for mpeg4 interlaced |
| 1064 | 1353 static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w) |
| 0 | 1354 { |
| 1064 | 1355 uint8_t *ptr, *last_line; |
| 0 | 1356 int i; |
| 1357 | |
| 1358 last_line = buf + (height - 1) * wrap; | |
| 1359 for(i=0;i<w;i++) { | |
| 1360 /* top and bottom */ | |
| 1361 memcpy(buf - (i + 1) * wrap, buf, width); | |
| 1362 memcpy(last_line + (i + 1) * wrap, last_line, width); | |
| 1363 } | |
| 1364 /* left and right */ | |
| 1365 ptr = buf; | |
| 1366 for(i=0;i<height;i++) { | |
| 1367 memset(ptr - w, ptr[0], w); | |
| 1368 memset(ptr + width, ptr[width-1], w); | |
| 1369 ptr += wrap; | |
| 1370 } | |
| 1371 /* corners */ | |
| 1372 for(i=0;i<w;i++) { | |
| 1373 memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */ | |
| 1374 memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */ | |
| 1375 memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */ | |
| 1376 memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */ | |
| 1377 } | |
| 1378 } | |
| 1379 | |
| 1586 | 1380 int ff_find_unused_picture(MpegEncContext *s, int shared){ |
| 924 | 1381 int i; |
| 1382 | |
| 1383 if(shared){ | |
| 1384 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
| 1586 | 1385 if(s->picture[i].data[0]==NULL && s->picture[i].type==0) return i; |
| 924 | 1386 } |
| 1387 }else{ | |
| 1388 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
| 1586 | 1389 if(s->picture[i].data[0]==NULL && s->picture[i].type!=0) return i; //FIXME |
| 924 | 1390 } |
| 1391 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
| 1586 | 1392 if(s->picture[i].data[0]==NULL) return i; |
| 924 | 1393 } |
| 1394 } | |
| 1395 | |
| 1586 | 1396 assert(0); |
| 1397 return -1; | |
| 924 | 1398 } |
| 1399 | |
| 1597 | 1400 static void update_noise_reduction(MpegEncContext *s){ |
| 1401 int intra, i; | |
| 1402 | |
| 1403 for(intra=0; intra<2; intra++){ | |
| 1404 if(s->dct_count[intra] > (1<<16)){ | |
| 1405 for(i=0; i<64; i++){ | |
| 1406 s->dct_error_sum[intra][i] >>=1; | |
| 1407 } | |
| 1408 s->dct_count[intra] >>= 1; | |
| 1409 } | |
| 1410 | |
| 1411 for(i=0; i<64; i++){ | |
| 1412 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); | |
| 1413 } | |
| 1414 } | |
| 1415 } | |
| 1416 | |
| 1586 | 1417 /** |
| 1418 * generic function for encode/decode called after coding/decoding the header and before a frame is coded/decoded | |
| 1419 */ | |
|
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
1420 int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) |
| 0 | 1421 { |
| 924 | 1422 int i; |
| 925 | 1423 AVFrame *pic; |
|
46
931417475f5b
fixed mpeg1 first block bug (pb with black picture optimisation for B frames)
glantau
parents:
40
diff
changeset
|
1424 s->mb_skiped = 0; |
| 1168 | 1425 |
| 1234 | 1426 assert(s->last_picture_ptr==NULL || s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3); |
| 1228 | 1427 |
| 903 | 1428 /* mark&release old frames */ |
| 1944 | 1429 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 | 1430 avctx->release_buffer(avctx, (AVFrame*)s->last_picture_ptr); |
| 903 | 1431 |
| 1432 /* release forgotten pictures */ | |
| 1433 /* if(mpeg124/h263) */ | |
| 1434 if(!s->encoding){ | |
| 1435 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
| 1138 | 1436 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
|
1437 av_log(avctx, AV_LOG_ERROR, "releasing zombie picture\n"); |
| 925 | 1438 avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]); |
| 903 | 1439 } |
| 1440 } | |
| 1441 } | |
| 1442 } | |
|
910
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
1443 alloc: |
|
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
1444 if(!s->encoding){ |
| 1228 | 1445 /* release non refernce frames */ |
| 1446 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
| 1447 if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){ | |
| 1448 s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]); | |
| 1449 } | |
| 1450 } | |
| 1451 | |
| 1586 | 1452 if(s->current_picture_ptr && s->current_picture_ptr->data[0]==NULL) |
| 1453 pic= (AVFrame*)s->current_picture_ptr; //we allready have a unused image (maybe it was set before reading the header) | |
| 1454 else{ | |
| 1455 i= ff_find_unused_picture(s, 0); | |
| 1456 pic= (AVFrame*)&s->picture[i]; | |
| 1457 } | |
| 1458 | |
| 1944 | 1459 pic->reference= s->pict_type != B_TYPE && !s->dropable ? 3 : 0; |
| 1138 | 1460 |
| 1705 | 1461 pic->coded_picture_number= s->coded_picture_number++; |
| 903 | 1462 |
| 1384 | 1463 if( alloc_picture(s, (Picture*)pic, 0) < 0) |
| 1464 return -1; | |
| 903 | 1465 |
| 1586 | 1466 s->current_picture_ptr= (Picture*)pic; |
| 1658 | 1467 s->current_picture_ptr->top_field_first= s->top_field_first; //FIXME use only the vars from current_pic |
| 1659 | 1468 s->current_picture_ptr->interlaced_frame= !s->progressive_frame && !s->progressive_sequence; |
| 903 | 1469 } |
| 456 | 1470 |
| 1173 | 1471 s->current_picture_ptr->pict_type= s->pict_type; |
|
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
|
1472 // if(s->flags && CODEC_FLAG_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
|
1473 // 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
|
1474 s->current_picture_ptr->key_frame= s->pict_type == I_TYPE; |
| 1173 | 1475 |
|
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
|
1476 copy_picture(&s->current_picture, s->current_picture_ptr); |
| 1173 | 1477 |
| 1234 | 1478 if(s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3){ |
| 903 | 1479 if (s->pict_type != B_TYPE) { |
| 1138 | 1480 s->last_picture_ptr= s->next_picture_ptr; |
| 1944 | 1481 if(!s->dropable) |
| 1482 s->next_picture_ptr= s->current_picture_ptr; | |
| 1483 } | |
| 1484 /* 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, | |
| 1485 s->last_picture_ptr ? s->last_picture_ptr->data[0] : NULL, | |
| 1486 s->next_picture_ptr ? s->next_picture_ptr->data[0] : NULL, | |
| 1487 s->current_picture_ptr ? s->current_picture_ptr->data[0] : NULL, | |
| 1488 s->pict_type, s->dropable);*/ | |
| 1214 | 1489 |
|
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
|
1490 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
|
1491 if(s->next_picture_ptr) copy_picture(&s->next_picture, s->next_picture_ptr); |
| 1138 | 1492 |
|
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
|
1493 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
|
1494 av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n"); |
| 1393 | 1495 assert(s->pict_type != B_TYPE); //these should have been dropped if we dont have a reference |
| 1496 goto alloc; | |
| 1497 } | |
| 1498 | |
| 1499 assert(s->pict_type == I_TYPE || (s->last_picture_ptr && s->last_picture_ptr->data[0])); | |
| 1500 | |
| 1138 | 1501 if(s->picture_structure!=PICT_FRAME){ |
| 1502 int i; | |
| 1503 for(i=0; i<4; i++){ | |
| 1504 if(s->picture_structure == PICT_BOTTOM_FIELD){ | |
| 1505 s->current_picture.data[i] += s->current_picture.linesize[i]; | |
| 1506 } | |
| 1507 s->current_picture.linesize[i] *= 2; | |
| 1508 s->last_picture.linesize[i] *=2; | |
| 1509 s->next_picture.linesize[i] *=2; | |
| 1510 } | |
| 553 | 1511 } |
| 1168 | 1512 } |
| 903 | 1513 |
|
910
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
1514 s->hurry_up= s->avctx->hurry_up; |
|
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
1515 s->error_resilience= avctx->error_resilience; |
|
eb448df811be
fixing files where the first frame isn a keyframe
michaelni
parents:
909
diff
changeset
|
1516 |
| 591 | 1517 /* set dequantizer, we cant do it during init as it might change for mpeg4 |
| 1518 and we cant do it in the header decode as init isnt called for mpeg4 there yet */ | |
| 1689 | 1519 if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO){ |
| 1520 s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra; | |
| 1521 s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter; | |
| 2345 | 1522 }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){ |
| 1689 | 1523 s->dct_unquantize_intra = s->dct_unquantize_h263_intra; |
| 1524 s->dct_unquantize_inter = s->dct_unquantize_h263_inter; | |
| 1525 }else{ | |
| 1526 s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra; | |
| 1527 s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter; | |
| 1528 } | |
|
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
1529 |
| 1597 | 1530 if(s->dct_error_sum){ |
| 1531 assert(s->avctx->noise_reduction && s->encoding); | |
| 1532 | |
| 1533 update_noise_reduction(s); | |
| 1534 } | |
| 1535 | |
| 1381 | 1536 #ifdef HAVE_XVMC |
| 1537 if(s->avctx->xvmc_acceleration) | |
| 1538 return XVMC_field_start(s, avctx); | |
| 1539 #endif | |
|
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
1540 return 0; |
| 0 | 1541 } |
|
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
|
1542 |
| 0 | 1543 /* generic function for encode/decode called after a frame has been coded/decoded */ |
| 1544 void MPV_frame_end(MpegEncContext *s) | |
| 1545 { | |
| 903 | 1546 int i; |
| 0 | 1547 /* draw edge for correct motion prediction if outside */ |
| 1381 | 1548 #ifdef HAVE_XVMC |
| 1549 //just to make sure that all data is rendered. | |
| 1550 if(s->avctx->xvmc_acceleration){ | |
| 1551 XVMC_field_end(s); | |
| 1552 }else | |
| 1553 #endif | |
|
1542
576861d6343a
emu_edge checks simplification and avoid redundant checks for mpeg1/2 if emu_edge is set
michael
parents:
1539
diff
changeset
|
1554 if(s->unrestricted_mv && s->pict_type != B_TYPE && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) { |
| 903 | 1555 draw_edges(s->current_picture.data[0], s->linesize , s->h_edge_pos , s->v_edge_pos , EDGE_WIDTH ); |
| 1556 draw_edges(s->current_picture.data[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); | |
| 1557 draw_edges(s->current_picture.data[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); | |
| 0 | 1558 } |
| 207 | 1559 emms_c(); |
| 329 | 1560 |
| 612 | 1561 s->last_pict_type = s->pict_type; |
| 329 | 1562 if(s->pict_type!=B_TYPE){ |
| 1563 s->last_non_b_pict_type= s->pict_type; | |
| 1564 } | |
| 1138 | 1565 #if 0 |
| 1566 /* copy back current_picture variables */ | |
| 903 | 1567 for(i=0; i<MAX_PICTURE_COUNT; i++){ |
| 1568 if(s->picture[i].data[0] == s->current_picture.data[0]){ | |
| 1569 s->picture[i]= s->current_picture; | |
| 1570 break; | |
| 1571 } | |
| 1572 } | |
| 1573 assert(i<MAX_PICTURE_COUNT); | |
| 1138 | 1574 #endif |
| 903 | 1575 |
| 1228 | 1576 if(s->encoding){ |
| 1577 /* release non refernce frames */ | |
| 1578 for(i=0; i<MAX_PICTURE_COUNT; i++){ | |
| 1579 if(s->picture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){ | |
| 1580 s->avctx->release_buffer(s->avctx, (AVFrame*)&s->picture[i]); | |
| 1581 } | |
| 1582 } | |
| 324 | 1583 } |
| 1138 | 1584 // clear copies, to avoid confusion |
| 1585 #if 0 | |
| 1586 memset(&s->last_picture, 0, sizeof(Picture)); | |
| 1587 memset(&s->next_picture, 0, sizeof(Picture)); | |
| 1588 memset(&s->current_picture, 0, sizeof(Picture)); | |
| 1589 #endif | |
| 2213 | 1590 s->avctx->coded_frame= (AVFrame*)s->current_picture_ptr; |
| 903 | 1591 } |
| 1592 | |
|
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
|
1593 /** |
| 1285 | 1594 * draws an line from (ex, ey) -> (sx, sy). |
| 1595 * @param w width of the image | |
| 1596 * @param h height of the image | |
| 1597 * @param stride stride/linesize of the image | |
| 1598 * @param color color of the arrow | |
| 1599 */ | |
| 1600 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
|
1601 int t, x, y, fr, f; |
| 1285 | 1602 |
| 1603 sx= clip(sx, 0, w-1); | |
| 1604 sy= clip(sy, 0, h-1); | |
| 1605 ex= clip(ex, 0, w-1); | |
| 1606 ey= clip(ey, 0, h-1); | |
| 1607 | |
| 1608 buf[sy*stride + sx]+= color; | |
| 1609 | |
| 1610 if(ABS(ex - sx) > ABS(ey - sy)){ | |
| 1611 if(sx > ex){ | |
| 1612 t=sx; sx=ex; ex=t; | |
| 1613 t=sy; sy=ey; ey=t; | |
| 1614 } | |
| 1615 buf+= sx + sy*stride; | |
| 1616 ex-= sx; | |
| 1617 f= ((ey-sy)<<16)/ex; | |
| 1618 for(x= 0; x <= ex; x++){ | |
|
1918
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1619 y = (x*f)>>16; |
|
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1620 fr= (x*f)&0xFFFF; |
|
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1621 buf[ y *stride + x]+= (color*(0x10000-fr))>>16; |
|
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1622 buf[(y+1)*stride + x]+= (color* fr )>>16; |
| 1285 | 1623 } |
| 1624 }else{ | |
| 1625 if(sy > ey){ | |
| 1626 t=sx; sx=ex; ex=t; | |
| 1627 t=sy; sy=ey; ey=t; | |
| 1628 } | |
| 1629 buf+= sx + sy*stride; | |
| 1630 ey-= sy; | |
| 1631 if(ey) f= ((ex-sx)<<16)/ey; | |
| 1632 else f= 0; | |
| 1633 for(y= 0; y <= ey; y++){ | |
|
1918
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1634 x = (y*f)>>16; |
|
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1635 fr= (y*f)&0xFFFF; |
|
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1636 buf[y*stride + x ]+= (color*(0x10000-fr))>>16;; |
|
ea20f38b8d57
nicer looking arrows for the motion vector vissualization
michael
parents:
1916
diff
changeset
|
1637 buf[y*stride + x+1]+= (color* fr )>>16;; |
| 1285 | 1638 } |
| 1639 } | |
| 1640 } | |
| 1641 | |
| 1642 /** | |
| 1643 * draws an arrow from (ex, ey) -> (sx, sy). | |
| 1644 * @param w width of the image | |
| 1645 * @param h height of the image | |
| 1646 * @param stride stride/linesize of the image | |
| 1647 * @param color color of the arrow | |
| 1648 */ | |
| 1649 static void draw_arrow(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){ | |
| 1650 int dx,dy; | |
| 1651 | |
| 1652 sx= clip(sx, -100, w+100); | |
| 1653 sy= clip(sy, -100, h+100); | |
| 1654 ex= clip(ex, -100, w+100); | |
| 1655 ey= clip(ey, -100, h+100); | |
| 1656 | |
| 1657 dx= ex - sx; | |
| 1658 dy= ey - sy; | |
| 1659 | |
| 1660 if(dx*dx + dy*dy > 3*3){ | |
| 1661 int rx= dx + dy; | |
| 1662 int ry= -dx + dy; | |
| 1663 int length= ff_sqrt((rx*rx + ry*ry)<<8); | |
| 1664 | |
| 1665 //FIXME subpixel accuracy | |
| 1666 rx= ROUNDED_DIV(rx*3<<4, length); | |
| 1667 ry= ROUNDED_DIV(ry*3<<4, length); | |
| 1668 | |
| 1669 draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color); | |
| 1670 draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color); | |
| 1671 } | |
| 1672 draw_line(buf, sx, sy, ex, ey, w, h, stride, color); | |
| 1673 } | |
| 1674 | |
| 1675 /** | |
|
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
|
1676 * 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
|
1677 */ |
|
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1678 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
|
1679 |
|
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
|
1680 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
|
1681 |
|
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
|
1682 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
|
1683 int x,y; |
|
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1684 |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1685 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
|
1686 switch (pict->pict_type) { |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1687 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
|
1688 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
|
1689 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
|
1690 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
|
1691 case FF_SI_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SI\n"); break; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1692 case FF_SP_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SP\n"); break; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1693 } |
|
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
|
1694 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
|
1695 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
|
1696 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
|
1697 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
|
1698 if(count>9) count=9; |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1699 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
|
1700 } |
|
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
|
1701 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
|
1702 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
|
1703 } |
|
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
|
1704 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
|
1705 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
|
1706 //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
|
1707 if(IS_PCM(mb_type)) |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1708 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
|
1709 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
|
1710 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
|
1711 else if(IS_INTRA4x4(mb_type)) |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1712 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
|
1713 else if(IS_INTRA16x16(mb_type)) |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1714 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
|
1715 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
|
1716 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
|
1717 else if(IS_DIRECT(mb_type)) |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1718 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
|
1719 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
|
1720 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
|
1721 else if(IS_GMC(mb_type)) |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1722 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
|
1723 else if(IS_SKIP(mb_type)) |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1724 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
|
1725 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
|
1726 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
|
1727 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
|
1728 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
|
1729 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
|
1730 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
|
1731 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
|
1732 } |
|
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
|
1733 |
|
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
|
1734 //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
|
1735 if(IS_8X8(mb_type)) |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1736 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
|
1737 else if(IS_16X8(mb_type)) |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1738 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
|
1739 else if(IS_8X16(mb_type)) |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1740 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
|
1741 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
|
1742 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
|
1743 else |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1744 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
|
1745 |
|
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
|
1746 |
|
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 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
|
1748 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
|
1749 else |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1750 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
|
1751 } |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1752 // 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
|
1753 } |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1754 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
|
1755 } |
|
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
|
1756 } |
|
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
1757 |
|
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1758 if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ |
| 1285 | 1759 const int shift= 1 + s->quarter_sample; |
| 1760 int mb_y; | |
|
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1761 uint8_t *ptr; |
| 1707 | 1762 int i; |
|
1723
033d889d7c2c
non YV12 vissualization fix by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1722
diff
changeset
|
1763 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
|
1764 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
|
1765 const int height= s->avctx->height; |
| 2395 | 1766 const int mv_sample_log2= 4 - pict->motion_subsample_log2; |
| 1767 const int mv_stride= (s->mb_width << mv_sample_log2) + 1; | |
| 1285 | 1768 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
|
1769 |
|
1723
033d889d7c2c
non YV12 vissualization fix by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1722
diff
changeset
|
1770 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
|
1771 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
|
1772 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
|
1773 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
|
1774 } |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1775 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
|
1776 ptr= pict->data[0]; |
| 1285 | 1777 |
| 1778 for(mb_y=0; mb_y<s->mb_height; mb_y++){ | |
| 1779 int mb_x; | |
| 1780 for(mb_x=0; mb_x<s->mb_width; mb_x++){ | |
| 1781 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
|
1782 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
|
1783 int type; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1784 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
|
1785 int direction = 0; |
|
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1786 switch (type) { |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1787 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
|
1788 continue; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1789 direction = 0; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1790 break; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1791 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
|
1792 continue; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1793 direction = 0; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1794 break; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1795 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
|
1796 continue; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1797 direction = 1; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1798 break; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1799 } |
| 1712 | 1800 if(!USES_LIST(pict->mb_type[mb_index], direction)) |
| 1801 continue; | |
| 1802 | |
|
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1803 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
|
1804 int i; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1805 for(i=0; i<4; i++){ |
| 1285 | 1806 int sx= mb_x*16 + 4 + 8*(i&1); |
| 1807 int sy= mb_y*16 + 4 + 8*(i>>1); | |
| 2395 | 1808 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
|
1809 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
|
1810 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
|
1811 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
|
1812 } |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1813 }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
|
1814 int i; |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1815 for(i=0; i<2; i++){ |
|
1629
74685a0ec851
16x8 MV vissualization by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1628
diff
changeset
|
1816 int sx=mb_x*16 + 8; |
|
74685a0ec851
16x8 MV vissualization by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1628
diff
changeset
|
1817 int sy=mb_y*16 + 4 + 8*i; |
| 2395 | 1818 int xy= (mb_x*2 + (mb_y*2 + i)*mv_stride) << mv_sample_log2-1; |
| 1819 int mx=(pict->motion_val[direction][xy][0]>>shift); | |
| 1820 int my=(pict->motion_val[direction][xy][1]>>shift); | |
| 1821 | |
| 1822 if(IS_INTERLACED(pict->mb_type[mb_index])) | |
| 1823 my*=2; | |
| 1824 | |
| 1825 draw_arrow(ptr, sx, sy, mx+sx, my+sy, width, height, s->linesize, 100); | |
| 1826 } | |
| 1827 }else if(IS_8X16(pict->mb_type[mb_index])){ | |
| 1828 int i; | |
| 1829 for(i=0; i<2; i++){ | |
| 1830 int sx=mb_x*16 + 4 + 8*i; | |
| 1831 int sy=mb_y*16 + 8; | |
| 1832 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
|
1833 int mx=(pict->motion_val[direction][xy][0]>>shift); |
|
b306574523ad
fix y scale of mv vissualization of interlaced MVs
michael
parents:
1945
diff
changeset
|
1834 int my=(pict->motion_val[direction][xy][1]>>shift); |
|
b306574523ad
fix y scale of mv vissualization of interlaced MVs
michael
parents:
1945
diff
changeset
|
1835 |
|
b306574523ad
fix y scale of mv vissualization of interlaced MVs
michael
parents:
1945
diff
changeset
|
1836 if(IS_INTERLACED(pict->mb_type[mb_index])) |
|
b306574523ad
fix y scale of mv vissualization of interlaced MVs
michael
parents:
1945
diff
changeset
|
1837 my*=2; |
|
b306574523ad
fix y scale of mv vissualization of interlaced MVs
michael
parents:
1945
diff
changeset
|
1838 |
|
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
|
1839 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
|
1840 } |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1841 }else{ |
|
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1842 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
|
1843 int sy= mb_y*16 + 8; |
| 2395 | 1844 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
|
1845 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
|
1846 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
|
1847 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
|
1848 } |
|
1706
3ba5c493db6f
motion vector vissualization improvements patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1705
diff
changeset
|
1849 } |
| 1685 | 1850 } |
| 1851 if((s->avctx->debug&FF_DEBUG_VIS_QP) && pict->motion_val){ | |
| 1852 uint64_t c= (pict->qscale_table[mb_index]*128/31) * 0x0101010101010101ULL; | |
| 1853 int y; | |
| 1854 for(y=0; y<8; y++){ | |
| 1855 *(uint64_t*)(pict->data[1] + 8*mb_x + (8*mb_y + y)*pict->linesize[1])= c; | |
| 1856 *(uint64_t*)(pict->data[2] + 8*mb_x + (8*mb_y + y)*pict->linesize[2])= c; | |
| 1857 } | |
| 1858 } | |
| 1859 if((s->avctx->debug&FF_DEBUG_VIS_MB_TYPE) && pict->motion_val){ | |
| 1860 int mb_type= pict->mb_type[mb_index]; | |
| 1861 uint64_t u,v; | |
| 1862 int y; | |
| 1863 #define COLOR(theta, r)\ | |
| 1864 u= (int)(128 + r*cos(theta*3.141592/180));\ | |
| 1865 v= (int)(128 + r*sin(theta*3.141592/180)); | |
| 1866 | |
| 1867 | |
| 1868 u=v=128; | |
| 1869 if(IS_PCM(mb_type)){ | |
| 1870 COLOR(120,48) | |
| 1871 }else if((IS_INTRA(mb_type) && IS_ACPRED(mb_type)) || IS_INTRA16x16(mb_type)){ | |
| 1872 COLOR(30,48) | |
| 1873 }else if(IS_INTRA4x4(mb_type)){ | |
| 1874 COLOR(90,48) | |
| 1875 }else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type)){ | |
| 1876 // COLOR(120,48) | |
| 1877 }else if(IS_DIRECT(mb_type)){ | |
| 1878 COLOR(150,48) | |
| 1879 }else if(IS_GMC(mb_type) && IS_SKIP(mb_type)){ | |
| 1880 COLOR(170,48) | |
| 1881 }else if(IS_GMC(mb_type)){ | |
| 1882 COLOR(190,48) | |
| 1883 }else if(IS_SKIP(mb_type)){ | |
| 1884 // COLOR(180,48) | |
| 1885 }else if(!USES_LIST(mb_type, 1)){ | |
| 1886 COLOR(240,48) | |
| 1887 }else if(!USES_LIST(mb_type, 0)){ | |
| 1888 COLOR(0,48) | |
| 1889 }else{ | |
| 1890 assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1)); | |
| 1891 COLOR(300,48) | |
| 1892 } | |
| 1893 | |
| 1894 u*= 0x0101010101010101ULL; | |
| 1895 v*= 0x0101010101010101ULL; | |
| 1896 for(y=0; y<8; y++){ | |
| 1897 *(uint64_t*)(pict->data[1] + 8*mb_x + (8*mb_y + y)*pict->linesize[1])= u; | |
| 1898 *(uint64_t*)(pict->data[2] + 8*mb_x + (8*mb_y + y)*pict->linesize[2])= v; | |
| 1899 } | |
| 1900 | |
| 1901 //segmentation | |
| 1902 if(IS_8X8(mb_type) || IS_16X8(mb_type)){ | |
| 1903 *(uint64_t*)(pict->data[0] + 16*mb_x + 0 + (16*mb_y + 8)*pict->linesize[0])^= 0x8080808080808080ULL; | |
| 1904 *(uint64_t*)(pict->data[0] + 16*mb_x + 8 + (16*mb_y + 8)*pict->linesize[0])^= 0x8080808080808080ULL; | |
| 1905 } | |
| 1906 if(IS_8X8(mb_type) || IS_8X16(mb_type)){ | |
| 1907 for(y=0; y<16; y++) | |
| 1908 pict->data[0][16*mb_x + 8 + (16*mb_y + y)*pict->linesize[0]]^= 0x80; | |
| 1909 } | |
| 1910 | |
| 1911 if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264){ | |
| 1912 // hmm | |
| 1913 } | |
| 1285 | 1914 } |
| 1915 s->mbskip_table[mb_index]=0; | |
| 1916 } | |
| 1917 } | |
| 1918 } | |
|
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
|
1919 } |
|
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
|
1920 |
|
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
|
1921 #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
|
1922 |
| 915 | 1923 static int get_sae(uint8_t *src, int ref, int stride){ |
| 1924 int x,y; | |
| 1925 int acc=0; | |
| 1926 | |
| 1927 for(y=0; y<16; y++){ | |
| 1928 for(x=0; x<16; x++){ | |
| 1929 acc+= ABS(src[x+y*stride] - ref); | |
| 1930 } | |
| 1931 } | |
| 1932 | |
| 1933 return acc; | |
| 1934 } | |
| 1935 | |
| 1936 static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride){ | |
| 1937 int x, y, w, h; | |
| 1938 int acc=0; | |
| 1939 | |
| 1940 w= s->width &~15; | |
| 1941 h= s->height&~15; | |
| 1942 | |
| 1943 for(y=0; y<h; y+=16){ | |
| 1944 for(x=0; x<w; x+=16){ | |
| 1945 int offset= x + y*stride; | |
| 1708 | 1946 int sad = s->dsp.sad[0](NULL, src + offset, ref + offset, stride, 16); |
| 915 | 1947 int mean= (s->dsp.pix_sum(src + offset, stride) + 128)>>8; |
| 1948 int sae = get_sae(src + offset, mean, stride); | |
| 1949 | |
| 1950 acc+= sae + 500 < sad; | |
| 1951 } | |
| 1952 } | |
| 1953 return acc; | |
| 1954 } | |
| 1955 | |
| 924 | 1956 |
| 925 | 1957 static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){ |
| 1373 | 1958 AVFrame *pic=NULL; |
| 2427 | 1959 int64_t pts; |
| 924 | 1960 int i; |
| 903 | 1961 const int encoding_delay= s->max_b_frames; |
| 924 | 1962 int direct=1; |
| 1373 | 1963 |
| 2419 | 1964 if(pic_arg){ |
| 2427 | 1965 pts= pic_arg->pts; |
| 1966 pic_arg->display_picture_number= s->input_picture_number++; | |
| 1967 | |
| 1968 if(pts != AV_NOPTS_VALUE){ | |
| 2419 | 1969 if(s->user_specified_pts != AV_NOPTS_VALUE){ |
| 2427 | 1970 int64_t time= av_rescale(pts, s->avctx->frame_rate, s->avctx->frame_rate_base*(int64_t)AV_TIME_BASE); |
| 2419 | 1971 int64_t last= av_rescale(s->user_specified_pts, s->avctx->frame_rate, s->avctx->frame_rate_base*(int64_t)AV_TIME_BASE); |
| 1972 | |
| 1973 if(time <= last){ | |
| 2427 | 1974 av_log(s->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%Ld, last=%Ld\n", pts, s->user_specified_pts); |
| 2419 | 1975 return -1; |
| 1976 } | |
| 1977 } | |
| 2427 | 1978 s->user_specified_pts= pts; |
| 2419 | 1979 }else{ |
| 1980 if(s->user_specified_pts != AV_NOPTS_VALUE){ | |
| 1981 s->user_specified_pts= | |
| 2427 | 1982 pts= s->user_specified_pts + AV_TIME_BASE*(int64_t)s->avctx->frame_rate_base / s->avctx->frame_rate; |
| 1983 av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%Ld)\n", pts); | |
| 2419 | 1984 }else{ |
| 2427 | 1985 pts= av_rescale(pic_arg->display_picture_number*(int64_t)s->avctx->frame_rate_base, AV_TIME_BASE, s->avctx->frame_rate); |
| 2419 | 1986 } |
| 1987 } | |
| 1988 } | |
| 1989 | |
| 1373 | 1990 if(pic_arg){ |
| 924 | 1991 if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0; |
| 1992 if(pic_arg->linesize[0] != s->linesize) direct=0; | |
| 1993 if(pic_arg->linesize[1] != s->uvlinesize) direct=0; | |
| 1994 if(pic_arg->linesize[2] != s->uvlinesize) direct=0; | |
| 1995 | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
1996 // av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize); |
| 924 | 1997 |
| 1998 if(direct){ | |
| 1586 | 1999 i= ff_find_unused_picture(s, 1); |
| 924 | 2000 |
| 925 | 2001 pic= (AVFrame*)&s->picture[i]; |
| 1168 | 2002 pic->reference= 3; |
| 903 | 2003 |
| 924 | 2004 for(i=0; i<4; i++){ |
| 2005 pic->data[i]= pic_arg->data[i]; | |
| 2006 pic->linesize[i]= pic_arg->linesize[i]; | |
| 2007 } | |
| 2008 alloc_picture(s, (Picture*)pic, 1); | |
| 2009 }else{ | |
|
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
|
2010 int offset= 16; |
| 1586 | 2011 i= ff_find_unused_picture(s, 0); |
| 924 | 2012 |
| 925 | 2013 pic= (AVFrame*)&s->picture[i]; |
| 1168 | 2014 pic->reference= 3; |
| 924 | 2015 |
| 2016 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
|
2017 |
|
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
|
2018 if( pic->data[0] + offset == pic_arg->data[0] |
|
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
|
2019 && pic->data[1] + offset == pic_arg->data[1] |
|
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
|
2020 && pic->data[2] + offset == pic_arg->data[2]){ |
| 924 | 2021 // empty |
| 2022 }else{ | |
| 2023 int h_chroma_shift, v_chroma_shift; | |
| 2024 avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); | |
| 2025 | |
| 2026 for(i=0; i<3; i++){ | |
| 2027 int src_stride= pic_arg->linesize[i]; | |
| 2028 int dst_stride= i ? s->uvlinesize : s->linesize; | |
| 2029 int h_shift= i ? h_chroma_shift : 0; | |
| 2030 int v_shift= i ? v_chroma_shift : 0; | |
| 2031 int w= s->width >>h_shift; | |
| 2032 int h= s->height>>v_shift; | |
| 2033 uint8_t *src= pic_arg->data[i]; | |
|
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
|
2034 uint8_t *dst= pic->data[i] + offset; |
| 924 | 2035 |
| 2036 if(src_stride==dst_stride) | |
| 2037 memcpy(dst, src, src_stride*h); | |
| 2038 else{ | |
| 2039 while(h--){ | |
| 2040 memcpy(dst, src, w); | |
| 2041 dst += dst_stride; | |
| 2042 src += src_stride; | |
| 2043 } | |
| 2044 } | |
| 2045 } | |
| 2046 } | |
| 324 | 2047 } |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
2048 copy_picture_attributes(s, pic, pic_arg); |
| 2427 | 2049 pic->pts= pts; //we set this here to avoid modifiying pic_arg |
| 1373 | 2050 } |
| 1829 | 2051 |
| 903 | 2052 /* shift buffer entries */ |
| 2053 for(i=1; i<MAX_PICTURE_COUNT /*s->encoding_delay+1*/; i++) | |
| 2054 s->input_picture[i-1]= s->input_picture[i]; | |
| 2055 | |
| 2056 s->input_picture[encoding_delay]= (Picture*)pic; | |
| 2057 | |
| 2058 return 0; | |
| 2059 } | |
| 2060 | |
| 2381 | 2061 static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){ |
| 2062 int x, y, plane; | |
| 2063 int score=0; | |
| 2382 | 2064 int64_t score64=0; |
| 2065 int64_t threshold; | |
| 2381 | 2066 |
| 2067 for(plane=0; plane<3; plane++){ | |
| 2068 const int stride= p->linesize[plane]; | |
| 2069 const int bw= plane ? 1 : 2; | |
| 2070 for(y=0; y<s->mb_height*bw; y++){ | |
| 2071 for(x=0; x<s->mb_width*bw; x++){ | |
| 2382 | 2072 int v= s->dsp.frame_skip_cmp[1](s, p->data[plane] + 8*(x + y*stride), ref->data[plane] + 8*(x + y*stride), stride, 8); |
| 2381 | 2073 |
| 2382 | 2074 switch(s->avctx->frame_skip_exp){ |
| 2075 case 0: score= FFMAX(score, v); break; | |
| 2076 case 1: score+= ABS(v);break; | |
| 2077 case 2: score+= v*v;break; | |
| 2078 case 3: score64+= ABS(v*v*(int64_t)v);break; | |
| 2079 case 4: score64+= v*v*(int64_t)(v*v);break; | |
| 2080 } | |
| 2381 | 2081 } |
| 2082 } | |
| 2083 } | |
| 2382 | 2084 |
| 2085 if(score) score64= score; | |
| 2086 | |
| 2087 if(score64 < s->avctx->frame_skip_threshold) | |
| 2381 | 2088 return 1; |
| 2382 | 2089 if(score64 < ((s->avctx->frame_skip_factor * (int64_t)s->lambda)>>8)) |
| 2381 | 2090 return 1; |
| 2091 return 0; | |
| 2092 } | |
| 2093 | |
| 903 | 2094 static void select_input_picture(MpegEncContext *s){ |
| 2095 int i; | |
| 924 | 2096 |
| 903 | 2097 for(i=1; i<MAX_PICTURE_COUNT; i++) |
| 2098 s->reordered_input_picture[i-1]= s->reordered_input_picture[i]; | |
| 2099 s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL; | |
| 2100 | |
| 2101 /* set next picture types & ordering */ | |
| 2102 if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){ | |
| 1138 | 2103 if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture_ptr==NULL || s->intra_only){ |
| 915 | 2104 s->reordered_input_picture[0]= s->input_picture[0]; |
| 2105 s->reordered_input_picture[0]->pict_type= I_TYPE; | |
| 1705 | 2106 s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; |
| 915 | 2107 }else{ |
| 2108 int b_frames; | |
| 2381 | 2109 |
| 2110 if(s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor){ | |
| 2111 if(skip_check(s, s->input_picture[0], s->next_picture_ptr)){ | |
| 2112 //av_log(NULL, AV_LOG_DEBUG, "skip %p %Ld\n", s->input_picture[0]->data[0], s->input_picture[0]->pts); | |
| 2113 | |
| 2114 if(s->input_picture[0]->type == FF_BUFFER_TYPE_SHARED){ | |
| 2115 for(i=0; i<4; i++) | |
| 2116 s->input_picture[0]->data[i]= NULL; | |
| 2117 s->input_picture[0]->type= 0; | |
| 2118 }else{ | |
| 2119 assert( s->input_picture[0]->type==FF_BUFFER_TYPE_USER | |
| 2120 || s->input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); | |
| 915 | 2121 |
| 2381 | 2122 s->avctx->release_buffer(s->avctx, (AVFrame*)s->input_picture[0]); |
| 2123 } | |
| 2124 | |
| 2125 goto no_output_pic; | |
| 2126 } | |
| 2127 } | |
| 2128 | |
| 915 | 2129 if(s->flags&CODEC_FLAG_PASS2){ |
| 2130 for(i=0; i<s->max_b_frames+1; i++){ | |
| 2131 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
|
2132 |
|
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
|
2133 if(pict_num >= s->rc_context.num_entries) |
|
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
|
2134 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
|
2135 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
|
2136 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
|
2137 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
|
2138 } |
|
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
|
2139 |
|
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
|
2140 s->input_picture[i]->pict_type= |
|
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
|
2141 s->rc_context.entry[pict_num].new_pict_type; |
| 915 | 2142 } |
| 2143 } | |
| 924 | 2144 |
| 2297 | 2145 if(s->avctx->b_frame_strategy==0){ |
| 915 | 2146 b_frames= s->max_b_frames; |
| 1373 | 2147 while(b_frames && !s->input_picture[b_frames]) b_frames--; |
| 1687 | 2148 }else if(s->avctx->b_frame_strategy==1){ |
| 915 | 2149 for(i=1; i<s->max_b_frames+1; i++){ |
| 1373 | 2150 if(s->input_picture[i] && s->input_picture[i]->b_frame_score==0){ |
| 915 | 2151 s->input_picture[i]->b_frame_score= |
| 924 | 2152 get_intra_count(s, s->input_picture[i ]->data[0], |
| 2153 s->input_picture[i-1]->data[0], s->linesize) + 1; | |
| 915 | 2154 } |
| 2155 } | |
| 2156 for(i=0; i<s->max_b_frames; i++){ | |
| 1373 | 2157 if(s->input_picture[i]==NULL || s->input_picture[i]->b_frame_score - 1 > s->mb_num/40) break; |
| 915 | 2158 } |
| 2159 | |
| 2160 b_frames= FFMAX(0, i-1); | |
|
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2161 |
| 915 | 2162 /* reset scores */ |
| 2163 for(i=0; i<b_frames+1; i++){ | |
| 2164 s->input_picture[i]->b_frame_score=0; | |
| 2165 } | |
| 2166 }else{ | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
2167 av_log(s->avctx, AV_LOG_ERROR, "illegal b frame strategy\n"); |
| 915 | 2168 b_frames=0; |
|
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2169 } |
| 915 | 2170 |
| 2171 emms_c(); | |
| 2172 //static int b_count=0; | |
| 2173 //b_count+= b_frames; | |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
2174 //av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count); |
| 2297 | 2175 |
| 2176 for(i= b_frames - 1; i>=0; i--){ | |
| 2177 int type= s->input_picture[i]->pict_type; | |
| 2178 if(type && type != B_TYPE) | |
| 2179 b_frames= i; | |
| 2180 } | |
| 2181 if(s->input_picture[b_frames]->pict_type == B_TYPE && b_frames == s->max_b_frames){ | |
| 2182 av_log(s->avctx, AV_LOG_ERROR, "warning, too many bframes in a row\n"); | |
| 2183 } | |
| 2184 | |
|
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2185 if(s->picture_in_gop_number + b_frames >= s->gop_size){ |
| 2298 | 2186 if((s->flags2 & CODEC_FLAG2_STRICT_GOP) && s->gop_size > s->picture_in_gop_number){ |
| 2187 b_frames= s->gop_size - s->picture_in_gop_number - 1; | |
| 2188 }else{ | |
|
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2189 if(s->flags & CODEC_FLAG_CLOSED_GOP) |
|
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2190 b_frames=0; |
|
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2191 s->input_picture[b_frames]->pict_type= I_TYPE; |
| 2298 | 2192 } |
|
1754
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2193 } |
|
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2194 |
|
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2195 if( (s->flags & CODEC_FLAG_CLOSED_GOP) |
|
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2196 && b_frames |
|
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2197 && 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
|
2198 b_frames--; |
|
bdf3927bf8c5
closed gop support & flags2 as all bits in flags are used
michael
parents:
1751
diff
changeset
|
2199 |
| 915 | 2200 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
|
2201 if(s->reordered_input_picture[0]->pict_type != I_TYPE) |
| 915 | 2202 s->reordered_input_picture[0]->pict_type= P_TYPE; |
| 1705 | 2203 s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; |
| 915 | 2204 for(i=0; i<b_frames; i++){ |
| 2205 s->reordered_input_picture[i+1]= s->input_picture[i]; | |
| 2206 s->reordered_input_picture[i+1]->pict_type= B_TYPE; | |
| 1705 | 2207 s->reordered_input_picture[i+1]->coded_picture_number= s->coded_picture_number++; |
| 903 | 2208 } |
| 324 | 2209 } |
| 2210 } | |
| 2381 | 2211 no_output_pic: |
| 903 | 2212 if(s->reordered_input_picture[0]){ |
| 1168 | 2213 s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=B_TYPE ? 3 : 0; |
| 1138 | 2214 |
|
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
|
2215 copy_picture(&s->new_picture, s->reordered_input_picture[0]); |
| 924 | 2216 |
| 2217 if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_SHARED){ | |
| 1138 | 2218 // input is a shared pix, so we cant modifiy it -> alloc a new one & ensure that the shared one is reuseable |
| 2219 | |
| 1586 | 2220 int i= ff_find_unused_picture(s, 0); |
| 924 | 2221 Picture *pic= &s->picture[i]; |
| 2222 | |
| 2223 /* mark us unused / free shared pic */ | |
| 2224 for(i=0; i<4; i++) | |
| 2225 s->reordered_input_picture[0]->data[i]= NULL; | |
| 2226 s->reordered_input_picture[0]->type= 0; | |
| 2227 | |
| 1702 | 2228 pic->reference = s->reordered_input_picture[0]->reference; |
| 924 | 2229 |
| 2230 alloc_picture(s, pic, 0); | |
| 2231 | |
|
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
|
2232 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
|
2233 |
| 1138 | 2234 s->current_picture_ptr= pic; |
| 924 | 2235 }else{ |
| 1138 | 2236 // input is not a shared pix -> reuse buffer for current_pix |
| 2237 | |
| 924 | 2238 assert( s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_USER |
| 2239 || s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); | |
| 2240 | |
| 1138 | 2241 s->current_picture_ptr= s->reordered_input_picture[0]; |
| 924 | 2242 for(i=0; i<4; i++){ |
|
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
|
2243 s->new_picture.data[i]+=16; |
| 924 | 2244 } |
| 903 | 2245 } |
|
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
|
2246 copy_picture(&s->current_picture, s->current_picture_ptr); |
| 903 | 2247 |
| 2248 s->picture_number= s->new_picture.display_picture_number; | |
| 2249 //printf("dpn:%d\n", s->picture_number); | |
| 2250 }else{ | |
| 2251 memset(&s->new_picture, 0, sizeof(Picture)); | |
| 324 | 2252 } |
| 2253 } | |
| 2254 | |
| 0 | 2255 int MPV_encode_picture(AVCodecContext *avctx, |
| 2256 unsigned char *buf, int buf_size, void *data) | |
| 2257 { | |
| 2258 MpegEncContext *s = avctx->priv_data; | |
| 925 | 2259 AVFrame *pic_arg = data; |
| 1684 | 2260 int i, stuffing_count; |
| 0 | 2261 |
| 1397 | 2262 if(avctx->pix_fmt != PIX_FMT_YUV420P){ |
|
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1597
diff
changeset
|
2263 av_log(avctx, AV_LOG_ERROR, "this codec supports only YUV420P\n"); |
| 1397 | 2264 return -1; |
| 2265 } | |
| 2266 | |
| 1799 | 2267 for(i=0; i<avctx->thread_count; i++){ |
| 1838 | 2268 int start_y= s->thread_context[i]->start_mb_y; |
| 2269 int end_y= s->thread_context[i]-> end_mb_y; | |
| 1799 | 2270 int h= s->mb_height; |
| 1838 | 2271 uint8_t *start= buf + buf_size*start_y/h; |
| 2272 uint8_t *end = buf + buf_size* end_y/h; | |
| 1799 | 2273 |
| 2274 init_put_bits(&s->thread_context[i]->pb, start, end - start); | |
| 2275 } | |
| 0 | 2276 |
| 903 | 2277 s->picture_in_gop_number++; |
| 2278 | |
|
2243
b8bad8bbbc64
check if the user specified timestamps are strictly monotone
michael
parents:
2235
diff
changeset
|
2279 if(load_input_picture(s, pic_arg) < 0) |
|
b8bad8bbbc64
check if the user specified timestamps are strictly monotone
michael
parents:
2235
diff
changeset
|
2280 return -1; |
| 329 | 2281 |
| 903 | 2282 select_input_picture(s); |
| 324 | 2283 |
| 2284 /* output? */ | |
| 903 | 2285 if(s->new_picture.data[0]){ |
| 2286 s->pict_type= s->new_picture.pict_type; | |
| 2287 //emms_c(); | |
| 2288 //printf("qs:%f %f %d\n", s->new_picture.quality, s->current_picture.quality, s->qscale); | |
| 553 | 2289 MPV_frame_start(s, avctx); |
| 286 | 2290 |
| 324 | 2291 encode_picture(s, s->picture_number); |
| 652 | 2292 |
| 376 | 2293 avctx->real_pict_num = s->picture_number; |
| 324 | 2294 avctx->header_bits = s->header_bits; |
| 2295 avctx->mv_bits = s->mv_bits; | |
| 2296 avctx->misc_bits = s->misc_bits; | |
| 2297 avctx->i_tex_bits = s->i_tex_bits; | |
| 2298 avctx->p_tex_bits = s->p_tex_bits; | |
| 2299 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
|
2300 avctx->p_count = s->mb_num - s->i_count - s->skip_count; //FIXME f/b_count in avctx |
| 324 | 2301 avctx->skip_count = s->skip_count; |
| 0 | 2302 |
| 324 | 2303 MPV_frame_end(s); |
| 2304 | |
| 2305 if (s->out_format == FMT_MJPEG) | |
| 2306 mjpeg_picture_trailer(s); | |
| 329 | 2307 |
| 2308 if(s->flags&CODEC_FLAG_PASS1) | |
| 2309 ff_write_pass1_stats(s); | |
| 1138 | 2310 |
| 2311 for(i=0; i<4; i++){ | |
| 2312 avctx->error[i] += s->current_picture_ptr->error[i]; | |
| 2313 } | |
| 1766 | 2314 |
|
2428
548c87c06dbb
assertion about bits statistic and minor bits stat fix
michael
parents:
2427
diff
changeset
|
2315 if(s->flags&CODEC_FLAG_PASS1) |
|
548c87c06dbb
assertion about bits statistic and minor bits stat fix
michael
parents:
2427
diff
changeset
|
2316 assert(avctx->header_bits + avctx->mv_bits + avctx->misc_bits + avctx->i_tex_bits + avctx->p_tex_bits == put_bits_count(&s->pb)); |
| 1684 | 2317 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
|
2318 s->frame_bits = put_bits_count(&s->pb); |
| 1766 | 2319 |
| 2320 stuffing_count= ff_vbv_update(s, s->frame_bits); | |
| 2321 if(stuffing_count){ | |
| 2422 | 2322 if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < stuffing_count + 50){ |
| 2323 av_log(s->avctx, AV_LOG_ERROR, "stuffing too large\n"); | |
| 2324 return -1; | |
| 2325 } | |
| 2326 | |
| 1766 | 2327 switch(s->codec_id){ |
| 2328 case CODEC_ID_MPEG1VIDEO: | |
| 2329 case CODEC_ID_MPEG2VIDEO: | |
| 2330 while(stuffing_count--){ | |
| 2331 put_bits(&s->pb, 8, 0); | |
| 2332 } | |
| 2333 break; | |
| 2334 case CODEC_ID_MPEG4: | |
| 2335 put_bits(&s->pb, 16, 0); | |
| 2336 put_bits(&s->pb, 16, 0x1C3); | |
| 2337 stuffing_count -= 4; | |
| 2338 while(stuffing_count--){ | |
| 2339 put_bits(&s->pb, 8, 0xFF); | |
| 2340 } | |
| 2341 break; | |
| 2342 default: | |
| 2343 av_log(s->avctx, AV_LOG_ERROR, "vbv buffer overflow\n"); | |
| 2344 } | |
| 2345 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
|
2346 s->frame_bits = put_bits_count(&s->pb); |
| 1766 | 2347 } |
| 2348 | |
| 2349 /* update mpeg1/2 vbv_delay for CBR */ | |
| 1907 | 2350 if(s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate && s->out_format == FMT_MPEG1 |
| 2351 && 90000LL * (avctx->rc_buffer_size-1) <= s->avctx->rc_max_rate*0xFFFFLL){ | |
| 1766 | 2352 int vbv_delay; |
| 2353 | |
| 2354 assert(s->repeat_first_field==0); | |
| 2355 | |
| 2356 vbv_delay= lrintf(90000 * s->rc_context.buffer_index / s->avctx->rc_max_rate); | |
| 2357 assert(vbv_delay < 0xFFFF); | |
| 2358 | |
| 2359 s->vbv_delay_ptr[0] &= 0xF8; | |
| 2360 s->vbv_delay_ptr[0] |= vbv_delay>>13; | |
| 2361 s->vbv_delay_ptr[1] = vbv_delay>>5; | |
| 2362 s->vbv_delay_ptr[2] &= 0x07; | |
| 2363 s->vbv_delay_ptr[2] |= vbv_delay<<3; | |
| 2364 } | |
| 2365 s->total_bits += s->frame_bits; | |
| 2366 avctx->frame_bits = s->frame_bits; | |
| 2367 }else{ | |
| 2368 assert((pbBufPtr(&s->pb) == s->pb.buf)); | |
| 2369 s->frame_bits=0; | |
| 1684 | 2370 } |
| 1766 | 2371 assert((s->frame_bits&7)==0); |
|
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
2372 |
| 1684 | 2373 return s->frame_bits/8; |
| 0 | 2374 } |
| 2375 | |
|
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
|
2376 #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
|
2377 |
| 255 | 2378 static inline void gmc1_motion(MpegEncContext *s, |
| 1064 | 2379 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
|
2380 uint8_t **ref_picture) |
| 255 | 2381 { |
| 1064 | 2382 uint8_t *ptr; |
| 556 | 2383 int offset, src_x, src_y, linesize, uvlinesize; |
| 255 | 2384 int motion_x, motion_y; |
| 566 | 2385 int emu=0; |
| 255 | 2386 |
| 2387 motion_x= s->sprite_offset[0][0]; | |
| 2388 motion_y= s->sprite_offset[0][1]; | |
| 2389 src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
| 2390 src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
| 2391 motion_x<<=(3-s->sprite_warping_accuracy); | |
| 2392 motion_y<<=(3-s->sprite_warping_accuracy); | |
| 2393 src_x = clip(src_x, -16, s->width); | |
| 2394 if (src_x == s->width) | |
| 2395 motion_x =0; | |
| 2396 src_y = clip(src_y, -16, s->height); | |
| 2397 if (src_y == s->height) | |
| 2398 motion_y =0; | |
| 753 | 2399 |
| 255 | 2400 linesize = s->linesize; |
| 556 | 2401 uvlinesize = s->uvlinesize; |
| 753 | 2402 |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2403 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
|
2404 |
| 566 | 2405 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
|
2406 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
|
2407 || (unsigned)src_y >= s->v_edge_pos - 17){ |
|
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2408 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 | 2409 ptr= s->edge_emu_buffer; |
| 2410 } | |
| 2411 } | |
| 753 | 2412 |
| 2413 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
|
2414 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
|
2415 s->dsp.gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); |
| 753 | 2416 }else{ |
| 2417 int dxy; | |
| 2418 | |
| 2419 dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2); | |
| 2420 if (s->no_rounding){ | |
|
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2421 s->dsp.put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16); |
| 753 | 2422 }else{ |
|
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2423 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
|
2424 } |
| 753 | 2425 } |
| 2426 | |
| 2427 if(s->flags&CODEC_FLAG_GRAY) return; | |
| 255 | 2428 |
| 2429 motion_x= s->sprite_offset[1][0]; | |
| 2430 motion_y= s->sprite_offset[1][1]; | |
| 2431 src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
| 2432 src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
| 2433 motion_x<<=(3-s->sprite_warping_accuracy); | |
| 2434 motion_y<<=(3-s->sprite_warping_accuracy); | |
| 2435 src_x = clip(src_x, -8, s->width>>1); | |
| 2436 if (src_x == s->width>>1) | |
| 2437 motion_x =0; | |
| 2438 src_y = clip(src_y, -8, s->height>>1); | |
| 2439 if (src_y == s->height>>1) | |
| 2440 motion_y =0; | |
| 2441 | |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2442 offset = (src_y * uvlinesize) + src_x; |
| 255 | 2443 ptr = ref_picture[1] + offset; |
| 1002 | 2444 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
|
2445 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
|
2446 || (unsigned)src_y >= (s->v_edge_pos>>1) - 9){ |
|
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2447 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 | 2448 ptr= s->edge_emu_buffer; |
| 2449 emu=1; | |
| 2450 } | |
| 566 | 2451 } |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2452 s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); |
| 566 | 2453 |
| 255 | 2454 ptr = ref_picture[2] + offset; |
| 566 | 2455 if(emu){ |
|
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2456 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 | 2457 ptr= s->edge_emu_buffer; |
| 2458 } | |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2459 s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); |
| 255 | 2460 |
| 2461 return; | |
| 2462 } | |
| 2463 | |
| 753 | 2464 static inline void gmc_motion(MpegEncContext *s, |
| 1064 | 2465 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
|
2466 uint8_t **ref_picture) |
| 753 | 2467 { |
| 1064 | 2468 uint8_t *ptr; |
| 753 | 2469 int linesize, uvlinesize; |
| 2470 const int a= s->sprite_warping_accuracy; | |
| 2471 int ox, oy; | |
| 2472 | |
| 2473 linesize = s->linesize; | |
| 2474 uvlinesize = s->uvlinesize; | |
| 2475 | |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2476 ptr = ref_picture[0]; |
|
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2477 |
| 753 | 2478 ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16; |
| 2479 oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16; | |
| 2480 | |
|
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
2481 s->dsp.gmc(dest_y, ptr, linesize, 16, |
| 753 | 2482 ox, |
| 2483 oy, | |
| 2484 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
| 2485 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
| 2486 a+1, (1<<(2*a+1)) - s->no_rounding, | |
| 2487 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
|
2488 s->dsp.gmc(dest_y+8, ptr, linesize, 16, |
| 753 | 2489 ox + s->sprite_delta[0][0]*8, |
| 2490 oy + s->sprite_delta[1][0]*8, | |
| 2491 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
| 2492 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
| 2493 a+1, (1<<(2*a+1)) - s->no_rounding, | |
| 2494 s->h_edge_pos, s->v_edge_pos); | |
| 2495 | |
| 2496 if(s->flags&CODEC_FLAG_GRAY) return; | |
| 2497 | |
| 2498 ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8; | |
| 2499 oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8; | |
| 2500 | |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2501 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
|
2502 s->dsp.gmc(dest_cb, ptr, uvlinesize, 8, |
| 753 | 2503 ox, |
| 2504 oy, | |
| 2505 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
| 2506 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
| 2507 a+1, (1<<(2*a+1)) - s->no_rounding, | |
| 2508 s->h_edge_pos>>1, s->v_edge_pos>>1); | |
| 2509 | |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2510 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
|
2511 s->dsp.gmc(dest_cr, ptr, uvlinesize, 8, |
| 753 | 2512 ox, |
| 2513 oy, | |
| 2514 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
| 2515 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
| 2516 a+1, (1<<(2*a+1)) - s->no_rounding, | |
| 2517 s->h_edge_pos>>1, s->v_edge_pos>>1); | |
| 2518 } | |
| 2519 | |
|
1317
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2520 /** |
|
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2521 * 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
|
2522 * @param buf destination buffer |
|
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2523 * @param src source buffer |
|
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2524 * @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
|
2525 * @param block_w width of block |
|
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2526 * @param block_h height of block |
|
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2527 * @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
|
2528 * @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
|
2529 * @param w width of the source buffer |
|
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2530 * @param h height of the source buffer |
|
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2531 */ |
|
26c44d2433c1
make ff_emulated_edge_mc() independant of MpegEncContext
michaelni
parents:
1315
diff
changeset
|
2532 void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h, |
| 553 | 2533 int src_x, int src_y, int w, int h){ |
| 2534 int x, y; | |
| 2535 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
|
2536 |
| 553 | 2537 if(src_y>= h){ |
| 2538 src+= (h-1-src_y)*linesize; | |
| 2539 src_y=h-1; | |
| 554 | 2540 }else if(src_y<=-block_h){ |
| 2541 src+= (1-block_h-src_y)*linesize; | |
| 2542 src_y=1-block_h; | |
| 553 | 2543 } |
| 2544 if(src_x>= w){ | |
| 2545 src+= (w-1-src_x); | |
| 2546 src_x=w-1; | |
| 554 | 2547 }else if(src_x<=-block_w){ |
| 2548 src+= (1-block_w-src_x); | |
| 2549 src_x=1-block_w; | |
| 553 | 2550 } |
| 2551 | |
| 847 | 2552 start_y= FFMAX(0, -src_y); |
| 2553 start_x= FFMAX(0, -src_x); | |
| 2554 end_y= FFMIN(block_h, h-src_y); | |
| 2555 end_x= FFMIN(block_w, w-src_x); | |
| 566 | 2556 |
| 553 | 2557 // copy existing part |
| 2558 for(y=start_y; y<end_y; y++){ | |
| 2559 for(x=start_x; x<end_x; x++){ | |
| 2560 buf[x + y*linesize]= src[x + y*linesize]; | |
| 2561 } | |
| 2562 } | |
| 2563 | |
| 2564 //top | |
| 2565 for(y=0; y<start_y; y++){ | |
| 2566 for(x=start_x; x<end_x; x++){ | |
| 2567 buf[x + y*linesize]= buf[x + start_y*linesize]; | |
| 2568 } | |
| 2569 } | |
| 2570 | |
| 2571 //bottom | |
| 2572 for(y=end_y; y<block_h; y++){ | |
| 2573 for(x=start_x; x<end_x; x++){ | |
| 2574 buf[x + y*linesize]= buf[x + (end_y-1)*linesize]; | |
| 2575 } | |
| 2576 } | |
| 2577 | |
| 2578 for(y=0; y<block_h; y++){ | |
| 2579 //left | |
| 2580 for(x=0; x<start_x; x++){ | |
| 2581 buf[x + y*linesize]= buf[start_x + y*linesize]; | |
| 2582 } | |
| 2583 | |
| 2584 //right | |
| 2585 for(x=end_x; x<block_w; x++){ | |
| 2586 buf[x + y*linesize]= buf[end_x - 1 + y*linesize]; | |
| 2587 } | |
| 2588 } | |
| 2589 } | |
| 2590 | |
| 1633 | 2591 static inline int hpel_motion(MpegEncContext *s, |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2592 uint8_t *dest, uint8_t *src, |
|
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2593 int field_based, int field_select, |
| 1633 | 2594 int src_x, int src_y, |
| 2595 int width, int height, int stride, | |
| 2596 int h_edge_pos, int v_edge_pos, | |
| 2597 int w, int h, op_pixels_func *pix_op, | |
| 2598 int motion_x, int motion_y) | |
| 2599 { | |
| 2600 int dxy; | |
| 2601 int emu=0; | |
| 2602 | |
| 2603 dxy = ((motion_y & 1) << 1) | (motion_x & 1); | |
| 2604 src_x += motion_x >> 1; | |
| 2605 src_y += motion_y >> 1; | |
| 2606 | |
| 2607 /* WARNING: do no forget half pels */ | |
| 2608 src_x = clip(src_x, -16, width); //FIXME unneeded for emu? | |
| 2609 if (src_x == width) | |
| 2610 dxy &= ~1; | |
| 2611 src_y = clip(src_y, -16, height); | |
| 2612 if (src_y == height) | |
| 2613 dxy &= ~2; | |
| 2614 src += src_y * stride + src_x; | |
| 2615 | |
| 2616 if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){ | |
| 2617 if( (unsigned)src_x > h_edge_pos - (motion_x&1) - w | |
| 2618 || (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
|
2619 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
|
2620 src_x, src_y<<field_based, h_edge_pos, s->v_edge_pos); |
| 1633 | 2621 src= s->edge_emu_buffer; |
| 2622 emu=1; | |
| 2623 } | |
| 2624 } | |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2625 if(field_select) |
|
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2626 src += s->linesize; |
| 1633 | 2627 pix_op[dxy](dest, src, stride, h); |
| 2628 return emu; | |
| 2629 } | |
| 553 | 2630 |
| 2292 | 2631 static inline int hpel_motion_lowres(MpegEncContext *s, |
| 2632 uint8_t *dest, uint8_t *src, | |
| 2633 int field_based, int field_select, | |
| 2634 int src_x, int src_y, | |
| 2635 int width, int height, int stride, | |
| 2636 int h_edge_pos, int v_edge_pos, | |
| 2637 int w, int h, h264_chroma_mc_func *pix_op, | |
| 2638 int motion_x, int motion_y) | |
| 2639 { | |
| 2640 const int lowres= s->avctx->lowres; | |
| 2641 const int s_mask= (2<<lowres)-1; | |
| 2642 int emu=0; | |
| 2643 int sx, sy; | |
| 2644 | |
| 2645 if(s->quarter_sample){ | |
| 2646 motion_x/=2; | |
| 2647 motion_y/=2; | |
| 2648 } | |
| 2649 | |
| 2650 sx= motion_x & s_mask; | |
| 2651 sy= motion_y & s_mask; | |
| 2652 src_x += motion_x >> (lowres+1); | |
| 2653 src_y += motion_y >> (lowres+1); | |
| 2654 | |
| 2655 src += src_y * stride + src_x; | |
| 2656 | |
| 2657 if( (unsigned)src_x > h_edge_pos - (!!sx) - w | |
| 2658 || (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){ | |
| 2659 ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based, | |
| 2660 src_x, src_y<<field_based, h_edge_pos, v_edge_pos); | |
| 2661 src= s->edge_emu_buffer; | |
| 2662 emu=1; | |
| 2663 } | |
| 2664 | |
| 2665 sx <<= 2 - lowres; | |
| 2666 sy <<= 2 - lowres; | |
| 2667 if(field_select) | |
| 2668 src += s->linesize; | |
| 2669 pix_op[lowres](dest, src, stride, h, sx, sy); | |
| 2670 return emu; | |
| 2671 } | |
| 2672 | |
| 0 | 2673 /* 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
|
2674 static always_inline void mpeg_motion(MpegEncContext *s, |
| 1064 | 2675 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
|
2676 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
|
2677 uint8_t **ref_picture, op_pixels_func (*pix_op)[4], |
| 0 | 2678 int motion_x, int motion_y, int h) |
| 2679 { | |
| 1846 | 2680 uint8_t *ptr_y, *ptr_cb, *ptr_cr; |
| 2681 int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize; | |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
2682 |
| 651 | 2683 #if 0 |
| 255 | 2684 if(s->quarter_sample) |
| 2685 { | |
| 2686 motion_x>>=1; | |
| 2687 motion_y>>=1; | |
| 2688 } | |
| 651 | 2689 #endif |
| 1633 | 2690 |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
2691 v_edge_pos = s->v_edge_pos >> field_based; |
| 1846 | 2692 linesize = s->current_picture.linesize[0] << field_based; |
| 1138 | 2693 uvlinesize = s->current_picture.linesize[1] << field_based; |
| 1633 | 2694 |
| 1846 | 2695 dxy = ((motion_y & 1) << 1) | (motion_x & 1); |
| 2696 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
|
2697 src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1); |
| 485 | 2698 |
| 0 | 2699 if (s->out_format == FMT_H263) { |
| 1916 | 2700 if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){ |
| 2701 mx = (motion_x>>1)|(motion_x&1); | |
| 2702 my = motion_y >>1; | |
| 2703 uvdxy = ((my & 1) << 1) | (mx & 1); | |
| 2704 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
|
2705 uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1); |
| 1916 | 2706 }else{ |
| 2707 uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1); | |
| 2708 uvsrc_x = src_x>>1; | |
| 2709 uvsrc_y = src_y>>1; | |
| 2710 } | |
|
2044
b6f2add2511e
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
2042
diff
changeset
|
2711 }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
|
2712 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
|
2713 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
|
2714 uvdxy = 0; |
|
b6f2add2511e
h261 decoder by (Maarten Daniels <maarten.daniels at student dot luc dot ac dot be>)
michael
parents:
2042
diff
changeset
|
2715 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
|
2716 uvsrc_y = s->mb_y*8 + my; |
| 0 | 2717 } else { |
|
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2718 if(s->chroma_y_shift){ |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2719 mx = motion_x / 2; |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2720 my = motion_y / 2; |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2721 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
|
2722 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
|
2723 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
|
2724 } else { |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2725 if(s->chroma_x_shift){ |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2726 //Chroma422 |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2727 mx = motion_x / 2; |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2728 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
|
2729 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
|
2730 uvsrc_y = src_y; |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2731 } else { |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2732 //Chroma444 |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2733 uvdxy = dxy; |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2734 uvsrc_x = src_x; |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2735 uvsrc_y = src_y; |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2736 } |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2737 } |
| 1846 | 2738 } |
| 2739 | |
| 2740 ptr_y = ref_picture[0] + src_y * linesize + src_x; | |
| 2741 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; | |
| 2742 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; | |
| 2743 | |
| 2744 if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16 | |
| 2745 || (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
|
2746 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
|
2747 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
|
2748 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
|
2749 return ; |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
2750 } |
| 1846 | 2751 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, |
| 2752 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); | |
| 2753 ptr_y = s->edge_emu_buffer; | |
| 2754 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
| 1874 | 2755 uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; |
| 1846 | 2756 ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based, |
| 2757 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
| 2758 ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based, | |
| 2759 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
| 2760 ptr_cb= uvbuf; | |
| 2761 ptr_cr= uvbuf+16; | |
| 2762 } | |
| 2763 } | |
| 2764 | |
| 2765 if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data | |
| 2766 dest_y += s->linesize; | |
| 2767 dest_cb+= s->uvlinesize; | |
| 2768 dest_cr+= s->uvlinesize; | |
| 2769 } | |
| 2770 | |
| 2771 if(field_select){ | |
| 2772 ptr_y += s->linesize; | |
| 2773 ptr_cb+= s->uvlinesize; | |
| 2774 ptr_cr+= s->uvlinesize; | |
| 2775 } | |
| 2776 | |
| 2777 pix_op[0][dxy](dest_y, ptr_y, linesize, h); | |
| 0 | 2778 |
| 1846 | 2779 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
|
2780 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
|
2781 pix_op[s->chroma_x_shift][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift); |
| 1846 | 2782 } |
| 2291 | 2783 if(s->out_format == FMT_H261){ |
| 2784 ff_h261_loop_filter(s); | |
| 2785 } | |
| 0 | 2786 } |
| 2256 | 2787 |
| 2788 /* apply one mpeg motion vector to the three components */ | |
| 2789 static always_inline void mpeg_motion_lowres(MpegEncContext *s, | |
| 2790 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | |
| 2791 int field_based, int bottom_field, int field_select, | |
| 2792 uint8_t **ref_picture, h264_chroma_mc_func *pix_op, | |
| 2793 int motion_x, int motion_y, int h) | |
| 2794 { | |
| 2795 uint8_t *ptr_y, *ptr_cb, *ptr_cr; | |
| 2796 int mx, my, src_x, src_y, uvsrc_x, uvsrc_y, uvlinesize, linesize, sx, sy, uvsx, uvsy; | |
| 2797 const int lowres= s->avctx->lowres; | |
| 2798 const int block_s= 8>>lowres; | |
| 2799 const int s_mask= (2<<lowres)-1; | |
| 2800 const int h_edge_pos = s->h_edge_pos >> lowres; | |
| 2801 const int v_edge_pos = s->v_edge_pos >> lowres; | |
| 2802 linesize = s->current_picture.linesize[0] << field_based; | |
| 2803 uvlinesize = s->current_picture.linesize[1] << field_based; | |
| 2804 | |
| 2260 | 2805 if(s->quarter_sample){ //FIXME obviously not perfect but qpel wont work in lowres anyway |
| 2806 motion_x/=2; | |
| 2807 motion_y/=2; | |
| 2808 } | |
| 2809 | |
| 2810 if(field_based){ | |
| 2811 motion_y += (bottom_field - field_select)*((1<<lowres)-1); | |
| 2812 } | |
| 2813 | |
| 2256 | 2814 sx= motion_x & s_mask; |
| 2815 sy= motion_y & s_mask; | |
| 2816 src_x = s->mb_x*2*block_s + (motion_x >> (lowres+1)); | |
| 2260 | 2817 src_y =(s->mb_y*2*block_s>>field_based) + (motion_y >> (lowres+1)); |
| 2256 | 2818 |
| 2819 if (s->out_format == FMT_H263) { | |
| 2265 | 2820 uvsx = ((motion_x>>1) & s_mask) | (sx&1); |
| 2821 uvsy = ((motion_y>>1) & s_mask) | (sy&1); | |
| 2256 | 2822 uvsrc_x = src_x>>1; |
| 2823 uvsrc_y = src_y>>1; | |
| 2824 }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261 | |
| 2825 mx = motion_x / 4; | |
| 2826 my = motion_y / 4; | |
| 2827 uvsx = (2*mx) & s_mask; | |
| 2828 uvsy = (2*my) & s_mask; | |
| 2829 uvsrc_x = s->mb_x*block_s + (mx >> lowres); | |
| 2830 uvsrc_y = s->mb_y*block_s + (my >> lowres); | |
| 2831 } else { | |
| 2832 mx = motion_x / 2; | |
| 2833 my = motion_y / 2; | |
| 2834 uvsx = mx & s_mask; | |
| 2835 uvsy = my & s_mask; | |
| 2836 uvsrc_x = s->mb_x*block_s + (mx >> (lowres+1)); | |
| 2260 | 2837 uvsrc_y =(s->mb_y*block_s>>field_based) + (my >> (lowres+1)); |
| 2256 | 2838 } |
| 2839 | |
| 2840 ptr_y = ref_picture[0] + src_y * linesize + src_x; | |
| 2841 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; | |
| 2842 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; | |
| 2843 | |
| 2844 if( (unsigned)src_x > h_edge_pos - (!!sx) - 2*block_s | |
| 2845 || (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){ | |
| 2846 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, | |
| 2847 src_x, src_y<<field_based, h_edge_pos, v_edge_pos); | |
| 2848 ptr_y = s->edge_emu_buffer; | |
| 2849 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
| 2850 uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; | |
| 2851 ff_emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based, | |
| 2852 uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1); | |
| 2853 ff_emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based, | |
| 2854 uvsrc_x, uvsrc_y<<field_based, h_edge_pos>>1, v_edge_pos>>1); | |
| 2855 ptr_cb= uvbuf; | |
| 2856 ptr_cr= uvbuf+16; | |
| 2857 } | |
| 2858 } | |
| 2859 | |
| 2260 | 2860 if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data |
| 2861 dest_y += s->linesize; | |
| 2862 dest_cb+= s->uvlinesize; | |
| 2863 dest_cr+= s->uvlinesize; | |
| 2864 } | |
| 2865 | |
| 2866 if(field_select){ | |
| 2867 ptr_y += s->linesize; | |
| 2868 ptr_cb+= s->uvlinesize; | |
| 2869 ptr_cr+= s->uvlinesize; | |
| 2870 } | |
| 2871 | |
| 2256 | 2872 sx <<= 2 - lowres; |
| 2873 sy <<= 2 - lowres; | |
| 2874 pix_op[lowres-1](dest_y, ptr_y, linesize, h, sx, sy); | |
| 2875 | |
| 2876 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
| 2877 uvsx <<= 2 - lowres; | |
| 2878 uvsy <<= 2 - lowres; | |
| 2879 pix_op[lowres](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); | |
| 2880 pix_op[lowres](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); | |
| 2881 } | |
| 2291 | 2882 //FIXME h261 lowres loop filter |
| 2256 | 2883 } |
| 2884 | |
| 1633 | 2885 //FIXME move to dsputil, avg variant, 16x16 version |
| 2886 static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){ | |
| 2887 int x; | |
| 2888 uint8_t * const top = src[1]; | |
| 2889 uint8_t * const left = src[2]; | |
| 2890 uint8_t * const mid = src[0]; | |
| 2891 uint8_t * const right = src[3]; | |
| 2892 uint8_t * const bottom= src[4]; | |
| 2893 #define OBMC_FILTER(x, t, l, m, r, b)\ | |
| 2894 dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3 | |
| 2895 #define OBMC_FILTER4(x, t, l, m, r, b)\ | |
| 2896 OBMC_FILTER(x , t, l, m, r, b);\ | |
| 2897 OBMC_FILTER(x+1 , t, l, m, r, b);\ | |
| 2898 OBMC_FILTER(x +stride, t, l, m, r, b);\ | |
| 2899 OBMC_FILTER(x+1+stride, t, l, m, r, b); | |
| 2900 | |
| 2901 x=0; | |
| 2902 OBMC_FILTER (x , 2, 2, 4, 0, 0); | |
| 2903 OBMC_FILTER (x+1, 2, 1, 5, 0, 0); | |
| 2904 OBMC_FILTER4(x+2, 2, 1, 5, 0, 0); | |
| 2905 OBMC_FILTER4(x+4, 2, 0, 5, 1, 0); | |
| 2906 OBMC_FILTER (x+6, 2, 0, 5, 1, 0); | |
| 2907 OBMC_FILTER (x+7, 2, 0, 4, 2, 0); | |
| 2908 x+= stride; | |
| 2909 OBMC_FILTER (x , 1, 2, 5, 0, 0); | |
| 2910 OBMC_FILTER (x+1, 1, 2, 5, 0, 0); | |
| 2911 OBMC_FILTER (x+6, 1, 0, 5, 2, 0); | |
| 2912 OBMC_FILTER (x+7, 1, 0, 5, 2, 0); | |
| 2913 x+= stride; | |
| 2914 OBMC_FILTER4(x , 1, 2, 5, 0, 0); | |
| 2915 OBMC_FILTER4(x+2, 1, 1, 6, 0, 0); | |
| 2916 OBMC_FILTER4(x+4, 1, 0, 6, 1, 0); | |
| 2917 OBMC_FILTER4(x+6, 1, 0, 5, 2, 0); | |
| 2918 x+= 2*stride; | |
| 2919 OBMC_FILTER4(x , 0, 2, 5, 0, 1); | |
| 2920 OBMC_FILTER4(x+2, 0, 1, 6, 0, 1); | |
| 2921 OBMC_FILTER4(x+4, 0, 0, 6, 1, 1); | |
| 2922 OBMC_FILTER4(x+6, 0, 0, 5, 2, 1); | |
| 2923 x+= 2*stride; | |
| 2924 OBMC_FILTER (x , 0, 2, 5, 0, 1); | |
| 2925 OBMC_FILTER (x+1, 0, 2, 5, 0, 1); | |
| 2926 OBMC_FILTER4(x+2, 0, 1, 5, 0, 2); | |
| 2927 OBMC_FILTER4(x+4, 0, 0, 5, 1, 2); | |
| 2928 OBMC_FILTER (x+6, 0, 0, 5, 2, 1); | |
| 2929 OBMC_FILTER (x+7, 0, 0, 5, 2, 1); | |
| 2930 x+= stride; | |
| 2931 OBMC_FILTER (x , 0, 2, 4, 0, 2); | |
| 2932 OBMC_FILTER (x+1, 0, 1, 5, 0, 2); | |
| 2933 OBMC_FILTER (x+6, 0, 0, 5, 1, 2); | |
| 2934 OBMC_FILTER (x+7, 0, 0, 4, 2, 2); | |
| 2935 } | |
| 2936 | |
| 2937 /* obmc for 1 8x8 luma block */ | |
| 2938 static inline void obmc_motion(MpegEncContext *s, | |
| 2939 uint8_t *dest, uint8_t *src, | |
| 2940 int src_x, int src_y, | |
| 2941 op_pixels_func *pix_op, | |
| 2942 int16_t mv[5][2]/* mid top left right bottom*/) | |
| 2943 #define MID 0 | |
| 2944 { | |
| 2945 int i; | |
| 2946 uint8_t *ptr[5]; | |
| 2947 | |
| 2948 assert(s->quarter_sample==0); | |
| 2949 | |
| 2950 for(i=0; i<5; i++){ | |
| 2951 if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){ | |
| 2952 ptr[i]= ptr[MID]; | |
| 2953 }else{ | |
| 1799 | 2954 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
|
2955 hpel_motion(s, ptr[i], src, 0, 0, |
| 1633 | 2956 src_x, src_y, |
| 2957 s->width, s->height, s->linesize, | |
| 2958 s->h_edge_pos, s->v_edge_pos, | |
| 2959 8, 8, pix_op, | |
| 2960 mv[i][0], mv[i][1]); | |
| 2961 } | |
| 2962 } | |
| 2963 | |
| 2964 put_obmc(dest, ptr, s->linesize); | |
| 2965 } | |
| 0 | 2966 |
| 255 | 2967 static inline void qpel_motion(MpegEncContext *s, |
| 1064 | 2968 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
|
2969 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
|
2970 uint8_t **ref_picture, op_pixels_func (*pix_op)[4], |
| 651 | 2971 qpel_mc_func (*qpix_op)[16], |
| 255 | 2972 int motion_x, int motion_y, int h) |
| 2973 { | |
| 1846 | 2974 uint8_t *ptr_y, *ptr_cb, *ptr_cr; |
| 2975 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
|
2976 |
| 255 | 2977 dxy = ((motion_y & 3) << 2) | (motion_x & 3); |
| 1846 | 2978 src_x = s->mb_x * 16 + (motion_x >> 2); |
| 255 | 2979 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); |
| 2980 | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
2981 v_edge_pos = s->v_edge_pos >> field_based; |
| 255 | 2982 linesize = s->linesize << field_based; |
| 671 | 2983 uvlinesize = s->uvlinesize << field_based; |
| 554 | 2984 |
| 671 | 2985 if(field_based){ |
| 2986 mx= motion_x/2; | |
| 2987 my= motion_y>>1; | |
| 1048 | 2988 }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA2){ |
| 2989 static const int rtab[8]= {0,0,1,1,0,0,0,1}; | |
| 2990 mx= (motion_x>>1) + rtab[motion_x&7]; | |
| 2991 my= (motion_y>>1) + rtab[motion_y&7]; | |
| 760 | 2992 }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){ |
| 671 | 2993 mx= (motion_x>>1)|(motion_x&1); |
| 2994 my= (motion_y>>1)|(motion_y&1); | |
| 2995 }else{ | |
| 2996 mx= motion_x/2; | |
| 2997 my= motion_y/2; | |
| 2998 } | |
| 2999 mx= (mx>>1)|(mx&1); | |
| 3000 my= (my>>1)|(my&1); | |
| 1048 | 3001 |
| 1846 | 3002 uvdxy= (mx&1) | ((my&1)<<1); |
| 671 | 3003 mx>>=1; |
| 3004 my>>=1; | |
| 255 | 3005 |
| 1846 | 3006 uvsrc_x = s->mb_x * 8 + mx; |
| 3007 uvsrc_y = s->mb_y * (8 >> field_based) + my; | |
| 3008 | |
| 3009 ptr_y = ref_picture[0] + src_y * linesize + src_x; | |
| 3010 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; | |
| 3011 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; | |
| 3012 | |
| 3013 if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16 | |
| 3014 || (unsigned)src_y > v_edge_pos - (motion_y&3) - h ){ | |
| 3015 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, | |
| 3016 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); | |
| 3017 ptr_y= s->edge_emu_buffer; | |
| 3018 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
| 1874 | 3019 uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize; |
| 1846 | 3020 ff_emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, 9, 9 + field_based, |
| 3021 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
| 3022 ff_emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, 9, 9 + field_based, | |
| 3023 uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
| 3024 ptr_cb= uvbuf; | |
| 3025 ptr_cr= uvbuf + 16; | |
| 3026 } | |
| 3027 } | |
| 3028 | |
| 3029 if(!field_based) | |
| 3030 qpix_op[0][dxy](dest_y, ptr_y, linesize); | |
| 3031 else{ | |
| 3032 if(bottom_field){ | |
| 3033 dest_y += s->linesize; | |
| 3034 dest_cb+= s->uvlinesize; | |
| 3035 dest_cr+= s->uvlinesize; | |
| 3036 } | |
| 3037 | |
| 3038 if(field_select){ | |
| 3039 ptr_y += s->linesize; | |
| 3040 ptr_cb += s->uvlinesize; | |
| 3041 ptr_cr += s->uvlinesize; | |
| 3042 } | |
| 3043 //damn interlaced mode | |
| 3044 //FIXME boundary mirroring is not exactly correct here | |
| 3045 qpix_op[1][dxy](dest_y , ptr_y , linesize); | |
| 3046 qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize); | |
| 3047 } | |
| 3048 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
| 3049 pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1); | |
| 3050 pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1); | |
| 3051 } | |
| 255 | 3052 } |
| 3053 | |
| 1013 | 3054 inline int ff_h263_round_chroma(int x){ |
| 3055 if (x >= 0) | |
| 3056 return (h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1)); | |
| 3057 else { | |
| 3058 x = -x; | |
| 3059 return -(h263_chroma_roundtab[x & 0xf] + ((x >> 3) & ~1)); | |
| 3060 } | |
| 3061 } | |
| 255 | 3062 |
| 1225 | 3063 /** |
| 1633 | 3064 * h263 chorma 4mv motion compensation. |
| 3065 */ | |
| 3066 static inline void chroma_4mv_motion(MpegEncContext *s, | |
| 3067 uint8_t *dest_cb, uint8_t *dest_cr, | |
| 3068 uint8_t **ref_picture, | |
| 3069 op_pixels_func *pix_op, | |
| 3070 int mx, int my){ | |
| 3071 int dxy, emu=0, src_x, src_y, offset; | |
| 3072 uint8_t *ptr; | |
| 3073 | |
| 3074 /* In case of 8X8, we construct a single chroma motion vector | |
| 3075 with a special rounding */ | |
| 3076 mx= ff_h263_round_chroma(mx); | |
| 3077 my= ff_h263_round_chroma(my); | |
| 3078 | |
| 3079 dxy = ((my & 1) << 1) | (mx & 1); | |
| 3080 mx >>= 1; | |
| 3081 my >>= 1; | |
| 3082 | |
| 3083 src_x = s->mb_x * 8 + mx; | |
| 3084 src_y = s->mb_y * 8 + my; | |
| 3085 src_x = clip(src_x, -8, s->width/2); | |
| 3086 if (src_x == s->width/2) | |
| 3087 dxy &= ~1; | |
| 3088 src_y = clip(src_y, -8, s->height/2); | |
| 3089 if (src_y == s->height/2) | |
| 3090 dxy &= ~2; | |
| 3091 | |
| 3092 offset = (src_y * (s->uvlinesize)) + src_x; | |
| 3093 ptr = ref_picture[1] + offset; | |
| 3094 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
| 3095 if( (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8 | |
| 3096 || (unsigned)src_y > (s->v_edge_pos>>1) - (dxy>>1) - 8){ | |
| 3097 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); | |
| 3098 ptr= s->edge_emu_buffer; | |
| 3099 emu=1; | |
| 3100 } | |
| 3101 } | |
| 3102 pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8); | |
| 3103 | |
| 3104 ptr = ref_picture[2] + offset; | |
| 3105 if(emu){ | |
| 3106 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); | |
| 3107 ptr= s->edge_emu_buffer; | |
| 3108 } | |
| 3109 pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); | |
| 3110 } | |
| 3111 | |
| 2292 | 3112 static inline void chroma_4mv_motion_lowres(MpegEncContext *s, |
| 3113 uint8_t *dest_cb, uint8_t *dest_cr, | |
| 3114 uint8_t **ref_picture, | |
| 3115 h264_chroma_mc_func *pix_op, | |
| 3116 int mx, int my){ | |
| 3117 const int lowres= s->avctx->lowres; | |
| 3118 const int block_s= 8>>lowres; | |
| 3119 const int s_mask= (2<<lowres)-1; | |
| 3120 const int h_edge_pos = s->h_edge_pos >> (lowres+1); | |
| 3121 const int v_edge_pos = s->v_edge_pos >> (lowres+1); | |
| 3122 int emu=0, src_x, src_y, offset, sx, sy; | |
| 3123 uint8_t *ptr; | |
| 3124 | |
| 3125 if(s->quarter_sample){ | |
| 3126 mx/=2; | |
| 3127 my/=2; | |
| 3128 } | |
| 3129 | |
| 3130 /* In case of 8X8, we construct a single chroma motion vector | |
| 3131 with a special rounding */ | |
| 3132 mx= ff_h263_round_chroma(mx); | |
| 3133 my= ff_h263_round_chroma(my); | |
| 3134 | |
| 3135 sx= mx & s_mask; | |
| 3136 sy= my & s_mask; | |
| 3137 src_x = s->mb_x*block_s + (mx >> (lowres+1)); | |
| 3138 src_y = s->mb_y*block_s + (my >> (lowres+1)); | |
| 3139 | |
| 3140 offset = src_y * s->uvlinesize + src_x; | |
| 3141 ptr = ref_picture[1] + offset; | |
| 3142 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
| 3143 if( (unsigned)src_x > h_edge_pos - (!!sx) - block_s | |
| 3144 || (unsigned)src_y > v_edge_pos - (!!sy) - block_s){ | |
| 3145 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos); | |
| 3146 ptr= s->edge_emu_buffer; | |
| 3147 emu=1; | |
| 3148 } | |
| 3149 } | |
| 3150 sx <<= 2 - lowres; | |
| 3151 sy <<= 2 - lowres; | |
| 3152 pix_op[lowres](dest_cb, ptr, s->uvlinesize, block_s, sx, sy); | |
| 3153 | |
| 3154 ptr = ref_picture[2] + offset; | |
| 3155 if(emu){ | |
| 3156 ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos); | |
| 3157 ptr= s->edge_emu_buffer; | |
| 3158 } | |
| 3159 pix_op[lowres](dest_cr, ptr, s->uvlinesize, block_s, sx, sy); | |
| 3160 } | |
| 3161 | |
| 1633 | 3162 /** |
| 1225 | 3163 * motion compesation of a single macroblock |
| 3164 * @param s context | |
| 3165 * @param dest_y luma destination pointer | |
| 3166 * @param dest_cb chroma cb/u destination pointer | |
| 3167 * @param dest_cr chroma cr/v destination pointer | |
| 3168 * @param dir direction (0->forward, 1->backward) | |
| 3169 * @param ref_picture array[3] of pointers to the 3 planes of the reference picture | |
| 3170 * @param pic_op halfpel motion compensation function (average or put normally) | |
| 3171 * @param pic_op qpel motion compensation function (average or put normally) | |
| 3172 * the motion vectors are taken from s->mv and the MV type from s->mv_type | |
| 3173 */ | |
| 0 | 3174 static inline void MPV_motion(MpegEncContext *s, |
| 1064 | 3175 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, |
| 3176 int dir, uint8_t **ref_picture, | |
| 651 | 3177 op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16]) |
| 0 | 3178 { |
| 1633 | 3179 int dxy, mx, my, src_x, src_y, motion_x, motion_y; |
| 0 | 3180 int mb_x, mb_y, i; |
| 1064 | 3181 uint8_t *ptr, *dest; |
| 0 | 3182 |
| 3183 mb_x = s->mb_x; | |
| 3184 mb_y = s->mb_y; | |
| 3185 | |
| 1655 | 3186 if(s->obmc && s->pict_type != B_TYPE){ |
| 1633 | 3187 int16_t mv_cache[4][4][2]; |
| 3188 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
|
3189 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
|
3190 const int mot_xy= mb_x*2 + mb_y*2*mot_stride; |
| 1633 | 3191 |
| 3192 assert(!s->mb_skiped); | |
| 3193 | |
|
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
3194 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
|
3195 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
|
3196 memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4); |
| 1633 | 3197 |
| 3198 if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){ | |
| 3199 memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4); | |
| 3200 }else{ | |
|
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
3201 memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4); |
| 1633 | 3202 } |
| 3203 | |
| 3204 if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){ | |
| 3205 *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1]; | |
| 3206 *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1]; | |
| 3207 }else{ | |
|
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
3208 *(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
|
3209 *(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride]; |
| 1633 | 3210 } |
| 3211 | |
| 3212 if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){ | |
| 3213 *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2]; | |
| 3214 *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2]; | |
| 3215 }else{ | |
|
1668
30746f429df6
move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents:
1662
diff
changeset
|
3216 *(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
|
3217 *(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride]; |
| 1633 | 3218 } |
| 3219 | |
| 3220 mx = 0; | |
| 3221 my = 0; | |
| 3222 for(i=0;i<4;i++) { | |
| 3223 const int x= (i&1)+1; | |
| 3224 const int y= (i>>1)+1; | |
| 3225 int16_t mv[5][2]= { | |
| 3226 {mv_cache[y][x ][0], mv_cache[y][x ][1]}, | |
| 3227 {mv_cache[y-1][x][0], mv_cache[y-1][x][1]}, | |
| 3228 {mv_cache[y][x-1][0], mv_cache[y][x-1][1]}, | |
| 3229 {mv_cache[y][x+1][0], mv_cache[y][x+1][1]}, | |
| 3230 {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}}; | |
| 3231 //FIXME cleanup | |
| 3232 obmc_motion(s, dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize, | |
| 3233 ref_picture[0], | |
| 3234 mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8, | |
| 3235 pix_op[1], | |
| 3236 mv); | |
| 3237 | |
| 3238 mx += mv[0][0]; | |
| 3239 my += mv[0][1]; | |
| 3240 } | |
| 3241 if(!(s->flags&CODEC_FLAG_GRAY)) | |
| 3242 chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); | |
| 3243 | |
| 3244 return; | |
| 3245 } | |
| 3246 | |
| 0 | 3247 switch(s->mv_type) { |
| 3248 case MV_TYPE_16X16: | |
| 1042 | 3249 #ifdef CONFIG_RISKY |
| 255 | 3250 if(s->mcsel){ |
| 753 | 3251 if(s->real_sprite_warping_points==1){ |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3252 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
|
3253 ref_picture); |
| 753 | 3254 }else{ |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3255 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
|
3256 ref_picture); |
| 753 | 3257 } |
| 651 | 3258 }else if(s->quarter_sample){ |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3259 qpel_motion(s, dest_y, dest_cb, dest_cr, |
|
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3260 0, 0, 0, |
|
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3261 ref_picture, pix_op, qpix_op, |
| 255 | 3262 s->mv[dir][0][0], s->mv[dir][0][1], 16); |
| 936 | 3263 }else if(s->mspel){ |
| 3264 ff_mspel_motion(s, dest_y, dest_cb, dest_cr, | |
| 3265 ref_picture, pix_op, | |
| 3266 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
| 1042 | 3267 }else |
| 3268 #endif | |
| 3269 { | |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3270 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
|
3271 0, 0, 0, |
|
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3272 ref_picture, pix_op, |
| 255 | 3273 s->mv[dir][0][0], s->mv[dir][0][1], 16); |
| 3274 } | |
| 0 | 3275 break; |
| 3276 case MV_TYPE_8X8: | |
| 673 | 3277 mx = 0; |
| 3278 my = 0; | |
| 3279 if(s->quarter_sample){ | |
| 3280 for(i=0;i<4;i++) { | |
| 3281 motion_x = s->mv[dir][i][0]; | |
| 3282 motion_y = s->mv[dir][i][1]; | |
| 0 | 3283 |
| 673 | 3284 dxy = ((motion_y & 3) << 2) | (motion_x & 3); |
| 3285 src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8; | |
| 3286 src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8; | |
| 3287 | |
| 3288 /* WARNING: do no forget half pels */ | |
| 3289 src_x = clip(src_x, -16, s->width); | |
| 3290 if (src_x == s->width) | |
| 3291 dxy &= ~3; | |
| 3292 src_y = clip(src_y, -16, s->height); | |
| 3293 if (src_y == s->height) | |
| 3294 dxy &= ~12; | |
| 0 | 3295 |
| 673 | 3296 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); |
| 3297 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
|
3298 if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8 |
|
576861d6343a
emu_edge checks simplification and avoid redundant checks for mpeg1/2 if emu_edge is set
michael
parents:
1539
diff
changeset
|
3299 || (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
|
3300 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 | 3301 ptr= s->edge_emu_buffer; |
| 3302 } | |
| 3303 } | |
| 3304 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; | |
| 3305 qpix_op[1][dxy](dest, ptr, s->linesize); | |
| 3306 | |
| 3307 mx += s->mv[dir][i][0]/2; | |
| 3308 my += s->mv[dir][i][1]/2; | |
| 3309 } | |
| 3310 }else{ | |
| 3311 for(i=0;i<4;i++) { | |
| 1633 | 3312 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
|
3313 ref_picture[0], 0, 0, |
| 1633 | 3314 mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8, |
| 3315 s->width, s->height, s->linesize, | |
| 3316 s->h_edge_pos, s->v_edge_pos, | |
| 3317 8, 8, pix_op[1], | |
| 3318 s->mv[dir][i][0], s->mv[dir][i][1]); | |
| 673 | 3319 |
| 3320 mx += s->mv[dir][i][0]; | |
| 3321 my += s->mv[dir][i][1]; | |
| 554 | 3322 } |
| 0 | 3323 } |
| 673 | 3324 |
| 1633 | 3325 if(!(s->flags&CODEC_FLAG_GRAY)) |
| 3326 chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my); | |
| 0 | 3327 break; |
| 3328 case MV_TYPE_FIELD: | |
| 3329 if (s->picture_structure == PICT_FRAME) { | |
| 671 | 3330 if(s->quarter_sample){ |
| 1843 | 3331 for(i=0; i<2; i++){ |
| 3332 qpel_motion(s, dest_y, dest_cb, dest_cr, | |
| 3333 1, i, s->field_select[dir][i], | |
| 3334 ref_picture, pix_op, qpix_op, | |
| 3335 s->mv[dir][i][0], s->mv[dir][i][1], 8); | |
| 3336 } | |
| 671 | 3337 }else{ |
| 3338 /* top field */ | |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3339 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
|
3340 1, 0, s->field_select[dir][0], |
|
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3341 ref_picture, pix_op, |
| 671 | 3342 s->mv[dir][0][0], s->mv[dir][0][1], 8); |
| 3343 /* bottom field */ | |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3344 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
|
3345 1, 1, s->field_select[dir][1], |
|
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3346 ref_picture, pix_op, |
| 671 | 3347 s->mv[dir][1][0], s->mv[dir][1][1], 8); |
| 3348 } | |
| 0 | 3349 } else { |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3350 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
|
3351 ref_picture= s->current_picture_ptr->data; |
|
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
|
3352 } |
|
5e6e505d8997
field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
michaelni
parents:
1095
diff
changeset
|
3353 |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3354 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
|
3355 0, 0, s->field_select[dir][0], |
|
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3356 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
|
3357 s->mv[dir][0][0], s->mv[dir][0][1], 16); |
| 0 | 3358 } |
| 3359 break; | |
| 1843 | 3360 case MV_TYPE_16X8: |
| 3361 for(i=0; i<2; i++){ | |
| 3362 uint8_t ** ref2picture; | |
| 3363 | |
| 3364 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
|
3365 ref2picture= ref_picture; |
|
338a2f6e6402
Mpeg2 16x8 Patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1328
diff
changeset
|
3366 }else{ |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3367 ref2picture= s->current_picture_ptr->data; |
|
1339
338a2f6e6402
Mpeg2 16x8 Patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1328
diff
changeset
|
3368 } |
|
338a2f6e6402
Mpeg2 16x8 Patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1328
diff
changeset
|
3369 |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3370 mpeg_motion(s, dest_y, dest_cb, dest_cr, |
| 1843 | 3371 0, 0, s->field_select[dir][i], |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3372 ref2picture, pix_op, |
| 1843 | 3373 s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8); |
| 3374 | |
| 3375 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
|
3376 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
|
3377 dest_cr+= (16>>s->chroma_y_shift)*s->uvlinesize; |
| 1843 | 3378 } |
|
1339
338a2f6e6402
Mpeg2 16x8 Patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1328
diff
changeset
|
3379 break; |
|
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1317
diff
changeset
|
3380 case MV_TYPE_DMV: |
|
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1317
diff
changeset
|
3381 if(s->picture_structure == PICT_FRAME){ |
| 1843 | 3382 for(i=0; i<2; i++){ |
| 3383 int j; | |
| 3384 for(j=0; j<2; j++){ | |
| 3385 mpeg_motion(s, dest_y, dest_cb, dest_cr, | |
| 3386 1, j, j^i, | |
| 3387 ref_picture, pix_op, | |
| 3388 s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8); | |
| 3389 } | |
| 3390 pix_op = s->dsp.avg_pixels_tab; | |
| 3391 } | |
|
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1317
diff
changeset
|
3392 }else{ |
| 1843 | 3393 for(i=0; i<2; i++){ |
| 3394 mpeg_motion(s, dest_y, dest_cb, dest_cr, | |
| 3395 0, 0, s->picture_structure != i+1, | |
| 3396 ref_picture, pix_op, | |
| 3397 s->mv[dir][2*i][0],s->mv[dir][2*i][1],16); | |
| 3398 | |
| 3399 // after put we make avg of the same block | |
| 3400 pix_op=s->dsp.avg_pixels_tab; | |
| 3401 | |
| 3402 //opposite parity is always in the same frame if this is second field | |
| 3403 if(!s->first_field){ | |
| 3404 ref_picture = s->current_picture_ptr->data; | |
| 3405 } | |
|
1842
0d82db458a3c
interlaced mpeg4 + edge emu fix (fixes decoding of mermaid.avi)
michael
parents:
1838
diff
changeset
|
3406 } |
|
1326
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1317
diff
changeset
|
3407 } |
|
6cdd3b8f4fd3
DMV support patch by ("Ivan Kalvachev" <ivan at cacad dot com>)
michaelni
parents:
1317
diff
changeset
|
3408 break; |
| 1633 | 3409 default: assert(0); |
| 0 | 3410 } |
| 3411 } | |
| 3412 | |
| 2256 | 3413 /** |
| 3414 * motion compesation of a single macroblock | |
| 3415 * @param s context | |
| 3416 * @param dest_y luma destination pointer | |
| 3417 * @param dest_cb chroma cb/u destination pointer | |
| 3418 * @param dest_cr chroma cr/v destination pointer | |
| 3419 * @param dir direction (0->forward, 1->backward) | |
| 3420 * @param ref_picture array[3] of pointers to the 3 planes of the reference picture | |
| 3421 * @param pic_op halfpel motion compensation function (average or put normally) | |
| 3422 * the motion vectors are taken from s->mv and the MV type from s->mv_type | |
| 3423 */ | |
| 3424 static inline void MPV_motion_lowres(MpegEncContext *s, | |
| 3425 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, | |
| 3426 int dir, uint8_t **ref_picture, | |
| 3427 h264_chroma_mc_func *pix_op) | |
| 3428 { | |
| 2292 | 3429 int mx, my; |
| 2260 | 3430 int mb_x, mb_y, i; |
| 3431 const int lowres= s->avctx->lowres; | |
| 3432 const int block_s= 8>>lowres; | |
| 3433 | |
| 3434 mb_x = s->mb_x; | |
| 3435 mb_y = s->mb_y; | |
| 3436 | |
| 3437 switch(s->mv_type) { | |
| 3438 case MV_TYPE_16X16: | |
| 3439 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
| 3440 0, 0, 0, | |
| 3441 ref_picture, pix_op, | |
| 3442 s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s); | |
| 3443 break; | |
| 2292 | 3444 case MV_TYPE_8X8: |
| 2260 | 3445 mx = 0; |
| 3446 my = 0; | |
| 3447 for(i=0;i<4;i++) { | |
| 2292 | 3448 hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * s->linesize)*block_s, |
| 2260 | 3449 ref_picture[0], 0, 0, |
| 2292 | 3450 (2*mb_x + (i & 1))*block_s, (2*mb_y + (i >>1))*block_s, |
| 2260 | 3451 s->width, s->height, s->linesize, |
| 2292 | 3452 s->h_edge_pos >> lowres, s->v_edge_pos >> lowres, |
| 3453 block_s, block_s, pix_op, | |
| 2260 | 3454 s->mv[dir][i][0], s->mv[dir][i][1]); |
| 3455 | |
| 3456 mx += s->mv[dir][i][0]; | |
| 3457 my += s->mv[dir][i][1]; | |
| 3458 } | |
| 3459 | |
| 3460 if(!(s->flags&CODEC_FLAG_GRAY)) | |
| 2292 | 3461 chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, pix_op, mx, my); |
| 3462 break; | |
| 2260 | 3463 case MV_TYPE_FIELD: |
| 3464 if (s->picture_structure == PICT_FRAME) { | |
| 3465 /* top field */ | |
| 3466 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
| 3467 1, 0, s->field_select[dir][0], | |
| 3468 ref_picture, pix_op, | |
| 3469 s->mv[dir][0][0], s->mv[dir][0][1], block_s); | |
| 3470 /* bottom field */ | |
| 3471 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
| 3472 1, 1, s->field_select[dir][1], | |
| 3473 ref_picture, pix_op, | |
| 3474 s->mv[dir][1][0], s->mv[dir][1][1], block_s); | |
| 3475 } else { | |
| 3476 if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != B_TYPE && !s->first_field){ | |
| 3477 ref_picture= s->current_picture_ptr->data; | |
| 3478 } | |
| 3479 | |
| 3480 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
| 3481 0, 0, s->field_select[dir][0], | |
| 3482 ref_picture, pix_op, | |
| 3483 s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s); | |
| 3484 } | |
| 3485 break; | |
| 3486 case MV_TYPE_16X8: | |
| 3487 for(i=0; i<2; i++){ | |
| 3488 uint8_t ** ref2picture; | |
| 3489 | |
| 3490 if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){ | |
| 3491 ref2picture= ref_picture; | |
| 3492 }else{ | |
| 3493 ref2picture= s->current_picture_ptr->data; | |
| 3494 } | |
| 3495 | |
| 3496 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
| 3497 0, 0, s->field_select[dir][i], | |
| 3498 ref2picture, pix_op, | |
| 3499 s->mv[dir][i][0], s->mv[dir][i][1] + 2*block_s*i, block_s); | |
| 3500 | |
| 3501 dest_y += 2*block_s*s->linesize; | |
| 3502 dest_cb+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize; | |
| 3503 dest_cr+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize; | |
| 3504 } | |
| 3505 break; | |
| 3506 case MV_TYPE_DMV: | |
| 3507 if(s->picture_structure == PICT_FRAME){ | |
| 3508 for(i=0; i<2; i++){ | |
| 3509 int j; | |
| 3510 for(j=0; j<2; j++){ | |
| 3511 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
| 3512 1, j, j^i, | |
| 3513 ref_picture, pix_op, | |
| 3514 s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], block_s); | |
| 3515 } | |
| 3516 pix_op = s->dsp.avg_h264_chroma_pixels_tab; | |
| 3517 } | |
| 3518 }else{ | |
| 3519 for(i=0; i<2; i++){ | |
| 3520 mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
| 3521 0, 0, s->picture_structure != i+1, | |
| 3522 ref_picture, pix_op, | |
| 3523 s->mv[dir][2*i][0],s->mv[dir][2*i][1],2*block_s); | |
| 3524 | |
| 3525 // after put we make avg of the same block | |
| 3526 pix_op = s->dsp.avg_h264_chroma_pixels_tab; | |
| 3527 | |
| 3528 //opposite parity is always in the same frame if this is second field | |
| 3529 if(!s->first_field){ | |
| 3530 ref_picture = s->current_picture_ptr->data; | |
| 3531 } | |
| 3532 } | |
| 3533 } | |
| 3534 break; | |
| 3535 default: assert(0); | |
| 3536 } | |
| 2256 | 3537 } |
| 0 | 3538 |
| 3539 /* put block[] to dest[] */ | |
| 3540 static inline void put_dct(MpegEncContext *s, | |
| 1651 | 3541 DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale) |
| 0 | 3542 { |
| 1689 | 3543 s->dct_unquantize_intra(s, block, i, qscale); |
| 1092 | 3544 s->dsp.idct_put (dest, line_size, block); |
| 0 | 3545 } |
| 3546 | |
| 3547 /* add block[] to dest[] */ | |
| 3548 static inline void add_dct(MpegEncContext *s, | |
| 1064 | 3549 DCTELEM *block, int i, uint8_t *dest, int line_size) |
| 0 | 3550 { |
| 3551 if (s->block_last_index[i] >= 0) { | |
| 1092 | 3552 s->dsp.idct_add (dest, line_size, block); |
| 481 | 3553 } |
| 3554 } | |
| 3555 | |
| 3556 static inline void add_dequant_dct(MpegEncContext *s, | |
| 1644 | 3557 DCTELEM *block, int i, uint8_t *dest, int line_size, int qscale) |
| 481 | 3558 { |
| 3559 if (s->block_last_index[i] >= 0) { | |
| 1689 | 3560 s->dct_unquantize_inter(s, block, i, qscale); |
| 324 | 3561 |
| 1092 | 3562 s->dsp.idct_add (dest, line_size, block); |
| 0 | 3563 } |
| 3564 } | |
| 3565 | |
| 456 | 3566 /** |
| 3567 * cleans dc, ac, coded_block for the current non intra MB | |
| 3568 */ | |
| 3569 void ff_clean_intra_table_entries(MpegEncContext *s) | |
| 3570 { | |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
3571 int wrap = s->b8_stride; |
| 456 | 3572 int xy = s->block_index[0]; |
| 3573 | |
| 3574 s->dc_val[0][xy ] = | |
| 3575 s->dc_val[0][xy + 1 ] = | |
| 3576 s->dc_val[0][xy + wrap] = | |
| 3577 s->dc_val[0][xy + 1 + wrap] = 1024; | |
| 3578 /* ac pred */ | |
| 1064 | 3579 memset(s->ac_val[0][xy ], 0, 32 * sizeof(int16_t)); |
| 3580 memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(int16_t)); | |
| 456 | 3581 if (s->msmpeg4_version>=3) { |
| 3582 s->coded_block[xy ] = | |
| 3583 s->coded_block[xy + 1 ] = | |
| 3584 s->coded_block[xy + wrap] = | |
| 3585 s->coded_block[xy + 1 + wrap] = 0; | |
| 3586 } | |
| 3587 /* chroma */ | |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
3588 wrap = s->mb_stride; |
|
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
3589 xy = s->mb_x + s->mb_y * wrap; |
| 456 | 3590 s->dc_val[1][xy] = |
| 3591 s->dc_val[2][xy] = 1024; | |
| 3592 /* ac pred */ | |
| 1064 | 3593 memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t)); |
| 3594 memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t)); | |
| 456 | 3595 |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
3596 s->mbintra_table[xy]= 0; |
| 456 | 3597 } |
| 3598 | |
| 0 | 3599 /* generic function called after a macroblock has been parsed by the |
| 3600 decoder or after it has been encoded by the encoder. | |
| 3601 | |
| 3602 Important variables used: | |
| 3603 s->mb_intra : true if intra macroblock | |
| 3604 s->mv_dir : motion vector direction | |
| 3605 s->mv_type : motion vector type | |
| 3606 s->mv : motion vector | |
| 3607 s->interlaced_dct : true if interlaced dct used (mpeg2) | |
| 3608 */ | |
| 2256 | 3609 static always_inline void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], int lowres_flag) |
| 0 | 3610 { |
| 244 | 3611 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
|
3612 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; |
| 1381 | 3613 #ifdef HAVE_XVMC |
| 3614 if(s->avctx->xvmc_acceleration){ | |
|
1580
628bf341e099
XvMC speedup by removing one memcpy and doing MB packing
iive
parents:
1579
diff
changeset
|
3615 XVMC_decode_mb(s);//xvmc uses pblocks |
| 1381 | 3616 return; |
| 3617 } | |
| 3618 #endif | |
| 0 | 3619 |
| 3620 mb_x = s->mb_x; | |
| 3621 mb_y = s->mb_y; | |
| 3622 | |
|
1833
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3623 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
|
3624 /* save DCT coefficients */ |
|
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3625 int i,j; |
|
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3626 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
|
3627 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
|
3628 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
|
3629 *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
|
3630 } |
|
ba27ce284d07
export DCT coefficients patch by (Wolfgang Hesseler <wolfgang.hesseler at imk dot fraunhofer dot de>)
michael
parents:
1831
diff
changeset
|
3631 |
| 903 | 3632 s->current_picture.qscale_table[mb_xy]= s->qscale; |
|
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
3633 |
| 0 | 3634 /* update DC predictors for P macroblocks */ |
| 3635 if (!s->mb_intra) { | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3636 if (s->h263_pred || s->h263_aic) { |
| 481 | 3637 if(s->mbintra_table[mb_xy]) |
| 456 | 3638 ff_clean_intra_table_entries(s); |
| 0 | 3639 } else { |
| 456 | 3640 s->last_dc[0] = |
| 3641 s->last_dc[1] = | |
| 0 | 3642 s->last_dc[2] = 128 << s->intra_dc_precision; |
| 3643 } | |
| 3644 } | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3645 else if (s->h263_pred || s->h263_aic) |
| 481 | 3646 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
|
3647 |
|
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
3648 if ((s->flags&CODEC_FLAG_PSNR) || !(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { //FIXME precalc |
| 1064 | 3649 uint8_t *dest_y, *dest_cb, *dest_cr; |
| 481 | 3650 int dct_linesize, dct_offset; |
| 651 | 3651 op_pixels_func (*op_pix)[4]; |
| 3652 qpel_mc_func (*op_qpix)[16]; | |
| 1138 | 3653 const int linesize= s->current_picture.linesize[0]; //not s->linesize as this woulnd be wrong for field pics |
| 3654 const int uvlinesize= s->current_picture.linesize[1]; | |
| 2256 | 3655 const int readable= s->pict_type != B_TYPE || s->encoding || s->avctx->draw_horiz_band || lowres_flag; |
| 3656 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
|
3657 |
| 903 | 3658 /* avoid copy if macroblock skipped in last frame too */ |
| 3659 /* skip only during decoding as we might trash the buffers during encoding a bit */ | |
| 3660 if(!s->encoding){ | |
| 1064 | 3661 uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy]; |
| 903 | 3662 const int age= s->current_picture.age; |
| 3663 | |
| 3664 assert(age); | |
| 3665 | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
3666 if (s->mb_skiped) { |
| 903 | 3667 s->mb_skiped= 0; |
| 3668 assert(s->pict_type!=I_TYPE); | |
| 3669 | |
| 556 | 3670 (*mbskip_ptr) ++; /* indicate that this time we skiped it */ |
| 3671 if(*mbskip_ptr >99) *mbskip_ptr= 99; | |
| 3672 | |
| 903 | 3673 /* 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
|
3674 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
|
3675 return; |
| 903 | 3676 } |
|
1021
2d7c9f5738de
trying to fix mb skip bug in mpeg1/2 if slices are not used
michaelni
parents:
1014
diff
changeset
|
3677 } 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
|
3678 (*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
|
3679 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
|
3680 } else{ |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
3681 *mbskip_ptr = 0; /* not skipped */ |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
3682 } |
| 717 | 3683 } |
| 2256 | 3684 |
|
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3685 dct_linesize = linesize << s->interlaced_dct; |
| 2256 | 3686 dct_offset =(s->interlaced_dct)? linesize : linesize*block_size; |
| 3687 | |
| 1632 | 3688 if(readable){ |
| 3689 dest_y= s->dest[0]; | |
| 3690 dest_cb= s->dest[1]; | |
| 3691 dest_cr= s->dest[2]; | |
| 3692 }else{ | |
| 1799 | 3693 dest_y = s->b_scratchpad; |
| 1834 | 3694 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
|
3695 dest_cr= s->b_scratchpad+32*linesize; |
| 1632 | 3696 } |
| 2256 | 3697 |
| 0 | 3698 if (!s->mb_intra) { |
| 3699 /* motion handling */ | |
| 456 | 3700 /* decoding or more than one mb_type (MC was allready done otherwise) */ |
| 1389 | 3701 if(!s->encoding){ |
| 2256 | 3702 if(lowres_flag){ |
| 3703 h264_chroma_mc_func *op_pix = s->dsp.put_h264_chroma_pixels_tab; | |
| 3704 | |
| 3705 if (s->mv_dir & MV_DIR_FORWARD) { | |
| 3706 MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix); | |
| 3707 op_pix = s->dsp.avg_h264_chroma_pixels_tab; | |
| 3708 } | |
| 3709 if (s->mv_dir & MV_DIR_BACKWARD) { | |
| 3710 MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix); | |
| 3711 } | |
| 324 | 3712 }else{ |
| 2256 | 3713 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
| 3714 op_pix = s->dsp.put_pixels_tab; | |
| 3715 op_qpix= s->dsp.put_qpel_pixels_tab; | |
| 3716 }else{ | |
| 3717 op_pix = s->dsp.put_no_rnd_pixels_tab; | |
| 3718 op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab; | |
| 3719 } | |
| 3720 if (s->mv_dir & MV_DIR_FORWARD) { | |
| 3721 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix); | |
| 3722 op_pix = s->dsp.avg_pixels_tab; | |
| 3723 op_qpix= s->dsp.avg_qpel_pixels_tab; | |
| 3724 } | |
| 3725 if (s->mv_dir & MV_DIR_BACKWARD) { | |
| 3726 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix); | |
| 3727 } | |
| 324 | 3728 } |
| 0 | 3729 } |
| 3730 | |
| 481 | 3731 /* skip dequant / idct if we are really late ;) */ |
| 814 | 3732 if(s->hurry_up>1) return; |
| 481 | 3733 |
| 0 | 3734 /* add dct residue */ |
| 1421 | 3735 if(s->encoding || !( s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO |
| 711 | 3736 || (s->codec_id==CODEC_ID_MPEG4 && !s->mpeg_quant))){ |
| 2256 | 3737 add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); |
| 3738 add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); | |
| 3739 add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); | |
| 3740 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); | |
| 0 | 3741 |
| 485 | 3742 if(!(s->flags&CODEC_FLAG_GRAY)){ |
| 1644 | 3743 add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); |
| 3744 add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); | |
| 485 | 3745 } |
| 936 | 3746 } else if(s->codec_id != CODEC_ID_WMV2){ |
| 2256 | 3747 add_dct(s, block[0], 0, dest_y , dct_linesize); |
| 3748 add_dct(s, block[1], 1, dest_y + block_size, dct_linesize); | |
| 3749 add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize); | |
| 3750 add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize); | |
| 481 | 3751 |
| 485 | 3752 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
|
3753 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
|
3754 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
|
3755 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
|
3756 }else{ |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3757 //chroma422 |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3758 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
|
3759 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
|
3760 |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3761 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
|
3762 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
|
3763 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
|
3764 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
|
3765 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
|
3766 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
|
3767 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
|
3768 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
|
3769 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
|
3770 } |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3771 } |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3772 }//fi gray |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3773 } |
| 1042 | 3774 #ifdef CONFIG_RISKY |
| 3775 else{ | |
| 936 | 3776 ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr); |
| 481 | 3777 } |
| 1042 | 3778 #endif |
| 0 | 3779 } else { |
| 3780 /* dct only in intra block */ | |
| 1421 | 3781 if(s->encoding || !(s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO)){ |
| 2256 | 3782 put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); |
| 3783 put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); | |
| 3784 put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); | |
| 3785 put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); | |
| 0 | 3786 |
| 711 | 3787 if(!(s->flags&CODEC_FLAG_GRAY)){ |
| 1651 | 3788 put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); |
| 3789 put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); | |
| 711 | 3790 } |
| 3791 }else{ | |
| 2256 | 3792 s->dsp.idct_put(dest_y , dct_linesize, block[0]); |
| 3793 s->dsp.idct_put(dest_y + block_size, dct_linesize, block[1]); | |
| 3794 s->dsp.idct_put(dest_y + dct_offset , dct_linesize, block[2]); | |
| 3795 s->dsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]); | |
| 711 | 3796 |
| 3797 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
|
3798 if(s->chroma_y_shift){ |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3799 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
|
3800 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
|
3801 }else{ |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3802 |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3803 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
|
3804 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
|
3805 |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3806 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
|
3807 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
|
3808 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
|
3809 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
|
3810 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
|
3811 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
|
3812 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
|
3813 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
|
3814 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
|
3815 } |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3816 } |
|
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3817 }//gray |
| 485 | 3818 } |
| 0 | 3819 } |
| 1632 | 3820 if(!readable){ |
| 3821 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
|
3822 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
|
3823 s->dsp.put_pixels_tab[s->chroma_x_shift][0](s->dest[2], dest_cr, uvlinesize,16 >> s->chroma_y_shift); |
| 1632 | 3824 } |
| 0 | 3825 } |
| 294 | 3826 } |
| 3827 | |
| 2256 | 3828 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64]){ |
| 3829 if(s->avctx->lowres) MPV_decode_mb_internal(s, block, 1); | |
| 3830 else MPV_decode_mb_internal(s, block, 0); | |
| 3831 } | |
| 3832 | |
|
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
|
3833 #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
|
3834 |
|
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
3835 static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold) |
| 456 | 3836 { |
| 3837 static const char tab[64]= | |
| 3838 {3,2,2,1,1,1,1,1, | |
| 3839 1,1,1,1,1,1,1,1, | |
| 3840 1,1,1,1,1,1,1,1, | |
| 3841 0,0,0,0,0,0,0,0, | |
| 3842 0,0,0,0,0,0,0,0, | |
| 3843 0,0,0,0,0,0,0,0, | |
| 3844 0,0,0,0,0,0,0,0, | |
| 3845 0,0,0,0,0,0,0,0}; | |
| 3846 int score=0; | |
| 3847 int run=0; | |
| 3848 int i; | |
| 3849 DCTELEM *block= s->block[n]; | |
| 3850 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
|
3851 int skip_dc; |
| 456 | 3852 |
|
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
|
3853 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
|
3854 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
|
3855 threshold= -threshold; |
|
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
3856 }else |
|
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
3857 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
|
3858 |
| 456 | 3859 /* are all which we could set to zero are allready zero? */ |
| 3860 if(last_index<=skip_dc - 1) return; | |
| 3861 | |
| 3862 for(i=0; i<=last_index; i++){ | |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3863 const int j = s->intra_scantable.permutated[i]; |
| 456 | 3864 const int level = ABS(block[j]); |
| 3865 if(level==1){ | |
| 3866 if(skip_dc && i==0) continue; | |
| 3867 score+= tab[run]; | |
| 3868 run=0; | |
| 3869 }else if(level>1){ | |
| 3870 return; | |
| 3871 }else{ | |
| 3872 run++; | |
| 3873 } | |
| 3874 } | |
| 3875 if(score >= threshold) return; | |
| 3876 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
|
3877 const int j = s->intra_scantable.permutated[i]; |
| 456 | 3878 block[j]=0; |
| 3879 } | |
| 3880 if(block[0]) s->block_last_index[n]= 0; | |
| 3881 else s->block_last_index[n]= -1; | |
| 3882 } | |
| 3883 | |
| 344 | 3884 static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) |
| 3885 { | |
| 3886 int i; | |
| 3887 const int maxlevel= s->max_qcoeff; | |
| 3888 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
|
3889 int overflow=0; |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3890 |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3891 if(s->mb_intra){ |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3892 i=1; //skip clipping of intra dc |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3893 }else |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3894 i=0; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3895 |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3896 for(;i<=last_index; i++){ |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3897 const int j= s->intra_scantable.permutated[i]; |
| 344 | 3898 int level = block[j]; |
| 3899 | |
|
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
|
3900 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
|
3901 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
|
3902 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
|
3903 }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
|
3904 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
|
3905 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
|
3906 } |
|
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
|
3907 |
| 344 | 3908 block[j]= level; |
| 3909 } | |
|
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
|
3910 |
|
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
|
3911 if(overflow && s->avctx->mb_decision == FF_MB_DECISION_SIMPLE) |
|
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
|
3912 av_log(s->avctx, AV_LOG_INFO, "warning, cliping %d dct coefficents to %d..%d\n", overflow, minlevel, maxlevel); |
| 344 | 3913 } |
| 324 | 3914 |
|
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
|
3915 #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
|
3916 |
|
1098
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
3917 /** |
|
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
3918 * |
|
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
3919 * @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
|
3920 */ |
|
b7f267d168b7
mpeg2 field pictures + sliced mode (doesnt work with mplayer though, dunno why)
michaelni
parents:
1096
diff
changeset
|
3921 void ff_draw_horiz_band(MpegEncContext *s, int y, int h){ |
| 1368 | 3922 if (s->avctx->draw_horiz_band) { |
| 1370 | 3923 AVFrame *src; |
| 1368 | 3924 int offset[4]; |
| 1370 | 3925 |
| 3926 if(s->picture_structure != PICT_FRAME){ | |
| 3927 h <<= 1; | |
| 3928 y <<= 1; | |
| 3929 if(s->first_field && !(s->avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return; | |
| 3930 } | |
| 3931 | |
|
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
|
3932 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
|
3933 |
| 1370 | 3934 if(s->pict_type==B_TYPE || s->low_delay || (s->avctx->slice_flags&SLICE_FLAG_CODED_ORDER)) |
| 3935 src= (AVFrame*)s->current_picture_ptr; | |
| 3936 else if(s->last_picture_ptr) | |
| 3937 src= (AVFrame*)s->last_picture_ptr; | |
| 3938 else | |
| 3939 return; | |
| 3940 | |
| 1369 | 3941 if(s->pict_type==B_TYPE && s->picture_structure == PICT_FRAME && s->out_format != FMT_H264){ |
| 1368 | 3942 offset[0]= |
| 3943 offset[1]= | |
| 3944 offset[2]= | |
| 3945 offset[3]= 0; | |
| 3946 }else{ | |
| 3947 offset[0]= y * s->linesize;; | |
| 3948 offset[1]= | |
|
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3949 offset[2]= (y >> s->chroma_y_shift) * s->uvlinesize; |
| 1368 | 3950 offset[3]= 0; |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3951 } |
| 1368 | 3952 |
| 813 | 3953 emms_c(); |
| 3954 | |
| 1370 | 3955 s->avctx->draw_horiz_band(s->avctx, src, offset, |
| 3956 y, s->picture_structure, h); | |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3957 } |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3958 } |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
3959 |
| 1389 | 3960 void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename |
| 3961 const int linesize= s->current_picture.linesize[0]; //not s->linesize as this woulnd be wrong for field pics | |
| 3962 const int uvlinesize= s->current_picture.linesize[1]; | |
| 2256 | 3963 const int mb_size= 4 - s->avctx->lowres; |
| 1389 | 3964 |
|
1938
e2501e6e7ff7
unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents:
1918
diff
changeset
|
3965 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
|
3966 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
|
3967 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
|
3968 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
|
3969 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
|
3970 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
|
3971 //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
|
3972 |
| 2256 | 3973 s->dest[0] = s->current_picture.data[0] + ((s->mb_x - 1) << mb_size); |
| 3974 s->dest[1] = s->current_picture.data[1] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift)); | |
| 3975 s->dest[2] = s->current_picture.data[2] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift)); | |
| 2168 | 3976 |
|
2074
2faafe7a3db6
mpeg2 chroma422/444 support, may be slower, may be faster for other codecs
iive
parents:
2066
diff
changeset
|
3977 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
|
3978 { |
| 2256 | 3979 s->dest[0] += s->mb_y * linesize << mb_size; |
| 3980 s->dest[1] += s->mb_y * uvlinesize << (mb_size - s->chroma_y_shift); | |
| 3981 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
|
3982 } |
| 1389 | 3983 } |
| 3984 | |
|
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
|
3985 #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
|
3986 |
| 1777 | 3987 static void get_vissual_weight(int16_t *weight, uint8_t *ptr, int stride){ |
| 3988 int x, y; | |
| 3989 //FIXME optimize | |
| 3990 for(y=0; y<8; y++){ | |
| 3991 for(x=0; x<8; x++){ | |
| 3992 int x2, y2; | |
| 3993 int sum=0; | |
| 3994 int sqr=0; | |
| 3995 int count=0; | |
| 3996 | |
| 3997 for(y2= FFMAX(y-1, 0); y2 < FFMIN(8, y+2); y2++){ | |
| 3998 for(x2= FFMAX(x-1, 0); x2 < FFMIN(8, x+2); x2++){ | |
| 3999 int v= ptr[x2 + y2*stride]; | |
| 4000 sum += v; | |
| 4001 sqr += v*v; | |
| 4002 count++; | |
| 4003 } | |
| 4004 } | |
| 4005 weight[x + 8*y]= (36*ff_sqrt(count*sqr - sum*sum)) / count; | |
| 4006 } | |
| 4007 } | |
| 4008 } | |
| 4009 | |
| 324 | 4010 static void encode_mb(MpegEncContext *s, int motion_x, int motion_y) |
| 294 | 4011 { |
| 1777 | 4012 int16_t weight[6][64]; |
| 4013 DCTELEM orig[6][64]; | |
| 294 | 4014 const int mb_x= s->mb_x; |
| 4015 const int mb_y= s->mb_y; | |
| 4016 int i; | |
| 456 | 4017 int skip_dct[6]; |
| 697 | 4018 int dct_offset = s->linesize*8; //default for progressive frames |
| 1778 | 4019 uint8_t *ptr_y, *ptr_cb, *ptr_cr; |
| 4020 int wrap_y, wrap_c; | |
| 697 | 4021 |
| 456 | 4022 for(i=0; i<6; i++) skip_dct[i]=0; |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
4023 |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
4024 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
|
4025 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
|
4026 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
|
4027 |
|
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
|
4028 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
|
4029 update_qscale(s); |
| 1616 | 4030 |
| 4031 if(!(s->flags&CODEC_FLAG_QP_RD)){ | |
| 4032 s->dquant= s->qscale - last_qp; | |
| 4033 | |
|
1805
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4034 if(s->out_format==FMT_H263){ |
| 1616 | 4035 s->dquant= clip(s->dquant, -2, 2); //FIXME RD |
| 697 | 4036 |
|
1805
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4037 if(s->codec_id==CODEC_ID_MPEG4){ |
|
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4038 if(!s->mb_intra){ |
|
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4039 if(s->pict_type == B_TYPE){ |
|
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4040 if(s->dquant&1) |
|
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4041 s->dquant= (s->dquant/2)*2; |
|
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4042 if(s->mv_dir&MV_DIRECT) |
|
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4043 s->dquant= 0; |
|
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4044 } |
|
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4045 if(s->mv_type==MV_TYPE_8X8) |
|
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4046 s->dquant=0; |
|
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4047 } |
| 1616 | 4048 } |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
4049 } |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
4050 } |
| 1652 | 4051 ff_set_qscale(s, last_qp + s->dquant); |
| 2054 | 4052 }else if(s->flags&CODEC_FLAG_QP_RD) |
| 4053 ff_set_qscale(s, s->qscale + s->dquant); | |
| 294 | 4054 |
| 1778 | 4055 wrap_y = s->linesize; |
| 4056 wrap_c = s->uvlinesize; | |
| 4057 ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16; | |
| 4058 ptr_cb = s->new_picture.data[1] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
| 4059 ptr_cr = s->new_picture.data[2] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
| 4060 | |
| 4061 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
|
4062 uint8_t *ebuf= s->edge_emu_buffer + 32; |
|
5ca07515a309
10l (dont store 2 different things at the same place ...)
michael
parents:
2132
diff
changeset
|
4063 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
|
4064 ptr_y= ebuf; |
|
5ca07515a309
10l (dont store 2 different things at the same place ...)
michael
parents:
2132
diff
changeset
|
4065 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
|
4066 ptr_cb= ebuf+18*wrap_y; |
|
5ca07515a309
10l (dont store 2 different things at the same place ...)
michael
parents:
2132
diff
changeset
|
4067 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
|
4068 ptr_cr= ebuf+18*wrap_y+8; |
| 1778 | 4069 } |
| 4070 | |
| 324 | 4071 if (s->mb_intra) { |
| 697 | 4072 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ |
| 4073 int progressive_score, interlaced_score; | |
| 1708 | 4074 |
| 1729 | 4075 s->interlaced_dct=0; |
| 1777 | 4076 progressive_score= s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y, 8) |
| 4077 +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y*8, NULL, wrap_y, 8) - 400; | |
| 1729 | 4078 |
| 4079 if(progressive_score > 0){ | |
| 1777 | 4080 interlaced_score = s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y*2, 8) |
| 4081 +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y , NULL, wrap_y*2, 8); | |
| 1729 | 4082 if(progressive_score > interlaced_score){ |
| 4083 s->interlaced_dct=1; | |
| 697 | 4084 |
| 1729 | 4085 dct_offset= wrap_y; |
| 4086 wrap_y<<=1; | |
| 4087 } | |
| 4088 } | |
| 697 | 4089 } |
| 4090 | |
| 1777 | 4091 s->dsp.get_pixels(s->block[0], ptr_y , wrap_y); |
| 4092 s->dsp.get_pixels(s->block[1], ptr_y + 8, wrap_y); | |
| 4093 s->dsp.get_pixels(s->block[2], ptr_y + dct_offset , wrap_y); | |
| 4094 s->dsp.get_pixels(s->block[3], ptr_y + dct_offset + 8, wrap_y); | |
| 294 | 4095 |
| 487 | 4096 if(s->flags&CODEC_FLAG_GRAY){ |
| 4097 skip_dct[4]= 1; | |
| 4098 skip_dct[5]= 1; | |
| 4099 }else{ | |
| 1777 | 4100 s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c); |
| 4101 s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c); | |
| 4102 } | |
| 324 | 4103 }else{ |
| 651 | 4104 op_pixels_func (*op_pix)[4]; |
| 4105 qpel_mc_func (*op_qpix)[16]; | |
| 1064 | 4106 uint8_t *dest_y, *dest_cb, *dest_cr; |
| 294 | 4107 |
| 1389 | 4108 dest_y = s->dest[0]; |
| 4109 dest_cb = s->dest[1]; | |
| 4110 dest_cr = s->dest[2]; | |
| 324 | 4111 |
| 327 | 4112 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
|
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
4113 op_pix = s->dsp.put_pixels_tab; |
|
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
4114 op_qpix= s->dsp.put_qpel_pixels_tab; |
| 295 | 4115 }else{ |
|
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
4116 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
|
4117 op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab; |
| 324 | 4118 } |
| 295 | 4119 |
| 324 | 4120 if (s->mv_dir & MV_DIR_FORWARD) { |
| 903 | 4121 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
|
4122 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
|
4123 op_qpix= s->dsp.avg_qpel_pixels_tab; |
| 324 | 4124 } |
| 4125 if (s->mv_dir & MV_DIR_BACKWARD) { | |
| 903 | 4126 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix); |
| 324 | 4127 } |
| 295 | 4128 |
| 697 | 4129 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ |
| 4130 int progressive_score, interlaced_score; | |
| 1729 | 4131 |
| 4132 s->interlaced_dct=0; | |
| 4133 progressive_score= s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y, 8) | |
| 4134 +s->dsp.ildct_cmp[0](s, dest_y + wrap_y*8, ptr_y + wrap_y*8, wrap_y, 8) - 400; | |
| 697 | 4135 |
| 1729 | 4136 if(s->avctx->ildct_cmp == FF_CMP_VSSE) progressive_score -= 400; |
| 4137 | |
| 4138 if(progressive_score>0){ | |
| 4139 interlaced_score = s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y*2, 8) | |
| 4140 +s->dsp.ildct_cmp[0](s, dest_y + wrap_y , ptr_y + wrap_y , wrap_y*2, 8); | |
| 697 | 4141 |
| 1729 | 4142 if(progressive_score > interlaced_score){ |
| 4143 s->interlaced_dct=1; | |
| 4144 | |
| 4145 dct_offset= wrap_y; | |
| 4146 wrap_y<<=1; | |
| 4147 } | |
| 4148 } | |
| 697 | 4149 } |
| 4150 | |
|
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
4151 s->dsp.diff_pixels(s->block[0], ptr_y , dest_y , wrap_y); |
|
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
4152 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
|
4153 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
|
4154 s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y); |
| 487 | 4155 |
| 4156 if(s->flags&CODEC_FLAG_GRAY){ | |
| 4157 skip_dct[4]= 1; | |
| 4158 skip_dct[5]= 1; | |
| 4159 }else{ | |
|
853
eacc2dd8fd9d
* using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents:
847
diff
changeset
|
4160 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
|
4161 s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); |
| 487 | 4162 } |
| 456 | 4163 /* 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
|
4164 if(s->current_picture.mc_mb_var[s->mb_stride*mb_y+ mb_x]<2*s->qscale*s->qscale){ |
| 697 | 4165 //FIXME optimize |
| 1708 | 4166 if(s->dsp.sad[1](NULL, ptr_y , dest_y , wrap_y, 8) < 20*s->qscale) skip_dct[0]= 1; |
| 4167 if(s->dsp.sad[1](NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20*s->qscale) skip_dct[1]= 1; | |
| 4168 if(s->dsp.sad[1](NULL, ptr_y +dct_offset , dest_y +dct_offset , wrap_y, 8) < 20*s->qscale) skip_dct[2]= 1; | |
| 4169 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; | |
| 4170 if(s->dsp.sad[1](NULL, ptr_cb , dest_cb , wrap_c, 8) < 20*s->qscale) skip_dct[4]= 1; | |
| 4171 if(s->dsp.sad[1](NULL, ptr_cr , dest_cr , wrap_c, 8) < 20*s->qscale) skip_dct[5]= 1; | |
| 456 | 4172 } |
| 1778 | 4173 } |
| 4174 | |
| 4175 if(s->avctx->quantizer_noise_shaping){ | |
| 4176 if(!skip_dct[0]) get_vissual_weight(weight[0], ptr_y , wrap_y); | |
| 4177 if(!skip_dct[1]) get_vissual_weight(weight[1], ptr_y + 8, wrap_y); | |
| 4178 if(!skip_dct[2]) get_vissual_weight(weight[2], ptr_y + dct_offset , wrap_y); | |
| 4179 if(!skip_dct[3]) get_vissual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y); | |
| 4180 if(!skip_dct[4]) get_vissual_weight(weight[4], ptr_cb , wrap_c); | |
| 4181 if(!skip_dct[5]) get_vissual_weight(weight[5], ptr_cr , wrap_c); | |
| 4182 memcpy(orig[0], s->block[0], sizeof(DCTELEM)*64*6); | |
| 294 | 4183 } |
| 4184 | |
| 4185 /* DCT & quantize */ | |
| 1778 | 4186 assert(s->out_format!=FMT_MJPEG || s->qscale==8); |
| 4187 { | |
| 344 | 4188 for(i=0;i<6;i++) { |
| 456 | 4189 if(!skip_dct[i]){ |
| 4190 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
|
4191 s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); |
| 344 | 4192 // 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
|
4193 // 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
|
4194 // of improve it. Just INTRADC clipping deserves changes in quantizer |
| 456 | 4195 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
| 4196 }else | |
| 4197 s->block_last_index[i]= -1; | |
| 344 | 4198 } |
| 1777 | 4199 if(s->avctx->quantizer_noise_shaping){ |
| 4200 for(i=0;i<6;i++) { | |
| 4201 if(!skip_dct[i]){ | |
| 4202 s->block_last_index[i] = dct_quantize_refine(s, s->block[i], weight[i], orig[i], i, s->qscale); | |
| 4203 } | |
| 4204 } | |
| 4205 } | |
|
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
4206 |
| 456 | 4207 if(s->luma_elim_threshold && !s->mb_intra) |
| 4208 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
|
4209 dct_single_coeff_elimination(s, i, s->luma_elim_threshold); |
| 456 | 4210 if(s->chroma_elim_threshold && !s->mb_intra) |
| 4211 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
|
4212 dct_single_coeff_elimination(s, i, s->chroma_elim_threshold); |
| 1497 | 4213 |
| 4214 if(s->flags & CODEC_FLAG_CBP_RD){ | |
| 4215 for(i=0;i<6;i++) { | |
| 4216 if(s->block_last_index[i] == -1) | |
| 4217 s->coded_score[i]= INT_MAX/256; | |
| 4218 } | |
| 4219 } | |
| 294 | 4220 } |
| 4221 | |
| 487 | 4222 if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){ |
| 4223 s->block_last_index[4]= | |
| 4224 s->block_last_index[5]= 0; | |
| 4225 s->block[4][0]= | |
| 1011 | 4226 s->block[5][0]= (1024 + s->c_dc_scale/2)/ s->c_dc_scale; |
| 487 | 4227 } |
| 4228 | |
| 1708 | 4229 //non c quantize code returns incorrect block_last_index FIXME |
| 4230 if(s->alternate_scan && s->dct_quantize != dct_quantize_c){ | |
| 4231 for(i=0; i<6; i++){ | |
| 4232 int j; | |
| 4233 if(s->block_last_index[i]>0){ | |
| 4234 for(j=63; j>0; j--){ | |
| 4235 if(s->block[i][ s->intra_scantable.permutated[j] ]) break; | |
| 4236 } | |
| 4237 s->block_last_index[i]= j; | |
| 4238 } | |
| 4239 } | |
| 4240 } | |
| 4241 | |
| 294 | 4242 /* huffman encode */ |
| 936 | 4243 switch(s->codec_id){ //FIXME funct ptr could be slightly faster |
| 4244 case CODEC_ID_MPEG1VIDEO: | |
| 1421 | 4245 case CODEC_ID_MPEG2VIDEO: |
| 936 | 4246 mpeg1_encode_mb(s, s->block, motion_x, motion_y); break; |
| 1042 | 4247 #ifdef CONFIG_RISKY |
| 936 | 4248 case CODEC_ID_MPEG4: |
| 4249 mpeg4_encode_mb(s, s->block, motion_x, motion_y); break; | |
| 4250 case CODEC_ID_MSMPEG4V2: | |
| 4251 case CODEC_ID_MSMPEG4V3: | |
| 4252 case CODEC_ID_WMV1: | |
| 4253 msmpeg4_encode_mb(s, s->block, motion_x, motion_y); break; | |
| 4254 case CODEC_ID_WMV2: | |
| 4255 ff_wmv2_encode_mb(s, s->block, motion_x, motion_y); break; | |
|
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
4256 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
|
4257 ff_h261_encode_mb(s, s->block, motion_x, motion_y); break; |
| 936 | 4258 case CODEC_ID_H263: |
| 4259 case CODEC_ID_H263P: | |
|
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4260 case CODEC_ID_FLV1: |
| 936 | 4261 case CODEC_ID_RV10: |
| 2380 | 4262 case CODEC_ID_RV20: |
| 936 | 4263 h263_encode_mb(s, s->block, motion_x, motion_y); break; |
| 1042 | 4264 #endif |
| 4265 case CODEC_ID_MJPEG: | |
| 4266 mjpeg_encode_mb(s, s->block); break; | |
| 936 | 4267 default: |
| 4268 assert(0); | |
| 294 | 4269 } |
| 4270 } | |
| 4271 | |
|
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
|
4272 #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
|
4273 |
| 1368 | 4274 void ff_mpeg_flush(AVCodecContext *avctx){ |
| 4275 int i; | |
| 4276 MpegEncContext *s = avctx->priv_data; | |
| 4277 | |
| 1751 | 4278 if(s==NULL || s->picture==NULL) |
| 4279 return; | |
| 4280 | |
| 1368 | 4281 for(i=0; i<MAX_PICTURE_COUNT; i++){ |
| 4282 if(s->picture[i].data[0] && ( s->picture[i].type == FF_BUFFER_TYPE_INTERNAL | |
| 4283 || s->picture[i].type == FF_BUFFER_TYPE_USER)) | |
| 4284 avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]); | |
| 4285 } | |
| 1601 | 4286 s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL; |
| 1395 | 4287 |
| 2380 | 4288 s->mb_x= s->mb_y= 0; |
| 4289 | |
| 1395 | 4290 s->parse_context.state= -1; |
| 4291 s->parse_context.frame_start_found= 0; | |
| 4292 s->parse_context.overread= 0; | |
| 4293 s->parse_context.overread_index= 0; | |
| 4294 s->parse_context.index= 0; | |
| 4295 s->parse_context.last_index= 0; | |
| 1851 | 4296 s->bitstream_buffer_size=0; |
| 1368 | 4297 } |
| 4298 | |
|
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
|
4299 #ifdef CONFIG_ENCODERS |
| 1064 | 4300 void ff_copy_bits(PutBitContext *pb, uint8_t *src, int length) |
| 294 | 4301 { |
| 1810 | 4302 const uint16_t *srcw= (uint16_t*)src; |
| 1799 | 4303 int words= length>>4; |
| 326 | 4304 int bits= length&15; |
| 4305 int i; | |
| 4306 | |
| 456 | 4307 if(length==0) return; |
| 1799 | 4308 |
| 1803 | 4309 if(words < 16){ |
| 4310 for(i=0; i<words; i++) put_bits(pb, 16, be2me_16(srcw[i])); | |
| 4311 }else if(put_bits_count(pb)&7){ | |
| 4312 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
|
4313 }else{ |
| 1803 | 4314 for(i=0; put_bits_count(pb)&31; i++) |
| 4315 put_bits(pb, 8, src[i]); | |
| 1799 | 4316 flush_put_bits(pb); |
| 1803 | 4317 memcpy(pbBufPtr(pb), src+i, 2*words-i); |
| 4318 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
|
4319 } |
| 1799 | 4320 |
| 1803 | 4321 put_bits(pb, bits, be2me_16(srcw[words])>>(16-bits)); |
| 0 | 4322 } |
| 4323 | |
| 456 | 4324 static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
| 326 | 4325 int i; |
| 4326 | |
| 4327 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
| 4328 | |
| 4329 /* mpeg1 */ | |
| 1160 | 4330 d->mb_skip_run= s->mb_skip_run; |
| 326 | 4331 for(i=0; i<3; i++) |
| 4332 d->last_dc[i]= s->last_dc[i]; | |
| 4333 | |
| 4334 /* statistics */ | |
| 4335 d->mv_bits= s->mv_bits; | |
| 4336 d->i_tex_bits= s->i_tex_bits; | |
| 4337 d->p_tex_bits= s->p_tex_bits; | |
| 4338 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
|
4339 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
|
4340 d->b_count= s->b_count; |
| 326 | 4341 d->skip_count= s->skip_count; |
| 4342 d->misc_bits= s->misc_bits; | |
| 329 | 4343 d->last_bits= 0; |
| 327 | 4344 |
| 1389 | 4345 d->mb_skiped= 0; |
| 912 | 4346 d->qscale= s->qscale; |
| 1616 | 4347 d->dquant= s->dquant; |
| 326 | 4348 } |
| 4349 | |
| 456 | 4350 static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
| 326 | 4351 int i; |
| 4352 | |
| 4353 memcpy(d->mv, s->mv, 2*4*2*sizeof(int)); | |
| 4354 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
| 4355 | |
| 4356 /* mpeg1 */ | |
| 1160 | 4357 d->mb_skip_run= s->mb_skip_run; |
| 326 | 4358 for(i=0; i<3; i++) |
| 4359 d->last_dc[i]= s->last_dc[i]; | |
| 4360 | |
| 4361 /* statistics */ | |
| 4362 d->mv_bits= s->mv_bits; | |
| 4363 d->i_tex_bits= s->i_tex_bits; | |
| 4364 d->p_tex_bits= s->p_tex_bits; | |
| 4365 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
|
4366 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
|
4367 d->b_count= s->b_count; |
| 326 | 4368 d->skip_count= s->skip_count; |
| 4369 d->misc_bits= s->misc_bits; | |
| 4370 | |
| 4371 d->mb_intra= s->mb_intra; | |
| 327 | 4372 d->mb_skiped= s->mb_skiped; |
| 326 | 4373 d->mv_type= s->mv_type; |
| 4374 d->mv_dir= s->mv_dir; | |
| 4375 d->pb= s->pb; | |
| 456 | 4376 if(s->data_partitioning){ |
| 4377 d->pb2= s->pb2; | |
| 4378 d->tex_pb= s->tex_pb; | |
| 4379 } | |
| 326 | 4380 d->block= s->block; |
| 4381 for(i=0; i<6; i++) | |
| 4382 d->block_last_index[i]= s->block_last_index[i]; | |
| 755 | 4383 d->interlaced_dct= s->interlaced_dct; |
| 912 | 4384 d->qscale= s->qscale; |
| 326 | 4385 } |
| 4386 | |
| 456 | 4387 static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type, |
| 4388 PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2], | |
| 4389 int *dmin, int *next_block, int motion_x, int motion_y) | |
| 4390 { | |
| 1389 | 4391 int score; |
| 4392 uint8_t *dest_backup[3]; | |
| 456 | 4393 |
| 4394 copy_context_before_encode(s, backup, type); | |
| 4395 | |
| 4396 s->block= s->blocks[*next_block]; | |
| 4397 s->pb= pb[*next_block]; | |
| 4398 if(s->data_partitioning){ | |
| 4399 s->pb2 = pb2 [*next_block]; | |
| 4400 s->tex_pb= tex_pb[*next_block]; | |
| 4401 } | |
| 1389 | 4402 |
| 4403 if(*next_block){ | |
| 4404 memcpy(dest_backup, s->dest, sizeof(s->dest)); | |
| 1799 | 4405 s->dest[0] = s->rd_scratchpad; |
| 4406 s->dest[1] = s->rd_scratchpad + 16*s->linesize; | |
| 4407 s->dest[2] = s->rd_scratchpad + 16*s->linesize + 8; | |
| 4408 assert(s->linesize >= 32); //FIXME | |
| 1389 | 4409 } |
| 456 | 4410 |
| 4411 encode_mb(s, motion_x, motion_y); | |
| 1389 | 4412 |
| 1786 | 4413 score= put_bits_count(&s->pb); |
| 456 | 4414 if(s->data_partitioning){ |
| 1786 | 4415 score+= put_bits_count(&s->pb2); |
| 4416 score+= put_bits_count(&s->tex_pb); | |
| 456 | 4417 } |
| 1389 | 4418 |
| 4419 if(s->avctx->mb_decision == FF_MB_DECISION_RD){ | |
| 4420 MPV_decode_mb(s, s->block); | |
| 4421 | |
|
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
|
4422 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
|
4423 score += sse_mb(s) << FF_LAMBDA_SHIFT; |
| 1389 | 4424 } |
| 4425 | |
| 4426 if(*next_block){ | |
| 4427 memcpy(s->dest, dest_backup, sizeof(s->dest)); | |
| 4428 } | |
| 4429 | |
| 4430 if(score<*dmin){ | |
| 4431 *dmin= score; | |
| 456 | 4432 *next_block^=1; |
| 4433 | |
| 4434 copy_context_after_encode(best, s, type); | |
| 4435 } | |
| 4436 } | |
|
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4437 |
| 1389 | 4438 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
|
4439 uint32_t *sq = squareTbl + 256; |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4440 int acc=0; |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4441 int x,y; |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4442 |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4443 if(w==16 && h==16) |
| 1708 | 4444 return s->dsp.sse[0](NULL, src1, src2, stride, 16); |
| 936 | 4445 else if(w==8 && h==8) |
| 1708 | 4446 return s->dsp.sse[1](NULL, src1, src2, stride, 8); |
|
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4447 |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4448 for(y=0; y<h; y++){ |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4449 for(x=0; x<w; x++){ |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4450 acc+= sq[src1[x + y*stride] - src2[x + y*stride]]; |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4451 } |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4452 } |
| 936 | 4453 |
| 4454 assert(acc>=0); | |
| 4455 | |
|
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4456 return acc; |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4457 } |
| 326 | 4458 |
| 1389 | 4459 static int sse_mb(MpegEncContext *s){ |
| 4460 int w= 16; | |
| 4461 int h= 16; | |
| 4462 | |
| 4463 if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16; | |
| 4464 if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; | |
| 4465 | |
| 4466 if(w==16 && h==16) | |
|
2065
9e4bebc39ade
noise preserving sum of squares comparission function
michael
parents:
2063
diff
changeset
|
4467 if(s->avctx->mb_cmp == FF_CMP_NSSE){ |
| 2066 | 4468 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) |
| 4469 +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) | |
| 4470 +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
|
4471 }else{ |
| 1708 | 4472 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) |
| 4473 +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) | |
| 4474 +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
|
4475 } |
| 1389 | 4476 else |
| 4477 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) | |
| 4478 +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) | |
| 4479 +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); | |
| 4480 } | |
| 4481 | |
| 1799 | 4482 static int pre_estimate_motion_thread(AVCodecContext *c, void *arg){ |
| 4483 MpegEncContext *s= arg; | |
| 4484 | |
| 4485 | |
| 4486 s->me.pre_pass=1; | |
| 4487 s->me.dia_size= s->avctx->pre_dia_size; | |
| 4488 s->first_slice_line=1; | |
| 4489 for(s->mb_y= s->end_mb_y-1; s->mb_y >= s->start_mb_y; s->mb_y--) { | |
| 4490 for(s->mb_x=s->mb_width-1; s->mb_x >=0 ;s->mb_x--) { | |
| 4491 ff_pre_estimate_p_frame_motion(s, s->mb_x, s->mb_y); | |
| 4492 } | |
| 4493 s->first_slice_line=0; | |
| 4494 } | |
| 4495 | |
| 4496 s->me.pre_pass=0; | |
| 4497 | |
| 4498 return 0; | |
| 4499 } | |
| 4500 | |
| 4501 static int estimate_motion_thread(AVCodecContext *c, void *arg){ | |
| 4502 MpegEncContext *s= arg; | |
| 4503 | |
| 4504 s->me.dia_size= s->avctx->dia_size; | |
| 4505 s->first_slice_line=1; | |
| 4506 for(s->mb_y= s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { | |
| 4507 s->mb_x=0; //for block init below | |
| 4508 ff_init_block_index(s); | |
| 4509 for(s->mb_x=0; s->mb_x < s->mb_width; s->mb_x++) { | |
| 4510 s->block_index[0]+=2; | |
| 4511 s->block_index[1]+=2; | |
| 4512 s->block_index[2]+=2; | |
| 4513 s->block_index[3]+=2; | |
| 4514 | |
| 4515 /* compute motion vector & mb_type and store in context */ | |
| 4516 if(s->pict_type==B_TYPE) | |
| 4517 ff_estimate_b_frame_motion(s, s->mb_x, s->mb_y); | |
| 4518 else | |
| 4519 ff_estimate_p_frame_motion(s, s->mb_x, s->mb_y); | |
| 4520 } | |
| 4521 s->first_slice_line=0; | |
| 4522 } | |
| 4523 return 0; | |
| 4524 } | |
| 4525 | |
|
1804
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4526 static int mb_var_thread(AVCodecContext *c, void *arg){ |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4527 MpegEncContext *s= arg; |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4528 int mb_x, mb_y; |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4529 |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4530 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
|
4531 for(mb_x=0; mb_x < s->mb_width; mb_x++) { |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4532 int xx = mb_x * 16; |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4533 int yy = mb_y * 16; |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4534 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
|
4535 int varc; |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4536 int sum = s->dsp.pix_sum(pix, s->linesize); |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4537 |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4538 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
|
4539 |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4540 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
|
4541 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
|
4542 s->me.mb_var_sum_temp += varc; |
|
1804
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4543 } |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4544 } |
|
1805
5dd5b2052f5b
mpeg4 b frame + adaptive quantization assertion failure fix
michael
parents:
1804
diff
changeset
|
4545 return 0; |
|
1804
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4546 } |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
4547 |
| 1799 | 4548 static void write_slice_end(MpegEncContext *s){ |
| 4549 if(s->codec_id==CODEC_ID_MPEG4){ | |
| 4550 if(s->partitioned_frame){ | |
| 4551 ff_mpeg4_merge_partitions(s); | |
| 4552 } | |
| 4553 | |
| 4554 ff_mpeg4_stuffing(&s->pb); | |
| 4555 }else if(s->out_format == FMT_MJPEG){ | |
| 4556 ff_mjpeg_stuffing(&s->pb); | |
| 4557 } | |
| 4558 | |
| 4559 align_put_bits(&s->pb); | |
| 4560 flush_put_bits(&s->pb); | |
|
2428
548c87c06dbb
assertion about bits statistic and minor bits stat fix
michael
parents:
2427
diff
changeset
|
4561 |
|
548c87c06dbb
assertion about bits statistic and minor bits stat fix
michael
parents:
2427
diff
changeset
|
4562 if((s->flags&CODEC_FLAG_PASS1) && !s->partitioned_frame) |
|
548c87c06dbb
assertion about bits statistic and minor bits stat fix
michael
parents:
2427
diff
changeset
|
4563 s->misc_bits+= get_bits_diff(s); |
| 1799 | 4564 } |
| 4565 | |
| 4566 static int encode_thread(AVCodecContext *c, void *arg){ | |
| 4567 MpegEncContext *s= arg; | |
| 766 | 4568 int mb_x, mb_y, pdif = 0; |
| 1708 | 4569 int i, j; |
| 326 | 4570 MpegEncContext best_s, backup_s; |
| 2422 | 4571 uint8_t bit_buf[2][MAX_MB_BYTES]; |
| 4572 uint8_t bit_buf2[2][MAX_MB_BYTES]; | |
| 4573 uint8_t bit_buf_tex[2][MAX_MB_BYTES]; | |
| 456 | 4574 PutBitContext pb[2], pb2[2], tex_pb[2]; |
| 1799 | 4575 //printf("%d->%d\n", s->resync_mb_y, s->end_mb_y); |
| 456 | 4576 |
| 4577 for(i=0; i<2; i++){ | |
| 2422 | 4578 init_put_bits(&pb [i], bit_buf [i], MAX_MB_BYTES); |
| 4579 init_put_bits(&pb2 [i], bit_buf2 [i], MAX_MB_BYTES); | |
| 4580 init_put_bits(&tex_pb[i], bit_buf_tex[i], MAX_MB_BYTES); | |
| 456 | 4581 } |
| 0 | 4582 |
| 1786 | 4583 s->last_bits= put_bits_count(&s->pb); |
| 286 | 4584 s->mv_bits=0; |
| 4585 s->misc_bits=0; | |
| 4586 s->i_tex_bits=0; | |
| 4587 s->p_tex_bits=0; | |
| 4588 s->i_count=0; | |
|
656
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
4589 s->f_count=0; |
|
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
4590 s->b_count=0; |
| 286 | 4591 s->skip_count=0; |
| 4592 | |
|
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4593 for(i=0; i<3; i++){ |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4594 /* init last dc values */ |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4595 /* note: quant matrix value (8) is implied here */ |
| 1992 | 4596 s->last_dc[i] = 128 << s->intra_dc_precision; |
|
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4597 |
| 1148 | 4598 s->current_picture_ptr->error[i] = 0; |
|
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
4599 } |
| 1160 | 4600 s->mb_skip_run = 0; |
| 1708 | 4601 memset(s->last_mv, 0, sizeof(s->last_mv)); |
|
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha?l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
4602 |
|
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha?l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
4603 s->last_mv_dir = 0; |
| 0 | 4604 |
| 1042 | 4605 #ifdef CONFIG_RISKY |
|
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4606 switch(s->codec_id){ |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4607 case CODEC_ID_H263: |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4608 case CODEC_ID_H263P: |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4609 case CODEC_ID_FLV1: |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4610 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
|
4611 break; |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4612 case CODEC_ID_MPEG4: |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4613 if(s->partitioned_frame) |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4614 ff_mpeg4_init_partitions(s); |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4615 break; |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
4616 } |
| 1042 | 4617 #endif |
| 456 | 4618 |
| 4619 s->resync_mb_x=0; | |
| 1799 | 4620 s->resync_mb_y=0; |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4621 s->first_slice_line = 1; |
| 766 | 4622 s->ptr_lastgob = s->pb.buf; |
| 1799 | 4623 for(mb_y= s->start_mb_y; mb_y < s->end_mb_y; mb_y++) { |
| 4624 // printf("row %d at %X\n", s->mb_y, (int)s); | |
| 1389 | 4625 s->mb_x=0; |
| 4626 s->mb_y= mb_y; | |
| 4627 | |
| 1652 | 4628 ff_set_qscale(s, s->qscale); |
| 1389 | 4629 ff_init_block_index(s); |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
4630 |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
4631 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
|
4632 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
|
4633 int mb_type= s->mb_type[xy]; |
| 456 | 4634 // int d; |
| 1389 | 4635 int dmin= INT_MAX; |
| 1708 | 4636 int dir; |
| 0 | 4637 |
| 2422 | 4638 if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < MAX_MB_BYTES){ |
| 4639 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); | |
| 4640 return -1; | |
| 4641 } | |
| 4642 if(s->data_partitioning){ | |
| 4643 if( s->pb2 .buf_end - s->pb2 .buf - (put_bits_count(&s-> pb2)>>3) < MAX_MB_BYTES | |
| 4644 || s->tex_pb.buf_end - s->tex_pb.buf - (put_bits_count(&s->tex_pb )>>3) < MAX_MB_BYTES){ | |
| 4645 av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); | |
| 4646 return -1; | |
| 4647 } | |
| 4648 } | |
| 4649 | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
4650 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
|
4651 s->mb_y = mb_y; // moved into loop, can get changed by H.261 |
| 1389 | 4652 ff_update_block_index(s); |
| 456 | 4653 |
|
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
4654 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
|
4655 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
|
4656 xy= s->mb_y*s->mb_stride + s->mb_x; |
| 2345 | 4657 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
|
4658 } |
|
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
4659 |
| 766 | 4660 /* write gob / video packet header */ |
| 1042 | 4661 #ifdef CONFIG_RISKY |
| 1661 | 4662 if(s->rtp_mode){ |
| 766 | 4663 int current_packet_size, is_gob_start; |
| 4664 | |
|
1801
3f26dfb3eba4
replace a few pbBufPtr() by put_bits_count(), one of them was actually wrong
michael
parents:
1799
diff
changeset
|
4665 current_packet_size= ((put_bits_count(&s->pb)+7)>>3) - (s->ptr_lastgob - s->pb.buf); |
| 1661 | 4666 |
| 4667 is_gob_start= s->avctx->rtp_payload_size && current_packet_size >= s->avctx->rtp_payload_size && mb_y + mb_x>0; | |
| 4668 | |
| 1799 | 4669 if(s->start_mb_y == mb_y && mb_y > 0 && mb_x==0) is_gob_start=1; |
| 4670 | |
| 1661 | 4671 switch(s->codec_id){ |
| 4672 case CODEC_ID_H263: | |
| 4673 case CODEC_ID_H263P: | |
| 4674 if(!s->h263_slice_structured) | |
| 4675 if(s->mb_x || s->mb_y%s->gob_index) is_gob_start=0; | |
| 4676 break; | |
| 4677 case CODEC_ID_MPEG2VIDEO: | |
| 4678 if(s->mb_x==0 && s->mb_y!=0) is_gob_start=1; | |
| 4679 case CODEC_ID_MPEG1VIDEO: | |
| 4680 if(s->mb_skip_run) is_gob_start=0; | |
| 4681 break; | |
| 4682 } | |
| 1799 | 4683 |
| 1661 | 4684 if(is_gob_start){ |
| 1799 | 4685 if(s->start_mb_y != mb_y || mb_x!=0){ |
| 4686 write_slice_end(s); | |
| 4687 | |
| 4688 if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame){ | |
| 4689 ff_mpeg4_init_partitions(s); | |
| 4690 } | |
| 1661 | 4691 } |
| 4692 | |
| 1786 | 4693 assert((put_bits_count(&s->pb)&7) == 0); |
| 1661 | 4694 current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob; |
| 1688 | 4695 |
| 4696 if(s->avctx->error_rate && s->resync_mb_x + s->resync_mb_y > 0){ | |
| 2371 | 4697 int r= put_bits_count(&s->pb)/8 + s->picture_number + 16 + s->mb_x + s->mb_y; |
| 1688 | 4698 int d= 100 / s->avctx->error_rate; |
| 4699 if(r % d == 0){ | |
| 4700 current_packet_size=0; | |
| 4701 #ifndef ALT_BITSTREAM_WRITER | |
| 4702 s->pb.buf_ptr= s->ptr_lastgob; | |
| 4703 #endif | |
| 4704 assert(pbBufPtr(&s->pb) == s->ptr_lastgob); | |
| 4705 } | |
| 4706 } | |
| 1661 | 4707 |
| 4708 if (s->avctx->rtp_callback) | |
|
2025
591233f22963
rtp callback context patch by ("Chris Flerackers" <cflerackers at androme dot be>)
michael
parents:
2024
diff
changeset
|
4709 s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, current_packet_size, 0); |
| 1661 | 4710 |
| 4711 switch(s->codec_id){ | |
| 4712 case CODEC_ID_MPEG4: | |
| 456 | 4713 ff_mpeg4_encode_video_packet_header(s); |
| 4714 ff_mpeg4_clean_buffers(s); | |
| 1661 | 4715 break; |
| 4716 case CODEC_ID_MPEG1VIDEO: | |
| 4717 case CODEC_ID_MPEG2VIDEO: | |
| 1421 | 4718 ff_mpeg1_encode_slice_header(s); |
| 4719 ff_mpeg1_clean_buffers(s); | |
| 1661 | 4720 break; |
| 4721 case CODEC_ID_H263: | |
| 4722 case CODEC_ID_H263P: | |
| 4723 h263_encode_gob_header(s, mb_y); | |
| 4724 break; | |
| 1160 | 4725 } |
| 1661 | 4726 |
| 4727 if(s->flags&CODEC_FLAG_PASS1){ | |
| 1786 | 4728 int bits= put_bits_count(&s->pb); |
| 1661 | 4729 s->misc_bits+= bits - s->last_bits; |
| 4730 s->last_bits= bits; | |
| 766 | 4731 } |
| 1661 | 4732 |
| 1662 | 4733 s->ptr_lastgob += current_packet_size; |
| 456 | 4734 s->first_slice_line=1; |
| 4735 s->resync_mb_x=mb_x; | |
| 4736 s->resync_mb_y=mb_y; | |
| 4737 } | |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4738 } |
| 1042 | 4739 #endif |
| 456 | 4740 |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4741 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
|
4742 && s->resync_mb_y+1 == s->mb_y){ |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
4743 s->first_slice_line=0; |
| 456 | 4744 } |
| 4745 | |
| 1389 | 4746 s->mb_skiped=0; |
| 1616 | 4747 s->dquant=0; //only for QP_RD |
| 4748 | |
| 2230 | 4749 if(mb_type & (mb_type-1) || (s->flags & CODEC_FLAG_QP_RD)){ // more than 1 MB type possible or CODEC_FLAG_QP_RD |
| 327 | 4750 int next_block=0; |
| 456 | 4751 int pb_bits_count, pb2_bits_count, tex_pb_bits_count; |
| 326 | 4752 |
| 4753 copy_context_before_encode(&backup_s, s, -1); | |
| 456 | 4754 backup_s.pb= s->pb; |
| 4755 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
|
4756 best_s.partitioned_frame= s->partitioned_frame; |
| 456 | 4757 if(s->data_partitioning){ |
| 4758 backup_s.pb2= s->pb2; | |
| 4759 backup_s.tex_pb= s->tex_pb; | |
| 4760 } | |
| 326 | 4761 |
| 1708 | 4762 if(mb_type&CANDIDATE_MB_TYPE_INTER){ |
| 327 | 4763 s->mv_dir = MV_DIR_FORWARD; |
| 295 | 4764 s->mv_type = MV_TYPE_16X16; |
| 294 | 4765 s->mb_intra= 0; |
| 324 | 4766 s->mv[0][0][0] = s->p_mv_table[xy][0]; |
| 4767 s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
| 1708 | 4768 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER, pb, pb2, tex_pb, |
| 456 | 4769 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); |
| 0 | 4770 } |
| 1708 | 4771 if(mb_type&CANDIDATE_MB_TYPE_INTER_I){ |
| 4772 s->mv_dir = MV_DIR_FORWARD; | |
| 4773 s->mv_type = MV_TYPE_FIELD; | |
| 4774 s->mb_intra= 0; | |
| 4775 for(i=0; i<2; i++){ | |
| 4776 j= s->field_select[0][i] = s->p_field_select_table[i][xy]; | |
| 4777 s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; | |
| 4778 s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; | |
| 4779 } | |
| 4780 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER_I, pb, pb2, tex_pb, | |
| 4781 &dmin, &next_block, 0, 0); | |
| 4782 } | |
| 4783 if(mb_type&CANDIDATE_MB_TYPE_SKIPED){ | |
|
1494
3ee63c12ea30
optionally try to encode each MB with MV=<0,0> and choose the one with better RD
michaelni
parents:
1490
diff
changeset
|
4784 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
|
4785 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
|
4786 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
|
4787 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
|
4788 s->mv[0][0][1] = 0; |
| 1708 | 4789 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_SKIPED, 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
|
4790 &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
|
4791 } |
| 1708 | 4792 if(mb_type&CANDIDATE_MB_TYPE_INTER4V){ |
| 327 | 4793 s->mv_dir = MV_DIR_FORWARD; |
| 295 | 4794 s->mv_type = MV_TYPE_8X8; |
| 4795 s->mb_intra= 0; | |
| 4796 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
|
4797 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
|
4798 s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; |
| 295 | 4799 } |
| 1708 | 4800 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb, |
| 456 | 4801 &dmin, &next_block, 0, 0); |
| 327 | 4802 } |
| 1708 | 4803 if(mb_type&CANDIDATE_MB_TYPE_FORWARD){ |
| 327 | 4804 s->mv_dir = MV_DIR_FORWARD; |
| 4805 s->mv_type = MV_TYPE_16X16; | |
| 4806 s->mb_intra= 0; | |
| 4807 s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
| 4808 s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
| 1708 | 4809 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD, pb, pb2, tex_pb, |
| 456 | 4810 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); |
| 327 | 4811 } |
| 1708 | 4812 if(mb_type&CANDIDATE_MB_TYPE_BACKWARD){ |
| 327 | 4813 s->mv_dir = MV_DIR_BACKWARD; |
| 4814 s->mv_type = MV_TYPE_16X16; | |
| 4815 s->mb_intra= 0; | |
| 4816 s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
| 4817 s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
| 1708 | 4818 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD, pb, pb2, tex_pb, |
| 456 | 4819 &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); |
| 327 | 4820 } |
| 1708 | 4821 if(mb_type&CANDIDATE_MB_TYPE_BIDIR){ |
| 327 | 4822 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; |
| 4823 s->mv_type = MV_TYPE_16X16; | |
| 4824 s->mb_intra= 0; | |
| 4825 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
| 4826 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
| 4827 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
| 4828 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
| 1708 | 4829 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR, pb, pb2, tex_pb, |
| 456 | 4830 &dmin, &next_block, 0, 0); |
| 327 | 4831 } |
| 1708 | 4832 if(mb_type&CANDIDATE_MB_TYPE_DIRECT){ |
| 936 | 4833 int mx= s->b_direct_mv_table[xy][0]; |
| 4834 int my= s->b_direct_mv_table[xy][1]; | |
| 4835 | |
| 327 | 4836 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
| 4837 s->mb_intra= 0; | |
| 1042 | 4838 #ifdef CONFIG_RISKY |
| 936 | 4839 ff_mpeg4_set_direct_mv(s, mx, my); |
| 1042 | 4840 #endif |
| 1708 | 4841 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_DIRECT, pb, pb2, tex_pb, |
| 936 | 4842 &dmin, &next_block, mx, my); |
| 295 | 4843 } |
| 1708 | 4844 if(mb_type&CANDIDATE_MB_TYPE_FORWARD_I){ |
| 4845 s->mv_dir = MV_DIR_FORWARD; | |
| 4846 s->mv_type = MV_TYPE_FIELD; | |
| 4847 s->mb_intra= 0; | |
| 4848 for(i=0; i<2; i++){ | |
| 4849 j= s->field_select[0][i] = s->b_field_select_table[0][i][xy]; | |
| 4850 s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0]; | |
| 4851 s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1]; | |
| 4852 } | |
| 4853 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_FORWARD_I, pb, pb2, tex_pb, | |
| 4854 &dmin, &next_block, 0, 0); | |
| 4855 } | |
| 4856 if(mb_type&CANDIDATE_MB_TYPE_BACKWARD_I){ | |
| 4857 s->mv_dir = MV_DIR_BACKWARD; | |
| 4858 s->mv_type = MV_TYPE_FIELD; | |
| 4859 s->mb_intra= 0; | |
| 4860 for(i=0; i<2; i++){ | |
| 4861 j= s->field_select[1][i] = s->b_field_select_table[1][i][xy]; | |
| 4862 s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0]; | |
| 4863 s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1]; | |
| 4864 } | |
| 4865 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BACKWARD_I, pb, pb2, tex_pb, | |
| 4866 &dmin, &next_block, 0, 0); | |
| 4867 } | |
| 4868 if(mb_type&CANDIDATE_MB_TYPE_BIDIR_I){ | |
| 4869 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
| 4870 s->mv_type = MV_TYPE_FIELD; | |
| 4871 s->mb_intra= 0; | |
| 4872 for(dir=0; dir<2; dir++){ | |
| 4873 for(i=0; i<2; i++){ | |
| 4874 j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy]; | |
| 4875 s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0]; | |
| 4876 s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1]; | |
| 4877 } | |
| 4878 } | |
| 4879 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_BIDIR_I, pb, pb2, tex_pb, | |
| 4880 &dmin, &next_block, 0, 0); | |
| 4881 } | |
| 4882 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
|
4883 s->mv_dir = 0; |
| 295 | 4884 s->mv_type = MV_TYPE_16X16; |
| 294 | 4885 s->mb_intra= 1; |
| 4886 s->mv[0][0][0] = 0; | |
| 4887 s->mv[0][0][1] = 0; | |
| 1708 | 4888 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTRA, pb, pb2, tex_pb, |
| 456 | 4889 &dmin, &next_block, 0, 0); |
| 1389 | 4890 if(s->h263_pred || s->h263_aic){ |
| 4891 if(best_s.mb_intra) | |
| 4892 s->mbintra_table[mb_x + mb_y*s->mb_stride]=1; | |
| 4893 else | |
| 4894 ff_clean_intra_table_entries(s); //old mode? | |
| 4895 } | |
| 295 | 4896 } |
| 1616 | 4897 |
| 4898 if(s->flags & CODEC_FLAG_QP_RD){ | |
| 4899 if(best_s.mv_type==MV_TYPE_16X16 && !(best_s.mv_dir&MV_DIRECT)){ | |
| 4900 const int last_qp= backup_s.qscale; | |
| 4901 int dquant, dir, qp, dc[6]; | |
| 1617 | 4902 DCTELEM ac[6][16]; |
| 1623 | 4903 const int mvdir= (best_s.mv_dir&MV_DIR_BACKWARD) ? 1 : 0; |
| 1616 | 4904 |
| 4905 assert(backup_s.dquant == 0); | |
| 4906 | |
| 4907 //FIXME intra | |
| 4908 s->mv_dir= best_s.mv_dir; | |
| 4909 s->mv_type = MV_TYPE_16X16; | |
| 4910 s->mb_intra= best_s.mb_intra; | |
| 4911 s->mv[0][0][0] = best_s.mv[0][0][0]; | |
| 4912 s->mv[0][0][1] = best_s.mv[0][0][1]; | |
| 4913 s->mv[1][0][0] = best_s.mv[1][0][0]; | |
| 4914 s->mv[1][0][1] = best_s.mv[1][0][1]; | |
| 4915 | |
| 4916 dir= s->pict_type == B_TYPE ? 2 : 1; | |
| 1623 | 4917 if(last_qp + dir > s->avctx->qmax) dir= -dir; |
| 1616 | 4918 for(dquant= dir; dquant<=2 && dquant>=-2; dquant += dir){ |
| 4919 qp= last_qp + dquant; | |
| 4920 if(qp < s->avctx->qmin || qp > s->avctx->qmax) | |
| 4921 break; | |
| 4922 backup_s.dquant= dquant; | |
| 2229 | 4923 if(s->mb_intra && s->dc_val[0]){ |
| 1617 | 4924 for(i=0; i<6; i++){ |
| 4925 dc[i]= s->dc_val[0][ s->block_index[i] ]; | |
| 4926 memcpy(ac[i], s->ac_val[0][s->block_index[i]], sizeof(DCTELEM)*16); | |
| 4927 } | |
| 1616 | 4928 } |
| 1617 | 4929 |
| 1708 | 4930 encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER /* wrong but unused */, pb, pb2, tex_pb, |
| 1623 | 4931 &dmin, &next_block, s->mv[mvdir][0][0], s->mv[mvdir][0][1]); |
| 1616 | 4932 if(best_s.qscale != qp){ |
| 2229 | 4933 if(s->mb_intra && s->dc_val[0]){ |
| 1617 | 4934 for(i=0; i<6; i++){ |
| 4935 s->dc_val[0][ s->block_index[i] ]= dc[i]; | |
| 4936 memcpy(s->ac_val[0][s->block_index[i]], ac[i], sizeof(DCTELEM)*16); | |
| 4937 } | |
| 1616 | 4938 } |
| 4939 if(dir > 0 && dquant==dir){ | |
| 4940 dquant= 0; | |
| 4941 dir= -dir; | |
| 4942 }else | |
| 4943 break; | |
| 4944 } | |
| 4945 } | |
| 4946 qp= best_s.qscale; | |
| 4947 s->current_picture.qscale_table[xy]= qp; | |
| 4948 } | |
| 4949 } | |
| 4950 | |
| 326 | 4951 copy_context_after_encode(s, &best_s, -1); |
| 456 | 4952 |
| 1786 | 4953 pb_bits_count= put_bits_count(&s->pb); |
| 456 | 4954 flush_put_bits(&s->pb); |
| 4955 ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); | |
| 4956 s->pb= backup_s.pb; | |
| 4957 | |
| 4958 if(s->data_partitioning){ | |
| 1786 | 4959 pb2_bits_count= put_bits_count(&s->pb2); |
| 456 | 4960 flush_put_bits(&s->pb2); |
| 4961 ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); | |
| 4962 s->pb2= backup_s.pb2; | |
| 4963 | |
| 1786 | 4964 tex_pb_bits_count= put_bits_count(&s->tex_pb); |
| 456 | 4965 flush_put_bits(&s->tex_pb); |
| 4966 ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); | |
| 4967 s->tex_pb= backup_s.tex_pb; | |
| 4968 } | |
| 1786 | 4969 s->last_bits= put_bits_count(&s->pb); |
|
1451
62c16edd18c6
--disable-risky fix by (Luca Abeni <lucabe72 at email dot it>)
michaelni
parents:
1444
diff
changeset
|
4970 |
|
62c16edd18c6
--disable-risky fix by (Luca Abeni <lucabe72 at email dot it>)
michaelni
parents:
1444
diff
changeset
|
4971 #ifdef CONFIG_RISKY |
| 1389 | 4972 if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE) |
| 4973 ff_h263_update_motion_val(s); | |
|
1451
62c16edd18c6
--disable-risky fix by (Luca Abeni <lucabe72 at email dot it>)
michaelni
parents:
1444
diff
changeset
|
4974 #endif |
| 1389 | 4975 |
| 1799 | 4976 if(next_block==0){ //FIXME 16 vs linesize16 |
| 4977 s->dsp.put_pixels_tab[0][0](s->dest[0], s->rd_scratchpad , s->linesize ,16); | |
| 4978 s->dsp.put_pixels_tab[1][0](s->dest[1], s->rd_scratchpad + 16*s->linesize , s->uvlinesize, 8); | |
| 4979 s->dsp.put_pixels_tab[1][0](s->dest[2], s->rd_scratchpad + 16*s->linesize + 8, s->uvlinesize, 8); | |
| 1389 | 4980 } |
| 4981 | |
| 4982 if(s->avctx->mb_decision == FF_MB_DECISION_BITS) | |
| 4983 MPV_decode_mb(s, s->block); | |
| 294 | 4984 } else { |
| 324 | 4985 int motion_x, motion_y; |
| 4986 s->mv_type=MV_TYPE_16X16; | |
| 294 | 4987 // only one MB-Type possible |
| 1013 | 4988 |
| 327 | 4989 switch(mb_type){ |
| 1708 | 4990 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
|
4991 s->mv_dir = 0; |
| 294 | 4992 s->mb_intra= 1; |
| 324 | 4993 motion_x= s->mv[0][0][0] = 0; |
| 4994 motion_y= s->mv[0][0][1] = 0; | |
| 327 | 4995 break; |
| 1708 | 4996 case CANDIDATE_MB_TYPE_INTER: |
| 324 | 4997 s->mv_dir = MV_DIR_FORWARD; |
| 4998 s->mb_intra= 0; | |
| 4999 motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; | |
| 5000 motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
| 327 | 5001 break; |
| 1708 | 5002 case CANDIDATE_MB_TYPE_INTER_I: |
| 5003 s->mv_dir = MV_DIR_FORWARD; | |
| 5004 s->mv_type = MV_TYPE_FIELD; | |
| 5005 s->mb_intra= 0; | |
| 5006 for(i=0; i<2; i++){ | |
| 5007 j= s->field_select[0][i] = s->p_field_select_table[i][xy]; | |
| 5008 s->mv[0][i][0] = s->p_field_mv_table[i][j][xy][0]; | |
| 5009 s->mv[0][i][1] = s->p_field_mv_table[i][j][xy][1]; | |
| 5010 } | |
| 5011 motion_x = motion_y = 0; | |
| 5012 break; | |
| 5013 case CANDIDATE_MB_TYPE_INTER4V: | |
| 456 | 5014 s->mv_dir = MV_DIR_FORWARD; |
| 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]; |
| 456 | 5020 } |
| 5021 motion_x= motion_y= 0; | |
| 5022 break; | |
| 1708 | 5023 case CANDIDATE_MB_TYPE_DIRECT: |
| 324 | 5024 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
| 5025 s->mb_intra= 0; | |
| 327 | 5026 motion_x=s->b_direct_mv_table[xy][0]; |
| 5027 motion_y=s->b_direct_mv_table[xy][1]; | |
| 1042 | 5028 #ifdef CONFIG_RISKY |
| 936 | 5029 ff_mpeg4_set_direct_mv(s, motion_x, motion_y); |
| 1042 | 5030 #endif |
| 327 | 5031 break; |
| 1708 | 5032 case CANDIDATE_MB_TYPE_BIDIR: |
| 324 | 5033 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; |
| 294 | 5034 s->mb_intra= 0; |
| 324 | 5035 motion_x=0; |
| 5036 motion_y=0; | |
| 5037 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
| 5038 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
| 5039 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
| 5040 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
| 327 | 5041 break; |
| 1708 | 5042 case CANDIDATE_MB_TYPE_BACKWARD: |
| 324 | 5043 s->mv_dir = MV_DIR_BACKWARD; |
| 5044 s->mb_intra= 0; | |
| 5045 motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
| 5046 motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
| 327 | 5047 break; |
| 1708 | 5048 case CANDIDATE_MB_TYPE_FORWARD: |
| 324 | 5049 s->mv_dir = MV_DIR_FORWARD; |
| 5050 s->mb_intra= 0; | |
| 5051 motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
| 5052 motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
| 5053 // printf(" %d %d ", motion_x, motion_y); | |
| 327 | 5054 break; |
| 1708 | 5055 case CANDIDATE_MB_TYPE_FORWARD_I: |
| 5056 s->mv_dir = MV_DIR_FORWARD; | |
| 5057 s->mv_type = MV_TYPE_FIELD; | |
| 5058 s->mb_intra= 0; | |
| 5059 for(i=0; i<2; i++){ | |
| 5060 j= s->field_select[0][i] = s->b_field_select_table[0][i][xy]; | |
| 5061 s->mv[0][i][0] = s->b_field_mv_table[0][i][j][xy][0]; | |
| 5062 s->mv[0][i][1] = s->b_field_mv_table[0][i][j][xy][1]; | |
| 5063 } | |
| 5064 motion_x=motion_y=0; | |
| 5065 break; | |
| 5066 case CANDIDATE_MB_TYPE_BACKWARD_I: | |
| 5067 s->mv_dir = MV_DIR_BACKWARD; | |
| 5068 s->mv_type = MV_TYPE_FIELD; | |
| 5069 s->mb_intra= 0; | |
| 5070 for(i=0; i<2; i++){ | |
| 5071 j= s->field_select[1][i] = s->b_field_select_table[1][i][xy]; | |
| 5072 s->mv[1][i][0] = s->b_field_mv_table[1][i][j][xy][0]; | |
| 5073 s->mv[1][i][1] = s->b_field_mv_table[1][i][j][xy][1]; | |
| 5074 } | |
| 5075 motion_x=motion_y=0; | |
| 5076 break; | |
| 5077 case CANDIDATE_MB_TYPE_BIDIR_I: | |
| 5078 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
| 5079 s->mv_type = MV_TYPE_FIELD; | |
| 5080 s->mb_intra= 0; | |
| 5081 for(dir=0; dir<2; dir++){ | |
| 5082 for(i=0; i<2; i++){ | |
| 5083 j= s->field_select[dir][i] = s->b_field_select_table[dir][i][xy]; | |
| 5084 s->mv[dir][i][0] = s->b_field_mv_table[dir][i][j][xy][0]; | |
| 5085 s->mv[dir][i][1] = s->b_field_mv_table[dir][i][j][xy][1]; | |
| 5086 } | |
| 5087 } | |
| 5088 motion_x=motion_y=0; | |
| 5089 break; | |
| 327 | 5090 default: |
| 324 | 5091 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
|
5092 av_log(s->avctx, AV_LOG_ERROR, "illegal MB type\n"); |
| 294 | 5093 } |
|
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha?l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
5094 |
| 324 | 5095 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
|
5096 |
|
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha?l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
5097 // RAL: Update last macrobloc type |
|
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha?l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
5098 s->last_mv_dir = s->mv_dir; |
| 1389 | 5099 |
|
1451
62c16edd18c6
--disable-risky fix by (Luca Abeni <lucabe72 at email dot it>)
michaelni
parents:
1444
diff
changeset
|
5100 #ifdef CONFIG_RISKY |
| 1389 | 5101 if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE) |
| 5102 ff_h263_update_motion_val(s); | |
|
1451
62c16edd18c6
--disable-risky fix by (Luca Abeni <lucabe72 at email dot it>)
michaelni
parents:
1444
diff
changeset
|
5103 #endif |
|
62c16edd18c6
--disable-risky fix by (Luca Abeni <lucabe72 at email dot it>)
michaelni
parents:
1444
diff
changeset
|
5104 |
| 1389 | 5105 MPV_decode_mb(s, s->block); |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
5106 } |
|
1051
e5a9dbf597d4
mpeg1 bframe encoding patch by (Rapha?l LEGRAND) with some modifications by me
michaelni
parents:
1048
diff
changeset
|
5107 |
| 327 | 5108 /* clean the MV table in IPS frames for direct mode in B frames */ |
| 5109 if(s->mb_intra /* && I,P,S_TYPE */){ | |
| 5110 s->p_mv_table[xy][0]=0; | |
| 5111 s->p_mv_table[xy][1]=0; | |
| 5112 } | |
|
909
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
5113 |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
5114 if(s->flags&CODEC_FLAG_PSNR){ |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
5115 int w= 16; |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
5116 int h= 16; |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
5117 |
|
8ae1e4c24e91
new PSNR code (now works with chroma, b frames, ...)
michaelni
parents:
903
diff
changeset
|
5118 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
|
5119 if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; |
| 936 | 5120 |
| 1148 | 5121 s->current_picture_ptr->error[0] += sse( |
| 1389 | 5122 s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, |
| 5123 s->dest[0], w, h, s->linesize); | |
| 1148 | 5124 s->current_picture_ptr->error[1] += sse( |
| 1389 | 5125 s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, |
| 5126 s->dest[1], w>>1, h>>1, s->uvlinesize); | |
| 1148 | 5127 s->current_picture_ptr->error[2] += sse( |
| 1389 | 5128 s, s->new_picture .data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, |
| 5129 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
|
5130 } |
| 2345 | 5131 if(s->loop_filter){ |
| 5132 if(s->out_format == FMT_H263) | |
| 5133 ff_h263_loop_filter(s); | |
| 5134 } | |
| 1786 | 5135 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_stride, put_bits_count(&s->pb)); |
| 0 | 5136 } |
| 5137 } | |
| 286 | 5138 |
| 1042 | 5139 #ifdef CONFIG_RISKY |
| 1799 | 5140 //not beautifull here but we must write it before flushing so it has to be here |
| 456 | 5141 if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE) |
| 208 | 5142 msmpeg4_encode_ext_header(s); |
| 1042 | 5143 #endif |
| 456 | 5144 |
| 1799 | 5145 write_slice_end(s); |
| 5146 | |
| 231 | 5147 /* Send the last GOB if RTP */ |
| 1661 | 5148 if (s->avctx->rtp_callback) { |
|
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
5149 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
| 231 | 5150 /* Call the RTP callback to send the last GOB */ |
| 1799 | 5151 emms_c(); |
|
2025
591233f22963
rtp callback context patch by ("Chris Flerackers" <cflerackers at androme dot be>)
michael
parents:
2024
diff
changeset
|
5152 s->avctx->rtp_callback(s->avctx, s->ptr_lastgob, pdif, 0); |
| 231 | 5153 } |
| 1799 | 5154 |
| 5155 return 0; | |
| 5156 } | |
| 5157 | |
| 5158 #define MERGE(field) dst->field += src->field; src->field=0 | |
| 5159 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
|
5160 MERGE(me.scene_change_score); |
|
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5161 MERGE(me.mc_mb_var_sum_temp); |
|
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5162 MERGE(me.mb_var_sum_temp); |
| 1799 | 5163 } |
| 5164 | |
| 5165 static void merge_context_after_encode(MpegEncContext *dst, MpegEncContext *src){ | |
| 5166 int i; | |
| 5167 | |
| 5168 MERGE(dct_count[0]); //note, the other dct vars are not part of the context | |
| 5169 MERGE(dct_count[1]); | |
| 5170 MERGE(mv_bits); | |
| 5171 MERGE(i_tex_bits); | |
| 5172 MERGE(p_tex_bits); | |
| 5173 MERGE(i_count); | |
| 5174 MERGE(f_count); | |
| 5175 MERGE(b_count); | |
| 5176 MERGE(skip_count); | |
| 5177 MERGE(misc_bits); | |
| 5178 MERGE(error_count); | |
| 5179 MERGE(padding_bug_score); | |
| 5180 | |
| 5181 if(dst->avctx->noise_reduction){ | |
| 5182 for(i=0; i<64; i++){ | |
| 5183 MERGE(dct_error_sum[0][i]); | |
| 5184 MERGE(dct_error_sum[1][i]); | |
| 5185 } | |
| 5186 } | |
| 5187 | |
| 5188 assert(put_bits_count(&src->pb) % 8 ==0); | |
| 5189 assert(put_bits_count(&dst->pb) % 8 ==0); | |
| 5190 ff_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb)); | |
| 5191 flush_put_bits(&dst->pb); | |
| 5192 } | |
| 5193 | |
| 5194 static void encode_picture(MpegEncContext *s, int picture_number) | |
| 5195 { | |
|
2024
f65d87bfdd5a
some of the warning fixes by (Michael Roitzsch <mroi at users dot sourceforge dot net>)
michael
parents:
2015
diff
changeset
|
5196 int i; |
| 1799 | 5197 int bits; |
| 5198 | |
| 5199 s->picture_number = picture_number; | |
| 5200 | |
| 5201 /* Reset the average MB variance */ | |
|
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5202 s->me.mb_var_sum_temp = |
|
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5203 s->me.mc_mb_var_sum_temp = 0; |
| 1799 | 5204 |
| 5205 #ifdef CONFIG_RISKY | |
| 5206 /* we need to initialize some time vars before we can encode b-frames */ | |
| 5207 // RAL: Condition added for MPEG1VIDEO | |
| 5208 if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4)) | |
| 1834 | 5209 ff_set_mpeg4_time(s, s->picture_number); //FIXME rename and use has_b_frames or similar |
| 1799 | 5210 #endif |
| 5211 | |
|
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5212 s->me.scene_change_score=0; |
| 1799 | 5213 |
| 2053 | 5214 // s->lambda= s->current_picture_ptr->quality; //FIXME qscale / ... stuff for ME ratedistoration |
| 1799 | 5215 |
| 5216 if(s->pict_type==I_TYPE){ | |
| 5217 if(s->msmpeg4_version >= 3) s->no_rounding=1; | |
| 5218 else s->no_rounding=0; | |
| 5219 }else if(s->pict_type!=B_TYPE){ | |
| 5220 if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4) | |
| 5221 s->no_rounding ^= 1; | |
| 5222 } | |
| 5223 | |
| 5224 s->mb_intra=0; //for the rate distoration & bit compare functions | |
| 5225 for(i=1; i<s->avctx->thread_count; i++){ | |
| 1827 | 5226 ff_update_duplicate_context(s->thread_context[i], s); |
| 1799 | 5227 } |
| 1962 | 5228 |
| 5229 ff_init_me(s); | |
| 5230 | |
| 1799 | 5231 /* Estimate motion for every MB */ |
| 5232 if(s->pict_type != I_TYPE){ | |
|
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
|
5233 if(s->pict_type != B_TYPE && s->avctx->me_threshold==0){ |
| 1799 | 5234 if((s->avctx->pre_me && s->last_non_b_pict_type==I_TYPE) || s->avctx->pre_me==2){ |
| 5235 s->avctx->execute(s->avctx, pre_estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); | |
| 5236 } | |
| 5237 } | |
| 5238 | |
| 5239 s->avctx->execute(s->avctx, estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); | |
| 5240 }else /* if(s->pict_type == I_TYPE) */{ | |
| 5241 /* I-Frame */ | |
| 5242 for(i=0; i<s->mb_stride*s->mb_height; i++) | |
| 5243 s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; | |
| 5244 | |
| 5245 if(!s->fixed_qscale){ | |
| 5246 /* finding spatial complexity for I-frame rate control */ | |
|
1804
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
5247 s->avctx->execute(s->avctx, mb_var_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); |
| 1799 | 5248 } |
| 5249 } | |
|
1804
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
5250 for(i=1; i<s->avctx->thread_count; i++){ |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
5251 merge_context_after_me(s, s->thread_context[i]); |
|
cc0a15943a87
multithreaded spatial complexity calculation for i frames
michael
parents:
1803
diff
changeset
|
5252 } |
|
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5253 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
|
5254 s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp; |
| 1799 | 5255 emms_c(); |
| 5256 | |
|
2015
3ab8f3e2ae6a
moving motion estimation specific variables from MpegEncContext -> MotionEstContext
michael
parents:
1994
diff
changeset
|
5257 if(s->me.scene_change_score > s->avctx->scenechange_threshold && s->pict_type == P_TYPE){ |
| 1799 | 5258 s->pict_type= I_TYPE; |
| 5259 for(i=0; i<s->mb_stride*s->mb_height; i++) | |
| 5260 s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; | |
| 5261 //printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum); | |
| 5262 } | |
| 5263 | |
| 5264 if(!s->umvplus){ | |
| 5265 if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) { | |
| 5266 s->f_code= ff_get_best_fcode(s, s->p_mv_table, CANDIDATE_MB_TYPE_INTER); | |
| 5267 | |
| 5268 if(s->flags & CODEC_FLAG_INTERLACED_ME){ | |
| 5269 int a,b; | |
| 5270 a= ff_get_best_fcode(s, s->p_field_mv_table[0][0], CANDIDATE_MB_TYPE_INTER_I); //FIXME field_select | |
| 5271 b= ff_get_best_fcode(s, s->p_field_mv_table[1][1], CANDIDATE_MB_TYPE_INTER_I); | |
| 5272 s->f_code= FFMAX(s->f_code, FFMAX(a,b)); | |
| 5273 } | |
| 5274 | |
| 5275 ff_fix_long_p_mvs(s); | |
| 5276 ff_fix_long_mvs(s, NULL, 0, s->p_mv_table, s->f_code, CANDIDATE_MB_TYPE_INTER, 0); | |
| 5277 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
|
5278 int j; |
| 1799 | 5279 for(i=0; i<2; i++){ |
| 5280 for(j=0; j<2; j++) | |
| 5281 ff_fix_long_mvs(s, s->p_field_select_table[i], j, | |
| 5282 s->p_field_mv_table[i][j], s->f_code, CANDIDATE_MB_TYPE_INTER_I, 0); | |
| 5283 } | |
| 5284 } | |
| 5285 } | |
| 5286 | |
| 5287 if(s->pict_type==B_TYPE){ | |
| 5288 int a, b; | |
| 5289 | |
| 5290 a = ff_get_best_fcode(s, s->b_forw_mv_table, CANDIDATE_MB_TYPE_FORWARD); | |
| 5291 b = ff_get_best_fcode(s, s->b_bidir_forw_mv_table, CANDIDATE_MB_TYPE_BIDIR); | |
| 5292 s->f_code = FFMAX(a, b); | |
| 5293 | |
| 5294 a = ff_get_best_fcode(s, s->b_back_mv_table, CANDIDATE_MB_TYPE_BACKWARD); | |
| 5295 b = ff_get_best_fcode(s, s->b_bidir_back_mv_table, CANDIDATE_MB_TYPE_BIDIR); | |
| 5296 s->b_code = FFMAX(a, b); | |
| 5297 | |
| 5298 ff_fix_long_mvs(s, NULL, 0, s->b_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_FORWARD, 1); | |
| 5299 ff_fix_long_mvs(s, NULL, 0, s->b_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BACKWARD, 1); | |
| 5300 ff_fix_long_mvs(s, NULL, 0, s->b_bidir_forw_mv_table, s->f_code, CANDIDATE_MB_TYPE_BIDIR, 1); | |
| 5301 ff_fix_long_mvs(s, NULL, 0, s->b_bidir_back_mv_table, s->b_code, CANDIDATE_MB_TYPE_BIDIR, 1); | |
| 5302 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
|
5303 int dir, j; |
| 1799 | 5304 for(dir=0; dir<2; dir++){ |
| 5305 for(i=0; i<2; i++){ | |
| 5306 for(j=0; j<2; j++){ | |
| 5307 int type= dir ? (CANDIDATE_MB_TYPE_BACKWARD_I|CANDIDATE_MB_TYPE_BIDIR_I) | |
| 5308 : (CANDIDATE_MB_TYPE_FORWARD_I |CANDIDATE_MB_TYPE_BIDIR_I); | |
| 5309 ff_fix_long_mvs(s, s->b_field_select_table[dir][i], j, | |
| 5310 s->b_field_mv_table[dir][i][j], dir ? s->b_code : s->f_code, type, 1); | |
| 5311 } | |
| 5312 } | |
| 5313 } | |
| 5314 } | |
| 5315 } | |
| 5316 } | |
| 5317 | |
| 5318 if (!s->fixed_qscale) | |
| 5319 s->current_picture.quality = ff_rate_estimate_qscale(s); //FIXME pic_ptr | |
| 5320 | |
| 5321 if(s->adaptive_quant){ | |
| 5322 #ifdef CONFIG_RISKY | |
| 5323 switch(s->codec_id){ | |
| 5324 case CODEC_ID_MPEG4: | |
| 5325 ff_clean_mpeg4_qscales(s); | |
| 5326 break; | |
| 5327 case CODEC_ID_H263: | |
| 5328 case CODEC_ID_H263P: | |
| 5329 case CODEC_ID_FLV1: | |
| 5330 ff_clean_h263_qscales(s); | |
| 5331 break; | |
| 5332 } | |
| 5333 #endif | |
| 5334 | |
| 5335 s->lambda= s->lambda_table[0]; | |
| 5336 //FIXME broken | |
| 5337 }else | |
| 5338 s->lambda= s->current_picture.quality; | |
| 5339 //printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality); | |
| 5340 update_qscale(s); | |
| 5341 | |
| 5342 if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==I_TYPE && !(s->flags & CODEC_FLAG_QSCALE)) | |
| 5343 s->qscale= 3; //reduce cliping problems | |
| 5344 | |
| 5345 if (s->out_format == FMT_MJPEG) { | |
| 5346 /* for mjpeg, we do include qscale in the matrix */ | |
| 5347 s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; | |
| 5348 for(i=1;i<64;i++){ | |
| 5349 int j= s->dsp.idct_permutation[i]; | |
| 5350 | |
| 5351 s->intra_matrix[j] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); | |
| 5352 } | |
| 5353 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
|
5354 s->intra_matrix, s->intra_quant_bias, 8, 8, 1); |
| 1799 | 5355 s->qscale= 8; |
| 5356 } | |
| 5357 | |
| 5358 //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
|
5359 s->current_picture_ptr->key_frame= |
| 1799 | 5360 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
|
5361 s->current_picture_ptr->pict_type= |
| 1799 | 5362 s->current_picture.pict_type= s->pict_type; |
| 5363 | |
| 5364 if(s->current_picture.key_frame) | |
| 5365 s->picture_in_gop_number=0; | |
| 5366 | |
| 5367 s->last_bits= put_bits_count(&s->pb); | |
| 5368 switch(s->out_format) { | |
| 5369 case FMT_MJPEG: | |
| 5370 mjpeg_picture_header(s); | |
| 5371 break; | |
| 5372 #ifdef CONFIG_RISKY | |
|
2327
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
5373 case FMT_H261: |
|
5e5cf598a48b
H.261 encoder by (Maarten Daniels <maarten dot daniels at luc dot ac dot be>)
michael
parents:
2298
diff
changeset
|
5374 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
|
5375 break; |
| 1799 | 5376 case FMT_H263: |
| 5377 if (s->codec_id == CODEC_ID_WMV2) | |
| 5378 ff_wmv2_encode_picture_header(s, picture_number); | |
| 5379 else if (s->h263_msmpeg4) | |
| 5380 msmpeg4_encode_picture_header(s, picture_number); | |
| 5381 else if (s->h263_pred) | |
| 5382 mpeg4_encode_picture_header(s, picture_number); | |
| 5383 else if (s->codec_id == CODEC_ID_RV10) | |
| 5384 rv10_encode_picture_header(s, picture_number); | |
| 2380 | 5385 else if (s->codec_id == CODEC_ID_RV20) |
| 5386 rv20_encode_picture_header(s, picture_number); | |
| 1799 | 5387 else if (s->codec_id == CODEC_ID_FLV1) |
| 5388 ff_flv_encode_picture_header(s, picture_number); | |
| 5389 else | |
| 5390 h263_encode_picture_header(s, picture_number); | |
| 5391 break; | |
| 5392 #endif | |
| 5393 case FMT_MPEG1: | |
| 5394 mpeg1_encode_picture_header(s, picture_number); | |
| 5395 break; | |
| 5396 case FMT_H264: | |
| 5397 break; | |
| 5398 default: | |
| 5399 assert(0); | |
| 5400 } | |
| 5401 bits= put_bits_count(&s->pb); | |
| 5402 s->header_bits= bits - s->last_bits; | |
| 5403 | |
| 5404 for(i=1; i<s->avctx->thread_count; i++){ | |
| 5405 update_duplicate_context_after_me(s->thread_context[i], s); | |
| 5406 } | |
| 5407 s->avctx->execute(s->avctx, encode_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count); | |
| 5408 for(i=1; i<s->avctx->thread_count; i++){ | |
| 5409 merge_context_after_encode(s, s->thread_context[i]); | |
| 5410 } | |
| 5411 emms_c(); | |
| 0 | 5412 } |
| 5413 | |
|
1686
68abbec33289
Here are juste two added #ifdef CONFIG_ENCODERS to allow
michael
parents:
1685
diff
changeset
|
5414 #endif //CONFIG_ENCODERS |
|
68abbec33289
Here are juste two added #ifdef CONFIG_ENCODERS to allow
michael
parents:
1685
diff
changeset
|
5415 |
| 1719 | 5416 static void denoise_dct_c(MpegEncContext *s, DCTELEM *block){ |
| 1597 | 5417 const int intra= s->mb_intra; |
| 5418 int i; | |
| 5419 | |
| 1599 | 5420 s->dct_count[intra]++; |
| 5421 | |
| 1597 | 5422 for(i=0; i<64; i++){ |
| 5423 int level= block[i]; | |
| 5424 | |
| 5425 if(level){ | |
| 5426 if(level>0){ | |
| 5427 s->dct_error_sum[intra][i] += level; | |
| 5428 level -= s->dct_offset[intra][i]; | |
| 5429 if(level<0) level=0; | |
| 5430 }else{ | |
| 5431 s->dct_error_sum[intra][i] -= level; | |
| 5432 level += s->dct_offset[intra][i]; | |
| 5433 if(level>0) level=0; | |
| 5434 } | |
| 5435 block[i]= level; | |
| 5436 } | |
| 5437 } | |
| 5438 } | |
| 5439 | |
|
1686
68abbec33289
Here are juste two added #ifdef CONFIG_ENCODERS to allow
michael
parents:
1685
diff
changeset
|
5440 #ifdef CONFIG_ENCODERS |
|
68abbec33289
Here are juste two added #ifdef CONFIG_ENCODERS to allow
michael
parents:
1685
diff
changeset
|
5441 |
| 945 | 5442 static int dct_quantize_trellis_c(MpegEncContext *s, |
| 5443 DCTELEM *block, int n, | |
| 5444 int qscale, int *overflow){ | |
| 5445 const int *qmat; | |
| 1064 | 5446 const uint8_t *scantable= s->intra_scantable.scantable; |
| 1718 | 5447 const uint8_t *perm_scantable= s->intra_scantable.permutated; |
| 945 | 5448 int max=0; |
| 5449 unsigned int threshold1, threshold2; | |
| 5450 int bias=0; | |
| 5451 int run_tab[65]; | |
| 5452 int level_tab[65]; | |
| 5453 int score_tab[65]; | |
| 1718 | 5454 int survivor[65]; |
| 5455 int survivor_count; | |
| 946 | 5456 int last_run=0; |
| 5457 int last_level=0; | |
| 5458 int last_score= 0; | |
| 1718 | 5459 int last_i; |
| 1715 | 5460 int coeff[2][64]; |
| 945 | 5461 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
|
5462 int qmul, qadd, start_i, last_non_zero, i, dc; |
| 945 | 5463 const int esc_length= s->ac_esc_length; |
| 5464 uint8_t * length; | |
| 5465 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
|
5466 const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); |
| 945 | 5467 |
| 1092 | 5468 s->dsp.fdct (block); |
| 1597 | 5469 |
| 5470 if(s->dct_error_sum) | |
| 1719 | 5471 s->denoise_dct(s, block); |
| 945 | 5472 qmul= qscale*16; |
| 5473 qadd= ((qscale-1)|1)*8; | |
| 946 | 5474 |
| 945 | 5475 if (s->mb_intra) { |
| 5476 int q; | |
| 5477 if (!s->h263_aic) { | |
| 5478 if (n < 4) | |
| 5479 q = s->y_dc_scale; | |
| 5480 else | |
| 5481 q = s->c_dc_scale; | |
| 5482 q = q << 3; | |
| 5483 } else{ | |
| 5484 /* For AIC we skip quant/dequant of INTRADC */ | |
| 5485 q = 1 << 3; | |
| 5486 qadd=0; | |
| 5487 } | |
| 5488 | |
| 5489 /* note: block[0] is assumed to be positive */ | |
| 5490 block[0] = (block[0] + (q >> 1)) / q; | |
| 5491 start_i = 1; | |
| 5492 last_non_zero = 0; | |
| 5493 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
|
5494 if(s->mpeg_quant || s->out_format == FMT_MPEG1) |
| 945 | 5495 bias= 1<<(QMAT_SHIFT-1); |
| 5496 length = s->intra_ac_vlc_length; | |
| 5497 last_length= s->intra_ac_vlc_last_length; | |
| 5498 } else { | |
| 5499 start_i = 0; | |
| 5500 last_non_zero = -1; | |
| 5501 qmat = s->q_inter_matrix[qscale]; | |
| 5502 length = s->inter_ac_vlc_length; | |
| 5503 last_length= s->inter_ac_vlc_last_length; | |
| 5504 } | |
| 1718 | 5505 last_i= start_i; |
| 945 | 5506 |
| 5507 threshold1= (1<<QMAT_SHIFT) - bias - 1; | |
| 5508 threshold2= (threshold1<<1); | |
| 946 | 5509 |
| 1715 | 5510 for(i=63; i>=start_i; i--) { |
| 5511 const int j = scantable[i]; | |
| 5512 int level = block[j] * qmat[j]; | |
| 5513 | |
| 5514 if(((unsigned)(level+threshold1))>threshold2){ | |
| 5515 last_non_zero = i; | |
| 5516 break; | |
| 5517 } | |
| 5518 } | |
| 5519 | |
| 5520 for(i=start_i; i<=last_non_zero; i++) { | |
| 945 | 5521 const int j = scantable[i]; |
| 1715 | 5522 int level = block[j] * qmat[j]; |
| 945 | 5523 |
| 5524 // if( bias+level >= (1<<(QMAT_SHIFT - 3)) | |
| 5525 // || bias-level >= (1<<(QMAT_SHIFT - 3))){ | |
| 5526 if(((unsigned)(level+threshold1))>threshold2){ | |
| 5527 if(level>0){ | |
| 5528 level= (bias + level)>>QMAT_SHIFT; | |
| 1718 | 5529 coeff[0][i]= level; |
| 5530 coeff[1][i]= level-1; | |
| 946 | 5531 // coeff[2][k]= level-2; |
| 945 | 5532 }else{ |
| 5533 level= (bias - level)>>QMAT_SHIFT; | |
| 1718 | 5534 coeff[0][i]= -level; |
| 5535 coeff[1][i]= -level+1; | |
| 946 | 5536 // coeff[2][k]= -level+2; |
| 945 | 5537 } |
| 1718 | 5538 coeff_count[i]= FFMIN(level, 2); |
| 5539 assert(coeff_count[i]); | |
| 945 | 5540 max |=level; |
| 5541 }else{ | |
| 1718 | 5542 coeff[0][i]= (level>>31)|1; |
| 5543 coeff_count[i]= 1; | |
| 945 | 5544 } |
| 5545 } | |
| 5546 | |
| 5547 *overflow= s->max_qcoeff < max; //overflow might have happend | |
| 5548 | |
| 5549 if(last_non_zero < start_i){ | |
| 5550 memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); | |
| 5551 return last_non_zero; | |
| 5552 } | |
| 5553 | |
| 1718 | 5554 score_tab[start_i]= 0; |
| 5555 survivor[0]= start_i; | |
| 5556 survivor_count= 1; | |
|
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
|
5557 |
| 1718 | 5558 for(i=start_i; i<=last_non_zero; i++){ |
| 5559 int level_index, j; | |
| 5560 const int dct_coeff= ABS(block[ scantable[i] ]); | |
| 945 | 5561 const int zero_distoration= dct_coeff*dct_coeff; |
| 946 | 5562 int best_score=256*256*256*120; |
| 945 | 5563 for(level_index=0; level_index < coeff_count[i]; level_index++){ |
| 5564 int distoration; | |
| 5565 int level= coeff[level_index][i]; | |
| 1716 | 5566 const int alevel= ABS(level); |
| 945 | 5567 int unquant_coeff; |
| 5568 | |
| 5569 assert(level); | |
| 5570 | |
| 5571 if(s->out_format == FMT_H263){ | |
| 1716 | 5572 unquant_coeff= alevel*qmul + qadd; |
| 947 | 5573 }else{ //MPEG1 |
| 1718 | 5574 j= s->dsp.idct_permutation[ scantable[i] ]; //FIXME optimize |
| 947 | 5575 if(s->mb_intra){ |
| 1716 | 5576 unquant_coeff = (int)( alevel * qscale * s->intra_matrix[j]) >> 3; |
| 947 | 5577 unquant_coeff = (unquant_coeff - 1) | 1; |
| 5578 }else{ | |
| 1716 | 5579 unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[j])) >> 4; |
| 947 | 5580 unquant_coeff = (unquant_coeff - 1) | 1; |
| 5581 } | |
| 5582 unquant_coeff<<= 3; | |
| 5583 } | |
| 946 | 5584 |
| 1715 | 5585 distoration= (unquant_coeff - dct_coeff) * (unquant_coeff - dct_coeff) - zero_distoration; |
| 945 | 5586 level+=64; |
| 5587 if((level&(~127)) == 0){ | |
| 1718 | 5588 for(j=survivor_count-1; j>=0; j--){ |
| 5589 int run= i - survivor[j]; | |
| 947 | 5590 int score= distoration + length[UNI_AC_ENC_INDEX(run, level)]*lambda; |
| 945 | 5591 score += score_tab[i-run]; |
| 5592 | |
| 5593 if(score < best_score){ | |
| 1718 | 5594 best_score= score; |
| 945 | 5595 run_tab[i+1]= run; |
| 5596 level_tab[i+1]= level-64; | |
| 5597 } | |
| 5598 } | |
| 5599 | |
| 5600 if(s->out_format == FMT_H263){ | |
| 1718 | 5601 for(j=survivor_count-1; j>=0; j--){ |
| 5602 int run= i - survivor[j]; | |
| 947 | 5603 int score= distoration + last_length[UNI_AC_ENC_INDEX(run, level)]*lambda; |
| 945 | 5604 score += score_tab[i-run]; |
| 946 | 5605 if(score < last_score){ |
| 5606 last_score= score; | |
| 5607 last_run= run; | |
| 5608 last_level= level-64; | |
| 5609 last_i= i+1; | |
| 945 | 5610 } |
| 5611 } | |
| 5612 } | |
| 5613 }else{ | |
| 5614 distoration += esc_length*lambda; | |
| 1718 | 5615 for(j=survivor_count-1; j>=0; j--){ |
| 5616 int run= i - survivor[j]; | |
| 945 | 5617 int score= distoration + score_tab[i-run]; |
| 5618 | |
| 5619 if(score < best_score){ | |
| 1718 | 5620 best_score= score; |
| 945 | 5621 run_tab[i+1]= run; |
| 5622 level_tab[i+1]= level-64; | |
| 5623 } | |
| 5624 } | |
| 5625 | |
| 5626 if(s->out_format == FMT_H263){ | |
| 1718 | 5627 for(j=survivor_count-1; j>=0; j--){ |
| 5628 int run= i - survivor[j]; | |
| 945 | 5629 int score= distoration + score_tab[i-run]; |
| 946 | 5630 if(score < last_score){ |
| 5631 last_score= score; | |
| 5632 last_run= run; | |
| 5633 last_level= level-64; | |
| 5634 last_i= i+1; | |
| 945 | 5635 } |
| 5636 } | |
| 5637 } | |
| 5638 } | |
| 5639 } | |
| 946 | 5640 |
| 1718 | 5641 score_tab[i+1]= best_score; |
| 5642 | |
| 946 | 5643 //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 | 5644 if(last_non_zero <= 27){ |
| 5645 for(; survivor_count; survivor_count--){ | |
| 5646 if(score_tab[ survivor[survivor_count-1] ] <= best_score) | |
| 5647 break; | |
| 5648 } | |
| 5649 }else{ | |
| 5650 for(; survivor_count; survivor_count--){ | |
| 5651 if(score_tab[ survivor[survivor_count-1] ] <= best_score + lambda) | |
| 5652 break; | |
| 5653 } | |
|
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
|
5654 } |
| 1718 | 5655 |
| 5656 survivor[ survivor_count++ ]= i+1; | |
| 945 | 5657 } |
| 946 | 5658 |
| 945 | 5659 if(s->out_format != FMT_H263){ |
| 946 | 5660 last_score= 256*256*256*120; |
| 1718 | 5661 for(i= survivor[0]; i<=last_non_zero + 1; i++){ |
| 946 | 5662 int score= score_tab[i]; |
| 947 | 5663 if(i) score += lambda*2; //FIXME exacter? |
| 5664 | |
| 946 | 5665 if(score < last_score){ |
| 5666 last_score= score; | |
| 5667 last_i= i; | |
| 5668 last_level= level_tab[i]; | |
| 5669 last_run= run_tab[i]; | |
| 5670 } | |
| 945 | 5671 } |
| 5672 } | |
|
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5673 |
| 1715 | 5674 s->coded_score[n] = last_score; |
| 945 | 5675 |
| 1716 | 5676 dc= ABS(block[0]); |
| 1718 | 5677 last_non_zero= last_i - 1; |
| 945 | 5678 memset(block + start_i, 0, (64-start_i)*sizeof(DCTELEM)); |
| 5679 | |
| 5680 if(last_non_zero < start_i) | |
| 5681 return last_non_zero; | |
|
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5682 |
|
1480
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5683 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
|
5684 int best_level= 0; |
|
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5685 int best_score= dc * dc; |
|
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5686 |
|
1480
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5687 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
|
5688 int level= coeff[i][0]; |
| 1716 | 5689 int alevel= ABS(level); |
| 5690 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
|
5691 |
|
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5692 if(s->out_format == FMT_H263){ |
| 1716 | 5693 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
|
5694 }else{ //MPEG1 |
| 1716 | 5695 unquant_coeff = ((( alevel << 1) + 1) * qscale * ((int) s->inter_matrix[0])) >> 4; |
| 5696 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
|
5697 } |
|
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5698 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
|
5699 unquant_coeff<<= 3 + 3; |
|
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5700 |
| 1716 | 5701 distortion= (unquant_coeff - dc) * (unquant_coeff - dc); |
|
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5702 level+=64; |
| 1716 | 5703 if((level&(~127)) == 0) score= distortion + last_length[UNI_AC_ENC_INDEX(0, level)]*lambda; |
| 5704 else score= distortion + esc_length*lambda; | |
|
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5705 |
|
1480
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5706 if(score < best_score){ |
|
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5707 best_score= score; |
|
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5708 best_level= level - 64; |
|
1480
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5709 } |
|
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5710 } |
|
8657d6800d15
slight quality improvement ( < +0.04 PSNR) for high bitrate videos with trellis quantization
michaelni
parents:
1471
diff
changeset
|
5711 block[0]= best_level; |
|
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5712 s->coded_score[n] = best_score - dc*dc; |
|
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5713 if(best_level == 0) return -1; |
|
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5714 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
|
5715 } |
|
1490
0355f2b3519a
rate distortion optimal cbp support (h263/mpeg4 non intra only)
michaelni
parents:
1480
diff
changeset
|
5716 |
| 946 | 5717 i= last_i; |
| 5718 assert(last_level); | |
| 1718 | 5719 |
| 5720 block[ perm_scantable[last_non_zero] ]= last_level; | |
| 946 | 5721 i -= last_run + 1; |
| 945 | 5722 |
| 1718 | 5723 for(; i>start_i; i -= run_tab[i] + 1){ |
| 5724 block[ perm_scantable[i-1] ]= level_tab[i]; | |
| 945 | 5725 } |
| 5726 | |
| 5727 return last_non_zero; | |
| 5728 } | |
| 5729 | |
| 1777 | 5730 //#define REFINE_STATS 1 |
| 5731 static int16_t basis[64][64]; | |
| 5732 | |
| 5733 static void build_basis(uint8_t *perm){ | |
| 5734 int i, j, x, y; | |
| 5735 emms_c(); | |
| 5736 for(i=0; i<8; i++){ | |
| 5737 for(j=0; j<8; j++){ | |
| 5738 for(y=0; y<8; y++){ | |
| 5739 for(x=0; x<8; x++){ | |
| 5740 double s= 0.25*(1<<BASIS_SHIFT); | |
| 5741 int index= 8*i + j; | |
| 5742 int perm_index= perm[index]; | |
| 5743 if(i==0) s*= sqrt(0.5); | |
| 5744 if(j==0) s*= sqrt(0.5); | |
| 5745 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))); | |
| 5746 } | |
| 5747 } | |
| 5748 } | |
| 5749 } | |
| 5750 } | |
| 5751 | |
| 5752 static int dct_quantize_refine(MpegEncContext *s, //FIXME breaks denoise? | |
| 5753 DCTELEM *block, int16_t *weight, DCTELEM *orig, | |
| 5754 int n, int qscale){ | |
| 5755 int16_t rem[64]; | |
|
2289
5443c3fc2448
Quantizer noise shaping crashes on SSE2 machines patch by (Milan Cutka <cutka at szm dot sk>)
michael
parents:
2266
diff
changeset
|
5756 DCTELEM d1[64] __align16; |
| 1777 | 5757 const int *qmat; |
| 5758 const uint8_t *scantable= s->intra_scantable.scantable; | |
| 5759 const uint8_t *perm_scantable= s->intra_scantable.permutated; | |
| 5760 // unsigned int threshold1, threshold2; | |
| 5761 // int bias=0; | |
| 5762 int run_tab[65]; | |
| 5763 int prev_run=0; | |
| 5764 int prev_level=0; | |
| 5765 int qmul, qadd, start_i, last_non_zero, i, dc; | |
| 5766 uint8_t * length; | |
| 5767 uint8_t * last_length; | |
| 5768 int lambda; | |
| 5769 int rle_index, run, q, sum; | |
| 5770 #ifdef REFINE_STATS | |
| 5771 static int count=0; | |
| 5772 static int after_last=0; | |
| 5773 static int to_zero=0; | |
| 5774 static int from_zero=0; | |
| 5775 static int raise=0; | |
| 5776 static int lower=0; | |
| 5777 static int messed_sign=0; | |
| 5778 #endif | |
| 5779 | |
| 5780 if(basis[0][0] == 0) | |
| 5781 build_basis(s->dsp.idct_permutation); | |
| 5782 | |
| 5783 qmul= qscale*2; | |
| 5784 qadd= (qscale-1)|1; | |
| 5785 if (s->mb_intra) { | |
| 5786 if (!s->h263_aic) { | |
| 5787 if (n < 4) | |
| 5788 q = s->y_dc_scale; | |
| 5789 else | |
| 5790 q = s->c_dc_scale; | |
| 5791 } else{ | |
| 5792 /* For AIC we skip quant/dequant of INTRADC */ | |
| 5793 q = 1; | |
| 5794 qadd=0; | |
| 5795 } | |
| 5796 q <<= RECON_SHIFT-3; | |
| 5797 /* note: block[0] is assumed to be positive */ | |
| 5798 dc= block[0]*q; | |
| 5799 // block[0] = (block[0] + (q >> 1)) / q; | |
| 5800 start_i = 1; | |
| 5801 qmat = s->q_intra_matrix[qscale]; | |
| 5802 // if(s->mpeg_quant || s->out_format == FMT_MPEG1) | |
| 5803 // bias= 1<<(QMAT_SHIFT-1); | |
| 5804 length = s->intra_ac_vlc_length; | |
| 5805 last_length= s->intra_ac_vlc_last_length; | |
| 5806 } else { | |
| 5807 dc= 0; | |
| 5808 start_i = 0; | |
| 5809 qmat = s->q_inter_matrix[qscale]; | |
| 5810 length = s->inter_ac_vlc_length; | |
| 5811 last_length= s->inter_ac_vlc_last_length; | |
| 5812 } | |
| 5813 last_non_zero = s->block_last_index[n]; | |
| 5814 | |
| 5815 #ifdef REFINE_STATS | |
| 5816 {START_TIMER | |
| 5817 #endif | |
| 1784 | 5818 dc += (1<<(RECON_SHIFT-1)); |
| 5819 for(i=0; i<64; i++){ | |
| 5820 rem[i]= dc - (orig[i]<<RECON_SHIFT); //FIXME use orig dirrectly insteadof copying to rem[] | |
| 1777 | 5821 } |
| 5822 #ifdef REFINE_STATS | |
| 5823 STOP_TIMER("memset rem[]")} | |
| 5824 #endif | |
| 5825 sum=0; | |
| 5826 for(i=0; i<64; i++){ | |
| 5827 int one= 36; | |
| 5828 int qns=4; | |
| 5829 int w; | |
| 5830 | |
| 5831 w= ABS(weight[i]) + qns*one; | |
| 5832 w= 15 + (48*qns*one + w/2)/w; // 16 .. 63 | |
| 5833 | |
| 5834 weight[i] = w; | |
| 5835 // w=weight[i] = (63*qns + (w/2)) / w; | |
| 5836 | |
| 5837 assert(w>0); | |
| 5838 assert(w<(1<<6)); | |
| 5839 sum += w*w; | |
| 5840 } | |
| 5841 lambda= sum*(uint64_t)s->lambda2 >> (FF_LAMBDA_SHIFT - 6 + 6 + 6 + 6); | |
| 5842 #ifdef REFINE_STATS | |
| 5843 {START_TIMER | |
| 5844 #endif | |
| 5845 run=0; | |
| 5846 rle_index=0; | |
| 5847 for(i=start_i; i<=last_non_zero; i++){ | |
| 5848 int j= perm_scantable[i]; | |
| 5849 const int level= block[j]; | |
| 5850 int coeff; | |
| 5851 | |
| 5852 if(level){ | |
| 5853 if(level<0) coeff= qmul*level - qadd; | |
| 5854 else coeff= qmul*level + qadd; | |
| 5855 run_tab[rle_index++]=run; | |
| 5856 run=0; | |
| 5857 | |
| 1784 | 5858 s->dsp.add_8x8basis(rem, basis[j], coeff); |
| 1777 | 5859 }else{ |
| 5860 run++; | |
| 5861 } | |
| 5862 } | |
| 5863 #ifdef REFINE_STATS | |
| 5864 if(last_non_zero>0){ | |
| 5865 STOP_TIMER("init rem[]") | |
| 5866 } | |
| 5867 } | |
| 5868 | |
| 5869 {START_TIMER | |
| 5870 #endif | |
| 5871 for(;;){ | |
| 1784 | 5872 int best_score=s->dsp.try_8x8basis(rem, weight, basis[0], 0); |
| 1777 | 5873 int best_coeff=0; |
| 5874 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
|
5875 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
|
5876 #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
|
5877 {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
|
5878 #endif |
|
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
5879 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
|
5880 |
|
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
5881 if(analyze_gradient){ |
| 1777 | 5882 #ifdef REFINE_STATS |
| 5883 {START_TIMER | |
| 5884 #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
|
5885 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
|
5886 int w= weight[i]; |
|
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
5887 |
|
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
5888 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
|
5889 } |
|
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
5890 #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
|
5891 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
|
5892 {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
|
5893 #endif |
|
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
5894 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
|
5895 #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
|
5896 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
|
5897 #endif |
|
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
5898 } |
|
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
5899 |
| 1777 | 5900 if(start_i){ |
| 5901 const int level= block[0]; | |
| 5902 int change, old_coeff; | |
| 5903 | |
| 5904 assert(s->mb_intra); | |
| 5905 | |
| 5906 old_coeff= q*level; | |
| 5907 | |
| 5908 for(change=-1; change<=1; change+=2){ | |
| 5909 int new_level= level + change; | |
| 5910 int score, new_coeff; | |
| 5911 | |
| 5912 new_coeff= q*new_level; | |
| 5913 if(new_coeff >= 2048 || new_coeff < 0) | |
| 5914 continue; | |
| 5915 | |
| 1784 | 5916 score= s->dsp.try_8x8basis(rem, weight, basis[0], new_coeff - old_coeff); |
| 1777 | 5917 if(score<best_score){ |
| 5918 best_score= score; | |
| 5919 best_coeff= 0; | |
| 5920 best_change= change; | |
| 5921 best_unquant_change= new_coeff - old_coeff; | |
| 5922 } | |
| 5923 } | |
| 5924 } | |
| 5925 | |
| 5926 run=0; | |
| 5927 rle_index=0; | |
| 5928 run2= run_tab[rle_index++]; | |
| 5929 prev_level=0; | |
| 5930 prev_run=0; | |
| 5931 | |
| 5932 for(i=start_i; i<64; i++){ | |
| 5933 int j= perm_scantable[i]; | |
| 5934 const int level= block[j]; | |
| 5935 int change, old_coeff; | |
| 5936 | |
| 5937 if(s->avctx->quantizer_noise_shaping < 3 && i > last_non_zero + 1) | |
| 5938 break; | |
| 5939 | |
| 5940 if(level){ | |
| 5941 if(level<0) old_coeff= qmul*level - qadd; | |
| 5942 else old_coeff= qmul*level + qadd; | |
| 5943 run2= run_tab[rle_index++]; //FIXME ! maybe after last | |
| 5944 }else{ | |
| 5945 old_coeff=0; | |
| 5946 run2--; | |
| 5947 assert(run2>=0 || i >= last_non_zero ); | |
| 5948 } | |
| 5949 | |
| 5950 for(change=-1; change<=1; change+=2){ | |
| 5951 int new_level= level + change; | |
| 5952 int score, new_coeff, unquant_change; | |
| 5953 | |
| 5954 score=0; | |
| 5955 if(s->avctx->quantizer_noise_shaping < 2 && ABS(new_level) > ABS(level)) | |
| 5956 continue; | |
| 5957 | |
| 5958 if(new_level){ | |
| 5959 if(new_level<0) new_coeff= qmul*new_level - qadd; | |
| 5960 else new_coeff= qmul*new_level + qadd; | |
| 5961 if(new_coeff >= 2048 || new_coeff <= -2048) | |
| 5962 continue; | |
| 5963 //FIXME check for overflow | |
| 5964 | |
| 5965 if(level){ | |
| 5966 if(level < 63 && level > -63){ | |
| 5967 if(i < last_non_zero) | |
| 5968 score += length[UNI_AC_ENC_INDEX(run, new_level+64)] | |
| 5969 - length[UNI_AC_ENC_INDEX(run, level+64)]; | |
| 5970 else | |
| 5971 score += last_length[UNI_AC_ENC_INDEX(run, new_level+64)] | |
| 5972 - last_length[UNI_AC_ENC_INDEX(run, level+64)]; | |
| 5973 } | |
| 5974 }else{ | |
| 5975 assert(ABS(new_level)==1); | |
|
1785
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
5976 |
|
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
5977 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
|
5978 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
|
5979 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
|
5980 continue; |
|
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
5981 } |
|
14d918d0ef42
analyze the gradient of the error surface to avoid a few checks in the quantizing noise shaper
michael
parents:
1784
diff
changeset
|
5982 |
| 1777 | 5983 if(i < last_non_zero){ |
| 5984 int next_i= i + run2 + 1; | |
| 5985 int next_level= block[ perm_scantable[next_i] ] + 64; | |
| 5986 | |
| 5987 if(next_level&(~127)) | |
| 5988 next_level= 0; | |
| 5989 | |
| 5990 if(next_i < last_non_zero) | |
| 5991 score += length[UNI_AC_ENC_INDEX(run, 65)] | |
| 5992 + length[UNI_AC_ENC_INDEX(run2, next_level)] | |
| 5993 - length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)]; | |
| 5994 else | |
| 5995 score += length[UNI_AC_ENC_INDEX(run, 65)] | |
| 5996 + last_length[UNI_AC_ENC_INDEX(run2, next_level)] | |
| 5997 - last_length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)]; | |
| 5998 }else{ | |
| 5999 score += last_length[UNI_AC_ENC_INDEX(run, 65)]; | |
| 6000 if(prev_level){ | |
| 6001 score += length[UNI_AC_ENC_INDEX(prev_run, prev_level)] | |
| 6002 - last_length[UNI_AC_ENC_INDEX(prev_run, prev_level)]; | |
| 6003 } | |
| 6004 } | |
| 6005 } | |
| 6006 }else{ | |
| 6007 new_coeff=0; | |
| 6008 assert(ABS(level)==1); | |
| 6009 | |
| 6010 if(i < last_non_zero){ | |
| 6011 int next_i= i + run2 + 1; | |
| 6012 int next_level= block[ perm_scantable[next_i] ] + 64; | |
| 6013 | |
| 6014 if(next_level&(~127)) | |
| 6015 next_level= 0; | |
| 6016 | |
| 6017 if(next_i < last_non_zero) | |
| 6018 score += length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)] | |
| 6019 - length[UNI_AC_ENC_INDEX(run2, next_level)] | |
| 6020 - length[UNI_AC_ENC_INDEX(run, 65)]; | |
| 6021 else | |
| 6022 score += last_length[UNI_AC_ENC_INDEX(run + run2 + 1, next_level)] | |
| 6023 - last_length[UNI_AC_ENC_INDEX(run2, next_level)] | |
| 6024 - length[UNI_AC_ENC_INDEX(run, 65)]; | |
| 6025 }else{ | |
| 6026 score += -last_length[UNI_AC_ENC_INDEX(run, 65)]; | |
| 6027 if(prev_level){ | |
| 6028 score += last_length[UNI_AC_ENC_INDEX(prev_run, prev_level)] | |
| 6029 - length[UNI_AC_ENC_INDEX(prev_run, prev_level)]; | |
| 6030 } | |
| 6031 } | |
| 6032 } | |
| 6033 | |
| 6034 score *= lambda; | |
| 6035 | |
| 6036 unquant_change= new_coeff - old_coeff; | |
| 6037 assert((score < 100*lambda && score > -100*lambda) || lambda==0); | |
| 6038 | |
| 1784 | 6039 score+= s->dsp.try_8x8basis(rem, weight, basis[j], unquant_change); |
| 1777 | 6040 if(score<best_score){ |
| 6041 best_score= score; | |
| 6042 best_coeff= i; | |
| 6043 best_change= change; | |
| 6044 best_unquant_change= unquant_change; | |
| 6045 } | |
| 6046 } | |
| 6047 if(level){ | |
| 6048 prev_level= level + 64; | |
| 6049 if(prev_level&(~127)) | |
| 6050 prev_level= 0; | |
| 6051 prev_run= run; | |
| 6052 run=0; | |
| 6053 }else{ | |
| 6054 run++; | |
| 6055 } | |
| 6056 } | |
| 6057 #ifdef REFINE_STATS | |
| 6058 STOP_TIMER("iterative step")} | |
| 6059 #endif | |
| 6060 | |
| 6061 if(best_change){ | |
| 6062 int j= perm_scantable[ best_coeff ]; | |
| 6063 | |
| 6064 block[j] += best_change; | |
| 6065 | |
| 6066 if(best_coeff > last_non_zero){ | |
| 6067 last_non_zero= best_coeff; | |
| 6068 assert(block[j]); | |
| 6069 #ifdef REFINE_STATS | |
| 6070 after_last++; | |
| 6071 #endif | |
| 6072 }else{ | |
| 6073 #ifdef REFINE_STATS | |
| 6074 if(block[j]){ | |
| 6075 if(block[j] - best_change){ | |
| 6076 if(ABS(block[j]) > ABS(block[j] - best_change)){ | |
| 6077 raise++; | |
| 6078 }else{ | |
| 6079 lower++; | |
| 6080 } | |
| 6081 }else{ | |
| 6082 from_zero++; | |
| 6083 } | |
| 6084 }else{ | |
| 6085 to_zero++; | |
| 6086 } | |
| 6087 #endif | |
| 6088 for(; last_non_zero>=start_i; last_non_zero--){ | |
| 6089 if(block[perm_scantable[last_non_zero]]) | |
| 6090 break; | |
| 6091 } | |
| 6092 } | |
| 6093 #ifdef REFINE_STATS | |
| 6094 count++; | |
| 6095 if(256*256*256*64 % count == 0){ | |
| 6096 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); | |
| 6097 } | |
| 6098 #endif | |
| 6099 run=0; | |
| 6100 rle_index=0; | |
| 6101 for(i=start_i; i<=last_non_zero; i++){ | |
| 6102 int j= perm_scantable[i]; | |
| 6103 const int level= block[j]; | |
| 6104 | |
| 6105 if(level){ | |
| 6106 run_tab[rle_index++]=run; | |
| 6107 run=0; | |
| 6108 }else{ | |
| 6109 run++; | |
| 6110 } | |
| 6111 } | |
| 6112 | |
| 1784 | 6113 s->dsp.add_8x8basis(rem, basis[j], best_unquant_change); |
| 1777 | 6114 }else{ |
| 6115 break; | |
| 6116 } | |
| 6117 } | |
| 6118 #ifdef REFINE_STATS | |
| 6119 if(last_non_zero>0){ | |
| 6120 STOP_TIMER("iterative search") | |
| 6121 } | |
| 6122 } | |
| 6123 #endif | |
| 6124 | |
| 6125 return last_non_zero; | |
| 6126 } | |
| 6127 | |
| 220 | 6128 static int dct_quantize_c(MpegEncContext *s, |
| 0 | 6129 DCTELEM *block, int n, |
| 344 | 6130 int qscale, int *overflow) |
| 0 | 6131 { |
| 1715 | 6132 int i, j, level, last_non_zero, q, start_i; |
| 0 | 6133 const int *qmat; |
| 1064 | 6134 const uint8_t *scantable= s->intra_scantable.scantable; |
| 344 | 6135 int bias; |
| 6136 int max=0; | |
| 6137 unsigned int threshold1, threshold2; | |
|
828
ace3ccd18dd2
Altivec Patch (Mark III) by (Dieter Shirley <dieters at schemasoft dot com>)
michaelni
parents:
815
diff
changeset
|
6138 |
| 1092 | 6139 s->dsp.fdct (block); |
| 0 | 6140 |
| 1597 | 6141 if(s->dct_error_sum) |
| 1719 | 6142 s->denoise_dct(s, block); |
| 1597 | 6143 |
| 0 | 6144 if (s->mb_intra) { |
|
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6145 if (!s->h263_aic) { |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6146 if (n < 4) |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6147 q = s->y_dc_scale; |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6148 else |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6149 q = s->c_dc_scale; |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6150 q = q << 3; |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6151 } else |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6152 /* 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
|
6153 q = 1 << 3; |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
6154 |
| 0 | 6155 /* note: block[0] is assumed to be positive */ |
| 6156 block[0] = (block[0] + (q >> 1)) / q; | |
| 1715 | 6157 start_i = 1; |
| 0 | 6158 last_non_zero = 0; |
| 344 | 6159 qmat = s->q_intra_matrix[qscale]; |
| 635 | 6160 bias= s->intra_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); |
| 0 | 6161 } else { |
| 1715 | 6162 start_i = 0; |
| 0 | 6163 last_non_zero = -1; |
| 344 | 6164 qmat = s->q_inter_matrix[qscale]; |
| 635 | 6165 bias= s->inter_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); |
| 0 | 6166 } |
| 635 | 6167 threshold1= (1<<QMAT_SHIFT) - bias - 1; |
| 6168 threshold2= (threshold1<<1); | |
| 1715 | 6169 for(i=63;i>=start_i;i--) { |
| 764 | 6170 j = scantable[i]; |
| 1715 | 6171 level = block[j] * qmat[j]; |
| 6172 | |
| 6173 if(((unsigned)(level+threshold1))>threshold2){ | |
| 6174 last_non_zero = i; | |
| 6175 break; | |
| 6176 }else{ | |
| 6177 block[j]=0; | |
| 6178 } | |
| 6179 } | |
| 6180 for(i=start_i; i<=last_non_zero; i++) { | |
| 6181 j = scantable[i]; | |
| 6182 level = block[j] * qmat[j]; | |
| 344 | 6183 |
| 1215 | 6184 // if( bias+level >= (1<<QMAT_SHIFT) |
| 6185 // || bias-level >= (1<<QMAT_SHIFT)){ | |
| 344 | 6186 if(((unsigned)(level+threshold1))>threshold2){ |
| 6187 if(level>0){ | |
| 635 | 6188 level= (bias + level)>>QMAT_SHIFT; |
| 344 | 6189 block[j]= level; |
| 6190 }else{ | |
| 635 | 6191 level= (bias - level)>>QMAT_SHIFT; |
| 344 | 6192 block[j]= -level; |
| 0 | 6193 } |
| 344 | 6194 max |=level; |
| 6195 }else{ | |
| 6196 block[j]=0; | |
| 0 | 6197 } |
| 6198 } | |
| 344 | 6199 *overflow= s->max_qcoeff < max; //overflow might have happend |
| 6200 | |
| 764 | 6201 /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */ |
| 1092 | 6202 if (s->dsp.idct_permutation_type != FF_NO_IDCT_PERM) |
| 6203 ff_block_permute(block, s->dsp.idct_permutation, scantable, last_non_zero); | |
| 764 | 6204 |
| 0 | 6205 return last_non_zero; |
| 6206 } | |
| 6207 | |
|
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
|
6208 #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
|
6209 |
| 1689 | 6210 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
|
6211 DCTELEM *block, int n, int qscale) |
| 0 | 6212 { |
| 200 | 6213 int i, level, nCoeffs; |
| 1064 | 6214 const uint16_t *quant_matrix; |
| 0 | 6215 |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6216 nCoeffs= s->block_last_index[n]; |
| 200 | 6217 |
| 1689 | 6218 if (n < 4) |
| 6219 block[0] = block[0] * s->y_dc_scale; | |
| 6220 else | |
| 6221 block[0] = block[0] * s->c_dc_scale; | |
| 6222 /* XXX: only mpeg1 */ | |
| 6223 quant_matrix = s->intra_matrix; | |
| 6224 for(i=1;i<=nCoeffs;i++) { | |
| 6225 int j= s->intra_scantable.permutated[i]; | |
| 6226 level = block[j]; | |
| 6227 if (level) { | |
| 6228 if (level < 0) { | |
| 6229 level = -level; | |
| 6230 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 6231 level = (level - 1) | 1; | |
| 6232 level = -level; | |
| 6233 } else { | |
| 6234 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 6235 level = (level - 1) | 1; | |
| 0 | 6236 } |
| 1689 | 6237 block[j] = level; |
| 0 | 6238 } |
| 6239 } | |
| 6240 } | |
|
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
|
6241 |
| 1689 | 6242 static void dct_unquantize_mpeg1_inter_c(MpegEncContext *s, |
| 6243 DCTELEM *block, int n, int qscale) | |
| 6244 { | |
| 6245 int i, level, nCoeffs; | |
| 6246 const uint16_t *quant_matrix; | |
| 6247 | |
| 6248 nCoeffs= s->block_last_index[n]; | |
| 6249 | |
| 6250 quant_matrix = s->inter_matrix; | |
| 6251 for(i=0; i<=nCoeffs; i++) { | |
| 6252 int j= s->intra_scantable.permutated[i]; | |
| 6253 level = block[j]; | |
| 6254 if (level) { | |
| 6255 if (level < 0) { | |
| 6256 level = -level; | |
| 6257 level = (((level << 1) + 1) * qscale * | |
| 6258 ((int) (quant_matrix[j]))) >> 4; | |
| 6259 level = (level - 1) | 1; | |
| 6260 level = -level; | |
| 6261 } else { | |
| 6262 level = (((level << 1) + 1) * qscale * | |
| 6263 ((int) (quant_matrix[j]))) >> 4; | |
| 6264 level = (level - 1) | 1; | |
| 6265 } | |
| 6266 block[j] = level; | |
| 6267 } | |
| 6268 } | |
| 6269 } | |
| 6270 | |
| 6271 static void dct_unquantize_mpeg2_intra_c(MpegEncContext *s, | |
| 325 | 6272 DCTELEM *block, int n, int qscale) |
| 6273 { | |
| 6274 int i, level, nCoeffs; | |
| 1064 | 6275 const uint16_t *quant_matrix; |
| 325 | 6276 |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6277 if(s->alternate_scan) nCoeffs= 63; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6278 else nCoeffs= s->block_last_index[n]; |
| 325 | 6279 |
| 1689 | 6280 if (n < 4) |
| 6281 block[0] = block[0] * s->y_dc_scale; | |
| 6282 else | |
| 6283 block[0] = block[0] * s->c_dc_scale; | |
| 6284 quant_matrix = s->intra_matrix; | |
| 6285 for(i=1;i<=nCoeffs;i++) { | |
| 6286 int j= s->intra_scantable.permutated[i]; | |
| 6287 level = block[j]; | |
| 6288 if (level) { | |
| 6289 if (level < 0) { | |
| 6290 level = -level; | |
| 6291 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 6292 level = -level; | |
| 6293 } else { | |
| 6294 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 6295 } | |
| 6296 block[j] = level; | |
| 6297 } | |
| 6298 } | |
| 6299 } | |
| 6300 | |
| 6301 static void dct_unquantize_mpeg2_inter_c(MpegEncContext *s, | |
| 6302 DCTELEM *block, int n, int qscale) | |
| 6303 { | |
| 6304 int i, level, nCoeffs; | |
| 6305 const uint16_t *quant_matrix; | |
| 6306 int sum=-1; | |
| 6307 | |
| 6308 if(s->alternate_scan) nCoeffs= 63; | |
| 6309 else nCoeffs= s->block_last_index[n]; | |
| 6310 | |
| 6311 quant_matrix = s->inter_matrix; | |
| 6312 for(i=0; i<=nCoeffs; i++) { | |
| 6313 int j= s->intra_scantable.permutated[i]; | |
| 6314 level = block[j]; | |
| 6315 if (level) { | |
| 6316 if (level < 0) { | |
| 6317 level = -level; | |
| 6318 level = (((level << 1) + 1) * qscale * | |
| 6319 ((int) (quant_matrix[j]))) >> 4; | |
| 6320 level = -level; | |
| 6321 } else { | |
| 6322 level = (((level << 1) + 1) * qscale * | |
| 6323 ((int) (quant_matrix[j]))) >> 4; | |
| 6324 } | |
| 6325 block[j] = level; | |
| 6326 sum+=level; | |
| 6327 } | |
| 6328 } | |
| 6329 block[63]^=sum&1; | |
| 6330 } | |
| 6331 | |
| 6332 static void dct_unquantize_h263_intra_c(MpegEncContext *s, | |
| 6333 DCTELEM *block, int n, int qscale) | |
| 6334 { | |
| 6335 int i, level, qmul, qadd; | |
| 6336 int nCoeffs; | |
| 6337 | |
| 6338 assert(s->block_last_index[n]>=0); | |
| 6339 | |
| 6340 qmul = qscale << 1; | |
| 6341 | |
| 6342 if (!s->h263_aic) { | |
| 325 | 6343 if (n < 4) |
| 6344 block[0] = block[0] * s->y_dc_scale; | |
| 6345 else | |
| 6346 block[0] = block[0] * s->c_dc_scale; | |
| 1689 | 6347 qadd = (qscale - 1) | 1; |
| 6348 }else{ | |
| 6349 qadd = 0; | |
| 6350 } | |
| 6351 if(s->ac_pred) | |
| 6352 nCoeffs=63; | |
| 6353 else | |
| 6354 nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ]; | |
| 6355 | |
| 6356 for(i=1; i<=nCoeffs; i++) { | |
| 6357 level = block[i]; | |
| 6358 if (level) { | |
| 6359 if (level < 0) { | |
| 6360 level = level * qmul - qadd; | |
| 6361 } else { | |
| 6362 level = level * qmul + qadd; | |
| 325 | 6363 } |
| 1689 | 6364 block[i] = level; |
| 325 | 6365 } |
| 6366 } | |
| 6367 } | |
| 6368 | |
| 1689 | 6369 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
|
6370 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
|
6371 { |
|
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
|
6372 int i, level, qmul, qadd; |
| 200 | 6373 int nCoeffs; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
6374 |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6375 assert(s->block_last_index[n]>=0); |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6376 |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6377 qadd = (qscale - 1) | 1; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6378 qmul = qscale << 1; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
6379 |
| 1689 | 6380 nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ]; |
| 6381 | |
| 6382 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
|
6383 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
|
6384 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
|
6385 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
|
6386 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
|
6387 } 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
|
6388 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
|
6389 } |
|
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
|
6390 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
|
6391 } |
|
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
|
6392 } |
|
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
|
6393 } |
| 0 | 6394 |
| 1059 | 6395 static const AVOption mpeg4_options[] = |
| 6396 { | |
| 6397 AVOPTION_CODEC_INT("bitrate", "desired video bitrate", bit_rate, 4, 240000000, 800000), | |
| 6398 AVOPTION_CODEC_INT("ratetol", "number of bits the bitstream is allowed to diverge from the reference" | |
| 6399 "the reference can be CBR (for CBR pass1) or VBR (for pass2)", | |
| 6400 bit_rate_tolerance, 4, 240000000, 8000), | |
| 6401 AVOPTION_CODEC_INT("qmin", "minimum quantizer", qmin, 1, 31, 2), | |
| 6402 AVOPTION_CODEC_INT("qmax", "maximum quantizer", qmax, 1, 31, 31), | |
| 6403 AVOPTION_CODEC_STRING("rc_eq", "rate control equation", | |
| 6404 rc_eq, "tex^qComp,option1,options2", 0), | |
| 6405 AVOPTION_CODEC_INT("rc_minrate", "rate control minimum bitrate", | |
| 6406 rc_min_rate, 4, 24000000, 0), | |
| 6407 AVOPTION_CODEC_INT("rc_maxrate", "rate control maximum bitrate", | |
| 6408 rc_max_rate, 4, 24000000, 0), | |
| 1130 | 6409 AVOPTION_CODEC_DOUBLE("rc_buf_aggresivity", "rate control buffer aggresivity", |
| 6410 rc_buffer_aggressivity, 4, 24000000, 0), | |
| 6411 AVOPTION_CODEC_DOUBLE("rc_initial_cplx", "initial complexity for pass1 ratecontrol", | |
| 6412 rc_initial_cplx, 0., 9999999., 0), | |
| 6413 AVOPTION_CODEC_DOUBLE("i_quant_factor", "qscale factor between p and i frames", | |
| 6414 i_quant_factor, 0., 0., 0), | |
| 6415 AVOPTION_CODEC_DOUBLE("i_quant_offset", "qscale offset between p and i frames", | |
| 6416 i_quant_factor, -999999., 999999., 0), | |
| 6417 AVOPTION_CODEC_INT("dct_algo", "dct alghorithm", | |
| 6418 dct_algo, 0, 5, 0), // fixme - "Auto,FastInt,Int,MMX,MLib,Altivec" | |
| 6419 AVOPTION_CODEC_DOUBLE("lumi_masking", "luminance masking", | |
| 6420 lumi_masking, 0., 999999., 0), | |
| 6421 AVOPTION_CODEC_DOUBLE("temporal_cplx_masking", "temporary complexity masking", | |
| 6422 temporal_cplx_masking, 0., 999999., 0), | |
| 6423 AVOPTION_CODEC_DOUBLE("spatial_cplx_masking", "spatial complexity masking", | |
| 6424 spatial_cplx_masking, 0., 999999., 0), | |
| 6425 AVOPTION_CODEC_DOUBLE("p_masking", "p block masking", | |
| 6426 p_masking, 0., 999999., 0), | |
| 6427 AVOPTION_CODEC_DOUBLE("dark_masking", "darkness masking", | |
| 6428 dark_masking, 0., 999999., 0), | |
| 6429 AVOPTION_CODEC_INT("idct_algo", "idct alghorithm", | |
| 6430 idct_algo, 0, 8, 0), // fixme - "Auto,Int,Simple,SimpleMMX,LibMPEG2MMX,PS2,MLib,ARM,Altivec" | |
| 6431 | |
| 6432 AVOPTION_CODEC_INT("mb_qmin", "minimum MB quantizer", | |
| 6433 mb_qmin, 0, 8, 0), | |
| 6434 AVOPTION_CODEC_INT("mb_qmax", "maximum MB quantizer", | |
| 6435 mb_qmin, 0, 8, 0), | |
| 6436 | |
| 6437 AVOPTION_CODEC_INT("me_cmp", "ME compare function", | |
| 6438 me_cmp, 0, 24000000, 0), | |
| 6439 AVOPTION_CODEC_INT("me_sub_cmp", "subpixel ME compare function", | |
| 6440 me_sub_cmp, 0, 24000000, 0), | |
| 6441 | |
| 6442 | |
| 6443 AVOPTION_CODEC_INT("dia_size", "ME diamond size & shape", | |
| 6444 dia_size, 0, 24000000, 0), | |
| 6445 AVOPTION_CODEC_INT("last_predictor_count", "amount of previous MV predictors", | |
| 6446 last_predictor_count, 0, 24000000, 0), | |
| 6447 | |
| 6448 AVOPTION_CODEC_INT("pre_me", "pre pass for ME", | |
| 6449 pre_me, 0, 24000000, 0), | |
| 6450 AVOPTION_CODEC_INT("me_pre_cmp", "ME pre pass compare function", | |
| 6451 me_pre_cmp, 0, 24000000, 0), | |
| 6452 | |
| 6453 AVOPTION_CODEC_INT("me_range", "maximum ME search range", | |
| 6454 me_range, 0, 24000000, 0), | |
| 6455 AVOPTION_CODEC_INT("pre_dia_size", "ME pre pass diamod size & shape", | |
| 6456 pre_dia_size, 0, 24000000, 0), | |
| 6457 AVOPTION_CODEC_INT("me_subpel_quality", "subpel ME quality", | |
| 6458 me_subpel_quality, 0, 24000000, 0), | |
| 6459 AVOPTION_CODEC_INT("me_range", "maximum ME search range", | |
| 6460 me_range, 0, 24000000, 0), | |
| 1059 | 6461 AVOPTION_CODEC_FLAG("psnr", "calculate PSNR of compressed frames", |
| 6462 flags, CODEC_FLAG_PSNR, 0), | |
| 6463 AVOPTION_CODEC_RCOVERRIDE("rc_override", "ratecontrol override (=startframe,endframe,qscale,quality_factor)", | |
| 6464 rc_override), | |
|
1124
64c7c76ed17c
* 'externaly' visible option list begins avoptions_ prefix
kabi
parents:
1116
diff
changeset
|
6465 AVOPTION_SUB(avoptions_common), |
| 1059 | 6466 AVOPTION_END() |
| 6467 }; | |
| 6468 | |
|
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
|
6469 #ifdef CONFIG_ENCODERS |
| 1042 | 6470 #ifdef CONFIG_RISKY |
| 0 | 6471 AVCodec h263_encoder = { |
| 6472 "h263", | |
| 6473 CODEC_TYPE_VIDEO, | |
| 6474 CODEC_ID_H263, | |
| 6475 sizeof(MpegEncContext), | |
| 6476 MPV_encode_init, | |
| 6477 MPV_encode_picture, | |
| 6478 MPV_encode_end, | |
| 6479 }; | |
| 6480 | |
| 6481 AVCodec h263p_encoder = { | |
| 6482 "h263p", | |
| 6483 CODEC_TYPE_VIDEO, | |
| 6484 CODEC_ID_H263P, | |
| 6485 sizeof(MpegEncContext), | |
| 6486 MPV_encode_init, | |
| 6487 MPV_encode_picture, | |
| 6488 MPV_encode_end, | |
| 6489 }; | |
| 6490 | |
|
1353
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6491 AVCodec flv_encoder = { |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6492 "flv", |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6493 CODEC_TYPE_VIDEO, |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6494 CODEC_ID_FLV1, |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6495 sizeof(MpegEncContext), |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6496 MPV_encode_init, |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6497 MPV_encode_picture, |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6498 MPV_encode_end, |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6499 }; |
|
cfc80b3a4ada
flash video (flv) support patch by (Garrick Meeker <gmeeker at theoryllc dot com>)
michaelni
parents:
1344
diff
changeset
|
6500 |
| 0 | 6501 AVCodec rv10_encoder = { |
| 6502 "rv10", | |
| 6503 CODEC_TYPE_VIDEO, | |
| 6504 CODEC_ID_RV10, | |
| 6505 sizeof(MpegEncContext), | |
| 6506 MPV_encode_init, | |
| 6507 MPV_encode_picture, | |
| 6508 MPV_encode_end, | |
| 6509 }; | |
| 6510 | |
| 2380 | 6511 AVCodec rv20_encoder = { |
| 6512 "rv20", | |
| 6513 CODEC_TYPE_VIDEO, | |
| 6514 CODEC_ID_RV20, | |
| 6515 sizeof(MpegEncContext), | |
| 6516 MPV_encode_init, | |
| 6517 MPV_encode_picture, | |
| 6518 MPV_encode_end, | |
| 6519 }; | |
| 6520 | |
| 71 | 6521 AVCodec mpeg4_encoder = { |
| 6522 "mpeg4", | |
| 0 | 6523 CODEC_TYPE_VIDEO, |
| 71 | 6524 CODEC_ID_MPEG4, |
| 0 | 6525 sizeof(MpegEncContext), |
| 6526 MPV_encode_init, | |
| 6527 MPV_encode_picture, | |
| 6528 MPV_encode_end, | |
| 1059 | 6529 .options = mpeg4_options, |
| 2111 | 6530 .capabilities= CODEC_CAP_DELAY, |
| 0 | 6531 }; |
| 6532 | |
| 307 | 6533 AVCodec msmpeg4v1_encoder = { |
| 6534 "msmpeg4v1", | |
| 0 | 6535 CODEC_TYPE_VIDEO, |
| 307 | 6536 CODEC_ID_MSMPEG4V1, |
| 0 | 6537 sizeof(MpegEncContext), |
| 6538 MPV_encode_init, | |
| 6539 MPV_encode_picture, | |
| 6540 MPV_encode_end, | |
| 1130 | 6541 .options = mpeg4_options, |
| 0 | 6542 }; |
| 307 | 6543 |
| 6544 AVCodec msmpeg4v2_encoder = { | |
| 6545 "msmpeg4v2", | |
| 6546 CODEC_TYPE_VIDEO, | |
| 6547 CODEC_ID_MSMPEG4V2, | |
| 6548 sizeof(MpegEncContext), | |
| 6549 MPV_encode_init, | |
| 6550 MPV_encode_picture, | |
| 6551 MPV_encode_end, | |
| 1130 | 6552 .options = mpeg4_options, |
| 307 | 6553 }; |
| 6554 | |
| 6555 AVCodec msmpeg4v3_encoder = { | |
| 6556 "msmpeg4", | |
| 6557 CODEC_TYPE_VIDEO, | |
| 6558 CODEC_ID_MSMPEG4V3, | |
| 6559 sizeof(MpegEncContext), | |
| 6560 MPV_encode_init, | |
| 6561 MPV_encode_picture, | |
| 6562 MPV_encode_end, | |
| 1130 | 6563 .options = mpeg4_options, |
| 307 | 6564 }; |
| 499 | 6565 |
| 6566 AVCodec wmv1_encoder = { | |
| 6567 "wmv1", | |
| 6568 CODEC_TYPE_VIDEO, | |
| 6569 CODEC_ID_WMV1, | |
| 6570 sizeof(MpegEncContext), | |
| 6571 MPV_encode_init, | |
| 6572 MPV_encode_picture, | |
| 6573 MPV_encode_end, | |
| 1130 | 6574 .options = mpeg4_options, |
| 499 | 6575 }; |
| 6576 | |
| 1042 | 6577 #endif |
| 6578 | |
| 6579 AVCodec mjpeg_encoder = { | |
| 6580 "mjpeg", | |
| 6581 CODEC_TYPE_VIDEO, | |
| 6582 CODEC_ID_MJPEG, | |
| 6583 sizeof(MpegEncContext), | |
| 6584 MPV_encode_init, | |
| 6585 MPV_encode_picture, | |
| 6586 MPV_encode_end, | |
| 6587 }; | |
|
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
|
6588 |
|
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
|
6589 #endif //CONFIG_ENCODERS |
