Mercurial > libavcodec.hg
annotate mpegvideo.c @ 287:32a3dcce2e9b libavcodec
fixing motion estimation with h263p hopefully
| author | michaelni |
|---|---|
| date | Sat, 23 Mar 2002 20:21:33 +0000 |
| parents | 91f7c38f5f37 |
| children | f82cce6cb182 |
| rev | line source |
|---|---|
| 0 | 1 /* |
| 2 * The simplest mpeg encoder (well, it was the simplest!) | |
| 3 * Copyright (c) 2000,2001 Gerard Lantau. | |
| 4 * | |
| 5 * This program is free software; you can redistribute it and/or modify | |
| 6 * it under the terms of the GNU General Public License as published by | |
| 7 * the Free Software Foundation; either version 2 of the License, or | |
| 8 * (at your option) any later version. | |
| 9 * | |
| 10 * This program is distributed in the hope that it will be useful, | |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 13 * GNU General Public License for more details. | |
| 14 * | |
| 15 * You should have received a copy of the GNU General Public License | |
| 16 * along with this program; if not, write to the Free Software | |
| 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 18 */ | |
| 19 #include <stdlib.h> | |
| 20 #include <stdio.h> | |
| 21 #include <math.h> | |
| 22 #include <string.h> | |
| 23 #include "avcodec.h" | |
| 24 #include "dsputil.h" | |
| 25 #include "mpegvideo.h" | |
| 26 | |
|
17
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
27 #ifdef USE_FASTMEMCPY |
|
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
28 #include "fastmemcpy.h" |
|
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
29 #endif |
|
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
30 |
|
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
|
31 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
|
32 static void rate_control_init(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
|
33 static int rate_estimate_qscale(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
|
34 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
|
35 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
|
36 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
|
37 DCTELEM *block, int n, int qscale); |
| 206 | 38 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w); |
| 220 | 39 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale); |
| 206 | 40 |
| 220 | 41 int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale)= dct_quantize_c; |
| 206 | 42 void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w)= draw_edges_c; |
| 43 | |
| 0 | 44 #define EDGE_WIDTH 16 |
| 45 | |
| 46 /* enable all paranoid tests for rounding, overflows, etc... */ | |
| 47 //#define PARANOID | |
| 48 | |
| 49 //#define DEBUG | |
| 50 | |
| 51 /* for jpeg fast DCT */ | |
| 52 #define CONST_BITS 14 | |
| 53 | |
| 54 static const unsigned short aanscales[64] = { | |
| 55 /* precomputed values scaled up by 14 bits */ | |
| 56 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
| 57 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, | |
| 58 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, | |
| 59 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, | |
| 60 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
| 61 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | |
| 62 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, | |
| 63 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 | |
| 64 }; | |
| 65 | |
| 66 static UINT8 h263_chroma_roundtab[16] = { | |
| 67 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, | |
| 68 }; | |
| 69 | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
70 static UINT16 default_mv_penalty[MAX_FCODE][MAX_MV*2+1]; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
71 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
|
72 |
| 0 | 73 /* default motion estimation */ |
| 74 int motion_estimation_method = ME_LOG; | |
| 75 | |
| 200 | 76 extern UINT8 zigzag_end[64]; |
| 77 | |
| 220 | 78 static void convert_matrix(int *qmat, UINT16 *qmat16, const UINT16 *quant_matrix, int qscale) |
| 0 | 79 { |
| 80 int i; | |
| 81 | |
| 82 if (av_fdct == jpeg_fdct_ifast) { | |
| 83 for(i=0;i<64;i++) { | |
| 84 /* 16 <= qscale * quant_matrix[i] <= 7905 */ | |
| 220 | 85 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ |
| 86 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ | |
| 87 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ | |
| 0 | 88 |
| 220 | 89 qmat[block_permute_op(i)] = (int)((UINT64_C(1) << (QMAT_SHIFT + 11)) / |
| 90 (aanscales[i] * qscale * quant_matrix[block_permute_op(i)])); | |
| 0 | 91 } |
| 92 } else { | |
| 93 for(i=0;i<64;i++) { | |
| 94 /* We can safely suppose that 16 <= quant_matrix[i] <= 255 | |
| 220 | 95 So 16 <= qscale * quant_matrix[i] <= 7905 |
| 96 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 | |
| 97 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 | |
| 0 | 98 */ |
| 220 | 99 qmat[i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); |
| 100 qmat16[i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[block_permute_op(i)]); | |
| 0 | 101 } |
| 102 } | |
| 103 } | |
| 104 | |
| 105 /* init common structure for both encoder and decoder */ | |
| 106 int MPV_common_init(MpegEncContext *s) | |
| 107 { | |
| 108 int c_size, i; | |
| 109 UINT8 *pict; | |
| 110 | |
|
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
|
111 if (s->out_format == FMT_H263) |
|
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
|
112 s->dct_unquantize = dct_unquantize_h263_c; |
|
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
|
113 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
|
114 s->dct_unquantize = dct_unquantize_mpeg1_c; |
|
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
|
115 |
|
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
|
116 #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
|
117 MPV_common_init_mmx(s); |
| 8 | 118 #endif |
| 0 | 119 s->mb_width = (s->width + 15) / 16; |
| 120 s->mb_height = (s->height + 15) / 16; | |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
121 s->mb_num = s->mb_width * s->mb_height; |
| 0 | 122 s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH; |
| 123 | |
| 124 for(i=0;i<3;i++) { | |
| 125 int w, h, shift, pict_start; | |
| 126 | |
| 127 w = s->linesize; | |
| 128 h = s->mb_height * 16 + 2 * EDGE_WIDTH; | |
| 129 shift = (i == 0) ? 0 : 1; | |
| 130 c_size = (w >> shift) * (h >> shift); | |
| 131 pict_start = (w >> shift) * (EDGE_WIDTH >> shift) + (EDGE_WIDTH >> shift); | |
| 132 | |
| 133 pict = av_mallocz(c_size); | |
| 134 if (pict == NULL) | |
| 135 goto fail; | |
| 136 s->last_picture_base[i] = pict; | |
| 137 s->last_picture[i] = pict + pict_start; | |
| 138 | |
| 139 pict = av_mallocz(c_size); | |
| 140 if (pict == NULL) | |
| 141 goto fail; | |
| 142 s->next_picture_base[i] = pict; | |
| 143 s->next_picture[i] = pict + pict_start; | |
| 144 | |
| 145 if (s->has_b_frames) { | |
| 146 pict = av_mallocz(c_size); | |
| 147 if (pict == NULL) | |
| 148 goto fail; | |
| 149 s->aux_picture_base[i] = pict; | |
| 150 s->aux_picture[i] = pict + pict_start; | |
| 151 } | |
| 152 } | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
153 |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
154 if (s->encoding) { |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
155 /* Allocate MB type table */ |
| 239 | 156 s->mb_type = av_mallocz(s->mb_num * sizeof(char)); |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
157 if (s->mb_type == NULL) { |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
158 perror("malloc"); |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
159 goto fail; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
160 } |
| 239 | 161 |
| 162 s->mb_var = av_mallocz(s->mb_num * sizeof(INT16)); | |
| 163 if (s->mb_var == NULL) { | |
| 164 perror("malloc"); | |
| 165 goto fail; | |
| 166 } | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
167 /* Allocate MV table */ |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
168 /* By now we just have one MV per MB */ |
| 239 | 169 s->mv_table[0] = av_mallocz(s->mb_num * sizeof(INT16)); |
| 170 s->mv_table[1] = av_mallocz(s->mb_num * sizeof(INT16)); | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
171 if (s->mv_table[1] == NULL || s->mv_table[0] == NULL) { |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
172 perror("malloc"); |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
173 goto fail; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
174 } |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
175 } |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
176 |
| 280 | 177 if (s->out_format == FMT_H263) { |
| 0 | 178 int size; |
| 179 /* MV prediction */ | |
| 180 size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | |
| 181 s->motion_val = malloc(size * 2 * sizeof(INT16)); | |
| 182 if (s->motion_val == NULL) | |
| 183 goto fail; | |
| 184 memset(s->motion_val, 0, size * 2 * sizeof(INT16)); | |
| 185 } | |
| 186 | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
187 if (s->h263_pred || s->h263_plus) { |
| 0 | 188 int y_size, c_size, i, size; |
| 189 | |
| 190 /* dc values */ | |
| 191 | |
| 192 y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | |
| 193 c_size = (s->mb_width + 2) * (s->mb_height + 2); | |
| 194 size = y_size + 2 * c_size; | |
| 195 s->dc_val[0] = malloc(size * sizeof(INT16)); | |
| 196 if (s->dc_val[0] == NULL) | |
| 197 goto fail; | |
| 198 s->dc_val[1] = s->dc_val[0] + y_size; | |
| 199 s->dc_val[2] = s->dc_val[1] + c_size; | |
| 200 for(i=0;i<size;i++) | |
| 201 s->dc_val[0][i] = 1024; | |
| 202 | |
| 203 /* ac values */ | |
| 204 s->ac_val[0] = av_mallocz(size * sizeof(INT16) * 16); | |
| 205 if (s->ac_val[0] == NULL) | |
| 206 goto fail; | |
| 207 s->ac_val[1] = s->ac_val[0] + y_size; | |
| 208 s->ac_val[2] = s->ac_val[1] + c_size; | |
| 209 | |
| 210 /* cbp values */ | |
| 211 s->coded_block = av_mallocz(y_size); | |
| 212 if (!s->coded_block) | |
| 213 goto fail; | |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
214 |
|
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
215 /* which mb is a intra block */ |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
216 s->mbintra_table = av_mallocz(s->mb_num); |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
217 if (!s->mbintra_table) |
|
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
218 goto fail; |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
219 memset(s->mbintra_table, 1, s->mb_num); |
|
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
|
220 } |
| 0 | 221 /* default structure is frame */ |
| 222 s->picture_structure = PICT_FRAME; | |
| 223 | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
224 /* init macroblock skip table */ |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
225 if (!s->encoding) { |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
226 s->mbskip_table = av_mallocz(s->mb_num); |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
227 if (!s->mbskip_table) |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
228 goto fail; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
229 } |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
230 |
| 0 | 231 s->context_initialized = 1; |
| 232 return 0; | |
| 233 fail: | |
| 244 | 234 MPV_common_end(s); |
| 235 return -1; | |
| 236 } | |
| 237 | |
| 238 /* init common structure for both encoder and decoder */ | |
| 239 void MPV_common_end(MpegEncContext *s) | |
| 240 { | |
| 241 int i; | |
| 242 | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
243 if (s->mb_type) |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
244 free(s->mb_type); |
| 239 | 245 if (s->mb_var) |
| 246 free(s->mb_var); | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
247 if (s->mv_table[0]) |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
248 free(s->mv_table[0]); |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
249 if (s->mv_table[1]) |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
250 free(s->mv_table[1]); |
| 0 | 251 if (s->motion_val) |
| 252 free(s->motion_val); | |
| 253 if (s->dc_val[0]) | |
| 254 free(s->dc_val[0]); | |
| 255 if (s->ac_val[0]) | |
| 256 free(s->ac_val[0]); | |
| 257 if (s->coded_block) | |
| 258 free(s->coded_block); | |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
259 if (s->mbintra_table) |
|
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
|
260 free(s->mbintra_table); |
| 244 | 261 |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
262 if (s->mbskip_table) |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
263 free(s->mbskip_table); |
| 0 | 264 for(i=0;i<3;i++) { |
| 265 if (s->last_picture_base[i]) | |
| 244 | 266 free(s->last_picture_base[i]); |
| 267 if (s->next_picture_base[i]) | |
| 268 free(s->next_picture_base[i]); | |
| 0 | 269 if (s->has_b_frames) |
| 270 free(s->aux_picture_base[i]); | |
| 271 } | |
| 272 s->context_initialized = 0; | |
| 273 } | |
| 274 | |
| 275 /* init video encoder */ | |
| 276 int MPV_encode_init(AVCodecContext *avctx) | |
| 277 { | |
| 278 MpegEncContext *s = avctx->priv_data; | |
| 60 | 279 int i; |
| 0 | 280 |
| 281 s->bit_rate = avctx->bit_rate; | |
| 268 | 282 s->bit_rate_tolerance = avctx->bit_rate_tolerance; |
| 0 | 283 s->frame_rate = avctx->frame_rate; |
| 284 s->width = avctx->width; | |
| 285 s->height = avctx->height; | |
| 286 s->gop_size = avctx->gop_size; | |
| 162 | 287 s->rtp_mode = avctx->rtp_mode; |
| 288 s->rtp_payload_size = avctx->rtp_payload_size; | |
| 231 | 289 if (avctx->rtp_callback) |
| 290 s->rtp_callback = avctx->rtp_callback; | |
| 268 | 291 s->qmin= avctx->qmin; |
| 292 s->qmax= avctx->qmax; | |
| 293 s->max_qdiff= avctx->max_qdiff; | |
| 294 s->qcompress= avctx->qcompress; | |
| 295 s->qblur= avctx->qblur; | |
|
194
27d1773552c9
mpeg4 encoder fix by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
191
diff
changeset
|
296 s->avctx = avctx; |
|
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
297 s->aspect_ratio_info= avctx->aspect_ratio_info; |
| 162 | 298 |
| 0 | 299 if (s->gop_size <= 1) { |
| 300 s->intra_only = 1; | |
| 301 s->gop_size = 12; | |
| 302 } else { | |
| 303 s->intra_only = 0; | |
| 304 } | |
| 305 s->full_search = motion_estimation_method; | |
| 306 | |
| 307 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
|
308 |
| 0 | 309 switch(avctx->codec->id) { |
| 310 case CODEC_ID_MPEG1VIDEO: | |
| 311 s->out_format = FMT_MPEG1; | |
| 312 break; | |
| 313 case CODEC_ID_MJPEG: | |
| 314 s->out_format = FMT_MJPEG; | |
| 315 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
|
316 s->mjpeg_write_tables = 1; /* write all tables */ |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
317 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
|
318 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
|
319 s->mjpeg_vsample[2] = 1; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
320 s->mjpeg_hsample[0] = 2; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
321 s->mjpeg_hsample[1] = 1; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
322 s->mjpeg_hsample[2] = 1; |
| 0 | 323 if (mjpeg_init(s) < 0) |
| 324 return -1; | |
| 325 break; | |
| 326 case CODEC_ID_H263: | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
327 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
|
328 printf("Input picture size isn't suitable for h263 codec! try h263+\n"); |
| 0 | 329 return -1; |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
330 } |
| 0 | 331 s->out_format = FMT_H263; |
| 332 break; | |
| 333 case CODEC_ID_H263P: | |
| 334 s->out_format = FMT_H263; | |
| 162 | 335 s->rtp_mode = 1; |
| 336 s->rtp_payload_size = 1200; | |
| 0 | 337 s->h263_plus = 1; |
| 78 | 338 s->unrestricted_mv = 1; |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
339 |
|
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
340 /* These are just to be sure */ |
|
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
341 s->umvplus = 0; |
|
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
342 s->umvplus_dec = 0; |
| 0 | 343 break; |
| 344 case CODEC_ID_RV10: | |
| 345 s->out_format = FMT_H263; | |
| 346 s->h263_rv10 = 1; | |
| 347 break; | |
| 71 | 348 case CODEC_ID_MPEG4: |
| 0 | 349 s->out_format = FMT_H263; |
| 350 s->h263_pred = 1; | |
| 351 s->unrestricted_mv = 1; | |
| 352 break; | |
| 353 case CODEC_ID_MSMPEG4: | |
| 354 s->out_format = FMT_H263; | |
| 355 s->h263_msmpeg4 = 1; | |
| 356 s->h263_pred = 1; | |
| 357 s->unrestricted_mv = 1; | |
| 358 break; | |
| 359 default: | |
| 360 return -1; | |
| 361 } | |
| 362 | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
363 { /* 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
|
364 static int done=0; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
365 if(!done){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
366 int i; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
367 done=1; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
368 memset(default_mv_penalty, 0, sizeof(UINT16)*MAX_FCODE*(2*MAX_MV+1)); |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
369 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
|
370 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
371 for(i=-16; i<16; i++){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
372 default_fcode_tab[i + MAX_MV]= 1; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
373 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
374 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
375 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
376 s->mv_penalty= default_mv_penalty; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
377 s->fcode_tab= default_fcode_tab; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
378 |
| 0 | 379 if (s->out_format == FMT_H263) |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
380 h263_encode_init(s); |
|
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
381 else if (s->out_format == FMT_MPEG1) |
|
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
382 mpeg1_encode_init(s); |
| 0 | 383 |
| 287 | 384 /* dont use mv_penalty table for crap MV as it would be confused */ |
| 385 if(s->full_search<4) s->mv_penalty= default_mv_penalty; | |
| 386 | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
387 s->encoding = 1; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
388 |
| 0 | 389 /* init */ |
| 390 if (MPV_common_init(s) < 0) | |
| 391 return -1; | |
| 392 | |
| 60 | 393 /* init default q matrix */ |
| 394 for(i=0;i<64;i++) { | |
| 395 s->intra_matrix[i] = default_intra_matrix[i]; | |
| 396 s->non_intra_matrix[i] = default_non_intra_matrix[i]; | |
| 397 } | |
| 398 | |
| 0 | 399 /* rate control init */ |
| 400 rate_control_init(s); | |
| 401 | |
| 402 s->picture_number = 0; | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
403 s->picture_in_gop_number = 0; |
| 0 | 404 s->fake_picture_number = 0; |
| 405 /* motion detector init */ | |
| 406 s->f_code = 1; | |
| 407 | |
| 408 return 0; | |
| 409 } | |
| 410 | |
| 411 int MPV_encode_end(AVCodecContext *avctx) | |
| 412 { | |
| 413 MpegEncContext *s = avctx->priv_data; | |
| 414 | |
| 415 #ifdef STATS | |
| 416 print_stats(); | |
| 417 #endif | |
| 418 MPV_common_end(s); | |
| 419 if (s->out_format == FMT_MJPEG) | |
| 420 mjpeg_close(s); | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
421 |
| 0 | 422 return 0; |
| 423 } | |
| 424 | |
| 425 /* draw the edges of width 'w' of an image of size width, height */ | |
| 206 | 426 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w) |
| 0 | 427 { |
| 428 UINT8 *ptr, *last_line; | |
| 429 int i; | |
| 430 | |
| 431 last_line = buf + (height - 1) * wrap; | |
| 432 for(i=0;i<w;i++) { | |
| 433 /* top and bottom */ | |
| 434 memcpy(buf - (i + 1) * wrap, buf, width); | |
| 435 memcpy(last_line + (i + 1) * wrap, last_line, width); | |
| 436 } | |
| 437 /* left and right */ | |
| 438 ptr = buf; | |
| 439 for(i=0;i<height;i++) { | |
| 440 memset(ptr - w, ptr[0], w); | |
| 441 memset(ptr + width, ptr[width-1], w); | |
| 442 ptr += wrap; | |
| 443 } | |
| 444 /* corners */ | |
| 445 for(i=0;i<w;i++) { | |
| 446 memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */ | |
| 447 memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */ | |
| 448 memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */ | |
| 449 memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */ | |
| 450 } | |
| 451 } | |
| 452 | |
| 453 /* generic function for encode/decode called before a frame is coded/decoded */ | |
| 454 void MPV_frame_start(MpegEncContext *s) | |
| 455 { | |
| 456 int i; | |
| 457 UINT8 *tmp; | |
| 458 | |
|
46
931417475f5b
fixed mpeg1 first block bug (pb with black picture optimisation for B frames)
glantau
parents:
40
diff
changeset
|
459 s->mb_skiped = 0; |
| 0 | 460 if (s->pict_type == B_TYPE) { |
| 461 for(i=0;i<3;i++) { | |
| 462 s->current_picture[i] = s->aux_picture[i]; | |
| 463 } | |
| 464 } else { | |
| 262 | 465 s->last_non_b_pict_type= s->pict_type; |
| 0 | 466 for(i=0;i<3;i++) { |
| 467 /* swap next and last */ | |
| 468 tmp = s->last_picture[i]; | |
| 469 s->last_picture[i] = s->next_picture[i]; | |
| 470 s->next_picture[i] = tmp; | |
| 471 s->current_picture[i] = tmp; | |
| 472 } | |
| 473 } | |
| 474 } | |
|
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
|
475 |
| 0 | 476 /* generic function for encode/decode called after a frame has been coded/decoded */ |
| 477 void MPV_frame_end(MpegEncContext *s) | |
| 478 { | |
| 479 /* draw edge for correct motion prediction if outside */ | |
| 220 | 480 if (s->pict_type != B_TYPE && !s->intra_only) { |
| 257 | 481 if(s->avctx==NULL || s->avctx->codec->id!=CODEC_ID_MPEG4 || s->divx_version==500){ |
|
176
9ce215ee9216
unrestricted MC fixed - thanks to Michael Niedermayer for idea
arpi_esp
parents:
162
diff
changeset
|
482 draw_edges(s->current_picture[0], s->linesize, s->mb_width*16, s->mb_height*16, EDGE_WIDTH); |
|
9ce215ee9216
unrestricted MC fixed - thanks to Michael Niedermayer for idea
arpi_esp
parents:
162
diff
changeset
|
483 draw_edges(s->current_picture[1], s->linesize/2, s->mb_width*8, s->mb_height*8, EDGE_WIDTH/2); |
|
9ce215ee9216
unrestricted MC fixed - thanks to Michael Niedermayer for idea
arpi_esp
parents:
162
diff
changeset
|
484 draw_edges(s->current_picture[2], s->linesize/2, s->mb_width*8, s->mb_height*8, EDGE_WIDTH/2); |
|
189
42552c1cf360
fix different UMV handling for mpeg4 vs. h263 - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
187
diff
changeset
|
485 }else{ |
| 257 | 486 /* mpeg4? / opendivx / xvid */ |
| 0 | 487 draw_edges(s->current_picture[0], s->linesize, s->width, s->height, EDGE_WIDTH); |
| 488 draw_edges(s->current_picture[1], s->linesize/2, s->width/2, s->height/2, EDGE_WIDTH/2); | |
| 489 draw_edges(s->current_picture[2], s->linesize/2, s->width/2, s->height/2, EDGE_WIDTH/2); | |
|
189
42552c1cf360
fix different UMV handling for mpeg4 vs. h263 - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
187
diff
changeset
|
490 } |
| 0 | 491 } |
| 207 | 492 emms_c(); |
| 0 | 493 } |
| 494 | |
| 495 int MPV_encode_picture(AVCodecContext *avctx, | |
| 496 unsigned char *buf, int buf_size, void *data) | |
| 497 { | |
| 498 MpegEncContext *s = avctx->priv_data; | |
| 499 AVPicture *pict = data; | |
| 500 int i, j; | |
| 501 | |
| 502 if (s->fixed_qscale) | |
| 503 s->qscale = avctx->quality; | |
| 504 | |
| 505 init_put_bits(&s->pb, buf, buf_size, NULL, NULL); | |
| 506 | |
| 507 if (!s->intra_only) { | |
| 508 /* first picture of GOP is intra */ | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
509 if (s->picture_in_gop_number >= s->gop_size){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
510 s->picture_in_gop_number=0; |
| 0 | 511 s->pict_type = I_TYPE; |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
512 }else |
| 0 | 513 s->pict_type = P_TYPE; |
| 514 } else { | |
| 515 s->pict_type = I_TYPE; | |
| 516 } | |
| 517 | |
| 518 MPV_frame_start(s); | |
| 220 | 519 |
| 0 | 520 for(i=0;i<3;i++) { |
| 521 UINT8 *src = pict->data[i]; | |
| 522 UINT8 *dest = s->current_picture[i]; | |
| 523 int src_wrap = pict->linesize[i]; | |
| 524 int dest_wrap = s->linesize; | |
| 525 int w = s->width; | |
| 526 int h = s->height; | |
| 527 | |
| 528 if (i >= 1) { | |
| 529 dest_wrap >>= 1; | |
| 530 w >>= 1; | |
| 531 h >>= 1; | |
| 532 } | |
| 533 | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
534 if(dest_wrap==src_wrap){ |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
535 s->new_picture[i] = pict->data[i]; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
536 } else { |
| 220 | 537 for(j=0;j<h;j++) { |
| 538 memcpy(dest, src, w); | |
| 539 dest += dest_wrap; | |
| 540 src += src_wrap; | |
| 541 } | |
|
227
ec1bc02a0a47
avoid copying input when encoding non intra stuff too
michaelni
parents:
220
diff
changeset
|
542 s->new_picture[i] = s->current_picture[i]; |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
543 } |
| 0 | 544 } |
| 545 | |
| 546 encode_picture(s, s->picture_number); | |
| 271 | 547 avctx->key_frame = (s->pict_type == I_TYPE); |
| 286 | 548 avctx->header_bits = s->header_bits; |
| 549 avctx->mv_bits = s->mv_bits; | |
| 550 avctx->misc_bits = s->misc_bits; | |
| 551 avctx->i_tex_bits = s->i_tex_bits; | |
| 552 avctx->p_tex_bits = s->p_tex_bits; | |
| 553 avctx->i_count = s->i_count; | |
| 554 avctx->p_count = s->p_count; | |
| 555 avctx->skip_count = s->skip_count; | |
| 556 | |
| 0 | 557 MPV_frame_end(s); |
| 558 s->picture_number++; | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
559 s->picture_in_gop_number++; |
| 0 | 560 |
| 561 if (s->out_format == FMT_MJPEG) | |
| 562 mjpeg_picture_trailer(s); | |
| 563 | |
| 564 flush_put_bits(&s->pb); | |
| 268 | 565 s->last_frame_bits= s->frame_bits; |
| 566 s->frame_bits = (pbBufPtr(&s->pb) - s->pb.buf) * 8; | |
| 567 s->total_bits += s->frame_bits; | |
| 286 | 568 avctx->frame_bits = s->frame_bits; |
| 569 //printf("fcode: %d, type: %d, head: %d, mv: %d, misc: %d, frame: %d, itex: %d, ptex: %d\n", | |
| 570 //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); | |
|
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
|
571 |
| 0 | 572 avctx->quality = s->qscale; |
|
252
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
573 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
|
574 /* 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
|
575 /* 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
|
576 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
|
577 pict->linesize, s->linesize, avctx); |
|
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
578 } |
|
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
|
579 return pbBufPtr(&s->pb) - s->pb.buf; |
| 0 | 580 } |
| 581 | |
| 582 static inline int clip(int a, int amin, int amax) | |
| 583 { | |
| 584 if (a < amin) | |
| 585 return amin; | |
| 586 else if (a > amax) | |
| 587 return amax; | |
| 588 else | |
| 589 return a; | |
| 590 } | |
| 591 | |
| 255 | 592 static inline void gmc1_motion(MpegEncContext *s, |
| 593 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 594 int dest_offset, | |
| 595 UINT8 **ref_picture, int src_offset, | |
| 596 int h) | |
| 597 { | |
| 598 UINT8 *ptr; | |
| 599 int dxy, offset, mx, my, src_x, src_y, height, linesize; | |
| 600 int motion_x, motion_y; | |
| 601 | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
262
diff
changeset
|
602 if(s->real_sprite_warping_points>1) printf("more than 1 warp point isnt supported\n"); |
| 255 | 603 motion_x= s->sprite_offset[0][0]; |
| 604 motion_y= s->sprite_offset[0][1]; | |
| 605 src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
| 606 src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
| 607 motion_x<<=(3-s->sprite_warping_accuracy); | |
| 608 motion_y<<=(3-s->sprite_warping_accuracy); | |
| 609 src_x = clip(src_x, -16, s->width); | |
| 610 if (src_x == s->width) | |
| 611 motion_x =0; | |
| 612 src_y = clip(src_y, -16, s->height); | |
| 613 if (src_y == s->height) | |
| 614 motion_y =0; | |
| 615 | |
| 616 linesize = s->linesize; | |
| 617 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; | |
| 618 | |
| 619 dest_y+=dest_offset; | |
| 620 gmc1(dest_y , ptr , linesize, h, motion_x&15, motion_y&15, s->no_rounding); | |
| 621 gmc1(dest_y+8, ptr+8, linesize, h, motion_x&15, motion_y&15, s->no_rounding); | |
| 622 | |
| 623 motion_x= s->sprite_offset[1][0]; | |
| 624 motion_y= s->sprite_offset[1][1]; | |
| 625 src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
| 626 src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
| 627 motion_x<<=(3-s->sprite_warping_accuracy); | |
| 628 motion_y<<=(3-s->sprite_warping_accuracy); | |
| 629 src_x = clip(src_x, -8, s->width>>1); | |
| 630 if (src_x == s->width>>1) | |
| 631 motion_x =0; | |
| 632 src_y = clip(src_y, -8, s->height>>1); | |
| 633 if (src_y == s->height>>1) | |
| 634 motion_y =0; | |
| 635 | |
| 636 offset = (src_y * linesize>>1) + src_x + (src_offset>>1); | |
| 637 ptr = ref_picture[1] + offset; | |
| 638 gmc1(dest_cb + (dest_offset>>1), ptr, linesize>>1, h>>1, motion_x&15, motion_y&15, s->no_rounding); | |
| 639 ptr = ref_picture[2] + offset; | |
| 640 gmc1(dest_cr + (dest_offset>>1), ptr, linesize>>1, h>>1, motion_x&15, motion_y&15, s->no_rounding); | |
| 641 | |
| 642 return; | |
| 643 } | |
| 644 | |
| 0 | 645 /* apply one mpeg motion vector to the three components */ |
| 646 static inline void mpeg_motion(MpegEncContext *s, | |
| 647 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 648 int dest_offset, | |
| 649 UINT8 **ref_picture, int src_offset, | |
| 650 int field_based, op_pixels_func *pix_op, | |
| 651 int motion_x, int motion_y, int h) | |
| 652 { | |
| 653 UINT8 *ptr; | |
| 654 int dxy, offset, mx, my, src_x, src_y, height, linesize; | |
| 255 | 655 if(s->quarter_sample) |
| 656 { | |
| 657 motion_x>>=1; | |
| 658 motion_y>>=1; | |
| 659 } | |
| 0 | 660 dxy = ((motion_y & 1) << 1) | (motion_x & 1); |
| 661 src_x = s->mb_x * 16 + (motion_x >> 1); | |
| 662 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1); | |
| 663 | |
| 664 /* WARNING: do no forget half pels */ | |
| 665 height = s->height >> field_based; | |
| 666 src_x = clip(src_x, -16, s->width); | |
| 667 if (src_x == s->width) | |
| 668 dxy &= ~1; | |
| 669 src_y = clip(src_y, -16, height); | |
| 670 if (src_y == height) | |
| 671 dxy &= ~2; | |
| 672 linesize = s->linesize << field_based; | |
| 673 ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset; | |
| 674 dest_y += dest_offset; | |
| 675 pix_op[dxy](dest_y, ptr, linesize, h); | |
| 676 pix_op[dxy](dest_y + 8, ptr + 8, linesize, h); | |
| 677 | |
| 678 if (s->out_format == FMT_H263) { | |
| 679 dxy = 0; | |
| 680 if ((motion_x & 3) != 0) | |
| 681 dxy |= 1; | |
| 682 if ((motion_y & 3) != 0) | |
| 683 dxy |= 2; | |
| 684 mx = motion_x >> 2; | |
| 685 my = motion_y >> 2; | |
| 686 } else { | |
| 687 mx = motion_x / 2; | |
| 688 my = motion_y / 2; | |
| 689 dxy = ((my & 1) << 1) | (mx & 1); | |
| 690 mx >>= 1; | |
| 691 my >>= 1; | |
| 692 } | |
| 693 | |
| 694 src_x = s->mb_x * 8 + mx; | |
| 695 src_y = s->mb_y * (8 >> field_based) + my; | |
| 696 src_x = clip(src_x, -8, s->width >> 1); | |
| 697 if (src_x == (s->width >> 1)) | |
| 698 dxy &= ~1; | |
| 699 src_y = clip(src_y, -8, height >> 1); | |
| 700 if (src_y == (height >> 1)) | |
| 701 dxy &= ~2; | |
| 702 | |
| 703 offset = (src_y * (linesize >> 1)) + src_x + (src_offset >> 1); | |
| 704 ptr = ref_picture[1] + offset; | |
| 705 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); | |
| 706 ptr = ref_picture[2] + offset; | |
| 707 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); | |
| 708 } | |
| 709 | |
| 255 | 710 static inline void qpel_motion(MpegEncContext *s, |
| 711 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 712 int dest_offset, | |
| 713 UINT8 **ref_picture, int src_offset, | |
| 714 int field_based, op_pixels_func *pix_op, | |
| 715 qpel_mc_func *qpix_op, | |
| 716 int motion_x, int motion_y, int h) | |
| 717 { | |
| 718 UINT8 *ptr; | |
| 719 int dxy, offset, mx, my, src_x, src_y, height, linesize; | |
| 720 | |
| 721 dxy = ((motion_y & 3) << 2) | (motion_x & 3); | |
| 722 src_x = s->mb_x * 16 + (motion_x >> 2); | |
| 723 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); | |
| 724 | |
| 725 height = s->height >> field_based; | |
| 726 src_x = clip(src_x, -16, s->width); | |
| 727 if (src_x == s->width) | |
| 728 dxy &= ~3; | |
| 729 src_y = clip(src_y, -16, height); | |
| 730 if (src_y == height) | |
| 731 dxy &= ~12; | |
| 732 linesize = s->linesize << field_based; | |
| 733 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; | |
| 734 dest_y += dest_offset; | |
| 735 //printf("%d %d %d\n", src_x, src_y, dxy); | |
| 736 qpix_op[dxy](dest_y , ptr , linesize, linesize, motion_x&3, motion_y&3); | |
| 737 qpix_op[dxy](dest_y + 8, ptr + 8, linesize, linesize, motion_x&3, motion_y&3); | |
| 738 qpix_op[dxy](dest_y + linesize*8 , ptr + linesize*8 , linesize, linesize, motion_x&3, motion_y&3); | |
| 739 qpix_op[dxy](dest_y + linesize*8 + 8, ptr + linesize*8 + 8, linesize, linesize, motion_x&3, motion_y&3); | |
| 740 | |
| 741 mx= (motion_x>>1) | (motion_x&1); | |
| 742 my= (motion_y>>1) | (motion_y&1); | |
| 743 | |
| 744 dxy = 0; | |
| 745 if ((mx & 3) != 0) | |
| 746 dxy |= 1; | |
| 747 if ((my & 3) != 0) | |
| 748 dxy |= 2; | |
| 749 mx = mx >> 2; | |
| 750 my = my >> 2; | |
| 751 | |
| 752 src_x = s->mb_x * 8 + mx; | |
| 753 src_y = s->mb_y * (8 >> field_based) + my; | |
| 754 src_x = clip(src_x, -8, s->width >> 1); | |
| 755 if (src_x == (s->width >> 1)) | |
| 756 dxy &= ~1; | |
| 757 src_y = clip(src_y, -8, height >> 1); | |
| 758 if (src_y == (height >> 1)) | |
| 759 dxy &= ~2; | |
| 760 | |
| 761 offset = (src_y * (linesize >> 1)) + src_x + (src_offset >> 1); | |
| 762 ptr = ref_picture[1] + offset; | |
| 763 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); | |
| 764 ptr = ref_picture[2] + offset; | |
| 765 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); | |
| 766 } | |
| 767 | |
| 768 | |
| 0 | 769 static inline void MPV_motion(MpegEncContext *s, |
| 770 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 771 int dir, UINT8 **ref_picture, | |
| 255 | 772 op_pixels_func *pix_op, qpel_mc_func *qpix_op) |
| 0 | 773 { |
| 774 int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y; | |
| 775 int mb_x, mb_y, i; | |
| 776 UINT8 *ptr, *dest; | |
| 777 | |
| 778 mb_x = s->mb_x; | |
| 779 mb_y = s->mb_y; | |
| 780 | |
| 781 switch(s->mv_type) { | |
| 782 case MV_TYPE_16X16: | |
| 255 | 783 if(s->mcsel){ |
| 784 #if 0 | |
| 785 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 786 ref_picture, 0, | |
| 787 0, pix_op, | |
| 788 s->sprite_offset[0][0]>>3, | |
| 789 s->sprite_offset[0][1]>>3, | |
| 790 16); | |
| 791 #else | |
| 792 gmc1_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 793 ref_picture, 0, | |
| 794 16); | |
| 795 #endif | |
| 262 | 796 }else if(s->quarter_sample && dir==0){ //FIXME |
| 255 | 797 qpel_motion(s, dest_y, dest_cb, dest_cr, 0, |
| 798 ref_picture, 0, | |
| 799 0, pix_op, qpix_op, | |
| 800 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
| 801 }else{ | |
| 802 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 803 ref_picture, 0, | |
| 804 0, pix_op, | |
| 805 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
| 806 } | |
| 0 | 807 break; |
| 808 case MV_TYPE_8X8: | |
| 809 for(i=0;i<4;i++) { | |
| 810 motion_x = s->mv[dir][i][0]; | |
| 811 motion_y = s->mv[dir][i][1]; | |
| 812 | |
| 813 dxy = ((motion_y & 1) << 1) | (motion_x & 1); | |
| 814 src_x = mb_x * 16 + (motion_x >> 1) + (i & 1) * 8; | |
| 815 src_y = mb_y * 16 + (motion_y >> 1) + ((i >> 1) & 1) * 8; | |
| 816 | |
| 817 /* WARNING: do no forget half pels */ | |
| 818 src_x = clip(src_x, -16, s->width); | |
| 819 if (src_x == s->width) | |
| 820 dxy &= ~1; | |
| 821 src_y = clip(src_y, -16, s->height); | |
| 822 if (src_y == s->height) | |
| 823 dxy &= ~2; | |
| 824 | |
| 825 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); | |
| 826 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; | |
| 827 pix_op[dxy](dest, ptr, s->linesize, 8); | |
| 828 } | |
| 829 /* In case of 8X8, we construct a single chroma motion vector | |
| 830 with a special rounding */ | |
| 831 mx = 0; | |
| 832 my = 0; | |
| 833 for(i=0;i<4;i++) { | |
| 834 mx += s->mv[dir][i][0]; | |
| 835 my += s->mv[dir][i][1]; | |
| 836 } | |
| 837 if (mx >= 0) | |
| 838 mx = (h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1)); | |
| 839 else { | |
| 840 mx = -mx; | |
| 841 mx = -(h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1)); | |
| 842 } | |
| 843 if (my >= 0) | |
| 844 my = (h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1)); | |
| 845 else { | |
| 846 my = -my; | |
| 847 my = -(h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1)); | |
| 848 } | |
| 849 dxy = ((my & 1) << 1) | (mx & 1); | |
| 850 mx >>= 1; | |
| 851 my >>= 1; | |
| 852 | |
| 853 src_x = mb_x * 8 + mx; | |
| 854 src_y = mb_y * 8 + my; | |
| 855 src_x = clip(src_x, -8, s->width/2); | |
| 856 if (src_x == s->width/2) | |
| 857 dxy &= ~1; | |
| 858 src_y = clip(src_y, -8, s->height/2); | |
| 859 if (src_y == s->height/2) | |
| 860 dxy &= ~2; | |
| 861 | |
| 862 offset = (src_y * (s->linesize >> 1)) + src_x; | |
| 863 ptr = ref_picture[1] + offset; | |
| 864 pix_op[dxy](dest_cb, ptr, s->linesize >> 1, 8); | |
| 865 ptr = ref_picture[2] + offset; | |
| 866 pix_op[dxy](dest_cr, ptr, s->linesize >> 1, 8); | |
| 867 break; | |
| 868 case MV_TYPE_FIELD: | |
| 869 if (s->picture_structure == PICT_FRAME) { | |
| 870 /* top field */ | |
| 871 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 872 ref_picture, s->field_select[dir][0] ? s->linesize : 0, | |
| 873 1, pix_op, | |
| 874 s->mv[dir][0][0], s->mv[dir][0][1], 8); | |
| 875 /* bottom field */ | |
| 876 mpeg_motion(s, dest_y, dest_cb, dest_cr, s->linesize, | |
| 877 ref_picture, s->field_select[dir][1] ? s->linesize : 0, | |
| 878 1, pix_op, | |
| 879 s->mv[dir][1][0], s->mv[dir][1][1], 8); | |
| 880 } else { | |
| 881 | |
| 882 | |
| 883 } | |
| 884 break; | |
| 885 } | |
| 886 } | |
| 887 | |
| 888 | |
| 889 /* put block[] to dest[] */ | |
| 890 static inline void put_dct(MpegEncContext *s, | |
| 891 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
| 892 { | |
| 893 if (!s->mpeg2) | |
|
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
|
894 s->dct_unquantize(s, block, i, s->qscale); |
|
19
82d4c9be9873
MMX/MMXEXT iDCT support, using external functions currently defined in libmpeg2
arpi_esp
parents:
18
diff
changeset
|
895 ff_idct (block); |
| 0 | 896 put_pixels_clamped(block, dest, line_size); |
| 897 } | |
| 898 | |
| 899 /* add block[] to dest[] */ | |
| 900 static inline void add_dct(MpegEncContext *s, | |
| 901 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
| 902 { | |
| 903 if (s->block_last_index[i] >= 0) { | |
| 904 if (!s->mpeg2) | |
| 206 | 905 if(s->encoding || (!s->h263_msmpeg4)) |
| 200 | 906 s->dct_unquantize(s, block, i, s->qscale); |
|
19
82d4c9be9873
MMX/MMXEXT iDCT support, using external functions currently defined in libmpeg2
arpi_esp
parents:
18
diff
changeset
|
907 ff_idct (block); |
| 0 | 908 add_pixels_clamped(block, dest, line_size); |
| 909 } | |
| 910 } | |
| 911 | |
| 912 /* generic function called after a macroblock has been parsed by the | |
| 913 decoder or after it has been encoded by the encoder. | |
| 914 | |
| 915 Important variables used: | |
| 916 s->mb_intra : true if intra macroblock | |
| 917 s->mv_dir : motion vector direction | |
| 918 s->mv_type : motion vector type | |
| 919 s->mv : motion vector | |
| 920 s->interlaced_dct : true if interlaced dct used (mpeg2) | |
| 921 */ | |
| 922 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) | |
| 923 { | |
| 244 | 924 int mb_x, mb_y; |
| 0 | 925 int dct_linesize, dct_offset; |
| 926 op_pixels_func *op_pix; | |
| 255 | 927 qpel_mc_func *op_qpix; |
| 0 | 928 |
| 929 mb_x = s->mb_x; | |
| 930 mb_y = s->mb_y; | |
| 931 | |
|
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
932 #ifdef FF_POSTPROCESS |
|
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
933 quant_store[mb_y][mb_x]=s->qscale; |
|
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
934 //printf("[%02d][%02d] %d\n",mb_x,mb_y,s->qscale); |
|
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
935 #endif |
|
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
936 |
| 0 | 937 /* update DC predictors for P macroblocks */ |
| 938 if (!s->mb_intra) { | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
939 if (s->h263_pred || s->h263_aic) { |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
940 if(s->mbintra_table[mb_x + mb_y*s->mb_width]) |
|
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
941 { |
| 244 | 942 int wrap, xy, v; |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
943 s->mbintra_table[mb_x + mb_y*s->mb_width]=0; |
| 0 | 944 wrap = 2 * s->mb_width + 2; |
| 244 | 945 xy = 2 * mb_x + 1 + (2 * mb_y + 1) * wrap; |
| 0 | 946 v = 1024; |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
947 |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
948 s->dc_val[0][xy] = v; |
| 244 | 949 s->dc_val[0][xy + 1] = v; |
| 950 s->dc_val[0][xy + wrap] = v; | |
| 951 s->dc_val[0][xy + 1 + wrap] = v; | |
| 0 | 952 /* ac pred */ |
| 244 | 953 memset(s->ac_val[0][xy], 0, 16 * sizeof(INT16)); |
| 954 memset(s->ac_val[0][xy + 1], 0, 16 * sizeof(INT16)); | |
| 955 memset(s->ac_val[0][xy + wrap], 0, 16 * sizeof(INT16)); | |
| 956 memset(s->ac_val[0][xy + 1 + wrap], 0, 16 * sizeof(INT16)); | |
| 0 | 957 if (s->h263_msmpeg4) { |
| 244 | 958 s->coded_block[xy] = 0; |
| 959 s->coded_block[xy + 1] = 0; | |
| 960 s->coded_block[xy + wrap] = 0; | |
| 961 s->coded_block[xy + 1 + wrap] = 0; | |
| 0 | 962 } |
| 963 /* chroma */ | |
| 964 wrap = s->mb_width + 2; | |
| 244 | 965 xy = mb_x + 1 + (mb_y + 1) * wrap; |
| 966 s->dc_val[1][xy] = v; | |
| 967 s->dc_val[2][xy] = v; | |
| 0 | 968 /* ac pred */ |
| 244 | 969 memset(s->ac_val[1][xy], 0, 16 * sizeof(INT16)); |
| 970 memset(s->ac_val[2][xy], 0, 16 * sizeof(INT16)); | |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
971 } |
| 0 | 972 } else { |
| 973 s->last_dc[0] = 128 << s->intra_dc_precision; | |
| 974 s->last_dc[1] = 128 << s->intra_dc_precision; | |
| 975 s->last_dc[2] = 128 << s->intra_dc_precision; | |
| 976 } | |
| 977 } | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
978 else if (s->h263_pred || s->h263_aic) |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
979 s->mbintra_table[mb_x + mb_y*s->mb_width]=1; |
|
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
980 |
| 280 | 981 /* update motion predictor, not for B-frames as they need the motion_val from the last P/S-Frame */ |
| 982 if (s->out_format == FMT_H263) { | |
| 262 | 983 if(s->pict_type!=B_TYPE){ |
| 244 | 984 int xy, wrap, motion_x, motion_y; |
| 0 | 985 |
| 986 wrap = 2 * s->mb_width + 2; | |
| 244 | 987 xy = 2 * mb_x + 1 + (2 * mb_y + 1) * wrap; |
| 0 | 988 if (s->mb_intra) { |
| 989 motion_x = 0; | |
| 990 motion_y = 0; | |
| 991 goto motion_init; | |
| 992 } else if (s->mv_type == MV_TYPE_16X16) { | |
| 993 motion_x = s->mv[0][0][0]; | |
| 994 motion_y = s->mv[0][0][1]; | |
| 995 motion_init: | |
| 996 /* no update if 8X8 because it has been done during parsing */ | |
| 244 | 997 s->motion_val[xy][0] = motion_x; |
| 998 s->motion_val[xy][1] = motion_y; | |
| 999 s->motion_val[xy + 1][0] = motion_x; | |
| 1000 s->motion_val[xy + 1][1] = motion_y; | |
| 1001 s->motion_val[xy + wrap][0] = motion_x; | |
| 1002 s->motion_val[xy + wrap][1] = motion_y; | |
| 1003 s->motion_val[xy + 1 + wrap][0] = motion_x; | |
| 1004 s->motion_val[xy + 1 + wrap][1] = motion_y; | |
| 0 | 1005 } |
| 262 | 1006 } |
| 0 | 1007 } |
| 1008 | |
| 1009 if (!s->intra_only) { | |
| 1010 UINT8 *dest_y, *dest_cb, *dest_cr; | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1011 UINT8 *mbskip_ptr; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1012 |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1013 /* avoid copy if macroblock skipped in last frame too */ |
|
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
|
1014 if (!s->encoding && s->pict_type != B_TYPE) { |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1015 mbskip_ptr = &s->mbskip_table[s->mb_y * s->mb_width + s->mb_x]; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1016 if (s->mb_skiped) { |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1017 s->mb_skiped = 0; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1018 /* if previous was skipped too, then nothing to do ! */ |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1019 if (*mbskip_ptr != 0) |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1020 goto the_end; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1021 *mbskip_ptr = 1; /* indicate that this time we skiped it */ |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1022 } else { |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1023 *mbskip_ptr = 0; /* not skipped */ |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1024 } |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1025 } |
| 0 | 1026 |
| 1027 dest_y = s->current_picture[0] + (mb_y * 16 * s->linesize) + mb_x * 16; | |
| 1028 dest_cb = s->current_picture[1] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; | |
| 1029 dest_cr = s->current_picture[2] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; | |
| 1030 | |
| 1031 if (s->interlaced_dct) { | |
| 1032 dct_linesize = s->linesize * 2; | |
| 1033 dct_offset = s->linesize; | |
| 1034 } else { | |
| 1035 dct_linesize = s->linesize; | |
| 1036 dct_offset = s->linesize * 8; | |
| 1037 } | |
| 1038 | |
| 1039 if (!s->mb_intra) { | |
| 1040 /* motion handling */ | |
| 255 | 1041 if (!s->no_rounding){ |
| 0 | 1042 op_pix = put_pixels_tab; |
| 255 | 1043 op_qpix= qpel_mc_rnd_tab; |
| 1044 }else{ | |
| 0 | 1045 op_pix = put_no_rnd_pixels_tab; |
| 255 | 1046 op_qpix= qpel_mc_no_rnd_tab; |
| 1047 } | |
| 0 | 1048 |
| 1049 if (s->mv_dir & MV_DIR_FORWARD) { | |
| 255 | 1050 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); |
| 0 | 1051 if (!s->no_rounding) |
| 1052 op_pix = avg_pixels_tab; | |
| 1053 else | |
| 1054 op_pix = avg_no_rnd_pixels_tab; | |
| 1055 } | |
| 1056 if (s->mv_dir & MV_DIR_BACKWARD) { | |
| 255 | 1057 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); |
| 0 | 1058 } |
| 1059 | |
| 1060 /* add dct residue */ | |
| 1061 add_dct(s, block[0], 0, dest_y, dct_linesize); | |
| 1062 add_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
| 1063 add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
| 1064 add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
| 1065 | |
| 57 | 1066 add_dct(s, block[4], 4, dest_cb, s->linesize >> 1); |
| 1067 add_dct(s, block[5], 5, dest_cr, s->linesize >> 1); | |
| 0 | 1068 } else { |
| 1069 /* dct only in intra block */ | |
| 1070 put_dct(s, block[0], 0, dest_y, dct_linesize); | |
| 1071 put_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
| 1072 put_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
| 1073 put_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
| 1074 | |
| 57 | 1075 put_dct(s, block[4], 4, dest_cb, s->linesize >> 1); |
| 1076 put_dct(s, block[5], 5, dest_cr, s->linesize >> 1); | |
| 0 | 1077 } |
| 1078 } | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1079 the_end: |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1080 emms_c(); |
| 0 | 1081 } |
| 1082 | |
| 1083 static void encode_picture(MpegEncContext *s, int picture_number) | |
| 1084 { | |
| 231 | 1085 int mb_x, mb_y, wrap, last_gob, pdif = 0; |
| 0 | 1086 UINT8 *ptr; |
| 1087 int i, motion_x, motion_y; | |
| 286 | 1088 int bits; |
| 0 | 1089 |
| 1090 s->picture_number = picture_number; | |
| 268 | 1091 |
| 1092 s->last_mc_mb_var = s->mc_mb_var; | |
| 1093 /* Reset the average MB variance */ | |
| 1094 s->avg_mb_var = 0; | |
| 1095 s->mc_mb_var = 0; | |
| 1096 /* Estimate motion for every MB */ | |
| 1097 for(mb_y=0; mb_y < s->mb_height; mb_y++) { | |
| 1098 for(mb_x=0; mb_x < s->mb_width; mb_x++) { | |
| 1099 int xy= mb_y * s->mb_width + mb_x; | |
| 1100 s->mb_x = mb_x; | |
| 1101 s->mb_y = mb_y; | |
| 1102 | |
| 1103 /* compute motion vector and macro block type (intra or non intra) */ | |
| 1104 motion_x = 0; | |
| 1105 motion_y = 0; | |
| 1106 if (s->pict_type == P_TYPE) { | |
| 1107 s->mb_intra = estimate_motion(s, mb_x, mb_y, | |
| 1108 &motion_x, | |
| 1109 &motion_y); | |
| 1110 } else { | |
| 1111 s->mb_intra = 1; | |
| 1112 } | |
| 1113 /* Store MB type and MV */ | |
| 1114 s->mb_type[xy] = s->mb_intra; | |
| 1115 s->mv_table[0][xy] = motion_x; | |
| 1116 s->mv_table[1][xy] = motion_y; | |
| 1117 } | |
| 1118 } | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1119 emms_c(); |
| 268 | 1120 |
| 271 | 1121 if(s->avg_mb_var < s->mc_mb_var && s->pict_type != B_TYPE){ //FIXME subtract MV bits |
| 1122 int i; | |
| 1123 s->pict_type= I_TYPE; | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1124 s->picture_in_gop_number=0; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1125 for(i=0; i<s->mb_num; i++){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1126 s->mb_type[i] = 1; |
| 271 | 1127 s->mv_table[0][i] = 0; |
| 1128 s->mv_table[1][i] = 0; | |
| 1129 } | |
| 1130 } | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1131 |
| 287 | 1132 /* find best f_code for ME which do unlimited searches */ |
| 1133 if(s->pict_type==P_TYPE && s->full_search>3){ | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1134 int mv_num[8]; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1135 int i; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1136 int loose=0; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1137 UINT8 * fcode_tab= s->fcode_tab; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1138 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1139 for(i=0; i<8; i++) mv_num[i]=0; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1140 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1141 for(i=0; i<s->mb_num; i++){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1142 if(s->mb_type[i] == 0){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1143 mv_num[ fcode_tab[s->mv_table[0][i] + MAX_MV] ]++; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1144 mv_num[ fcode_tab[s->mv_table[1][i] + MAX_MV] ]++; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1145 //printf("%d %d %d\n", s->mv_table[0][i], fcode_tab[s->mv_table[0][i] + MAX_MV], i); |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1146 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1147 //else printf("I"); |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1148 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1149 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1150 for(i=MAX_FCODE; i>1; i--){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1151 loose+= mv_num[i]; |
| 286 | 1152 if(loose > 10) break; //FIXME this is pretty ineffective |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1153 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1154 s->f_code= i; |
| 287 | 1155 /* for(i=0; i<=MAX_FCODE; i++){ |
| 1156 printf("%d ", mv_num[i]); | |
| 1157 } | |
| 1158 printf("\n");*/ | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1159 }else{ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1160 s->f_code= 1; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1161 } |
|
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
1162 |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1163 //printf("f_code %d ///\n", s->f_code); |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1164 /* convert MBs with too long MVs to I-Blocks */ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1165 if(s->pict_type==P_TYPE){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1166 int i; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1167 const int f_code= s->f_code; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1168 UINT8 * fcode_tab= s->fcode_tab; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1169 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1170 for(i=0; i<s->mb_num; i++){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1171 if(s->mb_type[i] == 0){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1172 if( fcode_tab[s->mv_table[0][i] + MAX_MV] > f_code |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1173 || fcode_tab[s->mv_table[0][i] + MAX_MV] == 0 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1174 || fcode_tab[s->mv_table[1][i] + MAX_MV] > f_code |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1175 || fcode_tab[s->mv_table[1][i] + MAX_MV] == 0 ){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1176 s->mb_type[i] = 1; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1177 s->mv_table[0][i] = 0; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1178 s->mv_table[1][i] = 0; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1179 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1180 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1181 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1182 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1183 |
| 271 | 1184 // printf("%d %d\n", s->avg_mb_var, s->mc_mb_var); |
| 1185 | |
| 0 | 1186 if (!s->fixed_qscale) |
| 1187 s->qscale = rate_estimate_qscale(s); | |
| 1188 | |
| 1189 /* precompute matrix */ | |
| 1190 if (s->out_format == FMT_MJPEG) { | |
| 1191 /* for mjpeg, we do include qscale in the matrix */ | |
| 1192 s->intra_matrix[0] = default_intra_matrix[0]; | |
| 1193 for(i=1;i<64;i++) | |
| 1194 s->intra_matrix[i] = (default_intra_matrix[i] * s->qscale) >> 3; | |
| 220 | 1195 convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, s->intra_matrix, 8); |
| 0 | 1196 } else { |
| 220 | 1197 convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, s->intra_matrix, s->qscale); |
| 1198 convert_matrix(s->q_non_intra_matrix, s->q_non_intra_matrix16, s->non_intra_matrix, s->qscale); | |
| 0 | 1199 } |
| 1200 | |
| 286 | 1201 s->last_bits= get_bit_count(&s->pb); |
| 0 | 1202 switch(s->out_format) { |
| 1203 case FMT_MJPEG: | |
| 1204 mjpeg_picture_header(s); | |
| 1205 break; | |
| 1206 case FMT_H263: | |
| 1207 if (s->h263_msmpeg4) | |
| 1208 msmpeg4_encode_picture_header(s, picture_number); | |
| 1209 else if (s->h263_pred) | |
| 1210 mpeg4_encode_picture_header(s, picture_number); | |
| 1211 else if (s->h263_rv10) | |
| 1212 rv10_encode_picture_header(s, picture_number); | |
| 1213 else | |
| 1214 h263_encode_picture_header(s, picture_number); | |
| 1215 break; | |
| 1216 case FMT_MPEG1: | |
| 1217 mpeg1_encode_picture_header(s, picture_number); | |
| 1218 break; | |
| 1219 } | |
| 286 | 1220 bits= get_bit_count(&s->pb); |
| 1221 s->header_bits= bits - s->last_bits; | |
| 1222 s->last_bits= bits; | |
| 1223 s->mv_bits=0; | |
| 1224 s->misc_bits=0; | |
| 1225 s->i_tex_bits=0; | |
| 1226 s->p_tex_bits=0; | |
| 1227 s->i_count=0; | |
| 1228 s->p_count=0; | |
| 1229 s->skip_count=0; | |
| 1230 | |
| 0 | 1231 /* init last dc values */ |
| 1232 /* note: quant matrix value (8) is implied here */ | |
| 1233 s->last_dc[0] = 128; | |
| 1234 s->last_dc[1] = 128; | |
| 1235 s->last_dc[2] = 128; | |
| 1236 s->mb_incr = 1; | |
| 1237 s->last_mv[0][0][0] = 0; | |
| 1238 s->last_mv[0][0][1] = 0; | |
| 1239 s->mv_type = MV_TYPE_16X16; | |
| 1240 s->mv_dir = MV_DIR_FORWARD; | |
| 1241 | |
| 162 | 1242 /* Get the GOB height based on picture height */ |
| 231 | 1243 if (s->out_format == FMT_H263 && !s->h263_pred && !s->h263_msmpeg4) { |
| 162 | 1244 if (s->height <= 400) |
| 1245 s->gob_index = 1; | |
| 1246 else if (s->height <= 800) | |
| 1247 s->gob_index = 2; | |
| 1248 else | |
| 1249 s->gob_index = 4; | |
| 1250 } | |
| 268 | 1251 |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1252 s->avg_mb_var = s->avg_mb_var / s->mb_num; |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1253 |
| 266 | 1254 s->block_wrap[0]= |
| 1255 s->block_wrap[1]= | |
| 1256 s->block_wrap[2]= | |
| 1257 s->block_wrap[3]= s->mb_width*2 + 2; | |
| 1258 s->block_wrap[4]= | |
| 1259 s->block_wrap[5]= s->mb_width + 2; | |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1260 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1261 /* Put GOB header based on RTP MTU */ |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1262 /* TODO: Put all this stuff in a separate generic function */ |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1263 if (s->rtp_mode) { |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1264 if (!mb_y) { |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1265 s->ptr_lastgob = s->pb.buf; |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1266 s->ptr_last_mb_line = s->pb.buf; |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1267 } else if (s->out_format == FMT_H263 && !s->h263_pred && !s->h263_msmpeg4 && !(mb_y % s->gob_index)) { |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1268 last_gob = h263_encode_gob_header(s, mb_y); |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1269 if (last_gob) { |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1270 s->first_gob_line = 1; |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1271 } |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1272 } |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1273 } |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1274 |
| 266 | 1275 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; |
| 1276 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
| 1277 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
| 1278 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
| 1279 s->block_index[4]= s->block_wrap[4]*(mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2); | |
| 1280 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
|
1281 for(mb_x=0; mb_x < s->mb_width; mb_x++) { |
| 0 | 1282 |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1283 s->mb_x = mb_x; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1284 s->mb_y = mb_y; |
| 266 | 1285 s->block_index[0]+=2; |
| 1286 s->block_index[1]+=2; | |
| 1287 s->block_index[2]+=2; | |
| 1288 s->block_index[3]+=2; | |
| 1289 s->block_index[4]++; | |
| 1290 s->block_index[5]++; | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1291 #if 0 |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1292 /* compute motion vector and macro block type (intra or non intra) */ |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1293 motion_x = 0; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1294 motion_y = 0; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1295 if (s->pict_type == P_TYPE) { |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1296 s->mb_intra = estimate_motion(s, mb_x, mb_y, |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1297 &motion_x, |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1298 &motion_y); |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1299 } else { |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1300 s->mb_intra = 1; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1301 } |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1302 #endif |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1303 |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1304 s->mb_intra = s->mb_type[mb_y * s->mb_width + mb_x]; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1305 motion_x = s->mv_table[0][mb_y * s->mb_width + mb_x]; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1306 motion_y = s->mv_table[1][mb_y * s->mb_width + mb_x]; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1307 |
| 0 | 1308 /* get the pixels */ |
| 1309 wrap = s->linesize; | |
| 1310 ptr = s->new_picture[0] + (mb_y * 16 * wrap) + mb_x * 16; | |
|
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
|
1311 get_pixels(s->block[0], ptr, wrap); |
|
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
|
1312 get_pixels(s->block[1], ptr + 8, wrap); |
|
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
|
1313 get_pixels(s->block[2], ptr + 8 * wrap, wrap); |
|
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
|
1314 get_pixels(s->block[3], ptr + 8 * wrap + 8, wrap); |
| 0 | 1315 wrap = s->linesize >> 1; |
| 1316 ptr = s->new_picture[1] + (mb_y * 8 * wrap) + mb_x * 8; | |
|
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
|
1317 get_pixels(s->block[4], ptr, wrap); |
| 0 | 1318 |
| 1319 wrap = s->linesize >> 1; | |
| 1320 ptr = s->new_picture[2] + (mb_y * 8 * wrap) + mb_x * 8; | |
|
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
|
1321 get_pixels(s->block[5], ptr, wrap); |
| 0 | 1322 |
| 1323 /* subtract previous frame if non intra */ | |
| 1324 if (!s->mb_intra) { | |
| 1325 int dxy, offset, mx, my; | |
| 1326 | |
| 1327 dxy = ((motion_y & 1) << 1) | (motion_x & 1); | |
| 1328 ptr = s->last_picture[0] + | |
| 1329 ((mb_y * 16 + (motion_y >> 1)) * s->linesize) + | |
| 1330 (mb_x * 16 + (motion_x >> 1)); | |
| 1331 | |
|
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
|
1332 sub_pixels_2(s->block[0], ptr, s->linesize, dxy); |
|
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
|
1333 sub_pixels_2(s->block[1], ptr + 8, s->linesize, dxy); |
|
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
|
1334 sub_pixels_2(s->block[2], ptr + s->linesize * 8, s->linesize, dxy); |
|
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
|
1335 sub_pixels_2(s->block[3], ptr + 8 + s->linesize * 8, s->linesize ,dxy); |
| 0 | 1336 |
| 1337 if (s->out_format == FMT_H263) { | |
| 1338 /* special rounding for h263 */ | |
| 1339 dxy = 0; | |
| 1340 if ((motion_x & 3) != 0) | |
| 1341 dxy |= 1; | |
| 1342 if ((motion_y & 3) != 0) | |
| 1343 dxy |= 2; | |
| 1344 mx = motion_x >> 2; | |
| 1345 my = motion_y >> 2; | |
| 1346 } else { | |
| 1347 mx = motion_x / 2; | |
| 1348 my = motion_y / 2; | |
| 1349 dxy = ((my & 1) << 1) | (mx & 1); | |
| 1350 mx >>= 1; | |
| 1351 my >>= 1; | |
| 1352 } | |
| 1353 offset = ((mb_y * 8 + my) * (s->linesize >> 1)) + (mb_x * 8 + mx); | |
| 1354 ptr = s->last_picture[1] + offset; | |
|
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
|
1355 sub_pixels_2(s->block[4], ptr, s->linesize >> 1, dxy); |
| 0 | 1356 ptr = s->last_picture[2] + offset; |
|
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
|
1357 sub_pixels_2(s->block[5], ptr, s->linesize >> 1, dxy); |
| 0 | 1358 } |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1359 emms_c(); |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1360 |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1361 #if 0 |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1362 { |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1363 float adap_parm; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1364 |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1365 adap_parm = ((s->avg_mb_var << 1) + s->mb_var[s->mb_width*mb_y+mb_x] + 1.0) / |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1366 ((s->mb_var[s->mb_width*mb_y+mb_x] << 1) + s->avg_mb_var + 1.0); |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1367 |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1368 printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d", |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1369 (s->mb_type[s->mb_width*mb_y+mb_x] > 0) ? 'I' : 'P', |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1370 s->qscale, adap_parm, s->qscale*adap_parm, |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1371 s->mb_var[s->mb_width*mb_y+mb_x], s->avg_mb_var); |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1372 } |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1373 #endif |
| 0 | 1374 /* DCT & quantize */ |
| 1375 if (s->h263_msmpeg4) { | |
| 1376 msmpeg4_dc_scale(s); | |
| 1377 } else if (s->h263_pred) { | |
| 1378 h263_dc_scale(s); | |
| 1379 } else { | |
| 1380 /* default quantization values */ | |
| 1381 s->y_dc_scale = 8; | |
| 1382 s->c_dc_scale = 8; | |
| 1383 } | |
| 1384 for(i=0;i<6;i++) { | |
| 220 | 1385 s->block_last_index[i] = dct_quantize(s, s->block[i], i, s->qscale); |
| 0 | 1386 } |
| 1387 | |
| 1388 /* huffman encode */ | |
| 1389 switch(s->out_format) { | |
| 1390 case FMT_MPEG1: | |
|
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
|
1391 mpeg1_encode_mb(s, s->block, motion_x, motion_y); |
| 0 | 1392 break; |
| 1393 case FMT_H263: | |
| 1394 if (s->h263_msmpeg4) | |
|
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
|
1395 msmpeg4_encode_mb(s, s->block, motion_x, motion_y); |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
262
diff
changeset
|
1396 else if(s->h263_pred) |
|
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
262
diff
changeset
|
1397 mpeg4_encode_mb(s, s->block, motion_x, motion_y); |
| 0 | 1398 else |
|
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
|
1399 h263_encode_mb(s, s->block, motion_x, motion_y); |
| 0 | 1400 break; |
| 1401 case FMT_MJPEG: | |
|
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
|
1402 mjpeg_encode_mb(s, s->block); |
| 0 | 1403 break; |
| 1404 } | |
| 286 | 1405 |
| 0 | 1406 /* decompress blocks so that we keep the state of the decoder */ |
| 1407 s->mv[0][0][0] = motion_x; | |
| 1408 s->mv[0][0][1] = motion_y; | |
| 1409 | |
|
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
|
1410 MPV_decode_mb(s, s->block); |
| 0 | 1411 } |
|
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
|
1412 |
|
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
|
1413 |
| 231 | 1414 /* Obtain average GOB size for RTP */ |
| 1415 if (s->rtp_mode) { | |
| 1416 if (!mb_y) | |
|
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
|
1417 s->mb_line_avgsize = pbBufPtr(&s->pb) - s->ptr_last_mb_line; |
| 231 | 1418 else if (!(mb_y % s->gob_index)) { |
|
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
|
1419 s->mb_line_avgsize = (s->mb_line_avgsize + pbBufPtr(&s->pb) - s->ptr_last_mb_line) >> 1; |
|
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
|
1420 s->ptr_last_mb_line = pbBufPtr(&s->pb); |
| 231 | 1421 } |
| 1422 //fprintf(stderr, "\nMB line: %d\tSize: %u\tAvg. Size: %u", s->mb_y, | |
| 1423 // (s->pb.buf_ptr - s->ptr_last_mb_line), s->mb_line_avgsize); | |
| 1424 s->first_gob_line = 0; | |
| 1425 } | |
| 0 | 1426 } |
| 286 | 1427 |
|
251
75091bfc577b
fixing msmpeg4 decoding if fps < 16 (i thought it was a indicator for the ext header, its the fps indeed)
michaelni
parents:
249
diff
changeset
|
1428 if (s->h263_msmpeg4 && s->pict_type == I_TYPE) |
| 208 | 1429 msmpeg4_encode_ext_header(s); |
| 1430 | |
| 162 | 1431 //if (s->gob_number) |
| 1432 // fprintf(stderr,"\nNumber of GOB: %d", s->gob_number); | |
| 231 | 1433 |
| 1434 /* Send the last GOB if RTP */ | |
| 1435 if (s->rtp_mode) { | |
| 1436 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
|
1437 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
| 231 | 1438 /* Call the RTP callback to send the last GOB */ |
| 1439 if (s->rtp_callback) | |
| 1440 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
|
1441 s->ptr_lastgob = pbBufPtr(&s->pb); |
| 231 | 1442 //fprintf(stderr,"\nGOB: %2d size: %d (last)", s->gob_number, pdif); |
| 1443 } | |
| 1444 | |
| 0 | 1445 } |
| 1446 | |
| 220 | 1447 static int dct_quantize_c(MpegEncContext *s, |
| 0 | 1448 DCTELEM *block, int n, |
| 1449 int qscale) | |
| 1450 { | |
| 1451 int i, j, level, last_non_zero, q; | |
| 1452 const int *qmat; | |
| 216 | 1453 int minLevel, maxLevel; |
| 1454 | |
| 1455 if(s->avctx!=NULL && s->avctx->codec->id==CODEC_ID_MPEG4){ | |
| 1456 /* mpeg4 */ | |
| 1457 minLevel= -2048; | |
| 1458 maxLevel= 2047; | |
| 1459 }else if(s->out_format==FMT_MPEG1){ | |
| 1460 /* mpeg1 */ | |
| 1461 minLevel= -255; | |
| 1462 maxLevel= 255; | |
| 230 | 1463 }else if(s->out_format==FMT_MJPEG){ |
| 1464 /* (m)jpeg */ | |
| 1465 minLevel= -1023; | |
| 1466 maxLevel= 1023; | |
| 216 | 1467 }else{ |
| 1468 /* h263 / msmpeg4 */ | |
| 1469 minLevel= -128; | |
| 1470 maxLevel= 127; | |
| 1471 } | |
| 0 | 1472 |
| 1473 av_fdct (block); | |
| 1474 | |
| 64 | 1475 /* we need this permutation so that we correct the IDCT |
| 1476 permutation. will be moved into DCT code */ | |
| 1477 block_permute(block); | |
| 1478 | |
| 0 | 1479 if (s->mb_intra) { |
| 1480 if (n < 4) | |
| 1481 q = s->y_dc_scale; | |
| 1482 else | |
| 1483 q = s->c_dc_scale; | |
| 1484 q = q << 3; | |
| 1485 | |
| 1486 /* note: block[0] is assumed to be positive */ | |
| 1487 block[0] = (block[0] + (q >> 1)) / q; | |
| 1488 i = 1; | |
| 1489 last_non_zero = 0; | |
| 1490 if (s->out_format == FMT_H263) { | |
| 1491 qmat = s->q_non_intra_matrix; | |
| 1492 } else { | |
| 1493 qmat = s->q_intra_matrix; | |
| 1494 } | |
| 1495 } else { | |
| 1496 i = 0; | |
| 1497 last_non_zero = -1; | |
| 1498 qmat = s->q_non_intra_matrix; | |
| 1499 } | |
| 1500 | |
| 1501 for(;i<64;i++) { | |
| 1502 j = zigzag_direct[i]; | |
| 1503 level = block[j]; | |
| 1504 level = level * qmat[j]; | |
| 1505 #ifdef PARANOID | |
| 1506 { | |
| 1507 static int count = 0; | |
| 1508 int level1, level2, qmat1; | |
| 1509 double val; | |
| 1510 if (qmat == s->q_non_intra_matrix) { | |
| 1511 qmat1 = default_non_intra_matrix[j] * s->qscale; | |
| 1512 } else { | |
| 1513 qmat1 = default_intra_matrix[j] * s->qscale; | |
| 1514 } | |
| 1515 if (av_fdct != jpeg_fdct_ifast) | |
| 1516 val = ((double)block[j] * 8.0) / (double)qmat1; | |
| 1517 else | |
| 1518 val = ((double)block[j] * 8.0 * 2048.0) / | |
| 1519 ((double)qmat1 * aanscales[j]); | |
| 1520 level1 = (int)val; | |
| 1521 level2 = level / (1 << (QMAT_SHIFT - 3)); | |
| 1522 if (level1 != level2) { | |
| 1523 fprintf(stderr, "%d: quant error qlevel=%d wanted=%d level=%d qmat1=%d qmat=%d wantedf=%0.6f\n", | |
| 1524 count, level2, level1, block[j], qmat1, qmat[j], | |
| 1525 val); | |
| 1526 count++; | |
| 1527 } | |
| 1528 | |
| 1529 } | |
| 1530 #endif | |
| 1531 /* XXX: slight error for the low range. Test should be equivalent to | |
| 1532 (level <= -(1 << (QMAT_SHIFT - 3)) || level >= (1 << | |
| 1533 (QMAT_SHIFT - 3))) | |
| 1534 */ | |
| 1535 if (((level << (31 - (QMAT_SHIFT - 3))) >> (31 - (QMAT_SHIFT - 3))) != | |
| 1536 level) { | |
| 1537 level = level / (1 << (QMAT_SHIFT - 3)); | |
| 1538 /* XXX: currently, this code is not optimal. the range should be: | |
| 1539 mpeg1: -255..255 | |
| 1540 mpeg2: -2048..2047 | |
| 1541 h263: -128..127 | |
| 1542 mpeg4: -2048..2047 | |
| 1543 */ | |
| 216 | 1544 if (level > maxLevel) |
| 1545 level = maxLevel; | |
| 1546 else if (level < minLevel) | |
| 1547 level = minLevel; | |
| 0 | 1548 |
| 1549 block[j] = level; | |
| 1550 last_non_zero = i; | |
| 1551 } else { | |
| 1552 block[j] = 0; | |
| 1553 } | |
| 1554 } | |
| 1555 return last_non_zero; | |
| 1556 } | |
| 1557 | |
|
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
|
1558 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
|
1559 DCTELEM *block, int n, int qscale) |
| 0 | 1560 { |
| 200 | 1561 int i, level, nCoeffs; |
| 0 | 1562 const UINT16 *quant_matrix; |
| 1563 | |
| 200 | 1564 if(s->alternate_scan) nCoeffs= 64; |
| 1565 else nCoeffs= s->block_last_index[n]+1; | |
| 1566 | |
| 0 | 1567 if (s->mb_intra) { |
| 1568 if (n < 4) | |
| 1569 block[0] = block[0] * s->y_dc_scale; | |
| 1570 else | |
| 1571 block[0] = block[0] * s->c_dc_scale; | |
| 1572 /* XXX: only mpeg1 */ | |
| 1573 quant_matrix = s->intra_matrix; | |
| 200 | 1574 for(i=1;i<nCoeffs;i++) { |
| 1575 int j= zigzag_direct[i]; | |
| 1576 level = block[j]; | |
| 0 | 1577 if (level) { |
| 1578 if (level < 0) { | |
| 1579 level = -level; | |
| 200 | 1580 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
| 0 | 1581 level = (level - 1) | 1; |
| 1582 level = -level; | |
| 1583 } else { | |
| 200 | 1584 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
| 0 | 1585 level = (level - 1) | 1; |
| 1586 } | |
| 1587 #ifdef PARANOID | |
| 1588 if (level < -2048 || level > 2047) | |
| 1589 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 1590 #endif | |
| 200 | 1591 block[j] = level; |
| 0 | 1592 } |
| 1593 } | |
| 1594 } else { | |
| 1595 i = 0; | |
| 1596 quant_matrix = s->non_intra_matrix; | |
| 217 | 1597 for(;i<nCoeffs;i++) { |
| 200 | 1598 int j= zigzag_direct[i]; |
| 1599 level = block[j]; | |
| 0 | 1600 if (level) { |
| 1601 if (level < 0) { | |
| 1602 level = -level; | |
| 1603 level = (((level << 1) + 1) * qscale * | |
| 200 | 1604 ((int) (quant_matrix[j]))) >> 4; |
| 0 | 1605 level = (level - 1) | 1; |
| 1606 level = -level; | |
| 1607 } else { | |
| 1608 level = (((level << 1) + 1) * qscale * | |
| 200 | 1609 ((int) (quant_matrix[j]))) >> 4; |
| 0 | 1610 level = (level - 1) | 1; |
| 1611 } | |
| 1612 #ifdef PARANOID | |
| 1613 if (level < -2048 || level > 2047) | |
| 1614 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 1615 #endif | |
| 200 | 1616 block[j] = level; |
| 0 | 1617 } |
| 1618 } | |
| 1619 } | |
| 1620 } | |
|
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
|
1621 |
|
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
|
1622 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
|
1623 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
|
1624 { |
|
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
|
1625 int i, level, qmul, qadd; |
| 200 | 1626 int nCoeffs; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1627 |
|
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
|
1628 if (s->mb_intra) { |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1629 if (!s->h263_aic) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1630 if (n < 4) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1631 block[0] = block[0] * s->y_dc_scale; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1632 else |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1633 block[0] = block[0] * s->c_dc_scale; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1634 } |
|
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
|
1635 i = 1; |
| 200 | 1636 nCoeffs= 64; //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
|
1637 } 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
|
1638 i = 0; |
| 200 | 1639 nCoeffs= zigzag_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
|
1640 } |
|
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
|
1641 |
|
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
|
1642 qmul = s->qscale << 1; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1643 if (s->h263_aic && s->mb_intra) |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1644 qadd = 0; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1645 else |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1646 qadd = (s->qscale - 1) | 1; |
|
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
|
1647 |
| 200 | 1648 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
|
1649 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
|
1650 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
|
1651 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
|
1652 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
|
1653 } 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
|
1654 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
|
1655 } |
|
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
|
1656 #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
|
1657 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
|
1658 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
|
1659 #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
|
1660 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
|
1661 } |
|
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
|
1662 } |
|
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
|
1663 } |
| 0 | 1664 |
| 1665 /* rate control */ | |
| 1666 | |
| 1667 /* an I frame is I_FRAME_SIZE_RATIO bigger than a P frame */ | |
| 1668 #define I_FRAME_SIZE_RATIO 3.0 | |
| 1669 #define QSCALE_K 20 | |
| 1670 | |
| 1671 static void rate_control_init(MpegEncContext *s) | |
| 1672 { | |
| 268 | 1673 #if 1 |
| 1674 emms_c(); | |
| 1675 | |
| 1676 //initial values, they dont really matter as they will be totally different within a few frames | |
| 1677 s->i_pred.coeff= s->p_pred.coeff= 7.0; | |
| 1678 s->i_pred.count= s->p_pred.count= 1.0; | |
| 1679 | |
| 1680 s->i_pred.decay= s->p_pred.decay= 0.4; | |
| 1681 | |
| 1682 // use more bits at the beginning, otherwise high motion at the begin will look like shit | |
| 1683 s->qsum=100; | |
| 1684 s->qcount=100; | |
| 1685 | |
| 1686 s->short_term_qsum=0.001; | |
| 1687 s->short_term_qcount=0.001; | |
| 1688 #else | |
| 0 | 1689 s->wanted_bits = 0; |
| 1690 | |
| 1691 if (s->intra_only) { | |
| 1692 s->I_frame_bits = ((INT64)s->bit_rate * FRAME_RATE_BASE) / s->frame_rate; | |
| 1693 s->P_frame_bits = s->I_frame_bits; | |
| 1694 } else { | |
| 1695 s->P_frame_bits = (int) ((float)(s->gop_size * s->bit_rate) / | |
| 1696 (float)((float)s->frame_rate / FRAME_RATE_BASE * (I_FRAME_SIZE_RATIO + s->gop_size - 1))); | |
| 1697 s->I_frame_bits = (int)(s->P_frame_bits * I_FRAME_SIZE_RATIO); | |
| 1698 } | |
| 268 | 1699 |
| 0 | 1700 #if defined(DEBUG) |
| 1701 printf("I_frame_size=%d P_frame_size=%d\n", | |
| 1702 s->I_frame_bits, s->P_frame_bits); | |
| 1703 #endif | |
| 268 | 1704 #endif |
| 1705 } | |
| 1706 | |
| 1707 static double predict(Predictor *p, double q, double var) | |
| 1708 { | |
| 1709 return p->coeff*var / (q*p->count); | |
| 1710 } | |
| 1711 | |
| 1712 static void update_predictor(Predictor *p, double q, double var, double size) | |
| 1713 { | |
| 1714 double new_coeff= size*q / (var + 1); | |
| 1715 if(var<1000) return; | |
| 1716 /*{ | |
| 1717 int pred= predict(p, q, var); | |
| 1718 int error= abs(pred-size); | |
| 1719 static double sum=0; | |
| 1720 static int count=0; | |
| 1721 if(count>5) sum+=error; | |
| 1722 count++; | |
| 1723 if(256*256*256*64%count==0){ | |
| 1724 printf("%d %f %f\n", count, sum/count, p->coeff); | |
| 1725 } | |
| 1726 }*/ | |
| 1727 p->count*= p->decay; | |
| 1728 p->coeff*= p->decay; | |
| 1729 p->count++; | |
| 1730 p->coeff+= new_coeff; | |
| 0 | 1731 } |
| 1732 | |
| 1733 static int rate_estimate_qscale(MpegEncContext *s) | |
| 1734 { | |
| 268 | 1735 #if 1 |
| 1736 int qmin= s->qmin; | |
| 1737 int qmax= s->qmax; | |
| 1738 int rate_q=5; | |
| 1739 float q; | |
| 1740 int qscale; | |
| 1741 float br_compensation; | |
| 1742 double diff; | |
| 1743 double short_term_q; | |
| 1744 double long_term_q; | |
| 1745 int last_qscale= s->qscale; | |
| 1746 double fps; | |
| 1747 INT64 wanted_bits; | |
| 1748 emms_c(); | |
| 1749 | |
| 1750 fps= (double)s->frame_rate / FRAME_RATE_BASE; | |
| 1751 wanted_bits= s->bit_rate*(double)s->picture_number/fps; | |
| 1752 | |
| 1753 | |
| 1754 if(s->picture_number>2){ | |
| 1755 /* update predictors */ | |
| 1756 if(s->last_pict_type == I_TYPE){ | |
| 1757 //FIXME | |
| 1758 }else{ //P Frame | |
| 1759 //printf("%d %d %d %f\n", s->qscale, s->last_mc_mb_var, s->frame_bits, s->p_pred.coeff); | |
| 1760 update_predictor(&s->p_pred, s->qscale, s->last_mc_mb_var, s->frame_bits); | |
| 1761 } | |
| 1762 } | |
| 1763 | |
| 1764 if(s->pict_type == I_TYPE){ | |
| 1765 //FIXME | |
| 1766 rate_q= s->qsum/s->qcount; | |
| 1767 }else{ //P Frame | |
| 1768 int i; | |
| 1769 int diff, best_diff=1000000000; | |
| 1770 for(i=1; i<=31; i++){ | |
| 1771 diff= predict(&s->p_pred, i, s->mc_mb_var) - (double)s->bit_rate/fps; | |
| 1772 if(diff<0) diff= -diff; | |
| 1773 if(diff<best_diff){ | |
| 1774 best_diff= diff; | |
| 1775 rate_q= i; | |
| 1776 } | |
| 1777 } | |
| 1778 } | |
| 1779 | |
| 1780 s->short_term_qsum*=s->qblur; | |
| 1781 s->short_term_qcount*=s->qblur; | |
| 1782 | |
| 1783 s->short_term_qsum+= rate_q; | |
| 1784 s->short_term_qcount++; | |
| 1785 short_term_q= s->short_term_qsum/s->short_term_qcount; | |
| 1786 | |
| 1787 long_term_q= s->qsum/s->qcount*s->total_bits/wanted_bits; | |
| 1788 | |
| 1789 // q= (long_term_q - short_term_q)*s->qcompress + short_term_q; | |
| 1790 q= 1/((1/long_term_q - 1/short_term_q)*s->qcompress + 1/short_term_q); | |
| 1791 | |
| 1792 diff= s->total_bits - wanted_bits; | |
| 1793 br_compensation= (s->bit_rate_tolerance - diff)/s->bit_rate_tolerance; | |
| 270 | 1794 if(br_compensation<=0.0) br_compensation=0.001; |
| 268 | 1795 q/=br_compensation; |
| 1796 | |
| 1797 qscale= (int)(q + 0.5); | |
| 1798 if (qscale<qmin) qscale=qmin; | |
| 1799 else if(qscale>qmax) qscale=qmax; | |
| 1800 | |
| 1801 if (qscale<last_qscale-s->max_qdiff) qscale=last_qscale-s->max_qdiff; | |
| 1802 else if(qscale>last_qscale+s->max_qdiff) qscale=last_qscale+s->max_qdiff; | |
| 1803 | |
| 1804 s->qsum+= qscale; | |
| 1805 s->qcount++; | |
| 1806 | |
| 1807 s->last_pict_type= s->pict_type; | |
| 1808 //printf("q:%d diff:%d comp:%f rate_q:%d st_q:%d fvar:%d last_size:%d\n", qscale, (int)diff, br_compensation, | |
| 1809 // rate_q, (int)short_term_q, s->mc_mb_var, s->frame_bits); | |
| 1810 //printf("%d %d\n", s->bit_rate, (int)fps); | |
| 1811 return qscale; | |
| 1812 #else | |
|
187
3f3b14d3a23d
qscale estimate fix, diff extended to 64bit wide. patch by Stephen Davies <steve@daviesfam.org>
arpi_esp
parents:
178
diff
changeset
|
1813 INT64 diff, total_bits = s->total_bits; |
| 0 | 1814 float q; |
| 268 | 1815 int qscale; |
| 0 | 1816 if (s->pict_type == I_TYPE) { |
| 1817 s->wanted_bits += s->I_frame_bits; | |
| 1818 } else { | |
| 1819 s->wanted_bits += s->P_frame_bits; | |
| 1820 } | |
| 1821 diff = s->wanted_bits - total_bits; | |
| 1822 q = 31.0 - (float)diff / (QSCALE_K * s->mb_height * s->mb_width); | |
| 1823 /* adjust for I frame */ | |
| 1824 if (s->pict_type == I_TYPE && !s->intra_only) { | |
| 1825 q /= I_FRAME_SIZE_RATIO; | |
| 1826 } | |
| 1827 | |
| 1828 /* using a too small Q scale leeds to problems in mpeg1 and h263 | |
| 1829 because AC coefficients are clamped to 255 or 127 */ | |
| 1830 qmin = 3; | |
| 1831 if (q < qmin) | |
| 1832 q = qmin; | |
| 1833 else if (q > 31) | |
| 1834 q = 31; | |
| 1835 qscale = (int)(q + 0.5); | |
| 1836 #if defined(DEBUG) | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1837 printf("\n%d: total=%0.0f wanted=%0.0f br=%0.1f diff=%d qest=%2.1f\n", |
| 0 | 1838 s->picture_number, |
| 64 | 1839 (double)total_bits, |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1840 (double)s->wanted_bits, |
| 0 | 1841 (float)s->frame_rate / FRAME_RATE_BASE * |
| 1842 total_bits / s->picture_number, | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1843 (int)diff, q); |
| 0 | 1844 #endif |
| 1845 return qscale; | |
| 268 | 1846 #endif |
| 0 | 1847 } |
| 1848 | |
| 1849 AVCodec mpeg1video_encoder = { | |
| 1850 "mpeg1video", | |
| 1851 CODEC_TYPE_VIDEO, | |
| 1852 CODEC_ID_MPEG1VIDEO, | |
| 1853 sizeof(MpegEncContext), | |
| 1854 MPV_encode_init, | |
| 1855 MPV_encode_picture, | |
| 1856 MPV_encode_end, | |
| 1857 }; | |
| 1858 | |
| 1859 AVCodec h263_encoder = { | |
| 1860 "h263", | |
| 1861 CODEC_TYPE_VIDEO, | |
| 1862 CODEC_ID_H263, | |
| 1863 sizeof(MpegEncContext), | |
| 1864 MPV_encode_init, | |
| 1865 MPV_encode_picture, | |
| 1866 MPV_encode_end, | |
| 1867 }; | |
| 1868 | |
| 1869 AVCodec h263p_encoder = { | |
| 1870 "h263p", | |
| 1871 CODEC_TYPE_VIDEO, | |
| 1872 CODEC_ID_H263P, | |
| 1873 sizeof(MpegEncContext), | |
| 1874 MPV_encode_init, | |
| 1875 MPV_encode_picture, | |
| 1876 MPV_encode_end, | |
| 1877 }; | |
| 1878 | |
| 1879 AVCodec rv10_encoder = { | |
| 1880 "rv10", | |
| 1881 CODEC_TYPE_VIDEO, | |
| 1882 CODEC_ID_RV10, | |
| 1883 sizeof(MpegEncContext), | |
| 1884 MPV_encode_init, | |
| 1885 MPV_encode_picture, | |
| 1886 MPV_encode_end, | |
| 1887 }; | |
| 1888 | |
| 1889 AVCodec mjpeg_encoder = { | |
| 1890 "mjpeg", | |
| 1891 CODEC_TYPE_VIDEO, | |
| 1892 CODEC_ID_MJPEG, | |
| 1893 sizeof(MpegEncContext), | |
| 1894 MPV_encode_init, | |
| 1895 MPV_encode_picture, | |
| 1896 MPV_encode_end, | |
| 1897 }; | |
| 1898 | |
| 71 | 1899 AVCodec mpeg4_encoder = { |
| 1900 "mpeg4", | |
| 0 | 1901 CODEC_TYPE_VIDEO, |
| 71 | 1902 CODEC_ID_MPEG4, |
| 0 | 1903 sizeof(MpegEncContext), |
| 1904 MPV_encode_init, | |
| 1905 MPV_encode_picture, | |
| 1906 MPV_encode_end, | |
| 1907 }; | |
| 1908 | |
| 1909 AVCodec msmpeg4_encoder = { | |
| 1910 "msmpeg4", | |
| 1911 CODEC_TYPE_VIDEO, | |
| 1912 CODEC_ID_MSMPEG4, | |
| 1913 sizeof(MpegEncContext), | |
| 1914 MPV_encode_init, | |
| 1915 MPV_encode_picture, | |
| 1916 MPV_encode_end, | |
| 1917 }; |
