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