Mercurial > libavcodec.hg
annotate mpegvideo.c @ 768:c3fc09466f92 libavcodec
idct_permutation_type variable, so the permutation type can quickly be identified
| author | michaelni |
|---|---|
| date | Fri, 25 Oct 2002 13:39:47 +0000 |
| parents | c75c3f1bef4b |
| children | d4cc92144266 |
| 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 */ | |
| 553 | 794 void 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){ |
| 803 avctx->get_buffer_callback(avctx, s->width, s->height, s->pict_type); | |
| 804 | |
| 556 | 805 s->linesize = avctx->dr_stride; |
| 806 s->uvlinesize= avctx->dr_uvstride; | |
| 807 s->ip_buffer_count= avctx->dr_ip_buffer_count; | |
| 553 | 808 } |
|
562
23e58889a108
exporting mbskip_table after it has been allocated
michaelni
parents:
557
diff
changeset
|
809 avctx->dr_ip_buffer_count= s->ip_buffer_count; |
| 553 | 810 |
| 0 | 811 if (s->pict_type == B_TYPE) { |
| 812 for(i=0;i<3;i++) { | |
| 553 | 813 if(avctx->flags&CODEC_FLAG_DR1) |
| 814 s->aux_picture[i]= avctx->dr_buffer[i]; | |
| 569 | 815 |
| 816 //FIXME the following should never be needed, the decoder should drop b frames if no reference is available | |
| 817 if(s->next_picture[i]==NULL) | |
| 818 s->next_picture[i]= s->aux_picture[i]; | |
| 819 if(s->last_picture[i]==NULL) | |
| 820 s->last_picture[i]= s->next_picture[i]; | |
| 553 | 821 |
| 0 | 822 s->current_picture[i] = s->aux_picture[i]; |
| 823 } | |
| 824 } else { | |
| 825 for(i=0;i<3;i++) { | |
| 826 /* swap next and last */ | |
| 553 | 827 if(avctx->flags&CODEC_FLAG_DR1) |
| 828 tmp= avctx->dr_buffer[i]; | |
| 829 else | |
| 830 tmp = s->last_picture[i]; | |
| 831 | |
| 0 | 832 s->last_picture[i] = s->next_picture[i]; |
| 833 s->next_picture[i] = tmp; | |
| 834 s->current_picture[i] = tmp; | |
| 553 | 835 |
|
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
|
836 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
|
837 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
|
838 |
| 553 | 839 s->last_dr_opaque= s->next_dr_opaque; |
| 840 s->next_dr_opaque= avctx->dr_opaque_frame; | |
| 841 | |
| 557 | 842 if(s->has_b_frames && s->last_dr_opaque && s->codec_id!=CODEC_ID_SVQ1) |
| 553 | 843 avctx->dr_opaque_frame= s->last_dr_opaque; |
| 844 else | |
| 845 avctx->dr_opaque_frame= s->next_dr_opaque; | |
| 0 | 846 } |
| 847 } | |
| 591 | 848 /* set dequantizer, we cant do it during init as it might change for mpeg4 |
| 849 and we cant do it in the header decode as init isnt called for mpeg4 there yet */ | |
| 850 if(s->out_format == FMT_H263){ | |
| 851 if(s->mpeg_quant) | |
| 852 s->dct_unquantize = s->dct_unquantize_mpeg2; | |
| 853 else | |
| 854 s->dct_unquantize = s->dct_unquantize_h263; | |
| 855 }else | |
| 856 s->dct_unquantize = s->dct_unquantize_mpeg1; | |
| 0 | 857 } |
|
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
|
858 |
| 0 | 859 /* generic function for encode/decode called after a frame has been coded/decoded */ |
| 860 void MPV_frame_end(MpegEncContext *s) | |
| 861 { | |
| 652 | 862 s->avctx->key_frame = (s->pict_type == I_TYPE); |
| 863 s->avctx->pict_type = s->pict_type; | |
| 456 | 864 |
| 0 | 865 /* draw edge for correct motion prediction if outside */ |
| 553 | 866 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
|
867 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
|
868 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
|
869 draw_edges(s->current_picture[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); |
| 0 | 870 } |
| 207 | 871 emms_c(); |
| 329 | 872 |
| 612 | 873 s->last_pict_type = s->pict_type; |
| 329 | 874 if(s->pict_type!=B_TYPE){ |
| 875 s->last_non_b_pict_type= s->pict_type; | |
| 341 | 876 s->num_available_buffers++; |
| 877 if(s->num_available_buffers>2) s->num_available_buffers= 2; | |
| 329 | 878 } |
| 0 | 879 } |
| 880 | |
| 324 | 881 /* reorder input for encoding */ |
| 882 void reorder_input(MpegEncContext *s, AVPicture *pict) | |
| 883 { | |
| 884 int i, j, index; | |
| 885 | |
| 886 if(s->max_b_frames > FF_MAX_B_FRAMES) s->max_b_frames= FF_MAX_B_FRAMES; | |
| 887 | |
| 888 // delay= s->max_b_frames+1; (or 0 if no b frames cuz decoder diff) | |
| 889 | |
| 890 for(j=0; j<REORDER_BUFFER_SIZE-1; j++){ | |
| 891 s->coded_order[j]= s->coded_order[j+1]; | |
| 892 } | |
| 893 s->coded_order[j].picture[0]= s->coded_order[j].picture[1]= s->coded_order[j].picture[2]= NULL; //catch uninitalized buffers | |
| 339 | 894 s->coded_order[j].pict_type=0; |
| 324 | 895 |
| 896 switch(s->input_pict_type){ | |
| 897 default: | |
| 898 case I_TYPE: | |
| 899 case S_TYPE: | |
| 900 case P_TYPE: | |
| 901 index= s->max_b_frames - s->b_frames_since_non_b; | |
| 902 s->b_frames_since_non_b=0; | |
| 903 break; | |
| 904 case B_TYPE: | |
| 905 index= s->max_b_frames + 1; | |
| 906 s->b_frames_since_non_b++; | |
| 907 break; | |
| 908 } | |
| 909 //printf("index:%d type:%d strides: %d %d\n", index, s->input_pict_type, pict->linesize[0], s->linesize); | |
| 910 if( (index==0 || (s->flags&CODEC_FLAG_INPUT_PRESERVED)) | |
| 911 && pict->linesize[0] == s->linesize | |
| 556 | 912 && pict->linesize[1] == s->uvlinesize |
| 913 && pict->linesize[2] == s->uvlinesize){ | |
| 324 | 914 //printf("ptr\n"); |
| 915 for(i=0; i<3; i++){ | |
| 916 s->coded_order[index].picture[i]= pict->data[i]; | |
| 917 } | |
| 918 }else{ | |
| 919 //printf("copy\n"); | |
| 920 for(i=0; i<3; i++){ | |
| 921 uint8_t *src = pict->data[i]; | |
| 922 uint8_t *dest; | |
| 923 int src_wrap = pict->linesize[i]; | |
| 924 int dest_wrap = s->linesize; | |
| 925 int w = s->width; | |
| 926 int h = s->height; | |
| 927 | |
| 928 if(index==0) dest= s->last_picture[i]+16; //is current_picture indeed but the switch hapens after reordering | |
| 929 else dest= s->picture_buffer[s->picture_buffer_index][i]; | |
| 930 | |
| 931 if (i >= 1) { | |
| 932 dest_wrap >>= 1; | |
| 933 w >>= 1; | |
| 934 h >>= 1; | |
| 935 } | |
| 936 | |
| 937 s->coded_order[index].picture[i]= dest; | |
| 938 for(j=0;j<h;j++) { | |
| 939 memcpy(dest, src, w); | |
| 940 dest += dest_wrap; | |
| 941 src += src_wrap; | |
| 942 } | |
| 943 } | |
| 944 if(index!=0){ | |
| 945 s->picture_buffer_index++; | |
| 588 | 946 if(s->picture_buffer_index >= REORDER_BUFFER_SIZE) s->picture_buffer_index=0; |
| 324 | 947 } |
| 948 } | |
| 949 s->coded_order[index].pict_type = s->input_pict_type; | |
| 950 s->coded_order[index].qscale = s->input_qscale; | |
| 951 s->coded_order[index].force_type= s->force_input_type; | |
| 952 s->coded_order[index].picture_in_gop_number= s->input_picture_in_gop_number; | |
| 953 s->coded_order[index].picture_number= s->input_picture_number; | |
| 954 | |
| 955 for(i=0; i<3; i++){ | |
| 956 s->new_picture[i]= s->coded_order[0].picture[i]; | |
| 957 } | |
| 958 } | |
| 959 | |
| 0 | 960 int MPV_encode_picture(AVCodecContext *avctx, |
| 961 unsigned char *buf, int buf_size, void *data) | |
| 962 { | |
| 963 MpegEncContext *s = avctx->priv_data; | |
| 964 AVPicture *pict = data; | |
| 965 | |
| 324 | 966 s->input_qscale = avctx->quality; |
| 0 | 967 |
| 968 init_put_bits(&s->pb, buf, buf_size, NULL, NULL); | |
| 969 | |
| 329 | 970 if(avctx->flags&CODEC_FLAG_TYPE){ |
| 971 s->input_pict_type= | |
| 972 s->force_input_type= avctx->key_frame ? I_TYPE : P_TYPE; | |
| 973 }else if(s->flags&CODEC_FLAG_PASS2){ | |
| 974 s->input_pict_type= | |
| 975 s->force_input_type= s->rc_context.entry[s->input_picture_number].new_pict_type; | |
| 976 }else{ | |
| 977 s->force_input_type=0; | |
| 978 if (!s->intra_only) { | |
| 979 /* first picture of GOP is intra */ | |
| 980 if (s->input_picture_in_gop_number % s->gop_size==0){ | |
| 981 s->input_pict_type = I_TYPE; | |
| 982 }else if(s->max_b_frames==0){ | |
| 983 s->input_pict_type = P_TYPE; | |
| 984 }else{ | |
| 985 if(s->b_frames_since_non_b < s->max_b_frames) //FIXME more IQ | |
| 986 s->input_pict_type = B_TYPE; | |
| 987 else | |
| 988 s->input_pict_type = P_TYPE; | |
| 989 } | |
| 990 } else { | |
| 324 | 991 s->input_pict_type = I_TYPE; |
| 992 } | |
| 0 | 993 } |
| 994 | |
| 329 | 995 if(s->input_pict_type==I_TYPE) |
| 996 s->input_picture_in_gop_number=0; | |
| 997 | |
| 324 | 998 reorder_input(s, pict); |
| 999 | |
| 1000 /* output? */ | |
| 1001 if(s->coded_order[0].picture[0]){ | |
| 1002 | |
| 1003 s->pict_type= s->coded_order[0].pict_type; | |
| 1004 if (s->fixed_qscale) /* the ratecontrol needs the last qscale so we dont touch it for CBR */ | |
| 1005 s->qscale= s->coded_order[0].qscale; | |
| 1006 s->force_type= s->coded_order[0].force_type; | |
| 1007 s->picture_in_gop_number= s->coded_order[0].picture_in_gop_number; | |
| 1008 s->picture_number= s->coded_order[0].picture_number; | |
| 1009 | |
| 553 | 1010 MPV_frame_start(s, avctx); |
| 286 | 1011 |
| 324 | 1012 encode_picture(s, s->picture_number); |
| 652 | 1013 |
| 376 | 1014 avctx->real_pict_num = s->picture_number; |
| 324 | 1015 avctx->header_bits = s->header_bits; |
| 1016 avctx->mv_bits = s->mv_bits; | |
| 1017 avctx->misc_bits = s->misc_bits; | |
| 1018 avctx->i_tex_bits = s->i_tex_bits; | |
| 1019 avctx->p_tex_bits = s->p_tex_bits; | |
| 1020 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
|
1021 avctx->p_count = s->mb_num - s->i_count - s->skip_count; //FIXME f/b_count in avctx |
| 324 | 1022 avctx->skip_count = s->skip_count; |
| 0 | 1023 |
| 324 | 1024 MPV_frame_end(s); |
| 1025 | |
| 1026 if (s->out_format == FMT_MJPEG) | |
| 1027 mjpeg_picture_trailer(s); | |
| 1028 | |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
1029 if(!s->fixed_qscale) |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
1030 avctx->quality = s->qscale; |
| 329 | 1031 |
| 1032 if(s->flags&CODEC_FLAG_PASS1) | |
| 1033 ff_write_pass1_stats(s); | |
| 456 | 1034 |
| 324 | 1035 } |
| 1036 | |
| 1037 s->input_picture_number++; | |
| 1038 s->input_picture_in_gop_number++; | |
| 0 | 1039 |
| 1040 flush_put_bits(&s->pb); | |
| 268 | 1041 s->frame_bits = (pbBufPtr(&s->pb) - s->pb.buf) * 8; |
| 612 | 1042 |
| 268 | 1043 s->total_bits += s->frame_bits; |
| 286 | 1044 avctx->frame_bits = s->frame_bits; |
| 1045 //printf("fcode: %d, type: %d, head: %d, mv: %d, misc: %d, frame: %d, itex: %d, ptex: %d\n", | |
| 1046 //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 | 1047 #if 0 //dump some stats to stats.txt for testing/debuging |
| 1048 if(s->max_b_frames==0) | |
| 1049 { | |
| 1050 static FILE *f=NULL; | |
| 1051 if(!f) f= fopen("stats.txt", "wb"); | |
| 1052 get_psnr(pict->data, s->current_picture, | |
| 1053 pict->linesize, s->linesize, avctx); | |
| 1054 fprintf(f, "%7d, %7d, %2.4f\n", pbBufPtr(&s->pb) - s->pb.buf, s->qscale, avctx->psnr_y); | |
| 1055 } | |
| 1056 #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
|
1057 |
|
252
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
1058 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
|
1059 /* 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
|
1060 /* 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
|
1061 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
|
1062 pict->linesize, s->linesize, avctx); |
| 324 | 1063 // 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
|
1064 } |
|
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
|
1065 return pbBufPtr(&s->pb) - s->pb.buf; |
| 0 | 1066 } |
| 1067 | |
| 255 | 1068 static inline void gmc1_motion(MpegEncContext *s, |
| 1069 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 1070 int dest_offset, | |
| 753 | 1071 UINT8 **ref_picture, int src_offset) |
| 255 | 1072 { |
| 1073 UINT8 *ptr; | |
| 556 | 1074 int offset, src_x, src_y, linesize, uvlinesize; |
| 255 | 1075 int motion_x, motion_y; |
| 566 | 1076 int emu=0; |
| 255 | 1077 |
| 1078 motion_x= s->sprite_offset[0][0]; | |
| 1079 motion_y= s->sprite_offset[0][1]; | |
| 1080 src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
| 1081 src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
| 1082 motion_x<<=(3-s->sprite_warping_accuracy); | |
| 1083 motion_y<<=(3-s->sprite_warping_accuracy); | |
| 1084 src_x = clip(src_x, -16, s->width); | |
| 1085 if (src_x == s->width) | |
| 1086 motion_x =0; | |
| 1087 src_y = clip(src_y, -16, s->height); | |
| 1088 if (src_y == s->height) | |
| 1089 motion_y =0; | |
| 753 | 1090 |
| 255 | 1091 linesize = s->linesize; |
| 556 | 1092 uvlinesize = s->uvlinesize; |
| 753 | 1093 |
| 255 | 1094 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; |
| 1095 | |
| 1096 dest_y+=dest_offset; | |
| 566 | 1097 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1098 if(src_x<0 || src_y<0 || src_x + (motion_x&15) + 16 > s->h_edge_pos |
| 753 | 1099 || src_y + (motion_y&15) + 16 > s->v_edge_pos){ |
| 1100 emulated_edge_mc(s, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos); | |
| 566 | 1101 ptr= s->edge_emu_buffer; |
| 1102 emu=1; | |
| 1103 } | |
| 1104 } | |
| 753 | 1105 |
| 1106 if((motion_x|motion_y)&7){ | |
| 1107 ff_gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); | |
| 1108 ff_gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); | |
| 1109 }else{ | |
| 1110 int dxy; | |
| 1111 | |
| 1112 dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2); | |
| 1113 if (s->no_rounding){ | |
| 1114 put_no_rnd_pixels_tab[0][dxy](dest_y, ptr, linesize, 16); | |
| 1115 }else{ | |
| 1116 put_pixels_tab [0][dxy](dest_y, ptr, linesize, 16); | |
| 1117 } | |
| 1118 } | |
| 1119 | |
| 1120 if(s->flags&CODEC_FLAG_GRAY) return; | |
| 255 | 1121 |
| 1122 motion_x= s->sprite_offset[1][0]; | |
| 1123 motion_y= s->sprite_offset[1][1]; | |
| 1124 src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
| 1125 src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
| 1126 motion_x<<=(3-s->sprite_warping_accuracy); | |
| 1127 motion_y<<=(3-s->sprite_warping_accuracy); | |
| 1128 src_x = clip(src_x, -8, s->width>>1); | |
| 1129 if (src_x == s->width>>1) | |
| 1130 motion_x =0; | |
| 1131 src_y = clip(src_y, -8, s->height>>1); | |
| 1132 if (src_y == s->height>>1) | |
| 1133 motion_y =0; | |
| 1134 | |
| 556 | 1135 offset = (src_y * uvlinesize) + src_x + (src_offset>>1); |
| 255 | 1136 ptr = ref_picture[1] + offset; |
| 566 | 1137 if(emu){ |
| 753 | 1138 emulated_edge_mc(s, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
| 566 | 1139 ptr= s->edge_emu_buffer; |
| 1140 } | |
| 753 | 1141 ff_gmc1(dest_cb + (dest_offset>>1), ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); |
| 566 | 1142 |
| 255 | 1143 ptr = ref_picture[2] + offset; |
| 566 | 1144 if(emu){ |
| 753 | 1145 emulated_edge_mc(s, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
| 566 | 1146 ptr= s->edge_emu_buffer; |
| 1147 } | |
| 753 | 1148 ff_gmc1(dest_cr + (dest_offset>>1), ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); |
| 255 | 1149 |
| 1150 return; | |
| 1151 } | |
| 1152 | |
| 753 | 1153 static inline void gmc_motion(MpegEncContext *s, |
| 1154 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 1155 int dest_offset, | |
| 1156 UINT8 **ref_picture, int src_offset) | |
| 1157 { | |
| 1158 UINT8 *ptr; | |
| 1159 int linesize, uvlinesize; | |
| 1160 const int a= s->sprite_warping_accuracy; | |
| 1161 int ox, oy; | |
| 1162 | |
| 1163 linesize = s->linesize; | |
| 1164 uvlinesize = s->uvlinesize; | |
| 1165 | |
| 1166 ptr = ref_picture[0] + src_offset; | |
| 1167 | |
| 1168 dest_y+=dest_offset; | |
| 1169 | |
| 1170 ox= s->sprite_offset[0][0] + s->sprite_delta[0][0]*s->mb_x*16 + s->sprite_delta[0][1]*s->mb_y*16; | |
| 1171 oy= s->sprite_offset[0][1] + s->sprite_delta[1][0]*s->mb_x*16 + s->sprite_delta[1][1]*s->mb_y*16; | |
| 1172 | |
| 1173 ff_gmc(dest_y, ptr, linesize, 16, | |
| 1174 ox, | |
| 1175 oy, | |
| 1176 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
| 1177 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
| 1178 a+1, (1<<(2*a+1)) - s->no_rounding, | |
| 1179 s->h_edge_pos, s->v_edge_pos); | |
| 1180 ff_gmc(dest_y+8, ptr, linesize, 16, | |
| 1181 ox + s->sprite_delta[0][0]*8, | |
| 1182 oy + s->sprite_delta[1][0]*8, | |
| 1183 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
| 1184 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
| 1185 a+1, (1<<(2*a+1)) - s->no_rounding, | |
| 1186 s->h_edge_pos, s->v_edge_pos); | |
| 1187 | |
| 1188 if(s->flags&CODEC_FLAG_GRAY) return; | |
| 1189 | |
| 1190 | |
| 1191 dest_cb+=dest_offset>>1; | |
| 1192 dest_cr+=dest_offset>>1; | |
| 1193 | |
| 1194 ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8; | |
| 1195 oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8; | |
| 1196 | |
| 1197 ptr = ref_picture[1] + (src_offset>>1); | |
| 1198 ff_gmc(dest_cb, ptr, uvlinesize, 8, | |
| 1199 ox, | |
| 1200 oy, | |
| 1201 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
| 1202 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
| 1203 a+1, (1<<(2*a+1)) - s->no_rounding, | |
| 1204 s->h_edge_pos>>1, s->v_edge_pos>>1); | |
| 1205 | |
| 1206 ptr = ref_picture[2] + (src_offset>>1); | |
| 1207 ff_gmc(dest_cr, ptr, uvlinesize, 8, | |
| 1208 ox, | |
| 1209 oy, | |
| 1210 s->sprite_delta[0][0], s->sprite_delta[0][1], | |
| 1211 s->sprite_delta[1][0], s->sprite_delta[1][1], | |
| 1212 a+1, (1<<(2*a+1)) - s->no_rounding, | |
| 1213 s->h_edge_pos>>1, s->v_edge_pos>>1); | |
| 1214 } | |
| 1215 | |
| 1216 | |
| 566 | 1217 static void emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int block_w, int block_h, |
| 553 | 1218 int src_x, int src_y, int w, int h){ |
| 1219 int x, y; | |
| 1220 int start_y, start_x, end_y, end_x; | |
| 566 | 1221 UINT8 *buf= s->edge_emu_buffer; |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1222 |
| 553 | 1223 if(src_y>= h){ |
| 1224 src+= (h-1-src_y)*linesize; | |
| 1225 src_y=h-1; | |
| 554 | 1226 }else if(src_y<=-block_h){ |
| 1227 src+= (1-block_h-src_y)*linesize; | |
| 1228 src_y=1-block_h; | |
| 553 | 1229 } |
| 1230 if(src_x>= w){ | |
| 1231 src+= (w-1-src_x); | |
| 1232 src_x=w-1; | |
| 554 | 1233 }else if(src_x<=-block_w){ |
| 1234 src+= (1-block_w-src_x); | |
| 1235 src_x=1-block_w; | |
| 553 | 1236 } |
| 1237 | |
| 1238 start_y= MAX(0, -src_y); | |
| 1239 start_x= MAX(0, -src_x); | |
| 1240 end_y= MIN(block_h, h-src_y); | |
| 1241 end_x= MIN(block_w, w-src_x); | |
| 566 | 1242 |
| 553 | 1243 // copy existing part |
| 1244 for(y=start_y; y<end_y; y++){ | |
| 1245 for(x=start_x; x<end_x; x++){ | |
| 1246 buf[x + y*linesize]= src[x + y*linesize]; | |
| 1247 } | |
| 1248 } | |
| 1249 | |
| 1250 //top | |
| 1251 for(y=0; y<start_y; y++){ | |
| 1252 for(x=start_x; x<end_x; x++){ | |
| 1253 buf[x + y*linesize]= buf[x + start_y*linesize]; | |
| 1254 } | |
| 1255 } | |
| 1256 | |
| 1257 //bottom | |
| 1258 for(y=end_y; y<block_h; y++){ | |
| 1259 for(x=start_x; x<end_x; x++){ | |
| 1260 buf[x + y*linesize]= buf[x + (end_y-1)*linesize]; | |
| 1261 } | |
| 1262 } | |
| 1263 | |
| 1264 for(y=0; y<block_h; y++){ | |
| 1265 //left | |
| 1266 for(x=0; x<start_x; x++){ | |
| 1267 buf[x + y*linesize]= buf[start_x + y*linesize]; | |
| 1268 } | |
| 1269 | |
| 1270 //right | |
| 1271 for(x=end_x; x<block_w; x++){ | |
| 1272 buf[x + y*linesize]= buf[end_x - 1 + y*linesize]; | |
| 1273 } | |
| 1274 } | |
| 1275 } | |
| 1276 | |
| 1277 | |
| 0 | 1278 /* apply one mpeg motion vector to the three components */ |
| 1279 static inline void mpeg_motion(MpegEncContext *s, | |
| 1280 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 1281 int dest_offset, | |
| 1282 UINT8 **ref_picture, int src_offset, | |
| 651 | 1283 int field_based, op_pixels_func (*pix_op)[4], |
| 0 | 1284 int motion_x, int motion_y, int h) |
| 1285 { | |
| 1286 UINT8 *ptr; | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1287 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize; |
| 553 | 1288 int emu=0; |
| 651 | 1289 #if 0 |
| 255 | 1290 if(s->quarter_sample) |
| 1291 { | |
| 1292 motion_x>>=1; | |
| 1293 motion_y>>=1; | |
| 1294 } | |
| 651 | 1295 #endif |
| 0 | 1296 dxy = ((motion_y & 1) << 1) | (motion_x & 1); |
| 1297 src_x = s->mb_x * 16 + (motion_x >> 1); | |
| 1298 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1); | |
| 1299 | |
| 1300 /* WARNING: do no forget half pels */ | |
| 1301 height = s->height >> field_based; | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1302 v_edge_pos = s->v_edge_pos >> field_based; |
| 0 | 1303 src_x = clip(src_x, -16, s->width); |
| 1304 if (src_x == s->width) | |
| 1305 dxy &= ~1; | |
| 1306 src_y = clip(src_y, -16, height); | |
| 1307 if (src_y == height) | |
| 1308 dxy &= ~2; | |
|
565
44d744901ded
interlaced mpeg2 fix ... replacing linesize>>1 by uvlinesize brainlessly wasnt a good idea
michaelni
parents:
562
diff
changeset
|
1309 linesize = s->linesize << field_based; |
|
44d744901ded
interlaced mpeg2 fix ... replacing linesize>>1 by uvlinesize brainlessly wasnt a good idea
michaelni
parents:
562
diff
changeset
|
1310 uvlinesize = s->uvlinesize << field_based; |
| 0 | 1311 ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset; |
| 1312 dest_y += dest_offset; | |
| 553 | 1313 |
| 1314 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1315 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
|
1316 || src_y + (motion_y&1) + h > v_edge_pos){ |
| 763 | 1317 emulated_edge_mc(s, ptr - src_offset, s->linesize, 17, 17+field_based, |
| 1318 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); | |
| 1319 ptr= s->edge_emu_buffer + src_offset; | |
| 553 | 1320 emu=1; |
| 1321 } | |
| 1322 } | |
| 651 | 1323 pix_op[0][dxy](dest_y, ptr, linesize, h); |
| 0 | 1324 |
| 485 | 1325 if(s->flags&CODEC_FLAG_GRAY) return; |
| 1326 | |
| 0 | 1327 if (s->out_format == FMT_H263) { |
| 1328 dxy = 0; | |
| 1329 if ((motion_x & 3) != 0) | |
| 1330 dxy |= 1; | |
| 1331 if ((motion_y & 3) != 0) | |
| 1332 dxy |= 2; | |
| 1333 mx = motion_x >> 2; | |
| 1334 my = motion_y >> 2; | |
| 1335 } else { | |
| 1336 mx = motion_x / 2; | |
| 1337 my = motion_y / 2; | |
| 1338 dxy = ((my & 1) << 1) | (mx & 1); | |
| 1339 mx >>= 1; | |
| 1340 my >>= 1; | |
| 1341 } | |
| 1342 | |
| 1343 src_x = s->mb_x * 8 + mx; | |
| 1344 src_y = s->mb_y * (8 >> field_based) + my; | |
| 1345 src_x = clip(src_x, -8, s->width >> 1); | |
| 1346 if (src_x == (s->width >> 1)) | |
| 1347 dxy &= ~1; | |
| 1348 src_y = clip(src_y, -8, height >> 1); | |
| 1349 if (src_y == (height >> 1)) | |
| 1350 dxy &= ~2; | |
|
565
44d744901ded
interlaced mpeg2 fix ... replacing linesize>>1 by uvlinesize brainlessly wasnt a good idea
michaelni
parents:
562
diff
changeset
|
1351 offset = (src_y * uvlinesize) + src_x + (src_offset >> 1); |
| 0 | 1352 ptr = ref_picture[1] + offset; |
| 553 | 1353 if(emu){ |
| 763 | 1354 emulated_edge_mc(s, ptr - (src_offset >> 1), s->uvlinesize, 9, 9+field_based, |
| 1355 src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
| 1356 ptr= s->edge_emu_buffer + (src_offset >> 1); | |
| 553 | 1357 } |
| 651 | 1358 pix_op[1][dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
| 553 | 1359 |
| 0 | 1360 ptr = ref_picture[2] + offset; |
| 553 | 1361 if(emu){ |
| 763 | 1362 emulated_edge_mc(s, ptr - (src_offset >> 1), s->uvlinesize, 9, 9+field_based, |
| 1363 src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
| 1364 ptr= s->edge_emu_buffer + (src_offset >> 1); | |
| 553 | 1365 } |
| 651 | 1366 pix_op[1][dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
| 0 | 1367 } |
| 1368 | |
| 255 | 1369 static inline void qpel_motion(MpegEncContext *s, |
| 1370 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 1371 int dest_offset, | |
| 1372 UINT8 **ref_picture, int src_offset, | |
| 651 | 1373 int field_based, op_pixels_func (*pix_op)[4], |
| 1374 qpel_mc_func (*qpix_op)[16], | |
| 255 | 1375 int motion_x, int motion_y, int h) |
| 1376 { | |
| 1377 UINT8 *ptr; | |
| 671 | 1378 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize; |
| 554 | 1379 int emu=0; |
| 255 | 1380 |
| 1381 dxy = ((motion_y & 3) << 2) | (motion_x & 3); | |
| 1382 src_x = s->mb_x * 16 + (motion_x >> 2); | |
| 1383 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); | |
| 1384 | |
| 1385 height = s->height >> field_based; | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1386 v_edge_pos = s->v_edge_pos >> field_based; |
| 255 | 1387 src_x = clip(src_x, -16, s->width); |
| 1388 if (src_x == s->width) | |
| 1389 dxy &= ~3; | |
| 1390 src_y = clip(src_y, -16, height); | |
| 1391 if (src_y == height) | |
| 1392 dxy &= ~12; | |
| 1393 linesize = s->linesize << field_based; | |
| 671 | 1394 uvlinesize = s->uvlinesize << field_based; |
| 255 | 1395 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; |
| 1396 dest_y += dest_offset; | |
| 1397 //printf("%d %d %d\n", src_x, src_y, dxy); | |
| 554 | 1398 |
| 1399 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1400 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
|
1401 || src_y + (motion_y&3) + h > v_edge_pos){ |
| 763 | 1402 emulated_edge_mc(s, ptr - src_offset, s->linesize, 17, 17+field_based, |
| 1403 src_x, src_y<<field_based, s->h_edge_pos, s->v_edge_pos); | |
| 1404 ptr= s->edge_emu_buffer + src_offset; | |
| 554 | 1405 emu=1; |
| 1406 } | |
| 1407 } | |
| 671 | 1408 if(!field_based) |
| 1409 qpix_op[0][dxy](dest_y, ptr, linesize); | |
| 1410 else{ | |
| 1411 //damn interlaced mode | |
| 1412 //FIXME boundary mirroring is not exactly correct here | |
| 1413 qpix_op[1][dxy](dest_y , ptr , linesize); | |
| 1414 qpix_op[1][dxy](dest_y+8, ptr+8, linesize); | |
| 1415 } | |
| 651 | 1416 |
| 485 | 1417 if(s->flags&CODEC_FLAG_GRAY) return; |
| 1418 | |
| 671 | 1419 if(field_based){ |
| 1420 mx= motion_x/2; | |
| 1421 my= motion_y>>1; | |
| 760 | 1422 }else if(s->workaround_bugs&FF_BUG_QPEL_CHROMA){ |
| 671 | 1423 mx= (motion_x>>1)|(motion_x&1); |
| 1424 my= (motion_y>>1)|(motion_y&1); | |
| 1425 }else{ | |
| 1426 mx= motion_x/2; | |
| 1427 my= motion_y/2; | |
| 1428 } | |
| 1429 mx= (mx>>1)|(mx&1); | |
| 1430 my= (my>>1)|(my&1); | |
| 1431 dxy= (mx&1) | ((my&1)<<1); | |
| 1432 mx>>=1; | |
| 1433 my>>=1; | |
| 255 | 1434 |
| 1435 src_x = s->mb_x * 8 + mx; | |
| 1436 src_y = s->mb_y * (8 >> field_based) + my; | |
| 1437 src_x = clip(src_x, -8, s->width >> 1); | |
| 1438 if (src_x == (s->width >> 1)) | |
| 1439 dxy &= ~1; | |
| 1440 src_y = clip(src_y, -8, height >> 1); | |
| 1441 if (src_y == (height >> 1)) | |
| 1442 dxy &= ~2; | |
| 1443 | |
| 671 | 1444 offset = (src_y * uvlinesize) + src_x + (src_offset >> 1); |
| 255 | 1445 ptr = ref_picture[1] + offset; |
| 554 | 1446 if(emu){ |
| 763 | 1447 emulated_edge_mc(s, ptr - (src_offset >> 1), s->uvlinesize, 9, 9 + field_based, |
| 1448 src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
| 1449 ptr= s->edge_emu_buffer + (src_offset >> 1); | |
| 554 | 1450 } |
| 671 | 1451 pix_op[1][dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
| 554 | 1452 |
| 255 | 1453 ptr = ref_picture[2] + offset; |
| 554 | 1454 if(emu){ |
| 763 | 1455 emulated_edge_mc(s, ptr - (src_offset >> 1), s->uvlinesize, 9, 9 + field_based, |
| 1456 src_x, src_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); | |
| 1457 ptr= s->edge_emu_buffer + (src_offset >> 1); | |
| 554 | 1458 } |
| 671 | 1459 pix_op[1][dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
| 255 | 1460 } |
| 1461 | |
| 1462 | |
| 0 | 1463 static inline void MPV_motion(MpegEncContext *s, |
| 1464 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 1465 int dir, UINT8 **ref_picture, | |
| 651 | 1466 op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16]) |
| 0 | 1467 { |
| 1468 int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y; | |
| 1469 int mb_x, mb_y, i; | |
| 1470 UINT8 *ptr, *dest; | |
| 554 | 1471 int emu=0; |
| 0 | 1472 |
| 1473 mb_x = s->mb_x; | |
| 1474 mb_y = s->mb_y; | |
| 1475 | |
| 1476 switch(s->mv_type) { | |
| 1477 case MV_TYPE_16X16: | |
| 255 | 1478 if(s->mcsel){ |
| 753 | 1479 if(s->real_sprite_warping_points==1){ |
| 1480 gmc1_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 1481 ref_picture, 0); | |
| 1482 }else{ | |
| 1483 gmc_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 1484 ref_picture, 0); | |
| 1485 } | |
| 651 | 1486 }else if(s->quarter_sample){ |
| 255 | 1487 qpel_motion(s, dest_y, dest_cb, dest_cr, 0, |
| 1488 ref_picture, 0, | |
| 1489 0, pix_op, qpix_op, | |
| 1490 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
| 1491 }else{ | |
| 1492 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 1493 ref_picture, 0, | |
| 1494 0, pix_op, | |
| 1495 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
| 1496 } | |
| 0 | 1497 break; |
| 1498 case MV_TYPE_8X8: | |
| 673 | 1499 mx = 0; |
| 1500 my = 0; | |
| 1501 if(s->quarter_sample){ | |
| 1502 for(i=0;i<4;i++) { | |
| 1503 motion_x = s->mv[dir][i][0]; | |
| 1504 motion_y = s->mv[dir][i][1]; | |
| 0 | 1505 |
| 673 | 1506 dxy = ((motion_y & 3) << 2) | (motion_x & 3); |
| 1507 src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8; | |
| 1508 src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8; | |
| 1509 | |
| 1510 /* WARNING: do no forget half pels */ | |
| 1511 src_x = clip(src_x, -16, s->width); | |
| 1512 if (src_x == s->width) | |
| 1513 dxy &= ~3; | |
| 1514 src_y = clip(src_y, -16, s->height); | |
| 1515 if (src_y == s->height) | |
| 1516 dxy &= ~12; | |
| 0 | 1517 |
| 673 | 1518 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); |
| 1519 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
| 1520 if(src_x<0 || src_y<0 || src_x + (motion_x&3) + 8 > s->h_edge_pos | |
| 1521 || src_y + (motion_y&3) + 8 > s->v_edge_pos){ | |
| 1522 emulated_edge_mc(s, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos); | |
| 1523 ptr= s->edge_emu_buffer; | |
| 1524 } | |
| 1525 } | |
| 1526 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; | |
| 1527 qpix_op[1][dxy](dest, ptr, s->linesize); | |
| 1528 | |
| 1529 mx += s->mv[dir][i][0]/2; | |
| 1530 my += s->mv[dir][i][1]/2; | |
| 1531 } | |
| 1532 }else{ | |
| 1533 for(i=0;i<4;i++) { | |
| 1534 motion_x = s->mv[dir][i][0]; | |
| 1535 motion_y = s->mv[dir][i][1]; | |
| 1536 | |
| 1537 dxy = ((motion_y & 1) << 1) | (motion_x & 1); | |
| 1538 src_x = mb_x * 16 + (motion_x >> 1) + (i & 1) * 8; | |
| 1539 src_y = mb_y * 16 + (motion_y >> 1) + (i >>1) * 8; | |
| 0 | 1540 |
| 673 | 1541 /* WARNING: do no forget half pels */ |
| 1542 src_x = clip(src_x, -16, s->width); | |
| 1543 if (src_x == s->width) | |
| 1544 dxy &= ~1; | |
| 1545 src_y = clip(src_y, -16, s->height); | |
| 1546 if (src_y == s->height) | |
| 1547 dxy &= ~2; | |
| 1548 | |
| 1549 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); | |
| 1550 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
| 1551 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 8 > s->h_edge_pos | |
| 1552 || src_y + (motion_y&1) + 8 > s->v_edge_pos){ | |
| 1553 emulated_edge_mc(s, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos); | |
| 1554 ptr= s->edge_emu_buffer; | |
| 1555 } | |
| 554 | 1556 } |
| 673 | 1557 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; |
| 1558 pix_op[1][dxy](dest, ptr, s->linesize, 8); | |
| 1559 | |
| 1560 mx += s->mv[dir][i][0]; | |
| 1561 my += s->mv[dir][i][1]; | |
| 554 | 1562 } |
| 0 | 1563 } |
| 673 | 1564 |
| 485 | 1565 if(s->flags&CODEC_FLAG_GRAY) break; |
| 0 | 1566 /* In case of 8X8, we construct a single chroma motion vector |
| 1567 with a special rounding */ | |
| 1568 for(i=0;i<4;i++) { | |
| 1569 } | |
| 1570 if (mx >= 0) | |
| 1571 mx = (h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1)); | |
| 1572 else { | |
| 1573 mx = -mx; | |
| 1574 mx = -(h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1)); | |
| 1575 } | |
| 1576 if (my >= 0) | |
| 1577 my = (h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1)); | |
| 1578 else { | |
| 1579 my = -my; | |
| 1580 my = -(h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1)); | |
| 1581 } | |
| 1582 dxy = ((my & 1) << 1) | (mx & 1); | |
| 1583 mx >>= 1; | |
| 1584 my >>= 1; | |
| 1585 | |
| 1586 src_x = mb_x * 8 + mx; | |
| 1587 src_y = mb_y * 8 + my; | |
| 1588 src_x = clip(src_x, -8, s->width/2); | |
| 1589 if (src_x == s->width/2) | |
| 1590 dxy &= ~1; | |
| 1591 src_y = clip(src_y, -8, s->height/2); | |
| 1592 if (src_y == s->height/2) | |
| 1593 dxy &= ~2; | |
| 1594 | |
| 556 | 1595 offset = (src_y * (s->uvlinesize)) + src_x; |
| 0 | 1596 ptr = ref_picture[1] + offset; |
| 554 | 1597 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1598 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
|
1599 || src_y + (dxy>>1) + 8 > s->v_edge_pos>>1){ |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1600 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
| 554 | 1601 ptr= s->edge_emu_buffer; |
| 1602 emu=1; | |
| 1603 } | |
| 1604 } | |
| 651 | 1605 pix_op[1][dxy](dest_cb, ptr, s->uvlinesize, 8); |
| 554 | 1606 |
| 0 | 1607 ptr = ref_picture[2] + offset; |
| 554 | 1608 if(emu){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1609 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
| 554 | 1610 ptr= s->edge_emu_buffer; |
| 1611 } | |
| 651 | 1612 pix_op[1][dxy](dest_cr, ptr, s->uvlinesize, 8); |
| 0 | 1613 break; |
| 1614 case MV_TYPE_FIELD: | |
| 1615 if (s->picture_structure == PICT_FRAME) { | |
| 671 | 1616 if(s->quarter_sample){ |
| 1617 /* top field */ | |
| 1618 qpel_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 1619 ref_picture, s->field_select[dir][0] ? s->linesize : 0, | |
| 1620 1, pix_op, qpix_op, | |
| 1621 s->mv[dir][0][0], s->mv[dir][0][1], 8); | |
| 1622 /* bottom field */ | |
| 1623 qpel_motion(s, dest_y, dest_cb, dest_cr, s->linesize, | |
| 1624 ref_picture, s->field_select[dir][1] ? s->linesize : 0, | |
| 1625 1, pix_op, qpix_op, | |
| 1626 s->mv[dir][1][0], s->mv[dir][1][1], 8); | |
| 1627 }else{ | |
| 1628 /* top field */ | |
| 1629 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 1630 ref_picture, s->field_select[dir][0] ? s->linesize : 0, | |
| 1631 1, pix_op, | |
| 1632 s->mv[dir][0][0], s->mv[dir][0][1], 8); | |
| 1633 /* bottom field */ | |
| 1634 mpeg_motion(s, dest_y, dest_cb, dest_cr, s->linesize, | |
| 1635 ref_picture, s->field_select[dir][1] ? s->linesize : 0, | |
| 1636 1, pix_op, | |
| 1637 s->mv[dir][1][0], s->mv[dir][1][1], 8); | |
| 1638 } | |
| 0 | 1639 } else { |
| 1640 | |
| 1641 | |
| 1642 } | |
| 1643 break; | |
| 1644 } | |
| 1645 } | |
| 1646 | |
| 1647 | |
| 1648 /* put block[] to dest[] */ | |
| 1649 static inline void put_dct(MpegEncContext *s, | |
| 1650 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
| 1651 { | |
| 711 | 1652 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
|
1653 s->idct_put (dest, line_size, block); |
| 0 | 1654 } |
| 1655 | |
| 1656 /* add block[] to dest[] */ | |
| 1657 static inline void add_dct(MpegEncContext *s, | |
| 1658 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
| 1659 { | |
| 1660 if (s->block_last_index[i] >= 0) { | |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1661 s->idct_add (dest, line_size, block); |
| 481 | 1662 } |
| 1663 } | |
| 1664 | |
| 1665 static inline void add_dequant_dct(MpegEncContext *s, | |
| 1666 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
| 1667 { | |
| 1668 if (s->block_last_index[i] >= 0) { | |
| 1669 s->dct_unquantize(s, block, i, s->qscale); | |
| 324 | 1670 |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1671 s->idct_add (dest, line_size, block); |
| 0 | 1672 } |
| 1673 } | |
| 1674 | |
| 456 | 1675 /** |
| 1676 * cleans dc, ac, coded_block for the current non intra MB | |
| 1677 */ | |
| 1678 void ff_clean_intra_table_entries(MpegEncContext *s) | |
| 1679 { | |
| 1680 int wrap = s->block_wrap[0]; | |
| 1681 int xy = s->block_index[0]; | |
| 1682 | |
| 1683 s->dc_val[0][xy ] = | |
| 1684 s->dc_val[0][xy + 1 ] = | |
| 1685 s->dc_val[0][xy + wrap] = | |
| 1686 s->dc_val[0][xy + 1 + wrap] = 1024; | |
| 1687 /* ac pred */ | |
| 1688 memset(s->ac_val[0][xy ], 0, 32 * sizeof(INT16)); | |
| 1689 memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(INT16)); | |
| 1690 if (s->msmpeg4_version>=3) { | |
| 1691 s->coded_block[xy ] = | |
| 1692 s->coded_block[xy + 1 ] = | |
| 1693 s->coded_block[xy + wrap] = | |
| 1694 s->coded_block[xy + 1 + wrap] = 0; | |
| 1695 } | |
| 1696 /* chroma */ | |
| 1697 wrap = s->block_wrap[4]; | |
| 1698 xy = s->mb_x + 1 + (s->mb_y + 1) * wrap; | |
| 1699 s->dc_val[1][xy] = | |
| 1700 s->dc_val[2][xy] = 1024; | |
| 1701 /* ac pred */ | |
| 1702 memset(s->ac_val[1][xy], 0, 16 * sizeof(INT16)); | |
| 1703 memset(s->ac_val[2][xy], 0, 16 * sizeof(INT16)); | |
| 1704 | |
| 1705 s->mbintra_table[s->mb_x + s->mb_y*s->mb_width]= 0; | |
| 1706 } | |
| 1707 | |
| 0 | 1708 /* generic function called after a macroblock has been parsed by the |
| 1709 decoder or after it has been encoded by the encoder. | |
| 1710 | |
| 1711 Important variables used: | |
| 1712 s->mb_intra : true if intra macroblock | |
| 1713 s->mv_dir : motion vector direction | |
| 1714 s->mv_type : motion vector type | |
| 1715 s->mv : motion vector | |
| 1716 s->interlaced_dct : true if interlaced dct used (mpeg2) | |
| 1717 */ | |
| 1718 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) | |
| 1719 { | |
| 244 | 1720 int mb_x, mb_y; |
| 481 | 1721 const int mb_xy = s->mb_y * s->mb_width + s->mb_x; |
| 0 | 1722 |
| 1723 mb_x = s->mb_x; | |
| 1724 mb_y = s->mb_y; | |
| 1725 | |
|
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1726 #ifdef FF_POSTPROCESS |
|
466
805714c0c10f
new field for communicating with external postprocessing
nickols_k
parents:
462
diff
changeset
|
1727 /* Obsolete. Exists for compatibility with mplayer only. */ |
|
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1728 quant_store[mb_y][mb_x]=s->qscale; |
|
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1729 //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
|
1730 #else |
| 575 | 1731 /* even more obsolete, exists for mplayer xp only */ |
| 467 | 1732 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
|
1733 #endif |
| 575 | 1734 s->qscale_table[mb_xy]= s->qscale; |
|
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1735 |
| 0 | 1736 /* update DC predictors for P macroblocks */ |
| 1737 if (!s->mb_intra) { | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1738 if (s->h263_pred || s->h263_aic) { |
| 481 | 1739 if(s->mbintra_table[mb_xy]) |
| 456 | 1740 ff_clean_intra_table_entries(s); |
| 0 | 1741 } else { |
| 456 | 1742 s->last_dc[0] = |
| 1743 s->last_dc[1] = | |
| 0 | 1744 s->last_dc[2] = 128 << s->intra_dc_precision; |
| 1745 } | |
| 1746 } | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1747 else if (s->h263_pred || s->h263_aic) |
| 481 | 1748 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
|
1749 |
| 280 | 1750 /* update motion predictor, not for B-frames as they need the motion_val from the last P/S-Frame */ |
| 481 | 1751 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 | 1752 |
| 481 | 1753 const int wrap = s->block_wrap[0]; |
| 1754 const int xy = s->block_index[0]; | |
| 664 | 1755 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
|
1756 if(s->mv_type == MV_TYPE_8X8){ |
| 664 | 1757 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
|
1758 } else { |
|
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1759 int motion_x, motion_y; |
|
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1760 if (s->mb_intra) { |
|
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1761 motion_x = 0; |
|
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1762 motion_y = 0; |
| 664 | 1763 if(s->co_located_type_table) |
| 1764 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
|
1765 } 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
|
1766 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
|
1767 motion_y = s->mv[0][0][1]; |
| 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_FIELD)*/ { |
| 664 | 1771 int i; |
|
619
2be2cc8fd0a1
mpeg4 interlaced decoding support (not completly implemented/tested due to lack of samples)
michaelni
parents:
618
diff
changeset
|
1772 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
|
1773 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
|
1774 motion_x = (motion_x>>1) | (motion_x&1); |
| 664 | 1775 for(i=0; i<2; i++){ |
| 1776 s->field_mv_table[mb_index][i][0]= s->mv[0][i][0]; | |
| 1777 s->field_mv_table[mb_index][i][1]= s->mv[0][i][1]; | |
| 1778 s->field_select_table[mb_index][i]= s->field_select[0][i]; | |
| 1779 } | |
| 1780 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
|
1781 } |
| 0 | 1782 /* no update if 8X8 because it has been done during parsing */ |
| 244 | 1783 s->motion_val[xy][0] = motion_x; |
| 1784 s->motion_val[xy][1] = motion_y; | |
| 1785 s->motion_val[xy + 1][0] = motion_x; | |
| 1786 s->motion_val[xy + 1][1] = motion_y; | |
| 1787 s->motion_val[xy + wrap][0] = motion_x; | |
| 1788 s->motion_val[xy + wrap][1] = motion_y; | |
| 1789 s->motion_val[xy + 1 + wrap][0] = motion_x; | |
| 1790 s->motion_val[xy + 1 + wrap][1] = motion_y; | |
| 0 | 1791 } |
| 1792 } | |
| 1793 | |
| 324 | 1794 if (!(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { |
| 0 | 1795 UINT8 *dest_y, *dest_cb, *dest_cr; |
| 481 | 1796 int dct_linesize, dct_offset; |
| 651 | 1797 op_pixels_func (*op_pix)[4]; |
| 1798 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
|
1799 |
| 324 | 1800 /* avoid copy if macroblock skipped in last frame too |
| 1801 dont touch it for B-frames as they need the skip info from the next p-frame */ | |
| 1802 if (s->pict_type != B_TYPE) { | |
| 481 | 1803 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
|
1804 if (s->mb_skiped) { |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1805 s->mb_skiped = 0; |
| 556 | 1806 |
| 1807 (*mbskip_ptr) ++; /* indicate that this time we skiped it */ | |
| 1808 if(*mbskip_ptr >99) *mbskip_ptr= 99; | |
| 1809 | |
| 324 | 1810 /* if previous was skipped too, then nothing to do ! |
| 1811 skip only during decoding as we might trash the buffers during encoding a bit */ | |
| 556 | 1812 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
|
1813 goto the_end; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1814 } else { |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1815 *mbskip_ptr = 0; /* not skipped */ |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1816 } |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1817 } |
| 0 | 1818 |
| 717 | 1819 if(s->pict_type==B_TYPE && s->avctx->draw_horiz_band){ |
| 1820 dest_y = s->current_picture [0] + mb_x * 16; | |
| 1821 dest_cb = s->current_picture[1] + mb_x * 8; | |
| 1822 dest_cr = s->current_picture[2] + mb_x * 8; | |
| 1823 }else{ | |
| 1824 dest_y = s->current_picture [0] + (mb_y * 16* s->linesize ) + mb_x * 16; | |
| 1825 dest_cb = s->current_picture[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; | |
| 1826 dest_cr = s->current_picture[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; | |
| 1827 } | |
| 0 | 1828 |
| 1829 if (s->interlaced_dct) { | |
| 1830 dct_linesize = s->linesize * 2; | |
| 1831 dct_offset = s->linesize; | |
| 1832 } else { | |
| 1833 dct_linesize = s->linesize; | |
| 1834 dct_offset = s->linesize * 8; | |
| 1835 } | |
| 1836 | |
| 1837 if (!s->mb_intra) { | |
| 1838 /* motion handling */ | |
| 456 | 1839 /* decoding or more than one mb_type (MC was allready done otherwise) */ |
| 481 | 1840 if((!s->encoding) || (s->mb_type[mb_xy]&(s->mb_type[mb_xy]-1))){ |
| 327 | 1841 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
| 324 | 1842 op_pix = put_pixels_tab; |
| 651 | 1843 op_qpix= put_qpel_pixels_tab; |
| 324 | 1844 }else{ |
| 1845 op_pix = put_no_rnd_pixels_tab; | |
| 651 | 1846 op_qpix= put_no_rnd_qpel_pixels_tab; |
| 324 | 1847 } |
| 0 | 1848 |
| 324 | 1849 if (s->mv_dir & MV_DIR_FORWARD) { |
| 1850 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); | |
| 651 | 1851 op_pix = avg_pixels_tab; |
| 1852 op_qpix= avg_qpel_pixels_tab; | |
| 324 | 1853 } |
| 1854 if (s->mv_dir & MV_DIR_BACKWARD) { | |
| 1855 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); | |
| 1856 } | |
| 0 | 1857 } |
| 1858 | |
| 481 | 1859 /* skip dequant / idct if we are really late ;) */ |
| 1860 if(s->hurry_up>1) goto the_end; | |
| 1861 | |
| 0 | 1862 /* add dct residue */ |
| 711 | 1863 if(s->encoding || !( s->mpeg2 || s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO |
| 1864 || (s->codec_id==CODEC_ID_MPEG4 && !s->mpeg_quant))){ | |
| 481 | 1865 add_dequant_dct(s, block[0], 0, dest_y, dct_linesize); |
| 1866 add_dequant_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
| 1867 add_dequant_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
| 1868 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
| 0 | 1869 |
| 485 | 1870 if(!(s->flags&CODEC_FLAG_GRAY)){ |
| 556 | 1871 add_dequant_dct(s, block[4], 4, dest_cb, s->uvlinesize); |
| 1872 add_dequant_dct(s, block[5], 5, dest_cr, s->uvlinesize); | |
| 485 | 1873 } |
| 481 | 1874 } else { |
| 1875 add_dct(s, block[0], 0, dest_y, dct_linesize); | |
| 1876 add_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
| 1877 add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
| 1878 add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
| 1879 | |
| 485 | 1880 if(!(s->flags&CODEC_FLAG_GRAY)){ |
| 556 | 1881 add_dct(s, block[4], 4, dest_cb, s->uvlinesize); |
| 1882 add_dct(s, block[5], 5, dest_cr, s->uvlinesize); | |
| 485 | 1883 } |
| 481 | 1884 } |
| 0 | 1885 } else { |
| 1886 /* dct only in intra block */ | |
| 711 | 1887 if(s->encoding || !(s->mpeg2 || s->codec_id==CODEC_ID_MPEG1VIDEO)){ |
| 1888 put_dct(s, block[0], 0, dest_y, dct_linesize); | |
| 1889 put_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
| 1890 put_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
| 1891 put_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
| 0 | 1892 |
| 711 | 1893 if(!(s->flags&CODEC_FLAG_GRAY)){ |
| 1894 put_dct(s, block[4], 4, dest_cb, s->uvlinesize); | |
| 1895 put_dct(s, block[5], 5, dest_cr, s->uvlinesize); | |
| 1896 } | |
| 1897 }else{ | |
| 1898 s->idct_put(dest_y , dct_linesize, block[0]); | |
| 1899 s->idct_put(dest_y + 8, dct_linesize, block[1]); | |
| 1900 s->idct_put(dest_y + dct_offset , dct_linesize, block[2]); | |
| 1901 s->idct_put(dest_y + dct_offset + 8, dct_linesize, block[3]); | |
| 1902 | |
| 1903 if(!(s->flags&CODEC_FLAG_GRAY)){ | |
| 1904 s->idct_put(dest_cb, s->uvlinesize, block[4]); | |
| 1905 s->idct_put(dest_cr, s->uvlinesize, block[5]); | |
| 1906 } | |
| 485 | 1907 } |
| 0 | 1908 } |
| 1909 } | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1910 the_end: |
| 294 | 1911 emms_c(); //FIXME remove |
| 1912 } | |
| 1913 | |
|
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
1914 static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold) |
| 456 | 1915 { |
| 1916 static const char tab[64]= | |
| 1917 {3,2,2,1,1,1,1,1, | |
| 1918 1,1,1,1,1,1,1,1, | |
| 1919 1,1,1,1,1,1,1,1, | |
| 1920 0,0,0,0,0,0,0,0, | |
| 1921 0,0,0,0,0,0,0,0, | |
| 1922 0,0,0,0,0,0,0,0, | |
| 1923 0,0,0,0,0,0,0,0, | |
| 1924 0,0,0,0,0,0,0,0}; | |
| 1925 int score=0; | |
| 1926 int run=0; | |
| 1927 int i; | |
| 1928 DCTELEM *block= s->block[n]; | |
| 1929 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
|
1930 int skip_dc; |
| 456 | 1931 |
|
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
|
1932 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
|
1933 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
|
1934 threshold= -threshold; |
|
605
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
1935 }else |
|
40874804a5af
same dc skip behavior for chroma & luma elimination, its confusing otherwise imho
michaelni
parents:
604
diff
changeset
|
1936 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
|
1937 |
| 456 | 1938 /* are all which we could set to zero are allready zero? */ |
| 1939 if(last_index<=skip_dc - 1) return; | |
| 1940 | |
| 1941 for(i=0; i<=last_index; i++){ | |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1942 const int j = s->intra_scantable.permutated[i]; |
| 456 | 1943 const int level = ABS(block[j]); |
| 1944 if(level==1){ | |
| 1945 if(skip_dc && i==0) continue; | |
| 1946 score+= tab[run]; | |
| 1947 run=0; | |
| 1948 }else if(level>1){ | |
| 1949 return; | |
| 1950 }else{ | |
| 1951 run++; | |
| 1952 } | |
| 1953 } | |
| 1954 if(score >= threshold) return; | |
| 1955 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
|
1956 const int j = s->intra_scantable.permutated[i]; |
| 456 | 1957 block[j]=0; |
| 1958 } | |
| 1959 if(block[0]) s->block_last_index[n]= 0; | |
| 1960 else s->block_last_index[n]= -1; | |
| 1961 } | |
| 1962 | |
| 344 | 1963 static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) |
| 1964 { | |
| 1965 int i; | |
| 1966 const int maxlevel= s->max_qcoeff; | |
| 1967 const int minlevel= s->min_qcoeff; | |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1968 |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1969 if(s->mb_intra){ |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1970 i=1; //skip clipping of intra dc |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1971 }else |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1972 i=0; |
|
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 for(;i<=last_index; i++){ |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1975 const int j= s->intra_scantable.permutated[i]; |
| 344 | 1976 int level = block[j]; |
| 1977 | |
| 1978 if (level>maxlevel) level=maxlevel; | |
| 1979 else if(level<minlevel) level=minlevel; | |
| 1980 block[j]= level; | |
| 1981 } | |
| 1982 } | |
| 324 | 1983 |
| 697 | 1984 static inline void requantize_coeffs(MpegEncContext *s, DCTELEM block[64], int oldq, int newq, int n) |
| 1985 { | |
| 1986 int i; | |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1987 |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1988 if(s->mb_intra){ |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1989 i=1; //skip clipping of intra dc |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
1990 //FIXME requantize, note (mpeg1/h263/h263p-aic dont need it,...) |
| 697 | 1991 }else |
| 1992 i=0; | |
| 1993 | |
| 1994 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
|
1995 const int j = s->intra_scantable.permutated[i]; |
| 697 | 1996 int level = block[j]; |
| 1997 | |
| 1998 block[j]= ROUNDED_DIV(level*oldq, newq); | |
| 1999 } | |
| 2000 | |
| 2001 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
|
2002 const int j = s->intra_scantable.permutated[i]; |
| 697 | 2003 if(block[j]) break; |
| 2004 } | |
| 2005 s->block_last_index[n]= i; | |
| 2006 } | |
| 2007 | |
| 2008 static inline void auto_requantize_coeffs(MpegEncContext *s, DCTELEM block[6][64]) | |
| 2009 { | |
| 2010 int i,n, newq; | |
| 2011 const int maxlevel= s->max_qcoeff; | |
| 2012 const int minlevel= s->min_qcoeff; | |
| 2013 int largest=0, smallest=0; | |
| 2014 | |
| 2015 assert(s->adaptive_quant); | |
| 2016 | |
| 2017 for(n=0; n<6; n++){ | |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2018 if(s->mb_intra){ |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2019 i=1; //skip clipping of intra dc |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2020 //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
|
2021 }else |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2022 i=0; |
| 697 | 2023 |
| 2024 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
|
2025 const int j = s->intra_scantable.permutated[i]; |
| 697 | 2026 int level = block[n][j]; |
| 2027 if(largest < level) largest = level; | |
| 2028 if(smallest > level) smallest= level; | |
| 2029 } | |
| 2030 } | |
| 2031 | |
| 2032 for(newq=s->qscale+1; newq<32; newq++){ | |
| 2033 if( ROUNDED_DIV(smallest*s->qscale, newq) >= minlevel | |
| 2034 && ROUNDED_DIV(largest *s->qscale, newq) <= maxlevel) | |
| 2035 break; | |
| 2036 } | |
| 2037 | |
| 2038 if(s->out_format==FMT_H263){ | |
| 2039 /* h263 like formats cannot change qscale by more than 2 easiely */ | |
| 2040 if(s->avctx->qmin + 2 < newq) | |
| 2041 newq= s->avctx->qmin + 2; | |
| 2042 } | |
| 2043 | |
| 2044 for(n=0; n<6; n++){ | |
| 2045 requantize_coeffs(s, block[n], s->qscale, newq, n); | |
| 2046 clip_coeffs(s, block[n], s->block_last_index[n]); | |
| 2047 } | |
| 2048 | |
| 2049 s->dquant+= newq - s->qscale; | |
| 2050 s->qscale= newq; | |
| 2051 } | |
| 2052 #if 0 | |
| 2053 static int pix_vcmp16x8(UINT8 *s, int stride){ //FIXME move to dsputil & optimize | |
| 2054 int score=0; | |
| 2055 int x,y; | |
| 2056 | |
| 2057 for(y=0; y<7; y++){ | |
| 2058 for(x=0; x<16; x+=4){ | |
| 2059 score+= ABS(s[x ] - s[x +stride]) + ABS(s[x+1] - s[x+1+stride]) | |
| 2060 +ABS(s[x+2] - s[x+2+stride]) + ABS(s[x+3] - s[x+3+stride]); | |
| 2061 } | |
| 2062 s+= stride; | |
| 2063 } | |
| 2064 | |
| 2065 return score; | |
| 2066 } | |
| 2067 | |
| 2068 static int pix_diff_vcmp16x8(UINT8 *s1, UINT8*s2, int stride){ //FIXME move to dsputil & optimize | |
| 2069 int score=0; | |
| 2070 int x,y; | |
| 2071 | |
| 2072 for(y=0; y<7; y++){ | |
| 2073 for(x=0; x<16; x++){ | |
| 2074 score+= ABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]); | |
| 2075 } | |
| 2076 s1+= stride; | |
| 2077 s2+= stride; | |
| 2078 } | |
| 2079 | |
| 2080 return score; | |
| 2081 } | |
| 2082 #else | |
| 2083 #define SQ(a) ((a)*(a)) | |
| 2084 | |
| 2085 static int pix_vcmp16x8(UINT8 *s, int stride){ //FIXME move to dsputil & optimize | |
| 2086 int score=0; | |
| 2087 int x,y; | |
| 2088 | |
| 2089 for(y=0; y<7; y++){ | |
| 2090 for(x=0; x<16; x+=4){ | |
| 2091 score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride]) | |
| 2092 +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]); | |
| 2093 } | |
| 2094 s+= stride; | |
| 2095 } | |
| 2096 | |
| 2097 return score; | |
| 2098 } | |
| 2099 | |
| 2100 static int pix_diff_vcmp16x8(UINT8 *s1, UINT8*s2, int stride){ //FIXME move to dsputil & optimize | |
| 2101 int score=0; | |
| 2102 int x,y; | |
| 2103 | |
| 2104 for(y=0; y<7; y++){ | |
| 2105 for(x=0; x<16; x++){ | |
| 2106 score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]); | |
| 2107 } | |
| 2108 s1+= stride; | |
| 2109 s2+= stride; | |
| 2110 } | |
| 2111 | |
| 2112 return score; | |
| 2113 } | |
| 2114 | |
| 2115 #endif | |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2116 |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2117 void ff_draw_horiz_band(MpegEncContext *s){ |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2118 if ( s->avctx->draw_horiz_band |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2119 && (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
|
2120 UINT8 *src_ptr[3]; |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2121 int y, h, offset; |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2122 y = s->mb_y * 16; |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2123 h = s->height - y; |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2124 if (h > 16) |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2125 h = 16; |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2126 |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2127 if(s->pict_type==B_TYPE) |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2128 offset = 0; |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2129 else |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2130 offset = y * s->linesize; |
|
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 || (!s->has_b_frames)){ |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2133 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
|
2134 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
|
2135 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
|
2136 } else { |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2137 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
|
2138 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
|
2139 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
|
2140 } |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2141 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
|
2142 y, s->width, h); |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2143 } |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2144 } |
|
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2145 |
| 324 | 2146 static void encode_mb(MpegEncContext *s, int motion_x, int motion_y) |
| 294 | 2147 { |
| 2148 const int mb_x= s->mb_x; | |
| 2149 const int mb_y= s->mb_y; | |
| 2150 int i; | |
| 456 | 2151 int skip_dct[6]; |
| 697 | 2152 int dct_offset = s->linesize*8; //default for progressive frames |
| 2153 | |
| 456 | 2154 for(i=0; i<6; i++) skip_dct[i]=0; |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2155 |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2156 if(s->adaptive_quant){ |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2157 s->dquant= s->qscale_table[mb_x + mb_y*s->mb_width] - s->qscale; |
| 697 | 2158 |
| 2159 if(s->out_format==FMT_H263){ | |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2160 if (s->dquant> 2) s->dquant= 2; |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2161 else if(s->dquant<-2) s->dquant=-2; |
| 697 | 2162 } |
| 2163 | |
| 2164 if(s->codec_id==CODEC_ID_MPEG4){ | |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2165 if(!s->mb_intra){ |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2166 assert(s->dquant==0 || s->mv_type!=MV_TYPE_8X8); |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2167 |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2168 if(s->mv_dir&MV_DIRECT) |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2169 s->dquant=0; |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2170 } |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2171 } |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2172 s->qscale+= s->dquant; |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2173 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2174 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2175 } |
| 294 | 2176 |
| 324 | 2177 if (s->mb_intra) { |
| 2178 UINT8 *ptr; | |
| 697 | 2179 int wrap_y; |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2180 int emu=0; |
| 294 | 2181 |
| 697 | 2182 wrap_y = s->linesize; |
| 2183 ptr = s->new_picture[0] + (mb_y * 16 * wrap_y) + mb_x * 16; | |
| 2184 | |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2185 if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ |
| 697 | 2186 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
|
2187 ptr= s->edge_emu_buffer; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2188 emu=1; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2189 } |
| 697 | 2190 |
| 2191 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ | |
| 2192 int progressive_score, interlaced_score; | |
| 2193 | |
| 2194 progressive_score= pix_vcmp16x8(ptr, wrap_y ) + pix_vcmp16x8(ptr + wrap_y*8, wrap_y ); | |
| 2195 interlaced_score = pix_vcmp16x8(ptr, wrap_y*2) + pix_vcmp16x8(ptr + wrap_y , wrap_y*2); | |
| 2196 | |
| 2197 if(progressive_score > interlaced_score + 100){ | |
| 2198 s->interlaced_dct=1; | |
| 2199 | |
| 2200 dct_offset= wrap_y; | |
| 2201 wrap_y<<=1; | |
| 2202 }else | |
| 2203 s->interlaced_dct=0; | |
| 2204 } | |
| 2205 | |
| 2206 get_pixels(s->block[0], ptr , wrap_y); | |
| 2207 get_pixels(s->block[1], ptr + 8, wrap_y); | |
| 2208 get_pixels(s->block[2], ptr + dct_offset , wrap_y); | |
| 2209 get_pixels(s->block[3], ptr + dct_offset + 8, wrap_y); | |
| 294 | 2210 |
| 487 | 2211 if(s->flags&CODEC_FLAG_GRAY){ |
| 2212 skip_dct[4]= 1; | |
| 2213 skip_dct[5]= 1; | |
| 2214 }else{ | |
| 697 | 2215 int wrap_c = s->uvlinesize; |
| 2216 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
|
2217 if(emu){ |
| 697 | 2218 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
|
2219 ptr= s->edge_emu_buffer; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2220 } |
| 697 | 2221 get_pixels(s->block[4], ptr, wrap_c); |
| 294 | 2222 |
| 697 | 2223 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
|
2224 if(emu){ |
| 697 | 2225 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
|
2226 ptr= s->edge_emu_buffer; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2227 } |
| 697 | 2228 get_pixels(s->block[5], ptr, wrap_c); |
| 487 | 2229 } |
| 324 | 2230 }else{ |
| 651 | 2231 op_pixels_func (*op_pix)[4]; |
| 2232 qpel_mc_func (*op_qpix)[16]; | |
| 324 | 2233 UINT8 *dest_y, *dest_cb, *dest_cr; |
| 456 | 2234 UINT8 *ptr_y, *ptr_cb, *ptr_cr; |
| 2235 int wrap_y, wrap_c; | |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2236 int emu=0; |
| 294 | 2237 |
| 324 | 2238 dest_y = s->current_picture[0] + (mb_y * 16 * s->linesize ) + mb_x * 16; |
| 556 | 2239 dest_cb = s->current_picture[1] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; |
| 2240 dest_cr = s->current_picture[2] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; | |
| 456 | 2241 wrap_y = s->linesize; |
| 697 | 2242 wrap_c = s->uvlinesize; |
| 456 | 2243 ptr_y = s->new_picture[0] + (mb_y * 16 * wrap_y) + mb_x * 16; |
| 2244 ptr_cb = s->new_picture[1] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
| 2245 ptr_cr = s->new_picture[2] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
| 324 | 2246 |
| 327 | 2247 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
| 324 | 2248 op_pix = put_pixels_tab; |
| 651 | 2249 op_qpix= put_qpel_pixels_tab; |
| 295 | 2250 }else{ |
| 324 | 2251 op_pix = put_no_rnd_pixels_tab; |
| 651 | 2252 op_qpix= put_no_rnd_qpel_pixels_tab; |
| 324 | 2253 } |
| 295 | 2254 |
| 324 | 2255 if (s->mv_dir & MV_DIR_FORWARD) { |
| 2256 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); | |
| 651 | 2257 op_pix = avg_pixels_tab; |
| 2258 op_qpix= avg_qpel_pixels_tab; | |
| 324 | 2259 } |
| 2260 if (s->mv_dir & MV_DIR_BACKWARD) { | |
| 2261 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); | |
| 2262 } | |
| 295 | 2263 |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2264 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
|
2265 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
|
2266 ptr_y= s->edge_emu_buffer; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2267 emu=1; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2268 } |
| 697 | 2269 |
| 2270 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ | |
| 2271 int progressive_score, interlaced_score; | |
| 2272 | |
| 2273 progressive_score= pix_diff_vcmp16x8(ptr_y , dest_y , wrap_y ) | |
| 2274 + pix_diff_vcmp16x8(ptr_y + wrap_y*8, dest_y + wrap_y*8, wrap_y ); | |
| 2275 interlaced_score = pix_diff_vcmp16x8(ptr_y , dest_y , wrap_y*2) | |
| 2276 + pix_diff_vcmp16x8(ptr_y + wrap_y , dest_y + wrap_y , wrap_y*2); | |
| 2277 | |
| 2278 if(progressive_score > interlaced_score + 600){ | |
| 2279 s->interlaced_dct=1; | |
| 2280 | |
| 2281 dct_offset= wrap_y; | |
| 2282 wrap_y<<=1; | |
| 2283 }else | |
| 2284 s->interlaced_dct=0; | |
| 2285 } | |
| 2286 | |
| 456 | 2287 diff_pixels(s->block[0], ptr_y , dest_y , wrap_y); |
| 2288 diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y); | |
| 697 | 2289 diff_pixels(s->block[2], ptr_y + dct_offset , dest_y + dct_offset , wrap_y); |
| 2290 diff_pixels(s->block[3], ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y); | |
| 487 | 2291 |
| 2292 if(s->flags&CODEC_FLAG_GRAY){ | |
| 2293 skip_dct[4]= 1; | |
| 2294 skip_dct[5]= 1; | |
| 2295 }else{ | |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2296 if(emu){ |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2297 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
|
2298 ptr_cb= s->edge_emu_buffer; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
2299 } |
| 487 | 2300 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
|
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_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
|
2303 ptr_cr= 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[5], ptr_cr, dest_cr, wrap_c); |
| 2306 } | |
| 2307 | |
| 456 | 2308 /* pre quantization */ |
| 2309 if(s->mc_mb_var[s->mb_width*mb_y+ mb_x]<2*s->qscale*s->qscale){ | |
| 697 | 2310 //FIXME optimize |
| 456 | 2311 if(pix_abs8x8(ptr_y , dest_y , wrap_y) < 20*s->qscale) skip_dct[0]= 1; |
| 2312 if(pix_abs8x8(ptr_y + 8, dest_y + 8, wrap_y) < 20*s->qscale) skip_dct[1]= 1; | |
| 697 | 2313 if(pix_abs8x8(ptr_y +dct_offset , dest_y +dct_offset , wrap_y) < 20*s->qscale) skip_dct[2]= 1; |
| 2314 if(pix_abs8x8(ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y) < 20*s->qscale) skip_dct[3]= 1; | |
| 456 | 2315 if(pix_abs8x8(ptr_cb , dest_cb , wrap_y) < 20*s->qscale) skip_dct[4]= 1; |
| 2316 if(pix_abs8x8(ptr_cr , dest_cr , wrap_y) < 20*s->qscale) skip_dct[5]= 1; | |
| 2317 #if 0 | |
| 2318 { | |
| 2319 static int stat[7]; | |
| 2320 int num=0; | |
| 2321 for(i=0; i<6; i++) | |
| 2322 if(skip_dct[i]) num++; | |
| 2323 stat[num]++; | |
| 2324 | |
| 2325 if(s->mb_x==0 && s->mb_y==0){ | |
| 2326 for(i=0; i<7; i++){ | |
| 2327 printf("%6d %1d\n", stat[i], i); | |
| 2328 } | |
| 2329 } | |
| 2330 } | |
| 2331 #endif | |
| 2332 } | |
| 324 | 2333 |
| 294 | 2334 } |
| 2335 | |
| 2336 #if 0 | |
| 2337 { | |
| 2338 float adap_parm; | |
| 2339 | |
| 2340 adap_parm = ((s->avg_mb_var << 1) + s->mb_var[s->mb_width*mb_y+mb_x] + 1.0) / | |
| 2341 ((s->mb_var[s->mb_width*mb_y+mb_x] << 1) + s->avg_mb_var + 1.0); | |
| 2342 | |
| 2343 printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d", | |
| 2344 (s->mb_type[s->mb_width*mb_y+mb_x] > 0) ? 'I' : 'P', | |
| 2345 s->qscale, adap_parm, s->qscale*adap_parm, | |
| 2346 s->mb_var[s->mb_width*mb_y+mb_x], s->avg_mb_var); | |
| 2347 } | |
| 2348 #endif | |
| 2349 /* DCT & quantize */ | |
| 344 | 2350 if(s->out_format==FMT_MJPEG){ |
| 2351 for(i=0;i<6;i++) { | |
| 2352 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
|
2353 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
|
2354 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
| 344 | 2355 } |
| 2356 }else{ | |
| 2357 for(i=0;i<6;i++) { | |
| 456 | 2358 if(!skip_dct[i]){ |
| 2359 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
|
2360 s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); |
| 344 | 2361 // 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
|
2362 // 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
|
2363 // of improve it. Just INTRADC clipping deserves changes in quantizer |
| 456 | 2364 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
| 2365 }else | |
| 2366 s->block_last_index[i]= -1; | |
| 344 | 2367 } |
| 456 | 2368 if(s->luma_elim_threshold && !s->mb_intra) |
| 2369 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
|
2370 dct_single_coeff_elimination(s, i, s->luma_elim_threshold); |
| 456 | 2371 if(s->chroma_elim_threshold && !s->mb_intra) |
| 2372 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
|
2373 dct_single_coeff_elimination(s, i, s->chroma_elim_threshold); |
| 294 | 2374 } |
| 2375 | |
| 487 | 2376 if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){ |
| 2377 s->block_last_index[4]= | |
| 2378 s->block_last_index[5]= 0; | |
| 2379 s->block[4][0]= | |
| 2380 s->block[5][0]= 128; | |
| 2381 } | |
| 2382 | |
| 294 | 2383 /* huffman encode */ |
| 2384 switch(s->out_format) { | |
| 2385 case FMT_MPEG1: | |
| 2386 mpeg1_encode_mb(s, s->block, motion_x, motion_y); | |
| 2387 break; | |
| 2388 case FMT_H263: | |
| 2389 if (s->h263_msmpeg4) | |
| 2390 msmpeg4_encode_mb(s, s->block, motion_x, motion_y); | |
| 2391 else if(s->h263_pred) | |
| 2392 mpeg4_encode_mb(s, s->block, motion_x, motion_y); | |
| 2393 else | |
| 2394 h263_encode_mb(s, s->block, motion_x, motion_y); | |
| 2395 break; | |
| 2396 case FMT_MJPEG: | |
| 2397 mjpeg_encode_mb(s, s->block); | |
| 2398 break; | |
| 2399 } | |
| 2400 } | |
| 2401 | |
| 456 | 2402 void ff_copy_bits(PutBitContext *pb, UINT8 *src, int length) |
| 294 | 2403 { |
| 326 | 2404 int bytes= length>>4; |
| 2405 int bits= length&15; | |
| 2406 int i; | |
| 2407 | |
| 456 | 2408 if(length==0) return; |
| 2409 | |
| 326 | 2410 for(i=0; i<bytes; i++) put_bits(pb, 16, be2me_16(((uint16_t*)src)[i])); |
| 2411 put_bits(pb, bits, be2me_16(((uint16_t*)src)[i])>>(16-bits)); | |
| 0 | 2412 } |
| 2413 | |
| 456 | 2414 static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
| 326 | 2415 int i; |
| 2416 | |
| 2417 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
| 2418 | |
| 2419 /* mpeg1 */ | |
| 2420 d->mb_incr= s->mb_incr; | |
| 2421 for(i=0; i<3; i++) | |
| 2422 d->last_dc[i]= s->last_dc[i]; | |
| 2423 | |
| 2424 /* statistics */ | |
| 2425 d->mv_bits= s->mv_bits; | |
| 2426 d->i_tex_bits= s->i_tex_bits; | |
| 2427 d->p_tex_bits= s->p_tex_bits; | |
| 2428 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
|
2429 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
|
2430 d->b_count= s->b_count; |
| 326 | 2431 d->skip_count= s->skip_count; |
| 2432 d->misc_bits= s->misc_bits; | |
| 329 | 2433 d->last_bits= 0; |
| 327 | 2434 |
| 2435 d->mb_skiped= s->mb_skiped; | |
| 326 | 2436 } |
| 2437 | |
| 456 | 2438 static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
| 326 | 2439 int i; |
| 2440 | |
| 2441 memcpy(d->mv, s->mv, 2*4*2*sizeof(int)); | |
| 2442 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
| 2443 | |
| 2444 /* mpeg1 */ | |
| 2445 d->mb_incr= s->mb_incr; | |
| 2446 for(i=0; i<3; i++) | |
| 2447 d->last_dc[i]= s->last_dc[i]; | |
| 2448 | |
| 2449 /* statistics */ | |
| 2450 d->mv_bits= s->mv_bits; | |
| 2451 d->i_tex_bits= s->i_tex_bits; | |
| 2452 d->p_tex_bits= s->p_tex_bits; | |
| 2453 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
|
2454 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
|
2455 d->b_count= s->b_count; |
| 326 | 2456 d->skip_count= s->skip_count; |
| 2457 d->misc_bits= s->misc_bits; | |
| 2458 | |
| 2459 d->mb_intra= s->mb_intra; | |
| 327 | 2460 d->mb_skiped= s->mb_skiped; |
| 326 | 2461 d->mv_type= s->mv_type; |
| 2462 d->mv_dir= s->mv_dir; | |
| 2463 d->pb= s->pb; | |
| 456 | 2464 if(s->data_partitioning){ |
| 2465 d->pb2= s->pb2; | |
| 2466 d->tex_pb= s->tex_pb; | |
| 2467 } | |
| 326 | 2468 d->block= s->block; |
| 2469 for(i=0; i<6; i++) | |
| 2470 d->block_last_index[i]= s->block_last_index[i]; | |
| 755 | 2471 d->interlaced_dct= s->interlaced_dct; |
| 326 | 2472 } |
| 2473 | |
| 456 | 2474 static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type, |
| 2475 PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2], | |
| 2476 int *dmin, int *next_block, int motion_x, int motion_y) | |
| 2477 { | |
| 2478 int bits_count; | |
| 2479 | |
| 2480 copy_context_before_encode(s, backup, type); | |
| 2481 | |
| 2482 s->block= s->blocks[*next_block]; | |
| 2483 s->pb= pb[*next_block]; | |
| 2484 if(s->data_partitioning){ | |
| 2485 s->pb2 = pb2 [*next_block]; | |
| 2486 s->tex_pb= tex_pb[*next_block]; | |
| 2487 } | |
| 2488 | |
| 2489 encode_mb(s, motion_x, motion_y); | |
| 2490 | |
| 2491 bits_count= get_bit_count(&s->pb); | |
| 2492 if(s->data_partitioning){ | |
| 2493 bits_count+= get_bit_count(&s->pb2); | |
| 2494 bits_count+= get_bit_count(&s->tex_pb); | |
| 2495 } | |
| 2496 | |
| 2497 if(bits_count<*dmin){ | |
| 2498 *dmin= bits_count; | |
| 2499 *next_block^=1; | |
| 2500 | |
| 2501 copy_context_after_encode(best, s, type); | |
| 2502 } | |
| 2503 } | |
| 326 | 2504 |
| 0 | 2505 static void encode_picture(MpegEncContext *s, int picture_number) |
| 2506 { | |
| 766 | 2507 int mb_x, mb_y, pdif = 0; |
| 294 | 2508 int i; |
| 286 | 2509 int bits; |
| 326 | 2510 MpegEncContext best_s, backup_s; |
| 456 | 2511 UINT8 bit_buf[2][3000]; |
| 2512 UINT8 bit_buf2[2][3000]; | |
| 2513 UINT8 bit_buf_tex[2][3000]; | |
| 2514 PutBitContext pb[2], pb2[2], tex_pb[2]; | |
| 2515 | |
| 2516 for(i=0; i<2; i++){ | |
| 2517 init_put_bits(&pb [i], bit_buf [i], 3000, NULL, NULL); | |
| 2518 init_put_bits(&pb2 [i], bit_buf2 [i], 3000, NULL, NULL); | |
| 2519 init_put_bits(&tex_pb[i], bit_buf_tex[i], 3000, NULL, NULL); | |
| 2520 } | |
| 0 | 2521 |
| 2522 s->picture_number = picture_number; | |
| 268 | 2523 |
| 294 | 2524 s->block_wrap[0]= |
| 2525 s->block_wrap[1]= | |
| 2526 s->block_wrap[2]= | |
| 2527 s->block_wrap[3]= s->mb_width*2 + 2; | |
| 2528 s->block_wrap[4]= | |
| 2529 s->block_wrap[5]= s->mb_width + 2; | |
| 2530 | |
| 268 | 2531 /* Reset the average MB variance */ |
| 456 | 2532 s->mb_var_sum = 0; |
| 2533 s->mc_mb_var_sum = 0; | |
| 327 | 2534 |
| 2535 /* we need to initialize some time vars before we can encode b-frames */ | |
| 2536 if (s->h263_pred && !s->h263_msmpeg4) | |
| 2537 ff_set_mpeg4_time(s, s->picture_number); | |
| 2538 | |
| 608 | 2539 s->scene_change_score=0; |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2540 |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2541 s->qscale= (int)(s->frame_qscale + 0.5); //FIXME qscale / ... stuff for ME ratedistoration |
| 608 | 2542 |
| 268 | 2543 /* Estimate motion for every MB */ |
| 324 | 2544 if(s->pict_type != I_TYPE){ |
| 294 | 2545 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
| 2546 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; | |
| 2547 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
| 2548 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
| 2549 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
| 2550 for(mb_x=0; mb_x < s->mb_width; mb_x++) { | |
| 2551 s->mb_x = mb_x; | |
| 2552 s->mb_y = mb_y; | |
| 2553 s->block_index[0]+=2; | |
| 2554 s->block_index[1]+=2; | |
| 2555 s->block_index[2]+=2; | |
| 2556 s->block_index[3]+=2; | |
| 268 | 2557 |
| 294 | 2558 /* compute motion vector & mb_type and store in context */ |
| 324 | 2559 if(s->pict_type==B_TYPE) |
| 2560 ff_estimate_b_frame_motion(s, mb_x, mb_y); | |
| 2561 else | |
| 2562 ff_estimate_p_frame_motion(s, mb_x, mb_y); | |
| 294 | 2563 // s->mb_type[mb_y*s->mb_width + mb_x]=MB_TYPE_INTER; |
| 268 | 2564 } |
| 2565 } | |
| 294 | 2566 emms_c(); |
| 456 | 2567 }else /* if(s->pict_type == I_TYPE) */{ |
| 294 | 2568 /* I-Frame */ |
| 2569 //FIXME do we need to zero them? | |
| 2570 memset(s->motion_val[0], 0, sizeof(INT16)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2); | |
| 324 | 2571 memset(s->p_mv_table , 0, sizeof(INT16)*(s->mb_width+2)*(s->mb_height+2)*2); |
| 294 | 2572 memset(s->mb_type , MB_TYPE_INTRA, sizeof(UINT8)*s->mb_width*s->mb_height); |
| 612 | 2573 |
| 2574 if(!s->fixed_qscale){ | |
| 2575 /* finding spatial complexity for I-frame rate control */ | |
| 2576 for(mb_y=0; mb_y < s->mb_height; mb_y++) { | |
| 2577 for(mb_x=0; mb_x < s->mb_width; mb_x++) { | |
| 2578 int xx = mb_x * 16; | |
| 2579 int yy = mb_y * 16; | |
| 2580 uint8_t *pix = s->new_picture[0] + (yy * s->linesize) + xx; | |
| 2581 int varc; | |
| 2582 int sum = pix_sum(pix, s->linesize); | |
| 2583 | |
| 2584 sum= (sum+8)>>4; | |
| 2585 varc = (pix_norm1(pix, s->linesize) - sum*sum + 500 + 128)>>8; | |
| 2586 | |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2587 s->mb_var [s->mb_width * mb_y + mb_x] = varc; |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2588 s->mb_mean[s->mb_width * mb_y + mb_x] = (sum+7)>>4; |
| 612 | 2589 s->mb_var_sum += varc; |
| 2590 } | |
| 2591 } | |
| 2592 } | |
| 268 | 2593 } |
| 608 | 2594 if(s->scene_change_score > 0 && s->pict_type == P_TYPE){ |
| 271 | 2595 s->pict_type= I_TYPE; |
| 294 | 2596 memset(s->mb_type , MB_TYPE_INTRA, sizeof(UINT8)*s->mb_width*s->mb_height); |
| 329 | 2597 if(s->max_b_frames==0){ |
| 2598 s->input_pict_type= I_TYPE; | |
| 2599 s->input_picture_in_gop_number=0; | |
| 2600 } | |
| 612 | 2601 //printf("Scene change detected, encoding as I Frame %d %d\n", s->mb_var_sum, s->mc_mb_var_sum); |
| 271 | 2602 } |
| 324 | 2603 |
| 2604 if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) | |
| 2605 s->f_code= ff_get_best_fcode(s, s->p_mv_table, MB_TYPE_INTER); | |
| 2606 ff_fix_long_p_mvs(s); | |
| 2607 if(s->pict_type==B_TYPE){ | |
| 2608 s->f_code= ff_get_best_fcode(s, s->b_forw_mv_table, MB_TYPE_FORWARD); | |
| 2609 s->b_code= ff_get_best_fcode(s, s->b_back_mv_table, MB_TYPE_BACKWARD); | |
| 327 | 2610 |
| 2611 ff_fix_long_b_mvs(s, s->b_forw_mv_table, s->f_code, MB_TYPE_FORWARD); | |
| 2612 ff_fix_long_b_mvs(s, s->b_back_mv_table, s->b_code, MB_TYPE_BACKWARD); | |
| 2613 ff_fix_long_b_mvs(s, s->b_bidir_forw_mv_table, s->f_code, MB_TYPE_BIDIR); | |
| 2614 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
|
2615 } |
| 324 | 2616 |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2617 if (s->fixed_qscale) |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2618 s->frame_qscale = s->avctx->quality; |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2619 else |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2620 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
|
2621 |
| 695 | 2622 if(s->adaptive_quant){ |
| 2623 switch(s->codec_id){ | |
| 2624 case CODEC_ID_MPEG4: | |
| 2625 ff_clean_mpeg4_qscales(s); | |
| 2626 break; | |
| 2627 case CODEC_ID_H263: | |
| 2628 case CODEC_ID_H263P: | |
| 2629 ff_clean_h263_qscales(s); | |
| 2630 break; | |
| 2631 } | |
| 2632 | |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2633 s->qscale= s->qscale_table[0]; |
| 695 | 2634 }else |
|
690
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2635 s->qscale= (int)(s->frame_qscale + 0.5); |
|
a1c69cb685b3
adaptive quantization (lumi/temporal & spatial complexity masking)
michaelni
parents:
673
diff
changeset
|
2636 |
| 0 | 2637 if (s->out_format == FMT_MJPEG) { |
| 2638 /* 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
|
2639 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
|
2640 for(i=1;i<64;i++){ |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2641 int j= s->idct_permutation[i]; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2642 |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
2643 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
|
2644 } |
|
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
|
2645 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
|
2646 s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias, 8, 8); |
| 0 | 2647 } |
| 2648 | |
| 286 | 2649 s->last_bits= get_bit_count(&s->pb); |
| 0 | 2650 switch(s->out_format) { |
| 2651 case FMT_MJPEG: | |
| 2652 mjpeg_picture_header(s); | |
| 2653 break; | |
| 2654 case FMT_H263: | |
| 2655 if (s->h263_msmpeg4) | |
| 2656 msmpeg4_encode_picture_header(s, picture_number); | |
| 2657 else if (s->h263_pred) | |
| 2658 mpeg4_encode_picture_header(s, picture_number); | |
| 2659 else if (s->h263_rv10) | |
| 2660 rv10_encode_picture_header(s, picture_number); | |
| 2661 else | |
| 2662 h263_encode_picture_header(s, picture_number); | |
| 2663 break; | |
| 2664 case FMT_MPEG1: | |
| 2665 mpeg1_encode_picture_header(s, picture_number); | |
| 2666 break; | |
| 2667 } | |
| 286 | 2668 bits= get_bit_count(&s->pb); |
| 2669 s->header_bits= bits - s->last_bits; | |
| 2670 s->last_bits= bits; | |
| 2671 s->mv_bits=0; | |
| 2672 s->misc_bits=0; | |
| 2673 s->i_tex_bits=0; | |
| 2674 s->p_tex_bits=0; | |
| 2675 s->i_count=0; | |
|
656
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
2676 s->f_count=0; |
|
e47fa3e3f2d5
statistics for forw & back p-MBs instead of just one counter for both
michaelni
parents:
652
diff
changeset
|
2677 s->b_count=0; |
| 286 | 2678 s->skip_count=0; |
| 2679 | |
| 0 | 2680 /* init last dc values */ |
| 2681 /* note: quant matrix value (8) is implied here */ | |
| 2682 s->last_dc[0] = 128; | |
| 2683 s->last_dc[1] = 128; | |
| 2684 s->last_dc[2] = 128; | |
| 2685 s->mb_incr = 1; | |
| 2686 s->last_mv[0][0][0] = 0; | |
| 2687 s->last_mv[0][0][1] = 0; | |
| 2688 | |
| 766 | 2689 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
|
2690 s->gob_index = ff_h263_get_gob_height(s); |
| 456 | 2691 |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2692 if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame) |
| 456 | 2693 ff_mpeg4_init_partitions(s); |
| 2694 | |
| 2695 s->resync_mb_x=0; | |
| 2696 s->resync_mb_y=0; | |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2697 s->first_slice_line = 1; |
| 766 | 2698 s->ptr_lastgob = s->pb.buf; |
| 2699 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
|
2700 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
| 499 | 2701 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; |
| 2702 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
|
2703 |
| 266 | 2704 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; |
| 2705 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
| 2706 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
| 2707 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
| 2708 s->block_index[4]= s->block_wrap[4]*(mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2); | |
| 2709 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
|
2710 for(mb_x=0; mb_x < s->mb_width; mb_x++) { |
| 327 | 2711 const int mb_type= s->mb_type[mb_y * s->mb_width + mb_x]; |
| 2712 const int xy= (mb_y+1) * (s->mb_width+2) + mb_x + 1; | |
| 456 | 2713 // int d; |
| 294 | 2714 int dmin=10000000; |
| 0 | 2715 |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
2716 s->mb_x = mb_x; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
2717 s->mb_y = mb_y; |
| 266 | 2718 s->block_index[0]+=2; |
| 2719 s->block_index[1]+=2; | |
| 2720 s->block_index[2]+=2; | |
| 2721 s->block_index[3]+=2; | |
| 2722 s->block_index[4]++; | |
| 2723 s->block_index[5]++; | |
| 456 | 2724 |
| 766 | 2725 /* write gob / video packet header */ |
| 2726 if(s->rtp_mode){ | |
| 2727 int current_packet_size, is_gob_start; | |
| 2728 | |
| 2729 current_packet_size= pbBufPtr(&s->pb) - s->ptr_lastgob; | |
| 2730 is_gob_start=0; | |
| 2731 | |
| 2732 if(s->codec_id==CODEC_ID_MPEG4){ | |
| 2733 if(current_packet_size + s->mb_line_avgsize/s->mb_width >= s->rtp_payload_size | |
| 2734 && s->mb_y + s->mb_x>0){ | |
| 2735 | |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2736 if(s->partitioned_frame){ |
| 456 | 2737 ff_mpeg4_merge_partitions(s); |
| 2738 ff_mpeg4_init_partitions(s); | |
| 2739 } | |
| 2740 ff_mpeg4_encode_video_packet_header(s); | |
| 2741 | |
| 2742 if(s->flags&CODEC_FLAG_PASS1){ | |
| 2743 int bits= get_bit_count(&s->pb); | |
| 2744 s->misc_bits+= bits - s->last_bits; | |
| 2745 s->last_bits= bits; | |
| 2746 } | |
| 2747 ff_mpeg4_clean_buffers(s); | |
| 766 | 2748 is_gob_start=1; |
| 456 | 2749 } |
| 766 | 2750 }else{ |
| 2751 if(current_packet_size + s->mb_line_avgsize*s->gob_index >= s->rtp_payload_size | |
| 2752 && s->mb_x==0 && s->mb_y>0 && s->mb_y%s->gob_index==0){ | |
| 2753 | |
| 2754 h263_encode_gob_header(s, mb_y); | |
| 2755 is_gob_start=1; | |
| 2756 } | |
| 2757 } | |
| 2758 | |
| 2759 if(is_gob_start){ | |
| 456 | 2760 s->ptr_lastgob = pbBufPtr(&s->pb); |
| 2761 s->first_slice_line=1; | |
| 2762 s->resync_mb_x=mb_x; | |
| 2763 s->resync_mb_y=mb_y; | |
| 2764 } | |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2765 } |
| 456 | 2766 |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2767 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
|
2768 && 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
|
2769 s->first_slice_line=0; |
| 456 | 2770 } |
| 2771 | |
| 294 | 2772 if(mb_type & (mb_type-1)){ // more than 1 MB type possible |
| 327 | 2773 int next_block=0; |
| 456 | 2774 int pb_bits_count, pb2_bits_count, tex_pb_bits_count; |
| 326 | 2775 |
| 2776 copy_context_before_encode(&backup_s, s, -1); | |
| 456 | 2777 backup_s.pb= s->pb; |
| 2778 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
|
2779 best_s.partitioned_frame= s->partitioned_frame; |
| 456 | 2780 if(s->data_partitioning){ |
| 2781 backup_s.pb2= s->pb2; | |
| 2782 backup_s.tex_pb= s->tex_pb; | |
| 2783 } | |
| 326 | 2784 |
| 294 | 2785 if(mb_type&MB_TYPE_INTER){ |
| 327 | 2786 s->mv_dir = MV_DIR_FORWARD; |
| 295 | 2787 s->mv_type = MV_TYPE_16X16; |
| 294 | 2788 s->mb_intra= 0; |
| 324 | 2789 s->mv[0][0][0] = s->p_mv_table[xy][0]; |
| 2790 s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
| 456 | 2791 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER, pb, pb2, tex_pb, |
| 2792 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); | |
| 0 | 2793 } |
| 326 | 2794 if(mb_type&MB_TYPE_INTER4V){ |
| 327 | 2795 s->mv_dir = MV_DIR_FORWARD; |
| 295 | 2796 s->mv_type = MV_TYPE_8X8; |
| 2797 s->mb_intra= 0; | |
| 2798 for(i=0; i<4; i++){ | |
| 2799 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; | |
| 2800 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; | |
| 2801 } | |
| 456 | 2802 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER4V, pb, pb2, tex_pb, |
| 2803 &dmin, &next_block, 0, 0); | |
| 327 | 2804 } |
| 2805 if(mb_type&MB_TYPE_FORWARD){ | |
| 2806 s->mv_dir = MV_DIR_FORWARD; | |
| 2807 s->mv_type = MV_TYPE_16X16; | |
| 2808 s->mb_intra= 0; | |
| 2809 s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
| 2810 s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
| 456 | 2811 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_FORWARD, pb, pb2, tex_pb, |
| 2812 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); | |
| 327 | 2813 } |
| 2814 if(mb_type&MB_TYPE_BACKWARD){ | |
| 2815 s->mv_dir = MV_DIR_BACKWARD; | |
| 2816 s->mv_type = MV_TYPE_16X16; | |
| 2817 s->mb_intra= 0; | |
| 2818 s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
| 2819 s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
| 456 | 2820 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BACKWARD, pb, pb2, tex_pb, |
| 2821 &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); | |
| 327 | 2822 } |
| 2823 if(mb_type&MB_TYPE_BIDIR){ | |
| 2824 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
| 2825 s->mv_type = MV_TYPE_16X16; | |
| 2826 s->mb_intra= 0; | |
| 2827 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
| 2828 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
| 2829 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
| 2830 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
| 456 | 2831 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BIDIR, pb, pb2, tex_pb, |
| 2832 &dmin, &next_block, 0, 0); | |
| 327 | 2833 } |
| 2834 if(mb_type&MB_TYPE_DIRECT){ | |
| 2835 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
| 2836 s->mv_type = MV_TYPE_16X16; //FIXME | |
| 2837 s->mb_intra= 0; | |
| 2838 s->mv[0][0][0] = s->b_direct_forw_mv_table[xy][0]; | |
| 2839 s->mv[0][0][1] = s->b_direct_forw_mv_table[xy][1]; | |
| 2840 s->mv[1][0][0] = s->b_direct_back_mv_table[xy][0]; | |
| 2841 s->mv[1][0][1] = s->b_direct_back_mv_table[xy][1]; | |
| 456 | 2842 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_DIRECT, pb, pb2, tex_pb, |
| 2843 &dmin, &next_block, s->b_direct_mv_table[xy][0], s->b_direct_mv_table[xy][1]); | |
| 295 | 2844 } |
| 294 | 2845 if(mb_type&MB_TYPE_INTRA){ |
| 327 | 2846 s->mv_dir = MV_DIR_FORWARD; |
| 295 | 2847 s->mv_type = MV_TYPE_16X16; |
| 294 | 2848 s->mb_intra= 1; |
| 2849 s->mv[0][0][0] = 0; | |
| 2850 s->mv[0][0][1] = 0; | |
| 456 | 2851 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTRA, pb, pb2, tex_pb, |
| 2852 &dmin, &next_block, 0, 0); | |
| 326 | 2853 /* force cleaning of ac/dc pred stuff if needed ... */ |
| 2854 if(s->h263_pred || s->h263_aic) | |
| 2855 s->mbintra_table[mb_x + mb_y*s->mb_width]=1; | |
| 295 | 2856 } |
| 326 | 2857 copy_context_after_encode(s, &best_s, -1); |
| 456 | 2858 |
| 2859 pb_bits_count= get_bit_count(&s->pb); | |
| 2860 flush_put_bits(&s->pb); | |
| 2861 ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); | |
| 2862 s->pb= backup_s.pb; | |
| 2863 | |
| 2864 if(s->data_partitioning){ | |
| 2865 pb2_bits_count= get_bit_count(&s->pb2); | |
| 2866 flush_put_bits(&s->pb2); | |
| 2867 ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); | |
| 2868 s->pb2= backup_s.pb2; | |
| 2869 | |
| 2870 tex_pb_bits_count= get_bit_count(&s->tex_pb); | |
| 2871 flush_put_bits(&s->tex_pb); | |
| 2872 ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); | |
| 2873 s->tex_pb= backup_s.tex_pb; | |
| 2874 } | |
| 329 | 2875 s->last_bits= get_bit_count(&s->pb); |
| 294 | 2876 } else { |
| 324 | 2877 int motion_x, motion_y; |
| 2878 s->mv_type=MV_TYPE_16X16; | |
| 294 | 2879 // only one MB-Type possible |
| 327 | 2880 switch(mb_type){ |
| 2881 case MB_TYPE_INTRA: | |
| 324 | 2882 s->mv_dir = MV_DIR_FORWARD; |
| 294 | 2883 s->mb_intra= 1; |
| 324 | 2884 motion_x= s->mv[0][0][0] = 0; |
| 2885 motion_y= s->mv[0][0][1] = 0; | |
| 327 | 2886 break; |
| 2887 case MB_TYPE_INTER: | |
| 324 | 2888 s->mv_dir = MV_DIR_FORWARD; |
| 2889 s->mb_intra= 0; | |
| 2890 motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; | |
| 2891 motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
| 327 | 2892 break; |
| 456 | 2893 case MB_TYPE_INTER4V: |
| 2894 s->mv_dir = MV_DIR_FORWARD; | |
| 2895 s->mv_type = MV_TYPE_8X8; | |
| 2896 s->mb_intra= 0; | |
| 2897 for(i=0; i<4; i++){ | |
| 2898 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; | |
| 2899 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; | |
| 2900 } | |
| 2901 motion_x= motion_y= 0; | |
| 2902 break; | |
| 327 | 2903 case MB_TYPE_DIRECT: |
| 324 | 2904 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
| 2905 s->mb_intra= 0; | |
| 327 | 2906 motion_x=s->b_direct_mv_table[xy][0]; |
| 2907 motion_y=s->b_direct_mv_table[xy][1]; | |
| 2908 s->mv[0][0][0] = s->b_direct_forw_mv_table[xy][0]; | |
| 2909 s->mv[0][0][1] = s->b_direct_forw_mv_table[xy][1]; | |
| 2910 s->mv[1][0][0] = s->b_direct_back_mv_table[xy][0]; | |
| 2911 s->mv[1][0][1] = s->b_direct_back_mv_table[xy][1]; | |
| 2912 break; | |
| 2913 case MB_TYPE_BIDIR: | |
| 324 | 2914 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; |
| 294 | 2915 s->mb_intra= 0; |
| 324 | 2916 motion_x=0; |
| 2917 motion_y=0; | |
| 2918 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
| 2919 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
| 2920 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
| 2921 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
| 327 | 2922 break; |
| 2923 case MB_TYPE_BACKWARD: | |
| 324 | 2924 s->mv_dir = MV_DIR_BACKWARD; |
| 2925 s->mb_intra= 0; | |
| 2926 motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
| 2927 motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
| 327 | 2928 break; |
| 2929 case MB_TYPE_FORWARD: | |
| 324 | 2930 s->mv_dir = MV_DIR_FORWARD; |
| 2931 s->mb_intra= 0; | |
| 2932 motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
| 2933 motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
| 2934 // printf(" %d %d ", motion_x, motion_y); | |
| 327 | 2935 break; |
| 2936 default: | |
| 324 | 2937 motion_x=motion_y=0; //gcc warning fix |
| 2938 printf("illegal MB type\n"); | |
| 294 | 2939 } |
| 324 | 2940 encode_mb(s, motion_x, motion_y); |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2941 } |
| 327 | 2942 /* clean the MV table in IPS frames for direct mode in B frames */ |
| 2943 if(s->mb_intra /* && I,P,S_TYPE */){ | |
| 2944 s->p_mv_table[xy][0]=0; | |
| 2945 s->p_mv_table[xy][1]=0; | |
| 2946 } | |
| 0 | 2947 |
|
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
|
2948 MPV_decode_mb(s, s->block); |
| 456 | 2949 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_width, get_bit_count(&s->pb)); |
| 0 | 2950 } |
|
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
|
2951 |
|
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
|
2952 |
| 766 | 2953 /* Obtain average mb_row size for RTP */ |
| 231 | 2954 if (s->rtp_mode) { |
| 766 | 2955 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
|
2956 s->mb_line_avgsize = pbBufPtr(&s->pb) - s->ptr_last_mb_line; |
| 766 | 2957 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
|
2958 s->mb_line_avgsize = (s->mb_line_avgsize + pbBufPtr(&s->pb) - s->ptr_last_mb_line) >> 1; |
| 231 | 2959 } |
| 766 | 2960 s->ptr_last_mb_line = pbBufPtr(&s->pb); |
| 231 | 2961 } |
| 0 | 2962 } |
| 294 | 2963 emms_c(); |
| 286 | 2964 |
|
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
731
diff
changeset
|
2965 if(s->codec_id==CODEC_ID_MPEG4 && s->partitioned_frame) |
| 456 | 2966 ff_mpeg4_merge_partitions(s); |
| 2967 | |
| 2968 if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE) | |
| 208 | 2969 msmpeg4_encode_ext_header(s); |
| 2970 | |
| 456 | 2971 if(s->codec_id==CODEC_ID_MPEG4) |
| 2972 ff_mpeg4_stuffing(&s->pb); | |
| 2973 | |
| 162 | 2974 //if (s->gob_number) |
| 2975 // fprintf(stderr,"\nNumber of GOB: %d", s->gob_number); | |
| 231 | 2976 |
| 2977 /* Send the last GOB if RTP */ | |
| 2978 if (s->rtp_mode) { | |
| 2979 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
|
2980 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
| 231 | 2981 /* Call the RTP callback to send the last GOB */ |
| 2982 if (s->rtp_callback) | |
| 2983 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
|
2984 s->ptr_lastgob = pbBufPtr(&s->pb); |
| 231 | 2985 //fprintf(stderr,"\nGOB: %2d size: %d (last)", s->gob_number, pdif); |
| 2986 } | |
| 0 | 2987 } |
| 2988 | |
| 220 | 2989 static int dct_quantize_c(MpegEncContext *s, |
| 0 | 2990 DCTELEM *block, int n, |
| 344 | 2991 int qscale, int *overflow) |
| 0 | 2992 { |
| 2993 int i, j, level, last_non_zero, q; | |
| 2994 const int *qmat; | |
| 764 | 2995 const UINT8 *scantable= s->intra_scantable.scantable; |
| 344 | 2996 int bias; |
| 2997 int max=0; | |
| 2998 unsigned int threshold1, threshold2; | |
| 456 | 2999 |
|
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
|
3000 s->fdct (block); |
| 0 | 3001 |
| 3002 if (s->mb_intra) { | |
|
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3003 if (!s->h263_aic) { |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3004 if (n < 4) |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3005 q = s->y_dc_scale; |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3006 else |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3007 q = s->c_dc_scale; |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3008 q = q << 3; |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3009 } else |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3010 /* 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
|
3011 q = 1 << 3; |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
3012 |
| 0 | 3013 /* note: block[0] is assumed to be positive */ |
| 3014 block[0] = (block[0] + (q >> 1)) / q; | |
| 3015 i = 1; | |
| 3016 last_non_zero = 0; | |
| 344 | 3017 qmat = s->q_intra_matrix[qscale]; |
| 635 | 3018 bias= s->intra_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); |
| 0 | 3019 } else { |
| 3020 i = 0; | |
| 3021 last_non_zero = -1; | |
| 344 | 3022 qmat = s->q_inter_matrix[qscale]; |
| 635 | 3023 bias= s->inter_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); |
| 0 | 3024 } |
| 635 | 3025 threshold1= (1<<QMAT_SHIFT) - bias - 1; |
| 3026 threshold2= (threshold1<<1); | |
| 0 | 3027 |
| 3028 for(;i<64;i++) { | |
| 764 | 3029 j = scantable[i]; |
| 0 | 3030 level = block[j]; |
| 3031 level = level * qmat[j]; | |
| 344 | 3032 |
| 3033 // if( bias+level >= (1<<(QMAT_SHIFT - 3)) | |
| 3034 // || bias-level >= (1<<(QMAT_SHIFT - 3))){ | |
| 3035 if(((unsigned)(level+threshold1))>threshold2){ | |
| 3036 if(level>0){ | |
| 635 | 3037 level= (bias + level)>>QMAT_SHIFT; |
| 344 | 3038 block[j]= level; |
| 3039 }else{ | |
| 635 | 3040 level= (bias - level)>>QMAT_SHIFT; |
| 344 | 3041 block[j]= -level; |
| 0 | 3042 } |
| 344 | 3043 max |=level; |
| 0 | 3044 last_non_zero = i; |
| 344 | 3045 }else{ |
| 3046 block[j]=0; | |
| 0 | 3047 } |
| 3048 } | |
| 344 | 3049 *overflow= s->max_qcoeff < max; //overflow might have happend |
| 3050 | |
| 764 | 3051 /* we need this permutation so that we correct the IDCT, we only permute the !=0 elements */ |
| 3052 ff_block_permute(block, s->idct_permutation, scantable, last_non_zero); | |
| 3053 | |
| 0 | 3054 return last_non_zero; |
| 3055 } | |
| 3056 | |
|
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
|
3057 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
|
3058 DCTELEM *block, int n, int qscale) |
| 0 | 3059 { |
| 200 | 3060 int i, level, nCoeffs; |
| 0 | 3061 const UINT16 *quant_matrix; |
| 3062 | |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3063 nCoeffs= s->block_last_index[n]; |
| 200 | 3064 |
| 0 | 3065 if (s->mb_intra) { |
| 3066 if (n < 4) | |
| 3067 block[0] = block[0] * s->y_dc_scale; | |
| 3068 else | |
| 3069 block[0] = block[0] * s->c_dc_scale; | |
| 3070 /* XXX: only mpeg1 */ | |
| 3071 quant_matrix = s->intra_matrix; | |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3072 for(i=1;i<=nCoeffs;i++) { |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3073 int j= s->intra_scantable.permutated[i]; |
| 200 | 3074 level = block[j]; |
| 0 | 3075 if (level) { |
| 3076 if (level < 0) { | |
| 3077 level = -level; | |
| 200 | 3078 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
| 0 | 3079 level = (level - 1) | 1; |
| 3080 level = -level; | |
| 3081 } else { | |
| 200 | 3082 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
| 0 | 3083 level = (level - 1) | 1; |
| 3084 } | |
| 3085 #ifdef PARANOID | |
| 3086 if (level < -2048 || level > 2047) | |
| 3087 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 3088 #endif | |
| 200 | 3089 block[j] = level; |
| 0 | 3090 } |
| 3091 } | |
| 3092 } else { | |
| 3093 i = 0; | |
| 344 | 3094 quant_matrix = s->inter_matrix; |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3095 for(;i<=nCoeffs;i++) { |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3096 int j= s->intra_scantable.permutated[i]; |
| 200 | 3097 level = block[j]; |
| 0 | 3098 if (level) { |
| 3099 if (level < 0) { | |
| 3100 level = -level; | |
| 3101 level = (((level << 1) + 1) * qscale * | |
| 200 | 3102 ((int) (quant_matrix[j]))) >> 4; |
| 0 | 3103 level = (level - 1) | 1; |
| 3104 level = -level; | |
| 3105 } else { | |
| 3106 level = (((level << 1) + 1) * qscale * | |
| 200 | 3107 ((int) (quant_matrix[j]))) >> 4; |
| 0 | 3108 level = (level - 1) | 1; |
| 3109 } | |
| 3110 #ifdef PARANOID | |
| 3111 if (level < -2048 || level > 2047) | |
| 3112 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 3113 #endif | |
| 200 | 3114 block[j] = level; |
| 0 | 3115 } |
| 3116 } | |
| 3117 } | |
| 3118 } | |
|
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
|
3119 |
| 325 | 3120 static void dct_unquantize_mpeg2_c(MpegEncContext *s, |
| 3121 DCTELEM *block, int n, int qscale) | |
| 3122 { | |
| 3123 int i, level, nCoeffs; | |
| 3124 const UINT16 *quant_matrix; | |
| 3125 | |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3126 if(s->alternate_scan) nCoeffs= 63; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3127 else nCoeffs= s->block_last_index[n]; |
| 325 | 3128 |
| 3129 if (s->mb_intra) { | |
| 3130 if (n < 4) | |
| 3131 block[0] = block[0] * s->y_dc_scale; | |
| 3132 else | |
| 3133 block[0] = block[0] * s->c_dc_scale; | |
| 3134 quant_matrix = s->intra_matrix; | |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3135 for(i=1;i<=nCoeffs;i++) { |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3136 int j= s->intra_scantable.permutated[i]; |
| 325 | 3137 level = block[j]; |
| 3138 if (level) { | |
| 3139 if (level < 0) { | |
| 3140 level = -level; | |
| 3141 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 3142 level = -level; | |
| 3143 } else { | |
| 3144 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 3145 } | |
| 3146 #ifdef PARANOID | |
| 3147 if (level < -2048 || level > 2047) | |
| 3148 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 3149 #endif | |
| 3150 block[j] = level; | |
| 3151 } | |
| 3152 } | |
| 3153 } else { | |
| 3154 int sum=-1; | |
| 3155 i = 0; | |
| 344 | 3156 quant_matrix = s->inter_matrix; |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3157 for(;i<=nCoeffs;i++) { |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3158 int j= s->intra_scantable.permutated[i]; |
| 325 | 3159 level = block[j]; |
| 3160 if (level) { | |
| 3161 if (level < 0) { | |
| 3162 level = -level; | |
| 3163 level = (((level << 1) + 1) * qscale * | |
| 3164 ((int) (quant_matrix[j]))) >> 4; | |
| 3165 level = -level; | |
| 3166 } else { | |
| 3167 level = (((level << 1) + 1) * qscale * | |
| 3168 ((int) (quant_matrix[j]))) >> 4; | |
| 3169 } | |
| 3170 #ifdef PARANOID | |
| 3171 if (level < -2048 || level > 2047) | |
| 3172 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 3173 #endif | |
| 3174 block[j] = level; | |
| 3175 sum+=level; | |
| 3176 } | |
| 3177 } | |
| 3178 block[63]^=sum&1; | |
| 3179 } | |
| 3180 } | |
| 3181 | |
| 3182 | |
|
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
|
3183 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
|
3184 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
|
3185 { |
|
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
|
3186 int i, level, qmul, qadd; |
| 200 | 3187 int nCoeffs; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3188 |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3189 assert(s->block_last_index[n]>=0); |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3190 |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3191 qadd = (qscale - 1) | 1; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3192 qmul = qscale << 1; |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3193 |
|
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
|
3194 if (s->mb_intra) { |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3195 if (!s->h263_aic) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3196 if (n < 4) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3197 block[0] = block[0] * s->y_dc_scale; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3198 else |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
3199 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
|
3200 }else |
|
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3201 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
|
3202 i = 1; |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3203 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
|
3204 } 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
|
3205 i = 0; |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3206 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
|
3207 } |
|
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
|
3208 |
|
706
e65798d228ea
idct permutation cleanup, idct can be selected per context now
michaelni
parents:
704
diff
changeset
|
3209 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
|
3210 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
|
3211 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
|
3212 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
|
3213 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
|
3214 } 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
|
3215 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
|
3216 } |
|
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 #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
|
3218 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
|
3219 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
|
3220 #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
|
3221 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
|
3222 } |
|
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 } |
|
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 } |
| 0 | 3225 |
| 3226 AVCodec mpeg1video_encoder = { | |
| 3227 "mpeg1video", | |
| 3228 CODEC_TYPE_VIDEO, | |
| 3229 CODEC_ID_MPEG1VIDEO, | |
| 3230 sizeof(MpegEncContext), | |
| 3231 MPV_encode_init, | |
| 3232 MPV_encode_picture, | |
| 3233 MPV_encode_end, | |
| 3234 }; | |
| 3235 | |
| 3236 AVCodec h263_encoder = { | |
| 3237 "h263", | |
| 3238 CODEC_TYPE_VIDEO, | |
| 3239 CODEC_ID_H263, | |
| 3240 sizeof(MpegEncContext), | |
| 3241 MPV_encode_init, | |
| 3242 MPV_encode_picture, | |
| 3243 MPV_encode_end, | |
| 3244 }; | |
| 3245 | |
| 3246 AVCodec h263p_encoder = { | |
| 3247 "h263p", | |
| 3248 CODEC_TYPE_VIDEO, | |
| 3249 CODEC_ID_H263P, | |
| 3250 sizeof(MpegEncContext), | |
| 3251 MPV_encode_init, | |
| 3252 MPV_encode_picture, | |
| 3253 MPV_encode_end, | |
| 3254 }; | |
| 3255 | |
| 3256 AVCodec rv10_encoder = { | |
| 3257 "rv10", | |
| 3258 CODEC_TYPE_VIDEO, | |
| 3259 CODEC_ID_RV10, | |
| 3260 sizeof(MpegEncContext), | |
| 3261 MPV_encode_init, | |
| 3262 MPV_encode_picture, | |
| 3263 MPV_encode_end, | |
| 3264 }; | |
| 3265 | |
| 3266 AVCodec mjpeg_encoder = { | |
| 3267 "mjpeg", | |
| 3268 CODEC_TYPE_VIDEO, | |
| 3269 CODEC_ID_MJPEG, | |
| 3270 sizeof(MpegEncContext), | |
| 3271 MPV_encode_init, | |
| 3272 MPV_encode_picture, | |
| 3273 MPV_encode_end, | |
| 3274 }; | |
| 3275 | |
| 71 | 3276 AVCodec mpeg4_encoder = { |
| 3277 "mpeg4", | |
| 0 | 3278 CODEC_TYPE_VIDEO, |
| 71 | 3279 CODEC_ID_MPEG4, |
| 0 | 3280 sizeof(MpegEncContext), |
| 3281 MPV_encode_init, | |
| 3282 MPV_encode_picture, | |
| 3283 MPV_encode_end, | |
| 3284 }; | |
| 3285 | |
| 307 | 3286 AVCodec msmpeg4v1_encoder = { |
| 3287 "msmpeg4v1", | |
| 0 | 3288 CODEC_TYPE_VIDEO, |
| 307 | 3289 CODEC_ID_MSMPEG4V1, |
| 0 | 3290 sizeof(MpegEncContext), |
| 3291 MPV_encode_init, | |
| 3292 MPV_encode_picture, | |
| 3293 MPV_encode_end, | |
| 3294 }; | |
| 307 | 3295 |
| 3296 AVCodec msmpeg4v2_encoder = { | |
| 3297 "msmpeg4v2", | |
| 3298 CODEC_TYPE_VIDEO, | |
| 3299 CODEC_ID_MSMPEG4V2, | |
| 3300 sizeof(MpegEncContext), | |
| 3301 MPV_encode_init, | |
| 3302 MPV_encode_picture, | |
| 3303 MPV_encode_end, | |
| 3304 }; | |
| 3305 | |
| 3306 AVCodec msmpeg4v3_encoder = { | |
| 3307 "msmpeg4", | |
| 3308 CODEC_TYPE_VIDEO, | |
| 3309 CODEC_ID_MSMPEG4V3, | |
| 3310 sizeof(MpegEncContext), | |
| 3311 MPV_encode_init, | |
| 3312 MPV_encode_picture, | |
| 3313 MPV_encode_end, | |
| 3314 }; | |
| 499 | 3315 |
| 3316 AVCodec wmv1_encoder = { | |
| 3317 "wmv1", | |
| 3318 CODEC_TYPE_VIDEO, | |
| 3319 CODEC_ID_WMV1, | |
| 3320 sizeof(MpegEncContext), | |
| 3321 MPV_encode_init, | |
| 3322 MPV_encode_picture, | |
| 3323 MPV_encode_end, | |
| 3324 }; | |
| 3325 | |
| 3326 AVCodec wmv2_encoder = { | |
| 3327 "wmv2", | |
| 3328 CODEC_TYPE_VIDEO, | |
| 3329 CODEC_ID_WMV2, | |
| 3330 sizeof(MpegEncContext), | |
| 3331 MPV_encode_init, | |
| 3332 MPV_encode_picture, | |
| 3333 MPV_encode_end, | |
| 3334 }; |
