#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "private/bitmath.h"
#include "private/bitreader.h"
#include "private/crc.h"
#include "private/macros.h"
#include "FLAC/assert.h"
#include "share/compat.h"
#include "share/endswap.h"
#if (ENABLE_64_BIT_WORDS == 0)
brword;
#define FLAC__BYTES_PER_WORD …
#define FLAC__BITS_PER_WORD …
#define FLAC__WORD_ALL_ONES …
#if WORDS_BIGENDIAN
#define SWAP_BE_WORD_TO_HOST …
#else
#define SWAP_BE_WORD_TO_HOST(x) …
#endif
#define COUNT_ZERO_MSBS(word) …
#define COUNT_ZERO_MSBS2(word) …
#else
typedef FLAC__uint64 brword;
#define FLAC__BYTES_PER_WORD …
#define FLAC__BITS_PER_WORD …
#define FLAC__WORD_ALL_ONES …
#if WORDS_BIGENDIAN
#define SWAP_BE_WORD_TO_HOST …
#else
#define SWAP_BE_WORD_TO_HOST …
#endif
#define COUNT_ZERO_MSBS …
#define COUNT_ZERO_MSBS2 …
#endif
static const uint32_t FLAC__BITREADER_DEFAULT_CAPACITY = …;
struct FLAC__BitReader { … };
static inline void crc16_update_word_(FLAC__BitReader *br, brword word)
{ … }
static inline void crc16_update_block_(FLAC__BitReader *br)
{ … }
static FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
{ … }
FLAC__BitReader *FLAC__bitreader_new(void)
{ … }
void FLAC__bitreader_delete(FLAC__BitReader *br)
{ … }
FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__BitReaderReadCallback rcb, void *cd)
{ … }
void FLAC__bitreader_free(FLAC__BitReader *br)
{ … }
FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
{ … }
void FLAC__bitreader_set_framesync_location(FLAC__BitReader *br)
{ … }
FLAC__bool FLAC__bitreader_rewind_to_after_last_seen_framesync(FLAC__BitReader *br)
{ … }
void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
{ … }
void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
{ … }
FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
{ … }
inline FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
{ … }
inline uint32_t FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
{ … }
inline uint32_t FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
{ … }
void FLAC__bitreader_set_limit(FLAC__BitReader *br, uint32_t limit)
{ … }
void FLAC__bitreader_remove_limit(FLAC__BitReader *br)
{ … }
uint32_t FLAC__bitreader_limit_remaining(FLAC__BitReader *br)
{ … }
void FLAC__bitreader_limit_invalidate(FLAC__BitReader *br)
{ … }
FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, uint32_t bits)
{ … }
FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, uint32_t bits)
{ … }
FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, uint32_t bits)
{ … }
FLAC__bool FLAC__bitreader_read_raw_int64(FLAC__BitReader *br, FLAC__int64 *val, uint32_t bits)
{ … }
inline FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
{ … }
FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, uint32_t bits)
{ … }
FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, uint32_t nvals)
{ … }
FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, uint32_t nvals)
{ … }
FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, uint32_t *val)
#if 0
{ … }
#endif
#if 0
FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, uint32_t parameter)
{
FLAC__uint32 lsbs = 0, msbs = 0;
uint32_t uval;
FLAC__ASSERT(0 != br);
FLAC__ASSERT(0 != br->buffer);
FLAC__ASSERT(parameter <= 31);
if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
return false;
if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
return false;
uval = (msbs << parameter) | lsbs;
if(uval & 1)
*val = -((int)(uval >> 1)) - 1;
else
*val = (int)(uval >> 1);
return true;
}
#endif
FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], uint32_t nvals, uint32_t parameter)
{ … }
#if 0
FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, uint32_t parameter)
{
FLAC__uint32 lsbs = 0, msbs = 0;
uint32_t bit, uval, k;
FLAC__ASSERT(0 != br);
FLAC__ASSERT(0 != br->buffer);
k = FLAC__bitmath_ilog2(parameter);
if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
return false;
if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
return false;
if(parameter == 1u<<k) {
uval = (msbs << k) | lsbs;
}
else {
uint32_t d = (1 << (k+1)) - parameter;
if(lsbs >= d) {
if(!FLAC__bitreader_read_bit(br, &bit))
return false;
lsbs <<= 1;
lsbs |= bit;
lsbs -= d;
}
uval = msbs * parameter + lsbs;
}
if(uval & 1)
*val = -((int)(uval >> 1)) - 1;
else
*val = (int)(uval >> 1);
return true;
}
FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, uint32_t *val, uint32_t parameter)
{
FLAC__uint32 lsbs, msbs = 0;
uint32_t bit, k;
FLAC__ASSERT(0 != br);
FLAC__ASSERT(0 != br->buffer);
k = FLAC__bitmath_ilog2(parameter);
if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
return false;
if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
return false;
if(parameter == 1u<<k) {
*val = (msbs << k) | lsbs;
}
else {
uint32_t d = (1 << (k+1)) - parameter;
if(lsbs >= d) {
if(!FLAC__bitreader_read_bit(br, &bit))
return false;
lsbs <<= 1;
lsbs |= bit;
lsbs -= d;
}
*val = msbs * parameter + lsbs;
}
return true;
}
#endif
FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, uint32_t *rawlen)
{ … }
FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, uint32_t *rawlen)
{ … }
extern FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
extern uint32_t FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
extern uint32_t FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
extern FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val);