Ocean
Medium.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_MEDIUM_H
9 #define META_OCEAN_MEDIA_MEDIUM_H
10 
11 #include "ocean/media/Media.h"
12 
13 #include "ocean/base/ObjectRef.h"
14 #include "ocean/base/Timestamp.h"
15 
16 namespace Ocean
17 {
18 
19 namespace Media
20 {
21 
22 // Forward declaration.
23 class Medium;
24 
25 /**
26  * This class implements a medium reference with an internal reference counter.
27  * @see ObjectRef, Medium
28  * @ingroup media
29  */
31 
32 /**
33  * This is the base class for all mediums.
34  * A medium may provide visual or/and audio content.<br>
35  * The medium's source may be live, a buffer or a file.<br>
36  *
37  * A new medium object cannot be created directly.<br>
38  * The Manager provides powerful functions allowing to create medium object from individual libraries and with individual properties.<br>
39  *
40  * Mediums can be exclusive or non-exclusive:<br>
41  * An non-exclusive medium can be used by several individual clients to save resources like memory or/and computational power.<br>
42  * An exclusive medium should be used by one client only.<br>
43  * The exclusiveness of a medium can be decided during the creation of a medium.<br>
44  * @see Manager
45  * @ingroup media
46  */
47 class OCEAN_MEDIA_EXPORT Medium
48 {
49  friend class ObjectRef<Medium>;
50 
51  public:
52 
53  /**
54  * Definition of different medium types.
55  */
56  enum Type : uint32_t
57  {
58  /// Simple medium.
59  MEDIUM = 0u,
60  /// Frame medium.
61  FRAME_MEDIUM = 1u << 0u,
62  /// Sound medium.
63  SOUND_MEDIUM = 1u << 1u,
64  /// Finite medium.
65  FINITE_MEDIUM = 1u << 2u,
66  /// Live medium.
67  LIVE_MEDIUM = 1u << 3u,
68  /// Config medium.
69  CONFIG_MEDIUM = 1u << 4u,
70  /// Audio medium.
71  AUDIO = (1u << 5u) | FINITE_MEDIUM | SOUND_MEDIUM,
72  /// Image medium.
73  IMAGE = (1u << 6u) | FRAME_MEDIUM,
74  /// Pixel image medium.
75  PIXEL_IMAGE = (1u << 7u) | FRAME_MEDIUM,
76  /// Pixel image medium.
77  BUFFER_IMAGE = (1u << 8u) | FRAME_MEDIUM,
78  /// Image sequence medium.
79  IMAGE_SEQUENCE = (1u << 9u) | FRAME_MEDIUM | FINITE_MEDIUM,
80  /// Live audio medium.
81  LIVE_AUDIO = (1u << 10u) | LIVE_MEDIUM | SOUND_MEDIUM,
82  /// Live video medium.
83  LIVE_VIDEO = (1u << 11u) | LIVE_MEDIUM | FRAME_MEDIUM,
84  /// Microphone medium.
85  MICROPHONE = (1u << 12u) | LIVE_MEDIUM,
86  /// Movie medium.
87  MOVIE = (1u << 13u) | FINITE_MEDIUM | FRAME_MEDIUM | SOUND_MEDIUM,
88  };
89 
90  public:
91 
92  /**
93  * Returns the url of the medium.
94  * @return Medium url
95  */
96  inline const std::string& url() const;
97 
98  /**
99  * Returns whether the medium is valid.
100  * @return True, if so
101  */
102  inline bool isValid() const;
103 
104  /**
105  * Returns the name of the owner library.
106  * @return Library name
107  */
108  inline const std::string& library() const;
109 
110  /**
111  * Returns the type of the medium.
112  * @return Medium type
113  */
114  inline Type type() const;
115 
116  /**
117  * Returns whether a medium has a given type.
118  * @param type Type to check
119  * @return True, if so
120  */
121  bool isType(const Type type) const;
122 
123  /**
124  * Returns whether the medium is started currently.
125  * @return True, if so
126  */
127  virtual bool isStarted() const = 0;
128 
129  /**
130  * Returns whether this medium can be use exclusively.
131  * @return True, if so
132  */
133  bool isExclusive() const;
134 
135  /**
136  * Starts the medium.
137  * @return True, if succeeded
138  */
139  virtual bool start() = 0;
140 
141  /**
142  * Pauses the medium.
143  * @return True, if succeeded
144  */
145  virtual bool pause() = 0;
146 
147  /**
148  * Stops the medium.
149  * @return True, if succeeded
150  */
151  virtual bool stop() = 0;
152 
153  /**
154  * Returns the start timestamp.
155  * @return Timestamp the medium has been started
156  */
157  virtual Timestamp startTimestamp() const = 0;
158 
159  /**
160  * Returns the pause timestamp.
161  * @return Timestamp the medium has been paused
162  */
163  virtual Timestamp pauseTimestamp() const = 0;
164 
165  /**
166  * Returns the stop timestamp.
167  * @return Timestamp the medium has been stopped
168  */
169  virtual Timestamp stopTimestamp() const = 0;
170 
171  /**
172  * Clones this medium and returns a new independent instance of this medium.
173  * Beware: Some medium objects like e.g. live video or live audio objects cannot be cloned.
174  * @return Cloned medium object
175  */
176  virtual MediumRef clone() const;
177 
178  /**
179  * Converts a medium type to a unique string.
180  * @param type Type of the medium to convert
181  * @return Unique string
182  */
183  static std::string convertType(const Type type);
184 
185  /**
186  * Converts a medium type string to a medium type.
187  * @param type String of the medium type
188  * @return Medium type
189  */
190  static Type convertType(const std::string& type);
191 
192  protected:
193 
194  /**
195  * Disabled copy constructor.
196  * @param medium Object which would be copied
197  */
198  Medium(const Medium& medium) = delete;
199 
200  /**
201  * Creates a new medium by a given url.
202  * @param url Url of the medium
203  */
204  explicit Medium(const std::string& url);
205 
206  /**
207  * Destructs a medium.
208  */
209  virtual ~Medium();
210 
211  /**
212  * Disabled copy operator.
213  * @param medium Object which would be copied
214  * @return Reference to this object
215  */
216  Medium& operator=(const Medium& medium) = delete;
217 
218  protected:
219 
220  /// Url of the medium.
221  std::string url_;
222 
223  /// Name of the owner library.
224  std::string libraryName_;
225 
226  /// Determines whether the medium is valid.
227  bool isValid_ = false;
228 
229  /// Type of the medium
230  Type type_ = MEDIUM;
231 
232  /// Medium lock.
233  mutable Lock lock_;
234 };
235 
236 inline const std::string& Medium::url() const
237 {
238  return url_;
239 }
240 
241 inline bool Medium::isValid() const
242 {
243  return isValid_;
244 }
245 
246 inline const std::string& Medium::library() const
247 {
248  return libraryName_;
249 }
250 
252 {
253  return type_;
254 }
255 
256 }
257 
258 }
259 
260 #endif // META_OCEAN_MEDIA_MEDIUM_H
This class implements a recursive lock object.
Definition: Lock.h:31
This is the base class for all mediums.
Definition: Medium.h:48
virtual ~Medium()
Destructs a medium.
Medium(const Medium &medium)=delete
Disabled copy constructor.
virtual bool pause()=0
Pauses the medium.
virtual bool isStarted() const =0
Returns whether the medium is started currently.
Lock lock_
Medium lock.
Definition: Medium.h:233
bool isType(const Type type) const
Returns whether a medium has a given type.
virtual bool start()=0
Starts the medium.
virtual MediumRef clone() const
Clones this medium and returns a new independent instance of this medium.
std::string libraryName_
Name of the owner library.
Definition: Medium.h:224
Type type_
Type of the medium.
Definition: Medium.h:230
static std::string convertType(const Type type)
Converts a medium type to a unique string.
virtual bool stop()=0
Stops the medium.
Medium(const std::string &url)
Creates a new medium by a given url.
bool isExclusive() const
Returns whether this medium can be use exclusively.
static Type convertType(const std::string &type)
Converts a medium type string to a medium type.
Type type() const
Returns the type of the medium.
Definition: Medium.h:251
Medium & operator=(const Medium &medium)=delete
Disabled copy operator.
std::string url_
Url of the medium.
Definition: Medium.h:221
virtual Timestamp pauseTimestamp() const =0
Returns the pause timestamp.
virtual Timestamp startTimestamp() const =0
Returns the start timestamp.
bool isValid() const
Returns whether the medium is valid.
Definition: Medium.h:241
const std::string & library() const
Returns the name of the owner library.
Definition: Medium.h:246
bool isValid_
Determines whether the medium is valid.
Definition: Medium.h:227
const std::string & url() const
Returns the url of the medium.
Definition: Medium.h:236
virtual Timestamp stopTimestamp() const =0
Returns the stop timestamp.
Type
Definition of different medium types.
Definition: Medium.h:57
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
This class implements a timestamp.
Definition: Timestamp.h:36
ObjectRef< Medium > MediumRef
This class implements a medium reference with an internal reference counter.
Definition: Medium.h:23
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15