Ocean
Loading...
Searching...
No Matches
AVFMovie.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_MEDIA_AVF_MOVIE_H
9#define META_OCEAN_MEDIA_AVF_MOVIE_H
10
13
14#include "ocean/base/Callback.h"
15#include "ocean/base/Thread.h"
16
17#include "ocean/media/Movie.h"
18
19namespace Ocean
20{
21
22namespace Media
23{
24
25namespace AVFoundation
26{
27
28/**
29 * This class implements an AVFoundation movie object.
30 * @ingroup mediaavf
31 */
32class AVFMovie :
33 virtual public AVFFrameMedium,
34 virtual public Movie,
35 protected Thread
36{
37 friend class AVFLibrary;
38
39 public:
40
41 /**
42 * Definition of a callback function for finished playing.
43 */
45
46 public:
47
48 /**
49 * Clones this movie medium and returns a new independent instance of this medium.
50 * @see Medium::clone()
51 */
52 MediumRef clone() const override;
53
54 /**
55 * Returns the duration of the movie medium.
56 * @see FiniteMedium::duration()
57 */
58 double duration() const override;
59
60 /**
61 * Returns the duration of the movie medium without speed consideration.
62 * @see FiniteMedium::normalDuration()
63 */
64 double normalDuration() const override;
65
66 /**
67 * Returns the recent position of the movie medium.
68 * @see FiniteMedium::position()
69 */
70 double position() const override;
71
72 /**
73 * Sets the recent position of the movie medium.
74 * @see FiniteMedium::setPosition()
75 */
76 bool setPosition(const double position) override;
77
78 /**
79 * Returns the speed of the movie medium.
80 * @see FiniteMedium::speed()
81 */
82 float speed() const override;
83
84 /**
85 * Sets the speed of the movie medium.
86 * @see FiniteMedium::setSpeed()
87 */
88 bool setSpeed(const float speed) override;
89
90 /**
91 * Returns the volume of the sound in db.
92 * @see SoundMedium::soundVolume()
93 */
94 float soundVolume() const override;
95
96 /**
97 * Returns whether the movie medium is in a mute state.
98 * @see SoundMedium::soundMute()
99 */
100 bool soundMute() const override;
101
102 /**
103 * Sets the volume of the sound in db.
104 * @see SoundMedium::setSoundVolume()
105 */
106 bool setSoundVolume(const float volume) override;
107
108 /**
109 * Sets or unsets the movie medium to a mute state.
110 * @see SoundMedium::setSoundMute()
111 */
112 bool setSoundMute(const bool mute) override;
113
114 /**
115 * Enables or disables the audio in this movie (has no effect if the movie does not have audio).
116 * @see Movie::setUseSound()
117 */
118 bool setUseSound(const bool state) override;
119
120 /**
121 * Sets the known camera profile of this frame medium.
122 * @see FrameMedium::setCamera()
123 */
124 bool setCamera(SharedAnyCamera&& camera) override;
125
126 protected:
127
128 /**
129 * Creates a new movie by a given url.
130 * @param url Url of the movie
131 */
132 explicit AVFMovie(const std::string& url);
133
134 /**
135 * Destructs a AVFMovie object.
136 */
137 ~AVFMovie() override;
138
139 /**
140 * Internally starts the medium.
141 * @see AVFMedium::internalStart()
142 */
143 bool internalStart() override;
144
145 /**
146 * Internally pauses the medium.
147 * @see AVFMedium::internalPause()
148 */
149 bool internalPause() override;
150
151 /**
152 * Internally stops the medium.
153 * @see AVFMedium::internalStop()
154 */
155 bool internalStop() override;
156
157 /**
158 * Event function for
159 */
161
162 /**
163 * Creates a new asset reader by a given start time.
164 * Ensure that the current asset reader and track output are unset before.
165 * @param startTime The start time of the asset reader.
166 * @return True, if succeeded
167 */
168 bool createNewAssetReader(const double startTime);
169
170 /**
171 * Creates a new player.
172 * @return True, if succeeded
173 */
175
176 private:
177
178 /**
179 * Thread run function.
180 */
181 void threadRun() override;
182
183 protected:
184
185 /// True to indicate that the player should be started.
186 bool playerShouldStart_ = false;
187
188 /// The speed of the movie medium
189 float speed_ = 1.0f;
190
191 /// The asset that holds the movie file
192 AVURLAsset* asset_ = nullptr;
193
194 /// The asset reader for non playback time respect
195 AVAssetReader* assetReader_ = nullptr;
196
197 /// The asset reader output
198 AVAssetReaderTrackOutput* assetReaderTrackOutput_ = nullptr;
199
200 /// The player for playback time respect
201 AVPlayer* player_ = nullptr;
202
203 /// The player item that is played
204 AVPlayerItem* playerItem_ = nullptr;
205
206 /// The player output
207 AVPlayerItemVideoOutput* playerItemVideoOutput_ = nullptr;
208
209 /// The player observer
210 NSObject* observer_ = nullptr;
211
212 /// The camera profile for all images.
214};
215
216}
217
218}
219
220}
221
222#endif // META_OCEAN_MEDIA_AVF_MOVIE_H
This is the base class for all AVFoundation frame mediums.
Definition AVFFrameMedium.h:34
This class implements the AVFoundation library.
Definition AVFLibrary.h:32
This class implements an AVFoundation movie object.
Definition AVFMovie.h:36
bool createNewPlayer()
Creates a new player.
AVAssetReaderTrackOutput * assetReaderTrackOutput_
The asset reader output.
Definition AVFMovie.h:198
double normalDuration() const override
Returns the duration of the movie medium without speed consideration.
AVPlayerItemVideoOutput * playerItemVideoOutput_
The player output.
Definition AVFMovie.h:207
AVPlayerItem * playerItem_
The player item that is played.
Definition AVFMovie.h:204
bool internalPause() override
Internally pauses the medium.
float speed() const override
Returns the speed of the movie medium.
AVURLAsset * asset_
The asset that holds the movie file.
Definition AVFMovie.h:192
AVFMovie(const std::string &url)
Creates a new movie by a given url.
bool internalStart() override
Internally starts the medium.
bool setCamera(SharedAnyCamera &&camera) override
Sets the known camera profile of this frame medium.
SharedAnyCamera camera_
The camera profile for all images.
Definition AVFMovie.h:213
bool createNewAssetReader(const double startTime)
Creates a new asset reader by a given start time.
double position() const override
Returns the recent position of the movie medium.
float speed_
The speed of the movie medium.
Definition AVFMovie.h:189
~AVFMovie() override
Destructs a AVFMovie object.
AVAssetReader * assetReader_
The asset reader for non playback time respect.
Definition AVFMovie.h:195
void onFinishedPlaying()
Event function for.
bool playerShouldStart_
True to indicate that the player should be started.
Definition AVFMovie.h:186
bool setSpeed(const float speed) override
Sets the speed of the movie medium.
double duration() const override
Returns the duration of the movie medium.
void threadRun() override
Thread run function.
AVPlayer * player_
The player for playback time respect.
Definition AVFMovie.h:201
bool internalStop() override
Internally stops the medium.
bool setUseSound(const bool state) override
Enables or disables the audio in this movie (has no effect if the movie does not have audio).
bool soundMute() const override
Returns whether the movie medium is in a mute state.
NSObject * observer_
The player observer.
Definition AVFMovie.h:210
bool setSoundMute(const bool mute) override
Sets or unsets the movie medium to a mute state.
float soundVolume() const override
Returns the volume of the sound in db.
bool setPosition(const double position) override
Sets the recent position of the movie medium.
MediumRef clone() const override
Clones this movie medium and returns a new independent instance of this medium.
bool setSoundVolume(const float volume) override
Sets the volume of the sound in db.
const std::string & url() const
Returns the url of the medium.
Definition Medium.h:236
This class is the base class for all movies.
Definition Movie.h:40
This class implements a thread.
Definition Thread.h:115
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