ifm3d
frame_grabber.h
1 /*
2  * Copyright 2022-present ifm electronic, gmbh
3 
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef IFM3D_FG_FRAMEGRABBER_H
8 #define IFM3D_FG_FRAMEGRABBER_H
9 
10 #include <cstdint>
11 #include <future>
12 #include <memory>
13 #include <optional>
14 #include <vector>
15 #include <variant>
16 #include <type_traits>
17 #include <ifm3d/device/device.h>
18 #include <ifm3d/device/err.h>
19 #include <ifm3d/fg/buffer.h>
20 #include <ifm3d/fg/organizer.h>
21 #include <ifm3d/fg/frame.h>
22 #include <ifm3d/fg/frame_grabber_export.h>
23 namespace ifm3d
24 {
29  class IFM3D_FRAME_GRABBER_EXPORT FrameGrabber
30  {
31  public:
32  using Ptr = std::shared_ptr<FrameGrabber>;
33  using NewFrameCallback = std::function<void(Frame::Ptr)>;
34  using AsyncErrorCallback = std::function<void(int, const std::string&)>;
35  using AsyncNotificationCallback =
36  std::function<void(const std::string&, const std::string&)>;
37  using BufferList =
38  std::vector<std::variant<std::uint64_t, int, ifm3d::buffer_id>>;
39  using ErrorCallback = std::function<void(const ifm3d::Error&)>;
40 
47  FrameGrabber(ifm3d::Device::Ptr cam,
48  std::optional<std::uint16_t> pcic_port = std::nullopt);
49 
54  virtual ~FrameGrabber();
55 
56  // disable copy/move semantics
57  FrameGrabber(FrameGrabber&&) = delete;
58  FrameGrabber& operator=(FrameGrabber&&) = delete;
59  FrameGrabber(FrameGrabber&) = delete;
60  FrameGrabber& operator=(const FrameGrabber&) = delete;
61 
77  std::shared_future<void> SWTrigger();
78 
83  void OnNewFrame(NewFrameCallback callback = nullptr);
84 
106  std::shared_future<void> Start(
107  const BufferList& buffers,
108  const std::optional<json>& pcicFormat = std::nullopt);
109 
115  std::shared_future<void> Stop();
116 
120  bool IsRunning();
121 
125  std::shared_future<Frame::Ptr> WaitForFrame();
126 
133  void SetOrganizer(std::unique_ptr<Organizer> organizer);
134 
141  void OnAsyncError(AsyncErrorCallback callback = nullptr);
142 
148  void OnAsyncNotification(AsyncNotificationCallback callback = nullptr);
149 
154  void OnError(ErrorCallback callback = nullptr);
155 
162  void SetMasking(const bool mask);
163 
167  bool IsMasking();
168 
169  private:
170  class Impl;
171  std::unique_ptr<Impl> pImpl;
172 
173  }; // end: class FrameGrabber
174 
175 } // end: namespace ifm3d
176 
177 #endif // IFM3D_FG_FRAMEGRABBER_H
ifm3d::FrameGrabber
Definition: frame_grabber.h:29
ifm3d::Error
Definition: err.h:117