Skip to content

Commit 4d0f725

Browse files
authored
Makes a second (final) validation stats update (#497)
If multiple GOPs are validated and the validation started being out of sync, but sync was established, the first GOP should no longer be ignored. Therefore, perform a final stats update after having looped through the GOPs. Co-authored-by: bjornvolcker <[email protected]>
1 parent 5d4c457 commit 4d0f725

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

lib/src/sv_auth.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ maybe_validate_gop(signed_video_t *self, bu_info_t *bu)
11791179
int max_loop = 10;
11801180
bool update_validation_status = false;
11811181
bool public_key_has_changed = false;
1182+
bool start_sei_in_sync = validation_flags->sei_in_sync;
11821183
char sei_validation_status = 'U';
11831184
// Keep validating as long as there are pending GOPs.
11841185
bool stop_validating = false;
@@ -1249,6 +1250,36 @@ maybe_validate_gop(signed_video_t *self, bu_info_t *bu)
12491250
DEBUG_LOG("Validation aborted after reaching max number of loops");
12501251
}
12511252

1253+
if (start_sei_in_sync != validation_flags->sei_in_sync) {
1254+
// Some partial GOPs may have been discarded due to being out of sync at that time
1255+
// because they were in fact correctly invalid. Get stats another time and update
1256+
// |latest->authenticity|.
1257+
SignedVideoAuthenticityResult valid = SV_AUTH_RESULT_NOT_OK;
1258+
int num_invalid;
1259+
int num_missed;
1260+
bu_list_get_stats(self->bu_list, NULL, &num_invalid, &num_missed);
1261+
DEBUG_LOG("Number of invalid Bitstream Units = %d.", num_invalid);
1262+
DEBUG_LOG("Number of missed Bitstream Units = %d.", num_missed);
1263+
1264+
valid = (num_invalid > 0) ? SV_AUTH_RESULT_NOT_OK : SV_AUTH_RESULT_OK;
1265+
1266+
// Determine if this GOP is valid, but has missing information. This happens if we have
1267+
// detected missed BUs or if the GOP is incomplete.
1268+
if (valid == SV_AUTH_RESULT_OK && (num_missed > 0)) {
1269+
valid = SV_AUTH_RESULT_OK_WITH_MISSING_INFO;
1270+
}
1271+
// Update |latest_validation| with the validation result.
1272+
if (latest->authenticity <= SV_AUTH_RESULT_SIGNATURE_PRESENT) {
1273+
// Still either pending validation or video has no signature. Update with the current
1274+
// result.
1275+
latest->authenticity = valid;
1276+
} else if (valid < latest->authenticity) {
1277+
// Current GOP validated a worse authenticity compared to what has been validated so
1278+
// far. Update with this worse result, since that is what should rule the total
1279+
// validation.
1280+
latest->authenticity = valid;
1281+
}
1282+
}
12521283
SV_THROW(bu_list_update_status(bu_list, update_validation_status));
12531284
if (validation_flags->is_first_validation) {
12541285
update_sei_in_validation(self, false, NULL, &sei_validation_status);

tests/check/check_signed_video_auth.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,9 @@ START_TEST(modify_one_p_frame)
524524
// ISPPIS ....P. ( valid, 1 pending)
525525
// 6 pending
526526
// ISP P.P (invalid, 3 pending)
527-
expected.valid_gops = 2; // 1;
528-
expected.invalid_gops = 0;
527+
expected.valid_gops = 1;
529528
expected.pending_bu = 6;
530529
expected.has_signature = 1;
531-
// Temporary stats
532-
expected.valid_gops_with_missing_info = 0;
533-
expected.missed_bu = 0;
534-
final_validation.authenticity = SV_AUTH_RESULT_OK;
535530
}
536531
validate_stream(NULL, list, expected, true);
537532

0 commit comments

Comments
 (0)