CAVAPA-GUI  30.5.2014
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
videofileset.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 VIDEOFILESET_H
31 #define VIDEOFILESET_H
32 
33 #include "videofile.h"
34 
35 namespace cavapa_gui
36 {
50 class VideoFileSet : public VideoFile
51 {
52 public:
62  : VideoFile(desired_id) {}
63 
64  FrameCapture get(FrameTime passed_time) override;
65 
66  double getBarrelCorrection() override;
67 
73  std::string getDescription() const override;
74 
75  double getFramerate() const override;
76 
77  std::vector<std::string> getFilenames() const override;
78 
79  cv::Size getResolution() const override;
80 
81  SourceType getSourceType() const override { return SourceType::VIDEOSET; }
82 
83  SourceStats getStats() override;
84 
85  bool hasNew() override
86  { return index_has_changed ? true : getVideo(current_index)->hasNew(); }
87 
91  enum class OpenError {
92  FILE_OPEN_FAILED, // Opening one of the video files failed.
93  INVALID_FRAMECOUNT, // A video file does not report frame count).
94  OK, // No error.
95  WRONG_FRAMERATE, // Not all video file framerates match.
96  WRONG_RESOLUTION // Not all video file resolutions match.
97  };
98 
103  bool open(const std::string& filename, bool get_first,
104  FrameTime start_point) override
105  {
106  Q_UNUSED(get_first);
107  return open({filename}, start_point) == OpenError::OK;
108  }
109 
118  OpenError open(const std::vector<std::string>& paths,
119  FrameTime start_point);
120 
121  void play() override;
122 
123  bool skipFrame(int step) override;
124 
129  void setBarrelCorrection(double amount) override;
130 
131  void stop() override;
132 
133 private:
140  inline unsigned int frameIndex(int i) const;
141 
147  int getFrameStart(int i) const { return videos.at(i).second; }
148 
154  std::shared_ptr<VideoFile> getVideo(unsigned int i) const
155  { return videos.at(i).first; }
156 
163  bool setActivePosition(int frame);
164 
175  inline bool setActiveVideo(unsigned int new_index, FrameTime start_seek);
176 
177  unsigned int current_index = 0; // Index of the currently played video.
178  bool index_has_changed = true; // Indicates if index changed from last get.
179  std::vector<std::pair<std::shared_ptr<VideoFile>, int>> videos;
180 };
181 } // namespace
182 
183 #endif // VIDEOFILESET_H
void stop() override
Will stop the file from playing.
Definition: videofileset.cpp:266
SourceType getSourceType() const override
Returns the type of the source.
Definition: videofileset.h:81
void setBarrelCorrection(double amount) override
Sets the new barrel correction value.
Definition: videofileset.cpp:258
std::vector< std::string > getFilenames() const override
Returns the filenames of the source.
Definition: videofileset.cpp:115
unsigned int SourceID
Used to indicate unique source ID-numbers.
Definition: common.h:229
The class for the video file source.
Definition: videofile.h:51
const SourceID UNDEFINED_SOURCE
Used to indicate unknown sources.
Definition: common.h:234
double getBarrelCorrection() override
Returns the barrel correction applied to the source frames.
Definition: videofileset.cpp:96
bool open(const std::string &filename, bool get_first, FrameTime start_point) override
Opens a video file.
Definition: videofileset.h:103
cv::Size getResolution() const override
Retrieves the resolution of the source.
Definition: videofileset.cpp:137
The structure to hold statistics about the source performance.
Definition: common.h:327
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
void play() override
Starts frame updates on the file.
Definition: videofileset.cpp:205
std::uint64_t FrameTime
Used to store milliseconds interval in frame times.
Definition: common.h:138
SourceStats getStats() override
Retrieves the source statistical information.
Definition: videofileset.cpp:144
The structure is used for storing a single source frame.
Definition: common.h:241
std::string getDescription() const override
Retrieves the description of the source.
Definition: videofileset.cpp:103
bool skipFrame(int step) override
Skips the specific amount of frames on the video.
Definition: videofileset.cpp:246
bool hasNew() override
Checks whether the device has a new image to be retrieved or not.
Definition: videofileset.h:85
VideoFileSet(SourceID desired_id=UNDEFINED_SOURCE)
Creates a new source.
Definition: videofileset.h:61
The extension to the VideoFile class for handling multiple files.
Definition: videofileset.h:50
OpenError
Values that the VideoFileSet::open() function can return.
Definition: videofileset.h:91
double getFramerate() const override
Retrieves the framerate.
Definition: videofileset.cpp:130