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