Drop "video" thread

Process all incoming packets in "network" thread.
This commit is contained in:
Patrick Nicolas
2024-05-20 16:47:52 +02:00
parent 0ce74f5e80
commit 061101f738
3 changed files with 12 additions and 50 deletions
+2 -43
View File
@@ -28,7 +28,6 @@
#include "spdlog/spdlog.h"
#include "utils/named_thread.h"
#include "utils/ranges.h"
#include "utils/sync_queue.h"
#include "vk/pipeline.h"
#include "vk/shader.h"
#include "wifi_lock.h"
@@ -78,7 +77,6 @@ static const std::array supported_formats =
std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_session> network_session)
{
std::shared_ptr<stream> self{new stream};
spdlog::info("decoder_mutex.native_handle() = {}", (void *)self->decoder_mutex.native_handle());
self->network_session = std::move(network_session);
from_headset::headset_info_packet info{};
@@ -126,8 +124,6 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
self->update_local_floor(self->instance.now());
self->network_thread = utils::named_thread("network_thread", &stream::process_packets, self.get());
self->video_thread = utils::named_thread("video_thread", &stream::video, self.get());
self->command_buffer = std::move(self->device.allocateCommandBuffers({
.commandPool = *self->commandpool,
.level = vk::CommandBufferLevel::ePrimary,
@@ -224,9 +220,6 @@ scenes::stream::~stream()
{
exit();
if (video_thread.joinable())
video_thread.join();
if (tracking_thread && tracking_thread->joinable())
tracking_thread->join();
@@ -242,7 +235,7 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p
return;
{
std::unique_lock lock(decoder_mutex);
std::shared_lock lock(decoder_mutex);
for (auto & i: decoders)
{
if (i.decoder.get() == decoder)
@@ -347,6 +340,7 @@ void scenes::stream::render(XrTime predicted_display_time, bool should_render)
if (exiting)
application::pop_scene();
std::shared_lock lock(decoder_mutex);
if (decoders.empty())
should_render = false;
@@ -531,7 +525,6 @@ void scenes::stream::render(XrTime predicted_display_time, bool should_render)
std::array<XrPosef, 2> pose{};
std::array<XrFovf, 2> fov{};
{
std::unique_lock lock(decoder_mutex);
// Search for frame with desired display time on all decoders
// If no such frame exists, use the latest frame for each decoder
auto common_frame = accumulator_images::common_frame(decoders, predicted_display_time);
@@ -727,14 +720,12 @@ void scenes::stream::render(XrTime predicted_display_time, bool should_render)
void scenes::stream::exit()
{
exiting = true;
shard_queue.close();
}
void scenes::stream::setup(const to_headset::video_stream_description & description)
{
std::unique_lock lock(decoder_mutex);
// FIXME: stop video thread
decoders.clear();
if (description.items.empty())
@@ -910,38 +901,6 @@ void scenes::stream::setup_reprojection_swapchain()
reprojector.emplace(device, physical_device, images, swapchain_images, extent, swapchains[0].format(), *video_stream_description);
}
void scenes::stream::video()
{
#ifdef __ANDROID__
application::instance().setup_jni();
#endif
while (not exiting)
{
try
{
auto shard = shard_queue.pop();
if (shard.stream_item_idx >= decoders.size())
{
// 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));
}
catch (utils::sync_queue_closed &)
{
break;
}
catch (std::exception & e)
{
spdlog::error("Exception in video thread: {}", e.what());
exit();
}
}
}
scene::meta & scenes::stream::get_meta_scene()
{
static meta m{
+2 -6
View File
@@ -24,10 +24,10 @@
#include "render/imgui_impl.h"
#include "scene.h"
#include "stream_reprojection.h"
#include "utils/sync_queue.h"
#include "wivrn_client.h"
#include "wivrn_packets.h"
#include <mutex>
#include <shared_mutex>
#include <thread>
#include <vulkan/vulkan_core.h>
@@ -79,11 +79,8 @@ private:
xr::space local_floor = nullptr;
std::atomic<std::chrono::nanoseconds::rep> tracking_prediction_offset;
std::optional<std::thread> tracking_thread;
std::thread video_thread;
utils::sync_queue<to_headset::video_stream_data_shard> shard_queue;
std::mutex decoder_mutex;
std::shared_mutex decoder_mutex;
std::optional<to_headset::video_stream_description> video_stream_description;
std::vector<accumulator_images> decoders; // Locked by decoder_mutex
vk::raii::DescriptorPool blit_descriptor_pool = nullptr;
@@ -157,7 +154,6 @@ public:
private:
void process_packets();
void tracking();
void video();
void read_actions();
void setup(const to_headset::video_stream_description &);
+8 -1
View File
@@ -44,7 +44,14 @@ void scenes::stream::process_packets()
void scenes::stream::operator()(to_headset::video_stream_data_shard && shard)
{
shard_queue.push(std::move(shard));
std::shared_lock lock(decoder_mutex);
if (shard.stream_item_idx >= decoders.size())
{
// 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));
}
void scenes::stream::operator()(to_headset::audio_stream_description && desc)