Mercurial > libavcodec.hg
annotate mpegvideo.c @ 790:b9156f8e6747 libavcodec
-fomit-frame-pointer is needed for the PIC code
author | michael |
---|---|
date | Tue, 29 Oct 2002 11:21:43 +0000 |
parents | d4cc92144266 |
children | 08423289ec57 |
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 |
22 #include <ctype.h> | |
0 | 23 #include "avcodec.h" |
24 #include "dsputil.h" | |
25 #include "mpegvideo.h" | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
26 #include "simple_idct.h" |
0 | 27 |
17
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
28 #ifdef USE_FASTMEMCPY |
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
29 #include "fastmemcpy.h" |
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
30 #endif |
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
31 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
32 //#undef NDEBUG |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
33 //#include <assert.h> |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
34 |
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
|
35 static void encode_picture(MpegEncContext *s, int picture_number); |
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
|
36 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
|
37 DCTELEM *block, int n, int qscale); |
325 | 38 static void dct_unquantize_mpeg2_c(MpegEncContext *s, |
39 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
|
40 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
|
41 DCTELEM *block, int n, int qscale); |
206 | 42 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w); |
344 | 43 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); |
206 | 44 |
45 void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w)= draw_edges_c; | |
566 | 46 static void emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int block_w, int block_h, |
47 int src_x, int src_y, int w, int h); | |
206 | 48 |
0 | 49 #define EDGE_WIDTH 16 |
50 | |
51 /* enable all paranoid tests for rounding, overflows, etc... */ | |
52 //#define PARANOID | |
53 | |
54 //#define DEBUG | |
55 | |
321 | 56 |
0 | 57 /* for jpeg fast DCT */ |
58 #define CONST_BITS 14 | |
59 | |
60 static const unsigned short aanscales[64] = { | |
61 /* precomputed values scaled up by 14 bits */ | |
62 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
63 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, | |
64 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, | |
65 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, | |
66 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
67 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | |
68 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, | |
69 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 | |
70 }; | |
71 | |
768
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
72 /* Input permutation for the simple_idct_mmx */ |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
73 static const UINT8 simple_mmx_permutation[64]={ |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
74 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D, |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
75 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D, |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
76 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D, |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
77 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F, |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
78 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F, |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
79 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D, |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
80 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F, |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
81 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F, |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
82 }; |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
83 |
0 | 84 static UINT8 h263_chroma_roundtab[16] = { |
85 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, | |
86 }; | |
87 | |
292
73a9ce3d9715
fcode_tables where too small, found by Klaas-Pieter Vlieg <vlieg@eurescom.de>
michaelni
parents:
288
diff
changeset
|
88 static UINT16 default_mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
89 static UINT8 default_fcode_tab[MAX_MV*2+1]; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
90 |
0 | 91 /* default motion estimation */ |
321 | 92 int motion_estimation_method = ME_EPZS; |
200 | 93 |
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
|
94 static void convert_matrix(MpegEncContext *s, int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64], |
709
afeff6ccb7f5
convert only needed matrixes in convert_matrix() (mjpeg calls it for every frame)
michaelni
parents:
706
diff
changeset
|
95 const UINT16 *quant_matrix, int bias, int qmin, int qmax) |
0 | 96 { |
344 | 97 int qscale; |
0 | 98 |
709
afeff6ccb7f5
convert only needed matrixes in convert_matrix() (mjpeg calls it for every frame)
michaelni
parents:
706
diff
changeset
|
99 for(qscale=qmin; qscale<=qmax; qscale++){ |
344 | 100 int 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
|
101 if (s->fdct == ff_jpeg_fdct_islow) { |
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
102 for(i=0;i<64;i++) { |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
103 const int j= s->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
|
104 /* 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
|
105 /* 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
|
106 /* (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
|
107 /* 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
|
108 |
764 | 109 qmat[qscale][i] = (int)((UINT64_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
|
110 (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
|
111 } |
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 } else if (s->fdct == fdct_ifast) { |
344 | 113 for(i=0;i<64;i++) { |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
114 const int j= s->idct_permutation[i]; |
344 | 115 /* 16 <= qscale * quant_matrix[i] <= 7905 */ |
116 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ | |
117 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ | |
118 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ | |
119 | |
764 | 120 qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT + 14)) / |
344 | 121 (aanscales[i] * qscale * quant_matrix[j])); |
122 } | |
123 } else { | |
124 for(i=0;i<64;i++) { | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
125 const int j= s->idct_permutation[i]; |
344 | 126 /* We can safely suppose that 16 <= quant_matrix[i] <= 255 |
127 So 16 <= qscale * quant_matrix[i] <= 7905 | |
128 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 | |
129 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 | |
130 */ | |
131 qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
132 qmat16[qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); |
344 | 133 |
134 if(qmat16[qscale][i]==0 || qmat16[qscale][i]==128*256) qmat16[qscale][i]=128*256-1; | |
135 qmat16_bias[qscale][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][i]); | |
136 } | |
0 | 137 } |
138 } | |
139 } | |
456 | 140 // move into common.c perhaps |
141 #define CHECKED_ALLOCZ(p, size)\ | |
142 {\ | |
143 p= av_mallocz(size);\ | |
144 if(p==NULL){\ | |
145 perror("malloc");\ | |
146 goto fail;\ | |
147 }\ | |
148 } | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
149 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
150 void ff_init_scantable(MpegEncContext *s, ScanTable *st, const UINT8 *src_scantable){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
151 int i; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
152 int end; |
764 | 153 |
154 st->scantable= src_scantable; | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
155 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
156 for(i=0; i<64; i++){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
157 int j; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
158 j = src_scantable[i]; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
159 st->permutated[i] = s->idct_permutation[j]; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
160 } |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
161 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
162 end=-1; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
163 for(i=0; i<64; i++){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
164 int j; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
165 j = st->permutated[i]; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
166 if(j>end) end=j; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
167 st->raster_end[i]= end; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
168 } |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
169 } |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
170 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
171 /* XXX: those functions should be suppressed ASAP when all IDCTs are |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
172 converted */ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
173 static void ff_jref_idct_put(UINT8 *dest, int line_size, DCTELEM *block) |
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 j_rev_dct (block); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
176 put_pixels_clamped(block, dest, line_size); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
177 } |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
178 static void ff_jref_idct_add(UINT8 *dest, int line_size, DCTELEM *block) |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
179 { |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
180 j_rev_dct (block); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
181 add_pixels_clamped(block, dest, line_size); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
182 } |
0 | 183 |
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
|
184 /* 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
|
185 int DCT_common_init(MpegEncContext *s) |
0 | 186 { |
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
|
187 int i; |
0 | 188 |
312 | 189 s->dct_unquantize_h263 = dct_unquantize_h263_c; |
325 | 190 s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_c; |
191 s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_c; | |
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
|
192 s->dct_quantize= dct_quantize_c; |
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
|
193 |
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
|
194 if(s->avctx->dct_algo==FF_DCT_FASTINT) |
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
|
195 s->fdct = fdct_ifast; |
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
|
196 else |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
197 s->fdct = ff_jpeg_fdct_islow; //slow/accurate/default |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
198 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
199 if(s->avctx->idct_algo==FF_IDCT_INT){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
200 s->idct_put= ff_jref_idct_put; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
201 s->idct_add= ff_jref_idct_add; |
768
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
202 s->idct_permutation_type= FF_LIBMPEG2_IDCT_PERM; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
203 }else{ //accurate/default |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
204 s->idct_put= simple_idct_put; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
205 s->idct_add= simple_idct_add; |
768
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
206 s->idct_permutation_type= FF_NO_IDCT_PERM; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
207 } |
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
|
208 |
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 #ifdef HAVE_MMX |
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
210 MPV_common_init_mmx(s); |
8 | 211 #endif |
514
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M«©ns Rullg«©rd
mellum
parents:
506
diff
changeset
|
212 #ifdef ARCH_ALPHA |
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M«©ns Rullg«©rd
mellum
parents:
506
diff
changeset
|
213 MPV_common_init_axp(s); |
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M«©ns Rullg«©rd
mellum
parents:
506
diff
changeset
|
214 #endif |
628
f596db4aa871
sun solaris compilation bugfix, patch by (Martin Olschewski <olschewski at zpr dot uni-koeln dot de>)
michaelni
parents:
625
diff
changeset
|
215 #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
|
216 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
|
217 #endif |
721
71f669e9f633
ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
michaelni
parents:
717
diff
changeset
|
218 #ifdef HAVE_MMI |
71f669e9f633
ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
michaelni
parents:
717
diff
changeset
|
219 MPV_common_init_mmi(s); |
71f669e9f633
ps2 optimizations update patch by (Leon van Stuivenberg <leonvs at iae dot nl>)
michaelni
parents:
717
diff
changeset
|
220 #endif |
730 | 221 #ifdef ARCH_ARMV4L |
222 MPV_common_init_armv4l(); | |
223 #endif | |
224 | |
768
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
225 switch(s->idct_permutation_type){ |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
226 case FF_NO_IDCT_PERM: |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
227 for(i=0; i<64; i++) |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
228 s->idct_permutation[i]= i; |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
229 break; |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
230 case FF_LIBMPEG2_IDCT_PERM: |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
231 for(i=0; i<64; i++) |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
232 s->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2); |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
233 break; |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
234 case FF_SIMPLE_IDCT_PERM: |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
235 for(i=0; i<64; i++) |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
236 s->idct_permutation[i]= simple_mmx_permutation[i]; |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
237 break; |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
238 case FF_TRANSPOSE_IDCT_PERM: |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
239 for(i=0; i<64; i++) |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
240 s->idct_permutation[i]= ((i&7)<<3) | (i>>3); |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
241 break; |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
242 default: |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
243 fprintf(stderr, "Internal error, IDCT permutation not set\n"); |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
244 return -1; |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
245 } |
c3fc09466f92
idct_permutation_type variable, so the permutation type can quickly be identified
michaelni
parents:
767
diff
changeset
|
246 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
247 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
248 /* load & permutate scantables |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
249 note: only wmv uses differnt ones |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
250 */ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
251 ff_init_scantable(s, &s->inter_scantable , ff_zigzag_direct); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
252 ff_init_scantable(s, &s->intra_scantable , ff_zigzag_direct); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
253 ff_init_scantable(s, &s->intra_h_scantable, ff_alternate_horizontal_scan); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
254 ff_init_scantable(s, &s->intra_v_scantable, ff_alternate_vertical_scan); |
591 | 255 |
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
|
256 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
|
257 } |
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
258 |
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
259 /* 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
|
260 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
|
261 { |
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
262 UINT8 *pict; |
756 | 263 int y_size, c_size, yc_size, i; |
726
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
264 |
a91203b34e71
moved dct init out from mpv_common_init to dct_common_init (for less-uglier way for dv)
al3x
parents:
721
diff
changeset
|
265 DCT_common_init(s); |
754 | 266 |
267 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
|
268 |
0 | 269 s->mb_width = (s->width + 15) / 16; |
270 s->mb_height = (s->height + 15) / 16; | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
271 |
756 | 272 y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); |
273 c_size = (s->mb_width + 2) * (s->mb_height + 2); | |
274 yc_size = y_size + 2 * c_size; | |
275 | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
276 /* set default edge pos, will be overriden in decode_header if needed */ |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
277 s->h_edge_pos= s->mb_width*16; |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
278 s->v_edge_pos= s->mb_height*16; |
701 | 279 |
280 /* convert fourcc to upper case */ | |
281 s->avctx->fourcc= toupper( s->avctx->fourcc &0xFF) | |
282 + (toupper((s->avctx->fourcc>>8 )&0xFF)<<8 ) | |
283 + (toupper((s->avctx->fourcc>>16)&0xFF)<<16) | |
284 + (toupper((s->avctx->fourcc>>24)&0xFF)<<24); | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
285 |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
286 s->mb_num = s->mb_width * s->mb_height; |
756 | 287 |
553 | 288 if(!(s->flags&CODEC_FLAG_DR1)){ |
556 | 289 s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH; |
290 s->uvlinesize = s->mb_width * 8 + EDGE_WIDTH; | |
0 | 291 |
553 | 292 for(i=0;i<3;i++) { |
756 | 293 int w, h, shift, pict_start, size; |
0 | 294 |
295 w = s->linesize; | |
296 h = s->mb_height * 16 + 2 * EDGE_WIDTH; | |
297 shift = (i == 0) ? 0 : 1; | |
756 | 298 size = (s->linesize>>shift) * (h >> shift); |
556 | 299 pict_start = (s->linesize>>shift) * (EDGE_WIDTH >> shift) + (EDGE_WIDTH >> shift); |
0 | 300 |
756 | 301 CHECKED_ALLOCZ(pict, size) |
0 | 302 s->last_picture_base[i] = pict; |
303 s->last_picture[i] = pict + pict_start; | |
756 | 304 if(i>0) memset(s->last_picture_base[i], 128, size); |
0 | 305 |
756 | 306 CHECKED_ALLOCZ(pict, size) |
0 | 307 s->next_picture_base[i] = pict; |
308 s->next_picture[i] = pict + pict_start; | |
756 | 309 if(i>0) memset(s->next_picture_base[i], 128, size); |
324 | 310 |
365
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
350
diff
changeset
|
311 if (s->has_b_frames || s->codec_id==CODEC_ID_MPEG4) { |
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
350
diff
changeset
|
312 /* Note the MPEG4 stuff is here cuz of buggy encoders which dont set the low_delay flag but |
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
350
diff
changeset
|
313 do low-delay encoding, so we cant allways distinguish b-frame containing streams from low_delay streams */ |
756 | 314 CHECKED_ALLOCZ(pict, size) |
0 | 315 s->aux_picture_base[i] = pict; |
316 s->aux_picture[i] = pict + pict_start; | |
756 | 317 if(i>0) memset(s->aux_picture_base[i], 128, size); |
0 | 318 } |
553 | 319 } |
556 | 320 s->ip_buffer_count= 2; |
0 | 321 } |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
322 |
567
5a6eaaa9fba2
larger edge emu buffer (might have been too small)
michaelni
parents:
566
diff
changeset
|
323 CHECKED_ALLOCZ(s->edge_emu_buffer, (s->width+64)*2*17*2); //(width + edge + align)*interlaced*MBsize*tolerance |
553 | 324 |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
325 if (s->encoding) { |
324 | 326 int j; |
327 int mv_table_size= (s->mb_width+2)*(s->mb_height+2); | |
239 | 328 |
456 | 329 CHECKED_ALLOCZ(s->mb_var , s->mb_num * sizeof(INT16)) |
330 CHECKED_ALLOCZ(s->mc_mb_var, s->mb_num * sizeof(INT16)) | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
331 CHECKED_ALLOCZ(s->mb_mean , s->mb_num * sizeof(INT8)) |
324 | 332 |
333 /* Allocate MV tables */ | |
456 | 334 CHECKED_ALLOCZ(s->p_mv_table , mv_table_size * 2 * sizeof(INT16)) |
335 CHECKED_ALLOCZ(s->b_forw_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
336 CHECKED_ALLOCZ(s->b_back_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
337 CHECKED_ALLOCZ(s->b_bidir_forw_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
338 CHECKED_ALLOCZ(s->b_bidir_back_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
339 CHECKED_ALLOCZ(s->b_direct_forw_mv_table, mv_table_size * 2 * sizeof(INT16)) | |
340 CHECKED_ALLOCZ(s->b_direct_back_mv_table, mv_table_size * 2 * sizeof(INT16)) | |
341 CHECKED_ALLOCZ(s->b_direct_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
324 | 342 |
456 | 343 CHECKED_ALLOCZ(s->me_scratchpad, s->linesize*16*3*sizeof(uint8_t)) |
344 | |
345 CHECKED_ALLOCZ(s->me_map , ME_MAP_SIZE*sizeof(uint32_t)) | |
346 CHECKED_ALLOCZ(s->me_score_map, ME_MAP_SIZE*sizeof(uint16_t)) | |
327 | 347 |
324 | 348 if(s->max_b_frames){ |
349 for(j=0; j<REORDER_BUFFER_SIZE; j++){ | |
350 int i; | |
351 for(i=0;i<3;i++) { | |
756 | 352 int w, h, shift, size; |
324 | 353 |
354 w = s->linesize; | |
355 h = s->mb_height * 16; | |
356 shift = (i == 0) ? 0 : 1; | |
756 | 357 size = (w >> shift) * (h >> shift); |
324 | 358 |
756 | 359 CHECKED_ALLOCZ(pict, size); |
324 | 360 s->picture_buffer[j][i] = pict; |
361 } | |
362 } | |
363 } | |
456 | 364 |
365 if(s->codec_id==CODEC_ID_MPEG4){ | |
366 CHECKED_ALLOCZ(s->tex_pb_buffer, PB_BUFFER_SIZE); | |
367 CHECKED_ALLOCZ( s->pb2_buffer, PB_BUFFER_SIZE); | |
368 } | |
612 | 369 |
650
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
370 if(s->msmpeg4_version){ |
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
371 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
|
372 } |
612 | 373 CHECKED_ALLOCZ(s->avctx->stats_out, 256); |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
374 } |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
375 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
376 CHECKED_ALLOCZ(s->error_status_table, s->mb_num*sizeof(UINT8)) |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
377 |
288 | 378 if (s->out_format == FMT_H263 || s->encoding) { |
0 | 379 int size; |
456 | 380 /* Allocate MB type table */ |
381 CHECKED_ALLOCZ(s->mb_type , s->mb_num * sizeof(UINT8)) | |
382 | |
0 | 383 /* MV prediction */ |
384 size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | |
456 | 385 CHECKED_ALLOCZ(s->motion_val, size * 2 * sizeof(INT16)); |
664 | 386 } |
387 | |
388 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
|
389 /* interlaced direct mode decoding tables */ |
664 | 390 CHECKED_ALLOCZ(s->field_mv_table, s->mb_num*2*2 * sizeof(INT16)) |
391 CHECKED_ALLOCZ(s->field_select_table, s->mb_num*2* sizeof(INT8)) | |
0 | 392 } |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
393 /* 4mv b frame decoding table */ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
394 //note this is needed for h263 without b frames too (segfault on damaged streams otherwise) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
395 CHECKED_ALLOCZ(s->co_located_type_table, s->mb_num * sizeof(UINT8)) |
767 | 396 if (s->out_format == FMT_H263) { |
0 | 397 /* ac values */ |
756 | 398 CHECKED_ALLOCZ(s->ac_val[0], yc_size * sizeof(INT16) * 16); |
0 | 399 s->ac_val[1] = s->ac_val[0] + y_size; |
400 s->ac_val[2] = s->ac_val[1] + c_size; | |
401 | |
402 /* cbp values */ | |
456 | 403 CHECKED_ALLOCZ(s->coded_block, y_size); |
333 | 404 |
405 /* divx501 bitstream reorder buffer */ | |
456 | 406 CHECKED_ALLOCZ(s->bitstream_buffer, BITSTREAM_BUFFER_SIZE); |
407 | |
408 /* cbp, ac_pred, pred_dir */ | |
409 CHECKED_ALLOCZ(s->cbp_table , s->mb_num * sizeof(UINT8)) | |
410 CHECKED_ALLOCZ(s->pred_dir_table, s->mb_num * sizeof(UINT8)) | |
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
|
411 } |
756 | 412 |
413 if (s->h263_pred || s->h263_plus || !s->encoding) { | |
414 /* dc values */ | |
415 //MN: we need these for error resilience of intra-frames | |
416 CHECKED_ALLOCZ(s->dc_val[0], yc_size * sizeof(INT16)); | |
417 s->dc_val[1] = s->dc_val[0] + y_size; | |
418 s->dc_val[2] = s->dc_val[1] + c_size; | |
419 for(i=0;i<yc_size;i++) | |
420 s->dc_val[0][i] = 1024; | |
421 } | |
422 | |
575 | 423 CHECKED_ALLOCZ(s->qscale_table , s->mb_num * sizeof(UINT8)) |
424 | |
611
3214d3f4519e
error concealment needs the mbintra_table so it should allways be allocated
michaelni
parents:
608
diff
changeset
|
425 /* which mb is a intra block */ |
3214d3f4519e
error concealment needs the mbintra_table so it should allways be allocated
michaelni
parents:
608
diff
changeset
|
426 CHECKED_ALLOCZ(s->mbintra_table, s->mb_num); |
3214d3f4519e
error concealment needs the mbintra_table so it should allways be allocated
michaelni
parents:
608
diff
changeset
|
427 memset(s->mbintra_table, 1, s->mb_num); |
3214d3f4519e
error concealment needs the mbintra_table so it should allways be allocated
michaelni
parents:
608
diff
changeset
|
428 |
0 | 429 /* default structure is frame */ |
430 s->picture_structure = PICT_FRAME; | |
553 | 431 |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
432 /* init macroblock skip table */ |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
433 CHECKED_ALLOCZ(s->mbskip_table, s->mb_num+1); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
434 //Note the +1 is for a quicker mpeg4 slice_end detection |
294 | 435 |
327 | 436 s->block= s->blocks[0]; |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
437 |
0 | 438 s->context_initialized = 1; |
439 return 0; | |
440 fail: | |
244 | 441 MPV_common_end(s); |
442 return -1; | |
443 } | |
444 | |
456 | 445 |
446 //extern int sads; | |
447 | |
244 | 448 /* init common structure for both encoder and decoder */ |
449 void MPV_common_end(MpegEncContext *s) | |
450 { | |
451 int i; | |
452 | |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
453 av_freep(&s->mb_type); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
454 av_freep(&s->mb_var); |
456 | 455 av_freep(&s->mc_mb_var); |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
456 av_freep(&s->mb_mean); |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
457 av_freep(&s->p_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
458 av_freep(&s->b_forw_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
459 av_freep(&s->b_back_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
460 av_freep(&s->b_bidir_forw_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
461 av_freep(&s->b_bidir_back_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
462 av_freep(&s->b_direct_forw_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
463 av_freep(&s->b_direct_back_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
464 av_freep(&s->b_direct_mv_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
465 av_freep(&s->motion_val); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
466 av_freep(&s->dc_val[0]); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
467 av_freep(&s->ac_val[0]); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
468 av_freep(&s->coded_block); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
469 av_freep(&s->mbintra_table); |
456 | 470 av_freep(&s->cbp_table); |
471 av_freep(&s->pred_dir_table); | |
472 av_freep(&s->qscale_table); | |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
473 av_freep(&s->me_scratchpad); |
456 | 474 av_freep(&s->me_map); |
475 av_freep(&s->me_score_map); | |
476 | |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
477 av_freep(&s->mbskip_table); |
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
478 av_freep(&s->bitstream_buffer); |
456 | 479 av_freep(&s->tex_pb_buffer); |
480 av_freep(&s->pb2_buffer); | |
553 | 481 av_freep(&s->edge_emu_buffer); |
664 | 482 av_freep(&s->co_located_type_table); |
483 av_freep(&s->field_mv_table); | |
484 av_freep(&s->field_select_table); | |
612 | 485 av_freep(&s->avctx->stats_out); |
650
ef4a33aad86e
reducing sizeof MpegEncContext to avoid stack overflow on crap M$ windo$
michaelni
parents:
635
diff
changeset
|
486 av_freep(&s->ac_stats); |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
487 av_freep(&s->error_status_table); |
612 | 488 |
0 | 489 for(i=0;i<3;i++) { |
324 | 490 int j; |
553 | 491 if(!(s->flags&CODEC_FLAG_DR1)){ |
492 av_freep(&s->last_picture_base[i]); | |
493 av_freep(&s->next_picture_base[i]); | |
494 av_freep(&s->aux_picture_base[i]); | |
495 } | |
496 s->last_picture_base[i]= | |
497 s->next_picture_base[i]= | |
498 s->aux_picture_base [i] = NULL; | |
499 s->last_picture[i]= | |
500 s->next_picture[i]= | |
501 s->aux_picture [i] = NULL; | |
502 | |
324 | 503 for(j=0; j<REORDER_BUFFER_SIZE; j++){ |
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
504 av_freep(&s->picture_buffer[j][i]); |
324 | 505 } |
0 | 506 } |
507 s->context_initialized = 0; | |
508 } | |
509 | |
510 /* init video encoder */ | |
511 int MPV_encode_init(AVCodecContext *avctx) | |
512 { | |
513 MpegEncContext *s = avctx->priv_data; | |
60 | 514 int i; |
0 | 515 |
315 | 516 avctx->pix_fmt = PIX_FMT_YUV420P; |
517 | |
0 | 518 s->bit_rate = avctx->bit_rate; |
268 | 519 s->bit_rate_tolerance = avctx->bit_rate_tolerance; |
0 | 520 s->frame_rate = avctx->frame_rate; |
521 s->width = avctx->width; | |
522 s->height = avctx->height; | |
456 | 523 if(avctx->gop_size > 600){ |
462
3fdd0627f6bd
typo (found by Bohdan Horst <nexus at hoth.amu.edu.pl>)
michaelni
parents:
461
diff
changeset
|
524 fprintf(stderr, "Warning keyframe interval too large! reducing it ...\n"); |
456 | 525 avctx->gop_size=600; |
526 } | |
0 | 527 s->gop_size = avctx->gop_size; |
162 | 528 s->rtp_mode = avctx->rtp_mode; |
529 s->rtp_payload_size = avctx->rtp_payload_size; | |
231 | 530 if (avctx->rtp_callback) |
531 s->rtp_callback = avctx->rtp_callback; | |
268 | 532 s->qmin= avctx->qmin; |
533 s->qmax= avctx->qmax; | |
534 s->max_qdiff= avctx->max_qdiff; | |
535 s->qcompress= avctx->qcompress; | |
536 s->qblur= avctx->qblur; | |
194
27d1773552c9
mpeg4 encoder fix by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
191
diff
changeset
|
537 s->avctx = avctx; |
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
538 s->aspect_ratio_info= avctx->aspect_ratio_info; |
618 | 539 if (avctx->aspect_ratio_info == FF_ASPECT_EXTENDED) |
540 { | |
541 s->aspected_width = avctx->aspected_width; | |
542 s->aspected_height = avctx->aspected_height; | |
543 } | |
294 | 544 s->flags= avctx->flags; |
324 | 545 s->max_b_frames= avctx->max_b_frames; |
329 | 546 s->b_frame_strategy= avctx->b_frame_strategy; |
344 | 547 s->codec_id= avctx->codec->id; |
456 | 548 s->luma_elim_threshold = avctx->luma_elim_threshold; |
549 s->chroma_elim_threshold= avctx->chroma_elim_threshold; | |
550 s->strict_std_compliance= avctx->strict_std_compliance; | |
551 s->data_partitioning= avctx->flags & CODEC_FLAG_PART; | |
599 | 552 s->mpeg_quant= avctx->mpeg_quant; |
344 | 553 |
0 | 554 if (s->gop_size <= 1) { |
555 s->intra_only = 1; | |
556 s->gop_size = 12; | |
557 } else { | |
558 s->intra_only = 0; | |
559 } | |
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
560 |
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
561 /* ME algorithm */ |
321 | 562 if (avctx->me_method == 0) |
563 /* For compatibility */ | |
564 s->me_method = motion_estimation_method; | |
565 else | |
566 s->me_method = avctx->me_method; | |
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
567 |
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
568 /* Fixed QSCALE */ |
0 | 569 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
|
570 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
571 s->adaptive_quant= ( s->avctx->lumi_masking |
693
b6a7ff92df57
darkness masking (lumi masking does only bright stuff now)
michaelni
parents:
690
diff
changeset
|
572 || s->avctx->dark_masking |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
573 || s->avctx->temporal_cplx_masking |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
574 || s->avctx->spatial_cplx_masking |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
575 || s->avctx->p_masking) |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
576 && !s->fixed_qscale; |
697 | 577 |
578 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
|
579 |
0 | 580 switch(avctx->codec->id) { |
581 case CODEC_ID_MPEG1VIDEO: | |
582 s->out_format = FMT_MPEG1; | |
336 | 583 avctx->delay=0; //FIXME not sure, should check the spec |
0 | 584 break; |
585 case CODEC_ID_MJPEG: | |
586 s->out_format = FMT_MJPEG; | |
587 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
|
588 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
|
589 s->mjpeg_data_only_frames = 0; /* write all the needed headers */ |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
590 s->mjpeg_vsample[0] = 2; /* set up default sampling factors */ |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
591 s->mjpeg_vsample[1] = 1; /* the only currently supported values */ |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
592 s->mjpeg_vsample[2] = 1; |
370
0eca28d16cbd
clamp intra matrix to 8bit for mjpeg (workaround for qscale>=25)
al3x
parents:
365
diff
changeset
|
593 s->mjpeg_hsample[0] = 2; |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
594 s->mjpeg_hsample[1] = 1; |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
595 s->mjpeg_hsample[2] = 1; |
0 | 596 if (mjpeg_init(s) < 0) |
597 return -1; | |
336 | 598 avctx->delay=0; |
0 | 599 break; |
600 case CODEC_ID_H263: | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
601 if (h263_get_picture_format(s->width, s->height) == 7) { |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
602 printf("Input picture size isn't suitable for h263 codec! try h263+\n"); |
0 | 603 return -1; |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
604 } |
0 | 605 s->out_format = FMT_H263; |
336 | 606 avctx->delay=0; |
0 | 607 break; |
608 case CODEC_ID_H263P: | |
609 s->out_format = FMT_H263; | |
610 s->h263_plus = 1; | |
78 | 611 s->unrestricted_mv = 1; |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
612 s->h263_aic = 1; |
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
613 |
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
614 /* These are just to be sure */ |
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
615 s->umvplus = 0; |
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
616 s->umvplus_dec = 0; |
336 | 617 avctx->delay=0; |
0 | 618 break; |
619 case CODEC_ID_RV10: | |
620 s->out_format = FMT_H263; | |
621 s->h263_rv10 = 1; | |
336 | 622 avctx->delay=0; |
0 | 623 break; |
71 | 624 case CODEC_ID_MPEG4: |
0 | 625 s->out_format = FMT_H263; |
626 s->h263_pred = 1; | |
627 s->unrestricted_mv = 1; | |
324 | 628 s->has_b_frames= s->max_b_frames ? 1 : 0; |
731 | 629 s->low_delay= !s->has_b_frames; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
630 avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); |
0 | 631 break; |
307 | 632 case CODEC_ID_MSMPEG4V1: |
0 | 633 s->out_format = FMT_H263; |
634 s->h263_msmpeg4 = 1; | |
635 s->h263_pred = 1; | |
636 s->unrestricted_mv = 1; | |
307 | 637 s->msmpeg4_version= 1; |
336 | 638 avctx->delay=0; |
307 | 639 break; |
640 case CODEC_ID_MSMPEG4V2: | |
641 s->out_format = FMT_H263; | |
642 s->h263_msmpeg4 = 1; | |
643 s->h263_pred = 1; | |
644 s->unrestricted_mv = 1; | |
645 s->msmpeg4_version= 2; | |
336 | 646 avctx->delay=0; |
307 | 647 break; |
648 case CODEC_ID_MSMPEG4V3: | |
649 s->out_format = FMT_H263; | |
650 s->h263_msmpeg4 = 1; | |
651 s->h263_pred = 1; | |
652 s->unrestricted_mv = 1; | |
653 s->msmpeg4_version= 3; | |
336 | 654 avctx->delay=0; |
0 | 655 break; |
499 | 656 case CODEC_ID_WMV1: |
657 s->out_format = FMT_H263; | |
658 s->h263_msmpeg4 = 1; | |
659 s->h263_pred = 1; | |
660 s->unrestricted_mv = 1; | |
661 s->msmpeg4_version= 4; | |
662 avctx->delay=0; | |
663 break; | |
664 case CODEC_ID_WMV2: | |
665 s->out_format = FMT_H263; | |
666 s->h263_msmpeg4 = 1; | |
667 s->h263_pred = 1; | |
668 s->unrestricted_mv = 1; | |
669 s->msmpeg4_version= 5; | |
670 avctx->delay=0; | |
671 break; | |
0 | 672 default: |
673 return -1; | |
674 } | |
295 | 675 |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
676 { /* 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
|
677 static int done=0; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
678 if(!done){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
679 int i; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
680 done=1; |
292
73a9ce3d9715
fcode_tables where too small, found by Klaas-Pieter Vlieg <vlieg@eurescom.de>
michaelni
parents:
288
diff
changeset
|
681 memset(default_mv_penalty, 0, sizeof(UINT16)*(MAX_FCODE+1)*(2*MAX_MV+1)); |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
682 memset(default_fcode_tab , 0, sizeof(UINT8)*(2*MAX_MV+1)); |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
683 |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
684 for(i=-16; i<16; i++){ |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
685 default_fcode_tab[i + MAX_MV]= 1; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
686 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
687 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
688 } |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
689 s->mv_penalty= default_mv_penalty; |
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
690 s->fcode_tab= default_fcode_tab; |
506
b9ed0ae72d51
init dc_scale tables to defaults (fixes mjpeg sig11)
michaelni
parents:
499
diff
changeset
|
691 s->y_dc_scale_table= |
b9ed0ae72d51
init dc_scale tables to defaults (fixes mjpeg sig11)
michaelni
parents:
499
diff
changeset
|
692 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
|
693 |
287 | 694 /* dont use mv_penalty table for crap MV as it would be confused */ |
324 | 695 if (s->me_method < ME_EPZS) s->mv_penalty = default_mv_penalty; |
287 | 696 |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
697 s->encoding = 1; |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
698 |
0 | 699 /* init */ |
700 if (MPV_common_init(s) < 0) | |
701 return -1; | |
702 | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
703 if (s->out_format == FMT_H263) |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
704 h263_encode_init(s); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
705 else if (s->out_format == FMT_MPEG1) |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
706 ff_mpeg1_encode_init(s); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
707 if(s->msmpeg4_version) |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
708 ff_msmpeg4_encode_init(s); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
709 |
60 | 710 /* init default q matrix */ |
711 for(i=0;i<64;i++) { | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
712 int j= s->idct_permutation[i]; |
599 | 713 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
|
714 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
|
715 s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i]; |
599 | 716 }else if(s->out_format == FMT_H263){ |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
717 s->intra_matrix[j] = |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
718 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; |
599 | 719 }else{ /* mpeg1 */ |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
720 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
|
721 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; |
599 | 722 } |
344 | 723 } |
724 | |
725 /* precompute matrix */ | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
726 /* for mjpeg, we do include qscale in the matrix */ |
344 | 727 if (s->out_format != FMT_MJPEG) { |
625
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
728 convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias, |
709
afeff6ccb7f5
convert only needed matrixes in convert_matrix() (mjpeg calls it for every frame)
michaelni
parents:
706
diff
changeset
|
729 s->intra_matrix, s->intra_quant_bias, 1, 31); |
625
bb6a69f9d409
slow but accurate integer dct from IJG (should be ok with the LGPL as the old DCT is the fast integer DCT from IJG)
michaelni
parents:
619
diff
changeset
|
730 convert_matrix(s, s->q_inter_matrix, s->q_inter_matrix16, s->q_inter_matrix16_bias, |
709
afeff6ccb7f5
convert only needed matrixes in convert_matrix() (mjpeg calls it for every frame)
michaelni
parents:
706
diff
changeset
|
731 s->inter_matrix, s->inter_quant_bias, 1, 31); |
60 | 732 } |
733 | |
329 | 734 if(ff_rate_control_init(s) < 0) |
735 return -1; | |
0 | 736 |
737 s->picture_number = 0; | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
738 s->picture_in_gop_number = 0; |
0 | 739 s->fake_picture_number = 0; |
740 /* motion detector init */ | |
741 s->f_code = 1; | |
324 | 742 s->b_code = 1; |
0 | 743 |
744 return 0; | |
745 } | |
746 | |
747 int MPV_encode_end(AVCodecContext *avctx) | |
748 { | |
749 MpegEncContext *s = avctx->priv_data; | |
750 | |
751 #ifdef STATS | |
752 print_stats(); | |
753 #endif | |
329 | 754 |
755 ff_rate_control_uninit(s); | |
756 | |
0 | 757 MPV_common_end(s); |
758 if (s->out_format == FMT_MJPEG) | |
759 mjpeg_close(s); | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
760 |
0 | 761 return 0; |
762 } | |
763 | |
764 /* 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
|
765 //FIXME check that this is ok for mpeg4 interlaced |
206 | 766 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w) |
0 | 767 { |
768 UINT8 *ptr, *last_line; | |
769 int i; | |
770 | |
771 last_line = buf + (height - 1) * wrap; | |
772 for(i=0;i<w;i++) { | |
773 /* top and bottom */ | |
774 memcpy(buf - (i + 1) * wrap, buf, width); | |
775 memcpy(last_line + (i + 1) * wrap, last_line, width); | |
776 } | |
777 /* left and right */ | |
778 ptr = buf; | |
779 for(i=0;i<height;i++) { | |
780 memset(ptr - w, ptr[0], w); | |
781 memset(ptr + width, ptr[width-1], w); | |
782 ptr += wrap; | |
783 } | |
784 /* corners */ | |
785 for(i=0;i<w;i++) { | |
786 memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */ | |
787 memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */ | |
788 memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */ | |
789 memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */ | |
790 } | |
791 } | |
792 | |
793 /* generic function for encode/decode called before a frame is coded/decoded */ | |
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
794 int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) |
0 | 795 { |
796 int i; | |
797 UINT8 *tmp; | |
798 | |
46
931417475f5b
fixed mpeg1 first block bug (pb with black picture optimisation for B frames)
glantau
parents:
40
diff
changeset
|
799 s->mb_skiped = 0; |
562
23e58889a108
exporting mbskip_table after it has been allocated
michaelni
parents:
557
diff
changeset
|
800 avctx->mbskip_table= s->mbskip_table; |
456 | 801 |
553 | 802 if(avctx->flags&CODEC_FLAG_DR1){ |
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
803 if(avctx->get_buffer_callback(avctx, s->width, s->height, s->pict_type) < 0){ |
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
804 fprintf(stderr, "get_buffer() failed\n"); |
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
805 return -1; |
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
806 } |
553 | 807 |
556 | 808 s->linesize = avctx->dr_stride; |
809 s->uvlinesize= avctx->dr_uvstride; | |
810 s->ip_buffer_count= avctx->dr_ip_buffer_count; | |
553 | 811 } |
562
23e58889a108
exporting mbskip_table after it has been allocated
michaelni
parents:
557
diff
changeset
|
812 avctx->dr_ip_buffer_count= s->ip_buffer_count; |
553 | 813 |
0 | 814 if (s->pict_type == B_TYPE) { |
815 for(i=0;i<3;i++) { | |
553 | 816 if(avctx->flags&CODEC_FLAG_DR1) |
817 s->aux_picture[i]= avctx->dr_buffer[i]; | |
569 | 818 |
819 //FIXME the following should never be needed, the decoder should drop b frames if no reference is available | |
820 if(s->next_picture[i]==NULL) | |
821 s->next_picture[i]= s->aux_picture[i]; | |
822 if(s->last_picture[i]==NULL) | |
823 s->last_picture[i]= s->next_picture[i]; | |
553 | 824 |
0 | 825 s->current_picture[i] = s->aux_picture[i]; |
826 } | |
827 } else { | |
828 for(i=0;i<3;i++) { | |
829 /* swap next and last */ | |
553 | 830 if(avctx->flags&CODEC_FLAG_DR1) |
831 tmp= avctx->dr_buffer[i]; | |
832 else | |
833 tmp = s->last_picture[i]; | |
834 | |
0 | 835 s->last_picture[i] = s->next_picture[i]; |
836 s->next_picture[i] = tmp; | |
837 s->current_picture[i] = tmp; | |
553 | 838 |
592
909e50c67d0e
last_picture should be never == NULL (it was with dr1) this might fix a segfault with error concealment
michaelni
parents:
591
diff
changeset
|
839 if(s->last_picture[i]==NULL) |
909e50c67d0e
last_picture should be never == NULL (it was with dr1) this might fix a segfault with error concealment
michaelni
parents:
591
diff
changeset
|
840 s->last_picture[i]= s->next_picture[i]; |
909e50c67d0e
last_picture should be never == NULL (it was with dr1) this might fix a segfault with error concealment
michaelni
parents:
591
diff
changeset
|
841 |
553 | 842 s->last_dr_opaque= s->next_dr_opaque; |
843 s->next_dr_opaque= avctx->dr_opaque_frame; | |
844 | |
557 | 845 if(s->has_b_frames && s->last_dr_opaque && s->codec_id!=CODEC_ID_SVQ1) |
553 | 846 avctx->dr_opaque_frame= s->last_dr_opaque; |
847 else | |
848 avctx->dr_opaque_frame= s->next_dr_opaque; | |
0 | 849 } |
850 } | |
591 | 851 /* set dequantizer, we cant do it during init as it might change for mpeg4 |
852 and we cant do it in the header decode as init isnt called for mpeg4 there yet */ | |
853 if(s->out_format == FMT_H263){ | |
854 if(s->mpeg_quant) | |
855 s->dct_unquantize = s->dct_unquantize_mpeg2; | |
856 else | |
857 s->dct_unquantize = s->dct_unquantize_h263; | |
858 }else | |
859 s->dct_unquantize = s->dct_unquantize_mpeg1; | |
771
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
860 |
d4cc92144266
handle direct rendering buffer allocation failure
michaelni
parents:
768
diff
changeset
|
861 return 0; |
0 | 862 } |
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
|
863 |
0 | 864 /* generic function for encode/decode called after a frame has been coded/decoded */ |
865 void MPV_frame_end(MpegEncContext *s) | |
866 { | |
652 | 867 s->avctx->key_frame = (s->pict_type == I_TYPE); |
868 s->avctx->pict_type = s->pict_type; | |
456 | 869 |
0 | 870 /* draw edge for correct motion prediction if outside */ |
553 | 871 if (s->pict_type != B_TYPE && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) { |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
872 draw_edges(s->current_picture[0], s->linesize , s->h_edge_pos , s->v_edge_pos , EDGE_WIDTH ); |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
873 draw_edges(s->current_picture[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
874 draw_edges(s->current_picture[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); |
0 | 875 } |
207 | 876 emms_c(); |
329 | 877 |
612 | 878 s->last_pict_type = s->pict_type; |
329 | 879 if(s->pict_type!=B_TYPE){ |
880 s->last_non_b_pict_type= s->pict_type; | |
341 | 881 s->num_available_buffers++; |
882 if(s->num_available_buffers>2) s->num_available_buffers= 2; | |
329 | 883 } |
0 | 884 } |
885 | |
324 | 886 /* reorder input for encoding */ |
887 void reorder_input(MpegEncContext *s, AVPicture *pict) | |
888 { | |
889 int i, j, index; | |
890 | |
891 if(s->max_b_frames > FF_MAX_B_FRAMES) s->max_b_frames= FF_MAX_B_FRAMES; | |
892 | |
893 // delay= s->max_b_frames+1; (or 0 if no b frames cuz decoder diff) | |
894 | |
895 for(j=0; j<REORDER_BUFFER_SIZE-1; j++){ | |
896 s->coded_order[j]= s->coded_order[j+1]; | |
897 } | |
898 s->coded_order[j].picture[0]= s->coded_order[j].picture[1]= s->coded_order[j].picture[2]= NULL; //catch uninitalized buffers | |
339 | 899 s->coded_order[j].pict_type=0; |
324 | 900 |
901 switch(s->input_pict_type){ | |
902 default: | |
903 case I_TYPE: | |
904 case S_TYPE: | |
905 case P_TYPE: | |
906 index= s->max_b_frames - s->b_frames_since_non_b; | |
907 s->b_frames_since_non_b=0; | |
908 break; | |
909 case B_TYPE: | |
910 index= s->max_b_frames + 1; | |
911 s->b_frames_since_non_b++; | |
912 break; | |
913 } | |
914 //printf("index:%d type:%d strides: %d %d\n", index, s->input_pict_type, pict->linesize[0], s->linesize); | |
915 if( (index==0 || (s->flags&CODEC_FLAG_INPUT_PRESERVED)) | |
916 && pict->linesize[0] == s->linesize | |
556 | 917 && pict->linesize[1] == s->uvlinesize |
918 && pict->linesize[2] == s->uvlinesize){ | |
324 | 919 //printf("ptr\n"); |
920 for(i=0; i<3; i++){ | |
921 s->coded_order[index].picture[i]= pict->data[i]; | |
922 } | |
923 }else{ | |
924 //printf("copy\n"); | |
925 for(i=0; i<3; i++){ | |
926 uint8_t *src = pict->data[i]; | |
927 uint8_t *dest; | |
928 int src_wrap = pict->linesize[i]; | |
929 int dest_wrap = s->linesize; | |
930 int w = s->width; | |
931 int h = s->height; | |
932 | |
933 if(index==0) dest= s->last_picture[i]+16; //is current_picture indeed but the switch hapens after reordering | |
934 else dest= s->picture_buffer[s->picture_buffer_index][i]; | |
935 | |
936 if (i >= 1) { | |
937 dest_wrap >>= 1; | |
938 w >>= 1; | |
939 h >>= 1; | |
940 } | |
941 | |
942 s->coded_order[index].picture[i]= dest; | |
943 for(j=0;j<h;j++) { | |
944 memcpy(dest, src, w); | |
945 dest += dest_wrap; | |
946 src += src_wrap; | |
947 } | |
948 } | |
949 if(index!=0){ | |
950 s->picture_buffer_index++; | |
588 | 951 if(s->picture_buffer_index >= REORDER_BUFFER_SIZE) s->picture_buffer_index=0; |
324 | 952 } |
953 } | |
954 s->coded_order[index].pict_type = s->input_pict_type; | |
955 s->coded_order[index].qscale = s->input_qscale; | |
956 s->coded_order[index].force_type= s->force_input_type; | |
957 s->coded_order[index].picture_in_gop_number= s->input_picture_in_gop_number; | |
958 s->coded_order[index].picture_number= s->input_picture_number; | |
959 | |
960 for(i=0; i<3; i++){ | |
961 s->new_picture[i]= s->coded_order[0].picture[i]; | |
962 } | |
963 } | |
964 | |
0 | 965 int MPV_encode_picture(AVCodecContext *avctx, |
966 unsigned char *buf, int buf_size, void *data) | |
967 { | |
968 MpegEncContext *s = avctx->priv_data; | |
969 AVPicture *pict = data; | |
970 | |
324 | 971 s->input_qscale = avctx->quality; |
0 | 972 |
973 init_put_bits(&s->pb, buf, buf_size, NULL, NULL); | |
974 | |
329 | 975 if(avctx->flags&CODEC_FLAG_TYPE){ |
976 s->input_pict_type= | |
977 s->force_input_type= avctx->key_frame ? I_TYPE : P_TYPE; | |
978 }else if(s->flags&CODEC_FLAG_PASS2){ | |
979 s->input_pict_type= | |
980 s->force_input_type= s->rc_context.entry[s->input_picture_number].new_pict_type; | |
981 }else{ | |
982 s->force_input_type=0; | |
983 if (!s->intra_only) { | |
984 /* first picture of GOP is intra */ | |
985 if (s->input_picture_in_gop_number % s->gop_size==0){ | |
986 s->input_pict_type = I_TYPE; | |
987 }else if(s->max_b_frames==0){ | |
988 s->input_pict_type = P_TYPE; | |
989 }else{ | |
990 if(s->b_frames_since_non_b < s->max_b_frames) //FIXME more IQ | |
991 s->input_pict_type = B_TYPE; | |
992 else | |
993 s->input_pict_type = P_TYPE; | |
994 } | |
995 } else { | |
324 | 996 s->input_pict_type = I_TYPE; |
997 } | |
0 | 998 } |
999 | |
329 | 1000 if(s->input_pict_type==I_TYPE) |
1001 s->input_picture_in_gop_number=0; | |
1002 | |
324 | 1003 reorder_input(s, pict); |
1004 | |
1005 /* output? */ | |
1006 if(s->coded_order[0].picture[0]){ | |
1007 | |
1008 s->pict_type= s->coded_order[0].pict_type; | |
1009 if (s->fixed_qscale) /* the ratecontrol needs the last qscale so we dont touch it for CBR */ | |
1010 s->qscale= s->coded_order[0].qscale; | |
1011 s->force_type= s->coded_order[0].force_type; | |
1012 s->picture_in_gop_number= s->coded_order[0].picture_in_gop_number; | |
1013 s->picture_number= s->coded_order[0].picture_number; | |
1014 | |
553 | 1015 MPV_frame_start(s, avctx); |
286 | 1016 |
324 | 1017 encode_picture(s, s->picture_number); |
652 | 1018 |
376 | 1019 avctx->real_pict_num = s->picture_number; |
324 | 1020 avctx->header_bits = s->header_bits; |
1021 avctx->mv_bits = s->mv_bits; | |
1022 avctx->misc_bits = s->misc_bits; | |
1023 avctx->i_tex_bits = s->i_tex_bits; | |
1024 avctx->p_tex_bits = s->p_tex_bits; | |
1025 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
|
1026 avctx->p_count = s->mb_num - s->i_count - s->skip_count; //FIXME f/b_count in avctx |
324 | 1027 avctx->skip_count = s->skip_count; |
0 | 1028 |
324 | 1029 MPV_frame_end(s); |
1030 | |
1031 if (s->out_format == FMT_MJPEG) | |
1032 mjpeg_picture_trailer(s); | |
1033 | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
1034 if(!s->fixed_qscale) |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
1035 avctx->quality = s->qscale; |
329 | 1036 |
1037 if(s->flags&CODEC_FLAG_PASS1) | |
1038 ff_write_pass1_stats(s); | |
456 | 1039 |
324 | 1040 } |
1041 | |
1042 s->input_picture_number++; | |
1043 s->input_picture_in_gop_number++; | |
0 | 1044 |
1045 flush_put_bits(&s->pb); | |
268 | 1046 s->frame_bits = (pbBufPtr(&s->pb) - s->pb.buf) * 8; |
612 | 1047 |
268 | 1048 s->total_bits += s->frame_bits; |
286 | 1049 avctx->frame_bits = s->frame_bits; |
1050 //printf("fcode: %d, type: %d, head: %d, mv: %d, misc: %d, frame: %d, itex: %d, ptex: %d\n", | |
1051 //s->f_code, avctx->key_frame, s->header_bits, s->mv_bits, s->misc_bits, s->frame_bits, s->i_tex_bits, s->p_tex_bits); | |
612 | 1052 #if 0 //dump some stats to stats.txt for testing/debuging |
1053 if(s->max_b_frames==0) | |
1054 { | |
1055 static FILE *f=NULL; | |
1056 if(!f) f= fopen("stats.txt", "wb"); | |
1057 get_psnr(pict->data, s->current_picture, | |
1058 pict->linesize, s->linesize, avctx); | |
1059 fprintf(f, "%7d, %7d, %2.4f\n", pbBufPtr(&s->pb) - s->pb.buf, s->qscale, avctx->psnr_y); | |
1060 } | |
1061 #endif | |
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
|
1062 |
252
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
1063 if (avctx->get_psnr) { |
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
1064 /* At this point pict->data should have the original frame */ |
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
1065 /* an s->current_picture should have the coded/decoded frame */ |
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
1066 get_psnr(pict->data, s->current_picture, |
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
1067 pict->linesize, s->linesize, avctx); |
324 | 1068 // printf("%f\n", avctx->psnr_y); |
252
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
1069 } |
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
|
1070 return pbBufPtr(&s->pb) - s->pb.buf; |
0 | 1071 } |
1072 | |
255 | 1073 static inline void gmc1_motion(MpegEncContext *s, |
1074 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
1075 int dest_offset, | |
753 | 1076 UINT8 **ref_picture, int src_offset) |
255 | 1077 { |
1078 UINT8 *ptr; | |
556 | 1079 int offset, src_x, src_y, linesize, uvlinesize; |
255 | 1080 int motion_x, motion_y; |
566 | 1081 int emu=0; |
255 | 1082 |
1083 motion_x= s->sprite_offset[0][0]; | |
1084 motion_y= s->sprite_offset[0][1]; | |
1085 src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
1086 src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
1087 motion_x<<=(3-s->sprite_warping_accuracy); | |
1088 motion_y<<=(3-s->sprite_warping_accuracy); | |
1089 src_x = clip(src_x, -16, s->width); | |
1090 if (src_x == s->width) | |
1091 motion_x =0; | |
1092 src_y = clip(src_y, -16, s->height); | |
1093 if (src_y == s->height) | |
1094 motion_y =0; | |
753 | 1095 |
255 | 1096 linesize = s->linesize; |
556 | 1097 uvlinesize = s->uvlinesize; |
753 | 1098 |
255 | 1099 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; |
1100 | |
1101 dest_y+=dest_offset; | |
566 | 1102 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1103 if(src_x<0 || src_y<0 || src_x + (motion_x&15) + 16 > s->h_edge_pos |
753 | 1104 || src_y + (motion_y&15) + 16 > s->v_edge_pos){ |
1105 emulated_edge_mc(s, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos); | |
566 | 1106 ptr= s->edge_emu_buffer; |
1107 emu=1; | |
1108 } | |
1109 } | |
753 | 1110 |
1111 if((motion_x|motion_y)&7){ | |
1112 ff_gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); | |
1113 ff_gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); | |
1114 }else{ | |
1115 int dxy; | |
1116 | |
1117 dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2); | |
1118 if (s->no_rounding){ | |
1119 put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16); | |
1120 }else{ | |
1121 put_pixels_tab [0][dxy](dest_y, ptr, linesize, 16); | |
1122 } | |
1123 } | |
1124 | |
1125 if(s->flags&CODEC_FLAG_GRAY) return; | |
255 | 1126 |
1127 motion_x= s->sprite_offset[1][0]; | |
1128 motion_y= s->sprite_offset[1][1]; | |
1129 src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
1130 src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
1131 motion_x<<=(3-s->sprite_warping_accuracy); | |
1132 motion_y<<=(3-s->sprite_warping_accuracy); | |
1133 src_x = clip(src_x, -8, s->width>>1); | |
1134 if (src_x == s->width>>1) | |
1135 motion_x =0; | |
1136 src_y = clip(src_y, -8, s->height>>1); | |
1137 if (src_y == s->height>>1) | |
1138 motion_y =0; | |
1139 | |
556 | 1140 offset = (src_y * uvlinesize) + src_x + (src_offset>>1); |
255 | 1141 ptr = ref_picture[1] + offset; |
566 | 1142 if(emu){ |
753 | 1143 emulated_edge_mc(s, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
566 | 1144 ptr= s->edge_emu_buffer; |
1145 } | |
753 | 1146 ff_gmc1(dest_cb + (dest_offset>>1), ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); |
566 | 1147 |
255 | 1148 ptr = ref_picture[2] + offset; |
566 | 1149 if(emu){ |
753 | 1150 emulated_edge_mc(s, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
566 | 1151 ptr= s->edge_emu_buffer; |
1152 } | |
753 | 1153 ff_gmc1(dest_cr + (dest_offset>>1), ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); |
255 | 1154 |
1155 return; | |
1156 } | |
1157 | |
753 | 1158 static inline void gmc_motion(MpegEncContext *s, |
1159 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
1160 int dest_offset, | |
1161 UINT8 **ref_picture, int src_offset) | |
1162 { | |
1163 UINT8 *ptr; | |
1164 int linesize, uvlinesize; | |
1165 const int a= s->sprite_warping_accuracy; | |
1166 int ox, oy; | |
1167 | |
1168 linesize = s->linesize; | |
1169 uvlinesize = s->uvlinesize; | |
1170 | |
1171 ptr = ref_picture[0] + src_offset; | |
1172 | |
1173 dest_y+=dest_offset; | |
1174 | |
1175 ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16; | |
1176 oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16; | |
1177 | |
1178 ff_gmc(dest_y, ptr, linesize, 16, | |
1179 ox, | |
1180 oy, | |
1181 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
1182 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
1183 a+1, (1<<(2*a+1)) - s->no_rounding, | |
1184 s->h_edge_pos, s->v_edge_pos); | |
1185 ff_gmc(dest_y+8, ptr, linesize, 16, | |
1186 ox + s->sprite_delta[0][0]*8, | |
1187 oy + s->sprite_delta[1][0]*8, | |
1188 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
1189 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
1190 a+1, (1<<(2*a+1)) - s->no_rounding, | |
1191 s->h_edge_pos, s->v_edge_pos); | |
1192 | |
1193 if(s->flags&CODEC_FLAG_GRAY) return; | |
1194 | |
1195 | |
1196 dest_cb+=dest_offset>>1; | |
1197 dest_cr+=dest_offset>>1; | |
1198 | |
1199 ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8; | |
1200 oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8; | |
1201 | |
1202 ptr = ref_picture[1] + (src_offset>>1); | |
1203 ff_gmc(dest_cb, ptr, uvlinesize, 8, | |
1204 ox, | |
1205 oy, | |
1206 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
1207 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
1208 a+1, (1<<(2*a+1)) - s->no_rounding, | |
1209 s->h_edge_pos>>1, s->v_edge_pos>>1); | |
1210 | |
1211 ptr = ref_picture[2] + (src_offset>>1); | |
1212 ff_gmc(dest_cr, ptr, uvlinesize, 8, | |
1213 ox, | |
1214 oy, | |
1215 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
1216 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
1217 a+1, (1<<(2*a+1)) - s->no_rounding, | |
1218 s->h_edge_pos>>1, s->v_edge_pos>>1); | |
1219 } | |
1220 | |
1221 | |
566 | 1222 static void emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int block_w, int block_h, |
553 | 1223 int src_x, int src_y, int w, int h){ |
1224 int x, y; | |
1225 int start_y, start_x, end_y, end_x; | |
566 | 1226 UINT8 *buf= s->edge_emu_buffer; |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1227 |
553 | 1228 if(src_y>= h){ |
1229 src+= (h-1-src_y)*linesize; | |
1230 src_y=h-1; | |
554 | 1231 }else if(src_y<=-block_h){ |
1232 src+= (1-block_h-src_y)*linesize; | |
1233 src_y=1-block_h; | |
553 | 1234 } |
1235 if(src_x>= w){ | |
1236 src+= (w-1-src_x); | |
1237 src_x=w-1; | |
554 | 1238 }else if(src_x<=-block_w){ |
1239 src+= (1-block_w-src_x); | |
1240 src_x=1-block_w; | |
553 | 1241 } |
1242 | |
1243 start_y= MAX(0, -src_y); | |
1244 start_x= MAX(0, -src_x); | |
1245 end_y= MIN(block_h, h-src_y); | |
1246 end_x= MIN(block_w, w-src_x); | |
566 | 1247 |
553 | 1248 // copy existing part |
1249 for(y=start_y; y<end_y; y++){ | |
1250 for(x=start_x; x<end_x; x++){ | |
1251 buf[x + y*linesize]= src[x + y*linesize]; | |
1252 } | |
1253 } | |
1254 | |
1255 //top | |
1256 for(y=0; y<start_y; y++){ | |
1257 for(x=start_x; x<end_x; x++){ | |
1258 buf[x + y*linesize]= buf[x + start_y*linesize]; | |
1259 } | |
1260 } | |
1261 | |
1262 //bottom | |
1263 for(y=end_y; y<block_h; y++){ | |
1264 for(x=start_x; x<end_x; x++){ | |
1265 buf[x + y*linesize]= buf[x + (end_y-1)*linesize]; | |
1266 } | |
1267 } | |
1268 | |
1269 for(y=0; y<block_h; y++){ | |
1270 //left | |
1271 for(x=0; x<start_x; x++){ | |
1272 buf[x + y*linesize]= buf[start_x + y*linesize]; | |
1273 } | |
1274 | |
1275 //right | |
1276 for(x=end_x; x<block_w; x++){ | |
1277 buf[x + y*linesize]= buf[end_x - 1 + y*linesize]; | |
1278 } | |
1279 } | |
1280 } | |
1281 | |
1282 | |
0 | 1283 /* apply one mpeg motion vector to the three components */ |
1284 static inline void mpeg_motion(MpegEncContext *s, | |
1285 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
1286 int dest_offset, | |
1287 UINT8 **ref_picture, int src_offset, | |
651 | 1288 int field_based, op_pixels_func (*pix_op)[4], |
0 | 1289 int motion_x, int motion_y, int h) |
1290 { | |
1291 UINT8 *ptr; | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1292 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize; |
553 | 1293 int emu=0; |
651 | 1294 #if 0 |
255 | 1295 if(s->quarter_sample) |
1296 { | |
1297 motion_x>>=1; | |
1298 motion_y>>=1; | |
1299 } | |
651 | 1300 #endif |
0 | 1301 dxy = ((motion_y & 1) << 1) | (motion_x & 1); |
1302 src_x = s->mb_x * 16 + (motion_x >> 1); | |
1303 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1); | |
1304 | |
1305 /* WARNING: do no forget half pels */ | |
1306 height = s->height >> field_based; | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1307 v_edge_pos = s->v_edge_pos >> field_based; |
0 | 1308 src_x = clip(src_x, -16, s->width); |
1309 if (src_x == s->width) | |
1310 dxy &= ~1; | |
1311 src_y = clip(src_y, -16, height); | |
1312 if (src_y == height) | |
1313 dxy &= ~2; | |
565
44d744901ded
interlaced mpeg2 fix ... replacing linesize>>1 by uvlinesize brainlessly wasnt a good idea
michaelni
parents:
562
diff
changeset
|
1314 linesize = s->linesize << field_based; |
44d744901ded
interlaced mpeg2 fix ... replacing linesize>>1 by uvlinesize brainlessly wasnt a good idea
michaelni
parents:
562
diff
changeset
|
1315 uvlinesize = s->uvlinesize << field_based; |
0 | 1316 ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset; |
1317 dest_y += dest_offset; | |
553 | 1318 |
1319 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1320 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 16 > s->h_edge_pos |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1321 || src_y + (motion_y&1) + h > v_edge_pos){ |
763 | 1322 emulated_edge_mc(s, ptr - src_offset, s->linesize, 17, 17+field_based, |
1323 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); | |
1324 ptr= s->edge_emu_buffer + src_offset; | |
553 | 1325 emu=1; |
1326 } | |
1327 } | |
651 | 1328 pix_op[0][dxy](dest_y, ptr, linesize, h); |
0 | 1329 |
485 | 1330 if(s->flags&CODEC_FLAG_GRAY) return; |
1331 | |
0 | 1332 if (s->out_format == FMT_H263) { |
1333 dxy = 0; | |
1334 if ((motion_x & 3) != 0) | |
1335 dxy |= 1; | |
1336 if ((motion_y & 3) != 0) | |
1337 dxy |= 2; | |
1338 mx = motion_x >> 2; | |
1339 my = motion_y >> 2; | |
1340 } else { | |
1341 mx = motion_x / 2; | |
1342 my = motion_y / 2; | |
1343 dxy = ((my & 1) << 1) | (mx & 1); | |
1344 mx >>= 1; | |
1345 my >>= 1; | |
1346 } | |
1347 | |
1348 src_x = s->mb_x * 8 + mx; | |
1349 src_y = s->mb_y * (8 >> field_based) + my; | |
1350 src_x = clip(src_x, -8, s->width >> 1); | |
1351 if (src_x == (s->width >> 1)) | |
1352 dxy &= ~1; | |
1353 src_y = clip(src_y, -8, height >> 1); | |
1354 if (src_y == (height >> 1)) | |
1355 dxy &= ~2; | |
565
44d744901ded
interlaced mpeg2 fix ... replacing linesize>>1 by uvlinesize brainlessly wasnt a good idea
michaelni
parents:
562
diff
changeset
|
1356 offset = (src_y * uvlinesize) + src_x + (src_offset >> 1); |
0 | 1357 ptr = ref_picture[1] + offset; |
553 | 1358 if(emu){ |
763 | 1359 emulated_edge_mc(s, ptr - (src_offset >> 1), s->uvlinesize, 9, 9+field_based, |
1360 src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
1361 ptr= s->edge_emu_buffer + (src_offset >> 1); | |
553 | 1362 } |
651 | 1363 pix_op[1][dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
553 | 1364 |
0 | 1365 ptr = ref_picture[2] + offset; |
553 | 1366 if(emu){ |
763 | 1367 emulated_edge_mc(s, ptr - (src_offset >> 1), s->uvlinesize, 9, 9+field_based, |
1368 src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
1369 ptr= s->edge_emu_buffer + (src_offset >> 1); | |
553 | 1370 } |
651 | 1371 pix_op[1][dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
0 | 1372 } |
1373 | |
255 | 1374 static inline void qpel_motion(MpegEncContext *s, |
1375 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
1376 int dest_offset, | |
1377 UINT8 **ref_picture, int src_offset, | |
651 | 1378 int field_based, op_pixels_func (*pix_op)[4], |
1379 qpel_mc_func (*qpix_op)[16], | |
255 | 1380 int motion_x, int motion_y, int h) |
1381 { | |
1382 UINT8 *ptr; | |
671 | 1383 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize; |
554 | 1384 int emu=0; |
255 | 1385 |
1386 dxy = ((motion_y & 3) << 2) | (motion_x & 3); | |
1387 src_x = s->mb_x * 16 + (motion_x >> 2); | |
1388 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); | |
1389 | |
1390 height = s->height >> field_based; | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1391 v_edge_pos = s->v_edge_pos >> field_based; |
255 | 1392 src_x = clip(src_x, -16, s->width); |
1393 if (src_x == s->width) | |
1394 dxy &= ~3; | |
1395 src_y = clip(src_y, -16, height); | |
1396 if (src_y == height) | |
1397 dxy &= ~12; | |
1398 linesize = s->linesize << field_based; | |
671 | 1399 uvlinesize = s->uvlinesize << field_based; |
255 | 1400 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; |
1401 dest_y += dest_offset; | |
1402 //printf("%d %d %d\n", src_x, src_y, dxy); | |
554 | 1403 |
1404 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1405 if(src_x<0 || src_y<0 || src_x + (motion_x&3) + 16 > s->h_edge_pos |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1406 || src_y + (motion_y&3) + h > v_edge_pos){ |
763 | 1407 emulated_edge_mc(s, ptr - src_offset, s->linesize, 17, 17+field_based, |
1408 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); | |
1409 ptr= s->edge_emu_buffer + src_offset; | |
554 | 1410 emu=1; |
1411 } | |
1412 } | |
671 | 1413 if(!field_based) |
1414 qpix_op[0][dxy](dest_y, ptr, linesize); | |
1415 else{ | |
1416 //damn interlaced mode | |
1417 //FIXME boundary mirroring is not exactly correct here | |
1418 qpix_op[1][dxy](dest_y , ptr , linesize); | |
1419 qpix_op[1][dxy](dest_y+8, ptr+8, linesize); | |
1420 } | |
651 | 1421 |
485 | 1422 if(s->flags&CODEC_FLAG_GRAY) return; |
1423 | |
671 | 1424 if(field_based){ |
1425 mx= motion_x/2; | |
1426 my= motion_y>>1; | |
760 | 1427 }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){ |
671 | 1428 mx= (motion_x>>1)|(motion_x&1); |
1429 my= (motion_y>>1)|(motion_y&1); | |
1430 }else{ | |
1431 mx= motion_x/2; | |
1432 my= motion_y/2; | |
1433 } | |
1434 mx= (mx>>1)|(mx&1); | |
1435 my= (my>>1)|(my&1); | |
1436 dxy= (mx&1) | ((my&1)<<1); | |
1437 mx>>=1; | |
1438 my>>=1; | |
255 | 1439 |
1440 src_x = s->mb_x * 8 + mx; | |
1441 src_y = s->mb_y * (8 >> field_based) + my; | |
1442 src_x = clip(src_x, -8, s->width >> 1); | |
1443 if (src_x == (s->width >> 1)) | |
1444 dxy &= ~1; | |
1445 src_y = clip(src_y, -8, height >> 1); | |
1446 if (src_y == (height >> 1)) | |
1447 dxy &= ~2; | |
1448 | |
671 | 1449 offset = (src_y * uvlinesize) + src_x + (src_offset >> 1); |
255 | 1450 ptr = ref_picture[1] + offset; |
554 | 1451 if(emu){ |
763 | 1452 emulated_edge_mc(s, ptr - (src_offset >> 1), s->uvlinesize, 9, 9 + field_based, |
1453 src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
1454 ptr= s->edge_emu_buffer + (src_offset >> 1); | |
554 | 1455 } |
671 | 1456 pix_op[1][dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
554 | 1457 |
255 | 1458 ptr = ref_picture[2] + offset; |
554 | 1459 if(emu){ |
763 | 1460 emulated_edge_mc(s, ptr - (src_offset >> 1), s->uvlinesize, 9, 9 + field_based, |
1461 src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
1462 ptr= s->edge_emu_buffer + (src_offset >> 1); | |
554 | 1463 } |
671 | 1464 pix_op[1][dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
255 | 1465 } |
1466 | |
1467 | |
0 | 1468 static inline void MPV_motion(MpegEncContext *s, |
1469 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
1470 int dir, UINT8 **ref_picture, | |
651 | 1471 op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16]) |
0 | 1472 { |
1473 int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y; | |
1474 int mb_x, mb_y, i; | |
1475 UINT8 *ptr, *dest; | |
554 | 1476 int emu=0; |
0 | 1477 |
1478 mb_x = s->mb_x; | |
1479 mb_y = s->mb_y; | |
1480 | |
1481 switch(s->mv_type) { | |
1482 case MV_TYPE_16X16: | |
255 | 1483 if(s->mcsel){ |
753 | 1484 if(s->real_sprite_warping_points==1){ |
1485 gmc1_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1486 ref_picture, 0); | |
1487 }else{ | |
1488 gmc_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1489 ref_picture, 0); | |
1490 } | |
651 | 1491 }else if(s->quarter_sample){ |
255 | 1492 qpel_motion(s, dest_y, dest_cb, dest_cr, 0, |
1493 ref_picture, 0, | |
1494 0, pix_op, qpix_op, | |
1495 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
1496 }else{ | |
1497 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1498 ref_picture, 0, | |
1499 0, pix_op, | |
1500 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
1501 } | |
0 | 1502 break; |
1503 case MV_TYPE_8X8: | |
673 | 1504 mx = 0; |
1505 my = 0; | |
1506 if(s->quarter_sample){ | |
1507 for(i=0;i<4;i++) { | |
1508 motion_x = s->mv[dir][i][0]; | |
1509 motion_y = s->mv[dir][i][1]; | |
0 | 1510 |
673 | 1511 dxy = ((motion_y & 3) << 2) | (motion_x & 3); |
1512 src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8; | |
1513 src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8; | |
1514 | |
1515 /* WARNING: do no forget half pels */ | |
1516 src_x = clip(src_x, -16, s->width); | |
1517 if (src_x == s->width) | |
1518 dxy &= ~3; | |
1519 src_y = clip(src_y, -16, s->height); | |
1520 if (src_y == s->height) | |
1521 dxy &= ~12; | |
0 | 1522 |
673 | 1523 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); |
1524 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
1525 if(src_x<0 || src_y<0 || src_x + (motion_x&3) + 8 > s->h_edge_pos | |
1526 || src_y + (motion_y&3) + 8 > s->v_edge_pos){ | |
1527 emulated_edge_mc(s, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos); | |
1528 ptr= s->edge_emu_buffer; | |
1529 } | |
1530 } | |
1531 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; | |
1532 qpix_op[1][dxy](dest, ptr, s->linesize); | |
1533 | |
1534 mx += s->mv[dir][i][0]/2; | |
1535 my += s->mv[dir][i][1]/2; | |
1536 } | |
1537 }else{ | |
1538 for(i=0;i<4;i++) { | |
1539 motion_x = s->mv[dir][i][0]; | |
1540 motion_y = s->mv[dir][i][1]; | |
1541 | |
1542 dxy = ((motion_y & 1) << 1) | (motion_x & 1); | |
1543 src_x = mb_x * 16 + (motion_x >> 1) + (i & 1) * 8; | |
1544 src_y = mb_y * 16 + (motion_y >> 1) + (i >>1) * 8; | |
0 | 1545 |
673 | 1546 /* WARNING: do no forget half pels */ |
1547 src_x = clip(src_x, -16, s->width); | |
1548 if (src_x == s->width) | |
1549 dxy &= ~1; | |
1550 src_y = clip(src_y, -16, s->height); | |
1551 if (src_y == s->height) | |
1552 dxy &= ~2; | |
1553 | |
1554 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); | |
1555 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
1556 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 8 > s->h_edge_pos | |
1557 || src_y + (motion_y&1) + 8 > s->v_edge_pos){ | |
1558 emulated_edge_mc(s, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos); | |
1559 ptr= s->edge_emu_buffer; | |
1560 } | |
554 | 1561 } |
673 | 1562 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; |
1563 pix_op[1][dxy](dest, ptr, s->linesize, 8); | |
1564 | |
1565 mx += s->mv[dir][i][0]; | |
1566 my += s->mv[dir][i][1]; | |
554 | 1567 } |
0 | 1568 } |
673 | 1569 |
485 | 1570 if(s->flags&CODEC_FLAG_GRAY) break; |
0 | 1571 /* In case of 8X8, we construct a single chroma motion vector |
1572 with a special rounding */ | |
1573 for(i=0;i<4;i++) { | |
1574 } | |
1575 if (mx >= 0) | |
1576 mx = (h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1)); | |
1577 else { | |
1578 mx = -mx; | |
1579 mx = -(h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1)); | |
1580 } | |
1581 if (my >= 0) | |
1582 my = (h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1)); | |
1583 else { | |
1584 my = -my; | |
1585 my = -(h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1)); | |
1586 } | |
1587 dxy = ((my & 1) << 1) | (mx & 1); | |
1588 mx >>= 1; | |
1589 my >>= 1; | |
1590 | |
1591 src_x = mb_x * 8 + mx; | |
1592 src_y = mb_y * 8 + my; | |
1593 src_x = clip(src_x, -8, s->width/2); | |
1594 if (src_x == s->width/2) | |
1595 dxy &= ~1; | |
1596 src_y = clip(src_y, -8, s->height/2); | |
1597 if (src_y == s->height/2) | |
1598 dxy &= ~2; | |
1599 | |
556 | 1600 offset = (src_y * (s->uvlinesize)) + src_x; |
0 | 1601 ptr = ref_picture[1] + offset; |
554 | 1602 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1603 if(src_x<0 || src_y<0 || src_x + (dxy &1) + 8 > s->h_edge_pos>>1 |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1604 || src_y + (dxy>>1) + 8 > s->v_edge_pos>>1){ |
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1605 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
554 | 1606 ptr= s->edge_emu_buffer; |
1607 emu=1; | |
1608 } | |
1609 } | |
651 | 1610 pix_op[1][dxy](dest_cb, ptr, s->uvlinesize, 8); |
554 | 1611 |
0 | 1612 ptr = ref_picture[2] + offset; |
554 | 1613 if(emu){ |
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1614 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
554 | 1615 ptr= s->edge_emu_buffer; |
1616 } | |
651 | 1617 pix_op[1][dxy](dest_cr, ptr, s->uvlinesize, 8); |
0 | 1618 break; |
1619 case MV_TYPE_FIELD: | |
1620 if (s->picture_structure == PICT_FRAME) { | |
671 | 1621 if(s->quarter_sample){ |
1622 /* top field */ | |
1623 qpel_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1624 ref_picture, s->field_select[dir][0] ? s->linesize : 0, | |
1625 1, pix_op, qpix_op, | |
1626 s->mv[dir][0][0], s->mv[dir][0][1], 8); | |
1627 /* bottom field */ | |
1628 qpel_motion(s, dest_y, dest_cb, dest_cr, s->linesize, | |
1629 ref_picture, s->field_select[dir][1] ? s->linesize : 0, | |
1630 1, pix_op, qpix_op, | |
1631 s->mv[dir][1][0], s->mv[dir][1][1], 8); | |
1632 }else{ | |
1633 /* top field */ | |
1634 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
1635 ref_picture, s->field_select[dir][0] ? s->linesize : 0, | |
1636 1, pix_op, | |
1637 s->mv[dir][0][0], s->mv[dir][0][1], 8); | |
1638 /* bottom field */ | |
1639 mpeg_motion(s, dest_y, dest_cb, dest_cr, s->linesize, | |
1640 ref_picture, s->field_select[dir][1] ? s->linesize : 0, | |
1641 1, pix_op, | |
1642 s->mv[dir][1][0], s->mv[dir][1][1], 8); | |
1643 } | |
0 | 1644 } else { |
1645 | |
1646 | |
1647 } | |
1648 break; | |
1649 } | |
1650 } | |
1651 | |
1652 | |
1653 /* put block[] to dest[] */ | |
1654 static inline void put_dct(MpegEncContext *s, | |
1655 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
1656 { | |
711 | 1657 s->dct_unquantize(s, block, i, s->qscale); |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1658 s->idct_put (dest, line_size, block); |
0 | 1659 } |
1660 | |
1661 /* add block[] to dest[] */ | |
1662 static inline void add_dct(MpegEncContext *s, | |
1663 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
1664 { | |
1665 if (s->block_last_index[i] >= 0) { | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1666 s->idct_add (dest, line_size, block); |
481 | 1667 } |
1668 } | |
1669 | |
1670 static inline void add_dequant_dct(MpegEncContext *s, | |
1671 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
1672 { | |
1673 if (s->block_last_index[i] >= 0) { | |
1674 s->dct_unquantize(s, block, i, s->qscale); | |
324 | 1675 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1676 s->idct_add (dest, line_size, block); |
0 | 1677 } |
1678 } | |
1679 | |
456 | 1680 /** |
1681 * cleans dc, ac, coded_block for the current non intra MB | |
1682 */ | |
1683 void ff_clean_intra_table_entries(MpegEncContext *s) | |
1684 { | |
1685 int wrap = s->block_wrap[0]; | |
1686 int xy = s->block_index[0]; | |
1687 | |
1688 s->dc_val[0][xy ] = | |
1689 s->dc_val[0][xy + 1 ] = | |
1690 s->dc_val[0][xy + wrap] = | |
1691 s->dc_val[0][xy + 1 + wrap] = 1024; | |
1692 /* ac pred */ | |
1693 memset(s->ac_val[0][xy ], 0, 32 * sizeof(INT16)); | |
1694 memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(INT16)); | |
1695 if (s->msmpeg4_version>=3) { | |
1696 s->coded_block[xy ] = | |
1697 s->coded_block[xy + 1 ] = | |
1698 s->coded_block[xy + wrap] = | |
1699 s->coded_block[xy + 1 + wrap] = 0; | |
1700 } | |
1701 /* chroma */ | |
1702 wrap = s->block_wrap[4]; | |
1703 xy = s->mb_x + 1 + (s->mb_y + 1) * wrap; | |
1704 s->dc_val[1][xy] = | |
1705 s->dc_val[2][xy] = 1024; | |
1706 /* ac pred */ | |
1707 memset(s->ac_val[1][xy], 0, 16 * sizeof(INT16)); | |
1708 memset(s->ac_val[2][xy], 0, 16 * sizeof(INT16)); | |
1709 | |
1710 s->mbintra_table[s->mb_x + s->mb_y*s->mb_width]= 0; | |
1711 } | |
1712 | |
0 | 1713 /* generic function called after a macroblock has been parsed by the |
1714 decoder or after it has been encoded by the encoder. | |
1715 | |
1716 Important variables used: | |
1717 s->mb_intra : true if intra macroblock | |
1718 s->mv_dir : motion vector direction | |
1719 s->mv_type : motion vector type | |
1720 s->mv : motion vector | |
1721 s->interlaced_dct : true if interlaced dct used (mpeg2) | |
1722 */ | |
1723 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) | |
1724 { | |
244 | 1725 int mb_x, mb_y; |
481 | 1726 const int mb_xy = s->mb_y * s->mb_width + s->mb_x; |
0 | 1727 |
1728 mb_x = s->mb_x; | |
1729 mb_y = s->mb_y; | |
1730 | |
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1731 #ifdef FF_POSTPROCESS |
466
805714c0c10f
new field for communicating with external postprocessing
nickols_k
parents:
462
diff
changeset
|
1732 /* Obsolete. Exists for compatibility with mplayer only. */ |
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1733 quant_store[mb_y][mb_x]=s->qscale; |
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1734 //printf("[%02d][%02d] %d\n",mb_x,mb_y,s->qscale); |
466
805714c0c10f
new field for communicating with external postprocessing
nickols_k
parents:
462
diff
changeset
|
1735 #else |
575 | 1736 /* even more obsolete, exists for mplayer xp only */ |
467 | 1737 if(s->avctx->quant_store) s->avctx->quant_store[mb_y*s->avctx->qstride+mb_x] = s->qscale; |
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1738 #endif |
575 | 1739 s->qscale_table[mb_xy]= s->qscale; |
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1740 |
0 | 1741 /* update DC predictors for P macroblocks */ |
1742 if (!s->mb_intra) { | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1743 if (s->h263_pred || s->h263_aic) { |
481 | 1744 if(s->mbintra_table[mb_xy]) |
456 | 1745 ff_clean_intra_table_entries(s); |
0 | 1746 } else { |
456 | 1747 s->last_dc[0] = |
1748 s->last_dc[1] = | |
0 | 1749 s->last_dc[2] = 128 << s->intra_dc_precision; |
1750 } | |
1751 } | |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1752 else if (s->h263_pred || s->h263_aic) |
481 | 1753 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
|
1754 |
280 | 1755 /* update motion predictor, not for B-frames as they need the motion_val from the last P/S-Frame */ |
481 | 1756 if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE) { //FIXME move into h263.c if possible, format specific stuff shouldnt be here |
0 | 1757 |
481 | 1758 const int wrap = s->block_wrap[0]; |
1759 const int xy = s->block_index[0]; | |
664 | 1760 const int mb_index= s->mb_x + s->mb_y*s->mb_width; |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1761 if(s->mv_type == MV_TYPE_8X8){ |
664 | 1762 s->co_located_type_table[mb_index]= CO_LOCATED_TYPE_4MV; |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1763 } else { |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1764 int motion_x, motion_y; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1765 if (s->mb_intra) { |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1766 motion_x = 0; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1767 motion_y = 0; |
664 | 1768 if(s->co_located_type_table) |
1769 s->co_located_type_table[mb_index]= 0; | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1770 } else if (s->mv_type == MV_TYPE_16X16) { |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1771 motion_x = s->mv[0][0][0]; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1772 motion_y = s->mv[0][0][1]; |
664 | 1773 if(s->co_located_type_table) |
1774 s->co_located_type_table[mb_index]= 0; | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1775 } else /*if (s->mv_type == MV_TYPE_FIELD)*/ { |
664 | 1776 int i; |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1777 motion_x = s->mv[0][0][0] + s->mv[0][1][0]; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1778 motion_y = s->mv[0][0][1] + s->mv[0][1][1]; |
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1779 motion_x = (motion_x>>1) | (motion_x&1); |
664 | 1780 for(i=0; i<2; i++){ |
1781 s->field_mv_table[mb_index][i][0]= s->mv[0][i][0]; | |
1782 s->field_mv_table[mb_index][i][1]= s->mv[0][i][1]; | |
1783 s->field_select_table[mb_index][i]= s->field_select[0][i]; | |
1784 } | |
1785 s->co_located_type_table[mb_index]= CO_LOCATED_TYPE_FIELDMV; | |
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1786 } |
0 | 1787 /* no update if 8X8 because it has been done during parsing */ |
244 | 1788 s->motion_val[xy][0] = motion_x; |
1789 s->motion_val[xy][1] = motion_y; | |
1790 s->motion_val[xy + 1][0] = motion_x; | |
1791 s->motion_val[xy + 1][1] = motion_y; | |
1792 s->motion_val[xy + wrap][0] = motion_x; | |
1793 s->motion_val[xy + wrap][1] = motion_y; | |
1794 s->motion_val[xy + 1 + wrap][0] = motion_x; | |
1795 s->motion_val[xy + 1 + wrap][1] = motion_y; | |
0 | 1796 } |
1797 } | |
1798 | |
324 | 1799 if (!(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { |
0 | 1800 UINT8 *dest_y, *dest_cb, *dest_cr; |
481 | 1801 int dct_linesize, dct_offset; |
651 | 1802 op_pixels_func (*op_pix)[4]; |
1803 qpel_mc_func (*op_qpix)[16]; | |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1804 |
324 | 1805 /* avoid copy if macroblock skipped in last frame too |
1806 dont touch it for B-frames as they need the skip info from the next p-frame */ | |
1807 if (s->pict_type != B_TYPE) { | |
481 | 1808 UINT8 *mbskip_ptr = &s->mbskip_table[mb_xy]; |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1809 if (s->mb_skiped) { |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1810 s->mb_skiped = 0; |
556 | 1811 |
1812 (*mbskip_ptr) ++; /* indicate that this time we skiped it */ | |
1813 if(*mbskip_ptr >99) *mbskip_ptr= 99; | |
1814 | |
324 | 1815 /* if previous was skipped too, then nothing to do ! |
1816 skip only during decoding as we might trash the buffers during encoding a bit */ | |
556 | 1817 if (*mbskip_ptr >= s->ip_buffer_count && !s->encoding) |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1818 goto the_end; |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1819 } else { |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1820 *mbskip_ptr = 0; /* not skipped */ |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1821 } |
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1822 } |
0 | 1823 |
717 | 1824 if(s->pict_type==B_TYPE && s->avctx->draw_horiz_band){ |
1825 dest_y = s->current_picture [0] + mb_x * 16; | |
1826 dest_cb = s->current_picture[1] + mb_x * 8; | |
1827 dest_cr = s->current_picture[2] + mb_x * 8; | |
1828 }else{ | |
1829 dest_y = s->current_picture [0] + (mb_y * 16* s->linesize ) + mb_x * 16; | |
1830 dest_cb = s->current_picture[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; | |
1831 dest_cr = s->current_picture[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; | |
1832 } | |
0 | 1833 |
1834 if (s->interlaced_dct) { | |
1835 dct_linesize = s->linesize * 2; | |
1836 dct_offset = s->linesize; | |
1837 } else { | |
1838 dct_linesize = s->linesize; | |
1839 dct_offset = s->linesize * 8; | |
1840 } | |
1841 | |
1842 if (!s->mb_intra) { | |
1843 /* motion handling */ | |
456 | 1844 /* decoding or more than one mb_type (MC was allready done otherwise) */ |
481 | 1845 if((!s->encoding) || (s->mb_type[mb_xy]&(s->mb_type[mb_xy]-1))){ |
327 | 1846 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
324 | 1847 op_pix = put_pixels_tab; |
651 | 1848 op_qpix= put_qpel_pixels_tab; |
324 | 1849 }else{ |
1850 op_pix = put_no_rnd_pixels_tab; | |
651 | 1851 op_qpix= put_no_rnd_qpel_pixels_tab; |
324 | 1852 } |
0 | 1853 |
324 | 1854 if (s->mv_dir & MV_DIR_FORWARD) { |
1855 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); | |
651 | 1856 op_pix = avg_pixels_tab; |
1857 op_qpix= avg_qpel_pixels_tab; | |
324 | 1858 } |
1859 if (s->mv_dir & MV_DIR_BACKWARD) { | |
1860 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); | |
1861 } | |
0 | 1862 } |
1863 | |
481 | 1864 /* skip dequant / idct if we are really late ;) */ |
1865 if(s->hurry_up>1) goto the_end; | |
1866 | |
0 | 1867 /* add dct residue */ |
711 | 1868 if(s->encoding || !( s->mpeg2 || s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO |
1869 || (s->codec_id==CODEC_ID_MPEG4 && !s->mpeg_quant))){ | |
481 | 1870 add_dequant_dct(s, block[0], 0, dest_y, dct_linesize); |
1871 add_dequant_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
1872 add_dequant_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
1873 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
0 | 1874 |
485 | 1875 if(!(s->flags&CODEC_FLAG_GRAY)){ |
556 | 1876 add_dequant_dct(s, block[4], 4, dest_cb, s->uvlinesize); |
1877 add_dequant_dct(s, block[5], 5, dest_cr, s->uvlinesize); | |
485 | 1878 } |
481 | 1879 } else { |
1880 add_dct(s, block[0], 0, dest_y, dct_linesize); | |
1881 add_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
1882 add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
1883 add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
1884 | |
485 | 1885 if(!(s->flags&CODEC_FLAG_GRAY)){ |
556 | 1886 add_dct(s, block[4], 4, dest_cb, s->uvlinesize); |
1887 add_dct(s, block[5], 5, dest_cr, s->uvlinesize); | |
485 | 1888 } |
481 | 1889 } |
0 | 1890 } else { |
1891 /* dct only in intra block */ | |
711 | 1892 if(s->encoding || !(s->mpeg2 || s->codec_id==CODEC_ID_MPEG1VIDEO)){ |
1893 put_dct(s, block[0], 0, dest_y, dct_linesize); | |
1894 put_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
1895 put_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
1896 put_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
0 | 1897 |
711 | 1898 if(!(s->flags&CODEC_FLAG_GRAY)){ |
1899 put_dct(s, block[4], 4, dest_cb, s->uvlinesize); | |
1900 put_dct(s, block[5], 5, dest_cr, s->uvlinesize); | |
1901 } | |
1902 }else{ | |
1903 s->idct_put(dest_y , dct_linesize, block[0]); | |
1904 s->idct_put(dest_y + 8, dct_linesize, block[1]); | |
1905 s->idct_put(dest_y + dct_offset , dct_linesize, block[2]); | |
1906 s->idct_put(dest_y + dct_offset + 8, dct_linesize, block[3]); | |
1907 | |
1908 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
1909 s->idct_put(dest_cb, s->uvlinesize, block[4]); | |
1910 s->idct_put(dest_cr, s->uvlinesize, block[5]); | |
1911 } | |
485 | 1912 } |
0 | 1913 } |
1914 } | |
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1915 the_end: |
294 | 1916 emms_c(); //FIXME remove |
1917 } | |
1918 | |
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
1919 static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold) |
456 | 1920 { |
1921 static const char tab[64]= | |
1922 {3,2,2,1,1,1,1,1, | |
1923 1,1,1,1,1,1,1,1, | |
1924 1,1,1,1,1,1,1,1, | |
1925 0,0,0,0,0,0,0,0, | |
1926 0,0,0,0,0,0,0,0, | |
1927 0,0,0,0,0,0,0,0, | |
1928 0,0,0,0,0,0,0,0, | |
1929 0,0,0,0,0,0,0,0}; | |
1930 int score=0; | |
1931 int run=0; | |
1932 int i; | |
1933 DCTELEM *block= s->block[n]; | |
1934 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
|
1935 int skip_dc; |
456 | 1936 |
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
|
1937 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
|
1938 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
|
1939 threshold= -threshold; |
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
1940 }else |
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
1941 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
|
1942 |
456 | 1943 /* are all which we could set to zero are allready zero? */ |
1944 if(last_index<=skip_dc - 1) return; | |
1945 | |
1946 for(i=0; i<=last_index; i++){ | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1947 const int j = s->intra_scantable.permutated[i]; |
456 | 1948 const int level = ABS(block[j]); |
1949 if(level==1){ | |
1950 if(skip_dc && i==0) continue; | |
1951 score+= tab[run]; | |
1952 run=0; | |
1953 }else if(level>1){ | |
1954 return; | |
1955 }else{ | |
1956 run++; | |
1957 } | |
1958 } | |
1959 if(score >= threshold) return; | |
1960 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
|
1961 const int j = s->intra_scantable.permutated[i]; |
456 | 1962 block[j]=0; |
1963 } | |
1964 if(block[0]) s->block_last_index[n]= 0; | |
1965 else s->block_last_index[n]= -1; | |
1966 } | |
1967 | |
344 | 1968 static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) |
1969 { | |
1970 int i; | |
1971 const int maxlevel= s->max_qcoeff; | |
1972 const int minlevel= s->min_qcoeff; | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1973 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1974 if(s->mb_intra){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1975 i=1; //skip clipping of intra dc |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1976 }else |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1977 i=0; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1978 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1979 for(;i<=last_index; i++){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1980 const int j= s->intra_scantable.permutated[i]; |
344 | 1981 int level = block[j]; |
1982 | |
1983 if (level>maxlevel) level=maxlevel; | |
1984 else if(level<minlevel) level=minlevel; | |
1985 block[j]= level; | |
1986 } | |
1987 } | |
324 | 1988 |
697 | 1989 static inline void requantize_coeffs(MpegEncContext *s, DCTELEM block[64], int oldq, int newq, int n) |
1990 { | |
1991 int i; | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1992 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1993 if(s->mb_intra){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1994 i=1; //skip clipping of intra dc |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1995 //FIXME requantize, note (mpeg1/h263/h263p-aic dont need it,...) |
697 | 1996 }else |
1997 i=0; | |
1998 | |
1999 for(;i<=s->block_last_index[n]; i++){ | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2000 const int j = s->intra_scantable.permutated[i]; |
697 | 2001 int level = block[j]; |
2002 | |
2003 block[j]= ROUNDED_DIV(level*oldq, newq); | |
2004 } | |
2005 | |
2006 for(i=s->block_last_index[n]; i>=0; i--){ | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2007 const int j = s->intra_scantable.permutated[i]; |
697 | 2008 if(block[j]) break; |
2009 } | |
2010 s->block_last_index[n]= i; | |
2011 } | |
2012 | |
2013 static inline void auto_requantize_coeffs(MpegEncContext *s, DCTELEM block[6][64]) | |
2014 { | |
2015 int i,n, newq; | |
2016 const int maxlevel= s->max_qcoeff; | |
2017 const int minlevel= s->min_qcoeff; | |
2018 int largest=0, smallest=0; | |
2019 | |
2020 assert(s->adaptive_quant); | |
2021 | |
2022 for(n=0; n<6; n++){ | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2023 if(s->mb_intra){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2024 i=1; //skip clipping of intra dc |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2025 //FIXME requantize, note (mpeg1/h263/h263p-aic dont need it,...) |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2026 }else |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2027 i=0; |
697 | 2028 |
2029 for(;i<=s->block_last_index[n]; i++){ | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2030 const int j = s->intra_scantable.permutated[i]; |
697 | 2031 int level = block[n][j]; |
2032 if(largest < level) largest = level; | |
2033 if(smallest > level) smallest= level; | |
2034 } | |
2035 } | |
2036 | |
2037 for(newq=s->qscale+1; newq<32; newq++){ | |
2038 if( ROUNDED_DIV(smallest*s->qscale, newq) >= minlevel | |
2039 && ROUNDED_DIV(largest *s->qscale, newq) <= maxlevel) | |
2040 break; | |
2041 } | |
2042 | |
2043 if(s->out_format==FMT_H263){ | |
2044 /* h263 like formats cannot change qscale by more than 2 easiely */ | |
2045 if(s->avctx->qmin + 2 < newq) | |
2046 newq= s->avctx->qmin + 2; | |
2047 } | |
2048 | |
2049 for(n=0; n<6; n++){ | |
2050 requantize_coeffs(s, block[n], s->qscale, newq, n); | |
2051 clip_coeffs(s, block[n], s->block_last_index[n]); | |
2052 } | |
2053 | |
2054 s->dquant+= newq - s->qscale; | |
2055 s->qscale= newq; | |
2056 } | |
2057 #if 0 | |
2058 static int pix_vcmp16x8(UINT8 *s, int stride){ //FIXME move to dsputil & optimize | |
2059 int score=0; | |
2060 int x,y; | |
2061 | |
2062 for(y=0; y<7; y++){ | |
2063 for(x=0; x<16; x+=4){ | |
2064 score+= ABS(s[x ] - s[x +stride]) + ABS(s[x+1] - s[x+1+stride]) | |
2065 +ABS(s[x+2] - s[x+2+stride]) + ABS(s[x+3] - s[x+3+stride]); | |
2066 } | |
2067 s+= stride; | |
2068 } | |
2069 | |
2070 return score; | |
2071 } | |
2072 | |
2073 static int pix_diff_vcmp16x8(UINT8 *s1, UINT8*s2, int stride){ //FIXME move to dsputil & optimize | |
2074 int score=0; | |
2075 int x,y; | |
2076 | |
2077 for(y=0; y<7; y++){ | |
2078 for(x=0; x<16; x++){ | |
2079 score+= ABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]); | |
2080 } | |
2081 s1+= stride; | |
2082 s2+= stride; | |
2083 } | |
2084 | |
2085 return score; | |
2086 } | |
2087 #else | |
2088 #define SQ(a) ((a)*(a)) | |
2089 | |
2090 static int pix_vcmp16x8(UINT8 *s, int stride){ //FIXME move to dsputil & optimize | |
2091 int score=0; | |
2092 int x,y; | |
2093 | |
2094 for(y=0; y<7; y++){ | |
2095 for(x=0; x<16; x+=4){ | |
2096 score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride]) | |
2097 +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]); | |
2098 } | |
2099 s+= stride; | |
2100 } | |
2101 | |
2102 return score; | |
2103 } | |
2104 | |
2105 static int pix_diff_vcmp16x8(UINT8 *s1, UINT8*s2, int stride){ //FIXME move to dsputil & optimize | |
2106 int score=0; | |
2107 int x,y; | |
2108 | |
2109 for(y=0; y<7; y++){ | |
2110 for(x=0; x<16; x++){ | |
2111 score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]); | |
2112 } | |
2113 s1+= stride; | |
2114 s2+= stride; | |
2115 } | |
2116 | |
2117 return score; | |
2118 } | |
2119 | |
2120 #endif | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2121 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2122 void ff_draw_horiz_band(MpegEncContext *s){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2123 if ( s->avctx->draw_horiz_band |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2124 && (s->num_available_buffers>=1 || (!s->has_b_frames)) ) { |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2125 UINT8 *src_ptr[3]; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2126 int y, h, offset; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2127 y = s->mb_y * 16; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2128 h = s->height - y; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2129 if (h > 16) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2130 h = 16; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2131 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2132 if(s->pict_type==B_TYPE) |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2133 offset = 0; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2134 else |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2135 offset = y * s->linesize; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2136 |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2137 if(s->pict_type==B_TYPE || (!s->has_b_frames)){ |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2138 src_ptr[0] = s->current_picture[0] + offset; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2139 src_ptr[1] = s->current_picture[1] + (offset >> 2); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2140 src_ptr[2] = s->current_picture[2] + (offset >> 2); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2141 } else { |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2142 src_ptr[0] = s->last_picture[0] + offset; |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2143 src_ptr[1] = s->last_picture[1] + (offset >> 2); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2144 src_ptr[2] = s->last_picture[2] + (offset >> 2); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2145 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2146 s->avctx->draw_horiz_band(s->avctx, src_ptr, s->linesize, |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2147 y, s->width, h); |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2148 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2149 } |
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2150 |
324 | 2151 static void encode_mb(MpegEncContext *s, int motion_x, int motion_y) |
294 | 2152 { |
2153 const int mb_x= s->mb_x; | |
2154 const int mb_y= s->mb_y; | |
2155 int i; | |
456 | 2156 int skip_dct[6]; |
697 | 2157 int dct_offset = s->linesize*8; //default for progressive frames |
2158 | |
456 | 2159 for(i=0; i<6; i++) skip_dct[i]=0; |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2160 |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2161 if(s->adaptive_quant){ |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2162 s->dquant= s->qscale_table[mb_x + mb_y*s->mb_width] - s->qscale; |
697 | 2163 |
2164 if(s->out_format==FMT_H263){ | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2165 if (s->dquant> 2) s->dquant= 2; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2166 else if(s->dquant<-2) s->dquant=-2; |
697 | 2167 } |
2168 | |
2169 if(s->codec_id==CODEC_ID_MPEG4){ | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2170 if(!s->mb_intra){ |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2171 assert(s->dquant==0 || s->mv_type!=MV_TYPE_8X8); |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2172 |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2173 if(s->mv_dir&MV_DIRECT) |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2174 s->dquant=0; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2175 } |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2176 } |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2177 s->qscale+= s->dquant; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2178 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2179 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2180 } |
294 | 2181 |
324 | 2182 if (s->mb_intra) { |
2183 UINT8 *ptr; | |
697 | 2184 int wrap_y; |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2185 int emu=0; |
294 | 2186 |
697 | 2187 wrap_y = s->linesize; |
2188 ptr = s->new_picture[0] + (mb_y * 16 * wrap_y) + mb_x * 16; | |
2189 | |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2190 if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ |
697 | 2191 emulated_edge_mc(s, ptr, wrap_y, 16, 16, mb_x*16, mb_y*16, s->width, s->height); |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2192 ptr= s->edge_emu_buffer; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2193 emu=1; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2194 } |
697 | 2195 |
2196 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ | |
2197 int progressive_score, interlaced_score; | |
2198 | |
2199 progressive_score= pix_vcmp16x8(ptr, wrap_y ) + pix_vcmp16x8(ptr + wrap_y*8, wrap_y ); | |
2200 interlaced_score = pix_vcmp16x8(ptr, wrap_y*2) + pix_vcmp16x8(ptr + wrap_y , wrap_y*2); | |
2201 | |
2202 if(progressive_score > interlaced_score + 100){ | |
2203 s->interlaced_dct=1; | |
2204 | |
2205 dct_offset= wrap_y; | |
2206 wrap_y<<=1; | |
2207 }else | |
2208 s->interlaced_dct=0; | |
2209 } | |
2210 | |
2211 get_pixels(s->block[0], ptr , wrap_y); | |
2212 get_pixels(s->block[1], ptr + 8, wrap_y); | |
2213 get_pixels(s->block[2], ptr + dct_offset , wrap_y); | |
2214 get_pixels(s->block[3], ptr + dct_offset + 8, wrap_y); | |
294 | 2215 |
487 | 2216 if(s->flags&CODEC_FLAG_GRAY){ |
2217 skip_dct[4]= 1; | |
2218 skip_dct[5]= 1; | |
2219 }else{ | |
697 | 2220 int wrap_c = s->uvlinesize; |
2221 ptr = s->new_picture[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
|
2222 if(emu){ |
697 | 2223 emulated_edge_mc(s, ptr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2224 ptr= s->edge_emu_buffer; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2225 } |
697 | 2226 get_pixels(s->block[4], ptr, wrap_c); |
294 | 2227 |
697 | 2228 ptr = s->new_picture[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
|
2229 if(emu){ |
697 | 2230 emulated_edge_mc(s, ptr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2231 ptr= s->edge_emu_buffer; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2232 } |
697 | 2233 get_pixels(s->block[5], ptr, wrap_c); |
487 | 2234 } |
324 | 2235 }else{ |
651 | 2236 op_pixels_func (*op_pix)[4]; |
2237 qpel_mc_func (*op_qpix)[16]; | |
324 | 2238 UINT8 *dest_y, *dest_cb, *dest_cr; |
456 | 2239 UINT8 *ptr_y, *ptr_cb, *ptr_cr; |
2240 int wrap_y, wrap_c; | |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2241 int emu=0; |
294 | 2242 |
324 | 2243 dest_y = s->current_picture[0] + (mb_y * 16 * s->linesize ) + mb_x * 16; |
556 | 2244 dest_cb = s->current_picture[1] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; |
2245 dest_cr = s->current_picture[2] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; | |
456 | 2246 wrap_y = s->linesize; |
697 | 2247 wrap_c = s->uvlinesize; |
456 | 2248 ptr_y = s->new_picture[0] + (mb_y * 16 * wrap_y) + mb_x * 16; |
2249 ptr_cb = s->new_picture[1] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
2250 ptr_cr = s->new_picture[2] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
324 | 2251 |
327 | 2252 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
324 | 2253 op_pix = put_pixels_tab; |
651 | 2254 op_qpix= put_qpel_pixels_tab; |
295 | 2255 }else{ |
324 | 2256 op_pix = put_no_rnd_pixels_tab; |
651 | 2257 op_qpix= put_no_rnd_qpel_pixels_tab; |
324 | 2258 } |
295 | 2259 |
324 | 2260 if (s->mv_dir & MV_DIR_FORWARD) { |
2261 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); | |
651 | 2262 op_pix = avg_pixels_tab; |
2263 op_qpix= avg_qpel_pixels_tab; | |
324 | 2264 } |
2265 if (s->mv_dir & MV_DIR_BACKWARD) { | |
2266 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); | |
2267 } | |
295 | 2268 |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2269 if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2270 emulated_edge_mc(s, ptr_y, wrap_y, 16, 16, mb_x*16, mb_y*16, s->width, s->height); |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2271 ptr_y= s->edge_emu_buffer; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2272 emu=1; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2273 } |
697 | 2274 |
2275 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ | |
2276 int progressive_score, interlaced_score; | |
2277 | |
2278 progressive_score= pix_diff_vcmp16x8(ptr_y , dest_y , wrap_y ) | |
2279 + pix_diff_vcmp16x8(ptr_y + wrap_y*8, dest_y + wrap_y*8, wrap_y ); | |
2280 interlaced_score = pix_diff_vcmp16x8(ptr_y , dest_y , wrap_y*2) | |
2281 + pix_diff_vcmp16x8(ptr_y + wrap_y , dest_y + wrap_y , wrap_y*2); | |
2282 | |
2283 if(progressive_score > interlaced_score + 600){ | |
2284 s->interlaced_dct=1; | |
2285 | |
2286 dct_offset= wrap_y; | |
2287 wrap_y<<=1; | |
2288 }else | |
2289 s->interlaced_dct=0; | |
2290 } | |
2291 | |
456 | 2292 diff_pixels(s->block[0], ptr_y , dest_y , wrap_y); |
2293 diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y); | |
697 | 2294 diff_pixels(s->block[2], ptr_y + dct_offset , dest_y + dct_offset , wrap_y); |
2295 diff_pixels(s->block[3], ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y); | |
487 | 2296 |
2297 if(s->flags&CODEC_FLAG_GRAY){ | |
2298 skip_dct[4]= 1; | |
2299 skip_dct[5]= 1; | |
2300 }else{ | |
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2301 if(emu){ |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2302 emulated_edge_mc(s, ptr_cb, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2303 ptr_cb= s->edge_emu_buffer; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2304 } |
487 | 2305 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
|
2306 if(emu){ |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2307 emulated_edge_mc(s, ptr_cr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2308 ptr_cr= s->edge_emu_buffer; |
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2309 } |
487 | 2310 diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); |
2311 } | |
2312 | |
456 | 2313 /* pre quantization */ |
2314 if(s->mc_mb_var[s->mb_width*mb_y+ mb_x]<2*s->qscale*s->qscale){ | |
697 | 2315 //FIXME optimize |
456 | 2316 if(pix_abs8x8(ptr_y , dest_y , wrap_y) < 20*s->qscale) skip_dct[0]= 1; |
2317 if(pix_abs8x8(ptr_y + 8, dest_y + 8, wrap_y) < 20*s->qscale) skip_dct[1]= 1; | |
697 | 2318 if(pix_abs8x8(ptr_y +dct_offset , dest_y +dct_offset , wrap_y) < 20*s->qscale) skip_dct[2]= 1; |
2319 if(pix_abs8x8(ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y) < 20*s->qscale) skip_dct[3]= 1; | |
456 | 2320 if(pix_abs8x8(ptr_cb , dest_cb , wrap_y) < 20*s->qscale) skip_dct[4]= 1; |
2321 if(pix_abs8x8(ptr_cr , dest_cr , wrap_y) < 20*s->qscale) skip_dct[5]= 1; | |
2322 #if 0 | |
2323 { | |
2324 static int stat[7]; | |
2325 int num=0; | |
2326 for(i=0; i<6; i++) | |
2327 if(skip_dct[i]) num++; | |
2328 stat[num]++; | |
2329 | |
2330 if(s->mb_x==0 && s->mb_y==0){ | |
2331 for(i=0; i<7; i++){ | |
2332 printf("%6d %1d\n", stat[i], i); | |
2333 } | |
2334 } | |
2335 } | |
2336 #endif | |
2337 } | |
324 | 2338 |
294 | 2339 } |
2340 | |
2341 #if 0 | |
2342 { | |
2343 float adap_parm; | |
2344 | |
2345 adap_parm = ((s->avg_mb_var << 1) + s->mb_var[s->mb_width*mb_y+mb_x] + 1.0) / | |
2346 ((s->mb_var[s->mb_width*mb_y+mb_x] << 1) + s->avg_mb_var + 1.0); | |
2347 | |
2348 printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d", | |
2349 (s->mb_type[s->mb_width*mb_y+mb_x] > 0) ? 'I' : 'P', | |
2350 s->qscale, adap_parm, s->qscale*adap_parm, | |
2351 s->mb_var[s->mb_width*mb_y+mb_x], s->avg_mb_var); | |
2352 } | |
2353 #endif | |
2354 /* DCT & quantize */ | |
344 | 2355 if(s->out_format==FMT_MJPEG){ |
2356 for(i=0;i<6;i++) { | |
2357 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
|
2358 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
|
2359 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
344 | 2360 } |
2361 }else{ | |
2362 for(i=0;i<6;i++) { | |
456 | 2363 if(!skip_dct[i]){ |
2364 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
|
2365 s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); |
344 | 2366 // 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
|
2367 // 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
|
2368 // of improve it. Just INTRADC clipping deserves changes in quantizer |
456 | 2369 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
2370 }else | |
2371 s->block_last_index[i]= -1; | |
344 | 2372 } |
456 | 2373 if(s->luma_elim_threshold && !s->mb_intra) |
2374 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
|
2375 dct_single_coeff_elimination(s, i, s->luma_elim_threshold); |
456 | 2376 if(s->chroma_elim_threshold && !s->mb_intra) |
2377 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
|
2378 dct_single_coeff_elimination(s, i, s->chroma_elim_threshold); |
294 | 2379 } |
2380 | |
487 | 2381 if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){ |
2382 s->block_last_index[4]= | |
2383 s->block_last_index[5]= 0; | |
2384 s->block[4][0]= | |
2385 s->block[5][0]= 128; | |
2386 } | |
2387 | |
294 | 2388 /* huffman encode */ |
2389 switch(s->out_format) { | |
2390 case FMT_MPEG1: | |
2391 mpeg1_encode_mb(s, s->block, motion_x, motion_y); | |
2392 break; | |
2393 case FMT_H263: | |
2394 if (s->h263_msmpeg4) | |
2395 msmpeg4_encode_mb(s, s->block, motion_x, motion_y); | |
2396 else if(s->h263_pred) | |
2397 mpeg4_encode_mb(s, s->block, motion_x, motion_y); | |
2398 else | |
2399 h263_encode_mb(s, s->block, motion_x, motion_y); | |
2400 break; | |
2401 case FMT_MJPEG: | |
2402 mjpeg_encode_mb(s, s->block); | |
2403 break; | |
2404 } | |
2405 } | |
2406 | |
456 | 2407 void ff_copy_bits(PutBitContext *pb, UINT8 *src, int length) |
294 | 2408 { |
326 | 2409 int bytes= length>>4; |
2410 int bits= length&15; | |
2411 int i; | |
2412 | |
456 | 2413 if(length==0) return; |
2414 | |
326 | 2415 for(i=0; i<bytes; i++) put_bits(pb, 16, be2me_16(((uint16_t*)src)[i])); |
2416 put_bits(pb, bits, be2me_16(((uint16_t*)src)[i])>>(16-bits)); | |
0 | 2417 } |
2418 | |
456 | 2419 static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
326 | 2420 int i; |
2421 | |
2422 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
2423 | |
2424 /* mpeg1 */ | |
2425 d->mb_incr= s->mb_incr; | |
2426 for(i=0; i<3; i++) | |
2427 d->last_dc[i]= s->last_dc[i]; | |
2428 | |
2429 /* statistics */ | |
2430 d->mv_bits= s->mv_bits; | |
2431 d->i_tex_bits= s->i_tex_bits; | |
2432 d->p_tex_bits= s->p_tex_bits; | |
2433 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
|
2434 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
|
2435 d->b_count= s->b_count; |
326 | 2436 d->skip_count= s->skip_count; |
2437 d->misc_bits= s->misc_bits; | |
329 | 2438 d->last_bits= 0; |
327 | 2439 |
2440 d->mb_skiped= s->mb_skiped; | |
326 | 2441 } |
2442 | |
456 | 2443 static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
326 | 2444 int i; |
2445 | |
2446 memcpy(d->mv, s->mv, 2*4*2*sizeof(int)); | |
2447 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
2448 | |
2449 /* mpeg1 */ | |
2450 d->mb_incr= s->mb_incr; | |
2451 for(i=0; i<3; i++) | |
2452 d->last_dc[i]= s->last_dc[i]; | |
2453 | |
2454 /* statistics */ | |
2455 d->mv_bits= s->mv_bits; | |
2456 d->i_tex_bits= s->i_tex_bits; | |
2457 d->p_tex_bits= s->p_tex_bits; | |
2458 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
|
2459 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
|
2460 d->b_count= s->b_count; |
326 | 2461 d->skip_count= s->skip_count; |
2462 d->misc_bits= s->misc_bits; | |
2463 | |
2464 d->mb_intra= s->mb_intra; | |
327 | 2465 d->mb_skiped= s->mb_skiped; |
326 | 2466 d->mv_type= s->mv_type; |
2467 d->mv_dir= s->mv_dir; | |
2468 d->pb= s->pb; | |
456 | 2469 if(s->data_partitioning){ |
2470 d->pb2= s->pb2; | |
2471 d->tex_pb= s->tex_pb; | |
2472 } | |
326 | 2473 d->block= s->block; |
2474 for(i=0; i<6; i++) | |
2475 d->block_last_index[i]= s->block_last_index[i]; | |
755 | 2476 d->interlaced_dct= s->interlaced_dct; |
326 | 2477 } |
2478 | |
456 | 2479 static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type, |
2480 PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2], | |
2481 int *dmin, int *next_block, int motion_x, int motion_y) | |
2482 { | |
2483 int bits_count; | |
2484 | |
2485 copy_context_before_encode(s, backup, type); | |
2486 | |
2487 s->block= s->blocks[*next_block]; | |
2488 s->pb= pb[*next_block]; | |
2489 if(s->data_partitioning){ | |
2490 s->pb2 = pb2 [*next_block]; | |
2491 s->tex_pb= tex_pb[*next_block]; | |
2492 } | |
2493 | |
2494 encode_mb(s, motion_x, motion_y); | |
2495 | |
2496 bits_count= get_bit_count(&s->pb); | |
2497 if(s->data_partitioning){ | |
2498 bits_count+= get_bit_count(&s->pb2); | |
2499 bits_count+= get_bit_count(&s->tex_pb); | |
2500 } | |
2501 | |
2502 if(bits_count<*dmin){ | |
2503 *dmin= bits_count; | |
2504 *next_block^=1; | |
2505 | |
2506 copy_context_after_encode(best, s, type); | |
2507 } | |
2508 } | |
326 | 2509 |
0 | 2510 static void encode_picture(MpegEncContext *s, int picture_number) |
2511 { | |
766 | 2512 int mb_x, mb_y, pdif = 0; |
294 | 2513 int i; |
286 | 2514 int bits; |
326 | 2515 MpegEncContext best_s, backup_s; |
456 | 2516 UINT8 bit_buf[2][3000]; |
2517 UINT8 bit_buf2[2][3000]; | |
2518 UINT8 bit_buf_tex[2][3000]; | |
2519 PutBitContext pb[2], pb2[2], tex_pb[2]; | |
2520 | |
2521 for(i=0; i<2; i++){ | |
2522 init_put_bits(&pb [i], bit_buf [i], 3000, NULL, NULL); | |
2523 init_put_bits(&pb2 [i], bit_buf2 [i], 3000, NULL, NULL); | |
2524 init_put_bits(&tex_pb[i], bit_buf_tex[i], 3000, NULL, NULL); | |
2525 } | |
0 | 2526 |
2527 s->picture_number = picture_number; | |
268 | 2528 |
294 | 2529 s->block_wrap[0]= |
2530 s->block_wrap[1]= | |
2531 s->block_wrap[2]= | |
2532 s->block_wrap[3]= s->mb_width*2 + 2; | |
2533 s->block_wrap[4]= | |
2534 s->block_wrap[5]= s->mb_width + 2; | |
2535 | |
268 | 2536 /* Reset the average MB variance */ |
456 | 2537 s->mb_var_sum = 0; |
2538 s->mc_mb_var_sum = 0; | |
327 | 2539 |
2540 /* we need to initialize some time vars before we can encode b-frames */ | |
2541 if (s->h263_pred && !s->h263_msmpeg4) | |
2542 ff_set_mpeg4_time(s, s->picture_number); | |
2543 | |
608 | 2544 s->scene_change_score=0; |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2545 |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2546 s->qscale= (int)(s->frame_qscale + 0.5); //FIXME qscale / ... stuff for ME ratedistoration |
608 | 2547 |
268 | 2548 /* Estimate motion for every MB */ |
324 | 2549 if(s->pict_type != I_TYPE){ |
294 | 2550 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
2551 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; | |
2552 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
2553 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
2554 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
2555 for(mb_x=0; mb_x < s->mb_width; mb_x++) { | |
2556 s->mb_x = mb_x; | |
2557 s->mb_y = mb_y; | |
2558 s->block_index[0]+=2; | |
2559 s->block_index[1]+=2; | |
2560 s->block_index[2]+=2; | |
2561 s->block_index[3]+=2; | |
268 | 2562 |
294 | 2563 /* compute motion vector & mb_type and store in context */ |
324 | 2564 if(s->pict_type==B_TYPE) |
2565 ff_estimate_b_frame_motion(s, mb_x, mb_y); | |
2566 else | |
2567 ff_estimate_p_frame_motion(s, mb_x, mb_y); | |
294 | 2568 // s->mb_type[mb_y*s->mb_width + mb_x]=MB_TYPE_INTER; |
268 | 2569 } |
2570 } | |
294 | 2571 emms_c(); |
456 | 2572 }else /* if(s->pict_type == I_TYPE) */{ |
294 | 2573 /* I-Frame */ |
2574 //FIXME do we need to zero them? | |
2575 memset(s->motion_val[0], 0, sizeof(INT16)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2); | |
324 | 2576 memset(s->p_mv_table , 0, sizeof(INT16)*(s->mb_width+2)*(s->mb_height+2)*2); |
294 | 2577 memset(s->mb_type , MB_TYPE_INTRA, sizeof(UINT8)*s->mb_width*s->mb_height); |
612 | 2578 |
2579 if(!s->fixed_qscale){ | |
2580 /* finding spatial complexity for I-frame rate control */ | |
2581 for(mb_y=0; mb_y < s->mb_height; mb_y++) { | |
2582 for(mb_x=0; mb_x < s->mb_width; mb_x++) { | |
2583 int xx = mb_x * 16; | |
2584 int yy = mb_y * 16; | |
2585 uint8_t *pix = s->new_picture[0] + (yy * s->linesize) + xx; | |
2586 int varc; | |
2587 int sum = pix_sum(pix, s->linesize); | |
2588 | |
2589 sum= (sum+8)>>4; | |
2590 varc = (pix_norm1(pix, s->linesize) - sum*sum + 500 + 128)>>8; | |
2591 | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2592 s->mb_var [s->mb_width * mb_y + mb_x] = varc; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2593 s->mb_mean[s->mb_width * mb_y + mb_x] = (sum+7)>>4; |
612 | 2594 s->mb_var_sum += varc; |
2595 } | |
2596 } | |
2597 } | |
268 | 2598 } |
608 | 2599 if(s->scene_change_score > 0 && s->pict_type == P_TYPE){ |
271 | 2600 s->pict_type= I_TYPE; |
294 | 2601 memset(s->mb_type , MB_TYPE_INTRA, sizeof(UINT8)*s->mb_width*s->mb_height); |
329 | 2602 if(s->max_b_frames==0){ |
2603 s->input_pict_type= I_TYPE; | |
2604 s->input_picture_in_gop_number=0; | |
2605 } | |
612 | 2606 //printf("Scene change detected, encoding as I Frame %d %d\n", s->mb_var_sum, s->mc_mb_var_sum); |
271 | 2607 } |
324 | 2608 |
2609 if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) | |
2610 s->f_code= ff_get_best_fcode(s, s->p_mv_table, MB_TYPE_INTER); | |
2611 ff_fix_long_p_mvs(s); | |
2612 if(s->pict_type==B_TYPE){ | |
2613 s->f_code= ff_get_best_fcode(s, s->b_forw_mv_table, MB_TYPE_FORWARD); | |
2614 s->b_code= ff_get_best_fcode(s, s->b_back_mv_table, MB_TYPE_BACKWARD); | |
327 | 2615 |
2616 ff_fix_long_b_mvs(s, s->b_forw_mv_table, s->f_code, MB_TYPE_FORWARD); | |
2617 ff_fix_long_b_mvs(s, s->b_back_mv_table, s->b_code, MB_TYPE_BACKWARD); | |
2618 ff_fix_long_b_mvs(s, s->b_bidir_forw_mv_table, s->f_code, MB_TYPE_BIDIR); | |
2619 ff_fix_long_b_mvs(s, s->b_bidir_back_mv_table, s->b_code, MB_TYPE_BIDIR); | |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
2620 } |
324 | 2621 |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2622 if (s->fixed_qscale) |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2623 s->frame_qscale = s->avctx->quality; |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2624 else |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2625 s->frame_qscale = ff_rate_estimate_qscale(s); |
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
2626 |
695 | 2627 if(s->adaptive_quant){ |
2628 switch(s->codec_id){ | |
2629 case CODEC_ID_MPEG4: | |
2630 ff_clean_mpeg4_qscales(s); | |
2631 break; | |
2632 case CODEC_ID_H263: | |
2633 case CODEC_ID_H263P: | |
2634 ff_clean_h263_qscales(s); | |
2635 break; | |
2636 } | |
2637 | |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2638 s->qscale= s->qscale_table[0]; |
695 | 2639 }else |
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2640 s->qscale= (int)(s->frame_qscale + 0.5); |
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2641 |
0 | 2642 if (s->out_format == FMT_MJPEG) { |
2643 /* 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
|
2644 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
|
2645 for(i=1;i<64;i++){ |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2646 int j= s->idct_permutation[i]; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2647 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2648 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
|
2649 } |
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
|
2650 convert_matrix(s, s->q_intra_matrix, s->q_intra_matrix16, |
709
afeff6ccb7f5
convert only needed matrixes in convert_matrix() (mjpeg calls it for every frame)
michaelni
parents:
706
diff
changeset
|
2651 s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias, 8, 8); |
0 | 2652 } |
2653 | |
286 | 2654 s->last_bits= get_bit_count(&s->pb); |
0 | 2655 switch(s->out_format) { |
2656 case FMT_MJPEG: | |
2657 mjpeg_picture_header(s); | |
2658 break; | |
2659 case FMT_H263: | |
2660 if (s->h263_msmpeg4) | |
2661 msmpeg4_encode_picture_header(s, picture_number); | |
2662 else if (s->h263_pred) | |
2663 mpeg4_encode_picture_header(s, picture_number); | |
2664 else if (s->h263_rv10) | |
2665 rv10_encode_picture_header(s, picture_number); | |
2666 else | |
2667 h263_encode_picture_header(s, picture_number); | |
2668 break; | |
2669 case FMT_MPEG1: | |
2670 mpeg1_encode_picture_header(s, picture_number); | |
2671 break; | |
2672 } | |
286 | 2673 bits= get_bit_count(&s->pb); |
2674 s->header_bits= bits - s->last_bits; | |
2675 s->last_bits= bits; | |
2676 s->mv_bits=0; | |
2677 s->misc_bits=0; | |
2678 s->i_tex_bits=0; | |
2679 s->p_tex_bits=0; | |
2680 s->i_count=0; | |
656
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
2681 s->f_count=0; |
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
2682 s->b_count=0; |
286 | 2683 s->skip_count=0; |
2684 | |
0 | 2685 /* init last dc values */ |
2686 /* note: quant matrix value (8) is implied here */ | |
2687 s->last_dc[0] = 128; | |
2688 s->last_dc[1] = 128; | |
2689 s->last_dc[2] = 128; | |
2690 s->mb_incr = 1; | |
2691 s->last_mv[0][0][0] = 0; | |
2692 s->last_mv[0][0][1] = 0; | |
2693 | |
766 | 2694 if (s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P) |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2695 s->gob_index = ff_h263_get_gob_height(s); |
456 | 2696 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2697 if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame) |
456 | 2698 ff_mpeg4_init_partitions(s); |
2699 | |
2700 s->resync_mb_x=0; | |
2701 s->resync_mb_y=0; | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2702 s->first_slice_line = 1; |
766 | 2703 s->ptr_lastgob = s->pb.buf; |
2704 s->ptr_last_mb_line = s->pb.buf; | |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2705 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
499 | 2706 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; |
2707 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; | |
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2708 |
266 | 2709 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; |
2710 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
2711 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
2712 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
2713 s->block_index[4]= s->block_wrap[4]*(mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2); | |
2714 s->block_index[5]= s->block_wrap[4]*(mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2); | |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
2715 for(mb_x=0; mb_x < s->mb_width; mb_x++) { |
327 | 2716 const int mb_type= s->mb_type[mb_y * s->mb_width + mb_x]; |
2717 const int xy= (mb_y+1) * (s->mb_width+2) + mb_x + 1; | |
456 | 2718 // int d; |
294 | 2719 int dmin=10000000; |
0 | 2720 |
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
2721 s->mb_x = mb_x; |
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
2722 s->mb_y = mb_y; |
266 | 2723 s->block_index[0]+=2; |
2724 s->block_index[1]+=2; | |
2725 s->block_index[2]+=2; | |
2726 s->block_index[3]+=2; | |
2727 s->block_index[4]++; | |
2728 s->block_index[5]++; | |
456 | 2729 |
766 | 2730 /* write gob / video packet header */ |
2731 if(s->rtp_mode){ | |
2732 int current_packet_size, is_gob_start; | |
2733 | |
2734 current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob; | |
2735 is_gob_start=0; | |
2736 | |
2737 if(s->codec_id==CODEC_ID_MPEG4){ | |
2738 if(current_packet_size + s->mb_line_avgsize/s->mb_width >= s->rtp_payload_size | |
2739 && s->mb_y + s->mb_x>0){ | |
2740 | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2741 if(s->partitioned_frame){ |
456 | 2742 ff_mpeg4_merge_partitions(s); |
2743 ff_mpeg4_init_partitions(s); | |
2744 } | |
2745 ff_mpeg4_encode_video_packet_header(s); | |
2746 | |
2747 if(s->flags&CODEC_FLAG_PASS1){ | |
2748 int bits= get_bit_count(&s->pb); | |
2749 s->misc_bits+= bits - s->last_bits; | |
2750 s->last_bits= bits; | |
2751 } | |
2752 ff_mpeg4_clean_buffers(s); | |
766 | 2753 is_gob_start=1; |
456 | 2754 } |
766 | 2755 }else{ |
2756 if(current_packet_size + s->mb_line_avgsize*s->gob_index >= s->rtp_payload_size | |
2757 && s->mb_x==0 && s->mb_y>0 && s->mb_y%s->gob_index==0){ | |
2758 | |
2759 h263_encode_gob_header(s, mb_y); | |
2760 is_gob_start=1; | |
2761 } | |
2762 } | |
2763 | |
2764 if(is_gob_start){ | |
456 | 2765 s->ptr_lastgob = pbBufPtr(&s->pb); |
2766 s->first_slice_line=1; | |
2767 s->resync_mb_x=mb_x; | |
2768 s->resync_mb_y=mb_y; | |
2769 } | |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2770 } |
456 | 2771 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2772 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
|
2773 && 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
|
2774 s->first_slice_line=0; |
456 | 2775 } |
2776 | |
294 | 2777 if(mb_type & (mb_type-1)){ // more than 1 MB type possible |
327 | 2778 int next_block=0; |
456 | 2779 int pb_bits_count, pb2_bits_count, tex_pb_bits_count; |
326 | 2780 |
2781 copy_context_before_encode(&backup_s, s, -1); | |
456 | 2782 backup_s.pb= s->pb; |
2783 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
|
2784 best_s.partitioned_frame= s->partitioned_frame; |
456 | 2785 if(s->data_partitioning){ |
2786 backup_s.pb2= s->pb2; | |
2787 backup_s.tex_pb= s->tex_pb; | |
2788 } | |
326 | 2789 |
294 | 2790 if(mb_type&MB_TYPE_INTER){ |
327 | 2791 s->mv_dir = MV_DIR_FORWARD; |
295 | 2792 s->mv_type = MV_TYPE_16X16; |
294 | 2793 s->mb_intra= 0; |
324 | 2794 s->mv[0][0][0] = s->p_mv_table[xy][0]; |
2795 s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
456 | 2796 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER, pb, pb2, tex_pb, |
2797 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); | |
0 | 2798 } |
326 | 2799 if(mb_type&MB_TYPE_INTER4V){ |
327 | 2800 s->mv_dir = MV_DIR_FORWARD; |
295 | 2801 s->mv_type = MV_TYPE_8X8; |
2802 s->mb_intra= 0; | |
2803 for(i=0; i<4; i++){ | |
2804 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; | |
2805 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; | |
2806 } | |
456 | 2807 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER4V, pb, pb2, tex_pb, |
2808 &dmin, &next_block, 0, 0); | |
327 | 2809 } |
2810 if(mb_type&MB_TYPE_FORWARD){ | |
2811 s->mv_dir = MV_DIR_FORWARD; | |
2812 s->mv_type = MV_TYPE_16X16; | |
2813 s->mb_intra= 0; | |
2814 s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
2815 s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
456 | 2816 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_FORWARD, pb, pb2, tex_pb, |
2817 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); | |
327 | 2818 } |
2819 if(mb_type&MB_TYPE_BACKWARD){ | |
2820 s->mv_dir = MV_DIR_BACKWARD; | |
2821 s->mv_type = MV_TYPE_16X16; | |
2822 s->mb_intra= 0; | |
2823 s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
2824 s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
456 | 2825 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BACKWARD, pb, pb2, tex_pb, |
2826 &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); | |
327 | 2827 } |
2828 if(mb_type&MB_TYPE_BIDIR){ | |
2829 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
2830 s->mv_type = MV_TYPE_16X16; | |
2831 s->mb_intra= 0; | |
2832 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
2833 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
2834 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
2835 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
456 | 2836 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BIDIR, pb, pb2, tex_pb, |
2837 &dmin, &next_block, 0, 0); | |
327 | 2838 } |
2839 if(mb_type&MB_TYPE_DIRECT){ | |
2840 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
2841 s->mv_type = MV_TYPE_16X16; //FIXME | |
2842 s->mb_intra= 0; | |
2843 s->mv[0][0][0] = s->b_direct_forw_mv_table[xy][0]; | |
2844 s->mv[0][0][1] = s->b_direct_forw_mv_table[xy][1]; | |
2845 s->mv[1][0][0] = s->b_direct_back_mv_table[xy][0]; | |
2846 s->mv[1][0][1] = s->b_direct_back_mv_table[xy][1]; | |
456 | 2847 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_DIRECT, pb, pb2, tex_pb, |
2848 &dmin, &next_block, s->b_direct_mv_table[xy][0], s->b_direct_mv_table[xy][1]); | |
295 | 2849 } |
294 | 2850 if(mb_type&MB_TYPE_INTRA){ |
327 | 2851 s->mv_dir = MV_DIR_FORWARD; |
295 | 2852 s->mv_type = MV_TYPE_16X16; |
294 | 2853 s->mb_intra= 1; |
2854 s->mv[0][0][0] = 0; | |
2855 s->mv[0][0][1] = 0; | |
456 | 2856 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTRA, pb, pb2, tex_pb, |
2857 &dmin, &next_block, 0, 0); | |
326 | 2858 /* force cleaning of ac/dc pred stuff if needed ... */ |
2859 if(s->h263_pred || s->h263_aic) | |
2860 s->mbintra_table[mb_x + mb_y*s->mb_width]=1; | |
295 | 2861 } |
326 | 2862 copy_context_after_encode(s, &best_s, -1); |
456 | 2863 |
2864 pb_bits_count= get_bit_count(&s->pb); | |
2865 flush_put_bits(&s->pb); | |
2866 ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); | |
2867 s->pb= backup_s.pb; | |
2868 | |
2869 if(s->data_partitioning){ | |
2870 pb2_bits_count= get_bit_count(&s->pb2); | |
2871 flush_put_bits(&s->pb2); | |
2872 ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); | |
2873 s->pb2= backup_s.pb2; | |
2874 | |
2875 tex_pb_bits_count= get_bit_count(&s->tex_pb); | |
2876 flush_put_bits(&s->tex_pb); | |
2877 ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); | |
2878 s->tex_pb= backup_s.tex_pb; | |
2879 } | |
329 | 2880 s->last_bits= get_bit_count(&s->pb); |
294 | 2881 } else { |
324 | 2882 int motion_x, motion_y; |
2883 s->mv_type=MV_TYPE_16X16; | |
294 | 2884 // only one MB-Type possible |
327 | 2885 switch(mb_type){ |
2886 case MB_TYPE_INTRA: | |
324 | 2887 s->mv_dir = MV_DIR_FORWARD; |
294 | 2888 s->mb_intra= 1; |
324 | 2889 motion_x= s->mv[0][0][0] = 0; |
2890 motion_y= s->mv[0][0][1] = 0; | |
327 | 2891 break; |
2892 case MB_TYPE_INTER: | |
324 | 2893 s->mv_dir = MV_DIR_FORWARD; |
2894 s->mb_intra= 0; | |
2895 motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; | |
2896 motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
327 | 2897 break; |
456 | 2898 case MB_TYPE_INTER4V: |
2899 s->mv_dir = MV_DIR_FORWARD; | |
2900 s->mv_type = MV_TYPE_8X8; | |
2901 s->mb_intra= 0; | |
2902 for(i=0; i<4; i++){ | |
2903 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; | |
2904 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; | |
2905 } | |
2906 motion_x= motion_y= 0; | |
2907 break; | |
327 | 2908 case MB_TYPE_DIRECT: |
324 | 2909 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
2910 s->mb_intra= 0; | |
327 | 2911 motion_x=s->b_direct_mv_table[xy][0]; |
2912 motion_y=s->b_direct_mv_table[xy][1]; | |
2913 s->mv[0][0][0] = s->b_direct_forw_mv_table[xy][0]; | |
2914 s->mv[0][0][1] = s->b_direct_forw_mv_table[xy][1]; | |
2915 s->mv[1][0][0] = s->b_direct_back_mv_table[xy][0]; | |
2916 s->mv[1][0][1] = s->b_direct_back_mv_table[xy][1]; | |
2917 break; | |
2918 case MB_TYPE_BIDIR: | |
324 | 2919 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; |
294 | 2920 s->mb_intra= 0; |
324 | 2921 motion_x=0; |
2922 motion_y=0; | |
2923 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
2924 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
2925 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
2926 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
327 | 2927 break; |
2928 case MB_TYPE_BACKWARD: | |
324 | 2929 s->mv_dir = MV_DIR_BACKWARD; |
2930 s->mb_intra= 0; | |
2931 motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
2932 motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
327 | 2933 break; |
2934 case MB_TYPE_FORWARD: | |
324 | 2935 s->mv_dir = MV_DIR_FORWARD; |
2936 s->mb_intra= 0; | |
2937 motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
2938 motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
2939 // printf(" %d %d ", motion_x, motion_y); | |
327 | 2940 break; |
2941 default: | |
324 | 2942 motion_x=motion_y=0; //gcc warning fix |
2943 printf("illegal MB type\n"); | |
294 | 2944 } |
324 | 2945 encode_mb(s, motion_x, motion_y); |
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2946 } |
327 | 2947 /* clean the MV table in IPS frames for direct mode in B frames */ |
2948 if(s->mb_intra /* && I,P,S_TYPE */){ | |
2949 s->p_mv_table[xy][0]=0; | |
2950 s->p_mv_table[xy][1]=0; | |
2951 } | |
0 | 2952 |
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
|
2953 MPV_decode_mb(s, s->block); |
456 | 2954 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_width, get_bit_count(&s->pb)); |
0 | 2955 } |
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
|
2956 |
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
|
2957 |
766 | 2958 /* Obtain average mb_row size for RTP */ |
231 | 2959 if (s->rtp_mode) { |
766 | 2960 if (mb_y==0) |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
2961 s->mb_line_avgsize = pbBufPtr(&s->pb) - s->ptr_last_mb_line; |
766 | 2962 else { |
234
5fc0c3af3fe4
alternative bitstream writer (disabled by default, uncomment #define ALT_BISTREAM_WRITER in common.h if u want to try it)
michaelni
parents:
233
diff
changeset
|
2963 s->mb_line_avgsize = (s->mb_line_avgsize + pbBufPtr(&s->pb) - s->ptr_last_mb_line) >> 1; |
231 | 2964 } |
766 | 2965 s->ptr_last_mb_line = pbBufPtr(&s->pb); |
231 | 2966 } |
0 | 2967 } |
294 | 2968 emms_c(); |
286 | 2969 |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2970 if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame) |
456 | 2971 ff_mpeg4_merge_partitions(s); |
2972 | |
2973 if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE) | |
208 | 2974 msmpeg4_encode_ext_header(s); |
2975 | |
456 | 2976 if(s->codec_id==CODEC_ID_MPEG4) |
2977 ff_mpeg4_stuffing(&s->pb); | |
2978 | |
162 | 2979 //if (s->gob_number) |
2980 // fprintf(stderr,"\nNumber of GOB: %d", s->gob_number); | |
231 | 2981 |
2982 /* Send the last GOB if RTP */ | |
2983 if (s->rtp_mode) { | |
2984 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
|
2985 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
231 | 2986 /* Call the RTP callback to send the last GOB */ |
2987 if (s->rtp_callback) | |
2988 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
|
2989 s->ptr_lastgob = pbBufPtr(&s->pb); |
231 | 2990 //fprintf(stderr,"\nGOB: %2d size: %d (last)", s->gob_number, pdif); |
2991 } | |
0 | 2992 } |
2993 | |
220 | 2994 static int dct_quantize_c(MpegEncContext *s, |
0 | 2995 DCTELEM *block, int n, |
344 | 2996 int qscale, int *overflow) |
0 | 2997 { |
2998 int i, j, level, last_non_zero, q; | |
2999 const int *qmat; | |
764 | 3000 const UINT8 *scantable= s->intra_scantable.scantable; |
344 | 3001 int bias; |
3002 int max=0; | |
3003 unsigned int threshold1, threshold2; | |
456 | 3004 |
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
|
3005 s->fdct (block); |
0 | 3006 |
3007 if (s->mb_intra) { | |
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3008 if (!s->h263_aic) { |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3009 if (n < 4) |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3010 q = s->y_dc_scale; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3011 else |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3012 q = s->c_dc_scale; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3013 q = q << 3; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3014 } else |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3015 /* 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
|
3016 q = 1 << 3; |
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3017 |
0 | 3018 /* note: block[0] is assumed to be positive */ |
3019 block[0] = (block[0] + (q >> 1)) / q; | |
3020 i = 1; | |
3021 last_non_zero = 0; | |
344 | 3022 qmat = s->q_intra_matrix[qscale]; |
635 | 3023 bias= s->intra_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); |
0 | 3024 } else { |
3025 i = 0; | |
3026 last_non_zero = -1; | |
344 | 3027 qmat = s->q_inter_matrix[qscale]; |
635 | 3028 bias= s->inter_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); |
0 | 3029 } |
635 | 3030 threshold1= (1<<QMAT_SHIFT) - bias - 1; |
3031 threshold2= (threshold1<<1); | |
0 | 3032 |
3033 for(;i<64;i++) { | |
764 | 3034 j = scantable[i]; |
0 | 3035 level = block[j]; |
3036 level = level * qmat[j]; | |
344 | 3037 |
3038 // if( bias+level >= (1<<(QMAT_SHIFT - 3)) | |
3039 // || bias-level >= (1<<(QMAT_SHIFT - 3))){ | |
3040 if(((unsigned)(level+threshold1))>threshold2){ | |
3041 if(level>0){ | |
635 | 3042 level= (bias + level)>>QMAT_SHIFT; |
344 | 3043 block[j]= level; |
3044 }else{ | |
635 | 3045 level= (bias - level)>>QMAT_SHIFT; |
344 | 3046 block[j]= -level; |
0 | 3047 } |
344 | 3048 max |=level; |
0 | 3049 last_non_zero = i; |
344 | 3050 }else{ |
3051 block[j]=0; | |
0 | 3052 } |
3053 } | |
344 | 3054 *overflow= s->max_qcoeff < max; //overflow might have happend |
3055 | |
764 | 3056 /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */ |
3057 ff_block_permute(block, s->idct_permutation, scantable, last_non_zero); | |
3058 | |
0 | 3059 return last_non_zero; |
3060 } | |
3061 | |
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
|
3062 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
|
3063 DCTELEM *block, int n, int qscale) |
0 | 3064 { |
200 | 3065 int i, level, nCoeffs; |
0 | 3066 const UINT16 *quant_matrix; |
3067 | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3068 nCoeffs= s->block_last_index[n]; |
200 | 3069 |
0 | 3070 if (s->mb_intra) { |
3071 if (n < 4) | |
3072 block[0] = block[0] * s->y_dc_scale; | |
3073 else | |
3074 block[0] = block[0] * s->c_dc_scale; | |
3075 /* XXX: only mpeg1 */ | |
3076 quant_matrix = s->intra_matrix; | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3077 for(i=1;i<=nCoeffs;i++) { |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3078 int j= s->intra_scantable.permutated[i]; |
200 | 3079 level = block[j]; |
0 | 3080 if (level) { |
3081 if (level < 0) { | |
3082 level = -level; | |
200 | 3083 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
0 | 3084 level = (level - 1) | 1; |
3085 level = -level; | |
3086 } else { | |
200 | 3087 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
0 | 3088 level = (level - 1) | 1; |
3089 } | |
3090 #ifdef PARANOID | |
3091 if (level < -2048 || level > 2047) | |
3092 fprintf(stderr, "unquant error %d %d\n", i, level); | |
3093 #endif | |
200 | 3094 block[j] = level; |
0 | 3095 } |
3096 } | |
3097 } else { | |
3098 i = 0; | |
344 | 3099 quant_matrix = s->inter_matrix; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3100 for(;i<=nCoeffs;i++) { |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3101 int j= s->intra_scantable.permutated[i]; |
200 | 3102 level = block[j]; |
0 | 3103 if (level) { |
3104 if (level < 0) { | |
3105 level = -level; | |
3106 level = (((level << 1) + 1) * qscale * | |
200 | 3107 ((int) (quant_matrix[j]))) >> 4; |
0 | 3108 level = (level - 1) | 1; |
3109 level = -level; | |
3110 } else { | |
3111 level = (((level << 1) + 1) * qscale * | |
200 | 3112 ((int) (quant_matrix[j]))) >> 4; |
0 | 3113 level = (level - 1) | 1; |
3114 } | |
3115 #ifdef PARANOID | |
3116 if (level < -2048 || level > 2047) | |
3117 fprintf(stderr, "unquant error %d %d\n", i, level); | |
3118 #endif | |
200 | 3119 block[j] = level; |
0 | 3120 } |
3121 } | |
3122 } | |
3123 } | |
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
|
3124 |
325 | 3125 static void dct_unquantize_mpeg2_c(MpegEncContext *s, |
3126 DCTELEM *block, int n, int qscale) | |
3127 { | |
3128 int i, level, nCoeffs; | |
3129 const UINT16 *quant_matrix; | |
3130 | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3131 if(s->alternate_scan) nCoeffs= 63; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3132 else nCoeffs= s->block_last_index[n]; |
325 | 3133 |
3134 if (s->mb_intra) { | |
3135 if (n < 4) | |
3136 block[0] = block[0] * s->y_dc_scale; | |
3137 else | |
3138 block[0] = block[0] * s->c_dc_scale; | |
3139 quant_matrix = s->intra_matrix; | |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3140 for(i=1;i<=nCoeffs;i++) { |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3141 int j= s->intra_scantable.permutated[i]; |
325 | 3142 level = block[j]; |
3143 if (level) { | |
3144 if (level < 0) { | |
3145 level = -level; | |
3146 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
3147 level = -level; | |
3148 } else { | |
3149 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
3150 } | |
3151 #ifdef PARANOID | |
3152 if (level < -2048 || level > 2047) | |
3153 fprintf(stderr, "unquant error %d %d\n", i, level); | |
3154 #endif | |
3155 block[j] = level; | |
3156 } | |
3157 } | |
3158 } else { | |
3159 int sum=-1; | |
3160 i = 0; | |
344 | 3161 quant_matrix = s->inter_matrix; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3162 for(;i<=nCoeffs;i++) { |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3163 int j= s->intra_scantable.permutated[i]; |
325 | 3164 level = block[j]; |
3165 if (level) { | |
3166 if (level < 0) { | |
3167 level = -level; | |
3168 level = (((level << 1) + 1) * qscale * | |
3169 ((int) (quant_matrix[j]))) >> 4; | |
3170 level = -level; | |
3171 } else { | |
3172 level = (((level << 1) + 1) * qscale * | |
3173 ((int) (quant_matrix[j]))) >> 4; | |
3174 } | |
3175 #ifdef PARANOID | |
3176 if (level < -2048 || level > 2047) | |
3177 fprintf(stderr, "unquant error %d %d\n", i, level); | |
3178 #endif | |
3179 block[j] = level; | |
3180 sum+=level; | |
3181 } | |
3182 } | |
3183 block[63]^=sum&1; | |
3184 } | |
3185 } | |
3186 | |
3187 | |
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
|
3188 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
|
3189 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
|
3190 { |
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
|
3191 int i, level, qmul, qadd; |
200 | 3192 int nCoeffs; |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3193 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3194 assert(s->block_last_index[n]>=0); |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3195 |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3196 qadd = (qscale - 1) | 1; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3197 qmul = qscale << 1; |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3198 |
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
|
3199 if (s->mb_intra) { |
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3200 if (!s->h263_aic) { |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3201 if (n < 4) |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3202 block[0] = block[0] * s->y_dc_scale; |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3203 else |
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3204 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
|
3205 }else |
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3206 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
|
3207 i = 1; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3208 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
|
3209 } 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
|
3210 i = 0; |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3211 nCoeffs= s->intra_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
|
3212 } |
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
|
3213 |
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3214 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
|
3215 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
|
3216 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
|
3217 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
|
3218 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
|
3219 } 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
|
3220 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
|
3221 } |
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
|
3222 #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
|
3223 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
|
3224 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
|
3225 #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
|
3226 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
|
3227 } |
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
|
3228 } |
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
|
3229 } |
0 | 3230 |
3231 AVCodec mpeg1video_encoder = { | |
3232 "mpeg1video", | |
3233 CODEC_TYPE_VIDEO, | |
3234 CODEC_ID_MPEG1VIDEO, | |
3235 sizeof(MpegEncContext), | |
3236 MPV_encode_init, | |
3237 MPV_encode_picture, | |
3238 MPV_encode_end, | |
3239 }; | |
3240 | |
3241 AVCodec h263_encoder = { | |
3242 "h263", | |
3243 CODEC_TYPE_VIDEO, | |
3244 CODEC_ID_H263, | |
3245 sizeof(MpegEncContext), | |
3246 MPV_encode_init, | |
3247 MPV_encode_picture, | |
3248 MPV_encode_end, | |
3249 }; | |
3250 | |
3251 AVCodec h263p_encoder = { | |
3252 "h263p", | |
3253 CODEC_TYPE_VIDEO, | |
3254 CODEC_ID_H263P, | |
3255 sizeof(MpegEncContext), | |
3256 MPV_encode_init, | |
3257 MPV_encode_picture, | |
3258 MPV_encode_end, | |
3259 }; | |
3260 | |
3261 AVCodec rv10_encoder = { | |
3262 "rv10", | |
3263 CODEC_TYPE_VIDEO, | |
3264 CODEC_ID_RV10, | |
3265 sizeof(MpegEncContext), | |
3266 MPV_encode_init, | |
3267 MPV_encode_picture, | |
3268 MPV_encode_end, | |
3269 }; | |
3270 | |
3271 AVCodec mjpeg_encoder = { | |
3272 "mjpeg", | |
3273 CODEC_TYPE_VIDEO, | |
3274 CODEC_ID_MJPEG, | |
3275 sizeof(MpegEncContext), | |
3276 MPV_encode_init, | |
3277 MPV_encode_picture, | |
3278 MPV_encode_end, | |
3279 }; | |
3280 | |
71 | 3281 AVCodec mpeg4_encoder = { |
3282 "mpeg4", | |
0 | 3283 CODEC_TYPE_VIDEO, |
71 | 3284 CODEC_ID_MPEG4, |
0 | 3285 sizeof(MpegEncContext), |
3286 MPV_encode_init, | |
3287 MPV_encode_picture, | |
3288 MPV_encode_end, | |
3289 }; | |
3290 | |
307 | 3291 AVCodec msmpeg4v1_encoder = { |
3292 "msmpeg4v1", | |
0 | 3293 CODEC_TYPE_VIDEO, |
307 | 3294 CODEC_ID_MSMPEG4V1, |
0 | 3295 sizeof(MpegEncContext), |
3296 MPV_encode_init, | |
3297 MPV_encode_picture, | |
3298 MPV_encode_end, | |
3299 }; | |
307 | 3300 |
3301 AVCodec msmpeg4v2_encoder = { | |
3302 "msmpeg4v2", | |
3303 CODEC_TYPE_VIDEO, | |
3304 CODEC_ID_MSMPEG4V2, | |
3305 sizeof(MpegEncContext), | |
3306 MPV_encode_init, | |
3307 MPV_encode_picture, | |
3308 MPV_encode_end, | |
3309 }; | |
3310 | |
3311 AVCodec msmpeg4v3_encoder = { | |
3312 "msmpeg4", | |
3313 CODEC_TYPE_VIDEO, | |
3314 CODEC_ID_MSMPEG4V3, | |
3315 sizeof(MpegEncContext), | |
3316 MPV_encode_init, | |
3317 MPV_encode_picture, | |
3318 MPV_encode_end, | |
3319 }; | |
499 | 3320 |
3321 AVCodec wmv1_encoder = { | |
3322 "wmv1", | |
3323 CODEC_TYPE_VIDEO, | |
3324 CODEC_ID_WMV1, | |
3325 sizeof(MpegEncContext), | |
3326 MPV_encode_init, | |
3327 MPV_encode_picture, | |
3328 MPV_encode_end, | |
3329 }; | |
3330 | |
3331 AVCodec wmv2_encoder = { | |
3332 "wmv2", | |
3333 CODEC_TYPE_VIDEO, | |
3334 CODEC_ID_WMV2, | |
3335 sizeof(MpegEncContext), | |
3336 MPV_encode_init, | |
3337 MPV_encode_picture, | |
3338 MPV_encode_end, | |
3339 }; |