VideoPlaybackStrategy.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package visionx::imrec
17  * @author Christian R. G. Dreher <christian.dreher@student.kit.edu>
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 
24 #pragma once
25 
26 
27 // STD/STL
28 #include <filesystem>
29 
30 // OpenCV 2
31 #include <opencv2/highgui/highgui.hpp>
32 
33 // VisionX
35 
36 
37 namespace visionx::imrec::strats
38 {
39  /**
40  * Strategy to play back OpenCV supported common video files like .avi
41  */
42  class VideoPlaybackStrategy;
43 }
44 
45 
46 
47 
50 {
51 
52 private:
53 
54  /**
55  * @brief Path to the recording file
56  */
57  std::filesystem::path filePath;
58 
59  /**
60  * @brief OpenCV VideoCapture object
61  */
62  cv::VideoCapture videoCapture;
63 
64  /**
65  * @brief FPS of the recording (cv::VideoCapture::get is not const)
66  */
67  unsigned int fps;
68 
69  /**
70  * @brief Current frame of the recording (cv::VideoCapture::get is not const)
71  */
72  unsigned int currentFrame;
73 
74  /**
75  * @brief Frame height of the recording (cv::VideoCapture::get is not const)
76  */
77  unsigned int frameHeight;
78 
79  /**
80  * @brief Frame width of the recording (cv::VideoCapture::get is not const)
81  */
82  unsigned int frameWidth;
83 
84  /**
85  * @brief Amount of frames in the recording (cv::VideoCapture::get is not const)
86  */
87  unsigned int frameCount;
88 
89 public:
90 
91  /**
92  * @brief Default constructor to manually setup later
93  */
95 
96  /**
97  * @brief Constructor initialising the playback immediately
98  * @param filePath Path to the recording
99  */
100  VideoPlaybackStrategy(const std::filesystem::path& filePath);
101 
102  /**
103  * @brief Destructor
104  */
105  virtual ~VideoPlaybackStrategy() override;
106 
107  /**
108  * @brief Indicates whether the instance is configured to be able to play back
109  * @return True if it is playing back, false otherwise
110  */
111  virtual bool isPlayingBack() const override;
112 
113  /**
114  * @brief Gets the amount of frames per second of the recording
115  * @return Amount of frames per second of the recording
116  */
117  virtual unsigned int getFps() const override;
118 
119  /**
120  * @brief Gets the total amout of frames in the recording
121  * @return Total amount of frames in the recording
122  */
123  virtual unsigned int getFrameCount() const override;
124 
125  /**
126  * @brief Gets the height of a frame in pixel
127  * @return Height of a frame in pixel
128  */
129  virtual unsigned int getFrameHeight() const override;
130 
131  /**
132  * @brief Gets the width of a frame in pixel
133  * @return Width of a frame in pixel
134  */
135  virtual unsigned int getFrameWidth() const override;
136 
137  /**
138  * @brief Sets the frame from there the playback should resume afterwards (seek)
139  * @param frame Frame from where the playback should be resumed (e.g. "0" to replay from the beginning)
140  */
141  virtual void setCurrentFrame(unsigned int frame) override;
142 
143  /**
144  * @brief Gets the current frame index of the playback
145  * @return The current frame index
146  */
147  virtual unsigned int getCurrentFrame() const override;
148 
149  /**
150  * @brief Indicates whether the recording has a consecutive frame
151  * @return True, if there is a consecutive frame, false otherwise
152  */
153  virtual bool hasNextFrame() const override;
154 
155  /**
156  * @brief Starts the playback
157  * @param filePath Path to the recording to play back
158  */
159  virtual void startPlayback(const std::filesystem::path& filePath) override;
160 
161  /**
162  * @brief Writes the next frame into a buffer of any form (RGB)
163  * @param buffer Output parameter where the frame data of the next frame should be written to
164  * @return True on success, false otherwise (no consecutive frame, error while loading frame)
165  */
166  virtual bool getNextFrame(void* buffer) override;
167 
168  /**
169  * @brief Writes the next frame into an IVT CByteImage buffer (RGB)
170  * @param buffer Output parameter where the frame data of the next frame should be written to
171  * @return True on success, false otherwise (no consecutive frame, error while loading frame)
172  */
173  virtual bool getNextFrame(::CByteImage& buffer) override;
174 
175  /**
176  * @brief Writes the next frame into an OpenCV Mat buffer (BGR)
177  * @param buffer Output parameter where the frame data of the next frame should be written to
178  * @return True on success, false otherwise (no consecutive frame, error while loading frame)
179  */
180  virtual bool getNextFrame(cv::Mat& buffer) override;
181 
182  /**
183  * @brief Stops the playback
184  */
185  virtual void stopPlayback() override;
186 
187 };
visionx::imrec::strats::VideoPlaybackStrategy::getNextFrame
virtual bool getNextFrame(void *buffer) override
Writes the next frame into a buffer of any form (RGB)
Definition: VideoPlaybackStrategy.cpp:135
visionx::imrec::strats::VideoPlaybackStrategy::startPlayback
virtual void startPlayback(const std::filesystem::path &filePath) override
Starts the playback.
Definition: VideoPlaybackStrategy.cpp:119
visionx::imrec::strats::VideoPlaybackStrategy::hasNextFrame
virtual bool hasNextFrame() const override
Indicates whether the recording has a consecutive frame.
Definition: VideoPlaybackStrategy.cpp:112
AbstractPlaybackStrategy.h
visionx::imrec::strats::VideoPlaybackStrategy::VideoPlaybackStrategy
VideoPlaybackStrategy()
Default constructor to manually setup later.
Definition: VideoPlaybackStrategy.cpp:39
visionx::imrec::strats::VideoPlaybackStrategy::stopPlayback
virtual void stopPlayback() override
Stops the playback.
Definition: VideoPlaybackStrategy.cpp:174
visionx::imrec::strats::VideoPlaybackStrategy::isPlayingBack
virtual bool isPlayingBack() const override
Indicates whether the instance is configured to be able to play back.
Definition: VideoPlaybackStrategy.cpp:58
visionx::imrec::strats::VideoPlaybackStrategy::getFps
virtual unsigned int getFps() const override
Gets the amount of frames per second of the recording.
Definition: VideoPlaybackStrategy.cpp:65
visionx::imrec::strats::VideoPlaybackStrategy
Definition: VideoPlaybackStrategy.h:48
visionx::imrec::strats::VideoPlaybackStrategy::getFrameWidth
virtual unsigned int getFrameWidth() const override
Gets the width of a frame in pixel.
Definition: VideoPlaybackStrategy.cpp:86
visionx::imrec::strats::VideoPlaybackStrategy::getCurrentFrame
virtual unsigned int getCurrentFrame() const override
Gets the current frame index of the playback.
Definition: VideoPlaybackStrategy.cpp:105
visionx::imrec::strats::VideoPlaybackStrategy::getFrameHeight
virtual unsigned int getFrameHeight() const override
Gets the height of a frame in pixel.
Definition: VideoPlaybackStrategy.cpp:79
visionx::imrec::strats
Definition: ChunkedImageSequencePlaybackStrategy.h:38
visionx::imrec::strats::VideoPlaybackStrategy::setCurrentFrame
virtual void setCurrentFrame(unsigned int frame) override
Sets the frame from there the playback should resume afterwards (seek)
Definition: VideoPlaybackStrategy.cpp:93
visionx::imrec::strats::VideoPlaybackStrategy::getFrameCount
virtual unsigned int getFrameCount() const override
Gets the total amout of frames in the recording.
Definition: VideoPlaybackStrategy.cpp:72
visionx::imrec::AbstractPlaybackStrategy
Definition: AbstractPlaybackStrategy.h:52
visionx::imrec::strats::VideoPlaybackStrategy::~VideoPlaybackStrategy
virtual ~VideoPlaybackStrategy() override
Destructor.
Definition: VideoPlaybackStrategy.cpp:51