CAVAPA-GUI  30.5.2014
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
source.h
1 /****************************************************************************
2  * Copyright (c) 2014, Joel Kivelä, Erkki Koskenkorva, Oskari Leppäaho,
3  * Mika Lehtinen and Petri Partanen.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 ****************************************************************************/
30 #ifndef SOURCE_H
31 #define SOURCE_H
32 
33 #include <deque>
34 #include <mutex>
35 #include <thread>
36 
37 #include "../common.h"
38 
39 namespace cavapa_gui
40 {
51 class Source
52 {
53 public:
54  virtual ~Source() {}
55 
60 
65  virtual bool canRecord() const = 0;
66 
80  virtual FrameCapture get(FrameTime passed_time) = 0;
81 
86  virtual double getBarrelCorrection() = 0;
87 
92  virtual std::string getDescription() const = 0;
93 
98  virtual double getFramerate() const = 0;
99 
104  virtual SourceID getID() const final { return source_id; }
105 
110  virtual cv::Size getResolution() const = 0;
111 
116  virtual FrameTime getPosition() const = 0;
117 
122  virtual SourceType getSourceType() const { return SourceType::NOTHING; }
123 
128  virtual SourceStats getStats() = 0;
129 
137  virtual bool hasNew() = 0;
138 
143  virtual bool isOpen() const = 0;
144 
149  virtual bool isPlaying() const = 0;
150 
155  virtual void play() {}
156 
166  virtual bool record(const std::string& filename,
167  const std::string& codec = "") = 0;
168 
172  virtual void resetStats() final { statistics = EMPTY_SOURCE_STATS; }
173 
181  virtual void setBarrelCorrection(double amount) = 0;
182 
188  virtual bool setResolution(const cv::Size& new_size) = 0;
189 
194  virtual void stop() = 0;
195 
196 private:
200  SourceID source_id;
201 
202 protected:
212  {
213  // Starting counter must differ from UNDEFINED_SOURCE.
214  static SourceID id_counter = UNDEFINED_SOURCE + 1;
215 
216  // We will advance our ID-counter to the next available number to
217  // prevent duplicating that number with our automated numbering system.
218  if (desired_id != UNDEFINED_SOURCE) {
219  id_counter = std::max(id_counter, desired_id+1);
220  source_id = desired_id;
221  } else {
222  source_id = id_counter++;
223  }
224  }
225 
229  SourceStats statistics = EMPTY_SOURCE_STATS;
230 };
231 } // namespace
232 
233 #endif // SOURCE_H
virtual bool hasNew()=0
Checks whether the device has a new image to be retrieved or not.
DISALLOW_COPY_AND_ASSIGN(Source)
Copy and assign of the class is not allowed.
virtual FrameTime getPosition() const =0
Retrieves the current time position of the source.
virtual void resetStats() final
Resets the source statistics.
Definition: source.h:172
unsigned int SourceID
Used to indicate unique source ID-numbers.
Definition: common.h:229
virtual SourceStats getStats()=0
Retrieves the source statistical information.
const SourceID UNDEFINED_SOURCE
Used to indicate unknown sources.
Definition: common.h:234
virtual bool record(const std::string &filename, const std::string &codec="")=0
Starts the recording of the source to the file.
virtual double getBarrelCorrection()=0
Returns the barrel correction applied to the source frames.
virtual cv::Size getResolution() const =0
Retrieves the resolution of the source.
virtual void setBarrelCorrection(double amount)=0
Sets the new barrel correction value.
virtual SourceType getSourceType() const
Returns the type of the source.
Definition: source.h:122
The structure to hold statistics about the source performance.
Definition: common.h:327
The camera and video file source base class.
Definition: source.h:51
virtual bool canRecord() const =0
Returns information on the source recording abilities.
virtual bool isPlaying() const =0
Checks whether the source is playing or not.
SourceStats statistics
The statistics of the source.
Definition: source.h:229
virtual bool isOpen() const =0
Checks whether the source has been initialized or not.
SourceType
Available source types are the following ones: CAMERA = hardware or network camera, NOTHING = not a working source, STREAM = network stream, VIDEO = video file and VIDEOSET = set of multiple files.
Definition: common.h:68
Source(SourceID desired_id=UNDEFINED_SOURCE)
General Source creator.
Definition: source.h:211
virtual SourceID getID() const final
Gets the unique source ID number.
Definition: source.h:104
virtual void stop()=0
Stops the source.
std::uint64_t FrameTime
Used to store milliseconds interval in frame times.
Definition: common.h:138
The structure is used for storing a single source frame.
Definition: common.h:241
virtual double getFramerate() const =0
Retrieves the framerate.
virtual bool setResolution(const cv::Size &new_size)=0
Sets the source resolution.
virtual std::string getDescription() const =0
Retrieves the description of the source.
virtual void play()
Starts to play the source.
Definition: source.h:155