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