Rework stream socket

Stream socket on server now uses the same port as the control socket.
Client does not assign a port to its stream socket, instead it sends a
handshake packet at the beginning, the server reads the remote port from
it.
This commit is contained in:
Patrick Nicolas
2023-11-08 19:15:59 +01:00
parent c3383521a4
commit 38fcf7dc00
12 changed files with 141 additions and 67 deletions
+12 -7
View File
@@ -26,8 +26,6 @@
#include <netinet/in.h>
#include <optional>
#include <span>
#include <string>
#include <tuple>
#include <variant>
#include <vector>
#include <openxr/openxr.h>
@@ -38,9 +36,8 @@ namespace xrt::drivers::wivrn
template <typename T, typename Enable>
struct serialization_traits;
static const int control_port = 9757;
static const int stream_client_port = 9757;
static const int stream_server_port = 9758;
// Default port for server to listen, both TCP and UDP
static const int default_port = 9757;
enum class device_id : uint8_t
{
@@ -110,6 +107,10 @@ struct headset_info_packet
std::optional<audio_description> microphone;
};
struct handshake
{
};
struct tracking
{
enum flags : uint8_t
@@ -186,12 +187,16 @@ struct feedback
};
using control_packets = std::variant<headset_info_packet, feedback, audio_data>;
using stream_packets = std::variant<tracking, inputs, timesync_response>;
using stream_packets = std::variant<handshake, tracking, inputs, timesync_response>;
} // namespace from_headset
namespace to_headset
{
struct handshake
{
};
struct audio_stream_description
{
struct device
@@ -303,8 +308,8 @@ struct timesync_query
std::chrono::nanoseconds query;
};
using control_packets = std::variant<handshake, audio_stream_description, video_stream_description, audio_data>;
using stream_packets = std::variant<video_stream_data_shard, video_stream_parity_shard, haptics, timesync_query>;
using control_packets = std::variant<audio_stream_description, video_stream_description, audio_data>;
} // namespace to_headset
+15 -15
View File
@@ -242,21 +242,21 @@ xrt::drivers::wivrn::TCPListener::TCPListener(int port)
}
}
// std::pair<xrt::drivers::wivrn::deserialization_packet, sockaddr_in6> xrt::drivers::wivrn::UDP::receive_from_raw()
// {
// std::vector<uint8_t> buffer(2000);
//
// sockaddr_in6 addr;
// socklen_t addrlen = sizeof(addr);
//
// ssize_t received = recvfrom(fd, buffer.data(), buffer.size(), 0, (sockaddr *)&addr, &addrlen);
// if (received < 0)
// throw std::system_error{errno, std::generic_category()};
//
// buffer.resize(received);
//
// return {deserialization_packet{buffer}, addr};
// }
std::pair<xrt::drivers::wivrn::deserialization_packet, sockaddr_in6> xrt::drivers::wivrn::UDP::receive_from_raw()
{
std::vector<uint8_t> buffer(2000);
sockaddr_in6 addr;
socklen_t addrlen = sizeof(addr);
ssize_t received = recvfrom(fd, buffer.data(), buffer.size(), 0, (sockaddr *)&addr, &addrlen);
if (received < 0)
throw std::system_error{errno, std::generic_category()};
buffer.resize(received);
return {deserialization_packet{buffer}, addr};
}
xrt::drivers::wivrn::deserialization_packet xrt::drivers::wivrn::UDP::receive_raw()
{
+2 -1
View File
@@ -25,7 +25,7 @@
#include <memory>
#include <mutex>
#include <netinet/ip.h>
#include <stdexcept>
#include <exception>
#include <utility>
#include <vector>
@@ -88,6 +88,7 @@ public:
UDP();
deserialization_packet receive_raw();
std::pair<xrt::drivers::wivrn::deserialization_packet, sockaddr_in6> receive_from_raw();
void send_raw(const std::vector<uint8_t> & data);
void connect(in6_addr address, int port);