Skip to content

Commit

Permalink
Fix roc-streaming#772: adding support for control packets
Browse files Browse the repository at this point in the history
  • Loading branch information
kiranlahiri committed Dec 9, 2024
1 parent 3a19267 commit c6d7747
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/tests/public_api/test_helpers/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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;

{
Expand Down
58 changes: 58 additions & 0 deletions src/tests/public_api/test_sender_receiver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <CppUTest/TestHarness.h>
#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

0 comments on commit c6d7747

Please sign in to comment.