StormByte C++ Library: Multimedia module 0.0.9999
StormByte-Multimedia is a StormByte library module for parsing configuration files
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 * 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>
47
48#include <cstdint>
49#include <memory>
50#include <optional>
51#include <vector>
52
81 friend class Backend::Pipeline::Packet;
82 friend class Decoder;
83 friend class Demuxer;
84 friend class Encoder;
85 friend class Filter::FFmpeg;
86 friend class Muxer;
87
88 public:
89 using PointerType = std::shared_ptr<Packet>;
90
95
99 Packet() noexcept;
100
119 Packet(int track, enum Type type, enum Producer producer,
120 StormByte::Buffer::FIFO payload,
121 std::optional<Property::Duration> pts,
122 std::optional<Property::Duration> dts,
123 std::optional<Property::Duration> duration,
124 bool key_frame,
125 std::vector<SideData> attachments,
126 const StormByte::Multimedia::Codec* codec,
127 std::uint64_t serial,
128 std::uint64_t part) noexcept;
129
138 Packet(const Packet& other) noexcept;
139
146 Packet(Packet&& other) noexcept;
147
151 ~Packet() noexcept override;
152
158 Packet& operator=(const Packet& other) noexcept;
159
167 Packet& operator=(Packet&& other) noexcept;
168
172
177
182 inline const std::optional<Property::Duration>& Pts() const noexcept {
183 return m_pts;
184 }
185
190 inline const std::optional<Property::Duration>& Dts() const noexcept {
191 return m_dts;
192 }
193
198 inline const std::optional<Property::Duration>& Duration() const noexcept {
199 return m_duration;
200 }
201
206 inline bool KeyFrame() const noexcept {
207 return m_keyFrame;
208 }
209
213
218
228 inline const std::optional<std::uint64_t>& Serial() const noexcept {
229 return m_serial;
230 }
231
238 inline std::uint64_t Part() const noexcept {
239 return m_part;
240 }
241
245
250
255 inline const StormByte::Multimedia::Codec* Codec() const noexcept {
256 return m_codec;
257 }
258
262
267
272 inline const StormByte::Buffer::FIFO& Payload() const noexcept {
273 return m_payload;
274 }
275
280 inline StormByte::Buffer::FIFO& Payload() noexcept {
281 return m_payload;
282 }
283
288 inline const std::vector<SideData>& Attachments() const noexcept {
289 return m_attachments;
290 }
291
296 inline std::vector<SideData>& Attachments() noexcept {
297 return m_attachments;
298 }
299
303
304 private:
309 void Bind(std::unique_ptr<Backend::Pipeline::Packet> backend) noexcept;
310
314 void BecomeEmpty() noexcept;
315
323 Item::PointerType Clone() const override;
324
332 Item::PointerType Move() override;
333
334 StormByte::Buffer::FIFO m_payload;
335 std::optional<Property::Duration> m_pts;
336 std::optional<Property::Duration> m_dts;
337 std::optional<Property::Duration> m_duration;
338 bool m_keyFrame;
339 std::vector<SideData> m_attachments;
340 const StormByte::Multimedia::Codec* m_codec;
341 std::optional<std::uint64_t> m_serial;
342 std::uint64_t m_part;
343 std::unique_ptr<Backend::Pipeline::Packet> m_backend;
344 };
345}
Immutable codec identity owned by Registry.
Definition codec.hxx:58
Abstract base for every StormByte Multimedia filter.
Definition ffmpeg.hxx:253
Facade shared by Frame and Packet.
Definition item.hxx:96
enum Producer Producer() const noexcept
Stage that created this unit.
Definition item.hxx:159
enum StormByte::Multimedia::Type Type() const noexcept
Media of this access unit.
Definition item.hxx:143
Item(const Item &other) noexcept=default
Copy constructor.
One compressed access unit.
Definition packet.hxx:80
const std::vector< SideData > & Attachments() const noexcept
Side-data blobs bound to this access unit.
Definition packet.hxx:288
const std::optional< std::uint64_t > & Serial() const noexcept
Monotonic lineage id assigned when the unit enters the pipe.
Definition packet.hxx:228
std::uint64_t Part() const noexcept
Sub-id inside Serial when one demuxed unit yields several frames.
Definition packet.hxx:238
const std::optional< Property::Duration > & Pts() const noexcept
Presentation timestamp on the stream clock.
Definition packet.hxx:182
const std::optional< Property::Duration > & Duration() const noexcept
Packet duration on the stream clock.
Definition packet.hxx:198
const std::optional< Property::Duration > & Dts() const noexcept
Decode timestamp on the stream clock.
Definition packet.hxx:190
friend class Decoder
Definition packet.hxx:82
std::vector< SideData > & Attachments() noexcept
Side-data blobs bound to this access unit (mutable).
Definition packet.hxx:296
StormByte::Buffer::FIFO & Payload() noexcept
Owned compressed payload (mutable).
Definition packet.hxx:280
friend class Encoder
Definition packet.hxx:84
friend class Backend::Pipeline::Packet
Definition packet.hxx:81
std::shared_ptr< Packet > PointerType
Definition packet.hxx:89
friend class Demuxer
Definition packet.hxx:83
const StormByte::Buffer::FIFO & Payload() const noexcept
Owned compressed payload.
Definition packet.hxx:272
bool KeyFrame() const noexcept
Whether this is a key frame / key packet.
Definition packet.hxx:206
Packet() noexcept
Empty packet (no payload, track -1, type Unknown).
const StormByte::Multimedia::Codec * Codec() const noexcept
Registry codec of this access unit.
Definition packet.hxx:255
friend class Muxer
Definition packet.hxx:86
One side-data blob attached to a Frame or Packet.
Definition side_data.hxx:90
Hopper and Sink live in StormByte-Buffer.
Definition AVFormatContext.hxx:52
Demux / decode / filter / encode / mux types.
Media property value types.
Public multimedia types: codecs, containers, streams and files.
#define STORMBYTE_MULTIMEDIA_PUBLIC
Imported symbol.
Definition visibility.h:47