Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds AV1 support in test text strings #277

Merged
merged 1 commit into from
Dec 16, 2024
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
1 change: 1 addition & 0 deletions lib/src/legacy/legacy_h26x_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/src/signed_video_h26x_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions lib/src/signed_video_h26x_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions tests/check/check_signed_video_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 44 additions & 12 deletions tests/check/test_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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.
Expand Down
Loading