From bcad9f4374f840b55f19e13917c3fd3adc5cfc7c Mon Sep 17 00:00:00 2001 From: bjornvolcker Date: Mon, 16 Dec 2024 11:53:28 +0100 Subject: [PATCH] Adds AV1 support in test text strings --- lib/src/legacy/legacy_h26x_common.c | 1 + lib/src/signed_video_h26x_common.c | 1 + lib/src/signed_video_h26x_sign.c | 5 +++ tests/check/check_signed_video_sign.c | 9 +++-- tests/check/test_stream.c | 56 +++++++++++++++++++++------ 5 files changed, 57 insertions(+), 15 deletions(-) diff --git a/lib/src/legacy/legacy_h26x_common.c b/lib/src/legacy/legacy_h26x_common.c index 95bd160..c90beb3 100644 --- a/lib/src/legacy/legacy_h26x_common.c +++ b/lib/src/legacy/legacy_h26x_common.c @@ -433,6 +433,7 @@ legacy_parse_av1_obu_header(legacy_h26x_nalu_t *obu) obu->nalu_type = NALU_TYPE_SEI; break; case 6: // 6 OBU_FRAME + // Read frame_type (2 bits) obu->nalu_type = ((*obu_ptr & 0x60) >> 5) == 0 ? NALU_TYPE_I : NALU_TYPE_P; obu->is_primary_slice = true; break; diff --git a/lib/src/signed_video_h26x_common.c b/lib/src/signed_video_h26x_common.c index 63c84d0..840ba7b 100644 --- a/lib/src/signed_video_h26x_common.c +++ b/lib/src/signed_video_h26x_common.c @@ -579,6 +579,7 @@ parse_av1_obu_header(h26x_nalu_t *obu) obu->nalu_type = NALU_TYPE_SEI; break; case 6: // 6 OBU_FRAME + // Read frame_type (2 bits) obu->nalu_type = ((*obu_ptr & 0x60) >> 5) == 0 ? NALU_TYPE_I : NALU_TYPE_P; obu->is_primary_slice = true; break; diff --git a/lib/src/signed_video_h26x_sign.c b/lib/src/signed_video_h26x_sign.c index 50d9ffc..96297f8 100644 --- a/lib/src/signed_video_h26x_sign.c +++ b/lib/src/signed_video_h26x_sign.c @@ -502,6 +502,11 @@ signed_video_add_nalu_part_for_signing_with_timestamp(signed_video_t *self, } nalu.hashable_data_size = nalu_data_size; } + if (self->codec == SV_CODEC_AV1) { + // Not yet implemented, but return SV_OK to run through tests. + free(nalu.nalu_data_wo_epb); + return prepare_for_nalus_to_prepend(self); + } svrc_t status = SV_UNKNOWN_FAILURE; SV_TRY() diff --git a/tests/check/check_signed_video_sign.c b/tests/check/check_signed_video_sign.c index de29704..f69358f 100644 --- a/tests/check/check_signed_video_sign.c +++ b/tests/check/check_signed_video_sign.c @@ -501,11 +501,14 @@ START_TEST(correct_nalu_sequence_without_eos) { // This test runs in a loop with loop index _i, corresponding to struct sv_setting _i in // |settings|; See signed_video_helpers.h. - if (settings[_i].codec == SV_CODEC_AV1) return; test_stream_t *list = create_signed_nalus("IPPIPPIPPIPPIPPIPP", settings[_i]); - test_stream_check_types(list, "IPPISPPISPPISPPISPPISPP"); - verify_seis(list, settings[_i]); + if (settings[_i].codec == SV_CODEC_AV1) { + test_stream_check_types(list, "IPPIPPIPPIPPIPPIPP"); + } else { + test_stream_check_types(list, "IPPISPPISPPISPPISPPISPP"); + verify_seis(list, settings[_i]); + } test_stream_free(list); } END_TEST diff --git a/tests/check/test_stream.c b/tests/check/test_stream.c index a1ecece..ca1297d 100644 --- a/tests/check/test_stream.c +++ b/tests/check/test_stream.c @@ -77,6 +77,22 @@ static const uint8_t p_nalu_h265[DUMMY_NALU_SIZE] = {0x02, 0x01, 0x00, 0x00, 0x8 static const uint8_t pps_nalu_h265[DUMMY_NALU_SIZE] = {0x44, 0x01, 0x00, 0x00, 0x80}; static const uint8_t sei_nalu_h265[DUMMY_SEI_SIZE] = {0x4e, 0x01, 0x05, 0x11, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x80}; +/* The AV1 pattern is as follows: + * + * general OBU + * |-- 1 byte --|-- 1 byte --|-- 1 byte --|-- 1 byte --|-- 1 byte --| + * OBU header size frame header id stop bit + * + * "SEI" + * |-- 1 byte --|-- 1 byte --|-- 1 byte --|-- 1 byte --|-- 1 byte --| + * OBU header size metadata type id stop bit + * + */ +const uint8_t I_av1[DUMMY_NALU_SIZE] = {0x32, 0x03, 0x10, 0x00, 0x80}; +const uint8_t P_av1[DUMMY_NALU_SIZE] = {0x32, 0x03, 0x30, 0x00, 0x80}; +const uint8_t sh_av1[DUMMY_NALU_SIZE] = {0x0a, 0x03, 0x00, 0x00, 0x80}; +const uint8_t sei_av1[DUMMY_NALU_SIZE] = {0x2a, 0x03, 0x18, 0x00, 0x80}; +const uint8_t invalid_av1[DUMMY_NALU_SIZE] = {0x02, 0x03, 0xff, 0x00, 0xff}; /* Helper that parses information from the NAL Unit |data| and returns a character * representing the NAL Unit type. */ @@ -151,41 +167,57 @@ generate_nalu(bool valid_start_code, test_stream_item_t * test_stream_item_create_from_type(char type, uint8_t id, SignedVideoCodec codec) { - uint8_t *nalu = NULL; // Final NAL Unit with start code and id. + uint8_t *nalu = NULL; // Final NAL Unit (or OBU) with id and with/without start code. const uint8_t *nalu_data = NULL; - size_t nalu_data_size = DUMMY_NALU_SIZE; // Change if we have a SEI. - bool start_code = true; // Use a valid start code by default. + size_t nalu_data_size = DUMMY_NALU_SIZE; // Change if it is a H.26x SEI. + bool start_code = true; // Use a valid start code by default unless AV1. // Find out which type of NAL Unit the character is and point |nalu_data| to it. switch (type) { case 'I': - nalu_data = codec == SV_CODEC_H264 ? I_nalu_h264 : I_nalu_h265; + nalu_data = + codec == SV_CODEC_H264 ? I_nalu_h264 : (codec == SV_CODEC_H265 ? I_nalu_h265 : I_av1); break; case 'i': - nalu_data = codec == SV_CODEC_H264 ? i_nalu_h264 : i_nalu_h265; + // Not yet valid for AV1. + nalu_data = codec == SV_CODEC_H264 ? i_nalu_h264 + : (codec == SV_CODEC_H265 ? i_nalu_h265 : invalid_av1); break; case 'P': - nalu_data = codec == SV_CODEC_H264 ? P_nalu_h264 : P_nalu_h265; + nalu_data = + codec == SV_CODEC_H264 ? P_nalu_h264 : (codec == SV_CODEC_H265 ? P_nalu_h265 : P_av1); break; case 'p': - nalu_data = codec == SV_CODEC_H264 ? p_nalu_h264 : p_nalu_h265; + // Not yet valid for AV1. + nalu_data = codec == SV_CODEC_H264 ? p_nalu_h264 + : (codec == SV_CODEC_H265 ? p_nalu_h265 : invalid_av1); break; case 'Z': - nalu_data = codec == SV_CODEC_H264 ? sei_nalu_h264 : sei_nalu_h265; - nalu_data_size = DUMMY_SEI_SIZE; + nalu_data = codec == SV_CODEC_H264 ? sei_nalu_h264 + : (codec == SV_CODEC_H265 ? sei_nalu_h265 : sei_av1); + nalu_data_size = (codec != SV_CODEC_AV1) ? DUMMY_SEI_SIZE : DUMMY_NALU_SIZE; break; case 'V': - nalu_data = codec == SV_CODEC_H264 ? pps_nalu_h264 : pps_nalu_h265; + nalu_data = codec == SV_CODEC_H264 ? pps_nalu_h264 + : (codec == SV_CODEC_H265 ? pps_nalu_h265 : sh_av1); break; case 'X': default: - nalu_data = invalid_nalu; + nalu_data = (codec != SV_CODEC_AV1) ? invalid_nalu : invalid_av1; start_code = false; break; } size_t nalu_size = 0; - nalu = generate_nalu(start_code, nalu_data, nalu_data_size, id, &nalu_size); + if (codec != SV_CODEC_AV1) { + nalu = generate_nalu(start_code, nalu_data, nalu_data_size, id, &nalu_size); + } else { + // For AV1 all OBUs are of same size and have no start code. No need for a function. + nalu = (uint8_t *)malloc(DUMMY_NALU_SIZE); + memcpy(nalu, nalu_data, nalu_data_size); + nalu[DUMMY_NALU_SIZE - 2] = id; // Set ID to make it unique. + nalu_size = DUMMY_NALU_SIZE; + } ck_assert(nalu); ck_assert(nalu_size > 0); ck_assert_int_eq(nalu[nalu_size - 2], id); // Check id.