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:
133
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
152
157
162 std::condition_variable& Wake() noexcept;
163
167
172
177 inline const std::shared_ptr<class Plan>& Plan() const noexcept {
178 return m_plan;
179 }
180
184
189
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
244
249
254 bool Failed() const noexcept;
255
260 const std::optional<std::string>& Error() const noexcept;
261
271 void Fail(std::string reason) noexcept;
272
276
277 protected:
278
283
293 Step(std::shared_ptr<StormByte::Logger::Log> log,
294 enum Producer name,
295 Kinds receives, Kinds produces) noexcept;
296
300
305
313 void Emit(Item::PointerType item) noexcept;
314
324 Item::PointerType CloneItem(const Item& item) const noexcept;
325
333 virtual void Wait() noexcept;
334
341 virtual bool WakeNow() const noexcept;
342
348 virtual void AfterWait() noexcept;
349
356 void Launch() noexcept;
357
367 void Halt() noexcept;
368
378 class Join final {
379 public:
380 explicit Join(Step& step) noexcept: m_step(step) {}
381 Join(const Join&) = delete;
382 Join(Join&&) noexcept = delete;
383 ~Join() noexcept {
384 m_step.Halt();
385 }
386 Join& operator=(const Join&) = delete;
387 Join& operator=(Join&&) noexcept = delete;
388
389 private:
390 Step& m_step;
391 };
392
397 bool Stopping() const noexcept;
398
403 void RecordWork(std::int64_t microseconds) noexcept;
404
409 std::int64_t LastWork() const noexcept;
410
414 void DumpWork() noexcept;
415
420 Backend::Pipeline::Host& Face() noexcept;
421
429 void Mount(std::unique_ptr<Backend::Pipeline::Pumper> pumper,
430 std::unique_ptr<Backend::Pipeline::Worker> worker) noexcept;
431
435
440
446 virtual std::string Label() const noexcept;
447
459 virtual void Log(StormByte::Logger::Level level, std::string_view message) noexcept;
460
464
465 std::shared_ptr<StormByte::Logger::Log> m_log;
469
470 private:
471 std::condition_variable m_wake;
472 std::unique_ptr<Backend::Pipeline::Pipe> m_pipe;
473
474 protected:
479 Backend::Pipeline::Pipe& pipe() noexcept;
480
485 const Backend::Pipeline::Pipe& pipe() const noexcept;
486
487 private:
488 class Surface;
489
493 void CloseHoppers() noexcept;
494
495 std::unique_ptr<Surface> m_surface;
496 std::unique_ptr<Backend::Pipeline::Pumper> m_pumper;
497 std::shared_ptr<class Plan> m_plan;
498 std::mutex m_wait;
499 std::optional<std::string> m_error;
500 bool m_exhausted;
501 std::uint64_t m_workN;
502 std::int64_t m_workMin;
503 std::int64_t m_workMax;
504 std::int64_t m_lastWork;
505 };
506}
Decodes packets of one origin track into frames.
Definition decoder.hxx:150
Reads interleaved packets from a File origin.
Definition demuxer.hxx:142
Encodes frames of one output track into packets.
Definition encoder.hxx:103
Optional facade: Between stretches, Add filters, Close.
Definition filters.hxx:102
Facade shared by Frame and Packet.
Definition item.hxx:96
Bitmask of Kind.
Definition typedefs.hxx:148
Writes interleaved packets to a destination container.
Definition muxer.hxx:155
Forwards compressed packets of one origin track to the muxer.
Definition remuxer.hxx:88
Join & operator=(const Join &)=delete
Join(Step &step) noexcept
Definition step.hxx:380
Join & operator=(Join &&) noexcept=delete
One stage with a Backend::Pipeline::Pipe (in / out).
Definition step.hxx:114
void DumpWork() noexcept
Writes min/max Process time at Debug.
friend Muxer & operator>>(Demuxer &demuxer, Muxer &muxer) noexcept
Binds demuxer as remux origin and forwards its attachments.
bool Stopping() const noexcept
Worker must return (Stop, Halt or Fail).
virtual std::size_t InputCeiling() const noexcept
Ceiling of this step's input hopper.
virtual ~Step() noexcept
Destructor.
Step(const Step &other)=delete
enum Producer m_name
UseLog leaf / default Label.
Definition step.hxx:466
const std::optional< std::string > & Error() const noexcept
Failure text.
friend Step & operator>>(Step &from, Step &to) noexcept
Shares Plan and binds every output hopper of from onto to.
void Stop() noexcept
Asks the worker to leave and closes all hoppers.
friend Remuxer & operator>>(Remuxer &remuxer, Muxer &muxer) noexcept
Reserves remuxer as an output track of muxer.
void Mount(std::unique_ptr< Backend::Pipeline::Pumper > pumper, std::unique_ptr< Backend::Pipeline::Worker > worker) noexcept
Takes ownership of pumper and binds worker.
Backend::Pipeline::Host & Face() noexcept
Owner surface for the Pumper and Worker.
virtual bool Ready() const noexcept
Whether this step can take work.
friend Demuxer & operator>>(class Plan &&plan, Demuxer &demuxer) noexcept
Hands plan to demuxer.
friend class Remuxer
Definition step.hxx:117
void Fail(std::string reason) noexcept
Marks Failed, closes all hoppers and wakes the worker.
std::shared_ptr< StormByte::Logger::Log > m_log
Scoped module logger (ThreadedLog preferred).
Definition step.hxx:465
friend Decoder & operator>>(Demuxer &demuxer, Decoder &decoder) noexcept
Binds one origin track of demuxer to decoder.
const Kinds & Produces() const noexcept
Kinds this step emits.
Definition step.hxx:202
const std::shared_ptr< class Plan > & Plan() const noexcept
Bound job intention, if any.
Definition step.hxx:177
std::int64_t LastWork() const noexcept
Duration of the last timed Process, or 0.
virtual void AfterWait() noexcept
Work on the waiting worker after Wait unblocks.
Step(Step &&other) noexcept=delete
friend Remuxer & operator>>(Demuxer &demuxer, Remuxer &remuxer) noexcept
Binds origin track remuxer.In() from demuxer onto remuxer.
friend class Route
Definition step.hxx:118
Kinds m_receives
Receives.
Definition step.hxx:467
bool Failed() const noexcept
Whether this step has failed.
const Kinds & Receives() const noexcept
Kinds this step consumes.
Definition step.hxx:194
virtual bool WakeNow() const noexcept
Extra reason to leave Wait.
virtual std::string Label() const noexcept
Display name of this step.
friend Encoder & operator>>(Encoder &encoder, Muxer &muxer) noexcept
Reserves encoder as an output track of muxer.
void Halt() noexcept
Stop and join the pumper.
friend class Filters
Definition step.hxx:119
friend class Demuxer
Definition step.hxx:115
void Launch() noexcept
Starts the pumper: Setup, Ready, Pump.
State Status() const noexcept
Current lifecycle value.
virtual void Wait() noexcept
Sleeps on Wake until hopper Ready, Failed, Stopping or WakeNow.
void RecordWork(std::int64_t microseconds) noexcept
Adds one Process duration to the step summary.
Item::PointerType CloneItem(const Item &item) const noexcept
Deep-copies item through Item::Clone.
friend class Muxer
Definition step.hxx:116
std::condition_variable & Wake() noexcept
Consumer condition variable.
Backend::Pipeline::Pipe & pipe() noexcept
In / out hoppers of this stage.
Kinds m_produces
Produces.
Definition step.hxx:468
void Emit(Item::PointerType item) noexcept
Write item to the Pipe (item >> pipe).
virtual void Log(StormByte::Logger::Level level, std::string_view message) noexcept
Writes one log line on the scoped module logger.
Multimedia-owned pipeline stages and unit holders.
Definition AVFormatContext.hxx:52
Definition AVFormatContext.hxx:52
Demux / decode / filter / encode / mux types.
State
Lifecycle of the stage thread.
Definition typedefs.hxx:211
Decoder & operator>>(Demuxer &demuxer, Decoder &decoder) noexcept
Binds one origin track of demuxer to decoder.
Producer
Named stage of the tube.
Definition typedefs.hxx:105
@ Route
Route
Definition typedefs.hxx:110
#define STORMBYTE_MULTIMEDIA_PUBLIC
Imported symbol.
Definition visibility.h:47