cabac.h 2.67 KB
Newer Older
Laurent Aimar's avatar
Laurent Aimar committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
/*****************************************************************************
 * cabac.h: h264 encoder library
 *****************************************************************************
 * Copyright (C) 2003 Laurent Aimar
 * $Id: cabac.h,v 1.1 2004/06/03 19:27:06 fenrir Exp $
 *
 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

#ifndef _CABAC_H
#define _CABAC_H 1

typedef struct
{
    /* model */
    struct
    {
        int i_model;
        int i_cost;
    } slice[3];

    /* context */
37
    /* states 436-459 are for interlacing, so are omitted for now */
Laurent Aimar's avatar
Laurent Aimar committed
38 39 40 41 42
    struct
    {
        int i_state;
        int i_mps;
        int i_count;
43
    } ctxstate[436];
Laurent Aimar's avatar
Laurent Aimar committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77

    /* state */
    int i_low;
    int i_range;

    int i_sym_cnt;

    /* bit stream */
    int b_first_bit;
    int i_bits_outstanding;
    bs_t *s;

} x264_cabac_t;

/* encoder/decoder: init the contexts given i_slice_type, the quantif and the model */
void x264_cabac_context_init( x264_cabac_t *cb, int i_slice_type, int i_qp, int i_model );

/* decoder only: */
void x264_cabac_decode_init    ( x264_cabac_t *cb, bs_t *s );
int  x264_cabac_decode_decision( x264_cabac_t *cb, int i_ctx_idx );
int  x264_cabac_decode_bypass  ( x264_cabac_t *cb );
int  x264_cabac_decode_terminal( x264_cabac_t *cb );

/* encoder only: adaptive model init */
void x264_cabac_model_init( x264_cabac_t *cb );
int  x264_cabac_model_get ( x264_cabac_t *cb, int i_slice_type );
void x264_cabac_model_update( x264_cabac_t *cb, int i_slice_type, int i_qp );
/* encoder only: */
void x264_cabac_encode_init ( x264_cabac_t *cb, bs_t *s );
void x264_cabac_encode_decision( x264_cabac_t *cb, int i_ctx_idx, int b );
void x264_cabac_encode_bypass( x264_cabac_t *cb, int b );
void x264_cabac_encode_terminal( x264_cabac_t *cb, int b );
void x264_cabac_encode_flush( x264_cabac_t *cb );

78 79 80 81
static inline int x264_cabac_pos( x264_cabac_t *cb )
{
    return bs_pos( cb->s ) + cb->i_bits_outstanding;
}
Laurent Aimar's avatar
Laurent Aimar committed
82 83

#endif