/*****************************************************************************
- * bitstream.h: h264 encoder library
+ * bitstream.h: bitstream writing
*****************************************************************************
- * Copyright (C) 2003-2008 x264 project
+ * Copyright (C) 2003-2016 x264 project
*
* Authors: Loren Merritt <lorenm@u.washington.edu>
* Fiona Glaser <fiona@x264.com>
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
+ *
+ * This program is also available under a commercial proprietary license.
+ * For more information, contact us at licensing@x264.com.
*****************************************************************************/
#ifndef X264_BS_H
uint8_t *p;
uint8_t *p_end;
- intptr_t cur_bits;
+ uintptr_t cur_bits;
int i_left; /* i_count number of available bits */
int i_bits_encoded; /* RD only */
} bs_t;
typedef struct
{
- int last;
- int16_t level[16];
- uint8_t run[16];
+ int32_t last;
+ int32_t mask;
+ ALIGNED_16( dctcoef level[18] );
} x264_run_level_t;
-extern const vlc_t x264_coeff0_token[5];
-extern const vlc_t x264_coeff_token[5][16][4];
+extern const vlc_t x264_coeff0_token[6];
+extern const vlc_t x264_coeff_token[6][16][4];
extern const vlc_t x264_total_zeros[15][16];
-extern const vlc_t x264_total_zeros_dc[3][4];
-extern const vlc_t x264_run_before[7][16];
+extern const vlc_t x264_total_zeros_2x2_dc[3][4];
+extern const vlc_t x264_total_zeros_2x4_dc[7][8];
typedef struct
{
uint8_t *(*nal_escape) ( uint8_t *dst, uint8_t *src, uint8_t *end );
+ void (*cabac_block_residual_internal)( dctcoef *l, int b_interlaced,
+ intptr_t ctx_block_cat, x264_cabac_t *cb );
+ void (*cabac_block_residual_rd_internal)( dctcoef *l, int b_interlaced,
+ intptr_t ctx_block_cat, x264_cabac_t *cb );
+ void (*cabac_block_residual_8x8_rd_internal)( dctcoef *l, int b_interlaced,
+ intptr_t ctx_block_cat, x264_cabac_t *cb );
} x264_bitstream_function_t;
-int x264_nal_encode( x264_t *h, uint8_t *dst, x264_nal_t *nal, int b_long_startcode );
void x264_bitstream_init( int cpu, x264_bitstream_function_t *pf );
/* A larger level table size theoretically could help a bit at extremely
#define LEVEL_TABLE_SIZE 128
extern vlc_large_t x264_level_token[7][LEVEL_TABLE_SIZE];
+/* The longest possible set of zero run codes sums to 25 bits. This leaves
+ * plenty of room for both the code (25 bits) and size (5 bits) in a uint32_t. */
+
+extern uint32_t x264_run_before[1<<16];
+
static inline void bs_init( bs_t *s, void *p_data, int i_data )
{
int offset = ((intptr_t)p_data & 3);
static inline void bs_flush( bs_t *s )
{
M32( s->p ) = endian_fix32( s->cur_bits << (s->i_left&31) );
- s->p += WORD_SIZE - s->i_left / 8;
+ s->p += WORD_SIZE - (s->i_left >> 3);
s->i_left = WORD_SIZE*8;
}
/* The inverse of bs_flush: prepare the bitstream to be written to again. */
s->i_left -= i_count;
if( s->i_left <= 32 )
{
-#ifdef WORDS_BIGENDIAN
+#if WORDS_BIGENDIAN
M32( s->p ) = s->cur_bits >> (32 - s->i_left);
#else
M32( s->p ) = endian_fix( s->cur_bits << s->i_left );