Mercurial > libavcodec.hg
annotate mpegvideo.c @ 329:5cc47d0ba53e libavcodec
fixed ratecontrol & b-frames
2pass ratecontrol
fixed hq with 2pass
inceased build num (a few more vars for the rc stuff)
hopefully no new bugs
| author | michaelni |
|---|---|
| date | Sun, 21 Apr 2002 21:18:17 +0000 |
| parents | d359db02fc90 |
| children | 8aa87f1dfc52 |
| 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. | |
| 295 | 18 * |
| 325 | 19 * 4MV & hq & b-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at> |
| 0 | 20 */ |
| 21 #include <stdlib.h> | |
| 22 #include <stdio.h> | |
| 23 #include <math.h> | |
| 24 #include <string.h> | |
| 25 #include "avcodec.h" | |
| 26 #include "dsputil.h" | |
| 27 #include "mpegvideo.h" | |
| 28 | |
|
17
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
29 #ifdef USE_FASTMEMCPY |
|
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
30 #include "fastmemcpy.h" |
|
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
31 #endif |
|
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
32 |
|
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
|
33 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
|
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); |
| 325 | 36 static void dct_unquantize_mpeg2_c(MpegEncContext *s, |
| 37 DCTELEM *block, int n, int qscale); | |
|
13
174ef88f619a
use block[] in structure to have it aligned on 8 bytes for mmx optimizations - dct_unquantize is always a function pointer - added specialized dct_unquantize_h263
glantau
parents:
8
diff
changeset
|
38 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
|
39 DCTELEM *block, int n, int qscale); |
| 206 | 40 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w); |
| 220 | 41 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale); |
| 206 | 42 |
| 220 | 43 int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale)= dct_quantize_c; |
| 206 | 44 void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w)= draw_edges_c; |
| 45 | |
| 0 | 46 #define EDGE_WIDTH 16 |
| 47 | |
| 48 /* enable all paranoid tests for rounding, overflows, etc... */ | |
| 49 //#define PARANOID | |
| 50 | |
| 51 //#define DEBUG | |
| 52 | |
| 321 | 53 |
| 0 | 54 /* for jpeg fast DCT */ |
| 55 #define CONST_BITS 14 | |
| 56 | |
| 57 static const unsigned short aanscales[64] = { | |
| 58 /* precomputed values scaled up by 14 bits */ | |
| 59 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
| 60 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, | |
| 61 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, | |
| 62 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, | |
| 63 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
| 64 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | |
| 65 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, | |
| 66 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 | |
| 67 }; | |
| 68 | |
| 69 static UINT8 h263_chroma_roundtab[16] = { | |
| 70 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, | |
| 71 }; | |
| 72 | |
|
292
73a9ce3d9715
fcode_tables where too small, found by Klaas-Pieter Vlieg <vlieg@eurescom.de>
michaelni
parents:
288
diff
changeset
|
73 static UINT16 default_mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
74 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
|
75 |
| 321 | 76 extern UINT8 zigzag_end[64]; |
| 77 | |
| 0 | 78 /* default motion estimation */ |
| 321 | 79 int motion_estimation_method = ME_EPZS; |
| 200 | 80 |
| 220 | 81 static void convert_matrix(int *qmat, UINT16 *qmat16, const UINT16 *quant_matrix, int qscale) |
| 0 | 82 { |
| 83 int i; | |
| 84 | |
| 85 if (av_fdct == jpeg_fdct_ifast) { | |
| 86 for(i=0;i<64;i++) { | |
| 87 /* 16 <= qscale * quant_matrix[i] <= 7905 */ | |
| 220 | 88 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ |
| 89 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ | |
| 90 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ | |
| 0 | 91 |
| 220 | 92 qmat[block_permute_op(i)] = (int)((UINT64_C(1) << (QMAT_SHIFT + 11)) / |
| 93 (aanscales[i] * qscale * quant_matrix[block_permute_op(i)])); | |
| 0 | 94 } |
| 95 } else { | |
| 96 for(i=0;i<64;i++) { | |
| 97 /* We can safely suppose that 16 <= quant_matrix[i] <= 255 | |
| 220 | 98 So 16 <= qscale * quant_matrix[i] <= 7905 |
| 99 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 | |
| 100 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 | |
| 0 | 101 */ |
| 220 | 102 qmat[i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); |
| 103 qmat16[i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[block_permute_op(i)]); | |
| 0 | 104 } |
| 105 } | |
| 106 } | |
| 107 | |
| 108 /* init common structure for both encoder and decoder */ | |
| 109 int MPV_common_init(MpegEncContext *s) | |
| 110 { | |
| 111 int c_size, i; | |
| 112 UINT8 *pict; | |
| 113 | |
| 312 | 114 s->dct_unquantize_h263 = dct_unquantize_h263_c; |
| 325 | 115 s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_c; |
| 116 s->dct_unquantize_mpeg2 = dct_unquantize_mpeg2_c; | |
|
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
|
117 |
|
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
|
118 #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
|
119 MPV_common_init_mmx(s); |
| 8 | 120 #endif |
| 312 | 121 //setup default unquantizers (mpeg4 might change it later) |
| 122 if(s->out_format == FMT_H263) | |
| 123 s->dct_unquantize = s->dct_unquantize_h263; | |
| 124 else | |
| 325 | 125 s->dct_unquantize = s->dct_unquantize_mpeg1; |
| 312 | 126 |
| 0 | 127 s->mb_width = (s->width + 15) / 16; |
| 128 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
|
129 s->mb_num = s->mb_width * s->mb_height; |
| 0 | 130 s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH; |
| 131 | |
| 132 for(i=0;i<3;i++) { | |
| 133 int w, h, shift, pict_start; | |
| 134 | |
| 135 w = s->linesize; | |
| 136 h = s->mb_height * 16 + 2 * EDGE_WIDTH; | |
| 137 shift = (i == 0) ? 0 : 1; | |
| 138 c_size = (w >> shift) * (h >> shift); | |
| 139 pict_start = (w >> shift) * (EDGE_WIDTH >> shift) + (EDGE_WIDTH >> shift); | |
| 140 | |
| 141 pict = av_mallocz(c_size); | |
| 142 if (pict == NULL) | |
| 143 goto fail; | |
| 144 s->last_picture_base[i] = pict; | |
| 145 s->last_picture[i] = pict + pict_start; | |
| 146 | |
| 147 pict = av_mallocz(c_size); | |
| 148 if (pict == NULL) | |
| 149 goto fail; | |
| 150 s->next_picture_base[i] = pict; | |
| 151 s->next_picture[i] = pict + pict_start; | |
| 324 | 152 |
| 0 | 153 if (s->has_b_frames) { |
| 154 pict = av_mallocz(c_size); | |
| 155 if (pict == NULL) | |
| 156 goto fail; | |
| 157 s->aux_picture_base[i] = pict; | |
| 158 s->aux_picture[i] = pict + pict_start; | |
| 159 } | |
| 160 } | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
161 |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
162 if (s->encoding) { |
| 324 | 163 int j; |
| 164 int mv_table_size= (s->mb_width+2)*(s->mb_height+2); | |
| 165 | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
166 /* Allocate MB type table */ |
| 239 | 167 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
|
168 if (s->mb_type == NULL) { |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
169 perror("malloc"); |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
170 goto fail; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
171 } |
| 239 | 172 |
| 173 s->mb_var = av_mallocz(s->mb_num * sizeof(INT16)); | |
| 174 if (s->mb_var == NULL) { | |
| 175 perror("malloc"); | |
| 176 goto fail; | |
| 177 } | |
| 324 | 178 |
| 179 /* Allocate MV tables */ | |
| 180 s->p_mv_table = av_mallocz(mv_table_size * 2 * sizeof(INT16)); | |
| 181 if (s->p_mv_table == NULL) { | |
| 182 perror("malloc"); | |
| 183 goto fail; | |
| 184 } | |
| 185 s->last_p_mv_table = av_mallocz(mv_table_size * 2 * sizeof(INT16)); | |
| 186 if (s->last_p_mv_table == NULL) { | |
| 187 perror("malloc"); | |
| 188 goto fail; | |
| 189 } | |
| 190 s->b_forw_mv_table = av_mallocz(mv_table_size * 2 * sizeof(INT16)); | |
| 191 if (s->b_forw_mv_table == NULL) { | |
| 192 perror("malloc"); | |
| 193 goto fail; | |
| 194 } | |
| 195 s->b_back_mv_table = av_mallocz(mv_table_size * 2 * sizeof(INT16)); | |
| 196 if (s->b_back_mv_table == NULL) { | |
| 197 perror("malloc"); | |
| 198 goto fail; | |
| 199 } | |
| 200 s->b_bidir_forw_mv_table = av_mallocz(mv_table_size * 2 * sizeof(INT16)); | |
| 201 if (s->b_bidir_forw_mv_table == NULL) { | |
| 202 perror("malloc"); | |
| 203 goto fail; | |
| 204 } | |
| 205 s->b_bidir_back_mv_table = av_mallocz(mv_table_size * 2 * sizeof(INT16)); | |
| 206 if (s->b_bidir_back_mv_table == NULL) { | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
207 perror("malloc"); |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
208 goto fail; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
209 } |
| 324 | 210 s->b_direct_forw_mv_table = av_mallocz(mv_table_size * 2 * sizeof(INT16)); |
| 211 if (s->b_direct_forw_mv_table == NULL) { | |
| 212 perror("malloc"); | |
| 213 goto fail; | |
| 214 } | |
| 215 s->b_direct_back_mv_table = av_mallocz(mv_table_size * 2 * sizeof(INT16)); | |
| 216 if (s->b_direct_back_mv_table == NULL) { | |
| 217 perror("malloc"); | |
| 218 goto fail; | |
| 219 } | |
| 220 s->b_direct_mv_table = av_mallocz(mv_table_size * 2 * sizeof(INT16)); | |
| 221 if (s->b_direct_mv_table == NULL) { | |
| 222 perror("malloc"); | |
| 223 goto fail; | |
| 224 } | |
| 225 | |
| 327 | 226 s->me_scratchpad = av_mallocz( s->linesize*16*3*sizeof(uint8_t)); |
| 227 if (s->me_scratchpad == NULL) { | |
| 228 perror("malloc"); | |
| 229 goto fail; | |
| 230 } | |
| 231 | |
| 324 | 232 if(s->max_b_frames){ |
| 233 for(j=0; j<REORDER_BUFFER_SIZE; j++){ | |
| 234 int i; | |
| 235 for(i=0;i<3;i++) { | |
| 236 int w, h, shift; | |
| 237 | |
| 238 w = s->linesize; | |
| 239 h = s->mb_height * 16; | |
| 240 shift = (i == 0) ? 0 : 1; | |
| 241 c_size = (w >> shift) * (h >> shift); | |
| 242 | |
| 243 pict = av_mallocz(c_size); | |
| 244 if (pict == NULL) | |
| 245 goto fail; | |
| 246 s->picture_buffer[j][i] = pict; | |
| 247 } | |
| 248 } | |
| 249 } | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
250 } |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
251 |
| 288 | 252 if (s->out_format == FMT_H263 || s->encoding) { |
| 0 | 253 int size; |
| 254 /* MV prediction */ | |
| 255 size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | |
| 256 s->motion_val = malloc(size * 2 * sizeof(INT16)); | |
| 257 if (s->motion_val == NULL) | |
| 258 goto fail; | |
| 259 memset(s->motion_val, 0, size * 2 * sizeof(INT16)); | |
| 260 } | |
| 261 | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
262 if (s->h263_pred || s->h263_plus) { |
| 0 | 263 int y_size, c_size, i, size; |
| 264 | |
| 265 /* dc values */ | |
| 266 | |
| 267 y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | |
| 268 c_size = (s->mb_width + 2) * (s->mb_height + 2); | |
| 269 size = y_size + 2 * c_size; | |
| 270 s->dc_val[0] = malloc(size * sizeof(INT16)); | |
| 271 if (s->dc_val[0] == NULL) | |
| 272 goto fail; | |
| 273 s->dc_val[1] = s->dc_val[0] + y_size; | |
| 274 s->dc_val[2] = s->dc_val[1] + c_size; | |
| 275 for(i=0;i<size;i++) | |
| 276 s->dc_val[0][i] = 1024; | |
| 277 | |
| 278 /* ac values */ | |
| 279 s->ac_val[0] = av_mallocz(size * sizeof(INT16) * 16); | |
| 280 if (s->ac_val[0] == NULL) | |
| 281 goto fail; | |
| 282 s->ac_val[1] = s->ac_val[0] + y_size; | |
| 283 s->ac_val[2] = s->ac_val[1] + c_size; | |
| 284 | |
| 285 /* cbp values */ | |
| 286 s->coded_block = av_mallocz(y_size); | |
| 287 if (!s->coded_block) | |
| 288 goto fail; | |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
289 |
|
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
290 /* 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
|
291 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
|
292 if (!s->mbintra_table) |
|
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
293 goto fail; |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
294 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
|
295 } |
| 0 | 296 /* default structure is frame */ |
| 297 s->picture_structure = PICT_FRAME; | |
| 298 | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
299 /* init macroblock skip table */ |
| 324 | 300 s->mbskip_table = av_mallocz(s->mb_num); |
| 301 if (!s->mbskip_table) | |
| 302 goto fail; | |
| 294 | 303 |
| 327 | 304 s->block= s->blocks[0]; |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
305 |
| 0 | 306 s->context_initialized = 1; |
| 307 return 0; | |
| 308 fail: | |
| 244 | 309 MPV_common_end(s); |
| 310 return -1; | |
| 311 } | |
| 312 | |
| 324 | 313 #define CHECK_FREE(p)\ |
| 314 {\ | |
| 315 if(p) free(p);\ | |
| 316 p= NULL;\ | |
| 317 } | |
| 318 | |
| 244 | 319 /* init common structure for both encoder and decoder */ |
| 320 void MPV_common_end(MpegEncContext *s) | |
| 321 { | |
| 322 int i; | |
| 323 | |
| 324 | 324 CHECK_FREE(s->mb_type); |
| 325 CHECK_FREE(s->mb_var); | |
| 326 CHECK_FREE(s->p_mv_table); | |
| 327 CHECK_FREE(s->last_p_mv_table); | |
| 328 CHECK_FREE(s->b_forw_mv_table); | |
| 329 CHECK_FREE(s->b_back_mv_table); | |
| 330 CHECK_FREE(s->b_bidir_forw_mv_table); | |
| 331 CHECK_FREE(s->b_bidir_back_mv_table); | |
| 332 CHECK_FREE(s->b_direct_forw_mv_table); | |
| 333 CHECK_FREE(s->b_direct_back_mv_table); | |
| 334 CHECK_FREE(s->b_direct_mv_table); | |
| 335 CHECK_FREE(s->motion_val); | |
| 336 CHECK_FREE(s->dc_val[0]); | |
| 337 CHECK_FREE(s->ac_val[0]); | |
| 338 CHECK_FREE(s->coded_block); | |
| 339 CHECK_FREE(s->mbintra_table); | |
| 327 | 340 CHECK_FREE(s->me_scratchpad); |
| 244 | 341 |
| 324 | 342 CHECK_FREE(s->mbskip_table); |
| 0 | 343 for(i=0;i<3;i++) { |
| 324 | 344 int j; |
| 345 CHECK_FREE(s->last_picture_base[i]); | |
| 346 CHECK_FREE(s->next_picture_base[i]); | |
| 347 CHECK_FREE(s->aux_picture_base[i]); | |
| 348 for(j=0; j<REORDER_BUFFER_SIZE; j++){ | |
| 349 CHECK_FREE(s->picture_buffer[j][i]); | |
| 350 } | |
| 0 | 351 } |
| 352 s->context_initialized = 0; | |
| 353 } | |
| 354 | |
| 355 /* init video encoder */ | |
| 356 int MPV_encode_init(AVCodecContext *avctx) | |
| 357 { | |
| 358 MpegEncContext *s = avctx->priv_data; | |
| 60 | 359 int i; |
| 0 | 360 |
| 315 | 361 avctx->pix_fmt = PIX_FMT_YUV420P; |
| 362 | |
| 0 | 363 s->bit_rate = avctx->bit_rate; |
| 268 | 364 s->bit_rate_tolerance = avctx->bit_rate_tolerance; |
| 0 | 365 s->frame_rate = avctx->frame_rate; |
| 366 s->width = avctx->width; | |
| 367 s->height = avctx->height; | |
| 368 s->gop_size = avctx->gop_size; | |
| 162 | 369 s->rtp_mode = avctx->rtp_mode; |
| 370 s->rtp_payload_size = avctx->rtp_payload_size; | |
| 231 | 371 if (avctx->rtp_callback) |
| 372 s->rtp_callback = avctx->rtp_callback; | |
| 268 | 373 s->qmin= avctx->qmin; |
| 374 s->qmax= avctx->qmax; | |
| 375 s->max_qdiff= avctx->max_qdiff; | |
| 376 s->qcompress= avctx->qcompress; | |
| 377 s->qblur= avctx->qblur; | |
| 329 | 378 s->b_quant_factor= avctx->b_quant_factor; |
|
194
27d1773552c9
mpeg4 encoder fix by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
191
diff
changeset
|
379 s->avctx = avctx; |
|
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
380 s->aspect_ratio_info= avctx->aspect_ratio_info; |
| 294 | 381 s->flags= avctx->flags; |
| 324 | 382 s->max_b_frames= avctx->max_b_frames; |
| 329 | 383 s->rc_strategy= avctx->rc_strategy; |
| 384 s->b_frame_strategy= avctx->b_frame_strategy; | |
| 162 | 385 |
| 0 | 386 if (s->gop_size <= 1) { |
| 387 s->intra_only = 1; | |
| 388 s->gop_size = 12; | |
| 389 } else { | |
| 390 s->intra_only = 0; | |
| 391 } | |
|
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
392 |
|
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
393 /* ME algorithm */ |
| 321 | 394 if (avctx->me_method == 0) |
| 395 /* For compatibility */ | |
| 396 s->me_method = motion_estimation_method; | |
| 397 else | |
| 398 s->me_method = avctx->me_method; | |
| 399 | |
|
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
400 /* Fixed QSCALE */ |
| 0 | 401 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
|
402 |
| 0 | 403 switch(avctx->codec->id) { |
| 404 case CODEC_ID_MPEG1VIDEO: | |
| 405 s->out_format = FMT_MPEG1; | |
| 406 break; | |
| 407 case CODEC_ID_MJPEG: | |
| 408 s->out_format = FMT_MJPEG; | |
| 409 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
|
410 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
|
411 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
|
412 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
|
413 s->mjpeg_vsample[2] = 1; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
414 s->mjpeg_hsample[0] = 2; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
415 s->mjpeg_hsample[1] = 1; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
416 s->mjpeg_hsample[2] = 1; |
| 0 | 417 if (mjpeg_init(s) < 0) |
| 418 return -1; | |
| 419 break; | |
| 420 case CODEC_ID_H263: | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
421 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
|
422 printf("Input picture size isn't suitable for h263 codec! try h263+\n"); |
| 0 | 423 return -1; |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
424 } |
| 0 | 425 s->out_format = FMT_H263; |
| 426 break; | |
| 427 case CODEC_ID_H263P: | |
| 428 s->out_format = FMT_H263; | |
| 162 | 429 s->rtp_mode = 1; |
| 430 s->rtp_payload_size = 1200; | |
| 0 | 431 s->h263_plus = 1; |
| 78 | 432 s->unrestricted_mv = 1; |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
433 |
|
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
434 /* These are just to be sure */ |
|
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
435 s->umvplus = 0; |
|
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
436 s->umvplus_dec = 0; |
| 0 | 437 break; |
| 438 case CODEC_ID_RV10: | |
| 439 s->out_format = FMT_H263; | |
| 440 s->h263_rv10 = 1; | |
| 441 break; | |
| 71 | 442 case CODEC_ID_MPEG4: |
| 0 | 443 s->out_format = FMT_H263; |
| 444 s->h263_pred = 1; | |
| 445 s->unrestricted_mv = 1; | |
| 324 | 446 s->has_b_frames= s->max_b_frames ? 1 : 0; |
| 0 | 447 break; |
| 307 | 448 case CODEC_ID_MSMPEG4V1: |
| 0 | 449 s->out_format = FMT_H263; |
| 450 s->h263_msmpeg4 = 1; | |
| 451 s->h263_pred = 1; | |
| 452 s->unrestricted_mv = 1; | |
| 307 | 453 s->msmpeg4_version= 1; |
| 454 break; | |
| 455 case CODEC_ID_MSMPEG4V2: | |
| 456 s->out_format = FMT_H263; | |
| 457 s->h263_msmpeg4 = 1; | |
| 458 s->h263_pred = 1; | |
| 459 s->unrestricted_mv = 1; | |
| 460 s->msmpeg4_version= 2; | |
| 461 break; | |
| 462 case CODEC_ID_MSMPEG4V3: | |
| 463 s->out_format = FMT_H263; | |
| 464 s->h263_msmpeg4 = 1; | |
| 465 s->h263_pred = 1; | |
| 466 s->unrestricted_mv = 1; | |
| 467 s->msmpeg4_version= 3; | |
| 0 | 468 break; |
| 469 default: | |
| 470 return -1; | |
| 471 } | |
| 295 | 472 |
| 473 if((s->flags&CODEC_FLAG_4MV) && !(s->flags&CODEC_FLAG_HQ)){ | |
| 474 printf("4MV is currently only supported in HQ mode\n"); | |
| 475 return -1; | |
| 476 } | |
| 0 | 477 |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
478 { /* 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
|
479 static int done=0; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
480 if(!done){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
481 int i; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
482 done=1; |
|
292
73a9ce3d9715
fcode_tables where too small, found by Klaas-Pieter Vlieg <vlieg@eurescom.de>
michaelni
parents:
288
diff
changeset
|
483 memset(default_mv_penalty, 0, sizeof(UINT16)*(MAX_FCODE+1)*(2*MAX_MV+1)); |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
484 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
|
485 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
486 for(i=-16; i<16; i++){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
487 default_fcode_tab[i + MAX_MV]= 1; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
488 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
489 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
490 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
491 s->mv_penalty= default_mv_penalty; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
492 s->fcode_tab= default_fcode_tab; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
493 |
| 0 | 494 if (s->out_format == FMT_H263) |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
495 h263_encode_init(s); |
|
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
496 else if (s->out_format == FMT_MPEG1) |
|
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
497 mpeg1_encode_init(s); |
| 0 | 498 |
| 287 | 499 /* dont use mv_penalty table for crap MV as it would be confused */ |
| 324 | 500 if (s->me_method < ME_EPZS) s->mv_penalty = default_mv_penalty; |
| 287 | 501 |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
502 s->encoding = 1; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
503 |
| 0 | 504 /* init */ |
| 505 if (MPV_common_init(s) < 0) | |
| 506 return -1; | |
| 507 | |
| 60 | 508 /* init default q matrix */ |
| 509 for(i=0;i<64;i++) { | |
| 510 s->intra_matrix[i] = default_intra_matrix[i]; | |
| 511 s->non_intra_matrix[i] = default_non_intra_matrix[i]; | |
| 512 } | |
| 513 | |
| 329 | 514 if(ff_rate_control_init(s) < 0) |
| 515 return -1; | |
| 0 | 516 |
| 517 s->picture_number = 0; | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
518 s->picture_in_gop_number = 0; |
| 0 | 519 s->fake_picture_number = 0; |
| 520 /* motion detector init */ | |
| 521 s->f_code = 1; | |
| 324 | 522 s->b_code = 1; |
| 0 | 523 |
| 524 return 0; | |
| 525 } | |
| 526 | |
| 527 int MPV_encode_end(AVCodecContext *avctx) | |
| 528 { | |
| 529 MpegEncContext *s = avctx->priv_data; | |
| 530 | |
| 531 #ifdef STATS | |
| 532 print_stats(); | |
| 533 #endif | |
| 329 | 534 |
| 535 ff_rate_control_uninit(s); | |
| 536 | |
| 0 | 537 MPV_common_end(s); |
| 538 if (s->out_format == FMT_MJPEG) | |
| 539 mjpeg_close(s); | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
540 |
| 0 | 541 return 0; |
| 542 } | |
| 543 | |
| 544 /* draw the edges of width 'w' of an image of size width, height */ | |
| 206 | 545 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w) |
| 0 | 546 { |
| 547 UINT8 *ptr, *last_line; | |
| 548 int i; | |
| 549 | |
| 550 last_line = buf + (height - 1) * wrap; | |
| 551 for(i=0;i<w;i++) { | |
| 552 /* top and bottom */ | |
| 553 memcpy(buf - (i + 1) * wrap, buf, width); | |
| 554 memcpy(last_line + (i + 1) * wrap, last_line, width); | |
| 555 } | |
| 556 /* left and right */ | |
| 557 ptr = buf; | |
| 558 for(i=0;i<height;i++) { | |
| 559 memset(ptr - w, ptr[0], w); | |
| 560 memset(ptr + width, ptr[width-1], w); | |
| 561 ptr += wrap; | |
| 562 } | |
| 563 /* corners */ | |
| 564 for(i=0;i<w;i++) { | |
| 565 memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */ | |
| 566 memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */ | |
| 567 memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */ | |
| 568 memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */ | |
| 569 } | |
| 570 } | |
| 571 | |
| 572 /* generic function for encode/decode called before a frame is coded/decoded */ | |
| 573 void MPV_frame_start(MpegEncContext *s) | |
| 574 { | |
| 575 int i; | |
| 576 UINT8 *tmp; | |
| 577 | |
|
46
931417475f5b
fixed mpeg1 first block bug (pb with black picture optimisation for B frames)
glantau
parents:
40
diff
changeset
|
578 s->mb_skiped = 0; |
| 0 | 579 if (s->pict_type == B_TYPE) { |
| 580 for(i=0;i<3;i++) { | |
| 581 s->current_picture[i] = s->aux_picture[i]; | |
| 582 } | |
| 583 } else { | |
| 584 for(i=0;i<3;i++) { | |
| 585 /* swap next and last */ | |
| 586 tmp = s->last_picture[i]; | |
| 587 s->last_picture[i] = s->next_picture[i]; | |
| 588 s->next_picture[i] = tmp; | |
| 589 s->current_picture[i] = tmp; | |
| 590 } | |
| 591 } | |
| 592 } | |
|
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
|
593 |
| 0 | 594 /* generic function for encode/decode called after a frame has been coded/decoded */ |
| 595 void MPV_frame_end(MpegEncContext *s) | |
| 596 { | |
| 597 /* draw edge for correct motion prediction if outside */ | |
| 220 | 598 if (s->pict_type != B_TYPE && !s->intra_only) { |
| 257 | 599 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
|
600 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
|
601 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
|
602 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
|
603 }else{ |
| 257 | 604 /* mpeg4? / opendivx / xvid */ |
| 0 | 605 draw_edges(s->current_picture[0], s->linesize, s->width, s->height, EDGE_WIDTH); |
| 606 draw_edges(s->current_picture[1], s->linesize/2, s->width/2, s->height/2, EDGE_WIDTH/2); | |
| 607 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
|
608 } |
| 0 | 609 } |
| 207 | 610 emms_c(); |
| 329 | 611 |
| 612 if(s->pict_type!=B_TYPE){ | |
| 613 s->last_non_b_pict_type= s->pict_type; | |
| 614 s->last_non_b_qscale= s->qscale; | |
| 615 s->last_non_b_mc_mb_var= s->mc_mb_var; | |
| 616 } | |
| 0 | 617 } |
| 618 | |
| 324 | 619 /* reorder input for encoding */ |
| 620 void reorder_input(MpegEncContext *s, AVPicture *pict) | |
| 621 { | |
| 622 int i, j, index; | |
| 623 | |
| 624 if(s->max_b_frames > FF_MAX_B_FRAMES) s->max_b_frames= FF_MAX_B_FRAMES; | |
| 625 | |
| 626 // delay= s->max_b_frames+1; (or 0 if no b frames cuz decoder diff) | |
| 627 | |
| 628 for(j=0; j<REORDER_BUFFER_SIZE-1; j++){ | |
| 629 s->coded_order[j]= s->coded_order[j+1]; | |
| 630 } | |
| 631 s->coded_order[j].picture[0]= s->coded_order[j].picture[1]= s->coded_order[j].picture[2]= NULL; //catch uninitalized buffers | |
| 632 | |
| 633 switch(s->input_pict_type){ | |
| 634 default: | |
| 635 case I_TYPE: | |
| 636 case S_TYPE: | |
| 637 case P_TYPE: | |
| 638 index= s->max_b_frames - s->b_frames_since_non_b; | |
| 639 s->b_frames_since_non_b=0; | |
| 640 break; | |
| 641 case B_TYPE: | |
| 642 index= s->max_b_frames + 1; | |
| 643 s->b_frames_since_non_b++; | |
| 644 break; | |
| 645 } | |
| 646 //printf("index:%d type:%d strides: %d %d\n", index, s->input_pict_type, pict->linesize[0], s->linesize); | |
| 647 if( (index==0 || (s->flags&CODEC_FLAG_INPUT_PRESERVED)) | |
| 648 && pict->linesize[0] == s->linesize | |
| 649 && pict->linesize[1] == s->linesize>>1 | |
| 650 && pict->linesize[2] == s->linesize>>1){ | |
| 651 //printf("ptr\n"); | |
| 652 for(i=0; i<3; i++){ | |
| 653 s->coded_order[index].picture[i]= pict->data[i]; | |
| 654 } | |
| 655 }else{ | |
| 656 //printf("copy\n"); | |
| 657 for(i=0; i<3; i++){ | |
| 658 uint8_t *src = pict->data[i]; | |
| 659 uint8_t *dest; | |
| 660 int src_wrap = pict->linesize[i]; | |
| 661 int dest_wrap = s->linesize; | |
| 662 int w = s->width; | |
| 663 int h = s->height; | |
| 664 | |
| 665 if(index==0) dest= s->last_picture[i]+16; //is current_picture indeed but the switch hapens after reordering | |
| 666 else dest= s->picture_buffer[s->picture_buffer_index][i]; | |
| 667 | |
| 668 if (i >= 1) { | |
| 669 dest_wrap >>= 1; | |
| 670 w >>= 1; | |
| 671 h >>= 1; | |
| 672 } | |
| 673 | |
| 674 s->coded_order[index].picture[i]= dest; | |
| 675 for(j=0;j<h;j++) { | |
| 676 memcpy(dest, src, w); | |
| 677 dest += dest_wrap; | |
| 678 src += src_wrap; | |
| 679 } | |
| 680 } | |
| 681 if(index!=0){ | |
| 682 s->picture_buffer_index++; | |
| 683 if(s->picture_buffer_index >= REORDER_BUFFER_SIZE-1) s->picture_buffer_index=0; | |
| 684 } | |
| 685 } | |
| 686 s->coded_order[index].pict_type = s->input_pict_type; | |
| 687 s->coded_order[index].qscale = s->input_qscale; | |
| 688 s->coded_order[index].force_type= s->force_input_type; | |
| 689 s->coded_order[index].picture_in_gop_number= s->input_picture_in_gop_number; | |
| 690 s->coded_order[index].picture_number= s->input_picture_number; | |
| 691 | |
| 692 for(i=0; i<3; i++){ | |
| 693 s->new_picture[i]= s->coded_order[0].picture[i]; | |
| 694 } | |
| 695 } | |
| 696 | |
| 0 | 697 int MPV_encode_picture(AVCodecContext *avctx, |
| 698 unsigned char *buf, int buf_size, void *data) | |
| 699 { | |
| 700 MpegEncContext *s = avctx->priv_data; | |
| 701 AVPicture *pict = data; | |
| 702 | |
| 324 | 703 s->input_qscale = avctx->quality; |
| 0 | 704 |
| 705 init_put_bits(&s->pb, buf, buf_size, NULL, NULL); | |
| 706 | |
| 329 | 707 if(avctx->flags&CODEC_FLAG_TYPE){ |
| 708 s->input_pict_type= | |
| 709 s->force_input_type= avctx->key_frame ? I_TYPE : P_TYPE; | |
| 710 }else if(s->flags&CODEC_FLAG_PASS2){ | |
| 711 s->input_pict_type= | |
| 712 s->force_input_type= s->rc_context.entry[s->input_picture_number].new_pict_type; | |
| 713 }else{ | |
| 714 s->force_input_type=0; | |
| 715 if (!s->intra_only) { | |
| 716 /* first picture of GOP is intra */ | |
| 717 if (s->input_picture_in_gop_number % s->gop_size==0){ | |
| 718 s->input_pict_type = I_TYPE; | |
| 719 }else if(s->max_b_frames==0){ | |
| 720 s->input_pict_type = P_TYPE; | |
| 721 }else{ | |
| 722 if(s->b_frames_since_non_b < s->max_b_frames) //FIXME more IQ | |
| 723 s->input_pict_type = B_TYPE; | |
| 724 else | |
| 725 s->input_pict_type = P_TYPE; | |
| 726 } | |
| 727 } else { | |
| 324 | 728 s->input_pict_type = I_TYPE; |
| 729 } | |
| 0 | 730 } |
| 731 | |
| 329 | 732 if(s->input_pict_type==I_TYPE) |
| 733 s->input_picture_in_gop_number=0; | |
| 734 | |
| 324 | 735 reorder_input(s, pict); |
| 736 | |
| 737 /* output? */ | |
| 738 if(s->coded_order[0].picture[0]){ | |
| 739 | |
| 740 s->pict_type= s->coded_order[0].pict_type; | |
| 741 if (s->fixed_qscale) /* the ratecontrol needs the last qscale so we dont touch it for CBR */ | |
| 742 s->qscale= s->coded_order[0].qscale; | |
| 743 s->force_type= s->coded_order[0].force_type; | |
| 744 s->picture_in_gop_number= s->coded_order[0].picture_in_gop_number; | |
| 745 s->picture_number= s->coded_order[0].picture_number; | |
| 746 | |
| 747 MPV_frame_start(s); | |
| 286 | 748 |
| 324 | 749 encode_picture(s, s->picture_number); |
| 750 avctx->key_frame = (s->pict_type == I_TYPE); | |
| 751 avctx->header_bits = s->header_bits; | |
| 752 avctx->mv_bits = s->mv_bits; | |
| 753 avctx->misc_bits = s->misc_bits; | |
| 754 avctx->i_tex_bits = s->i_tex_bits; | |
| 755 avctx->p_tex_bits = s->p_tex_bits; | |
| 756 avctx->i_count = s->i_count; | |
| 757 avctx->p_count = s->p_count; | |
| 758 avctx->skip_count = s->skip_count; | |
| 0 | 759 |
| 324 | 760 MPV_frame_end(s); |
| 761 | |
| 762 if (s->out_format == FMT_MJPEG) | |
| 763 mjpeg_picture_trailer(s); | |
| 764 | |
| 765 avctx->quality = s->qscale; | |
| 329 | 766 |
| 767 if(s->flags&CODEC_FLAG_PASS1) | |
| 768 ff_write_pass1_stats(s); | |
| 324 | 769 } |
| 770 | |
| 771 s->input_picture_number++; | |
| 772 s->input_picture_in_gop_number++; | |
| 0 | 773 |
| 774 flush_put_bits(&s->pb); | |
| 268 | 775 s->frame_bits = (pbBufPtr(&s->pb) - s->pb.buf) * 8; |
| 329 | 776 if(s->pict_type==B_TYPE) s->pb_frame_bits+= s->frame_bits; |
| 777 else s->pb_frame_bits= s->frame_bits; | |
| 778 | |
| 268 | 779 s->total_bits += s->frame_bits; |
| 286 | 780 avctx->frame_bits = s->frame_bits; |
| 781 //printf("fcode: %d, type: %d, head: %d, mv: %d, misc: %d, frame: %d, itex: %d, ptex: %d\n", | |
| 782 //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
|
783 |
|
252
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
784 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
|
785 /* 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
|
786 /* 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
|
787 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
|
788 pict->linesize, s->linesize, avctx); |
| 324 | 789 // printf("%f\n", avctx->psnr_y); |
|
252
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
790 } |
|
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
|
791 return pbBufPtr(&s->pb) - s->pb.buf; |
| 0 | 792 } |
| 793 | |
| 255 | 794 static inline void gmc1_motion(MpegEncContext *s, |
| 795 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 796 int dest_offset, | |
| 797 UINT8 **ref_picture, int src_offset, | |
| 798 int h) | |
| 799 { | |
| 800 UINT8 *ptr; | |
| 324 | 801 int offset, src_x, src_y, linesize; |
| 255 | 802 int motion_x, motion_y; |
| 803 | |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
262
diff
changeset
|
804 if(s->real_sprite_warping_points>1) printf("more than 1 warp point isnt supported\n"); |
| 255 | 805 motion_x= s->sprite_offset[0][0]; |
| 806 motion_y= s->sprite_offset[0][1]; | |
| 807 src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
| 808 src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
| 809 motion_x<<=(3-s->sprite_warping_accuracy); | |
| 810 motion_y<<=(3-s->sprite_warping_accuracy); | |
| 811 src_x = clip(src_x, -16, s->width); | |
| 812 if (src_x == s->width) | |
| 813 motion_x =0; | |
| 814 src_y = clip(src_y, -16, s->height); | |
| 815 if (src_y == s->height) | |
| 816 motion_y =0; | |
| 817 | |
| 818 linesize = s->linesize; | |
| 819 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; | |
| 820 | |
| 821 dest_y+=dest_offset; | |
| 822 gmc1(dest_y , ptr , linesize, h, motion_x&15, motion_y&15, s->no_rounding); | |
| 823 gmc1(dest_y+8, ptr+8, linesize, h, motion_x&15, motion_y&15, s->no_rounding); | |
| 824 | |
| 825 motion_x= s->sprite_offset[1][0]; | |
| 826 motion_y= s->sprite_offset[1][1]; | |
| 827 src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
| 828 src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
| 829 motion_x<<=(3-s->sprite_warping_accuracy); | |
| 830 motion_y<<=(3-s->sprite_warping_accuracy); | |
| 831 src_x = clip(src_x, -8, s->width>>1); | |
| 832 if (src_x == s->width>>1) | |
| 833 motion_x =0; | |
| 834 src_y = clip(src_y, -8, s->height>>1); | |
| 835 if (src_y == s->height>>1) | |
| 836 motion_y =0; | |
| 837 | |
| 838 offset = (src_y * linesize>>1) + src_x + (src_offset>>1); | |
| 839 ptr = ref_picture[1] + offset; | |
| 840 gmc1(dest_cb + (dest_offset>>1), ptr, linesize>>1, h>>1, motion_x&15, motion_y&15, s->no_rounding); | |
| 841 ptr = ref_picture[2] + offset; | |
| 842 gmc1(dest_cr + (dest_offset>>1), ptr, linesize>>1, h>>1, motion_x&15, motion_y&15, s->no_rounding); | |
| 843 | |
| 844 return; | |
| 845 } | |
| 846 | |
| 0 | 847 /* apply one mpeg motion vector to the three components */ |
| 848 static inline void mpeg_motion(MpegEncContext *s, | |
| 849 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 850 int dest_offset, | |
| 851 UINT8 **ref_picture, int src_offset, | |
| 852 int field_based, op_pixels_func *pix_op, | |
| 853 int motion_x, int motion_y, int h) | |
| 854 { | |
| 855 UINT8 *ptr; | |
| 856 int dxy, offset, mx, my, src_x, src_y, height, linesize; | |
| 255 | 857 if(s->quarter_sample) |
| 858 { | |
| 859 motion_x>>=1; | |
| 860 motion_y>>=1; | |
| 861 } | |
| 324 | 862 |
| 0 | 863 dxy = ((motion_y & 1) << 1) | (motion_x & 1); |
| 864 src_x = s->mb_x * 16 + (motion_x >> 1); | |
| 865 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1); | |
| 866 | |
| 867 /* WARNING: do no forget half pels */ | |
| 868 height = s->height >> field_based; | |
| 869 src_x = clip(src_x, -16, s->width); | |
| 870 if (src_x == s->width) | |
| 871 dxy &= ~1; | |
| 872 src_y = clip(src_y, -16, height); | |
| 873 if (src_y == height) | |
| 874 dxy &= ~2; | |
| 875 linesize = s->linesize << field_based; | |
| 876 ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset; | |
| 877 dest_y += dest_offset; | |
| 878 pix_op[dxy](dest_y, ptr, linesize, h); | |
| 879 pix_op[dxy](dest_y + 8, ptr + 8, linesize, h); | |
| 880 | |
| 881 if (s->out_format == FMT_H263) { | |
| 882 dxy = 0; | |
| 883 if ((motion_x & 3) != 0) | |
| 884 dxy |= 1; | |
| 885 if ((motion_y & 3) != 0) | |
| 886 dxy |= 2; | |
| 887 mx = motion_x >> 2; | |
| 888 my = motion_y >> 2; | |
| 889 } else { | |
| 890 mx = motion_x / 2; | |
| 891 my = motion_y / 2; | |
| 892 dxy = ((my & 1) << 1) | (mx & 1); | |
| 893 mx >>= 1; | |
| 894 my >>= 1; | |
| 895 } | |
| 896 | |
| 897 src_x = s->mb_x * 8 + mx; | |
| 898 src_y = s->mb_y * (8 >> field_based) + my; | |
| 899 src_x = clip(src_x, -8, s->width >> 1); | |
| 900 if (src_x == (s->width >> 1)) | |
| 901 dxy &= ~1; | |
| 902 src_y = clip(src_y, -8, height >> 1); | |
| 903 if (src_y == (height >> 1)) | |
| 904 dxy &= ~2; | |
| 905 | |
| 906 offset = (src_y * (linesize >> 1)) + src_x + (src_offset >> 1); | |
| 907 ptr = ref_picture[1] + offset; | |
| 908 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); | |
| 909 ptr = ref_picture[2] + offset; | |
| 910 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); | |
| 911 } | |
| 912 | |
| 255 | 913 static inline void qpel_motion(MpegEncContext *s, |
| 914 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 915 int dest_offset, | |
| 916 UINT8 **ref_picture, int src_offset, | |
| 917 int field_based, op_pixels_func *pix_op, | |
| 918 qpel_mc_func *qpix_op, | |
| 919 int motion_x, int motion_y, int h) | |
| 920 { | |
| 921 UINT8 *ptr; | |
| 922 int dxy, offset, mx, my, src_x, src_y, height, linesize; | |
| 923 | |
| 924 dxy = ((motion_y & 3) << 2) | (motion_x & 3); | |
| 925 src_x = s->mb_x * 16 + (motion_x >> 2); | |
| 926 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); | |
| 927 | |
| 928 height = s->height >> field_based; | |
| 929 src_x = clip(src_x, -16, s->width); | |
| 930 if (src_x == s->width) | |
| 931 dxy &= ~3; | |
| 932 src_y = clip(src_y, -16, height); | |
| 933 if (src_y == height) | |
| 934 dxy &= ~12; | |
| 935 linesize = s->linesize << field_based; | |
| 936 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; | |
| 937 dest_y += dest_offset; | |
| 938 //printf("%d %d %d\n", src_x, src_y, dxy); | |
| 939 qpix_op[dxy](dest_y , ptr , linesize, linesize, motion_x&3, motion_y&3); | |
| 940 qpix_op[dxy](dest_y + 8, ptr + 8, linesize, linesize, motion_x&3, motion_y&3); | |
| 941 qpix_op[dxy](dest_y + linesize*8 , ptr + linesize*8 , linesize, linesize, motion_x&3, motion_y&3); | |
| 942 qpix_op[dxy](dest_y + linesize*8 + 8, ptr + linesize*8 + 8, linesize, linesize, motion_x&3, motion_y&3); | |
| 943 | |
| 944 mx= (motion_x>>1) | (motion_x&1); | |
| 945 my= (motion_y>>1) | (motion_y&1); | |
| 946 | |
| 947 dxy = 0; | |
| 948 if ((mx & 3) != 0) | |
| 949 dxy |= 1; | |
| 950 if ((my & 3) != 0) | |
| 951 dxy |= 2; | |
| 952 mx = mx >> 2; | |
| 953 my = my >> 2; | |
| 954 | |
| 955 src_x = s->mb_x * 8 + mx; | |
| 956 src_y = s->mb_y * (8 >> field_based) + my; | |
| 957 src_x = clip(src_x, -8, s->width >> 1); | |
| 958 if (src_x == (s->width >> 1)) | |
| 959 dxy &= ~1; | |
| 960 src_y = clip(src_y, -8, height >> 1); | |
| 961 if (src_y == (height >> 1)) | |
| 962 dxy &= ~2; | |
| 963 | |
| 964 offset = (src_y * (linesize >> 1)) + src_x + (src_offset >> 1); | |
| 965 ptr = ref_picture[1] + offset; | |
| 966 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); | |
| 967 ptr = ref_picture[2] + offset; | |
| 968 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); | |
| 969 } | |
| 970 | |
| 971 | |
| 0 | 972 static inline void MPV_motion(MpegEncContext *s, |
| 973 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 974 int dir, UINT8 **ref_picture, | |
| 255 | 975 op_pixels_func *pix_op, qpel_mc_func *qpix_op) |
| 0 | 976 { |
| 977 int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y; | |
| 978 int mb_x, mb_y, i; | |
| 979 UINT8 *ptr, *dest; | |
| 980 | |
| 981 mb_x = s->mb_x; | |
| 982 mb_y = s->mb_y; | |
| 983 | |
| 984 switch(s->mv_type) { | |
| 985 case MV_TYPE_16X16: | |
| 255 | 986 if(s->mcsel){ |
| 987 #if 0 | |
| 988 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 989 ref_picture, 0, | |
| 990 0, pix_op, | |
| 991 s->sprite_offset[0][0]>>3, | |
| 992 s->sprite_offset[0][1]>>3, | |
| 993 16); | |
| 994 #else | |
| 995 gmc1_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 996 ref_picture, 0, | |
| 997 16); | |
| 998 #endif | |
| 262 | 999 }else if(s->quarter_sample && dir==0){ //FIXME |
| 255 | 1000 qpel_motion(s, dest_y, dest_cb, dest_cr, 0, |
| 1001 ref_picture, 0, | |
| 1002 0, pix_op, qpix_op, | |
| 1003 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
| 1004 }else{ | |
| 1005 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 1006 ref_picture, 0, | |
| 1007 0, pix_op, | |
| 1008 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
| 1009 } | |
| 0 | 1010 break; |
| 1011 case MV_TYPE_8X8: | |
| 1012 for(i=0;i<4;i++) { | |
| 1013 motion_x = s->mv[dir][i][0]; | |
| 1014 motion_y = s->mv[dir][i][1]; | |
| 1015 | |
| 1016 dxy = ((motion_y & 1) << 1) | (motion_x & 1); | |
| 1017 src_x = mb_x * 16 + (motion_x >> 1) + (i & 1) * 8; | |
| 295 | 1018 src_y = mb_y * 16 + (motion_y >> 1) + (i >>1) * 8; |
| 0 | 1019 |
| 1020 /* WARNING: do no forget half pels */ | |
| 1021 src_x = clip(src_x, -16, s->width); | |
| 1022 if (src_x == s->width) | |
| 1023 dxy &= ~1; | |
| 1024 src_y = clip(src_y, -16, s->height); | |
| 1025 if (src_y == s->height) | |
| 1026 dxy &= ~2; | |
| 1027 | |
| 1028 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); | |
| 1029 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; | |
| 1030 pix_op[dxy](dest, ptr, s->linesize, 8); | |
| 1031 } | |
| 1032 /* In case of 8X8, we construct a single chroma motion vector | |
| 1033 with a special rounding */ | |
| 1034 mx = 0; | |
| 1035 my = 0; | |
| 1036 for(i=0;i<4;i++) { | |
| 1037 mx += s->mv[dir][i][0]; | |
| 1038 my += s->mv[dir][i][1]; | |
| 1039 } | |
| 1040 if (mx >= 0) | |
| 1041 mx = (h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1)); | |
| 1042 else { | |
| 1043 mx = -mx; | |
| 1044 mx = -(h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1)); | |
| 1045 } | |
| 1046 if (my >= 0) | |
| 1047 my = (h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1)); | |
| 1048 else { | |
| 1049 my = -my; | |
| 1050 my = -(h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1)); | |
| 1051 } | |
| 1052 dxy = ((my & 1) << 1) | (mx & 1); | |
| 1053 mx >>= 1; | |
| 1054 my >>= 1; | |
| 1055 | |
| 1056 src_x = mb_x * 8 + mx; | |
| 1057 src_y = mb_y * 8 + my; | |
| 1058 src_x = clip(src_x, -8, s->width/2); | |
| 1059 if (src_x == s->width/2) | |
| 1060 dxy &= ~1; | |
| 1061 src_y = clip(src_y, -8, s->height/2); | |
| 1062 if (src_y == s->height/2) | |
| 1063 dxy &= ~2; | |
| 1064 | |
| 1065 offset = (src_y * (s->linesize >> 1)) + src_x; | |
| 1066 ptr = ref_picture[1] + offset; | |
| 1067 pix_op[dxy](dest_cb, ptr, s->linesize >> 1, 8); | |
| 1068 ptr = ref_picture[2] + offset; | |
| 1069 pix_op[dxy](dest_cr, ptr, s->linesize >> 1, 8); | |
| 1070 break; | |
| 1071 case MV_TYPE_FIELD: | |
| 1072 if (s->picture_structure == PICT_FRAME) { | |
| 1073 /* top field */ | |
| 1074 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 1075 ref_picture, s->field_select[dir][0] ? s->linesize : 0, | |
| 1076 1, pix_op, | |
| 1077 s->mv[dir][0][0], s->mv[dir][0][1], 8); | |
| 1078 /* bottom field */ | |
| 1079 mpeg_motion(s, dest_y, dest_cb, dest_cr, s->linesize, | |
| 1080 ref_picture, s->field_select[dir][1] ? s->linesize : 0, | |
| 1081 1, pix_op, | |
| 1082 s->mv[dir][1][0], s->mv[dir][1][1], 8); | |
| 1083 } else { | |
| 1084 | |
| 1085 | |
| 1086 } | |
| 1087 break; | |
| 1088 } | |
| 1089 } | |
| 1090 | |
| 1091 | |
| 1092 /* put block[] to dest[] */ | |
| 1093 static inline void put_dct(MpegEncContext *s, | |
| 1094 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
| 1095 { | |
| 1096 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
|
1097 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
|
1098 ff_idct (block); |
| 0 | 1099 put_pixels_clamped(block, dest, line_size); |
| 1100 } | |
| 1101 | |
| 1102 /* add block[] to dest[] */ | |
| 1103 static inline void add_dct(MpegEncContext *s, | |
| 1104 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
| 1105 { | |
| 1106 if (s->block_last_index[i] >= 0) { | |
| 1107 if (!s->mpeg2) | |
| 206 | 1108 if(s->encoding || (!s->h263_msmpeg4)) |
| 200 | 1109 s->dct_unquantize(s, block, i, s->qscale); |
| 324 | 1110 |
|
19
82d4c9be9873
MMX/MMXEXT iDCT support, using external functions currently defined in libmpeg2
arpi_esp
parents:
18
diff
changeset
|
1111 ff_idct (block); |
| 0 | 1112 add_pixels_clamped(block, dest, line_size); |
| 1113 } | |
| 1114 } | |
| 1115 | |
| 1116 /* generic function called after a macroblock has been parsed by the | |
| 1117 decoder or after it has been encoded by the encoder. | |
| 1118 | |
| 1119 Important variables used: | |
| 1120 s->mb_intra : true if intra macroblock | |
| 1121 s->mv_dir : motion vector direction | |
| 1122 s->mv_type : motion vector type | |
| 1123 s->mv : motion vector | |
| 1124 s->interlaced_dct : true if interlaced dct used (mpeg2) | |
| 1125 */ | |
| 1126 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) | |
| 1127 { | |
| 244 | 1128 int mb_x, mb_y; |
| 0 | 1129 int dct_linesize, dct_offset; |
| 1130 op_pixels_func *op_pix; | |
| 255 | 1131 qpel_mc_func *op_qpix; |
| 0 | 1132 |
| 1133 mb_x = s->mb_x; | |
| 1134 mb_y = s->mb_y; | |
| 1135 | |
|
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1136 #ifdef FF_POSTPROCESS |
|
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1137 quant_store[mb_y][mb_x]=s->qscale; |
|
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1138 //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
|
1139 #endif |
|
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1140 |
| 0 | 1141 /* update DC predictors for P macroblocks */ |
| 1142 if (!s->mb_intra) { | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1143 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
|
1144 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
|
1145 { |
| 244 | 1146 int wrap, xy, v; |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
1147 s->mbintra_table[mb_x + mb_y*s->mb_width]=0; |
| 0 | 1148 wrap = 2 * s->mb_width + 2; |
| 244 | 1149 xy = 2 * mb_x + 1 + (2 * mb_y + 1) * wrap; |
| 0 | 1150 v = 1024; |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
1151 |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1152 s->dc_val[0][xy] = v; |
| 244 | 1153 s->dc_val[0][xy + 1] = v; |
| 1154 s->dc_val[0][xy + wrap] = v; | |
| 1155 s->dc_val[0][xy + 1 + wrap] = v; | |
| 0 | 1156 /* ac pred */ |
| 244 | 1157 memset(s->ac_val[0][xy], 0, 16 * sizeof(INT16)); |
| 1158 memset(s->ac_val[0][xy + 1], 0, 16 * sizeof(INT16)); | |
| 1159 memset(s->ac_val[0][xy + wrap], 0, 16 * sizeof(INT16)); | |
| 1160 memset(s->ac_val[0][xy + 1 + wrap], 0, 16 * sizeof(INT16)); | |
| 0 | 1161 if (s->h263_msmpeg4) { |
| 244 | 1162 s->coded_block[xy] = 0; |
| 1163 s->coded_block[xy + 1] = 0; | |
| 1164 s->coded_block[xy + wrap] = 0; | |
| 1165 s->coded_block[xy + 1 + wrap] = 0; | |
| 0 | 1166 } |
| 1167 /* chroma */ | |
| 1168 wrap = s->mb_width + 2; | |
| 244 | 1169 xy = mb_x + 1 + (mb_y + 1) * wrap; |
| 1170 s->dc_val[1][xy] = v; | |
| 1171 s->dc_val[2][xy] = v; | |
| 0 | 1172 /* ac pred */ |
| 244 | 1173 memset(s->ac_val[1][xy], 0, 16 * sizeof(INT16)); |
| 1174 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
|
1175 } |
| 0 | 1176 } else { |
| 1177 s->last_dc[0] = 128 << s->intra_dc_precision; | |
| 1178 s->last_dc[1] = 128 << s->intra_dc_precision; | |
| 1179 s->last_dc[2] = 128 << s->intra_dc_precision; | |
| 1180 } | |
| 1181 } | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1182 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
|
1183 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
|
1184 |
| 280 | 1185 /* update motion predictor, not for B-frames as they need the motion_val from the last P/S-Frame */ |
| 324 | 1186 if (s->out_format == FMT_H263) { //FIXME move into h263.c if possible, format specific stuff shouldnt be here |
| 262 | 1187 if(s->pict_type!=B_TYPE){ |
| 244 | 1188 int xy, wrap, motion_x, motion_y; |
| 0 | 1189 |
| 1190 wrap = 2 * s->mb_width + 2; | |
| 244 | 1191 xy = 2 * mb_x + 1 + (2 * mb_y + 1) * wrap; |
| 0 | 1192 if (s->mb_intra) { |
| 1193 motion_x = 0; | |
| 1194 motion_y = 0; | |
| 1195 goto motion_init; | |
| 1196 } else if (s->mv_type == MV_TYPE_16X16) { | |
| 1197 motion_x = s->mv[0][0][0]; | |
| 1198 motion_y = s->mv[0][0][1]; | |
| 1199 motion_init: | |
| 1200 /* no update if 8X8 because it has been done during parsing */ | |
| 244 | 1201 s->motion_val[xy][0] = motion_x; |
| 1202 s->motion_val[xy][1] = motion_y; | |
| 1203 s->motion_val[xy + 1][0] = motion_x; | |
| 1204 s->motion_val[xy + 1][1] = motion_y; | |
| 1205 s->motion_val[xy + wrap][0] = motion_x; | |
| 1206 s->motion_val[xy + wrap][1] = motion_y; | |
| 1207 s->motion_val[xy + 1 + wrap][0] = motion_x; | |
| 1208 s->motion_val[xy + 1 + wrap][1] = motion_y; | |
| 0 | 1209 } |
| 262 | 1210 } |
| 0 | 1211 } |
| 1212 | |
| 324 | 1213 if (!(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { |
| 0 | 1214 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
|
1215 UINT8 *mbskip_ptr; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1216 |
| 324 | 1217 /* avoid copy if macroblock skipped in last frame too |
| 1218 dont touch it for B-frames as they need the skip info from the next p-frame */ | |
| 1219 if (s->pict_type != B_TYPE) { | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1220 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
|
1221 if (s->mb_skiped) { |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1222 s->mb_skiped = 0; |
| 324 | 1223 /* if previous was skipped too, then nothing to do ! |
| 1224 skip only during decoding as we might trash the buffers during encoding a bit */ | |
| 1225 if (*mbskip_ptr != 0 && !s->encoding) | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1226 goto the_end; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1227 *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
|
1228 } else { |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1229 *mbskip_ptr = 0; /* not skipped */ |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1230 } |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1231 } |
| 0 | 1232 |
| 1233 dest_y = s->current_picture[0] + (mb_y * 16 * s->linesize) + mb_x * 16; | |
| 1234 dest_cb = s->current_picture[1] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; | |
| 1235 dest_cr = s->current_picture[2] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; | |
| 1236 | |
| 1237 if (s->interlaced_dct) { | |
| 1238 dct_linesize = s->linesize * 2; | |
| 1239 dct_offset = s->linesize; | |
| 1240 } else { | |
| 1241 dct_linesize = s->linesize; | |
| 1242 dct_offset = s->linesize * 8; | |
| 1243 } | |
| 1244 | |
| 1245 if (!s->mb_intra) { | |
| 1246 /* motion handling */ | |
| 324 | 1247 if((s->flags&CODEC_FLAG_HQ) || (!s->encoding)){ |
| 327 | 1248 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
| 324 | 1249 op_pix = put_pixels_tab; |
| 1250 op_qpix= qpel_mc_rnd_tab; | |
| 1251 }else{ | |
| 1252 op_pix = put_no_rnd_pixels_tab; | |
| 1253 op_qpix= qpel_mc_no_rnd_tab; | |
| 1254 } | |
| 0 | 1255 |
| 324 | 1256 if (s->mv_dir & MV_DIR_FORWARD) { |
| 1257 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); | |
| 327 | 1258 if ((!s->no_rounding) || s->pict_type==B_TYPE) |
| 324 | 1259 op_pix = avg_pixels_tab; |
| 1260 else | |
| 1261 op_pix = avg_no_rnd_pixels_tab; | |
| 1262 } | |
| 1263 if (s->mv_dir & MV_DIR_BACKWARD) { | |
| 1264 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); | |
| 1265 } | |
| 0 | 1266 } |
| 1267 | |
| 1268 /* add dct residue */ | |
| 1269 add_dct(s, block[0], 0, dest_y, dct_linesize); | |
| 1270 add_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
| 1271 add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
| 1272 add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
| 1273 | |
| 57 | 1274 add_dct(s, block[4], 4, dest_cb, s->linesize >> 1); |
| 1275 add_dct(s, block[5], 5, dest_cr, s->linesize >> 1); | |
| 0 | 1276 } else { |
| 1277 /* dct only in intra block */ | |
| 1278 put_dct(s, block[0], 0, dest_y, dct_linesize); | |
| 1279 put_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
| 1280 put_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
| 1281 put_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
| 1282 | |
| 57 | 1283 put_dct(s, block[4], 4, dest_cb, s->linesize >> 1); |
| 1284 put_dct(s, block[5], 5, dest_cr, s->linesize >> 1); | |
| 0 | 1285 } |
| 1286 } | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1287 the_end: |
| 294 | 1288 emms_c(); //FIXME remove |
| 1289 } | |
| 1290 | |
| 324 | 1291 |
| 1292 static void encode_mb(MpegEncContext *s, int motion_x, int motion_y) | |
| 294 | 1293 { |
| 1294 const int mb_x= s->mb_x; | |
| 1295 const int mb_y= s->mb_y; | |
| 1296 int i; | |
| 324 | 1297 #if 0 |
| 1298 if (s->interlaced_dct) { | |
| 1299 dct_linesize = s->linesize * 2; | |
| 1300 dct_offset = s->linesize; | |
| 1301 } else { | |
| 1302 dct_linesize = s->linesize; | |
| 1303 dct_offset = s->linesize * 8; | |
| 1304 } | |
| 1305 #endif | |
| 294 | 1306 |
| 324 | 1307 if (s->mb_intra) { |
| 1308 UINT8 *ptr; | |
| 1309 int wrap; | |
| 294 | 1310 |
| 324 | 1311 wrap = s->linesize; |
| 1312 ptr = s->new_picture[0] + (mb_y * 16 * wrap) + mb_x * 16; | |
| 1313 get_pixels(s->block[0], ptr , wrap); | |
| 1314 get_pixels(s->block[1], ptr + 8, wrap); | |
| 1315 get_pixels(s->block[2], ptr + 8 * wrap , wrap); | |
| 1316 get_pixels(s->block[3], ptr + 8 * wrap + 8, wrap); | |
| 294 | 1317 |
| 324 | 1318 wrap >>=1; |
| 1319 ptr = s->new_picture[1] + (mb_y * 8 * wrap) + mb_x * 8; | |
| 1320 get_pixels(s->block[4], ptr, wrap); | |
| 294 | 1321 |
| 324 | 1322 ptr = s->new_picture[2] + (mb_y * 8 * wrap) + mb_x * 8; |
| 1323 get_pixels(s->block[5], ptr, wrap); | |
| 1324 }else{ | |
| 1325 op_pixels_func *op_pix; | |
| 1326 qpel_mc_func *op_qpix; | |
| 1327 UINT8 *dest_y, *dest_cb, *dest_cr; | |
| 1328 UINT8 *ptr; | |
| 1329 int wrap; | |
| 294 | 1330 |
| 324 | 1331 dest_y = s->current_picture[0] + (mb_y * 16 * s->linesize ) + mb_x * 16; |
| 1332 dest_cb = s->current_picture[1] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; | |
| 1333 dest_cr = s->current_picture[2] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; | |
| 1334 | |
| 327 | 1335 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
| 324 | 1336 op_pix = put_pixels_tab; |
| 1337 op_qpix= qpel_mc_rnd_tab; | |
| 295 | 1338 }else{ |
| 324 | 1339 op_pix = put_no_rnd_pixels_tab; |
| 1340 op_qpix= qpel_mc_no_rnd_tab; | |
| 1341 } | |
| 295 | 1342 |
| 324 | 1343 if (s->mv_dir & MV_DIR_FORWARD) { |
| 1344 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); | |
| 327 | 1345 if ((!s->no_rounding) || s->pict_type==B_TYPE) |
| 324 | 1346 op_pix = avg_pixels_tab; |
| 1347 else | |
| 1348 op_pix = avg_no_rnd_pixels_tab; | |
| 1349 } | |
| 1350 if (s->mv_dir & MV_DIR_BACKWARD) { | |
| 1351 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); | |
| 1352 } | |
| 1353 wrap = s->linesize; | |
| 1354 ptr = s->new_picture[0] + (mb_y * 16 * wrap) + mb_x * 16; | |
| 1355 diff_pixels(s->block[0], ptr , dest_y , wrap); | |
| 1356 diff_pixels(s->block[1], ptr + 8, dest_y + 8, wrap); | |
| 1357 diff_pixels(s->block[2], ptr + 8 * wrap , dest_y + 8 * wrap , wrap); | |
| 1358 diff_pixels(s->block[3], ptr + 8 * wrap + 8, dest_y + 8 * wrap + 8, wrap); | |
| 295 | 1359 |
| 324 | 1360 wrap >>=1; |
| 1361 ptr = s->new_picture[1] + (mb_y * 8 * wrap) + mb_x * 8; | |
| 1362 diff_pixels(s->block[4], ptr, dest_cb, wrap); | |
| 1363 | |
| 1364 ptr = s->new_picture[2] + (mb_y * 8 * wrap) + mb_x * 8; | |
| 1365 diff_pixels(s->block[5], ptr, dest_cr, wrap); | |
| 294 | 1366 } |
| 1367 | |
| 1368 #if 0 | |
| 1369 { | |
| 1370 float adap_parm; | |
| 1371 | |
| 1372 adap_parm = ((s->avg_mb_var << 1) + s->mb_var[s->mb_width*mb_y+mb_x] + 1.0) / | |
| 1373 ((s->mb_var[s->mb_width*mb_y+mb_x] << 1) + s->avg_mb_var + 1.0); | |
| 1374 | |
| 1375 printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d", | |
| 1376 (s->mb_type[s->mb_width*mb_y+mb_x] > 0) ? 'I' : 'P', | |
| 1377 s->qscale, adap_parm, s->qscale*adap_parm, | |
| 1378 s->mb_var[s->mb_width*mb_y+mb_x], s->avg_mb_var); | |
| 1379 } | |
| 1380 #endif | |
| 1381 /* DCT & quantize */ | |
| 1382 if (s->h263_msmpeg4) { | |
| 1383 msmpeg4_dc_scale(s); | |
| 1384 } else if (s->h263_pred) { | |
| 1385 h263_dc_scale(s); | |
| 1386 } else { | |
| 1387 /* default quantization values */ | |
| 1388 s->y_dc_scale = 8; | |
| 1389 s->c_dc_scale = 8; | |
| 1390 } | |
| 1391 for(i=0;i<6;i++) { | |
| 1392 s->block_last_index[i] = dct_quantize(s, s->block[i], i, s->qscale); | |
| 1393 } | |
| 1394 | |
| 1395 /* huffman encode */ | |
| 1396 switch(s->out_format) { | |
| 1397 case FMT_MPEG1: | |
| 1398 mpeg1_encode_mb(s, s->block, motion_x, motion_y); | |
| 1399 break; | |
| 1400 case FMT_H263: | |
| 1401 if (s->h263_msmpeg4) | |
| 1402 msmpeg4_encode_mb(s, s->block, motion_x, motion_y); | |
| 1403 else if(s->h263_pred) | |
| 1404 mpeg4_encode_mb(s, s->block, motion_x, motion_y); | |
| 1405 else | |
| 1406 h263_encode_mb(s, s->block, motion_x, motion_y); | |
| 1407 break; | |
| 1408 case FMT_MJPEG: | |
| 1409 mjpeg_encode_mb(s, s->block); | |
| 1410 break; | |
| 1411 } | |
| 1412 } | |
| 1413 | |
| 1414 static void copy_bits(PutBitContext *pb, UINT8 *src, int length) | |
| 1415 { | |
| 326 | 1416 #if 1 |
| 1417 int bytes= length>>4; | |
| 1418 int bits= length&15; | |
| 1419 int i; | |
| 1420 | |
| 1421 for(i=0; i<bytes; i++) put_bits(pb, 16, be2me_16(((uint16_t*)src)[i])); | |
| 1422 put_bits(pb, bits, be2me_16(((uint16_t*)src)[i])>>(16-bits)); | |
| 1423 #else | |
| 294 | 1424 int bytes= length>>3; |
| 1425 int bits= length&7; | |
| 1426 int i; | |
| 1427 | |
| 1428 for(i=0; i<bytes; i++) put_bits(pb, 8, src[i]); | |
| 1429 put_bits(pb, bits, src[i]>>(8-bits)); | |
| 326 | 1430 #endif |
| 0 | 1431 } |
| 1432 | |
| 326 | 1433 static void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
| 1434 int i; | |
| 1435 | |
| 1436 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
| 1437 | |
| 1438 /* mpeg1 */ | |
| 1439 d->mb_incr= s->mb_incr; | |
| 1440 for(i=0; i<3; i++) | |
| 1441 d->last_dc[i]= s->last_dc[i]; | |
| 1442 | |
| 1443 /* statistics */ | |
| 1444 d->mv_bits= s->mv_bits; | |
| 1445 d->i_tex_bits= s->i_tex_bits; | |
| 1446 d->p_tex_bits= s->p_tex_bits; | |
| 1447 d->i_count= s->i_count; | |
| 1448 d->p_count= s->p_count; | |
| 1449 d->skip_count= s->skip_count; | |
| 1450 d->misc_bits= s->misc_bits; | |
| 329 | 1451 d->last_bits= 0; |
| 327 | 1452 |
| 1453 d->mb_skiped= s->mb_skiped; | |
| 326 | 1454 } |
| 1455 | |
| 1456 static void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){ | |
| 1457 int i; | |
| 1458 | |
| 1459 memcpy(d->mv, s->mv, 2*4*2*sizeof(int)); | |
| 1460 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
| 1461 | |
| 1462 /* mpeg1 */ | |
| 1463 d->mb_incr= s->mb_incr; | |
| 1464 for(i=0; i<3; i++) | |
| 1465 d->last_dc[i]= s->last_dc[i]; | |
| 1466 | |
| 1467 /* statistics */ | |
| 1468 d->mv_bits= s->mv_bits; | |
| 1469 d->i_tex_bits= s->i_tex_bits; | |
| 1470 d->p_tex_bits= s->p_tex_bits; | |
| 1471 d->i_count= s->i_count; | |
| 1472 d->p_count= s->p_count; | |
| 1473 d->skip_count= s->skip_count; | |
| 1474 d->misc_bits= s->misc_bits; | |
| 1475 | |
| 1476 d->mb_intra= s->mb_intra; | |
| 327 | 1477 d->mb_skiped= s->mb_skiped; |
| 326 | 1478 d->mv_type= s->mv_type; |
| 1479 d->mv_dir= s->mv_dir; | |
| 1480 d->pb= s->pb; | |
| 1481 d->block= s->block; | |
| 1482 for(i=0; i<6; i++) | |
| 1483 d->block_last_index[i]= s->block_last_index[i]; | |
| 1484 } | |
| 1485 | |
| 1486 | |
| 0 | 1487 static void encode_picture(MpegEncContext *s, int picture_number) |
| 1488 { | |
| 294 | 1489 int mb_x, mb_y, last_gob, pdif = 0; |
| 1490 int i; | |
| 286 | 1491 int bits; |
| 326 | 1492 MpegEncContext best_s, backup_s; |
| 327 | 1493 UINT8 bit_buf[7][3000]; //FIXME check that this is ALLWAYS large enogh for a MB |
| 0 | 1494 |
| 1495 s->picture_number = picture_number; | |
| 268 | 1496 |
| 294 | 1497 s->block_wrap[0]= |
| 1498 s->block_wrap[1]= | |
| 1499 s->block_wrap[2]= | |
| 1500 s->block_wrap[3]= s->mb_width*2 + 2; | |
| 1501 s->block_wrap[4]= | |
| 1502 s->block_wrap[5]= s->mb_width + 2; | |
| 1503 | |
| 268 | 1504 /* Reset the average MB variance */ |
| 1505 s->avg_mb_var = 0; | |
| 1506 s->mc_mb_var = 0; | |
| 327 | 1507 |
| 1508 /* we need to initialize some time vars before we can encode b-frames */ | |
| 1509 if (s->h263_pred && !s->h263_msmpeg4) | |
| 1510 ff_set_mpeg4_time(s, s->picture_number); | |
| 1511 | |
| 268 | 1512 /* Estimate motion for every MB */ |
| 324 | 1513 if(s->pict_type != I_TYPE){ |
| 1514 // int16_t (*tmp)[2]= s->p_mv_table; | |
| 1515 // s->p_mv_table= s->last_mv_table; | |
| 1516 // s->last_mv_table= s->mv_table; | |
| 1517 | |
| 294 | 1518 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
| 1519 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; | |
| 1520 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
| 1521 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
| 1522 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
| 1523 for(mb_x=0; mb_x < s->mb_width; mb_x++) { | |
| 1524 s->mb_x = mb_x; | |
| 1525 s->mb_y = mb_y; | |
| 1526 s->block_index[0]+=2; | |
| 1527 s->block_index[1]+=2; | |
| 1528 s->block_index[2]+=2; | |
| 1529 s->block_index[3]+=2; | |
| 268 | 1530 |
| 294 | 1531 /* compute motion vector & mb_type and store in context */ |
| 324 | 1532 if(s->pict_type==B_TYPE) |
| 1533 ff_estimate_b_frame_motion(s, mb_x, mb_y); | |
| 1534 else | |
| 1535 ff_estimate_p_frame_motion(s, mb_x, mb_y); | |
| 294 | 1536 // s->mb_type[mb_y*s->mb_width + mb_x]=MB_TYPE_INTER; |
| 268 | 1537 } |
| 1538 } | |
| 294 | 1539 emms_c(); |
| 324 | 1540 }else if(s->pict_type == I_TYPE){ |
| 294 | 1541 /* I-Frame */ |
| 1542 //FIXME do we need to zero them? | |
| 1543 memset(s->motion_val[0], 0, sizeof(INT16)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2); | |
| 324 | 1544 memset(s->p_mv_table , 0, sizeof(INT16)*(s->mb_width+2)*(s->mb_height+2)*2); |
| 294 | 1545 memset(s->mb_type , MB_TYPE_INTRA, sizeof(UINT8)*s->mb_width*s->mb_height); |
| 268 | 1546 } |
| 1547 | |
| 329 | 1548 if(s->avg_mb_var < s->mc_mb_var && s->pict_type == P_TYPE){ //FIXME subtract MV bits |
| 271 | 1549 s->pict_type= I_TYPE; |
| 294 | 1550 memset(s->mb_type , MB_TYPE_INTRA, sizeof(UINT8)*s->mb_width*s->mb_height); |
| 329 | 1551 if(s->max_b_frames==0){ |
| 1552 s->input_pict_type= I_TYPE; | |
| 1553 s->input_picture_in_gop_number=0; | |
| 1554 } | |
| 294 | 1555 //printf("Scene change detected, encoding as I Frame\n"); |
| 271 | 1556 } |
| 324 | 1557 |
| 1558 if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) | |
| 1559 s->f_code= ff_get_best_fcode(s, s->p_mv_table, MB_TYPE_INTER); | |
| 1560 ff_fix_long_p_mvs(s); | |
| 1561 if(s->pict_type==B_TYPE){ | |
| 1562 s->f_code= ff_get_best_fcode(s, s->b_forw_mv_table, MB_TYPE_FORWARD); | |
| 1563 s->b_code= ff_get_best_fcode(s, s->b_back_mv_table, MB_TYPE_BACKWARD); | |
| 327 | 1564 |
| 1565 ff_fix_long_b_mvs(s, s->b_forw_mv_table, s->f_code, MB_TYPE_FORWARD); | |
| 1566 ff_fix_long_b_mvs(s, s->b_back_mv_table, s->b_code, MB_TYPE_BACKWARD); | |
| 1567 ff_fix_long_b_mvs(s, s->b_bidir_forw_mv_table, s->f_code, MB_TYPE_BIDIR); | |
| 1568 ff_fix_long_b_mvs(s, s->b_bidir_back_mv_table, s->b_code, MB_TYPE_BIDIR); | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1569 } |
| 324 | 1570 |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
1571 //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
|
1572 |
| 271 | 1573 // printf("%d %d\n", s->avg_mb_var, s->mc_mb_var); |
| 1574 | |
| 329 | 1575 if(s->flags&CODEC_FLAG_PASS2) |
| 1576 s->qscale = ff_rate_estimate_qscale_pass2(s); | |
| 1577 else if (!s->fixed_qscale) | |
| 1578 s->qscale = ff_rate_estimate_qscale(s); | |
| 1579 | |
| 0 | 1580 |
| 1581 /* precompute matrix */ | |
| 1582 if (s->out_format == FMT_MJPEG) { | |
| 1583 /* for mjpeg, we do include qscale in the matrix */ | |
| 1584 s->intra_matrix[0] = default_intra_matrix[0]; | |
| 1585 for(i=1;i<64;i++) | |
| 1586 s->intra_matrix[i] = (default_intra_matrix[i] * s->qscale) >> 3; | |
| 220 | 1587 convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, s->intra_matrix, 8); |
| 0 | 1588 } else { |
| 220 | 1589 convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, s->intra_matrix, s->qscale); |
| 1590 convert_matrix(s->q_non_intra_matrix, s->q_non_intra_matrix16, s->non_intra_matrix, s->qscale); | |
| 0 | 1591 } |
| 1592 | |
| 286 | 1593 s->last_bits= get_bit_count(&s->pb); |
| 0 | 1594 switch(s->out_format) { |
| 1595 case FMT_MJPEG: | |
| 1596 mjpeg_picture_header(s); | |
| 1597 break; | |
| 1598 case FMT_H263: | |
| 1599 if (s->h263_msmpeg4) | |
| 1600 msmpeg4_encode_picture_header(s, picture_number); | |
| 1601 else if (s->h263_pred) | |
| 1602 mpeg4_encode_picture_header(s, picture_number); | |
| 1603 else if (s->h263_rv10) | |
| 1604 rv10_encode_picture_header(s, picture_number); | |
| 1605 else | |
| 1606 h263_encode_picture_header(s, picture_number); | |
| 1607 break; | |
| 1608 case FMT_MPEG1: | |
| 1609 mpeg1_encode_picture_header(s, picture_number); | |
| 1610 break; | |
| 1611 } | |
| 286 | 1612 bits= get_bit_count(&s->pb); |
| 1613 s->header_bits= bits - s->last_bits; | |
| 1614 s->last_bits= bits; | |
| 1615 s->mv_bits=0; | |
| 1616 s->misc_bits=0; | |
| 1617 s->i_tex_bits=0; | |
| 1618 s->p_tex_bits=0; | |
| 1619 s->i_count=0; | |
| 1620 s->p_count=0; | |
| 1621 s->skip_count=0; | |
| 1622 | |
| 0 | 1623 /* init last dc values */ |
| 1624 /* note: quant matrix value (8) is implied here */ | |
| 1625 s->last_dc[0] = 128; | |
| 1626 s->last_dc[1] = 128; | |
| 1627 s->last_dc[2] = 128; | |
| 1628 s->mb_incr = 1; | |
| 1629 s->last_mv[0][0][0] = 0; | |
| 1630 s->last_mv[0][0][1] = 0; | |
| 1631 | |
| 162 | 1632 /* Get the GOB height based on picture height */ |
| 231 | 1633 if (s->out_format == FMT_H263 && !s->h263_pred && !s->h263_msmpeg4) { |
| 162 | 1634 if (s->height <= 400) |
| 1635 s->gob_index = 1; | |
| 1636 else if (s->height <= 800) | |
| 1637 s->gob_index = 2; | |
| 1638 else | |
| 1639 s->gob_index = 4; | |
| 1640 } | |
| 268 | 1641 |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1642 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
|
1643 |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1644 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
|
1645 /* 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
|
1646 /* 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
|
1647 if (s->rtp_mode) { |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1648 if (!mb_y) { |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1649 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
|
1650 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
|
1651 } 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
|
1652 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
|
1653 if (last_gob) { |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1654 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
|
1655 } |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1656 } |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1657 } |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
1658 |
| 266 | 1659 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; |
| 1660 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
| 1661 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
| 1662 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
| 1663 s->block_index[4]= s->block_wrap[4]*(mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2); | |
| 1664 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
|
1665 for(mb_x=0; mb_x < s->mb_width; mb_x++) { |
| 327 | 1666 const int mb_type= s->mb_type[mb_y * s->mb_width + mb_x]; |
| 1667 const int xy= (mb_y+1) * (s->mb_width+2) + mb_x + 1; | |
| 294 | 1668 PutBitContext pb; |
| 1669 int d; | |
| 1670 int dmin=10000000; | |
| 1671 int best=0; | |
| 0 | 1672 |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1673 s->mb_x = mb_x; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
1674 s->mb_y = mb_y; |
| 266 | 1675 s->block_index[0]+=2; |
| 1676 s->block_index[1]+=2; | |
| 1677 s->block_index[2]+=2; | |
| 1678 s->block_index[3]+=2; | |
| 1679 s->block_index[4]++; | |
| 1680 s->block_index[5]++; | |
| 294 | 1681 if(mb_type & (mb_type-1)){ // more than 1 MB type possible |
| 327 | 1682 int next_block=0; |
| 294 | 1683 pb= s->pb; |
| 326 | 1684 |
| 1685 copy_context_before_encode(&backup_s, s, -1); | |
| 1686 | |
| 294 | 1687 if(mb_type&MB_TYPE_INTER){ |
| 327 | 1688 s->mv_dir = MV_DIR_FORWARD; |
| 295 | 1689 s->mv_type = MV_TYPE_16X16; |
| 294 | 1690 s->mb_intra= 0; |
| 324 | 1691 s->mv[0][0][0] = s->p_mv_table[xy][0]; |
| 1692 s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
| 294 | 1693 init_put_bits(&s->pb, bit_buf[1], 3000, NULL, NULL); |
| 327 | 1694 s->block= s->blocks[next_block]; |
| 329 | 1695 s->last_bits= 0; //done in copy_context_before_encode but we skip that here |
| 0 | 1696 |
| 324 | 1697 encode_mb(s, s->mv[0][0][0], s->mv[0][0][1]); |
| 294 | 1698 d= get_bit_count(&s->pb); |
| 1699 if(d<dmin){ | |
| 1700 flush_put_bits(&s->pb); | |
| 1701 dmin=d; | |
| 326 | 1702 copy_context_after_encode(&best_s, s, MB_TYPE_INTER); |
| 294 | 1703 best=1; |
| 327 | 1704 next_block^=1; |
| 294 | 1705 } |
| 0 | 1706 } |
| 326 | 1707 if(mb_type&MB_TYPE_INTER4V){ |
| 1708 copy_context_before_encode(s, &backup_s, MB_TYPE_INTER4V); | |
| 327 | 1709 s->mv_dir = MV_DIR_FORWARD; |
| 295 | 1710 s->mv_type = MV_TYPE_8X8; |
| 1711 s->mb_intra= 0; | |
| 1712 for(i=0; i<4; i++){ | |
| 1713 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; | |
| 1714 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; | |
| 1715 } | |
| 1716 init_put_bits(&s->pb, bit_buf[2], 3000, NULL, NULL); | |
| 327 | 1717 s->block= s->blocks[next_block]; |
| 295 | 1718 |
| 324 | 1719 encode_mb(s, 0, 0); |
| 295 | 1720 d= get_bit_count(&s->pb); |
| 327 | 1721 if(d<dmin){ |
| 295 | 1722 flush_put_bits(&s->pb); |
| 1723 dmin=d; | |
| 326 | 1724 copy_context_after_encode(&best_s, s, MB_TYPE_INTER4V); |
| 295 | 1725 best=2; |
| 327 | 1726 next_block^=1; |
| 1727 } | |
| 1728 } | |
| 1729 if(mb_type&MB_TYPE_FORWARD){ | |
| 1730 copy_context_before_encode(s, &backup_s, MB_TYPE_FORWARD); | |
| 1731 s->mv_dir = MV_DIR_FORWARD; | |
| 1732 s->mv_type = MV_TYPE_16X16; | |
| 1733 s->mb_intra= 0; | |
| 1734 s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
| 1735 s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
| 1736 init_put_bits(&s->pb, bit_buf[3], 3000, NULL, NULL); | |
| 1737 s->block= s->blocks[next_block]; | |
| 1738 | |
| 1739 encode_mb(s, s->mv[0][0][0], s->mv[0][0][1]); | |
| 1740 d= get_bit_count(&s->pb); | |
| 1741 if(d<dmin){ | |
| 1742 flush_put_bits(&s->pb); | |
| 1743 dmin=d; | |
| 1744 copy_context_after_encode(&best_s, s, MB_TYPE_FORWARD); | |
| 1745 best=3; | |
| 1746 next_block^=1; | |
| 1747 } | |
| 1748 } | |
| 1749 if(mb_type&MB_TYPE_BACKWARD){ | |
| 1750 copy_context_before_encode(s, &backup_s, MB_TYPE_BACKWARD); | |
| 1751 s->mv_dir = MV_DIR_BACKWARD; | |
| 1752 s->mv_type = MV_TYPE_16X16; | |
| 1753 s->mb_intra= 0; | |
| 1754 s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
| 1755 s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
| 1756 init_put_bits(&s->pb, bit_buf[4], 3000, NULL, NULL); | |
| 1757 s->block= s->blocks[next_block]; | |
| 1758 | |
| 1759 encode_mb(s, s->mv[1][0][0], s->mv[1][0][1]); | |
| 1760 d= get_bit_count(&s->pb); | |
| 1761 if(d<dmin){ | |
| 1762 flush_put_bits(&s->pb); | |
| 1763 dmin=d; | |
| 1764 copy_context_after_encode(&best_s, s, MB_TYPE_BACKWARD); | |
| 1765 best=4; | |
| 1766 next_block^=1; | |
| 1767 } | |
| 1768 } | |
| 1769 if(mb_type&MB_TYPE_BIDIR){ | |
| 1770 copy_context_before_encode(s, &backup_s, MB_TYPE_BIDIR); | |
| 1771 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
| 1772 s->mv_type = MV_TYPE_16X16; | |
| 1773 s->mb_intra= 0; | |
| 1774 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
| 1775 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
| 1776 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
| 1777 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
| 1778 init_put_bits(&s->pb, bit_buf[5], 3000, NULL, NULL); | |
| 1779 s->block= s->blocks[next_block]; | |
| 1780 | |
| 1781 encode_mb(s, 0, 0); | |
| 1782 d= get_bit_count(&s->pb); | |
| 1783 if(d<dmin){ | |
| 1784 flush_put_bits(&s->pb); | |
| 1785 dmin=d; | |
| 1786 copy_context_after_encode(&best_s, s, MB_TYPE_BIDIR); | |
| 1787 best=5; | |
| 1788 next_block^=1; | |
| 1789 } | |
| 1790 } | |
| 1791 if(mb_type&MB_TYPE_DIRECT){ | |
| 1792 copy_context_before_encode(s, &backup_s, MB_TYPE_DIRECT); | |
| 1793 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
| 1794 s->mv_type = MV_TYPE_16X16; //FIXME | |
| 1795 s->mb_intra= 0; | |
| 1796 s->mv[0][0][0] = s->b_direct_forw_mv_table[xy][0]; | |
| 1797 s->mv[0][0][1] = s->b_direct_forw_mv_table[xy][1]; | |
| 1798 s->mv[1][0][0] = s->b_direct_back_mv_table[xy][0]; | |
| 1799 s->mv[1][0][1] = s->b_direct_back_mv_table[xy][1]; | |
| 1800 init_put_bits(&s->pb, bit_buf[6], 3000, NULL, NULL); | |
| 1801 s->block= s->blocks[next_block]; | |
| 1802 | |
| 1803 encode_mb(s, s->b_direct_mv_table[xy][0], s->b_direct_mv_table[xy][1]); | |
| 1804 d= get_bit_count(&s->pb); | |
| 1805 if(d<dmin){ | |
| 1806 flush_put_bits(&s->pb); | |
| 1807 dmin=d; | |
| 1808 copy_context_after_encode(&best_s, s, MB_TYPE_DIRECT); | |
| 1809 best=6; | |
| 1810 next_block^=1; | |
| 295 | 1811 } |
| 1812 } | |
| 294 | 1813 if(mb_type&MB_TYPE_INTRA){ |
| 326 | 1814 copy_context_before_encode(s, &backup_s, MB_TYPE_INTRA); |
| 327 | 1815 s->mv_dir = MV_DIR_FORWARD; |
| 295 | 1816 s->mv_type = MV_TYPE_16X16; |
| 294 | 1817 s->mb_intra= 1; |
| 1818 s->mv[0][0][0] = 0; | |
| 1819 s->mv[0][0][1] = 0; | |
| 1820 init_put_bits(&s->pb, bit_buf[0], 3000, NULL, NULL); | |
| 327 | 1821 s->block= s->blocks[next_block]; |
| 294 | 1822 |
| 324 | 1823 encode_mb(s, 0, 0); |
| 294 | 1824 d= get_bit_count(&s->pb); |
| 1825 if(d<dmin){ | |
| 1826 flush_put_bits(&s->pb); | |
| 1827 dmin=d; | |
| 326 | 1828 copy_context_after_encode(&best_s, s, MB_TYPE_INTRA); |
| 294 | 1829 best=0; |
| 327 | 1830 next_block^=1; |
| 294 | 1831 } |
| 326 | 1832 /* force cleaning of ac/dc pred stuff if needed ... */ |
| 1833 if(s->h263_pred || s->h263_aic) | |
| 1834 s->mbintra_table[mb_x + mb_y*s->mb_width]=1; | |
| 295 | 1835 } |
| 326 | 1836 copy_context_after_encode(s, &best_s, -1); |
| 294 | 1837 copy_bits(&pb, bit_buf[best], dmin); |
| 1838 s->pb= pb; | |
| 329 | 1839 s->last_bits= get_bit_count(&s->pb); |
| 294 | 1840 } else { |
| 324 | 1841 int motion_x, motion_y; |
| 1842 s->mv_type=MV_TYPE_16X16; | |
| 294 | 1843 // only one MB-Type possible |
| 327 | 1844 switch(mb_type){ |
| 1845 case MB_TYPE_INTRA: | |
| 324 | 1846 s->mv_dir = MV_DIR_FORWARD; |
| 294 | 1847 s->mb_intra= 1; |
| 324 | 1848 motion_x= s->mv[0][0][0] = 0; |
| 1849 motion_y= s->mv[0][0][1] = 0; | |
| 327 | 1850 break; |
| 1851 case MB_TYPE_INTER: | |
| 324 | 1852 s->mv_dir = MV_DIR_FORWARD; |
| 1853 s->mb_intra= 0; | |
| 1854 motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; | |
| 1855 motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
| 327 | 1856 break; |
| 1857 case MB_TYPE_DIRECT: | |
| 324 | 1858 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
| 1859 s->mb_intra= 0; | |
| 327 | 1860 motion_x=s->b_direct_mv_table[xy][0]; |
| 1861 motion_y=s->b_direct_mv_table[xy][1]; | |
| 1862 s->mv[0][0][0] = s->b_direct_forw_mv_table[xy][0]; | |
| 1863 s->mv[0][0][1] = s->b_direct_forw_mv_table[xy][1]; | |
| 1864 s->mv[1][0][0] = s->b_direct_back_mv_table[xy][0]; | |
| 1865 s->mv[1][0][1] = s->b_direct_back_mv_table[xy][1]; | |
| 1866 break; | |
| 1867 case MB_TYPE_BIDIR: | |
| 324 | 1868 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; |
| 294 | 1869 s->mb_intra= 0; |
| 324 | 1870 motion_x=0; |
| 1871 motion_y=0; | |
| 1872 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
| 1873 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
| 1874 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
| 1875 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
| 327 | 1876 break; |
| 1877 case MB_TYPE_BACKWARD: | |
| 324 | 1878 s->mv_dir = MV_DIR_BACKWARD; |
| 1879 s->mb_intra= 0; | |
| 1880 motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
| 1881 motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
| 327 | 1882 break; |
| 1883 case MB_TYPE_FORWARD: | |
| 324 | 1884 s->mv_dir = MV_DIR_FORWARD; |
| 1885 s->mb_intra= 0; | |
| 1886 motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
| 1887 motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
| 1888 // printf(" %d %d ", motion_x, motion_y); | |
| 327 | 1889 break; |
| 1890 default: | |
| 324 | 1891 motion_x=motion_y=0; //gcc warning fix |
| 1892 printf("illegal MB type\n"); | |
| 294 | 1893 } |
| 324 | 1894 encode_mb(s, motion_x, motion_y); |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
1895 } |
| 327 | 1896 /* clean the MV table in IPS frames for direct mode in B frames */ |
| 1897 if(s->mb_intra /* && I,P,S_TYPE */){ | |
| 1898 s->p_mv_table[xy][0]=0; | |
| 1899 s->p_mv_table[xy][1]=0; | |
| 1900 } | |
| 0 | 1901 |
|
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
|
1902 MPV_decode_mb(s, s->block); |
| 0 | 1903 } |
|
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
|
1904 |
|
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
|
1905 |
| 231 | 1906 /* Obtain average GOB size for RTP */ |
| 1907 if (s->rtp_mode) { | |
| 1908 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
|
1909 s->mb_line_avgsize = pbBufPtr(&s->pb) - s->ptr_last_mb_line; |
| 231 | 1910 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
|
1911 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
|
1912 s->ptr_last_mb_line = pbBufPtr(&s->pb); |
| 231 | 1913 } |
| 1914 //fprintf(stderr, "\nMB line: %d\tSize: %u\tAvg. Size: %u", s->mb_y, | |
| 1915 // (s->pb.buf_ptr - s->ptr_last_mb_line), s->mb_line_avgsize); | |
| 1916 s->first_gob_line = 0; | |
| 1917 } | |
| 0 | 1918 } |
| 294 | 1919 emms_c(); |
| 286 | 1920 |
| 311 | 1921 if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type == I_TYPE) |
| 208 | 1922 msmpeg4_encode_ext_header(s); |
| 1923 | |
| 162 | 1924 //if (s->gob_number) |
| 1925 // fprintf(stderr,"\nNumber of GOB: %d", s->gob_number); | |
| 231 | 1926 |
| 1927 /* Send the last GOB if RTP */ | |
| 1928 if (s->rtp_mode) { | |
| 1929 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
|
1930 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
| 231 | 1931 /* Call the RTP callback to send the last GOB */ |
| 1932 if (s->rtp_callback) | |
| 1933 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
|
1934 s->ptr_lastgob = pbBufPtr(&s->pb); |
| 231 | 1935 //fprintf(stderr,"\nGOB: %2d size: %d (last)", s->gob_number, pdif); |
| 1936 } | |
| 0 | 1937 } |
| 1938 | |
| 220 | 1939 static int dct_quantize_c(MpegEncContext *s, |
| 0 | 1940 DCTELEM *block, int n, |
| 1941 int qscale) | |
| 1942 { | |
| 1943 int i, j, level, last_non_zero, q; | |
| 1944 const int *qmat; | |
| 216 | 1945 int minLevel, maxLevel; |
| 1946 | |
| 1947 if(s->avctx!=NULL && s->avctx->codec->id==CODEC_ID_MPEG4){ | |
| 1948 /* mpeg4 */ | |
| 1949 minLevel= -2048; | |
| 1950 maxLevel= 2047; | |
| 1951 }else if(s->out_format==FMT_MPEG1){ | |
| 1952 /* mpeg1 */ | |
| 1953 minLevel= -255; | |
| 1954 maxLevel= 255; | |
| 230 | 1955 }else if(s->out_format==FMT_MJPEG){ |
| 1956 /* (m)jpeg */ | |
| 1957 minLevel= -1023; | |
| 1958 maxLevel= 1023; | |
| 216 | 1959 }else{ |
| 1960 /* h263 / msmpeg4 */ | |
| 1961 minLevel= -128; | |
| 1962 maxLevel= 127; | |
| 1963 } | |
| 0 | 1964 |
| 1965 av_fdct (block); | |
| 1966 | |
| 64 | 1967 /* we need this permutation so that we correct the IDCT |
| 1968 permutation. will be moved into DCT code */ | |
| 1969 block_permute(block); | |
| 1970 | |
| 0 | 1971 if (s->mb_intra) { |
| 1972 if (n < 4) | |
| 1973 q = s->y_dc_scale; | |
| 1974 else | |
| 1975 q = s->c_dc_scale; | |
| 1976 q = q << 3; | |
| 1977 | |
| 1978 /* note: block[0] is assumed to be positive */ | |
| 1979 block[0] = (block[0] + (q >> 1)) / q; | |
| 1980 i = 1; | |
| 1981 last_non_zero = 0; | |
| 1982 if (s->out_format == FMT_H263) { | |
| 1983 qmat = s->q_non_intra_matrix; | |
| 1984 } else { | |
| 1985 qmat = s->q_intra_matrix; | |
| 1986 } | |
| 1987 } else { | |
| 1988 i = 0; | |
| 1989 last_non_zero = -1; | |
| 1990 qmat = s->q_non_intra_matrix; | |
| 1991 } | |
| 1992 | |
| 1993 for(;i<64;i++) { | |
| 1994 j = zigzag_direct[i]; | |
| 1995 level = block[j]; | |
| 1996 level = level * qmat[j]; | |
| 1997 #ifdef PARANOID | |
| 1998 { | |
| 1999 static int count = 0; | |
| 2000 int level1, level2, qmat1; | |
| 2001 double val; | |
| 2002 if (qmat == s->q_non_intra_matrix) { | |
| 2003 qmat1 = default_non_intra_matrix[j] * s->qscale; | |
| 2004 } else { | |
| 2005 qmat1 = default_intra_matrix[j] * s->qscale; | |
| 2006 } | |
| 2007 if (av_fdct != jpeg_fdct_ifast) | |
| 2008 val = ((double)block[j] * 8.0) / (double)qmat1; | |
| 2009 else | |
| 2010 val = ((double)block[j] * 8.0 * 2048.0) / | |
| 2011 ((double)qmat1 * aanscales[j]); | |
| 2012 level1 = (int)val; | |
| 2013 level2 = level / (1 << (QMAT_SHIFT - 3)); | |
| 2014 if (level1 != level2) { | |
| 2015 fprintf(stderr, "%d: quant error qlevel=%d wanted=%d level=%d qmat1=%d qmat=%d wantedf=%0.6f\n", | |
| 2016 count, level2, level1, block[j], qmat1, qmat[j], | |
| 2017 val); | |
| 2018 count++; | |
| 2019 } | |
| 2020 | |
| 2021 } | |
| 2022 #endif | |
| 2023 /* XXX: slight error for the low range. Test should be equivalent to | |
| 2024 (level <= -(1 << (QMAT_SHIFT - 3)) || level >= (1 << | |
| 2025 (QMAT_SHIFT - 3))) | |
| 2026 */ | |
| 2027 if (((level << (31 - (QMAT_SHIFT - 3))) >> (31 - (QMAT_SHIFT - 3))) != | |
| 2028 level) { | |
| 2029 level = level / (1 << (QMAT_SHIFT - 3)); | |
| 2030 /* XXX: currently, this code is not optimal. the range should be: | |
| 2031 mpeg1: -255..255 | |
| 2032 mpeg2: -2048..2047 | |
| 2033 h263: -128..127 | |
| 2034 mpeg4: -2048..2047 | |
| 2035 */ | |
| 216 | 2036 if (level > maxLevel) |
| 2037 level = maxLevel; | |
| 2038 else if (level < minLevel) | |
| 2039 level = minLevel; | |
| 0 | 2040 |
| 2041 block[j] = level; | |
| 2042 last_non_zero = i; | |
| 2043 } else { | |
| 2044 block[j] = 0; | |
| 2045 } | |
| 2046 } | |
| 2047 return last_non_zero; | |
| 2048 } | |
| 2049 | |
|
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
|
2050 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
|
2051 DCTELEM *block, int n, int qscale) |
| 0 | 2052 { |
| 200 | 2053 int i, level, nCoeffs; |
| 0 | 2054 const UINT16 *quant_matrix; |
| 2055 | |
| 200 | 2056 if(s->alternate_scan) nCoeffs= 64; |
| 2057 else nCoeffs= s->block_last_index[n]+1; | |
| 2058 | |
| 0 | 2059 if (s->mb_intra) { |
| 2060 if (n < 4) | |
| 2061 block[0] = block[0] * s->y_dc_scale; | |
| 2062 else | |
| 2063 block[0] = block[0] * s->c_dc_scale; | |
| 2064 /* XXX: only mpeg1 */ | |
| 2065 quant_matrix = s->intra_matrix; | |
| 200 | 2066 for(i=1;i<nCoeffs;i++) { |
| 2067 int j= zigzag_direct[i]; | |
| 2068 level = block[j]; | |
| 0 | 2069 if (level) { |
| 2070 if (level < 0) { | |
| 2071 level = -level; | |
| 200 | 2072 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
| 0 | 2073 level = (level - 1) | 1; |
| 2074 level = -level; | |
| 2075 } else { | |
| 200 | 2076 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
| 0 | 2077 level = (level - 1) | 1; |
| 2078 } | |
| 2079 #ifdef PARANOID | |
| 2080 if (level < -2048 || level > 2047) | |
| 2081 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 2082 #endif | |
| 200 | 2083 block[j] = level; |
| 0 | 2084 } |
| 2085 } | |
| 2086 } else { | |
| 2087 i = 0; | |
| 2088 quant_matrix = s->non_intra_matrix; | |
| 217 | 2089 for(;i<nCoeffs;i++) { |
| 200 | 2090 int j= zigzag_direct[i]; |
| 2091 level = block[j]; | |
| 0 | 2092 if (level) { |
| 2093 if (level < 0) { | |
| 2094 level = -level; | |
| 2095 level = (((level << 1) + 1) * qscale * | |
| 200 | 2096 ((int) (quant_matrix[j]))) >> 4; |
| 0 | 2097 level = (level - 1) | 1; |
| 2098 level = -level; | |
| 2099 } else { | |
| 2100 level = (((level << 1) + 1) * qscale * | |
| 200 | 2101 ((int) (quant_matrix[j]))) >> 4; |
| 0 | 2102 level = (level - 1) | 1; |
| 2103 } | |
| 2104 #ifdef PARANOID | |
| 2105 if (level < -2048 || level > 2047) | |
| 2106 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 2107 #endif | |
| 200 | 2108 block[j] = level; |
| 0 | 2109 } |
| 2110 } | |
| 2111 } | |
| 2112 } | |
|
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
|
2113 |
| 325 | 2114 static void dct_unquantize_mpeg2_c(MpegEncContext *s, |
| 2115 DCTELEM *block, int n, int qscale) | |
| 2116 { | |
| 2117 int i, level, nCoeffs; | |
| 2118 const UINT16 *quant_matrix; | |
| 2119 | |
| 2120 if(s->alternate_scan) nCoeffs= 64; | |
| 2121 else nCoeffs= s->block_last_index[n]+1; | |
| 2122 | |
| 2123 if (s->mb_intra) { | |
| 2124 if (n < 4) | |
| 2125 block[0] = block[0] * s->y_dc_scale; | |
| 2126 else | |
| 2127 block[0] = block[0] * s->c_dc_scale; | |
| 2128 quant_matrix = s->intra_matrix; | |
| 2129 for(i=1;i<nCoeffs;i++) { | |
| 2130 int j= zigzag_direct[i]; | |
| 2131 level = block[j]; | |
| 2132 if (level) { | |
| 2133 if (level < 0) { | |
| 2134 level = -level; | |
| 2135 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 2136 level = -level; | |
| 2137 } else { | |
| 2138 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 2139 } | |
| 2140 #ifdef PARANOID | |
| 2141 if (level < -2048 || level > 2047) | |
| 2142 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 2143 #endif | |
| 2144 block[j] = level; | |
| 2145 } | |
| 2146 } | |
| 2147 } else { | |
| 2148 int sum=-1; | |
| 2149 i = 0; | |
| 2150 quant_matrix = s->non_intra_matrix; | |
| 2151 for(;i<nCoeffs;i++) { | |
| 2152 int j= zigzag_direct[i]; | |
| 2153 level = block[j]; | |
| 2154 if (level) { | |
| 2155 if (level < 0) { | |
| 2156 level = -level; | |
| 2157 level = (((level << 1) + 1) * qscale * | |
| 2158 ((int) (quant_matrix[j]))) >> 4; | |
| 2159 level = -level; | |
| 2160 } else { | |
| 2161 level = (((level << 1) + 1) * qscale * | |
| 2162 ((int) (quant_matrix[j]))) >> 4; | |
| 2163 } | |
| 2164 #ifdef PARANOID | |
| 2165 if (level < -2048 || level > 2047) | |
| 2166 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 2167 #endif | |
| 2168 block[j] = level; | |
| 2169 sum+=level; | |
| 2170 } | |
| 2171 } | |
| 2172 block[63]^=sum&1; | |
| 2173 } | |
| 2174 } | |
| 2175 | |
| 2176 | |
|
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
|
2177 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
|
2178 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
|
2179 { |
|
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
|
2180 int i, level, qmul, qadd; |
| 200 | 2181 int nCoeffs; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2182 |
|
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
|
2183 if (s->mb_intra) { |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2184 if (!s->h263_aic) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2185 if (n < 4) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2186 block[0] = block[0] * s->y_dc_scale; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2187 else |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2188 block[0] = block[0] * s->c_dc_scale; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2189 } |
|
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
|
2190 i = 1; |
| 200 | 2191 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
|
2192 } 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
|
2193 i = 0; |
| 200 | 2194 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
|
2195 } |
|
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
|
2196 |
|
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
|
2197 qmul = s->qscale << 1; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2198 if (s->h263_aic && s->mb_intra) |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2199 qadd = 0; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2200 else |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2201 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
|
2202 |
| 200 | 2203 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
|
2204 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
|
2205 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
|
2206 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
|
2207 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
|
2208 } 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
|
2209 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
|
2210 } |
|
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
|
2211 #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
|
2212 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
|
2213 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
|
2214 #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
|
2215 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
|
2216 } |
|
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
|
2217 } |
|
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
|
2218 } |
| 0 | 2219 |
| 2220 AVCodec mpeg1video_encoder = { | |
| 2221 "mpeg1video", | |
| 2222 CODEC_TYPE_VIDEO, | |
| 2223 CODEC_ID_MPEG1VIDEO, | |
| 2224 sizeof(MpegEncContext), | |
| 2225 MPV_encode_init, | |
| 2226 MPV_encode_picture, | |
| 2227 MPV_encode_end, | |
| 2228 }; | |
| 2229 | |
| 2230 AVCodec h263_encoder = { | |
| 2231 "h263", | |
| 2232 CODEC_TYPE_VIDEO, | |
| 2233 CODEC_ID_H263, | |
| 2234 sizeof(MpegEncContext), | |
| 2235 MPV_encode_init, | |
| 2236 MPV_encode_picture, | |
| 2237 MPV_encode_end, | |
| 2238 }; | |
| 2239 | |
| 2240 AVCodec h263p_encoder = { | |
| 2241 "h263p", | |
| 2242 CODEC_TYPE_VIDEO, | |
| 2243 CODEC_ID_H263P, | |
| 2244 sizeof(MpegEncContext), | |
| 2245 MPV_encode_init, | |
| 2246 MPV_encode_picture, | |
| 2247 MPV_encode_end, | |
| 2248 }; | |
| 2249 | |
| 2250 AVCodec rv10_encoder = { | |
| 2251 "rv10", | |
| 2252 CODEC_TYPE_VIDEO, | |
| 2253 CODEC_ID_RV10, | |
| 2254 sizeof(MpegEncContext), | |
| 2255 MPV_encode_init, | |
| 2256 MPV_encode_picture, | |
| 2257 MPV_encode_end, | |
| 2258 }; | |
| 2259 | |
| 2260 AVCodec mjpeg_encoder = { | |
| 2261 "mjpeg", | |
| 2262 CODEC_TYPE_VIDEO, | |
| 2263 CODEC_ID_MJPEG, | |
| 2264 sizeof(MpegEncContext), | |
| 2265 MPV_encode_init, | |
| 2266 MPV_encode_picture, | |
| 2267 MPV_encode_end, | |
| 2268 }; | |
| 2269 | |
| 71 | 2270 AVCodec mpeg4_encoder = { |
| 2271 "mpeg4", | |
| 0 | 2272 CODEC_TYPE_VIDEO, |
| 71 | 2273 CODEC_ID_MPEG4, |
| 0 | 2274 sizeof(MpegEncContext), |
| 2275 MPV_encode_init, | |
| 2276 MPV_encode_picture, | |
| 2277 MPV_encode_end, | |
| 2278 }; | |
| 2279 | |
| 307 | 2280 AVCodec msmpeg4v1_encoder = { |
| 2281 "msmpeg4v1", | |
| 0 | 2282 CODEC_TYPE_VIDEO, |
| 307 | 2283 CODEC_ID_MSMPEG4V1, |
| 0 | 2284 sizeof(MpegEncContext), |
| 2285 MPV_encode_init, | |
| 2286 MPV_encode_picture, | |
| 2287 MPV_encode_end, | |
| 2288 }; | |
| 307 | 2289 |
| 2290 AVCodec msmpeg4v2_encoder = { | |
| 2291 "msmpeg4v2", | |
| 2292 CODEC_TYPE_VIDEO, | |
| 2293 CODEC_ID_MSMPEG4V2, | |
| 2294 sizeof(MpegEncContext), | |
| 2295 MPV_encode_init, | |
| 2296 MPV_encode_picture, | |
| 2297 MPV_encode_end, | |
| 2298 }; | |
| 2299 | |
| 2300 AVCodec msmpeg4v3_encoder = { | |
| 2301 "msmpeg4", | |
| 2302 CODEC_TYPE_VIDEO, | |
| 2303 CODEC_ID_MSMPEG4V3, | |
| 2304 sizeof(MpegEncContext), | |
| 2305 MPV_encode_init, | |
| 2306 MPV_encode_picture, | |
| 2307 MPV_encode_end, | |
| 2308 }; |
