AbstractPlaybackStrategy.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 #include <memory>
30 
31 // OpenCV 2
32 #include <opencv2/core/core.hpp>
33 
34 // IVT
35 #include <Image/ByteImage.h>
36 
37 namespace visionx::imrec
38 {
39  /**
40  * Interface of a playback strategy
41  */
42  class AbstractPlaybackStrategy;
43 
44  /**
45  * Convenience alias for an instance of any playback strategy
46  */
47  using Playback = std::shared_ptr<visionx::imrec::AbstractPlaybackStrategy>;
48 } // namespace visionx::imrec
49 
51 {
52 
53 public:
54  /**
55  * @brief Destructor
56  */
57  virtual ~AbstractPlaybackStrategy();
58 
59  /**
60  * @brief Indicates whether the instance is configured to be able to play back
61  * @return True if it is playing back, false otherwise
62  */
63  virtual bool isPlayingBack() const = 0;
64 
65  /**
66  * @brief Gets the amount of frames per second of the recording
67  * @return Amount of frames per second of the recording
68  */
69  virtual unsigned int getFps() const = 0;
70 
71  /**
72  * @brief Gets the total amout of frames in the recording
73  * @return Total amount of frames in the recording
74  */
75  virtual unsigned int getFrameCount() const = 0;
76 
77  /**
78  * @brief Gets the height of a frame in pixel
79  * @return Height of a frame in pixel
80  */
81  virtual unsigned int getFrameHeight() const = 0;
82 
83  /**
84  * @brief Gets the width of a frame in pixel
85  * @return Width of a frame in pixel
86  */
87  virtual unsigned int getFrameWidth() const = 0;
88 
89  /**
90  * @brief Sets the frame from there the playback should resume afterwards (seek)
91  * @param frame Frame from where the playback should be resumed (e.g. "0" to replay from the beginning)
92  */
93  virtual void setCurrentFrame(unsigned int frame) = 0;
94 
95  /**
96  * @brief Gets the current frame index of the playback
97  * @return The current frame index
98  */
99  virtual unsigned int getCurrentFrame() const = 0;
100 
101  /**
102  * @brief Indicates whether the recording has a consecutive frame
103  * @return True, if there is a consecutive frame, false otherwise
104  */
105  virtual bool hasNextFrame() const = 0;
106 
107  /**
108  * @brief Starts the playback
109  * @param filePath Path to the recording to play back
110  */
111  virtual void startPlayback(const std::filesystem::path& filePath) = 0;
112 
113  /**
114  * @brief Writes the next frame into an RGB buffer (one byte per channel => 3 byte per pixel)
115  * @param buffer Output parameter where the frame data of the next frame should be written to
116  * @return True on success, false otherwise (no consecutive frame, error while loading frame)
117  */
118  virtual bool getNextFrame(void* buffer) = 0;
119 
120  /**
121  * @brief Writes the next frame into an IVT CByteImage buffer (RGB)
122  * @param buffer Output parameter where the frame data of the next frame should be written to
123  * @return True on success, false otherwise (no consecutive frame, error while loading frame)
124  */
125  virtual bool getNextFrame(::CByteImage& buffer) = 0;
126 
127  /**
128  * @brief Writes the next frame into an OpenCV Mat buffer (BGR)
129  * @param buffer Output parameter where the frame data of the next frame should be written to
130  * @return True on success, false otherwise (no consecutive frame, error while loading frame)
131  */
132  virtual bool getNextFrame(cv::Mat& buffer) = 0;
133 
134  /**
135  * @brief Stops the playback
136  */
137  virtual void stopPlayback() = 0;
138 };
visionx::imrec::AbstractPlaybackStrategy::getFps
virtual unsigned int getFps() const =0
Gets the amount of frames per second of the recording.
visionx::imrec::AbstractPlaybackStrategy::startPlayback
virtual void startPlayback(const std::filesystem::path &filePath)=0
Starts the playback.
visionx::imrec::AbstractPlaybackStrategy::getFrameHeight
virtual unsigned int getFrameHeight() const =0
Gets the height of a frame in pixel.
visionx::imrec::AbstractPlaybackStrategy::isPlayingBack
virtual bool isPlayingBack() const =0
Indicates whether the instance is configured to be able to play back.
visionx::imrec::AbstractPlaybackStrategy::getFrameCount
virtual unsigned int getFrameCount() const =0
Gets the total amout of frames in the recording.
visionx::imrec::Playback
std::shared_ptr< visionx::imrec::AbstractPlaybackStrategy > Playback
Convenience alias for an instance of any playback strategy.
Definition: AbstractPlaybackStrategy.h:47
visionx::imrec::AbstractPlaybackStrategy::~AbstractPlaybackStrategy
virtual ~AbstractPlaybackStrategy()
Destructor.
Definition: AbstractPlaybackStrategy.cpp:26
visionx::imrec::AbstractPlaybackStrategy::setCurrentFrame
virtual void setCurrentFrame(unsigned int frame)=0
Sets the frame from there the playback should resume afterwards (seek)
visionx::imrec::AbstractPlaybackStrategy::getNextFrame
virtual bool getNextFrame(void *buffer)=0
Writes the next frame into an RGB buffer (one byte per channel => 3 byte per pixel)
visionx::imrec::AbstractPlaybackStrategy::getCurrentFrame
virtual unsigned int getCurrentFrame() const =0
Gets the current frame index of the playback.
visionx::imrec::AbstractPlaybackStrategy::getFrameWidth
virtual unsigned int getFrameWidth() const =0
Gets the width of a frame in pixel.
visionx::imrec::AbstractPlaybackStrategy::stopPlayback
virtual void stopPlayback()=0
Stops the playback.
visionx::imrec::AbstractPlaybackStrategy::hasNextFrame
virtual bool hasNextFrame() const =0
Indicates whether the recording has a consecutive frame.
visionx::imrec
Definition: json_conversions.h:35
visionx::imrec::AbstractPlaybackStrategy
Definition: AbstractPlaybackStrategy.h:50