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