Mercurial > libavcodec.hg
comparison mpegvideo.c @ 1892:5ac49e7a1b8f libavcodec
init cleanup
author | michael |
---|---|
date | Tue, 16 Mar 2004 16:11:29 +0000 |
parents | 6588eda7d107 |
children | 3135de68d556 |
comparison
equal
deleted
inserted
replaced
1891:f403b3e286b3 | 1892:5ac49e7a1b8f |
---|---|
500 COPY(progressive_frame); //FIXME dont set in encode_header | 500 COPY(progressive_frame); //FIXME dont set in encode_header |
501 COPY(partitioned_frame); //FIXME dont set in encode_header | 501 COPY(partitioned_frame); //FIXME dont set in encode_header |
502 #undef COPY | 502 #undef COPY |
503 } | 503 } |
504 | 504 |
505 /* init common structure for both encoder and decoder */ | 505 /** |
506 * sets the given MpegEncContext to common defaults (same for encoding and decoding). | |
507 * the changed fields will not depend upon the prior state of the MpegEncContext. | |
508 */ | |
509 static void MPV_common_defaults(MpegEncContext *s){ | |
510 s->y_dc_scale_table= | |
511 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
512 s->chroma_qscale_table= ff_default_chroma_qscale_table; | |
513 s->progressive_frame= 1; | |
514 s->progressive_sequence= 1; | |
515 s->picture_structure= PICT_FRAME; | |
516 | |
517 s->coded_picture_number = 0; | |
518 s->picture_number = 0; | |
519 s->input_picture_number = 0; | |
520 | |
521 s->picture_in_gop_number = 0; | |
522 } | |
523 | |
524 /** | |
525 * sets the given MpegEncContext to defaults for decoding. | |
526 * the changed fields will not depend upon the prior state of the MpegEncContext. | |
527 */ | |
528 void MPV_decode_defaults(MpegEncContext *s){ | |
529 MPV_common_defaults(s); | |
530 } | |
531 | |
532 /** | |
533 * sets the given MpegEncContext to defaults for encoding. | |
534 * the changed fields will not depend upon the prior state of the MpegEncContext. | |
535 */ | |
536 void MPV_encode_defaults(MpegEncContext *s){ | |
537 static int done=0; | |
538 | |
539 MPV_common_defaults(s); | |
540 | |
541 if(!done){ | |
542 int i; | |
543 done=1; | |
544 | |
545 default_mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) ); | |
546 memset(default_mv_penalty, 0, sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1)); | |
547 memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1)); | |
548 | |
549 for(i=-16; i<16; i++){ | |
550 default_fcode_tab[i + MAX_MV]= 1; | |
551 } | |
552 } | |
553 s->me.mv_penalty= default_mv_penalty; | |
554 s->fcode_tab= default_fcode_tab; | |
555 } | |
556 | |
557 /** | |
558 * init common structure for both encoder and decoder. | |
559 * this assumes that some variables like width/height are already set | |
560 */ | |
506 int MPV_common_init(MpegEncContext *s) | 561 int MPV_common_init(MpegEncContext *s) |
507 { | 562 { |
508 int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y; | 563 int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y; |
509 | 564 |
510 dsputil_init(&s->dsp, s->avctx); | 565 dsputil_init(&s->dsp, s->avctx); |
531 s->block_wrap[1]= | 586 s->block_wrap[1]= |
532 s->block_wrap[2]= | 587 s->block_wrap[2]= |
533 s->block_wrap[3]= s->mb_width*2 + 2; | 588 s->block_wrap[3]= s->mb_width*2 + 2; |
534 s->block_wrap[4]= | 589 s->block_wrap[4]= |
535 s->block_wrap[5]= s->mb_width + 2; | 590 s->block_wrap[5]= s->mb_width + 2; |
536 | 591 |
537 s->y_dc_scale_table= | |
538 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
539 s->chroma_qscale_table= ff_default_chroma_qscale_table; | |
540 if( s->codec_id != CODEC_ID_MPEG1VIDEO && | |
541 s->codec_id != CODEC_ID_MPEG2VIDEO) | |
542 { | |
543 /* default structure is frame */ | |
544 s->progressive_frame= 1; | |
545 s->picture_structure= PICT_FRAME; | |
546 | |
547 s->y_dc_scale_table= | |
548 s->c_dc_scale_table= ff_mpeg1_dc_scale_table; | |
549 if (!s->encoding) | |
550 s->progressive_sequence= 1; | |
551 } | |
552 s->coded_picture_number = 0; | |
553 | |
554 y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); | 592 y_size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2); |
555 c_size = (s->mb_width + 2) * (s->mb_height + 2); | 593 c_size = (s->mb_width + 2) * (s->mb_height + 2); |
556 yc_size = y_size + 2 * c_size; | 594 yc_size = y_size + 2 * c_size; |
557 | 595 |
558 /* convert fourcc to upper case */ | 596 /* convert fourcc to upper case */ |
559 s->avctx->codec_tag= toupper( s->avctx->codec_tag &0xFF) | 597 s->avctx->codec_tag= toupper( s->avctx->codec_tag &0xFF) |
560 + (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 ) | 598 + (toupper((s->avctx->codec_tag>>8 )&0xFF)<<8 ) |
561 + (toupper((s->avctx->codec_tag>>16)&0xFF)<<16) | 599 + (toupper((s->avctx->codec_tag>>16)&0xFF)<<16) |
562 + (toupper((s->avctx->codec_tag>>24)&0xFF)<<24); | 600 + (toupper((s->avctx->codec_tag>>24)&0xFF)<<24); |
660 } | 698 } |
661 | 699 |
662 /* which mb is a intra block */ | 700 /* which mb is a intra block */ |
663 CHECKED_ALLOCZ(s->mbintra_table, mb_array_size); | 701 CHECKED_ALLOCZ(s->mbintra_table, mb_array_size); |
664 memset(s->mbintra_table, 1, mb_array_size); | 702 memset(s->mbintra_table, 1, mb_array_size); |
665 | |
666 /* default structure is frame */ | |
667 s->picture_structure = PICT_FRAME; | |
668 | 703 |
669 /* init macroblock skip table */ | 704 /* init macroblock skip table */ |
670 CHECKED_ALLOCZ(s->mbskip_table, mb_array_size+2); | 705 CHECKED_ALLOCZ(s->mbskip_table, mb_array_size+2); |
671 //Note the +1 is for a quicker mpeg4 slice_end detection | 706 //Note the +1 is for a quicker mpeg4 slice_end detection |
672 CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE); | 707 CHECKED_ALLOCZ(s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE); |
785 int MPV_encode_init(AVCodecContext *avctx) | 820 int MPV_encode_init(AVCodecContext *avctx) |
786 { | 821 { |
787 MpegEncContext *s = avctx->priv_data; | 822 MpegEncContext *s = avctx->priv_data; |
788 int i, dummy; | 823 int i, dummy; |
789 int chroma_h_shift, chroma_v_shift; | 824 int chroma_h_shift, chroma_v_shift; |
825 | |
826 MPV_encode_defaults(s); | |
790 | 827 |
791 avctx->pix_fmt = PIX_FMT_YUV420P; // FIXME | 828 avctx->pix_fmt = PIX_FMT_YUV420P; // FIXME |
792 | 829 |
793 s->bit_rate = avctx->bit_rate; | 830 s->bit_rate = avctx->bit_rate; |
794 s->width = avctx->width; | 831 s->width = avctx->width; |
1068 #endif | 1105 #endif |
1069 default: | 1106 default: |
1070 return -1; | 1107 return -1; |
1071 } | 1108 } |
1072 | 1109 |
1073 { /* set up some save defaults, some codecs might override them later */ | |
1074 static int done=0; | |
1075 if(!done){ | |
1076 int i; | |
1077 done=1; | |
1078 | |
1079 default_mv_penalty= av_mallocz( sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1) ); | |
1080 memset(default_mv_penalty, 0, sizeof(uint8_t)*(MAX_FCODE+1)*(2*MAX_MV+1)); | |
1081 memset(default_fcode_tab , 0, sizeof(uint8_t)*(2*MAX_MV+1)); | |
1082 | |
1083 for(i=-16; i<16; i++){ | |
1084 default_fcode_tab[i + MAX_MV]= 1; | |
1085 } | |
1086 } | |
1087 } | |
1088 s->me.mv_penalty= default_mv_penalty; | |
1089 s->fcode_tab= default_fcode_tab; | |
1090 | |
1091 /* dont use mv_penalty table for crap MV as it would be confused */ | |
1092 //FIXME remove after fixing / removing old ME | |
1093 if (s->me_method < ME_EPZS) s->me.mv_penalty = default_mv_penalty; | |
1094 | |
1095 s->encoding = 1; | 1110 s->encoding = 1; |
1096 | 1111 |
1097 /* init */ | 1112 /* init */ |
1098 if (MPV_common_init(s) < 0) | 1113 if (MPV_common_init(s) < 0) |
1099 return -1; | 1114 return -1; |
1117 #endif | 1132 #endif |
1118 if (s->out_format == FMT_MPEG1) | 1133 if (s->out_format == FMT_MPEG1) |
1119 ff_mpeg1_encode_init(s); | 1134 ff_mpeg1_encode_init(s); |
1120 #endif | 1135 #endif |
1121 | 1136 |
1122 /* init default q matrix */ | 1137 /* init q matrix */ |
1123 for(i=0;i<64;i++) { | 1138 for(i=0;i<64;i++) { |
1124 int j= s->dsp.idct_permutation[i]; | 1139 int j= s->dsp.idct_permutation[i]; |
1125 #ifdef CONFIG_RISKY | 1140 #ifdef CONFIG_RISKY |
1126 if(s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){ | 1141 if(s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){ |
1127 s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i]; | 1142 s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i]; |
1151 } | 1166 } |
1152 | 1167 |
1153 if(ff_rate_control_init(s) < 0) | 1168 if(ff_rate_control_init(s) < 0) |
1154 return -1; | 1169 return -1; |
1155 | 1170 |
1156 s->picture_number = 0; | |
1157 s->input_picture_number = 0; | |
1158 s->picture_in_gop_number = 0; | |
1159 /* motion detector init */ | 1171 /* motion detector init */ |
1160 s->f_code = 1; | 1172 s->f_code = 1; |
1161 s->b_code = 1; | 1173 s->b_code = 1; |
1162 | 1174 |
1163 return 0; | 1175 return 0; |
1164 } | 1176 } |
1165 | 1177 |
1166 int MPV_encode_end(AVCodecContext *avctx) | 1178 int MPV_encode_end(AVCodecContext *avctx) |
1167 { | 1179 { |