]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[unit-tests] add RTP test with session
authorDragos Oancea <dragos@signalwire.com>
Tue, 24 Dec 2019 16:50:36 +0000 (16:50 +0000)
committerAndrey Volk <andywolk@gmail.com>
Thu, 9 Jan 2020 08:38:38 +0000 (12:38 +0400)
tests/unit/switch_rtp.c

index 8c41764eba75c4e51acafec3db8ad92cc8178cba..9b0054ac7d55561401a115411083252a61c9424c 100644 (file)
@@ -23,6 +23,7 @@ FST_SUITE_BEGIN(switch_rtp)
 {
 FST_SETUP_BEGIN()
 {
+       fst_requires_module("mod_loopback");
 }
 FST_SETUP_END()
 
@@ -30,28 +31,72 @@ 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);
 
-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()
+               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()
 }