comparison vc1.c @ 9732:c25359a56edf libavcodec

set pict_type in VC-1 parser, fix some timestamps problems
author bcoudurier
date Sat, 30 May 2009 00:09:00 +0000
parents 3a8dfce3dc17
children 67f917b48068
comparison
equal deleted inserted replaced
9731:5b1b3c4a1f17 9732:c25359a56edf
803 * @see Figure 7-8, p16-17 803 * @see Figure 7-8, p16-17
804 * @param avctx Codec context 804 * @param avctx Codec context
805 * @param gb GetBit context initialized from Codec context extra_data 805 * @param gb GetBit context initialized from Codec context extra_data
806 * @return Status 806 * @return Status
807 */ 807 */
808 static int decode_sequence_header(AVCodecContext *avctx, GetBitContext *gb) 808 int vc1_decode_sequence_header(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
809 { 809 {
810 VC1Context *v = avctx->priv_data;
811
812 av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32)); 810 av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32));
813 v->profile = get_bits(gb, 2); 811 v->profile = get_bits(gb, 2);
814 if (v->profile == PROFILE_COMPLEX) 812 if (v->profile == PROFILE_COMPLEX)
815 { 813 {
816 av_log(avctx, AV_LOG_ERROR, "WMV3 Complex Profile is not fully supported\n"); 814 av_log(avctx, AV_LOG_ERROR, "WMV3 Complex Profile is not fully supported\n");
1023 } 1021 }
1024 } 1022 }
1025 return 0; 1023 return 0;
1026 } 1024 }
1027 1025
1028 static int decode_entry_point(AVCodecContext *avctx, GetBitContext *gb) 1026 int vc1_decode_entry_point(AVCodecContext *avctx, VC1Context *v, GetBitContext *gb)
1029 { 1027 {
1030 VC1Context *v = avctx->priv_data;
1031 int i; 1028 int i;
1032 1029
1033 av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32)); 1030 av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32));
1034 v->broken_link = get_bits1(gb); 1031 v->broken_link = get_bits1(gb);
1035 v->closed_entry = get_bits1(gb); 1032 v->closed_entry = get_bits1(gb);
1072 v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode); 1069 v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode);
1073 1070
1074 return 0; 1071 return 0;
1075 } 1072 }
1076 1073
1077 static int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb) 1074 int vc1_parse_frame_header(VC1Context *v, GetBitContext* gb)
1078 { 1075 {
1079 int pqindex, lowquant, status; 1076 int pqindex, lowquant, status;
1080 1077
1081 if(v->finterpflag) v->interpfrm = get_bits1(gb); 1078 if(v->finterpflag) v->interpfrm = get_bits1(gb);
1082 skip_bits(gb, 2); //framecnt unused 1079 skip_bits(gb, 2); //framecnt unused
1098 v->s.pict_type = FF_BI_TYPE; 1095 v->s.pict_type = FF_BI_TYPE;
1099 } 1096 }
1100 } 1097 }
1101 if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE) 1098 if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)
1102 skip_bits(gb, 7); // skip buffer fullness 1099 skip_bits(gb, 7); // skip buffer fullness
1100
1101 if(v->parse_only)
1102 return 0;
1103 1103
1104 /* calculate RND */ 1104 /* calculate RND */
1105 if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE) 1105 if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)
1106 v->rnd = 1; 1106 v->rnd = 1;
1107 if(v->s.pict_type == FF_P_TYPE) 1107 if(v->s.pict_type == FF_P_TYPE)
1284 v->bi_type = 1; 1284 v->bi_type = 1;
1285 } 1285 }
1286 return 0; 1286 return 0;
1287 } 1287 }
1288 1288
1289 static int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) 1289 int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb)
1290 { 1290 {
1291 int pqindex, lowquant; 1291 int pqindex, lowquant;
1292 int status; 1292 int status;
1293 1293
1294 v->p_frame_skipped = 0; 1294 v->p_frame_skipped = 0;
1359 v->pquantizer = get_bits1(gb); 1359 v->pquantizer = get_bits1(gb);
1360 if(v->postprocflag) 1360 if(v->postprocflag)
1361 v->postproc = get_bits(gb, 2); 1361 v->postproc = get_bits(gb, 2);
1362 1362
1363 if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_P_TYPE) v->use_ic = 0; 1363 if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_P_TYPE) v->use_ic = 0;
1364
1365 if(v->parse_only)
1366 return 0;
1364 1367
1365 switch(v->s.pict_type) { 1368 switch(v->s.pict_type) {
1366 case FF_I_TYPE: 1369 case FF_I_TYPE:
1367 case FF_BI_TYPE: 1370 case FF_BI_TYPE:
1368 status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v); 1371 status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v);
3913 break; 3916 break;
3914 } 3917 }
3915 } 3918 }
3916 } 3919 }
3917 3920
3918 /** Find VC-1 marker in buffer
3919 * @return position where next marker starts or end of buffer if no marker found
3920 */
3921 static av_always_inline const uint8_t* find_next_marker(const uint8_t *src, const uint8_t *end)
3922 {
3923 uint32_t mrk = 0xFFFFFFFF;
3924
3925 if(end-src < 4) return end;
3926 while(src < end){
3927 mrk = (mrk << 8) | *src++;
3928 if(IS_MARKER(mrk))
3929 return src-4;
3930 }
3931 return end;
3932 }
3933
3934 static av_always_inline int vc1_unescape_buffer(const uint8_t *src, int size, uint8_t *dst)
3935 {
3936 int dsize = 0, i;
3937
3938 if(size < 4){
3939 for(dsize = 0; dsize < size; dsize++) *dst++ = *src++;
3940 return size;
3941 }
3942 for(i = 0; i < size; i++, src++) {
3943 if(src[0] == 3 && i >= 2 && !src[-1] && !src[-2] && i < size-1 && src[1] < 4) {
3944 dst[dsize++] = src[1];
3945 src++;
3946 i++;
3947 } else
3948 dst[dsize++] = *src;
3949 }
3950 return dsize;
3951 }
3952
3953 /** Initialize a VC1/WMV3 decoder 3921 /** Initialize a VC1/WMV3 decoder
3954 * @todo TODO: Handle VC-1 IDUs (Transport level?) 3922 * @todo TODO: Handle VC-1 IDUs (Transport level?)
3955 * @todo TODO: Decypher remaining bits in extra_data 3923 * @todo TODO: Decypher remaining bits in extra_data
3956 */ 3924 */
3957 static av_cold int vc1_decode_init(AVCodecContext *avctx) 3925 static av_cold int vc1_decode_init(AVCodecContext *avctx)
3989 // the last byte of the extradata is a version number, 1 for the 3957 // the last byte of the extradata is a version number, 1 for the
3990 // samples we can decode 3958 // samples we can decode
3991 3959
3992 init_get_bits(&gb, avctx->extradata, avctx->extradata_size*8); 3960 init_get_bits(&gb, avctx->extradata, avctx->extradata_size*8);
3993 3961
3994 if (decode_sequence_header(avctx, &gb) < 0) 3962 if (vc1_decode_sequence_header(avctx, v, &gb) < 0)
3995 return -1; 3963 return -1;
3996 3964
3997 count = avctx->extradata_size*8 - get_bits_count(&gb); 3965 count = avctx->extradata_size*8 - get_bits_count(&gb);
3998 if (count>0) 3966 if (count>0)
3999 { 3967 {
4026 if(size <= 0) continue; 3994 if(size <= 0) continue;
4027 buf2_size = vc1_unescape_buffer(start + 4, size, buf2); 3995 buf2_size = vc1_unescape_buffer(start + 4, size, buf2);
4028 init_get_bits(&gb, buf2, buf2_size * 8); 3996 init_get_bits(&gb, buf2, buf2_size * 8);
4029 switch(AV_RB32(start)){ 3997 switch(AV_RB32(start)){
4030 case VC1_CODE_SEQHDR: 3998 case VC1_CODE_SEQHDR:
4031 if(decode_sequence_header(avctx, &gb) < 0){ 3999 if(vc1_decode_sequence_header(avctx, v, &gb) < 0){
4032 av_free(buf2); 4000 av_free(buf2);
4033 return -1; 4001 return -1;
4034 } 4002 }
4035 seq_initialized = 1; 4003 seq_initialized = 1;
4036 break; 4004 break;
4037 case VC1_CODE_ENTRYPOINT: 4005 case VC1_CODE_ENTRYPOINT:
4038 if(decode_entry_point(avctx, &gb) < 0){ 4006 if(vc1_decode_entry_point(avctx, v, &gb) < 0){
4039 av_free(buf2); 4007 av_free(buf2);
4040 return -1; 4008 return -1;
4041 } 4009 }
4042 ep_initialized = 1; 4010 ep_initialized = 1;
4043 break; 4011 break;
4148 buf_size2 = vc1_unescape_buffer(start + 4, size, buf2); 4116 buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
4149 break; 4117 break;
4150 case VC1_CODE_ENTRYPOINT: /* it should be before frame data */ 4118 case VC1_CODE_ENTRYPOINT: /* it should be before frame data */
4151 buf_size2 = vc1_unescape_buffer(start + 4, size, buf2); 4119 buf_size2 = vc1_unescape_buffer(start + 4, size, buf2);
4152 init_get_bits(&s->gb, buf2, buf_size2*8); 4120 init_get_bits(&s->gb, buf2, buf_size2*8);
4153 decode_entry_point(avctx, &s->gb); 4121 vc1_decode_entry_point(avctx, v, &s->gb);
4154 break; 4122 break;
4155 case VC1_CODE_SLICE: 4123 case VC1_CODE_SLICE:
4156 av_log(avctx, AV_LOG_ERROR, "Sliced decoding is not implemented (yet)\n"); 4124 av_log(avctx, AV_LOG_ERROR, "Sliced decoding is not implemented (yet)\n");
4157 av_free(buf2); 4125 av_free(buf2);
4158 return -1; 4126 return -1;