StormByte C++ Library: Multimedia module 0.0.9999
StormByte-Multimedia is a StormByte library module for parsing configuration files
Loading...
Searching...
No Matches
muxer.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/logger/log.hxx>
48
49#include <atomic>
50#include <cstddef>
51#include <cstdint>
52#include <filesystem>
53#include <map>
54#include <memory>
55#include <optional>
56#include <string>
57
65 class Muxer;
66}
67
69 class Mux;
70}
71
79 class Container;
80}
81
89 class Demuxer;
90 class Encoder;
91 class Muxer;
92 class Remuxer;
93
101
109
116 STORMBYTE_MULTIMEDIA_PUBLIC Muxer& operator>>(Muxer& muxer, const std::filesystem::path& path) noexcept;
117
124 STORMBYTE_MULTIMEDIA_PUBLIC Muxer& operator>>(const File& file, Muxer& muxer) noexcept;
125
138
156 friend class Backend::Pipeline::Detail::Muxer::Matroska::Container;
157 friend class Backend::Pipeline::Muxer;
158 friend class Backend::Pipeline::Detail::Worker::Mux;
159 friend Encoder& operator>>(Encoder& encoder, Muxer& muxer) noexcept;
160 friend Muxer& operator>>(const File& file, Muxer& muxer) noexcept;
161 friend Muxer& operator>>(Demuxer& demuxer, Muxer& muxer) noexcept;
162 friend Muxer& operator>>(Muxer& muxer, const std::filesystem::path& path) noexcept;
163 friend Remuxer& operator>>(Remuxer& remuxer, Muxer& muxer) noexcept;
164
165 public:
170
176 explicit Muxer(std::shared_ptr<StormByte::Logger::Log> log,
177 const Container& container) noexcept;
178
183 Muxer(const Muxer& other) = delete;
184
189 Muxer(Muxer&& other) noexcept = delete;
190
194 ~Muxer() noexcept override;
195
201 Muxer& operator=(const Muxer& other) = delete;
202
208 Muxer& operator=(Muxer&& other) noexcept = delete;
209
213
218 explicit operator bool() const noexcept;
219
224 bool Closed() const noexcept;
225
231 std::optional<Property::Duration> Position() const noexcept;
232
237 const Container& Destination() const noexcept;
238
253 bool Armed() const noexcept;
254
259 bool Ready() const noexcept override;
260
270 std::size_t InputCeiling() const noexcept override;
271
276
282 std::optional<std::string> Language(int output_index) const noexcept;
283
289 void Language(int output_index, std::string language) noexcept;
290
296 std::optional<std::string> Title(int output_index) const noexcept;
297
303 void Title(int output_index, std::string title) noexcept;
304
308
309 private:
310 using Step::Log;
311
315 void WaitArmed() noexcept;
316
323 bool BindEncoderStream(Encoder& encoder, void* avStream) noexcept;
324
332 bool RemuxCodec(int inIndex, void*& params, void* timeBase) noexcept;
333
338 std::size_t ExpectedSlots() const noexcept;
339
343 void ClockMuxDone() noexcept;
344
349 void ClockPass(std::int64_t ns) noexcept;
350
351 const Container* m_container;
352 std::unique_ptr<Backend::Pipeline::Muxer> m_backend;
353 Demuxer* m_origin;
354 std::shared_ptr<class Progress> m_progress;
355 std::map<int, std::string> m_language;
356 std::map<int, std::string> m_title;
357 std::atomic<bool> m_closed;
358 std::atomic<std::size_t> m_reserved;
359 std::atomic<std::int64_t> m_positionNs;
360 Join m_join{*this};
361 };
362}
Immutable container identity owned by StormByte::Multimedia::Registry.
Definition container.hxx:59
Snapshot of a media source: path or Consumer, container, streams and tags.
Definition file.hxx:84
Reads interleaved packets from a File origin.
Definition demuxer.hxx:142
Encodes frames of one output track into packets.
Definition encoder.hxx:103
Writes interleaved packets to a destination container.
Definition muxer.hxx:155
bool Ready() const noexcept override
Open finished without Fail or Stop, and Armed.
friend Muxer & operator>>(Demuxer &demuxer, Muxer &muxer) noexcept
Binds demuxer as remux origin and forwards its attachments.
std::size_t InputCeiling() const noexcept override
Ceiling of the muxer input hopper.
const Container & Destination() const noexcept
Destination container.
friend Muxer & operator>>(const File &file, Muxer &muxer) noexcept
Snapshots attachments of file onto muxer.
friend class Backend::Pipeline::Muxer
Definition muxer.hxx:157
Muxer(std::shared_ptr< StormByte::Logger::Log > log, const Container &container) noexcept
Muxer for container.
friend Remuxer & operator>>(Remuxer &remuxer, Muxer &muxer) noexcept
Reserves remuxer as an output track of muxer.
friend Muxer & operator>>(Muxer &muxer, const std::filesystem::path &path) noexcept
Binds the output path of muxer.
friend class Backend::Pipeline::Detail::Muxer::Matroska::Container
Definition muxer.hxx:156
bool Closed() const noexcept
true after Finish flushed the trailer, or after Fail.
Muxer(const Muxer &other)=delete
Copy constructor.
std::optional< Property::Duration > Position() const noexcept
Presentation time of the last packet written.
friend Encoder & operator>>(Encoder &encoder, Muxer &muxer) noexcept
Reserves encoder as an output track of muxer.
Muxer(Muxer &&other) noexcept=delete
Move constructor.
bool Armed() const noexcept
Whether every muxable Plan track has a reserved hopper.
std::optional< std::string > Title(int output_index) const noexcept
Title tag for mux output output_index.
std::optional< std::string > Language(int output_index) const noexcept
Language tag for mux output output_index.
~Muxer() noexcept override
Destructor.
Job clock for one tube.
Definition progress.hxx:83
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
friend class Demuxer
Definition step.hxx:115
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
@ Encoder
Encoder
Definition typedefs.hxx:112
@ Remuxer
Remuxer
Definition typedefs.hxx:108
@ Muxer
Muxer
Definition typedefs.hxx:113
Media property value types.
#define STORMBYTE_MULTIMEDIA_PUBLIC
Imported symbol.
Definition visibility.h:47