CVB++ 15.0
packet.hpp
1#pragma once
2
3
4#include "codec_bridge.hpp"
5#include "../global.hpp"
6#include "../utilities/system_info.hpp"
7#include "../shims/stdoptional.hpp"
8
9namespace Cvb
10{
11
12CVB_BEGIN_INLINE_NS
13
14template <>
15inline HandleGuard<CodecBridge::Packet>::HandleGuard(void* handle) noexcept
16 : HandleGuard<CodecBridge::Packet>(handle, [](void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
17{
18}
19
20namespace CodecBridge
21{
22
27class Packet final
28{
29
30public:
31
32 static std::unique_ptr<Packet> FromHandle(HandleGuard<Packet>&& guard)
33 {
34 if (!guard.Handle())
35 throw std::runtime_error("handle must not be null");
36
37 return std::make_unique<Packet>(std::move(guard));
38 }
39
40 explicit Packet(HandleGuard<Packet>&& guard) noexcept
41 : handle_(std::move(guard))
42 {
43
44 }
45
46 Packet(const Packet& other) = delete;
47 Packet& operator=(const Packet& other) = delete;
48 Packet(Packet&& other) = delete;
49 Packet& operator=(Packet&& other) = delete;
50
51 ~Packet() = default;
52
53 void* Handle() const noexcept
54 {
55 return handle_.Handle();
56 }
57
59
63 size_t Size() const
64 {
65 size_t size = 0;
66 CVB_CALL_CAPI_CHECKED(CVCBufferGetSize(Handle(), size));
67 return size;
68 }
69
71
77 void* BasePtr() const
78 {
79 void* basePtr = nullptr;
80 CVB_CALL_CAPI_CHECKED(CVCBufferGetBasePtr(Handle(), basePtr));
81 return basePtr;
82 }
83
85
94 {
95 auto index = Property<int>(CExports::CVCBPP_StreamIndex);
96 if (index == -1)
97 return {};
98 return index;
99 }
100
102
108 int64_t PresentationTimeStamp() const
109 {
110 return static_cast<int64_t>(Property<int64_t>(CExports::CVCBPP_PresentationTimestamp));
111 }
112
114
120 {
121 auto timeBase = Property<CExports::CVCBRational>(CExports::CVCBPP_TimeBase);
122 return { timeBase.Numerator, timeBase.Denominator };
123 }
124
125
126private:
127
128 template<class T>
129 T Property(CExports::CVCBPacketProperty property) const
130 {
131 T value = {};
132 size_t size = sizeof(T);
133 CVB_CALL_CAPI_CHECKED(CVCBPacketGetProperty(Handle(), property, &value, size));
134 return value;
135 }
136
137 HandleGuard<Packet> handle_;
138};
139
140}
141
142CVB_END_INLINE_NS
143}
A packet that holds encoded data frame data.
Definition: packet.hpp:28
size_t Size() const
Get the size of the packet.
Definition: packet.hpp:63
Cvb::optional< int > StreamIndex() const
Get the stream index this packet belongs to, if any.
Definition: packet.hpp:93
int64_t PresentationTimeStamp() const
Get the presentation time stamp for this packet.
Definition: packet.hpp:108
Rational TimeBase() const
Get time base that was used for encoding this packet.
Definition: packet.hpp:119
void * BasePtr() const
Get the pointer to the packet content.
Definition: packet.hpp:77
A pair of rational numbers.
Definition: codec_bridge.hpp:200
This class is a replacement for C++17 std::optional.
Definition: optional.hpp:60
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24