StormByte-Multimedia 3.3.2
C++26 multimedia processing module of the StormByte suite
Loading...
Searching...
No Matches
decoder.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 * A written StormByte commercial agreement may license this original source
24 * on terms other than the LGPL, including specific use, distribution or
25 * linking arrangements such as static linking, as stated in that agreement.
26 * It does not grant rights to dependencies or waive their license conditions.
27 * Enabling WITH_GPL or WITH_NONFREE may include components with separate
28 * obligations for modification, linking (static or dynamic), redistribution
29 * or works that incorporate them. The person modifying, linking, packaging or
30 * distributing the resulting work is responsible for determining and meeting
31 * all applicable requirements, including any needed patent permissions.
32 * A StormByte commercial agreement does not provide those rights for GPL or
33 * nonfree components.
34 *
35 * Neither license grants any patent rights. Any patent licenses required
36 * to use this software or third-party components must be obtained separately
37 * from the patent holders.
38 *
39 * StormByte-Multimedia is distributed in the hope that it will be useful,
40 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 * GNU Lesser General Public License for more details.
43 *
44 * You should have received a copy of the GNU Lesser General Public License
45 * version 3 along with StormByte-Multimedia. If not, see
46 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
47 *
48 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
49 */
50
51#pragma once
52
53#include <StormByte/size.hxx>
54#include <StormByte/bitmask.hxx>
55#include <StormByte/logger/log.hxx>
61#include <StormByte/safe/atomic.hxx>
62#include <StormByte/safe/optional.hxx>
63#include <StormByte/safe/pointers.hxx>
64#include <StormByte/safe/string.hxx>
65
66#include <cstddef>
67#include <cstdint>
68#include <string>
69
77 class Decoder;
78 class Demuxer;
79 class Frame;
80}
81
85
93 class Decoder;
94 class Demuxer;
95 class Encoder;
96 class Filters;
97 class Frame;
98 class Packet;
99 class Route;
100
105 enum class DecoderFlag: std::uint8_t {
107 };
108
113 class STORMBYTE_MULTIMEDIA_PUBLIC DecoderFlags: public StormByte::Bitmask<DecoderFlags, DecoderFlag> {
114 public:
115 using Bitmask::Bitmask;
116 };
117
119
127
149 friend class Backend::Pipeline::Decoder;
150 friend class Backend::Pipeline::Demuxer;
151 friend class Backend::Pipeline::Detail::Worker::Decode;
152 friend class Demuxer;
153 friend class Filters;
154 friend class Route;
155 friend Decoder& operator>>(Demuxer& demuxer, Decoder& decoder) noexcept;
156
157 public:
162
173 int track, DecoderFlags flags = DecoderFlags{});
174
179 Decoder(const Decoder& other) = delete;
180
185 Decoder(Decoder&& other) noexcept = delete;
186
190 ~Decoder() noexcept override;
191
197 Decoder& operator=(const Decoder& other) = delete;
198
204 Decoder& operator=(Decoder&& other) noexcept = delete;
205
210 explicit operator bool() const noexcept;
211
215
220
225 inline int Index() const noexcept {
226 return m_index;
227 }
228
233 StormByte::Size InputCeiling() const noexcept override;
234
239 inline const DecoderFlags& Flags() const noexcept {
240 return m_flags;
241 }
242
247 inline void Flags(DecoderFlags flags) noexcept {
248 m_flags = flags;
249 }
250
256 return m_language;
257 }
258
264 return m_title;
265 }
266
270
275
281 return m_implementation;
282 }
283
290
295 inline DecodeAcceleration Acceleration() const noexcept {
296 return m_acceleration;
297 }
298
303 inline void Acceleration(DecodeAcceleration acceleration) noexcept {
304 m_acceleration = acceleration;
305 }
306
311 inline const Features& Require() const noexcept {
312 return m_require;
313 }
314
319 inline void Require(Features features) noexcept {
320 m_require = features;
321 }
322
327 inline const Features& Capabilities() const noexcept {
328 return m_capabilities;
329 }
330
334
335 private:
336 void HardwareFallback() noexcept;
337
342 struct EncodeLook {};
343
348 struct RemuxLook {};
349
354 struct SourceLook {};
355
356 public:
369 int track, EncodeLook tag);
370
382 int track, RemuxLook tag);
383
395 int track, SourceLook tag);
396
397 private:
398 using Step::Log;
399
406 StormByte::Safe::String Label() const override;
407
412 void Bind(StormByte::Safe::Unique<Backend::Pipeline::Decoder> backend) noexcept;
413
419
425 void Stamp(StormByte::Safe::Optional<StormByte::Safe::String> language,
426 StormByte::Safe::Optional<StormByte::Safe::String> title) noexcept;
427
431 void InheritSourceTags();
432
437 void AttachOrigin(Demuxer& demuxer) noexcept;
438
443 bool WaitForPlan() noexcept;
444
449 bool SetupPlan() noexcept;
450
458 void MeasureSourceClosed() noexcept;
459
467 void DrainMeasure() noexcept;
468
476 bool ResetAfterMeasure() noexcept;
477
483 void Attach(Frame& frame, StormByte::Safe::Unique<Backend::Pipeline::Frame> backend) noexcept;
484
490 void CloseCue(Frame& frame, Property::Duration duration) noexcept;
491
496 void StampLineage(Frame& frame) noexcept;
497
503 bool OpenLook(const Packet& packet) noexcept;
504
515 void StampLook(Frame& frame) noexcept;
516
524 void BindAnalytics(Filters& filters) noexcept;
525
529 bool WakeNow() const noexcept override;
530
534 void AfterWait() noexcept override;
535
536 int m_index;
537 int m_sourceIndex = -1;
538 Encoder* m_encodeSource = nullptr;
539 DecoderFlags m_flags;
540 StormByte::Safe::Optional<StormByte::Safe::String> m_language;
541 StormByte::Safe::Optional<StormByte::Safe::String> m_title;
542 StormByte::Safe::Optional<StormByte::Safe::String> m_implementation;
543 bool m_implementationConfigured = false;
544 Features m_require;
545 Features m_capabilities;
546 DecodeAcceleration m_acceleration = DecodeAcceleration::Auto;
547 Demuxer* m_origin = nullptr;
548 Filters* m_analytics = nullptr;
549 StormByte::Safe::Unique<Backend::Pipeline::Decoder> m_backend;
550 StormByte::Safe::Optional<std::uint64_t> m_serial;
551 std::uint64_t m_part;
552 StormByte::Safe::Optional<Property::Duration> m_inDts;
553 std::uint32_t m_pass = 0;
554 bool m_look = false;
555 StormByte::Safe::Optional<Producer> m_lookStamp;
556 StormByte::Safe::Atomic<bool> m_measureClosed{false};
557 StormByte::Safe::Atomic<bool> m_measureDrained{false};
558 Join m_join{*this};
559 };
560}
561
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Buffer::Bridge)
constexpr Bitmask() noexcept
Bitmask of Feature flags.
Definition features.hxx:77
Bitmask of DecoderFlag.
Definition decoder.hxx:113
Decodes packets of one origin track into frames.
Definition decoder.hxx:148
void Flags(DecoderFlags flags) noexcept
Replaces flags (before demuxer >> decoder).
Definition decoder.hxx:247
int Index() const noexcept
Bound origin track.
Definition decoder.hxx:225
void Require(Features features) noexcept
Replaces extra required Feature bits.
Definition decoder.hxx:319
DecodeAcceleration Acceleration() const noexcept
Video decode acceleration policy, independent of encoder selection.
Definition decoder.hxx:295
const StormByte::Safe::Optional< StormByte::Safe::String > & Title() const noexcept
Stream title tag copied from the origin File.
Definition decoder.hxx:263
friend class Backend::Pipeline::Decoder
Definition decoder.hxx:149
Decoder(StormByte::Safe::Shared< StormByte::Logger::Log > log, int track, DecoderFlags flags=DecoderFlags{})
Decoder for one origin track.
const StormByte::Safe::Optional< StormByte::Safe::String > & Language() const noexcept
Stream language tag copied from the origin File.
Definition decoder.hxx:255
void Acceleration(DecodeAcceleration acceleration) noexcept
Sets video decode acceleration before the decoder is wired.
Definition decoder.hxx:303
const Features & Capabilities() const noexcept
Features of the opened implementation.
Definition decoder.hxx:327
StormByte::Size InputCeiling() const noexcept override
Maximum number of queued input packets.
const Features & Require() const noexcept
Extra required Feature bits.
Definition decoder.hxx:311
friend Decoder & operator>>(Demuxer &demuxer, Decoder &decoder) noexcept
Binds one origin track of demuxer to decoder.
Decoder(StormByte::Safe::Shared< StormByte::Logger::Log > log, int track, EncodeLook tag)
Post-encode recon for Analytics.
Decoder(Decoder &&other) noexcept=delete
Move constructor.
friend class Route
Definition decoder.hxx:154
const DecoderFlags & Flags() const noexcept
Flags.
Definition decoder.hxx:239
Decoder(const Decoder &other)=delete
Copy constructor.
friend class Filters
Definition decoder.hxx:153
Decoder(StormByte::Safe::Shared< StormByte::Logger::Log > log, int track, SourceLook tag)
Packet-origin recon for Analytics (Demuxer remux stretch).
friend class Backend::Pipeline::Demuxer
Definition decoder.hxx:150
void Implementation(StormByte::Safe::String name) noexcept
Pins an FFmpeg decoder name (before demuxer >> decoder).
~Decoder() noexcept override
Destructor.
const StormByte::Safe::Optional< StormByte::Safe::String > & Implementation() const noexcept
Pinned FFmpeg decoder name, if any.
Definition decoder.hxx:280
Decoder(StormByte::Safe::Shared< StormByte::Logger::Log > log, int track, RemuxLook tag)
Post-remux recon for Analytics.
Reads interleaved compressed packets from the Plan reader.
Definition demuxer.hxx:148
Encodes frames of one output track into packets.
Definition encoder.hxx:145
One decoded access unit.
Definition frame.hxx:103
One compressed access unit.
Definition packet.hxx:102
Step(const Step &other)=delete
Copy construction is disabled.
virtual void Log(StormByte::Logger::Level level, std::string_view message) noexcept
Writes one log line on the scoped module logger.
Producer
Named stage of the tube.
Definition typedefs.hxx:136
@ Route
A configured connection between pipeline stages.
Definition typedefs.hxx:141
@ Filters
Filters stage.
Definition typedefs.hxx:142
@ Frame
Decoded StormByte::Multimedia::Pipeline::Frame.
Definition typedefs.hxx:111
Pipeline Demux / decode / filter / encode / mux types.
Media property value types.
Internal pipeline workers.
Definition decoder.hxx:82
Multimedia-owned pipeline stages and unit holders.
Demux / decode / filter / encode / mux types.
DecoderFlag
Decoder behaviour bits.
Definition decoder.hxx:105
@ HeuristicsHDR10
Definition decoder.hxx:106
@ Packet
Packet filter (Filter::Packet and derived).
Definition telemetry.hxx:409
Decoder & operator>>(Demuxer &demuxer, Decoder &decoder) noexcept
Binds one origin track of demuxer to decoder.
const DecoderFlags Heuristics
All current heuristic bits.
Definition decoder.hxx:118
@ Demuxer
Container reader; owns the demux pending queues.
Definition telemetry.hxx:393
@ Encoder
Track encoder feeding the muxer.
Definition telemetry.hxx:396
@ Decoder
Track decoder feeding a decode/encode lane.
Definition telemetry.hxx:394
DecodeAcceleration
Selects whether video decoders may use an available FFmpeg hardware backend.
Definition decode_policy.hxx:43
Root namespace of the StormByte C++ suite.
STL namespace.
#define STORMBYTE_MULTIMEDIA_PUBLIC
Definition visibility.h:61