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>
47
48#include <atomic>
49#include <cstddef>
50#include <cstdint>
51#include <filesystem>
52#include <map>
53#include <memory>
54#include <optional>
55#include <string>
56
64 class Muxer;
65}
66
68 class Mux;
69}
70
78 class Container;
79}
80
88 class Demuxer;
89 class Encoder;
90 class Muxer;
91 class Remuxer;
92
100
108
115 STORMBYTE_MULTIMEDIA_PUBLIC Muxer& operator>>(Muxer& muxer, const std::filesystem::path& path) noexcept;
116
123 STORMBYTE_MULTIMEDIA_PUBLIC Muxer& operator>>(const File& file, Muxer& muxer) noexcept;
124
136
151 friend class Backend::Pipeline::Detail::Muxer::Matroska::Container;
152 friend class Backend::Pipeline::Muxer;
153 friend class Backend::Pipeline::Detail::Worker::Mux;
154 friend Encoder& operator>>(Encoder& encoder, Muxer& muxer) noexcept;
155 friend Muxer& operator>>(const File& file, Muxer& muxer) noexcept;
156 friend Muxer& operator>>(Demuxer& demuxer, Muxer& muxer) noexcept;
157 friend Muxer& operator>>(Muxer& muxer, const std::filesystem::path& path) noexcept;
158 friend Remuxer& operator>>(Remuxer& remuxer, Muxer& muxer) noexcept;
159
160 public:
171 explicit Muxer(std::shared_ptr<StormByte::Logger::Log> log,
172 const Container& container) noexcept;
173
178 Muxer(const Muxer& other) = delete;
179
184 Muxer(Muxer&& other) noexcept = delete;
185
189 ~Muxer() noexcept override;
190
196 Muxer& operator=(const Muxer& other) = delete;
197
203 Muxer& operator=(Muxer&& other) noexcept = delete;
204
213 explicit operator bool() const noexcept;
214
219 bool Closed() const noexcept;
220
226 std::optional<Property::Duration> Position() const noexcept;
227
232 const Container& Destination() const noexcept;
233
248 bool Armed() const noexcept;
249
254 bool Ready() const noexcept override;
255
260 std::size_t InputCeiling() const noexcept override {
261 return Ceiling;
262 }
263
274 std::optional<std::string> Language(int output_index) const noexcept;
275
281 void Language(int output_index, std::string language) noexcept;
282
288 std::optional<std::string> Title(int output_index) const noexcept;
289
295 void Title(int output_index, std::string title) noexcept;
296
301 private:
302 using Step::Log;
303
307 void WaitArmed() noexcept;
308
315 bool BindEncoderStream(Encoder& encoder, void* avStream) noexcept;
316
324 bool RemuxCodec(int inIndex, void*& params, void* timeBase) noexcept;
325
330 std::size_t ExpectedSlots() const noexcept;
331
332 static constexpr std::size_t Ceiling = 64;
333 const Container* m_container;
334 std::unique_ptr<Backend::Pipeline::Muxer> m_backend;
335 Demuxer* m_origin;
336 std::map<int, std::string> m_language;
337 std::map<int, std::string> m_title;
338 std::atomic<bool> m_closed;
339 std::atomic<std::size_t> m_reserved;
340 std::atomic<std::int64_t> m_positionNs;
341 Join m_join{*this};
342 };
343}
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:121
Encodes frames of one output track into packets.
Definition encoder.hxx:103
Writes interleaved packets to a destination container.
Definition muxer.hxx:150
friend Muxer & operator>>(Muxer &muxer, const std::filesystem::path &path) noexcept
Binds the output path of muxer.
Muxer(std::shared_ptr< StormByte::Logger::Log > log, const Container &container) noexcept
Muxer for container.
friend Muxer & operator>>(Demuxer &demuxer, Muxer &muxer) noexcept
Binds demuxer as remux origin and forwards its attachments.
void Language(int output_index, std::string language) noexcept
Sets the language tag for mux output output_index.
Muxer(const Muxer &other)=delete
Copy constructor.
Muxer(Muxer &&other) noexcept=delete
Move constructor.
void Title(int output_index, std::string title) noexcept
Sets the title tag for mux output output_index.
std::optional< std::string > Title(int output_index) const noexcept
Title tag for mux output output_index.
friend Encoder & operator>>(Encoder &encoder, Muxer &muxer) noexcept
Reserves encoder as an output track of muxer.
friend Remuxer & operator>>(Remuxer &remuxer, Muxer &muxer) noexcept
Reserves remuxer as an output track of muxer.
std::optional< std::string > Language(int output_index) const noexcept
Language tag for mux output output_index.
~Muxer() noexcept override
Destructor.
friend Muxer & operator>>(const File &file, Muxer &muxer) noexcept
Snapshots attachments of file onto muxer.
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:359
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.
#define STORMBYTE_MULTIMEDIA_PUBLIC
Imported symbol.
Definition visibility.h:47