yading@10: /* yading@10: * H263 internal header yading@10: * yading@10: * This file is part of FFmpeg. yading@10: * yading@10: * FFmpeg is free software; you can redistribute it and/or yading@10: * modify it under the terms of the GNU Lesser General Public yading@10: * License as published by the Free Software Foundation; either yading@10: * version 2.1 of the License, or (at your option) any later version. yading@10: * yading@10: * FFmpeg is distributed in the hope that it will be useful, yading@10: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@10: * Lesser General Public License for more details. yading@10: * yading@10: * You should have received a copy of the GNU Lesser General Public yading@10: * License along with FFmpeg; if not, write to the Free Software yading@10: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@10: */ yading@10: #ifndef AVCODEC_H263_H yading@10: #define AVCODEC_H263_H yading@10: yading@10: #include yading@10: #include "libavutil/rational.h" yading@10: #include "get_bits.h" yading@10: #include "mpegvideo.h" yading@10: #include "rl.h" yading@10: yading@10: // The defines below define the number of bits that are read at once for yading@10: // reading vlc values. Changing these may improve speed and data cache needs yading@10: // be aware though that decreasing them may need the number of stages that is yading@10: // passed to get_vlc* to be increased. yading@10: #define INTRA_MCBPC_VLC_BITS 6 yading@10: #define INTER_MCBPC_VLC_BITS 7 yading@10: #define CBPY_VLC_BITS 6 yading@10: #define TEX_VLC_BITS 9 yading@10: yading@10: extern const AVRational ff_h263_pixel_aspect[16]; yading@10: extern const uint8_t ff_h263_cbpy_tab[16][2]; yading@10: yading@10: extern const uint8_t ff_cbpc_b_tab[4][2]; yading@10: yading@10: extern const uint8_t ff_mvtab[33][2]; yading@10: yading@10: extern const uint8_t ff_h263_intra_MCBPC_code[9]; yading@10: extern const uint8_t ff_h263_intra_MCBPC_bits[9]; yading@10: yading@10: extern const uint8_t ff_h263_inter_MCBPC_code[28]; yading@10: extern const uint8_t ff_h263_inter_MCBPC_bits[28]; yading@10: extern const uint8_t ff_h263_mbtype_b_tab[15][2]; yading@10: yading@10: extern VLC ff_h263_intra_MCBPC_vlc; yading@10: extern VLC ff_h263_inter_MCBPC_vlc; yading@10: extern VLC ff_h263_cbpy_vlc; yading@10: yading@10: extern RLTable ff_h263_rl_inter; yading@10: yading@10: extern RLTable ff_rl_intra_aic; yading@10: yading@10: extern const uint16_t ff_h263_format[8][2]; yading@10: extern const uint8_t ff_modified_quant_tab[2][32]; yading@10: extern const uint16_t ff_mba_max[6]; yading@10: extern const uint8_t ff_mba_length[7]; yading@10: yading@10: extern uint8_t ff_h263_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; yading@10: yading@10: extern const enum AVPixelFormat ff_h263_hwaccel_pixfmt_list_420[]; yading@10: yading@10: yading@10: int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code); yading@10: av_const int ff_h263_aspect_to_info(AVRational aspect); yading@10: int ff_h263_decode_init(AVCodecContext *avctx); yading@10: int ff_h263_decode_frame(AVCodecContext *avctx, yading@10: void *data, int *got_frame, yading@10: AVPacket *avpkt); yading@10: int ff_h263_decode_end(AVCodecContext *avctx); yading@10: void ff_h263_encode_mb(MpegEncContext *s, yading@10: int16_t block[6][64], yading@10: int motion_x, int motion_y); yading@10: void ff_h263_encode_picture_header(MpegEncContext *s, int picture_number); yading@10: void ff_h263_encode_gob_header(MpegEncContext * s, int mb_line); yading@10: int16_t *ff_h263_pred_motion(MpegEncContext * s, int block, int dir, yading@10: int *px, int *py); yading@10: void ff_h263_encode_init(MpegEncContext *s); yading@10: void ff_h263_decode_init_vlc(void); yading@10: int ff_h263_decode_picture_header(MpegEncContext *s); yading@10: int ff_h263_decode_gob_header(MpegEncContext *s); yading@10: void ff_h263_update_motion_val(MpegEncContext * s); yading@10: void ff_h263_loop_filter(MpegEncContext * s); yading@10: int ff_h263_decode_mba(MpegEncContext *s); yading@10: void ff_h263_encode_mba(MpegEncContext *s); yading@10: void ff_init_qscale_tab(MpegEncContext *s); yading@10: int ff_h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr); yading@10: void ff_h263_pred_acdc(MpegEncContext * s, int16_t *block, int n); yading@10: yading@10: yading@10: /** yading@10: * Print picture info if FF_DEBUG_PICT_INFO is set. yading@10: */ yading@10: void ff_h263_show_pict_info(MpegEncContext *s); yading@10: yading@10: int ff_intel_h263_decode_picture_header(MpegEncContext *s); yading@10: int ff_h263_decode_mb(MpegEncContext *s, yading@10: int16_t block[6][64]); yading@10: yading@10: /** yading@10: * Return the value of the 3bit "source format" syntax element. yading@10: * This represents some standard picture dimensions or indicates that yading@10: * width&height are explicitly stored later. yading@10: */ yading@10: int av_const h263_get_picture_format(int width, int height); yading@10: yading@10: void ff_clean_h263_qscales(MpegEncContext *s); yading@10: int ff_h263_resync(MpegEncContext *s); yading@10: const uint8_t *ff_h263_find_resync_marker(MpegEncContext *s, const uint8_t *p, const uint8_t *end); yading@10: int ff_h263_get_gob_height(MpegEncContext *s); yading@10: void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code); yading@10: yading@10: yading@10: static inline int h263_get_motion_length(MpegEncContext * s, int val, int f_code){ yading@10: int l, bit_size, code; yading@10: yading@10: if (val == 0) { yading@10: return ff_mvtab[0][1]; yading@10: } else { yading@10: bit_size = f_code - 1; yading@10: /* modulo encoding */ yading@10: l= INT_BIT - 6 - bit_size; yading@10: val = (val<>l; yading@10: val--; yading@10: code = (val >> bit_size) + 1; yading@10: yading@10: return ff_mvtab[code][1] + 1 + bit_size; yading@10: } yading@10: } yading@10: yading@10: static inline void ff_h263_encode_motion_vector(MpegEncContext * s, int x, int y, int f_code){ yading@10: if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){ yading@10: skip_put_bits(&s->pb, yading@10: h263_get_motion_length(s, x, f_code) yading@10: +h263_get_motion_length(s, y, f_code)); yading@10: }else{ yading@10: ff_h263_encode_motion(s, x, f_code); yading@10: ff_h263_encode_motion(s, y, f_code); yading@10: } yading@10: } yading@10: yading@10: static inline int get_p_cbp(MpegEncContext * s, yading@10: int16_t block[6][64], yading@10: int motion_x, int motion_y){ yading@10: int cbp, i; yading@10: yading@10: if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) { yading@10: int best_cbpy_score= INT_MAX; yading@10: int best_cbpc_score= INT_MAX; yading@10: int cbpc = (-1), cbpy= (-1); yading@10: const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0); yading@10: const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); yading@10: yading@10: for(i=0; i<4; i++){ yading@10: int score= ff_h263_inter_MCBPC_bits[i + offset] * lambda; yading@10: if(i&1) score += s->coded_score[5]; yading@10: if(i&2) score += s->coded_score[4]; yading@10: yading@10: if(score < best_cbpc_score){ yading@10: best_cbpc_score= score; yading@10: cbpc= i; yading@10: } yading@10: } yading@10: yading@10: for(i=0; i<16; i++){ yading@10: int score= ff_h263_cbpy_tab[i ^ 0xF][1] * lambda; yading@10: if(i&1) score += s->coded_score[3]; yading@10: if(i&2) score += s->coded_score[2]; yading@10: if(i&4) score += s->coded_score[1]; yading@10: if(i&8) score += s->coded_score[0]; yading@10: yading@10: if(score < best_cbpy_score){ yading@10: best_cbpy_score= score; yading@10: cbpy= i; yading@10: } yading@10: } yading@10: cbp= cbpc + 4*cbpy; yading@10: if ((motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16){ yading@10: if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0) yading@10: cbp= 0; yading@10: } yading@10: yading@10: for (i = 0; i < 6; i++) { yading@10: if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ yading@10: s->block_last_index[i]= -1; yading@10: s->dsp.clear_block(s->block[i]); yading@10: } yading@10: } yading@10: }else{ yading@10: cbp= 0; yading@10: for (i = 0; i < 6; i++) { yading@10: if (s->block_last_index[i] >= 0) yading@10: cbp |= 1 << (5 - i); yading@10: } yading@10: } yading@10: return cbp; yading@10: } yading@10: yading@10: static inline void memsetw(short *tab, int val, int n) yading@10: { yading@10: int i; yading@10: for(i=0;i