ffmpeg解析SPS PPS部分代码

/* 获取一个bit位*/
//index 表示要获取的bit位下标
static inline unsigned int get_bits1(GetBitContext *s)
{
    unsigned int index = s->index;
    //获取index所在的byte
    uint8_t result     = s->buffer[index >> 3];
#ifdef BITSTREAM_READER_LE //没有定义
    result >>= index & 7;
    result  &= 1;
#else
    result <<= index & 7; //左移index(index<7)位
    result >>= 8 - 1; //右移7位
#endif
#if !UNCHECKED_BITSTREAM_READER
    if (s->index < s->size_in_bits_plus8)
#endif
        index++;
    s->index = index;

    return result;
}
/*获取n个bit位的值*/
static inline unsigned int get_bits(GetBitContext *s, int n)
{
    register unsigned int tmp;
    OPEN_READER(re, s);
    av_assert2(n>0 && n<=25);
    UPDATE_CACHE(re, s);
    tmp = SHOW_UBITS(re, s, n);
    LAST_SKIP_BITS(re, s, n);
    CLOSE_READER(re, s);
    av_assert2(tmp < UINT64_C(1) << n);
    return tmp;
}
//展开后
#define AV_BSWAP16C(x) (((x) << 8 & 0xff00)  | ((x) >> 8 & 0x00ff))
#define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16))

static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
{
    return AV_BSWAP32C(x);
}

#define NEG_USR32 NEG_USR32
static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
    __asm__ ("shrl %1, %0\n\t"
         : "+r" (a)
         : "ic" ((uint8_t)(-s))
    );
    return a;
}
or
#ifndef NEG_USR32
#   define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
#endif

static inline unsigned int get_bits(GetBitContext *s, int n)
{
	register unsigned int tmp;
	// OPEN_READER(re, s);
	unsigned int re_index = (s)->index; 
	unsigned int __attribute__((unused)) re_cache;
	unsigned int re_size_plus8 = (s)->size_in_bits_plus8;

	av_assert2(n>0 && n<=25);
	
	//UPDATE_CACHE(re, s);
	//将8位的buffer扩展为32位的re_cache,扩展中需要将高低位对调
	re_cache = av_bswap32((((const union unaligned_32 *) ((s)->buffer + (re_index >> 3)))->l)) << (re_index & 7);
	// tmp = SHOW_UBITS(re, s, n);
	//右移n位
	NEG_USR32(re_cache, n);

	//LAST_SKIP_BITS(re, s, n);
	re_index = ((re_size_plus8) > (re_index + (n)) ? (re_index + (n)) : (re_size_plus8));

	//CLOSE_READER(re, s);
	(s)->index = re_index;
	
	//UINT64_C(1) = 1UL
	av_assert2(tmp < UINT64_C(1) << n);
    return tmp;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值