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
1 change: 1 addition & 0 deletions lib/src/sv_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ typedef enum {
BU_TYPE_PS = 4, // Parameter Set: PPS/SPS/VPS and similar for AV1
BU_TYPE_AUD = 5,
BU_TYPE_OTHER = 6,
BU_TYPE_TG = 7,
} SignedVideoFrameType;

typedef enum {
Expand Down
42 changes: 21 additions & 21 deletions tests/check/check_signed_video_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ START_TEST(invalid_api_inputs)

signed_video_t *sv = signed_video_create(codec);
ck_assert(sv);
test_stream_item_t *p_frame = test_stream_item_create_from_type('P', 0, codec);
test_stream_item_t *invalid = test_stream_item_create_from_type('X', 0, codec);
test_stream_item_t *p_frame = test_stream_item_create_from_type('P', 0, codec, false);
test_stream_item_t *invalid = test_stream_item_create_from_type('X', 0, codec, false);

// signed_video_add_nalu_and_authenticate()
// NULL pointers are invalid, as well as zero sized BUs.
Expand Down Expand Up @@ -1001,7 +1001,7 @@ START_TEST(add_one_sei_after_signing)
test_stream_check_types(list, "IPPISPPPISPPISP");

const uint8_t id = 0;
test_stream_item_t *sei = test_stream_item_create_from_type('Z', id, codec);
test_stream_item_t *sei = test_stream_item_create_from_type('Z', id, codec, false);

// Append the middle 'P' in second GOP: IPPISP P(Z) PISPPISP
const int append_item_number = 7;
Expand Down Expand Up @@ -1463,7 +1463,7 @@ END_TEST
*/
START_TEST(onvif_seis)
{
test_stream_t *list = test_stream_create("IPIOPIOP", settings[_i].codec);
test_stream_t *list = test_stream_create("IPIOPIOP", settings[_i].codec, false);
if (settings[_i].codec == SV_CODEC_AV1) {
// ONVIF Media Signing is not supported for AV1.
test_stream_check_types(list, "IPIPIP");
Expand Down Expand Up @@ -1499,7 +1499,7 @@ END_TEST
*/
START_TEST(no_signature)
{
test_stream_t *list = test_stream_create("IPPIPPIPPIPPI", settings[_i].codec);
test_stream_t *list = test_stream_create("IPPIPPIPPIPPI", settings[_i].codec, false);
test_stream_check_types(list, "IPPIPPIPPIPPI");

// Video is not signed, hence all Bitstream Units are pending.
Expand All @@ -1519,7 +1519,7 @@ START_TEST(multislice_no_signature)
{
// For AV1, multi-slices are covered in one single OBU (OBU Frame).
if (settings[_i].codec == SV_CODEC_AV1) return;
test_stream_t *list = test_stream_create("IiPpPpIiPpPpIiPpPpIiPpPpIi", settings[_i].codec);
test_stream_t *list = test_stream_create("IiPpPpIiPpPpIiPpPpIiPpPpIi", settings[_i].codec, false);
test_stream_check_types(list, "IiPpPpIiPpPpIiPpPpIiPpPpIi");

// Video is not signed, hence all Bitstream Units are pending.
Expand Down Expand Up @@ -1576,9 +1576,9 @@ START_TEST(vendor_axis_communications_operation)
SignedVideoReturnCode sv_rc;
struct sv_setting setting = settings[_i];
SignedVideoCodec codec = settings[_i].codec;
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, codec);
test_stream_item_t *p_frame = test_stream_item_create_from_type('P', 1, codec);
test_stream_item_t *i_frame_2 = test_stream_item_create_from_type('I', 2, codec);
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, codec, false);
test_stream_item_t *p_frame = test_stream_item_create_from_type('P', 1, codec, false);
test_stream_item_t *i_frame_2 = test_stream_item_create_from_type('I', 2, codec, false);
test_stream_item_t *sei_item = NULL;
uint8_t *sei = NULL;
size_t sei_size = 0;
Expand Down Expand Up @@ -1691,9 +1691,9 @@ START_TEST(factory_provisioned_key)
#ifndef NO_ONVIF_MEDIA_SIGNING
if (codec != SV_CODEC_AV1) return;
#endif
test_stream_item_t *i_item = test_stream_item_create_from_type('I', 0, codec);
test_stream_item_t *p_item = test_stream_item_create_from_type('P', 1, codec);
test_stream_item_t *i_item_2 = test_stream_item_create_from_type('I', 2, codec);
test_stream_item_t *i_item = test_stream_item_create_from_type('I', 0, codec, false);
test_stream_item_t *p_item = test_stream_item_create_from_type('P', 1, codec, false);
test_stream_item_t *i_item_2 = test_stream_item_create_from_type('I', 2, codec, false);
test_stream_item_t *sei_item = NULL;
uint8_t *sei = NULL;
size_t sei_size = 0;
Expand Down Expand Up @@ -1844,8 +1844,8 @@ generate_and_set_private_key_on_camera_side(struct sv_setting setting,
SignedVideoReturnCode sv_rc;
char *private_key = NULL;
size_t private_key_size = 0;
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, setting.codec);
test_stream_item_t *i_frame_2 = test_stream_item_create_from_type('I', 1, setting.codec);
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, setting.codec, false);
test_stream_item_t *i_frame_2 = test_stream_item_create_from_type('I', 1, setting.codec, false);
signed_video_t *sv = signed_video_create(setting.codec);
ck_assert(sv);
// Read and set content of private_key.
Expand Down Expand Up @@ -1894,7 +1894,7 @@ validate_public_key_scenario(signed_video_t *sv,
signed_video_authenticity_t *auth_report = NULL;
signed_video_latest_validation_t *latest = NULL;

test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, codec);
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, codec, false);
sv_rc =
signed_video_add_nalu_and_authenticate(sv, i_frame->data, i_frame->data_size, &auth_report);
ck_assert(!auth_report);
Expand Down Expand Up @@ -2028,8 +2028,8 @@ START_TEST(no_public_key_in_sei_and_bad_public_key_on_validation_side)
{
SignedVideoReturnCode sv_rc;
SignedVideoCodec codec = settings[_i].codec;
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, codec);
test_stream_item_t *i_frame_2 = test_stream_item_create_from_type('I', 1, codec);
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, codec, false);
test_stream_item_t *i_frame_2 = test_stream_item_create_from_type('I', 1, codec, false);
test_stream_item_t *sei = NULL;
signed_video_t *sv_camera = NULL;
char *tmp_private_key = NULL;
Expand Down Expand Up @@ -2098,8 +2098,8 @@ START_TEST(no_emulation_prevention_bytes)
SignedVideoReturnCode sv_rc;

