Skip to content

Commit e1dc707

Browse files
authored
Adds new AV1 tests in a separate file (#505)
One test has been added and that is "normal" signing with FH. A new input parameter to test stream creation has been added. This parameter tells the system to use OBU_FRAME or FH+TG. Co-authored-by: bjornvolcker <[email protected]>
1 parent 391f05b commit e1dc707

File tree

8 files changed

+153
-24
lines changed

8 files changed

+153
-24
lines changed

lib/src/sv_codec_av1.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ parse_av1_obu_header(bu_info_t *obu)
7777
obu_header_is_valid &= (obu_size == 0);
7878
break;
7979
case 3: // 3 OBU_FRAME_HEADER
80-
obu->bu_type = BU_TYPE_OTHER;
81-
obu_header_is_valid = false; // Not yet supported
80+
obu->bu_type = ((*obu_ptr & 0x60) >> 5) == 0 ? BU_TYPE_I : BU_TYPE_P;
81+
obu->is_primary_slice = true;
8282
break;
8383
case 4: // 4 OBU_TILE_GROUP
84-
obu->bu_type = BU_TYPE_OTHER;
85-
obu_header_is_valid = false; // Not yet supported
84+
obu->bu_type = BU_TYPE_TG;
8685
break;
8786
case 5: // 5 OBU_METADATA
8887
obu->bu_type = BU_TYPE_SEI;

lib/src/sv_common.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,9 @@ parse_bu_info(const uint8_t *bu_data,
509509
bu.is_valid = bu_header_is_valid;
510510

511511
// Only picture BUs are hashed.
512-
if (bu.bu_type == BU_TYPE_I || bu.bu_type == BU_TYPE_P) bu.is_hashable = true;
512+
if (bu.bu_type == BU_TYPE_I || bu.bu_type == BU_TYPE_P || bu.bu_type == BU_TYPE_TG) {
513+
bu.is_hashable = true;
514+
}
513515

514516
bu.is_first_bu_in_gop = (bu.bu_type == BU_TYPE_I) && bu.is_primary_slice;
515517

tests/check/check_codec_av1.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2021 Axis Communications AB
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7+
* and associated documentation files (the "Software"), to deal in the Software without
8+
* restriction, including without limitation the rights to use, copy, modify, merge, publish,
9+
* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
10+
* Software is furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice (including the next paragraph) shall be
13+
* included in all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16+
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20+
*/
21+
#include <check.h>
22+
#include <stdbool.h>
23+
#ifdef PRINT_DECODED_SEI
24+
#include <stdio.h>
25+
#endif
26+
#include <stdlib.h> // EXIT_SUCCESS, EXIT_FAILURE
27+
28+
#include "includes/signed_video_auth.h"
29+
#include "includes/signed_video_common.h"
30+
#include "includes/signed_video_sign.h"
31+
#include "test_helpers.h"
32+
#include "test_stream.h"
33+
34+
#define NUM_SETTINGS_AV1 2
35+
struct sv_setting settings_av1[NUM_SETTINGS_AV1] = {
36+
{SV_CODEC_AV1, SV_AUTHENTICITY_LEVEL_GOP, true, false, false, 0, NULL, 0, 1, false, 0, 0, true},
37+
{SV_CODEC_AV1, SV_AUTHENTICITY_LEVEL_FRAME, true, false, false, 0, NULL, 0, 1, false, 0, 0,
38+
true}};
39+
/* General comments to the validation tests.
40+
* All tests loop through the settings in settings_av1[NUM_SETTINGS_AV1]; See
41+
* signed_video_helpers.h. The index in the loop is _i and something the check test
42+
* framework provides. */
43+
44+
static void
45+
setup()
46+
{
47+
}
48+
49+
static void
50+
teardown()
51+
{
52+
}
53+
54+
START_TEST(signed_stream_with_fh)
55+
{
56+
// This test runs in a loop with loop index _i, corresponding to struct sv_setting _i in
57+
// |settings_av1|; See signed_video_helpers.h.
58+
59+
struct sv_setting setting = settings_av1[_i];
60+
setting.with_fh = true;
61+
test_stream_t *list = create_signed_stream("ItPtPtItPtPtItPtPtItPtPtItPtPt", setting);
62+
test_stream_check_types(list, "ItPtPtItSPtPtItSPtPtItSPtPtItSPtPt");
63+
test_stream_free(list);
64+
}
65+
END_TEST
66+
67+
static Suite *
68+
signed_video_suite(void)
69+
{
70+
// Setup test suit and test case
71+
Suite *suite = suite_create("Signed video signing tests");
72+
TCase *tc = tcase_create("Signed video standard unit test");
73+
tcase_add_checked_fixture(tc, setup, teardown);
74+
75+
// The test loop works like this
76+
// for (int _i = s; _i < e; _i++) {}
77+
78+
int s = 0;
79+
int e = NUM_SETTINGS_AV1;
80+
81+
// Add tests
82+
tcase_add_loop_test(tc, signed_stream_with_fh, s, e);
83+
84+
// Add test case to suit
85+
suite_add_tcase(suite, tc);
86+
return suite;
87+
}
88+
89+
int
90+
main(void)
91+
{
92+
// Create suite runner and run
93+
int failed_tests = 0;
94+
SRunner *sr = srunner_create(NULL);
95+
srunner_add_suite(sr, signed_video_suite());
96+
srunner_run_all(sr, CK_ENV);
97+
failed_tests = srunner_ntests_failed(sr);
98+
srunner_free(sr);
99+
return (failed_tests == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
100+
}

tests/check/check_signed_video_auth.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ START_TEST(fallback_to_gop_level)
15551555

15561556
// Create a list of Bitstream Units given the input string.
15571557
test_stream_t *list =
1558-
create_signed_stream_with_sv(sv, "IPPIPPPPPPPPPPPPPPPPPPPPPPPPIPPIP", false, 0);
1558+
create_signed_stream_with_sv(sv, "IPPIPPPPPPPPPPPPPPPPPPPPPPPPIPPIP", false, 0, false);
15591559
test_stream_check_types(list, "IPPISPPPPPPPPPPPPPPPPPPPPPPPPISPPISP");
15601560

15611561
signed_video_accumulated_validation_t final_validation = {
@@ -1809,7 +1809,7 @@ START_TEST(onvif_intact_stream)
18091809
setting.vendor_axis_mode = 2;
18101810

18111811
// Create a signed video stream with SV.
1812-
test_stream_t *list = create_signed_stream_with_sv(sv, "IPPIPPIPPIPPIPPIPPIP", false, 0);
1812+
test_stream_t *list = create_signed_stream_with_sv(sv, "IPPIPPIPPIPPIPPIPPIP", false, 0, false);
18131813

18141814
// Define expected validation results.
18151815
signed_video_accumulated_validation_t final_validation = {
@@ -2269,7 +2269,7 @@ START_TEST(golden_sei_principle)
22692269
signed_video_t *sv = get_initialized_signed_video(setting, false);
22702270
ck_assert(sv);
22712271

2272-
test_stream_t *list = create_signed_stream_with_sv(sv, "IPPIPPIPPIP", false, 0);
2272+
test_stream_t *list = create_signed_stream_with_sv(sv, "IPPIPPIPPIP", false, 0, false);
22732273
test_stream_check_types(list, "GIPPISPPISPPISP");
22742274

22752275
// GIPPISPPISPPISP

tests/check/check_signed_video_sign.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ START_TEST(vendor_axis_communications_operation)
450450

451451
// Add 2 P-frames between 2 I-frames to mimic a GOP structure in the stream to trigger a
452452
// SEI.
453-
test_stream_t *list = create_signed_stream_with_sv(sv, "IPPIP", false, 0);
453+
test_stream_t *list = create_signed_stream_with_sv(sv, "IPPIP", false, 0, false);
454454
test_stream_check_types(list, "IPPISP");
455455
verify_seis(list, setting);
456456
test_stream_free(list);
@@ -485,7 +485,7 @@ START_TEST(factory_provisioned_key)
485485
setting.vendor_axis_mode = 2;
486486

487487
// Generate a GOP to trigger a SEI.
488-
test_stream_t *list = create_signed_stream_with_sv(sv, "IPPIP", false, 0);
488+
test_stream_t *list = create_signed_stream_with_sv(sv, "IPPIP", false, 0, false);
489489
// If the test has been built with ONVIF Media Signing, factory provisioned keys will
490490
// use Media Signing for H.264 and H.265.
491491
#ifndef NO_ONVIF_MEDIA_SIGNING
@@ -625,7 +625,7 @@ START_TEST(fallback_to_gop_level)
625625

626626
// Create a test stream given the input string.
627627
test_stream_t *list =
628-
create_signed_stream_with_sv(sv, "IPPIPPPPPPPPPPPPPPPPPPPPPPPPIP", false, 0);
628+
create_signed_stream_with_sv(sv, "IPPIPPPPPPPPPPPPPPPPPPPPPPPPIP", false, 0, false);
629629
test_stream_check_types(list, "IPPISPPPPPPPPPPPPPPPPPPPPPPPPISP");
630630
test_stream_item_t *sei_2 = test_stream_item_remove(list, 31);
631631
test_stream_item_check_type(sei_2, 'S');

tests/check/meson.build

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ tests = [
1414
'test_helpers.h'
1515
]
1616
],
17+
['unittest_av1',
18+
[
19+
'check_codec_av1.c',
20+
'test_stream.c',
21+
'test_stream.h',
22+
'test_helpers.c',
23+
'test_helpers.h'
24+
]
25+
],
1726
]
1827

1928
if (get_option('signingplugin') != 'threaded_unless_check_dep')

tests/check/test_helpers.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,26 @@ const int64_t g_testTimestamp = 42;
8585
// unsigned delay;
8686
// };
8787
struct sv_setting settings[NUM_SETTINGS] = {
88-
{SV_CODEC_H264, SV_AUTHENTICITY_LEVEL_GOP, true, true, false, 0, NULL, 0, 1, false, 0, 0},
89-
{SV_CODEC_H265, SV_AUTHENTICITY_LEVEL_GOP, true, true, false, 0, NULL, 0, 1, false, 0, 0},
90-
{SV_CODEC_H264, SV_AUTHENTICITY_LEVEL_FRAME, true, true, false, 0, NULL, 0, 1, false, 0, 0},
91-
{SV_CODEC_H265, SV_AUTHENTICITY_LEVEL_FRAME, true, true, false, 0, NULL, 0, 1, false, 0, 0},
88+
{SV_CODEC_H264, SV_AUTHENTICITY_LEVEL_GOP, true, true, false, 0, NULL, 0, 1, false, 0, 0,
89+
false},
90+
{SV_CODEC_H265, SV_AUTHENTICITY_LEVEL_GOP, true, true, false, 0, NULL, 0, 1, false, 0, 0,
91+
false},
92+
{SV_CODEC_H264, SV_AUTHENTICITY_LEVEL_FRAME, true, true, false, 0, NULL, 0, 1, false, 0, 0,
93+
false},
94+
{SV_CODEC_H265, SV_AUTHENTICITY_LEVEL_FRAME, true, true, false, 0, NULL, 0, 1, false, 0, 0,
95+
false},
9296
// Special cases
93-
{SV_CODEC_H265, SV_AUTHENTICITY_LEVEL_GOP, false, true, false, 0, NULL, 0, 1, false, 0, 0},
94-
{SV_CODEC_H264, SV_AUTHENTICITY_LEVEL_FRAME, false, true, false, 0, NULL, 0, 1, false, 0, 0},
95-
{SV_CODEC_H264, SV_AUTHENTICITY_LEVEL_FRAME, true, true, false, 0, "sha512", 0, 1, false, 0, 0},
97+
{SV_CODEC_H265, SV_AUTHENTICITY_LEVEL_GOP, false, true, false, 0, NULL, 0, 1, false, 0, 0,
98+
false},
99+
{SV_CODEC_H264, SV_AUTHENTICITY_LEVEL_FRAME, false, true, false, 0, NULL, 0, 1, false, 0, 0,
100+
false},
101+
{SV_CODEC_H264, SV_AUTHENTICITY_LEVEL_FRAME, true, true, false, 0, "sha512", 0, 1, false, 0, 0,
102+
false},
96103
// AV1 tests
97-
{SV_CODEC_AV1, SV_AUTHENTICITY_LEVEL_GOP, true, false, false, 0, NULL, 0, 1, false, 0, 0},
98-
{SV_CODEC_AV1, SV_AUTHENTICITY_LEVEL_FRAME, true, false, false, 0, NULL, 0, 1, false, 0, 0},
104+
{SV_CODEC_AV1, SV_AUTHENTICITY_LEVEL_GOP, true, false, false, 0, NULL, 0, 1, false, 0, 0,
105+
false},
106+
{SV_CODEC_AV1, SV_AUTHENTICITY_LEVEL_FRAME, true, false, false, 0, NULL, 0, 1, false, 0, 0,
107+
false},
99108
};
100109

101110
static char private_key_rsa[RSA_PRIVATE_KEY_ALLOC_BYTES];
@@ -360,7 +369,11 @@ pull_seis(signed_video_t *sv, test_stream_item_t **item, bool apply_ep, unsigned
360369
* generates Bitstream Unit data for these. Then adds these Bitstream Units to the input session.
361370
* The generated SEIs are added to the stream. */
362371
test_stream_t *
363-
create_signed_stream_with_sv(signed_video_t *sv, const char *str, bool split_bu, int delay)
372+
create_signed_stream_with_sv(signed_video_t *sv,
373+
const char *str,
374+
bool split_bu,
375+
int delay,
376+
bool with_fh)
364377
{
365378
SignedVideoReturnCode rc = SV_UNKNOWN_FAILURE;
366379
ck_assert(sv);
@@ -369,7 +382,7 @@ create_signed_stream_with_sv(signed_video_t *sv, const char *str, bool split_bu,
369382
const bool apply_ep = false; // Apply emulation prevention on generated SEI afterwards.
370383
const bool get_seis_at_end = false; // Fetch all SEIs at once at the end of the stream.
371384
// Create a test stream given the input string.
372-
test_stream_t *list = test_stream_create(str, sv->codec, false);
385+
test_stream_t *list = test_stream_create(str, sv->codec, with_fh);
373386
test_stream_item_t *item = list->first_item;
374387
int64_t timestamp = g_testTimestamp;
375388
num_gops_until_signing = sv->signing_frequency - 1;
@@ -454,7 +467,8 @@ create_signed_stream_splitted_bu_int(const char *str,
454467
ck_assert(sv);
455468

456469
// Create a test stream of Bitstream Units given the input string.
457-
test_stream_t *list = create_signed_stream_with_sv(sv, str, split_bu, settings.delay);
470+
test_stream_t *list =
471+
create_signed_stream_with_sv(sv, str, split_bu, settings.delay, settings.with_fh);
458472
signed_video_free(sv);
459473

460474
return list;

tests/check/test_helpers.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ struct sv_setting {
5353
bool increased_sei_size;
5454
int vendor_axis_mode; // 0: not Axis, 1: attestation, 2: factory provisioned
5555
unsigned delay; // Delay of SEIs
56+
bool with_fh; // Use FH+TG principle if AV1
5657
};
5758

5859
#define NUM_SETTINGS 9
@@ -144,7 +145,11 @@ create_signed_stream_int(const char *str, struct sv_setting settings, bool new_p
144145
* generates Bitstream Unit data for these. Then adds these Bitstream Units to the input
145146
* session. The generated SEIs are added to the stream. */
146147
test_stream_t *
147-
create_signed_stream_with_sv(signed_video_t *sv, const char *str, bool split_bu, int delay);
148+
create_signed_stream_with_sv(signed_video_t *sv,
149+
const char *str,
150+
bool split_bu,
151+
int delay,
152+
bool with_fh);
148153

149154
/* Removes the Bitstream Unit item with position |item_number| from the test stream |list|. The
150155
* item is, after a check against the expected |type|, then freed. */

0 commit comments

Comments
 (0)