Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
VideoDecoder.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <expected>
6#include <filesystem>
7#include <memory>
8#include <optional>
9#include <string>
10#include <vector>
11
12namespace monopoly::video
13{
15 {
16 // External FFmpeg/FFprobe executables, resolved through PATH by SDL.
17 std::string ffmpeg{"ffmpeg"};
18 std::string ffprobe{"ffprobe"};
19 std::size_t videoQueueFrames{3};
20 std::size_t audioQueueChunks{16};
21 std::size_t maximumFrameBytes{16U * 1024U * 1024U};
22 std::uint32_t probeTimeoutMilliseconds{15000};
23 bool decodeVideo{true};
24 bool decodeAudio{true};
25 };
26
28 {
29 std::uint32_t width{};
30 std::uint32_t height{};
31 std::uint32_t frameRateNumerator{};
32 std::uint32_t frameRateDenominator{1};
33 std::uint64_t durationMicroseconds{};
34 bool hasAudio{};
35 std::uint32_t audioSampleRate{};
36 std::string videoCodec;
37 std::string audioCodec;
38 };
39
41 {
42 // Position on the normalized movie timeline, including the seek offset.
43 // Legacy AVI/Bink frames are delivered at the reported rational cadence.
44 std::uint64_t timestampMicroseconds{};
45 std::uint32_t width{};
46 std::uint32_t height{};
47 std::vector<std::uint8_t> rgba;
48 };
49
51 {
52 static constexpr std::uint32_t sampleRate = 48000;
53 static constexpr std::uint32_t channels = 2;
54 std::uint64_t timestampMicroseconds{};
55 // Interleaved signed 16-bit little-endian PCM, independent of host endian.
56 std::vector<std::uint8_t> pcm;
57 };
58
60
62 {
64 std::optional<DecoderMetadata> metadata;
65 std::string error;
66 std::size_t queuedVideoFrames{};
67 std::size_t queuedAudioChunks{};
68 std::uint64_t generation{};
69 // Each stream has reached EOF; already queued output remains consumable.
70 bool videoEnded{};
71 bool audioEnded{};
72 };
73
74 // One worker owns all SDL process/pipe operations. Public control and queue
75 // methods belong to the UI thread; they never read or drain a process pipe.
76 // Decoding uses installed FFmpeg (including Indeo5/Bink decoders), not the
77 // incompatible historical 32-bit codec DLLs. No shell is ever invoked.
79 {
80 public:
81 Decoder();
82 ~Decoder();
83 Decoder(const Decoder&) = delete;
84 Decoder& operator=(const Decoder&) = delete;
85 Decoder(Decoder&&) = delete;
87
88 [[nodiscard]] std::expected<void, std::string> open(
89 const std::filesystem::path& file,
90 const DecoderOptions& options = {});
91
92 // Asynchronous, clears stale output immediately; zero also restarts EOF.
93 [[nodiscard]] std::expected<void, std::string> seek(
94 std::uint64_t timestampMicroseconds);
95
96 // Cancels the worker, force-stops/reaps its children, then releases queues.
97 // Backpressure and pending probe/decode work never need to drain first.
98 void stop() noexcept;
99
103
104 private:
105 struct Impl;
106 std::unique_ptr<Impl> impl_;
107 };
108}
unsigned index
std::optional< DecodedVideoFrame > popVideo()
std::expected< void, std::string > seek(std::uint64_t timestampMicroseconds)
std::expected< void, std::string > open(const std::filesystem::path &file, const DecoderOptions &options={})
std::optional< DecodedAudioChunk > popAudio()
DecoderSnapshot snapshot() const
Decoder(const Decoder &)=delete
Decoder & operator=(const Decoder &)=delete
Decoder & operator=(Decoder &&)=delete
Decoder(Decoder &&)=delete
static constexpr std::uint32_t channels
std::vector< std::uint8_t > pcm
static constexpr std::uint32_t sampleRate
std::vector< std::uint8_t > rgba
std::optional< DecoderMetadata > metadata