Ocean
Loading...
Searching...
No Matches
platform/meta/quest/platformsdk/Microphone.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_PLATFORM_META_QUEST_PLATFORMSDK_MICROPHONE_H
9#define META_OCEAN_PLATFORM_META_QUEST_PLATFORMSDK_MICROPHONE_H
10
12
13#include "ocean/base/Lock.h"
16#include "ocean/base/Thread.h"
17
18#include <OVR_Voip_LowLevel.h>
19
20namespace Ocean
21{
22
23namespace Platform
24{
25
26namespace Meta
27{
28
29namespace Quest
30{
31
32namespace PlatformSDK
33{
34
35/**
36 * This class provides access to the device's microphone.
37 * @ingroup platformmetaquestplatformsdk
38 */
39class OCEAN_PLATFORM_META_QUEST_PLATFORMSDK_EXPORT Microphone :
40 public Singleton<Microphone>,
41 protected Thread
42{
43 friend class Singleton<Microphone>;
44
45 public:
46
47 /**
48 * Definition of a callback function for microphone samples.
49 * The data format is signed 16 bit integer 48khz mono.
50 * @param elements The elements of the sample, must be valid
51 * @param size The number of elements in the sample, with range [1, infinity)
52 */
53 using SampleCallback = std::function<void(const int16_t* elements, const size_t size)>;
54
55 /**
56 * Definition of a subscription object for microphone samples.
57 * The subscription exists as long as this object exists.<br>
58 * The microphone will be stopped once the last subscription object is disposed.
59 */
61
62 protected:
63
64 /**
65 * Definition of a map mapping subscription ids to callback functions for microphone samples.
66 */
67 using SampleCallbackMap = std::unordered_map<unsigned int, SampleCallback>;
68
69 public:
70
71 /**
72 * Starts the microphone.
73 * This function can be called several times for several users.<br>
74 * The microphone will be recording as long as at least one ScopedSubscription object exists.
75 * @param sampleCallback The callback function for microphone samples, must be valid
76 * @return The subscription object, invalid if the microphone could not be started
77 */
78 [[nodiscard]] ScopedSubscription start(SampleCallback sampleCallback);
79
80 protected:
81
82 /**
83 * Default constructor.
84 */
85 Microphone() = default;
86
87 /**
88 * Stops the microphone.
89 * @param subscriptionId The subscription id for which the microphone will be stopped, must be valid
90 */
91 void stop(const unsigned int& subscriptionId);
92
93 /**
94 * The internal thread function.
95 */
96 void threadRun() override;
97
98 protected:
99
100 /// The counter for subscription ids.
101 unsigned int subscriptionIdCounter_ = 1u;
102
103 /// The handle for the microphone.
104 ovrMicrophoneHandle microphoneHandle_ = nullptr;
105
106 /// The callback functions for microphone samples.
108
109 /// The microphone's lock.
111};
112
113}
114
115}
116
117}
118
119}
120
121}
122
123#endif // META_OCEAN_PLATFORM_META_QUEST_PLATFORMSDK_MICROPHONE_H
This class implements a recursive lock object.
Definition Lock.h:31
This class provides access to the device's microphone.
Definition platform/meta/quest/platformsdk/Microphone.h:42
SampleCallbackMap sampleCallbackMap_
The callback functions for microphone samples.
Definition platform/meta/quest/platformsdk/Microphone.h:107
void threadRun() override
The internal thread function.
std::function< void(const int16_t *elements, const size_t size)> SampleCallback
Definition of a callback function for microphone samples.
Definition platform/meta/quest/platformsdk/Microphone.h:53
std::unordered_map< unsigned int, SampleCallback > SampleCallbackMap
Definition of a map mapping subscription ids to callback functions for microphone samples.
Definition platform/meta/quest/platformsdk/Microphone.h:67
ScopedSubscription start(SampleCallback sampleCallback)
Starts the microphone.
void stop(const unsigned int &subscriptionId)
Stops the microphone.
Lock lock_
The microphone's lock.
Definition platform/meta/quest/platformsdk/Microphone.h:110
This class implements a subscription object which can be used unique subscriptions to e....
Definition ScopedSubscription.h:28
This template class is the base class for all singleton objects.
Definition Singleton.h:71
This class implements a thread.
Definition Thread.h:115
The namespace covering the entire Ocean framework.
Definition Accessor.h:15