diff --git a/client/decoder/android/android_decoder.cpp b/client/decoder/android/android_decoder.cpp index f276c348..fe213739 100644 --- a/client/decoder/android/android_decoder.cpp +++ b/client/decoder/android/android_decoder.cpp @@ -106,9 +106,8 @@ decoder::decoder( const wivrn::to_headset::video_stream_description::item & description, float fps, uint8_t stream_index, - std::weak_ptr weak_scene, - shard_accumulator * accumulator) : - wivrn::decoder(description), stream_index(stream_index), fps(fps), device(device), weak_scene(weak_scene), accumulator(accumulator) + std::weak_ptr weak_scene) : + wivrn::decoder(description), stream_index(stream_index), fps(fps), device(device), weak_scene(weak_scene) { spdlog::info("hbm_mutex.native_handle() = {}", (void *)hbm_mutex.native_handle()); @@ -314,7 +313,7 @@ void decoder::on_image_available(AImageReader * reader) std::move(image)); if (auto scene = weak_scene.lock()) - scene->push_blit_handle(accumulator, std::move(handle)); + scene->push_blit_handle(std::move(handle)); } catch (...) { diff --git a/client/decoder/android/android_decoder.h b/client/decoder/android/android_decoder.h index 3cfa3cb4..8d89c423 100644 --- a/client/decoder/android/android_decoder.h +++ b/client/decoder/android/android_decoder.h @@ -48,11 +48,6 @@ DEUGLIFY(AImage) DEUGLIFY(AImageReader) DEUGLIFY(AMediaCodec) -namespace wivrn -{ -class shard_accumulator; -} - namespace scenes { class stream; @@ -80,7 +75,6 @@ private: AMediaCodec_ptr media_codec; std::weak_ptr weak_scene; - shard_accumulator * accumulator; PFN_vkGetAndroidHardwareBufferPropertiesANDROID vkGetAndroidHardwareBufferPropertiesANDROID; @@ -125,8 +119,7 @@ public: const wivrn::to_headset::video_stream_description::item & description, float fps, uint8_t stream_index, - std::weak_ptr scene, - shard_accumulator * accumulator); + std::weak_ptr scene); ~decoder(); void push_data(std::span> data, uint64_t frame_index, bool partial) override; diff --git a/client/decoder/decoder.cpp b/client/decoder/decoder.cpp index d92f657f..6c566541 100644 --- a/client/decoder/decoder.cpp +++ b/client/decoder/decoder.cpp @@ -34,8 +34,7 @@ std::shared_ptr wivrn::decoder::make( const wivrn::to_headset::video_stream_description::item & description, float fps, uint8_t stream_index, - std::weak_ptr scene, - shard_accumulator * acc) + std::weak_ptr scene) { switch (description.codec) { @@ -49,16 +48,14 @@ std::shared_ptr wivrn::decoder::make( description, fps, stream_index, - scene, - acc); + scene); #else return std::make_shared( device, phys_dev, description, stream_index, - scene, - acc); + scene); #endif case raw: return std::make_shared( @@ -67,8 +64,7 @@ std::shared_ptr wivrn::decoder::make( vk_queue_family_index, description, stream_index, - scene, - acc); + scene); } __builtin_unreachable(); } diff --git a/client/decoder/decoder.h b/client/decoder/decoder.h index da927082..30c0c917 100644 --- a/client/decoder/decoder.h +++ b/client/decoder/decoder.h @@ -32,7 +32,6 @@ class stream; namespace wivrn { -class shard_accumulator; class decoder { public: @@ -62,8 +61,7 @@ public: const wivrn::to_headset::video_stream_description::item & description, float fps, uint8_t stream_index, - std::weak_ptr, - shard_accumulator *); + std::weak_ptr); virtual ~decoder(); virtual void push_data(std::span> data, uint64_t frame_index, bool partial) = 0; diff --git a/client/decoder/ffmpeg/ffmpeg_decoder.cpp b/client/decoder/ffmpeg/ffmpeg_decoder.cpp index 1fddf3f6..e690f06c 100644 --- a/client/decoder/ffmpeg/ffmpeg_decoder.cpp +++ b/client/decoder/ffmpeg/ffmpeg_decoder.cpp @@ -102,14 +102,12 @@ decoder::decoder( vk::raii::PhysicalDevice & physical_device, const wivrn::to_headset::video_stream_description::item & description, uint8_t stream_index, - std::weak_ptr scene, - shard_accumulator * accumulator) : + std::weak_ptr scene) : wivrn::decoder(description), device(device), codec(nullptr, free_codec_context), sws(nullptr, sws_freeContext), - weak_scene(scene), - accumulator(accumulator) + weak_scene(scene) { free_images.resize(image_count); @@ -264,7 +262,7 @@ void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, co this); if (auto scene = weak_scene.lock()) - scene->push_blit_handle(accumulator, std::move(handle)); + scene->push_blit_handle(std::move(handle)); } void decoder::supported_codecs(std::vector & res) diff --git a/client/decoder/ffmpeg/ffmpeg_decoder.h b/client/decoder/ffmpeg/ffmpeg_decoder.h index 9bc121d5..3061cc22 100644 --- a/client/decoder/ffmpeg/ffmpeg_decoder.h +++ b/client/decoder/ffmpeg/ffmpeg_decoder.h @@ -28,11 +28,6 @@ #include #include -namespace wivrn -{ -class shard_accumulator; -} - extern "C" { struct AVBufferRef; @@ -72,7 +67,6 @@ private: std::vector packet; uint64_t frame_index; std::weak_ptr weak_scene; - shard_accumulator * accumulator; std::mutex mutex; @@ -81,8 +75,7 @@ public: vk::raii::PhysicalDevice & physical_device, const wivrn::to_headset::video_stream_description::item & description, uint8_t stream_index, - std::weak_ptr scene, - shard_accumulator * accumulator); + std::weak_ptr scene); void push_data(std::span> data, uint64_t frame_index, bool partial) override; diff --git a/client/decoder/raw_decoder.cpp b/client/decoder/raw_decoder.cpp index 74c12596..77b81844 100644 --- a/client/decoder/raw_decoder.cpp +++ b/client/decoder/raw_decoder.cpp @@ -83,8 +83,7 @@ raw_decoder::raw_decoder( uint32_t vk_queue_family_index, const wivrn::to_headset::video_stream_description::item & description, uint8_t stream_index, - std::weak_ptr scene, - shard_accumulator * accumulator) : + std::weak_ptr scene) : decoder(description), device(device), ycbcr_conversion(device, @@ -105,8 +104,7 @@ raw_decoder::raw_decoder( })[0] .release()), fence(device, vk::FenceCreateInfo{.flags = vk::FenceCreateFlagBits::eSignaled}), - weak_scene(scene), - accumulator(accumulator) + weak_scene(scene) { extent_ = vk::Extent2D{ .width = description.width, @@ -330,7 +328,7 @@ void raw_decoder::frame_completed( *fence); if (auto scene = weak_scene.lock()) - scene->push_blit_handle(accumulator, std::move(handle)); + scene->push_blit_handle(std::move(handle)); std::swap(input[0], input[1]); input_pos = (uint8_t *)input[0].map(); diff --git a/client/decoder/raw_decoder.h b/client/decoder/raw_decoder.h index 01eb9269..5e696308 100644 --- a/client/decoder/raw_decoder.h +++ b/client/decoder/raw_decoder.h @@ -51,7 +51,6 @@ private: std::array image_pool; std::weak_ptr weak_scene; - shard_accumulator * accumulator; uint64_t current_frame = 0; std::array input; @@ -65,8 +64,7 @@ public: uint32_t vk_queue_family_index, const wivrn::to_headset::video_stream_description::item & description, uint8_t stream_index, - std::weak_ptr scene, - shard_accumulator * accumulator); + std::weak_ptr scene); void push_data(std::span> data, uint64_t frame_index, bool partial) override; diff --git a/client/decoder/shard_accumulator.h b/client/decoder/shard_accumulator.h index 6f099534..52ea854f 100644 --- a/client/decoder/shard_accumulator.h +++ b/client/decoder/shard_accumulator.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include namespace xr { @@ -77,15 +77,11 @@ private: public: explicit shard_accumulator( - vk::raii::Device & device, - vk::raii::PhysicalDevice & physical_device, + std::shared_ptr decoder_, xr::instance & instance, - uint32_t vk_queue_family_index, - const wivrn::to_headset::video_stream_description::item & description, - float fps, std::weak_ptr scene, uint8_t stream_index) : - decoder_(decoder::make(device, physical_device, vk_queue_family_index, description, fps, stream_index, scene, this)), + decoder_(std::move(decoder_)), current(stream_index), next(stream_index), weak_scene(scene), diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index 17144c9e..6b3f99be 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -524,7 +524,7 @@ scenes::stream::~stream() network_thread.join(); } -void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_ptr handle) +void scenes::stream::push_blit_handle(std::shared_ptr handle) { assert(handle); if (!application::is_visible()) @@ -536,8 +536,6 @@ void scenes::stream::push_blit_handle(shard_accumulator * decoder, std::shared_p auto stream = handle->feedback.stream_index; if (stream < decoders.size()) { - if (decoder != decoders[stream].decoder.get()) - return; handle->feedback.received_from_decoder = instance.now(); std::swap(handle, decoders[stream].latest_frames[handle->feedback.frame_index % decoders[stream].latest_frames.size()]); } @@ -1145,7 +1143,11 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript spdlog::info("Creating decoder size {}x{} offset {},{}", item.width, item.height, item.offset_x, item.offset_y); decoders.push_back(accumulator_images{ - .decoder = std::make_unique(device, physical_device, instance, queue_family_index, item, description.fps, shared_from_this(), stream_index), + .decoder = std::make_unique( + decoder::make(device, physical_device, queue_family_index, item, description.fps, stream_index, shared_from_this()), + instance, + shared_from_this(), + stream_index), }); } } diff --git a/client/scenes/stream.h b/client/scenes/stream.h index 143f1eef..0a3d6aca 100644 --- a/client/scenes/stream.h +++ b/client/scenes/stream.h @@ -213,7 +213,7 @@ public: void operator()(to_headset::running_applications &&); void operator()(audio_data &&); - void push_blit_handle(wivrn::shard_accumulator * decoder, std::shared_ptr handle); + void push_blit_handle(std::shared_ptr handle); void send_feedback(const wivrn::from_headset::feedback & feedback);