4747
4848static svrc_t
4949decode_sei_data (signed_video_t * signed_video , const uint8_t * payload , size_t payload_size );
50- static void
51- detect_lost_sei (signed_video_t * self );
5250static bool
5351hash_is_empty (const uint8_t * hash , size_t hash_size );
5452static bool
@@ -89,9 +87,12 @@ decode_sei_data(signed_video_t *self, const uint8_t *payload, size_t payload_siz
8987{
9088 assert (self && payload && (payload_size > 0 ));
9189 gop_info_t * gop_info = self -> gop_info ;
92- int64_t partial_gop_number = gop_info -> current_partial_gop ;
93- DEBUG_LOG ("SEI payload size = %zu, exp (partial) gop number = %ld" , payload_size ,
94- partial_gop_number + 1 );
90+ int64_t last_gop_number = gop_info -> current_partial_gop ;
91+ int64_t exp_gop_number = last_gop_number + 1 ;
92+ int64_t previous_next_partial_gop = gop_info -> next_partial_gop ;
93+ DEBUG_LOG ("SEI payload size = %zu, exp (partial) gop number = %ld" , payload_size , exp_gop_number );
94+ // Reset hash list to make sure the list does not contain old hashes if not populated.
95+ gop_info -> list_idx = 0 ;
9596
9697 svrc_t status = sv_tlv_decode (self , payload , payload_size );
9798 if (status != SV_OK ) {
@@ -101,49 +102,28 @@ decode_sei_data(signed_video_t *self, const uint8_t *payload, size_t payload_siz
101102
102103 // Compare new with last number of GOPs to detect potential wraparound.
103104 int64_t new_partial_gop_number = gop_info -> next_partial_gop ;
104- if (new_partial_gop_number < partial_gop_number ) {
105+ if (new_partial_gop_number < previous_next_partial_gop ) {
105106 // There is a potential wraparound, but it could also be due to re-ordering of SEIs.
106107 // Use the distance to determine which of these options is the most likely one.
107- if (((int64_t )1 << 31 ) < partial_gop_number - new_partial_gop_number ) {
108+ if (((int64_t )1 << 31 ) < previous_next_partial_gop - new_partial_gop_number ) {
108109 gop_info -> num_partial_gop_wraparounds ++ ;
110+ } else {
111+ new_partial_gop_number = previous_next_partial_gop ;
109112 }
110113 }
111-
112- return status ;
113- }
114-
115- /**
116- * Detects if there are any missing SEI messages based on the GOP counter and updates the GOP state.
117- */
118- static void
119- detect_lost_sei (signed_video_t * self )
120- {
121- gop_info_t * gop_info = self -> gop_info ;
122- // Get the last GOP counter.
123- int64_t exp_partial_gop_number = gop_info -> current_partial_gop + 1 ;
124- // Compare new with last number of GOPs to detect potentially lost SEIs.
125- int64_t new_partial_gop_number = gop_info -> next_partial_gop ;
126114 // Compensate for counter wraparounds.
127115 new_partial_gop_number += (int64_t )gop_info -> num_partial_gop_wraparounds << 32 ;
128- int64_t potentially_lost_seis = new_partial_gop_number - exp_partial_gop_number ;
129-
130- // If this is the first SEI used in this session there can by definition not be any lost
131- // SEIs. Also, if a SEI is detected that is the first SEI of a stream (no linked hash)
132- // it is infeasible to detect lost SEIs as well. This can happen if the session is reset
133- // on the camera/signing device.
134- size_t hash_size = self -> verify_data -> hash_size ;
135- bool is_start_of_stream = hash_is_empty (self -> received_linked_hash , hash_size );
136- if (is_start_of_stream || self -> validation_flags .is_first_sei ) {
116+ int64_t potentially_lost_seis = new_partial_gop_number - exp_gop_number ;
117+ // Before the SEIs are in sync it is, by definition, not possible to detect number of
118+ // lost SEIs.
119+ if (!self -> validation_flags .sei_in_sync ) {
137120 potentially_lost_seis = 0 ;
138121 }
139122 // Check if any SEIs have been lost. Wraparound of 64 bits is not feasible in practice.
140123 // Hence, a negative value means that an older SEI has been received.
141- // NOTE: It should not be necessary to check if |potentially_lost_seis| is outside
142- // range, since if that many GOPs have been lost that is a much more serious issue.
143- self -> validation_flags .num_lost_seis = (int )potentially_lost_seis ;
144- // If there are no lost SEIs it is in sync. Otherwise, validation should probably be
145- // performed without this SEI.
146- self -> validation_flags .sei_in_sync = (potentially_lost_seis == 0 );
124+ self -> validation_flags .num_lost_seis = potentially_lost_seis ;
125+
126+ return status ;
147127}
148128
149129/* Checks if the hash is empty, that is, consists of all zeros. */
@@ -948,7 +928,6 @@ prepare_for_validation(signed_video_t *self, bu_list_item_t **sei)
948928 (* sei )-> has_been_decoded = true;
949929 memcpy (verify_data -> hash , (* sei )-> hash , hash_size );
950930 }
951- detect_lost_sei (self );
952931 // Mark status of |sei| based on signature verification.
953932 if (validation_flags -> num_lost_seis == 0 ) {
954933 if ((* sei )-> bu -> is_signed ) {
0 commit comments