YARP
Yet Another Robot Platform
ServerFrameGrabberDual.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_DEV_SERVERGRABBER_H
11 #define YARP_DEV_SERVERGRABBER_H
12 
13 #include <cstdio>
14 
20 #include <yarp/dev/PolyDriver.h>
22 #include <yarp/os/BufferedPort.h>
23 #include <yarp/os/Time.h>
24 #include <yarp/os/Network.h>
25 #include <yarp/os/PeriodicThread.h>
26 #include <yarp/os/Vocab.h>
27 #include <yarp/os/Bottle.h>
29 #include <yarp/dev/IWrapper.h>
31 
32 
33 class ServerGrabber;
34 
35 class DC1394Parser :
37 {
38 private:
39  yarp::dev::IFrameGrabberControlsDC1394 *fgCtrl_DC1394{nullptr};
40 
41 public:
42  DC1394Parser() = default;
43  ~DC1394Parser() override = default;
45  bool respond(const yarp::os::Bottle& cmd, yarp::os::Bottle& response) override;
46 };
47 
48 
51 {
52 private:
53  bool left{false};
54  ServerGrabber* server{nullptr};
55 public:
56  ServerGrabberResponder(bool _left = false);
57  ~ServerGrabberResponder() override = default;
58  bool configure(ServerGrabber* _server);
59  bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply) override;
60 };
61 
62 
64 {
65 // AV,
67  RAW,
68 };
69 
70 
72 {
73  bool spoke{false}; // location of this variable tickles bug on Solaris/gcc3.2
74  bool canDrop{true};
75  bool addStamp{false};
76  bool active{false};
77  bool singleThreaded{false};
78  bool twoCameras{false};
79  bool split{false};
80  bool splitterMode{false};
81  bool hasAudio{false};
83 };
84 
85 
86 #define DEFAULT_THREAD_PERIOD 0.03 //s
87 
88 
183  public yarp::dev::IWrapper,
186 {
187 private:
188  double period{DEFAULT_THREAD_PERIOD};
189  int count{0};
190  int count2{0};
191  ServerGrabberResponder* responder{nullptr};
192  ServerGrabberResponder* responder2{nullptr};
195  yarp::dev::IRgbVisualParams* rgbVis_p{nullptr};
196  yarp::dev::IRgbVisualParams* rgbVis_p2{nullptr};
197  std::string rpcPort_Name;
198  std::string rpcPort2_Name;
199  yarp::os::Port rpcPort;
200  yarp::os::Port rpcPort2;
201  std::string pImg_Name;
202  std::string pImg2_Name;
205  yarp::os::Port *p2{nullptr};//audio
206  yarp::dev::PolyDriver* poly{nullptr}; //subDeviceOwned convert to pointer
207  yarp::dev::PolyDriver* poly2{nullptr};
208  yarp::dev::IFrameGrabberImage *fgImage{nullptr};
209  yarp::dev::IFrameGrabberImage *fgImage2{nullptr};
210  yarp::dev::IFrameGrabberImageRaw *fgImageRaw{nullptr};
211  yarp::dev::IFrameGrabberImageRaw *fgImageRaw2{nullptr};
212  //yarp::sig::FlexImage doubleImage, doubleImage2;
213 // IAudioVisualGrabber *fgAv{nullptr}; //TODO: manage the AV
214  yarp::dev::IFrameGrabberControls *fgCtrl{nullptr};
215  yarp::dev::IFrameGrabberControls *fgCtrl2{nullptr};
216  yarp::dev::IFrameGrabberControlsDC1394* fgCtrl_DC1394{nullptr};
217  yarp::dev::IFrameGrabberControlsDC1394* fgCtrl2_DC1394{nullptr};
218  yarp::dev::IPreciselyTimed *fgTimed{nullptr};
221  DC1394Parser ifgCtrl_DC1394_Parser;
222  DC1394Parser ifgCtrl2_DC1394_Parser;
223  Configuration param;
227  yarp::sig::ImageOf<yarp::sig::PixelMono>* img2_Raw{nullptr};
228 
229  // Open the wrapper only, the attach method needs to be called before using it
230  // Typical usage: yarprobotinterface
231  bool openDeferredAttach(yarp::os::Searchable& prop);
232 
233  // If a subdevice parameter is given, the wrapper will open it(or them) and attach to immediately.
234  // Typical usage: simulator or command line
235  bool isSubdeviceOwned{false};
236  bool openAndAttachSubDevice(yarp::os::Searchable& prop);
237 
238 public:
239  ServerGrabber();
240  ServerGrabber(const ServerGrabber&) = delete;
244  ~ServerGrabber() override;
245 
246  //DeviceDriver
247  bool close() override;
253  bool open(yarp::os::Searchable& config) override;
254 
255  //bool read(ConnectionReader& connection) override;
256 
257  //DeviceResponder
258  bool respond(const yarp::os::Bottle& command,
259  yarp::os::Bottle& reply, bool left, bool both);
260  // IMultipleWrapper interface
261  bool attachAll(const yarp::dev::PolyDriverList &device2attach) override;
262 
263  bool detachAll() override;
264 
265  // IWrapper interface
266  bool attach(yarp::dev::PolyDriver *poly) override;
267 
268  bool detach() override;
269 
270  //RateThread
271  bool threadInit() override;
272 
273  void threadRelease() override;
274 
275  void run() override;
276 protected:
277 
278  bool fromConfig(yarp::os::Searchable &config);
279 
281 
282  void stopThread();
283 
284  void setupFlexImage(const yarp::sig::Image& img, yarp::sig::FlexImage& flex_i);
285 
287 
288  void cleanUp();
289 };
290 
291 #endif // YARP_DEV_SERVERGRABBER_H
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
yarp::dev::IFrameGrabberImageRaw
Read a YARP-format image from a device.
Definition: FrameGrabberInterfaces.h:293
ServiceInterfaces.h
Network.h
DC1394Parser::respond
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
Definition: ServerFrameGrabberDual.cpp:39
ServerGrabber::close
bool close() override
Close the DeviceDriver.
Definition: ServerFrameGrabberDual.cpp:202
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
Configuration::singleThreaded
bool singleThreaded
Definition: ServerFrameGrabberDual.h:77
IWrapper.h
IPreciselyTimed.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
Configuration::splitterMode
bool splitterMode
Definition: ServerFrameGrabberDual.h:80
Capabilities
Capabilities
Definition: ServerFrameGrabberDual.h:64
ServerGrabber::attach
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
Definition: ServerFrameGrabberDual.cpp:943
ServerGrabber::ServerGrabber
ServerGrabber()
Definition: ServerFrameGrabberDual.cpp:191
ServerGrabber::setupFlexImage
void setupFlexImage(const yarp::sig::Image &img, yarp::sig::FlexImage &flex_i)
Definition: ServerFrameGrabberDual.cpp:935
Configuration::split
bool split
Definition: ServerFrameGrabberDual.h:79
AudioGrabberInterfaces.h
DC1394Parser
Definition: ServerFrameGrabberDual.h:37
Configuration::hasAudio
bool hasAudio
Definition: ServerFrameGrabberDual.h:81
yarp::dev::PolyDriverList
Definition: PolyDriverList.h:22
FrameGrabberControlImpl.h
DC1394Parser::configure
bool configure(yarp::dev::IFrameGrabberControlsDC1394 *interface)
Definition: ServerFrameGrabberDual.cpp:33
ServerGrabberResponder
Definition: ServerFrameGrabberDual.h:51
COLOR
@ COLOR
Definition: ServerFrameGrabberDual.h:66
yarp::sig::ImageOf< yarp::sig::PixelRgb >
DC1394Parser::~DC1394Parser
~DC1394Parser() override=default
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
yarp::os::BufferedPort< yarp::sig::FlexImage >
ServerGrabber::open
bool open(yarp::os::Searchable &config) override
Configure with a set of options.
Definition: ServerFrameGrabberDual.cpp:260
Configuration::spoke
bool spoke
Definition: ServerFrameGrabberDual.h:73
Configuration
Definition: ServerFrameGrabberDual.h:72
ServerGrabber::stopThread
void stopThread()
Definition: ServerFrameGrabberDual.cpp:918
ServerGrabber::cleanUp
void cleanUp()
Definition: ServerFrameGrabberDual.cpp:1327
AudioVisualInterfaces.h
ServerGrabberResponder::respond
bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply) override
Respond to a message.
Definition: ServerFrameGrabberDual.cpp:173
ServerGrabber::initialize_YARP
bool initialize_YARP(yarp::os::Searchable &params)
Definition: ServerFrameGrabberDual.cpp:426
IVisualParamsImpl.h
ServerGrabber::~ServerGrabber
~ServerGrabber() override
Definition: ServerFrameGrabberDual.cpp:196
yarp::dev::IFrameGrabberImage
Read a YARP-format image from a device.
Definition: FrameGrabberInterfaces.h:241
PolyDriver.h
yarp::sig::FlexImage
Image class with user control of representation details.
Definition: Image.h:403
RAW
@ RAW
Definition: ServerFrameGrabberDual.h:67
ServerGrabber::shallowCopyImages
void shallowCopyImages(const yarp::sig::FlexImage &src, yarp::sig::FlexImage &dest)
Definition: ServerFrameGrabberDual.cpp:1321
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
Configuration::cap
Capabilities cap
Definition: ServerFrameGrabberDual.h:82
ServerGrabber::detach
bool detach() override
Detach the object (you must have first called attach).
Definition: ServerFrameGrabberDual.cpp:964
yarp::dev::IWrapper
Interface for an object that can wrap/or "attach" to another.
Definition: IWrapper.h:29
ServerGrabber::operator=
ServerGrabber & operator=(const ServerGrabber &)=delete
Configuration::active
bool active
Definition: ServerFrameGrabberDual.h:76
ServerGrabber::ServerGrabber
ServerGrabber(ServerGrabber &&)=delete
ServerGrabber::respond
bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply, bool left, bool both)
Definition: ServerFrameGrabberDual.cpp:472
yarp::dev::IFrameGrabberControls
Control interface for frame grabber devices.
Definition: FrameGrabberInterfaces.h:365
BufferedPort.h
IMultipleWrapper.h
ServerGrabber::fromConfig
bool fromConfig(yarp::os::Searchable &config)
Definition: ServerFrameGrabberDual.cpp:325
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
FrameGrabberInterfaces.h
define common interfaces to discover remote camera capabilities
yarp::dev::Implement_RgbVisualParams_Parser
Definition: IVisualParamsImpl.h:54
ServerGrabber::run
void run() override
Loop function.
Definition: ServerFrameGrabberDual.cpp:1133
PeriodicThread.h
Configuration::canDrop
bool canDrop
Definition: ServerFrameGrabberDual.h:74
yarp::dev::DeviceResponder
A cheap and cheerful framework for human readable/writable forms of messages to devices.
Definition: DeviceDriver.h:134
yarp::dev::IRgbVisualParams
An interface for retrieving intrinsic parameter from a rgb camera.
Definition: IVisualParams.h:73
DEFAULT_THREAD_PERIOD
#define DEFAULT_THREAD_PERIOD
Definition: ServerFrameGrabberDual.h:86
DC1394Parser::DC1394Parser
DC1394Parser()=default
yarp::dev::IMultipleWrapper
Interface for an object that can wrap/attach to to another.
Definition: IMultipleWrapper.h:30
ServerGrabber::attachAll
bool attachAll(const yarp::dev::PolyDriverList &device2attach) override
Attach to a list of objects.
Definition: ServerFrameGrabberDual.cpp:739
ServerGrabberResponder::~ServerGrabberResponder
~ServerGrabberResponder() override=default
yarp::sig::Image
Base class for storing images.
Definition: Image.h:85
Vocab.h
yarp::dev::IFrameGrabberControlsDC1394
Definition: FrameGrabberInterfaces.h:714
Time.h
ServerGrabberResponder::ServerGrabberResponder
ServerGrabberResponder(bool _left=false)
Definition: ServerFrameGrabberDual.cpp:157
Configuration::twoCameras
bool twoCameras
Definition: ServerFrameGrabberDual.h:78
ServerGrabber::threadInit
bool threadInit() override
Initialization method.
Definition: ServerFrameGrabberDual.cpp:1072
ServerGrabber::threadRelease
void threadRelease() override
Release method.
Definition: ServerFrameGrabberDual.cpp:1127
ServerGrabber::detachAll
bool detachAll() override
Detach the object (you must have first called attach).
Definition: ServerFrameGrabberDual.cpp:909
ServerGrabber::operator=
ServerGrabber & operator=(ServerGrabber &&)=delete
ServerGrabber::ServerGrabber
ServerGrabber(const ServerGrabber &)=delete
yarp::dev::FrameGrabberControls_Parser
Definition: FrameGrabberControlImpl.h:59
yarp::dev::IPreciselyTimed
Definition: IPreciselyTimed.h:21
ServerGrabber
grabberDual: A Network grabber for camera devices.
Definition: ServerFrameGrabberDual.h:186
Bottle.h
Configuration::addStamp
bool addStamp
Definition: ServerFrameGrabberDual.h:75
ServerGrabberResponder::configure
bool configure(ServerGrabber *_server)
Definition: ServerFrameGrabberDual.cpp:162