VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gvcamera.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file gvcamera.h
19 ///
20 
21 #ifndef GV_CAMERA__H
22 #define GV_CAMERA__H
23 
24 #include "gdef.h"
25 #include "gnet.h"
26 #include "gtimer.h"
27 #include "geventloop.h"
28 #include "gvimageinput.h"
29 #include "gvcapture.h"
30 #include "gvoverlay.h"
31 #include "gvcapturebuffer.h"
32 #include "geventhandler.h"
33 #include "gvtimezone.h"
34 #include "gtimer.h"
35 #include "glog.h"
36 #include "gassert.h"
37 #include <string>
38 #include <memory>
39 
40 namespace Gv
41 {
42  class Camera ;
43 }
44 
45 /// \class Gv::Camera
46 /// A high-level webcam interface that hooks into the GNet event loop and acts
47 /// as an Gv::ImageInputSource. Supports lazy device opening, transparent
48 /// re-opening, and slow reads.
49 ///
51 {
52 public:
53  Camera( Gr::ImageConverter & , const std::string & dev_name , const std::string & dev_config ,
54  bool one_shot , bool lazy_open , unsigned int lazy_open_timeout ,
55  const std::string & caption , const Gv::Timezone & caption_tz = Gv::Timezone() ,
56  const std::string & image_input_source_name = std::string() ) ;
57  ///< Constructor. Adds itself to the GNet event loop.
58  ///<
59  ///< The device configuration string supports a "sleep" parameter for slow
60  ///< reads; while sleeping any read events are ignored. The device
61  ///< configuration is also passed to the Gv::Capture sub-object.
62  ///<
63  ///< Images are received by objects implementing Gv::ImageInputHandler,
64  ///< and they need to register themselves by calling the base class
65  ///< Gv::ImageInputSource::addImageInputHandler() method.
66 
67  virtual ~Camera() ;
68  ///< Destructor.
69 
70  bool isOpen() const ;
71  ///< Returns true if the webcam device is open.
72 
73 private:
74  Camera( const Camera & ) ;
75  void operator=( const Camera & ) ;
76  int fd() const ;
77  Capture * create( const std::string & , const std::string & , bool ) ;
78  void onOpenTimeout() ;
79  void onReadTimeout() ;
80  void onSendTimeout() ;
81  void onOpen() ;
82  void doRead() ;
83  bool doReadImp() ;
84  void blank() ;
85 
86 private:
87  virtual void readEvent() override ; // GNet::EventHandler
88  virtual void onException( std::exception & ) override ; // GNet::EventHandler
89  virtual void resend( ImageInputHandler & ) override ; // Gv::ImageInputSource
90 
91 private:
92  std::string m_dev_name ;
93  std::string m_dev_config ;
94  bool m_one_shot ;
95  bool m_lazy_open ;
96  unsigned int m_open_timeout ;
97  std::string m_caption ;
98  Gv::Timezone m_tz ;
99  Gr::Image m_image ;
100  Gr::ImageType m_image_type ;
101  unique_ptr<Gv::Capture> m_capture ;
102  int m_dx ;
103  int m_dy ;
104  GNet::Timer<Camera> m_open_timer ;
105  GNet::Timer<Camera> m_read_timer ;
106  GNet::Timer<Camera> m_send_timer ;
107  unsigned int m_sleep_ms ;
108 } ;
109 
110 #endif
virtual ~Camera()
Destructor.
Definition: gvcamera.cpp:56
A high-level webcam interface that hooks into the GNet event loop and acts as an Gv::ImageInputSource...
Definition: gvcamera.h:50
A representation of a timezone.
Definition: gvtimezone.h:35
An encapsulation of image type, including width, height and number of channels, with support for a st...
Definition: grimagetype.h:43
A callback interface for Gv::ImageInputSource.
Definition: gvimageinput.h:84
bool isOpen() const
Returns true if the webcam device is open.
Definition: gvcamera.cpp:62
A class holding shared read-only image data (Gr::ImageBuffer) and its associated image type (Gr::Imag...
Definition: grimage.h:41
A base class for distributing incoming images to multiple client objects, supporting some simple imag...
Definition: gvimageinput.h:116
A base class for classes that handle asynchronous events from the event loop.
Definition: geventhandler.h:78
A video capture abstract interface, exposing a file descriptor and a method to handle read events on ...
Definition: gvcapture.h:40
An image format converter that can convert to and from the raw and jpeg formats (only), with scaling and monochrome options.
A timer class template in which the timeout is delivered to the specified method. ...
Definition: gtimer.h:110
Camera(Gr::ImageConverter &, const std::string &dev_name, const std::string &dev_config, bool one_shot, bool lazy_open, unsigned int lazy_open_timeout, const std::string &caption, const Gv::Timezone &caption_tz=Gv::Timezone(), const std::string &image_input_source_name=std::string())
Constructor.
Definition: gvcamera.cpp:28