/* * WiVRn VR streaming * Copyright (C) 2022 Guillaume Meunier * Copyright (C) 2022 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 "video_encoder.h" #include "vk/allocation.h" #include "x264.h" #include #include #include 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; uint32_t chroma_width; struct pending_nal { int first_mb; int last_mb; std::vector data; }; std::mutex mutex; int next_mb; int num_mb; // Number of macroblocks in a frame std::list 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 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