Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions decoder/ihevcd_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2466,6 +2466,8 @@ WORD32 ihevcd_create(iv_obj_t *ps_codec_obj,
ps_create_ip->u4_enable_yuv_formats = 1 << CHROMA_FMT_IDC_YUV420;
}
ps_codec->u4_enable_yuv_formats = ps_create_ip->u4_enable_yuv_formats;
ps_codec->u4_enable_hbd = ps_create_ip->u4_enable_hbd;

ret = ihevcd_init(ps_codec);

TRACE_INIT(NULL);
Expand Down
12 changes: 12 additions & 0 deletions decoder/ihevcd_cxa.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ typedef struct {
* NOTE: If this field is set to 0, YUV 4:2:0 will be enabled by default.
*/
UWORD32 u4_enable_yuv_formats;

/**
* Flag specifying whether the decoder is allowed to support 10-bit decoding.
*
* Values and corresponding behavior:
* 0: Disable 10-bit decoding (only 8-bit decoding is supported)
* 1: Enable 10-bit decoding
*
* NOTE: When this field is set to 0, an error will be returned if
* bit_depth_luma_minus8 or bit_depth_chroma_minus8 are non-zero in SPS.
*/
UWORD32 u4_enable_hbd;
}ihevcd_cxa_create_ip_t;


Expand Down
10 changes: 10 additions & 0 deletions decoder/ihevcd_parse_headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1709,6 +1709,11 @@ IHEVCD_ERROR_T ihevcd_parse_sps(codec_t *ps_codec)


UEV_PARSE("bit_depth_luma_minus8", value, ps_bitstrm);
if ((0 == ps_codec->u4_enable_hbd) && (0 != value))
{
ps_codec->s_parse.i4_error_code = IHEVCD_UNSUPPORTED_BIT_DEPTH;
return IHEVCD_UNSUPPORTED_BIT_DEPTH;
}
// Limit the support to max bit depth of 10-bit
if (value > 2)
return IHEVCD_UNSUPPORTED_BIT_DEPTH;
Expand All @@ -1722,6 +1727,11 @@ IHEVCD_ERROR_T ihevcd_parse_sps(codec_t *ps_codec)
ps_sps->i1_bit_depth_luma_minus8 = value;

UEV_PARSE("bit_depth_chroma_minus8", value, ps_bitstrm);
if ((0 == ps_codec->u4_enable_hbd) && (0 != value))
{
ps_codec->s_parse.i4_error_code = IHEVCD_UNSUPPORTED_BIT_DEPTH;
return IHEVCD_UNSUPPORTED_BIT_DEPTH;
}
// Limit the support to max bit depth of 10-bit
if (value > 2)
return IHEVCD_UNSUPPORTED_BIT_DEPTH;
Expand Down
5 changes: 5 additions & 0 deletions decoder/ihevcd_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,11 @@ struct _codec_t
*/
UWORD32 u4_enable_yuv_formats;

/**
* Controls whether the decoder is allowed to support 10-bit decoding
*/
UWORD32 u4_enable_hbd;

/**
* Pointer to hold TU data for a set of CTBs or a picture
*/
Expand Down
14 changes: 13 additions & 1 deletion examples/decoder/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ typedef struct
/* Enable YUV formats */
UWORD32 u4_enable_yuv_formats;

/* Enable High Bit Depth (10-bit) */
UWORD32 u4_enable_hbd;

/* Active threads present*/
UWORD32 i4_active_threads;

Expand Down Expand Up @@ -286,6 +289,7 @@ typedef enum
PICLEN_FILE,

ENABLE_YUV_FORMAT,
ENABLE_HBD,
KEEP_THREADS_ACTIVE,
}ARGUMENT_T;

Expand Down Expand Up @@ -353,7 +357,9 @@ static const argument_t argument_mapping[] =
{ "--", "--soc", SOC,
"Set SOC. Supported values GENERIC, HISI_37X \n" },
{ "--", "--enable_yuv_format", ENABLE_YUV_FORMAT,
"Enable specific YUV formats" },
"Enable specific YUV formats\n" },
{ "--", "--enable_hbd", ENABLE_HBD,
"Enable High Bit Depth (10-bit) decoding\n" },
{"--", "--keep_threads_active", KEEP_THREADS_ACTIVE,
"Keep threads active"},
};
Expand Down Expand Up @@ -1346,6 +1352,10 @@ void parse_argument(vid_dec_ctx_t *ps_app_ctx, CHAR *argument, CHAR *value)
sscanf(value, "%d", &ps_app_ctx->u4_enable_yuv_formats);
break;

case ENABLE_HBD:
sscanf(value, "%d", &ps_app_ctx->u4_enable_hbd);
break;

