Reduce some copies in serialization
Also update a bunch of stuff
This commit is contained in:
@@ -8,6 +8,7 @@ if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.24)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
|
||||||
# See: https://github.com/cpm-cmake/CPM.cmake
|
# See: https://github.com/cpm-cmake/CPM.cmake
|
||||||
include("cmake/CPM.cmake")
|
include("cmake/CPM.cmake")
|
||||||
|
|||||||
+2
-2
@@ -19,8 +19,8 @@ apply plugin: 'com.android.application'
|
|||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 29
|
compileSdkVersion 29
|
||||||
buildToolsVersion "30.0.3"
|
buildToolsVersion '33.0.0'
|
||||||
ndkVersion "25.1.8937393"
|
ndkVersion "26.1.10909125"
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "org.meumeu.wivrn"
|
applicationId "org.meumeu.wivrn"
|
||||||
|
|||||||
@@ -22,13 +22,11 @@
|
|||||||
#include "rs.h"
|
#include "rs.h"
|
||||||
#include "scenes/stream.h"
|
#include "scenes/stream.h"
|
||||||
#include "spdlog/spdlog.h"
|
#include "spdlog/spdlog.h"
|
||||||
#include "utils/typename.h"
|
|
||||||
#include "wivrn_serialization.h"
|
#include "wivrn_serialization.h"
|
||||||
|
|
||||||
using namespace xrt::drivers::wivrn::to_headset;
|
using namespace xrt::drivers::wivrn::to_headset;
|
||||||
using shard_set = shard_accumulator::shard_set;
|
using shard_set = shard_accumulator::shard_set;
|
||||||
using data_shard = shard_accumulator::data_shard;
|
using data_shard = shard_accumulator::data_shard;
|
||||||
using parity_shard = shard_accumulator::parity_shard;
|
|
||||||
|
|
||||||
shard_set::shard_set(uint8_t stream_index)
|
shard_set::shard_set(uint8_t stream_index)
|
||||||
{
|
{
|
||||||
@@ -40,7 +38,6 @@ void shard_set::reset(uint64_t frame_index)
|
|||||||
num_shards = 0;
|
num_shards = 0;
|
||||||
min_for_reconstruction = -1;
|
min_for_reconstruction = -1;
|
||||||
data.clear();
|
data.clear();
|
||||||
parity.clear();
|
|
||||||
|
|
||||||
uint8_t stream_index = feedback.stream_index;
|
uint8_t stream_index = feedback.stream_index;
|
||||||
feedback = {};
|
feedback = {};
|
||||||
@@ -79,125 +76,9 @@ uint16_t shard_set::insert(data_shard && shard)
|
|||||||
if (not data[idx])
|
if (not data[idx])
|
||||||
++num_shards;
|
++num_shards;
|
||||||
data[idx] = std::move(shard);
|
data[idx] = std::move(shard);
|
||||||
if (auto i = try_reconstruct())
|
|
||||||
return *i;
|
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<uint16_t> shard_set::insert(parity_shard && shard)
|
|
||||||
{
|
|
||||||
XrTime now = application::now();
|
|
||||||
if (empty())
|
|
||||||
feedback.received_first_packet = now;
|
|
||||||
feedback.received_last_packet = now;
|
|
||||||
|
|
||||||
auto idx = shard.parity_element;
|
|
||||||
min_for_reconstruction = shard.data_shard_count;
|
|
||||||
if (idx >= parity.size())
|
|
||||||
parity.resize(idx + 1);
|
|
||||||
if (not parity[idx])
|
|
||||||
++num_shards;
|
|
||||||
parity[idx] = std::move(shard);
|
|
||||||
|
|
||||||
return try_reconstruct();
|
|
||||||
}
|
|
||||||
|
|
||||||
parity_shard & shard_set::get_parity()
|
|
||||||
{
|
|
||||||
for (auto & shard: parity)
|
|
||||||
{
|
|
||||||
if (shard)
|
|
||||||
return *shard;
|
|
||||||
}
|
|
||||||
// this function shall be called only when at least one parity shard exists
|
|
||||||
assert(false);
|
|
||||||
|
|
||||||
__builtin_unreachable();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<uint16_t> shard_set::try_reconstruct()
|
|
||||||
{
|
|
||||||
if (parity.empty())
|
|
||||||
return {};
|
|
||||||
if (num_shards < min_for_reconstruction)
|
|
||||||
return {};
|
|
||||||
|
|
||||||
static std::once_flag once;
|
|
||||||
std::call_once(once, reed_solomon_init);
|
|
||||||
auto & p = get_parity();
|
|
||||||
std::unique_ptr<reed_solomon, void (*)(reed_solomon *)> rs(
|
|
||||||
reed_solomon_new(p.data_shard_count, p.num_parity_elements), reed_solomon_release);
|
|
||||||
|
|
||||||
size_t shard_size = p.payload.size();
|
|
||||||
|
|
||||||
std::vector<uint8_t *> rs_shards;
|
|
||||||
std::vector<uint8_t> rs_marks;
|
|
||||||
|
|
||||||
std::vector<std::vector<uint8_t>> data_raw;
|
|
||||||
data.resize(p.data_shard_count);
|
|
||||||
data_raw.reserve(p.data_shard_count);
|
|
||||||
for (auto & shard: data)
|
|
||||||
{
|
|
||||||
if (shard)
|
|
||||||
{
|
|
||||||
xrt::drivers::wivrn::serialization_packet s;
|
|
||||||
s.serialize(*shard);
|
|
||||||
data_raw.emplace_back(std::move(s)).resize(shard_size);
|
|
||||||
rs_marks.push_back(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
data_raw.emplace_back(shard_size, 0);
|
|
||||||
rs_marks.push_back(1);
|
|
||||||
}
|
|
||||||
rs_shards.push_back(data_raw.back().data());
|
|
||||||
}
|
|
||||||
// WARNING: do not use p after this line, the array it points to has been modified
|
|
||||||
parity.resize(p.num_parity_elements);
|
|
||||||
std::vector<std::vector<uint8_t>> dummy;
|
|
||||||
dummy.reserve(p.num_parity_elements);
|
|
||||||
for (auto & shard: parity)
|
|
||||||
{
|
|
||||||
if (shard)
|
|
||||||
{
|
|
||||||
rs_shards.push_back(shard->payload.data());
|
|
||||||
rs_marks.push_back(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
auto d = dummy.emplace_back(shard_size).data();
|
|
||||||
rs_shards.push_back(d);
|
|
||||||
rs_marks.push_back(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int err = reed_solomon_reconstruct(rs.get(), rs_shards.data(), rs_marks.data(), data.size() + parity.size(), shard_size);
|
|
||||||
if (err)
|
|
||||||
{
|
|
||||||
spdlog::info("reed_solomon_reconstruct failed");
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
std::optional<uint16_t> first_reconstructed;
|
|
||||||
for (size_t i = 0; i < data.size(); ++i)
|
|
||||||
{
|
|
||||||
if (not data[i])
|
|
||||||
{
|
|
||||||
xrt::drivers::wivrn::deserialization_packet d(data_raw[i]);
|
|
||||||
data[i] = d.deserialize<data_shard>();
|
|
||||||
if (not first_reconstructed)
|
|
||||||
first_reconstructed = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert(first_reconstructed);
|
|
||||||
spdlog::info("reed_solomon_reconstruct success frame {}, reconstructed {} (out of {} shards)",
|
|
||||||
data[0]->frame_idx,
|
|
||||||
*first_reconstructed,
|
|
||||||
data.size());
|
|
||||||
|
|
||||||
feedback.reconstructed = application::now();
|
|
||||||
return first_reconstructed;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void debug_why_not_sent(const shard_set & shards)
|
static void debug_why_not_sent(const shard_set & shards)
|
||||||
{
|
{
|
||||||
const auto & frame = shards.data;
|
const auto & frame = shards.data;
|
||||||
@@ -207,10 +88,7 @@ static void debug_why_not_sent(const shard_set & shards)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int frame_idx = -1;
|
int frame_idx = -1;
|
||||||
int expected_data = -1;
|
|
||||||
int expected_parity = -1;
|
|
||||||
size_t data = 0;
|
size_t data = 0;
|
||||||
size_t parity = 0;
|
|
||||||
for (const auto & shard: frame)
|
for (const auto & shard: frame)
|
||||||
{
|
{
|
||||||
if (shard)
|
if (shard)
|
||||||
@@ -219,18 +97,8 @@ static void debug_why_not_sent(const shard_set & shards)
|
|||||||
++data;
|
++data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const auto & shard: shards.parity)
|
|
||||||
{
|
|
||||||
if (shard)
|
|
||||||
{
|
|
||||||
frame_idx = shard->frame_idx;
|
|
||||||
expected_data = shard->data_shard_count;
|
|
||||||
expected_parity = shard->num_parity_elements;
|
|
||||||
++parity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
spdlog::info("frame {} was not sent with {}/{} data, {}/{} parity shards)", frame_idx, data, expected_data, parity, expected_parity);
|
spdlog::info("frame {} was not sent with {} data shards", frame_idx, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shard_accumulator::advance()
|
void shard_accumulator::advance()
|
||||||
@@ -239,8 +107,7 @@ void shard_accumulator::advance()
|
|||||||
next.reset(current.frame_index() + 1);
|
next.reset(current.frame_index() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Shard>
|
void shard_accumulator::push_shard(video_stream_data_shard&& shard)
|
||||||
void shard_accumulator::push_shard(Shard && shard)
|
|
||||||
{
|
{
|
||||||
assert(current.frame_index() + 1 == next.frame_index());
|
assert(current.frame_index() + 1 == next.frame_index());
|
||||||
|
|
||||||
@@ -251,7 +118,6 @@ void shard_accumulator::push_shard(Shard && shard)
|
|||||||
}
|
}
|
||||||
else if (frame_diff == 0)
|
else if (frame_diff == 0)
|
||||||
{
|
{
|
||||||
// Due to error correction, inserting a shard might create a valid one before
|
|
||||||
auto shard_idx = current.insert(std::move(shard));
|
auto shard_idx = current.insert(std::move(shard));
|
||||||
try_submit_frame(shard_idx);
|
try_submit_frame(shard_idx);
|
||||||
}
|
}
|
||||||
@@ -290,9 +156,6 @@ void shard_accumulator::push_shard(Shard && shard)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template void shard_accumulator::push_shard<parity_shard>(parity_shard && shard);
|
|
||||||
template void shard_accumulator::push_shard<video_stream_data_shard>(video_stream_data_shard && shard);
|
|
||||||
|
|
||||||
void shard_accumulator::try_submit_frame(std::optional<uint16_t> shard_idx)
|
void shard_accumulator::try_submit_frame(std::optional<uint16_t> shard_idx)
|
||||||
{
|
{
|
||||||
if (shard_idx)
|
if (shard_idx)
|
||||||
|
|||||||
@@ -30,9 +30,6 @@ using decoder_impl = ::ffmpeg::decoder;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wivrn_packets.h"
|
#include "wivrn_packets.h"
|
||||||
#include <array>
|
|
||||||
#include <atomic>
|
|
||||||
#include <mutex>
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -42,21 +39,15 @@ class shard_accumulator
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
using data_shard = xrt::drivers::wivrn::to_headset::video_stream_data_shard;
|
using data_shard = xrt::drivers::wivrn::to_headset::video_stream_data_shard;
|
||||||
using parity_shard = xrt::drivers::wivrn::to_headset::video_stream_parity_shard;
|
|
||||||
struct shard_set
|
struct shard_set
|
||||||
{
|
{
|
||||||
size_t num_shards = 0;
|
size_t num_shards = 0;
|
||||||
size_t min_for_reconstruction = -1;
|
size_t min_for_reconstruction = -1;
|
||||||
std::vector<std::optional<data_shard>> data;
|
std::vector<std::optional<data_shard>> data;
|
||||||
std::vector<std::optional<parity_shard>> parity;
|
|
||||||
void reset(uint64_t frame_index);
|
void reset(uint64_t frame_index);
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
|
|
||||||
uint16_t insert(data_shard &&);
|
uint16_t insert(data_shard &&);
|
||||||
std::optional<uint16_t> insert(parity_shard &&);
|
|
||||||
|
|
||||||
parity_shard & get_parity();
|
|
||||||
std::optional<uint16_t> try_reconstruct();
|
|
||||||
|
|
||||||
xrt::drivers::wivrn::from_headset::feedback feedback{};
|
xrt::drivers::wivrn::from_headset::feedback feedback{};
|
||||||
|
|
||||||
@@ -93,8 +84,7 @@ public:
|
|||||||
next.reset(1);
|
next.reset(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Shard>
|
void push_shard(xrt::drivers::wivrn::to_headset::video_stream_data_shard&&);
|
||||||
void push_shard(Shard &&);
|
|
||||||
|
|
||||||
auto & desc() const
|
auto & desc() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -543,17 +543,13 @@ void scenes::stream::video()
|
|||||||
{
|
{
|
||||||
auto shard = shard_queue.pop();
|
auto shard = shard_queue.pop();
|
||||||
|
|
||||||
std::visit(
|
if (shard.stream_item_idx >= decoders.size())
|
||||||
[this](auto & shard) {
|
{
|
||||||
if (shard.stream_item_idx >= decoders.size())
|
// We don't know (yet?) about this stream, ignore packet
|
||||||
{
|
return;
|
||||||
// We don't know (yet?) about this stream, ignore packet
|
}
|
||||||
return;
|
auto idx = shard.stream_item_idx;
|
||||||
}
|
decoders[idx].decoder->push_shard(std::move(shard));
|
||||||
auto idx = shard.stream_item_idx;
|
|
||||||
decoders[idx].decoder->push_shard(std::move(shard));
|
|
||||||
},
|
|
||||||
shard);
|
|
||||||
}
|
}
|
||||||
catch (utils::sync_queue_closed &)
|
catch (utils::sync_queue_closed &)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class stream : public scene, public std::enable_shared_from_this<stream>
|
|||||||
std::optional<std::thread> tracking_thread;
|
std::optional<std::thread> tracking_thread;
|
||||||
std::thread video_thread;
|
std::thread video_thread;
|
||||||
|
|
||||||
utils::sync_queue<std::variant<to_headset::video_stream_data_shard, to_headset::video_stream_parity_shard>> shard_queue;
|
utils::sync_queue<to_headset::video_stream_data_shard> shard_queue;
|
||||||
|
|
||||||
std::mutex decoder_mutex;
|
std::mutex decoder_mutex;
|
||||||
std::vector<accumulator_images> decoders; // Locked by decoder_mutex
|
std::vector<accumulator_images> decoders; // Locked by decoder_mutex
|
||||||
@@ -102,7 +102,6 @@ public:
|
|||||||
|
|
||||||
void operator()(to_headset::handshake&&) {};
|
void operator()(to_headset::handshake&&) {};
|
||||||
void operator()(to_headset::video_stream_data_shard &&);
|
void operator()(to_headset::video_stream_data_shard &&);
|
||||||
void operator()(to_headset::video_stream_parity_shard &&);
|
|
||||||
void operator()(to_headset::haptics &&);
|
void operator()(to_headset::haptics &&);
|
||||||
void operator()(to_headset::timesync_query &&);
|
void operator()(to_headset::timesync_query &&);
|
||||||
void operator()(to_headset::audio_stream_description &&);
|
void operator()(to_headset::audio_stream_description &&);
|
||||||
|
|||||||
@@ -43,12 +43,6 @@ void scenes::stream::operator()(to_headset::video_stream_data_shard && shard)
|
|||||||
shard_queue.push(std::move(shard));
|
shard_queue.push(std::move(shard));
|
||||||
}
|
}
|
||||||
|
|
||||||
void scenes::stream::operator()(to_headset::video_stream_parity_shard && shard)
|
|
||||||
{
|
|
||||||
video_started_ = true;
|
|
||||||
shard_queue.push(std::move(shard));
|
|
||||||
}
|
|
||||||
|
|
||||||
void scenes::stream::operator()(to_headset::audio_stream_description && desc)
|
void scenes::stream::operator()(to_headset::audio_stream_description && desc)
|
||||||
{
|
{
|
||||||
audio_handle.emplace(desc, *network_session, instance);
|
audio_handle.emplace(desc, *network_session, instance);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace vk::details
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
struct structure_traits_base
|
struct structure_traits_base
|
||||||
{
|
{
|
||||||
static constexpr inline VkStructureType type = static_cast<VkStructureType>(-1);
|
static constexpr inline VkStructureType type = VK_STRUCTURE_TYPE_MAX_ENUM;
|
||||||
using base = T;
|
using base = T;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ auto enumerate(F f, Args &&... args) -> auto
|
|||||||
|
|
||||||
if (result >= 0)
|
if (result >= 0)
|
||||||
{
|
{
|
||||||
if constexpr (structure_type<T> == static_cast<VkStructureType>(-1))
|
if constexpr (structure_type<T> == VK_STRUCTURE_TYPE_MAX_ENUM)
|
||||||
{
|
{
|
||||||
array.resize(count);
|
array.resize(count);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-14
@@ -19,10 +19,7 @@
|
|||||||
|
|
||||||
#include "wivrn_client.h"
|
#include "wivrn_client.h"
|
||||||
#include "spdlog/common.h"
|
#include "spdlog/common.h"
|
||||||
#include "version.h"
|
|
||||||
#include "wivrn_packets.h"
|
#include "wivrn_packets.h"
|
||||||
#include "wivrn_serialization.h"
|
|
||||||
#include <algorithm>
|
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#include <linux/ipv6.h>
|
#include <linux/ipv6.h>
|
||||||
@@ -60,7 +57,7 @@ void wivrn_session::handshake()
|
|||||||
if (std::holds_alternative<to_headset::handshake>(*packet))
|
if (std::holds_alternative<to_headset::handshake>(*packet))
|
||||||
{
|
{
|
||||||
// If this packet is lost, a tracking packet will do the job to establish the connection
|
// If this packet is lost, a tracking packet will do the job to establish the connection
|
||||||
send_stream(from_headset::stream_packets(from_headset::handshake{}));
|
send_stream(from_headset::handshake{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,13 +134,3 @@ wivrn_session::wivrn_session(in_addr address, int port) :
|
|||||||
//
|
//
|
||||||
// return {};
|
// return {};
|
||||||
// }
|
// }
|
||||||
|
|
||||||
void wivrn_session::send_control(const from_headset::control_packets & packet)
|
|
||||||
{
|
|
||||||
control.send(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wivrn_session::send_stream(const from_headset::stream_packets & packet)
|
|
||||||
{
|
|
||||||
stream.send(packet);
|
|
||||||
}
|
|
||||||
|
|||||||
+10
-3
@@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
#include "wivrn_packets.h"
|
#include "wivrn_packets.h"
|
||||||
#include "wivrn_sockets.h"
|
#include "wivrn_sockets.h"
|
||||||
#include <memory>
|
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
|
||||||
using namespace xrt::drivers::wivrn;
|
using namespace xrt::drivers::wivrn;
|
||||||
@@ -41,8 +40,16 @@ public:
|
|||||||
wivrn_session(const wivrn_session &) = delete;
|
wivrn_session(const wivrn_session &) = delete;
|
||||||
wivrn_session & operator=(const wivrn_session &) = delete;
|
wivrn_session & operator=(const wivrn_session &) = delete;
|
||||||
|
|
||||||
void send_control(const from_headset::control_packets & packet);
|
template <typename T>
|
||||||
void send_stream(const from_headset::stream_packets & packet);
|
void send_control(T && packet)
|
||||||
|
{
|
||||||
|
control.send(std::forward<T>(packet));
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
void send_stream(T && packet)
|
||||||
|
{
|
||||||
|
stream.send(std::forward<T>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
int poll(T && visitor, std::chrono::milliseconds timeout)
|
int poll(T && visitor, std::chrono::milliseconds timeout)
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ if (USE_SYSTEM_FREETYPE)
|
|||||||
target_link_libraries(FreetypeHarfbuzz INTERFACE Freetype::Freetype harfbuzz::harfbuzz)
|
target_link_libraries(FreetypeHarfbuzz INTERFACE Freetype::Freetype harfbuzz::harfbuzz)
|
||||||
|
|
||||||
else()
|
else()
|
||||||
set(HARFBUZZ_VERSION 5.3.1)
|
set(HARFBUZZ_VERSION 8.3.0)
|
||||||
set(FREETYPE_VERSION 2.12.1)
|
set(FREETYPE_VERSION 2.13.2)
|
||||||
|
|
||||||
if(NOT EXISTS ${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}.tar.xz)
|
if(NOT EXISTS ${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}.tar.xz)
|
||||||
if (EXISTS ${CMAKE_SOURCE_DIR}/freetype-${FREETYPE_VERSION}.tar.xz)
|
if (EXISTS ${CMAKE_SOURCE_DIR}/freetype-${FREETYPE_VERSION}.tar.xz)
|
||||||
file(CREATE_LINK ${CMAKE_SOURCE_DIR}/freetype-${FREETYPE_VERSION}.tar.xz ${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}.tar.xz SYMBOLIC)
|
file(CREATE_LINK ${CMAKE_SOURCE_DIR}/freetype-${FREETYPE_VERSION}.tar.xz ${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}.tar.xz SYMBOLIC)
|
||||||
else()
|
else()
|
||||||
file(DOWNLOAD https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VERSION}.tar.xz ${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}.tar.xz
|
file(DOWNLOAD https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VERSION}.tar.xz ${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}.tar.xz
|
||||||
EXPECTED_HASH SHA256=4766f20157cc4cf0cd292f80bf917f92d1c439b243ac3018debf6b9140c41a7f)
|
EXPECTED_HASH SHA256=12991c4e55c506dd7f9b765933e62fd2be2e06d421505d7950a132e4f1bb484d)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ else()
|
|||||||
file(CREATE_LINK ${CMAKE_SOURCE_DIR}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz ${CMAKE_BINARY_DIR}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz SYMBOLIC)
|
file(CREATE_LINK ${CMAKE_SOURCE_DIR}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz ${CMAKE_BINARY_DIR}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz SYMBOLIC)
|
||||||
else()
|
else()
|
||||||
file(DOWNLOAD https://github.com/harfbuzz/harfbuzz/releases/download/${HARFBUZZ_VERSION}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz ${CMAKE_BINARY_DIR}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz
|
file(DOWNLOAD https://github.com/harfbuzz/harfbuzz/releases/download/${HARFBUZZ_VERSION}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz ${CMAKE_BINARY_DIR}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz
|
||||||
EXPECTED_HASH SHA256=4a6ce097b75a8121facc4ba83b5b083bfec657f45b003cd5a3424f2ae6b4434d)
|
EXPECTED_HASH SHA256=109501eaeb8bde3eadb25fab4164e993fbace29c3d775bcaa1c1e58e2f15f847)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
+5
-60
@@ -29,12 +29,11 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <openxr/openxr.h>
|
#include <openxr/openxr.h>
|
||||||
|
|
||||||
|
#include "wivrn_serialization_types.h"
|
||||||
|
|
||||||
namespace xrt::drivers::wivrn
|
namespace xrt::drivers::wivrn
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T, typename Enable>
|
|
||||||
struct serialization_traits;
|
|
||||||
|
|
||||||
// Default port for server to listen, both TCP and UDP
|
// Default port for server to listen, both TCP and UDP
|
||||||
static const int default_port = 9757;
|
static const int default_port = 9757;
|
||||||
|
|
||||||
@@ -180,9 +179,7 @@ struct feedback
|
|||||||
std::array<XrPosef, 2> real_pose;
|
std::array<XrPosef, 2> real_pose;
|
||||||
|
|
||||||
uint8_t data_packets;
|
uint8_t data_packets;
|
||||||
uint8_t parity_packets;
|
|
||||||
uint8_t received_data_packets;
|
uint8_t received_data_packets;
|
||||||
uint8_t received_parity_packets;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
using control_packets = std::variant<headset_info_packet, feedback, audio_data>;
|
using control_packets = std::variant<headset_info_packet, feedback, audio_data>;
|
||||||
@@ -270,22 +267,11 @@ public:
|
|||||||
std::array<XrFovf, 2> fov;
|
std::array<XrFovf, 2> fov;
|
||||||
};
|
};
|
||||||
std::optional<view_info_t> view_info;
|
std::optional<view_info_t> view_info;
|
||||||
|
|
||||||
// Container for the data, read payload instead
|
|
||||||
std::vector<uint8_t> data;
|
|
||||||
// Actual video data, may contain multiple NAL units
|
// Actual video data, may contain multiple NAL units
|
||||||
std::span<uint8_t> payload;
|
std::span<uint8_t> payload;
|
||||||
};
|
|
||||||
|
|
||||||
struct video_stream_parity_shard
|
// Container for the data, read payload instead
|
||||||
{
|
data_holder data;
|
||||||
uint8_t stream_item_idx;
|
|
||||||
uint64_t frame_idx;
|
|
||||||
uint16_t data_shard_count;
|
|
||||||
uint8_t num_parity_elements;
|
|
||||||
uint8_t parity_element;
|
|
||||||
// Parity data
|
|
||||||
std::vector<uint8_t> payload;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct haptics
|
struct haptics
|
||||||
@@ -302,49 +288,8 @@ struct timesync_query
|
|||||||
};
|
};
|
||||||
|
|
||||||
using control_packets = std::variant<handshake, audio_stream_description, video_stream_description, audio_data>;
|
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 stream_packets = std::variant<video_stream_data_shard, haptics, timesync_query>;
|
||||||
|
|
||||||
} // namespace to_headset
|
} // namespace to_headset
|
||||||
|
|
||||||
template <>
|
|
||||||
struct serialization_traits<to_headset::video_stream_data_shard, void>
|
|
||||||
{
|
|
||||||
template <typename T>
|
|
||||||
static constexpr void type_hash(T & h)
|
|
||||||
{
|
|
||||||
h.feed("video_v0");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static void serialize(const to_headset::video_stream_data_shard & shard, T & packet)
|
|
||||||
{
|
|
||||||
packet.reserve(to_headset::video_stream_data_shard::max_payload_size + 20);
|
|
||||||
packet.serialize(shard.stream_item_idx);
|
|
||||||
packet.serialize(shard.frame_idx);
|
|
||||||
packet.serialize(shard.shard_idx);
|
|
||||||
packet.serialize(shard.flags);
|
|
||||||
packet.serialize(shard.view_info);
|
|
||||||
uint16_t size = shard.payload.size();
|
|
||||||
packet.serialize(size);
|
|
||||||
packet.write(shard.payload.data(), shard.payload.size_bytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static to_headset::video_stream_data_shard deserialize(T & packet)
|
|
||||||
{
|
|
||||||
to_headset::video_stream_data_shard shard;
|
|
||||||
packet.deserialize(shard.stream_item_idx);
|
|
||||||
packet.deserialize(shard.frame_idx);
|
|
||||||
packet.deserialize(shard.shard_idx);
|
|
||||||
packet.deserialize(shard.flags);
|
|
||||||
packet.deserialize(shard.view_info);
|
|
||||||
uint16_t size;
|
|
||||||
packet.deserialize(size);
|
|
||||||
size_t read_index;
|
|
||||||
std::tie(read_index, shard.data) = packet.steal_buffer();
|
|
||||||
shard.payload = std::span<uint8_t>(shard.data.data() + read_index, shard.data.size() - read_index);
|
|
||||||
return shard;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace xrt::drivers::wivrn
|
} // namespace xrt::drivers::wivrn
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <span>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@@ -35,6 +36,8 @@
|
|||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "wivrn_serialization_types.h"
|
||||||
|
|
||||||
namespace xrt::drivers::wivrn
|
namespace xrt::drivers::wivrn
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -99,12 +102,9 @@ class serialization_packet
|
|||||||
std::vector<uint8_t> buffer;
|
std::vector<uint8_t> buffer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
serialization_packet() = default;
|
std::span<uint8_t> span; // Will be sent at the end, untouched
|
||||||
|
|
||||||
void reserve(size_t n)
|
serialization_packet() = default;
|
||||||
{
|
|
||||||
buffer.reserve(n);
|
|
||||||
}
|
|
||||||
|
|
||||||
void write(const void * data, size_t size)
|
void write(const void * data, size_t size)
|
||||||
{
|
{
|
||||||
@@ -113,24 +113,17 @@ public:
|
|||||||
memcpy(&buffer[index], data, size);
|
memcpy(&buffer[index], data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t * data() const
|
|
||||||
{
|
|
||||||
return buffer.data();
|
|
||||||
}
|
|
||||||
size_t size() const
|
|
||||||
{
|
|
||||||
return buffer.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void serialize(const T & value)
|
void serialize(const T & value)
|
||||||
{
|
{
|
||||||
serialization_traits<T>::serialize(value, *this);
|
serialization_traits<T>::serialize(value, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
operator std::vector<uint8_t> &&() &&
|
operator std::vector<std::span<uint8_t>> ()
|
||||||
{
|
{
|
||||||
return std::move(buffer);
|
if (span.empty())
|
||||||
|
return {buffer};
|
||||||
|
return {buffer, span};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -154,6 +147,14 @@ public:
|
|||||||
read_index += size;
|
read_index += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::span<uint8_t> read_span(size_t size)
|
||||||
|
{
|
||||||
|
check_remaining_size(size);
|
||||||
|
std::span<uint8_t> res(&buffer[read_index], size);
|
||||||
|
read_index += size;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
size_t remaining() const
|
size_t remaining() const
|
||||||
{
|
{
|
||||||
return buffer.size() - read_index;
|
return buffer.size() - read_index;
|
||||||
@@ -455,7 +456,7 @@ struct serialization_traits<std::variant<T...>>
|
|||||||
|
|
||||||
static void serialize(const std::variant<T...> & value, serialization_packet & packet)
|
static void serialize(const std::variant<T...> & value, serialization_packet & packet)
|
||||||
{
|
{
|
||||||
packet.serialize<uint32_t>(value.index());
|
packet.serialize<uint8_t>(value.index());
|
||||||
std::visit([&](const auto & x) { packet.serialize(x); }, value);
|
std::visit([&](const auto & x) { packet.serialize(x); }, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,7 +473,7 @@ struct serialization_traits<std::variant<T...>>
|
|||||||
|
|
||||||
static std::variant<T...> deserialize(deserialization_packet & packet)
|
static std::variant<T...> deserialize(deserialization_packet & packet)
|
||||||
{
|
{
|
||||||
uint32_t type_index = packet.deserialize<uint32_t>();
|
uint8_t type_index = packet.deserialize<uint8_t>();
|
||||||
if (type_index >= sizeof...(T))
|
if (type_index >= sizeof...(T))
|
||||||
throw deserialization_error();
|
throw deserialization_error();
|
||||||
|
|
||||||
@@ -506,6 +507,48 @@ struct serialization_traits<std::chrono::duration<Rep, Period>>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct serialization_traits<std::span<uint8_t>>
|
||||||
|
{
|
||||||
|
static constexpr void type_hash(details::hash_context & h)
|
||||||
|
{
|
||||||
|
h.feed("span<uint8_t>");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void serialize(const std::span<uint8_t>& value, serialization_packet & packet)
|
||||||
|
{
|
||||||
|
packet.serialize<uint16_t>(value.size());
|
||||||
|
//FIXME: nocopy
|
||||||
|
packet.write(value.data(), value.size_bytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::span<uint8_t> deserialize(deserialization_packet & packet)
|
||||||
|
{
|
||||||
|
size_t size = packet.deserialize<uint16_t>();
|
||||||
|
return packet.read_span(size);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct serialization_traits<data_holder>
|
||||||
|
{
|
||||||
|
static constexpr void type_hash(details::hash_context & h)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static void serialize(const data_holder&, serialization_packet &)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
static data_holder deserialize(deserialization_packet & packet)
|
||||||
|
{
|
||||||
|
data_holder value;
|
||||||
|
size_t size;
|
||||||
|
std::tie(size, value.c) = packet.steal_buffer();
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
namespace unit_tests
|
namespace unit_tests
|
||||||
{
|
{
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* WiVRn VR streaming
|
||||||
|
* Copyright (C) 2023 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||||
|
* Copyright (C) 2023 Patrick Nicolas <patricknicolas@laposte.net>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace xrt::drivers::wivrn
|
||||||
|
{
|
||||||
|
|
||||||
|
// Intended to be the last element of a serializable type
|
||||||
|
// contains the data referenced by spans
|
||||||
|
struct data_holder
|
||||||
|
{
|
||||||
|
data_holder() = default;
|
||||||
|
data_holder(const data_holder&) = delete;
|
||||||
|
data_holder(data_holder&&) = default;
|
||||||
|
data_holder& operator=(const data_holder&) = delete;
|
||||||
|
data_holder& operator=(data_holder&&) = default;
|
||||||
|
|
||||||
|
std::vector<uint8_t> c;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@@ -282,6 +283,16 @@ void xrt::drivers::wivrn::UDP::send_raw(const std::vector<uint8_t> & data)
|
|||||||
throw std::system_error{errno, std::generic_category()};
|
throw std::system_error{errno, std::generic_category()};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void xrt::drivers::wivrn::UDP::send_raw(const std::vector<std::span<uint8_t>> & data)
|
||||||
|
{
|
||||||
|
std::vector<iovec> spans;
|
||||||
|
for (const auto& span: data)
|
||||||
|
spans.emplace_back((void*)span.data(), span.size());
|
||||||
|
|
||||||
|
if (::writev(fd, spans.data(), spans.size()) < 0)
|
||||||
|
throw std::system_error{errno, std::generic_category()};
|
||||||
|
}
|
||||||
|
|
||||||
xrt::drivers::wivrn::deserialization_packet xrt::drivers::wivrn::TCP::receive_raw()
|
xrt::drivers::wivrn::deserialization_packet xrt::drivers::wivrn::TCP::receive_raw()
|
||||||
{
|
{
|
||||||
size_t expected_size;
|
size_t expected_size;
|
||||||
@@ -323,10 +334,12 @@ xrt::drivers::wivrn::deserialization_packet xrt::drivers::wivrn::TCP::receive_ra
|
|||||||
return deserialization_packet{std::move(new_buffer), 4};
|
return deserialization_packet{std::move(new_buffer), 4};
|
||||||
}
|
}
|
||||||
|
|
||||||
void xrt::drivers::wivrn::TCP::send_raw(const std::vector<uint8_t> & data)
|
void xrt::drivers::wivrn::TCP::send_raw(const std::vector<std::span<uint8_t>> & spans)
|
||||||
{
|
{
|
||||||
std::lock_guard lock(*mutex);
|
std::lock_guard lock(*mutex);
|
||||||
|
|
||||||
|
assert(spans.size() == 1);
|
||||||
|
const auto& data = spans[0];
|
||||||
uint32_t size = data.size();
|
uint32_t size = data.size();
|
||||||
ssize_t sent = ::send(fd, &size, sizeof(size), MSG_NOSIGNAL);
|
ssize_t sent = ::send(fd, &size, sizeof(size), MSG_NOSIGNAL);
|
||||||
|
|
||||||
|
|||||||
+29
-7
@@ -26,6 +26,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <netinet/ip.h>
|
#include <netinet/ip.h>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <span>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -90,6 +91,7 @@ public:
|
|||||||
deserialization_packet receive_raw();
|
deserialization_packet receive_raw();
|
||||||
std::pair<xrt::drivers::wivrn::deserialization_packet, sockaddr_in6> receive_from_raw();
|
std::pair<xrt::drivers::wivrn::deserialization_packet, sockaddr_in6> receive_from_raw();
|
||||||
void send_raw(const std::vector<uint8_t> & data);
|
void send_raw(const std::vector<uint8_t> & data);
|
||||||
|
void send_raw(const std::vector<std::span<uint8_t>> & data);
|
||||||
|
|
||||||
void connect(in6_addr address, int port);
|
void connect(in6_addr address, int port);
|
||||||
void connect(in_addr address, int port);
|
void connect(in_addr address, int port);
|
||||||
@@ -114,7 +116,7 @@ public:
|
|||||||
explicit TCP(int fd);
|
explicit TCP(int fd);
|
||||||
|
|
||||||
deserialization_packet receive_raw();
|
deserialization_packet receive_raw();
|
||||||
void send_raw(const std::vector<uint8_t> & data);
|
void send_raw(const std::vector<std::span<uint8_t>> & data);
|
||||||
};
|
};
|
||||||
|
|
||||||
class TCPListener : public fd_base
|
class TCPListener : public fd_base
|
||||||
@@ -137,9 +139,27 @@ public:
|
|||||||
return {T{fd2}, addr};
|
return {T{fd2}, addr};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Socket, typename ReceivedType, typename SentType>
|
template <typename Socket, typename ReceivedType, typename SentType>
|
||||||
class typed_socket : public Socket
|
class typed_socket;
|
||||||
|
|
||||||
|
namespace details
|
||||||
|
{
|
||||||
|
template <class T, class Tuple>
|
||||||
|
struct Index;
|
||||||
|
|
||||||
|
template <class T, class... Types>
|
||||||
|
struct Index<T, std::tuple<T, Types...>> {
|
||||||
|
static const std::size_t value = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class T, class U, class... Types>
|
||||||
|
struct Index<T, std::tuple<U, Types...>> {
|
||||||
|
static const std::size_t value = 1 + Index<T, std::tuple<Types...>>::value;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Socket, typename ReceivedType, typename ...VariantTypes>
|
||||||
|
class typed_socket<Socket, ReceivedType, std::variant<VariantTypes...>> : public Socket
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
@@ -156,12 +176,14 @@ public:
|
|||||||
return packet.deserialize<ReceivedType>();
|
return packet.deserialize<ReceivedType>();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T = SentType, typename = std::enable_if_t<std::is_same_v<T, SentType>>>
|
template <typename T>
|
||||||
void send(const T & data)
|
void send(T && data)
|
||||||
{
|
{
|
||||||
serialization_packet p;
|
serialization_packet p;
|
||||||
p.serialize(data);
|
uint8_t index = details::Index<std::decay_t<T>, std::tuple<VariantTypes...>>::value;
|
||||||
this->send_raw(std::move(p));
|
p.serialize(index);
|
||||||
|
p.serialize(std::forward<T>(data));
|
||||||
|
this->send_raw(p);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Vendored
+606
-521
File diff suppressed because it is too large
Load Diff
@@ -112,10 +112,11 @@ void VideoEncoder::Encode(wivrn_session & cnx,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoEncoder::SendData(std::vector<uint8_t> && data)
|
void VideoEncoder::SendData(std::vector<uint8_t> && data_)
|
||||||
{
|
{
|
||||||
auto & max_payload_size = to_headset::video_stream_data_shard::max_payload_size;
|
auto & max_payload_size = to_headset::video_stream_data_shard::max_payload_size;
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
|
data = std::move(data_);
|
||||||
#if 0
|
#if 0
|
||||||
std::ofstream debug("/tmp/video_dump-" + std::to_string(stream_idx), std::ios::app);
|
std::ofstream debug("/tmp/video_dump-" + std::to_string(stream_idx), std::ios::app);
|
||||||
debug.write((char*)data.data(), data.size());
|
debug.write((char*)data.data(), data.size());
|
||||||
@@ -138,7 +139,6 @@ void VideoEncoder::SendData(std::vector<uint8_t> && data)
|
|||||||
begin = next;
|
begin = next;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
}
|
}
|
||||||
shard.data = std::move(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void VideoEncoder::PushShard(const std::span<uint8_t> & payload, uint8_t flags)
|
void VideoEncoder::PushShard(const std::span<uint8_t> & payload, uint8_t flags)
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ private:
|
|||||||
|
|
||||||
// shard waiting to be sent
|
// shard waiting to be sent
|
||||||
to_headset::video_stream_data_shard shard;
|
to_headset::video_stream_data_shard shard;
|
||||||
|
// and its data
|
||||||
|
std::vector<uint8_t> data;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<VideoEncoder> Create(vk_bundle * vk,
|
static std::unique_ptr<VideoEncoder> Create(vk_bundle * vk,
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ wivrn_connection::wivrn_connection(TCP && tcp) :
|
|||||||
|
|
||||||
stream.bind(port);
|
stream.bind(port);
|
||||||
|
|
||||||
control.send(to_headset::control_packets(to_headset::handshake{}));
|
control.send(to_headset::handshake{});
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@@ -98,16 +98,6 @@ wivrn_connection::wivrn_connection(TCP && tcp) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wivrn_connection::send_control(const to_headset::control_packets & packet)
|
|
||||||
{
|
|
||||||
control.send(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wivrn_connection::send_stream(const to_headset::stream_packets & packet)
|
|
||||||
{
|
|
||||||
stream.send(packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::optional<from_headset::control_packets> wivrn_connection::poll_control(int timeout)
|
std::optional<from_headset::control_packets> wivrn_connection::poll_control(int timeout)
|
||||||
{
|
{
|
||||||
pollfd fds{};
|
pollfd fds{};
|
||||||
|
|||||||
@@ -36,8 +36,16 @@ public:
|
|||||||
wivrn_connection(const wivrn_connection &) = delete;
|
wivrn_connection(const wivrn_connection &) = delete;
|
||||||
wivrn_connection & operator=(const wivrn_connection &) = delete;
|
wivrn_connection & operator=(const wivrn_connection &) = delete;
|
||||||
|
|
||||||
void send_control(const to_headset::control_packets & packet);
|
template <typename T>
|
||||||
void send_stream(const to_headset::stream_packets & packet);
|
void send_control(T && packet)
|
||||||
|
{
|
||||||
|
control.send(std::forward<T>(packet));
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
void send_stream(T && packet)
|
||||||
|
{
|
||||||
|
stream.send(std::forward<T>(packet));
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<from_headset::control_packets> poll_control(int timeout);
|
std::optional<from_headset::control_packets> poll_control(int timeout);
|
||||||
|
|
||||||
|
|||||||
@@ -82,15 +82,15 @@ public:
|
|||||||
void operator()(audio_data &&);
|
void operator()(audio_data &&);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void send_stream(const T & packet)
|
void send_stream(T && packet)
|
||||||
{
|
{
|
||||||
connection.send_stream(packet);
|
connection.send_stream(std::forward<T>(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void send_control(const T & packet)
|
void send_control(T && packet)
|
||||||
{
|
{
|
||||||
connection.send_control(packet);
|
connection.send_control(std::forward<T>(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<to_headset::video_stream_description::foveation_parameter, 2> get_foveation_parameters();
|
std::array<to_headset::video_stream_description::foveation_parameter, 2> get_foveation_parameters();
|
||||||
|
|||||||
Reference in New Issue
Block a user