Ocean
USBLibrary.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_USB_USB_LIBRARY_H
9 #define META_OCEAN_MEDIA_USB_USB_LIBRARY_H
10 
11 #include "ocean/media/usb/USB.h"
12 
13 #include "ocean/media/Library.h"
14 #include "ocean/media/Manager.h"
15 
16 #ifdef OCEAN_PLATFORM_BUILD_ANDROID
18 #endif
19 
20 namespace Ocean
21 {
22 
23 namespace Media
24 {
25 
26 namespace USB
27 {
28 
29 /**
30  * This class implements the USB library.
31  * @ingroup mediausb
32  */
33 class OCEAN_MEDIA_USB_EXPORT USBLibrary : public Library
34 {
35  friend class USBLiveVideo;
36  friend class Media::Manager;
37 
38  public:
39 
40  /**
41  * Creates a new medium by a given url.
42  * @see Library::newMedium().
43  */
44  MediumRef newMedium(const std::string& url, bool useExclusive = false) override;
45 
46  /**
47  * Creates a new medium by a given url and an expected type.
48  * @see Library::newMedium().
49  */
50  MediumRef newMedium(const std::string& url, const Medium::Type type, bool useExclusive = false) override;
51 
52  /**
53  * Creates a new recorder specified by the recorder type.
54  * @see Library::newRecorder().
55  */
56  RecorderRef newRecorder(const Recorder::Type type) override;
57 
58  /**
59  * Returns a list of selectable mediums.
60  * @see Library::selectableMedia().
61  */
62  Definitions selectableMedia() const override;
63 
64  /**
65  * Returns a list of specific selectable mediums.
66  * @see Library::selectableMedia().
67  */
68  Definitions selectableMedia(const Medium::Type type) const override;
69 
70  /**
71  * Returns the supported medium types.
72  * @see Library::supportedTypes().
73  */
74  Medium::Type supportedTypes() const override;
75 
76  /**
77  * Registers this library at the global media manager.
78  * With each register call, the reference counter for a specific library will be incremented.
79  * Each call to registerLibrary() needs to be balanced with a corresponding call of unregisterLibrary() before shutting down.
80  * @return True, if the library has not been registered before
81  * @see Manager, unregisterLibrary()
82  */
83  static bool registerLibrary();
84 
85  /**
86  * Unregisters this library at the global media manager.
87  * With each unregister call, the reference counter for a specific library will be decremented and removed from the system if the counter reaches zero.
88  * Each call to registerLibrary() needs to be balanced with a corresponding call of unregisterLibrary() before shutting down.
89  * @return True, if the library was actually removed from the system (as the reference counter reached zero); False, if the library is still used by someone else
90  * @see registerLibrary().
91  */
92  static bool unregisterLibrary();
93 
94  /**
95  * Returns the definitions of all available USB camera devices.
96  * @return The definitions of the available USB cameras, empty if no camera is connected or an error occurred
97  */
99 
100 #ifdef OCEAN_PLATFORM_BUILD_ANDROID
101 
102  /**
103  * Returns device descriptors for all available USB camera devices on Android platforms.
104  * On Android, we cannot enumerate all USB devices through libusb, instead we need to enumerate devices through Java.
105  * @return The device descriptors for all available USB camera devices, empty if no camera is connected or an error occurred
106  */
108 
109 #endif // OCEAN_PLATFORM_BUILD_ANDROID
110 
111  protected:
112 
113  /**
114  * Creates a new USBLibrary object.
115  */
117 
118  /**
119  * Destructs an USBLibrary object.
120  */
121  ~USBLibrary() override;
122 
123  /**
124  * Ensures that the available devices are up-to-date.
125  */
127 
128  /**
129  * Resolves a medium url to a device name.
130  * @param url The URL of the medium, must be valid
131  * @param deviceName The resulting device name
132  * @return True, if succeeded
133  */
134  std::string resolveUrl(const std::string& url, std::string& deviceName) const;
135 
136  /**
137  * Creates a new live video medium.
138  * @param url The URL of the live video medium to create
139  * @param useExclusive Determines whether the caller would like to use this medium exclusively
140  * @return Reference of the new medium
141  */
142  MediumRef newLiveVideo(const std::string& url, bool useExclusive);
143 
144  /**
145  * Creates this library and returns it an object reference.
146  * @return The new library object
147  */
148  static LibraryRef create();
149 
150  protected:
151 
152  /// The definitions of available USB devices.
154 
155  /// The timestamp when the available devices have been queried the last time.
157 };
158 
159 }
160 
161 }
162 
163 }
164 
165 #endif // META_OCEAN_MEDIA_USB_USB_LIBRARY_H
This class is the base class for all media libraries.
Definition: media/Library.h:42
std::vector< Definition > Definitions
Definition of a vector holding medium definition objects.
Definition: media/Library.h:111
This class is the manager for all media objects.
Definition: media/Manager.h:34
Type
Definition of different medium types.
Definition: Medium.h:57
Type
Definition of different recorder types.
Definition: Recorder.h:46
This class implements the USB library.
Definition: USBLibrary.h:34
static LibraryRef create()
Creates this library and returns it an object reference.
Timestamp lastAvailableDevicesTimestamp_
The timestamp when the available devices have been queried the last time.
Definition: USBLibrary.h:156
static bool unregisterLibrary()
Unregisters this library at the global media manager.
Definitions selectableMedia() const override
Returns a list of selectable mediums.
MediumRef newMedium(const std::string &url, const Medium::Type type, bool useExclusive=false) override
Creates a new medium by a given url and an expected type.
Medium::Type supportedTypes() const override
Returns the supported medium types.
MediumRef newLiveVideo(const std::string &url, bool useExclusive)
Creates a new live video medium.
Definitions selectableMedia(const Medium::Type type) const override
Returns a list of specific selectable mediums.
void updateAvailableDevices() const
Ensures that the available devices are up-to-date.
MediumRef newMedium(const std::string &url, bool useExclusive=false) override
Creates a new medium by a given url.
static Definitions enumerateCameraDefinitions()
Returns the definitions of all available USB camera devices.
~USBLibrary() override
Destructs an USBLibrary object.
RecorderRef newRecorder(const Recorder::Type type) override
Creates a new recorder specified by the recorder type.
static bool registerLibrary()
Registers this library at the global media manager.
Definitions availableDevices_
The definitions of available USB devices.
Definition: USBLibrary.h:153
std::string resolveUrl(const std::string &url, std::string &deviceName) const
Resolves a medium url to a device name.
USBLibrary()
Creates a new USBLibrary object.
static System::USB::Android::OceanUSBManager::DeviceDescriptors androidEnumerateCameraDevices()
Returns device descriptors for all available USB camera devices on Android platforms.
This class implements an live video class for USB devices.
Definition: USBLiveVideo.h:45
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
std::vector< DeviceDescriptor > DeviceDescriptors
Definition of a vector holding device descriptor objects.
Definition: OceanUSBManager.h:97
This class implements a timestamp.
Definition: Timestamp.h:36
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15