case KEEP_THREADS_ACTIVE:
sscanf(value, "%d", &ps_app_ctx->i4_active_threads);
break;
Expand Down Expand Up @@ -1895,6 +1905,7 @@ int main(WORD32 argc, CHAR *argv[])
s_app_ctx.u4_piclen_flag = 0;
s_app_ctx.u4_frame_info_enable = 0;
s_app_ctx.i4_active_threads = 1;
s_app_ctx.u4_enable_hbd = 1;
s_app_ctx.fps = DEFAULT_FPS;
file_pos = 0;
total_bytes_comsumed = 0;
Expand Down Expand Up @@ -2174,6 +2185,7 @@ int main(WORD32 argc, CHAR *argv[])
s_create_op.s_ivd_create_op_t.u4_size = sizeof(ihevcd_cxa_create_op_t);
s_create_ip.u4_enable_frame_info = s_app_ctx.u4_frame_info_enable;
s_create_ip.u4_enable_yuv_formats = s_app_ctx.u4_enable_yuv_formats;
s_create_ip.u4_enable_hbd = s_app_ctx.u4_enable_hbd;
s_create_ip.u4_keep_threads_active = s_app_ctx.i4_active_threads;


Expand Down
1 change: 1 addition & 0 deletions fuzzer/hevc_dec_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void Codec::createCodec(FuzzedDataProvider &fdp) {
create_ip.s_ivd_create_ip_t.pf_aligned_free = iv_aligned_free;
create_ip.s_ivd_create_ip_t.pv_mem_ctxt = NULL;
create_ip.u4_enable_yuv_formats = 0b1111; // Enable 400, 420, 422 and 444
create_ip.u4_enable_hbd = 1;
create_ip.s_ivd_create_ip_t.u4_size = sizeof(ihevcd_cxa_create_ip_t);
create_op.s_ivd_create_op_t.u4_size = sizeof(ihevcd_cxa_create_op_t);

Expand Down
2 changes: 2 additions & 0 deletions tests/decoder/DecHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ std::unique_ptr<DecHelper> DecHelper::Builder::build() {
helper->mInputFilePath = mInputFilePath;
helper->mOutputFilePath = mOutputFilePath;
helper->mRefMd5Path = mRefMd5Path;
helper->mEnableHbd = mEnableHbd;

// Load and parse expected reference MD5s if the path is provided
if (mRefMd5Path.has_value()) {
Expand Down Expand Up @@ -214,6 +215,7 @@ bool DecHelper::initDecoder() {

createIp.u4_enable_frame_info = 0;
createIp.u4_enable_yuv_formats = 15; // Supports all chroma formats
createIp.u4_enable_hbd = mEnableHbd;
createIp.u4_keep_threads_active = 1;

IV_API_CALL_STATUS_T ret =
Expand Down
6 changes: 6 additions & 0 deletions tests/decoder/DecHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class DecHelper {
mRefMd5Path = path;
return *this;
}
Builder& setEnableHbd(bool enableHbd) {
mEnableHbd = enableHbd;
return *this;
}

// Validates parameters and returns an initialized DecHelper instance
std::unique_ptr<DecHelper> build();
Expand All @@ -73,6 +77,7 @@ class DecHelper {
std::optional<std::string> mInputFilePath;
std::optional<std::string> mOutputFilePath;
std::optional<std::string> mRefMd5Path;
bool mEnableHbd = true;
friend class DecHelper;
};

Expand Down Expand Up @@ -116,6 +121,7 @@ class DecHelper {
std::optional<std::string> mOutputFilePath;
std::optional<std::string> mRefMd5Path;
std::vector<std::string> mRefMd5s;
bool mEnableHbd = true;

BitsFile mBitsFile;
RawFile mOutFile;
Expand Down
24 changes: 24 additions & 0 deletions tests/decoder/DecTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@ TEST_P(DecTestFixture, DecodeVerify) {
<< "Decoding failed for input: " << inputPath;
}

TEST(DecTest, Decode10bDisabledHbdError) {
const std::vector<std::pair<std::string, Format>> k10bStreams = {
{"bbb_10b_176x144_yuv400.hevc", Format::yuv400p},
{"bbb_10b_176x144_yuv420.hevc", Format::yuv420p},
{"bbb_10b_176x144_yuv422.hevc", Format::yuv422p},
{"bbb_10b_176x144_yuv444.hevc", Format::yuv444p},
};
for (const auto& [inputFile, format] : k10bStreams) {
std::string inputPath = getFullPath(inputFile);
auto builder = DecHelper::Builder()
.setInputFilePath(inputPath)
.setFormat(format)
.setEnableHbd(false);

std::unique_ptr<DecHelper> helper = builder.build();
ASSERT_NE(helper, nullptr)
<< "Failed to build DecHelper for input: " << inputPath;
EXPECT_FALSE(helper->decodeFile())
<< "Decoder should return an error when decoding 10-bit clip with "
"u4_enable_hbd set to 0 for: "
<< inputPath;
}
}

static const std::vector<DecodeStreamConfig> kDecodeStreams = {
{"bbb_176x144_yuv400.hevc", Format::yuv400p, "bbb_176x144_yuv400_md5.txt"},
{"bbb_176x144_yuv420.hevc", Format::yuv420p, "bbb_176x144_yuv420_md5.txt"},
Expand Down
Loading