VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gvcapture.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 gvcapture.h
19 ///
20 
21 #ifndef GV_CAPTURE__H
22 #define GV_CAPTURE__H
23 
24 #include "gdef.h"
25 #include "gvcapturebuffer.h"
26 #include "gexception.h"
27 #include <string>
28 
29 namespace Gv
30 {
31  class CaptureCallback ;
32  class Capture ;
33 }
34 
35 /// \class Gv::Capture
36 /// A video capture abstract interface, exposing a file descriptor
37 /// and a method to handle read events on it. The read method
38 /// delivers images to a callback interface in a "capture buffer".
39 ///
41 {
42 public:
43  G_EXCEPTION( NoDevice , "no such device" ) ;
44  G_EXCEPTION( Error , "video capture error" ) ;
45 
46  virtual ~Capture() = 0 ;
47  ///< Destructor.
48 
49  virtual void start() = 0 ;
50  ///< Restarts capturing after a stop(). Not normally needed.
51 
52  virtual void stop() = 0 ;
53  ///< Stops capturing.
54 
55  virtual bool simple() const = 0 ;
56  ///< Returns true if a complete RGB24 image can be read out
57  ///< of the capture device and straight into a contiguous
58  ///< image buffer using the appropriate read() overload.
59  ///< This is typically only true when using libv4l with the
60  ///< 'read' i/o method.
61 
62  virtual bool read( unsigned char * , size_t n ) = 0 ;
63  ///< Does a read of an RGB24 image into the user-supplied buffer,
64  ///< on condition that the device is simple().
65 
66  virtual bool read( CaptureCallback & ) = 0 ;
67  ///< Delivers an image to the given callback fn. Returns true if an
68  ///< image was delivered to the callback interface, or false if
69  ///< none was available.
70 
71  virtual int fd() const = 0 ;
72  ///< Returns the fd for select().
73  ///<
74  ///< Note that when using streaming i/o there is no way to stop
75  ///< events being delivered to this file descriptor. Using stop()
76  ///< is not sufficient; also remove the file descriptor from the
77  ///< event loop.
78 
79  virtual unsigned int dx() const = 0 ;
80  ///< Returns the width.
81 
82  virtual unsigned int dy() const = 0 ;
83  ///< Returns the height.
84 
85  virtual bool active() const = 0 ;
86  ///< Returns true after construction or start(), and false
87  ///< after stop().
88 
89  virtual std::string info() const = 0 ;
90  ///< Returns information for debugging and logging purposes.
91 
92 private:
93  void operator=( const Capture & ) ;
94 } ;
95 
96 /// \class Gv::CaptureCallback
97 /// A callback interface for the Gv::Capture class.
98 ///
100 {
101 public:
102  virtual void operator()( const Gv::CaptureBuffer & ) = 0 ;
103  ///< Called to pass back an image buffer.
104 
105 protected:
106  virtual ~CaptureCallback() {}
107 } ;
108 
109 #endif
virtual ~Capture()=0
Destructor.
Definition: gvcapture.cpp:24
virtual unsigned int dx() const =0
Returns the width.
virtual bool simple() const =0
Returns true if a complete RGB24 image can be read out of the capture device and straight into a cont...
virtual int fd() const =0
Returns the fd for select().
virtual unsigned int dy() const =0
Returns the height.
virtual bool active() const =0
Returns true after construction or start(), and false after stop().
A video-capture buffer class to hold image data, with overloaded constructors for the various V4l i/o...
virtual void operator()(const Gv::CaptureBuffer &)=0
Called to pass back an image buffer.
virtual void stop()=0
Stops capturing.
virtual std::string info() const =0
Returns information for debugging and logging purposes.
A callback interface for the Gv::Capture class.
Definition: gvcapture.h:99
virtual bool read(unsigned char *, size_t n)=0
Does a read of an RGB24 image into the user-supplied buffer, on condition that the device is simple()...
A video capture abstract interface, exposing a file descriptor and a method to handle read events on ...
Definition: gvcapture.h:40
virtual void start()=0
Restarts capturing after a stop(). Not normally needed.