From 8a1388f102fd36810df59ec146493ce787fd9ffd Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Tue, 15 Nov 2022 11:42:39 +0100 Subject: [PATCH] Use actual fps hint for mediacodec init --- client/src/decoder/android/android_decoder.cpp | 12 +++++++++--- client/src/decoder/android/android_decoder.h | 9 ++++++++- client/src/decoder/ffmpeg/ffmpeg_decoder.cpp | 8 +++++++- client/src/decoder/ffmpeg/ffmpeg_decoder.h | 8 +++++++- client/src/decoder/shard_accumulator.h | 3 ++- client/src/scenes/stream.cpp | 2 +- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/client/src/decoder/android/android_decoder.cpp b/client/src/decoder/android/android_decoder.cpp index 096c15cc..3c67fb12 100644 --- a/client/src/decoder/android/android_decoder.cpp +++ b/client/src/decoder/android/android_decoder.cpp @@ -388,8 +388,14 @@ void decoder::push_nals(std::span data, int64_t timestamp, uint32_t fla } } -decoder::decoder(VkDevice device, VkPhysicalDevice physical_device, const xrt::drivers::wivrn::to_headset::video_stream_description::item & description, std::weak_ptr weak_scene, shard_accumulator * accumulator) : - description(description), device(device), weak_scene(weak_scene), accumulator(accumulator) +decoder::decoder( + VkDevice device, + VkPhysicalDevice physical_device, + const xrt::drivers::wivrn::to_headset::video_stream_description::item & description, + float fps, + std::weak_ptr weak_scene, + shard_accumulator * accumulator) : + description(description), fps(fps), device(device), weak_scene(weak_scene), accumulator(accumulator) { AImageReader * ir; check(AImageReader_newWithUsage(description.width, description.height, AIMAGE_FORMAT_PRIVATE, AHARDWAREBUFFER_USAGE_CPU_READ_NEVER | AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE, 5 /* maxImages */, &ir), @@ -496,7 +502,7 @@ void decoder::push_data(std::span data, uint64_t frame_index, bool part // latency mode AMediaFormat_setInt32(format.get(), AMEDIAFORMAT_KEY_WIDTH, description.width); AMediaFormat_setInt32(format.get(), AMEDIAFORMAT_KEY_HEIGHT, description.height); - AMediaFormat_setInt32(format.get(), AMEDIAFORMAT_KEY_OPERATING_RATE, 72); + AMediaFormat_setInt32(format.get(), AMEDIAFORMAT_KEY_OPERATING_RATE, std::ceil(fps)); AMediaFormat_setInt32(format.get(), AMEDIAFORMAT_KEY_PRIORITY, 0); // AMediaFormat_setBuffer(format.get(), AMEDIAFORMAT_KEY_CSD_0, csd.data(), csd.size()); diff --git a/client/src/decoder/android/android_decoder.h b/client/src/decoder/android/android_decoder.h index 03217111..8c6bbb34 100644 --- a/client/src/decoder/android/android_decoder.h +++ b/client/src/decoder/android/android_decoder.h @@ -92,6 +92,7 @@ public: private: xrt::drivers::wivrn::to_headset::video_stream_description::item description; + float fps; VkDevice device; @@ -128,7 +129,13 @@ private: std::shared_ptr map_hardware_buffer(AImage *); public: - decoder(VkDevice device, VkPhysicalDevice physical_device, const xrt::drivers::wivrn::to_headset::video_stream_description::item & description, std::weak_ptr scene, shard_accumulator * accumulator); + decoder( + VkDevice device, + VkPhysicalDevice physical_device, + const xrt::drivers::wivrn::to_headset::video_stream_description::item & description, + float fps, + std::weak_ptr scene, + shard_accumulator * accumulator); decoder(const decoder &) = delete; decoder(decoder &&) = delete; diff --git a/client/src/decoder/ffmpeg/ffmpeg_decoder.cpp b/client/src/decoder/ffmpeg/ffmpeg_decoder.cpp index 87558fb6..4df624a5 100644 --- a/client/src/decoder/ffmpeg/ffmpeg_decoder.cpp +++ b/client/src/decoder/ffmpeg/ffmpeg_decoder.cpp @@ -68,7 +68,13 @@ decoder::blit_handle::~blit_handle() self->free_images.push_back(image_index); } -decoder::decoder(VkDevice device, VkPhysicalDevice physical_device, const xrt::drivers::wivrn::to_headset::video_stream_description::item & description, std::weak_ptr scene, shard_accumulator * accumulator) : +decoder::decoder( + VkDevice device, + VkPhysicalDevice physical_device, + const xrt::drivers::wivrn::to_headset::video_stream_description::item & description, + float fps, + 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) { free_images.resize(image_count); diff --git a/client/src/decoder/ffmpeg/ffmpeg_decoder.h b/client/src/decoder/ffmpeg/ffmpeg_decoder.h index 653f3bb9..acce6ed8 100644 --- a/client/src/decoder/ffmpeg/ffmpeg_decoder.h +++ b/client/src/decoder/ffmpeg/ffmpeg_decoder.h @@ -84,7 +84,13 @@ private: std::mutex mutex; public: - decoder(VkDevice device, VkPhysicalDevice physical_device, const xrt::drivers::wivrn::to_headset::video_stream_description::item & description, std::weak_ptr scene, shard_accumulator * accumulator); + decoder( + VkDevice device, + VkPhysicalDevice physical_device, + const xrt::drivers::wivrn::to_headset::video_stream_description::item & description, + float fps, + std::weak_ptr scene, + shard_accumulator * accumulator); void push_data(std::span data, uint64_t frame_index, bool partial); diff --git a/client/src/decoder/shard_accumulator.h b/client/src/decoder/shard_accumulator.h index 6d866a86..5de3d663 100644 --- a/client/src/decoder/shard_accumulator.h +++ b/client/src/decoder/shard_accumulator.h @@ -82,9 +82,10 @@ public: VkDevice device, VkPhysicalDevice physical_device, const xrt::drivers::wivrn::to_headset::video_stream_description::item & description, + float fps, std::weak_ptr scene, uint8_t stream_index) : - decoder(std::make_shared(device, physical_device, description, scene, this)), + decoder(std::make_shared(device, physical_device, description, fps, scene, this)), current(stream_index), next(stream_index), weak_scene(scene) diff --git a/client/src/scenes/stream.cpp b/client/src/scenes/stream.cpp index ccebabee..5c20b4bd 100644 --- a/client/src/scenes/stream.cpp +++ b/client/src/scenes/stream.cpp @@ -507,7 +507,7 @@ 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); accumulator_images dec; - dec.decoder = std::make_unique(device, physical_device, item, shared_from_this(), stream_index); + dec.decoder = std::make_unique(device, physical_device, item, description.fps, shared_from_this(), stream_index); dec.decoder->set_blit_targets(blit_targets, VK_FORMAT_A8B8G8R8_SRGB_PACK32); decoders.push_back(std::move(dec));