// Create a video with a single I-frame, and a SEI (to be created later).
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, codec);
test_stream_item_t *i_frame_2 = test_stream_item_create_from_type('I', 1, codec);
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, codec, false);
test_stream_item_t *i_frame_2 = test_stream_item_create_from_type('I', 1, codec, false);

test_stream_item_t *sei_item = NULL;
uint8_t *sei = NULL;
Expand Down Expand Up @@ -2561,7 +2561,7 @@ START_TEST(add_one_p_frame_partial_gops)
test_stream_check_types(list, "IPPPPSPISPPISPPPPSPISP");

// Add a middle 'P' in third GOP: IPPPPSPISPPISP P PPPSPISP
test_stream_item_t *p = test_stream_item_create_from_type('P', 100, settings[_i].codec);
test_stream_item_t *p = test_stream_item_create_from_type('P', 100, settings[_i].codec, false);
const int append_item_number = 14;
test_stream_append_item(list, p, append_item_number);
test_stream_check_types(list, "IPPPPSPISPPISPPPPPSPISP");
Expand Down Expand Up @@ -3018,7 +3018,7 @@ START_TEST(add_one_p_frame_multiple_gops)
test_stream_check_types(list, "IPPIsPPIsPPISPPIsPPIsPPISP");

// Add a middle 'P' in second GOP: IPPIsP P PIsPPISPPIsPPIsPPISP
test_stream_item_t *p = test_stream_item_create_from_type('P', 100, settings[_i].codec);
test_stream_item_t *p = test_stream_item_create_from_type('P', 100, settings[_i].codec, false);
const int append_nalu_number = 6;
test_stream_append_item(list, p, append_nalu_number);
test_stream_check_types(list, "IPPIsPPPIsPPISPPIsPPIsPPISP");
Expand Down
22 changes: 11 additions & 11 deletions tests/check/check_signed_video_sign.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ START_TEST(api_inputs)
{
SignedVideoReturnCode sv_rc;
SignedVideoCodec codec = settings[_i].codec;
test_stream_item_t *p_frame = test_stream_item_create_from_type('P', 0, codec);
test_stream_item_t *invalid = test_stream_item_create_from_type('X', 0, codec);
test_stream_item_t *p_frame = test_stream_item_create_from_type('P', 0, codec, false);
test_stream_item_t *invalid = test_stream_item_create_from_type('X', 0, codec, false);
char *private_key = NULL;
size_t private_key_size = 0;
uint8_t *sei = NULL;
Expand Down Expand Up @@ -357,8 +357,8 @@ START_TEST(incorrect_operation)
ck_assert(sv);
char *private_key = NULL;
size_t private_key_size = 0;
test_stream_item_t *p_frame = test_stream_item_create_from_type('P', 0, codec);
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, codec);
test_stream_item_t *p_frame = test_stream_item_create_from_type('P', 0, codec, false);
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, codec, false);
// The path to openssl keys has to be set before start of signing.
SignedVideoReturnCode sv_rc =
signed_video_add_nalu_for_signing_with_timestamp(sv, i_frame->data, i_frame->data_size, NULL);
Expand Down Expand Up @@ -685,11 +685,11 @@ START_TEST(two_completed_seis_pending)
signed_video_t *sv = get_initialized_signed_video(settings[_i], false);
ck_assert(sv);

