📄 mpeg12.c
字号:
} i += run; j = scantable[i]; if(level<0){ level= -level; level= ((level*2+1)*qscale*quant_matrix[j])>>4; level= (level-1)|1; level= -level; }else{ level= ((level*2+1)*qscale*quant_matrix[j])>>4; level= (level-1)|1; } } if (i > 63){ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } block[j] = level; } CLOSE_READER(re, &s->gb); } s->block_last_index[n] = i; return 0;}/* Also does unquantization here, since I will never support mpeg2 encoding */static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n){ int level, i, j, run; RLTable *rl = &rl_mpeg1; uint8_t * const scantable= s->intra_scantable.permutated; const uint16_t *quant_matrix; const int qscale= s->qscale; int mismatch; mismatch = 1; { int v; OPEN_READER(re, &s->gb); i = -1; if (n < 4) quant_matrix = s->inter_matrix; else quant_matrix = s->chroma_inter_matrix; /* special case for the first coef. no need to add a second vlc table */ UPDATE_CACHE(re, &s->gb); v= SHOW_UBITS(re, &s->gb, 2); if (v & 2) { LAST_SKIP_BITS(re, &s->gb, 2); level= (3*qscale*quant_matrix[0])>>5; if(v&1) level= -level; block[0] = level; mismatch ^= level; i++; } /* now quantify & encode AC coefs */ for(;;) { UPDATE_CACHE(re, &s->gb); GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2); if(level == 127){ break; } else if(level != 0) { i += run; j = scantable[i]; level= ((level*2+1)*qscale*quant_matrix[j])>>5; level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_BITS(re, &s->gb, 1); } else { /* escape */ run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); UPDATE_CACHE(re, &s->gb); level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); i += run; j = scantable[i]; if(level<0){ level= ((-level*2+1)*qscale*quant_matrix[j])>>5; level= -level; }else{ level= ((level*2+1)*qscale*quant_matrix[j])>>5; } } if (i > 63){ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } mismatch ^= level; block[j] = level; } CLOSE_READER(re, &s->gb); } block[63] ^= (mismatch & 1); s->block_last_index[n] = i; return 0;}static inline int mpeg2_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n){ int level, dc, diff, i, j, run; int component; RLTable *rl; uint8_t * const scantable= s->intra_scantable.permutated; const uint16_t *quant_matrix; const int qscale= s->qscale; int mismatch; /* DC coef */ if (n < 4){ quant_matrix = s->intra_matrix; component = 0; }else{ quant_matrix = s->chroma_intra_matrix; component = n - 3; } diff = decode_dc(&s->gb, component); if (diff >= 0xffff) return -1; dc = s->last_dc[component]; dc += diff; s->last_dc[component] = dc; block[0] = dc << (3 - s->intra_dc_precision); dprintf("dc=%d\n", block[0]); mismatch = block[0] ^ 1; i = 0; if (s->intra_vlc_format) rl = &rl_mpeg2; else rl = &rl_mpeg1; { OPEN_READER(re, &s->gb); /* now quantify & encode AC coefs */ for(;;) { UPDATE_CACHE(re, &s->gb); GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2); if(level == 127){ break; } else if(level != 0) { i += run; j = scantable[i]; level= (level*qscale*quant_matrix[j])>>4; level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_BITS(re, &s->gb, 1); } else { /* escape */ run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); UPDATE_CACHE(re, &s->gb); level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); i += run; j = scantable[i]; if(level<0){ level= (-level*qscale*quant_matrix[j])>>4; level= -level; }else{ level= (level*qscale*quant_matrix[j])>>4; } } if (i > 63){ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); return -1; } mismatch^= level; block[j] = level; } CLOSE_READER(re, &s->gb); } block[63]^= mismatch&1; s->block_last_index[n] = i; return 0;}typedef struct Mpeg1Context { MpegEncContext mpeg_enc_ctx; int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ int repeat_field; /* true if we must repeat the field */ AVPanScan pan_scan; /** some temporary storage for the panscan */} Mpeg1Context;static int mpeg_decode_init(AVCodecContext *avctx){ Mpeg1Context *s = avctx->priv_data; s->mpeg_enc_ctx.flags= avctx->flags; common_init(&s->mpeg_enc_ctx); init_vlcs(); s->mpeg_enc_ctx_allocated = 0; s->mpeg_enc_ctx.picture_number = 0; s->repeat_field = 0; s->mpeg_enc_ctx.codec_id= avctx->codec->id; return 0;}/* return the 8 bit start code value and update the search state. Return -1 if no start code found */static int find_start_code(uint8_t **pbuf_ptr, uint8_t *buf_end){ uint8_t *buf_ptr; unsigned int state=0xFFFFFFFF, v; int val; buf_ptr = *pbuf_ptr; while (buf_ptr < buf_end) { v = *buf_ptr++; if (state == 0x000001) { state = ((state << 8) | v) & 0xffffff; val = state; goto found; } state = ((state << 8) | v) & 0xffffff; } val = -1; found: *pbuf_ptr = buf_ptr; return val;}static int mpeg1_decode_picture(AVCodecContext *avctx, uint8_t *buf, int buf_size){ Mpeg1Context *s1 = avctx->priv_data; MpegEncContext *s = &s1->mpeg_enc_ctx; int ref, f_code; init_get_bits(&s->gb, buf, buf_size*8); ref = get_bits(&s->gb, 10); /* temporal ref */ s->pict_type = get_bits(&s->gb, 3); dprintf("pict_type=%d number=%d\n", s->pict_type, s->picture_number); skip_bits(&s->gb, 16); if (s->pict_type == P_TYPE || s->pict_type == B_TYPE) { s->full_pel[0] = get_bits1(&s->gb); f_code = get_bits(&s->gb, 3); if (f_code == 0) return -1; s->mpeg_f_code[0][0] = f_code; s->mpeg_f_code[0][1] = f_code; } if (s->pict_type == B_TYPE) { s->full_pel[1] = get_bits1(&s->gb); f_code = get_bits(&s->gb, 3); if (f_code == 0) return -1; s->mpeg_f_code[1][0] = f_code; s->mpeg_f_code[1][1] = f_code; } s->current_picture.pict_type= s->pict_type; s->current_picture.key_frame= s->pict_type == I_TYPE; s->y_dc_scale = 8; s->c_dc_scale = 8; s->first_slice = 1; return 0;}static void mpeg_decode_sequence_extension(MpegEncContext *s){ int horiz_size_ext, vert_size_ext; int bit_rate_ext, vbv_buf_ext; int frame_rate_ext_n, frame_rate_ext_d; int level, profile; skip_bits(&s->gb, 1); /* profil and level esc*/ profile= get_bits(&s->gb, 3); level= get_bits(&s->gb, 4); s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */ skip_bits(&s->gb, 2); /* chroma_format */ horiz_size_ext = get_bits(&s->gb, 2); vert_size_ext = get_bits(&s->gb, 2); s->width |= (horiz_size_ext << 12); s->height |= (vert_size_ext << 12); bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */ s->bit_rate = ((s->bit_rate / 400) | (bit_rate_ext << 12)) * 400; skip_bits1(&s->gb); /* marker */ vbv_buf_ext = get_bits(&s->gb, 8); s->low_delay = get_bits1(&s->gb); if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1; frame_rate_ext_n = get_bits(&s->gb, 2); frame_rate_ext_d = get_bits(&s->gb, 5); av_reduce( &s->avctx->frame_rate, &s->avctx->frame_rate_base, frame_rate_tab[s->frame_rate_index] * (frame_rate_ext_n+1), MPEG1_FRAME_RATE_BASE * (frame_rate_ext_d+1), 1<<30); dprintf("sequence extension\n"); s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO; s->avctx->sub_id = 2; /* indicates mpeg2 found */ if(s->aspect_ratio_info <= 1) s->avctx->sample_aspect_ratio= mpeg2_aspect[s->aspect_ratio_info]; else{ s->avctx->sample_aspect_ratio= av_div_q( mpeg2_aspect[s->aspect_ratio_info], (AVRational){s->width, s->height} ); } if(s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d \n", profile, level);}static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1){ MpegEncContext *s= &s1->mpeg_enc_ctx; int color_description, w, h; skip_bits(&s->gb, 3); /* video format */ color_description= get_bits1(&s->gb); if(color_description){ skip_bits(&s->gb, 8); /* color primaries */ skip_bits(&s->gb, 8); /* transfer_characteristics */ skip_bits(&s->gb, 8); /* matrix_coefficients */ } w= get_bits(&s->gb, 14); skip_bits(&s->gb, 1); //marker h= get_bits(&s->gb, 14); skip_bits(&s->gb, 1); //marker s1->pan_scan.width= 16*w; s1->pan_scan.height=16*h; if(s->aspect_ratio_info > 1) s->avctx->sample_aspect_ratio= av_div_q( mpeg2_aspect[s->aspect_ratio_info], (AVRational){w, h} ); if(s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_DEBUG, "sde w:%d, h:%d\n", w, h);}static void mpeg_decode_picture_display_extension(Mpeg1Context *s1){ MpegEncContext *s= &s1->mpeg_enc_ctx; int i; for(i=0; i<1; i++){ //FIXME count s1->pan_scan.position[i][0]= get_sbits(&s->gb, 16); skip_bits(&s->gb, 1); //marker s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16); skip_bits(&s->gb, 1); //marker } if(s->avctx->debug & FF_DEBUG_PICT_INFO) av_log(s->avctx, AV_LOG_DEBUG, "pde (%d,%d) (%d,%d) (%d,%d)\n", s1->pan_scan.position[0][0], s1->pan_scan.position[0][1], s1->pan_scan.position[1][0], s1->pan_scan.position[1][1], s1->pan_scan.position[2][0], s1->pan_scan.position[2][1]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -