CVB++ 15.0
detail_video_device.hpp
1#pragma once
2
3#include <memory>
4
5#include "../../global.hpp"
6
7#include "../_decl/decl_video_device.hpp"
8#include "../_decl/decl_video_image.hpp"
9#include "../_decl/decl_device_control.hpp"
10#include "../_decl/decl_indexed_stream.hpp"
11
12namespace Cvb
13{
14
15 CVB_BEGIN_INLINE_NS
16
17 namespace Driver
18 {
19
21 {
22 auto stream = StreamsOptional(0);
23 if (!stream)
24 return playbackMode_;
25
26 // if stream is out read value from stream instead and write back
27 switch (stream->AcquisitionInterface())
28 {
29 default:
32 break;
33
36 break;
37 }
38
39 return playbackMode_;
40 }
41
43 {
44 if (playbackMode_ == playbackMode)
45 return;
46
47 playbackMode_ = playbackMode;
48 auto stream = StreamsOptional(0);
49 if (!stream)
50 return;
51
52 stream->SetAcquisitionInterface(AcquisitionInterfaceForPlaybackMode(playbackMode_));
53 }
54
55 inline std::chrono::milliseconds VideoDevice::FrameTime() const
56 {
57 double frameTime = std::numeric_limits<double>::quiet_NaN();
58 auto deviceControl = DeviceControl();
59 deviceControl->SendCommand(DeviceControlCommand(CExports::DC_FRAMETIME, DeviceControlOperation::Get), nullptr,
60 frameTime);
61 return std::chrono::milliseconds(static_cast<std::uint32_t>(frameTime));
62 }
63
64 inline DeviceImagePtr VideoDevice::CreateDeviceImage() const
65 {
67 }
68
69 inline StreamBasePtr VideoDevice::CreateStream(int, StreamType streamType) const
70 {
71 if (streamType != StreamType::Legacy)
72 throw std::logic_error("this device supports only legacy streams");
74 }
75
76 inline VideoDevice::VideoStream::VideoStream(const DevicePtr &device)
77 : IndexedStream(device)
78 , layout_(Driver::BufferImage::ImageLayout::FromIMGHandle(device->Handle()))
79 , imageCount_(
80 static_cast<int>(device->DigitalIO()->ReadInputGroup(CExports::Video::ImageCountGroup).to_ulong()))
81 {
82 }
83
84 inline int VideoDevice::VideoStream::ImageIndex() const
85 {
86 auto digitalIO = Parent()->DigitalIO();
87 return static_cast<int>(digitalIO->ReadOutputGroup(CExports::Video::CurrentImageIndexGroup).to_ulong());
88 }
89
90 inline void VideoDevice::VideoStream::SetImageIndex(int index)
91 {
92 if (index < 0 || index >= ImageCount())
93 throw std::out_of_range("image index out of range");
94
95 auto digitalIO = Parent()->DigitalIO();
96 digitalIO->WriteOutputGroup(CExports::Video::CurrentImageIndexGroup,
97 std::bitset<32>(static_cast<std::uint32_t>(index)));
98 auto result = CExports::Snap(Parent()->Handle());
99 if (result < 0)
100 std::rethrow_exception(CvbException::FromCvbResult(result, "failed to snap"));
101 std::dynamic_pointer_cast<const VideoDevice>(Parent())->OnImageAcquired();
102 }
103
104 } // namespace Driver
105
106 CVB_END_INLINE_NS
107
108} // namespace Cvb
DeviceControlPtr DeviceControl() const
Gets the DeviceControl interface if present.
Definition detail_device.hpp:157
void * Handle() const noexcept
Classic API device handle.
Definition decl_device.hpp:122
A specific command to send to the driver.
Definition decl_device_control.hpp:19
Digital I/O operations on a device.
Definition decl_digital_io.hpp:19
A stream with a finite number of images, which can also be accessed via an index.
Definition decl_indexed_stream.hpp:20
DevicePtr Parent() const noexcept
Gets the parent device of this stream.
Definition stream_base.hpp:42
Cvb::Driver::PlaybackMode PlaybackMode() const noexcept
Gets how images are delivered by the stream.
Definition detail_video_device.hpp:20
void SetPlaybackMode(Cvb::Driver::PlaybackMode playbackMode)
Sets how images are delivered by the stream.
Definition detail_video_device.hpp:42
T make_shared(T... args)
Namespace for driver or device related operations.
Definition decl_composite.hpp:28
@ Get
Get information from the device.
Definition driver.hpp:528
PlaybackMode
Defines how frames are acquired by this video device.
Definition driver.hpp:421
@ FrameByFrame
The Stream::Wait() method always returns the next image in the video stream.
Definition driver.hpp:423
@ Stream
Definition driver.hpp:430
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
@ Grab2
Ring buffer / queue based acquisition.
Definition driver.hpp:439
@ Grabber
Basic grabber interface for single image acquisition.
Definition driver.hpp:437
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
T const_pointer_cast(T... args)
T quiet_NaN(T... args)