ACMX 2.136.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
snapshot_writer.hpp
Go to the documentation of this file.
1#ifndef ACMXVK_APP_SNAPSHOT_WRITER_HPP
2#define ACMXVK_APP_SNAPSHOT_WRITER_HPP
3
4#include "options.hpp"
5
6#include <condition_variable>
7#include <cstdint>
8#include <deque>
9#include <mutex>
10#include <string_view>
11#include <thread>
12#include <vector>
13
14namespace acmxvk {
15 enum class SnapshotFormat { Png,
18 Raw };
19
20 struct SnapshotJob {
21 fs::path path;
22 std::vector<std::uint8_t> rgba;
23 std::vector<std::uint16_t> rgba16;
24 std::uint32_t width = 0;
25 std::uint32_t height = 0;
27 };
28
30 public:
31 SnapshotWriter() = default;
33 SnapshotWriter(const SnapshotWriter &) = delete;
37
38 [[nodiscard]] bool start();
39 void stop() noexcept;
40 [[nodiscard]] bool queueFull();
41 void enqueue(SnapshotJob job);
42
43 static void savePng(const fs::path &path, std::uint8_t *rgba,
44 int width, int height);
45 [[nodiscard]] static std::string_view
46 formatName(SnapshotFormat format) noexcept;
47
48 private:
49 static constexpr std::size_t QUEUE_CAPACITY = 4;
50
51 static void saveRaw(const fs::path &path,
52 const std::vector<std::uint8_t> &rgba,
53 std::uint32_t width, std::uint32_t height);
54 static void saveRaw16(const fs::path &path,
55 const std::vector<std::uint16_t> &rgba,
56 std::uint32_t width, std::uint32_t height);
57#ifdef ACMXVK_WITH_WEBP
58 static void saveWebP(const fs::path &path, const std::uint8_t *rgba,
59 int width, int height);
60#endif
61#ifdef ACMXVK_WITH_TIFF
62 static void saveTiff(const fs::path &path, const std::uint8_t *rgba,
63 int width, int height);
64 static void saveTiff16(const fs::path &path,
65 const std::uint16_t *rgba, int width,
66 int height);
67#endif
68 void workerLoop() noexcept;
69
70 std::deque<SnapshotJob> jobs;
72 std::condition_variable condition;
73 std::thread worker;
74 std::size_t jobs_in_flight = 0;
75 bool stopping = false;
76 };
77} // namespace acmxvk
78
79#endif
std::condition_variable condition
static void saveRaw16(const fs::path &path, const std::vector< std::uint16_t > &rgba, std::uint32_t width, std::uint32_t height)
static void savePng(const fs::path &path, std::uint8_t *rgba, int width, int height)
SnapshotWriter & operator=(SnapshotWriter &&)=delete
std::deque< SnapshotJob > jobs
static std::string_view formatName(SnapshotFormat format) noexcept
static void saveRaw(const fs::path &path, const std::vector< std::uint8_t > &rgba, std::uint32_t width, std::uint32_t height)
SnapshotWriter(SnapshotWriter &&)=delete
static constexpr std::size_t QUEUE_CAPACITY
SnapshotWriter & operator=(const SnapshotWriter &)=delete
void enqueue(SnapshotJob job)
SnapshotWriter(const SnapshotWriter &)=delete
std::vector< std::uint16_t > rgba16
std::vector< std::uint8_t > rgba