annotate h263.h @ 11572:e00f9288527a libavcodec

Store range coder state transition table. Use a better table, 2% compression gain for foreman
author michael
date Thu, 01 Apr 2010 18:51:08 +0000
parents 811467079ec9
children fdafbcef52f5
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
11412
811467079ec9 Add lots of missing includes
mru
parents: 11377
diff changeset
23 #include <stdint.h>
811467079ec9 Add lots of missing includes
mru
parents: 11377
diff changeset
24 #include "libavutil/rational.h"
811467079ec9 Add lots of missing includes
mru
parents: 11377
diff changeset
25 #include "get_bits.h"
811467079ec9 Add lots of missing includes
mru
parents: 11377
diff changeset
26 #include "mpegvideo.h"
811467079ec9 Add lots of missing includes
mru
parents: 11377
diff changeset
27 #include "rl.h"
811467079ec9 Add lots of missing includes
mru
parents: 11377
diff changeset
28
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
29 // 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
30 // 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
31 // 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
32 // passed to get_vlc* to be increased.
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
33 #define INTRA_MCBPC_VLC_BITS 6
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
34 #define INTER_MCBPC_VLC_BITS 7
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
35 #define CBPY_VLC_BITS 6
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
36 #define TEX_VLC_BITS 9
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
37
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
38 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
39 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
40
10828
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
41 extern const uint8_t cbpc_b_tab[4][2];
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
42
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
43 extern const uint8_t mvtab[33][2];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
44
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
45 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
46 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
47
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
48 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
49 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
50 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
51
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
52 extern VLC ff_h263_intra_MCBPC_vlc;
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
53 extern VLC ff_h263_inter_MCBPC_vlc;
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
54 extern VLC ff_h263_cbpy_vlc;
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
55
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
56 extern RLTable ff_h263_rl_inter;
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
57
10828
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
58 extern RLTable rl_intra_aic;
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
59
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
60 extern const uint16_t h263_format[8][2];
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
61 extern const uint8_t modified_quant_tab[2][32];
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
62 extern uint16_t ff_mba_max[6];
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
63 extern uint8_t ff_mba_length[7];
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
64
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
65 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
66
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
67
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
68 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
69 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
70 int ff_h263_decode_init(AVCodecContext *avctx);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
71 int ff_h263_decode_frame(AVCodecContext *avctx,
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
72 void *data, int *data_size,
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
73 AVPacket *avpkt);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
74 int ff_h263_decode_end(AVCodecContext *avctx);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
75 void h263_encode_mb(MpegEncContext *s,
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
76 DCTELEM block[6][64],
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
77 int motion_x, int motion_y);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
78 void h263_encode_picture_header(MpegEncContext *s, int picture_number);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
79 void h263_encode_gob_header(MpegEncContext * s, int mb_line);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
80 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
81 int *px, int *py);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
82 void h263_encode_init(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
83 void h263_decode_init_vlc(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
84 int h263_decode_picture_header(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
85 int ff_h263_decode_gob_header(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
86 void ff_h263_update_motion_val(MpegEncContext * s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
87 void ff_h263_loop_filter(MpegEncContext * s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
88 int ff_h263_decode_mba(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
89 void ff_h263_encode_mba(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
90 void ff_init_qscale_tab(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
91 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
92 void h263_pred_acdc(MpegEncContext * s, DCTELEM *block, int n);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
93
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 /**
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
96 * Prints picture info if FF_DEBUG_PICT_INFO is set.
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
97 */
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
98 void ff_h263_show_pict_info(MpegEncContext *s);
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 int ff_intel_h263_decode_picture_header(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
101 int ff_h263_decode_mb(MpegEncContext *s,
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
102 DCTELEM block[6][64]);
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 /**
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
105 * Returns the value of the 3bit "source format" syntax element.
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
106 * that represents some standard picture dimensions or indicates that
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
107 * width&height are explicitly stored later.
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
108 */
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
109 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
110
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
111 void ff_clean_h263_qscales(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
112 int ff_h263_resync(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
113 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
114 int ff_h263_get_gob_height(MpegEncContext *s);
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
115 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
116
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
117
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
118 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
119 int l, bit_size, code;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
120
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
121 if (val == 0) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
122 return mvtab[0][1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
123 } else {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
124 bit_size = f_code - 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
125 /* modulo encoding */
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
126 l= INT_BIT - 6 - bit_size;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
127 val = (val<<l)>>l;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
128 val--;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
129 code = (val >> bit_size) + 1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
130
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
131 return mvtab[code][1] + 1 + bit_size;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
132 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
133 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
134
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
135 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
136 if(s->flags2 & CODEC_FLAG2_NO_OUTPUT){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
137 skip_put_bits(&s->pb,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
138 h263_get_motion_length(s, x, f_code)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
139 +h263_get_motion_length(s, y, f_code));
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
140 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
141 ff_h263_encode_motion(s, x, f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
142 ff_h263_encode_motion(s, y, f_code);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
143 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
144 }
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 static inline int get_p_cbp(MpegEncContext * s,
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
147 DCTELEM block[6][64],
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
148 int motion_x, int motion_y){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
149 int cbp, i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
150
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
151 if(s->flags & CODEC_FLAG_CBP_RD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
152 int best_cbpy_score= INT_MAX;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
153 int best_cbpc_score= INT_MAX;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
154 int cbpc = (-1), cbpy= (-1);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
155 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
156 const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
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 for(i=0; i<4; i++){
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
159 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
160 if(i&1) score += s->coded_score[5];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
161 if(i&2) score += s->coded_score[4];
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 if(score < best_cbpc_score){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
164 best_cbpc_score= score;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
165 cbpc= i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
166 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
167 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
168
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
169 for(i=0; i<16; i++){
10818
514dc1c87b2e Rename most non static h263 tables so their name contains h263.
michael
parents: 10803
diff changeset
170 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
171 if(i&1) score += s->coded_score[3];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
172 if(i&2) score += s->coded_score[2];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
173 if(i&4) score += s->coded_score[1];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
174 if(i&8) score += s->coded_score[0];
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 if(score < best_cbpy_score){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
177 best_cbpy_score= score;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
178 cbpy= i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
179 }
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 cbp= cbpc + 4*cbpy;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
182 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
183 if(best_cbpy_score + best_cbpc_score + 2*lambda >= 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
184 cbp= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
185 }
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 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
188 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
189 s->block_last_index[i]= -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
190 s->dsp.clear_block(s->block[i]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
191 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
192 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
193 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
194 cbp= 0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
195 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
196 if (s->block_last_index[i] >= 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
197 cbp |= 1 << (5 - i);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
198 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
199 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
200 return cbp;
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
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
203 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
204 int motion_x, int motion_y, int mb_type){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
205 int cbp=0, i;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
206
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
207 if(s->flags & CODEC_FLAG_CBP_RD){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
208 int score=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
209 const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6);
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 for(i=0; i<6; i++){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
212 if(s->coded_score[i] < 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
213 score += s->coded_score[i];
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
214 cbp |= 1 << (5 - i);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
215 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
216 }
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 if(cbp){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
219 int zero_score= -6;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
220 if ((motion_x | motion_y | s->dquant | mb_type) == 0){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
221 zero_score-= 4; //2*MV + mb_type + cbp bit
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 zero_score*= lambda;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
225 if(zero_score <= score){
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
226 cbp=0;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
227 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
228 }
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 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
231 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
232 s->block_last_index[i]= -1;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
233 s->dsp.clear_block(s->block[i]);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
234 }
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 }else{
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
237 for (i = 0; i < 6; i++) {
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
238 if (s->block_last_index[i] >= 0)
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
239 cbp |= 1 << (5 - i);
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
240 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
241 }
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
242 return cbp;
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
243 }
10828
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
244
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
245 static inline void memsetw(short *tab, int val, int n)
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
246 {
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
247 int i;
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
248 for(i=0;i<n;i++)
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
249 tab[i] = val;
d0657e337f91 Split H263 encoder and decoder from common code.
michael
parents: 10818
diff changeset
250 }
10803
4605bd2fdb7f Split the mpeg4 encoder and decoder off h263.c
michael
parents:
diff changeset
251 #endif