📄 vc9.c
字号:
vc9_norm2_bits, 1, 1, vc9_norm2_codes, 1, 1, 1); INIT_VLC(&vc9_norm6_vlc, VC9_NORM6_VLC_BITS, 64, vc9_norm6_bits, 1, 1, vc9_norm6_codes, 2, 2, 1); INIT_VLC(&vc9_imode_vlc, VC9_IMODE_VLC_BITS, 7, vc9_imode_bits, 1, 1, vc9_imode_codes, 1, 1, 1); for (i=0; i<3; i++) { INIT_VLC(&vc9_ttmb_vlc[i], VC9_TTMB_VLC_BITS, 16, vc9_ttmb_bits[i], 1, 1, vc9_ttmb_codes[i], 2, 2, 1); INIT_VLC(&vc9_ttblk_vlc[i], VC9_TTBLK_VLC_BITS, 8, vc9_ttblk_bits[i], 1, 1, vc9_ttblk_codes[i], 1, 1, 1); INIT_VLC(&vc9_subblkpat_vlc[i], VC9_SUBBLKPAT_VLC_BITS, 15, vc9_subblkpat_bits[i], 1, 1, vc9_subblkpat_codes[i], 1, 1, 1); } for(i=0; i<4; i++) { INIT_VLC(&vc9_4mv_block_pattern_vlc[i], VC9_4MV_BLOCK_PATTERN_VLC_BITS, 16, vc9_4mv_block_pattern_bits[i], 1, 1, vc9_4mv_block_pattern_codes[i], 1, 1, 1); INIT_VLC(&vc9_cbpcy_p_vlc[i], VC9_CBPCY_P_VLC_BITS, 64, vc9_cbpcy_p_bits[i], 1, 1, vc9_cbpcy_p_codes[i], 2, 2, 1); INIT_VLC(&vc9_mv_diff_vlc[i], VC9_MV_DIFF_VLC_BITS, 73, vc9_mv_diff_bits[i], 1, 1, vc9_mv_diff_codes[i], 2, 2, 1); } } /* Other defaults */ v->pq = -1; v->mvrange = 0; /* 7.1.1.18, p80 */ return 0;}#if HAS_ADVANCED_PROFILE/** * Decode sequence header's Hypothetic Reference Decoder data * @see 6.2.1, p32 * @param v The VC9Context to initialize * @param gb A GetBitContext initialized from AVCodecContext extra_data * @return Status */static int decode_hrd(VC9Context *v, GetBitContext *gb){ int i, num; num = 1 + get_bits(gb, 5); /*hrd rate*/ if (v->hrd_rate || num != v->hrd_num_leaky_buckets) { av_freep(&v->hrd_rate); } if (!v->hrd_rate) v->hrd_rate = av_malloc(num*sizeof(uint16_t)); if (!v->hrd_rate) return -1; /*hrd buffer*/ if (v->hrd_buffer || num != v->hrd_num_leaky_buckets) { av_freep(&v->hrd_buffer); } if (!v->hrd_buffer) v->hrd_buffer = av_malloc(num*sizeof(uint16_t)); if (!v->hrd_buffer) { av_freep(&v->hrd_rate); return -1; } /*hrd fullness*/ if (v->hrd_fullness || num != v->hrd_num_leaky_buckets) { av_freep(&v->hrd_buffer); } if (!v->hrd_fullness) v->hrd_fullness = av_malloc(num*sizeof(uint8_t)); if (!v->hrd_fullness) { av_freep(&v->hrd_rate); av_freep(&v->hrd_buffer); return -1; } v->hrd_num_leaky_buckets = num; //exponent in base-2 for rate v->bit_rate_exponent = 6 + get_bits(gb, 4); //exponent in base-2 for buffer_size v->buffer_size_exponent = 4 + get_bits(gb, 4); for (i=0; i<num; i++) { //mantissae, ordered (if not, use a function ? v->hrd_rate[i] = 1 + get_bits(gb, 16); if (i && v->hrd_rate[i-1]>=v->hrd_rate[i]) { av_log(v->s.avctx, AV_LOG_ERROR, "HDR Rates aren't strictly increasing:" "%i vs %i\n", v->hrd_rate[i-1], v->hrd_rate[i]); return -1; } v->hrd_buffer[i] = 1 + get_bits(gb, 16); if (i && v->hrd_buffer[i-1]<v->hrd_buffer[i]) { av_log(v->s.avctx, AV_LOG_ERROR, "HDR Buffers aren't decreasing:" "%i vs %i\n", v->hrd_buffer[i-1], v->hrd_buffer[i]); return -1; } } return 0;}/** * Decode sequence header for Advanced Profile * @see Table 2, p18 * @see 6.1.7, pp21-27 * @param v The VC9Context to initialize * @param gb A GetBitContext initialized from AVCodecContext extra_data * @return Status */static int decode_advanced_sequence_header(AVCodecContext *avctx, GetBitContext *gb){ VC9Context *v = avctx->priv_data; int nr, dr, aspect_ratio; v->postprocflag = get_bits(gb, 1); v->broadcast = get_bits(gb, 1); v->interlace = get_bits(gb, 1); v->tfcntrflag = get_bits(gb, 1); v->finterpflag = get_bits(gb, 1); //common v->panscanflag = get_bits(gb, 1); v->reserved = get_bits(gb, 1); if (v->reserved) { av_log(avctx, AV_LOG_ERROR, "RESERVED should be 0 (is %i)\n", v->reserved); return -1; } if (v->extended_mv) v->extended_dmv = get_bits(gb, 1); /* 6.1.7, p21 */ if (get_bits(gb, 1) /* pic_size_flag */) { avctx->coded_width = get_bits(gb, 12) << 1; avctx->coded_height = get_bits(gb, 12) << 1; if ( get_bits(gb, 1) /* disp_size_flag */) { avctx->width = get_bits(gb, 14); avctx->height = get_bits(gb, 14); } /* 6.1.7.4, p23 */ if ( get_bits(gb, 1) /* aspect_ratio_flag */) { aspect_ratio = get_bits(gb, 4); //SAR if (aspect_ratio == 0x0F) //FF_ASPECT_EXTENDED { avctx->sample_aspect_ratio.num = 1 + get_bits(gb, 8); avctx->sample_aspect_ratio.den = 1 + get_bits(gb, 8); } else if (aspect_ratio == 0x0E) { av_log(avctx, AV_LOG_DEBUG, "Reserved AR found\n"); } else { avctx->sample_aspect_ratio = vc9_pixel_aspect[aspect_ratio]; } } } else { avctx->coded_width = avctx->width; avctx->coded_height = avctx->height; } /* 6.1.8, p23 */ if ( get_bits(gb, 1) /* framerateflag */) { if ( !get_bits(gb, 1) /* framerateind */) { nr = get_bits(gb, 8); dr = get_bits(gb, 4); if (nr<1) { av_log(avctx, AV_LOG_ERROR, "0 is forbidden for FRAMERATENR\n"); return -1; } if (nr>5) { av_log(avctx, AV_LOG_ERROR, "Reserved FRAMERATENR %i not handled\n", nr); nr = 5; /* overflow protection */ } if (dr<1) { av_log(avctx, AV_LOG_ERROR, "0 is forbidden for FRAMERATEDR\n"); return -1; } if (dr>2) { av_log(avctx, AV_LOG_ERROR, "Reserved FRAMERATEDR %i not handled\n", dr); dr = 2; /* overflow protection */ } avctx->time_base.num = fps_nr[dr - 1]; avctx->time_base.den = fps_nr[nr - 1]; } else { nr = get_bits(gb, 16); // 0.03125->2048Hz / 0.03125Hz avctx->time_base.den = 1000000; avctx->time_base.num = 31250*(1+nr); } } /* 6.1.9, p25 */ if ( get_bits(gb, 1) /* color_format_flag */) { //Chromacity coordinates of color primaries //like ITU-R BT.709-2, BT.470-2, ... v->color_prim = get_bits(gb, 8); if (v->color_prim<1) { av_log(avctx, AV_LOG_ERROR, "0 for COLOR_PRIM is forbidden\n"); return -1; } if (v->color_prim == 3 || v->color_prim>6) { av_log(avctx, AV_LOG_DEBUG, "Reserved COLOR_PRIM %i found\n", v->color_prim); return -1; } //Opto-electronic transfer characteristics v->transfer_char = get_bits(gb, 8); if (v->transfer_char < 1) { av_log(avctx, AV_LOG_ERROR, "0 for TRAMSFER_CHAR is forbidden\n"); return -1; } if (v->transfer_char == 3 || v->transfer_char>8) { av_log(avctx, AV_LOG_DEBUG, "Reserved TRANSFERT_CHAR %i found\n", v->color_prim); return -1; } //Matrix coefficient for primariev->YCbCr v->matrix_coef = get_bits(gb, 8); if (v->matrix_coef < 1) { av_log(avctx, AV_LOG_ERROR, "0 for MATRIX_COEF is forbidden\n"); return -1; } if ((v->matrix_coef > 2 && v->matrix_coef < 6) || v->matrix_coef > 7) { av_log(avctx, AV_LOG_DEBUG, "Reserved MATRIX_COEF %i found\n", v->color_prim); return -1; } } //Hypothetical reference decoder indicator flag v->hrd_param_flag = get_bits(gb, 1); if (v->hrd_param_flag) { if (decode_hrd(v, gb) < 0) return -1; } /*reset scaling ranges, 6.2.2 & 6.2.3, p33*/ v->range_mapy_flag = 0; v->range_mapuv_flag = 0; av_log(avctx, AV_LOG_DEBUG, "Advanced profile not supported yet\n"); return -1;}#endif/** * Decode Simple/Main Profiles sequence header * @see Figure 7-8, p16-17 * @param avctx Codec context * @param gb GetBit context initialized from Codec context extra_data * @return Status */static int decode_sequence_header(AVCodecContext *avctx, GetBitContext *gb){ VC9Context *v = avctx->priv_data; av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32)); v->profile = get_bits(gb, 2); if (v->profile == 2) { av_log(avctx, AV_LOG_ERROR, "Profile value 2 is forbidden\n"); return -1; }#if HAS_ADVANCED_PROFILE if (v->profile == PROFILE_ADVANCED) { v->level = get_bits(gb, 3); if(v->level >= 5) { av_log(avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level); } v->chromaformat = get_bits(gb, 2); if (v->chromaformat != 1) { av_log(avctx, AV_LOG_ERROR, "Only 4:2:0 chroma format supported\n"); return -1; } } else#endif { v->res_sm = get_bits(gb, 2); //reserved if (v->res_sm) { av_log(avctx, AV_LOG_ERROR, "Reserved RES_SM=%i is forbidden\n", v->res_sm); return -1; } } // (fps-2)/4 (->30) v->frmrtq_postproc = get_bits(gb, 3); //common // (bitrate-32kbps)/64kbps v->bitrtq_postproc = get_bits(gb, 5); //common v->s.loop_filter = get_bits(gb, 1); //common if(v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE) { av_log(avctx, AV_LOG_ERROR, "LOOPFILTER shell not be enabled in simple profile\n"); }#if HAS_ADVANCED_PROFILE if (v->profile < PROFILE_ADVANCED)#endif { v->res_x8 = get_bits(gb, 1); //reserved if (v->res_x8) { av_log(avctx, AV_LOG_ERROR, "1 for reserved RES_X8 is forbidden\n"); //return -1; } v->multires = get_bits(gb, 1); v->res_fasttx = get_bits(gb, 1); if (!v->res_fasttx) { av_log(avctx, AV_LOG_ERROR, "0 for reserved RES_FASTTX is forbidden\n"); //return -1; } } v->fastuvmc = get_bits(gb, 1); //common if (!v->profile && !v->fastuvmc) { av_log(avctx, AV_LOG_ERROR, "FASTUVMC unavailable in Simple Profile\n"); return -1; } v->extended_mv = get_bits(gb, 1); //common if (!v->profile && v->extended_mv) { av_log(avctx, AV_LOG_ERROR, "Extended MVs unavailable in Simple Profile\n"); return -1; } v->dquant = get_bits(gb, 2); //common v->vstransform = get_bits(gb, 1); //common#if HAS_ADVANCED_PROFILE if (v->profile < PROFILE_ADVANCED)#endif { v->res_transtab = get_bits(gb, 1); if (v->res_transtab) { av_log(avctx, AV_LOG_ERROR, "1 for reserved RES_TRANSTAB is forbidden\n"); return -1; } } v->overlap = get_bits(gb, 1); //common#if HAS_ADVANCED_PROFILE if (v->profile < PROFILE_ADVANCED)#endif { v->s.resync_marker = get_bits(gb, 1); v->rangered = get_bits(gb, 1); if (v->rangered && v->profile == PROFILE_SIMPLE) { av_log(avctx, AV_LOG_DEBUG, "RANGERED should be set to 0 in simple profile\n"); } } v->s.max_b_frames = avctx->max_b_frames = get_bits(gb, 3); //common v->quantizer_mode = get_bits(gb, 2); //common#if HAS_ADVANCED_PROFILE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -