StormByte-Multimedia 3.3.2
C++26 multimedia processing module of the StormByte suite
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 * 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/size.hxx>
54#include <StormByte/logger/log.hxx>
63#include <StormByte/safe/atomic.hxx>
64#include <StormByte/safe/map.hxx>
65#include <StormByte/safe/optional.hxx>
66#include <StormByte/safe/pointers.hxx>
67#include <StormByte/safe/set.hxx>
68#include <StormByte/safe/string.hxx>
69
70#include <cstddef>
71#include <cstdint>
72
77namespace StormByte {
82 namespace Multimedia {
87 namespace Backend {
92 namespace Pipeline {
96 class Muxer;
97
102 namespace Detail {
107 namespace Worker {
111 class Mux;
112 }
113
118 namespace Muxer {
123 namespace FFmpeg {
127 class Container;
128 }
129 }
130 }
131 }
132 }
133
140 namespace Pipeline {
144 class Demuxer;
145
149 class Encoder;
150
154 class Muxer;
155
159 class Remuxer;
160
172
184
199
218 public:
223
232
237 Muxer(const Muxer& other) = delete;
238
243 Muxer(Muxer&& other) noexcept = delete;
244
248 ~Muxer() noexcept override;
249
255 Muxer& operator=(const Muxer& other) = delete;
256
262 Muxer& operator=(Muxer&& other) noexcept = delete;
263
267
272 explicit operator bool() const noexcept;
273
278 bool Closed() const noexcept;
279
285 StormByte::Safe::Optional<Property::Duration> Position() const;
286
291 const Container& Destination() const noexcept;
292
307 bool Armed() const noexcept;
308
313 bool Ready() const noexcept override;
314
323 StormByte::Size InputCeiling() const noexcept override;
324
329
335 StormByte::Safe::Optional<StormByte::Safe::String> Language(int output_index) const;
336
342 void Language(int output_index, StormByte::Safe::String language);
343
348 void RemoveLanguage(int output_index);
349
355 StormByte::Safe::Optional<StormByte::Safe::String> Title(int output_index) const;
356
362 void Title(int output_index, StormByte::Safe::String title);
363
368 void RemoveTitle(int output_index);
369
375 StormByte::Safe::Optional<StormByte::Multimedia::Metadata::Disposition> Disposition(int output_index) const;
376
382 void Disposition(int output_index, StormByte::Multimedia::Metadata::Disposition disposition);
383
387
393
399 StormByte::Safe::Optional<StormByte::Safe::String> Tag(StormByte::Multimedia::Metadata::FileTag tag) const;
400
407 void Tag(StormByte::Multimedia::Metadata::FileTag tag, StormByte::Safe::String value);
408
414
418
419 private:
424
428 friend class Backend::Pipeline::Muxer;
429
433 friend class Backend::Pipeline::Detail::Worker::Mux;
434
441 friend Encoder& operator>>(Encoder& encoder, Muxer& muxer) noexcept;
442
449 friend Muxer& operator>>(Demuxer& demuxer, Muxer& muxer) noexcept;
450
457 friend Remuxer& operator>>(Remuxer& remuxer, Muxer& muxer) noexcept;
458
462 using Step::Log;
463
467 void WaitArmed() noexcept;
468
474 bool ConnectInput(Step& source) noexcept;
475
480 bool SetupPlan() noexcept;
481
485 class Connections;
486
491 bool SpawnBackend() noexcept;
492
499 bool ArmOctets() noexcept;
500
508 bool BindPlanAttachments() noexcept;
509
515 void FlushOctets() noexcept;
516
523 bool BindEncoderStream(Encoder& encoder, void* avStream) noexcept;
524
533 bool RemuxCodec(int inIndex, void*& params, void* timeBase,
534 void* averageFrameRate) noexcept;
535
540 StormByte::Size ExpectedSlots() const noexcept;
541
545 void ClockMuxDone() noexcept;
546
551 void ClockPass(std::int64_t ns) noexcept;
552
553 const Container* m_container;
554 StormByte::Safe::Unique<Backend::Pipeline::Muxer> m_backend;
555 Demuxer* m_origin;
556 StormByte::Safe::Shared<class Progress> m_progress;
557 Attachments m_attachments;
558 StormByte::Safe::Set<int> m_wired;
559 StormByte::Safe::Unique<Connections> m_connections;
560 StormByte::Safe::Map<int, StormByte::Safe::String> m_language;
561 StormByte::Safe::Map<int, StormByte::Safe::String> m_title;
562 StormByte::Safe::Map<StormByte::Multimedia::Metadata::FileTag, StormByte::Safe::String> m_tags;
563 StormByte::Safe::Map<int, StormByte::Safe::Optional<StormByte::Multimedia::Metadata::Disposition>> m_disposition;
564 StormByte::Safe::Atomic<bool> m_closed;
565 StormByte::Safe::Atomic<std::uint64_t> m_reserved;
566 StormByte::Safe::Atomic<std::int64_t> m_positionNs;
567 Join m_join{*this};
568 };
569 }
570 }
571}
572
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Buffer::Bridge)
Immutable container identity owned by StormByte::Multimedia::Registry.
Definition container.hxx:84
Reads interleaved compressed packets from the Plan reader.
Definition demuxer.hxx:148
Encodes frames of one output track into packets.
Definition encoder.hxx:145
Writes interleaved packets to the Plan writer.
Definition muxer.hxx:217
bool Ready() const noexcept override
Open finished without Fail or Stop, and Armed.
const Container & Destination() const noexcept
Destination container.
StormByte::Safe::Optional< StormByte::Multimedia::Metadata::Disposition > Disposition(int output_index) const
Disposition for mux output output_index.
friend class Backend::Pipeline::Muxer
Allows the mux backend to access its owning stage.
Definition muxer.hxx:428
Muxer(StormByte::Safe::Shared< StormByte::Logger::Log > log)
Muxer.
friend class Backend::Pipeline::Detail::Muxer::FFmpeg::Container
Allows the FFmpeg container backend to access mux state.
Definition muxer.hxx:423
StormByte::Safe::Optional< StormByte::Safe::String > Tag(StormByte::Multimedia::Metadata::FileTag tag) const
Edit of file tag tag.
void RemoveTag(StormByte::Multimedia::Metadata::FileTag tag)
Writes the output without file tag tag.
bool Closed() const noexcept
true after Finish flushed the trailer, or after Fail.
Muxer(const Muxer &other)=delete
Copy constructor (deleted).
friend class Backend::Pipeline::Detail::Worker::Mux
Allows the mux worker to drive output and progress.
Definition muxer.hxx:433
StormByte::Safe::Optional< Property::Duration > Position() const
Presentation time of the last packet written.
void RemoveLanguage(int output_index)
Writes mux output output_index without a language tag.
Muxer(Muxer &&other) noexcept=delete
Move constructor (deleted).
bool Armed() const noexcept
Whether every muxable Plan track has an output connection.
StormByte::Safe::Optional< StormByte::Safe::String > Language(int output_index) const
Language tag for mux output output_index.
StormByte::Size InputCeiling() const noexcept override
Maximum number of queued input packets.
void RemoveTitle(int output_index)
Writes mux output output_index without a title.
~Muxer() noexcept override
Destructor.
StormByte::Safe::Optional< StormByte::Safe::String > Title(int output_index) const
Title tag for mux output output_index.
Job clock for one tube.
Definition progress.hxx:150
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 Demuxer
Allows the demultiplexing stage to access step internals.
Definition step.hxx:633
Multimedia module of the StormByte suite.
Pipeline Demux / decode / filter / encode / mux types.
Media property value types.
Internal pipeline workers.
Definition decoder.hxx:82
Private pipeline implementation details.
Definition decoder.hxx:82
Multimedia-owned pipeline stages and unit holders.
Private RAII wrappers over libav*.
Snapshot metadata for files and streams.
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
@ Encoder
Track encoder feeding the muxer.
Definition telemetry.hxx:396
@ Remuxer
Stream-copy stage feeding the muxer.
Definition telemetry.hxx:397
@ Muxer
Container writer.
Definition telemetry.hxx:398
Multimedia module of the StormByte suite.
StormByte::Safe::Vector< Attachment > Attachments
Ordered attachments with creator-owned Safe storage.
Definition attachment.hxx:175
Root namespace of the StormByte C++ suite.
STL namespace.
#define STORMBYTE_MULTIMEDIA_PUBLIC
Definition visibility.h:61