Ocean
Loading...
Searching...
No Matches
DevicePlayer.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_DEVICES_DEVICE_PLAYER_H
9#define META_OCEAN_DEVICES_DEVICE_PLAYER_H
10
12
14
16
18
19namespace Ocean
20{
21
22namespace Devices
23{
24
25// Forward declaration.
26class DevicePlayer;
27
28/**
29 * Definition of a shared pointer holding a DevicePlayer object.
30 * @see DevicePlayer.
31 * @ingroup devices
32 */
33using SharedDevicePlayer = std::shared_ptr<DevicePlayer>;
34
35/**
36 * This class implements the abstract base class for all device players.
37 * The device player can be used to re-play a previously captured data and exposing the data through devices.
38 * @ingroup devices
39 */
40class OCEAN_DEVICES_EXPORT DevicePlayer
41{
42 public:
43
44 /**
45 * Definition of a speed value for the stop-motion replay mode.
46 */
47 static constexpr float SPEED_USE_STOP_MOTION = 0.0f;
48
49 /**
50 * Definition of individual transformation results.
51 */
52 enum TransformationResult : uint32_t
53 {
54 /// The transformation does not exist in the recording.
55 TR_DOES_NOT_EXIST = 0u,
56 /// The resulting transformation is valid but interpolated due to a not perfectly matching timestamp.
58 /// The resulting transformation is valid and the timestamp matched perfectly with a transformation in the recording.
59 TR_PRECISE
60 };
61
62 public:
63
64 /**
65 * Creates a new device player.
66 */
67 DevicePlayer() = default;
68
69 /**
70 * Destructs the device player.
71 */
72 virtual ~DevicePlayer();
73
74 /**
75 * Initializes the player with a recording.
76 * @param filename The name of the file to be used in the player, must be valid
77 * @return True, if succeeded
78 */
79 virtual bool initialize(const std::string& filename) = 0;
80
81 /**
82 * Starts the replay.
83 * The recording can be payed with individual speed, e.g., real-time, slower than real-time, faster than real-time.<br>
84 * Further, the player support a stop-motion mode in which the player will play one frame by another.
85 * @param speed The speed at which the recording will be played, e.g., 2 means two times faster than normal, with range (0, infinity), 'SPEED_USE_STOP_MOTION' to play the recording in a stop-motion (frame by frame) mode
86 * @return True, if succeeded
87 * @see duration(), playNextFrame();
88 */
89 virtual bool start(const float speed = 1.0f) = 0;
90
91 /**
92 * Stops the replay.
93 * @return True, if succeeded
94 */
95 virtual bool stop() = 0;
96
97 /**
98 * Plays the next frame of the recording, the player must be started with stop-motion mode ('SPEED_USE_STOP_MOTION').
99 * In case the recording holds several media objects, the fist media objects is used to identify the next frame.<br>
100 * This function will read all records which have been recorded before or at the same time as the next frame of the first media object.<br>
101 * If the recording does not have any media object nothing happens.
102 * @return The timestamp of the frame which has been played, invalid if no additional frame exists
103 * @see start(), frameMediums().
104 */
106
107 /**
108 * Returns the duration of the content when played with default speed.
109 * @return The recording's default duration, in seconds, with range [0, infinity)
110 */
111 virtual double duration() const = 0;
112
113 /**
114 * Returns all frame media objects which have been created based on the recording.
115 * @return The media objects, empty if the recording does not contain any frame medium objects
116 */
118
119 /**
120 * Returns a specific transformation which is expected to be part of the recording.
121 * This function is intended as a helper function to simplify access to important transformations which otherwise would be accessed through the player's tracking devices.
122 * @param name The name of the transformation, must be valid
123 * @param timestamp The timestamp for which the transformation is evaluated, must be valid
124 * @param matrix The resulting transformation matrix
125 * @return The transformation result
126 */
127 virtual TransformationResult transformation(const std::string& name, const Timestamp& timestamp, HomogenousMatrixD4& matrix) = 0;
128
129 /**
130 * Returns whether this player is currently started.
131 * @return True, if so
132 */
133 virtual bool isStarted() const = 0;
134
135 /**
136 * Returns whether this player holds a valid recording.
137 * @return True, if so
138 */
139 virtual bool isValid() const;
140
141 protected:
142
143 /// The filename of the recording which is used.
144 std::string filename_;
145
146 /// The player's lock.
147 mutable Lock lock_;
148};
149
150} // namespace Devices
151
152} // namespace Ocean
153
154#endif // META_OCEAN_DEVICES_DEVICE_PLAYER_H
This class implements the abstract base class for all device players.
Definition DevicePlayer.h:41
virtual TransformationResult transformation(const std::string &name, const Timestamp &timestamp, HomogenousMatrixD4 &matrix)=0
Returns a specific transformation which is expected to be part of the recording.
virtual Media::FrameMediumRefs frameMediums()
Returns all frame media objects which have been created based on the recording.
TransformationResult
Definition of individual transformation results.
Definition DevicePlayer.h:53
@ TR_INTERPOLATED
The resulting transformation is valid but interpolated due to a not perfectly matching timestamp.
Definition DevicePlayer.h:57
virtual ~DevicePlayer()
Destructs the device player.
virtual bool isStarted() const =0
Returns whether this player is currently started.
virtual Timestamp playNextFrame()=0
Plays the next frame of the recording, the player must be started with stop-motion mode ('SPEED_USE_S...
virtual bool isValid() const
Returns whether this player holds a valid recording.
DevicePlayer()=default
Creates a new device player.
virtual bool initialize(const std::string &filename)=0
Initializes the player with a recording.
virtual bool stop()=0
Stops the replay.
Lock lock_
The player's lock.
Definition DevicePlayer.h:147
std::string filename_
The filename of the recording which is used.
Definition DevicePlayer.h:144
virtual double duration() const =0
Returns the duration of the content when played with default speed.
virtual bool start(const float speed=1.0f)=0
Starts the replay.
This class implements a recursive lock object.
Definition Lock.h:31
This class implements a timestamp.
Definition Timestamp.h:36
std::shared_ptr< DevicePlayer > SharedDevicePlayer
Definition of a shared pointer holding a DevicePlayer object.
Definition DevicePlayer.h:33
std::vector< FrameMediumRef > FrameMediumRefs
Definition of a vector holding frame medium reference objects.
Definition FrameMedium.h:46
The namespace covering the entire Ocean framework.
Definition Accessor.h:15