From 10499ff82816c20cd8a44e85615005a4b5af4516 Mon Sep 17 00:00:00 2001 From: Naresh Nayak Date: Fri, 28 Jun 2024 10:26:31 +0000 Subject: [PATCH 1/3] Removed avtp-stream.c/.h and related tests. Signed-off-by: Naresh Nayak --- include/avtp_stream.h | 100 ------------ meson.build | 13 -- src/avtp_stream.c | 207 ------------------------ unit/test-stream.c | 358 ------------------------------------------ 4 files changed, 678 deletions(-) delete mode 100644 include/avtp_stream.h delete mode 100644 src/avtp_stream.c delete mode 100644 unit/test-stream.c diff --git a/include/avtp_stream.h b/include/avtp_stream.h deleted file mode 100644 index d02e71c..0000000 --- a/include/avtp_stream.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (c) 2019, Intel Corporation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Intel Corporation nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include - -#pragma GCC visibility push(hidden) - -#ifdef __cplusplus -extern "C" { -#endif - -/* XXX: To be able to use the functions provided by this header, - * without needing to direct "translate" enum values, it is necessary - * that any format specific enum have the following fields (excluding - * AVTP_STREAM_FIELD_MAX) in the same order as below. For instance, - * some `enum avtp_newformat_field` would start like: - * - * enum avtp_newformat_field { - * AVTP_NEWFORMAT_FIELD_SV, - * AVTP_NEWFORMAT_FIELD_MR, - * // (other stream fields here) - * AVTP_NEWFORMAT_FIELD_XYZ, - * // (other newformat specific fields here) - * } - * - * This way, one can simply cast enums when calling functions from this - * header: - * - * avtp_stream_pdu_get(pdu, (enum avtp_stream_field) field, val); - * - * Otherwise, the mapping step would be necessary before the calls. - */ -enum avtp_stream_field { - AVTP_STREAM_FIELD_SV, - AVTP_STREAM_FIELD_MR, - AVTP_STREAM_FIELD_TV, - AVTP_STREAM_FIELD_SEQ_NUM, - AVTP_STREAM_FIELD_TU, - AVTP_STREAM_FIELD_STREAM_ID, - AVTP_STREAM_FIELD_TIMESTAMP, - AVTP_STREAM_FIELD_STREAM_DATA_LEN, - AVTP_STREAM_FIELD_MAX -}; - -/* Get value from Stream AVTPDU field. - * @pdu: Pointer to PDU struct. - * @field: PDU field to be retrieved. - * @val: Pointer to variable which the retrieved value should be saved. - * - * Returns: - * 0: Success. - * -EINVAL: If any argument is invalid. - */ -int avtp_stream_pdu_get(const struct avtp_stream_pdu *pdu, - enum avtp_stream_field field, uint64_t *val); - -/* Set value from Stream AVTPDU field. - * @pdu: Pointer to PDU struct. - * @field: PDU field to be set. - * @val: Value to be set. - * - * Returns: - * 0: Success. - * -EINVAL: If any argument is invalid. - */ -int avtp_stream_pdu_set(struct avtp_stream_pdu *pdu, - enum avtp_stream_field field, uint64_t val); - -#ifdef __cplusplus -} -#endif - -#pragma GCC visibility pop diff --git a/meson.build b/meson.build index cc665d8..0270748 100644 --- a/meson.build +++ b/meson.build @@ -10,8 +10,6 @@ avtp_lib = library( 'open1722', [ 'src/avtp.c', - 'src/avtp_stream.c', - 'src/avtp/Utils.c', 'src/avtp/acf/Ntscf.c', 'src/avtp/acf/Tscf.c', @@ -127,16 +125,6 @@ if cmocka.found() build_by_default: false, ) - test_stream = executable( - 'test-stream', - 'unit/test-stream.c', - 'src/avtp_stream.c', - include_directories: include_directories('include', 'src'), - link_with: avtp_lib, - dependencies: cmocka, - build_by_default: false, - ) - test_cvf = executable( 'test-cvf', 'unit/test-cvf.c', @@ -157,7 +145,6 @@ if cmocka.found() test('AVTP API', test_avtp) - test('Stream API', test_stream) test('AAF API', test_aaf) test('CRF API', test_crf) test('CVF API', test_cvf) diff --git a/src/avtp_stream.c b/src/avtp_stream.c deleted file mode 100644 index 0fafd2f..0000000 --- a/src/avtp_stream.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (c) 2019, Intel Corporation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Intel Corporation nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#include "avtp.h" -#include "avtp_stream.h" -#include "util.h" - -#define SHIFT_SV (31 - 8) -#define SHIFT_MR (31 - 12) -#define SHIFT_TV (31 - 15) -#define SHIFT_SEQ_NUM (31 - 23) -#define SHIFT_STREAM_DATA_LEN (31 - 15) - -#define MASK_SV (BITMASK(1) << SHIFT_SV) -#define MASK_MR (BITMASK(1) << SHIFT_MR) -#define MASK_TV (BITMASK(1) << SHIFT_TV) -#define MASK_SEQ_NUM (BITMASK(8) << SHIFT_SEQ_NUM) -#define MASK_TU (BITMASK(1)) -#define MASK_STREAM_DATA_LEN (BITMASK(16) << SHIFT_STREAM_DATA_LEN) - -static int get_field_value(const struct avtp_stream_pdu *pdu, - enum avtp_stream_field field, uint64_t *val) -{ - uint32_t bitmap, mask; - uint8_t shift; - - switch (field) { - case AVTP_STREAM_FIELD_SV: - mask = MASK_SV; - shift = SHIFT_SV; - bitmap = ntohl(pdu->subtype_data); - break; - case AVTP_STREAM_FIELD_MR: - mask = MASK_MR; - shift = SHIFT_MR; - bitmap = ntohl(pdu->subtype_data); - break; - case AVTP_STREAM_FIELD_TV: - mask = MASK_TV; - shift = SHIFT_TV; - bitmap = ntohl(pdu->subtype_data); - break; - case AVTP_STREAM_FIELD_SEQ_NUM: - mask = MASK_SEQ_NUM; - shift = SHIFT_SEQ_NUM; - bitmap = ntohl(pdu->subtype_data); - break; - case AVTP_STREAM_FIELD_TU: - mask = MASK_TU; - shift = 0; - bitmap = ntohl(pdu->subtype_data); - break; - case AVTP_STREAM_FIELD_STREAM_DATA_LEN: - mask = MASK_STREAM_DATA_LEN; - shift = SHIFT_STREAM_DATA_LEN; - bitmap = ntohl(pdu->packet_info); - break; - default: - return -EINVAL; - } - - *val = BITMAP_GET_VALUE(bitmap, mask, shift); - - return 0; -} - -int avtp_stream_pdu_get(const struct avtp_stream_pdu *pdu, - enum avtp_stream_field field, uint64_t *val) -{ - int res; - - if (!pdu || !val) - return -EINVAL; - - switch (field) { - case AVTP_STREAM_FIELD_SV: - case AVTP_STREAM_FIELD_MR: - case AVTP_STREAM_FIELD_TV: - case AVTP_STREAM_FIELD_SEQ_NUM: - case AVTP_STREAM_FIELD_TU: - case AVTP_STREAM_FIELD_STREAM_DATA_LEN: - res = get_field_value(pdu, field, val); - break; - case AVTP_STREAM_FIELD_TIMESTAMP: - *val = ntohl(pdu->avtp_time); - res = 0; - break; - case AVTP_STREAM_FIELD_STREAM_ID: - *val = be64toh(pdu->stream_id); - res = 0; - break; - default: - return -EINVAL; - } - - return res; -} - -static int set_field_value(struct avtp_stream_pdu *pdu, - enum avtp_stream_field field, uint64_t val) -{ - uint32_t bitmap, mask; - uint8_t shift; - void *ptr; - - switch (field) { - case AVTP_STREAM_FIELD_SV: - mask = MASK_SV; - shift = SHIFT_SV; - ptr = &pdu->subtype_data; - break; - case AVTP_STREAM_FIELD_MR: - mask = MASK_MR; - shift = SHIFT_MR; - ptr = &pdu->subtype_data; - break; - case AVTP_STREAM_FIELD_TV: - mask = MASK_TV; - shift = SHIFT_TV; - ptr = &pdu->subtype_data; - break; - case AVTP_STREAM_FIELD_SEQ_NUM: - mask = MASK_SEQ_NUM; - shift = SHIFT_SEQ_NUM; - ptr = &pdu->subtype_data; - break; - case AVTP_STREAM_FIELD_TU: - mask = MASK_TU; - shift = 0; - ptr = &pdu->subtype_data; - break; - case AVTP_STREAM_FIELD_STREAM_DATA_LEN: - mask = MASK_STREAM_DATA_LEN; - shift = SHIFT_STREAM_DATA_LEN; - ptr = &pdu->packet_info; - break; - default: - return -EINVAL; - } - - bitmap = get_unaligned_be32(ptr); - - BITMAP_SET_VALUE(bitmap, val, mask, shift); - - put_unaligned_be32(bitmap, ptr); - - return 0; -} - -int avtp_stream_pdu_set(struct avtp_stream_pdu *pdu, - enum avtp_stream_field field, uint64_t value) -{ - int res; - - if (!pdu) - return -EINVAL; - - switch (field) { - case AVTP_STREAM_FIELD_SV: - case AVTP_STREAM_FIELD_MR: - case AVTP_STREAM_FIELD_TV: - case AVTP_STREAM_FIELD_SEQ_NUM: - case AVTP_STREAM_FIELD_TU: - case AVTP_STREAM_FIELD_STREAM_DATA_LEN: - res = set_field_value(pdu, field, value); - break; - case AVTP_STREAM_FIELD_TIMESTAMP: - pdu->avtp_time = htonl(value); - res = 0; - break; - case AVTP_STREAM_FIELD_STREAM_ID: - pdu->stream_id = htobe64(value); - res = 0; - break; - default: - return -EINVAL; - } - - return res; -} diff --git a/unit/test-stream.c b/unit/test-stream.c deleted file mode 100644 index 7db0359..0000000 --- a/unit/test-stream.c +++ /dev/null @@ -1,358 +0,0 @@ -/* - * Copyright (c) 2019, Intel Corporation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Intel Corporation nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include - -#include "avtp.h" -#include "avtp_stream.h" - -static void stream_get_field_null_pdu(void **state) -{ - int res; - uint64_t val; - - res = avtp_stream_pdu_get(NULL, AVTP_STREAM_FIELD_SV, &val); - - assert_int_equal(res, -EINVAL); -} - -static void stream_get_field_null_val(void **state) -{ - int res; - struct avtp_stream_pdu pdu = { 0 }; - - res = avtp_stream_pdu_get(&pdu, AVTP_STREAM_FIELD_SV, NULL); - - assert_int_equal(res, -EINVAL); -} - -static void stream_get_field_invalid_field(void **state) -{ - int res; - uint64_t val; - struct avtp_stream_pdu pdu = { 0 }; - - res = avtp_stream_pdu_get(&pdu, AVTP_STREAM_FIELD_MAX, &val); - - assert_int_equal(res, -EINVAL); -} - -static void stream_get_field_sv(void **state) -{ - int res; - uint64_t val; - struct avtp_stream_pdu pdu = { 0 }; - - /* stream_set 'sv' field to 1. */ - pdu.subtype_data = htonl(0x00800000); - - res = avtp_stream_pdu_get(&pdu, AVTP_STREAM_FIELD_SV, &val); - - assert_int_equal(res, 0); - assert_true(val == 1); -} - -static void stream_get_field_mr(void **state) -{ - int res; - uint64_t val; - struct avtp_stream_pdu pdu = { 0 }; - - /* stream_set 'mr' field to 1. */ - pdu.subtype_data = htonl(0x00080000); - - res = avtp_stream_pdu_get(&pdu, AVTP_STREAM_FIELD_MR, &val); - - assert_int_equal(res, 0); - assert_true(val == 1); -} - -static void stream_get_field_tv(void **state) -{ - int res; - uint64_t val; - struct avtp_stream_pdu pdu = { 0 }; - - /* stream_set 'tv' field to 1. */ - pdu.subtype_data = htonl(0x00010000); - - res = avtp_stream_pdu_get(&pdu, AVTP_STREAM_FIELD_TV, &val); - - assert_int_equal(res, 0); - assert_true(val == 1); -} - -static void stream_get_field_seq_num(void **state) -{ - int res; - uint64_t val; - struct avtp_stream_pdu pdu = { 0 }; - - /* stream_set 'sequence_num' field to 0x55. */ - pdu.subtype_data = htonl(0x00005500); - - res = avtp_stream_pdu_get(&pdu, AVTP_STREAM_FIELD_SEQ_NUM, &val); - - assert_int_equal(res, 0); - assert_true(val == 0x55); -} - -static void stream_get_field_tu(void **state) -{ - int res; - uint64_t val; - struct avtp_stream_pdu pdu = { 0 }; - - /* stream_set 'tu' field to 1. */ - pdu.subtype_data = htonl(0x00000001); - - res = avtp_stream_pdu_get(&pdu, AVTP_STREAM_FIELD_TU, &val); - - assert_int_equal(res, 0); - assert_true(val == 1); -} - -static void stream_get_field_stream_id(void **state) -{ - int res; - uint64_t val; - struct avtp_stream_pdu pdu = { 0 }; - - /* stream_set 'stream_id' field to 0xAABBCCDDEEFF0001. */ - pdu.stream_id = htobe64(0xAABBCCDDEEFF0001); - - res = avtp_stream_pdu_get(&pdu, AVTP_STREAM_FIELD_STREAM_ID, &val); - - assert_int_equal(res, 0); - assert_true(val == 0xAABBCCDDEEFF0001); -} - -static void stream_get_field_timestamp(void **state) -{ - int res; - uint64_t val; - struct avtp_stream_pdu pdu = { 0 }; - - /* stream_set 'avtp_timestamp' field to 0x80C0FFEE. */ - pdu.avtp_time = htonl(0x80C0FFEE); - - res = avtp_stream_pdu_get(&pdu, AVTP_STREAM_FIELD_TIMESTAMP, &val); - - assert_int_equal(res, 0); - assert_true(val == 0x80C0FFEE); -} - -static void stream_get_field_data_len(void **state) -{ - int res; - uint64_t val; - struct avtp_stream_pdu pdu = { 0 }; - - /* stream_set 'stream_data_length' field to 0xAAAA. */ - pdu.packet_info = htonl(0xAAAA0000); - - res = avtp_stream_pdu_get(&pdu, AVTP_STREAM_FIELD_STREAM_DATA_LEN, - &val); - - assert_int_equal(res, 0); - assert_true(val == 0xAAAA); -} - -static void stream_set_field_null_pdu(void **state) -{ - int res; - - res = avtp_stream_pdu_set(NULL, AVTP_STREAM_FIELD_SV, 0); - - assert_int_equal(res, -EINVAL); -} - -static void stream_set_field_invalid_field(void **state) -{ - int res; - struct avtp_stream_pdu pdu = { 0 }; - - res = avtp_stream_pdu_set(&pdu, AVTP_STREAM_FIELD_MAX, 1); - - assert_int_equal(res, -EINVAL); -} - -static void stream_set_field_sv(void **state) -{ - int res; - struct avtp_stream_pdu pdu = { 0 }; - - res = avtp_stream_pdu_set(&pdu, AVTP_STREAM_FIELD_SV, 1); - - assert_int_equal(res, 0); - assert_true(ntohl(pdu.subtype_data) == 0x00800000); - assert_true(pdu.stream_id == 0); - assert_true(pdu.avtp_time == 0); - assert_true(pdu.format_specific == 0); - assert_true(pdu.packet_info == 0); -} - -static void stream_set_field_mr(void **state) -{ - int res; - struct avtp_stream_pdu pdu = { 0 }; - - res = avtp_stream_pdu_set(&pdu, AVTP_STREAM_FIELD_MR, 1); - - assert_int_equal(res, 0); - assert_true(ntohl(pdu.subtype_data) == 0x00080000); - assert_true(pdu.stream_id == 0); - assert_true(pdu.avtp_time == 0); - assert_true(pdu.format_specific == 0); - assert_true(pdu.packet_info == 0); -} - -static void stream_set_field_tv(void **state) -{ - int res; - struct avtp_stream_pdu pdu = { 0 }; - - res = avtp_stream_pdu_set(&pdu, AVTP_STREAM_FIELD_TV, 1); - - assert_int_equal(res, 0); - assert_true(ntohl(pdu.subtype_data) == 0x00010000); - assert_true(pdu.stream_id == 0); - assert_true(pdu.avtp_time == 0); - assert_true(pdu.format_specific == 0); - assert_true(pdu.packet_info == 0); -} - -static void stream_set_field_seq_num(void **state) -{ - int res; - struct avtp_stream_pdu pdu = { 0 }; - - res = avtp_stream_pdu_set(&pdu, AVTP_STREAM_FIELD_SEQ_NUM, 0x55); - - assert_int_equal(res, 0); - assert_true(ntohl(pdu.subtype_data) == 0x00005500); - assert_true(pdu.stream_id == 0); - assert_true(pdu.avtp_time == 0); - assert_true(pdu.format_specific == 0); - assert_true(pdu.packet_info == 0); -} - -static void stream_set_field_tu(void **state) -{ - int res; - struct avtp_stream_pdu pdu = { 0 }; - - res = avtp_stream_pdu_set(&pdu, AVTP_STREAM_FIELD_TU, 1); - - assert_int_equal(res, 0); - assert_true(ntohl(pdu.subtype_data) == 0x00000001); - assert_true(pdu.stream_id == 0); - assert_true(pdu.avtp_time == 0); - assert_true(pdu.format_specific == 0); - assert_true(pdu.packet_info == 0); -} - -static void stream_set_field_stream_id(void **state) -{ - int res; - struct avtp_stream_pdu pdu = { 0 }; - - res = avtp_stream_pdu_set(&pdu, AVTP_STREAM_FIELD_STREAM_ID, - 0xAABBCCDDEEFF0001); - - assert_int_equal(res, 0); - assert_true(be64toh(pdu.stream_id) == 0xAABBCCDDEEFF0001); - assert_true(pdu.subtype_data == 0); - assert_true(pdu.avtp_time == 0); - assert_true(pdu.format_specific == 0); - assert_true(pdu.packet_info == 0); -} - -static void stream_set_field_timestamp(void **state) -{ - int res; - struct avtp_stream_pdu pdu = { 0 }; - - res = avtp_stream_pdu_set(&pdu, AVTP_STREAM_FIELD_TIMESTAMP, - 0x80C0FFEE); - - assert_int_equal(res, 0); - assert_true(ntohl(pdu.avtp_time) == 0x80C0FFEE); - assert_true(pdu.subtype_data == 0); - assert_true(pdu.stream_id == 0); - assert_true(pdu.format_specific == 0); - assert_true(pdu.packet_info == 0); -} - -static void stream_set_field_data_len(void **state) -{ - int res; - struct avtp_stream_pdu pdu = { 0 }; - - res = avtp_stream_pdu_set(&pdu, AVTP_STREAM_FIELD_STREAM_DATA_LEN, - 0xAAAA); - - assert_int_equal(res, 0); - assert_true(ntohl(pdu.packet_info) == 0xAAAA0000); - assert_true(pdu.subtype_data == 0); - assert_true(pdu.stream_id == 0); - assert_true(pdu.avtp_time == 0); - assert_true(pdu.format_specific == 0); -} - -int main(void) -{ - const struct CMUnitTest tests[] = { - cmocka_unit_test(stream_get_field_null_pdu), - cmocka_unit_test(stream_get_field_null_val), - cmocka_unit_test(stream_get_field_invalid_field), - cmocka_unit_test(stream_get_field_sv), - cmocka_unit_test(stream_get_field_mr), - cmocka_unit_test(stream_get_field_tv), - cmocka_unit_test(stream_get_field_seq_num), - cmocka_unit_test(stream_get_field_tu), - cmocka_unit_test(stream_get_field_stream_id), - cmocka_unit_test(stream_get_field_timestamp), - cmocka_unit_test(stream_get_field_data_len), - cmocka_unit_test(stream_set_field_null_pdu), - cmocka_unit_test(stream_set_field_invalid_field), - cmocka_unit_test(stream_set_field_sv), - cmocka_unit_test(stream_set_field_mr), - cmocka_unit_test(stream_set_field_tv), - cmocka_unit_test(stream_set_field_seq_num), - cmocka_unit_test(stream_set_field_tu), - cmocka_unit_test(stream_set_field_stream_id), - cmocka_unit_test(stream_set_field_timestamp), - cmocka_unit_test(stream_set_field_data_len), - }; - - return cmocka_run_group_tests(tests, NULL, NULL); -} From 41c8083ac77126e28bb6c879e45355ab25272193 Mon Sep 17 00:00:00 2001 From: Naresh Nayak Date: Fri, 28 Jun 2024 11:47:02 +0000 Subject: [PATCH 2/3] Removed avtp.c/.h and related files. Signed-off-by: Naresh Nayak --- include/avtp.h | 90 ---------------------------------------------- src/avtp.c | 98 -------------------------------------------------- src/util.h | 59 ------------------------------ 3 files changed, 247 deletions(-) delete mode 100644 include/avtp.h delete mode 100644 src/avtp.c delete mode 100644 src/util.h diff --git a/include/avtp.h b/include/avtp.h deleted file mode 100644 index 8dbfe48..0000000 --- a/include/avtp.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2017, Intel Corporation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Intel Corporation nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* XXX: Fields from PDU structs should not be read or written directly since - * they are encoded in Network order which may be different from the Host - * order (see section 3.4.1 from IEEE 1722-2016 spec for further information). - * - * Any read or write operation with PDU structs should be done via getter and - * setter APIs which handle byte order conversion. - */ -struct avtp_common_pdu { - uint32_t subtype_data; - uint8_t pdu_specific[0]; -} __attribute__ ((__packed__)); - -struct avtp_stream_pdu { - uint32_t subtype_data; - uint64_t stream_id; - uint32_t avtp_time; - uint32_t format_specific; - uint32_t packet_info; - uint8_t avtp_payload[0]; -} __attribute__ ((__packed__)); - -enum avtp_field { - AVTP_FIELD_SUBTYPE, - AVTP_FIELD_VERSION, - AVTP_FIELD_MAX, -}; - -/* Get value from Common AVTPDU field. - * @pdu: Pointer to PDU struct. - * @field: PDU field to be retrieved. - * @val: Pointer to variable which the retrieved value should be saved. - * - * Returns: - * 0: Success. - * -EINVAL: If any argument is invalid. - */ -int avtp_pdu_get(const struct avtp_common_pdu *pdu, enum avtp_field field, - uint32_t *val); - -/* Set value from Common AVTPDU field. - * @pdu: Pointer to PDU struct. - * @field: PDU field to be set. - * @val: Value to be set. - * - * Returns: - * 0: Success. - * -EINVAL: If any argument is invalid. - */ -int avtp_pdu_set(struct avtp_common_pdu *pdu, enum avtp_field field, - uint32_t val); - -#ifdef __cplusplus -} -#endif diff --git a/src/avtp.c b/src/avtp.c deleted file mode 100644 index 9cb492e..0000000 --- a/src/avtp.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2017, Intel Corporation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Intel Corporation nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#include "avtp.h" -#include "util.h" - -#define SHIFT_SUBTYPE (31 - 7) -#define SHIFT_VERSION (31 - 11) - -#define MASK_SUBTYPE (BITMASK(8) << SHIFT_SUBTYPE) -#define MASK_VERSION (BITMASK(3) << SHIFT_VERSION) - -int avtp_pdu_get(const struct avtp_common_pdu *pdu, enum avtp_field field, - uint32_t *val) -{ - uint32_t bitmap, mask; - uint8_t shift; - - if (!pdu || !val) - return -EINVAL; - - switch (field) { - case AVTP_FIELD_SUBTYPE: - mask = MASK_SUBTYPE; - shift = SHIFT_SUBTYPE; - break; - case AVTP_FIELD_VERSION: - mask = MASK_VERSION; - shift = SHIFT_VERSION; - break; - default: - return -EINVAL; - } - - bitmap = ntohl(pdu->subtype_data); - - *val = BITMAP_GET_VALUE(bitmap, mask, shift); - - return 0; -} - -int avtp_pdu_set(struct avtp_common_pdu *pdu, enum avtp_field field, - uint32_t value) -{ - uint32_t bitmap, mask; - uint8_t shift; - - if (!pdu) - return -EINVAL; - - switch (field) { - case AVTP_FIELD_SUBTYPE: - mask = MASK_SUBTYPE; - shift = SHIFT_SUBTYPE; - break; - case AVTP_FIELD_VERSION: - mask = MASK_VERSION; - shift = SHIFT_VERSION; - break; - default: - return -EINVAL; - } - - bitmap = ntohl(pdu->subtype_data); - - BITMAP_SET_VALUE(bitmap, value, mask, shift); - - pdu->subtype_data = htonl(bitmap); - - return 0; -} diff --git a/src/util.h b/src/util.h deleted file mode 100644 index 91c8b31..0000000 --- a/src/util.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2017, Intel Corporation - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of Intel Corporation nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#define BIT(n) (1ULL << n) - -#define BITMASK(len) (BIT(len) - 1) - -/* Get value from the bits within 'bitmap' represented by 'mask'. The 'mask' - * parameter must be a continuous bit mask (e.g. 0b00111000). This macro - * doesn't work with non-continuous bit masks (e.g. 0b00101001). - */ -#define BITMAP_GET_VALUE(bitmap, mask, shift) \ - ((bitmap & mask) >> shift) - -/* Set the value 'val' in the 'bitmap' variable at the position represented by - * 'mask'. - */ -#define BITMAP_SET_VALUE(bitmap, val, mask, shift) \ - (bitmap = (bitmap & ~mask) | ((val << shift) & mask)) - -struct __una_u32 { uint32_t x; } __attribute__((packed)); - -static inline uint32_t get_unaligned_be32(const void *p) -{ - const struct __una_u32 *ptr = (const struct __una_u32 *)p; - return ntohl(ptr->x); -} - -static inline void put_unaligned_be32(uint32_t val, void *p) -{ - struct __una_u32 *ptr = (struct __una_u32 *)p; - ptr->x = htonl(val); -} From 7e737d73f12ce91d6aa1816dfde2ebea984fd994 Mon Sep 17 00:00:00 2001 From: Naresh Nayak Date: Fri, 28 Jun 2024 11:50:53 +0000 Subject: [PATCH 3/3] First version for uC setup. Signed-off-by: Naresh Nayak --- examples/aaf/aaf-listener.c | 1 - examples/aaf/aaf-talker.c | 1 - examples/crf/crf-listener.c | 1 - examples/crf/crf-talker.c | 1 - examples/cvf/cvf-listener.c | 1 - examples/cvf/cvf-talker.c | 1 - include/avtp/CommonHeader.h | 50 +++++++++++++++++++++++++++++++++++-- meson.build | 1 - src/avtp/CommonHeader.c | 21 ++++++++++++++++ unit/test-aaf.c | 3 ++- unit/test-avtp.c | 2 +- unit/test-crf.c | 3 ++- unit/test-cvf.c | 3 ++- unit/test-rvf.c | 3 ++- 14 files changed, 78 insertions(+), 14 deletions(-) diff --git a/examples/aaf/aaf-listener.c b/examples/aaf/aaf-listener.c index a8541b7..74b7355 100644 --- a/examples/aaf/aaf-listener.c +++ b/examples/aaf/aaf-listener.c @@ -69,7 +69,6 @@ #include #include -#include "avtp.h" #include "avtp/aaf/PcmStream.h" #include "common.h" #include "avtp/CommonHeader.h" diff --git a/examples/aaf/aaf-talker.c b/examples/aaf/aaf-talker.c index 0b59859..19ee08f 100644 --- a/examples/aaf/aaf-talker.c +++ b/examples/aaf/aaf-talker.c @@ -64,7 +64,6 @@ #include #include -#include "avtp.h" #include "avtp/aaf/PcmStream.h" #include "common.h" #include "avtp/CommonHeader.h" diff --git a/examples/crf/crf-listener.c b/examples/crf/crf-listener.c index 83d70f2..951bfe9 100644 --- a/examples/crf/crf-listener.c +++ b/examples/crf/crf-listener.c @@ -99,7 +99,6 @@ #include #include -#include "avtp.h" #include "avtp/Crf.h" #include "avtp/aaf/PcmStream.h" #include "common.h" diff --git a/examples/crf/crf-talker.c b/examples/crf/crf-talker.c index 8b47257..75ee047 100644 --- a/examples/crf/crf-talker.c +++ b/examples/crf/crf-talker.c @@ -62,7 +62,6 @@ #include #include -#include "avtp.h" #include "avtp/Crf.h" #include "common.h" #include "avtp/CommonHeader.h" diff --git a/examples/cvf/cvf-listener.c b/examples/cvf/cvf-listener.c index ddf2bbb..f7cbba8 100644 --- a/examples/cvf/cvf-listener.c +++ b/examples/cvf/cvf-listener.c @@ -72,7 +72,6 @@ #include #include -#include "avtp.h" #include "avtp/cvf/Cvf.h" #include "avtp/cvf/H264.h" #include "avtp/CommonHeader.h" diff --git a/examples/cvf/cvf-talker.c b/examples/cvf/cvf-talker.c index 5a36d5c..3e4e4c2 100644 --- a/examples/cvf/cvf-talker.c +++ b/examples/cvf/cvf-talker.c @@ -75,7 +75,6 @@ #include #include -#include "avtp.h" #include "avtp/cvf/Cvf.h" #include "avtp/cvf/H264.h" #include "common.h" diff --git a/include/avtp/CommonHeader.h b/include/avtp/CommonHeader.h index 4d68402..54ff590 100644 --- a/include/avtp/CommonHeader.h +++ b/include/avtp/CommonHeader.h @@ -51,7 +51,7 @@ typedef struct { * Enumeration over all IEEE 1722 header fields. The naming convention used is * AVTP__FIELD_. */ -typedef enum { +typedef enum Avtp_CommonHeaderField{ /* Common AVTP header fields */ AVTP_COMMON_HEADER_FIELD_SUBTYPE = 0, AVTP_COMMON_HEADER_FIELD_H, @@ -104,4 +104,50 @@ int Avtp_CommonHeader_GetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderF * @returns This function returns 0 if the data field was successfully set in * the 1722 AVTP PDU. */ -int Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field, uint64_t value); \ No newline at end of file +int Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderField_t field, uint64_t value); + +/****************************************************************************** + * Legacy API (deprecated) + *****************************************************************************/ + +struct avtp_common_pdu { + uint32_t subtype_data; + uint8_t pdu_specific[0]; +} __attribute__ ((__packed__)); + +struct avtp_stream_pdu { + uint32_t subtype_data; + uint64_t stream_id; + uint32_t avtp_time; + uint32_t format_specific; + uint32_t packet_info; + uint8_t avtp_payload[0]; +} __attribute__ ((__packed__)); + +#define AVTP_FIELD_SUBTYPE (AVTP_COMMON_HEADER_FIELD_SUBTYPE) +#define AVTP_FIELD_VERSION (AVTP_COMMON_HEADER_FIELD_VERSION) +#define AVTP_FIELD_MAX (AVTP_COMMON_HEADER_FIELD_MAX) + +/* Get value from Common AVTPDU field. + * @pdu: Pointer to PDU struct. + * @field: PDU field to be retrieved. + * @val: Pointer to variable which the retrieved value should be saved. + * + * Returns: + * 0: Success. + * -EINVAL: If any argument is invalid. + */ +int avtp_pdu_get(const struct avtp_common_pdu *pdu, Avtp_CommonHeaderField_t field, + uint32_t *val); + +/* Set value from Common AVTPDU field. + * @pdu: Pointer to PDU struct. + * @field: PDU field to be set. + * @val: Value to be set. + * + * Returns: + * 0: Success. + * -EINVAL: If any argument is invalid. + */ +int avtp_pdu_set(struct avtp_common_pdu *pdu, Avtp_CommonHeaderField_t field, + uint32_t val); \ No newline at end of file diff --git a/meson.build b/meson.build index 0270748..9bb2350 100644 --- a/meson.build +++ b/meson.build @@ -9,7 +9,6 @@ project( avtp_lib = library( 'open1722', [ - 'src/avtp.c', 'src/avtp/Utils.c', 'src/avtp/acf/Ntscf.c', 'src/avtp/acf/Tscf.c', diff --git a/src/avtp/CommonHeader.c b/src/avtp/CommonHeader.c index 4389556..1cd6e97 100644 --- a/src/avtp/CommonHeader.c +++ b/src/avtp/CommonHeader.c @@ -52,3 +52,24 @@ int Avtp_CommonHeader_SetField(Avtp_CommonHeader_t* avtp_pdu, Avtp_CommonHeaderF { return Avtp_SetField(Avtp_CommonHeaderFieldDesc, AVTP_COMMON_HEADER_FIELD_MAX, (uint8_t*)avtp_pdu, (uint8_t)field, value); } + +/****************************************************************************** + * Legacy API + *****************************************************************************/ +int avtp_pdu_get(const struct avtp_common_pdu *pdu, Avtp_CommonHeaderField_t field, + uint32_t *val) +{ + uint64_t temp; + int ret; + ret = Avtp_CommonHeader_GetField((Avtp_CommonHeader_t*) pdu, field, &temp); + if (val == NULL) return -EINVAL; + + *val = (uint32_t)temp; + return ret; +} + +int avtp_pdu_set(struct avtp_common_pdu *pdu, Avtp_CommonHeaderField_t field, + uint32_t value) +{ + return Avtp_CommonHeader_SetField((Avtp_CommonHeader_t*) pdu, field, value); +} \ No newline at end of file diff --git a/unit/test-aaf.c b/unit/test-aaf.c index b9879a0..ec5dd8a 100644 --- a/unit/test-aaf.c +++ b/unit/test-aaf.c @@ -30,8 +30,9 @@ #include #include #include +#include -#include "avtp.h" +#include "avtp/CommonHeader.h" #include "avtp/aaf/PcmStream.h" static void aaf_get_field_null_pdu(void **state) diff --git a/unit/test-avtp.c b/unit/test-avtp.c index ac295d7..107e9d8 100644 --- a/unit/test-avtp.c +++ b/unit/test-avtp.c @@ -30,8 +30,8 @@ #include #include #include +#include -#include "avtp.h" #include "avtp/CommonHeader.h" static void get_field_null_pdu(void **state) diff --git a/unit/test-crf.c b/unit/test-crf.c index e83ff72..f6eaa70 100644 --- a/unit/test-crf.c +++ b/unit/test-crf.c @@ -31,8 +31,9 @@ #include #include #include +#include -#include "avtp.h" +#include "avtp/CommonHeader.h" #include "avtp/Crf.h" static void crf_get_field_null_pdu(void **state) diff --git a/unit/test-cvf.c b/unit/test-cvf.c index 76f1025..98acfc7 100644 --- a/unit/test-cvf.c +++ b/unit/test-cvf.c @@ -33,8 +33,9 @@ #include #include #include +#include -#include "avtp.h" +#include "avtp/CommonHeader.h" #include "avtp/cvf/Cvf.h" #include "avtp/cvf/H264.h" diff --git a/unit/test-rvf.c b/unit/test-rvf.c index 5b53d06..1d342b0 100644 --- a/unit/test-rvf.c +++ b/unit/test-rvf.c @@ -34,8 +34,9 @@ #include #include #include +#include -#include "avtp.h" +#include "avtp/CommonHeader.h" #include "avtp/Rvf.h" static void rvf_get_field_null_pdu(void **state)