[core, mod_av] move switch_packetizer to core

This commit is contained in:
Seven Du
2020-05-13 09:18:44 +08:00
committed by Andrey Volk
parent 64aebc31ed
commit 5243fbd3c5
6 changed files with 31 additions and 58 deletions
+2 -5
View File
@@ -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)
@@ -1,256 +0,0 @@
/*
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2005-2018, Anthony Minessale II <anthm@freeswitch.org>
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
*
* The Initial Developer of the Original Code is
* Seven Du <seven@signalwire.com>
* Portions created by the Initial Developer are Copyright (C)
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
*
* test_avformat -- avformat tests
*
*/
#include <test/switch_test.h>
#include <switch_packetizer.h>
#define SLICE_SIZE 4
FST_CORE_BEGIN("conf")
{
FST_MODULE_BEGIN(mod_av, mod_av_test)
{
FST_SETUP_BEGIN()
{
fst_requires_module("mod_av");
}
FST_SETUP_END()
FST_TEST_BEGIN(test_packetizer_bitstream)
{
switch_packetizer_t *packetizer = switch_packetizer_create(SPT_H264_BITSTREAM, SLICE_SIZE);
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_frame_t frame = {0};
switch_status_t status;
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;
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_packetizer_close(&packetizer);
}
FST_TEST_END()
FST_TEST_BEGIN(test_packetizer_sized_bitstream_has_sps_pps)
{
switch_packetizer_t *packetizer = switch_packetizer_create(SPT_H264_SIZED_BITSTREAM, SLICE_SIZE);
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_frame_t frame = {0};
switch_status_t status;
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;
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);
fst_check(frame.m == 1);
switch_packetizer_close(&packetizer);
}
FST_TEST_END()
FST_TEST_BEGIN(test_packetizer_sized_bitstream_no_sps_pps)
{
switch_packetizer_t *packetizer = switch_packetizer_create(SPT_H264_SIZED_BITSTREAM, SLICE_SIZE);
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_frame_t frame = {0};
switch_status_t status;
uint8_t h264data[] = {0, 0, 0, 3, 0x06, 1, 2, 0, 0, 0, 3, 0x09, 1, 2, 0, 0, 0, 7, 0x65, 1, 2, 3, 4, 5, 6};
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;
switch_set_flag(&frame, SFF_ENCODED);
status = switch_packetizer_feed_extradata(packetizer, extradata, sizeof(extradata));
fst_requires(status == SWITCH_STATUS_SUCCESS);
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);
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);
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);
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);
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);
fst_requires(status == SWITCH_STATUS_MORE_DATA);
fst_requires(frame.datalen == 4);
fst_check((*(uint8_t *)frame.data & 0x1f) == 0x1c);
fst_check(frame.m == 0);
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);
fst_requires(status == SWITCH_STATUS_MORE_DATA);
fst_requires(frame.datalen == 4);
fst_check((*(uint8_t *)frame.data & 0x1f) == 0x1c);
fst_check(frame.m == 0);
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);
fst_requires(status == SWITCH_STATUS_SUCCESS);
fst_requires(frame.datalen == 4);
fst_check((*(uint8_t *)frame.data & 0x1f) == 0x1c);
fst_check(frame.m == 1);
switch_packetizer_close(&packetizer);
}
FST_TEST_END()
FST_TEST_BEGIN(test_packetizer_invalid)
{
switch_packetizer_t *packetizer = switch_packetizer_create(SPT_H264_BITSTREAM, SLICE_SIZE);
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_frame_t frame = {0};
switch_status_t status;
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;
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_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_CORE_END()