hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright 2015 - 2017 Rockchip Electronics Co. LTD
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#ifndef __MPP_BITWRITER_H__
#define __MPP_BITWRITER_H__
 
#include "rk_type.h"
#include "mpp_err.h"
 
/*
 * Mpp bitstream writer for H.264/H.265
 */
typedef struct MppWriteCtx_t {
    RK_U8 *buffer;          /* point to first byte of stream */
    RK_U8 *stream;          /* Pointer to next byte of stream */
    RK_U32 size;            /* Byte size of stream buffer */
    RK_U32 byte_cnt;        /* Byte counter */
    RK_U32 byte_buffer;     /* Byte buffer */
    RK_U32 buffered_bits;   /* Amount of bits in byte buffer, [0-7] */
    RK_U32 zero_bytes;      /* Amount of consecutive zero bytes */
    RK_S32 overflow;        /* This will signal a buffer overflow */
    RK_U32 emul_cnt;        /* Counter for emulation_3_byte, needed in SEI */
} MppWriteCtx;
 
MPP_RET mpp_writer_init(MppWriteCtx *ctx, void *p, RK_S32 size);
MPP_RET mpp_writer_reset(MppWriteCtx *ctx);
 
/* check overflow status */
MPP_RET mpp_writer_status(MppWriteCtx *ctx);
/* write bit in last byte to memory */
void mpp_writer_flush(MppWriteCtx *ctx);
 
/* write raw bit without emulation prevention 0x03 byte */
void mpp_writer_put_raw_bits(MppWriteCtx *ctx, RK_S32 val, RK_S32 len);
 
/* write bit with emulation prevention 0x03 byte */
void mpp_writer_put_bits(MppWriteCtx *ctx, RK_S32 val, RK_S32 len);
 
/* insert zero bits until byte-aligned */
void mpp_writer_align_zero(MppWriteCtx *ctx);
 
/* insert one bits until byte-aligned */
void mpp_writer_align_one(MppWriteCtx *ctx);
 
/* insert one bit then pad to byte-align with zero */
void mpp_writer_trailing(MppWriteCtx * ctx);
 
void mpp_writer_put_ue(MppWriteCtx *ctx, RK_U32 val);
void mpp_writer_put_se(MppWriteCtx *ctx, RK_S32 val);
 
RK_S32 mpp_writer_bytes(MppWriteCtx *ctx);
RK_S32 mpp_writer_bits(MppWriteCtx *ctx);
 
RK_S32 mpp_exp_golomb_signed(RK_S32 val);
 
#endif /* __MPP_BITWRITER_H__ */