StormByte-Multimedia 3.3.2
C++26 multimedia processing module of the StormByte suite
Loading...
Searching...
No Matches
demuxer.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/buffer/fifo.hxx>
54#include <StormByte/buffer/io/buffered_file_reader.hxx>
55#include <StormByte/logger/log.hxx>
63#include <StormByte/safe/atomic.hxx>
64#include <StormByte/safe/condition_variable.hxx>
65#include <StormByte/safe/map.hxx>
66#include <StormByte/safe/mutex.hxx>
67#include <StormByte/safe/pointers.hxx>
68#include <StormByte/safe/vector.hxx>
69
70#include <atomic>
71#include <condition_variable>
72#include <cstdint>
73#include <memory>
74#include <mutex>
75#include <optional>
76#include <unordered_map>
77#include <vector>
78
83namespace StormByte {
90 namespace Multimedia {
91 namespace Backend {
92 class FileAvio;
93
94 namespace Pipeline {
95 class Decoder;
96 class Demuxer;
97 }
98
99 namespace Pipeline::Detail::Worker {
100 class Demux;
101 }
102 }
103
110 namespace Pipeline {
111 class Decoder;
112 class Demuxer;
113 class Filters;
114 class Muxer;
115 class Packet;
116 class Plan;
117 class Remuxer;
118
125 STORMBYTE_MULTIMEDIA_PUBLIC Decoder& operator>>(Demuxer& demuxer, Decoder& decoder) noexcept;
126
149 friend class Backend::Pipeline::Demuxer;
150 friend class Backend::Pipeline::Detail::Worker::Demux;
151 friend class Decoder;
152 friend class Filters;
153 friend class Muxer;
154 friend Decoder& operator>>(Demuxer& demuxer, Decoder& decoder) noexcept;
155 friend Demuxer& operator>>(class Plan&& plan, Demuxer& demuxer) noexcept;
157 friend Muxer& operator>>(Demuxer& demuxer, Muxer& muxer) noexcept;
158 friend Remuxer& operator>>(Demuxer& demuxer, Remuxer& remuxer) noexcept;
159
160 public:
165
171
179
184 Demuxer(const Demuxer& other) = delete;
185
190 Demuxer(Demuxer&& other) noexcept = delete;
191
195 ~Demuxer() noexcept override;
196
202 Demuxer& operator=(const Demuxer& other) = delete;
203
209 Demuxer& operator=(Demuxer&& other) noexcept = delete;
210
214
219 explicit operator bool() const noexcept;
220
225
232 bool Eof() const noexcept;
233
238 StormByte::Safe::Optional<Property::Duration> Position() const;
239
249 Progress::Pointer Progress() const noexcept;
250
254
255 private:
256 using Step::Log;
257
261 void WaitForPlan() noexcept;
262
269 void LatchDuration() noexcept;
270
277 void ReachedEof() noexcept;
278
285 void Measure(StormByte::Safe::Vector<int> tracks) noexcept;
286
291 bool Measuring() const noexcept;
292
299 bool WakeNow() const noexcept override;
300
309 bool Rewind() noexcept;
310
315 const StormByte::Buffer::IO::BufferedLocationReader& Origin() const noexcept;
316
321 StormByte::Buffer::IO::BufferedLocationReader& Origin() noexcept;
322
328 StormByte::Safe::Unique<Backend::Pipeline::Decoder> OpenDecoder(Decoder& decoder) noexcept;
329
353 Packet::PointerType Wrap(
354 int track,
355 Type type,
356 StormByte::Buffer::FIFO payload,
357 StormByte::Safe::Optional<Property::Duration> pts,
358 StormByte::Safe::Optional<Property::Duration> dts,
359 StormByte::Safe::Optional<Property::Duration> duration,
360 bool keyframe,
361 StormByte::Safe::Unique<Backend::Pipeline::Packet> backend) noexcept;
362
363 StormByte::Safe::Unique<Backend::Pipeline::Demuxer> m_backend;
364 bool m_eof;
365 StormByte::Safe::Mutex m_planMutex;
366 StormByte::Safe::ConditionVariable m_planPresent;
367 StormByte::Safe::Atomic<std::int64_t> m_positionNs;
368 StormByte::Safe::Map<int, std::uint64_t> m_nextSerial;
369 StormByte::Safe::Vector<int> m_measureTracks;
370 bool m_measuring = false;
371 Filters* m_filters = nullptr;
372 StormByte::Safe::Shared<class Progress> m_progress;
373 Join m_join{*this};
374 };
375 }
376 }
377}
378
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Buffer::Bridge)
Decodes packets of one origin track into frames.
Definition decoder.hxx:148
Reads interleaved compressed packets from the Plan reader.
Definition demuxer.hxx:148
friend Muxer & operator>>(Demuxer &demuxer, Muxer &muxer) noexcept
Binds demuxer as remux origin and forwards Plan attachments.
Progress::Pointer Progress() const noexcept
Job clock for this tube (measure, analytics, All).
bool Eof() const noexcept
Whether the last read hit EOF.
~Demuxer() noexcept override
Destructor.
friend Decoder & operator>>(Demuxer &demuxer, Decoder &decoder) noexcept
Binds one origin track of demuxer to decoder.
friend class Decoder
Definition demuxer.hxx:151
friend Remuxer & operator>>(Demuxer &demuxer, Remuxer &remuxer) noexcept
Binds origin track remuxer.In() from demuxer onto remuxer.
friend Demuxer & operator>>(class Plan &&plan, Demuxer &demuxer) noexcept
Demuxer(const Demuxer &other)=delete
Copy constructor.
friend class Filters
Definition demuxer.hxx:152
StormByte::Safe::Optional< Property::Duration > Position() const
Presentation time of the last emitted packet.
friend class Backend::Pipeline::Demuxer
Definition demuxer.hxx:149
friend Demuxer & operator>>(StormByte::Safe::Shared< class Plan > plan, Demuxer &demuxer) noexcept
Transfers a shared intention without slicing its dynamic type.
Demuxer(Demuxer &&other) noexcept=delete
Move constructor.
friend class Muxer
Definition demuxer.hxx:153
Demuxer(StormByte::Safe::Shared< StormByte::Logger::Log > log)
Demuxer.
Demuxer(StormByte::Safe::Shared< StormByte::Logger::Log > log, StormByte::Safe::Shared< class Progress > progress)
Launch with a clock already used by duration resolution.
Optional facade: Between stretches, Add filters, Close.
Definition filters.hxx:194
Writes interleaved packets to the Plan writer.
Definition muxer.hxx:217
One compressed access unit.
Definition packet.hxx:102
Closed job intention: owned location reader, writer and tracks.
Definition plan.hxx:206
Forwards compressed packets of one origin track to the muxer.
Definition remuxer.hxx:133
Ensures a derived stage stops before its resources expire.
Definition step.hxx:501
Step(const Step &other)=delete
Copy construction is disabled.
friend class Remuxer
Allows the remultiplexing stage to access step internals.
Definition step.hxx:643
friend class Plan
Allows the shared plan to wake registered stages.
Definition step.hxx:628
Pipeline Demux / decode / filter / encode / mux types.
Media property value types.
Typed item queues provided by StormByte-Buffer.
Internal pipeline workers.
Definition decoder.hxx:82
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.
@ Demuxer
Container reader; owns the demux pending queues.
Definition telemetry.hxx:393
@ Decoder
Track decoder feeding a decode/encode lane.
Definition telemetry.hxx:394
Multimedia module of the StormByte suite.
Root namespace of the StormByte C++ suite.
STL namespace.
#define STORMBYTE_MULTIMEDIA_PUBLIC
Definition visibility.h:61