[av1d]: Add av1 parser api

Change-Id: Iff3c205d34cd8d8c2074de42eadc8418f5144a42
Signed-off-by: sayon.chen <sayon.chen@rock-chips.com>
This commit is contained in:
sayon.chen
2021-03-24 11:21:25 +08:00
committed by Herman Chen
parent 3d0f65b356
commit 55b425c97b
21 changed files with 11438 additions and 0 deletions

View File

@@ -100,6 +100,7 @@ typedef enum {
MPP_VIDEO_CodingAVSPLUS, /**< AVS+ */
MPP_VIDEO_CodingAVS, /**< AVS profile=0x20 */
MPP_VIDEO_CodingAVS2, /**< AVS2 */
MPP_VIDEO_CodingAV1, /**< av1 */
MPP_VIDEO_CodingKhronosExtensions = 0x6F000000, /**< Reserved region for introducing Khronos Standard Extensions */
MPP_VIDEO_CodingVendorStartUnused = 0x7F000000, /**< Reserved region for introducing Vendor Extensions */
MPP_VIDEO_CodingMax = 0x7FFFFFFF

View File

@@ -32,6 +32,7 @@ target_link_libraries(mpp_codec
${CODEC_VP8D}
${CODEC_VP9D}
${CODEC_JPEGD}
${CODEC_AV1D}
${CODEC_H264E}
${CODEC_JPEGE}
${CODEC_H265E}

View File

@@ -37,3 +37,7 @@ endif()
if( HAVE_JPEGD )
add_subdirectory(jpeg)
endif()
if( HAVE_AV1D )
add_subdirectory(av1)
endif()

View File

@@ -0,0 +1,30 @@
# vim: syntax=cmake
include_directories(.)
# av1 decoder api
set(AV1_D_API
../../inc/av1d_api.h
)
# AV1 decoder header
set(AV1D_HDR
)
# av1 decoder sourse
set(AV1D_SRC
av1d_api.c
av1d_parser.c
av1d_parser2_syntax.c
av1d_cbs.c
av1d_probs.c
av1_entropymode.c
)
add_library(${CODEC_AV1D} STATIC
${AV1D_API}
${AV1D_HDR}
${AV1D_SRC}
)
target_link_libraries(${CODEC_AV1D} mpp_base)
set_target_properties(${CODEC_AV1D} PROPERTIES FOLDER "mpp/codec")

169
mpp/codec/dec/av1/av1.h Normal file
View File

@@ -0,0 +1,169 @@
/*
* Copyright 2021 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 __AV1_H__
#define __AV1_H__
// OBU types (section 6.2.2).
typedef enum {
// 0 reserved.
AV1_OBU_SEQUENCE_HEADER = 1,
AV1_OBU_TEMPORAL_DELIMITER = 2,
AV1_OBU_FRAME_HEADER = 3,
AV1_OBU_TILE_GROUP = 4,
AV1_OBU_METADATA = 5,
AV1_OBU_FRAME = 6,
AV1_OBU_REDUNDANT_FRAME_HEADER = 7,
AV1_OBU_TILE_LIST = 8,
// 9-14 reserved.
AV1_OBU_PADDING = 15,
} AV1_OBU_Type;
// Metadata types (section 6.7.1).
enum {
AV1_METADATA_TYPE_HDR_CLL = 1,
AV1_METADATA_TYPE_HDR_MDCV = 2,
AV1_METADATA_TYPE_SCALABILITY = 3,
AV1_METADATA_TYPE_ITUT_T35 = 4,
AV1_METADATA_TYPE_TIMECODE = 5,
};
// Frame types (section 6.8.2).
enum {
AV1_FRAME_KEY = 0,
AV1_FRAME_INTER = 1,
AV1_FRAME_INTRA_ONLY = 2,
AV1_FRAME_SWITCH = 3,
};
// Reference frames (section 6.10.24).
enum {
AV1_REF_FRAME_INTRA = 0,
AV1_REF_FRAME_LAST = 1,
AV1_REF_FRAME_LAST2 = 2,
AV1_REF_FRAME_LAST3 = 3,
AV1_REF_FRAME_GOLDEN = 4,
AV1_REF_FRAME_BWDREF = 5,
AV1_REF_FRAME_ALTREF2 = 6,
AV1_REF_FRAME_ALTREF = 7,
};
// Constants (section 3).
enum {
AV1_MAX_OPERATING_POINTS = 32,
AV1_MAX_SB_SIZE = 128,
AV1_MI_SIZE = 4,
AV1_MAX_TILE_WIDTH = 4096,
AV1_MAX_TILE_AREA = 4096 * 2304,
AV1_MAX_TILE_ROWS = 64,
AV1_MAX_TILE_COLS = 64,
AV1_NUM_REF_FRAMES = 8,
AV1_REFS_PER_FRAME = 7,
AV1_TOTAL_REFS_PER_FRAME = 8,
AV1_PRIMARY_REF_NONE = 7,
AV1_MAX_SEGMENTS = 8,
AV1_SEG_LVL_MAX = 8,
AV1_SEG_LVL_ALT_Q = 0,
AV1_SEG_LVL_ALT_LF_Y_V = 1,
AV1_SEG_LVL_REF_FRAME = 5,
AV1_SEG_LVL_SKIP = 6,
AV1_SEG_LVL_GLOBAL_MV = 7,
AV1_SELECT_SCREEN_CONTENT_TOOLS = 2,
AV1_SELECT_INTEGER_MV = 2,
AV1_SUPERRES_NUM = 8,
AV1_SUPERRES_DENOM_MIN = 9,
AV1_INTERPOLATION_FILTER_SWITCHABLE = 4,
AV1_GM_ABS_ALPHA_BITS = 12,
AV1_GM_ALPHA_PREC_BITS = 15,
AV1_GM_ABS_TRANS_ONLY_BITS = 9,
AV1_GM_TRANS_ONLY_PREC_BITS = 3,
AV1_GM_ABS_TRANS_BITS = 12,
AV1_GM_TRANS_PREC_BITS = 6,
AV1_WARPEDMODEL_PREC_BITS = 16,
AV1_WARP_MODEL_IDENTITY = 0,
AV1_WARP_MODEL_TRANSLATION = 1,
AV1_WARP_MODEL_ROTZOOM = 2,
AV1_WARP_MODEL_AFFINE = 3,
};
// The main colour configuration information uses the same ISO/IEC 23001-8
// (H.273) enums as FFmpeg does, so separate definitions are not required.
// Chroma sample position.
enum {
AV1_CSP_UNKNOWN = 0,
AV1_CSP_VERTICAL = 1, // -> AVCHROMA_LOC_LEFT.
AV1_CSP_COLOCATED = 2, // -> AVCHROMA_LOC_TOPLEFT.
};
// Scalability modes (section 6.7.5)
enum {
AV1_SCALABILITY_L1T2 = 0,
AV1_SCALABILITY_L1T3 = 1,
AV1_SCALABILITY_L2T1 = 2,
AV1_SCALABILITY_L2T2 = 3,
AV1_SCALABILITY_L2T3 = 4,
AV1_SCALABILITY_S2T1 = 5,
AV1_SCALABILITY_S2T2 = 6,
AV1_SCALABILITY_S2T3 = 7,
AV1_SCALABILITY_L2T1h = 8,
AV1_SCALABILITY_L2T2h = 9,
AV1_SCALABILITY_L2T3h = 10,
AV1_SCALABILITY_S2T1h = 11,
AV1_SCALABILITY_S2T2h = 12,
AV1_SCALABILITY_S2T3h = 13,
AV1_SCALABILITY_SS = 14,
AV1_SCALABILITY_L3T1 = 15,
AV1_SCALABILITY_L3T2 = 16,
AV1_SCALABILITY_L3T3 = 17,
AV1_SCALABILITY_S3T1 = 18,
AV1_SCALABILITY_S3T2 = 19,
AV1_SCALABILITY_S3T3 = 20,
AV1_SCALABILITY_L3T2_KEY = 21,
AV1_SCALABILITY_L3T3_KEY = 22,
AV1_SCALABILITY_L4T5_KEY = 23,
AV1_SCALABILITY_L4T7_KEY = 24,
AV1_SCALABILITY_L3T2_KEY_SHIFT = 25,
AV1_SCALABILITY_L3T3_KEY_SHIFT = 26,
AV1_SCALABILITY_L4T5_KEY_SHIFT = 27,
AV1_SCALABILITY_L4T7_KEY_SHIFT = 28,
};
// Frame Restoration types (section 6.10.15)
enum {
AV1_RESTORE_NONE = 0,
AV1_RESTORE_WIENER = 1,
AV1_RESTORE_SGRPROJ = 2,
AV1_RESTORE_SWITCHABLE = 3,
};
#define PROFILE_AV1_MAIN 0
#define PROFILE_AV1_HIGH 1
#define PROFILE_AV1_PROFESSIONAL 2
#define AV1_MAX_TILES 128
#endif /*__AV1_H__ */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,75 @@
/*
* Copyright 2021 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 AV1_ENTROPYMODE_H_
#define AV1_ENTROPYMODE_H_
#include "av1d_common.h"
#define DEFAULT_COMP_INTRA_PROB 32
#define AV1_DEF_INTERINTRA_PROB 248
#define AV1_UPD_INTERINTRA_PROB 192
#define SEPARATE_INTERINTRA_UV 0
typedef RK_U8 av1_prob;
extern const RK_S8 av1hwd_intra_mode_tree[];
extern const av1_prob av1_kf_default_bmode_probs[AV1_INTRA_MODES]
[AV1_INTRA_MODES]
[AV1_INTRA_MODES - 1];
extern const RK_S8 av1hwd_intra_mode_tree[];
extern const RK_S8 av1_sb_mv_ref_tree[];
/* probability models for partition information */
extern const RK_S8 av1hwd_partition_tree[];
// extern struct av1_token av1_partition_encodings[PARTITION_TYPES];
// extern const av1_prob av1_partition_probs[NUM_FRAME_TYPES]
// [NUM_PARTITION_CONTEXTS]
// [PARTITION_TYPES];
void Av1EntropyModeInit(void);
void AV1SetDefaultCDFs(AV1CDFs *cdfs, MvCDFs *cdfs_ndvc);
void Av1DefaultCoeffProbs(RK_U32 base_qindex, void *ptr);
struct AV1Common;
// void Av1InitMbmodeProbs(struct Av1Decoder *x);
// extern void Av1InitModeContexts(struct Av1Decoder *pc);
extern const enum InterpolationFilterType av1hwd_switchable_interp[AV1_SWITCHABLE_FILTERS];
extern const int av1hwd_switchable_interp_map[SWITCHABLE + 1];
extern const RK_S8 av1hwd_switchable_interp_tree[2 * (AV1_SWITCHABLE_FILTERS - 1)];
// extern struct av1_token av1hwd_switchable_interp_encodings[AV1_SWITCHABLE_FILTERS];
extern const av1_prob av1hwd_switchable_interp_prob[AV1_SWITCHABLE_FILTERS + 1][AV1_SWITCHABLE_FILTERS - 1];
extern const av1_prob av1_default_tx_probs_32x32p[TX_SIZE_CONTEXTS] [TX_SIZE_MAX_SB - 1];
extern const av1_prob av1_default_tx_probs_16x16p[TX_SIZE_CONTEXTS] [TX_SIZE_MAX_SB - 2];
extern const av1_prob av1_default_tx_probs_8x8p[TX_SIZE_CONTEXTS] [TX_SIZE_MAX_SB - 3];
extern const av1_prob av1_default_intra_ext_tx_prob[EXT_TX_SIZES][TX_TYPES] [TX_TYPES - 1];
extern const av1_prob av1_default_inter_ext_tx_prob[EXT_TX_SIZES][TX_TYPES - 1];
extern const RK_S8 av1_segment_tree[];
#endif

View File

@@ -0,0 +1,253 @@
/*
* Copyright 2015 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.
*/
#define MODULE_TAG "av1d_api"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mpp_mem.h"
#include "mpp_log.h"
#include "mpp_packet_impl.h"
#include "av1d_codec.h"
#include "av1d_parser.h"
#include "av1d_api.h"
/*!
***********************************************************************
* \brief
* alloc all buffer
***********************************************************************
*/
MPP_RET av1d_init(void *ctx, ParserCfg *init)
{
MPP_RET ret = MPP_OK;
RK_U8 *buf = NULL;
RK_S32 size = SZ_512K;
Av1CodecContext *av1_ctx = (Av1CodecContext *)ctx;
if (!av1_ctx || !init) {
mpp_err("av1d init fail");
return MPP_ERR_NULL_PTR;
}
av1_ctx->pix_fmt = MPP_FMT_BUTT;
if ((ret = av1d_parser_init(av1_ctx, init)) != MPP_OK)
goto _err_exit;
if ((ret = av1d_split_init(av1_ctx)) != MPP_OK)
goto _err_exit;
buf = mpp_malloc(RK_U8, size);
if (!buf) {
mpp_err("av1d init malloc stream buffer fail");
ret = MPP_ERR_NOMEM;
goto _err_exit;
}
if ((ret = mpp_packet_init(&av1_ctx->pkt, (void *)buf, size)) != MPP_OK)
goto _err_exit;
return ret;
_err_exit:
av1d_deinit(av1_ctx);
return ret;
}
/*!
***********************************************************************
* \brief
* free all buffer
***********************************************************************
*/
MPP_RET av1d_deinit(void *ctx)
{
RK_U8 *buf = NULL;
Av1CodecContext *av1_ctx = (Av1CodecContext *)ctx;
if (av1_ctx) {
av1d_parser_deinit(av1_ctx);
av1d_split_deinit(av1_ctx);
if (av1_ctx->pkt) {
buf = mpp_packet_get_data(av1_ctx->pkt);
MPP_FREE(buf);
mpp_packet_deinit(&av1_ctx->pkt);
}
}
return MPP_OK;
}
/*!
***********************************************************************
* \brief
* reset
***********************************************************************
*/
MPP_RET av1d_reset(void *ctx)
{
MPP_RET ret = MPP_ERR_UNKNOW;
Av1CodecContext *av1_ctx = (Av1CodecContext *)ctx;
av1d_paser_reset(av1_ctx);
return ret = MPP_OK;
}
/*!
***********************************************************************
* \brief
* flush
***********************************************************************
*/
MPP_RET av1d_flush(void *ctx)
{
MPP_RET ret = MPP_ERR_UNKNOW;
(void)ctx;
return ret = MPP_OK;
}
/*!
***********************************************************************
* \brief
* prepare
***********************************************************************
*/
MPP_RET av1d_prepare(void *ctx, MppPacket pkt, HalDecTask *task)
{
MPP_RET ret = MPP_OK;
Av1CodecContext *av1_ctx = (Av1CodecContext *)ctx;
SplitContext_t *ps = (SplitContext_t *)av1_ctx->priv_data2;
AV1Context *s = (AV1Context *)av1_ctx->priv_data;
RK_S64 pts = -1;
RK_S64 dts = -1;
RK_U8 *buf = NULL;
RK_S32 length = 0;
RK_U8 *out_data = NULL;
RK_S32 out_size = -1;
RK_S32 consumed = 0;
RK_U8 *pos = NULL;
task->valid = 0;
pts = mpp_packet_get_pts(pkt);
dts = mpp_packet_get_dts(pkt);
av1_ctx->eos = mpp_packet_get_eos(pkt);
buf = pos = mpp_packet_get_pos(pkt);
length = (RK_S32)mpp_packet_get_length(pkt);
if (mpp_packet_get_flag(pkt)& MPP_PACKET_FLAG_EXTRA_DATA) {
s->extra_has_frame = 0;
task = NULL;
s->current_obu.data = buf;
s->current_obu.data_size = length;
ret = mpp_av1_split_fragment(s, &s->current_obu, 1);
if (ret < 0) {
return ret;
}
ret = mpp_av1_read_fragment_content(s, &s->current_obu);
if (ret < 0) {
return ret;
}
if (!s->sequence_header) {
goto end;
}
ret = mpp_av1_set_context_with_sequence(av1_ctx, s->sequence_header);
end:
pos = buf + length;
mpp_packet_set_pos(pkt, pos);
mpp_av1_fragment_reset(&s->current_obu);
return ret;
}
consumed = av1d_split_frame(ps, &out_data, &out_size, buf, length);
pos += (consumed >= 0) ? consumed : length;
mpp_packet_set_pos(pkt, pos);
av1d_dbg(AV1D_DBG_STRMIN, "pkt_len=%d, pts=%lld , out_size %d \n", length, pts, out_size);
if (out_size > 0) {
av1d_get_frame_stream(av1_ctx, out_data, out_size);
task->input_packet = av1_ctx->pkt;
task->valid = 1;
mpp_packet_set_pts(av1_ctx->pkt, pts);
mpp_packet_set_dts(av1_ctx->pkt, dts);
task->flags.eos = av1_ctx->eos;
} else {
task->valid = 0;
task->flags.eos = av1_ctx->eos;
}
(void)pts;
(void)dts;
(void)task;
return ret = MPP_OK;
}
/*!
***********************************************************************
* \brief
* parser
***********************************************************************
*/
MPP_RET av1d_parser(void *ctx, HalDecTask *in_task)
{
Av1CodecContext *av1_ctx = (Av1CodecContext *)ctx;
MPP_RET ret = MPP_OK;
av1d_parser_frame(av1_ctx, in_task);
return ret;
}
/*!
***********************************************************************
* \brief
* callback
***********************************************************************
*/
MPP_RET av1d_callback(void *decoder, void *info)
{
MPP_RET ret = MPP_ERR_UNKNOW;
Av1CodecContext *av1_ctx = (Av1CodecContext *)decoder;
av1d_parser_update(av1_ctx, info);
return ret = MPP_OK;
}
/*!
***********************************************************************
* \brief
* api struct interface
***********************************************************************
*/
const ParserApi api_av1d_parser = {
.name = "av1d_parse",
.coding = MPP_VIDEO_CodingAV1,
.ctx_size = sizeof(Av1CodecContext),
.flag = 0,
.init = av1d_init,
.deinit = av1d_deinit,
.prepare = av1d_prepare,
.parse = av1d_parser,
.reset = av1d_reset,
.flush = av1d_flush,
.control = NULL,
.callback = av1d_callback,
};

2932
mpp/codec/dec/av1/av1d_cbs.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,446 @@
/*
* Copyright 2021 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 __AV1D_CBS_H__
#define __AV1D_CBS_H__
#include "av1.h"
typedef struct AV1RawOBUHeader {
RK_U8 obu_forbidden_bit;
RK_U8 obu_type;
RK_U8 obu_extension_flag;
RK_U8 obu_has_size_field;
RK_U8 obu_reserved_1bit;
RK_U8 temporal_id;
RK_U8 spatial_id;
RK_U8 extension_header_reserved_3bits;
} AV1RawOBUHeader;
typedef struct AV1RawColorConfig {
RK_U8 high_bitdepth;
RK_U8 twelve_bit;
RK_U8 mono_chrome;
RK_U8 color_description_present_flag;
RK_U8 color_primaries;
RK_U8 transfer_characteristics;
RK_U8 matrix_coefficients;
RK_U8 color_range;
RK_U8 subsampling_x;
RK_U8 subsampling_y;
RK_U8 chroma_sample_position;
RK_U8 separate_uv_delta_q;
} AV1RawColorConfig;
typedef struct AV1RawTimingInfo {
RK_U32 num_units_in_display_tick;
RK_U32 time_scale;
RK_U8 equal_picture_interval;
RK_U32 num_ticks_per_picture_minus_1;
} AV1RawTimingInfo;
typedef struct AV1RawDecoderModelInfo {
RK_U8 buffer_delay_length_minus_1;
RK_U32 num_units_in_decoding_tick;
RK_U8 buffer_removal_time_length_minus_1;
RK_U8 frame_presentation_time_length_minus_1;
} AV1RawDecoderModelInfo;
typedef struct AV1RawSequenceHeader {
RK_U8 seq_profile;
RK_U8 still_picture;
RK_U8 reduced_still_picture_header;
RK_U8 timing_info_present_flag;
RK_U8 decoder_model_info_present_flag;
RK_U8 initial_display_delay_present_flag;
RK_U8 operating_points_cnt_minus_1;
AV1RawTimingInfo timing_info;
AV1RawDecoderModelInfo decoder_model_info;
RK_U16 operating_point_idc[AV1_MAX_OPERATING_POINTS];
RK_U8 seq_level_idx[AV1_MAX_OPERATING_POINTS];
RK_U8 seq_tier[AV1_MAX_OPERATING_POINTS];
RK_U8 decoder_model_present_for_this_op[AV1_MAX_OPERATING_POINTS];
RK_U32 decoder_buffer_delay[AV1_MAX_OPERATING_POINTS];
RK_U32 encoder_buffer_delay[AV1_MAX_OPERATING_POINTS];
RK_U8 low_delay_mode_flag[AV1_MAX_OPERATING_POINTS];
RK_U8 initial_display_delay_present_for_this_op[AV1_MAX_OPERATING_POINTS];
RK_U8 initial_display_delay_minus_1[AV1_MAX_OPERATING_POINTS];
RK_U8 frame_width_bits_minus_1;
RK_U8 frame_height_bits_minus_1;
RK_U16 max_frame_width_minus_1;
RK_U16 max_frame_height_minus_1;
RK_U8 frame_id_numbers_present_flag;
RK_U8 delta_frame_id_length_minus_2;
RK_U8 additional_frame_id_length_minus_1;
RK_U8 use_128x128_superblock;
RK_U8 enable_filter_intra;
RK_U8 enable_intra_edge_filter;
RK_U8 enable_interintra_compound;
RK_U8 enable_masked_compound;
RK_U8 enable_warped_motion;
RK_U8 enable_dual_filter;
RK_U8 enable_order_hint;
RK_U8 enable_jnt_comp;
RK_U8 enable_ref_frame_mvs;
RK_U8 seq_choose_screen_content_tools;
RK_U8 seq_force_screen_content_tools;
RK_U8 seq_choose_integer_mv;
RK_U8 seq_force_integer_mv;
RK_U8 order_hint_bits_minus_1;
RK_U8 enable_superres;
RK_U8 enable_cdef;
RK_U8 enable_restoration;
AV1RawColorConfig color_config;
RK_U8 film_grain_params_present;
} AV1RawSequenceHeader;
typedef struct AV1RawFilmGrainParams {
RK_U8 apply_grain;
RK_U16 grain_seed;
RK_U8 update_grain;
RK_U8 film_grain_params_ref_idx;
RK_U8 num_y_points;
RK_U8 point_y_value[14];
RK_U8 point_y_scaling[14];
RK_U8 chroma_scaling_from_luma;
RK_U8 num_cb_points;
RK_U8 point_cb_value[10];
RK_U8 point_cb_scaling[10];
RK_U8 num_cr_points;
RK_U8 point_cr_value[10];
RK_U8 point_cr_scaling[10];
RK_U8 grain_scaling_minus_8;
RK_U8 ar_coeff_lag;
RK_U8 ar_coeffs_y_plus_128[24];
RK_U8 ar_coeffs_cb_plus_128[25];
RK_U8 ar_coeffs_cr_plus_128[25];
RK_U8 ar_coeff_shift_minus_6;
RK_U8 grain_scale_shift;
RK_U8 cb_mult;
RK_U8 cb_luma_mult;
RK_U16 cb_offset;
RK_U8 cr_mult;
RK_U8 cr_luma_mult;
RK_U16 cr_offset;
RK_U8 overlap_flag;
RK_U8 clip_to_restricted_range;
} AV1RawFilmGrainParams;
typedef struct AV1RawFrameHeader {
RK_U8 show_existing_frame;
RK_U8 frame_to_show_map_idx;
RK_U32 frame_presentation_time;
RK_U32 display_frame_id;
RK_U8 frame_type;
RK_U8 show_frame;
RK_U8 showable_frame;
RK_U8 error_resilient_mode;
RK_U8 disable_cdf_update;
RK_U8 allow_screen_content_tools;
RK_U8 force_integer_mv;
RK_S32 current_frame_id;
RK_U8 frame_size_override_flag;
RK_U8 order_hint;
RK_U8 buffer_removal_time_present_flag;
RK_U32 buffer_removal_time[AV1_MAX_OPERATING_POINTS];
RK_U8 primary_ref_frame;
RK_U16 frame_width_minus_1;
RK_U16 frame_height_minus_1;
RK_U8 use_superres;
RK_U8 coded_denom;
RK_U8 render_and_frame_size_different;
RK_U16 render_width_minus_1;
RK_U16 render_height_minus_1;
RK_U8 found_ref[AV1_REFS_PER_FRAME];
RK_U8 refresh_frame_flags;
RK_U8 allow_intrabc;
RK_U8 ref_order_hint[AV1_NUM_REF_FRAMES];
RK_U8 frame_refs_short_signaling;
RK_U8 last_frame_idx;
RK_U8 golden_frame_idx;
RK_S8 ref_frame_idx[AV1_REFS_PER_FRAME];
RK_U32 delta_frame_id_minus1[AV1_REFS_PER_FRAME];
RK_U8 allow_high_precision_mv;
RK_U8 is_filter_switchable;
RK_U8 interpolation_filter;
RK_U8 is_motion_mode_switchable;
RK_U8 use_ref_frame_mvs;
RK_U8 disable_frame_end_update_cdf;
RK_U8 uniform_tile_spacing_flag;
RK_U8 tile_cols_log2;
RK_U8 tile_rows_log2;
RK_U8 width_in_sbs_minus_1[AV1_MAX_TILE_COLS];
RK_U8 height_in_sbs_minus_1[AV1_MAX_TILE_ROWS];
RK_U16 context_update_tile_id;
RK_U8 tile_size_bytes_minus1;
// These are derived values, but it's very unhelpful to have to
// recalculate them all the time so we store them here.
RK_U16 tile_cols;
RK_U16 tile_rows;
RK_U8 base_q_idx;
RK_S8 delta_q_y_dc;
RK_U8 diff_uv_delta;
RK_S8 delta_q_u_dc;
RK_S8 delta_q_u_ac;
RK_S8 delta_q_v_dc;
RK_S8 delta_q_v_ac;
RK_U8 using_qmatrix;
RK_U8 qm_y;
RK_U8 qm_u;
RK_U8 qm_v;
RK_U8 segmentation_enabled;
RK_U8 segmentation_update_map;
RK_U8 segmentation_temporal_update;
RK_U8 segmentation_update_data;
RK_U8 feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX];
RK_S16 feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX];
RK_U8 delta_q_present;
RK_U8 delta_q_res;
RK_U8 delta_lf_present;
RK_U8 delta_lf_res;
RK_U8 delta_lf_multi;
RK_U8 loop_filter_level[4];
RK_U8 loop_filter_sharpness;
RK_U8 loop_filter_delta_enabled;
RK_U8 loop_filter_delta_update;
RK_U8 update_ref_delta[AV1_TOTAL_REFS_PER_FRAME];
RK_S8 loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME];
RK_U8 update_mode_delta[2];
RK_S8 loop_filter_mode_deltas[2];
RK_U8 cdef_damping_minus_3;
RK_U8 cdef_bits;
RK_U8 cdef_y_pri_strength[8];
RK_U8 cdef_y_sec_strength[8];
RK_U8 cdef_uv_pri_strength[8];
RK_U8 cdef_uv_sec_strength[8];
RK_U8 lr_type[3];
RK_U8 lr_unit_shift;
RK_U8 lr_uv_shift;
RK_U8 tx_mode;
RK_U8 reference_select;
RK_U8 skip_mode_present;
RK_U8 allow_warped_motion;
RK_U8 reduced_tx_set;
RK_U8 is_global[AV1_TOTAL_REFS_PER_FRAME];
RK_U8 is_rot_zoom[AV1_TOTAL_REFS_PER_FRAME];
RK_U8 is_translation[AV1_TOTAL_REFS_PER_FRAME];
//AV1RawSubexp gm_params[AV1_TOTAL_REFS_PER_FRAME][6];
RK_U32 gm_params[AV1_TOTAL_REFS_PER_FRAME][6];
AV1RawFilmGrainParams film_grain;
} AV1RawFrameHeader;
typedef struct AV1RawTileData {
RK_U8 *data;
size_t data_size;
} AV1RawTileData;
typedef struct AV1RawTileGroup {
RK_U8 tile_start_and_end_present_flag;
RK_U8 tg_start;
RK_U8 tg_end;
AV1RawTileData tile_data;
} AV1RawTileGroup;
typedef struct AV1RawFrame {
AV1RawFrameHeader header;
AV1RawTileGroup tile_group;
} AV1RawFrame;
typedef struct AV1RawTileList {
RK_U8 output_frame_width_in_tiles_minus_1;
RK_U8 output_frame_height_in_tiles_minus_1;
RK_U8 tile_count_minus_1;
AV1RawTileData tile_data;
} AV1RawTileList;
typedef struct AV1RawMetadataHDRCLL {
RK_U8 max_cll;
RK_U8 max_fall;
} AV1RawMetadataHDRCLL;
typedef struct AV1RawMetadataHDRMDCV {
RK_U8 primary_chromaticity_x[3];
RK_U8 primary_chromaticity_y[3];
RK_U8 white_point_chromaticity_x;
RK_U8 white_point_chromaticity_y;
RK_U32 luminance_max;
RK_U32 luminance_min;
} AV1RawMetadataHDRMDCV;
typedef struct AV1RawMetadataScalability {
RK_U8 scalability_mode_idc;
RK_U8 spatial_layers_cnt_minus_1;
RK_U8 spatial_layer_dimensions_present_flag;
RK_U8 spatial_layer_description_present_flag;
RK_U8 temporal_group_description_present_flag;
RK_U8 scalability_structure_reserved_3bits;
RK_U8 spatial_layer_max_width[4];
RK_U8 spatial_layer_max_height[4];
RK_U8 spatial_layer_ref_id[4];
RK_U8 temporal_group_size;
RK_U8 temporal_group_temporal_id[255];
RK_U8 temporal_group_temporal_switching_up_point_flag[255];
RK_U8 temporal_group_spatial_switching_up_point_flag[255];
RK_U8 temporal_group_ref_cnt[255];
RK_U8 temporal_group_ref_pic_diff[255][7];
} AV1RawMetadataScalability;
typedef struct AV1RawMetadataITUTT35 {
RK_U8 itu_t_t35_country_code;
RK_U8 itu_t_t35_country_code_extension_byte;
RK_U8 *payload;
size_t payload_size;
} AV1RawMetadataITUTT35;
typedef struct AV1RawMetadataTimecode {
RK_U8 counting_type;
RK_U8 full_timestamp_flag;
RK_U8 discontinuity_flag;
RK_U8 cnt_dropped_flag;
RK_U8 n_frames;
RK_U8 seconds_value;
RK_U8 minutes_value;
RK_U8 hours_value;
RK_U8 seconds_flag;
RK_U8 minutes_flag;
RK_U8 hours_flag;
RK_U8 time_offset_length;
RK_U32 time_offset_value;
} AV1RawMetadataTimecode;
typedef struct AV1RawMetadata {
RK_U64 metadata_type;
union {
AV1RawMetadataHDRCLL hdr_cll;
AV1RawMetadataHDRMDCV hdr_mdcv;
AV1RawMetadataScalability scalability;
AV1RawMetadataITUTT35 itut_t35;
AV1RawMetadataTimecode timecode;
} metadata;
} AV1RawMetadata;
typedef struct AV1RawPadding {
RK_U8 *payload;
size_t payload_size;
} AV1RawPadding;
typedef struct AV1RawOBU {
AV1RawOBUHeader header;
size_t obu_size;
union {
AV1RawSequenceHeader sequence_header;
AV1RawFrameHeader frame_header;
AV1RawFrame frame;
AV1RawTileGroup tile_group;
AV1RawTileList tile_list;
AV1RawMetadata metadata;
AV1RawPadding padding;
} obu;
} AV1RawOBU;
typedef struct AV1ReferenceFrameState {
RK_S32 valid; // RefValid
RK_S32 frame_id; // RefFrameId
RK_S32 upscaled_width; // RefUpscaledWidth
RK_S32 frame_width; // RefFrameWidth
RK_S32 frame_height; // RefFrameHeight
RK_S32 render_width; // RefRenderWidth
RK_S32 render_height; // RefRenderHeight
RK_S32 frame_type; // RefFrameType
RK_S32 subsampling_x; // RefSubsamplingX
RK_S32 subsampling_y; // RefSubsamplingY
RK_S32 bit_depth; // RefBitDepth
RK_S32 order_hint; // RefOrderHint
RK_S8 loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME];
RK_S8 loop_filter_mode_deltas[2];
RK_U8 feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX];
RK_S16 feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX];
} AV1ReferenceFrameState;
typedef RK_U32 Av1UnitType;
typedef struct Av1ObuUnit_t {
/**
* Codec-specific type of this unit.
*/
Av1UnitType type;
/**
* Pointer to the directly-parsable bitstream form of this unit.
*
* May be NULL if the unit currently only exists in decomposed form.
*/
RK_U8 *data;
size_t data_size;
void *content;
} Av1ObuUnit;
typedef struct Av1UnitFragment_t {
RK_U8 *data;
size_t data_size;
int nb_units;
int nb_units_allocated;
Av1ObuUnit *units;
} Av1UnitFragment;
#endif //__AV1D_CBS_H__

View File

@@ -0,0 +1,122 @@
/*
* Copyright 2021 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 __AV1D_CODEC_H__
#define __AV1D_CODEC_H__
#include "mpp_frame.h"
#include "hal_task.h"
#include "av1d_cbs.h"
#include "av1d_syntax.h"
#include "mpp_bitread.h"
typedef struct AV1ParseContext {
Av1UnitFragment temporal_unit;
int parsed_extradata;
} AV1ParseContext;
#define MPP_PARSER_PTS_NB 4
#define MAX_OBU_HEADER_SIZE (2 + 8)
typedef struct AV1OBU_T {
/** Size of payload */
int size;
const uint8_t *data;
/**
* Size, in bits, of just the data, excluding the trailing_one_bit and
* any trailing padding.
*/
int size_bits;
/** Size of entire OBU, including header */
int raw_size;
const uint8_t *raw_data;
/** GetBitContext initialized to the start of the payload */
BitReadCtx_t gb;
int type;
int temporal_id;
int spatial_id;
} AV1OBU;
typedef struct SplitContext {
RK_U8 *buffer;
RK_U32 buffer_size;
RK_S32 index;
RK_S32 last_index;
RK_U32 state; ///< contains the last few bytes in MSB order
RK_S32 frame_start_found;
RK_S32 overread; ///< the number of bytes which where irreversibly read from the next frame
RK_S32 overread_index; ///< the index into ParseContext.buffer of the overread bytes
RK_U64 state64; ///< contains the last 8 bytes in MSB order
RK_S64 pts; /* pts of the current frame */
RK_S64 dts; /* dts of the current frame */
RK_S64 frame_offset; /* offset of the current frame */
RK_S64 cur_offset; /* current offset
(incremented by each av_parser_parse()) */
RK_S64 next_frame_offset; /* offset of the next frame */
/* private data */
void *priv_data;
RK_S64 last_pts;
RK_S64 last_dts;
RK_S32 fetch_timestamp;
RK_S32 cur_frame_start_index;
RK_S64 cur_frame_offset[MPP_PARSER_PTS_NB];
RK_S64 cur_frame_pts[MPP_PARSER_PTS_NB];
RK_S64 cur_frame_dts[MPP_PARSER_PTS_NB];
RK_S64 offset; ///< byte offset from starting packet start
RK_S64 cur_frame_end[MPP_PARSER_PTS_NB];
/**
* Set by parser to 1 for key frames and 0 for non-key frames.
* It is initialized to -1, so if the parser doesn't set this flag,
* old-style fallback using AV_PICTURE_TYPE_I picture type as key frames
* will be used.
*/
RK_S32 key_frame;
RK_S32 eos;
} SplitContext_t;
typedef struct Av1CodecContext_t {
void *priv_data; /* Av1Context */
void *priv_data2; /* SplitContext */
MppFrameFormat pix_fmt;
MppFrameColorSpace colorspace;
MppFrameColorRange color_range;
MppFrameColorPrimaries color_primaries;
MppFrameColorTransferCharacteristic color_trc;
MppFrameChromaLocation chroma_sample_location;
RK_S32 width, height;
RK_S32 profile, level;
MppPacket pkt;
DXVA_PicParams_AV1 pic_params;
RK_S32 eos;
} Av1CodecContext;
#endif /*__AV1D_CODEC_H__*/

