mirror of
https://github.com/nyanmisaka/mpp.git
synced 2025-10-07 18:11:02 +08:00
[mpp_bitput]optimize mpp_bitput function to reduce cpu used
git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@736 6e48237b-75ef-9749-8fc9-41990f28c85a
This commit is contained in:
@@ -16,64 +16,46 @@
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "mpp_bitput.h"
|
||||
|
||||
static RK_U64 mpp_get_bits(RK_U64 src, RK_S32 size, RK_S32 offset)
|
||||
{
|
||||
RK_S32 i;
|
||||
RK_U64 temp = 0;
|
||||
|
||||
mpp_assert(size + offset <= 64);// 64 is the FIFO_BIT_WIDTH
|
||||
|
||||
for (i = 0; i < size ; i++) {
|
||||
temp <<= 1;
|
||||
temp |= 1;
|
||||
}
|
||||
temp &= (src >> offset);
|
||||
temp <<= offset;
|
||||
return temp;
|
||||
}
|
||||
|
||||
RK_S32 mpp_set_bitput_ctx(BitputCtx_t *bp, RK_U64 *data, RK_U32 len)
|
||||
{
|
||||
memset(bp, 0, sizeof(BitputCtx_t));
|
||||
bp->bit_buf = data;
|
||||
bp->total_len = len;
|
||||
bp->index = 0;
|
||||
bp->bitpos = 0;
|
||||
bp->bvalue = 0;
|
||||
bp->size = len;
|
||||
bp->buflen = len; // align 64bit
|
||||
bp->pbuf = data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mpp_put_bits(BitputCtx_t *bp, RK_U64 data, RK_S32 size)
|
||||
void mpp_put_bits(BitputCtx_t *bp, RK_U64 invalue, RK_S32 lbits)
|
||||
{
|
||||
// h265h_dbg(H265H_DBG_RPS , "_count = %d value = %d", _count++, (RK_U32)data);
|
||||
if (bp->p_uint_index >= bp->total_len) return;
|
||||
if (size + bp->p_bit_offset >= 64) { // 64 is the FIFO_BIT_WIDTH
|
||||
RK_S32 len = 64 - bp->p_bit_offset;
|
||||
bp->bit_buf[bp->p_uint_index] = (mpp_get_bits(data, len, 0) << bp->p_bit_offset) |
|
||||
mpp_get_bits( bp->bit_buf[bp->p_uint_index], bp->p_bit_offset, 0);
|
||||
bp->p_uint_index++;
|
||||
if (bp->p_uint_index > bp->total_len) bp->p_uint_index = 0;
|
||||
RK_U8 hbits = 0;
|
||||
|
||||
bp->bit_buf[bp->p_uint_index] = (mpp_get_bits(data, size - len, len) >> len);
|
||||
bp->p_bit_offset = size + bp->p_bit_offset - 64; // 64 is the FIFO_BIT_WIDTH
|
||||
if (!lbits) return;
|
||||
|
||||
} else {
|
||||
bp->bit_buf[bp->p_uint_index] = ((data << (64 - size)) >> (64 - size - bp->p_bit_offset)) |
|
||||
mpp_get_bits( bp->bit_buf[bp->p_uint_index], bp->p_bit_offset, 0);
|
||||
bp->p_bit_offset += size;
|
||||
if (bp->index >= bp->buflen) return;
|
||||
|
||||
hbits = 64 - lbits;
|
||||
invalue = (invalue << hbits) >> hbits;
|
||||
bp->bvalue |= invalue << bp->bitpos; // high bits value
|
||||
if ((bp->bitpos + lbits) >= 64) {
|
||||
bp->pbuf[bp->index] = bp->bvalue;
|
||||
bp->bvalue = invalue >> (64 - bp->bitpos); // low bits value
|
||||
bp->index++;
|
||||
}
|
||||
bp->p_bit_len += size;
|
||||
bp->pbuf[bp->index] = bp->bvalue;
|
||||
bp->bitpos = (bp->bitpos + lbits) & 63;
|
||||
// mpp_log("bp->index = %d bp->bitpos = %d lbits = %d invalue 0x%x bp->hvalue 0x%x bp->lvalue 0x%x",bp->index,bp->bitpos,lbits, (RK_U32)invalue,(RK_U32)(bp->bvalue >> 32),(RK_U32)bp->bvalue);
|
||||
}
|
||||
|
||||
void mpp_align(BitputCtx_t *bp, RK_S32 align_width, int flag)
|
||||
void mpp_align(BitputCtx_t *bp, RK_S32 align_bits, int flag)
|
||||
{
|
||||
RK_S32 len = 0;
|
||||
RK_S32 word_offset = 0;
|
||||
RK_U32 word_offset = 0, len = 0;
|
||||
|
||||
if (bp->p_uint_index >= bp->total_len) return;
|
||||
|
||||
word_offset = align_width >= 64 ? (bp->p_uint_index & (((align_width & 0xfe0) >> 6) - 1)) * 64 : 0;
|
||||
len = (align_width - (word_offset + (bp->p_bit_offset % align_width ))) % align_width ;
|
||||
|
||||
while (len > 0) { //.len > 0)
|
||||
word_offset = (align_bits >= 64) ? ((bp->index & (((align_bits & 0xfe0) >> 6) - 1)) << 6) : 0;
|
||||
len = (align_bits - (word_offset + (bp->bitpos % align_bits))) % align_bits;
|
||||
while (len > 0) {
|
||||
if (len >= 8) {
|
||||
if (flag == 0)
|
||||
mpp_put_bits(bp, ((RK_U64)0 << (64 - 8)) >> (64 - 8), 8);
|
||||
@@ -89,3 +71,4 @@ void mpp_align(BitputCtx_t *bp, RK_S32 align_width, int flag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -23,30 +23,23 @@
|
||||
#include "mpp_common.h"
|
||||
#include "mpp_err.h"
|
||||
|
||||
|
||||
typedef struct bitput_ctx_t {
|
||||
// Pointer to the start of put address
|
||||
RK_U64 *bit_buf;
|
||||
|
||||
// Pointer to current wite address offset (8 Byte as uint)
|
||||
RK_S32 p_uint_index;
|
||||
|
||||
// Pointer to bit alreay write in uint
|
||||
RK_S32 p_bit_offset;
|
||||
|
||||
// total bit have write
|
||||
RK_S32 p_bit_len;
|
||||
|
||||
// total len of the region to write
|
||||
RK_S32 total_len;
|
||||
RK_U32 buflen; //!< max buf length, 64bit uint
|
||||
RK_U32 index; //!< current uint position
|
||||
RK_U64 *pbuf; //!< outpacket data
|
||||
RK_U64 bvalue; //!< buffer value, 64 bit
|
||||
RK_U8 bitpos; //!< bit pos in 64bit
|
||||
RK_U32 size; //!< data size,except header
|
||||
} BitputCtx_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
RK_S32 mpp_set_bitput_ctx(BitputCtx_t *bp, RK_U64 *data, RK_U32 len);
|
||||
void mpp_put_bits(BitputCtx_t *bp, RK_U64 data, RK_S32 size);
|
||||
void mpp_align(BitputCtx_t *bp, RK_S32 align_width, int flag);
|
||||
void mpp_put_bits(BitputCtx_t *bp, RK_U64 invalue, RK_S32 lbits);
|
||||
void mpp_align(BitputCtx_t *bp, RK_S32 align_bits, int flag);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user