Ocean
Loading...
Searching...
No Matches
FiniteMedium.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_FINITE_MEDIUM_H
9#define META_OCEAN_MEDIA_FINITE_MEDIUM_H
10
11#include "ocean/media/Media.h"
12#include "ocean/media/Medium.h"
14
15namespace Ocean
16{
17
18namespace Media
19{
20
21// Forward declaration.
22class FiniteMedium;
23
24/**
25 * Definition of a smart medium reference holding a finite medium object.
26 * @see SmartMediumRef, FiniteMedium.
27 * @ingroup media
28 */
30
31/**
32 * This class is the base class for all finite mediums.
33 * @ingroup media
34 */
35class OCEAN_MEDIA_EXPORT FiniteMedium : virtual public Medium
36{
37 public:
38
39 /**
40 * Definition of a speed value allowing to deliver the media content as fast as possible.
41 * At the same time, no media content is skipped.
42 */
43 static constexpr float AS_FAST_AS_POSSIBLE = 0.0f;
44
45 public:
46
47 /**
48 * Returns the duration of the finite medium.
49 * @return Duration in seconds
50 */
51 virtual double duration() const = 0;
52
53 /**
54 * Returns the duration without speed consideration.
55 * @return Duration in seconds
56 */
57 virtual double normalDuration() const = 0;
58
59 /**
60 * Returns the recent position of the finite medium.
61 * @return Recent position in seconds
62 */
63 virtual double position() const = 0;
64
65 /**
66 * Returns the speed of the finite medium.
67 * The speed value is relative to the media's standard speed.<br>
68 * For example, a speed value of 1.0 means the standard speed, 2.0 is twice as fast, and 0.5 is half as fast as the standard speed.<br>
69 * However, a speed value of 0 (or AS_FAST_AS_POSSIBLE) will ignore the standard playback time and will deliver the media content as fast as possible.
70 * @return Speed as a factor
71 */
72 virtual float speed() const = 0;
73
74 /**
75 * Returns whether the medium is played in a loop.
76 * By default a finite medium will not be looped.
77 * @return True, if so
78 * @see setLoop().
79 */
80 inline bool loop() const;
81
82 /**
83 * Sets the recent position of the finite medium.
84 * @param position New position in seconds
85 * @return True, if succeeded
86 */
87 virtual bool setPosition(const double position);
88
89 /**
90 * Sets the speed of the finite medium.
91 * The speed value is relative to the media's standard speed.<br>
92 * For example, a speed value of 1.0 means the standard speed, 2.0 is twice as fast, and 0.5 is half as fast as the standard speed.<br>
93 * However, a speed value of 0 (or AS_FAST_AS_POSSIBLE) will ignore the standard playback time and will deliver the media content as fast as possible.
94 * @param speed The speed to set, with range (0, infinity), AS_FAST_AS_POSSIBLE to run the medium as fast as possible
95 * @return True, if the speed is accepted
96 */
97 virtual bool setSpeed(const float speed);
98
99 /**
100 * Sets whether the medium has to be played in a loop.
101 * @param value True, if looping
102 * @return True, if succeeded
103 * @see loop().
104 */
105 virtual bool setLoop(const bool value);
106
107 /**
108 * Returns whether a previous task has been finished.
109 * A task has been finished if all data that has been requested before has been provided (or e.g. rendered).
110 * @return True, if so
111 */
112 virtual bool taskFinished() const;
113
114 protected:
115
116 /**
117 * Creates a new finite medium by a given url.
118 * @param url Url of the finite medium
119 */
120 explicit FiniteMedium(const std::string& url);
121
122 protected:
123
124 /// Determines whether the medium is played in a loop.
125 bool loop_ = false;
126};
127
128inline bool FiniteMedium::loop() const
129{
130 const ScopedLock scopedLock(lock_);
131
132 return loop_;
133}
134
135}
136
137}
138
139#endif // META_OCEAN_MEDIA_FINITE_MEDIUM_H
This class is the base class for all finite mediums.
Definition FiniteMedium.h:36
virtual bool setSpeed(const float speed)
Sets the speed of the finite medium.
FiniteMedium(const std::string &url)
Creates a new finite medium by a given url.
virtual bool taskFinished() const
Returns whether a previous task has been finished.
virtual bool setPosition(const double position)
Sets the recent position of the finite medium.
virtual double duration() const =0
Returns the duration of the finite medium.
bool loop() const
Returns whether the medium is played in a loop.
Definition FiniteMedium.h:128
virtual bool setLoop(const bool value)
Sets whether the medium has to be played in a loop.
virtual float speed() const =0
Returns the speed of the finite medium.
bool loop_
Determines whether the medium is played in a loop.
Definition FiniteMedium.h:125
virtual double normalDuration() const =0
Returns the duration without speed consideration.
virtual double position() const =0
Returns the recent position of the finite medium.
This is the base class for all mediums.
Definition Medium.h:48
Lock lock_
Medium lock.
Definition Medium.h:233
This class implements a smart medium reference.
Definition MediumRef.h:33
This class implements a scoped lock object for recursive lock objects.
Definition Lock.h:135
SmartMediumRef< FiniteMedium > FiniteMediumRef
Definition of a smart medium reference holding a finite medium object.
Definition FiniteMedium.h:29
The namespace covering the entire Ocean framework.
Definition Accessor.h:15