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