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