Ocean
AVFMicrophone.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_MICROPHONE_H
9 #define META_OCEAN_MEDIA_AVF_MICROPHONE_H
10 
13 
14 #include "ocean/media/Microphone.h"
15 
16 
17 namespace Ocean
18 {
19 
20 namespace Media
21 {
22 
23 namespace AVFoundation
24 {
25 
26 /**
27  * This class implements an AVFoundation microphone object.
28  * @ingroup mediaavf
29  */
31  virtual public AVFMedium,
32  virtual public Microphone
33 {
34  friend class AVFLibrary;
35 
36  protected:
37 
38  /**
39  * Definition of a vector holding sample elements.
40  */
41  typedef std::vector<int16_t> Buffer;
42 
43  protected:
44 
45  /**
46  * Creates a new medium by a given url.
47  * @param url Url of the medium
48  */
49  explicit AVFMicrophone(const std::string& url);
50 
51  /**
52  * Destructs the media object.
53  */
54  ~AVFMicrophone() override;
55 
56  /**
57  * Internally starts the medium.
58  * @see AVFMedium::internalStart()
59  */
60  bool internalStart() override;
61 
62  /**
63  * Internally pauses the medium.
64  * @see AVFMedium::internalPause()
65  */
66  bool internalPause() override;
67 
68  /**
69  * Internally stops the medium.
70  * @see AVFMedium::internalStop()
71  */
72  bool internalStop() override;
73 
74  /**
75  * Extracts and sends mono samles form a PCM buffer.
76  * @param avAudioPCMBuffer The PCM buffer from which the samples will be extracted, must be valid
77  * @return True, if succeeded
78  */
79  bool sendSamplesMono(AVAudioPCMBuffer* avAudioPCMBuffer);
80 
81  protected:
82 
83  /// The audio engine.
84  AVAudioEngine* avAudioEngine_ = nullptr;
85 
86  /// Optional convert from external audio format to internal audio format.
87  AVAudioConverter* avAudioConverter_ = nullptr;
88 
89  /// Optional audio format for int16 samples.
90  AVAudioFormat* avAudioFormatInternalInt16_ = nullptr;
91 
92  /// Optional audio buffer for int16 samples.
93  AVAudioPCMBuffer* avAudioPCMBufferInternalInt16_ = nullptr;
94 
95  /// True, if the audio session was started.
96  bool audioSessionStarted_ = false;
97 };
98 
99 }
100 
101 }
102 
103 }
104 
105 #endif // META_OCEAN_MEDIA_AVF_MICROPHONE_H
This class implements the AVFoundation library.
Definition: AVFLibrary.h:32
This is the base class for all AVFoundation mediums.
Definition: AVFMedium.h:36
This class implements an AVFoundation microphone object.
Definition: AVFMicrophone.h:33
bool internalStart() override
Internally starts the medium.
bool internalStop() override
Internally stops the medium.
bool internalPause() override
Internally pauses the medium.
AVAudioEngine * avAudioEngine_
The audio engine.
Definition: AVFMicrophone.h:84
std::vector< int16_t > Buffer
Definition of a vector holding sample elements.
Definition: AVFMicrophone.h:41
AVFMicrophone(const std::string &url)
Creates a new medium by a given url.
~AVFMicrophone() override
Destructs the media object.
bool sendSamplesMono(AVAudioPCMBuffer *avAudioPCMBuffer)
Extracts and sends mono samles form a PCM buffer.
bool audioSessionStarted_
True, if the audio session was started.
Definition: AVFMicrophone.h:96
AVAudioPCMBuffer * avAudioPCMBufferInternalInt16_
Optional audio buffer for int16 samples.
Definition: AVFMicrophone.h:93
AVAudioFormat * avAudioFormatInternalInt16_
Optional audio format for int16 samples.
Definition: AVFMicrophone.h:90
AVAudioConverter * avAudioConverter_
Optional convert from external audio format to internal audio format.
Definition: AVFMicrophone.h:87
const std::string & url() const
Returns the url of the medium.
Definition: Medium.h:236
This class is the base class for all microphones.
Definition: media/Microphone.h:37
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15