StormByte C++ Library: Multimedia module 0.0.9999
StormByte-Multimedia is a StormByte library module for parsing configuration files
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 * 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/bitmask.hxx>
42#include <StormByte/logger/log.hxx>
47
48#include <cstddef>
49#include <cstdint>
50#include <memory>
51#include <optional>
52#include <string>
53
61 class Decoder;
62}
63
67
75 class Decoder;
76 class Demuxer;
77 class Frame;
78 class Packet;
79 class Route;
80
85 enum class DecoderFlag: std::uint8_t {
86 HeuristicsHDR10 = 1u << 0
87 };
88
93 class STORMBYTE_MULTIMEDIA_PUBLIC DecoderFlags: public StormByte::Bitmask<DecoderFlags, DecoderFlag> {
94 public:
95 using Bitmask::Bitmask;
96 };
97
102
110
142 friend class Backend::Pipeline::Decoder;
143 friend class Backend::Pipeline::Detail::Worker::Decode;
144 friend class Demuxer;
145 friend class Route;
146 friend Decoder& operator>>(Demuxer& demuxer, Decoder& decoder) noexcept;
147
148 public:
163 explicit Decoder(std::shared_ptr<StormByte::Logger::Log> log,
164 int track, DecoderFlags flags = DecoderFlags{}) noexcept;
165
170 Decoder(const Decoder& other) = delete;
171
176 Decoder(Decoder&& other) noexcept = delete;
177
181 ~Decoder() noexcept override;
182
188 Decoder& operator=(const Decoder& other) = delete;
189
195 Decoder& operator=(Decoder&& other) noexcept = delete;
196
201 explicit operator bool() const noexcept;
202
216 inline int Index() const noexcept {
217 return m_index;
218 }
219
224 std::size_t InputCeiling() const noexcept override {
225 return Ceiling;
226 }
227
232 inline const DecoderFlags& Flags() const noexcept {
233 return m_flags;
234 }
235
240 inline void Flags(DecoderFlags flags) noexcept {
241 m_flags = flags;
242 }
243
248 inline const std::optional<std::string>& Language() const noexcept {
249 return m_language;
250 }
251
256 inline const std::optional<std::string>& Title() const noexcept {
257 return m_title;
258 }
259
273 inline const std::optional<std::string>& Implementation() const noexcept {
274 return m_implementation;
275 }
276
281 void Implementation(std::string name) noexcept;
282
287 inline const Features& Require() const noexcept {
288 return m_require;
289 }
290
295 inline void Require(Features features) noexcept {
296 m_require = features;
297 }
298
303 inline const Features& Capabilities() const noexcept {
304 return m_capabilities;
305 }
306
311 private:
316 struct EncodeLook {};
317
322 struct RemuxLook {};
323
328 struct SourceLook {};
329
341 Decoder(std::shared_ptr<StormByte::Logger::Log> log,
342 int track, EncodeLook tag) noexcept;
343
354 Decoder(std::shared_ptr<StormByte::Logger::Log> log,
355 int track, RemuxLook tag) noexcept;
356
367 Decoder(std::shared_ptr<StormByte::Logger::Log> log,
368 int track, SourceLook tag) noexcept;
369
370 using Step::Log;
371
378 std::string Label() const noexcept override;
379
384 void Bind(std::unique_ptr<Backend::Pipeline::Decoder> backend) noexcept;
385
390 std::unique_ptr<Backend::Pipeline::Decoder> OpenOrigin() noexcept;
391
397 void Stamp(std::optional<std::string> language, std::optional<std::string> title) noexcept;
398
403 void AttachOrigin(Demuxer& demuxer) noexcept;
404
410 void Attach(Frame& frame, std::unique_ptr<Backend::Pipeline::Frame> backend) noexcept;
411
417 void CloseCue(Frame& frame, Property::Duration duration) noexcept;
418
423 void StampLineage(Frame& frame) noexcept;
424
430 bool OpenLook(const Packet& packet) noexcept;
431
440 void StampLook(Frame& frame) noexcept;
441
442 static constexpr std::size_t Ceiling = 32;
443 int m_index;
444 DecoderFlags m_flags;
445 std::optional<std::string> m_language;
446 std::optional<std::string> m_title;
447 std::optional<std::string> m_implementation;
448 Features m_require;
449 Features m_capabilities;
450 Demuxer* m_origin = nullptr;
451 std::unique_ptr<Backend::Pipeline::Decoder> m_backend;
452 std::optional<std::uint64_t> m_serial;
453 std::uint64_t m_part;
454 std::optional<Property::Duration> m_inDts;
455 bool m_look = false;
456 std::optional<Producer> m_lookStamp;
457 Join m_join{*this};
458 };
459}
Bitmask of Feature flags.
Definition features.hxx:56
Bitmask of DecoderFlag.
Definition decoder.hxx:93
Decodes packets of one origin track into frames.
Definition decoder.hxx:141
void Flags(DecoderFlags flags) noexcept
Replaces flags (before demuxer >> decoder).
Definition decoder.hxx:240
void Require(Features features) noexcept
Replaces extra required Feature bits.
Definition decoder.hxx:295
const Features & Capabilities() const noexcept
Features of the opened implementation.
Definition decoder.hxx:303
const std::optional< std::string > & Title() const noexcept
Stream title tag copied from the origin File.
Definition decoder.hxx:256
const Features & Require() const noexcept
Extra required Feature bits.
Definition decoder.hxx:287
Decoder(Decoder &&other) noexcept=delete
Move constructor.
void Implementation(std::string name) noexcept
Pins an FFmpeg decoder name (before demuxer >> decoder).
const DecoderFlags & Flags() const noexcept
Flags.
Definition decoder.hxx:232
Decoder(std::shared_ptr< StormByte::Logger::Log > log, int track, DecoderFlags flags=DecoderFlags{}) noexcept
Decoder for one origin track.
friend Decoder & operator>>(Demuxer &demuxer, Decoder &decoder) noexcept
Binds one origin track of demuxer to decoder.
Decoder(const Decoder &other)=delete
Copy constructor.
const std::optional< std::string > & Implementation() const noexcept
Pinned FFmpeg decoder name, if any.
Definition decoder.hxx:273
std::size_t InputCeiling() const noexcept override
Ceiling of the decoder input hopper.
Definition decoder.hxx:224
~Decoder() noexcept override
Destructor.
const std::optional< std::string > & Language() const noexcept
Stream language tag copied from the origin File.
Definition decoder.hxx:248
Reads interleaved packets from a File origin.
Definition demuxer.hxx:121
Owns the filter chain of one origin track and two ends.
Definition route.hxx:90
One stage with a Backend::Pipeline::Pipe (in / out).
Definition step.hxx:114
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.
DecoderFlag
Decoder behaviour bits.
Definition decoder.hxx:85
const DecoderFlags Heuristics
All current heuristic bits.
Definition decoder.hxx:101
#define STORMBYTE_MULTIMEDIA_PUBLIC
Imported symbol.
Definition visibility.h:47