test_stream_item_t *i_frame_1 = test_stream_item_create_from_type('I', 0, codec);
test_stream_item_t *i_frame_2 = test_stream_item_create_from_type('I', 1, codec);
test_stream_item_t *p_frame = test_stream_item_create_from_type('P', 2, codec);
test_stream_item_t *i_frame_3 = test_stream_item_create_from_type('I', 3, codec);
test_stream_item_t *i_frame_4 = test_stream_item_create_from_type('i', 4, codec);
test_stream_item_t *i_frame_1 = test_stream_item_create_from_type('I', 0, codec, false);
test_stream_item_t *i_frame_2 = test_stream_item_create_from_type('I', 1, codec, false);
test_stream_item_t *p_frame = test_stream_item_create_from_type('P', 2, codec, false);
test_stream_item_t *i_frame_3 = test_stream_item_create_from_type('I', 3, codec, false);
test_stream_item_t *i_frame_4 = test_stream_item_create_from_type('i', 4, codec, false);

sv_rc = signed_video_add_nalu_for_signing_with_timestamp(
sv, i_frame_1->data, i_frame_1->data_size, NULL);
Expand Down Expand Up @@ -808,8 +808,8 @@ START_TEST(w_wo_emulation_prevention_bytes)
uint8_t *seis[NUM_EPB_CASES] = {NULL, NULL};
size_t sei_sizes[NUM_EPB_CASES] = {0, 0};
bool with_emulation_prevention[NUM_EPB_CASES] = {true, false};
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, codec);
test_stream_item_t *i_frame_2 = test_stream_item_create_from_type('I', 1, codec);
test_stream_item_t *i_frame = test_stream_item_create_from_type('I', 0, codec, false);
test_stream_item_t *i_frame_2 = test_stream_item_create_from_type('I', 1, codec, false);

size_t sei_size = 0;
unsigned num_pending_seis = 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/check/legacy_test_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ get_legacy_stream(int idx, SignedVideoCodec codec)
// Check if this test case is valid.
if (!legacy_data[idx][0].data || (legacy_data[idx][0].data_size == 0)) return NULL;

