CVB++ 15.0
detail_vin_device.hpp
1#pragma once
2
3#include <memory>
4
5#include "../../global.hpp"
6
7#include "../vin_image.hpp"
8#include "../stream_image.hpp"
9
10#include "../_decl/decl_stream.hpp"
11#include "../_decl/decl_buffer_image.hpp"
12#include "../_decl/decl_ring_buffer.hpp"
13#include "../_decl/decl_vin_device.hpp"
14
15namespace Cvb
16{
17
18 CVB_BEGIN_INLINE_NS
19
20 namespace Driver
21 {
22
24 {
25 bool hasBsOrCs = false;
26
27 CExports::cvbval_t currentBoard = 0;
28 if (CExports::CanBoardSelect2(Handle()))
29 {
30 auto result = CExports::BS2GetBoard(Handle(), currentBoard);
31 if (result < 0)
32 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to get board"));
33 hasBsOrCs = true;
34 }
35 else if (CExports::CanBoardSelect(Handle()))
36 {
37 auto result = CExports::GetBoard(Handle(), &currentBoard);
38 if (result < 0)
39 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to get board"));
40 hasBsOrCs = true;
41 }
42
43 CExports::cvbval_t currentPort = 0;
44 if (CExports::CanCameraSelect2(Handle()))
45 {
46 auto result = CExports::CS2GetCamPort(Handle(), currentPort);
47 if (result < 0)
48 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to get port"));
49 hasBsOrCs = true;
50 }
51 else if (CExports::CanCameraSelect(Handle()))
52 {
53 auto result = CExports::GetCamPort(Handle(), currentPort);
54 if (result < 0)
55 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to get port"));
56 hasBsOrCs = true;
57 }
58
59 if (hasBsOrCs)
60 return Cvb::Driver::VinConnectionInformation(static_cast<int>(currentPort), static_cast<int>(currentBoard));
61 else if (Internal::IsAccessToken(ResourceLocator()))
63
65 }
66
67 inline void VinDevice::ChangeHandle(HandleGuard<Device> &&guard, DeviceUpdateMode mode)
68 {
69 Device::ChangeHandle(std::move(guard), mode);
70 }
71
72 inline DeviceImagePtr VinDevice::CreateDeviceImage() const
73 {
75 }
76
77 inline StreamBasePtr VinDevice::CreateStream(int, StreamType streamType) const
78 {
79 if (streamType != StreamType::Legacy)
80 throw std::logic_error("this device supports only legacy streams");
81
82 if (!CExports::CanRingBuffer(Handle()))
84 else
86 }
87
88 inline VinDevice::NonRingBufferVinStream::NonRingBufferVinStream(const DevicePtr &device)
89 : VinStream(device)
90 , layout_(Driver::BufferImage::ImageLayout::FromIMGHandle(device->Handle()))
91 {
92 }
93
94 inline StreamImagePtr VinDevice::NonRingBufferVinStream::MakeSnapshotImage()
95 {
96 double rawTimestamp = std::numeric_limits<double>::quiet_NaN();
97 if (CExports::G2GetGrabStatus(Parent()->Handle(), CExports::GRAB_INFO_TIMESTAMP, rawTimestamp) >= 0)
98 return Driver::BufferImage::Create(Parent(), *layout_, rawTimestamp);
99 else
100 return Driver::BufferImage::Create(Parent(), *layout_, std::numeric_limits<double>::quiet_NaN());
101 }
102
103 inline VinDevice::RingBufferVinStream::RingBufferVinStream(const DevicePtr &device)
104 : VinStream(device)
105 , ringBuffer_(std::make_shared<class RingBuffer>(device))
106 {
107 }
108
109 inline StreamImagePtr VinDevice::RingBufferVinStream::MakeStreamImage()
110 {
111 CExports::cvbval_t bufferIndex = 0;
112 auto result = CExports::RBBufferSeq(Parent()->Handle(), 0, bufferIndex);
113
114 if (result < 0)
115 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to get ring buffer sequence"));
116
117 auto image = RingBuffer()->At(bufferIndex);
118 image->RaisePixelContentChanged();
119 return image;
120 }
121
122 inline StreamImagePtr VinDevice::RingBufferVinStream::MakeSnapshotImage()
123 {
124
125 double rawTimestamp = std::numeric_limits<double>::quiet_NaN();
126 CExports::G2GetGrabStatus(Parent()->Handle(), CExports::GRAB_INFO_TIMESTAMP, rawTimestamp);
127 return BufferImage::Create(Parent(), rawTimestamp);
128 }
129
130 inline RingBufferPtr VinDevice::RingBufferVinStream::RingBuffer() const noexcept
131 {
132 return ringBuffer_;
133 }
134
135 } // namespace Driver
136
137 CVB_END_INLINE_NS
138
139} // namespace Cvb
String ResourceLocator() const noexcept
Gets the access token or path of the file name including its extension.
Definition decl_device.hpp:132
void * Handle() const noexcept
Classic API device handle.
Definition decl_device.hpp:122
DevicePtr Parent() const noexcept
Gets the parent device of this stream.
Definition stream_base.hpp:42
Contains the board and port information of a device or its access token.
Definition vin_connection_information.hpp:24
Cvb::Driver::VinConnectionInformation VinConnectionInformation() const
Gets the board and port information of this device.
Definition detail_vin_device.hpp:23
T make_shared(T... args)
T move(T... args)
Namespace for driver or device related operations.
Definition decl_composite.hpp:28
std::shared_ptr< StreamImage > StreamImagePtr
Convenience shared pointer for StreamImage.
Definition driver.hpp:93
std::shared_ptr< DeviceImage > DeviceImagePtr
Convenience shared pointer for DeviceImage.
Definition driver.hpp:61
std::shared_ptr< StreamBase > StreamBasePtr
Convenience shared pointer for StreamBase.
Definition driver.hpp:113
std::shared_ptr< RingBuffer > RingBufferPtr
Convenience shared pointer for RingBuffer.
Definition driver.hpp:41
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::shared_ptr< Device > DevicePtr
Convenience shared pointer for Device.
Definition global.hpp:98
DeviceUpdateMode
Defines how to treat the optional device image, when the device itself is updated.
Definition global.hpp:252
T const_pointer_cast(T... args)
T quiet_NaN(T... args)
T rethrow_exception(T... args)