]> git.sesse.net Git - x264/blob - common/cabac.h
3bc0f94d3fd56401b1d949ffd0cc15cdf6bb360e
[x264] / common / cabac.h
1 /*****************************************************************************
2  * cabac.h: h264 encoder library
3  *****************************************************************************
4  * Copyright (C) 2003 Laurent Aimar
5  * $Id: cabac.h,v 1.1 2004/06/03 19:27:06 fenrir Exp $
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #ifndef _CABAC_H
25 #define _CABAC_H 1
26
27 typedef struct
28 {
29     /* model */
30     struct
31     {
32         int i_model;
33         int i_cost;
34     } slice[3];
35
36     /* context */
37     /* states 436-459 are for interlacing, so are omitted for now */
38     struct
39     {
40         int i_state;
41         int i_mps;
42         int i_count;
43     } ctxstate[436];
44
45     /* state */
46     int i_low;
47     int i_range;
48
49     /* bit stream */
50     int b_first_bit;
51     int i_bits_outstanding;
52     int f8_bits_encoded; // only if using x264_cabac_size_decision()
53     bs_t *s;
54
55 } x264_cabac_t;
56
57 /* encoder/decoder: init the contexts given i_slice_type, the quantif and the model */
58 void x264_cabac_context_init( x264_cabac_t *cb, int i_slice_type, int i_qp, int i_model );
59
60 /* decoder only: */
61 void x264_cabac_decode_init    ( x264_cabac_t *cb, bs_t *s );
62 int  x264_cabac_decode_decision( x264_cabac_t *cb, int i_ctx_idx );
63 int  x264_cabac_decode_bypass  ( x264_cabac_t *cb );
64 int  x264_cabac_decode_terminal( x264_cabac_t *cb );
65
66 /* encoder only: adaptive model init */
67 void x264_cabac_model_init( x264_cabac_t *cb );
68 int  x264_cabac_model_get ( x264_cabac_t *cb, int i_slice_type );
69 void x264_cabac_model_update( x264_cabac_t *cb, int i_slice_type, int i_qp );
70 /* encoder only: */
71 void x264_cabac_encode_init ( x264_cabac_t *cb, bs_t *s );
72 void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx_idx, int b );
73 void x264_cabac_encode_bypass( x264_cabac_t *cb, int b );
74 void x264_cabac_encode_terminal( x264_cabac_t *cb, int b );
75 void x264_cabac_encode_flush( x264_cabac_t *cb );
76 /* don't write the bitstream, just calculate cost: */
77 void x264_cabac_size_decision( x264_cabac_t *cb, int i_ctx, int b );
78
79 static inline int x264_cabac_pos( x264_cabac_t *cb )
80 {
81     return bs_pos( cb->s ) + cb->i_bits_outstanding;
82 }
83
84 #endif