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