View File

@@ -0,0 +1,876 @@
/*
* Copyright 2021 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 __AV1D_COMMON_H__
#define __AV1D_COMMON_H__
#include "mpp_common.h"
// #include "hal_av1d_common.h"
#define AV1_REF_SCALE_SHIFT 14
#define NUM_REF_FRAMES 8
#define NUM_REF_FRAMES_LG2 3
// Max tiles for AV1 (custom size) for Level <= 6.x
#define AV1_MAX_TILES 128
#define AV1_MAX_TILE_COL 64
#define AV1_MAX_TILE_ROW 64
#define AV1_MIN_COMP_BASIS 8
#define AV1_MAX_CODED_FRAME_SIZE \
(8192 * 4352 * 10 * 6 / 32 / AV1_MIN_COMP_BASIS) /* approx 8 MB */
#define ALLOWED_REFS_PER_FRAME_EX 7
#define NUM_FRAME_CONTEXTS_LG2_EX 3
#define NUM_FRAME_CONTEXTS_EX (1 << NUM_FRAME_CONTEXTS_LG2_EX)
#define MIN_TILE_WIDTH 256
#define MAX_TILE_WIDTH 4096
#define MIN_TILE_WIDTH_SBS (MIN_TILE_WIDTH >> 6)
#define MAX_TILE_WIDTH_SBS (MAX_TILE_WIDTH >> 6)
#define FRAME_OFFSET_BITS 5
#define MAX_TILE_AREA (4096 * 2304)
// #define AV1_MAX_TILE_COLS 64
// #define AV1_MAX_TILE_ROWS 64
#define ALLOWED_REFS_PER_FRAME 3
#define NUM_FRAME_CONTEXTS_LG2 2
#define NUM_FRAME_CONTEXTS (1 << NUM_FRAME_CONTEXTS_LG2)
#define DCPREDSIMTHRESH 0
#define DCPREDCNTTHRESH 3
#define PREDICTION_PROBS 3
#define DEFAULT_PRED_PROB_0 120
#define DEFAULT_PRED_PROB_1 80
#define DEFAULT_PRED_PROB_2 40
#define AV1_DEF_UPDATE_PROB 252
#define MBSKIP_CONTEXTS 3
#define MAX_MB_SEGMENTS 8
#define MB_SEG_TREE_PROBS (MAX_MB_SEGMENTS - 1)
#define MAX_REF_LF_DELTAS_EX 8
#define MAX_REF_LF_DELTAS 4
#define MAX_MODE_LF_DELTAS 2
/* Segment Feature Masks */
#define SEGMENT_DELTADATA 0
#define SEGMENT_ABSDATA 1
#define MAX_MV_REFS 9
#define AV1_SWITCHABLE_FILTERS 3 /* number of switchable filters */
#define SWITCHABLE_FILTER_CONTEXTS ((AV1_SWITCHABLE_FILTERS + 1) * 4)
#ifdef DUAL_FILTER
#define AV1_SWITCHABLE_EXT_FILTERS 4 /* number of switchable filters */
#endif
#define COMP_PRED_CONTEXTS 2
#define COEF_UPDATE_PROB 252
#define AV1_PROB_HALF 128
#define AV1_NMV_UPDATE_PROB 252
#define AV1_MV_UPDATE_PRECISION 7
#define MV_JOINTS 4
#define MV_FP_SIZE 4
#define MV_CLASSES 11
#define CLASS0_BITS 1
#define CLASS0_SIZE (1 << CLASS0_BITS)
#define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2)
#define MV_MAX_BITS (MV_CLASSES + CLASS0_BITS + 2)
#define MV_MAX ((1 << MV_MAX_BITS) - 1)
#define MV_VALS ((MV_MAX << 1) + 1)
#define MAX_ENTROPY_TOKENS 12
#define ENTROPY_NODES 11
/* The first nodes of the entropy probs are unconstrained, the rest are
* modeled with statistic distribution. */
#define UNCONSTRAINED_NODES 3
#define MODEL_NODES (ENTROPY_NODES - UNCONSTRAINED_NODES)
#define PIVOT_NODE 2 // which node is pivot
#define COEFPROB_MODELS 128
/* Entropy nodes above is divided in two parts, first three probs in part1
* and the modeled probs in part2. Part1 is padded so that tables align with
* 32 byte addresses, so there is four bytes for each table. */
#define ENTROPY_NODES_PART1 4
#define ENTROPY_NODES_PART2 8
#define INTER_MODE_CONTEXTS 7
#define AV1_INTER_MODE_CONTEXTS 15
#define CFL_JOINT_SIGNS 8
#define CFL_ALPHA_CONTEXTS 6
#define CFL_ALPHABET_SIZE 16
#define NEWMV_MODE_CONTEXTS 6
#define ZEROMV_MODE_CONTEXTS 2
#define GLOBALMV_MODE_CONTEXTS 2
#define REFMV_MODE_CONTEXTS 9
#define DRL_MODE_CONTEXTS 3
#define NMV_CONTEXTS 3
#define INTRA_INTER_CONTEXTS 4
#define COMP_INTER_CONTEXTS 5
#define REF_CONTEXTS 5
#define AV1_REF_CONTEXTS 3
#define FWD_REFS 4
#define BWD_REFS 3
#define SINGLE_REFS 7
#define BLOCK_TYPES 2
#define REF_TYPES 2 // intra=0, inter=1
#define COEF_BANDS 6
#define PREV_COEF_CONTEXTS 6
#define MODULUS_PARAM 13 /* Modulus parameter */
#define ACTIVE_HT 110 // quantization stepsize threshold
#define MAX_MV_REF_CANDIDATES 2
/* Coefficient token alphabet */
#define ZERO_TOKEN 0 /* 0 Extra Bits 0+0 */
#define ONE_TOKEN 1 /* 1 Extra Bits 0+1 */
#define TWO_TOKEN 2 /* 2 Extra Bits 0+1 */
#define THREE_TOKEN 3 /* 3 Extra Bits 0+1 */
#define FOUR_TOKEN 4 /* 4 Extra Bits 0+1 */
#define DCT_VAL_CATEGORY1 5 /* 5-6 Extra Bits 1+1 */
#define DCT_VAL_CATEGORY2 6 /* 7-10 Extra Bits 2+1 */
#define DCT_VAL_CATEGORY3 7 /* 11-18 Extra Bits 3+1 */
#define DCT_VAL_CATEGORY4 8 /* 19-34 Extra Bits 4+1 */
#define DCT_VAL_CATEGORY5 9 /* 35-66 Extra Bits 5+1 */
#define DCT_VAL_CATEGORY6 10 /* 67+ Extra Bits 13+1 */
#define DCT_EOB_TOKEN 11 /* EOB Extra Bits 0+0 */
#define MAX_ENTROPY_TOKENS 12
#define INTERINTRA_MODES 4
#define INTER_COMPOUND_MODES 8
#define COMPOUND_TYPES 3
#define HEAD_TOKENS 5
#define TAIL_TOKENS 9
#define ONE_TOKEN_EOB 1
#define ONE_TOKEN_NEOB 2
#define MULTICORE_LEFT_TILE 1
#define MULTICORE_INNER_TILE 2
#define MULTICORE_RIGHT_TILE 3
#define DCT_EOB_MODEL_TOKEN 3 /* EOB Extra Bits 0+0 */
typedef RK_U32 av1_coeff_count[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[UNCONSTRAINED_NODES + 1];
typedef RK_U8 av1_coeff_probs[REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[UNCONSTRAINED_NODES];
#define BLOCK_SIZE_GROUPS 4
// AV1 extended transforms (ext_tx)
#define EXT_TX_SETS_INTER 4 // Sets of transform selections for INTER
#define EXT_TX_SETS_INTRA 3 // Sets of transform selections for INTRA
#define EXTTX_SIZES 4 // ext_tx experiment tx sizes
#define EXT_TX_TYPES 16
#define EXT_TX_SIZES 3
#define TX_TYPES 4
#define ROUND_POWER_OF_TWO(value, n) (((value) + (1 << ((n)-1))) >> (n))
/* Shift down with rounding for use when n >= 0, value >= 0 for (64 bit) */
#define ROUND_POWER_OF_TWO_64(value, n) \
(((value) + ((((int64)1 << (n)) >> 1))) >> (n))
/* Shift down with rounding for signed integers, for use when n >= 0 (64 bit) */
#define ROUND_POWER_OF_TWO_SIGNED_64(value, n) \
(((value) < 0) ? -ROUND_POWER_OF_TWO_64(-(value), (n)) \
: ROUND_POWER_OF_TWO_64((value), (n)))
/* Shift down with rounding for signed integers, for use when n >= 0 */
#define ROUND_POWER_OF_TWO_SIGNED(value, n) \
(((value) < 0) ? -ROUND_POWER_OF_TWO(-(value), (n)) \
: ROUND_POWER_OF_TWO((value), (n)))
typedef RK_U16 av1_cdf;
#define MAX_MB_SEGMENTS 8
enum Av1SegLevelFeatures {
SEG_AV1_LVL_ALT_Q, // Use alternate Quantizer ....
SEG_AV1_LVL_ALT_LF_Y_V, // Use alternate loop filter value on y plane
// vertical
SEG_AV1_LVL_ALT_LF_Y_H, // Use alternate loop filter value on y plane
// horizontal
SEG_AV1_LVL_ALT_LF_U, // Use alternate loop filter value on u plane
SEG_AV1_LVL_ALT_LF_V, // Use alternate loop filter value on v plane
SEG_AV1_LVL_REF_FRAME, // Optional Segment reference frame
SEG_AV1_LVL_SKIP, // Optional Segment (0,0) + skip mode
SEG_AV1_LVL_GLOBALMV,
SEG_AV1_LVL_MAX
};
#define AV1_ACTIVE_REFS 3
#define AV1_ACTIVE_REFS_EX 7
#define AV1_REF_LIST_SIZE 8
#define AV1_REF_SCALE_SHIFT 14
enum MvReferenceFrame {
NONE = -1,
INTRA_FRAME = 0,
LAST_FRAME = 1,
LAST2_FRAME_EX = 2,
LAST3_FRAME_EX = 3,
GOLDEN_FRAME_EX = 4,
BWDREF_FRAME_EX = 5,
ALTREF2_FRAME_EX = 6,
ALTREF_FRAME_EX = 7,
MAX_REF_FRAMES_EX = 8,
GOLDEN_FRAME = 2,
ALTREF_FRAME = 3,
MAX_REF_FRAMES = 4
};
enum BlockSizeType {
BLOCK_SIZE_AB4X4,
BLOCK_SIZE_SB4X8,
BLOCK_SIZE_SB8X4,
BLOCK_SIZE_SB8X8,
BLOCK_SIZE_SB8X16,
BLOCK_SIZE_SB16X8,
BLOCK_SIZE_MB16X16,
BLOCK_SIZE_SB16X32,
BLOCK_SIZE_SB32X16,
BLOCK_SIZE_SB32X32,
BLOCK_SIZE_SB32X64,
BLOCK_SIZE_SB64X32,
BLOCK_SIZE_SB64X64,
BLOCK_SIZE_SB64X128,
BLOCK_SIZE_SB128X64,
BLOCK_SIZE_SB128X128,
BLOCK_SIZE_SB4X16,
BLOCK_SIZE_SB16X4,
BLOCK_SIZE_SB8X32,
BLOCK_SIZE_SB32X8,
BLOCK_SIZE_SB16X64,
BLOCK_SIZE_SB64X16,
BLOCK_SIZE_TYPES,
BLOCK_SIZES_ALL = BLOCK_SIZE_TYPES
};
enum PartitionType {
PARTITION_NONE,
PARTITION_HORZ,
PARTITION_VERT,
PARTITION_SPLIT,
/*
PARTITION_HORZ_A,
PARTITION_HORZ_B,
PARTITION_VERT_A,
PARTITION_VERT_B,
PARTITION_HORZ_4,
PARTITION_VERT_4,
*/
PARTITION_TYPES
};
#define PARTITION_PLOFFSET 4 // number of probability models per block size
#define NUM_PARTITION_CONTEXTS (4 * PARTITION_PLOFFSET)
enum FrameType {
KEY_FRAME = 0,
INTER_FRAME = 1,
NUM_FRAME_TYPES,
};
enum MbPredictionMode {
DC_PRED, /* average of above and left pixels */
V_PRED, /* vertical prediction */
H_PRED, /* horizontal prediction */
D45_PRED, /* Directional 45 deg prediction [anti-clockwise from 0 deg hor] */
D135_PRED, /* Directional 135 deg prediction [anti-clockwise from 0 deg hor]
*/
D117_PRED, /* Directional 112 deg prediction [anti-clockwise from 0 deg hor]
*/
D153_PRED, /* Directional 157 deg prediction [anti-clockwise from 0 deg hor]
*/
D27_PRED, /* Directional 22 deg prediction [anti-clockwise from 0 deg hor] */
D63_PRED, /* Directional 67 deg prediction [anti-clockwise from 0 deg hor] */
SMOOTH_PRED,
TM_PRED_AV1 = SMOOTH_PRED,
SMOOTH_V_PRED, // Vertical interpolation
SMOOTH_H_PRED, // Horizontal interpolation
TM_PRED, /* Truemotion prediction */
PAETH_PRED = TM_PRED,
NEARESTMV,
NEARMV,
ZEROMV,
NEWMV,
NEAREST_NEARESTMV,
NEAR_NEARMV,
NEAREST_NEWMV,
NEW_NEARESTMV,
NEAR_NEWMV,
NEW_NEARMV,
ZERO_ZEROMV,
NEW_NEWMV,
SPLITMV,
MB_MODE_COUNT
};
// Must match hardware/src/include/common_defs.h
#define AV1_INTRA_MODES 13
#define MAX_INTRA_MODES AV1_INTRA_MODES
#define MAX_INTRA_MODES_DRAM_ALIGNED ((MAX_INTRA_MODES + 15) & (~15))
#define AV1_INTER_MODES (1 + NEWMV - NEARESTMV)
#define MOTION_MODE_CONTEXTS 10
#define DIRECTIONAL_MODES 8
#define MAX_ANGLE_DELTA 3
enum FilterIntraModeType {
FILTER_DC_PRED,
FILTER_V_PRED,
FILTER_H_PRED,
FILTER_D153_PRED,
FILTER_PAETH_PRED,
FILTER_INTRA_MODES,
FILTER_INTRA_UNUSED = 7
};
#define FILTER_INTRA_SIZES 19
enum { SIMPLE_TRANSLATION, OBMC_CAUSAL, MOTION_MODE_COUNT };
#define SUBMVREF_COUNT 5
/* Integer pel reference mv threshold for use of high-precision 1/8 mv */
#define COMPANDED_MVREF_THRESH 8
#define TX_SIZE_CONTEXTS 2
#define AV1_TX_SIZE_CONTEXTS 3
#define VARTX_PART_CONTEXTS 22
#define TXFM_PARTITION_CONTEXTS 22
enum InterpolationFilterType {
EIGHTTAP_SMOOTH,
EIGHTTAP,
EIGHTTAP_SHARP,
#ifdef DUAL_FILTER
EIGHTTAP_SMOOTH2,
BILINEAR,
SWITCHABLE, /* should be the last one */
#else
BILINEAR,
SWITCHABLE, /* should be the last one */
#endif
MULTITAP_SHARP = EIGHTTAP_SHARP
};
static const int av1_literal_to_filter[4] = {EIGHTTAP_SMOOTH, EIGHTTAP,
EIGHTTAP_SHARP, BILINEAR
};
extern const enum InterpolationFilterType
av1hwd_switchable_interp[AV1_SWITCHABLE_FILTERS];
enum CompPredModeType {
SINGLE_PREDICTION_ONLY = 0,
COMP_PREDICTION_ONLY = 1,
HYBRID_PREDICTION = 2,
NB_PREDICTION_TYPES = 3,
};
enum TxfmMode {
ONLY_4X4 = 0,
ALLOW_8X8 = 1,
ALLOW_16X16 = 2,
ALLOW_32X32 = 3,
TX_MODE_LARGEST = ALLOW_32X32, // AV1
TX_MODE_SELECT = 4,
NB_TXFM_MODES = 5,
};
enum SegLevelFeatures {
SEG_LVL_ALT_Q = 0,
SEG_LVL_ALT_LF = 1,
SEG_LVL_REF_FRAME = 2,
SEG_LVL_SKIP = 3,
SEG_LVL_MAX = 4
};
enum { AV1_SEG_FEATURE_DELTA, AV1_SEG_FEATURE_ABS };
static const int av1_seg_feature_data_signed[SEG_AV1_LVL_MAX] = {1, 1, 1, 1,
1, 0, 0
};
static const int av1_seg_feature_data_max[SEG_AV1_LVL_MAX] = {255, 63, 63, 63,
63, 7, 0
};
static const int av1_seg_feature_data_bits[SEG_AV1_LVL_MAX] = {8, 6, 6, 6,
6, 3, 0
};
enum TxSize {
TX_4X4 = 0,
TX_8X8 = 1,
TX_16X16 = 2,
TX_32X32 = 3,
TX_SIZE_MAX_SB,
};
#define MAX_TX_DEPTH 2
enum TxType { DCT_DCT = 0, ADST_DCT = 1, DCT_ADST = 2, ADST_ADST = 3 };
enum SplitMvPartitioningType {
PARTITIONING_16X8 = 0,
PARTITIONING_8X16,
PARTITIONING_8X8,
PARTITIONING_4X4,
NB_PARTITIONINGS,
};
enum PredId {
PRED_SEG_ID = 0,
PRED_MBSKIP = 1,
PRED_SWITCHABLE_INTERP = 2,
PRED_INTRA_INTER = 3,
PRED_COMP_INTER_INTER = 4,
PRED_SINGLE_REF_P1 = 5,
PRED_SINGLE_REF_P2 = 6,
PRED_COMP_REF_P = 7,
PRED_TX_SIZE = 8
};
/* Symbols for coding which components are zero jointly */
enum MvJointType {
MV_JOINT_ZERO = 0, /* Zero vector */
MV_JOINT_HNZVZ = 1, /* Vert zero, hor nonzero */
MV_JOINT_HZVNZ = 2, /* Hor zero, vert nonzero */
MV_JOINT_HNZVNZ = 3, /* Both components nonzero */
};
/* Symbols for coding magnitude class of nonzero components */
enum MvClassType {
MV_CLASS_0 = 0, /* (0, 2] integer pel */
MV_CLASS_1 = 1, /* (2, 4] integer pel */
MV_CLASS_2 = 2, /* (4, 8] integer pel */
MV_CLASS_3 = 3, /* (8, 16] integer pel */
MV_CLASS_4 = 4, /* (16, 32] integer pel */
MV_CLASS_5 = 5, /* (32, 64] integer pel */
MV_CLASS_6 = 6, /* (64, 128] integer pel */
MV_CLASS_7 = 7, /* (128, 256] integer pel */
MV_CLASS_8 = 8, /* (256, 512] integer pel */
MV_CLASS_9 = 9, /* (512, 1024] integer pel */
MV_CLASS_10 = 10, /* (1024,2048] integer pel */
};
enum RefreshFrameContextModeAv1 {
/**
* AV1 Only, no refresh
*/
AV1_REFRESH_FRAME_CONTEXT_NONE,
/**
* Update frame context to values resulting from backward probability
* updates based on entropy/counts in the decoded frame
*/
AV1_REFRESH_FRAME_CONTEXT_BACKWARD
};
// 75B
struct NmvContext {
// Start at +27B offset
RK_U8 joints[MV_JOINTS - 1]; // 3B
RK_U8 sign[2]; // 2B
// A+1
RK_U8 class0[2][CLASS0_SIZE - 1]; // 2B
RK_U8 fp[2][MV_FP_SIZE - 1]; // 6B
RK_U8 class0_hp[2]; // 2B
RK_U8 hp[2]; // 2B
RK_U8 classes[2][MV_CLASSES - 1]; // 20B
// A+2
RK_U8 class0_fp[2][CLASS0_SIZE][MV_FP_SIZE - 1]; // 12B
RK_U8 bits[2][MV_OFFSET_BITS]; // 20B
};
struct NmvContextCounts {
// 8dw (u32) / DRAM word (u256)
RK_U32 joints[MV_JOINTS];
RK_U32 sign[2][2];
RK_U32 classes[2][MV_CLASSES];
RK_U32 class0[2][CLASS0_SIZE];
RK_U32 bits[2][MV_OFFSET_BITS][2];
RK_U32 class0_fp[2][CLASS0_SIZE][4];
RK_U32 fp[2][4];
RK_U32 class0_hp[2][2];
RK_U32 hp[2][2];
};
typedef RK_U8 av1_prob;
#define ICDF(x) (32768U - (x))
#define CDF_SIZE(x) ((x)-1)
#define AV1HWPAD(x, y) RK_U8 x[y]
struct NmvJointSign {
RK_U8 joints[MV_JOINTS - 1]; // 3B
RK_U8 sign[2]; // 2B
};
struct NmvMagnitude {
RK_U8 class0[2][CLASS0_SIZE - 1];
RK_U8 fp[2][MV_FP_SIZE - 1];
RK_U8 class0_hp[2];
RK_U8 hp[2];
RK_U8 classes[2][MV_CLASSES - 1];
RK_U8 class0_fp[2][CLASS0_SIZE][MV_FP_SIZE - 1];
RK_U8 bits[2][MV_OFFSET_BITS];
};
struct RefMvNmvContext {
// Starts at +4B offset (for mbskip)
struct NmvJointSign joints_sign[NMV_CONTEXTS]; // 15B
AV1HWPAD(pad1, 13);
// A+1
struct NmvMagnitude magnitude[NMV_CONTEXTS];
};
/* Adaptive entropy contexts, padding elements are added to have
* 256 bit aligned tables for HW access.
* Compile with TRACE_PROB_TABLES to print bases for each table. */
struct Av1AdaptiveEntropyProbs {
// address A (56)
// Address A+0
RK_U8 inter_mode_prob[INTER_MODE_CONTEXTS][4]; // 7*4 = 28B
RK_U8 intra_inter_prob[INTRA_INTER_CONTEXTS]; // 4B
// Address A+1
RK_U8 uv_mode_prob[MAX_INTRA_MODES]
[MAX_INTRA_MODES_DRAM_ALIGNED]; // 10*16/32 = 5 addrs
#if ((MAX_INTRA_MODES * MAX_INTRA_MODES_DRAM_ALIGNED) % 32)
AV1HWPAD(pad1,
((MAX_INTRA_MODES * MAX_INTRA_MODES_DRAM_ALIGNED) % 32 == 0)
? 0
: 32 - (MAX_INTRA_MODES * MAX_INTRA_MODES_DRAM_ALIGNED) % 32);
#endif
// Address A+6
RK_U8 tx8x8_prob[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 3]; // 2*(4-3) = 2B
RK_U8 tx16x16_prob[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 2]; // 2*(4-2) = 4B
RK_U8 tx32x32_prob[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 1]; // 2*(4-1) = 6B
RK_U8 switchable_interp_prob[AV1_SWITCHABLE_FILTERS + 1]
[AV1_SWITCHABLE_FILTERS - 1]; // 8B
RK_U8 comp_inter_prob[COMP_INTER_CONTEXTS]; // 5B
AV1HWPAD(pad6, 7);
// Address A+7
RK_U8 sb_ymode_prob[BLOCK_SIZE_GROUPS]
[MAX_INTRA_MODES_DRAM_ALIGNED]; // 4*16/32 = 2 addrs
// Address A+9
RK_U8 partition_prob[NUM_FRAME_TYPES][NUM_PARTITION_CONTEXTS]
[PARTITION_TYPES]; // 2*16*4 = 4 addrs
// Address A+13
AV1HWPAD(pad13, 24);
RK_U8 mbskip_probs[MBSKIP_CONTEXTS]; // 3B
struct NmvContext nmvc;
// Address A+16
RK_U8 single_ref_prob[REF_CONTEXTS][2]; // 10B
RK_U8 comp_ref_prob[REF_CONTEXTS]; // 5B
RK_U8 mb_segment_tree_probs[MB_SEG_TREE_PROBS]; // 7B
RK_U8 segment_pred_probs[PREDICTION_PROBS]; // 3B
AV1HWPAD(pad16, 7);
// Address A+17
RK_U8 prob_coeffs[BLOCK_TYPES][REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[ENTROPY_NODES_PART1]; // 18 addrs
RK_U8 prob_coeffs8x8[BLOCK_TYPES][REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[ENTROPY_NODES_PART1];
RK_U8 prob_coeffs16x16[BLOCK_TYPES][REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[ENTROPY_NODES_PART1];
RK_U8 prob_coeffs32x32[BLOCK_TYPES][REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[ENTROPY_NODES_PART1];
};
/* Entropy contexts */
struct Av1EntropyProbs {
/* Default keyframe probs */
/* Table formatted for 256b memory, probs 0to7 for all tables followed by
* probs 8toN for all tables.
* Compile with TRACE_PROB_TABLES to print bases for each table. */
// In AOM code, this table is [M][M][M-1]; we pad to 16B so each entry is 1/2
// DRAM word.
RK_U8 kf_bmode_prob[MAX_INTRA_MODES][MAX_INTRA_MODES]
[MAX_INTRA_MODES_DRAM_ALIGNED];
#if ((MAX_INTRA_MODES * MAX_INTRA_MODES * MAX_INTRA_MODES_DRAM_ALIGNED) % 32)
AV1HWPAD(pad0, (((MAX_INTRA_MODES * MAX_INTRA_MODES *
MAX_INTRA_MODES_DRAM_ALIGNED) %
32) == 0)
? 0
: 32 - ((MAX_INTRA_MODES * MAX_INTRA_MODES *
MAX_INTRA_MODES_DRAM_ALIGNED) %
32));
#endif
// Address 50
AV1HWPAD(unused_bytes, 4); // 4B of padding to maintain the old alignments.
RK_U8 ref_pred_probs[PREDICTION_PROBS]; // 3B
RK_U8 ref_scores[MAX_REF_FRAMES]; // 4B
RK_U8 prob_comppred[COMP_PRED_CONTEXTS]; // 2B
AV1HWPAD(pad1, 19);
// Address 51
RK_U8 kf_uv_mode_prob[MAX_INTRA_MODES][MAX_INTRA_MODES_DRAM_ALIGNED];
#if ((MAX_INTRA_MODES * MAX_INTRA_MODES_DRAM_ALIGNED) % 32)
AV1HWPAD(pad51,
((MAX_INTRA_MODES * MAX_INTRA_MODES_DRAM_ALIGNED) % 32 == 0)
? 0
: 32 - (MAX_INTRA_MODES * MAX_INTRA_MODES_DRAM_ALIGNED) % 32);
#endif
// Address 56
struct Av1AdaptiveEntropyProbs a; // Probs with backward adaptation
};
/* Counters for adaptive entropy contexts */
struct Av1EntropyCounts {
RK_U32 inter_mode_counts[INTER_MODE_CONTEXTS][AV1_INTER_MODES - 1][2];
RK_U32 sb_ymode_counts[BLOCK_SIZE_GROUPS][MAX_INTRA_MODES];
RK_U32 uv_mode_counts[MAX_INTRA_MODES][MAX_INTRA_MODES];
RK_U32 partition_counts[NUM_PARTITION_CONTEXTS][PARTITION_TYPES];
RK_U32 switchable_interp_counts[AV1_SWITCHABLE_FILTERS + 1]
[AV1_SWITCHABLE_FILTERS];
RK_U32 intra_inter_count[INTRA_INTER_CONTEXTS][2];
RK_U32 comp_inter_count[COMP_INTER_CONTEXTS][2];
RK_U32 single_ref_count[REF_CONTEXTS][2][2];
RK_U32 comp_ref_count[REF_CONTEXTS][2];
RK_U32 tx32x32_count[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB];
RK_U32 tx16x16_count[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 1];
RK_U32 tx8x8_count[TX_SIZE_CONTEXTS][TX_SIZE_MAX_SB - 2];
RK_U32 mbskip_count[MBSKIP_CONTEXTS][2];
struct NmvContextCounts nmvcount;
RK_U32 count_coeffs[BLOCK_TYPES][REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[UNCONSTRAINED_NODES + 1];
RK_U32 count_coeffs8x8[BLOCK_TYPES][REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[UNCONSTRAINED_NODES + 1];
RK_U32 count_coeffs16x16[BLOCK_TYPES][REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[UNCONSTRAINED_NODES + 1];
RK_U32 count_coeffs32x32[BLOCK_TYPES][REF_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
[UNCONSTRAINED_NODES + 1];
RK_U32 count_eobs[TX_SIZE_MAX_SB][BLOCK_TYPES][REF_TYPES][COEF_BANDS]
[PREV_COEF_CONTEXTS];
};
struct CoeffHeadCDFModel {
RK_U16 band0[3][5];
RK_U16 bands[5][6][4];
};
struct CoeffTailCDFModel {
RK_U16 band0[3][9];
RK_U16 bands[5][6][9];
};
// 135
typedef struct CoeffHeadCDFModel coeff_head_cdf_model[BLOCK_TYPES][REF_TYPES];
// 297
typedef struct CoeffTailCDFModel coeff_tail_cdf_model[BLOCK_TYPES][REF_TYPES];
//#define PALETTE_BLOCK_SIZES (BLOCK_SIZE_SB64X64 - BLOCK_SIZE_SB8X8 + 1)
#define PALETTE_BLOCK_SIZES 7
#define PALETTE_SIZES 7
#define PALETTE_Y_MODE_CONTEXTS 3
#define PALETTE_UV_MODE_CONTEXTS 2
#define PALETTE_COLOR_INDEX_CONTEXTS 5
#define PALETTE_IDX_CONTEXTS 18
#define PALETTE_COLORS 8
#define KF_MODE_CONTEXTS 5
#define PLANE_TYPES 2
#define TX_SIZES 5
#define TXB_SKIP_CONTEXTS 13
#define DC_SIGN_CONTEXTS 3
#define SIG_COEF_CONTEXTS_EOB 4
#define SIG_COEF_CONTEXTS 42
#define COEFF_BASE_CONTEXTS 42
#define EOB_COEF_CONTEXTS 9
#define LEVEL_CONTEXTS 21
#define NUM_BASE_LEVELS 2
#define BR_CDF_SIZE 4
#define MOTION_MODES 3
#define DELTA_Q_PROBS 3
#define COMP_REF_TYPE_CONTEXTS 5
#define UNI_COMP_REF_CONTEXTS 3
#define UNIDIR_COMP_REFS 4
//#define FILTER_INTRA_MODES 5
#define SKIP_MODE_CONTEXTS 3
#define SKIP_CONTEXTS 3
#define COMP_INDEX_CONTEXTS 6
#define COMP_GROUP_IDX_CONTEXTS 7
#define MAX_TX_CATS 4
#define CFL_ALLOWED_TYPES 2
#define UV_INTRA_MODES 14
#define EXT_PARTITION_TYPES 10
#define AV1_PARTITION_CONTEXTS (5 * PARTITION_PLOFFSET)
#define RESTORE_SWITCHABLE_TYPES 3
#define DELTA_LF_PROBS 3
#define FRAME_LF_COUNT 4
#define MAX_SEGMENTS 8
#define TOKEN_CDF_Q_CTXS 4
#define SEG_TEMPORAL_PRED_CTXS 3
#define SPATIAL_PREDICTION_PROBS 3
typedef RK_U16 aom_cdf_prob;
typedef struct {
RK_U16 joint_cdf[3];
RK_U16 sign_cdf[2];
RK_U16 clsss_cdf[2][10];
RK_U16 clsss0_fp_cdf[2][2][3];
RK_U16 fp_cdf[2][3];
RK_U16 class0_hp_cdf[2];
RK_U16 hp_cdf[2];
RK_U16 class0_cdf[2];
RK_U16 bits_cdf[2][10];
} MvCDFs;
typedef struct {
RK_U16 partition_cdf[13][16];
// 64
RK_U16 kf_ymode_cdf[KF_MODE_CONTEXTS][KF_MODE_CONTEXTS][AV1_INTRA_MODES - 1];
RK_U16 segment_pred_cdf[PREDICTION_PROBS];
RK_U16 spatial_pred_seg_tree_cdf[SPATIAL_PREDICTION_PROBS][MAX_MB_SEGMENTS - 1];
RK_U16 mbskip_cdf[MBSKIP_CONTEXTS];
RK_U16 delta_q_cdf[DELTA_Q_PROBS];
RK_U16 delta_lf_multi_cdf[FRAME_LF_COUNT][DELTA_LF_PROBS];
RK_U16 delta_lf_cdf[DELTA_LF_PROBS];
RK_U16 skip_mode_cdf[SKIP_MODE_CONTEXTS];
RK_U16 vartx_part_cdf[VARTX_PART_CONTEXTS][1];
RK_U16 tx_size_cdf[MAX_TX_CATS][AV1_TX_SIZE_CONTEXTS][MAX_TX_DEPTH];
RK_U16 if_ymode_cdf[BLOCK_SIZE_GROUPS][AV1_INTRA_MODES - 1];
RK_U16 uv_mode_cdf[2][AV1_INTRA_MODES][AV1_INTRA_MODES - 1 + 1];
RK_U16 intra_inter_cdf[INTRA_INTER_CONTEXTS];
RK_U16 comp_inter_cdf[COMP_INTER_CONTEXTS];
RK_U16 single_ref_cdf[AV1_REF_CONTEXTS][SINGLE_REFS - 1];
RK_U16 comp_ref_type_cdf[COMP_REF_TYPE_CONTEXTS][1];
RK_U16 uni_comp_ref_cdf[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1][1];
RK_U16 comp_ref_cdf[AV1_REF_CONTEXTS][FWD_REFS - 1];
RK_U16 comp_bwdref_cdf[AV1_REF_CONTEXTS][BWD_REFS - 1];
RK_U16 newmv_cdf[NEWMV_MODE_CONTEXTS];
RK_U16 zeromv_cdf[ZEROMV_MODE_CONTEXTS];
RK_U16 refmv_cdf[REFMV_MODE_CONTEXTS];
RK_U16 drl_cdf[DRL_MODE_CONTEXTS];
RK_U16 interp_filter_cdf[SWITCHABLE_FILTER_CONTEXTS][AV1_SWITCHABLE_FILTERS - 1];
MvCDFs mv_cdf;
RK_U16 obmc_cdf[BLOCK_SIZE_TYPES];
RK_U16 motion_mode_cdf[BLOCK_SIZE_TYPES][2];
RK_U16 inter_compound_mode_cdf[AV1_INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES - 1];
RK_U16 compound_type_cdf[BLOCK_SIZE_TYPES][CDF_SIZE(COMPOUND_TYPES - 1)];
RK_U16 interintra_cdf[BLOCK_SIZE_GROUPS];
RK_U16 interintra_mode_cdf[BLOCK_SIZE_GROUPS][INTERINTRA_MODES - 1];
RK_U16 wedge_interintra_cdf[BLOCK_SIZE_TYPES];
RK_U16 wedge_idx_cdf[BLOCK_SIZE_TYPES][CDF_SIZE(16)];
RK_U16 palette_y_mode_cdf[PALETTE_BLOCK_SIZES][PALETTE_Y_MODE_CONTEXTS][1];
RK_U16 palette_uv_mode_cdf[PALETTE_UV_MODE_CONTEXTS][1];
RK_U16 palette_y_size_cdf[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1];
RK_U16 palette_uv_size_cdf[PALETTE_BLOCK_SIZES][PALETTE_SIZES - 1];
RK_U16 cfl_sign_cdf[CFL_JOINT_SIGNS - 1];
RK_U16 cfl_alpha_cdf[CFL_ALPHA_CONTEXTS][CFL_ALPHABET_SIZE - 1];
RK_U16 intrabc_cdf[1];
RK_U16 angle_delta_cdf[DIRECTIONAL_MODES][6];
RK_U16 filter_intra_mode_cdf[FILTER_INTRA_MODES - 1];
RK_U16 filter_intra_cdf[BLOCK_SIZES_ALL];
RK_U16 comp_group_idx_cdf[COMP_GROUP_IDX_CONTEXTS][CDF_SIZE(2)];
RK_U16 compound_idx_cdf[COMP_INDEX_CONTEXTS][CDF_SIZE(2)];
RK_U16 dummy0[14];
// Palette index contexts; sizes 1/7, 2/6, 3/5 packed together
RK_U16 palette_y_color_index_cdf[PALETTE_IDX_CONTEXTS][8];
RK_U16 palette_uv_color_index_cdf[PALETTE_IDX_CONTEXTS][8];
// RK_U16 dummy1[0];
// Note: cdf space can be optimized (most sets have fewer than EXT_TX_TYPES
// symbols)
RK_U16 tx_type_intra0_cdf[EXTTX_SIZES][AV1_INTRA_MODES][8];
RK_U16 tx_type_intra1_cdf[EXTTX_SIZES][AV1_INTRA_MODES][4];
RK_U16 tx_type_inter_cdf[2][EXTTX_SIZES][EXT_TX_TYPES];
aom_cdf_prob txb_skip_cdf[TX_SIZES][TXB_SKIP_CONTEXTS][CDF_SIZE(2)];
aom_cdf_prob eob_extra_cdf[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS][CDF_SIZE(2)];
RK_U16 dummy_[5];
aom_cdf_prob eob_flag_cdf16[PLANE_TYPES][2][4];
aom_cdf_prob eob_flag_cdf32[PLANE_TYPES][2][8];
aom_cdf_prob eob_flag_cdf64[PLANE_TYPES][2][8];
aom_cdf_prob eob_flag_cdf128[PLANE_TYPES][2][8];
aom_cdf_prob eob_flag_cdf256[PLANE_TYPES][2][8];
aom_cdf_prob eob_flag_cdf512[PLANE_TYPES][2][16];
aom_cdf_prob eob_flag_cdf1024[PLANE_TYPES][2][16];
aom_cdf_prob coeff_base_eob_cdf[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS_EOB][CDF_SIZE(3)];
aom_cdf_prob coeff_base_cdf[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS][CDF_SIZE(4) + 1];
aom_cdf_prob dc_sign_cdf[PLANE_TYPES][DC_SIGN_CONTEXTS][CDF_SIZE(2)];
RK_U16 dummy_2[2];
aom_cdf_prob coeff_br_cdf[TX_SIZES][PLANE_TYPES][LEVEL_CONTEXTS][CDF_SIZE(BR_CDF_SIZE) + 1];
RK_U16 dummy2[16];
} AV1CDFs;
typedef struct {
RK_U8 scaling_lut_y[256];
RK_U8 scaling_lut_cb[256];
RK_U8 scaling_lut_cr[256];
RK_S16 cropped_luma_grain_block[4096];
RK_S16 cropped_chroma_grain_block[1024 * 2];
} AV1FilmGrainMemory;
#endif // __AV1COMMONDEC_H__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,185 @@
/*
* Copyright 2021 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 __AV1D_PARSER_H__
#define __AV1D_PARSER_H__
#include <stdlib.h>
#include "mpp_mem.h"
#include "mpp_bitread.h"
#include "parser_api.h"
#include "av1.h"
#include "av1d_codec.h"
#include "av1d_cbs.h"
#include "av1d_syntax.h"
#include "av1d_common.h"
#include "av1_entropymode.h"
extern RK_U32 av1d_debug;
#define AV1D_DBG_FUNCTION (0x00000001)
#define AV1D_DBG_HEADER (0x00000002)
#define AV1D_DBG_REF (0x00000004)
#define AV1D_DBG_STRMIN (0x00000008)
#define av1d_dbg(flag, fmt, ...) _mpp_dbg(av1d_debug, flag, fmt, ##__VA_ARGS__)
#define av1d_dbg_func(fmt, ...) av1d_dbg(AV1D_DBG_FUNCTION, fmt, ## __VA_ARGS__)
typedef struct RefInfo {
RK_S32 ref_count;
RK_U32 invisible;
RK_U32 is_output;
RK_U32 lst_frame_offset;
RK_U32 lst2_frame_offset;
RK_U32 lst3_frame_offset;
RK_U32 gld_frame_offset;
RK_U32 bwd_frame_offset;
RK_U32 alt2_frame_offset;
RK_U32 alt_frame_offset;
RK_U32 is_intra_frame;
RK_U32 intra_only;
} RefInfo;
typedef struct AV1Frame {
MppFrame f;
RK_S32 slot_index;
AV1RawFrameHeader *raw_frame_header;
RK_S32 temporal_id;
RK_S32 spatial_id;
RK_U8 order_hint;
RK_U8 gm_type[AV1_NUM_REF_FRAMES];
RK_S32 gm_params[AV1_NUM_REF_FRAMES][6];
RK_U8 skip_mode_frame_idx[2];
AV1RawFilmGrainParams film_grain;
RK_U8 coded_lossless;
RefInfo *ref;
} AV1Frame;
typedef struct AV1Context_t {
BitReadCtx_t gb;
AV1RawSequenceHeader *sequence_header;
AV1RawSequenceHeader *seq_ref;
AV1RawFrameHeader *raw_frame_header;
Av1UnitFragment current_obu;
RK_S32 seen_frame_header;
RK_U8 *frame_header;
size_t frame_header_size;
AV1Frame ref[AV1_NUM_REF_FRAMES];
AV1Frame cur_frame;
RK_S32 temporal_id;
RK_S32 spatial_id;
RK_S32 operating_point_idc;
RK_S32 bit_depth;
RK_S32 order_hint;
RK_S32 frame_width;
RK_S32 frame_height;
RK_S32 upscaled_width;
RK_S32 render_width;
RK_S32 render_height;
RK_S32 num_planes;
RK_S32 coded_lossless;
RK_S32 all_lossless;
RK_S32 tile_cols;
RK_S32 tile_rows;
RK_S32 tile_num;
RK_S32 operating_point;
RK_S32 extra_has_frame;
RK_U32 frame_tag_size;
RK_U32 obu_len;
AV1CDFs *cdfs;
MvCDFs *cdfs_ndvc;
AV1CDFs default_cdfs;
MvCDFs default_cdfs_ndvc;
AV1CDFs cdfs_last[NUM_REF_FRAMES];
MvCDFs cdfs_last_ndvc[NUM_REF_FRAMES];
RK_U8 disable_frame_end_update_cdf;
RK_U8 frame_is_intra;
RK_U8 refresh_frame_flags;
const Av1UnitType *unit_types;
RK_S32 nb_unit_types;
RK_U32 tile_offset_start[AV1_MAX_TILES];
RK_U32 tile_offset_end[AV1_MAX_TILES];
AV1ReferenceFrameState ref_s[AV1_NUM_REF_FRAMES];
MppBufSlots slots;
MppBufSlots packet_slots;
RK_U8 skip_ref0;
RK_U8 skip_ref1;
MppDecCfgSet *cfg;
HalDecTask *task;
RK_S32 eos; ///< current packet contains an EOS/EOB NAL
RK_S64 pts;
} AV1Context;
#ifdef __cplusplus
extern "C" {
#endif
MPP_RET av1d_parser_init(Av1CodecContext *ctx, ParserCfg *init);
MPP_RET av1d_parser_deinit(Av1CodecContext *ctx);
RK_S32 av1d_parser_frame(Av1CodecContext *ctx, HalDecTask *in_task);
void av1d_parser_update(Av1CodecContext *ctx, void *info);
MPP_RET av1d_paser_reset(Av1CodecContext *ctx);
RK_S32 av1d_split_frame(SplitContext_t *ctx,
RK_U8 **out_data, RK_S32 *out_size,
RK_U8 *data, RK_S32 size);
MPP_RET av1d_get_frame_stream(Av1CodecContext *ctx, RK_U8 *buf, RK_S32 length);
MPP_RET av1d_split_deinit(Av1CodecContext *ctx);
MPP_RET av1d_split_init(Av1CodecContext *ctx);
RK_S32 av1d_parser2_syntax(Av1CodecContext *ctx);
RK_S32 mpp_av1_split_fragment(AV1Context *ctx, Av1UnitFragment *frag, RK_S32 header_flag);
RK_S32 mpp_av1_read_fragment_content(AV1Context *ctx, Av1UnitFragment *frag);
RK_S32 mpp_av1_set_context_with_sequence(Av1CodecContext *ctx,
const AV1RawSequenceHeader *seq);
void mpp_av1_fragment_reset(Av1UnitFragment *frag);
RK_S32 mpp_av1_assemble_fragment(AV1Context *ctx, Av1UnitFragment *frag);
void mpp_av1_flush(AV1Context *ctx);
void mpp_av1_close(AV1Context *ctx);
void mpp_av1_free_metadata(void *unit, RK_U8 *content);
void Av1GetCDFs(AV1Context *ctx, RK_U32 ref_idx);
void Av1StoreCDFs(AV1Context *ctx, RK_U32 refresh_frame_flags);
#ifdef __cplusplus
}
#endif
#endif // __AV1D_PARSER_H__

View File

@@ -0,0 +1,287 @@
/*
* Copyright 2021 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.
*/
#define MODULE_TAG "av1d_parser2syntax"
#include <string.h>
#include "av1d_parser.h"
#include "av1d_syntax.h"
static int av1d_fill_picparams(Av1CodecContext *ctx, DXVA_PicParams_AV1 *pp)
{
int i, j, uses_lr;
AV1Context *h = ctx->priv_data;
const AV1RawSequenceHeader *seq = h->sequence_header;
const AV1RawFrameHeader *frame_header = h->raw_frame_header;
const AV1RawFilmGrainParams *film_grain = &h->cur_frame.film_grain;
unsigned char remap_lr_type[4] = { AV1_RESTORE_NONE, AV1_RESTORE_SWITCHABLE, AV1_RESTORE_WIENER, AV1_RESTORE_SGRPROJ };
// int apply_grain = !(ctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN) && film_grain->apply_grain;
int apply_grain = film_grain->apply_grain;
memset(pp, 0, sizeof(*pp));
pp->width = ctx->width;
pp->height = ctx->height;
pp->max_width = seq->max_frame_width_minus_1 + 1;
pp->max_height = seq->max_frame_height_minus_1 + 1;
pp->CurrPicTextureIndex = h->cur_frame.slot_index;
pp->superres_denom = frame_header->use_superres ? frame_header->coded_denom : AV1_SUPERRES_NUM;
pp->bitdepth = h->bit_depth;
pp->seq_profile = seq->seq_profile;
/* Tiling info */
pp->tiles.cols = frame_header->tile_cols;
pp->tiles.rows = frame_header->tile_rows;
pp->tiles.context_update_id = frame_header->context_update_tile_id;
{
RK_U8 val = 0;
for (i = 0; i < pp->tiles.cols; i++) {
pp->tiles.widths[i] = val;
val += frame_header->width_in_sbs_minus_1[i] + 1;
}
pp->tiles.widths[i] = val;
val = 0;
for (i = 0; i < pp->tiles.rows; i++) {
pp->tiles.heights[i] = val;
val += frame_header->height_in_sbs_minus_1[i] + 1;
}
pp->tiles.heights[i] = val;
}
for (i = 0; i < AV1_MAX_TILES; i++) {
pp->tiles.tile_offset_start[i] = h->tile_offset_start[i];
pp->tiles.tile_offset_end[i] = h->tile_offset_end[i];
}
pp->tiles.tile_sz_mag = h->raw_frame_header->tile_size_bytes_minus1;
/* Coding tools */
pp->coding.use_128x128_superblock = seq->use_128x128_superblock;
pp->coding.intra_edge_filter = seq->enable_intra_edge_filter;
pp->coding.interintra_compound = seq->enable_interintra_compound;
pp->coding.masked_compound = seq->enable_masked_compound;
pp->coding.warped_motion = frame_header->allow_warped_motion;
pp->coding.dual_filter = seq->enable_dual_filter;
pp->coding.jnt_comp = seq->enable_jnt_comp;
pp->coding.screen_content_tools = frame_header->allow_screen_content_tools;
pp->coding.integer_mv = frame_header->force_integer_mv;
pp->coding.cdef_en = seq->enable_cdef;
pp->coding.restoration = seq->enable_restoration;
pp->coding.film_grain_en = seq->film_grain_params_present ;//&& !(avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN);
pp->coding.intrabc = frame_header->allow_intrabc;
pp->coding.high_precision_mv = frame_header->allow_high_precision_mv;
pp->coding.switchable_motion_mode = frame_header->is_motion_mode_switchable;
pp->coding.filter_intra = seq->enable_filter_intra;
pp->coding.disable_frame_end_update_cdf = frame_header->disable_frame_end_update_cdf;
pp->coding.disable_cdf_update = frame_header->disable_cdf_update;
pp->coding.reference_mode = frame_header->reference_select;
pp->coding.skip_mode = frame_header->skip_mode_present;
pp->coding.reduced_tx_set = frame_header->reduced_tx_set;
pp->coding.superres = frame_header->use_superres;
pp->coding.tx_mode = frame_header->tx_mode;
pp->coding.use_ref_frame_mvs = frame_header->use_ref_frame_mvs;
pp->coding.enable_ref_frame_mvs = seq->enable_ref_frame_mvs;
pp->coding.reference_frame_update = 1; // 0 for show_existing_frame with key frames, but those are not passed to the hwaccel
pp->coding.error_resilient_mode = frame_header->error_resilient_mode;
/* Format & Picture Info flags */
pp->format.frame_type = frame_header->frame_type;
pp->format.show_frame = frame_header->show_frame;
pp->format.showable_frame = frame_header->showable_frame;
pp->format.subsampling_x = seq->color_config.subsampling_x;
pp->format.subsampling_y = seq->color_config.subsampling_y;
pp->format.mono_chrome = seq->color_config.mono_chrome;
pp->coded_lossless = h->cur_frame.coded_lossless;
/* References */
pp->primary_ref_frame = frame_header->primary_ref_frame;
pp->order_hint = frame_header->order_hint;
pp->order_hint_bits = seq->enable_order_hint ? seq->order_hint_bits_minus_1 + 1 : 0;
memset(pp->RefFrameMapTextureIndex, 0xFF, sizeof(pp->RefFrameMapTextureIndex));
for (i = 0; i < AV1_REFS_PER_FRAME; i++) {
int8_t ref_idx = frame_header->ref_frame_idx[i];
AV1Frame *ref_frame = &h->ref[ref_idx];
RefInfo *ref_i = ref_frame->ref;
pp->frame_refs[i].width = mpp_frame_get_width(ref_frame->f);
pp->frame_refs[i].height = mpp_frame_get_height(ref_frame->f);;
pp->frame_refs[i].Index = ref_frame->slot_index;
pp->frame_refs[i].order_hint = ref_frame->order_hint;
if (ref_i) {
pp->frame_refs[i].lst_frame_offset = ref_i->lst_frame_offset;
pp->frame_refs[i].lst2_frame_offset = ref_i->lst2_frame_offset;
pp->frame_refs[i].lst3_frame_offset = ref_i->lst3_frame_offset;
pp->frame_refs[i].gld_frame_offset = ref_i->gld_frame_offset;
pp->frame_refs[i].bwd_frame_offset = ref_i->bwd_frame_offset;
pp->frame_refs[i].alt2_frame_offset = ref_i->alt2_frame_offset;
pp->frame_refs[i].alt_frame_offset = ref_i->alt_frame_offset ;
pp->frame_refs[i].is_intra_frame = ref_i->is_intra_frame;
pp->frame_refs[i].intra_only = ref_i->intra_only;
}
/* Global Motion */
pp->frame_refs[i].wminvalid = (h->cur_frame.gm_type[AV1_REF_FRAME_LAST + i] == AV1_WARP_MODEL_IDENTITY);
pp->frame_refs[i].wmtype = h->cur_frame.gm_type[AV1_REF_FRAME_LAST + i];
for (j = 0; j < 6; ++j) {
pp->frame_refs[i].wmmat[j] = h->cur_frame.gm_params[AV1_REF_FRAME_LAST + i][j];
}
}
for (i = 0; i < AV1_NUM_REF_FRAMES; i++) {
AV1Frame *ref_frame = &h->ref[i];
if (ref_frame->slot_index < 0x7f)
pp->RefFrameMapTextureIndex[i] = ref_frame->slot_index;
else
pp->RefFrameMapTextureIndex[i] = 0xff;
}
/* Loop filter parameters */
pp->loop_filter.filter_level[0] = frame_header->loop_filter_level[0];
pp->loop_filter.filter_level[1] = frame_header->loop_filter_level[1];
pp->loop_filter.filter_level_u = frame_header->loop_filter_level[2];
pp->loop_filter.filter_level_v = frame_header->loop_filter_level[3];
pp->loop_filter.sharpness_level = frame_header->loop_filter_sharpness;
pp->loop_filter.mode_ref_delta_enabled = frame_header->loop_filter_delta_enabled;
pp->loop_filter.mode_ref_delta_update = frame_header->loop_filter_delta_update;
pp->loop_filter.delta_lf_multi = frame_header->delta_lf_multi;
pp->loop_filter.delta_lf_present = frame_header->delta_lf_present;
pp->loop_filter.delta_lf_res = frame_header->delta_lf_res;
for (i = 0; i < AV1_TOTAL_REFS_PER_FRAME; i++) {
pp->loop_filter.ref_deltas[i] = frame_header->loop_filter_ref_deltas[i];
}
pp->loop_filter.mode_deltas[0] = frame_header->loop_filter_mode_deltas[0];
pp->loop_filter.mode_deltas[1] = frame_header->loop_filter_mode_deltas[1];
pp->loop_filter.frame_restoration_type[0] = remap_lr_type[frame_header->lr_type[0]];
pp->loop_filter.frame_restoration_type[1] = remap_lr_type[frame_header->lr_type[1]];
pp->loop_filter.frame_restoration_type[2] = remap_lr_type[frame_header->lr_type[2]];
uses_lr = frame_header->lr_type[0] || frame_header->lr_type[1] || frame_header->lr_type[2];
pp->loop_filter.log2_restoration_unit_size[0] = uses_lr ? (1 + frame_header->lr_unit_shift) : 3;
pp->loop_filter.log2_restoration_unit_size[1] = uses_lr ? (1 + frame_header->lr_unit_shift - frame_header->lr_uv_shift) : 3;
pp->loop_filter.log2_restoration_unit_size[2] = uses_lr ? (1 + frame_header->lr_unit_shift - frame_header->lr_uv_shift) : 3;
/* Quantization */
pp->quantization.delta_q_present = frame_header->delta_q_present;
pp->quantization.delta_q_res = frame_header->delta_q_res;
pp->quantization.base_qindex = frame_header->base_q_idx;
pp->quantization.y_dc_delta_q = frame_header->delta_q_y_dc;
pp->quantization.u_dc_delta_q = frame_header->delta_q_u_dc;
pp->quantization.v_dc_delta_q = frame_header->delta_q_v_dc;
pp->quantization.u_ac_delta_q = frame_header->delta_q_u_ac;
pp->quantization.v_ac_delta_q = frame_header->delta_q_v_ac;
pp->quantization.qm_y = frame_header->using_qmatrix ? frame_header->qm_y : 0xFF;
pp->quantization.qm_u = frame_header->using_qmatrix ? frame_header->qm_u : 0xFF;
pp->quantization.qm_v = frame_header->using_qmatrix ? frame_header->qm_v : 0xFF;
/* Cdef parameters */
pp->cdef.damping = frame_header->cdef_damping_minus_3;
pp->cdef.bits = frame_header->cdef_bits;
for (i = 0; i < 8; i++) {
pp->cdef.y_strengths[i].primary = frame_header->cdef_y_pri_strength[i];
pp->cdef.y_strengths[i].secondary = frame_header->cdef_y_sec_strength[i];
pp->cdef.uv_strengths[i].primary = frame_header->cdef_uv_pri_strength[i];
pp->cdef.uv_strengths[i].secondary = frame_header->cdef_uv_sec_strength[i];
}
/* Misc flags */
pp->interp_filter = frame_header->interpolation_filter;
/* Segmentation */
pp->segmentation.enabled = frame_header->segmentation_enabled;
pp->segmentation.update_map = frame_header->segmentation_update_map;
pp->segmentation.update_data = frame_header->segmentation_update_data;
pp->segmentation.temporal_update = frame_header->segmentation_temporal_update;
for (i = 0; i < AV1_MAX_SEGMENTS; i++) {
for (j = 0; j < AV1_SEG_LVL_MAX; j++) {
pp->segmentation.feature_mask[i] |= frame_header->feature_enabled[i][j] << j;
pp->segmentation.feature_data[i][j] = frame_header->feature_value[i][j];
}
}
/* Film grain */
if (apply_grain) {
pp->film_grain.apply_grain = 1;
pp->film_grain.scaling_shift_minus8 = film_grain->grain_scaling_minus_8;
pp->film_grain.chroma_scaling_from_luma = film_grain->chroma_scaling_from_luma;
pp->film_grain.ar_coeff_lag = film_grain->ar_coeff_lag;
pp->film_grain.ar_coeff_shift_minus6 = film_grain->ar_coeff_shift_minus_6;
pp->film_grain.grain_scale_shift = film_grain->grain_scale_shift;
pp->film_grain.overlap_flag = film_grain->overlap_flag;
pp->film_grain.clip_to_restricted_range = film_grain->clip_to_restricted_range;
pp->film_grain.matrix_coeff_is_identity = (seq->color_config.matrix_coefficients == MPP_FRAME_SPC_RGB);
pp->film_grain.grain_seed = film_grain->grain_seed;
pp->film_grain.num_y_points = film_grain->num_y_points;
for (i = 0; i < film_grain->num_y_points; i++) {
pp->film_grain.scaling_points_y[i][0] = film_grain->point_y_value[i];
pp->film_grain.scaling_points_y[i][1] = film_grain->point_y_scaling[i];
}
pp->film_grain.num_cb_points = film_grain->num_cb_points;
for (i = 0; i < film_grain->num_cb_points; i++) {
pp->film_grain.scaling_points_cb[i][0] = film_grain->point_cb_value[i];
pp->film_grain.scaling_points_cb[i][1] = film_grain->point_cb_scaling[i];
}
pp->film_grain.num_cr_points = film_grain->num_cr_points;
for (i = 0; i < film_grain->num_cr_points; i++) {
pp->film_grain.scaling_points_cr[i][0] = film_grain->point_cr_value[i];
pp->film_grain.scaling_points_cr[i][1] = film_grain->point_cr_scaling[i];
}
for (i = 0; i < 24; i++) {
pp->film_grain.ar_coeffs_y[i] = film_grain->ar_coeffs_y_plus_128[i];
}
for (i = 0; i < 25; i++) {
pp->film_grain.ar_coeffs_cb[i] = film_grain->ar_coeffs_cb_plus_128[i];
pp->film_grain.ar_coeffs_cr[i] = film_grain->ar_coeffs_cr_plus_128[i];
}
pp->film_grain.cb_mult = film_grain->cb_mult;
pp->film_grain.cb_luma_mult = film_grain->cb_luma_mult;
pp->film_grain.cr_mult = film_grain->cr_mult;
pp->film_grain.cr_luma_mult = film_grain->cr_luma_mult;
pp->film_grain.cb_offset = film_grain->cb_offset;
pp->film_grain.cr_offset = film_grain->cr_offset;
pp->film_grain.cr_offset = film_grain->cr_offset;
}
pp->upscaled_width = h->upscaled_width;
pp->frame_to_show_map_idx = frame_header->frame_to_show_map_idx;
pp->frame_tag_size = h->frame_tag_size;
pp->skip_ref0 = h->skip_ref0;
pp->skip_ref1 = h->skip_ref1;
pp->refresh_frame_flags = frame_header->refresh_frame_flags;
pp->cdfs = h->cdfs;
pp->cdfs_ndvc = h->cdfs_ndvc;
pp->tile_cols_log2 = frame_header->tile_cols_log2;
// XXX: Setting the StatusReportFeedbackNumber breaks decoding on some drivers (tested on NVIDIA 457.09)
// Status Reporting is not used by FFmpeg, hence not providing a number does not cause any issues
//pp->StatusReportFeedbackNumber = 1 + DXVA_CONTEXT_REPORT_ID(avctx, ctx)++;
return 0;
}
void av1d_fill_counts(Av1CodecContext *ctx)
{
//AV1Context *s = ctx->priv_data;
(void) ctx;
// memcpy(&ctx->pic_params.counts, &s->counts, sizeof(s->counts));
}
RK_S32 av1d_parser2_syntax(Av1CodecContext *ctx)
{
av1d_fill_picparams(ctx, &ctx->pic_params);
return 0;
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2021 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.
*/
#include "av1d_parser.h"
#include "av1d_common.h"
void Av1GetCDFs(AV1Context *ctx, RK_U32 ref_idx)
{
ctx->cdfs = &ctx->cdfs_last[ref_idx];
ctx->cdfs_ndvc = &ctx->cdfs_last_ndvc[ref_idx];
}
void Av1StoreCDFs(AV1Context *ctx, RK_U32 refresh_frame_flags)
{
RK_U32 i;
for (i = 0; i < NUM_REF_FRAMES; i++) {
if (refresh_frame_flags & (1 << i)) {
if (&ctx->cdfs_last[i] != ctx->cdfs) {
ctx->cdfs_last[i] = *ctx->cdfs;
ctx->cdfs_last_ndvc[i] = *ctx->cdfs_ndvc;
}
}
}
}

41
mpp/codec/inc/av1d_api.h Normal file
View File

@@ -0,0 +1,41 @@
/*
* Copyright 2021 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 __AV1D_API_H__
#define __AV1D_API_H__
#include "parser_api.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const ParserApi api_av1d_parser;
MPP_RET av1d_init (void *decoder, ParserCfg *cfg);
MPP_RET av1d_deinit (void *decoder);
MPP_RET av1d_reset (void *decoder);
MPP_RET av1d_flush (void *decoder);
MPP_RET av1d_control(void *decoder, MpiCmd cmd_type, void *param);
MPP_RET av1d_prepare(void *decoder, MppPacket pkt, HalDecTask *task);
MPP_RET av1d_parse (void *decoder, HalDecTask *task);
MPP_RET av1d_callback(void *decoder, void *info);
#ifdef __cplusplus
}
#endif
#endif /* __AV1D_API_H__*/

View File

@@ -33,6 +33,8 @@
#include "mpg4d_api.h"
#include "vp8d_api.h"
#include "jpegd_api.h"
#include "av1d_api.h"
// for test and demo
#include "dummy_dec_api.h"
@@ -68,6 +70,9 @@ static const ParserApi *parsers[] = {
&api_jpegd_parser,
#endif
&dummy_dec_parser,
#if HAVE_AV1D
&api_av1d_parser,
#endif
};
typedef struct ParserImpl_t {

View File

@@ -82,6 +82,15 @@ if( ENABLE_JPEGD )
add_definitions(-DHAVE_JPEGD)
endif()
# AV1 decoder
option(ENABLE_AV1D "Enable av1 decoder" ON)
if( ENABLE_AV1D )
set(HAVE_AV1D true)
set(CODEC_AV1D codec_av1d)
set(HAL_AV1D hal_av1d)
add_definitions(-DHAVE_AV1D)
endif()
# H.264 encoder
option(ENABLE_H264E "Enable h.264 encoder" ON)
if( ENABLE_H264E )

236
mpp/common/av1d_syntax.h Normal file
View File

@@ -0,0 +1,236 @@
/*
* Copyright 2021 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 _AV1D_SYNTAX_H_
#define _AV1D_SYNTAX_H_
typedef unsigned long DWORD;
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long ULONG;
typedef unsigned short USHORT;
typedef unsigned char UCHAR;
typedef unsigned int UINT;
typedef unsigned int UINT32;
typedef signed int BOOL;
typedef signed int INT;
typedef signed char CHAR;
typedef signed short SHORT;
typedef signed long LONG;
typedef void *PVOID;
typedef struct _DXVA_PicEntry_AV1 {
union {
struct {
UCHAR Index7Bits : 7;
UCHAR AssociatedFlag : 1;
};
UCHAR bPicEntry;
};
} DXVA_PicEntry_AV1, *LPDXVA_PicEntry_AV1;
typedef struct _DXVA_PicParams_AV1 {
DXVA_PicEntry_AV1 CurrPic;
USHORT width ;
USHORT height ;
USHORT max_width ;
USHORT max_height ;
USHORT CurrPicTextureIndex ;
USHORT superres_denom ;
USHORT bitdepth ;
USHORT seq_profile ;
union {
struct {
UINT32 use_128x128_superblock : 1;
UINT32 intra_edge_filter : 1;
UINT32 interintra_compound : 1;
UINT32 masked_compound : 1;
UINT32 warped_motion : 1;
UINT32 dual_filter : 1;
UINT32 jnt_comp : 1;
UINT32 screen_content_tools : 1;
UINT32 integer_mv : 2;
UINT32 cdef_en : 1;
UINT32 restoration : 1;
UINT32 film_grain_en : 1;
UINT32 intrabc : 1;
UINT32 high_precision_mv : 1;
UINT32 switchable_motion_mode : 1;
UINT32 filter_intra : 1;
UINT32 disable_frame_end_update_cdf : 1;
UINT32 disable_cdf_update : 1;
UINT32 reference_mode : 1;
UINT32 skip_mode : 1;
UINT32 reduced_tx_set : 1;
UINT32 superres : 1;
UINT32 tx_mode : 3;
UINT32 use_ref_frame_mvs : 1;
UINT32 enable_ref_frame_mvs : 1;
UINT32 reference_frame_update : 1;
UINT32 error_resilient_mode : 1;
} coding;
};
struct {
USHORT cols;
USHORT rows;
USHORT context_update_id;
USHORT widths[64];
USHORT heights[64];
UINT32 tile_offset_start[128];
UINT32 tile_offset_end[128];
UCHAR tile_sz_mag;
} tiles;
struct {
UCHAR frame_type ;
UCHAR show_frame ;
UCHAR showable_frame;
UCHAR subsampling_x ;
UCHAR subsampling_y ;
UCHAR mono_chrome ;
} format;
UCHAR primary_ref_frame;
UCHAR order_hint;
UCHAR order_hint_bits;
struct {
UCHAR filter_level[2] ;
UCHAR filter_level_u ;
UCHAR filter_level_v ;
UCHAR sharpness_level ;
UCHAR mode_ref_delta_enabled ;
UCHAR mode_ref_delta_update ;
UCHAR delta_lf_multi ;
UCHAR delta_lf_present ;
UCHAR delta_lf_res ;
CHAR ref_deltas[8] ;
CHAR mode_deltas[2] ;
UCHAR frame_restoration_type[3] ;
UCHAR log2_restoration_unit_size[3];
} loop_filter;
struct {
UCHAR delta_q_present;
UCHAR delta_q_res ;
UCHAR base_qindex ;
CHAR y_dc_delta_q ;
CHAR u_dc_delta_q ;
CHAR v_dc_delta_q ;
CHAR u_ac_delta_q ;
CHAR v_ac_delta_q ;
UCHAR qm_y ;
UCHAR qm_u ;
UCHAR qm_v ;
} quantization;
struct {
UCHAR damping;
UCHAR bits;
struct {
UCHAR primary;
UCHAR secondary;
} y_strengths[8];
struct {
UCHAR primary;
UCHAR secondary;
} uv_strengths[8];
} cdef;
struct {
UCHAR enabled ;
UCHAR update_map ;
UCHAR update_data ;
UCHAR temporal_update ;
UCHAR feature_mask[8] ;
INT feature_data[8][8];
} segmentation;
struct {
UCHAR apply_grain ;
UCHAR scaling_shift_minus8 ;
UCHAR chroma_scaling_from_luma ;
UCHAR ar_coeff_lag ;
UCHAR ar_coeff_shift_minus6 ;
UCHAR grain_scale_shift ;
UCHAR overlap_flag ;
UCHAR clip_to_restricted_range ;
UCHAR matrix_coeff_is_identity ;
UCHAR num_y_points ;
UCHAR num_cb_points ;
UCHAR num_cr_points ;
UCHAR scaling_points_y[14][2] ;
UCHAR scaling_points_cb[10][2] ;
UCHAR scaling_points_cr[10][2] ;
UCHAR ar_coeffs_y[24] ;
UCHAR ar_coeffs_cb[25] ;
UCHAR ar_coeffs_cr[25] ;
UCHAR cb_mult ;
UCHAR cb_luma_mult ;
UCHAR cr_mult ;
UCHAR cr_luma_mult ;
USHORT grain_seed ;
USHORT cb_offset ;
USHORT cr_offset ;
} film_grain;
struct {
UINT32 width;
UINT32 height;
UINT32 order_hint;
UINT32 lst_frame_offset;
UINT32 lst2_frame_offset;
UINT32 lst3_frame_offset;
UINT32 gld_frame_offset;
UINT32 bwd_frame_offset;
UINT32 alt2_frame_offset;
UINT32 alt_frame_offset;
UINT32 is_intra_frame;
UINT32 intra_only;
CHAR Index;
UCHAR wminvalid;
UCHAR wmtype;
RK_S32 wmmat[6];
USHORT alpha, beta, gamma, delta;
} frame_refs[7];
UCHAR coded_lossless;
UCHAR interp_filter;
UCHAR RefFrameMapTextureIndex[7];
UINT32 upscaled_width;
UINT32 frame_to_show_map_idx;
UINT32 frame_tag_size;
UINT32 offset_to_dct_parts;
UCHAR skip_ref0;
UCHAR skip_ref1;
RK_U8 refresh_frame_flags;
void *cdfs;
void *cdfs_ndvc;
RK_U8 tile_cols_log2;
} DXVA_PicParams_AV1, *LPDXVA_PicParams_AV1;
typedef struct _DXVA_Slice_AV1_Short {
UINT BSNALunitDataLocation;
UINT SliceByteInBuffer;
USHORT wBadSliceChopping;
} DXVA_Slice_AV1_Short, *LPDXVA_Slice_AV1_Short;
#endif

View File

@@ -65,6 +65,9 @@ static MppCodingTypeInfo support_list[] = {
#if HAVE_JPEGD
{ MPP_CTX_DEC, MPP_VIDEO_CodingMJPEG, "dec", "jpeg", },
#endif
#if HAVE_AV1D
{ MPP_CTX_DEC, MPP_VIDEO_CodingAV1, "dec", "av1", },
#endif
#if HAVE_H264E
{ MPP_CTX_ENC, MPP_VIDEO_CodingAVC, "enc", "h.264/AVC", },
#endif