annotate h263.h @ 10919:241c0f3bba65 libavcodec

PAFF CABAC P slices seem to work as well, so enable them for ff_h264_filter_mb_fast() too.
author michael
date Mon, 18 Jan 2010 16:29:16 +0000
parents d0657e337f91
children f9e0f62a7d8a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
1 /*
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
2 * H263 internal header
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
3 *
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
4 * This file is part of FFmpeg.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
5 *
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
10 *
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
14 * Lesser General Public License for more details.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
15 *
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
19 */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
20 #ifndef AVCODEC_H263_H
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
21 #define AVCODEC_H263_H
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
22
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
23 // The defines below define the number of bits that are read at once for
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
24 // reading vlc values. Changing these may improve speed and data cache needs
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
25 // be aware though that decreasing them may need the number of stages that is
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
26 // passed to get_vlc* to be increased.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
27 #define INTRA_MCBPC_VLC_BITS 6
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
28 #define INTER_MCBPC_VLC_BITS 7
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
29 #define CBPY_VLC_BITS 6
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
30 #define TEX_VLC_BITS 9
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
31
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
32 extern const AVRational ff_h263_pixel_aspect[16];
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
33 extern const uint8_t ff_h263_cbpy_tab[16][2];
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
34
10828
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
35 extern const uint8_t cbpc_b_tab[4][2];
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
36
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
37 extern const uint8_t mvtab[33][2];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
38
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
39 extern const uint8_t ff_h263_intra_MCBPC_code[9];
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
40 extern const uint8_t ff_h263_intra_MCBPC_bits[9];
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
41
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
42 extern const uint8_t ff_h263_inter_MCBPC_code[28];
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
43 extern const uint8_t ff_h263_inter_MCBPC_bits[28];
10828
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
44 extern const uint8_t h263_mbtype_b_tab[15][2];
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
45
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
46 extern VLC ff_h263_intra_MCBPC_vlc;
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
47 extern VLC ff_h263_inter_MCBPC_vlc;
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
48 extern VLC ff_h263_cbpy_vlc;
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
49
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
50 extern RLTable ff_h263_rl_inter;
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
51
10828
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
52 extern RLTable rl_intra_aic;
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
53
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
54 extern const uint16_t h263_format[8][2];
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
55 extern const uint8_t modified_quant_tab[2][32];
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
56 extern uint16_t ff_mba_max[6];
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
57 extern uint8_t ff_mba_length[7];
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
58
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
59 extern uint8_t ff_h263_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3];
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
60
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
61
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
62 int h263_decode_motion(MpegEncContext * s, int pred, int f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
63 av_const int ff_h263_aspect_to_info(AVRational aspect);
10828
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
64 int ff_h263_decode_init(AVCodecContext *avctx);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
65 int ff_h263_decode_frame(AVCodecContext *avctx,
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
66 void *data, int *data_size,
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
67 AVPacket *avpkt);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
68 int ff_h263_decode_end(AVCodecContext *avctx);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
69 void h263_encode_mb(MpegEncContext *s,
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
70 DCTELEM block[6][64],
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
71 int motion_x, int motion_y);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
72 void h263_encode_picture_header(MpegEncContext *s, int picture_number);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
73 void h263_encode_gob_header(MpegEncContext * s, int mb_line);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
74 int16_t *h263_pred_motion(MpegEncContext * s, int block, int dir,
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
75 int *px, int *py);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
76 void h263_encode_init(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
77 void h263_decode_init_vlc(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
78 int h263_decode_picture_header(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
79 int ff_h263_decode_gob_header(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
80 void ff_h263_update_motion_val(MpegEncContext * s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
81 void ff_h263_loop_filter(MpegEncContext * s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
82 void ff_set_qscale(MpegEncContext * s, int qscale);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
83 int ff_h263_decode_mba(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
84 void ff_h263_encode_mba(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
85 void ff_init_qscale_tab(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
86 int h263_pred_dc(MpegEncContext * s, int n, int16_t **dc_val_ptr);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
87 void h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
88
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
89
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
90 /**
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
91 * Prints picture info if FF_DEBUG_PICT_INFO is set.
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
92 */
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
93 void ff_h263_show_pict_info(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
94
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
95 int ff_intel_h263_decode_picture_header(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
96 int ff_h263_decode_mb(MpegEncContext *s,
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
97 DCTELEM block[6][64]);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
98
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
99 /**
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
100 * Returns the value of the 3bit "source format" syntax element.
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
101 * that represents some standard picture dimensions or indicates that
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
102 * width&height are explicitly stored later.
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
103 */
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
104 int av_const h263_get_picture_format(int width, int height);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
105
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
106 void ff_clean_h263_qscales(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
107 int ff_h263_resync(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
108 const uint8_t *ff_h263_find_resync_marker(const uint8_t *p, const uint8_t *end);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
109 int ff_h263_get_gob_height(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
110 void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
111
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
112
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
113 static inline int h263_get_motion_length(MpegEncContext * s, int val, int f_code){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
114 int l, bit_size, code;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
115
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
116 if (val == 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
117 return mvtab[0][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
118 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
119 bit_size = f_code - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
120 /* modulo encoding */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
121 l= INT_BIT - 6 - bit_size;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
122 val = (val<<l)>>l;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
123 val--;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
124 code = (val >> bit_size) + 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
125
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
126 return mvtab[code][1] + 1 + bit_size;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
127 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
128 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
129
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
130 static inline void ff_h263_encode_motion_vector(MpegEncContext * s, int x, int y, int f_code){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
131 if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
132 skip_put_bits(&s->pb,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
133 h263_get_motion_length(s, x, f_code)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
134 +h263_get_motion_length(s, y, f_code));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
135 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
136 ff_h263_encode_motion(s, x, f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
137 ff_h263_encode_motion(s, y, f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
138 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
139 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
140
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
141 static inline int get_p_cbp(MpegEncContext * s,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
142 DCTELEM block[6][64],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
143 int motion_x, int motion_y){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
144 int cbp, i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
145
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
146 if(s->flags & CODEC_FLAG_CBP_RD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
147 int best_cbpy_score= INT_MAX;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
148 int best_cbpc_score= INT_MAX;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
149 int cbpc = (-1), cbpy= (-1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
150 const int offset= (s->mv_type==MV_TYPE_16X16 ? 0 : 16) + (s->dquant ? 8 : 0);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
151 const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
152
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
153 for(i=0; i<4; i++){
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
154 int score= ff_h263_inter_MCBPC_bits[i + offset] * lambda;
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
155 if(i&1) score += s->coded_score[5];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
156 if(i&2) score += s->coded_score[4];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
157
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
158 if(score < best_cbpc_score){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
159 best_cbpc_score= score;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
160 cbpc= i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
161 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
162 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
163
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
164 for(i=0; i<16; i++){
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
165 int score= ff_h263_cbpy_tab[i ^ 0xF][1] * lambda;
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
166 if(i&1) score += s->coded_score[3];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
167 if(i&2) score += s->coded_score[2];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
168 if(i&4) score += s->coded_score[1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
169 if(i&8) score += s->coded_score[0];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
170
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
171 if(score < best_cbpy_score){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
172 best_cbpy_score= score;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
173 cbpy= i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
174 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
175 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
176 cbp= cbpc + 4*cbpy;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
177 if ((motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
178 if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
179 cbp= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
180 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
181
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
182 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
183 if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
184 s->block_last_index[i]= -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
185 s->dsp.clear_block(s->block[i]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
186 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
187 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
188 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
189 cbp= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
190 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
191 if (s->block_last_index[i] >= 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
192 cbp |= 1 << (5 - i);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
193 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
194 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
195 return cbp;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
196 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
197
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
198 static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
199 int motion_x, int motion_y, int mb_type){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
200 int cbp=0, i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
201
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
202 if(s->flags & CODEC_FLAG_CBP_RD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
203 int score=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
204 const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
205
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
206 for(i=0; i<6; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
207 if(s->coded_score[i] < 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
208 score += s->coded_score[i];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
209 cbp |= 1 << (5 - i);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
210 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
211 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
212
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
213 if(cbp){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
214 int zero_score= -6;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
215 if ((motion_x | motion_y | s->dquant | mb_type) == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
216 zero_score-= 4; //2*MV + mb_type + cbp bit
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
217 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
218
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
219 zero_score*= lambda;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
220 if(zero_score <= score){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
221 cbp=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
222 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
223 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
224
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
225 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
226 if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
227 s->block_last_index[i]= -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
228 s->dsp.clear_block(s->block[i]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
229 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
230 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
231 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
232 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
233 if (s->block_last_index[i] >= 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
234 cbp |= 1 << (5 - i);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
235 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
236 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
237 return cbp;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
238 }
10828
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
239
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
240 static inline void memsetw(short *tab, int val, int n)
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
241 {
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
242 int i;
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
243 for(i=0;i<n;i++)
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
244 tab[i] = val;
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
245 }
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
246 #endif