From c6d774797e74f1121cd677fbeab887b1e19ebd68 Mon Sep 17 00:00:00 2001 From: lahirik Date: Mon, 9 Dec 2024 18:06:16 -0500 Subject: [PATCH] Fix #772: adding support for control packets --- src/tests/public_api/test_helpers/proxy.h | 24 +++++++- src/tests/public_api/test_sender_receiver.cpp | 58 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/tests/public_api/test_sender_receiver.cpp diff --git a/src/tests/public_api/test_helpers/proxy.h b/src/tests/public_api/test_helpers/proxy.h index 76401341f..90f21efc2 100644 --- a/src/tests/public_api/test_helpers/proxy.h +++ b/src/tests/public_api/test_helpers/proxy.h @@ -31,12 +31,14 @@ class Proxy : private packet::IWriter { Proxy(const roc_endpoint* receiver_source_endp, const roc_endpoint* receiver_repair_endp, size_t n_source_packets, - size_t n_repair_packets) + size_t n_repair_packets, + size_t n_control_packets) // Added control packets count : packet_pool_("proxy_packet_pool", arena_) , buffer_pool_("proxy_buffer_pool", arena_, 2000) , net_loop_(packet_pool_, buffer_pool_, arena_) , n_source_packets_(n_source_packets) , n_repair_packets_(n_repair_packets) + , n_control_packets_(n_control_packets) // Initialize control packets count , pos_(0) { CHECK(net_loop_.is_valid()); @@ -65,6 +67,26 @@ class Proxy : private packet::IWriter { CHECK(recv_repair_config_.bind_address.set_host_port(address::Family_IPv4, "127.0.0.1", 0)); + + // Control endpoint setup + if (receiver_control_endp) { + roc_protocol control_proto; + CHECK(roc_endpoint_get_protocol(receiver_control_endp, &control_proto) == 0); + + int control_port = 0; + CHECK(roc_endpoint_get_port(receiver_control_endp, &control_port) == 0); + + CHECK(receiver_control_endp_.set_host_port(address::Family_IPv4, "127.0.0.1", control_port)); + + CHECK(recv_control_config_.bind_address.set_host_port(address::Family_IPv4, "127.0.0.1", 0)); + + netio::NetworkLoop::Tasks::AddUdpPort add_task(recv_control_config_); + CHECK(net_loop_.schedule_and_wait(add_task)); + + netio::NetworkLoop::Tasks::StartUdpRecv recv_task(add_task.get_handle(), *this); + CHECK(net_loop_.schedule_and_wait(recv_task)); + } + netio::NetworkLoop::PortHandle send_port = NULL; { diff --git a/src/tests/public_api/test_sender_receiver.cpp b/src/tests/public_api/test_sender_receiver.cpp new file mode 100644 index 000000000..5f4a55368 --- /dev/null +++ b/src/tests/public_api/test_sender_receiver.cpp @@ -0,0 +1,58 @@ +#include +#include "roc_core/stddefs.h" +#include "roc/endpoint.h" +#include "roc/sender.h" +#include "roc/receiver.h" + +namespace roc { +namespace api { + +TEST(SenderReceiverIntegration, ProxyWithControlEndpoint) { + roc_context* context; + roc_proxy* proxy; + + roc_context_config context_config; + memset(&context_config, 0, sizeof(context_config)); + CHECK(roc_context_open(&context_config, &context) == 0); + CHECK(context); + + roc_endpoint* source_endpoint; + CHECK(roc_endpoint_allocate(&source_endpoint) == 0); + CHECK(roc_endpoint_set_uri(source_endpoint, "rtp://127.0.0.1:10001") == 0); + + roc_endpoint* repair_endpoint; + CHECK(roc_endpoint_allocate(&repair_endpoint) == 0); + CHECK(roc_endpoint_set_uri(repair_endpoint, "rs8m://127.0.0.1:10002") == 0); + + roc_endpoint* control_endpoint; + CHECK(roc_endpoint_allocate(&control_endpoint) == 0); + CHECK(roc_endpoint_set_uri(control_endpoint, "rtcp://127.0.0.1:10003") == 0); + + // Initialize the Proxy with endpoints + Proxy proxy_instance( + source_endpoint, repair_endpoint, control_endpoint, + 10, 10, 10 // Packet counts for source, repair, and control + ); + + // Verify that endpoints are set correctly + CHECK(proxy_instance.source_endpoint() == source_endpoint); + CHECK(proxy_instance.repair_endpoint() == repair_endpoint); + CHECK(proxy_instance.control_endpoint() == control_endpoint); + + // Simulate communication through Proxy + // For example, create a dummy packet, send it, and check the result + packet::PacketPtr dummy_packet = packet::Packet::make(); + dummy_packet->udp()->dst_addr = control_endpoint->address; // Set destination to control + CHECK(proxy_instance.write(dummy_packet) == status::StatusOK); + + // Clean up + CHECK(roc_endpoint_deallocate(source_endpoint) == 0); + CHECK(roc_endpoint_deallocate(repair_endpoint) == 0); + CHECK(roc_endpoint_deallocate(control_endpoint) == 0); + CHECK(roc_context_close(context) == 0); +} + + + +} // namespace api +} // namespace roc \ No newline at end of file