From 8e43604dbd841240ce8c307ae57a57ae204a5dc7 Mon Sep 17 00:00:00 2001 From: Seven Du Date: Wed, 23 Jan 2019 21:44:13 +0800 Subject: [PATCH] FS-11425 add vpx test code --- tests/unit/Makefile.am | 2 +- tests/unit/switch_vpx.c | 93 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 tests/unit/switch_vpx.c diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index d30299e169..6d6270208c 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -1,6 +1,6 @@ include $(top_srcdir)/build/modmake.rulesam -bin_PROGRAMS = switch_event switch_hash switch_ivr_originate switch_utils switch_core switch_console +bin_PROGRAMS = switch_event switch_hash switch_ivr_originate switch_utils switch_core switch_console switch_vpx AM_LDFLAGS = -avoid-version -no-undefined $(SWITCH_AM_LDFLAGS) $(openssl_LIBS) AM_LDFLAGS += $(FREESWITCH_LIBS) $(switch_builddir)/libfreeswitch.la $(CORE_LIBS) $(APR_LIBS) AM_CFLAGS = $(SWITCH_AM_CPPFLAGS) diff --git a/tests/unit/switch_vpx.c b/tests/unit/switch_vpx.c new file mode 100644 index 0000000000..97c55fdba5 --- /dev/null +++ b/tests/unit/switch_vpx.c @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2018, Signalwire, Inc. ALL RIGHTS RESERVED + * + * switch_vpx.c -- Tests vpx functions + */ +#include + +FST_CORE_BEGIN("./conf") +{ + FST_SUITE_BEGIN() + { + FST_SETUP_BEGIN() + { + } + FST_SETUP_END() + + FST_TEST_BEGIN(avcodec_test) + { + switch_status_t status; + switch_codec_t codec = { 0 }; + switch_codec_settings_t codec_settings = { 0 }; + + // switch_set_string(codec_settings.video.config_profile_name, "conference"); + codec_settings.video.width = 1280; + codec_settings.video.height = 720; + + status = switch_core_codec_init(&codec, + "VP8", + NULL, + NULL, + 0, + 0, + 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + &codec_settings, fst_pool); + fst_check(status == SWITCH_STATUS_SUCCESS); + + switch_image_t *img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, 1280, 720, 1); + fst_requires(img); + + uint8_t buf[SWITCH_DEFAULT_VIDEO_SIZE + 12]; + switch_frame_t frame = { 0 }; + + frame.packet = buf; + frame.packetlen = SWITCH_DEFAULT_VIDEO_SIZE + 12; + frame.data = buf + 12; + frame.datalen = SWITCH_DEFAULT_VIDEO_SIZE; + frame.payload = 96; + frame.m = 0; + frame.seq = 0; + frame.timestamp = 0; + frame.img = img; + + int packets = 0; + switch_status_t encode_status; + + do { + frame.datalen = SWITCH_DEFAULT_VIDEO_SIZE; + encode_status = switch_core_codec_encode_video(&codec, &frame); + + if (encode_status == SWITCH_STATUS_SUCCESS || encode_status == SWITCH_STATUS_MORE_DATA) { + + switch_assert((encode_status == SWITCH_STATUS_SUCCESS && frame.m) || !frame.m); + + if (frame.flags & SFF_PICTURE_RESET) { + frame.flags &= ~SFF_PICTURE_RESET; + // fst_check(0); + } + + if (frame.datalen == 0) break; + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%02x %02x | m=%d | %d\n", buf[12], buf[13], frame.m, frame.datalen); + packets++; + } + + } while(encode_status == SWITCH_STATUS_MORE_DATA); + + fst_check(frame.m == 1); + fst_check(packets > 0); + + switch_core_codec_destroy(&codec); + } + FST_TEST_END() + + FST_TEARDOWN_BEGIN() + { + switch_sleep(1000000); + // switch_core_destroy(); + } + FST_TEARDOWN_END() + } + FST_SUITE_END() +} +FST_CORE_END()