📄 bitreader.h
字号:
#ifndef _DECODER_BITREADER_H_
#define _DECODER_BITREADER_H_
#include "../global.h"
#include "decoder.h"
#define MARKER() bs_skip(bs, 1)
// header interpreter
// support B_VOP decoding
int bs_headers(Decoder * dec);
static void __inline bs_init(BitReader * const br, void * const bitstream, uint32_t length)
{
br->buf = br->ptr = (uint32_t*)bitstream;
br->pos = 0;
br->length = length;
br->curr = BSWAP(*br->ptr ++);
br->next = BSWAP(*br->ptr ++);
br->dec_err = 0;
}
// return the ammount of bytes used for decoding, ptr is for uint32_t *
static __inline uint32_t bs_length(BitReader * const br)
{
return ((br->ptr - br->buf)<<2) - 4 - ((32 - br->pos) >> 3);
}
static __inline uint32_t bs_show(BitReader * const br, const uint32_t bits)
{
int32_t nbit = (int32_t)(bits + br->pos) - 32;
if (nbit > 0)
{
return ((br->curr & (0xffffffff >> br->pos)) << nbit) |
(br->next >> (32 - nbit));
}
else
{
return (br->curr & (0xffffffff >> br->pos)) >> (32 - br->pos - bits);
}
}
static __inline void bs_skip(BitReader * const br, const uint32_t bits)
{
br->pos += bits;
if (br->pos > 31)
{
uint32_t consumed;
br->curr = br->next;
br->next = BSWAP(*br->ptr++);
br->pos -= 32;
consumed = bs_length(br);
if(consumed > br->length)
{
br->dec_err = 1; // set error flag for detection of decoder
}
}
}
static __inline void bs_bytealign(BitReader * const br)
{
uint32_t remained = br->pos & 7;
if (remained)
bs_skip(br, 8 - remained);
}
static __inline uint32_t bs_get(BitReader * const br, const uint32_t n)
{
register uint32_t val;
val = bs_show(br, n);
bs_skip(br, n);
return val;
}
static __inline uint32_t bs_get1(BitReader * const br)
{
return bs_get(br, 1);
}
#endif /* _DECODER_BITREADER_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -