VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gvcapture_test.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_test.h
19 ///
20 
21 #ifndef GV_CAPTURE_TEST__H
22 #define GV_CAPTURE_TEST__H
23 
24 #include "gdef.h"
25 #include "gnet.h"
26 #include "gtimer.h"
27 #include "gvcapture.h"
28 #include "gvcapturebuffer.h"
29 #include "gvimagegenerator.h"
30 
31 namespace Gv
32 {
33  class CaptureTest ;
34 }
35 
36 /// \class Gv::CaptureTest
37 /// A Gv::Capture implementation that serves up dummy frames created
38 /// by a Gv::ImageGenerator.
39 ///
41 {
42 public:
43  CaptureTest( const std::string & config , ImageGenerator * ) ;
44  ///< Constructor. Ownership of the new()ed ImageGenerator
45  ///< is transferred.
46 
47  virtual ~CaptureTest() ;
48  ///< Destructor.
49 
50  virtual void start() override ;
51  ///< Override from Capture.
52 
53  virtual void stop() override ;
54  ///< Override from Capture.
55 
56  virtual bool simple() const override ;
57  ///< Override from Capture.
58 
59  virtual bool read( unsigned char * , size_t ) override ;
60  ///< Override from Capture.
61 
62  virtual bool read( CaptureCallback & ) override ;
63  ///< Override from Capture.
64 
65  virtual int fd() const override ;
66  ///< Override from Capture.
67 
68  virtual unsigned int dx() const override ;
69  ///< Override from Capture.
70 
71  virtual unsigned int dy() const override ;
72  ///< Override from Capture.
73 
74  virtual bool active() const override ;
75  ///< Override from Capture.
76 
77  virtual std::string info() const override ;
78  ///< Override from Capture.
79 
80  static int dx( int ) ;
81  ///< Static overload.
82 
83  static int dy( int ) ;
84  ///< Static overload.
85 
86 private:
87  bool createSockets() ;
88  void raiseEvent() ;
89  void flushEvents() ;
90  void readSocket() ;
91  void onTimeout() ;
92  virtual void onException( std::exception & ) override ;
93 
94 private:
95  int m_dx ;
96  int m_dy ;
97  ImageGenerator * m_generator ;
98  bool m_capturing ;
99  int m_fd_read ;
100  int m_fd_write ;
101  CaptureBufferFormat m_format ;
102  CaptureBufferScale m_scale ;
103  unique_ptr<CaptureBuffer> m_buffer ;
104  std::string m_config ;
105  GNet::Timer<CaptureTest> m_timer ;
106  unsigned int m_sleep_ms ;
107 } ;
108 
109 #endif
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket events and t...
Definition: geventhandler.h:44
virtual bool simple() const override
Override from Capture.
virtual unsigned int dx() const override
Override from Capture.
A descriptor for a v4l pixel format.
An abstract interface for filling a YUYV capture buffer with a generated image.
virtual void start() override
Override from Capture.
virtual int fd() const override
Override from Capture.
A structure holding capture buffer dimensions.
virtual bool read(unsigned char *, size_t) override
Override from Capture.
virtual bool active() const override
Override from Capture.
A callback interface for the Gv::Capture class.
Definition: gvcapture.h:99
virtual void stop() override
Override from Capture.
virtual ~CaptureTest()
Destructor.
CaptureTest(const std::string &config, ImageGenerator *)
Constructor.
A video capture abstract interface, exposing a file descriptor and a method to handle read events on ...
Definition: gvcapture.h:40
A Gv::Capture implementation that serves up dummy frames created by a Gv::ImageGenerator.
virtual std::string info() const override
Override from Capture.
virtual unsigned int dy() const override
Override from Capture.
A timer class template in which the timeout is delivered to the specified method. ...
Definition: gtimer.h:110