CVB++ 15.0
decoder.hpp
1#pragma once
2
3
4#include "codec_bridge.hpp"
5#include "../global.hpp"
6#include "../utilities/system_info.hpp"
7
8#include "codec_config.hpp"
9#include "frame.hpp"
10#include "packet.hpp"
11
12namespace Cvb
13{
14
15CVB_BEGIN_INLINE_NS
16
17 template <>
18inline HandleGuard<CodecBridge::Decoder>::HandleGuard(void* handle) noexcept
19 : HandleGuard<CodecBridge::Decoder>(handle, [](void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
20{
21}
22
23 namespace CodecBridge
24 {
25
32 class Decoder final
33 {
34
35 public:
36
37 static std::unique_ptr<Decoder> FromHandle(HandleGuard<Decoder>&& guard)
38 {
39 if (!guard.Handle())
40 throw std::runtime_error("handle must not be null");
41
42 return std::make_unique<Decoder>(std::move(guard));
43 }
44
45 explicit Decoder(HandleGuard<Decoder>&& guard) noexcept
46 : handle_(std::move(guard))
47 {
48
49 }
50
51 Decoder(const Decoder& other) = delete;
52 Decoder& operator=(const Decoder& other) = delete;
53 Decoder(Decoder&& other) = delete;
54 Decoder& operator=(Decoder&& other) = delete;
55
56 ~Decoder() = default;
57
58 void* Handle() const noexcept
59 {
60 return handle_.Handle();
61 }
62
64
72 CodecStatus Decode(const Packet& packet)
73 {
74 CExports::CVCBCodecStatus status = CExports::CVCBCS_ReadoutRequired;
75 CVB_CALL_CAPI_CHECKED(CVCBDecoderSendPacket(Handle(), packet.Handle(), status));
76 return static_cast<CodecStatus>(status);
77 }
78
80
86 void Flush()
87 {
88 CExports::CVCBCodecStatus status = CExports::CVCBCS_ReadoutRequired;
89 CVB_CALL_CAPI_CHECKED(CVCBDecoderSendPacket(Handle(), nullptr, status));
90 }
91
93
101 {
102 CExports::CVCBFRAME handle = nullptr;
103 CVB_CALL_CAPI_CHECKED(CVCBDecoderReceiveFrame(Handle(), handle));
104 if (!handle)
105 return {};
106 HandleGuard<Frame> guard(handle);
107 return Frame::FromHandle(std::move(guard));
108 }
109
111
117 int StreamIndex() const
118 {
119 return Property<int>(CExports::CVCBDP_StreamIndex);
120 }
121
122
123 private:
124
125 template<class T>
126 T Property(CExports::CVCBDecoderProperty property) const
127 {
128 T value = {};
129 size_t size = sizeof(T);
130 CVB_CALL_CAPI_CHECKED(CVCBDecoderGetProperty(Handle(), property, &value, size));
131 return value;
132 }
133
134 HandleGuard<Decoder> handle_;
135 };
136
137}
138
139CVB_END_INLINE_NS
140}
A decoder for video frames.
Definition: decoder.hpp:33
void Flush()
Flush the decoder and finish decoding.
Definition: decoder.hpp:86
CodecStatus Decode(const Packet &packet)
Decode a packet.
Definition: decoder.hpp:72
int StreamIndex() const
Get the stream index this decoder can work on.
Definition: decoder.hpp:117
std::unique_ptr< Frame > ReceiveFrame()
Receive an an decoded frame.
Definition: decoder.hpp:100
A packet that holds encoded data frame data.
Definition: packet.hpp:28
CodecStatus
Status of the encoder/decoder after sending data.
Definition: codec_bridge.hpp:187
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24