freeswitch/tests/unit/switch_rtp.c
2020-01-13 18:23:58 +00:00

104 lines
3.6 KiB
C

#include <switch.h>
#include <test/switch_test.h>
static const char *rx_host = "127.0.0.1";
static switch_port_t rx_port = 12346;
static const char *tx_host = "127.0.0.1";
static switch_port_t tx_port = 54320;
static switch_memory_pool_t *pool = NULL;
static switch_rtp_t *rtp_session = NULL;
static switch_rtp_flag_t flags[SWITCH_RTP_FLAG_INVALID] = {0};
const char *err = NULL;
static const switch_payload_t TEST_PT = 8;
switch_rtp_packet_t rtp_packet;
switch_frame_flag_t *frame_flags;
switch_io_flag_t io_flags;
switch_payload_t read_pt;
FST_CORE_BEGIN("./conf")
{
FST_SUITE_BEGIN(switch_rtp)
{
FST_SETUP_BEGIN()
{
fst_requires_module("mod_loopback");
}
FST_SETUP_END()
FST_TEARDOWN_BEGIN()
{
}
FST_TEARDOWN_END()
FST_TEST_BEGIN(test_rtp)
{
switch_core_new_memory_pool(&pool);
rtp_session = switch_rtp_new(rx_host, rx_port, tx_host, tx_port, TEST_PT, 8000, 20 * 1000, flags, "soft", &err, pool, 0, 0);
fst_xcheck(rtp_session != NULL, "get RTP session");
fst_requires(rtp_session);
fst_requires(switch_rtp_ready(rtp_session));
switch_rtp_activate_rtcp(rtp_session, 5, rx_port + 1, 0);
switch_rtp_set_default_payload(rtp_session, TEST_PT);
fst_xcheck(switch_rtp_get_default_payload(rtp_session) == TEST_PT, "get Payload Type")
switch_rtp_set_ssrc(rtp_session, 0xabcd);
switch_rtp_set_remote_ssrc(rtp_session, 0xcdef);
fst_xcheck(switch_rtp_get_ssrc(rtp_session) == 0xabcd, "get SSRC");
switch_rtp_stats_t *stats = switch_rtp_get_stats(rtp_session, pool);
fst_requires(stats);
switch_rtp_destroy(&rtp_session);
switch_core_destroy_memory_pool(&pool);
}
FST_TEST_END()
FST_TEST_BEGIN(test_session_with_rtp)
{
switch_core_session_t *session = NULL;
switch_channel_t *channel = NULL;
switch_status_t status;
switch_call_cause_t cause;
switch_core_new_memory_pool(&pool);
status = switch_ivr_originate(NULL, &session, &cause, "null/+15553334444", 2, NULL, NULL, NULL, NULL, NULL, SOF_NONE, NULL, NULL);
fst_requires(session);
fst_check(status == SWITCH_STATUS_SUCCESS);
channel = switch_core_session_get_channel(session);
fst_requires(channel);
switch_core_memory_pool_set_data(pool, "__session", session);
session = switch_core_memory_pool_get_data(pool, "__session");
fst_requires(session);
rtp_session = switch_rtp_new(rx_host, rx_port, tx_host, tx_port, TEST_PT, 8000, 20 * 1000, flags, "soft", &err, pool, 0, 0);
fst_xcheck(rtp_session != NULL, "switch_rtp_new()");
fst_requires(switch_rtp_ready(rtp_session));
switch_rtp_activate_rtcp(rtp_session, 5, rx_port + 1, 0);
switch_rtp_set_default_payload(rtp_session, TEST_PT);
switch_core_media_set_rtp_session(session, SWITCH_MEDIA_TYPE_AUDIO, rtp_session);
channel = switch_core_session_get_channel(session);
fst_requires(channel);
session = switch_rtp_get_core_session(rtp_session);
fst_requires(session);
status = switch_rtp_activate_jitter_buffer(rtp_session, 1, 10, 80, 8000);
fst_xcheck(status == SWITCH_STATUS_SUCCESS, "switch_rtp_activate_jitter_buffer()")
status = switch_rtp_debug_jitter_buffer(rtp_session, "debug");
fst_xcheck(status == SWITCH_STATUS_SUCCESS, "switch_rtp_debug_jitter_buffer()")
fst_requires(switch_rtp_get_jitter_buffer(rtp_session));
status = switch_rtp_pause_jitter_buffer(rtp_session, SWITCH_TRUE);
fst_xcheck(status == SWITCH_STATUS_SUCCESS, "switch_rtp_pause_jitter_buffer()");
status = switch_rtp_deactivate_jitter_buffer(rtp_session);
fst_xcheck(status == SWITCH_STATUS_SUCCESS, "switch_rtp_deactivate_jitter_buffer()");
switch_rtp_destroy(&rtp_session);
switch_core_session_rwunlock(session);
switch_core_destroy_memory_pool(&pool);
}
FST_TEST_END()
}
FST_SUITE_END()
}
FST_CORE_END()