chromium/third_party/ffmpeg/libavcodec/get_bits.h

/*
 * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

/**
 * @file
 * bitstream reader API header.
 */

#ifndef AVCODEC_GET_BITS_H
#define AVCODEC_GET_BITS_H

#include <stdint.h>

#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/avassert.h"

#include "defs.h"
#include "mathops.h"
#include "vlc.h"

/*
 * Safe bitstream reading:
 * optionally, the get_bits API can check to ensure that we
 * don't read past input buffer boundaries. This is protected
 * with CONFIG_SAFE_BITSTREAM_READER at the global level, and
 * then below that with UNCHECKED_BITSTREAM_READER at the per-
 * decoder level. This means that decoders that check internally
 * can "#define UNCHECKED_BITSTREAM_READER 1" to disable
 * overread checks.
 * Boundary checking causes a minor performance penalty so for
 * applications that won't want/need this, it can be disabled
 * globally using "#define CONFIG_SAFE_BITSTREAM_READER 0".
 */
#ifndef UNCHECKED_BITSTREAM_READER
#define UNCHECKED_BITSTREAM_READER
#endif

#ifndef CACHED_BITSTREAM_READER
#define CACHED_BITSTREAM_READER
#endif

#if CACHED_BITSTREAM_READER

// we always want the LE implementation, to provide get_bits_le()
#define BITSTREAM_LE

#ifndef BITSTREAM_READER_LE
#define BITSTREAM_BE
#define BITSTREAM_DEFAULT_BE
#endif

#include "bitstream.h"

#undef BITSTREAM_LE
#undef BITSTREAM_BE
#undef BITSTREAM_DEFAULT_BE

typedef BitstreamContext GetBitContext;

#define get_bits_count
#define get_bits_left
#define skip_bits_long
#define skip_bits
#define get_bits
#define get_bitsz
#define get_bits_long
#define get_bits1
#define get_bits64
#define get_xbits
#define get_sbits
#define get_sbits_long
#define show_bits
#define show_bits_long
#define init_get_bits
#define init_get_bits8
#define align_get_bits
#define get_vlc2
#define get_vlc_multi

#define init_get_bits8_le
#define get_bits_le

#define show_bits1
#define skip_bits1

#define skip_1stop_8data_bits

#else   // CACHED_BITSTREAM_READER

GetBitContext;

static inline unsigned int get_bits(GetBitContext *s, int n);
static inline void skip_bits(GetBitContext *s, int n);
static inline unsigned int show_bits(GetBitContext *s, int n);

/* Bitstream reader API docs:
 * name
 *   arbitrary name which is used as prefix for the internal variables
 *
 * gb
 *   getbitcontext
 *
 * OPEN_READER(name, gb)
 *   load gb into local variables
 *
 * CLOSE_READER(name, gb)
 *   store local vars in gb
 *
 * UPDATE_CACHE(name, gb)
 *   Refill the internal cache from the bitstream.
 *   After this call at least MIN_CACHE_BITS will be available.
 *
 * GET_CACHE(name, gb)
 *   Will output the contents of the internal cache,
 *   next bit is MSB of 32 or 64 bits (FIXME 64 bits).
 *
 * SHOW_UBITS(name, gb, num)
 *   Will return the next num bits.
 *
 * SHOW_SBITS(name, gb, num)
 *   Will return the next num bits and do sign extension.
 *
 * SKIP_BITS(name, gb, num)
 *   Will skip over the next num bits.
 *   Note, this is equivalent to SKIP_CACHE; SKIP_COUNTER.
 *
 * SKIP_CACHE(name, gb, num)
 *   Will remove the next num bits from the cache (note SKIP_COUNTER
 *   MUST be called before UPDATE_CACHE / CLOSE_READER).
 *
 * SKIP_COUNTER(name, gb, num)
 *   Will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS).
 *
 * LAST_SKIP_BITS(name, gb, num)
 *   Like SKIP_BITS, to be used if next call is UPDATE_CACHE or CLOSE_READER.
 *
 * BITS_LEFT(name, gb)
 *   Return the number of bits left
 *
 * For examples see get_bits, show_bits, skip_bits, get_vlc.
 */

#if defined LONG_BITSTREAM_READER
#define MIN_CACHE_BITS
#else
#define MIN_CACHE_BITS
#endif

#define OPEN_READER_NOSIZE(name, gb)

#if UNCHECKED_BITSTREAM_READER
#define OPEN_READER

#define BITS_AVAILABLE
#else
#define OPEN_READER(name, gb)

#define BITS_AVAILABLE(name, gb)
#endif

#define CLOSE_READER(name, gb)

#define UPDATE_CACHE_BE_EXT(name, gb, bits, dst_bits)

#define UPDATE_CACHE_LE_EXT(name, gb, bits, dst_bits)

/* Using these two macros ensures that 32 bits are available. */
#define UPDATE_CACHE_LE_32(name, gb)

#define UPDATE_CACHE_BE_32(name, gb)

# ifdef LONG_BITSTREAM_READER

#define UPDATE_CACHE_LE

#define UPDATE_CACHE_BE

#else

#define UPDATE_CACHE_LE(name, gb)

#define UPDATE_CACHE_BE(name, gb)

#endif


#ifdef BITSTREAM_READER_LE

