1 /* 2 * Copyright 2021 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 __AV1D_CODEC_H__ 18 #define __AV1D_CODEC_H__ 19 20 #include "mpp_frame.h" 21 22 #include "av1d_cbs.h" 23 #include "av1d_syntax.h" 24 #include "mpp_bitread.h" 25 26 typedef struct AV1ParseContext { 27 Av1UnitFragment temporal_unit; 28 int parsed_extradata; 29 } AV1ParseContext; 30 31 #define MPP_PARSER_PTS_NB 4 32 #define MAX_OBU_HEADER_SIZE (2 + 8) 33 34 typedef struct AV1OBU_T { 35 /** Size of payload */ 36 int size; 37 const uint8_t *data; 38 39 /** 40 * Size, in bits, of just the data, excluding the trailing_one_bit and 41 * any trailing padding. 42 */ 43 int size_bits; 44 45 /** Size of entire OBU, including header */ 46 int raw_size; 47 const uint8_t *raw_data; 48 49 /** GetBitContext initialized to the start of the payload */ 50 BitReadCtx_t gb; 51 52 int type; 53 54 int temporal_id; 55 int spatial_id; 56 } AV1OBU; 57 58 typedef struct SplitContext { 59 RK_U8 *buffer; 60 RK_U32 buffer_size; 61 RK_S32 index; 62 RK_S32 last_index; 63 RK_U32 state; ///< contains the last few bytes in MSB order 64 RK_S32 frame_start_found; 65 RK_S32 overread; ///< the number of bytes which where irreversibly read from the next frame 66 RK_S32 overread_index; ///< the index into ParseContext.buffer of the overread bytes 67 RK_U64 state64; ///< contains the last 8 bytes in MSB order 68 RK_S64 pts; /* pts of the current frame */ 69 RK_S64 dts; /* dts of the current frame */ 70 RK_S64 frame_offset; /* offset of the current frame */ 71 RK_S64 cur_offset; /* current offset 72 (incremented by each av_parser_parse()) */ 73 RK_S64 next_frame_offset; /* offset of the next frame */ 74 75 /* private data */ 76 void *priv_data; 77 RK_S64 last_pts; 78 RK_S64 last_dts; 79 RK_S32 fetch_timestamp; 80 81 RK_S32 cur_frame_start_index; 82 RK_S64 cur_frame_offset[MPP_PARSER_PTS_NB]; 83 RK_S64 cur_frame_pts[MPP_PARSER_PTS_NB]; 84 RK_S64 cur_frame_dts[MPP_PARSER_PTS_NB]; 85 86 RK_S64 offset; ///< byte offset from starting packet start 87 RK_S64 cur_frame_end[MPP_PARSER_PTS_NB]; 88 /** 89 * Set by parser to 1 for key frames and 0 for non-key frames. 90 * It is initialized to -1, so if the parser doesn't set this flag, 91 * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames 92 * will be used. 93 */ 94 RK_S32 key_frame; 95 RK_S32 eos; 96 RK_U32 frame_header; 97 } SplitContext_t; 98 99 typedef struct Av1CodecContext_t { 100 101 void *priv_data; /* Av1Context */ 102 void *priv_data2; /* SplitContext */ 103 104 MppFrameFormat pix_fmt; 105 MppFrameColorSpace colorspace; 106 MppFrameColorRange color_range; 107 MppFrameColorPrimaries color_primaries; 108 MppFrameColorTransferCharacteristic color_trc; 109 MppFrameChromaLocation chroma_sample_location; 110 111 RK_S32 width, height; 112 113 RK_S32 profile, level; 114 115 MppPacket pkt; 116 117 DXVA_PicParams_AV1 pic_params; 118 119 /* split info */ 120 RK_U32 frame_header; 121 RK_U32 new_frame; 122 RK_U8 *stream; 123 RK_U32 stream_size; 124 RK_U32 stream_offset; 125 126 RK_S32 eos; 127 MppFrameFormat usr_set_fmt; 128 } Av1CodecContext; 129 130 #endif /*__AV1D_CODEC_H__*/ 131