StormByte-Multimedia 3.3.2
C++26 multimedia processing module of the StormByte suite
Loading...
Searching...
No Matches
packet.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>
59#include <StormByte/safe/optional.hxx>
60#include <StormByte/safe/vector.hxx>
61
62#include <cstdint>
63
68namespace StormByte {
73 namespace Multimedia {
80 namespace Pipeline {
103 public:
108
113
119
139 Packet(int track, enum Type type, enum Producer producer,
144 bool key_frame,
146 const StormByte::Multimedia::Codec* codec,
147 std::uint64_t serial,
148 std::uint64_t part);
149
160 Packet(const Packet& other);
161
168 Packet(Packet&& other) noexcept;
169
173 ~Packet() noexcept override;
174
183 Packet& operator=(const Packet& other);
184
192 Packet& operator=(Packet&& other) noexcept;
193
197
202
207 inline const StormByte::Safe::Optional<Property::Duration>& Pts() const noexcept {
208 return m_pts;
209 }
210
215 inline const StormByte::Safe::Optional<Property::Duration>& Dts() const noexcept {
216 return m_dts;
217 }
218
224 return m_duration;
225 }
226
231 inline bool KeyFrame() const noexcept {
232 return m_keyFrame;
233 }
234
238
243
253 inline const StormByte::Safe::Optional<std::uint64_t>& Serial() const noexcept {
254 return m_serial;
255 }
256
263 inline std::uint64_t Part() const noexcept {
264 return m_part;
265 }
266
270
275
281 inline const StormByte::Multimedia::Codec* Codec() const noexcept {
282 return m_codec;
283 }
284
288
293
298 inline const StormByte::Buffer::FIFO& Payload() const noexcept {
299 return m_payload;
300 }
301
306 inline StormByte::Buffer::FIFO& Payload() noexcept {
307 return m_payload;
308 }
309
318
323 inline const StormByte::Safe::Vector<SideData>& Attachments() const noexcept {
324 return m_attachments;
325 }
326
332 return m_attachments;
333 }
334
338
339 private:
343 friend class Backend::Pipeline::Packet;
344
348 friend class Decoder;
349
353 friend class Demuxer;
354
358 friend class Encoder;
359
363 friend class Filter::FFmpeg;
364
368 friend class Muxer;
369 friend class Remuxer;
370
375 void Bind(StormByte::Safe::Unique<Backend::Pipeline::Packet> backend) noexcept;
376
382 void BecomeEmpty() noexcept;
383
391 Item::PointerType Clone() const override;
392
400 Item::PointerType Move() override;
401
402 StormByte::Buffer::FIFO m_payload;
403 StormByte::Safe::Optional<Property::Duration> m_pts;
404 StormByte::Safe::Optional<Property::Duration> m_dts;
405 StormByte::Safe::Optional<Property::Duration> m_duration;
406 bool m_keyFrame;
407 StormByte::Safe::Vector<SideData> m_attachments;
408 const StormByte::Multimedia::Codec* m_codec;
409 StormByte::Safe::Optional<std::uint64_t> m_serial;
410 std::uint64_t m_part;
411 int m_muxTrack = -1;
412 bool m_measuring = false;
413 StormByte::Safe::Unique<Backend::Pipeline::Packet> m_backend;
414 };
415 }
416 }
417}
418
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Buffer::Bridge)
Immutable codec identity owned by Registry.
Definition codec.hxx:94
Abstract base for every StormByte Multimedia filter.
Definition ffmpeg.hxx:261
enum Producer Producer() const noexcept
Stage that created this unit.
Definition item.hxx:213
Item(const Item &other) noexcept=default
Copy constructor.
StormByte::ByteSize BufferingWeight() const noexcept
Estimates the compressed payload weight for queue accounting.
std::uint64_t Part() const noexcept
Sub-id inside Serial when one demuxed unit yields several frames.
Definition packet.hxx:263
const StormByte::Safe::Optional< Property::Duration > & Dts() const noexcept
Decode timestamp on the stream clock.
Definition packet.hxx:215
StormByte::Safe::Vector< SideData > & Attachments() noexcept
Side-data blobs bound to this access unit (mutable).
Definition packet.hxx:331
friend class Remuxer
Definition packet.hxx:369
Packet(int track, enum Type type, enum Producer producer, StormByte::Buffer::FIFO payload, StormByte::Safe::Optional< Property::Duration > pts, StormByte::Safe::Optional< Property::Duration > dts, StormByte::Safe::Optional< Property::Duration > duration, bool key_frame, StormByte::Safe::Vector< SideData > attachments, const StormByte::Multimedia::Codec *codec, std::uint64_t serial, std::uint64_t part)
Builds a packet.
const StormByte::Safe::Optional< Property::Duration > & Duration() const noexcept
Packet duration on the stream clock.
Definition packet.hxx:223
friend class Decoder
Allows the decoder to access the compressed backend packet.
Definition packet.hxx:348
~Packet() noexcept override
Destructor.
const StormByte::Safe::Optional< std::uint64_t > & Serial() const noexcept
Monotonic lineage id assigned when the unit enters the pipe.
Definition packet.hxx:253
Packet()
Empty packet (no payload, track -1, type Unknown).
StormByte::Buffer::FIFO & Payload() noexcept
Owned compressed payload (mutable).
Definition packet.hxx:306
const StormByte::Safe::Optional< Property::Duration > & Pts() const noexcept
Presentation timestamp on the stream clock.
Definition packet.hxx:207
friend class Encoder
Allows the encoder to populate encoded media and metadata.
Definition packet.hxx:358
friend class Backend::Pipeline::Packet
Allows the backend holder to access the packet's media storage.
Definition packet.hxx:343
const StormByte::Safe::Vector< SideData > & Attachments() const noexcept
Side-data blobs bound to this access unit.
Definition packet.hxx:323
friend class Demuxer
Allows the demuxer to populate compressed media and metadata.
Definition packet.hxx:353
StormByte::Safe::Shared< Packet > PointerType
Base-heap shared owner of a packet; keep its providers loaded.
Definition packet.hxx:107
const StormByte::Buffer::FIFO & Payload() const noexcept
Owned compressed payload.
Definition packet.hxx:298
bool KeyFrame() const noexcept
Whether this is a key frame / key packet.
Definition packet.hxx:231
Packet(const Packet &other)
Copy.
Packet(Packet &&other) noexcept
Move constructor.
const StormByte::Multimedia::Codec * Codec() const noexcept
Registry codec of this access unit.
Definition packet.hxx:281
friend class Muxer
Allows the muxer to access the compressed backend packet.
Definition packet.hxx:368
One side-data blob attached to a Frame or Packet.
Definition side_data.hxx:114
Multimedia module of the StormByte suite.
Pipeline Demux / decode / filter / encode / mux types.
Media property value types.
Typed item queues provided by StormByte-Buffer.
Demux / decode / filter / encode / mux types.
Multimedia module of the StormByte suite.
Root namespace of the StormByte C++ suite.
STL namespace.
#define STORMBYTE_MULTIMEDIA_PUBLIC
Definition visibility.h:61