annotate ffmpeg/libavcodec/h263.h @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * H263 internal header
yading@10 3 *
yading@10 4 * This file is part of FFmpeg.
yading@10 5 *
yading@10 6 * FFmpeg is free software; you can redistribute it and/or
yading@10 7 * modify it under the terms of the GNU Lesser General Public
yading@10 8 * License as published by the Free Software Foundation; either
yading@10 9 * version 2.1 of the License, or (at your option) any later version.
yading@10 10 *
yading@10 11 * FFmpeg is distributed in the hope that it will be useful,
yading@10 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 14 * Lesser General Public License for more details.
yading@10 15 *
yading@10 16 * You should have received a copy of the GNU Lesser General Public
yading@10 17 * License along with FFmpeg; if not, write to the Free Software
yading@10 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 19 */
yading@10 20 #ifndef AVCODEC_H263_H
yading@10 21 #define AVCODEC_H263_H
yading@10 22
yading@10 23 #include <stdint.h>
yading@10 24 #include "libavutil/rational.h"
yading@10 25 #include "get_bits.h"
yading@10 26 #include "mpegvideo.h"
yading@10 27 #include "rl.h"
yading@10 28
yading@10 29 // The defines below define the number of bits that are read at once for
yading@10 30 // reading vlc values. Changing these may improve speed and data cache needs
yading@10 31 // be aware though that decreasing them may need the number of stages that is
yading@10 32 // passed to get_vlc* to be increased.
yading@10 33 #define INTRA_MCBPC_VLC_BITS 6
yading@10 34 #define INTER_MCBPC_VLC_BITS 7
yading@10 35 #define CBPY_VLC_BITS 6
yading@10 36 #define TEX_VLC_BITS 9
yading@10 37
yading@10 38 extern const AVRational ff_h263_pixel_aspect[16];
yading@10 39 extern const uint8_t ff_h263_cbpy_tab[16][2];
yading@10 40
yading@10 41 extern const uint8_t ff_cbpc_b_tab[4][2];
yading@10 42
yading@10 43 extern const uint8_t ff_mvtab[33][2];
yading@10 44
yading@10 45 extern const uint8_t ff_h263_intra_MCBPC_code[9];
yading@10 46 extern const uint8_t ff_h263_intra_MCBPC_bits[9];
yading@10 47
yading@10 48 extern const uint8_t ff_h263_inter_MCBPC_code[28];
yading@10 49 extern const uint8_t ff_h263_inter_MCBPC_bits[28];
yading@10 50 extern const uint8_t ff_h263_mbtype_b_tab[15][2];
yading@10 51
yading@10 52 extern VLC ff_h263_intra_MCBPC_vlc;
yading@10 53 extern VLC ff_h263_inter_MCBPC_vlc;
yading@10 54 extern VLC ff_h263_cbpy_vlc;
yading@10 55
yading@10 56 extern RLTable ff_h263_rl_inter;
yading@10 57
yading@10 58 extern RLTable ff_rl_intra_aic;
yading@10 59
yading@10 60 extern const uint16_t ff_h263_format[8][2];
yading@10 61 extern const uint8_t ff_modified_quant_tab[2][32];
yading@10 62 extern const uint16_t ff_mba_max[6];
yading@10 63 extern const uint8_t ff_mba_length[7];
yading@10 64
yading@10 65 extern uint8_t ff_h263_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3];
yading@10 66
yading@10 67 extern const enum AVPixelFormat ff_h263_hwaccel_pixfmt_list_420[];
yading@10 68
yading@10 69
yading@10 70 int ff_h263_decode_motion(MpegEncContext * s, int pred, int f_code);
yading@10 71 av_const int ff_h263_aspect_to_info(AVRational aspect);
yading@10 72 int ff_h263_decode_init(AVCodecContext *avctx);
yading@10 73 int ff_h263_decode_frame(AVCodecContext *avctx,
yading@10 74 void *data, int *got_frame,
yading@10 75 AVPacket *avpkt);
yading@10 76 int ff_h263_decode_end(AVCodecContext *avctx);
yading@10 77 void ff_h263_encode_mb(MpegEncContext *s,
yading@10 78 int16_t block[6][64],
yading@10 79 int motion_x, int motion_y);
yading@10 80 void ff_h263_encode_picture_header(MpegEncContext *s, int picture_number);
yading@10 81 void ff_h263_encode_gob_header(MpegEncContext * s, int mb_line);
yading@10 82 int16_t *ff_h263_pred_motion(MpegEncContext * s, int block, int dir,
yading@10 83 int *px, int *py);
yading@10 84 void ff_h263_encode_init(MpegEncContext *s);
yading@10 85 void ff_h263_decode_init_vlc(void);
yading@10 86 int ff_h263_decode_picture_header(MpegEncContext *s);
yading@10 87 int ff_h263_decode_gob_header(MpegEncContext *s);
yading@10 88 void ff_h263_update_motion_val(MpegEncContext * s);
yading@10 89 void ff_h263_loop_filter(MpegEncContext * s);
yading@10 90 int ff_h263_decode_mba(MpegEncContext *s);
yading@10 91 void ff_h263_encode_mba(MpegEncContext *s);
yading@10 92 void ff_init_qscale_tab(MpegEncContext *s);
yading@10 93 int ff_h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr);
yading@10 94 void ff_h263_pred_acdc(MpegEncContext * s, int16_t *block, int n);
yading@10 95
yading@10 96
yading@10 97 /**
yading@10 98 * Print picture info if FF_DEBUG_PICT_INFO is set.
yading@10 99 */
yading@10 100 void ff_h263_show_pict_info(MpegEncContext *s);
yading@10 101
yading@10 102 int ff_intel_h263_decode_picture_header(MpegEncContext *s);
yading@10 103 int ff_h263_decode_mb(MpegEncContext *s,
yading@10 104 int16_t block[6][64]);
yading@10 105
yading@10 106 /**
yading@10 107 * Return the value of the 3bit "source format" syntax element.
yading@10 108 * This represents some standard picture dimensions or indicates that
yading@10 109 * width&height are explicitly stored later.
yading@10 110 */
yading@10 111 int av_const h263_get_picture_format(int width, int height);
yading@10 112
yading@10 113 void ff_clean_h263_qscales(MpegEncContext *s);
yading@10 114 int ff_h263_resync(MpegEncContext *s);
yading@10 115 const uint8_t *ff_h263_find_resync_marker(MpegEncContext *s, const uint8_t *p, const uint8_t *end);
yading@10 116 int ff_h263_get_gob_height(MpegEncContext *s);
yading@10 117 void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code);
yading@10 118
yading@10 119
yading@10 120 static inline int h263_get_motion_length(MpegEncContext * s, int val, int f_code){
yading@10 121 int l, bit_size, code;
yading@10 122
yading@10 123 if (val == 0) {
yading@10 124 return ff_mvtab[0][1];
yading@10 125 } else {
yading@10 126 bit_size = f_code - 1;
yading@10 127 /* modulo encoding */
yading@10 128 l= INT_BIT - 6 - bit_size;
yading@10 129 val = (val<<l)>>l;
yading@10 130 val--;
yading@10 131 code = (val >> bit_size) + 1;
yading@10 132
yading@10 133 return ff_mvtab[code][1] + 1 + bit_size;
yading@10 134 }
yading@10 135 }
yading@10 136
yading@10 137 static inline void ff_h263_encode_motion_vector(MpegEncContext * s, int x, int y, int f_code){
yading@10 138 if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){
yading@10 139 skip_put_bits(&s->pb,
yading@10 140 h263_get_motion_length(s, x, f_code)
yading@10 141 +h263_get_motion_length(s, y, f_code));
yading@10 142 }else{
yading@10 143 ff_h263_encode_motion(s, x, f_code);
yading@10 144 ff_h263_encode_motion(s, y, f_code);
yading@10 145 }
yading@10 146 }
yading@10 147
yading@10 148 static inline int get_p_cbp(MpegEncContext * s,
yading@10 149 int16_t block[6][64],
yading@10 150 int motion_x, int motion_y){
yading@10 151 int cbp, i;
yading@10 152
yading@10 153 if (s->mpv_flags & FF_MPV_FLAG_CBP_RD) {
yading@10 154 int best_cbpy_score= INT_MAX;
yading@10 155 int best_cbpc_score= INT_MAX;
yading@10 156 int cbpc = (-1), cbpy= (-1);
yading@10 157 const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0);
yading@10 158 const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
yading@10 159
yading@10 160 for(i=0; i<4; i++){
yading@10 161 int score= ff_h263_inter_MCBPC_bits[i + offset] * lambda;
yading@10 162 if(i&1) score += s->coded_score[5];
yading@10 163 if(i&2) score += s->coded_score[4];
yading@10 164
yading@10 165 if(score < best_cbpc_score){
yading@10 166 best_cbpc_score= score;
yading@10 167 cbpc= i;
yading@10 168 }
yading@10 169 }
yading@10 170
yading@10 171 for(i=0; i<16; i++){
yading@10 172 int score= ff_h263_cbpy_tab[i ^ 0xF][1] * lambda;
yading@10 173 if(i&1) score += s->coded_score[3];
yading@10 174 if(i&2) score += s->coded_score[2];
yading@10 175 if(i&4) score += s->coded_score[1];
yading@10 176 if(i&8) score += s->coded_score[0];
yading@10 177
yading@10 178 if(score < best_cbpy_score){
yading@10 179 best_cbpy_score= score;
yading@10 180 cbpy= i;
yading@10 181 }
yading@10 182 }
yading@10 183 cbp= cbpc + 4*cbpy;
yading@10 184 if ((motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16){
yading@10 185 if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0)
yading@10 186 cbp= 0;
yading@10 187 }
yading@10 188
yading@10 189 for (i = 0; i < 6; i++) {
yading@10 190 if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){
yading@10 191 s->block_last_index[i]= -1;
yading@10 192 s->dsp.clear_block(s->block[i]);
yading@10 193 }
yading@10 194 }
yading@10 195 }else{
yading@10 196 cbp= 0;
yading@10 197 for (i = 0; i < 6; i++) {
yading@10 198 if (s->block_last_index[i] >= 0)
yading@10 199 cbp |= 1 << (5 - i);
yading@10 200 }
yading@10 201 }
yading@10 202 return cbp;
yading@10 203 }
yading@10 204
yading@10 205 static inline void memsetw(short *tab, int val, int n)
yading@10 206 {
yading@10 207 int i;
yading@10 208 for(i=0;i<n;i++)
yading@10 209 tab[i] = val;
yading@10 210 }
yading@10 211
yading@10 212 #endif /* AVCODEC_H263_H */