Monopoly — Portage moderne 0.1.0
Portage moderne C/C++23 du Monopoly de 1999
Loading...
Searching...
No Matches
VideoRuntime.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <expected>
5#include <map>
6#include <optional>
7#include <span>
8#include <string>
9
10namespace monopoly::video
11{
13 {
14 std::uint32_t microsecondsPerFrame{};
15 std::uint32_t totalFrames{};
16 std::uint32_t width{};
17 std::uint32_t height{};
18 friend bool operator==(
19 const AviMetadata&, const AviMetadata&) = default;
20 };
21
22 struct Status
23 {
24 std::int32_t currentFrame{-1};
25 std::int32_t desiredFrame{-1};
26 std::int32_t numberOfFrames{};
27 bool ended{};
28 friend bool operator==(const Status&, const Status&) = default;
29 };
30
31 struct JumpEvent
32 {
33 std::int32_t decisionFrame{-1};
34 std::int32_t jumpToFrame{-1};
36 friend bool operator==(const JumpEvent&, const JumpEvent&) = default;
37 };
38
39 [[nodiscard]] std::expected<AviMetadata, std::string>
40 parseAviMetadata(std::span<const std::uint8_t> bytes);
41
43 {
44 public:
45 [[nodiscard]] std::expected<void, std::string> open(
46 std::span<const std::uint8_t> aviBytes,
47 bool loopAtEnd = false);
48
49 [[nodiscard]] std::expected<void, std::string> open(
50 AviMetadata metadata, bool loopAtEnd = false);
51
52 void stop() noexcept;
53
54 [[nodiscard]] std::expected<Status, std::string> feedToFrame(
55 std::int32_t desiredFrame);
56
57 [[nodiscard]] std::expected<std::int32_t, std::string>
58 frameAtElapsed(std::uint64_t elapsedMicroseconds) const;
59
60 [[nodiscard]] std::expected<void, std::string> cutToFrame(
61 std::int32_t frame);
62
63 [[nodiscard]] std::expected<void, std::string> setAlternative(
64 std::int32_t decisionFrame,
65 std::int32_t jumpToFrame);
66
68 std::int32_t decisionFrame,
69 bool takeJump) noexcept;
70
71 void forgetAlternatives() noexcept;
72
73 [[nodiscard]] std::optional<JumpEvent> takeJumpEvent() noexcept;
74
76 {
77 return status_;
78 }
79
81 {
82 return metadata_;
83 }
84
86 {
87 return status_.numberOfFrames > 0;
88 }
89
90 private:
91 struct Alternative
92 {
93 std::int32_t jumpToFrame{-1};
94 bool takeJump{};
95 };
96
97 AviMetadata metadata_{};
98 Status status_{};
99 bool loopAtEnd_{};
100 std::map<std::int32_t, Alternative> alternatives_;
101 std::optional<JumpEvent> pendingJump_;
102 };
103}
std::vector< std::byte > bytes
unsigned index
std::size_t frame
const AviMetadata & metadata() const noexcept
std::expected< void, std::string > cutToFrame(std::int32_t frame)
std::expected< std::int32_t, std::string > frameAtElapsed(std::uint64_t elapsedMicroseconds) const
std::expected< Status, std::string > feedToFrame(std::int32_t desiredFrame)
std::optional< JumpEvent > takeJumpEvent() noexcept
bool open() const noexcept
const Status & status() const noexcept
std::expected< void, std::string > setAlternative(std::int32_t decisionFrame, std::int32_t jumpToFrame)
void forgetAlternatives() noexcept
bool changeAlternative(std::int32_t decisionFrame, bool takeJump) noexcept
std::expected< AviMetadata, std::string > parseAviMetadata(std::span< const std::uint8_t > bytes)
friend bool operator==(const AviMetadata &, const AviMetadata &)=default
friend bool operator==(const JumpEvent &, const JumpEvent &)=default
friend bool operator==(const Status &, const Status &)=default