Ocean
Loading...
Searching...
No Matches
TestMovie.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_TEST_TESTMEDIA_TEST_MOVIE_H
9#define META_OCEAN_TEST_TESTMEDIA_TEST_MOVIE_H
10
12
13#include "ocean/base/Frame.h"
14#include "ocean/base/Lock.h"
15
17
18#include "ocean/io/Directory.h"
19
20namespace Ocean
21{
22
23namespace Test
24{
25
26namespace TestMedia
27{
28
29/**
30 * This class implements a test for Movie objects.
31 * @ingroup testmedia
32 */
33class OCEAN_TEST_MEDIA_EXPORT TestMovie
34{
35 protected:
36
37 /// The number of bits to be encoded in each movie.
38 static constexpr unsigned int numberBits_ = 16u;
39
40 /// The size of the bits in pixel.
41 static constexpr unsigned int bitSize_ = 15u;
42
43 /// The vertical location of the color strip.
44 static constexpr unsigned int yColorStrip_ = 200u;
45
46 /**
47 * This class implements a verifier for movies.
48 */
49 class OCEAN_TEST_MEDIA_EXPORT MovieVerifier
50 {
51 public:
52
53 /**
54 * Creates a new verifier object.
55 * @param expectedWidth The expected width of the movie, in pixel, with range [1, infinity)
56 * @param expectedHeight The expected height of the movie, in pixel, with range [1, infinity)
57 * @param expectedNumberFrames The expected number of frames the movie has, with range [1, infinity)
58 * @param expectedFps The expected number of frames per seconds the movie has, with range (0, infinity)
59 */
60 MovieVerifier(const unsigned int expectedWidth, const unsigned int expectedHeight, const unsigned int expectedNumberFrames, const double expectedFps);
61
62 /**
63 * Event function for a new movie frame.
64 * @param frame The new movie frame, will be valid
65 * @param camera The camera profile associated with the frame, invalid if unknown
66 */
67 void onFrame(const Frame& frame, const SharedAnyCamera& camera);
68
69 /**
70 * Returns the timestamp when this verifier has been updated the last time.
71 * @return The verifier's timestamp
72 */
74
75 /**
76 * Returns whether the verifier has verified all frames.
77 * @return True, if so
78 */
79 bool succeeded() const;
80
81 /**
82 * Parses the frame index encoded in the frame.
83 * @param rgbFrame The frame to parse, must be valid, must have pixel format FORMAT_RGB24
84 * @param frameIndex The resulting parsed frame index, with range [0, infinity)
85 * @return True, if succeeded
86 */
87 static bool parseFrameIndex(const Frame& rgbFrame, unsigned int& frameIndex);
88
89 /**
90 * Verifies the color of the color stripe in the frame.
91 * @param rgbFrame The frame to verify, must be valid, must have pixel format FORMAT_RGB24
92 * @param frameIndex The frame index for which the color will be verified, with range [0, infinity)
93 * @return True, if succeeded
94 */
95 static bool verifyColor(const Frame& rgbFrame, const unsigned int frameIndex);
96
97 protected:
98
99 /// The expected width of the movie, in pixel, with range [1, infinity).
100 const unsigned int expectedWidth_ = 0u;
101
102 /// The expected height of the movie, in pixel, with range [1, infinity).
103 const unsigned int expectedHeight_ = 0u;
104
105 /// The expected number of frames the movie has, with range [1, infinity).
106 const unsigned int expectedNumberFrames_ = 0u;
107
108 /// The expected number of frames per seconds the movie has, with range (0, infinity).
109 const double expectedFps_ = 0.0;
110
111 /// The number of received frames.
112 unsigned int numberReceivedFrames_ = 0u;
113
114 /// The timestamp this verifier was updated the last time.
116
117 /// True, if the verifier has seen an error.
118 bool hasError_ = false;
119
120 /// The verifier's lock.
121 mutable Lock lock_;
122 };
123
124 public:
125
126 /**
127 * Invokes all tests that are defined.
128 * @param testDuration The number of seconds for each test
129 * @return True, if succeeded
130 */
131 static bool test(const double testDuration);
132
133 /**
134 * Tests the encoder and decoder of movies.
135 * @return True, if succeeded
136 */
137 static bool testEncodeDecode();
138
139 /**
140 * Tests the loop functionality of movies.
141 * @return True, if succeeded
142 */
143 static bool testLoop();
144
145 /**
146 * Tests the pause functionality of movies.
147 * @return True, if succeeded
148 */
149 static bool testPause();
150
151 /**
152 * Registers all necessary media libraries.
153 */
155
156 /**
157 * Unregisters all media libraries.
158 */
160
161 protected:
162
163 /**
164 * Returns the names of media libraries support movie encoding.
165 * @return The names of all available libraries
166 */
167 static std::vector<std::string> libraryNamesEncoder();
168
169 /**
170 * Returns the names of media libraries support movie decoding.
171 * @return The names all available libraries
172 */
173 static std::vector<std::string> libraryNamesDecoder();
174
175 /**
176 * Creates a movie and writes it to a file.
177 * @param directory The directory in which the movie will be written, must exist
178 * @param width The width of the movie, in pixel, with range [1, infinity)
179 * @param height The height of the movie, in pixel, with range [1, infinity)
180 * @param numberFrames The number of frames the movie will have, with range [1, infinity)
181 * @param fps The frames per second the movie will have, with range (0, infinity)
182 * @param libraryName The name of the library to be used, empty to use any
183 * @return The file of the movie, if succeeded
184 */
185 static IO::File writeMovie(const IO::Directory& directory, const unsigned int width, const unsigned int height, const unsigned int numberFrames, const double fps, const std::string& libraryName = std::string());
186
187 /**
188 * Reads a movie from a file and verifies whether the movie has the correct properties.
189 * @param file The file to the movie, must exist
190 * @param width The expected width of the movie, in pixel, with range [1, infinity)
191 * @param height The expected height of the movie, in pixel, with range [1, infinity)
192 * @param numberFrames The expected number of frames the movie has, with range [1, infinity)
193 * @param fps The expected frames per second the movie has, with range (0, infinity)
194 * @param libraryName The name of the library to be used, empty to use any
195 * @return True, if the movie could be read and if the properties are as expected
196 */
197 static bool readMovie(const IO::File& file, const unsigned int width, const unsigned int height, const unsigned int numberFrames, const double fps, const std::string& libraryName = std::string());
198
199 /**
200 * Returns a unique id.
201 * @return The unique id
202 */
203 static unsigned int uniqueId();
204
205 /**
206 * Returns a unique RGB24 color for a frame index.
207 * @param frameIndex The index of the frame for which the color will be returned, with range [0, infinity)
208 * @return The unique color
209 */
210 static const uint8_t* uniqueColor(const unsigned int frameIndex);
211};
212
213}
214
215}
216
217}
218
219#endif // META_OCEAN_TEST_TESTMEDIA_TEST_MOVIE_H
This class implements Ocean's image class.
Definition Frame.h:1808
This class holds a directory.
Definition Directory.h:36
This class holds a file.
Definition File.h:36
This class implements a recursive lock object.
Definition Lock.h:31
This class implements a verifier for movies.
Definition TestMovie.h:50
Lock lock_
The verifier's lock.
Definition TestMovie.h:121
bool succeeded() const
Returns whether the verifier has verified all frames.
void onFrame(const Frame &frame, const SharedAnyCamera &camera)
Event function for a new movie frame.
static bool verifyColor(const Frame &rgbFrame, const unsigned int frameIndex)
Verifies the color of the color stripe in the frame.
static bool parseFrameIndex(const Frame &rgbFrame, unsigned int &frameIndex)
Parses the frame index encoded in the frame.
MovieVerifier(const unsigned int expectedWidth, const unsigned int expectedHeight, const unsigned int expectedNumberFrames, const double expectedFps)
Creates a new verifier object.
Timestamp lastUpdateTimestamp_
The timestamp this verifier was updated the last time.
Definition TestMovie.h:115
Timestamp lastUpdateTimestamp() const
Returns the timestamp when this verifier has been updated the last time.
This class implements a test for Movie objects.
Definition TestMovie.h:34
static bool testLoop()
Tests the loop functionality of movies.
static void unregisterMediaLibraries()
Unregisters all media libraries.
static const uint8_t * uniqueColor(const unsigned int frameIndex)
Returns a unique RGB24 color for a frame index.
static bool testEncodeDecode()
Tests the encoder and decoder of movies.
static bool testPause()
Tests the pause functionality of movies.
static IO::File writeMovie(const IO::Directory &directory, const unsigned int width, const unsigned int height, const unsigned int numberFrames, const double fps, const std::string &libraryName=std::string())
Creates a movie and writes it to a file.
static std::vector< std::string > libraryNamesDecoder()
Returns the names of media libraries support movie decoding.
static void registerMediaLibraries()
Registers all necessary media libraries.
static bool readMovie(const IO::File &file, const unsigned int width, const unsigned int height, const unsigned int numberFrames, const double fps, const std::string &libraryName=std::string())
Reads a movie from a file and verifies whether the movie has the correct properties.
static bool test(const double testDuration)
Invokes all tests that are defined.
static unsigned int uniqueId()
Returns a unique id.
static std::vector< std::string > libraryNamesEncoder()
Returns the names of media libraries support movie encoding.
This class implements a timestamp.
Definition Timestamp.h:36
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:60
The namespace covering the entire Ocean framework.
Definition Accessor.h:15