YARP
Yet Another Robot Platform
ServerFrameGrabberDual.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef YARP_DEV_SERVERGRABBER_H
8 #define YARP_DEV_SERVERGRABBER_H
9 
10 #include <cstdio>
11 
12 
17 #include <yarp/dev/PolyDriver.h>
19 #include <yarp/os/BufferedPort.h>
20 #include <yarp/os/Time.h>
21 #include <yarp/os/Network.h>
22 #include <yarp/os/PeriodicThread.h>
23 #include <yarp/os/Vocab.h>
24 #include <yarp/os/Bottle.h>
25 #include <yarp/dev/IWrapper.h>
27 
31 
32 class ServerGrabber;
33 
34 
37 {
38 private:
39  bool left{false};
40  ServerGrabber* server{nullptr};
41 public:
42  ServerGrabberResponder(bool _left = false);
43  ~ServerGrabberResponder() override = default;
44  bool configure(ServerGrabber* _server);
45  bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply) override;
46 };
47 
48 
50 {
51 // AV,
53  RAW,
54 };
55 
56 
58 {
59  bool spoke{false}; // location of this variable tickles bug on Solaris/gcc3.2
60  bool canDrop{true};
61  bool addStamp{false};
62  bool active{false};
63  bool singleThreaded{false};
64  bool twoCameras{false};
65  bool split{false};
66  bool splitterMode{false};
67  bool hasAudio{false};
69 };
70 
71 
72 #define DEFAULT_THREAD_PERIOD 0.03 //s
73 
74 
169  public yarp::dev::IWrapper,
172 {
173 private:
174  double period{DEFAULT_THREAD_PERIOD};
175  int count{0};
176  int count2{0};
177  ServerGrabberResponder* responder{nullptr};
178  ServerGrabberResponder* responder2{nullptr};
181  yarp::dev::IRgbVisualParams* rgbVis_p{nullptr};
182  yarp::dev::IRgbVisualParams* rgbVis_p2{nullptr};
183  std::string rpcPort_Name;
184  std::string rpcPort2_Name;
185  yarp::os::Port rpcPort;
186  yarp::os::Port rpcPort2;
187  std::string pImg_Name;
188  std::string pImg2_Name;
191  yarp::os::Port *p2{nullptr};//audio
192  yarp::dev::PolyDriver* poly{nullptr}; //subDeviceOwned convert to pointer
193  yarp::dev::PolyDriver* poly2{nullptr};
194  yarp::dev::IFrameGrabberImage *fgImage{nullptr};
195  yarp::dev::IFrameGrabberImage *fgImage2{nullptr};
196  yarp::dev::IFrameGrabberImageRaw *fgImageRaw{nullptr};
197  yarp::dev::IFrameGrabberImageRaw *fgImageRaw2{nullptr};
198  //yarp::sig::FlexImage doubleImage, doubleImage2;
199 // IAudioVisualGrabber *fgAv{nullptr}; //TODO: manage the AV
200  yarp::dev::IFrameGrabberControls *fgCtrl{nullptr};
201  yarp::dev::IFrameGrabberControls *fgCtrl2{nullptr};
202  yarp::dev::IFrameGrabberControlsDC1394* fgCtrl_DC1394{nullptr};
203  yarp::dev::IFrameGrabberControlsDC1394* fgCtrl2_DC1394{nullptr};
204  yarp::dev::IPreciselyTimed *fgTimed{nullptr};
209  Configuration param;
213  yarp::sig::ImageOf<yarp::sig::PixelMono>* img2_Raw{nullptr};
214 
215  // Open the wrapper only, the attach method needs to be called before using it
216  // Typical usage: yarprobotinterface
217  bool openDeferredAttach(yarp::os::Searchable& prop);
218 
219  // If a subdevice parameter is given, the wrapper will open it(or them) and attach to immediately.
220  // Typical usage: simulator or command line
221  bool isSubdeviceOwned{false};
222  bool openAndAttachSubDevice(yarp::os::Searchable& prop);
223 
224 public:
225  ServerGrabber();
226  ServerGrabber(const ServerGrabber&) = delete;
230  ~ServerGrabber() override;
231 
232  //DeviceDriver
233  bool close() override;
239  bool open(yarp::os::Searchable& config) override;
240 
241  //bool read(ConnectionReader& connection) override;
242 
243  //DeviceResponder
244  bool respond(const yarp::os::Bottle& command,
245  yarp::os::Bottle& reply, bool left, bool both);
246  // IMultipleWrapper interface
247  bool attachAll(const yarp::dev::PolyDriverList &device2attach) override;
248 
249  bool detachAll() override;
250 
251  // IWrapper interface
252  bool attach(yarp::dev::PolyDriver *poly) override;
253 
254  bool detach() override;
255 
256  //RateThread
257  bool threadInit() override;
258 
259  void threadRelease() override;
260 
261  void run() override;
262 protected:
263 
264  bool fromConfig(yarp::os::Searchable &config);
265 
267 
268  void stopThread();
269 
270  void setupFlexImage(const yarp::sig::Image& img, yarp::sig::FlexImage& flex_i);
271 
273 
274  void cleanUp();
275 };
276 
277 #endif // YARP_DEV_SERVERGRABBER_H
#define DEFAULT_THREAD_PERIOD
ServerGrabberResponder(bool _left=false)
bool configure(ServerGrabber *_server)
bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply) override
Respond to a message.
~ServerGrabberResponder() override=default
grabberDual deprecated: A Network grabber for camera devices.
void threadRelease() override
Release method.
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
ServerGrabber & operator=(ServerGrabber &&)=delete
bool detach() override
Detach the object (you must have first called attach).
bool open(yarp::os::Searchable &config) override
Configure with a set of options.
ServerGrabber(const ServerGrabber &)=delete
bool close() override
Close the DeviceDriver.
void setupFlexImage(const yarp::sig::Image &img, yarp::sig::FlexImage &flex_i)
void shallowCopyImages(const yarp::sig::FlexImage &src, yarp::sig::FlexImage &dest)
void run() override
Loop function.
ServerGrabber(ServerGrabber &&)=delete
bool detachAll() override
Detach the object (you must have first called attach).
ServerGrabber & operator=(const ServerGrabber &)=delete
bool initialize_YARP(yarp::os::Searchable &params)
bool attachAll(const yarp::dev::PolyDriverList &device2attach) override
Attach to a list of objects.
bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply, bool left, bool both)
bool fromConfig(yarp::os::Searchable &config)
bool threadInit() override
Initialization method.
Interface implemented by all device drivers.
Definition: DeviceDriver.h:35
A cheap and cheerful framework for human readable/writable forms of messages to devices.
Definition: DeviceDriver.h:131
Control interface for frame grabber devices.
Interface for an object that can wrap/attach to to another.
An interface for retrieving intrinsic parameter from a rgb camera.
Interface for an object that can wrap/or "attach" to another.
Definition: IWrapper.h:26
A container for a device driver.
Definition: PolyDriver.h:24
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
An abstraction for a periodic thread.
A mini-server for network communication.
Definition: Port.h:47
A base class for nested structures that can be searched.
Definition: Searchable.h:66
Image class with user control of representation details.
Definition: Image.h:414
Base class for storing images.
Definition: Image.h:82