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 <atomic>
49#include <cstddef>
50#include <cstdint>
51#include <memory>
52#include <optional>
53#include <string>
54
62 class Decoder;
63 class Frame;
64}
65
69
77 class Decoder;
78 class Demuxer;
79 class Filters;
80 class Frame;
81 class Packet;
82 class Route;
83
88 enum class DecoderFlag: std::uint8_t {
90 };
91
96 class STORMBYTE_MULTIMEDIA_PUBLIC DecoderFlags: public StormByte::Bitmask<DecoderFlags, DecoderFlag> {
97 public:
98 using Bitmask::Bitmask;
99 };
100
105
113
151 friend class Backend::Pipeline::Decoder;
152 friend class Backend::Pipeline::Detail::Worker::Decode;
153 friend class Demuxer;
154 friend class Filters;
155 friend class Route;
156 friend Decoder& operator>>(Demuxer& demuxer, Decoder& decoder) noexcept;
157
158 public:
163
173 explicit Decoder(std::shared_ptr<StormByte::Logger::Log> log,
174 int track, DecoderFlags flags = DecoderFlags{}) noexcept;
175
180 Decoder(const Decoder& other) = delete;
181
186 Decoder(Decoder&& other) noexcept = delete;
187
191 ~Decoder() noexcept override;
192
198 Decoder& operator=(const Decoder& other) = delete;
199
205 Decoder& operator=(Decoder&& other) noexcept = delete;
206
211 explicit operator bool() const noexcept;
212
216
221
226 inline int Index() const noexcept {
227 return m_index;
228 }
229
234 std::size_t InputCeiling() const noexcept override;
235
240 inline const DecoderFlags& Flags() const noexcept {
241 return m_flags;
242 }
243
248 inline void Flags(DecoderFlags flags) noexcept {
249 m_flags = flags;
250 }
251
256 inline const std::optional<std::string>& Language() const noexcept {
257 return m_language;
258 }
259
264 inline const std::optional<std::string>& Title() const noexcept {
265 return m_title;
266 }
267
271
276
281 inline const std::optional<std::string>& Implementation() const noexcept {
282 return m_implementation;
283 }
284
289 void Implementation(std::string name) noexcept;
290
295 inline const Features& Require() const noexcept {
296 return m_require;
297 }
298
303 inline void Require(Features features) noexcept {
304 m_require = features;
305 }
306
311 inline const Features& Capabilities() const noexcept {
312 return m_capabilities;
313 }
314
318
319 private:
324 struct EncodeLook {};
325
330 struct RemuxLook {};
331
336 struct SourceLook {};
337
349 Decoder(std::shared_ptr<StormByte::Logger::Log> log,
350 int track, EncodeLook tag) noexcept;
351
362 Decoder(std::shared_ptr<StormByte::Logger::Log> log,
363 int track, RemuxLook tag) noexcept;
364
375 Decoder(std::shared_ptr<StormByte::Logger::Log> log,
376 int track, SourceLook tag) noexcept;
377
378 using Step::Log;
379
386 std::string Label() const noexcept override;
387
392 void Bind(std::unique_ptr<Backend::Pipeline::Decoder> backend) noexcept;
393
398 std::unique_ptr<Backend::Pipeline::Decoder> OpenOrigin() noexcept;
399
405 void Stamp(std::optional<std::string> language, std::optional<std::string> title) noexcept;
406
411 void AttachOrigin(Demuxer& demuxer) noexcept;
412
420 void MeasureSourceClosed() noexcept;
421
429 void DrainMeasure() noexcept;
430
438 bool ResetAfterMeasure() noexcept;
439
445 void Attach(Frame& frame, std::unique_ptr<Backend::Pipeline::Frame> backend) noexcept;
446
452 void CloseCue(Frame& frame, Property::Duration duration) noexcept;
453
458 void StampLineage(Frame& frame) noexcept;
459
465 bool OpenLook(const Packet& packet) noexcept;
466
477 void StampLook(Frame& frame) noexcept;
478
486 void BindAnalytics(Filters& filters) noexcept;
487
491 bool WakeNow() const noexcept override;
492
496 void AfterWait() noexcept override;
497
498 int m_index;
499 DecoderFlags m_flags;
500 std::optional<std::string> m_language;
501 std::optional<std::string> m_title;
502 std::optional<std::string> m_implementation;
503 Features m_require;
504 Features m_capabilities;
505 Demuxer* m_origin = nullptr;
506 Filters* m_analytics = nullptr;
507 std::unique_ptr<Backend::Pipeline::Decoder> m_backend;
508 std::optional<std::uint64_t> m_serial;
509 std::uint64_t m_part;
510 std::optional<Property::Duration> m_inDts;
511 bool m_look = false;
512 std::optional<Producer> m_lookStamp;
513 std::atomic<bool> m_measureClosed{false};
514 std::atomic<bool> m_measureDrained{false};
515 Join m_join{*this};
516 };
517}
Bitmask of Feature flags.
Definition features.hxx:56
Bitmask of DecoderFlag.
Definition decoder.hxx:96
Decodes packets of one origin track into frames.
Definition decoder.hxx:150
void Flags(DecoderFlags flags) noexcept
Replaces flags (before demuxer >> decoder).
Definition decoder.hxx:248
int Index() const noexcept
Bound origin track.
Definition decoder.hxx:226
void Require(Features features) noexcept
Replaces extra required Feature bits.
Definition decoder.hxx:303
friend class Backend::Pipeline::Decoder
Definition decoder.hxx:151
const Features & Capabilities() const noexcept
Features of the opened implementation.
Definition decoder.hxx:311
const std::optional< std::string > & Title() const noexcept
Stream title tag copied from the origin File.
Definition decoder.hxx:264
const Features & Require() const noexcept
Extra required Feature bits.
Definition decoder.hxx:295
friend Decoder & operator>>(Demuxer &demuxer, Decoder &decoder) noexcept
Binds one origin track of demuxer to decoder.
Decoder(Decoder &&other) noexcept=delete
Move constructor.
friend class Route
Definition decoder.hxx:155
void Implementation(std::string name) noexcept
Pins an FFmpeg decoder name (before demuxer >> decoder).
const DecoderFlags & Flags() const noexcept
Flags.
Definition decoder.hxx:240
Decoder(std::shared_ptr< StormByte::Logger::Log > log, int track, DecoderFlags flags=DecoderFlags{}) noexcept
Decoder for one origin track.
Decoder(const Decoder &other)=delete
Copy constructor.
friend class Filters
Definition decoder.hxx:154
const std::optional< std::string > & Implementation() const noexcept
Pinned FFmpeg decoder name, if any.
Definition decoder.hxx:281
friend class Demuxer
Definition decoder.hxx:153
std::size_t InputCeiling() const noexcept override
Ceiling of the decoder input hopper.
~Decoder() noexcept override
Destructor.
const std::optional< std::string > & Language() const noexcept
Stream language tag copied from the origin File.
Definition decoder.hxx:256
Reads interleaved packets from a File origin.
Definition demuxer.hxx:142
Step(const Step &other)=delete
Multimedia-owned pipeline stages and unit holders.
Definition AVFormatContext.hxx:52
Demux / decode / filter / encode / mux types.
DecoderFlag
Decoder behaviour bits.
Definition decoder.hxx:88
@ HeuristicsHDR10
Definition decoder.hxx:89
Decoder & operator>>(Demuxer &demuxer, Decoder &decoder) noexcept
Binds one origin track of demuxer to decoder.
@ Demuxer
Demuxer
Definition typedefs.hxx:106
@ Route
Route
Definition typedefs.hxx:110
@ Decoder
Decoder
Definition typedefs.hxx:107
@ Filters
Filters
Definition typedefs.hxx:111
const DecoderFlags Heuristics
All current heuristic bits.
Definition decoder.hxx:104
@ Frame
StormByte::Multimedia::Pipeline::Frame
Definition typedefs.hxx:80
@ Packet
StormByte::Multimedia::Pipeline::Packet
Definition typedefs.hxx:79
#define STORMBYTE_MULTIMEDIA_PUBLIC
Imported symbol.
Definition visibility.h:47