StormByte-Multimedia 3.3.2
C++26 multimedia processing module of the StormByte suite
Loading...
Searching...
No Matches
buffering.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Multimedia.
5 *
6 * StormByte-Multimedia original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License, version 3, or (at your option) any
11 * later version.
12 *
13 * 2. Commercial license
14 * Alternatively, this file may be used under the terms of a commercial
15 * license agreement with the copyright holder
16 * (David C. Manuelda <StormByte@gmail.com>).
17 *
18 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
19 */
20
21#pragma once
22
23#include <StormByte/buffer/byte_budget.hxx>
24#include <StormByte/byte_size.hxx>
25#include <StormByte/size.hxx>
27#include <StormByte/safe/optional.hxx>
28#include <StormByte/type_traits/safe.hxx>
29
30#include <cstdint>
31
41 public:
42 enum class Mode: std::uint8_t {
46 };
47
48 constexpr QueueLimit() noexcept = default;
49
50 static constexpr QueueLimit Automatic() noexcept {
51 return QueueLimit{Mode::Automatic, 0};
52 }
53
54 static constexpr QueueLimit Unlimited() noexcept {
55 return QueueLimit{Mode::Unlimited, 0};
56 }
57
58 static constexpr QueueLimit Bounded(StormByte::Size value) noexcept {
59 return QueueLimit{Mode::Bounded, value};
60 }
61
62 constexpr Mode GetMode() const noexcept {
63 return m_mode;
64 }
65
66 constexpr StormByte::Size Value() const noexcept {
67 return m_value;
68 }
69
70 constexpr bool Valid(StormByte::Size minimum) const noexcept {
71 return m_mode != Mode::Bounded || m_value >= minimum;
72 }
73
74 constexpr StormByte::Size Resolve(StormByte::Size automatic) const noexcept {
75 switch (m_mode) {
76 case Mode::Automatic: return automatic;
77 case Mode::Unlimited: return 0;
78 case Mode::Bounded: return m_value;
79 }
80 return automatic;
81 }
82
83 private:
84 constexpr QueueLimit(Mode mode, StormByte::Size value) noexcept
85 : m_mode(mode), m_value(value) {}
86
87 Mode m_mode = Mode::Automatic;
88 StormByte::Size m_value = 0;
89 };
90
100 public:
101 constexpr QueueLimit VideoFrames() const noexcept { return m_video_frames; }
102 constexpr QueueLimit AudioFrames() const noexcept { return m_audio_frames; }
103 constexpr QueueLimit Packets() const noexcept { return m_packets; }
104 constexpr QueueLimit DemuxPending() const noexcept { return m_demux_pending; }
105
107 return m_queue_bytes;
108 }
109
110 const StormByte::Buffer::ByteBudget& Budget() const noexcept {
111 return m_budget;
112 }
113
114 constexpr void VideoFrames(QueueLimit limit) noexcept { m_video_frames = limit; }
115 constexpr void AudioFrames(QueueLimit limit) noexcept { m_audio_frames = limit; }
116 constexpr void Packets(QueueLimit limit) noexcept { m_packets = limit; }
117 constexpr void DemuxPending(QueueLimit limit) noexcept { m_demux_pending = limit; }
118
120 m_queue_bytes = limit;
121 }
122
123 void Budget(const StormByte::Buffer::ByteBudget& budget) noexcept {
124 m_budget = budget;
125 }
126
127 constexpr bool Valid() const noexcept {
128 return m_video_frames.Valid(2)
129 && m_audio_frames.Valid(1)
130 && m_packets.Valid(1)
131 && m_demux_pending.Valid(1);
132 }
133
134 private:
135 QueueLimit m_video_frames;
136 QueueLimit m_audio_frames;
137 QueueLimit m_packets;
138 QueueLimit m_demux_pending;
141 };
142}
143
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Buffer::Bridge)
Queue element-cap overrides shared by Plans and Transcoders.
Definition buffering.hxx:99
constexpr void VideoFrames(QueueLimit limit) noexcept
Definition buffering.hxx:114
constexpr QueueLimit DemuxPending() const noexcept
Definition buffering.hxx:104
constexpr void DemuxPending(QueueLimit limit) noexcept
Definition buffering.hxx:117
void Budget(const StormByte::Buffer::ByteBudget &budget) noexcept
Definition buffering.hxx:123
constexpr QueueLimit Packets() const noexcept
Definition buffering.hxx:103
void QueueBytes(StormByte::Safe::Optional< StormByte::ByteSize > limit) noexcept
Definition buffering.hxx:119
const StormByte::Buffer::ByteBudget & Budget() const noexcept
Definition buffering.hxx:110
constexpr QueueLimit AudioFrames() const noexcept
Definition buffering.hxx:102
constexpr QueueLimit VideoFrames() const noexcept
Definition buffering.hxx:101
constexpr void Packets(QueueLimit limit) noexcept
Definition buffering.hxx:116
constexpr void AudioFrames(QueueLimit limit) noexcept
Definition buffering.hxx:115
const StormByte::Safe::Optional< StormByte::ByteSize > & QueueBytes() const noexcept
Definition buffering.hxx:106
constexpr bool Valid() const noexcept
Definition buffering.hxx:127
Automatic, explicitly bounded, or unlimited queue element cap.
Definition buffering.hxx:40
constexpr Mode GetMode() const noexcept
Definition buffering.hxx:62
constexpr QueueLimit() noexcept=default
constexpr StormByte::Size Resolve(StormByte::Size automatic) const noexcept
Definition buffering.hxx:74
constexpr bool Valid(StormByte::Size minimum) const noexcept
Definition buffering.hxx:70
static constexpr QueueLimit Automatic() noexcept
Definition buffering.hxx:50
static constexpr QueueLimit Bounded(StormByte::Size value) noexcept
Definition buffering.hxx:58
static constexpr QueueLimit Unlimited() noexcept
Definition buffering.hxx:54
constexpr StormByte::Size Value() const noexcept
Definition buffering.hxx:66
Demux / decode / filter / encode / mux types.
#define STORMBYTE_MULTIMEDIA_PUBLIC
Definition visibility.h:61