Mercurial > libavcodec.hg
annotate mpegvideo.c @ 582:5132a4ee50cd libavcodec
different edge positions fixed with edge emu / dr1
| author | michaelni |
|---|---|
| date | Thu, 25 Jul 2002 20:22:36 +0000 |
| parents | 23eee7d73c4b |
| children | 9e271424160f |
| rev | line source |
|---|---|
| 0 | 1 /* |
| 2 * The simplest mpeg encoder (well, it was the simplest!) | |
| 429 | 3 * Copyright (c) 2000,2001 Fabrice Bellard. |
| 0 | 4 * |
| 429 | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Lesser General Public | |
| 7 * License as published by the Free Software Foundation; either | |
| 8 * version 2 of the License, or (at your option) any later version. | |
| 0 | 9 * |
| 429 | 10 * This library is distributed in the hope that it will be useful, |
| 0 | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 429 | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Lesser General Public License for more details. | |
| 0 | 14 * |
| 429 | 15 * You should have received a copy of the GNU Lesser General Public |
| 16 * License along with this library; if not, write to the Free Software | |
| 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 295 | 18 * |
| 325 | 19 * 4MV & hq & b-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at> |
| 0 | 20 */ |
| 21 #include "avcodec.h" | |
| 22 #include "dsputil.h" | |
| 23 #include "mpegvideo.h" | |
| 24 | |
|
17
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
25 #ifdef USE_FASTMEMCPY |
|
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
26 #include "fastmemcpy.h" |
|
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
27 #endif |
|
b69fe46fd708
Adding fastmemcpy stuff to speedup mplayer project
nickols_k
parents:
13
diff
changeset
|
28 |
|
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
|
29 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
|
30 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
|
31 DCTELEM *block, int n, int qscale); |
| 325 | 32 static void dct_unquantize_mpeg2_c(MpegEncContext *s, |
| 33 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
|
34 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
|
35 DCTELEM *block, int n, int qscale); |
| 206 | 36 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w); |
| 344 | 37 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); |
| 206 | 38 |
| 344 | 39 int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow)= dct_quantize_c; |
| 206 | 40 void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w)= draw_edges_c; |
| 566 | 41 static void emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int block_w, int block_h, |
| 42 int src_x, int src_y, int w, int h); | |
| 206 | 43 |
| 0 | 44 #define EDGE_WIDTH 16 |
| 45 | |
| 46 /* enable all paranoid tests for rounding, overflows, etc... */ | |
| 47 //#define PARANOID | |
| 48 | |
| 49 //#define DEBUG | |
| 50 | |
| 321 | 51 |
| 0 | 52 /* for jpeg fast DCT */ |
| 53 #define CONST_BITS 14 | |
| 54 | |
| 55 static const unsigned short aanscales[64] = { | |
| 56 /* precomputed values scaled up by 14 bits */ | |
| 57 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
| 58 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270, | |
| 59 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906, | |
| 60 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315, | |
| 61 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520, | |
| 62 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552, | |
| 63 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446, | |
| 64 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247 | |
| 65 }; | |
| 66 | |
| 67 static UINT8 h263_chroma_roundtab[16] = { | |
| 68 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, | |
| 69 }; | |
| 70 | |
|
292
73a9ce3d9715
fcode_tables where too small, found by Klaas-Pieter Vlieg <vlieg@eurescom.de>
michaelni
parents:
288
diff
changeset
|
71 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
|
72 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
|
73 |
| 321 | 74 extern UINT8 zigzag_end[64]; |
| 75 | |
| 0 | 76 /* default motion estimation */ |
| 321 | 77 int motion_estimation_method = ME_EPZS; |
| 200 | 78 |
| 344 | 79 static void convert_matrix(int (*qmat)[64], uint16_t (*qmat16)[64], uint16_t (*qmat16_bias)[64], |
| 80 const UINT16 *quant_matrix, int bias) | |
| 0 | 81 { |
| 344 | 82 int qscale; |
| 0 | 83 |
| 344 | 84 for(qscale=1; qscale<32; qscale++){ |
| 85 int i; | |
|
474
11dbd00682fc
avoid name clash with libjpeg - added missing externs
bellard
parents:
467
diff
changeset
|
86 if (av_fdct == fdct_ifast) { |
| 344 | 87 for(i=0;i<64;i++) { |
| 88 const int j= block_permute_op(i); | |
| 89 /* 16 <= qscale * quant_matrix[i] <= 7905 */ | |
| 90 /* 19952 <= aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ | |
| 91 /* (1<<36)/19952 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ | |
| 92 /* 3444240 >= (1<<36)/(aanscales[i] * qscale * quant_matrix[i]) >= 275 */ | |
| 93 | |
| 94 qmat[qscale][j] = (int)((UINT64_C(1) << (QMAT_SHIFT + 11)) / | |
| 95 (aanscales[i] * qscale * quant_matrix[j])); | |
| 96 } | |
| 97 } else { | |
| 98 for(i=0;i<64;i++) { | |
| 99 /* We can safely suppose that 16 <= quant_matrix[i] <= 255 | |
| 100 So 16 <= qscale * quant_matrix[i] <= 7905 | |
| 101 so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 | |
| 102 so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 | |
| 103 */ | |
| 104 qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); | |
| 105 qmat16[qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[block_permute_op(i)]); | |
| 106 | |
| 107 if(qmat16[qscale][i]==0 || qmat16[qscale][i]==128*256) qmat16[qscale][i]=128*256-1; | |
| 108 | |
| 109 qmat16_bias[qscale][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][i]); | |
| 110 } | |
| 0 | 111 } |
| 112 } | |
| 113 } | |
| 456 | 114 // move into common.c perhaps |
| 115 #define CHECKED_ALLOCZ(p, size)\ | |
| 116 {\ | |
| 117 p= av_mallocz(size);\ | |
| 118 if(p==NULL){\ | |
| 119 perror("malloc");\ | |
| 120 goto fail;\ | |
| 121 }\ | |
| 122 } | |
| 0 | 123 |
| 124 /* init common structure for both encoder and decoder */ | |
| 125 int MPV_common_init(MpegEncContext *s) | |
| 126 { | |
| 127 int c_size, i; | |
| 128 UINT8 *pict; | |
| 129 | |
| 312 | 130 s->dct_unquantize_h263 = dct_unquantize_h263_c; |
| 325 | 131 s->dct_unquantize_mpeg1 = dct_unquantize_mpeg1_c; |
| 132 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
|
133 |
|
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
|
134 #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
|
135 MPV_common_init_mmx(s); |
| 8 | 136 #endif |
|
514
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M?ns Rullg?rd
mellum
parents:
506
diff
changeset
|
137 #ifdef ARCH_ALPHA |
|
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M?ns Rullg?rd
mellum
parents:
506
diff
changeset
|
138 MPV_common_init_axp(s); |
|
c9f724e3a797
Update and activate dct_unquantize_h263_mvi. Thanks to M?ns Rullg?rd
mellum
parents:
506
diff
changeset
|
139 #endif |
| 312 | 140 //setup default unquantizers (mpeg4 might change it later) |
| 141 if(s->out_format == FMT_H263) | |
| 142 s->dct_unquantize = s->dct_unquantize_h263; | |
| 143 else | |
| 325 | 144 s->dct_unquantize = s->dct_unquantize_mpeg1; |
| 312 | 145 |
| 0 | 146 s->mb_width = (s->width + 15) / 16; |
| 147 s->mb_height = (s->height + 15) / 16; | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
148 |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
149 /* set default edge pos, will be overriden in decode_header if needed */ |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
150 s->h_edge_pos= s->mb_width*16; |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
151 s->v_edge_pos= s->mb_height*16; |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
152 |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
153 s->mb_num = s->mb_width * s->mb_height; |
| 553 | 154 if(!(s->flags&CODEC_FLAG_DR1)){ |
| 556 | 155 s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH; |
| 156 s->uvlinesize = s->mb_width * 8 + EDGE_WIDTH; | |
| 0 | 157 |
| 553 | 158 for(i=0;i<3;i++) { |
| 0 | 159 int w, h, shift, pict_start; |
| 160 | |
| 161 w = s->linesize; | |
| 162 h = s->mb_height * 16 + 2 * EDGE_WIDTH; | |
| 163 shift = (i == 0) ? 0 : 1; | |
| 556 | 164 c_size = (s->linesize>>shift) * (h >> shift); |
| 165 pict_start = (s->linesize>>shift) * (EDGE_WIDTH >> shift) + (EDGE_WIDTH >> shift); | |
| 0 | 166 |
| 456 | 167 CHECKED_ALLOCZ(pict, c_size) |
| 0 | 168 s->last_picture_base[i] = pict; |
| 169 s->last_picture[i] = pict + pict_start; | |
| 485 | 170 if(i>0) memset(s->last_picture_base[i], 128, c_size); |
| 0 | 171 |
| 456 | 172 CHECKED_ALLOCZ(pict, c_size) |
| 0 | 173 s->next_picture_base[i] = pict; |
| 174 s->next_picture[i] = pict + pict_start; | |
| 485 | 175 if(i>0) memset(s->next_picture_base[i], 128, c_size); |
| 324 | 176 |
|
365
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
350
diff
changeset
|
177 if (s->has_b_frames || s->codec_id==CODEC_ID_MPEG4) { |
|
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
350
diff
changeset
|
178 /* Note the MPEG4 stuff is here cuz of buggy encoders which dont set the low_delay flag but |
|
fdeec2834c79
there are divx5? encoded files without a userdata section but with b-frames :(
michaelni
parents:
350
diff
changeset
|
179 do low-delay encoding, so we cant allways distinguish b-frame containing streams from low_delay streams */ |
| 456 | 180 CHECKED_ALLOCZ(pict, c_size) |
| 0 | 181 s->aux_picture_base[i] = pict; |
| 182 s->aux_picture[i] = pict + pict_start; | |
| 485 | 183 if(i>0) memset(s->aux_picture_base[i], 128, c_size); |
| 0 | 184 } |
| 553 | 185 } |
| 556 | 186 s->ip_buffer_count= 2; |
| 0 | 187 } |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
188 |
|
567
5a6eaaa9fba2
larger edge emu buffer (might have been too small)
michaelni
parents:
566
diff
changeset
|
189 CHECKED_ALLOCZ(s->edge_emu_buffer, (s->width+64)*2*17*2); //(width + edge + align)*interlaced*MBsize*tolerance |
| 553 | 190 |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
191 if (s->encoding) { |
| 324 | 192 int j; |
| 193 int mv_table_size= (s->mb_width+2)*(s->mb_height+2); | |
| 239 | 194 |
| 456 | 195 CHECKED_ALLOCZ(s->mb_var , s->mb_num * sizeof(INT16)) |
| 196 CHECKED_ALLOCZ(s->mc_mb_var, s->mb_num * sizeof(INT16)) | |
| 324 | 197 |
| 198 /* Allocate MV tables */ | |
| 456 | 199 CHECKED_ALLOCZ(s->p_mv_table , mv_table_size * 2 * sizeof(INT16)) |
| 200 CHECKED_ALLOCZ(s->b_forw_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
| 201 CHECKED_ALLOCZ(s->b_back_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
| 202 CHECKED_ALLOCZ(s->b_bidir_forw_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
| 203 CHECKED_ALLOCZ(s->b_bidir_back_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
| 204 CHECKED_ALLOCZ(s->b_direct_forw_mv_table, mv_table_size * 2 * sizeof(INT16)) | |
| 205 CHECKED_ALLOCZ(s->b_direct_back_mv_table, mv_table_size * 2 * sizeof(INT16)) | |
| 206 CHECKED_ALLOCZ(s->b_direct_mv_table , mv_table_size * 2 * sizeof(INT16)) | |
| 324 | 207 |
| 456 | 208 CHECKED_ALLOCZ(s->me_scratchpad, s->linesize*16*3*sizeof(uint8_t)) |
| 209 | |
| 210 CHECKED_ALLOCZ(s->me_map , ME_MAP_SIZE*sizeof(uint32_t)) | |
| 211 CHECKED_ALLOCZ(s->me_score_map, ME_MAP_SIZE*sizeof(uint16_t)) | |
| 327 | 212 |
| 324 | 213 if(s->max_b_frames){ |
| 214 for(j=0; j<REORDER_BUFFER_SIZE; j++){ | |
| 215 int i; | |
| 216 for(i=0;i<3;i++) { | |
| 217 int w, h, shift; | |
| 218 | |
| 219 w = s->linesize; | |
| 220 h = s->mb_height * 16; | |
| 221 shift = (i == 0) ? 0 : 1; | |
| 222 c_size = (w >> shift) * (h >> shift); | |
| 223 | |
| 456 | 224 CHECKED_ALLOCZ(pict, c_size); |
| 324 | 225 s->picture_buffer[j][i] = pict; |
| 226 } | |
| 227 } | |
| 228 } | |
| 456 | 229 |
| 230 if(s->codec_id==CODEC_ID_MPEG4){ | |
| 231 CHECKED_ALLOCZ(s->tex_pb_buffer, PB_BUFFER_SIZE); | |
| 232 CHECKED_ALLOCZ( s->pb2_buffer, PB_BUFFER_SIZE); | |
| 233 } | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
234 } |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
235 |
| 288 | 236 if (s->out_format == FMT_H263 || s->encoding) { |
| 0 | 237 int size; |
| 456 | 238 /* Allocate MB type table */ |
| 239 CHECKED_ALLOCZ(s->mb_type , s->mb_num * sizeof(UINT8)) | |
| 240 | |
| 0 | 241 /* MV prediction */ |
| 242 size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | |
| 456 | 243 CHECKED_ALLOCZ(s->motion_val, size * 2 * sizeof(INT16)); |
| 0 | 244 } |
| 245 | |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
246 if (s->h263_pred || s->h263_plus) { |
| 0 | 247 int y_size, c_size, i, size; |
| 248 | |
| 249 /* dc values */ | |
| 250 | |
| 251 y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | |
| 252 c_size = (s->mb_width + 2) * (s->mb_height + 2); | |
| 253 size = y_size + 2 * c_size; | |
| 456 | 254 CHECKED_ALLOCZ(s->dc_val[0], size * sizeof(INT16)); |
| 0 | 255 s->dc_val[1] = s->dc_val[0] + y_size; |
| 256 s->dc_val[2] = s->dc_val[1] + c_size; | |
| 257 for(i=0;i<size;i++) | |
| 258 s->dc_val[0][i] = 1024; | |
| 259 | |
| 260 /* ac values */ | |
| 456 | 261 CHECKED_ALLOCZ(s->ac_val[0], size * sizeof(INT16) * 16); |
| 0 | 262 s->ac_val[1] = s->ac_val[0] + y_size; |
| 263 s->ac_val[2] = s->ac_val[1] + c_size; | |
| 264 | |
| 265 /* cbp values */ | |
| 456 | 266 CHECKED_ALLOCZ(s->coded_block, y_size); |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
267 |
|
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
268 /* which mb is a intra block */ |
| 456 | 269 CHECKED_ALLOCZ(s->mbintra_table, s->mb_num); |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
270 memset(s->mbintra_table, 1, s->mb_num); |
| 333 | 271 |
| 272 /* divx501 bitstream reorder buffer */ | |
| 456 | 273 CHECKED_ALLOCZ(s->bitstream_buffer, BITSTREAM_BUFFER_SIZE); |
| 274 | |
| 275 /* cbp, ac_pred, pred_dir */ | |
| 276 CHECKED_ALLOCZ(s->cbp_table , s->mb_num * sizeof(UINT8)) | |
| 277 CHECKED_ALLOCZ(s->pred_dir_table, s->mb_num * sizeof(UINT8)) | |
|
197
21abf1b20016
different fix, s->mbintra_table used only if h263_pred set. - patch by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
196
diff
changeset
|
278 } |
| 575 | 279 CHECKED_ALLOCZ(s->qscale_table , s->mb_num * sizeof(UINT8)) |
| 280 | |
| 0 | 281 /* default structure is frame */ |
| 282 s->picture_structure = PICT_FRAME; | |
| 553 | 283 |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
284 /* init macroblock skip table */ |
| 456 | 285 CHECKED_ALLOCZ(s->mbskip_table, s->mb_num); |
| 294 | 286 |
| 327 | 287 s->block= s->blocks[0]; |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
288 |
| 0 | 289 s->context_initialized = 1; |
| 290 return 0; | |
| 291 fail: | |
| 244 | 292 MPV_common_end(s); |
| 293 return -1; | |
| 294 } | |
| 295 | |
| 456 | 296 |
| 297 //extern int sads; | |
| 298 | |
| 244 | 299 /* init common structure for both encoder and decoder */ |
| 300 void MPV_common_end(MpegEncContext *s) | |
| 301 { | |
| 302 int i; | |
| 303 | |
|
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
304 av_freep(&s->mb_type); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
305 av_freep(&s->mb_var); |
| 456 | 306 av_freep(&s->mc_mb_var); |
|
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
307 av_freep(&s->p_mv_table); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
308 av_freep(&s->b_forw_mv_table); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
309 av_freep(&s->b_back_mv_table); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
310 av_freep(&s->b_bidir_forw_mv_table); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
311 av_freep(&s->b_bidir_back_mv_table); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
312 av_freep(&s->b_direct_forw_mv_table); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
313 av_freep(&s->b_direct_back_mv_table); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
314 av_freep(&s->b_direct_mv_table); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
315 av_freep(&s->motion_val); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
316 av_freep(&s->dc_val[0]); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
317 av_freep(&s->ac_val[0]); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
318 av_freep(&s->coded_block); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
319 av_freep(&s->mbintra_table); |
| 456 | 320 av_freep(&s->cbp_table); |
| 321 av_freep(&s->pred_dir_table); | |
| 322 av_freep(&s->qscale_table); | |
|
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
323 av_freep(&s->me_scratchpad); |
| 456 | 324 av_freep(&s->me_map); |
| 325 av_freep(&s->me_score_map); | |
| 326 | |
|
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
327 av_freep(&s->mbskip_table); |
|
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
328 av_freep(&s->bitstream_buffer); |
| 456 | 329 av_freep(&s->tex_pb_buffer); |
| 330 av_freep(&s->pb2_buffer); | |
| 553 | 331 av_freep(&s->edge_emu_buffer); |
| 332 | |
| 0 | 333 for(i=0;i<3;i++) { |
| 324 | 334 int j; |
| 553 | 335 if(!(s->flags&CODEC_FLAG_DR1)){ |
| 336 av_freep(&s->last_picture_base[i]); | |
| 337 av_freep(&s->next_picture_base[i]); | |
| 338 av_freep(&s->aux_picture_base[i]); | |
| 339 } | |
| 340 s->last_picture_base[i]= | |
| 341 s->next_picture_base[i]= | |
| 342 s->aux_picture_base [i] = NULL; | |
| 343 s->last_picture[i]= | |
| 344 s->next_picture[i]= | |
| 345 s->aux_picture [i] = NULL; | |
| 346 | |
| 324 | 347 for(j=0; j<REORDER_BUFFER_SIZE; j++){ |
|
396
fce0a2520551
removed useless header includes - use av memory functions
glantau
parents:
376
diff
changeset
|
348 av_freep(&s->picture_buffer[j][i]); |
| 324 | 349 } |
| 0 | 350 } |
| 351 s->context_initialized = 0; | |
| 352 } | |
| 353 | |
| 354 /* init video encoder */ | |
| 355 int MPV_encode_init(AVCodecContext *avctx) | |
| 356 { | |
| 357 MpegEncContext *s = avctx->priv_data; | |
| 60 | 358 int i; |
| 0 | 359 |
| 315 | 360 avctx->pix_fmt = PIX_FMT_YUV420P; |
| 361 | |
| 0 | 362 s->bit_rate = avctx->bit_rate; |
| 268 | 363 s->bit_rate_tolerance = avctx->bit_rate_tolerance; |
| 0 | 364 s->frame_rate = avctx->frame_rate; |
| 365 s->width = avctx->width; | |
| 366 s->height = avctx->height; | |
| 456 | 367 if(avctx->gop_size > 600){ |
|
462
3fdd0627f6bd
typo (found by Bohdan Horst <nexus at hoth.amu.edu.pl>)
michaelni
parents:
461
diff
changeset
|
368 fprintf(stderr, "Warning keyframe interval too large! reducing it ...\n"); |
| 456 | 369 avctx->gop_size=600; |
| 370 } | |
| 0 | 371 s->gop_size = avctx->gop_size; |
| 162 | 372 s->rtp_mode = avctx->rtp_mode; |
| 373 s->rtp_payload_size = avctx->rtp_payload_size; | |
| 231 | 374 if (avctx->rtp_callback) |
| 375 s->rtp_callback = avctx->rtp_callback; | |
| 268 | 376 s->qmin= avctx->qmin; |
| 377 s->qmax= avctx->qmax; | |
| 378 s->max_qdiff= avctx->max_qdiff; | |
| 379 s->qcompress= avctx->qcompress; | |
| 380 s->qblur= avctx->qblur; | |
| 329 | 381 s->b_quant_factor= avctx->b_quant_factor; |
| 456 | 382 s->b_quant_offset= avctx->b_quant_offset; |
|
194
27d1773552c9
mpeg4 encoder fix by Michael Niedermayer <michaelni@gmx.at>
arpi_esp
parents:
191
diff
changeset
|
383 s->avctx = avctx; |
|
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
384 s->aspect_ratio_info= avctx->aspect_ratio_info; |
| 294 | 385 s->flags= avctx->flags; |
| 324 | 386 s->max_b_frames= avctx->max_b_frames; |
| 329 | 387 s->rc_strategy= avctx->rc_strategy; |
| 388 s->b_frame_strategy= avctx->b_frame_strategy; | |
| 344 | 389 s->codec_id= avctx->codec->id; |
| 456 | 390 s->luma_elim_threshold = avctx->luma_elim_threshold; |
| 391 s->chroma_elim_threshold= avctx->chroma_elim_threshold; | |
| 392 s->strict_std_compliance= avctx->strict_std_compliance; | |
| 393 s->data_partitioning= avctx->flags & CODEC_FLAG_PART; | |
| 344 | 394 |
| 0 | 395 if (s->gop_size <= 1) { |
| 396 s->intra_only = 1; | |
| 397 s->gop_size = 12; | |
| 398 } else { | |
| 399 s->intra_only = 0; | |
| 400 } | |
|
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
401 |
|
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
402 /* ME algorithm */ |
| 321 | 403 if (avctx->me_method == 0) |
| 404 /* For compatibility */ | |
| 405 s->me_method = motion_estimation_method; | |
| 406 else | |
| 407 s->me_method = avctx->me_method; | |
| 408 | |
|
320
cda7d0857baf
- ME setting moved to AVCodecContext/MpegEncContext, no longer a global.
pulento
parents:
315
diff
changeset
|
409 /* Fixed QSCALE */ |
| 0 | 410 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
|
411 |
| 0 | 412 switch(avctx->codec->id) { |
| 413 case CODEC_ID_MPEG1VIDEO: | |
| 414 s->out_format = FMT_MPEG1; | |
| 336 | 415 avctx->delay=0; //FIXME not sure, should check the spec |
| 0 | 416 break; |
| 417 case CODEC_ID_MJPEG: | |
| 418 s->out_format = FMT_MJPEG; | |
| 419 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
|
420 s->mjpeg_write_tables = 1; /* write all tables */ |
|
370
0eca28d16cbd
clamp intra matrix to 8bit for mjpeg (workaround for qscale>=25)
al3x
parents:
365
diff
changeset
|
421 s->mjpeg_data_only_frames = 0; /* write all the needed headers */ |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
422 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
|
423 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
|
424 s->mjpeg_vsample[2] = 1; |
|
370
0eca28d16cbd
clamp intra matrix to 8bit for mjpeg (workaround for qscale>=25)
al3x
parents:
365
diff
changeset
|
425 s->mjpeg_hsample[0] = 2; |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
426 s->mjpeg_hsample[1] = 1; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
427 s->mjpeg_hsample[2] = 1; |
| 0 | 428 if (mjpeg_init(s) < 0) |
| 429 return -1; | |
| 336 | 430 avctx->delay=0; |
| 0 | 431 break; |
| 432 case CODEC_ID_H263: | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
433 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
|
434 printf("Input picture size isn't suitable for h263 codec! try h263+\n"); |
| 0 | 435 return -1; |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
436 } |
| 0 | 437 s->out_format = FMT_H263; |
| 336 | 438 avctx->delay=0; |
| 0 | 439 break; |
| 440 case CODEC_ID_H263P: | |
| 441 s->out_format = FMT_H263; | |
| 162 | 442 s->rtp_mode = 1; |
| 443 s->rtp_payload_size = 1200; | |
| 0 | 444 s->h263_plus = 1; |
| 78 | 445 s->unrestricted_mv = 1; |
|
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
446 s->h263_aic = 1; |
|
79
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
447 |
|
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
448 /* These are just to be sure */ |
|
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
449 s->umvplus = 0; |
|
82e579c37bc3
Moved some H.263+ variables to MpegEncContext to be thread-safe.
pulento
parents:
78
diff
changeset
|
450 s->umvplus_dec = 0; |
| 336 | 451 avctx->delay=0; |
| 0 | 452 break; |
| 453 case CODEC_ID_RV10: | |
| 454 s->out_format = FMT_H263; | |
| 455 s->h263_rv10 = 1; | |
| 336 | 456 avctx->delay=0; |
| 0 | 457 break; |
| 71 | 458 case CODEC_ID_MPEG4: |
| 0 | 459 s->out_format = FMT_H263; |
| 460 s->h263_pred = 1; | |
| 461 s->unrestricted_mv = 1; | |
| 324 | 462 s->has_b_frames= s->max_b_frames ? 1 : 0; |
| 336 | 463 s->low_delay=0; |
| 464 avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); | |
| 0 | 465 break; |
| 307 | 466 case CODEC_ID_MSMPEG4V1: |
| 0 | 467 s->out_format = FMT_H263; |
| 468 s->h263_msmpeg4 = 1; | |
| 469 s->h263_pred = 1; | |
| 470 s->unrestricted_mv = 1; | |
| 307 | 471 s->msmpeg4_version= 1; |
| 336 | 472 avctx->delay=0; |
| 307 | 473 break; |
| 474 case CODEC_ID_MSMPEG4V2: | |
| 475 s->out_format = FMT_H263; | |
| 476 s->h263_msmpeg4 = 1; | |
| 477 s->h263_pred = 1; | |
| 478 s->unrestricted_mv = 1; | |
| 479 s->msmpeg4_version= 2; | |
| 336 | 480 avctx->delay=0; |
| 307 | 481 break; |
| 482 case CODEC_ID_MSMPEG4V3: | |
| 483 s->out_format = FMT_H263; | |
| 484 s->h263_msmpeg4 = 1; | |
| 485 s->h263_pred = 1; | |
| 486 s->unrestricted_mv = 1; | |
| 487 s->msmpeg4_version= 3; | |
| 336 | 488 avctx->delay=0; |
| 0 | 489 break; |
| 499 | 490 case CODEC_ID_WMV1: |
| 491 s->out_format = FMT_H263; | |
| 492 s->h263_msmpeg4 = 1; | |
| 493 s->h263_pred = 1; | |
| 494 s->unrestricted_mv = 1; | |
| 495 s->msmpeg4_version= 4; | |
| 496 avctx->delay=0; | |
| 497 break; | |
| 498 case CODEC_ID_WMV2: | |
| 499 s->out_format = FMT_H263; | |
| 500 s->h263_msmpeg4 = 1; | |
| 501 s->h263_pred = 1; | |
| 502 s->unrestricted_mv = 1; | |
| 503 s->msmpeg4_version= 5; | |
| 504 avctx->delay=0; | |
| 505 break; | |
| 0 | 506 default: |
| 507 return -1; | |
| 508 } | |
| 295 | 509 |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
510 { /* 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
|
511 static int done=0; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
512 if(!done){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
513 int i; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
514 done=1; |
|
292
73a9ce3d9715
fcode_tables where too small, found by Klaas-Pieter Vlieg <vlieg@eurescom.de>
michaelni
parents:
288
diff
changeset
|
515 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
|
516 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
|
517 |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
518 for(i=-16; i<16; i++){ |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
519 default_fcode_tab[i + MAX_MV]= 1; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
520 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
521 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
522 } |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
523 s->mv_penalty= default_mv_penalty; |
|
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
524 s->fcode_tab= default_fcode_tab; |
|
506
b9ed0ae72d51
init dc_scale tables to defaults (fixes mjpeg sig11)
michaelni
parents:
499
diff
changeset
|
525 s->y_dc_scale_table= |
|
b9ed0ae72d51
init dc_scale tables to defaults (fixes mjpeg sig11)
michaelni
parents:
499
diff
changeset
|
526 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; |
|
b9ed0ae72d51
init dc_scale tables to defaults (fixes mjpeg sig11)
michaelni
parents:
499
diff
changeset
|
527 |
| 0 | 528 if (s->out_format == FMT_H263) |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
529 h263_encode_init(s); |
|
281
1fc96b02142e
mpeg4 aspect_ratio_info in AVCodecContext (requested by alex)
michaelni
parents:
280
diff
changeset
|
530 else if (s->out_format == FMT_MPEG1) |
| 499 | 531 ff_mpeg1_encode_init(s); |
| 532 if(s->msmpeg4_version) | |
| 533 ff_msmpeg4_encode_init(s); | |
| 0 | 534 |
| 287 | 535 /* dont use mv_penalty table for crap MV as it would be confused */ |
| 324 | 536 if (s->me_method < ME_EPZS) s->mv_penalty = default_mv_penalty; |
| 287 | 537 |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
538 s->encoding = 1; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
539 |
| 0 | 540 /* init */ |
| 541 if (MPV_common_init(s) < 0) | |
| 542 return -1; | |
| 543 | |
| 60 | 544 /* init default q matrix */ |
| 545 for(i=0;i<64;i++) { | |
| 344 | 546 if(s->out_format == FMT_H263) |
|
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
514
diff
changeset
|
547 s->intra_matrix[i] = ff_mpeg1_default_non_intra_matrix[i]; |
| 344 | 548 else |
|
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
514
diff
changeset
|
549 s->intra_matrix[i] = ff_mpeg1_default_intra_matrix[i]; |
| 344 | 550 |
|
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
514
diff
changeset
|
551 s->inter_matrix[i] = ff_mpeg1_default_non_intra_matrix[i]; |
| 344 | 552 } |
| 553 | |
| 554 /* precompute matrix */ | |
|
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
555 /* for mjpeg, we do include qscale in the matrix */ |
| 344 | 556 if (s->out_format != FMT_MJPEG) { |
| 557 convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias, | |
| 558 s->intra_matrix, s->intra_quant_bias); | |
| 559 convert_matrix(s->q_inter_matrix, s->q_inter_matrix16, s->q_inter_matrix16_bias, | |
| 560 s->inter_matrix, s->inter_quant_bias); | |
| 60 | 561 } |
| 562 | |
| 329 | 563 if(ff_rate_control_init(s) < 0) |
| 564 return -1; | |
| 0 | 565 |
| 566 s->picture_number = 0; | |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
567 s->picture_in_gop_number = 0; |
| 0 | 568 s->fake_picture_number = 0; |
| 569 /* motion detector init */ | |
| 570 s->f_code = 1; | |
| 324 | 571 s->b_code = 1; |
| 0 | 572 |
| 573 return 0; | |
| 574 } | |
| 575 | |
| 576 int MPV_encode_end(AVCodecContext *avctx) | |
| 577 { | |
| 578 MpegEncContext *s = avctx->priv_data; | |
| 579 | |
| 580 #ifdef STATS | |
| 581 print_stats(); | |
| 582 #endif | |
| 329 | 583 |
| 584 ff_rate_control_uninit(s); | |
| 585 | |
| 0 | 586 MPV_common_end(s); |
| 587 if (s->out_format == FMT_MJPEG) | |
| 588 mjpeg_close(s); | |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
589 |
| 0 | 590 return 0; |
| 591 } | |
| 592 | |
| 593 /* draw the edges of width 'w' of an image of size width, height */ | |
| 206 | 594 static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w) |
| 0 | 595 { |
| 596 UINT8 *ptr, *last_line; | |
| 597 int i; | |
| 598 | |
| 599 last_line = buf + (height - 1) * wrap; | |
| 600 for(i=0;i<w;i++) { | |
| 601 /* top and bottom */ | |
| 602 memcpy(buf - (i + 1) * wrap, buf, width); | |
| 603 memcpy(last_line + (i + 1) * wrap, last_line, width); | |
| 604 } | |
| 605 /* left and right */ | |
| 606 ptr = buf; | |
| 607 for(i=0;i<height;i++) { | |
| 608 memset(ptr - w, ptr[0], w); | |
| 609 memset(ptr + width, ptr[width-1], w); | |
| 610 ptr += wrap; | |
| 611 } | |
| 612 /* corners */ | |
| 613 for(i=0;i<w;i++) { | |
| 614 memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */ | |
| 615 memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */ | |
| 616 memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */ | |
| 617 memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */ | |
| 618 } | |
| 619 } | |
| 620 | |
| 621 /* generic function for encode/decode called before a frame is coded/decoded */ | |
| 553 | 622 void MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) |
| 0 | 623 { |
| 624 int i; | |
| 625 UINT8 *tmp; | |
| 626 | |
|
46
931417475f5b
fixed mpeg1 first block bug (pb with black picture optimisation for B frames)
glantau
parents:
40
diff
changeset
|
627 s->mb_skiped = 0; |
| 456 | 628 s->decoding_error=0; |
|
562
23e58889a108
exporting mbskip_table after it has been allocated
michaelni
parents:
557
diff
changeset
|
629 avctx->mbskip_table= s->mbskip_table; |
| 456 | 630 |
| 553 | 631 if(avctx->flags&CODEC_FLAG_DR1){ |
| 632 avctx->get_buffer_callback(avctx, s->width, s->height, s->pict_type); | |
| 633 | |
| 556 | 634 s->linesize = avctx->dr_stride; |
| 635 s->uvlinesize= avctx->dr_uvstride; | |
| 636 s->ip_buffer_count= avctx->dr_ip_buffer_count; | |
| 553 | 637 } |
|
562
23e58889a108
exporting mbskip_table after it has been allocated
michaelni
parents:
557
diff
changeset
|
638 avctx->dr_ip_buffer_count= s->ip_buffer_count; |
| 553 | 639 |
| 0 | 640 if (s->pict_type == B_TYPE) { |
| 641 for(i=0;i<3;i++) { | |
| 553 | 642 if(avctx->flags&CODEC_FLAG_DR1) |
| 643 s->aux_picture[i]= avctx->dr_buffer[i]; | |
| 569 | 644 |
| 645 //FIXME the following should never be needed, the decoder should drop b frames if no reference is available | |
| 646 if(s->next_picture[i]==NULL) | |
| 647 s->next_picture[i]= s->aux_picture[i]; | |
| 648 if(s->last_picture[i]==NULL) | |
| 649 s->last_picture[i]= s->next_picture[i]; | |
| 553 | 650 |
| 0 | 651 s->current_picture[i] = s->aux_picture[i]; |
| 652 } | |
| 653 } else { | |
| 654 for(i=0;i<3;i++) { | |
| 655 /* swap next and last */ | |
| 553 | 656 if(avctx->flags&CODEC_FLAG_DR1) |
| 657 tmp= avctx->dr_buffer[i]; | |
| 658 else | |
| 659 tmp = s->last_picture[i]; | |
| 660 | |
| 0 | 661 s->last_picture[i] = s->next_picture[i]; |
| 662 s->next_picture[i] = tmp; | |
| 663 s->current_picture[i] = tmp; | |
| 553 | 664 |
| 665 s->last_dr_opaque= s->next_dr_opaque; | |
| 666 s->next_dr_opaque= avctx->dr_opaque_frame; | |
| 667 | |
| 557 | 668 if(s->has_b_frames && s->last_dr_opaque && s->codec_id!=CODEC_ID_SVQ1) |
| 553 | 669 avctx->dr_opaque_frame= s->last_dr_opaque; |
| 670 else | |
| 671 avctx->dr_opaque_frame= s->next_dr_opaque; | |
| 0 | 672 } |
| 673 } | |
| 674 } | |
|
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
|
675 |
| 0 | 676 /* generic function for encode/decode called after a frame has been coded/decoded */ |
| 677 void MPV_frame_end(MpegEncContext *s) | |
| 678 { | |
| 456 | 679 // if((s->picture_number%100)==0 && s->encoding) printf("sads:%d //\n", sads); |
| 680 | |
| 0 | 681 /* draw edge for correct motion prediction if outside */ |
| 553 | 682 if (s->pict_type != B_TYPE && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) { |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
683 draw_edges(s->current_picture[0], s->linesize , s->h_edge_pos , s->v_edge_pos , EDGE_WIDTH ); |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
684 draw_edges(s->current_picture[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
685 draw_edges(s->current_picture[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); |
| 0 | 686 } |
| 207 | 687 emms_c(); |
| 329 | 688 |
| 689 if(s->pict_type!=B_TYPE){ | |
| 690 s->last_non_b_pict_type= s->pict_type; | |
| 691 s->last_non_b_qscale= s->qscale; | |
| 456 | 692 s->last_non_b_mc_mb_var= s->mc_mb_var_sum; |
| 341 | 693 s->num_available_buffers++; |
| 694 if(s->num_available_buffers>2) s->num_available_buffers= 2; | |
| 329 | 695 } |
| 0 | 696 } |
| 697 | |
| 324 | 698 /* reorder input for encoding */ |
| 699 void reorder_input(MpegEncContext *s, AVPicture *pict) | |
| 700 { | |
| 701 int i, j, index; | |
| 702 | |
| 703 if(s->max_b_frames > FF_MAX_B_FRAMES) s->max_b_frames= FF_MAX_B_FRAMES; | |
| 704 | |
| 705 // delay= s->max_b_frames+1; (or 0 if no b frames cuz decoder diff) | |
| 706 | |
| 707 for(j=0; j<REORDER_BUFFER_SIZE-1; j++){ | |
| 708 s->coded_order[j]= s->coded_order[j+1]; | |
| 709 } | |
| 710 s->coded_order[j].picture[0]= s->coded_order[j].picture[1]= s->coded_order[j].picture[2]= NULL; //catch uninitalized buffers | |
| 339 | 711 s->coded_order[j].pict_type=0; |
| 324 | 712 |
| 713 switch(s->input_pict_type){ | |
| 714 default: | |
| 715 case I_TYPE: | |
| 716 case S_TYPE: | |
| 717 case P_TYPE: | |
| 718 index= s->max_b_frames - s->b_frames_since_non_b; | |
| 719 s->b_frames_since_non_b=0; | |
| 720 break; | |
| 721 case B_TYPE: | |
| 722 index= s->max_b_frames + 1; | |
| 723 s->b_frames_since_non_b++; | |
| 724 break; | |
| 725 } | |
| 726 //printf("index:%d type:%d strides: %d %d\n", index, s->input_pict_type, pict->linesize[0], s->linesize); | |
| 727 if( (index==0 || (s->flags&CODEC_FLAG_INPUT_PRESERVED)) | |
| 728 && pict->linesize[0] == s->linesize | |
| 556 | 729 && pict->linesize[1] == s->uvlinesize |
| 730 && pict->linesize[2] == s->uvlinesize){ | |
| 324 | 731 //printf("ptr\n"); |
| 732 for(i=0; i<3; i++){ | |
| 733 s->coded_order[index].picture[i]= pict->data[i]; | |
| 734 } | |
| 735 }else{ | |
| 736 //printf("copy\n"); | |
| 737 for(i=0; i<3; i++){ | |
| 738 uint8_t *src = pict->data[i]; | |
| 739 uint8_t *dest; | |
| 740 int src_wrap = pict->linesize[i]; | |
| 741 int dest_wrap = s->linesize; | |
| 742 int w = s->width; | |
| 743 int h = s->height; | |
| 744 | |
| 745 if(index==0) dest= s->last_picture[i]+16; //is current_picture indeed but the switch hapens after reordering | |
| 746 else dest= s->picture_buffer[s->picture_buffer_index][i]; | |
| 747 | |
| 748 if (i >= 1) { | |
| 749 dest_wrap >>= 1; | |
| 750 w >>= 1; | |
| 751 h >>= 1; | |
| 752 } | |
| 753 | |
| 754 s->coded_order[index].picture[i]= dest; | |
| 755 for(j=0;j<h;j++) { | |
| 756 memcpy(dest, src, w); | |
| 757 dest += dest_wrap; | |
| 758 src += src_wrap; | |
| 759 } | |
| 760 } | |
| 761 if(index!=0){ | |
| 762 s->picture_buffer_index++; | |
| 763 if(s->picture_buffer_index >= REORDER_BUFFER_SIZE-1) s->picture_buffer_index=0; | |
| 764 } | |
| 765 } | |
| 766 s->coded_order[index].pict_type = s->input_pict_type; | |
| 767 s->coded_order[index].qscale = s->input_qscale; | |
| 768 s->coded_order[index].force_type= s->force_input_type; | |
| 769 s->coded_order[index].picture_in_gop_number= s->input_picture_in_gop_number; | |
| 770 s->coded_order[index].picture_number= s->input_picture_number; | |
| 771 | |
| 772 for(i=0; i<3; i++){ | |
| 773 s->new_picture[i]= s->coded_order[0].picture[i]; | |
| 774 } | |
| 775 } | |
| 776 | |
| 0 | 777 int MPV_encode_picture(AVCodecContext *avctx, |
| 778 unsigned char *buf, int buf_size, void *data) | |
| 779 { | |
| 780 MpegEncContext *s = avctx->priv_data; | |
| 781 AVPicture *pict = data; | |
| 782 | |
| 324 | 783 s->input_qscale = avctx->quality; |
| 0 | 784 |
| 785 init_put_bits(&s->pb, buf, buf_size, NULL, NULL); | |
| 786 | |
| 329 | 787 if(avctx->flags&CODEC_FLAG_TYPE){ |
| 788 s->input_pict_type= | |
| 789 s->force_input_type= avctx->key_frame ? I_TYPE : P_TYPE; | |
| 790 }else if(s->flags&CODEC_FLAG_PASS2){ | |
| 791 s->input_pict_type= | |
| 792 s->force_input_type= s->rc_context.entry[s->input_picture_number].new_pict_type; | |
| 793 }else{ | |
| 794 s->force_input_type=0; | |
| 795 if (!s->intra_only) { | |
| 796 /* first picture of GOP is intra */ | |
| 797 if (s->input_picture_in_gop_number % s->gop_size==0){ | |
| 798 s->input_pict_type = I_TYPE; | |
| 799 }else if(s->max_b_frames==0){ | |
| 800 s->input_pict_type = P_TYPE; | |
| 801 }else{ | |
| 802 if(s->b_frames_since_non_b < s->max_b_frames) //FIXME more IQ | |
| 803 s->input_pict_type = B_TYPE; | |
| 804 else | |
| 805 s->input_pict_type = P_TYPE; | |
| 806 } | |
| 807 } else { | |
| 324 | 808 s->input_pict_type = I_TYPE; |
| 809 } | |
| 0 | 810 } |
| 811 | |
| 329 | 812 if(s->input_pict_type==I_TYPE) |
| 813 s->input_picture_in_gop_number=0; | |
| 814 | |
| 324 | 815 reorder_input(s, pict); |
| 816 | |
| 817 /* output? */ | |
| 818 if(s->coded_order[0].picture[0]){ | |
| 819 | |
| 820 s->pict_type= s->coded_order[0].pict_type; | |
| 821 if (s->fixed_qscale) /* the ratecontrol needs the last qscale so we dont touch it for CBR */ | |
| 822 s->qscale= s->coded_order[0].qscale; | |
| 823 s->force_type= s->coded_order[0].force_type; | |
| 824 s->picture_in_gop_number= s->coded_order[0].picture_in_gop_number; | |
| 825 s->picture_number= s->coded_order[0].picture_number; | |
| 826 | |
| 553 | 827 MPV_frame_start(s, avctx); |
| 286 | 828 |
| 324 | 829 encode_picture(s, s->picture_number); |
| 376 | 830 avctx->key_frame = (s->pict_type == I_TYPE); |
| 831 avctx->pict_type = s->pict_type; | |
| 832 avctx->real_pict_num = s->picture_number; | |
| 324 | 833 avctx->header_bits = s->header_bits; |
| 834 avctx->mv_bits = s->mv_bits; | |
| 835 avctx->misc_bits = s->misc_bits; | |
| 836 avctx->i_tex_bits = s->i_tex_bits; | |
| 837 avctx->p_tex_bits = s->p_tex_bits; | |
| 838 avctx->i_count = s->i_count; | |
| 839 avctx->p_count = s->p_count; | |
| 840 avctx->skip_count = s->skip_count; | |
| 0 | 841 |
| 324 | 842 MPV_frame_end(s); |
| 843 | |
| 844 if (s->out_format == FMT_MJPEG) | |
| 845 mjpeg_picture_trailer(s); | |
| 846 | |
| 847 avctx->quality = s->qscale; | |
| 329 | 848 |
| 849 if(s->flags&CODEC_FLAG_PASS1) | |
| 850 ff_write_pass1_stats(s); | |
| 456 | 851 |
| 324 | 852 } |
| 853 | |
| 854 s->input_picture_number++; | |
| 855 s->input_picture_in_gop_number++; | |
| 0 | 856 |
| 857 flush_put_bits(&s->pb); | |
| 268 | 858 s->frame_bits = (pbBufPtr(&s->pb) - s->pb.buf) * 8; |
| 329 | 859 if(s->pict_type==B_TYPE) s->pb_frame_bits+= s->frame_bits; |
| 860 else s->pb_frame_bits= s->frame_bits; | |
| 861 | |
| 268 | 862 s->total_bits += s->frame_bits; |
| 286 | 863 avctx->frame_bits = s->frame_bits; |
| 864 //printf("fcode: %d, type: %d, head: %d, mv: %d, misc: %d, frame: %d, itex: %d, ptex: %d\n", | |
| 865 //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
|
866 |
|
252
ddb1a0e94cf4
- Added PSNR feature to libavcodec and ffmpeg. By now just Y PSNR until I'm
pulento
parents:
251
diff
changeset
|
867 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
|
868 /* 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
|
869 /* 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
|
870 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
|
871 pict->linesize, s->linesize, avctx); |
| 324 | 872 // 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
|
873 } |
|
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
|
874 return pbBufPtr(&s->pb) - s->pb.buf; |
| 0 | 875 } |
| 876 | |
| 255 | 877 static inline void gmc1_motion(MpegEncContext *s, |
| 878 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 879 int dest_offset, | |
| 880 UINT8 **ref_picture, int src_offset, | |
| 881 int h) | |
| 882 { | |
| 883 UINT8 *ptr; | |
| 556 | 884 int offset, src_x, src_y, linesize, uvlinesize; |
| 255 | 885 int motion_x, motion_y; |
| 566 | 886 int emu=0; |
| 255 | 887 |
|
265
4e9e728021d8
use ac prediction in mpeg4 encoding (5% smaller intra-blocks/keyframes)
michaelni
parents:
262
diff
changeset
|
888 if(s->real_sprite_warping_points>1) printf("more than 1 warp point isnt supported\n"); |
| 255 | 889 motion_x= s->sprite_offset[0][0]; |
| 890 motion_y= s->sprite_offset[0][1]; | |
| 891 src_x = s->mb_x * 16 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
| 892 src_y = s->mb_y * 16 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
| 893 motion_x<<=(3-s->sprite_warping_accuracy); | |
| 894 motion_y<<=(3-s->sprite_warping_accuracy); | |
| 895 src_x = clip(src_x, -16, s->width); | |
| 896 if (src_x == s->width) | |
| 897 motion_x =0; | |
| 898 src_y = clip(src_y, -16, s->height); | |
| 899 if (src_y == s->height) | |
| 900 motion_y =0; | |
| 901 | |
| 902 linesize = s->linesize; | |
| 556 | 903 uvlinesize = s->uvlinesize; |
| 255 | 904 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; |
| 905 | |
| 906 dest_y+=dest_offset; | |
| 566 | 907 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
908 if(src_x<0 || src_y<0 || src_x + (motion_x&15) + 16 > s->h_edge_pos |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
909 || src_y + (motion_y&15) + h > s->v_edge_pos){ |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
910 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->h_edge_pos, s->v_edge_pos); |
| 566 | 911 ptr= s->edge_emu_buffer; |
| 912 emu=1; | |
| 913 } | |
| 914 } | |
| 255 | 915 gmc1(dest_y , ptr , linesize, h, motion_x&15, motion_y&15, s->no_rounding); |
| 916 gmc1(dest_y+8, ptr+8, linesize, h, motion_x&15, motion_y&15, s->no_rounding); | |
| 917 | |
| 918 motion_x= s->sprite_offset[1][0]; | |
| 919 motion_y= s->sprite_offset[1][1]; | |
| 920 src_x = s->mb_x * 8 + (motion_x >> (s->sprite_warping_accuracy+1)); | |
| 921 src_y = s->mb_y * 8 + (motion_y >> (s->sprite_warping_accuracy+1)); | |
| 922 motion_x<<=(3-s->sprite_warping_accuracy); | |
| 923 motion_y<<=(3-s->sprite_warping_accuracy); | |
| 924 src_x = clip(src_x, -8, s->width>>1); | |
| 925 if (src_x == s->width>>1) | |
| 926 motion_x =0; | |
| 927 src_y = clip(src_y, -8, s->height>>1); | |
| 928 if (src_y == s->height>>1) | |
| 929 motion_y =0; | |
| 930 | |
| 556 | 931 offset = (src_y * uvlinesize) + src_x + (src_offset>>1); |
| 255 | 932 ptr = ref_picture[1] + offset; |
| 566 | 933 if(emu){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
934 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
| 566 | 935 ptr= s->edge_emu_buffer; |
| 936 } | |
| 556 | 937 gmc1(dest_cb + (dest_offset>>1), ptr, uvlinesize, h>>1, motion_x&15, motion_y&15, s->no_rounding); |
| 566 | 938 |
| 255 | 939 ptr = ref_picture[2] + offset; |
| 566 | 940 if(emu){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
941 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
| 566 | 942 ptr= s->edge_emu_buffer; |
| 943 } | |
| 556 | 944 gmc1(dest_cr + (dest_offset>>1), ptr, uvlinesize, h>>1, motion_x&15, motion_y&15, s->no_rounding); |
| 255 | 945 |
| 946 return; | |
| 947 } | |
| 948 | |
| 566 | 949 static void emulated_edge_mc(MpegEncContext *s, UINT8 *src, int linesize, int block_w, int block_h, |
| 553 | 950 int src_x, int src_y, int w, int h){ |
| 951 int x, y; | |
| 952 int start_y, start_x, end_y, end_x; | |
| 566 | 953 UINT8 *buf= s->edge_emu_buffer; |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
954 |
| 553 | 955 if(src_y>= h){ |
| 956 src+= (h-1-src_y)*linesize; | |
| 957 src_y=h-1; | |
| 554 | 958 }else if(src_y<=-block_h){ |
| 959 src+= (1-block_h-src_y)*linesize; | |
| 960 src_y=1-block_h; | |
| 553 | 961 } |
| 962 if(src_x>= w){ | |
| 963 src+= (w-1-src_x); | |
| 964 src_x=w-1; | |
| 554 | 965 }else if(src_x<=-block_w){ |
| 966 src+= (1-block_w-src_x); | |
| 967 src_x=1-block_w; | |
| 553 | 968 } |
| 969 | |
| 970 start_y= MAX(0, -src_y); | |
| 971 start_x= MAX(0, -src_x); | |
| 972 end_y= MIN(block_h, h-src_y); | |
| 973 end_x= MIN(block_w, w-src_x); | |
| 566 | 974 |
| 553 | 975 // copy existing part |
| 976 for(y=start_y; y<end_y; y++){ | |
| 977 for(x=start_x; x<end_x; x++){ | |
| 978 buf[x + y*linesize]= src[x + y*linesize]; | |
| 979 } | |
| 980 } | |
| 981 | |
| 982 //top | |
| 983 for(y=0; y<start_y; y++){ | |
| 984 for(x=start_x; x<end_x; x++){ | |
| 985 buf[x + y*linesize]= buf[x + start_y*linesize]; | |
| 986 } | |
| 987 } | |
| 988 | |
| 989 //bottom | |
| 990 for(y=end_y; y<block_h; y++){ | |
| 991 for(x=start_x; x<end_x; x++){ | |
| 992 buf[x + y*linesize]= buf[x + (end_y-1)*linesize]; | |
| 993 } | |
| 994 } | |
| 995 | |
| 996 for(y=0; y<block_h; y++){ | |
| 997 //left | |
| 998 for(x=0; x<start_x; x++){ | |
| 999 buf[x + y*linesize]= buf[start_x + y*linesize]; | |
| 1000 } | |
| 1001 | |
| 1002 //right | |
| 1003 for(x=end_x; x<block_w; x++){ | |
| 1004 buf[x + y*linesize]= buf[end_x - 1 + y*linesize]; | |
| 1005 } | |
| 1006 } | |
| 1007 } | |
| 1008 | |
| 1009 | |
| 0 | 1010 /* apply one mpeg motion vector to the three components */ |
| 1011 static inline void mpeg_motion(MpegEncContext *s, | |
| 1012 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 1013 int dest_offset, | |
| 1014 UINT8 **ref_picture, int src_offset, | |
| 1015 int field_based, op_pixels_func *pix_op, | |
| 1016 int motion_x, int motion_y, int h) | |
| 1017 { | |
| 1018 UINT8 *ptr; | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1019 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize, uvlinesize; |
| 553 | 1020 int emu=0; |
| 1021 | |
| 255 | 1022 if(s->quarter_sample) |
| 1023 { | |
| 1024 motion_x>>=1; | |
| 1025 motion_y>>=1; | |
| 1026 } | |
| 0 | 1027 dxy = ((motion_y & 1) << 1) | (motion_x & 1); |
| 1028 src_x = s->mb_x * 16 + (motion_x >> 1); | |
| 1029 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 1); | |
| 1030 | |
| 1031 /* WARNING: do no forget half pels */ | |
| 1032 height = s->height >> field_based; | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1033 v_edge_pos = s->v_edge_pos >> field_based; |
| 0 | 1034 src_x = clip(src_x, -16, s->width); |
| 1035 if (src_x == s->width) | |
| 1036 dxy &= ~1; | |
| 1037 src_y = clip(src_y, -16, height); | |
| 1038 if (src_y == height) | |
| 1039 dxy &= ~2; | |
|
565
44d744901ded
interlaced mpeg2 fix ... replacing linesize>>1 by uvlinesize brainlessly wasnt a good idea
michaelni
parents:
562
diff
changeset
|
1040 linesize = s->linesize << field_based; |
|
44d744901ded
interlaced mpeg2 fix ... replacing linesize>>1 by uvlinesize brainlessly wasnt a good idea
michaelni
parents:
562
diff
changeset
|
1041 uvlinesize = s->uvlinesize << field_based; |
| 0 | 1042 ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset; |
| 1043 dest_y += dest_offset; | |
| 553 | 1044 |
| 1045 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1046 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 16 > s->h_edge_pos |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1047 || src_y + (motion_y&1) + h > v_edge_pos){ |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1048 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->h_edge_pos, v_edge_pos); |
| 553 | 1049 ptr= s->edge_emu_buffer; |
| 1050 emu=1; | |
| 1051 } | |
| 1052 } | |
| 0 | 1053 pix_op[dxy](dest_y, ptr, linesize, h); |
| 1054 pix_op[dxy](dest_y + 8, ptr + 8, linesize, h); | |
| 1055 | |
| 485 | 1056 if(s->flags&CODEC_FLAG_GRAY) return; |
| 1057 | |
| 0 | 1058 if (s->out_format == FMT_H263) { |
| 1059 dxy = 0; | |
| 1060 if ((motion_x & 3) != 0) | |
| 1061 dxy |= 1; | |
| 1062 if ((motion_y & 3) != 0) | |
| 1063 dxy |= 2; | |
| 1064 mx = motion_x >> 2; | |
| 1065 my = motion_y >> 2; | |
| 1066 } else { | |
| 1067 mx = motion_x / 2; | |
| 1068 my = motion_y / 2; | |
| 1069 dxy = ((my & 1) << 1) | (mx & 1); | |
| 1070 mx >>= 1; | |
| 1071 my >>= 1; | |
| 1072 } | |
| 1073 | |
| 1074 src_x = s->mb_x * 8 + mx; | |
| 1075 src_y = s->mb_y * (8 >> field_based) + my; | |
| 1076 src_x = clip(src_x, -8, s->width >> 1); | |
| 1077 if (src_x == (s->width >> 1)) | |
| 1078 dxy &= ~1; | |
| 1079 src_y = clip(src_y, -8, height >> 1); | |
| 1080 if (src_y == (height >> 1)) | |
| 1081 dxy &= ~2; | |
|
565
44d744901ded
interlaced mpeg2 fix ... replacing linesize>>1 by uvlinesize brainlessly wasnt a good idea
michaelni
parents:
562
diff
changeset
|
1082 offset = (src_y * uvlinesize) + src_x + (src_offset >> 1); |
| 0 | 1083 ptr = ref_picture[1] + offset; |
| 553 | 1084 if(emu){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1085 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1); |
| 553 | 1086 ptr= s->edge_emu_buffer; |
| 1087 } | |
|
565
44d744901ded
interlaced mpeg2 fix ... replacing linesize>>1 by uvlinesize brainlessly wasnt a good idea
michaelni
parents:
562
diff
changeset
|
1088 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
| 553 | 1089 |
| 0 | 1090 ptr = ref_picture[2] + offset; |
| 553 | 1091 if(emu){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1092 emulated_edge_mc(s, ptr, uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1); |
| 553 | 1093 ptr= s->edge_emu_buffer; |
| 1094 } | |
|
565
44d744901ded
interlaced mpeg2 fix ... replacing linesize>>1 by uvlinesize brainlessly wasnt a good idea
michaelni
parents:
562
diff
changeset
|
1095 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, uvlinesize, h >> 1); |
| 0 | 1096 } |
| 1097 | |
| 255 | 1098 static inline void qpel_motion(MpegEncContext *s, |
| 1099 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 1100 int dest_offset, | |
| 1101 UINT8 **ref_picture, int src_offset, | |
| 1102 int field_based, op_pixels_func *pix_op, | |
| 1103 qpel_mc_func *qpix_op, | |
| 1104 int motion_x, int motion_y, int h) | |
| 1105 { | |
| 1106 UINT8 *ptr; | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1107 int dxy, offset, mx, my, src_x, src_y, height, v_edge_pos, linesize; |
| 554 | 1108 int emu=0; |
| 255 | 1109 |
| 1110 dxy = ((motion_y & 3) << 2) | (motion_x & 3); | |
| 1111 src_x = s->mb_x * 16 + (motion_x >> 2); | |
| 1112 src_y = s->mb_y * (16 >> field_based) + (motion_y >> 2); | |
| 1113 | |
| 1114 height = s->height >> field_based; | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1115 v_edge_pos = s->v_edge_pos >> field_based; |
| 255 | 1116 src_x = clip(src_x, -16, s->width); |
| 1117 if (src_x == s->width) | |
| 1118 dxy &= ~3; | |
| 1119 src_y = clip(src_y, -16, height); | |
| 1120 if (src_y == height) | |
| 1121 dxy &= ~12; | |
| 1122 linesize = s->linesize << field_based; | |
| 1123 ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; | |
| 1124 dest_y += dest_offset; | |
| 1125 //printf("%d %d %d\n", src_x, src_y, dxy); | |
| 554 | 1126 |
| 1127 if(s->flags&CODEC_FLAG_EMU_EDGE){ | |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1128 if(src_x<0 || src_y<0 || src_x + (motion_x&3) + 16 > s->h_edge_pos |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1129 || src_y + (motion_y&3) + h > v_edge_pos){ |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1130 emulated_edge_mc(s, ptr, linesize, 17, h+1, src_x, src_y, s->h_edge_pos, v_edge_pos); |
| 554 | 1131 ptr= s->edge_emu_buffer; |
| 1132 emu=1; | |
| 1133 } | |
| 1134 } | |
| 255 | 1135 qpix_op[dxy](dest_y , ptr , linesize, linesize, motion_x&3, motion_y&3); |
| 1136 qpix_op[dxy](dest_y + 8, ptr + 8, linesize, linesize, motion_x&3, motion_y&3); | |
| 1137 qpix_op[dxy](dest_y + linesize*8 , ptr + linesize*8 , linesize, linesize, motion_x&3, motion_y&3); | |
| 1138 qpix_op[dxy](dest_y + linesize*8 + 8, ptr + linesize*8 + 8, linesize, linesize, motion_x&3, motion_y&3); | |
| 1139 | |
| 485 | 1140 if(s->flags&CODEC_FLAG_GRAY) return; |
| 1141 | |
| 255 | 1142 mx= (motion_x>>1) | (motion_x&1); |
| 1143 my= (motion_y>>1) | (motion_y&1); | |
| 1144 | |
| 1145 dxy = 0; | |
| 1146 if ((mx & 3) != 0) | |
| 1147 dxy |= 1; | |
| 1148 if ((my & 3) != 0) | |
| 1149 dxy |= 2; | |
| 1150 mx = mx >> 2; | |
| 1151 my = my >> 2; | |
| 1152 | |
| 1153 src_x = s->mb_x * 8 + mx; | |
| 1154 src_y = s->mb_y * (8 >> field_based) + my; | |
| 1155 src_x = clip(src_x, -8, s->width >> 1); | |
| 1156 if (src_x == (s->width >> 1)) | |
| 1157 dxy &= ~1; | |
| 1158 src_y = clip(src_y, -8, height >> 1); | |
| 1159 if (src_y == (height >> 1)) | |
| 1160 dxy &= ~2; | |
| 1161 | |
| 556 | 1162 offset = (src_y * s->uvlinesize) + src_x + (src_offset >> 1); |
| 255 | 1163 ptr = ref_picture[1] + offset; |
| 554 | 1164 if(emu){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1165 emulated_edge_mc(s, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1); |
| 554 | 1166 ptr= s->edge_emu_buffer; |
| 1167 } | |
| 556 | 1168 pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1); |
| 554 | 1169 |
| 255 | 1170 ptr = ref_picture[2] + offset; |
| 554 | 1171 if(emu){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1172 emulated_edge_mc(s, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->h_edge_pos>>1, v_edge_pos>>1); |
| 554 | 1173 ptr= s->edge_emu_buffer; |
| 1174 } | |
| 556 | 1175 pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1); |
| 255 | 1176 } |
| 1177 | |
| 1178 | |
| 0 | 1179 static inline void MPV_motion(MpegEncContext *s, |
| 1180 UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, | |
| 1181 int dir, UINT8 **ref_picture, | |
| 255 | 1182 op_pixels_func *pix_op, qpel_mc_func *qpix_op) |
| 0 | 1183 { |
| 1184 int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y; | |
| 1185 int mb_x, mb_y, i; | |
| 1186 UINT8 *ptr, *dest; | |
| 554 | 1187 int emu=0; |
| 0 | 1188 |
| 1189 mb_x = s->mb_x; | |
| 1190 mb_y = s->mb_y; | |
| 1191 | |
| 1192 switch(s->mv_type) { | |
| 1193 case MV_TYPE_16X16: | |
| 255 | 1194 if(s->mcsel){ |
| 1195 #if 0 | |
| 1196 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 1197 ref_picture, 0, | |
| 1198 0, pix_op, | |
| 1199 s->sprite_offset[0][0]>>3, | |
| 1200 s->sprite_offset[0][1]>>3, | |
| 1201 16); | |
| 1202 #else | |
| 1203 gmc1_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 1204 ref_picture, 0, | |
| 1205 16); | |
| 1206 #endif | |
| 262 | 1207 }else if(s->quarter_sample && dir==0){ //FIXME |
| 255 | 1208 qpel_motion(s, dest_y, dest_cb, dest_cr, 0, |
| 1209 ref_picture, 0, | |
| 1210 0, pix_op, qpix_op, | |
| 1211 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
| 1212 }else{ | |
| 1213 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 1214 ref_picture, 0, | |
| 1215 0, pix_op, | |
| 1216 s->mv[dir][0][0], s->mv[dir][0][1], 16); | |
| 1217 } | |
| 0 | 1218 break; |
| 1219 case MV_TYPE_8X8: | |
| 1220 for(i=0;i<4;i++) { | |
| 1221 motion_x = s->mv[dir][i][0]; | |
| 1222 motion_y = s->mv[dir][i][1]; | |
| 1223 | |
| 1224 dxy = ((motion_y & 1) << 1) | (motion_x & 1); | |
| 1225 src_x = mb_x * 16 + (motion_x >> 1) + (i & 1) * 8; | |
| 295 | 1226 src_y = mb_y * 16 + (motion_y >> 1) + (i >>1) * 8; |
| 0 | 1227 |
| 1228 /* WARNING: do no forget half pels */ | |
| 1229 src_x = clip(src_x, -16, s->width); | |
| 1230 if (src_x == s->width) | |
| 1231 dxy &= ~1; | |
| 1232 src_y = clip(src_y, -16, s->height); | |
| 1233 if (src_y == s->height) | |
| 1234 dxy &= ~2; | |
| 1235 | |
| 1236 ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); | |
| 554 | 1237 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1238 if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 8 > s->h_edge_pos |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1239 || src_y + (motion_y&1) + 8 > s->v_edge_pos){ |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1240 emulated_edge_mc(s, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos); |
| 554 | 1241 ptr= s->edge_emu_buffer; |
| 1242 } | |
| 1243 } | |
| 0 | 1244 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; |
| 1245 pix_op[dxy](dest, ptr, s->linesize, 8); | |
| 1246 } | |
| 485 | 1247 |
| 1248 if(s->flags&CODEC_FLAG_GRAY) break; | |
| 0 | 1249 /* In case of 8X8, we construct a single chroma motion vector |
| 1250 with a special rounding */ | |
| 1251 mx = 0; | |
| 1252 my = 0; | |
| 1253 for(i=0;i<4;i++) { | |
| 1254 mx += s->mv[dir][i][0]; | |
| 1255 my += s->mv[dir][i][1]; | |
| 1256 } | |
| 1257 if (mx >= 0) | |
| 1258 mx = (h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1)); | |
| 1259 else { | |
| 1260 mx = -mx; | |
| 1261 mx = -(h263_chroma_roundtab[mx & 0xf] + ((mx >> 3) & ~1)); | |
| 1262 } | |
| 1263 if (my >= 0) | |
| 1264 my = (h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1)); | |
| 1265 else { | |
| 1266 my = -my; | |
| 1267 my = -(h263_chroma_roundtab[my & 0xf] + ((my >> 3) & ~1)); | |
| 1268 } | |
| 1269 dxy = ((my & 1) << 1) | (mx & 1); | |
| 1270 mx >>= 1; | |
| 1271 my >>= 1; | |
| 1272 | |
| 1273 src_x = mb_x * 8 + mx; | |
| 1274 src_y = mb_y * 8 + my; | |
| 1275 src_x = clip(src_x, -8, s->width/2); | |
| 1276 if (src_x == s->width/2) | |
| 1277 dxy &= ~1; | |
| 1278 src_y = clip(src_y, -8, s->height/2); | |
| 1279 if (src_y == s->height/2) | |
| 1280 dxy &= ~2; | |
| 1281 | |
| 556 | 1282 offset = (src_y * (s->uvlinesize)) + src_x; |
| 0 | 1283 ptr = ref_picture[1] + offset; |
| 554 | 1284 if(s->flags&CODEC_FLAG_EMU_EDGE){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1285 if(src_x<0 || src_y<0 || src_x + (dxy &1) + 8 > s->h_edge_pos>>1 |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1286 || src_y + (dxy>>1) + 8 > s->v_edge_pos>>1){ |
|
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1287 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
| 554 | 1288 ptr= s->edge_emu_buffer; |
| 1289 emu=1; | |
| 1290 } | |
| 1291 } | |
| 556 | 1292 pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8); |
| 554 | 1293 |
| 0 | 1294 ptr = ref_picture[2] + offset; |
| 554 | 1295 if(emu){ |
|
582
5132a4ee50cd
different edge positions fixed with edge emu / dr1
michaelni
parents:
575
diff
changeset
|
1296 emulated_edge_mc(s, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); |
| 554 | 1297 ptr= s->edge_emu_buffer; |
| 1298 } | |
| 556 | 1299 pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); |
| 0 | 1300 break; |
| 1301 case MV_TYPE_FIELD: | |
| 1302 if (s->picture_structure == PICT_FRAME) { | |
| 1303 /* top field */ | |
| 1304 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 1305 ref_picture, s->field_select[dir][0] ? s->linesize : 0, | |
| 1306 1, pix_op, | |
| 1307 s->mv[dir][0][0], s->mv[dir][0][1], 8); | |
| 1308 /* bottom field */ | |
| 1309 mpeg_motion(s, dest_y, dest_cb, dest_cr, s->linesize, | |
| 1310 ref_picture, s->field_select[dir][1] ? s->linesize : 0, | |
| 1311 1, pix_op, | |
| 1312 s->mv[dir][1][0], s->mv[dir][1][1], 8); | |
| 1313 } else { | |
| 1314 | |
| 1315 | |
| 1316 } | |
| 1317 break; | |
| 1318 } | |
| 1319 } | |
| 1320 | |
| 1321 | |
| 1322 /* put block[] to dest[] */ | |
| 1323 static inline void put_dct(MpegEncContext *s, | |
| 1324 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
| 1325 { | |
| 1326 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
|
1327 s->dct_unquantize(s, block, i, s->qscale); |
| 478 | 1328 ff_idct_put (dest, line_size, block); |
| 0 | 1329 } |
| 1330 | |
| 1331 /* add block[] to dest[] */ | |
| 1332 static inline void add_dct(MpegEncContext *s, | |
| 1333 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
| 1334 { | |
| 1335 if (s->block_last_index[i] >= 0) { | |
| 481 | 1336 ff_idct_add (dest, line_size, block); |
| 1337 } | |
| 1338 } | |
| 1339 | |
| 1340 static inline void add_dequant_dct(MpegEncContext *s, | |
| 1341 DCTELEM *block, int i, UINT8 *dest, int line_size) | |
| 1342 { | |
| 1343 if (s->block_last_index[i] >= 0) { | |
| 1344 s->dct_unquantize(s, block, i, s->qscale); | |
| 324 | 1345 |
| 478 | 1346 ff_idct_add (dest, line_size, block); |
| 0 | 1347 } |
| 1348 } | |
| 1349 | |
| 456 | 1350 /** |
| 1351 * cleans dc, ac, coded_block for the current non intra MB | |
| 1352 */ | |
| 1353 void ff_clean_intra_table_entries(MpegEncContext *s) | |
| 1354 { | |
| 1355 int wrap = s->block_wrap[0]; | |
| 1356 int xy = s->block_index[0]; | |
| 1357 | |
| 1358 s->dc_val[0][xy ] = | |
| 1359 s->dc_val[0][xy + 1 ] = | |
| 1360 s->dc_val[0][xy + wrap] = | |
| 1361 s->dc_val[0][xy + 1 + wrap] = 1024; | |
| 1362 /* ac pred */ | |
| 1363 memset(s->ac_val[0][xy ], 0, 32 * sizeof(INT16)); | |
| 1364 memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(INT16)); | |
| 1365 if (s->msmpeg4_version>=3) { | |
| 1366 s->coded_block[xy ] = | |
| 1367 s->coded_block[xy + 1 ] = | |
| 1368 s->coded_block[xy + wrap] = | |
| 1369 s->coded_block[xy + 1 + wrap] = 0; | |
| 1370 } | |
| 1371 /* chroma */ | |
| 1372 wrap = s->block_wrap[4]; | |
| 1373 xy = s->mb_x + 1 + (s->mb_y + 1) * wrap; | |
| 1374 s->dc_val[1][xy] = | |
| 1375 s->dc_val[2][xy] = 1024; | |
| 1376 /* ac pred */ | |
| 1377 memset(s->ac_val[1][xy], 0, 16 * sizeof(INT16)); | |
| 1378 memset(s->ac_val[2][xy], 0, 16 * sizeof(INT16)); | |
| 1379 | |
| 1380 s->mbintra_table[s->mb_x + s->mb_y*s->mb_width]= 0; | |
| 1381 } | |
| 1382 | |
| 0 | 1383 /* generic function called after a macroblock has been parsed by the |
| 1384 decoder or after it has been encoded by the encoder. | |
| 1385 | |
| 1386 Important variables used: | |
| 1387 s->mb_intra : true if intra macroblock | |
| 1388 s->mv_dir : motion vector direction | |
| 1389 s->mv_type : motion vector type | |
| 1390 s->mv : motion vector | |
| 1391 s->interlaced_dct : true if interlaced dct used (mpeg2) | |
| 1392 */ | |
| 1393 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) | |
| 1394 { | |
| 244 | 1395 int mb_x, mb_y; |
| 481 | 1396 const int mb_xy = s->mb_y * s->mb_width + s->mb_x; |
| 0 | 1397 |
| 1398 mb_x = s->mb_x; | |
| 1399 mb_y = s->mb_y; | |
| 1400 | |
|
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1401 #ifdef FF_POSTPROCESS |
|
466
805714c0c10f
new field for communicating with external postprocessing
nickols_k
parents:
462
diff
changeset
|
1402 /* Obsolete. Exists for compatibility with mplayer only. */ |
|
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1403 quant_store[mb_y][mb_x]=s->qscale; |
|
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1404 //printf("[%02d][%02d] %d\n",mb_x,mb_y,s->qscale); |
|
466
805714c0c10f
new field for communicating with external postprocessing
nickols_k
parents:
462
diff
changeset
|
1405 #else |
| 575 | 1406 /* even more obsolete, exists for mplayer xp only */ |
| 467 | 1407 if(s->avctx->quant_store) s->avctx->quant_store[mb_y*s->avctx->qstride+mb_x] = s->qscale; |
|
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1408 #endif |
| 575 | 1409 s->qscale_table[mb_xy]= s->qscale; |
|
108
1e4a4af694d1
exporting qscale data for postprocessing (for MPlayer)
arpi_esp
parents:
79
diff
changeset
|
1410 |
| 0 | 1411 /* update DC predictors for P macroblocks */ |
| 1412 if (!s->mb_intra) { | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1413 if (s->h263_pred || s->h263_aic) { |
| 481 | 1414 if(s->mbintra_table[mb_xy]) |
| 456 | 1415 ff_clean_intra_table_entries(s); |
| 0 | 1416 } else { |
| 456 | 1417 s->last_dc[0] = |
| 1418 s->last_dc[1] = | |
| 0 | 1419 s->last_dc[2] = 128 << s->intra_dc_precision; |
| 1420 } | |
| 1421 } | |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
1422 else if (s->h263_pred || s->h263_aic) |
| 481 | 1423 s->mbintra_table[mb_xy]=1; |
|
191
883f184537e6
AC table reset (memset) optimization - patch by Michael Niedermayer <michaelni@gmx.at>
uid46427
parents:
189
diff
changeset
|
1424 |
| 280 | 1425 /* update motion predictor, not for B-frames as they need the motion_val from the last P/S-Frame */ |
| 481 | 1426 if (s->out_format == FMT_H263 && s->pict_type!=B_TYPE) { //FIXME move into h263.c if possible, format specific stuff shouldnt be here |
| 1427 int motion_x, motion_y; | |
| 0 | 1428 |
| 481 | 1429 const int wrap = s->block_wrap[0]; |
| 1430 const int xy = s->block_index[0]; | |
| 0 | 1431 if (s->mb_intra) { |
| 1432 motion_x = 0; | |
| 1433 motion_y = 0; | |
| 1434 goto motion_init; | |
| 1435 } else if (s->mv_type == MV_TYPE_16X16) { | |
| 1436 motion_x = s->mv[0][0][0]; | |
| 1437 motion_y = s->mv[0][0][1]; | |
| 1438 motion_init: | |
| 1439 /* no update if 8X8 because it has been done during parsing */ | |
| 244 | 1440 s->motion_val[xy][0] = motion_x; |
| 1441 s->motion_val[xy][1] = motion_y; | |
| 1442 s->motion_val[xy + 1][0] = motion_x; | |
| 1443 s->motion_val[xy + 1][1] = motion_y; | |
| 1444 s->motion_val[xy + wrap][0] = motion_x; | |
| 1445 s->motion_val[xy + wrap][1] = motion_y; | |
| 1446 s->motion_val[xy + 1 + wrap][0] = motion_x; | |
| 1447 s->motion_val[xy + 1 + wrap][1] = motion_y; | |
| 0 | 1448 } |
| 1449 } | |
| 1450 | |
| 324 | 1451 if (!(s->encoding && (s->intra_only || s->pict_type==B_TYPE))) { |
| 0 | 1452 UINT8 *dest_y, *dest_cb, *dest_cr; |
| 481 | 1453 int dct_linesize, dct_offset; |
| 1454 op_pixels_func *op_pix; | |
| 1455 qpel_mc_func *op_qpix; | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1456 |
| 324 | 1457 /* avoid copy if macroblock skipped in last frame too |
| 1458 dont touch it for B-frames as they need the skip info from the next p-frame */ | |
| 1459 if (s->pict_type != B_TYPE) { | |
| 481 | 1460 UINT8 *mbskip_ptr = &s->mbskip_table[mb_xy]; |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1461 if (s->mb_skiped) { |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1462 s->mb_skiped = 0; |
| 556 | 1463 |
| 1464 (*mbskip_ptr) ++; /* indicate that this time we skiped it */ | |
| 1465 if(*mbskip_ptr >99) *mbskip_ptr= 99; | |
| 1466 | |
| 324 | 1467 /* if previous was skipped too, then nothing to do ! |
| 1468 skip only during decoding as we might trash the buffers during encoding a bit */ | |
| 556 | 1469 if (*mbskip_ptr >= s->ip_buffer_count && !s->encoding) |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1470 goto the_end; |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1471 } else { |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1472 *mbskip_ptr = 0; /* not skipped */ |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1473 } |
|
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1474 } |
| 0 | 1475 |
|
562
23e58889a108
exporting mbskip_table after it has been allocated
michaelni
parents:
557
diff
changeset
|
1476 dest_y = s->current_picture [0] + (mb_y * 16* s->linesize ) + mb_x * 16; |
|
23e58889a108
exporting mbskip_table after it has been allocated
michaelni
parents:
557
diff
changeset
|
1477 dest_cb = s->current_picture[1] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; |
|
23e58889a108
exporting mbskip_table after it has been allocated
michaelni
parents:
557
diff
changeset
|
1478 dest_cr = s->current_picture[2] + (mb_y * 8 * s->uvlinesize) + mb_x * 8; |
| 0 | 1479 |
| 1480 if (s->interlaced_dct) { | |
| 1481 dct_linesize = s->linesize * 2; | |
| 1482 dct_offset = s->linesize; | |
| 1483 } else { | |
| 1484 dct_linesize = s->linesize; | |
| 1485 dct_offset = s->linesize * 8; | |
| 1486 } | |
| 1487 | |
| 1488 if (!s->mb_intra) { | |
| 1489 /* motion handling */ | |
| 456 | 1490 /* decoding or more than one mb_type (MC was allready done otherwise) */ |
| 481 | 1491 if((!s->encoding) || (s->mb_type[mb_xy]&(s->mb_type[mb_xy]-1))){ |
| 327 | 1492 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
| 324 | 1493 op_pix = put_pixels_tab; |
| 1494 op_qpix= qpel_mc_rnd_tab; | |
| 1495 }else{ | |
| 1496 op_pix = put_no_rnd_pixels_tab; | |
| 1497 op_qpix= qpel_mc_no_rnd_tab; | |
| 1498 } | |
| 0 | 1499 |
| 324 | 1500 if (s->mv_dir & MV_DIR_FORWARD) { |
| 1501 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); | |
| 327 | 1502 if ((!s->no_rounding) || s->pict_type==B_TYPE) |
| 324 | 1503 op_pix = avg_pixels_tab; |
| 1504 else | |
| 1505 op_pix = avg_no_rnd_pixels_tab; | |
| 1506 } | |
| 1507 if (s->mv_dir & MV_DIR_BACKWARD) { | |
| 1508 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); | |
| 1509 } | |
| 0 | 1510 } |
| 1511 | |
| 481 | 1512 /* skip dequant / idct if we are really late ;) */ |
| 1513 if(s->hurry_up>1) goto the_end; | |
| 1514 | |
| 0 | 1515 /* add dct residue */ |
| 549 | 1516 if(s->encoding || !(s->mpeg2 || s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG4)){ |
| 481 | 1517 add_dequant_dct(s, block[0], 0, dest_y, dct_linesize); |
| 1518 add_dequant_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
| 1519 add_dequant_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
| 1520 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
| 0 | 1521 |
| 485 | 1522 if(!(s->flags&CODEC_FLAG_GRAY)){ |
| 556 | 1523 add_dequant_dct(s, block[4], 4, dest_cb, s->uvlinesize); |
| 1524 add_dequant_dct(s, block[5], 5, dest_cr, s->uvlinesize); | |
| 485 | 1525 } |
| 481 | 1526 } else { |
| 1527 add_dct(s, block[0], 0, dest_y, dct_linesize); | |
| 1528 add_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
| 1529 add_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
| 1530 add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
| 1531 | |
| 485 | 1532 if(!(s->flags&CODEC_FLAG_GRAY)){ |
| 556 | 1533 add_dct(s, block[4], 4, dest_cb, s->uvlinesize); |
| 1534 add_dct(s, block[5], 5, dest_cr, s->uvlinesize); | |
| 485 | 1535 } |
| 481 | 1536 } |
| 0 | 1537 } else { |
| 1538 /* dct only in intra block */ | |
| 1539 put_dct(s, block[0], 0, dest_y, dct_linesize); | |
| 1540 put_dct(s, block[1], 1, dest_y + 8, dct_linesize); | |
| 1541 put_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); | |
| 1542 put_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); | |
| 1543 | |
| 485 | 1544 if(!(s->flags&CODEC_FLAG_GRAY)){ |
| 556 | 1545 put_dct(s, block[4], 4, dest_cb, s->uvlinesize); |
| 1546 put_dct(s, block[5], 5, dest_cr, s->uvlinesize); | |
| 485 | 1547 } |
| 0 | 1548 } |
| 1549 } | |
|
7
1d3ac9654178
added skip macroblock optimization (big perf win on black regions for example)
glantau
parents:
0
diff
changeset
|
1550 the_end: |
| 294 | 1551 emms_c(); //FIXME remove |
| 1552 } | |
| 1553 | |
| 456 | 1554 static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold, int skip_dc) |
| 1555 { | |
| 1556 static const char tab[64]= | |
| 1557 {3,2,2,1,1,1,1,1, | |
| 1558 1,1,1,1,1,1,1,1, | |
| 1559 1,1,1,1,1,1,1,1, | |
| 1560 0,0,0,0,0,0,0,0, | |
| 1561 0,0,0,0,0,0,0,0, | |
| 1562 0,0,0,0,0,0,0,0, | |
| 1563 0,0,0,0,0,0,0,0, | |
| 1564 0,0,0,0,0,0,0,0}; | |
| 1565 int score=0; | |
| 1566 int run=0; | |
| 1567 int i; | |
| 1568 DCTELEM *block= s->block[n]; | |
| 1569 const int last_index= s->block_last_index[n]; | |
| 1570 | |
| 1571 if(skip_dc) skip_dc=1; | |
| 1572 | |
| 1573 /* are all which we could set to zero are allready zero? */ | |
| 1574 if(last_index<=skip_dc - 1) return; | |
| 1575 | |
| 1576 for(i=0; i<=last_index; i++){ | |
| 1577 const int j = zigzag_direct[i]; | |
| 1578 const int level = ABS(block[j]); | |
| 1579 if(level==1){ | |
| 1580 if(skip_dc && i==0) continue; | |
| 1581 score+= tab[run]; | |
| 1582 run=0; | |
| 1583 }else if(level>1){ | |
| 1584 return; | |
| 1585 }else{ | |
| 1586 run++; | |
| 1587 } | |
| 1588 } | |
| 1589 if(score >= threshold) return; | |
| 1590 for(i=skip_dc; i<=last_index; i++){ | |
| 1591 const int j = zigzag_direct[i]; | |
| 1592 block[j]=0; | |
| 1593 } | |
| 1594 if(block[0]) s->block_last_index[n]= 0; | |
| 1595 else s->block_last_index[n]= -1; | |
| 1596 } | |
| 1597 | |
| 344 | 1598 static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) |
| 1599 { | |
| 1600 int i; | |
| 1601 const int maxlevel= s->max_qcoeff; | |
| 1602 const int minlevel= s->min_qcoeff; | |
|
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
1603 |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
1604 for(i=0;i<=last_index; i++){ |
| 344 | 1605 const int j = zigzag_direct[i]; |
| 1606 int level = block[j]; | |
| 1607 | |
| 1608 if (level>maxlevel) level=maxlevel; | |
| 1609 else if(level<minlevel) level=minlevel; | |
| 1610 block[j]= level; | |
| 1611 } | |
| 1612 } | |
| 324 | 1613 |
| 1614 static void encode_mb(MpegEncContext *s, int motion_x, int motion_y) | |
| 294 | 1615 { |
| 1616 const int mb_x= s->mb_x; | |
| 1617 const int mb_y= s->mb_y; | |
| 1618 int i; | |
| 456 | 1619 int skip_dct[6]; |
| 324 | 1620 #if 0 |
| 1621 if (s->interlaced_dct) { | |
| 1622 dct_linesize = s->linesize * 2; | |
| 1623 dct_offset = s->linesize; | |
| 1624 } else { | |
| 1625 dct_linesize = s->linesize; | |
| 1626 dct_offset = s->linesize * 8; | |
| 1627 } | |
| 1628 #endif | |
| 456 | 1629 for(i=0; i<6; i++) skip_dct[i]=0; |
| 294 | 1630 |
| 324 | 1631 if (s->mb_intra) { |
| 1632 UINT8 *ptr; | |
| 1633 int wrap; | |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1634 int emu=0; |
| 294 | 1635 |
| 324 | 1636 wrap = s->linesize; |
| 1637 ptr = s->new_picture[0] + (mb_y * 16 * wrap) + mb_x * 16; | |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1638 if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1639 emulated_edge_mc(s, ptr, wrap, 16, 16, mb_x*16, mb_y*16, s->width, s->height); |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1640 ptr= s->edge_emu_buffer; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1641 emu=1; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1642 } |
| 324 | 1643 get_pixels(s->block[0], ptr , wrap); |
| 1644 get_pixels(s->block[1], ptr + 8, wrap); | |
| 1645 get_pixels(s->block[2], ptr + 8 * wrap , wrap); | |
| 1646 get_pixels(s->block[3], ptr + 8 * wrap + 8, wrap); | |
| 294 | 1647 |
| 487 | 1648 if(s->flags&CODEC_FLAG_GRAY){ |
| 1649 skip_dct[4]= 1; | |
| 1650 skip_dct[5]= 1; | |
| 1651 }else{ | |
| 1652 wrap >>=1; | |
| 1653 ptr = s->new_picture[1] + (mb_y * 8 * wrap) + mb_x * 8; | |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1654 if(emu){ |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1655 emulated_edge_mc(s, ptr, wrap, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1656 ptr= s->edge_emu_buffer; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1657 } |
| 487 | 1658 get_pixels(s->block[4], ptr, wrap); |
| 294 | 1659 |
| 487 | 1660 ptr = s->new_picture[2] + (mb_y * 8 * wrap) + mb_x * 8; |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1661 if(emu){ |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1662 emulated_edge_mc(s, ptr, wrap, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1663 ptr= s->edge_emu_buffer; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1664 } |
| 487 | 1665 get_pixels(s->block[5], ptr, wrap); |
| 1666 } | |
| 324 | 1667 }else{ |
| 1668 op_pixels_func *op_pix; | |
| 1669 qpel_mc_func *op_qpix; | |
| 1670 UINT8 *dest_y, *dest_cb, *dest_cr; | |
| 456 | 1671 UINT8 *ptr_y, *ptr_cb, *ptr_cr; |
| 1672 int wrap_y, wrap_c; | |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1673 int emu=0; |
| 294 | 1674 |
| 324 | 1675 dest_y = s->current_picture[0] + (mb_y * 16 * s->linesize ) + mb_x * 16; |
| 556 | 1676 dest_cb = s->current_picture[1] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; |
| 1677 dest_cr = s->current_picture[2] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; | |
| 456 | 1678 wrap_y = s->linesize; |
| 1679 wrap_c = wrap_y>>1; | |
| 1680 ptr_y = s->new_picture[0] + (mb_y * 16 * wrap_y) + mb_x * 16; | |
| 1681 ptr_cb = s->new_picture[1] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
| 1682 ptr_cr = s->new_picture[2] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
| 324 | 1683 |
| 327 | 1684 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
| 324 | 1685 op_pix = put_pixels_tab; |
| 1686 op_qpix= qpel_mc_rnd_tab; | |
| 295 | 1687 }else{ |
| 324 | 1688 op_pix = put_no_rnd_pixels_tab; |
| 1689 op_qpix= qpel_mc_no_rnd_tab; | |
| 1690 } | |
| 295 | 1691 |
| 324 | 1692 if (s->mv_dir & MV_DIR_FORWARD) { |
| 1693 MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture, op_pix, op_qpix); | |
| 327 | 1694 if ((!s->no_rounding) || s->pict_type==B_TYPE) |
| 324 | 1695 op_pix = avg_pixels_tab; |
| 1696 else | |
| 1697 op_pix = avg_no_rnd_pixels_tab; | |
| 1698 } | |
| 1699 if (s->mv_dir & MV_DIR_BACKWARD) { | |
| 1700 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture, op_pix, op_qpix); | |
| 1701 } | |
| 295 | 1702 |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1703 if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1704 emulated_edge_mc(s, ptr_y, wrap_y, 16, 16, mb_x*16, mb_y*16, s->width, s->height); |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1705 ptr_y= s->edge_emu_buffer; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1706 emu=1; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1707 } |
| 456 | 1708 diff_pixels(s->block[0], ptr_y , dest_y , wrap_y); |
| 1709 diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y); | |
| 1710 diff_pixels(s->block[2], ptr_y + 8 * wrap_y , dest_y + 8 * wrap_y , wrap_y); | |
| 1711 diff_pixels(s->block[3], ptr_y + 8 * wrap_y + 8, dest_y + 8 * wrap_y + 8, wrap_y); | |
| 487 | 1712 |
| 1713 if(s->flags&CODEC_FLAG_GRAY){ | |
| 1714 skip_dct[4]= 1; | |
| 1715 skip_dct[5]= 1; | |
| 1716 }else{ | |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1717 if(emu){ |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1718 emulated_edge_mc(s, ptr_cb, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1719 ptr_cb= s->edge_emu_buffer; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1720 } |
| 487 | 1721 diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c); |
|
570
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1722 if(emu){ |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1723 emulated_edge_mc(s, ptr_cr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1724 ptr_cr= s->edge_emu_buffer; |
|
274d9c5a75ee
use edge emu for encoding of width or height %16!=0 files
michaelni
parents:
569
diff
changeset
|
1725 } |
| 487 | 1726 diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); |
| 1727 } | |
| 1728 | |
| 456 | 1729 /* pre quantization */ |
| 1730 if(s->mc_mb_var[s->mb_width*mb_y+ mb_x]<2*s->qscale*s->qscale){ | |
| 1731 if(pix_abs8x8(ptr_y , dest_y , wrap_y) < 20*s->qscale) skip_dct[0]= 1; | |
| 1732 if(pix_abs8x8(ptr_y + 8, dest_y + 8, wrap_y) < 20*s->qscale) skip_dct[1]= 1; | |
| 1733 if(pix_abs8x8(ptr_y + 8*wrap_y , dest_y + 8*wrap_y , wrap_y) < 20*s->qscale) skip_dct[2]= 1; | |
| 1734 if(pix_abs8x8(ptr_y + 8*wrap_y + 8, dest_y + 8*wrap_y + 8, wrap_y) < 20*s->qscale) skip_dct[3]= 1; | |
| 1735 if(pix_abs8x8(ptr_cb , dest_cb , wrap_y) < 20*s->qscale) skip_dct[4]= 1; | |
| 1736 if(pix_abs8x8(ptr_cr , dest_cr , wrap_y) < 20*s->qscale) skip_dct[5]= 1; | |
| 1737 #if 0 | |
| 1738 { | |
| 1739 static int stat[7]; | |
| 1740 int num=0; | |
| 1741 for(i=0; i<6; i++) | |
| 1742 if(skip_dct[i]) num++; | |
| 1743 stat[num]++; | |
| 1744 | |
| 1745 if(s->mb_x==0 && s->mb_y==0){ | |
| 1746 for(i=0; i<7; i++){ | |
| 1747 printf("%6d %1d\n", stat[i], i); | |
| 1748 } | |
| 1749 } | |
| 1750 } | |
| 1751 #endif | |
| 1752 } | |
| 324 | 1753 |
| 294 | 1754 } |
| 1755 | |
| 1756 #if 0 | |
| 1757 { | |
| 1758 float adap_parm; | |
| 1759 | |
| 1760 adap_parm = ((s->avg_mb_var << 1) + s->mb_var[s->mb_width*mb_y+mb_x] + 1.0) / | |
| 1761 ((s->mb_var[s->mb_width*mb_y+mb_x] << 1) + s->avg_mb_var + 1.0); | |
| 1762 | |
| 1763 printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d", | |
| 1764 (s->mb_type[s->mb_width*mb_y+mb_x] > 0) ? 'I' : 'P', | |
| 1765 s->qscale, adap_parm, s->qscale*adap_parm, | |
| 1766 s->mb_var[s->mb_width*mb_y+mb_x], s->avg_mb_var); | |
| 1767 } | |
| 1768 #endif | |
| 1769 /* DCT & quantize */ | |
| 344 | 1770 if(s->out_format==FMT_MJPEG){ |
| 1771 for(i=0;i<6;i++) { | |
| 1772 int overflow; | |
| 1773 s->block_last_index[i] = dct_quantize(s, s->block[i], i, 8, &overflow); | |
|
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
1774 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
| 344 | 1775 } |
| 1776 }else{ | |
| 1777 for(i=0;i<6;i++) { | |
| 456 | 1778 if(!skip_dct[i]){ |
| 1779 int overflow; | |
| 1780 s->block_last_index[i] = dct_quantize(s, s->block[i], i, s->qscale, &overflow); | |
| 344 | 1781 // FIXME we could decide to change to quantizer instead of clipping |
|
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
1782 // JS: I don't think that would be a good idea it could lower quality instead |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
1783 // of improve it. Just INTRADC clipping deserves changes in quantizer |
| 456 | 1784 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); |
| 1785 }else | |
| 1786 s->block_last_index[i]= -1; | |
| 344 | 1787 } |
| 456 | 1788 if(s->luma_elim_threshold && !s->mb_intra) |
| 1789 for(i=0; i<4; i++) | |
| 1790 dct_single_coeff_elimination(s, i, s->luma_elim_threshold, 0); | |
| 1791 if(s->chroma_elim_threshold && !s->mb_intra) | |
| 1792 for(i=4; i<6; i++) | |
| 1793 dct_single_coeff_elimination(s, i, s->chroma_elim_threshold, 1); | |
| 294 | 1794 } |
| 1795 | |
| 487 | 1796 if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){ |
| 1797 s->block_last_index[4]= | |
| 1798 s->block_last_index[5]= 0; | |
| 1799 s->block[4][0]= | |
| 1800 s->block[5][0]= 128; | |
| 1801 } | |
| 1802 | |
| 294 | 1803 /* huffman encode */ |
| 1804 switch(s->out_format) { | |
| 1805 case FMT_MPEG1: | |
| 1806 mpeg1_encode_mb(s, s->block, motion_x, motion_y); | |
| 1807 break; | |
| 1808 case FMT_H263: | |
| 1809 if (s->h263_msmpeg4) | |
| 1810 msmpeg4_encode_mb(s, s->block, motion_x, motion_y); | |
| 1811 else if(s->h263_pred) | |
| 1812 mpeg4_encode_mb(s, s->block, motion_x, motion_y); | |
| 1813 else | |
| 1814 h263_encode_mb(s, s->block, motion_x, motion_y); | |
| 1815 break; | |
| 1816 case FMT_MJPEG: | |
| 1817 mjpeg_encode_mb(s, s->block); | |
| 1818 break; | |
| 1819 } | |
| 1820 } | |
| 1821 | |
| 456 | 1822 void ff_copy_bits(PutBitContext *pb, UINT8 *src, int length) |
| 294 | 1823 { |
| 326 | 1824 int bytes= length>>4; |
| 1825 int bits= length&15; | |
| 1826 int i; | |
| 1827 | |
| 456 | 1828 if(length==0) return; |
| 1829 | |
| 326 | 1830 for(i=0; i<bytes; i++) put_bits(pb, 16, be2me_16(((uint16_t*)src)[i])); |
| 1831 put_bits(pb, bits, be2me_16(((uint16_t*)src)[i])>>(16-bits)); | |
| 0 | 1832 } |
| 1833 | |
| 456 | 1834 static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
| 326 | 1835 int i; |
| 1836 | |
| 1837 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
| 1838 | |
| 1839 /* mpeg1 */ | |
| 1840 d->mb_incr= s->mb_incr; | |
| 1841 for(i=0; i<3; i++) | |
| 1842 d->last_dc[i]= s->last_dc[i]; | |
| 1843 | |
| 1844 /* statistics */ | |
| 1845 d->mv_bits= s->mv_bits; | |
| 1846 d->i_tex_bits= s->i_tex_bits; | |
| 1847 d->p_tex_bits= s->p_tex_bits; | |
| 1848 d->i_count= s->i_count; | |
| 1849 d->p_count= s->p_count; | |
| 1850 d->skip_count= s->skip_count; | |
| 1851 d->misc_bits= s->misc_bits; | |
| 329 | 1852 d->last_bits= 0; |
| 327 | 1853 |
| 1854 d->mb_skiped= s->mb_skiped; | |
| 326 | 1855 } |
| 1856 | |
| 456 | 1857 static inline void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){ |
| 326 | 1858 int i; |
| 1859 | |
| 1860 memcpy(d->mv, s->mv, 2*4*2*sizeof(int)); | |
| 1861 memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? | |
| 1862 | |
| 1863 /* mpeg1 */ | |
| 1864 d->mb_incr= s->mb_incr; | |
| 1865 for(i=0; i<3; i++) | |
| 1866 d->last_dc[i]= s->last_dc[i]; | |
| 1867 | |
| 1868 /* statistics */ | |
| 1869 d->mv_bits= s->mv_bits; | |
| 1870 d->i_tex_bits= s->i_tex_bits; | |
| 1871 d->p_tex_bits= s->p_tex_bits; | |
| 1872 d->i_count= s->i_count; | |
| 1873 d->p_count= s->p_count; | |
| 1874 d->skip_count= s->skip_count; | |
| 1875 d->misc_bits= s->misc_bits; | |
| 1876 | |
| 1877 d->mb_intra= s->mb_intra; | |
| 327 | 1878 d->mb_skiped= s->mb_skiped; |
| 326 | 1879 d->mv_type= s->mv_type; |
| 1880 d->mv_dir= s->mv_dir; | |
| 1881 d->pb= s->pb; | |
| 456 | 1882 if(s->data_partitioning){ |
| 1883 d->pb2= s->pb2; | |
| 1884 d->tex_pb= s->tex_pb; | |
| 1885 } | |
| 326 | 1886 d->block= s->block; |
| 1887 for(i=0; i<6; i++) | |
| 1888 d->block_last_index[i]= s->block_last_index[i]; | |
| 1889 } | |
| 1890 | |
| 456 | 1891 static inline void encode_mb_hq(MpegEncContext *s, MpegEncContext *backup, MpegEncContext *best, int type, |
| 1892 PutBitContext pb[2], PutBitContext pb2[2], PutBitContext tex_pb[2], | |
| 1893 int *dmin, int *next_block, int motion_x, int motion_y) | |
| 1894 { | |
| 1895 int bits_count; | |
| 1896 | |
| 1897 copy_context_before_encode(s, backup, type); | |
| 1898 | |
| 1899 s->block= s->blocks[*next_block]; | |
| 1900 s->pb= pb[*next_block]; | |
| 1901 if(s->data_partitioning){ | |
| 1902 s->pb2 = pb2 [*next_block]; | |
| 1903 s->tex_pb= tex_pb[*next_block]; | |
| 1904 } | |
| 1905 | |
| 1906 encode_mb(s, motion_x, motion_y); | |
| 1907 | |
| 1908 bits_count= get_bit_count(&s->pb); | |
| 1909 if(s->data_partitioning){ | |
| 1910 bits_count+= get_bit_count(&s->pb2); | |
| 1911 bits_count+= get_bit_count(&s->tex_pb); | |
| 1912 } | |
| 1913 | |
| 1914 if(bits_count<*dmin){ | |
| 1915 *dmin= bits_count; | |
| 1916 *next_block^=1; | |
| 1917 | |
| 1918 copy_context_after_encode(best, s, type); | |
| 1919 } | |
| 1920 } | |
| 326 | 1921 |
| 0 | 1922 static void encode_picture(MpegEncContext *s, int picture_number) |
| 1923 { | |
| 294 | 1924 int mb_x, mb_y, last_gob, pdif = 0; |
| 1925 int i; | |
| 286 | 1926 int bits; |
| 326 | 1927 MpegEncContext best_s, backup_s; |
| 456 | 1928 UINT8 bit_buf[2][3000]; |
| 1929 UINT8 bit_buf2[2][3000]; | |
| 1930 UINT8 bit_buf_tex[2][3000]; | |
| 1931 PutBitContext pb[2], pb2[2], tex_pb[2]; | |
| 1932 | |
| 1933 for(i=0; i<2; i++){ | |
| 1934 init_put_bits(&pb [i], bit_buf [i], 3000, NULL, NULL); | |
| 1935 init_put_bits(&pb2 [i], bit_buf2 [i], 3000, NULL, NULL); | |
| 1936 init_put_bits(&tex_pb[i], bit_buf_tex[i], 3000, NULL, NULL); | |
| 1937 } | |
| 0 | 1938 |
| 1939 s->picture_number = picture_number; | |
| 268 | 1940 |
| 294 | 1941 s->block_wrap[0]= |
| 1942 s->block_wrap[1]= | |
| 1943 s->block_wrap[2]= | |
| 1944 s->block_wrap[3]= s->mb_width*2 + 2; | |
| 1945 s->block_wrap[4]= | |
| 1946 s->block_wrap[5]= s->mb_width + 2; | |
| 1947 | |
| 268 | 1948 /* Reset the average MB variance */ |
| 456 | 1949 s->mb_var_sum = 0; |
| 1950 s->mc_mb_var_sum = 0; | |
| 327 | 1951 |
| 1952 /* we need to initialize some time vars before we can encode b-frames */ | |
| 1953 if (s->h263_pred && !s->h263_msmpeg4) | |
| 1954 ff_set_mpeg4_time(s, s->picture_number); | |
| 1955 | |
| 268 | 1956 /* Estimate motion for every MB */ |
| 324 | 1957 if(s->pict_type != I_TYPE){ |
| 294 | 1958 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
| 1959 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; | |
| 1960 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
| 1961 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
| 1962 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
| 1963 for(mb_x=0; mb_x < s->mb_width; mb_x++) { | |
| 1964 s->mb_x = mb_x; | |
| 1965 s->mb_y = mb_y; | |
| 1966 s->block_index[0]+=2; | |
| 1967 s->block_index[1]+=2; | |
| 1968 s->block_index[2]+=2; | |
| 1969 s->block_index[3]+=2; | |
| 268 | 1970 |
| 294 | 1971 /* compute motion vector & mb_type and store in context */ |
| 324 | 1972 if(s->pict_type==B_TYPE) |
| 1973 ff_estimate_b_frame_motion(s, mb_x, mb_y); | |
| 1974 else | |
| 1975 ff_estimate_p_frame_motion(s, mb_x, mb_y); | |
| 294 | 1976 // s->mb_type[mb_y*s->mb_width + mb_x]=MB_TYPE_INTER; |
| 268 | 1977 } |
| 1978 } | |
| 294 | 1979 emms_c(); |
| 456 | 1980 }else /* if(s->pict_type == I_TYPE) */{ |
| 294 | 1981 /* I-Frame */ |
| 1982 //FIXME do we need to zero them? | |
| 1983 memset(s->motion_val[0], 0, sizeof(INT16)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2); | |
| 324 | 1984 memset(s->p_mv_table , 0, sizeof(INT16)*(s->mb_width+2)*(s->mb_height+2)*2); |
| 294 | 1985 memset(s->mb_type , MB_TYPE_INTRA, sizeof(UINT8)*s->mb_width*s->mb_height); |
| 268 | 1986 } |
| 1987 | |
| 456 | 1988 if(s->mb_var_sum < s->mc_mb_var_sum && s->pict_type == P_TYPE){ //FIXME subtract MV bits |
| 271 | 1989 s->pict_type= I_TYPE; |
| 294 | 1990 memset(s->mb_type , MB_TYPE_INTRA, sizeof(UINT8)*s->mb_width*s->mb_height); |
| 329 | 1991 if(s->max_b_frames==0){ |
| 1992 s->input_pict_type= I_TYPE; | |
| 1993 s->input_picture_in_gop_number=0; | |
| 1994 } | |
| 294 | 1995 //printf("Scene change detected, encoding as I Frame\n"); |
| 271 | 1996 } |
| 324 | 1997 |
| 1998 if(s->pict_type==P_TYPE || s->pict_type==S_TYPE) | |
| 1999 s->f_code= ff_get_best_fcode(s, s->p_mv_table, MB_TYPE_INTER); | |
| 2000 ff_fix_long_p_mvs(s); | |
| 2001 if(s->pict_type==B_TYPE){ | |
| 2002 s->f_code= ff_get_best_fcode(s, s->b_forw_mv_table, MB_TYPE_FORWARD); | |
| 2003 s->b_code= ff_get_best_fcode(s, s->b_back_mv_table, MB_TYPE_BACKWARD); | |
| 327 | 2004 |
| 2005 ff_fix_long_b_mvs(s, s->b_forw_mv_table, s->f_code, MB_TYPE_FORWARD); | |
| 2006 ff_fix_long_b_mvs(s, s->b_back_mv_table, s->b_code, MB_TYPE_BACKWARD); | |
| 2007 ff_fix_long_b_mvs(s, s->b_bidir_forw_mv_table, s->f_code, MB_TYPE_BIDIR); | |
| 2008 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
|
2009 } |
| 324 | 2010 |
|
277
5cb2978e701f
new motion estimation (epzs) not complete yet but allready pretty good :)
michaelni
parents:
271
diff
changeset
|
2011 //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
|
2012 |
| 271 | 2013 // printf("%d %d\n", s->avg_mb_var, s->mc_mb_var); |
| 329 | 2014 if(s->flags&CODEC_FLAG_PASS2) |
| 2015 s->qscale = ff_rate_estimate_qscale_pass2(s); | |
| 2016 else if (!s->fixed_qscale) | |
| 2017 s->qscale = ff_rate_estimate_qscale(s); | |
| 2018 | |
| 0 | 2019 if (s->out_format == FMT_MJPEG) { |
| 2020 /* for mjpeg, we do include qscale in the matrix */ | |
|
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
514
diff
changeset
|
2021 s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; |
| 0 | 2022 for(i=1;i<64;i++) |
|
533
3c07cf9595de
adding ff prefix to avoid global name conficts with xvid (patch by Marko Kreen <marko at l-t.ee>)
michaelni
parents:
514
diff
changeset
|
2023 s->intra_matrix[i] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); |
| 344 | 2024 convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, |
| 2025 s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias); | |
| 0 | 2026 } |
| 2027 | |
| 286 | 2028 s->last_bits= get_bit_count(&s->pb); |
| 0 | 2029 switch(s->out_format) { |
| 2030 case FMT_MJPEG: | |
| 2031 mjpeg_picture_header(s); | |
| 2032 break; | |
| 2033 case FMT_H263: | |
| 2034 if (s->h263_msmpeg4) | |
| 2035 msmpeg4_encode_picture_header(s, picture_number); | |
| 2036 else if (s->h263_pred) | |
| 2037 mpeg4_encode_picture_header(s, picture_number); | |
| 2038 else if (s->h263_rv10) | |
| 2039 rv10_encode_picture_header(s, picture_number); | |
| 2040 else | |
| 2041 h263_encode_picture_header(s, picture_number); | |
| 2042 break; | |
| 2043 case FMT_MPEG1: | |
| 2044 mpeg1_encode_picture_header(s, picture_number); | |
| 2045 break; | |
| 2046 } | |
| 286 | 2047 bits= get_bit_count(&s->pb); |
| 2048 s->header_bits= bits - s->last_bits; | |
| 2049 s->last_bits= bits; | |
| 2050 s->mv_bits=0; | |
| 2051 s->misc_bits=0; | |
| 2052 s->i_tex_bits=0; | |
| 2053 s->p_tex_bits=0; | |
| 2054 s->i_count=0; | |
| 2055 s->p_count=0; | |
| 2056 s->skip_count=0; | |
| 2057 | |
| 0 | 2058 /* init last dc values */ |
| 2059 /* note: quant matrix value (8) is implied here */ | |
| 2060 s->last_dc[0] = 128; | |
| 2061 s->last_dc[1] = 128; | |
| 2062 s->last_dc[2] = 128; | |
| 2063 s->mb_incr = 1; | |
| 2064 s->last_mv[0][0][0] = 0; | |
| 2065 s->last_mv[0][0][1] = 0; | |
| 2066 | |
| 162 | 2067 /* Get the GOB height based on picture height */ |
| 231 | 2068 if (s->out_format == FMT_H263 && !s->h263_pred && !s->h263_msmpeg4) { |
| 162 | 2069 if (s->height <= 400) |
| 2070 s->gob_index = 1; | |
| 2071 else if (s->height <= 800) | |
| 2072 s->gob_index = 2; | |
| 2073 else | |
| 2074 s->gob_index = 4; | |
| 456 | 2075 }else if(s->codec_id==CODEC_ID_MPEG4){ |
| 2076 s->gob_index = 1; | |
| 162 | 2077 } |
| 456 | 2078 |
| 2079 if(s->codec_id==CODEC_ID_MPEG4 && s->data_partitioning && s->pict_type!=B_TYPE) | |
| 2080 ff_mpeg4_init_partitions(s); | |
| 2081 | |
| 2082 s->resync_mb_x=0; | |
| 2083 s->resync_mb_y=0; | |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2084 for(mb_y=0; mb_y < s->mb_height; mb_y++) { |
| 456 | 2085 /* Put GOB header based on RTP MTU for formats which support it per line (H263*)*/ |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2086 /* 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
|
2087 if (s->rtp_mode) { |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2088 if (!mb_y) { |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2089 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
|
2090 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
|
2091 } else if (s->out_format == FMT_H263 && !s->h263_pred && !s->h263_msmpeg4 && !(mb_y % s->gob_index)) { |
| 456 | 2092 // MN: we could move the space check from h263 -> here, as its not h263 specific |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2093 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
|
2094 if (last_gob) { |
| 456 | 2095 s->first_slice_line = 1; |
| 2096 }else{ | |
| 2097 /*MN: we reset it here instead at the end of each line cuz mpeg4 can have | |
| 2098 slice lines starting & ending in the middle*/ | |
| 2099 s->first_slice_line = 0; | |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2100 } |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2101 } |
|
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2102 } |
| 499 | 2103 |
| 2104 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; | |
| 2105 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; | |
|
233
3f5b72726118
- More work on preliminary bit rate control, just to be able to get an
pulento
parents:
232
diff
changeset
|
2106 |
| 266 | 2107 s->block_index[0]= s->block_wrap[0]*(mb_y*2 + 1) - 1; |
| 2108 s->block_index[1]= s->block_wrap[0]*(mb_y*2 + 1); | |
| 2109 s->block_index[2]= s->block_wrap[0]*(mb_y*2 + 2) - 1; | |
| 2110 s->block_index[3]= s->block_wrap[0]*(mb_y*2 + 2); | |
| 2111 s->block_index[4]= s->block_wrap[4]*(mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2); | |
| 2112 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
|
2113 for(mb_x=0; mb_x < s->mb_width; mb_x++) { |
| 327 | 2114 const int mb_type= s->mb_type[mb_y * s->mb_width + mb_x]; |
| 2115 const int xy= (mb_y+1) * (s->mb_width+2) + mb_x + 1; | |
| 456 | 2116 // int d; |
| 294 | 2117 int dmin=10000000; |
| 0 | 2118 |
|
232
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
2119 s->mb_x = mb_x; |
|
b640ec5948b0
- Now the ME is done for the entire picture when enconding, the
pulento
parents:
231
diff
changeset
|
2120 s->mb_y = mb_y; |
| 266 | 2121 s->block_index[0]+=2; |
| 2122 s->block_index[1]+=2; | |
| 2123 s->block_index[2]+=2; | |
| 2124 s->block_index[3]+=2; | |
| 2125 s->block_index[4]++; | |
| 2126 s->block_index[5]++; | |
| 456 | 2127 |
| 2128 /* write gob / video packet header for formats which support it at any MB (MPEG4) */ | |
| 2129 if(s->rtp_mode && s->mb_y>0 && s->codec_id==CODEC_ID_MPEG4){ | |
| 2130 int pdif= pbBufPtr(&s->pb) - s->ptr_lastgob; | |
| 2131 | |
| 2132 //the *2 is there so we stay below the requested size | |
| 2133 if(pdif + s->mb_line_avgsize/s->mb_width >= s->rtp_payload_size){ | |
| 2134 if(s->codec_id==CODEC_ID_MPEG4){ | |
| 2135 if(s->data_partitioning && s->pict_type!=B_TYPE){ | |
| 2136 ff_mpeg4_merge_partitions(s); | |
| 2137 ff_mpeg4_init_partitions(s); | |
| 2138 } | |
| 2139 ff_mpeg4_encode_video_packet_header(s); | |
| 2140 | |
| 2141 if(s->flags&CODEC_FLAG_PASS1){ | |
| 2142 int bits= get_bit_count(&s->pb); | |
| 2143 s->misc_bits+= bits - s->last_bits; | |
| 2144 s->last_bits= bits; | |
| 2145 } | |
| 2146 ff_mpeg4_clean_buffers(s); | |
| 2147 } | |
| 2148 s->ptr_lastgob = pbBufPtr(&s->pb); | |
| 2149 s->first_slice_line=1; | |
| 2150 s->resync_mb_x=mb_x; | |
| 2151 s->resync_mb_y=mb_y; | |
| 2152 } | |
| 2153 | |
| 2154 if( (s->resync_mb_x == s->mb_x) | |
| 2155 && s->resync_mb_y+1 == s->mb_y){ | |
| 2156 s->first_slice_line=0; | |
| 2157 } | |
| 2158 } | |
| 2159 | |
| 294 | 2160 if(mb_type & (mb_type-1)){ // more than 1 MB type possible |
| 327 | 2161 int next_block=0; |
| 456 | 2162 int pb_bits_count, pb2_bits_count, tex_pb_bits_count; |
| 326 | 2163 |
| 2164 copy_context_before_encode(&backup_s, s, -1); | |
| 456 | 2165 backup_s.pb= s->pb; |
| 2166 best_s.data_partitioning= s->data_partitioning; | |
| 2167 if(s->data_partitioning){ | |
| 2168 backup_s.pb2= s->pb2; | |
| 2169 backup_s.tex_pb= s->tex_pb; | |
| 2170 } | |
| 326 | 2171 |
| 294 | 2172 if(mb_type&MB_TYPE_INTER){ |
| 327 | 2173 s->mv_dir = MV_DIR_FORWARD; |
| 295 | 2174 s->mv_type = MV_TYPE_16X16; |
| 294 | 2175 s->mb_intra= 0; |
| 324 | 2176 s->mv[0][0][0] = s->p_mv_table[xy][0]; |
| 2177 s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
| 456 | 2178 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER, pb, pb2, tex_pb, |
| 2179 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); | |
| 0 | 2180 } |
| 326 | 2181 if(mb_type&MB_TYPE_INTER4V){ |
| 327 | 2182 s->mv_dir = MV_DIR_FORWARD; |
| 295 | 2183 s->mv_type = MV_TYPE_8X8; |
| 2184 s->mb_intra= 0; | |
| 2185 for(i=0; i<4; i++){ | |
| 2186 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; | |
| 2187 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; | |
| 2188 } | |
| 456 | 2189 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER4V, pb, pb2, tex_pb, |
| 2190 &dmin, &next_block, 0, 0); | |
| 327 | 2191 } |
| 2192 if(mb_type&MB_TYPE_FORWARD){ | |
| 2193 s->mv_dir = MV_DIR_FORWARD; | |
| 2194 s->mv_type = MV_TYPE_16X16; | |
| 2195 s->mb_intra= 0; | |
| 2196 s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
| 2197 s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
| 456 | 2198 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_FORWARD, pb, pb2, tex_pb, |
| 2199 &dmin, &next_block, s->mv[0][0][0], s->mv[0][0][1]); | |
| 327 | 2200 } |
| 2201 if(mb_type&MB_TYPE_BACKWARD){ | |
| 2202 s->mv_dir = MV_DIR_BACKWARD; | |
| 2203 s->mv_type = MV_TYPE_16X16; | |
| 2204 s->mb_intra= 0; | |
| 2205 s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
| 2206 s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
| 456 | 2207 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BACKWARD, pb, pb2, tex_pb, |
| 2208 &dmin, &next_block, s->mv[1][0][0], s->mv[1][0][1]); | |
| 327 | 2209 } |
| 2210 if(mb_type&MB_TYPE_BIDIR){ | |
| 2211 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; | |
| 2212 s->mv_type = MV_TYPE_16X16; | |
| 2213 s->mb_intra= 0; | |
| 2214 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
| 2215 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
| 2216 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
| 2217 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
| 456 | 2218 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_BIDIR, pb, pb2, tex_pb, |
| 2219 &dmin, &next_block, 0, 0); | |
| 327 | 2220 } |
| 2221 if(mb_type&MB_TYPE_DIRECT){ | |
| 2222 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; | |
| 2223 s->mv_type = MV_TYPE_16X16; //FIXME | |
| 2224 s->mb_intra= 0; | |
| 2225 s->mv[0][0][0] = s->b_direct_forw_mv_table[xy][0]; | |
| 2226 s->mv[0][0][1] = s->b_direct_forw_mv_table[xy][1]; | |
| 2227 s->mv[1][0][0] = s->b_direct_back_mv_table[xy][0]; | |
| 2228 s->mv[1][0][1] = s->b_direct_back_mv_table[xy][1]; | |
| 456 | 2229 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_DIRECT, pb, pb2, tex_pb, |
| 2230 &dmin, &next_block, s->b_direct_mv_table[xy][0], s->b_direct_mv_table[xy][1]); | |
| 295 | 2231 } |
| 294 | 2232 if(mb_type&MB_TYPE_INTRA){ |
| 327 | 2233 s->mv_dir = MV_DIR_FORWARD; |
| 295 | 2234 s->mv_type = MV_TYPE_16X16; |
| 294 | 2235 s->mb_intra= 1; |
| 2236 s->mv[0][0][0] = 0; | |
| 2237 s->mv[0][0][1] = 0; | |
| 456 | 2238 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTRA, pb, pb2, tex_pb, |
| 2239 &dmin, &next_block, 0, 0); | |
| 326 | 2240 /* force cleaning of ac/dc pred stuff if needed ... */ |
| 2241 if(s->h263_pred || s->h263_aic) | |
| 2242 s->mbintra_table[mb_x + mb_y*s->mb_width]=1; | |
| 295 | 2243 } |
| 326 | 2244 copy_context_after_encode(s, &best_s, -1); |
| 456 | 2245 |
| 2246 pb_bits_count= get_bit_count(&s->pb); | |
| 2247 flush_put_bits(&s->pb); | |
| 2248 ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); | |
| 2249 s->pb= backup_s.pb; | |
| 2250 | |
| 2251 if(s->data_partitioning){ | |
| 2252 pb2_bits_count= get_bit_count(&s->pb2); | |
| 2253 flush_put_bits(&s->pb2); | |
| 2254 ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); | |
| 2255 s->pb2= backup_s.pb2; | |
| 2256 | |
| 2257 tex_pb_bits_count= get_bit_count(&s->tex_pb); | |
| 2258 flush_put_bits(&s->tex_pb); | |
| 2259 ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); | |
| 2260 s->tex_pb= backup_s.tex_pb; | |
| 2261 } | |
| 329 | 2262 s->last_bits= get_bit_count(&s->pb); |
| 294 | 2263 } else { |
| 324 | 2264 int motion_x, motion_y; |
| 2265 s->mv_type=MV_TYPE_16X16; | |
| 294 | 2266 // only one MB-Type possible |
| 327 | 2267 switch(mb_type){ |
| 2268 case MB_TYPE_INTRA: | |
| 324 | 2269 s->mv_dir = MV_DIR_FORWARD; |
| 294 | 2270 s->mb_intra= 1; |
| 324 | 2271 motion_x= s->mv[0][0][0] = 0; |
| 2272 motion_y= s->mv[0][0][1] = 0; | |
| 327 | 2273 break; |
| 2274 case MB_TYPE_INTER: | |
| 324 | 2275 s->mv_dir = MV_DIR_FORWARD; |
| 2276 s->mb_intra= 0; | |
| 2277 motion_x= s->mv[0][0][0] = s->p_mv_table[xy][0]; | |
| 2278 motion_y= s->mv[0][0][1] = s->p_mv_table[xy][1]; | |
| 327 | 2279 break; |
| 456 | 2280 case MB_TYPE_INTER4V: |
| 2281 s->mv_dir = MV_DIR_FORWARD; | |
| 2282 s->mv_type = MV_TYPE_8X8; | |
| 2283 s->mb_intra= 0; | |
| 2284 for(i=0; i<4; i++){ | |
| 2285 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; | |
| 2286 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; | |
| 2287 } | |
| 2288 motion_x= motion_y= 0; | |
| 2289 break; | |
| 327 | 2290 case MB_TYPE_DIRECT: |
| 324 | 2291 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; |
| 2292 s->mb_intra= 0; | |
| 327 | 2293 motion_x=s->b_direct_mv_table[xy][0]; |
| 2294 motion_y=s->b_direct_mv_table[xy][1]; | |
| 2295 s->mv[0][0][0] = s->b_direct_forw_mv_table[xy][0]; | |
| 2296 s->mv[0][0][1] = s->b_direct_forw_mv_table[xy][1]; | |
| 2297 s->mv[1][0][0] = s->b_direct_back_mv_table[xy][0]; | |
| 2298 s->mv[1][0][1] = s->b_direct_back_mv_table[xy][1]; | |
| 2299 break; | |
| 2300 case MB_TYPE_BIDIR: | |
| 324 | 2301 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; |
| 294 | 2302 s->mb_intra= 0; |
| 324 | 2303 motion_x=0; |
| 2304 motion_y=0; | |
| 2305 s->mv[0][0][0] = s->b_bidir_forw_mv_table[xy][0]; | |
| 2306 s->mv[0][0][1] = s->b_bidir_forw_mv_table[xy][1]; | |
| 2307 s->mv[1][0][0] = s->b_bidir_back_mv_table[xy][0]; | |
| 2308 s->mv[1][0][1] = s->b_bidir_back_mv_table[xy][1]; | |
| 327 | 2309 break; |
| 2310 case MB_TYPE_BACKWARD: | |
| 324 | 2311 s->mv_dir = MV_DIR_BACKWARD; |
| 2312 s->mb_intra= 0; | |
| 2313 motion_x= s->mv[1][0][0] = s->b_back_mv_table[xy][0]; | |
| 2314 motion_y= s->mv[1][0][1] = s->b_back_mv_table[xy][1]; | |
| 327 | 2315 break; |
| 2316 case MB_TYPE_FORWARD: | |
| 324 | 2317 s->mv_dir = MV_DIR_FORWARD; |
| 2318 s->mb_intra= 0; | |
| 2319 motion_x= s->mv[0][0][0] = s->b_forw_mv_table[xy][0]; | |
| 2320 motion_y= s->mv[0][0][1] = s->b_forw_mv_table[xy][1]; | |
| 2321 // printf(" %d %d ", motion_x, motion_y); | |
| 327 | 2322 break; |
| 2323 default: | |
| 324 | 2324 motion_x=motion_y=0; //gcc warning fix |
| 2325 printf("illegal MB type\n"); | |
| 294 | 2326 } |
| 324 | 2327 encode_mb(s, motion_x, motion_y); |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2328 } |
| 327 | 2329 /* clean the MV table in IPS frames for direct mode in B frames */ |
| 2330 if(s->mb_intra /* && I,P,S_TYPE */){ | |
| 2331 s->p_mv_table[xy][0]=0; | |
| 2332 s->p_mv_table[xy][1]=0; | |
| 2333 } | |
| 0 | 2334 |
|
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
|
2335 MPV_decode_mb(s, s->block); |
| 456 | 2336 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_width, get_bit_count(&s->pb)); |
| 0 | 2337 } |
|
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
|
2338 |
|
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
|
2339 |
| 231 | 2340 /* Obtain average GOB size for RTP */ |
| 2341 if (s->rtp_mode) { | |
| 2342 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
|
2343 s->mb_line_avgsize = pbBufPtr(&s->pb) - s->ptr_last_mb_line; |
| 231 | 2344 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
|
2345 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
|
2346 s->ptr_last_mb_line = pbBufPtr(&s->pb); |
| 231 | 2347 } |
| 2348 //fprintf(stderr, "\nMB line: %d\tSize: %u\tAvg. Size: %u", s->mb_y, | |
| 2349 // (s->pb.buf_ptr - s->ptr_last_mb_line), s->mb_line_avgsize); | |
| 456 | 2350 if(s->codec_id!=CODEC_ID_MPEG4) s->first_slice_line = 0; //FIXME clean |
| 231 | 2351 } |
| 0 | 2352 } |
| 294 | 2353 emms_c(); |
| 286 | 2354 |
| 456 | 2355 if(s->codec_id==CODEC_ID_MPEG4 && s->data_partitioning && s->pict_type!=B_TYPE) |
| 2356 ff_mpeg4_merge_partitions(s); | |
| 2357 | |
| 2358 if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == I_TYPE) | |
| 208 | 2359 msmpeg4_encode_ext_header(s); |
| 2360 | |
| 456 | 2361 if(s->codec_id==CODEC_ID_MPEG4) |
| 2362 ff_mpeg4_stuffing(&s->pb); | |
| 2363 | |
| 162 | 2364 //if (s->gob_number) |
| 2365 // fprintf(stderr,"\nNumber of GOB: %d", s->gob_number); | |
| 231 | 2366 |
| 2367 /* Send the last GOB if RTP */ | |
| 2368 if (s->rtp_mode) { | |
| 2369 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
|
2370 pdif = pbBufPtr(&s->pb) - s->ptr_lastgob; |
| 231 | 2371 /* Call the RTP callback to send the last GOB */ |
| 2372 if (s->rtp_callback) | |
| 2373 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
|
2374 s->ptr_lastgob = pbBufPtr(&s->pb); |
| 231 | 2375 //fprintf(stderr,"\nGOB: %2d size: %d (last)", s->gob_number, pdif); |
| 2376 } | |
| 0 | 2377 } |
| 2378 | |
| 220 | 2379 static int dct_quantize_c(MpegEncContext *s, |
| 0 | 2380 DCTELEM *block, int n, |
| 344 | 2381 int qscale, int *overflow) |
| 0 | 2382 { |
| 2383 int i, j, level, last_non_zero, q; | |
| 2384 const int *qmat; | |
| 344 | 2385 int bias; |
| 2386 int max=0; | |
| 2387 unsigned int threshold1, threshold2; | |
| 456 | 2388 |
| 0 | 2389 av_fdct (block); |
| 2390 | |
| 64 | 2391 /* we need this permutation so that we correct the IDCT |
| 2392 permutation. will be moved into DCT code */ | |
| 2393 block_permute(block); | |
| 2394 | |
| 0 | 2395 if (s->mb_intra) { |
|
350
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2396 if (!s->h263_aic) { |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2397 if (n < 4) |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2398 q = s->y_dc_scale; |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2399 else |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2400 q = s->c_dc_scale; |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2401 q = q << 3; |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2402 } else |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2403 /* For AIC we skip quant/dequant of INTRADC */ |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2404 q = 1 << 3; |
|
6ebbecc10063
- Advanced Intra Coding (AIC) support for H.263+ encoder, just DC by now.
pulento
parents:
347
diff
changeset
|
2405 |
| 0 | 2406 /* note: block[0] is assumed to be positive */ |
| 2407 block[0] = (block[0] + (q >> 1)) / q; | |
| 2408 i = 1; | |
| 2409 last_non_zero = 0; | |
| 344 | 2410 qmat = s->q_intra_matrix[qscale]; |
| 2411 bias= s->intra_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT); | |
| 0 | 2412 } else { |
| 2413 i = 0; | |
| 2414 last_non_zero = -1; | |
| 344 | 2415 qmat = s->q_inter_matrix[qscale]; |
| 2416 bias= s->inter_quant_bias<<(QMAT_SHIFT - 3 - QUANT_BIAS_SHIFT); | |
| 0 | 2417 } |
| 344 | 2418 threshold1= (1<<(QMAT_SHIFT - 3)) - bias - 1; |
| 2419 threshold2= threshold1<<1; | |
| 0 | 2420 |
| 2421 for(;i<64;i++) { | |
| 2422 j = zigzag_direct[i]; | |
| 2423 level = block[j]; | |
| 2424 level = level * qmat[j]; | |
| 344 | 2425 |
| 2426 // if( bias+level >= (1<<(QMAT_SHIFT - 3)) | |
| 2427 // || bias-level >= (1<<(QMAT_SHIFT - 3))){ | |
| 2428 if(((unsigned)(level+threshold1))>threshold2){ | |
| 2429 if(level>0){ | |
| 2430 level= (bias + level)>>(QMAT_SHIFT - 3); | |
| 2431 block[j]= level; | |
| 2432 }else{ | |
| 2433 level= (bias - level)>>(QMAT_SHIFT - 3); | |
| 2434 block[j]= -level; | |
| 0 | 2435 } |
| 344 | 2436 max |=level; |
| 0 | 2437 last_non_zero = i; |
| 344 | 2438 }else{ |
| 2439 block[j]=0; | |
| 0 | 2440 } |
| 2441 } | |
| 344 | 2442 *overflow= s->max_qcoeff < max; //overflow might have happend |
| 2443 | |
| 0 | 2444 return last_non_zero; |
| 2445 } | |
| 2446 | |
|
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
|
2447 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
|
2448 DCTELEM *block, int n, int qscale) |
| 0 | 2449 { |
| 200 | 2450 int i, level, nCoeffs; |
| 0 | 2451 const UINT16 *quant_matrix; |
| 2452 | |
| 200 | 2453 if(s->alternate_scan) nCoeffs= 64; |
| 2454 else nCoeffs= s->block_last_index[n]+1; | |
| 2455 | |
| 0 | 2456 if (s->mb_intra) { |
| 2457 if (n < 4) | |
| 2458 block[0] = block[0] * s->y_dc_scale; | |
| 2459 else | |
| 2460 block[0] = block[0] * s->c_dc_scale; | |
| 2461 /* XXX: only mpeg1 */ | |
| 2462 quant_matrix = s->intra_matrix; | |
| 200 | 2463 for(i=1;i<nCoeffs;i++) { |
| 2464 int j= zigzag_direct[i]; | |
| 2465 level = block[j]; | |
| 0 | 2466 if (level) { |
| 2467 if (level < 0) { | |
| 2468 level = -level; | |
| 200 | 2469 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
| 0 | 2470 level = (level - 1) | 1; |
| 2471 level = -level; | |
| 2472 } else { | |
| 200 | 2473 level = (int)(level * qscale * quant_matrix[j]) >> 3; |
| 0 | 2474 level = (level - 1) | 1; |
| 2475 } | |
| 2476 #ifdef PARANOID | |
| 2477 if (level < -2048 || level > 2047) | |
| 2478 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 2479 #endif | |
| 200 | 2480 block[j] = level; |
| 0 | 2481 } |
| 2482 } | |
| 2483 } else { | |
| 2484 i = 0; | |
| 344 | 2485 quant_matrix = s->inter_matrix; |
| 217 | 2486 for(;i<nCoeffs;i++) { |
| 200 | 2487 int j= zigzag_direct[i]; |
| 2488 level = block[j]; | |
| 0 | 2489 if (level) { |
| 2490 if (level < 0) { | |
| 2491 level = -level; | |
| 2492 level = (((level << 1) + 1) * qscale * | |
| 200 | 2493 ((int) (quant_matrix[j]))) >> 4; |
| 0 | 2494 level = (level - 1) | 1; |
| 2495 level = -level; | |
| 2496 } else { | |
| 2497 level = (((level << 1) + 1) * qscale * | |
| 200 | 2498 ((int) (quant_matrix[j]))) >> 4; |
| 0 | 2499 level = (level - 1) | 1; |
| 2500 } | |
| 2501 #ifdef PARANOID | |
| 2502 if (level < -2048 || level > 2047) | |
| 2503 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 2504 #endif | |
| 200 | 2505 block[j] = level; |
| 0 | 2506 } |
| 2507 } | |
| 2508 } | |
| 2509 } | |
|
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
|
2510 |
| 325 | 2511 static void dct_unquantize_mpeg2_c(MpegEncContext *s, |
| 2512 DCTELEM *block, int n, int qscale) | |
| 2513 { | |
| 2514 int i, level, nCoeffs; | |
| 2515 const UINT16 *quant_matrix; | |
| 2516 | |
| 2517 if(s->alternate_scan) nCoeffs= 64; | |
| 2518 else nCoeffs= s->block_last_index[n]+1; | |
| 2519 | |
| 2520 if (s->mb_intra) { | |
| 2521 if (n < 4) | |
| 2522 block[0] = block[0] * s->y_dc_scale; | |
| 2523 else | |
| 2524 block[0] = block[0] * s->c_dc_scale; | |
| 2525 quant_matrix = s->intra_matrix; | |
| 2526 for(i=1;i<nCoeffs;i++) { | |
| 2527 int j= zigzag_direct[i]; | |
| 2528 level = block[j]; | |
| 2529 if (level) { | |
| 2530 if (level < 0) { | |
| 2531 level = -level; | |
| 2532 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 2533 level = -level; | |
| 2534 } else { | |
| 2535 level = (int)(level * qscale * quant_matrix[j]) >> 3; | |
| 2536 } | |
| 2537 #ifdef PARANOID | |
| 2538 if (level < -2048 || level > 2047) | |
| 2539 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 2540 #endif | |
| 2541 block[j] = level; | |
| 2542 } | |
| 2543 } | |
| 2544 } else { | |
| 2545 int sum=-1; | |
| 2546 i = 0; | |
| 344 | 2547 quant_matrix = s->inter_matrix; |
| 325 | 2548 for(;i<nCoeffs;i++) { |
| 2549 int j= zigzag_direct[i]; | |
| 2550 level = block[j]; | |
| 2551 if (level) { | |
| 2552 if (level < 0) { | |
| 2553 level = -level; | |
| 2554 level = (((level << 1) + 1) * qscale * | |
| 2555 ((int) (quant_matrix[j]))) >> 4; | |
| 2556 level = -level; | |
| 2557 } else { | |
| 2558 level = (((level << 1) + 1) * qscale * | |
| 2559 ((int) (quant_matrix[j]))) >> 4; | |
| 2560 } | |
| 2561 #ifdef PARANOID | |
| 2562 if (level < -2048 || level > 2047) | |
| 2563 fprintf(stderr, "unquant error %d %d\n", i, level); | |
| 2564 #endif | |
| 2565 block[j] = level; | |
| 2566 sum+=level; | |
| 2567 } | |
| 2568 } | |
| 2569 block[63]^=sum&1; | |
| 2570 } | |
| 2571 } | |
| 2572 | |
| 2573 | |
|
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
|
2574 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
|
2575 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
|
2576 { |
|
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
|
2577 int i, level, qmul, qadd; |
| 200 | 2578 int nCoeffs; |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2579 |
|
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
|
2580 if (s->mb_intra) { |
|
249
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2581 if (!s->h263_aic) { |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2582 if (n < 4) |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2583 block[0] = block[0] * s->y_dc_scale; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2584 else |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2585 block[0] = block[0] * s->c_dc_scale; |
|
42a0b7b16738
- Bug fixes in H.263+ Advanced INTRA Coding decoder.
pulento
parents:
248
diff
changeset
|
2586 } |
|
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
|
2587 i = 1; |
| 200 | 2588 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
|
2589 } 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
|
2590 i = 0; |
| 200 | 2591 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
|
2592 } |
|
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
|
2593 |
|
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
|
2594 qmul = s->qscale << 1; |
|
248
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2595 if (s->h263_aic && s->mb_intra) |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2596 qadd = 0; |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2597 else |
|
56ee684c48bb
- H.263+ decoder support for Advanded INTRA Coding (buggy)
pulento
parents:
244
diff
changeset
|
2598 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
|
2599 |
| 200 | 2600 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
|
2601 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
|
2602 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
|
2603 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
|
2604 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
|
2605 } 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
|
2606 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
|
2607 } |
|
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
|
2608 #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
|
2609 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
|
2610 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
|
2611 #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
|
2612 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
|
2613 } |
|
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
|
2614 } |
|
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
|
2615 } |
| 0 | 2616 |
| 456 | 2617 static void remove_ac(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y) |
| 2618 { | |
| 2619 int dc, dcb, dcr, y, i; | |
| 2620 for(i=0; i<4; i++){ | |
| 2621 dc= s->dc_val[0][mb_x*2+1 + (i&1) + (mb_y*2+1 + (i>>1))*(s->mb_width*2+2)]; | |
| 2622 for(y=0; y<8; y++){ | |
| 2623 int x; | |
| 2624 for(x=0; x<8; x++){ | |
| 2625 dest_y[x + (i&1)*8 + (y + (i>>1)*8)*s->linesize]= dc/8; | |
| 2626 } | |
| 2627 } | |
| 2628 } | |
| 2629 dcb = s->dc_val[1][mb_x+1 + (mb_y+1)*(s->mb_width+2)]; | |
| 2630 dcr= s->dc_val[2][mb_x+1 + (mb_y+1)*(s->mb_width+2)]; | |
| 2631 for(y=0; y<8; y++){ | |
| 2632 int x; | |
| 2633 for(x=0; x<8; x++){ | |
| 556 | 2634 dest_cb[x + y*(s->uvlinesize)]= dcb/8; |
| 2635 dest_cr[x + y*(s->uvlinesize)]= dcr/8; | |
| 456 | 2636 } |
| 2637 } | |
| 2638 } | |
| 2639 | |
| 2640 /** | |
| 2641 * will conceal past errors, and allso drop b frames if needed | |
| 2642 * | |
| 2643 */ | |
| 2644 void ff_conceal_past_errors(MpegEncContext *s, int unknown_pos) | |
| 2645 { | |
| 2646 int mb_x= s->mb_x; | |
| 2647 int mb_y= s->mb_y; | |
| 2648 int mb_dist=0; | |
| 2649 int i, intra_count=0, inter_count=0; | |
| 2650 int intra_conceal= s->msmpeg4_version ? 50 : 50; //FIXME finetune | |
| 2651 int inter_conceal= s->msmpeg4_version ? 50 : 50; | |
| 2652 | |
| 2653 // for last block | |
| 2654 if(mb_x>=s->mb_width) mb_x= s->mb_width -1; | |
| 2655 if(mb_y>=s->mb_height) mb_y= s->mb_height-1; | |
| 2656 | |
| 2657 if(s->decoding_error==0 && unknown_pos){ | |
| 2658 if(s->data_partitioning && s->pict_type!=B_TYPE) | |
| 2659 s->decoding_error= DECODING_AC_LOST; | |
| 2660 else | |
| 2661 s->decoding_error= DECODING_DESYNC; | |
| 2662 } | |
| 2663 | |
| 2664 if(s->decoding_error==DECODING_DESYNC && s->pict_type!=B_TYPE) s->next_p_frame_damaged=1; | |
| 2665 | |
| 2666 for(i=mb_x + mb_y*s->mb_width; i>=0; i--){ | |
| 2667 if(s->mbintra_table[i]) intra_count++; | |
| 2668 else inter_count++; | |
| 2669 } | |
| 2670 | |
| 2671 if(s->decoding_error==DECODING_AC_LOST){ | |
| 2672 intra_conceal*=2; | |
| 2673 inter_conceal*=2; | |
| 2674 }else if(s->decoding_error==DECODING_ACDC_LOST){ | |
| 2675 intra_conceal*=2; | |
| 2676 inter_conceal*=2; | |
| 2677 } | |
| 2678 | |
| 2679 if(unknown_pos && (intra_count<inter_count)){ | |
| 2680 intra_conceal= inter_conceal= s->mb_num; | |
| 2681 // printf("%d %d\n",intra_count, inter_count); | |
| 2682 } | |
| 2683 | |
| 2684 fprintf(stderr, "concealing errors\n"); | |
| 2685 | |
| 2686 /* for all MBs from the current one back until the last resync marker */ | |
| 2687 for(; mb_y>=0 && mb_y>=s->resync_mb_y; mb_y--){ | |
| 2688 for(; mb_x>=0; mb_x--){ | |
| 2689 uint8_t *dest_y = s->current_picture[0] + (mb_y * 16* s->linesize ) + mb_x * 16; | |
| 556 | 2690 uint8_t *dest_cb = s->current_picture[1] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; |
| 2691 uint8_t *dest_cr = s->current_picture[2] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; | |
| 456 | 2692 int mb_x_backup= s->mb_x; //FIXME pass xy to mpeg_motion |
| 2693 int mb_y_backup= s->mb_y; | |
| 2694 s->mb_x=mb_x; | |
| 2695 s->mb_y=mb_y; | |
| 2696 if(s->mbintra_table[mb_y*s->mb_width + mb_x] && mb_dist<intra_conceal){ | |
| 2697 if(s->decoding_error==DECODING_AC_LOST){ | |
| 2698 remove_ac(s, dest_y, dest_cb, dest_cr, mb_x, mb_y); | |
| 2699 // printf("remove ac to %d %d\n", mb_x, mb_y); | |
| 2700 }else{ | |
| 2701 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 2702 s->last_picture, 0, 0, put_pixels_tab, | |
| 2703 0/*mx*/, 0/*my*/, 16); | |
| 2704 } | |
| 2705 } | |
| 2706 else if(!s->mbintra_table[mb_y*s->mb_width + mb_x] && mb_dist<inter_conceal){ | |
| 2707 int mx=0; | |
| 2708 int my=0; | |
| 2709 | |
| 2710 if(s->decoding_error!=DECODING_DESYNC){ | |
| 2711 int xy= mb_x*2+1 + (mb_y*2+1)*(s->mb_width*2+2); | |
| 2712 mx= s->motion_val[ xy ][0]; | |
| 2713 my= s->motion_val[ xy ][1]; | |
| 2714 } | |
| 2715 | |
| 2716 mpeg_motion(s, dest_y, dest_cb, dest_cr, 0, | |
| 2717 s->last_picture, 0, 0, put_pixels_tab, | |
| 2718 mx, my, 16); | |
| 2719 } | |
| 2720 s->mb_x= mb_x_backup; | |
| 2721 s->mb_y= mb_y_backup; | |
| 2722 | |
| 2723 if(mb_x== s->resync_mb_x && mb_y== s->resync_mb_y) return; | |
| 2724 if(!s->mbskip_table[mb_x + mb_y*s->mb_width]) mb_dist++; | |
| 2725 } | |
| 2726 mb_x=s->mb_width-1; | |
| 2727 } | |
| 2728 } | |
| 2729 | |
| 0 | 2730 AVCodec mpeg1video_encoder = { |
| 2731 "mpeg1video", | |
| 2732 CODEC_TYPE_VIDEO, | |
| 2733 CODEC_ID_MPEG1VIDEO, | |
| 2734 sizeof(MpegEncContext), | |
| 2735 MPV_encode_init, | |
| 2736 MPV_encode_picture, | |
| 2737 MPV_encode_end, | |
| 2738 }; | |
| 2739 | |
| 2740 AVCodec h263_encoder = { | |
| 2741 "h263", | |
| 2742 CODEC_TYPE_VIDEO, | |
| 2743 CODEC_ID_H263, | |
| 2744 sizeof(MpegEncContext), | |
| 2745 MPV_encode_init, | |
| 2746 MPV_encode_picture, | |
| 2747 MPV_encode_end, | |
| 2748 }; | |
| 2749 | |
| 2750 AVCodec h263p_encoder = { | |
| 2751 "h263p", | |
| 2752 CODEC_TYPE_VIDEO, | |
| 2753 CODEC_ID_H263P, | |
| 2754 sizeof(MpegEncContext), | |
| 2755 MPV_encode_init, | |
| 2756 MPV_encode_picture, | |
| 2757 MPV_encode_end, | |
| 2758 }; | |
| 2759 | |
| 2760 AVCodec rv10_encoder = { | |
| 2761 "rv10", | |
| 2762 CODEC_TYPE_VIDEO, | |
| 2763 CODEC_ID_RV10, | |
| 2764 sizeof(MpegEncContext), | |
| 2765 MPV_encode_init, | |
| 2766 MPV_encode_picture, | |
| 2767 MPV_encode_end, | |
| 2768 }; | |
| 2769 | |
| 2770 AVCodec mjpeg_encoder = { | |
| 2771 "mjpeg", | |
| 2772 CODEC_TYPE_VIDEO, | |
| 2773 CODEC_ID_MJPEG, | |
| 2774 sizeof(MpegEncContext), | |
| 2775 MPV_encode_init, | |
| 2776 MPV_encode_picture, | |
| 2777 MPV_encode_end, | |
| 2778 }; | |
| 2779 | |
| 71 | 2780 AVCodec mpeg4_encoder = { |
| 2781 "mpeg4", | |
| 0 | 2782 CODEC_TYPE_VIDEO, |
| 71 | 2783 CODEC_ID_MPEG4, |
| 0 | 2784 sizeof(MpegEncContext), |
| 2785 MPV_encode_init, | |
| 2786 MPV_encode_picture, | |
| 2787 MPV_encode_end, | |
| 2788 }; | |
| 2789 | |
| 307 | 2790 AVCodec msmpeg4v1_encoder = { |
| 2791 "msmpeg4v1", | |
| 0 | 2792 CODEC_TYPE_VIDEO, |
| 307 | 2793 CODEC_ID_MSMPEG4V1, |
| 0 | 2794 sizeof(MpegEncContext), |
| 2795 MPV_encode_init, | |
| 2796 MPV_encode_picture, | |
| 2797 MPV_encode_end, | |
| 2798 }; | |
| 307 | 2799 |
| 2800 AVCodec msmpeg4v2_encoder = { | |
| 2801 "msmpeg4v2", | |
| 2802 CODEC_TYPE_VIDEO, | |
| 2803 CODEC_ID_MSMPEG4V2, | |
| 2804 sizeof(MpegEncContext), | |
| 2805 MPV_encode_init, | |
| 2806 MPV_encode_picture, | |
| 2807 MPV_encode_end, | |
| 2808 }; | |
| 2809 | |
| 2810 AVCodec msmpeg4v3_encoder = { | |
| 2811 "msmpeg4", | |
| 2812 CODEC_TYPE_VIDEO, | |
| 2813 CODEC_ID_MSMPEG4V3, | |
| 2814 sizeof(MpegEncContext), | |
| 2815 MPV_encode_init, | |
| 2816 MPV_encode_picture, | |
| 2817 MPV_encode_end, | |
| 2818 }; | |
| 499 | 2819 |
| 2820 AVCodec wmv1_encoder = { | |
| 2821 "wmv1", | |
| 2822 CODEC_TYPE_VIDEO, | |
| 2823 CODEC_ID_WMV1, | |
| 2824 sizeof(MpegEncContext), | |
| 2825 MPV_encode_init, | |
| 2826 MPV_encode_picture, | |
| 2827 MPV_encode_end, | |
| 2828 }; | |
| 2829 | |
| 2830 AVCodec wmv2_encoder = { | |
| 2831 "wmv2", | |
| 2832 CODEC_TYPE_VIDEO, | |
| 2833 CODEC_ID_WMV2, | |
| 2834 sizeof(MpegEncContext), | |
| 2835 MPV_encode_init, | |
| 2836 MPV_encode_picture, | |
| 2837 MPV_encode_end, | |
| 2838 }; |