test_stream_t *list = test_stream_create("", codec);
test_stream_t *list = test_stream_create("", codec, false);
for (int ii = 0; ii < LEGACY_STREAM_LENGTH; ii++) {
uint8_t *data = malloc(legacy_data[idx][ii].data_size);
memcpy(data, legacy_data[idx][ii].data, legacy_data[idx][ii].data_size);
Expand Down
2 changes: 1 addition & 1 deletion tests/check/test_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ create_signed_stream_with_sv(signed_video_t *sv, const char *str, bool split_bu,
const bool apply_ep = false; // Apply emulation prevention on generated SEI afterwards.
const bool get_seis_at_end = false; // Fetch all SEIs at once at the end of the stream.
// Create a test stream given the input string.
test_stream_t *list = test_stream_create(str, sv->codec);
test_stream_t *list = test_stream_create(str, sv->codec, false);
test_stream_item_t *item = list->first_item;
int64_t timestamp = g_testTimestamp;
num_gops_until_signing = sv->signing_frequency - 1;
Expand Down
42 changes: 29 additions & 13 deletions tests/check/test_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ 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};

const uint8_t I_fh_av1[DUMMY_NALU_SIZE] = {0x1a, 0x03, 0x10, 0x00, 0x80};
const uint8_t P_fh_av1[DUMMY_NALU_SIZE] = {0x1a, 0x03, 0x30, 0x00, 0x80};
const uint8_t tg_av1[DUMMY_NALU_SIZE] = {0x22, 0x03, 0x00, 0x00, 0x80};
// TODO: Maybe add OBU_TILE_LIST later
// const uint8_t P_tl_av1[DUMMY_NALU_SIZE] = {0x42, 0x03, 0x02, 0x00, 0x80};

/* Helper that parses information from the Bitstream Unit |data| and returns a character
* representing the Bitstream Unit type. */
static char
Expand Down Expand Up @@ -133,6 +139,9 @@ get_type_char(const uint8_t *data, size_t data_size, SignedVideoCodec codec)
type = 's';
break;
}
case BU_TYPE_TG:
type = 't';
break;
default:
type = '\0';
break;
Expand Down Expand Up @@ -174,7 +183,7 @@ generate_nalu(bool valid_start_code,

/* Creates a test_stream_item_t from |type| for |codec|, then sets the |id|. */
test_stream_item_t *
test_stream_item_create_from_type(char type, uint8_t id, SignedVideoCodec codec)
test_stream_item_create_from_type(char type, uint8_t id, SignedVideoCodec codec, bool with_fh)
{
uint8_t *bu = NULL; // Final Bitstream Unit with id and with/without start code.
const uint8_t *bu_data = NULL;
Expand All @@ -184,22 +193,26 @@ test_stream_item_create_from_type(char type, uint8_t id, SignedVideoCodec codec)
// Find out which type of Bitstream Unit the character is and point |bu_data| to it.
switch (type) {
case 'I':
bu_data =
codec == SV_CODEC_H264 ? I_nalu_h264 : (codec == SV_CODEC_H265 ? I_nalu_h265 : I_av1);
bu_data = codec == SV_CODEC_H264
? I_nalu_h264
: (codec == SV_CODEC_H265 ? I_nalu_h265 : (with_fh ? I_fh_av1 : I_av1));
break;
case 'i':
// Not yet valid for AV1.
bu_data = codec == SV_CODEC_H264 ? i_nalu_h264
: (codec == SV_CODEC_H265 ? i_nalu_h265 : invalid_av1);
bu_data = codec == SV_CODEC_H264
? i_nalu_h264
: (codec == SV_CODEC_H265 ? i_nalu_h265 : invalid_av1);
break;
case 'P':
bu_data =
codec == SV_CODEC_H264 ? P_nalu_h264 : (codec == SV_CODEC_H265 ? P_nalu_h265 : P_av1);
bu_data = codec == SV_CODEC_H264
? P_nalu_h264
: (codec == SV_CODEC_H265 ? P_nalu_h265 : (with_fh ? P_fh_av1 : P_av1));
break;
case 'p':
// Not yet valid for AV1.
bu_data = codec == SV_CODEC_H264 ? p_nalu_h264
: (codec == SV_CODEC_H265 ? p_nalu_h265 : invalid_av1);
bu_data = codec == SV_CODEC_H264
? p_nalu_h264
: (codec == SV_CODEC_H265 ? p_nalu_h265 : invalid_av1);
break;
case 'O':
bu_data = codec == SV_CODEC_H264 ? oms_sei_nalu_h264
Expand All @@ -215,6 +228,9 @@ test_stream_item_create_from_type(char type, uint8_t id, SignedVideoCodec codec)
bu_data = codec == SV_CODEC_H264 ? pps_nalu_h264
: (codec == SV_CODEC_H265 ? pps_nalu_h265 : sh_av1);
break;
case 't':
bu_data = (codec == SV_CODEC_AV1 && with_fh) ? tg_av1 : invalid_av1;
break;
case 'X':
default:
bu_data = (codec != SV_CODEC_AV1) ? invalid_nalu : invalid_av1;
Expand Down Expand Up @@ -398,15 +414,15 @@ test_stream_item_print(test_stream_item_t *item)
/* Creates a test stream with items based on the input string for a given |codec|. The
* string is converted to test stream items. */
test_stream_t *
test_stream_create(const char *str, SignedVideoCodec codec)
test_stream_create(const char *str, SignedVideoCodec codec, bool with_fh)
{
test_stream_t *list = (test_stream_t *)calloc(1, sizeof(test_stream_t));
ck_assert(list);
list->codec = codec;
uint8_t i = 0;

while (str[i]) {
test_stream_item_t *new_item = test_stream_item_create_from_type(str[i], i, codec);
test_stream_item_t *new_item = test_stream_item_create_from_type(str[i], i, codec, with_fh);
if (!new_item) {
// No character could be identified. Continue without adding.
i++;
Expand Down Expand Up @@ -470,7 +486,7 @@ test_stream_pop(test_stream_t *list, int number_of_items)
if (!list || number_of_items > list->num_items) return NULL;

// Create an empty list.
test_stream_t *new_list = test_stream_create("", list->codec);
test_stream_t *new_list = test_stream_create("", list->codec, false);
ck_assert(new_list);
// Pop items from list and append to the new_list.
while (number_of_items--) {
Expand Down Expand Up @@ -503,7 +519,7 @@ test_stream_pop_gops(test_stream_t *list, int number_of_gops)
}

// Create an empty list.
test_stream_t *new_list = test_stream_create("", list->codec);
test_stream_t *new_list = test_stream_create("", list->codec, false);
ck_assert(new_list);
// Pop items from list and append to the new_list.
while (number_of_gops) {
Expand Down
11 changes: 7 additions & 4 deletions tests/check/test_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ typedef struct _test_stream_st {
**/

/* Creates a test stream with test stream items based on the input string. The string is
* converted to test stream items. */
* converted to test stream items. For AV1, one can select representing frames with
* OBU_FRAME or OBU_FRAME_HEADER + OBU_TILE_GROUP, the latter if |with_fh| is 'true'. */
test_stream_t *
test_stream_create(const char *str, SignedVideoCodec codec);
test_stream_create(const char *str, SignedVideoCodec codec, bool with_fh);

/* Frees all the items in the list and the list itself. */
void
Expand Down Expand Up @@ -112,9 +113,11 @@ test_stream_print(test_stream_t *list);
* test_stream_item_t functions
**/

/* Creates a test_stream_item_t from a |type| and |codec|. Then sets the |id|. */
/* Creates a test_stream_item_t from a |type| and |codec|. Then sets the |id|. For AV1,
* one can select representing frames with OBU_FRAME or OBU_FRAME_HEADER + OBU_TILE_GROUP,
* the latter if |with_fh| is 'true'.*/
test_stream_item_t *
test_stream_item_create_from_type(char type, uint8_t id, SignedVideoCodec codec);
test_stream_item_create_from_type(char type, uint8_t id, SignedVideoCodec codec, bool with_fh);

/* Creates a new test stream item. Takes pointers to the Bitstream Unit data, the bu data
* size. Memory ownership is transferred. */
Expand Down