StormByte C++ Library: Multimedia module 0.0.9999
StormByte-Multimedia is a StormByte library module for parsing configuration files
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 * 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/fifo.hxx>
42#include <StormByte/logger/log.hxx>
50
51#include <atomic>
52#include <condition_variable>
53#include <cstdint>
54#include <memory>
55#include <mutex>
56#include <optional>
57#include <unordered_map>
58#include <vector>
59
67 class Decoder;
68 class Demuxer;
69}
70
72 class Demux;
73}
74
79namespace StormByte::Multimedia {
80 class Origin;
81}
82
90 class Decoder;
91 class Demuxer;
92 class Filters;
93 class Muxer;
94 class Packet;
95 class Plan;
96 class Remuxer;
97
104 STORMBYTE_MULTIMEDIA_PUBLIC Decoder& operator>>(Demuxer& demuxer, Decoder& decoder) noexcept;
105
143 friend class Backend::Pipeline::Demuxer;
144 friend class Backend::Pipeline::Detail::Worker::Demux;
145 friend class Decoder;
146 friend class Filters;
147 friend class Muxer;
148 friend Decoder& operator>>(Demuxer& demuxer, Decoder& decoder) noexcept;
149 friend Demuxer& operator>>(class Plan&& plan, Demuxer& demuxer) noexcept;
150 friend Muxer& operator>>(Demuxer& demuxer, Muxer& muxer) noexcept;
151 friend Remuxer& operator>>(Demuxer& demuxer, Remuxer& remuxer) noexcept;
152
153 public:
158
163 explicit Demuxer(std::shared_ptr<StormByte::Logger::Log> log) noexcept;
164
169 Demuxer(const Demuxer& other) = delete;
170
175 Demuxer(Demuxer&& other) noexcept = delete;
176
180 ~Demuxer() noexcept override;
181
187 Demuxer& operator=(const Demuxer& other) = delete;
188
194 Demuxer& operator=(Demuxer&& other) noexcept = delete;
195
199
204 explicit operator bool() const noexcept;
205
210
217 bool Eof() const noexcept;
218
223 std::optional<Property::Duration> Position() const noexcept;
224
234 Progress::Pointer Progress() const noexcept;
235
239
240 private:
241 using Step::Log;
242
246 void WaitForPlan() noexcept;
247
253 void LatchDuration() noexcept;
254
261 void ReachedEof() noexcept;
262
269 void Measure(std::vector<int> tracks) noexcept;
270
275 bool Measuring() const noexcept;
276
283 bool WakeNow() const noexcept override;
284
292 bool Rewind() noexcept;
293
298 const File& OriginFile() const noexcept;
299
304 Origin& BoundOrigin() noexcept;
305
311 std::unique_ptr<Backend::Pipeline::Decoder> OpenDecoder(Decoder& decoder) noexcept;
312
336 Packet::PointerType Wrap(
337 int track,
338 Type type,
339 StormByte::Buffer::FIFO payload,
340 std::optional<Property::Duration> pts,
341 std::optional<Property::Duration> dts,
342 std::optional<Property::Duration> duration,
343 bool keyframe,
344 std::unique_ptr<Backend::Pipeline::Packet> backend) noexcept;
345
346 std::unique_ptr<Backend::Pipeline::Demuxer> m_backend;
347 bool m_eof;
348 std::mutex m_planMutex;
349 std::condition_variable m_planPresent;
350 std::atomic<std::int64_t> m_positionNs;
351 std::unordered_map<int, std::uint64_t> m_nextSerial;
352 std::vector<int> m_measureTracks;
353 bool m_measuring = false;
354 Filters* m_filters = nullptr;
355 std::shared_ptr<class Progress> m_progress;
356 Join m_join{*this};
357 };
358}
Snapshot of a media source: path or Consumer, container, streams and tags.
Definition file.hxx:84
Decodes packets of one origin track into frames.
Definition decoder.hxx:150
Reads interleaved packets from a File origin.
Definition demuxer.hxx:142
friend Muxer & operator>>(Demuxer &demuxer, Muxer &muxer) noexcept
Binds demuxer as remux origin and forwards its attachments.
Progress::Pointer Progress() const noexcept
Job clock for this tube (measure, analytics, All).
bool Eof() const noexcept
Whether the last read hit EOF.
std::optional< Property::Duration > Position() const noexcept
Presentation time of the last emitted packet.
friend Demuxer & operator>>(class Plan &&plan, Demuxer &demuxer) noexcept
Hands plan to demuxer.
~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:145
friend Remuxer & operator>>(Demuxer &demuxer, Remuxer &remuxer) noexcept
Binds origin track remuxer.In() from demuxer onto remuxer.
Demuxer(std::shared_ptr< StormByte::Logger::Log > log) noexcept
Demuxer.
Demuxer(const Demuxer &other)=delete
Copy constructor.
friend class Filters
Definition demuxer.hxx:146
friend class Backend::Pipeline::Demuxer
Definition demuxer.hxx:143
Demuxer(Demuxer &&other) noexcept=delete
Move constructor.
friend class Muxer
Definition demuxer.hxx:147
Optional facade: Between stretches, Add filters, Close.
Definition filters.hxx:102
Writes interleaved packets to a destination container.
Definition muxer.hxx:155
One compressed access unit.
Definition packet.hxx:80
Closed job intention: source File, destination container and tracks that enter the tube.
Definition plan.hxx:76
Forwards compressed packets of one origin track to the muxer.
Definition remuxer.hxx:88
Last data member of every most-derived Step.
Definition step.hxx:378
Step(const Step &other)=delete
friend class Remuxer
Definition step.hxx:117
const std::shared_ptr< class Plan > & Plan() const noexcept
Bound job intention, if any.
Definition step.hxx:177
Hopper and Sink live in StormByte-Buffer.
Multimedia-owned pipeline stages and unit holders.
Definition AVFormatContext.hxx:52
Definition AVFormatContext.hxx:52
Demux / decode / filter / encode / mux types.
Decoder & operator>>(Demuxer &demuxer, Decoder &decoder) noexcept
Binds one origin track of demuxer to decoder.
@ Demuxer
Demuxer
Definition typedefs.hxx:106
@ Decoder
Decoder
Definition typedefs.hxx:107
Media property value types.
Public multimedia types: codecs, containers, streams and files.
Type
Kind of media stream or codec.
Definition type.hxx:55
#define STORMBYTE_MULTIMEDIA_PUBLIC
Imported symbol.
Definition visibility.h:47