#define UPDATE_CACHE
#define UPDATE_CACHE_32

#define SKIP_CACHE

#else

#define UPDATE_CACHE(name, gb)
#define UPDATE_CACHE_32(name, gb)

#define SKIP_CACHE(name, gb, num)

#endif

#if UNCHECKED_BITSTREAM_READER
#define SKIP_COUNTER
#else
#define SKIP_COUNTER(name, gb, num)
#endif

#define BITS_LEFT(name, gb)

#define SKIP_BITS(name, gb, num)

#define LAST_SKIP_BITS(name, gb, num)

#define SHOW_UBITS_LE(name, gb, num)
#define SHOW_SBITS_LE(name, gb, num)

#define SHOW_UBITS_BE(name, gb, num)
#define SHOW_SBITS_BE(name, gb, num)

#ifdef BITSTREAM_READER_LE
#define SHOW_UBITS
#define SHOW_SBITS
#else
#define SHOW_UBITS(name, gb, num)
#define SHOW_SBITS(name, gb, num)
#endif

#define GET_CACHE(name, gb)


static inline int get_bits_count(const GetBitContext *s)
{}

/**
 * Skips the specified number of bits.
 * @param n the number of bits to skip,
 *          For the UNCHECKED_BITSTREAM_READER this must not cause the distance
 *          from the start to overflow int32_t. Staying within the bitstream + padding
 *          is sufficient, too.
 */
static inline void skip_bits_long(GetBitContext *s, int n)
{}

/**
 * Read MPEG-1 dc-style VLC (sign bit + mantissa with no MSB).
 * if MSB not set it is negative
 * @param n length in bits
 */
static inline int get_xbits(GetBitContext *s, int n)
{}

static inline int get_xbits_le(GetBitContext *s, int n)
{}

static inline int get_sbits(GetBitContext *s, int n)
{}

/**
 * Read 1-25 bits.
 */
static inline unsigned int get_bits(GetBitContext *s, int n)
{}

/**
 * Read 0-25 bits.
 */
static av_always_inline int get_bitsz(GetBitContext *s, int n)
{}

static inline unsigned int get_bits_le(GetBitContext *s, int n)
{}

/**
 * Show 1-25 bits.
 */
static inline unsigned int show_bits(GetBitContext *s, int n)
{}

static inline void skip_bits(GetBitContext *s, int n)
{}

static inline unsigned int get_bits1(GetBitContext *s)
{}

static inline unsigned int show_bits1(GetBitContext *s)
{}

static inline void skip_bits1(GetBitContext *s)
{}

/**
 * Read 0-32 bits.
 */
static inline unsigned int get_bits_long(GetBitContext *s, int n)
{}

/**
 * Read 0-64 bits.
 */
static inline uint64_t get_bits64(GetBitContext *s, int n)
{}

/**
 * Read 0-32 bits as a signed integer.
 */
static inline int get_sbits_long(GetBitContext *s, int n)
{}

/**
 * Read 0-64 bits as a signed integer.
 */
static inline int64_t get_sbits64(GetBitContext *s, int n)
{}

/**
 * Show 0-32 bits.
 */
static inline unsigned int show_bits_long(GetBitContext *s, int n)
{}


/**
 * Initialize GetBitContext.
 * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
 *        larger than the actual read bits because some optimized bitstream
 *        readers read 32 or 64 bit at once and could read over the end
 * @param bit_size the size of the buffer in bits
 * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
 */
static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
                                int bit_size)
{}

/**
 * Initialize GetBitContext.
 * @param buffer bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE bytes
 *        larger than the actual read bits because some optimized bitstream
 *        readers read 32 or 64 bit at once and could read over the end
 * @param byte_size the size of the buffer in bytes
 * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
 */
static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer,
                                 int byte_size)
{}

static inline int init_get_bits8_le(GetBitContext *s, const uint8_t *buffer,
                                    int byte_size)
{}

static inline const uint8_t *align_get_bits(GetBitContext *s)
{}

/**
 * If the vlc code is invalid and max_depth=1, then no bits will be removed.
 * If the vlc code is invalid and max_depth>1, then the number of bits removed
 * is undefined.
 */
#define GET_VLC(code, name, gb, table, bits, max_depth)

#define GET_RL_VLC(level, run, name, gb, table, bits,  \
                   max_depth, need_update)

/**
 * Parse a vlc code.
 * @param bits is the number of bits which will be read at once, must be
 *             identical to nb_bits in vlc_init()
 * @param max_depth is the number of times bits bits must be read to completely
 *                  read the longest vlc code
 *                  = (max_vlc_length + bits - 1) / bits
 * @returns the code parsed or -1 if no vlc matches
 */
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table,
                                     int bits, int max_depth)
{}

static inline int get_vlc_multi(GetBitContext *s, uint8_t *dst,
                                const VLC_MULTI_ELEM *const Jtable,
                                const VLCElem *const table,
                                const int bits, const int max_depth,
                                const int symbols_size)
{}

static inline int decode012(GetBitContext *gb)
{}

static inline int decode210(GetBitContext *gb)
{}

static inline int get_bits_left(GetBitContext *gb)
{}

static inline int skip_1stop_8data_bits(GetBitContext *gb)
{}

#endif // CACHED_BITSTREAM_READER

#endif /* AVCODEC_GET_BITS_H */