From 5243fbd3c5feb3bbc2a04c7c7a501e088b0e70c5 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Wed, 13 May 2020 09:18:44 +0800 Subject: [PATCH] [core, mod_av] move switch_packetizer to core --- Makefile.am | 1 + .../mod_av => include}/switch_packetizer.h | 0 src/mod/applications/mod_av/Makefile.am | 7 +- .../mod_av => }/switch_packetizer.c | 0 tests/unit/Makefile.am | 2 +- .../unit/switch_packetizer.c | 79 +++++++------------ 6 files changed, 31 insertions(+), 58 deletions(-) rename src/{mod/applications/mod_av => include}/switch_packetizer.h (100%) rename src/{mod/applications/mod_av => }/switch_packetizer.c (100%) rename src/mod/applications/mod_av/test/test_packetizer.c => tests/unit/switch_packetizer.c (69%) diff --git a/Makefile.am b/Makefile.am index 09d500a4d7..e9fb74c646 100644 --- a/Makefile.am +++ b/Makefile.am @@ -364,6 +364,7 @@ libfreeswitch_la_SOURCES = \ src/switch_version.c \ src/switch_core_media.c \ src/switch_core_video.c \ + src/switch_packetizer.c \ src/switch_sdp.c \ src/switch_scheduler.c \ src/switch_core_db.c \ diff --git a/src/mod/applications/mod_av/switch_packetizer.h b/src/include/switch_packetizer.h similarity index 100% rename from src/mod/applications/mod_av/switch_packetizer.h rename to src/include/switch_packetizer.h diff --git a/src/mod/applications/mod_av/Makefile.am b/src/mod/applications/mod_av/Makefile.am index 39cb581611..ebf4c93929 100644 --- a/src/mod/applications/mod_av/Makefile.am +++ b/src/mod/applications/mod_av/Makefile.am @@ -13,7 +13,7 @@ endif noinst_LTLIBRARIES = libavmod.la -libavmod_la_SOURCES = mod_av.c avformat.c avcodec.c switch_packetizer.c +libavmod_la_SOURCES = mod_av.c avformat.c avcodec.c libavmod_la_CFLAGS = $(AM_CFLAGS) $(AVFORMAT_CFLAGS) $(AVCODEC_CFLAGS) $(SWSCALE_CFLAGS) $(AVUTIL_CFLAGS) $(RESAMPLE_CFLAGS) mod_LTLIBRARIES = mod_av.la @@ -22,16 +22,13 @@ mod_av_la_LIBADD = libavmod.la $(switch_builddir)/libfreeswitch.la $(AVFORMAT_ mod_av_la_LDFLAGS = -avoid-version -module -no-undefined -shared -lm -lz -noinst_PROGRAMS = test/test_mod_av test/test_avformat test/test_packetizer +noinst_PROGRAMS = test/test_mod_av test/test_avformat test_test_mod_av_CFLAGS = $(SWITCH_AM_CFLAGS) -I../ -DSWITCH_TEST_BASE_DIR_FOR_CONF=\"${abs_builddir}/test\" -DSWITCH_TEST_BASE_DIR_OVERRIDE=\"${abs_builddir}/test\" $(AVFORMAT_CFLAGS) $(AVCODEC_CFLAGS) $(SWSCALE_CFLAGS) $(AVUTIL_CFLAGS) $(RESAMPLE_CFLAGS) test_test_mod_av_LDFLAGS = $(AVFORMAT_LIBS) $(AVCODEC_LIBS) $(SWSCALE_LIBS) $(AVUTIL_LIBS) $(RESAMPLE_LIBS) -avoid-version -no-undefined $(SWITCH_AM_LDFLAGS) test_test_mod_av_LDADD = libavmod.la $(switch_builddir)/libfreeswitch.la test_test_avformat_CFLAGS = $(SWITCH_AM_CFLAGS) -I../ -DSWITCH_TEST_BASE_DIR_FOR_CONF=\"${abs_builddir}/test\" -DSWITCH_TEST_BASE_DIR_OVERRIDE=\"${abs_builddir}/test\" $(AVFORMAT_CFLAGS) $(AVCODEC_CFLAGS) $(SWSCALE_CFLAGS) $(AVUTIL_CFLAGS) $(RESAMPLE_CFLAGS) test_test_avformat_LDFLAGS = $(AVFORMAT_LIBS) $(AVCODEC_LIBS) $(SWSCALE_LIBS) $(AVUTIL_LIBS) $(RESAMPLE_LIBS) -avoid-version -no-undefined $(SWITCH_AM_LDFLAGS) test_test_avformat_LDADD = libavmod.la $(switch_builddir)/libfreeswitch.la -test_test_packetizer_CFLAGS = $(SWITCH_AM_CFLAGS) -I../ -DSWITCH_TEST_BASE_DIR_FOR_CONF=\"${abs_builddir}/test\" -DSWITCH_TEST_BASE_DIR_OVERRIDE=\"${abs_builddir}/test\" $(AVFORMAT_CFLAGS) $(AVCODEC_CFLAGS) $(SWSCALE_CFLAGS) $(AVUTIL_CFLAGS) $(RESAMPLE_CFLAGS) -test_test_packetizer_LDFLAGS = $(AVFORMAT_LIBS) $(AVCODEC_LIBS) $(SWSCALE_LIBS) $(AVUTIL_LIBS) $(RESAMPLE_LIBS) -avoid-version -no-undefined $(SWITCH_AM_LDFLAGS) -test_test_packetizer_LDADD = libavmod.la $(switch_builddir)/libfreeswitch.la TESTS = $(noinst_PROGRAMS) diff --git a/src/mod/applications/mod_av/switch_packetizer.c b/src/switch_packetizer.c similarity index 100% rename from src/mod/applications/mod_av/switch_packetizer.c rename to src/switch_packetizer.c diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 231225c5aa..212c54b2bf 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/build/modmake.rulesam noinst_PROGRAMS = switch_event switch_hash switch_ivr_originate switch_utils switch_core switch_console switch_vpx switch_core_file \ switch_ivr_play_say switch_core_codec switch_rtp switch_xml -noinst_PROGRAMS += switch_core_video switch_core_db switch_vad switch_core_asr test_sofia +noinst_PROGRAMS += switch_core_video switch_core_db switch_vad switch_packetizer test_sofia switch_core_asr AM_LDFLAGS += -avoid-version -no-undefined $(SWITCH_AM_LDFLAGS) $(openssl_LIBS) AM_LDFLAGS += $(FREESWITCH_LIBS) $(switch_builddir)/libfreeswitch.la $(CORE_LIBS) $(APR_LIBS) diff --git a/src/mod/applications/mod_av/test/test_packetizer.c b/tests/unit/switch_packetizer.c similarity index 69% rename from src/mod/applications/mod_av/test/test_packetizer.c rename to tests/unit/switch_packetizer.c index 9d34f98d51..242ca6ae33 100644 --- a/src/mod/applications/mod_av/test/test_packetizer.c +++ b/tests/unit/switch_packetizer.c @@ -1,6 +1,6 @@ /* * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application - * Copyright (C) 2005-2018, Anthony Minessale II + * Copyright (C) 2005-2020, Anthony Minessale II * * Version: MPL 1.1 * @@ -24,7 +24,7 @@ * Contributor(s): * * - * test_avformat -- avformat tests + * switch_packetizer.c unit test * */ @@ -35,11 +35,10 @@ FST_CORE_BEGIN("conf") { - FST_MODULE_BEGIN(mod_av, mod_av_test) + FST_SUITE_BEGIN(switch_packetizer) { FST_SETUP_BEGIN() { - fst_requires_module("mod_av"); } FST_SETUP_END() @@ -52,33 +51,33 @@ FST_CORE_BEGIN("conf") uint8_t h264data[] = {0, 0, 0, 1, 0x67, 1, 2, 0, 0, 0, 1, 0x68, 1, 2, 0, 0, 0, 1, 0x65, 1, 2, 3, 4, 5, 6}; frame.data = data; - frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; + frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; switch_set_flag(&frame, SFF_ENCODED); status = switch_packetizer_feed(packetizer, h264data, sizeof(h264data)); fst_requires(status == SWITCH_STATUS_SUCCESS); status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u\n", frame.datalen); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 3); frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u\n", frame.datalen); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 3); frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u\n", frame.datalen); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 4); frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u\n", frame.datalen); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 4); frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u\n", frame.datalen); fst_requires(status == SWITCH_STATUS_SUCCESS); fst_requires(frame.datalen == 4); switch_packetizer_close(&packetizer); @@ -94,33 +93,33 @@ FST_CORE_BEGIN("conf") uint8_t h264data[] = {0, 0, 0, 3, 0x67, 1, 2, 0, 0, 0, 3, 0x68, 1, 2, 0, 0, 0, 7, 0x65, 1, 2, 3, 4, 5, 6}; frame.data = data; - frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; + frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; switch_set_flag(&frame, SFF_ENCODED); status = switch_packetizer_feed(packetizer, h264data, sizeof(h264data)); fst_requires(status == SWITCH_STATUS_SUCCESS); status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u\n", frame.datalen); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 3); frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u\n", frame.datalen); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 3); frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u\n", frame.datalen); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 4); frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u\n", frame.datalen); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 4); frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u\n", frame.datalen); fst_requires(status == SWITCH_STATUS_SUCCESS); fst_requires(frame.datalen == 4); fst_check(frame.m == 1); @@ -138,7 +137,7 @@ FST_CORE_BEGIN("conf") uint8_t extradata[] = {0x01, 0x64, 0x00, 0x1e, 0xff, 0xe1, 0x00, 0x03, 0x67, 0x64, 0x00, 0xe1, 0x00, 0x03, 0x68, 0x01, 0x02}; // 1 fps 3 bytes 1pps 3 bytes frame.data = data; - frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; + frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; switch_set_flag(&frame, SFF_ENCODED); status = switch_packetizer_feed_extradata(packetizer, extradata, sizeof(extradata)); @@ -148,35 +147,35 @@ FST_CORE_BEGIN("conf") fst_requires(status == SWITCH_STATUS_SUCCESS); status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u\n", frame.datalen); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 3); fst_check((*(uint8_t *)frame.data & 0x1f) == 0x06); frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u %x\n", frame.datalen, *(uint8_t *)frame.data); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u %x\n", frame.datalen, *(uint8_t *)frame.data); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 3); fst_check((*(uint8_t *)frame.data & 0x1f) == 0x09); frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u %x\n", frame.datalen, *(uint8_t *)frame.data); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u %x\n", frame.datalen, *(uint8_t *)frame.data); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 3); fst_check((*(uint8_t *)frame.data & 0x1f) == 0x07); frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u %x\n", frame.datalen, *(uint8_t *)frame.data); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u %x\n", frame.datalen, *(uint8_t *)frame.data); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 3); fst_check((*(uint8_t *)frame.data & 0x1f) == 0x08); frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u %x\n", frame.datalen, *(uint8_t *)frame.data); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u %x\n", frame.datalen, *(uint8_t *)frame.data); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 4); fst_check((*(uint8_t *)frame.data & 0x1f) == 0x1c); @@ -184,7 +183,7 @@ FST_CORE_BEGIN("conf") frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u %x\n", frame.datalen, *(uint8_t *)frame.data); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u %x\n", frame.datalen, *(uint8_t *)frame.data); fst_requires(status == SWITCH_STATUS_MORE_DATA); fst_requires(frame.datalen == 4); fst_check((*(uint8_t *)frame.data & 0x1f) == 0x1c); @@ -192,7 +191,7 @@ FST_CORE_BEGIN("conf") frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u %x\n", frame.datalen, *(uint8_t *)frame.data); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%u %x\n", frame.datalen, *(uint8_t *)frame.data); fst_requires(status == SWITCH_STATUS_SUCCESS); fst_requires(frame.datalen == 4); fst_check((*(uint8_t *)frame.data & 0x1f) == 0x1c); @@ -210,47 +209,23 @@ FST_CORE_BEGIN("conf") uint8_t h264data[] = {0, 0, 2, 9, 0x67, 1, 2, 0, 0, 0, 0, 0x68, 1, 2, 0, 0, 0, 0, 0x65, 1, 2, 3, 4, 5, 6}; frame.data = data; - frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; + frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE; switch_set_flag(&frame, SFF_ENCODED); status = switch_packetizer_feed(packetizer, h264data, sizeof(h264data)); fst_requires(status == SWITCH_STATUS_SUCCESS); status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); - fst_requires(status == SWITCH_STATUS_MORE_DATA); - fst_requires(frame.datalen == 3); - frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; - status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); - fst_requires(status == SWITCH_STATUS_MORE_DATA); - fst_requires(frame.datalen == 3); - frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; - status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); - fst_requires(status == SWITCH_STATUS_MORE_DATA); - fst_requires(frame.datalen == 4); - frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; - status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); - fst_requires(status == SWITCH_STATUS_MORE_DATA); - fst_requires(frame.datalen == 4); - frame.datalen = SWITCH_RECOMMENDED_BUFFER_SIZE; - status = switch_packetizer_read(packetizer, &frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%u\n", frame.datalen); - fst_requires(status == SWITCH_STATUS_SUCCESS); - fst_requires(frame.datalen == 4); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "status = %d datalen = %u\n", status, frame.datalen); + fst_requires(status == SWITCH_STATUS_FALSE); switch_packetizer_close(&packetizer); } FST_TEST_END() FST_TEARDOWN_BEGIN() { - //const char *err = NULL; - switch_sleep(1000000); - //fst_check(switch_loadable_module_unload_module(SWITCH_GLOBAL_dirs.mod_dir, (char *)"mod_av", SWITCH_TRUE, &err) == SWITCH_STATUS_SUCCESS); } FST_TEARDOWN_END() } - FST_MODULE_END() + FST_SUITE_END() } FST_CORE_END()