comparison mpegvideo.c @ 2345:ada3891b859d libavcodec

H261 fixing and cleaning: -corrected wrong value in mv data -set correct mb_type after adjusting index -don't use H263 loop filter when the loop filter flag is set but when using the H261 encoder -use the same unquantizer as H263 (which is optimized btw) -removed unused members in H261Context patch by (Maarten Daniels <maarten.daniels >at< luc >dot< ac >dot< be>) regression test checksum update by me
author michael
date Fri, 12 Nov 2004 01:21:34 +0000
parents 5e5cf598a48b
children e0bda0b8359a
comparison
equal deleted inserted replaced
2344:f09680c5e8f4 2345:ada3891b859d
51 DCTELEM *block, int n, int qscale); 51 DCTELEM *block, int n, int qscale);
52 static void dct_unquantize_h263_intra_c(MpegEncContext *s, 52 static void dct_unquantize_h263_intra_c(MpegEncContext *s,
53 DCTELEM *block, int n, int qscale); 53 DCTELEM *block, int n, int qscale);
54 static void dct_unquantize_h263_inter_c(MpegEncContext *s, 54 static void dct_unquantize_h263_inter_c(MpegEncContext *s,
55 DCTELEM *block, int n, int qscale); 55 DCTELEM *block, int n, int qscale);
56 static void dct_unquantize_h261_intra_c(MpegEncContext *s,
57 DCTELEM *block, int n, int qscale);
58 static void dct_unquantize_h261_inter_c(MpegEncContext *s,
59 DCTELEM *block, int n, int qscale);
60 static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w); 56 static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w);
61 #ifdef CONFIG_ENCODERS 57 #ifdef CONFIG_ENCODERS
62 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); 58 static int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
63 static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); 59 static int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
64 static int dct_quantize_refine(MpegEncContext *s, DCTELEM *block, int16_t *weight, DCTELEM *orig, int n, int qscale); 60 static int dct_quantize_refine(MpegEncContext *s, DCTELEM *block, int16_t *weight, DCTELEM *orig, int n, int qscale);
217 /* init common dct for both encoder and decoder */ 213 /* init common dct for both encoder and decoder */
218 int DCT_common_init(MpegEncContext *s) 214 int DCT_common_init(MpegEncContext *s)
219 { 215 {
220 s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c; 216 s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c;
221 s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c; 217 s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c;
222 s->dct_unquantize_h261_intra = dct_unquantize_h261_intra_c;
223 s->dct_unquantize_h261_inter = dct_unquantize_h261_inter_c;
224 s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c; 218 s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c;
225 s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c; 219 s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c;
226 s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c; 220 s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c;
227 s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c; 221 s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c;
228 222
1480 /* set dequantizer, we cant do it during init as it might change for mpeg4 1474 /* set dequantizer, we cant do it during init as it might change for mpeg4
1481 and we cant do it in the header decode as init isnt called for mpeg4 there yet */ 1475 and we cant do it in the header decode as init isnt called for mpeg4 there yet */
1482 if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO){ 1476 if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO){
1483 s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra; 1477 s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;
1484 s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter; 1478 s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;
1485 }else if(s->out_format == FMT_H263){ 1479 }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){
1486 s->dct_unquantize_intra = s->dct_unquantize_h263_intra; 1480 s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
1487 s->dct_unquantize_inter = s->dct_unquantize_h263_inter; 1481 s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
1488 }else if(s->out_format == FMT_H261){
1489 s->dct_unquantize_intra = s->dct_unquantize_h261_intra;
1490 s->dct_unquantize_inter = s->dct_unquantize_h261_inter;
1491 }else{ 1482 }else{
1492 s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra; 1483 s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra;
1493 s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter; 1484 s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
1494 } 1485 }
1495 1486
4515 ff_update_block_index(s); 4506 ff_update_block_index(s);
4516 4507
4517 if(s->codec_id == CODEC_ID_H261){ 4508 if(s->codec_id == CODEC_ID_H261){
4518 ff_h261_reorder_mb_index(s); 4509 ff_h261_reorder_mb_index(s);
4519 xy= s->mb_y*s->mb_stride + s->mb_x; 4510 xy= s->mb_y*s->mb_stride + s->mb_x;
4511 mb_type= s->mb_type[xy];
4520 } 4512 }
4521 4513
4522 /* write gob / video packet header */ 4514 /* write gob / video packet header */
4523 #ifdef CONFIG_RISKY 4515 #ifdef CONFIG_RISKY
4524 if(s->rtp_mode){ 4516 if(s->rtp_mode){
4988 s->dest[1], w>>1, h>>1, s->uvlinesize); 4980 s->dest[1], w>>1, h>>1, s->uvlinesize);
4989 s->current_picture_ptr->error[2] += sse( 4981 s->current_picture_ptr->error[2] += sse(
4990 s, s->new_picture .data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8, 4982 s, s->new_picture .data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,
4991 s->dest[2], w>>1, h>>1, s->uvlinesize); 4983 s->dest[2], w>>1, h>>1, s->uvlinesize);
4992 } 4984 }
4993 if(s->loop_filter) 4985 if(s->loop_filter){
4994 ff_h263_loop_filter(s); 4986 if(s->out_format == FMT_H263)
4987 ff_h263_loop_filter(s);
4988 }
4995 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_stride, put_bits_count(&s->pb)); 4989 //printf("MB %d %d bits\n", s->mb_x+s->mb_y*s->mb_stride, put_bits_count(&s->pb));
4996 } 4990 }
4997 } 4991 }
4998 4992
4999 #ifdef CONFIG_RISKY 4993 #ifdef CONFIG_RISKY
6245 } else { 6239 } else {
6246 level = level * qmul + qadd; 6240 level = level * qmul + qadd;
6247 } 6241 }
6248 block[i] = level; 6242 block[i] = level;
6249 } 6243 }
6250 }
6251 }
6252
6253 static void dct_unquantize_h261_intra_c(MpegEncContext *s,
6254 DCTELEM *block, int n, int qscale)
6255 {
6256 int i, level, even;
6257 int nCoeffs;
6258
6259 assert(s->block_last_index[n]>=0);
6260
6261 if (n < 4)
6262 block[0] = block[0] * s->y_dc_scale;
6263 else
6264 block[0] = block[0] * s->c_dc_scale;
6265 even = (qscale & 1)^1;
6266 nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
6267
6268 for(i=1; i<=nCoeffs; i++){
6269 level = block[i];
6270 if (level){
6271 if (level < 0){
6272 level = qscale * ((level << 1) - 1) + even;
6273 }else{
6274 level = qscale * ((level << 1) + 1) - even;
6275 }
6276 }
6277 block[i] = level;
6278 }
6279 }
6280
6281 static void dct_unquantize_h261_inter_c(MpegEncContext *s,
6282 DCTELEM *block, int n, int qscale)
6283 {
6284 int i, level, even;
6285 int nCoeffs;
6286
6287 assert(s->block_last_index[n]>=0);
6288
6289 even = (qscale & 1)^1;
6290
6291 nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
6292
6293 for(i=0; i<=nCoeffs; i++){
6294 level = block[i];
6295 if (level){
6296 if (level < 0){
6297 level = qscale * ((level << 1) - 1) + even;
6298 }else{
6299 level = qscale * ((level << 1) + 1) - even;
6300 }
6301 }
6302 block[i] = level;
6303 } 6244 }
6304 } 6245 }
6305 6246
6306 static const AVOption mpeg4_options[] = 6247 static const AVOption mpeg4_options[] =
6307 { 6248 {