Files
WiVRn/server/encoder/video_encoder_x264.h
T
Patrick Nicolas 7e8c479cc5 Release swapchain earlier
Encoders now have a buffer for next image so that they can encode one
and the compositor write to an other one.
2024-09-11 23:41:10 +02:00

81 lines
2.0 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 xrt::drivers::wivrn
{
class VideoEncoderX264 : public VideoEncoder
{
x264_param_t param = {};
x264_t * enc;
x264_picture_t pic_out = {};
struct in_t
{
x264_picture_t pic;
buffer_allocation luma;
buffer_allocation chroma;
};
std::array<in_t, num_slots> in;
uint32_t chroma_width;
vk::Rect2D rect;
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:
VideoEncoderX264(wivrn_vk_bundle & vk, encoder_settings & settings, float fps);
void present_image(vk::Image y_cbcr, vk::raii::CommandBuffer & cmd_buf, uint8_t slot) override;
std::optional<data> encode(bool idr, std::chrono::steady_clock::time_point pts, uint8_t slot) override;
~VideoEncoderX264();
private:
static void ProcessCb(x264_t * h, x264_nal_t * nal, void * opaque);
void ProcessNal(pending_nal && nal);
void InsertInPendingNal(pending_nal && nal);
};
} // namespace xrt::drivers::wivrn