From 68178faca8cbb4c37d2b048cf5fa52651f102aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20V=C3=B6lcker?= <65532189+bjornvolcker@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:55:00 +0100 Subject: [PATCH] API change signed_video_get_sei(...) (#287) Now returns a pointer to the SEI/OBU Metadata memory. The memory is transferred and the user is responsible for freeing it. Also, payload_offset is made unsigned, since it cannot take negative values. Version is bumped to v2.0.2. Co-authored-by: bjornvolcker --- lib/src/includes/signed_video_sign.h | 28 +++------ lib/src/signed_video_h26x_sign.c | 25 ++++---- lib/src/signed_video_internal.h | 2 +- meson.build | 2 +- tests/check/check_signed_video_auth.c | 42 ++++++------- tests/check/check_signed_video_sign.c | 91 ++++++++++----------------- tests/check/test_helpers.c | 13 ++-- 7 files changed, 82 insertions(+), 121 deletions(-) diff --git a/lib/src/includes/signed_video_sign.h b/lib/src/includes/signed_video_sign.h index 490ba3b..590dc0c 100644 --- a/lib/src/includes/signed_video_sign.h +++ b/lib/src/includes/signed_video_sign.h @@ -231,19 +231,17 @@ signed_video_get_nalu_to_prepend(signed_video_t *self, /** * @brief Gets generated SEIs/OBU Metadata to add to the stream * - * This function should be called before + * This function is recommended to be called before * signed_video_add_nalu_for_signing_with_timestamp(...). The user has an option to * provide this function with a |peek_nalu|, which is the same NAL Unit/OBU that is to be - * added for signing. Even though, the user does not have to call this function before - * adding NAL Units for signing, it is highly recommended to avoid missing or delaying - * SEIs/OBU Metadata. + * added for signing. * * These SEIs/OBU Metadata are generated by the Signed Video library and are complete NAL Units + 4 * start code bytes, or OBUs. Hence, the user can simply pull and prepend existing H26x NAL Units, * or AV1 OBUs. Pull NAL Units/OBUs to prepend from signed_video_t one by one until no more * generated SEIs/OBU Metadata exists, that is, when |sei_size| is zero. * - * NOTE: The user is responsible for allocating memory for the |sei|. + * NOTE: The memory is transferred and the user is responsible for freeing memory of the |sei|. * * Here is an example code of usage: * @@ -256,20 +254,15 @@ signed_video_get_nalu_to_prepend(signed_video_t *self, * // Handle error * } * SignedVideoReturnCode status; + * uint8_t *sei = NULL; * size_t sei_size = 0; - * // The first call of the function is for getting the |sei_size|. - * status = signed_video_get_sei(sv, NULL, &sei_size, NULL, NULL, 0, NULL); - * // The second call is to get the sei. + * // Get the SEI data. + * status = signed_video_get_sei(sv, &sei, &sei_size, NULL, NULL, 0, NULL); * while (status == SV_OK && sei_size > 0) { - * uint8_t *sei = malloc(sei_size); - * status = signed_video_get_sei(sv, sei, &sei_size, NULL, NULL, 0, NULL); - * if (status != SV_OK) { - * // True error. Handle it properly. - * } * // Add the SEI to the stream according to the standard. * // The user is responsible for freeing |sei|. * // Check for more SEIs. - * status = signed_video_get_sei(sv, NULL, &sei_size, NULL, NULL, 0, NULL); + * status = signed_video_get_sei(sv, &sei, &sei_size, NULL, NULL, 0, NULL); * } * status = signed_video_add_nalu_for_signing_with_timestamp(sv, nalu, nalu_size, NULL); * if (status != SV_OK) { @@ -277,8 +270,7 @@ signed_video_get_nalu_to_prepend(signed_video_t *self, * } * * @param self Pointer to the signed_video_t object in use. - * @param sei Pointer to the memory to which a complete SEI/OBU Metadata will be copied. - * If a NULL pointer is used, only the |sei_size| is updated. + * @param sei Pointer to the memory pointer to which a complete SEI/OBU Metadata is located. * @param sei_size Pointer to where the size of the SEI/OBU Metadata is written. * @param payload_offset Pointer to where the offset to the start of the SEI/OBU Metadata payload is * written. This is useful if the SEI/OBU Metadata is added by the encoder, which would take the @@ -297,9 +289,9 @@ signed_video_get_nalu_to_prepend(signed_video_t *self, */ SignedVideoReturnCode signed_video_get_sei(signed_video_t *self, - uint8_t *sei, + uint8_t **sei, size_t *sei_size, - int *payload_offset, + unsigned *payload_offset, const uint8_t *peek_nalu, size_t peek_nalu_size, unsigned *num_pending_seis); diff --git a/lib/src/signed_video_h26x_sign.c b/lib/src/signed_video_h26x_sign.c index 65a7c0d..da25ae1 100644 --- a/lib/src/signed_video_h26x_sign.c +++ b/lib/src/signed_video_h26x_sign.c @@ -670,15 +670,16 @@ get_latest_sei(signed_video_t *self, uint8_t *sei, size_t *sei_size) SignedVideoReturnCode signed_video_get_sei(signed_video_t *self, - uint8_t *sei, + uint8_t **sei, size_t *sei_size, - int *payload_offset, + unsigned *payload_offset, const uint8_t *peek_nalu, size_t peek_nalu_size, unsigned *num_pending_seis) { - if (!self || !sei_size) return SV_INVALID_PARAMETER; + if (!self || !sei || !sei_size) return SV_INVALID_PARAMETER; + *sei = NULL; *sei_size = 0; if (payload_offset) { *payload_offset = 0; @@ -710,22 +711,20 @@ signed_video_get_sei(signed_video_t *self, } *sei_size = self->sei_data_buffer[0].completed_sei_size; - if (!sei) return SV_OK; - // Copy the SEI data to the provided pointer. - memcpy(sei, self->sei_data_buffer[0].sei, *sei_size); - - // Reset the fetched SEI information from the sei buffer. - free(self->sei_data_buffer[0].sei); - --(self->num_of_completed_seis); - shift_sei_buffer_at_index(self, 0); + // Transfer the memory. + *sei = self->sei_data_buffer[0].sei; // Get the offset to the start of the SEI payload if requested. if (payload_offset) { - h26x_nalu_t nalu_info = parse_nalu_info(sei, *sei_size, self->codec, false, false); + h26x_nalu_t nalu_info = parse_nalu_info(*sei, *sei_size, self->codec, false, false); free(nalu_info.nalu_data_wo_epb); - *payload_offset = nalu_info.payload - sei; + *payload_offset = (unsigned)(nalu_info.payload - *sei); } + // Reset the fetched SEI information from the sei buffer. + --(self->num_of_completed_seis); + shift_sei_buffer_at_index(self, 0); + // Update |num_pending_seis| in case SEIs were fetched. if (num_pending_seis) { *num_pending_seis = self->sei_data_buffer_idx; diff --git a/lib/src/signed_video_internal.h b/lib/src/signed_video_internal.h index cb88bcf..a702afc 100644 --- a/lib/src/signed_video_internal.h +++ b/lib/src/signed_video_internal.h @@ -52,7 +52,7 @@ typedef struct _h26x_nalu_t h26x_nalu_t; #define DEFAULT_HASH_SIZE (256 / 8) #define SV_VERSION_BYTES 3 -#define SIGNED_VIDEO_VERSION "v2.0.1" +#define SIGNED_VIDEO_VERSION "v2.0.2" #define SV_VERSION_MAX_STRLEN 13 // Longest possible string #define DEFAULT_AUTHENTICITY_LEVEL SV_AUTHENTICITY_LEVEL_FRAME diff --git a/meson.build b/meson.build index 8115b25..3aa0e43 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('signed-video-framework', 'c', - version : '2.0.1', + version : '2.0.2', meson_version : '>= 0.47.0', default_options : [ 'warning_level=2', 'werror=true', diff --git a/tests/check/check_signed_video_auth.c b/tests/check/check_signed_video_auth.c index e13dc30..70fbca2 100644 --- a/tests/check/check_signed_video_auth.c +++ b/tests/check/check_signed_video_auth.c @@ -1566,6 +1566,7 @@ START_TEST(vendor_axis_communications_operation) test_stream_item_t *p_nalu = test_stream_item_create_from_type('P', 1, codec); test_stream_item_t *i_nalu_2 = test_stream_item_create_from_type('I', 2, codec); test_stream_item_t *sei_item = NULL; + uint8_t *sei = NULL; size_t sei_size = 0; // Check generate private key. @@ -1591,17 +1592,17 @@ START_TEST(vendor_axis_communications_operation) ck_assert_int_eq(sv_rc, SV_OK); sv_rc = signed_video_add_nalu_for_signing(sv, i_nalu_2->data, i_nalu_2->data_size); ck_assert_int_eq(sv_rc, SV_OK); - sv_rc = signed_video_get_sei(sv, NULL, &sei_size, NULL, NULL, 0, NULL); - ck_assert(sei_size > 0); - ck_assert_int_eq(sv_rc, SV_OK); - uint8_t *sei = malloc(sei_size); - sv_rc = signed_video_get_sei(sv, sei, &sei_size, NULL, NULL, 0, NULL); + sv_rc = signed_video_get_sei(sv, &sei, &sei_size, NULL, NULL, 0, NULL); ck_assert_int_eq(sv_rc, SV_OK); + ck_assert(sei_size > 0); + ck_assert(sei); sei_item = test_stream_item_create(sei, sei_size, codec); ck_assert(tag_is_present(sei_item, codec, VENDOR_AXIS_COMMUNICATIONS_TAG)); - sv_rc = signed_video_get_sei(sv, NULL, &sei_size, NULL, NULL, 0, NULL); + uint8_t *tmp_sei = NULL; + sv_rc = signed_video_get_sei(sv, &tmp_sei, &sei_size, NULL, NULL, 0, NULL); ck_assert_int_eq(sv_rc, SV_OK); - ck_assert(sei_size == 0); + ck_assert_int_eq(sei_size, 0); + ck_assert(!tmp_sei); signed_video_free(sv); @@ -1682,18 +1683,14 @@ generate_and_set_private_key_on_camera_side(struct sv_setting setting, sv_rc = signed_video_add_nalu_for_signing(sv, i_nalu_2->data, i_nalu_2->data_size); ck_assert_int_eq(sv_rc, SV_OK); + uint8_t *sei = NULL; size_t sei_size = 0; - sv_rc = signed_video_get_sei(sv, NULL, &sei_size, NULL, NULL, 0, NULL); - ck_assert(sei_size > 0); - ck_assert_int_eq(sv_rc, SV_OK); - uint8_t *sei = malloc(sei_size); - sv_rc = signed_video_get_sei(sv, sei, &sei_size, NULL, NULL, 0, NULL); + sv_rc = signed_video_get_sei(sv, &sei, &sei_size, NULL, NULL, 0, NULL); ck_assert_int_eq(sv_rc, SV_OK); + ck_assert(sei_size > 0); + ck_assert(sei); *sei_item = test_stream_item_create(sei, sei_size, setting.codec); - sv_rc = signed_video_get_sei(sv, NULL, &sei_size, NULL, NULL, 0, NULL); - ck_assert_int_eq(sv_rc, SV_OK); - ck_assert(sei_size == 0); ck_assert(tag_is_present(*sei_item, setting.codec, PUBLIC_KEY_TAG) == add_public_key_to_sei); test_stream_item_free(i_nalu); @@ -1925,6 +1922,7 @@ START_TEST(no_emulation_prevention_bytes) test_stream_item_t *i_nalu_2 = test_stream_item_create_from_type('I', 1, codec); test_stream_item_t *sei_item = NULL; + uint8_t *sei = NULL; size_t sei_size; // Signing side @@ -1952,12 +1950,9 @@ START_TEST(no_emulation_prevention_bytes) sv, i_nalu_2->data, i_nalu_2->data_size, &g_testTimestamp); ck_assert_int_eq(sv_rc, SV_OK); - sv_rc = signed_video_get_sei(sv, NULL, &sei_size, NULL, NULL, 0, NULL); - ck_assert_int_eq(sv_rc, SV_OK); - uint8_t *sei = malloc(sei_size); - sv_rc = signed_video_get_sei(sv, sei, &sei_size, NULL, NULL, 0, NULL); - + sv_rc = signed_video_get_sei(sv, &sei, &sei_size, NULL, NULL, 0, NULL); ck_assert(sei_size != 0); + ck_assert(sei); ck_assert_int_eq(sv_rc, SV_OK); // Allocate memory for a new buffer to write to, and add emulation prevention bytes. @@ -1970,14 +1965,15 @@ START_TEST(no_emulation_prevention_bytes) size_t src_size = sei_size - 4; write_byte_many(&sei_p, src, src_size, &last_two_bytes, true); size_t sei_with_epb_size = sei_p - sei_with_epb; - signed_video_nalu_data_free(sei); + free(sei); // Create a SEI. sei_item = test_stream_item_create(sei_with_epb, sei_with_epb_size, codec); - sv_rc = signed_video_get_sei(sv, sei, &sei_size, NULL, NULL, 0, NULL); + sv_rc = signed_video_get_sei(sv, &sei, &sei_size, NULL, NULL, 0, NULL); ck_assert_int_eq(sv_rc, SV_OK); - ck_assert(sei_size == 0); + ck_assert_int_eq(sei_size, 0); + ck_assert(!sei); // Close signing side. signed_video_free(sv); diff --git a/tests/check/check_signed_video_sign.c b/tests/check/check_signed_video_sign.c index 1149bd7..92169fa 100644 --- a/tests/check/check_signed_video_sign.c +++ b/tests/check/check_signed_video_sign.c @@ -143,22 +143,19 @@ get_seis(signed_video_t *sv, int num_seis_to_get, int *num_seis_gotten) SignedVideoReturnCode sv_rc = SV_OK; int num_pulled_nalus = 0; + uint8_t *sei = NULL; size_t sei_size = 0; - int payload_offset = 0; + unsigned payload_offset = 0; // Pull SEIs without peek. - sv_rc = signed_video_get_sei(sv, NULL, &sei_size, &payload_offset, NULL, 0, NULL); + sv_rc = signed_video_get_sei(sv, &sei, &sei_size, &payload_offset, NULL, 0, NULL); while (num_seis_to_get != 0 && sv_rc == SV_OK && sei_size > 0) { - uint8_t *sei = malloc(sei_size); - ck_assert(sei); - sv_rc = signed_video_get_sei(sv, sei, &sei_size, &payload_offset, NULL, 0, NULL); - ck_assert_int_eq(sv_rc, SV_OK); // Check that the SEI payload starts with the Signed Video UUID. ck_assert_int_eq(memcmp(sei + payload_offset, kUuidSignedVideo, UUID_LEN), 0); // Sizes can vary between SEIs, so it is better to free and allocate new memory for each SEI free(sei); num_pulled_nalus++; num_seis_to_get--; - sv_rc = signed_video_get_sei(sv, NULL, &sei_size, &payload_offset, NULL, 0, NULL); + sv_rc = signed_video_get_sei(sv, &sei, &sei_size, &payload_offset, NULL, 0, NULL); } if (num_seis_gotten) *num_seis_gotten = num_pulled_nalus; @@ -178,6 +175,7 @@ START_TEST(api_inputs) test_stream_item_t *invalid = test_stream_item_create_from_type('X', 0, codec); char *private_key = NULL; size_t private_key_size = 0; + uint8_t *sei = NULL; size_t sei_size = 0; signed_video_t *sv = signed_video_create(codec); @@ -306,14 +304,9 @@ START_TEST(api_inputs) unsigned num_pending_seis = 0; sv_rc = signed_video_get_sei(sv, NULL, NULL, NULL, NULL, 0, NULL); ck_assert_int_eq(sv_rc, SV_INVALID_PARAMETER); - sv_rc = signed_video_get_sei(sv, NULL, &sei_size, NULL, NULL, 0, &num_pending_seis); - ck_assert_int_eq(sv_rc, SV_OK); - ck_assert(sei_size == 0); - ck_assert_int_eq(num_pending_seis, 0); - uint8_t *sei = malloc(sei_size); - sv_rc = signed_video_get_sei(NULL, sei, &sei_size, NULL, NULL, 0, &num_pending_seis); + sv_rc = signed_video_get_sei(NULL, &sei, &sei_size, NULL, NULL, 0, &num_pending_seis); ck_assert_int_eq(sv_rc, SV_INVALID_PARAMETER); - sv_rc = signed_video_get_sei(sv, sei, &sei_size, NULL, NULL, 0, &num_pending_seis); + sv_rc = signed_video_get_sei(sv, &sei, &sei_size, NULL, NULL, 0, &num_pending_seis); ck_assert_int_eq(sv_rc, SV_OK); ck_assert_int_eq(num_pending_seis, 0); // Checking signed_video_set_end_of_stream() for NULL pointers. @@ -654,6 +647,7 @@ START_TEST(two_completed_seis_pending) SignedVideoCodec codec = settings[_i].codec; SignedVideoReturnCode sv_rc; + uint8_t *sei = NULL; size_t sei_size_1 = 0; size_t sei_size_2 = 0; size_t sei_size_3 = 0; @@ -679,37 +673,32 @@ START_TEST(two_completed_seis_pending) unsigned num_pending_seis = 0; // First, peek with a secondary slice NAL Unit which should not provide a SEI. sv_rc = signed_video_get_sei( - sv, NULL, &sei_size_1, NULL, i_nalu_4->data, i_nalu_4->data_size, &num_pending_seis); + sv, &sei, &sei_size_1, NULL, i_nalu_4->data, i_nalu_4->data_size, &num_pending_seis); ck_assert_int_eq(sv_rc, SV_OK); ck_assert_int_eq(num_pending_seis, 2); - ck_assert(sei_size_1 == 0); + ck_assert_int_eq(sei_size_1, 0); + ck_assert(!sei); // Secondly, peek with a primary slice NAL Unit should reveil the SEI. sv_rc = signed_video_get_sei( - sv, NULL, &sei_size_1, NULL, p_nalu->data, p_nalu->data_size, &num_pending_seis); - ck_assert_int_eq(sv_rc, SV_OK); - ck_assert_int_eq(num_pending_seis, 2); - ck_assert(sei_size_1 != 0); - uint8_t *sei_1 = malloc(sei_size_1); - ck_assert_int_eq(sv_rc, SV_OK); - // From now on skipping peeks. - sv_rc = signed_video_get_sei(sv, sei_1, &sei_size_1, NULL, NULL, 0, &num_pending_seis); + sv, &sei, &sei_size_1, NULL, p_nalu->data, p_nalu->data_size, &num_pending_seis); ck_assert_int_eq(sv_rc, SV_OK); ck_assert_int_eq(num_pending_seis, 1); - // Now get the second one. - sv_rc = signed_video_get_sei(sv, NULL, &sei_size_2, NULL, NULL, 0, &num_pending_seis); - ck_assert_int_eq(sv_rc, SV_OK); - ck_assert_int_eq(num_pending_seis, 1); - ck_assert(sei_size_2 != 0); - uint8_t *sei_2 = malloc(sei_size_2); - ck_assert_int_eq(sv_rc, SV_OK); - sv_rc = signed_video_get_sei(sv, sei_2, &sei_size_2, NULL, NULL, 0, &num_pending_seis); + ck_assert(sei_size_1 != 0); + ck_assert(sei); + free(sei); + // From now on skipping peeks. Now get the second one. + sv_rc = signed_video_get_sei(sv, &sei, &sei_size_2, NULL, NULL, 0, &num_pending_seis); ck_assert_int_eq(sv_rc, SV_OK); ck_assert_int_eq(num_pending_seis, 0); + ck_assert(sei_size_2 != 0); + ck_assert(sei); + free(sei); // There should not be a third one. - sv_rc = signed_video_get_sei(sv, NULL, &sei_size_3, NULL, NULL, 0, &num_pending_seis); + sv_rc = signed_video_get_sei(sv, &sei, &sei_size_3, NULL, NULL, 0, &num_pending_seis); ck_assert_int_eq(sv_rc, SV_OK); ck_assert_int_eq(num_pending_seis, 0); ck_assert_int_eq(sei_size_3, 0); + ck_assert(!sei); // Verify the transfer order of NAL Units // Expect |sei_size_1| to be less than |sei_size_2| because the second SEI includes one @@ -722,8 +711,6 @@ START_TEST(two_completed_seis_pending) test_stream_item_free(i_nalu_3); test_stream_item_free(i_nalu_4); signed_video_free(sv); - free(sei_1); - free(sei_2); } END_TEST @@ -741,15 +728,13 @@ START_TEST(golden_sei_created) ck_assert_int_eq(sv_rc, SV_OK); unsigned num_pending_seis = 0; + uint8_t *sei = NULL; size_t sei_size = 0; - sv_rc = signed_video_get_sei(sv, NULL, &sei_size, NULL, NULL, 0, &num_pending_seis); - ck_assert(sei_size != 0); - ck_assert_int_eq(num_pending_seis, 1); - uint8_t *sei = malloc(sei_size); - ck_assert_int_eq(sv_rc, SV_OK); - sv_rc = signed_video_get_sei(sv, sei, &sei_size, NULL, NULL, 0, &num_pending_seis); + sv_rc = signed_video_get_sei(sv, &sei, &sei_size, NULL, NULL, 0, &num_pending_seis); ck_assert_int_eq(sv_rc, SV_OK); ck_assert_int_eq(num_pending_seis, 0); + ck_assert(sei_size != 0); + ck_assert(sei); // Verify the golden SEI ck_assert(signed_video_is_golden_sei(sv, sei, sei_size)); @@ -848,6 +833,8 @@ START_TEST(correct_timestamp) ck_assert(sv_ts); test_stream_item_t *i_nalu = test_stream_item_create_from_type('I', 0, codec); test_stream_item_t *i_nalu_2 = test_stream_item_create_from_type('I', 1, codec); + uint8_t *sei = NULL; + uint8_t *sei_ts = NULL; size_t sei_size = 0; size_t sei_size_ts = 0; @@ -857,14 +844,11 @@ START_TEST(correct_timestamp) sv_rc = signed_video_add_nalu_for_signing(sv, i_nalu_2->data, i_nalu_2->data_size); ck_assert_int_eq(sv_rc, SV_OK); unsigned num_pending_seis = 0; - sv_rc = signed_video_get_sei(sv, NULL, &sei_size, NULL, NULL, 0, &num_pending_seis); - ck_assert_int_eq(sv_rc, SV_OK); - ck_assert_int_eq(num_pending_seis, 1); - uint8_t *sei = malloc(sei_size); - sv_rc = signed_video_get_sei(sv, sei, &sei_size, NULL, NULL, 0, &num_pending_seis); + sv_rc = signed_video_get_sei(sv, &sei, &sei_size, NULL, NULL, 0, &num_pending_seis); ck_assert_int_eq(sv_rc, SV_OK); ck_assert_int_eq(num_pending_seis, 0); ck_assert(sei_size > 0); + ck_assert(sei); // Test new API with timestamp as NULL. It should give the same result as the old API sv_rc = signed_video_add_nalu_for_signing_with_timestamp( @@ -872,14 +856,11 @@ START_TEST(correct_timestamp) ck_assert_int_eq(sv_rc, SV_OK); sv_rc = signed_video_add_nalu_for_signing(sv_ts, i_nalu_2->data, i_nalu_2->data_size); ck_assert_int_eq(sv_rc, SV_OK); - sv_rc = signed_video_get_sei(sv_ts, NULL, &sei_size_ts, NULL, NULL, 0, &num_pending_seis); - ck_assert_int_eq(sv_rc, SV_OK); - ck_assert_int_eq(num_pending_seis, 1); - uint8_t *sei_ts = malloc(sei_size_ts); - sv_rc = signed_video_get_sei(sv_ts, sei_ts, &sei_size_ts, NULL, NULL, 0, &num_pending_seis); + sv_rc = signed_video_get_sei(sv_ts, &sei_ts, &sei_size_ts, NULL, NULL, 0, &num_pending_seis); ck_assert_int_eq(sv_rc, SV_OK); ck_assert_int_eq(num_pending_seis, 0); ck_assert(sei_size_ts > 0); + ck_assert(sei_ts); // Verify the sizes of the nalus ck_assert(sei_size > 0); @@ -970,14 +951,10 @@ START_TEST(w_wo_emulation_prevention_bytes) sv_rc = signed_video_add_nalu_for_signing_with_timestamp( sv, i_nalu_2->data, i_nalu_2->data_size, &g_testTimestamp); ck_assert_int_eq(sv_rc, SV_OK); - sv_rc = signed_video_get_sei(sv, NULL, &sei_size, NULL, NULL, 0, &num_pending_seis); - ck_assert_int_eq(sv_rc, SV_OK); - ck_assert_int_eq(num_pending_seis, 1); - ck_assert(sei_size > 0); - seis[ii] = malloc(sei_size); - sv_rc = signed_video_get_sei(sv, seis[ii], &sei_size, NULL, NULL, 0, &num_pending_seis); + sv_rc = signed_video_get_sei(sv, &seis[ii], &sei_size, NULL, NULL, 0, &num_pending_seis); ck_assert_int_eq(sv_rc, SV_OK); ck_assert_int_eq(num_pending_seis, 0); + ck_assert(sei_size > 0); ck_assert(seis[ii]); sei_sizes[ii] = sei_size; nalus[ii] = parse_nalu_info(seis[ii], sei_sizes[ii], codec, false, true); diff --git a/tests/check/test_helpers.c b/tests/check/test_helpers.c index a9c8a47..21f0e02 100644 --- a/tests/check/test_helpers.c +++ b/tests/check/test_helpers.c @@ -115,20 +115,17 @@ pull_seis(signed_video_t *sv, test_stream_item_t **item) { bool is_first_sei = true; int num_seis = 0; - int payload_offset = 0; + unsigned payload_offset = 0; + uint8_t *sei = NULL; size_t sei_size = 0; uint8_t *peek_nalu = (*item)->data; size_t peek_nalu_size = (*item)->data_size; // Only prepend the SEI if it follows the standard, by peeking the current NAL Unit. SignedVideoReturnCode sv_rc = - signed_video_get_sei(sv, NULL, &sei_size, &payload_offset, peek_nalu, peek_nalu_size, NULL); + signed_video_get_sei(sv, &sei, &sei_size, &payload_offset, peek_nalu, peek_nalu_size, NULL); ck_assert_int_eq(sv_rc, SV_OK); - while (sv_rc == SV_OK && (sei_size != 0)) { - uint8_t *sei = malloc(sei_size); - sv_rc = - signed_video_get_sei(sv, sei, &sei_size, &payload_offset, peek_nalu, peek_nalu_size, NULL); - ck_assert_int_eq(sv_rc, SV_OK); + while (sv_rc == SV_OK && (sei_size != 0) && sei) { // Check that the SEI payload starts with the Signed Video UUID. ck_assert_int_eq(memcmp(sei + payload_offset, kUuidSignedVideo, UUID_LEN), 0); if (!is_first_sei) { @@ -142,7 +139,7 @@ pull_seis(signed_video_t *sv, test_stream_item_t **item) num_seis++; // Ask for next completed SEI. sv_rc = - signed_video_get_sei(sv, NULL, &sei_size, &payload_offset, peek_nalu, peek_nalu_size, NULL); + signed_video_get_sei(sv, &sei, &sei_size, &payload_offset, peek_nalu, peek_nalu_size, NULL); ck_assert_int_eq(sv_rc, SV_OK); is_first_sei = false; }