diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 1bb2e9c6..7dca9c2c 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -45,7 +45,7 @@ if(ANDROID) file(GLOB PLATFORM_SOURCE CONFIGURE_DEPENDS "android/*.cpp" "audio/android/*.cpp" - #"decoder/android/*.cpp" + "decoder/android/*.cpp" ) target_sources(wivrn PRIVATE ${PLATFORM_SOURCE}) else() @@ -63,7 +63,7 @@ else() file(GLOB PLATFORM_SOURCE CONFIGURE_DEPENDS "decoder/ffmpeg/*.cpp") - #target_sources(wivrn PRIVATE ${PLATFORM_SOURCE}) + target_sources(wivrn PRIVATE ${PLATFORM_SOURCE}) file(CREATE_LINK ${CMAKE_CURRENT_BINARY_DIR}/share ${CMAKE_BINARY_DIR}/share SYMBOLIC) endif() diff --git a/client/decoder/android/android_decoder.cpp b/client/decoder/android/android_decoder.cpp index 2a091ad4..343d26e8 100644 --- a/client/decoder/android/android_decoder.cpp +++ b/client/decoder/android/android_decoder.cpp @@ -59,8 +59,11 @@ const char * mime(wivrn::video_codec codec) return "video/hevc"; case c::av1: return "video/av01"; + case c::pyrowave: + assert(false); } assert(false); + __builtin_unreachable(); } void check(media_status_t status, const char * msg) @@ -72,6 +75,26 @@ void check(media_status_t status, const char * msg) } } +struct android_blit_handle : public decoder::blit_handle +{ + std::shared_ptr vk_data; + std::shared_ptr image_reader; + AImage_ptr aimage; + android_blit_handle( + const wivrn::from_headset::feedback & feedback, + const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info, + vk::ImageView image_view, + vk::Image image, + vk::ImageLayout & current_layout, + decltype(vk_data) vk_data, + decltype(image_reader) image_reader, + decltype(aimage) aimage) : + decoder::blit_handle(feedback, view_info, image_view, image, current_layout), + vk_data(vk_data), + image_reader(image_reader), + aimage(std::move(aimage)) {} +}; + } // namespace namespace wivrn::android @@ -85,7 +108,7 @@ decoder::decoder( uint8_t stream_index, std::weak_ptr weak_scene, shard_accumulator * accumulator) : - description(description), stream_index(stream_index), fps(fps), device(device), weak_scene(weak_scene), accumulator(accumulator) + wivrn::decoder(description), stream_index(stream_index), fps(fps), device(device), weak_scene(weak_scene), accumulator(accumulator) { spdlog::info("hbm_mutex.native_handle() = {}", (void *)hbm_mutex.native_handle()); @@ -222,7 +245,7 @@ void decoder::push_data(std::span> data, uint64_t frame current_input_buffer = input_buffer{}; } -void decoder::frame_completed(wivrn::from_headset::feedback & feedback, const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info) +void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info) { if (not media_codec) { @@ -255,7 +278,7 @@ void decoder::on_image_available(AImageReader * reader) assert(reader == image_reader.get()); // Executed on image reader thread - decltype(blit_handle::aimage) image; + decltype(android_blit_handle::aimage) image; try { AImage * tmp; @@ -280,13 +303,13 @@ void decoder::on_image_available(AImageReader * reader) auto vk_data = map_hardware_buffer(image.get()); - auto handle = std::make_shared( + auto handle = std::make_shared( info->feedback, info->view_info, - vk_data->image_view, + *vk_data->image_view, *vk_data->vimage, - &vk_data->layout, - vk_data, + vk_data->layout, + std::move(vk_data), image_reader, std::move(image)); @@ -514,11 +537,6 @@ void decoder::on_media_output_available(AMediaCodec * media_codec, void * userda }); } -void decoder::blit_handle::deleter::operator()(AImage * aimage) -{ - AImage_delete(aimage); -} - static bool hardware_accelerated(AMediaCodec * media_codec) { // MediaCodecInfo has isHardwareAccelerated, but this does not exist in NDK. @@ -542,11 +560,10 @@ static bool hardware_accelerated(AMediaCodec * media_codec) return true; } -std::vector decoder::supported_codecs() +void decoder::supported_codecs(std::vector & result) { - std::vector result; // Make sure we update this code when codecs are changed - static_assert(magic_enum::enum_count() == 3); + static_assert(magic_enum::enum_count() == 4); // In order or preference, from preferred to least preferred for (auto codec: { @@ -563,8 +580,6 @@ std::vector decoder::supported_codecs() spdlog::info("video codec {}: {}supported", magic_enum::enum_name(codec), supported ? "" : "NOT "); } - - return result; } } // namespace wivrn::android diff --git a/client/decoder/android/android_decoder.h b/client/decoder/android/android_decoder.h index 63926935..27d26c1f 100644 --- a/client/decoder/android/android_decoder.h +++ b/client/decoder/android/android_decoder.h @@ -19,6 +19,7 @@ #pragma once +#include "decoder/decoder.h" #include "utils/sync_queue.h" #include "wivrn_packets.h" #include @@ -59,31 +60,12 @@ class stream; namespace wivrn::android { -class decoder +class decoder : public wivrn::decoder { public: struct mapped_hardware_buffer; - struct blit_handle - { - struct deleter - { - void operator()(AImage *); - }; - wivrn::from_headset::feedback feedback; - wivrn::to_headset::video_stream_data_shard::view_info_t view_info; - vk::raii::ImageView & image_view; - vk::Image image = nullptr; - vk::ImageLayout * current_layout = nullptr; - - std::shared_ptr vk_data; - - std::shared_ptr image_reader; - AImage_ptr aimage; - }; - private: - wivrn::to_headset::video_stream_description::item description; uint8_t stream_index; float fps; @@ -146,33 +128,20 @@ public: uint8_t stream_index, std::weak_ptr scene, shard_accumulator * accumulator); - - decoder(const decoder &) = delete; - decoder(decoder &&) = delete; ~decoder(); - void push_data(std::span> data, uint64_t frame_index, bool partial); + void push_data(std::span> data, uint64_t frame_index, bool partial) override; void frame_completed( - wivrn::from_headset::feedback & feedback, - const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info); + const wivrn::from_headset::feedback & feedback, + const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info) override; - const auto & desc() const - { - return description; - } - - vk::Sampler sampler() + vk::Sampler sampler() override { return *ycbcr_sampler; } - vk::Extent2D image_size() - { - return extent; - } - - static std::vector supported_codecs(); + static void supported_codecs(std::vector &); }; } // namespace wivrn::android diff --git a/client/decoder/decoder.cpp b/client/decoder/decoder.cpp new file mode 100644 index 00000000..8a56d33e --- /dev/null +++ b/client/decoder/decoder.cpp @@ -0,0 +1,80 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Patrick Nicolas + * + * 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 . + */ + +#include "decoder.h" + +#include "decoder/pyrowave/decoder.h" +#ifdef __ANDROID__ +#include "decoder/android/android_decoder.h" +#else +#include "decoder/ffmpeg/ffmpeg_decoder.h" +#endif + +wivrn::decoder::~decoder() = default; + +std::shared_ptr wivrn::decoder::make( + vk::raii::Device & device, + vk::raii::PhysicalDevice & phys_dev, + uint32_t vk_queue_family_index, + const wivrn::to_headset::video_stream_description::item & description, + float fps, + uint8_t stream_index, + std::weak_ptr scene, + shard_accumulator * acc) +{ + if (description.codec == pyrowave) + return std::make_shared( + device, + phys_dev, + vk_queue_family_index, + description, + fps, + stream_index, + scene, + acc); +#ifdef __ANDROID__ + return std::make_shared( + device, + phys_dev, + description, + fps, + stream_index, + scene, + acc); +#else + return std::make_shared( + device, + phys_dev, + description, + stream_index, + scene, + acc); +#endif +} + +std::vector wivrn::decoder::supported_codecs() +{ + std::vector res; +#ifdef __ANDROID__ + android::decoder::supported_codecs(res); +#else + ffmpeg::decoder::supported_codecs(res); +#endif + // Don't probe for pyrowave for now + return res; +} diff --git a/client/decoder/decoder.h b/client/decoder/decoder.h new file mode 100644 index 00000000..9e6d7538 --- /dev/null +++ b/client/decoder/decoder.h @@ -0,0 +1,77 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2025 Patrick Nicolas + * + * 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 . + */ + +#pragma once + +#include "wivrn_packets.h" + +#include +#include +#include +#include + +namespace scenes +{ +class stream; +} + +namespace wivrn +{ +class shard_accumulator; +class decoder +{ +public: + struct blit_handle + { + wivrn::from_headset::feedback feedback; + wivrn::to_headset::video_stream_data_shard::view_info_t view_info; + vk::ImageView image_view = nullptr; + vk::Image image = nullptr; + vk::ImageLayout & current_layout; + vk::Semaphore semaphore = nullptr; + uint64_t * semaphore_val = nullptr; + }; + + const wivrn::to_headset::video_stream_description::item description; + +protected: + decoder(const wivrn::to_headset::video_stream_description::item & description) : + description(description) {} + +public: + static std::shared_ptr make( + vk::raii::Device &, + vk::raii::PhysicalDevice &, + uint32_t vk_queue_family_index, + const wivrn::to_headset::video_stream_description::item & description, + float fps, + uint8_t stream_index, + std::weak_ptr, + shard_accumulator *); + virtual ~decoder(); + virtual void push_data(std::span> data, uint64_t frame_index, bool partial) = 0; + + virtual void frame_completed( + const from_headset::feedback & feedback, + const to_headset::video_stream_data_shard::view_info_t & view_info) = 0; + + virtual vk::Sampler sampler() = 0; + + static std::vector supported_codecs(); +}; +} // namespace wivrn diff --git a/client/decoder/ffmpeg/ffmpeg_decoder.cpp b/client/decoder/ffmpeg/ffmpeg_decoder.cpp index 09416a28..11151bcc 100644 --- a/client/decoder/ffmpeg/ffmpeg_decoder.cpp +++ b/client/decoder/ffmpeg/ffmpeg_decoder.cpp @@ -56,29 +56,60 @@ static AVCodecID codec_id(wivrn::video_codec codec) return AV_CODEC_ID_HEVC; case c::av1: return AV_CODEC_ID_AV1; + case c::pyrowave: + assert(false); } assert(false); __builtin_unreachable(); } -decoder::blit_handle::~blit_handle() +struct decoder::ffmpeg_blit_handle : public wivrn::decoder::blit_handle { - std::unique_lock lock(self->mutex); - if (image_index < 0) - return; + int image_index; + wivrn::ffmpeg::decoder * self; - self->free_images.push_back(image_index); -} + ffmpeg_blit_handle( + const wivrn::from_headset::feedback & feedback, + const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info, + vk::ImageView image_view, + vk::Image image, + vk::ImageLayout & current_layout, + int image_index, + wivrn::ffmpeg::decoder * self) : + wivrn::decoder::blit_handle{ + feedback, + view_info, + image_view, + image, + current_layout, + }, + image_index(image_index), + self(self) + {} + + ~ffmpeg_blit_handle() + { + std::unique_lock lock(self->mutex); + if (image_index < 0) + return; + + self->free_images.push_back(image_index); + } +}; decoder::decoder( vk::raii::Device & device, vk::raii::PhysicalDevice & physical_device, const wivrn::to_headset::video_stream_description::item & description, - float fps, uint8_t stream_index, std::weak_ptr scene, shard_accumulator * accumulator) : - device(device), description(description), codec(nullptr, free_codec_context), sws(nullptr, sws_freeContext), weak_scene(scene), accumulator(accumulator) + wivrn::decoder(description), + device(device), + codec(nullptr, free_codec_context), + sws(nullptr, sws_freeContext), + weak_scene(scene), + accumulator(accumulator) { free_images.resize(image_count); @@ -221,12 +252,12 @@ void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, co if (res == 0) throw std::runtime_error{"sws_scale failed"}; - auto handle = std::make_shared( + auto handle = std::make_shared( feedback, view_info, - decoded_images[index].image_view, - (vk::Image)decoded_images[index].image, - &decoded_images[index].current_layout, + *decoded_images[index].image_view, + decoded_images[index].image, + decoded_images[index].current_layout, index, this); @@ -234,13 +265,11 @@ void decoder::frame_completed(const wivrn::from_headset::feedback & feedback, co scene->push_blit_handle(accumulator, std::move(handle)); } -std::vector decoder::supported_codecs() +void decoder::supported_codecs(std::vector & res) { - return { - wivrn::video_codec::h264, - wivrn::video_codec::h265, - wivrn::video_codec::av1, - }; + res.push_back(wivrn::video_codec::h264); + res.push_back(wivrn::video_codec::h265); + res.push_back(wivrn::video_codec::av1); } } // namespace wivrn::ffmpeg diff --git a/client/decoder/ffmpeg/ffmpeg_decoder.h b/client/decoder/ffmpeg/ffmpeg_decoder.h index 33190af8..360de157 100644 --- a/client/decoder/ffmpeg/ffmpeg_decoder.h +++ b/client/decoder/ffmpeg/ffmpeg_decoder.h @@ -19,6 +19,7 @@ #pragma once +#include "decoder/decoder.h" #include "vk/allocation.h" #include "wivrn_packets.h" #include @@ -46,24 +47,10 @@ class stream; namespace wivrn::ffmpeg { -class decoder +class decoder : public wivrn::decoder { -public: - struct blit_handle - { - wivrn::from_headset::feedback feedback; - wivrn::to_headset::video_stream_data_shard::view_info_t view_info; - vk::raii::ImageView & image_view; - vk::Image image = nullptr; - vk::ImageLayout * current_layout = nullptr; - - int image_index; - decoder * self; - - ~blit_handle(); - }; - private: + struct ffmpeg_blit_handle; static const int image_count = 12; struct image { @@ -81,8 +68,6 @@ private: vk::Extent2D extent{}; std::vector free_images; - wivrn::to_headset::video_stream_description::item description; - std::unique_ptr codec; std::unique_ptr sws; std::vector packet; @@ -96,26 +81,17 @@ public: decoder(vk::raii::Device & device, vk::raii::PhysicalDevice & physical_device, const wivrn::to_headset::video_stream_description::item & description, - float fps, uint8_t stream_index, std::weak_ptr scene, shard_accumulator * accumulator); - decoder(const decoder &) = delete; - decoder(decoder &&) = delete; - - void push_data(std::span> data, uint64_t frame_index, bool partial); + void push_data(std::span> data, uint64_t frame_index, bool partial) override; void frame_completed( const wivrn::from_headset::feedback & feedback, - const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info); + const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info) override; - const auto & desc() const - { - return description; - } - - vk::Sampler sampler() + vk::Sampler sampler() override { return *rgb_sampler; } @@ -125,6 +101,6 @@ public: return extent; } - static std::vector supported_codecs(); + static void supported_codecs(std::vector &); }; } // namespace wivrn::ffmpeg diff --git a/client/decoder/pyrowave/decoder.cpp b/client/decoder/pyrowave/decoder.cpp index ddef4fd3..9f4264ad 100644 --- a/client/decoder/pyrowave/decoder.cpp +++ b/client/decoder/pyrowave/decoder.cpp @@ -21,9 +21,33 @@ #include "application.h" #include "scenes/stream.h" +namespace +{ +struct pyrowave_blit_handle : public decoder::blit_handle +{ + std::atomic_bool & free; + + pyrowave_blit_handle( + const wivrn::from_headset::feedback & feedback, + const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info, + vk::ImageView image_view, + vk::Image image, + vk::ImageLayout & current_layout, + vk::Semaphore semaphore, + uint64_t & semaphore_val, + std::atomic_bool & free) : + decoder::blit_handle{feedback, view_info, image_view, image, current_layout, semaphore, &semaphore_val}, + free(free) {} + ~pyrowave_blit_handle() + { + free = true; + }; +}; +} // namespace + namespace wivrn { -decoder::decoder( +pyrowave_decoder::pyrowave_decoder( vk::raii::Device & device, vk::raii::PhysicalDevice & physical_device, uint32_t vk_queue_family_index, @@ -32,6 +56,7 @@ decoder::decoder( uint8_t stream_index, std::weak_ptr scene, shard_accumulator * accumulator) : + decoder(description), ycbcr_conversion(device, { .format = vk::Format::eG8B8R83Plane420Unorm, .ycbcrModel = vk::SamplerYcbcrModelConversion(description.color_model.value_or(VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709)), @@ -53,7 +78,6 @@ decoder::decoder( }, } .get()), - description(description), weak_scene(scene), accumulator(accumulator), dec(physical_device, device, description.width, description.height, PyroWave::ChromaSubsampling::Chroma420, true) @@ -140,7 +164,7 @@ decoder::decoder( worker = std::thread([&, vk_queue_family_index] { worker_function(vk_queue_family_index); }); } -decoder::~decoder() +pyrowave_decoder::~pyrowave_decoder() { exiting = true; pending.lock().notify_all(); @@ -148,13 +172,13 @@ decoder::~decoder() worker.join(); } -void decoder::push_data(std::span> data, uint64_t frame_index, bool partial) +void pyrowave_decoder::push_data(std::span> data, uint64_t frame_index, bool partial) { for (auto & item: data) input_acc->push_data(item); } -void decoder::frame_completed( +void pyrowave_decoder::frame_completed( const from_headset::feedback & feedback, const to_headset::video_stream_data_shard::view_info_t & view_info) { @@ -169,7 +193,7 @@ void decoder::frame_completed( input_acc->clear(); } -decoder::image * decoder::get_free() +pyrowave_decoder::image * pyrowave_decoder::get_free() { for (auto & item: image_pool) { @@ -179,7 +203,7 @@ decoder::image * decoder::get_free() return nullptr; } -void decoder::worker_function(uint32_t queue_family_index) +void pyrowave_decoder::worker_function(uint32_t queue_family_index) { auto & device = dec.device; vk::raii::CommandPool command_pool( @@ -236,12 +260,12 @@ void decoder::worker_function(uint32_t queue_family_index) continue; } std::array views{*item->view_y, *item->view_cb, *item->view_cr}; - auto handle = std::make_shared( + auto handle = std::make_shared( feedback, view_info, - item->view_full, + *item->view_full, item->image, - &item->current_layout, + item->current_layout, *item->semaphore, item->semaphore_val, item->free); @@ -335,13 +359,8 @@ void decoder::worker_function(uint32_t queue_family_index) } } -std::vector decoder::supported_codecs() +std::vector pyrowave_decoder::supported_codecs() { return {video_codec::pyrowave}; } - -decoder::blit_handle::~blit_handle() -{ - free = true; -} } // namespace wivrn diff --git a/client/decoder/pyrowave/decoder.h b/client/decoder/pyrowave/decoder.h index cf3ecd45..7e8684f9 100644 --- a/client/decoder/pyrowave/decoder.h +++ b/client/decoder/pyrowave/decoder.h @@ -18,6 +18,7 @@ #pragma once +#include "decoder/decoder.h" #include "pyrowave/pyrowave_decoder.h" #include "utils/thread_safe.h" #include "vk/allocation.h" @@ -40,24 +41,8 @@ class stream; namespace wivrn { -class decoder +class pyrowave_decoder : public decoder { -public: - struct blit_handle - { - wivrn::from_headset::feedback feedback; - wivrn::to_headset::video_stream_data_shard::view_info_t view_info; - vk::raii::ImageView & image_view; - vk::Image image = nullptr; - vk::ImageLayout * current_layout = nullptr; - vk::Semaphore semaphore = nullptr; - uint64_t & semaphore_val; - - std::atomic_bool & free; - - ~blit_handle(); - }; - private: static const int image_count = 12; struct image @@ -78,8 +63,6 @@ private: std::array image_pool; - wivrn::to_headset::video_stream_description::item description; - std::weak_ptr weak_scene; shard_accumulator * accumulator; @@ -98,29 +81,24 @@ private: std::atomic_bool exiting = false; public: - decoder(vk::raii::Device & device, - vk::raii::PhysicalDevice & physical_device, - uint32_t vk_queue_family_index, - const wivrn::to_headset::video_stream_description::item & description, - float fps, - uint8_t stream_index, - std::weak_ptr scene, - shard_accumulator * accumulator); + pyrowave_decoder(vk::raii::Device & device, + vk::raii::PhysicalDevice & physical_device, + uint32_t vk_queue_family_index, + const wivrn::to_headset::video_stream_description::item & description, + float fps, + uint8_t stream_index, + std::weak_ptr scene, + shard_accumulator * accumulator); - ~decoder(); + ~pyrowave_decoder(); - void push_data(std::span> data, uint64_t frame_index, bool partial); + void push_data(std::span> data, uint64_t frame_index, bool partial) override; void frame_completed( const wivrn::from_headset::feedback & feedback, - const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info); + const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info) override; - const auto & desc() const - { - return description; - } - - vk::Sampler sampler() + vk::Sampler sampler() override { return *sampler_; } diff --git a/client/decoder/shard_accumulator.cpp b/client/decoder/shard_accumulator.cpp index 900c05ee..a7ec0636 100644 --- a/client/decoder/shard_accumulator.cpp +++ b/client/decoder/shard_accumulator.cpp @@ -186,7 +186,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx) payload.emplace_back(data_shards[idx]->payload); bool frame_complete = last_idx == data_shards.size() and data_shards.back()->flags & video_stream_data_shard::end_of_frame; - decoder->push_data(payload, data_shards[shard_idx]->frame_idx, not frame_complete); + decoder_->push_data(payload, data_shards[shard_idx]->frame_idx, not frame_complete); if (not frame_complete) return; @@ -206,7 +206,7 @@ void shard_accumulator::try_submit_frame(uint16_t shard_idx) } // Try to extract a frame - decoder->frame_completed(current.feedback, *data_shards.front()->view_info); + decoder_->frame_completed(current.feedback, *data_shards.front()->view_info); send_feedback(current.feedback); diff --git a/client/decoder/shard_accumulator.h b/client/decoder/shard_accumulator.h index fb18dd17..f70e85c0 100644 --- a/client/decoder/shard_accumulator.h +++ b/client/decoder/shard_accumulator.h @@ -19,37 +19,30 @@ #pragma once -#include -#include - -#if 1 -#include "decoder/pyrowave/decoder.h" -using decoder_impl = ::wivrn::decoder; -#else -#ifdef __ANDROID__ -#include "decoder/android/android_decoder.h" -using decoder_impl = ::wivrn::android::decoder; -#else -#include "decoder/ffmpeg/ffmpeg_decoder.h" -using decoder_impl = ::wivrn::ffmpeg::decoder; -#endif -#endif - +#include "decoder.h" #include "wivrn_packets.h" + +#include #include #include +#include namespace xr { class instance; } +namespace scenes +{ +class stream; +} + namespace wivrn { class shard_accumulator { - std::shared_ptr decoder; + std::shared_ptr decoder_; public: using data_shard = wivrn::to_headset::video_stream_data_shard; @@ -92,7 +85,7 @@ public: float fps, std::weak_ptr scene, uint8_t stream_index) : - decoder(std::make_shared(device, physical_device, vk_queue_family_index, description, fps, stream_index, scene, this)), + decoder_(decoder::make(device, physical_device, vk_queue_family_index, description, fps, stream_index, scene, this)), current(stream_index), next(stream_index), weak_scene(scene), @@ -105,20 +98,15 @@ public: auto & desc() const { - return decoder->desc(); + return decoder_->description; } vk::Sampler sampler() { - return decoder->sampler(); + return decoder_->sampler(); } - vk::Extent2D image_size() - { - return decoder->image_size(); - } - - using blit_handle = decoder_impl::blit_handle; + using blit_handle = decoder::blit_handle; private: void try_submit_frame(std::optional shard_idx); diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index c86ab1a6..292e5590 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -299,7 +299,7 @@ std::shared_ptr scenes::stream::create(std::unique_ptrview_info.foveation; use_alpha = blit_handle->view_info.alpha; - if (*blit_handle->current_layout == vk::ImageLayout::eUndefined) + if (blit_handle->current_layout == vk::ImageLayout::eUndefined) { vk::ImageMemoryBarrier barrier{ .srcAccessMask = vk::AccessFlagBits::eNone, @@ -865,7 +865,7 @@ void scenes::stream::render(const XrFrameState & frame_state) }; command_buffer.pipelineBarrier(vk::PipelineStageFlagBits::eAllCommands, vk::PipelineStageFlagBits::eAllCommands, {}, {}, {}, barrier); - *blit_handle->current_layout = vk::ImageLayout::eGeneral; + blit_handle->current_layout = vk::ImageLayout::eGeneral; } } @@ -878,7 +878,7 @@ void scenes::stream::render(const XrFrameState & frame_state) { if (not blit_handle) continue; - b.push_image(command_buffer, j, decoders[j].decoder->sampler(), *blit_handle->image_view, *blit_handle->current_layout); + b.push_image(command_buffer, j, decoders[j].decoder->sampler(), blit_handle->image_view, blit_handle->current_layout); } blitted[i] = b.end(command_buffer); } @@ -935,8 +935,9 @@ void scenes::stream::render(const XrFrameState & frame_state) { if (b and b->semaphore) { + assert(b->semaphore_val); semaphores.push_back(b->semaphore); - semaphore_vals.push_back(b->semaphore_val); + semaphore_vals.push_back(*b->semaphore_val); wait_stages.push_back(vk::PipelineStageFlagBits::eFragmentShader); } } diff --git a/server/encoder/encoder_settings.cpp b/server/encoder/encoder_settings.cpp index ff627324..398880ad 100644 --- a/server/encoder/encoder_settings.cpp +++ b/server/encoder/encoder_settings.cpp @@ -268,6 +268,9 @@ static void fill_defaults(wivrn_vk_bundle & bundle, const std::vector get_encoder_default_settings(wivrn_vk return {base}; } +static void check_offsets(const configuration::encoder & c) +{ + if (c.name == encoder_pyrowave) + { + if (c.offset_x != 0 or c.offset_y != 0 or c.width != 1 or c.height != 1) + U_LOG_E("Pyrowave does not support multi-encoder layout"); + } +} + static uint16_t align(uint16_t value, uint16_t alignment) { return ((value + alignment - 1) / alignment) * alignment; @@ -376,21 +388,8 @@ std::vector get_encoder_settings(wivrn_vk_bundle & bundle, uin config.encoder_passthrough->offset_x = 0; config.encoder_passthrough->offset_y = 0; fill_defaults(bundle, info.supported_codecs, *config.encoder_passthrough, config.bit_depth); - - config.encoder_passthrough = { - .name = encoder_pyrowave, - .width = 1, - .height = 1, - .codec = video_codec::pyrowave, - }; - config.encoders = { - { - .name = encoder_pyrowave, - .width = 1, - .height = 1, - .codec = video_codec::pyrowave, - }, - }; + if (config.encoder_passthrough->name == encoder_pyrowave) + U_LOG_E("Pyrowave is not supported for alpha channel"); uint64_t bitrate = config.bitrate.value_or(default_bitrate); std::array default_scale; @@ -413,6 +412,7 @@ std::vector get_encoder_settings(wivrn_vk_bundle & bundle, uin std::ceil(encoder.width.value_or(1) * width), std::ceil(encoder.height.value_or(1) * height), scale); + check_offsets(encoder); } width = align(width * scale[0], 64);