StormByte C++ Library: Multimedia module 0.0.9999
StormByte-Multimedia is a StormByte library module for parsing configuration files
Loading...
Searching...
No Matches
step.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 as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Multimedia source in this
20 * file. Third-party components — including FFmpeg and embedded trained data —
21 * remain under their own licenses and are not covered by the commercial grant.
22 *
23 * Neither license grants any patent rights. Any patent licenses required
24 * to use this software or third-party components must be obtained separately
25 * from the patent holders.
26 *
27 * StormByte-Multimedia is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 *
32 * You should have received a copy of the GNU Lesser General Public License
33 * version 3 along with StormByte-Multimedia. If not, see
34 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
35 *
36 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
37 */
38
39#pragma once
40
41#include <StormByte/buffer/sink.hxx>
42#include <StormByte/logger/log.hxx>
47
48#include <condition_variable>
49#include <cstddef>
50#include <cstdint>
51#include <limits>
52#include <memory>
53#include <mutex>
54#include <optional>
55#include <string>
56#include <string_view>
57
59 class Host;
60 class Pipe;
61 class Pumper;
62 class Worker;
63}
64
72 class Decoder;
73 class Demuxer;
74 class Encoder;
75 class Muxer;
76 class Remuxer;
77 class Route;
78 class Filters;
79 class Step;
80
94
115 friend class Demuxer;
116 friend class Muxer;
117 friend class Remuxer;
118 friend class Route;
119 friend class Filters;
120 friend Decoder& operator>>(Demuxer& demuxer, Decoder& decoder) noexcept;
121 friend Demuxer& operator>>(class Plan&& plan, Demuxer& demuxer) noexcept;
122 friend Encoder& operator>>(Encoder& encoder, Muxer& muxer) noexcept;
123 friend Muxer& operator>>(Demuxer& demuxer, Muxer& muxer) noexcept;
124 friend Remuxer& operator>>(Demuxer& demuxer, Remuxer& remuxer) noexcept;
125 friend Remuxer& operator>>(Remuxer& remuxer, Muxer& muxer) noexcept;
126 friend Step& operator>>(Step& from, Step& to) noexcept;
127
128 public:
134 Step(const Step& other) = delete;
135 Step(Step&& other) noexcept = delete;
136
144 virtual ~Step() noexcept;
145
146 Step& operator=(const Step& other) = delete;
147 Step& operator=(Step&& other) noexcept = delete;
148
162 std::condition_variable& Wake() noexcept;
163
177 inline const std::shared_ptr<class Plan>& Plan() const noexcept {
178 return m_plan;
179 }
180
194 inline const Kinds& Receives() const noexcept {
195 return m_receives;
196 }
197
202 inline const Kinds& Produces() const noexcept {
203 return m_produces;
204 }
205
210 State Status() const noexcept;
211
221 virtual bool Ready() const noexcept;
222
230 void Stop() noexcept;
231
239 virtual std::size_t InputCeiling() const noexcept;
240
254 bool Failed() const noexcept;
255
260 const std::optional<std::string>& Error() const noexcept;
261
271 void Fail(std::string reason) noexcept;
272
277 protected:
278
293 Step(std::shared_ptr<StormByte::Logger::Log> log,
294 enum Producer name,
295 Kinds receives, Kinds produces) noexcept;
296
313 void Emit(Item::PointerType item) noexcept;
314
324 Item::PointerType CloneItem(const Item& item) const noexcept;
325
329 void Wait() noexcept;
330
337 void Launch() noexcept;
338
348 void Halt() noexcept;
349
359 class Join final {
360 public:
361 explicit Join(Step& step) noexcept: m_step(step) {}
362 Join(const Join&) = delete;
363 Join(Join&&) noexcept = delete;
364 ~Join() noexcept {
365 m_step.Halt();
366 }
367 Join& operator=(const Join&) = delete;
368 Join& operator=(Join&&) noexcept = delete;
369
370 private:
371 Step& m_step;
372 };
373
378 bool Stopping() const noexcept;
379
384 void RecordWork(std::int64_t microseconds) noexcept;
385
390 std::int64_t LastWork() const noexcept;
391
395 void DumpWork() noexcept;
396
401 Backend::Pipeline::Host& Face() noexcept;
402
410 void Mount(std::unique_ptr<Backend::Pipeline::Pumper> pumper,
411 std::unique_ptr<Backend::Pipeline::Worker> worker) noexcept;
412
427 virtual std::string Label() const noexcept;
428
440 virtual void Log(StormByte::Logger::Level level, std::string_view message) noexcept;
441
446 std::shared_ptr<StormByte::Logger::Log> m_log;
447 enum Producer m_name;
448 Kinds m_receives;
449 Kinds m_produces;
450
451 private:
452 std::condition_variable m_wake;
453 std::unique_ptr<Backend::Pipeline::Pipe> m_pipe;
454
455 protected:
460 Backend::Pipeline::Pipe& pipe() noexcept;
461
466 const Backend::Pipeline::Pipe& pipe() const noexcept;
467
468 private:
469 class Surface;
470
474 void CloseHoppers() noexcept;
475
476 std::unique_ptr<Surface> m_surface;
477 std::unique_ptr<Backend::Pipeline::Pumper> m_pumper;
478 std::shared_ptr<class Plan> m_plan;
479 std::mutex m_wait;
480 std::optional<std::string> m_error;
481 bool m_exhausted;
482 std::uint64_t m_workN;
483 std::int64_t m_workMin;
484 std::int64_t m_workMax;
485 std::int64_t m_lastWork;
486 };
487}
Decodes packets of one origin track into frames.
Definition decoder.hxx:141
Reads interleaved packets from a File origin.
Definition demuxer.hxx:121
Encodes frames of one output track into packets.
Definition encoder.hxx:103
Optional facade: Between stretches, Add filters, Close.
Definition filters.hxx:76
Facade shared by Frame and Packet.
Definition item.hxx:91
Bitmask of Kind.
Definition typedefs.hxx:148
Writes interleaved packets to a destination container.
Definition muxer.hxx:150
Closed job intention: source File, destination container and tracks that enter the tube.
Definition plan.hxx:76
Forwards compressed packets of one origin track to the muxer.
Definition remuxer.hxx:88
Owns the filter chain of one origin track and two ends.
Definition route.hxx:90
Last data member of every most-derived Step.
Definition step.hxx:359
Join & operator=(const Join &)=delete
Join(Step &step) noexcept
Definition step.hxx:361
Join & operator=(Join &&) noexcept=delete
One stage with a Backend::Pipeline::Pipe (in / out).
Definition step.hxx:114
virtual ~Step() noexcept
Destructor.
Step(const Step &other)=delete
friend Muxer & operator>>(Demuxer &demuxer, Muxer &muxer) noexcept
Binds demuxer as remux origin and forwards its attachments.
friend Step & operator>>(Step &from, Step &to) noexcept
Shares Plan and binds every output hopper of from onto to.
const Kinds & Produces() const noexcept
Kinds this step emits.
Definition step.hxx:202
friend Remuxer & operator>>(Demuxer &demuxer, Remuxer &remuxer) noexcept
Binds origin track remuxer.In() from demuxer onto remuxer.
Step(Step &&other) noexcept=delete
friend Demuxer & operator>>(class Plan &&plan, Demuxer &demuxer) noexcept
Hands plan to demuxer.
friend Decoder & operator>>(Demuxer &demuxer, Decoder &decoder) noexcept
Binds one origin track of demuxer to decoder.
const Kinds & Receives() const noexcept
Kinds this step consumes.
Definition step.hxx:194
State Status() const noexcept
Current lifecycle value.
friend Encoder & operator>>(Encoder &encoder, Muxer &muxer) noexcept
Reserves encoder as an output track of muxer.
friend Remuxer & operator>>(Remuxer &remuxer, Muxer &muxer) noexcept
Reserves remuxer as an output track of muxer.
Multimedia-owned pipeline stages and unit holders.
Demux / decode / filter / encode / mux types.
Decoder & operator>>(Demuxer &demuxer, Decoder &decoder) noexcept
Binds one origin track of demuxer to decoder.
State
Definition typedefs.hxx:211
Producer
Definition typedefs.hxx:105
#define STORMBYTE_MULTIMEDIA_PUBLIC
Imported symbol.
Definition visibility.h:47