RDK Documentation (Open Sourced RDK Components)
rmfAudioCapture.h
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 /***************************************************************************
20 *
21 * Rmf Audio Capture -> RAC -> rac
22 */
23 
24 
25 /**
26  * @defgroup MEDIA_UTILS Media Utils
27  * - Audio capture manager presents the audio data to registered applications.
28  *
29  * @defgroup MEDIA_UTILS_TYPES Media Utils Data types
30  * @ingroup MEDIA_UTILS
31  *
32  * @defgroup MEDIA_UTILS_HAL_APIS Media Utils hal APIs
33  * @ingroup MEDIA_UTILS
34  *
35  **/
36 
37 
38 #ifndef __RMF_AUDIO_CAPTURE_H__
39 #define __RMF_AUDIO_CAPTURE_H__
40 
41 #include <stddef.h> /* size_t */
42 
43 /* tbd, Can we use RMF_errors instead of having private errors? */
44 #include "rmf_error.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
50 /**
51  * @addtogroup MEDIA_UTILS_TYPES
52  * @{
53  */
54 
55 typedef struct RMF_AudioCapture_Struct *RMF_AudioCaptureHandle;
56 
57 typedef char *RMF_AudioCaptureType;
58 
59 /* tbd, Can we use RMF_errors instead of having private errors? */
60 #define RMF_ERROR (1)
61 #define RMF_INVALID_PARM (2)
62 
63 
64 #define RMF_AC_TYPE_PRIMARY "primary"
65 #define RMF_AC_TYPE_AUXILIARY "auxiliary"
66 
68  racFormat_e16BitStereo, /**< Stereo, 16 bits per sample interleaved into a 32-bit word. */
69  racFormat_e24BitStereo, /**< Stereo, 24 bits per sample. The data is aligned to 32-bits,
70  left-justified. Left and right channels will interleave
71  one sample per 32-bit word. */
72  racFormat_e16BitMonoLeft, /**< Mono, 16 bits per sample interleaved into a 32-bit word. Left channel samples only. */
73  racFormat_e16BitMonoRight, /**< Mono, 16 bits per sample interleaved into a 32-bit word. Right channel samples only. */
74  racFormat_e16BitMono, /**< Mono, 16 bits per sample interleaved into a 32-bit word. Left and Right channels mixed. */
75  racFormat_e24Bit5_1, /**< 5.1 Multichannel, 24 bits per sample. The data is aligned to 32-bits,
76  left-justified. Channels will interleave
77  one sample per 32-bit word, ordered L,R,Ls,Rs,C,LFE. */
78  racFormat_eMax
79 } racFormat;
80 
81 
82 typedef enum RMF_AudioCapture_Freq {
83  racFreq_e16000, /**< 16KHz */
84  racFreq_e22050, /**< 22.05KHz */
85  racFreq_e24000, /**< 24KHz */
86  racFreq_e32000, /**< 32KHz */
87  racFreq_e44100, /**< 44.1KHz */
88  racFreq_e48000, /**< 48KHz */
89  racFreq_eMax
90 } racFreq;
91 
92 
93 
94 /*
95  * Callbacks
96  */
97 /* Callback which will be called when captured Audio Buffer is ready to be processed */
98 typedef rmf_Error (*RMF_AudioCaptureBufferReadyCb)(void *cbBufferReadyParm, void *AudioCaptureBuffer, unsigned int AudioCaptureBufferSize);
99 
100 /* Callback which will be called when there is a change in the AudioCapture modules status, application can call Get Status */
101 typedef rmf_Error (*RMF_AudioCapture_StatusChangeCb)(void *cbStatusParm);
102 
103 
105  RMF_AudioCaptureBufferReadyCb cbBufferReady; /**< Callback to send audio data to application. Must be set during Open call, no other way to get audio data to application */
106  void *cbBufferReadyParm; /**< Application context data passed back in Buffer Ready callback, can be NULL */
107 
108  RMF_AudioCapture_StatusChangeCb cbStatusChange; /**< If cbStatusChange is NOT NULL, then the library should trigger the callback when there is a status change is AudioCapture
109  Examples: OnStart of AC, Change from Start to Stop of AC. On underflow/overflow */
110  void *cbStatusParm; /**< Application context data passed back in Status Change callback */
111 
112  size_t fifoSize; /**< FIFO size in bytes. This value is a total FIFO size to hold all channels of data
113  If not set, a default size will be used. Needs to be big enough to avoid overflow (expected service time * byte rate)*/
114  size_t threshold; /**< FIFO data callback threshold in bytes. When the amount of data in the FIFO reaches this level, the dataCallback will be invoked */
115  racFormat format; /**< Captured data format. Default is 16bit stereo.
116  This value is ignored for compressed data, and
117  can not be changed while connected to any inputs. */
118  racFreq samplingFreq; /**< Captured data sampling freq tbd, not currently supported..*/
119 
120  unsigned int delayCompensation_ms; /**< Delay compensation in milli seconds */
122 
123 
124 typedef struct RMF_AudioCapture_Status {
125  int started; /**< is the capture started */ //TODO: C interface, bool not define, typedef later
126  racFormat format; /**< Current capture format (Bit depth & Channel) */
127  racFreq samplingFreq; /**< Current capture sample rate */
128  size_t fifoDepth; /**< number of bytes in local fifo */
129  unsigned int overflows; /**< count of overflows */
130  unsigned int underflows; /**< count of overflows */
131  int muted; /**< is the capture muted */ //TODO: C interface, bool not define, typedef later
132  int paused; /**< is the capture muted */ //TODO: C interface, bool not define, typedef later
133  float volume; /**< current capture volume */
134  /* tbd ... need to determine what is useful or even what is possible.*/
136 
137 /** @} */ //END OF GROUP MEDIA_UTILS_TYPES
138 
139 
140 /**
141  * @addtogroup MEDIA_UTILS_HAL_APIS
142  * @{
143  */
144 
145 /*
146  * Interfaces
147  */
148 
149 /**
150  * @brief This API creates audio capture session, create all required resources to provide audio capture handle.
151  *
152  * @param[in] handle RMF audio capture instance handle.
153  *
154  * @return Returns a opaque AudioCaptureHandle, which has to be passed as an argument for all subsequent AudioCapture calls
155  * @return Returns RMF error code.
156  */
157 rmf_Error RMF_AudioCapture_Open (RMF_AudioCaptureHandle* handle);
158 
159 /**
160  * @brief This API creates audio capture session, create all required resources to provide audio capture handle.
161  *
162  * @param[in] handle RMF audio capture instance handle.
163  * @param[in] rmfAcType RMF audio capture instance handle.
164  *
165  * @return Returns a opaque AudioCaptureHandle, which has to be passed as an argument for all subsequent AudioCapture calls
166  * @return Returns RMF error code.
167  */
168 rmf_Error RMF_AudioCapture_Open_Type (RMF_AudioCaptureHandle* handle, RMF_AudioCaptureType rmfAcType);
169 
170 /**
171  * @brief This API is used to enquire the current status of Audio Capture associated with the current Audio Capture context.
172  *
173  * @param[in] handle Audio capture handle.
174  * @param[in] status Structure which has audio capture status informations.
175  *
176  * @return Returns RMF error code.
177  */
178 rmf_Error RMF_AudioCapture_GetStatus (RMF_AudioCaptureHandle handle, RMF_AudioCapture_Status* status);
179 
180 /**
181  * @brief This API Will return default RMF audio capture settings.
182  *
183  * Once audio capture gets started this API will continue to return the default capture settings.
184  *
185  * @param[in] settings Structure which holds the audio properties.
186  *
187  * @return Returns RMF error code.
188  */
190 
191 /**
192  * @brief This API will return the audio capture settings which has been successfully set for that context.
193  *
194  * Return the settings currently being used to capture data as part of the specific Audio capture context.
195  *
196  * @param[in] handle Audio capture handle.
197  * @param[in] settings Structure which holds the audio properties.
198  *
199  * @return Returns RMF error code.
200  */
201 rmf_Error RMF_AudioCapture_GetCurrentSettings (RMF_AudioCaptureHandle handle, RMF_AudioCapture_Settings* settings);
202 
203 /**
204  * @brief This API will start the Audio capture.
205  *
206  * If audio capture settings are retained then this API will reconfigure with the provided capture settings to start audio capture.
207  * If audio capture settings are not retained then audio capture will start with the default capture settings.
208  *
209  * @param[in] handle audio capture handle.
210  * @param[in] settings Structure which holds the audio settings.
211  *
212  * @return Returns RMF error code.
213 */
214 rmf_Error RMF_AudioCapture_Start (RMF_AudioCaptureHandle handle, RMF_AudioCapture_Settings* settings);
215 
216 /**
217  * @brief This API will stop the audio capture.
218  *
219  * Start can be called again after a Stop, as long as Close has not been called.
220  *
221  * @param[in] handle audio capture handle.
222  *
223  * @return Returns RMF error code.
224  */
225 rmf_Error RMF_AudioCapture_Stop (RMF_AudioCaptureHandle handle);
226 
227 /**
228  * @brief This API will free all resources associated with this audio capture handle. It will close audio capture session.
229  *
230  * @param[in] handle audio capture handle.
231  *
232  * @return Returns RMF error code.
233  */
234 rmf_Error RMF_AudioCapture_Close (RMF_AudioCaptureHandle handle);
235 
236 
237 /** @} */ //END OF GROUP MEDIA_UTILS_HAL_APIS
238 
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 #endif /* __RMF_AUDIO_CAPTURE_H__ */
racFormat_e24Bit5_1
@ racFormat_e24Bit5_1
Definition: rmfAudioCapture.h:75
racFreq_e24000
@ racFreq_e24000
Definition: rmfAudioCapture.h:85
RMF_AudioCapture_Settings
Definition: rmfAudioCapture.h:104
RMF_AudioCapture_Settings::cbStatusParm
void * cbStatusParm
Definition: rmfAudioCapture.h:110
racFreq_e22050
@ racFreq_e22050
Definition: rmfAudioCapture.h:84
racFreq_e48000
@ racFreq_e48000
Definition: rmfAudioCapture.h:88
RMF_AudioCapture_Settings::delayCompensation_ms
unsigned int delayCompensation_ms
Definition: rmfAudioCapture.h:120
RMF_AudioCapture_Start
rmf_Error RMF_AudioCapture_Start(RMF_AudioCaptureHandle handle, RMF_AudioCapture_Settings *settings)
This API will start the Audio capture.
Definition: rmfAudioCapture.c:71
RMF_AudioCapture_Status::fifoDepth
size_t fifoDepth
Definition: rmfAudioCapture.h:128
RMF_AudioCapture_Status::started
int started
Definition: rmfAudioCapture.h:125
RMF_AudioCapture_Settings::threshold
size_t threshold
Definition: rmfAudioCapture.h:114
RMF_AudioCapture_Open
rmf_Error RMF_AudioCapture_Open(RMF_AudioCaptureHandle *handle)
This API creates audio capture session, create all required resources to provide audio capture handle...
Definition: rmfAudioCapture.c:23
racFreq_e32000
@ racFreq_e32000
Definition: rmfAudioCapture.h:86
RMF_AudioCapture_Status::muted
int muted
Definition: rmfAudioCapture.h:131
RMF_AudioCapture_Freq
RMF_AudioCapture_Freq
Definition: rmfAudioCapture.h:82
racFormat_e16BitMonoRight
@ racFormat_e16BitMonoRight
Definition: rmfAudioCapture.h:73
RMF_AudioCapture_Settings::cbBufferReadyParm
void * cbBufferReadyParm
Definition: rmfAudioCapture.h:106
RMF_AudioCapture_Status::format
racFormat format
Definition: rmfAudioCapture.h:126
racFormat_e24BitStereo
@ racFormat_e24BitStereo
Definition: rmfAudioCapture.h:69
racFormat_e16BitMono
@ racFormat_e16BitMono
Definition: rmfAudioCapture.h:74
RMF_AudioCapture_Status::paused
int paused
Definition: rmfAudioCapture.h:132
RMF_AudioCapture_Settings::fifoSize
size_t fifoSize
Definition: rmfAudioCapture.h:112
RMF_AudioCapture_Stop
rmf_Error RMF_AudioCapture_Stop(RMF_AudioCaptureHandle handle)
This API will stop the audio capture.
Definition: rmfAudioCapture.c:82
RMF_AudioCapture_Settings::cbStatusChange
RMF_AudioCapture_StatusChangeCb cbStatusChange
Definition: rmfAudioCapture.h:108
RMF_AudioCapture_Status::underflows
unsigned int underflows
Definition: rmfAudioCapture.h:130
RMF_AudioCapture_GetCurrentSettings
rmf_Error RMF_AudioCapture_GetCurrentSettings(RMF_AudioCaptureHandle handle, RMF_AudioCapture_Settings *settings)
This API will return the audio capture settings which has been successfully set for that context.
Definition: rmfAudioCapture.c:60
racFreq_e44100
@ racFreq_e44100
Definition: rmfAudioCapture.h:87
RMF_AudioCapture_Close
rmf_Error RMF_AudioCapture_Close(RMF_AudioCaptureHandle handle)
This API will free all resources associated with this audio capture handle. It will close audio captu...
Definition: rmfAudioCapture.c:91
RMF_AudioCapture_Status::overflows
unsigned int overflows
Definition: rmfAudioCapture.h:129
RMF_AudioCapture_GetDefaultSettings
rmf_Error RMF_AudioCapture_GetDefaultSettings(RMF_AudioCapture_Settings *settings)
This API Will return default RMF audio capture settings.
Definition: rmfAudioCapture.c:51
RMF_AudioCapture_Open_Type
rmf_Error RMF_AudioCapture_Open_Type(RMF_AudioCaptureHandle *handle, RMF_AudioCaptureType rmfAcType)
This API creates audio capture session, create all required resources to provide audio capture handle...
Definition: rmfAudioCapture.c:31
RMF_AudioCapture_Settings::samplingFreq
racFreq samplingFreq
Definition: rmfAudioCapture.h:118
RMF_AudioCapture_Settings::cbBufferReady
RMF_AudioCaptureBufferReadyCb cbBufferReady
Definition: rmfAudioCapture.h:105
racFreq_e16000
@ racFreq_e16000
Definition: rmfAudioCapture.h:83
racFormat_e16BitStereo
@ racFormat_e16BitStereo
Definition: rmfAudioCapture.h:68
RMF_AudioCapture_Settings::format
racFormat format
Definition: rmfAudioCapture.h:115
RMF_AudioCapture_Status
Definition: rmfAudioCapture.h:124
RMF_AudioCapture_Format
RMF_AudioCapture_Format
Definition: rmfAudioCapture.h:67
RMF_AudioCapture_GetStatus
rmf_Error RMF_AudioCapture_GetStatus(RMF_AudioCaptureHandle handle, RMF_AudioCapture_Status *status)
This API is used to enquire the current status of Audio Capture associated with the current Audio Cap...
Definition: rmfAudioCapture.c:40
racFormat_e16BitMonoLeft
@ racFormat_e16BitMonoLeft
Definition: rmfAudioCapture.h:72
RMF_AudioCapture_Status::samplingFreq
racFreq samplingFreq
Definition: rmfAudioCapture.h:127
RMF_AudioCapture_Status::volume
float volume
Definition: rmfAudioCapture.h:133