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