Files
WiVRn/server/encoder/video_encoder_x264.h
Patrick Nicolas ce83e8fb03 Major synchronization rework
unify submit/post_submit encoder entrypoints
encoders must now wait for their command completion
use transfer queues for CPU -> GPU copy
2026-04-11 16:55:02 +02:00

86 lines
2.1 KiB
C++

/*
* WiVRn VR streaming
* Copyright (C) 2022 Guillaume Meunier <[email protected]>
* Copyright (C) 2022 Patrick Nicolas <[email protected]>
*
* 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 "video_encoder.h"
#include "vk/allocation.h"
#include "x264.h"
#include <list>
#include <mutex>
#include <vulkan/vulkan_raii.hpp>
namespace wivrn
{
class video_encoder_x264 : public video_encoder
{
x264_param_t param = {};
x264_t * enc;
bool control;
x264_picture_t pic_out = {};
wivrn::vk_bundle & vk;
uint64_t sem_value = 0; // current value of the semaphore
vk::raii::CommandPool cmd_pool;
struct in_t
{
vk::raii::Fence fence = nullptr;
vk::raii::CommandBuffer cmd = nullptr;
x264_picture_t pic;
buffer_allocation luma;
buffer_allocation chroma;
};
std::array<in_t, num_slots> in;
uint32_t chroma_width;
struct pending_nal
{
int first_mb;
int last_mb;
std::vector<uint8_t> data;
};
std::mutex mutex;
int next_mb;
int num_mb; // Number of macroblocks in a frame
std::list<pending_nal> pending_nals;
public:
video_encoder_x264(wivrn::vk_bundle & vk, const encoder_settings & settings, uint8_t stream_idx);
void present_image(vk::Image y_cbcr, vk::SemaphoreSubmitInfo, uint8_t slot, uint64_t frame_index) override;
std::optional<data> encode(uint8_t slot, uint64_t frame_index) override;
~video_encoder_x264();
private:
static void ProcessCb(x264_t * h, x264_nal_t * nal, void * opaque);
void ProcessNal(pending_nal && nal);
void InsertInPendingNal(pending_nal && nal);
};
} // namespace wivrn