RDK-V RMF AudioCapture HAL 0.2.0
 
Loading...
Searching...
No Matches
rmfAudioCapture.h
Go to the documentation of this file.
1/*
2 * If not stated otherwise in this file or this component's LICENSE 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 * @addtogroup HPK HPK
26 * @{
27 * @par The Hardware Porting Kit
28 * HPK is the next evolution of the well-defined Hardware Abstraction Layer
29 * (HAL), but augmented with more comprehensive documentation and test suites
30 * that OEM or SOC vendors can use to self-certify their ports before taking
31 * them to RDKM for validation or to an operator for final integration and
32 * deployment. The Hardware Porting Kit effectively enables an OEM and/or SOC
33 * vendor to self-certify their own Video Accelerator devices, with minimal RDKM
34 * assistance.
35 *
36 */
37
38/**
39 * @addtogroup RMF_AudioCapture RMF Audio Capture
40 * @{
41 * @par Application API Specification
42 * RMF AudioCapture is the RDK interface designed to tap into the audio output
43 * of an STB/TV. When in use, the underlying SoC implementation will deliver a
44 * steady stream of raw audio data (PCM). This audio will include the active
45 * audio track of whatever content is being played, and may include other sounds
46 * mixed in, such as voice-guidance, application-driven audio overlays (eg:
47 * beeps) etc. RDK will attempt to configure audio format parameters (channels,
48 * bit rate etc.) to its liking but not all combinations are expected to be
49 * supported by the SoC implementation.
50 *
51 */
52
53/**
54 * @defgroup RMF_AudioCapture_HAL RMF Audio Capture HAL
55 * @{
56 */
57
58#ifndef __RMF_AUDIO_CAPTURE_H__
59#define __RMF_AUDIO_CAPTURE_H__
60
61#include <stddef.h> /* size_t */
62
63/* tbd, Can we use RMF_errors instead of having private errors? */
64#include "rmf_error.h"
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70/**
71 * @brief Opaque handle to an instance of RMF AudioCapture interface.
72 *
73 */
74typedef struct RMF_AudioCapture_Struct *RMF_AudioCaptureHandle;
75
76typedef char *RMF_AudioCaptureType; //!< Audio source to be captured. Options are RMF_AC_TYPE_PRIMARY or RMF_AC_TYPE_AUXILIARY
77
78/* tbd, Can we use RMF_errors instead of having private errors? */
79#define RMF_ERROR (1)
80#define RMF_INVALID_PARM (2)
81
82#define RMF_AC_TYPE_PRIMARY "primary" //!< Primary audio that is currently selected to play with video
83#define RMF_AC_TYPE_AUXILIARY "auxiliary" //!< Audio source that is different from primary audio - can be audio track with a different language
84
85/**
86 * @brief Describes more specifics about the audio parameters to be used for audio samples
87 *
88 */
90 racFormat_e16BitStereo, //!< Stereo, 16 bits per sample interleaved into a 32-bit word
91 racFormat_e24BitStereo, //!< Stereo, 24 bits per sample. The data is aligned to 32-bits left-justified. Left and right channels will interleave one sample per 32-bit word
92 racFormat_e16BitMonoLeft, //!< Mono, 16 bits per sample interleaved into a 32-bit word. Left channel samples only
93 racFormat_e16BitMonoRight, //!< Mono, 16 bits per sample interleaved into a 32-bit word. Right channel samples only
94 racFormat_e16BitMono, //!< Mono, 16 bits per sample interleaved into a 32-bit word. Left and Right channels mixed
95 racFormat_e24Bit5_1, //!< 5.1 Multichannel, 24 bits per sample. The data is aligned to 32-bits, left-justified. Channels will interleave one sample per 32-bit word, ordered L,R,Ls,Rs,C,LFE
98
99/**
100 * @brief Audio sampling rate
101 */
103 racFreq_e16000, //!< 16KHz
104 racFreq_e22050, //!< 22.05KHz
105 racFreq_e24000, //!< 24KHz
106 racFreq_e32000, //!< 32KHz
107 racFreq_e44100, //!< 44.1KHz
108 racFreq_e48000, //!< 48KHz
111
112/**
113 * @brief Callbacks
114 */
115
116/**
117 * @brief Callback via which SoC will send captured audio samples
118 *
119 * The callback will not take ownership of AudioCaptureBuffer. It will consume the audio data completely before returning and it is the responsibility
120 * of the caller to free/manage this memory.
121 *
122 * @param [in] cbBufferReadyParm - Caller context data passed back (optional) in the callback
123 * @param [in] AudioCaptureBuffer - Pointer to the buffer holding audio data
124 * @param [in] AudioCaptureBufferSize - Size of audio data available in buffer
125 *
126 * @return Indicates an error if a non-zero value is returned
127 * @retval RMF_ERROR General error
128 * @retval RMF_INVALID_PARM Invalid parameter
129 *
130 * @see RMF_AudioCapture_Settings, RMF_AudioCapture_Start()
131 */
132typedef rmf_Error (*RMF_AudioCaptureBufferReadyCb)(void *cbBufferReadyParm, void *AudioCaptureBuffer, unsigned int AudioCaptureBufferSize);
133
134/**
135 * @brief Callback for underlying implementation to signal a change in status
136 *
137 * RDK may then call RMF_AudioCapture_GetStatus() to get more details
138 *
139 * @param [in] cbStatusParm - Caller context data passed back (optional) in the callback
140 *
141 * @return Indicates an error if a non-zero value is returned.
142 * @retval RMF_ERROR General error
143 * @retval RMF_INVALID_PARM Invalid parameter
144 *
145 * @see RMF_AudioCapture_Settings, RMF_AudioCapture_Start()
146 */
147typedef rmf_Error (*RMF_AudioCapture_StatusChangeCb)(void *cbStatusParm);
148
149/**
150 * @brief Configuration parameters of audio capture interface
151 */
153 RMF_AudioCaptureBufferReadyCb cbBufferReady; //!< Callback to send audio data to caller. Must be set in Open call
154 void *cbBufferReadyParm; //!< Caller context data passed back in buffer-ready callback; can be NULL
155
156 RMF_AudioCapture_StatusChangeCb cbStatusChange; //!< If cbStatusChange is not NULL, then the underlying implementation should invoke this callback when there is a change of state in the audio capture interface. Examples: OnStart of AC, Change from Start to Stop of AC. On underflow/overflow
157 void *cbStatusParm; //!< Caller context data passed back in status change callback
158
159 size_t fifoSize; //!< FIFO size in bytes. This value is a total FIFO size to hold all channels of data. If not set, a default size will be used. Needs to be big enough to avoid overflow (expected service time * byte rate)
160 size_t threshold; //!< FIFO data callback threshold in bytes. When the amount of data in the FIFO reaches this level, the buffer-ready will be invoked
161 racFormat format; //!< Format of captured data. Default is racFormat_e16BitStereThis value is ignored for compressed data, and can not be changed while connected to any inputs
162 racFreq samplingFreq; //!< Sampling rate of captured audio. Not currently supported. TBD
163 unsigned int delayCompensation_ms; //!< Delay compensation in milli seconds. This parameter is used to maintain AV sync when using latency-prone audio outputs like Bluetooth. It's the number of ms to delay video by in order to stay in sync with Bluetooth audio
165
166/**
167 * @brief Status of audio capture interface
168 *
169 */
171 int started; //!< Indicates whether capture has started
172 racFormat format; //!< Current capture format (bit depth & channel)
173 racFreq samplingFreq; //!< Current capture sample rate
174 size_t fifoDepth; //!< Number of bytes in local fifo
175 unsigned int overflows; //!< Overflow count
176 unsigned int underflows; //!< Underflow count
177 int muted; //!< Indicates whether capture is muted
178 int paused; //!< Indicates whether capture is paused
179 float volume; //!< Current capture volume
180
181 /* tbd ... need to determine what is useful or even what is possible. */
183
184
185/*
186 * Interfaces
187 */
188
189/**
190 * @brief Opens the audio capture interface for primary audio
191 *
192 * This function or RMF_AudioCapture_Open_Type() will be the first call when this library is used. Any other interface exposed by this library.
193 * Underlying implementation must acquire the necessary hardware and software resources necessary to capture audio.
194 * RMF_AudioCapture doesn't expect more than one primary capture session to be available concurrently and will close the open session before calling open again.
195 *
196 * @param [out] handle - An opaque capture interface handle, which should not be modified by caller and has to be passed as an argument
197 * for all subsequent API calls.
198 *
199 * @return rmf_Error
200 * @retval RMF_ERROR General error
201 * @retval RMF_INVALID_PARM Invalid parameter
202 *
203 * @see RMF_AudioCapture_Close()
204 *
205 * @note Should the application crash, it's recommended that the HAL be capable of automatically releasing any hardware resources, either when terminating or when
206 * the application restarts and RMF_AudioCapture_Open()/RMF_AudioCapture_Open_Type() again
207 */
209
210/**
211 * @brief Opens the audio capture interface for specified audio source.
212 *
213 * This function or RMF_AudioCapture_Open() will be the first call when this library is used. Underlying implementation must acquire the necessary hardware and
214 * software resources to capture audio. RMF_AudioCapture may have both primary and auxiliary capture sessions open at the same time.
215 * There will not be more than one capture session open for the same capture type at any point of time.
216 *
217 * @param [out] handle - An opaque capture interface handle, which should not be modified by caller and has to be passed as an argument
218 * for all subsequent API calls.
219 * @param [in] rmfAcType - Source of audio to be captured (primary or auxiliary).
220 *
221 * @return rmf_Error
222 * @retval RMF_ERROR General error
223 * @retval RMF_INVALID_PARM Invalid parameter
224 *
225 * @see RMF_AudioCapture_Close()
226 *
227 * @note Should the application crash, it's recommended that the HAL be capable of automatically releasing any hardware resources, either when terminating or when
228 * the application restarts and calls RMF_AudioCapture_Open()/RMF_AudioCapture_Open_Type() again.
229 */
231
232/**
233 * @brief Gets the current status of audio capture interface
234 *
235 * This API can be called as long as a valid handle is available (after opening and before close).
236 * API may be invoked as a resonse to RMF_AudioCapture_StatusChangeCb(), possibly inside the callback itself.
237 *
238 * @param [in] handle - Handle of the audio capture interface.
239 * @param [out] status - Status returned by the underlying implementation.
240 * The life-cycle of status will be managed by the caller.
241 *
242 * @return rmf_Error
243 * @retval RMF_ERROR General error
244 * @retval RMF_INVALID_PARM Invalid parameter
245 *
246 * @pre Must possess a valid handle obtained using RMF_AudioCapture_Open() before invoking this function.
247 *
248 * @see RMF_AudioCapture_Open()
249 */
251
252/**
253 * @brief Returns friendly default values for @b RMF_AudioCapture_Settings
254 *
255 * Caller will use this to understand what audio-related parameters preferable for this interface. Caller may then use this structure as a
256 * baseline and tweak only stricly necessary parameters before passing it with RMF_AudioCapture_Start(). The defaults are not expected to change
257 * no matter how the capture interface was configured by caller previously (if at all). Caller will only call this API when the interface is in
258 * OPEN or STARTED state.
259 *
260 * @param [out] settings - Default values for audio capture settings.
261 * The life-cycle of settings will be managed by the caller.
262 *
263 * @return rmf_Error
264 * @retval RMF_ERROR General error
265 * @retval RMF_INVALID_PARM Invalid parameter
266 *
267 * @see RMF_AudioCapture_Start()
268 */
270
271/**
272 * @brief Returns current values of @b RMF_AudioCapture_Settings in effect
273 *
274 * The output should match the configuration previously set successfully via RMF_AudioCapture_Start()
275 *
276 * @param [in] handle - Handle of the audio capture interface.
277 * @param [out] settings - current values of audio capture Settings.
278 * The life-cycle of settings will be managed by the caller.
279 *
280 * @return rmf_Error
281 * @retval RMF_ERROR General error
282 * @retval RMF_INVALID_PARM Invalid parameter
283 *
284 * @see RMF_AudioCapture_Start()
285 *
286 * @pre Must call RMF_AudioCapture_Start() before invoking this function
287 */
289
290/**
291 * @brief Starts audio capture
292 *
293 * HAL must apply the new settings before starting audio capture. Underlying implementation must invoke RMF_AudioCaptureBufferReadyCb() repeatedly to deliver
294 * the data in accordance with the FIFO thresholds set. This process must continue until RMF_AudioCapture_Stop() is called. Once stopped, RMF_AudioCapture may
295 * call RMF_AudioCapture_Start() again so long as RMF_AudioCapture_Close() hasn't been invoked yet. settings.cbBufferReady is not allowed to be NULL.
296 *
297 * @param [in] handle - Handle of the audio capture interface.
298 * @param [in] settings - Capture settings to use.
299 * The life-cycle of settings will be managed by the caller.
300 *
301 * @return rmf_Error
302 * @retval RMF_ERROR General error
303 * @retval RMF_INVALID_PARM Invalid settings
304 *
305 * @see RMF_AudioCapture_Stop(), RMF_AudioCaptureBufferReadyCb(), RMF_AudioCapture_GetDefaultSettings(), RMF_AudioCapture_Close()
306 *
307 * @pre Must call RMF_AudioCapture_Open() before invoking this function
308 */
310
311/**
312 * @brief Stops audio capture
313 *
314 * Underlying implementation must no longer generate RMF_AudioCaptureBufferReadyCb() calls after this. Caller may
315 * choose to call RMF_AudioCapture_Start() again to restart capture as long as RMF_AudioCapture_Close() hasn't been called.
316 *
317 * @param [in] handle - Handle of the audio capture interface.
318 *
319 * @return rmf_Error
320 * @retval RMF_ERROR General error.
321 *
322 * @see RMF_AudioCapture_Start(), RMF_AudioCaptureBufferReadyCb(), RMF_AudioCapture_Close()
323 *
324 * @pre Must call RMF_AudioCapture_Start() before invoking this function
325 */
327
328/**
329 * @brief Closes the audio capture interface
330 *
331 * This call must free all resources acquired since RMF_AudioCapture_Open() call and will invalidate the handle. The caller will not go directly from
332 * STARTED to CLOSED state; it will call stop beforehand. RMF_AudioCapture may choose to open the interface again using RMF_AudioCapture_Open() in future.
333 *
334 * @param [in] handle - Handle of the audio capture interface.
335 *
336 * @return rmf_Error
337 * @retval RMF_ERROR General error
338 *
339 * @see RMF_AudioCapture_Start(), RMF_AudioCapture_Close(), RMF_AudioCapture_Open()
340 *
341 * @pre Must call RMF_AudioCapture_Open() before invoking this function
342 *
343 * @pre If RMF_AudioCapture_Start() was invoked, capture must be stopped by calling RMF_AudioCapture_Stop() first
344 */
346
347#ifdef __cplusplus
348}
349#endif
350
351/** @} */ // End of RMF_AudioCapture_HAL
352/** @} */ // End of RMF_AudioCapture
353/** @} */ // End of HPK
354#endif /* __RMF_AUDIO_CAPTURE_H__ */
char * RMF_AudioCaptureType
Audio source to be captured. Options are RMF_AC_TYPE_PRIMARY or RMF_AC_TYPE_AUXILIARY.
Definition rmfAudioCapture.h:76
rmf_Error RMF_AudioCapture_Close(RMF_AudioCaptureHandle handle)
Closes the audio capture interface.
rmf_Error RMF_AudioCapture_Stop(RMF_AudioCaptureHandle handle)
Stops audio capture.
rmf_Error RMF_AudioCapture_Open_Type(RMF_AudioCaptureHandle *handle, RMF_AudioCaptureType rmfAcType)
Opens the audio capture interface for specified audio source.
rmf_Error RMF_AudioCapture_Open(RMF_AudioCaptureHandle *handle)
Opens the audio capture interface for primary audio.
struct RMF_AudioCapture_Settings RMF_AudioCapture_Settings
Configuration parameters of audio capture interface.
rmf_Error RMF_AudioCapture_Start(RMF_AudioCaptureHandle handle, RMF_AudioCapture_Settings *settings)
Starts audio capture.
rmf_Error RMF_AudioCapture_GetDefaultSettings(RMF_AudioCapture_Settings *settings)
Returns friendly default values for RMF_AudioCapture_Settings.
enum RMF_AudioCapture_Freq racFreq
Audio sampling rate.
rmf_Error RMF_AudioCapture_GetStatus(RMF_AudioCaptureHandle handle, RMF_AudioCapture_Status *status)
Gets the current status of audio capture interface.
rmf_Error(* RMF_AudioCapture_StatusChangeCb)(void *cbStatusParm)
Callback for underlying implementation to signal a change in status.
Definition rmfAudioCapture.h:147
rmf_Error RMF_AudioCapture_GetCurrentSettings(RMF_AudioCaptureHandle handle, RMF_AudioCapture_Settings *settings)
Returns current values of RMF_AudioCapture_Settings in effect.
struct RMF_AudioCapture_Status RMF_AudioCapture_Status
Status of audio capture interface.
struct RMF_AudioCapture_Struct * RMF_AudioCaptureHandle
Opaque handle to an instance of RMF AudioCapture interface.
Definition rmfAudioCapture.h:74
RMF_AudioCapture_Format
Describes more specifics about the audio parameters to be used for audio samples.
Definition rmfAudioCapture.h:89
rmf_Error(* RMF_AudioCaptureBufferReadyCb)(void *cbBufferReadyParm, void *AudioCaptureBuffer, unsigned int AudioCaptureBufferSize)
Callbacks.
Definition rmfAudioCapture.h:132
RMF_AudioCapture_Freq
Audio sampling rate.
Definition rmfAudioCapture.h:102
enum RMF_AudioCapture_Format racFormat
Describes more specifics about the audio parameters to be used for audio samples.
@ racFormat_e16BitMonoLeft
Mono, 16 bits per sample interleaved into a 32-bit word. Left channel samples only.
Definition rmfAudioCapture.h:92
@ racFormat_e16BitMonoRight
Mono, 16 bits per sample interleaved into a 32-bit word. Right channel samples only.
Definition rmfAudioCapture.h:93
@ racFormat_e24BitStereo
Stereo, 24 bits per sample. The data is aligned to 32-bits left-justified. Left and right channels wi...
Definition rmfAudioCapture.h:91
@ racFormat_e16BitStereo
Stereo, 16 bits per sample interleaved into a 32-bit word.
Definition rmfAudioCapture.h:90
@ racFormat_e24Bit5_1
5.1 Multichannel, 24 bits per sample. The data is aligned to 32-bits, left-justified....
Definition rmfAudioCapture.h:95
@ racFormat_e16BitMono
Mono, 16 bits per sample interleaved into a 32-bit word. Left and Right channels mixed.
Definition rmfAudioCapture.h:94
@ racFormat_eMax
Definition rmfAudioCapture.h:96
@ racFreq_e48000
48KHz
Definition rmfAudioCapture.h:108
@ racFreq_e22050
22.05KHz
Definition rmfAudioCapture.h:104
@ racFreq_eMax
Definition rmfAudioCapture.h:109
@ racFreq_e24000
24KHz
Definition rmfAudioCapture.h:105
@ racFreq_e44100
44.1KHz
Definition rmfAudioCapture.h:107
@ racFreq_e16000
16KHz
Definition rmfAudioCapture.h:103
@ racFreq_e32000
32KHz
Definition rmfAudioCapture.h:106
Configuration parameters of audio capture interface.
Definition rmfAudioCapture.h:152
size_t fifoSize
FIFO size in bytes. This value is a total FIFO size to hold all channels of data. If not set,...
Definition rmfAudioCapture.h:159
void * cbStatusParm
Caller context data passed back in status change callback.
Definition rmfAudioCapture.h:157
racFreq samplingFreq
Sampling rate of captured audio. Not currently supported. TBD.
Definition rmfAudioCapture.h:162
RMF_AudioCapture_StatusChangeCb cbStatusChange
If cbStatusChange is not NULL, then the underlying implementation should invoke this callback when th...
Definition rmfAudioCapture.h:156
RMF_AudioCaptureBufferReadyCb cbBufferReady
Callback to send audio data to caller. Must be set in Open call.
Definition rmfAudioCapture.h:153
unsigned int delayCompensation_ms
Delay compensation in milli seconds. This parameter is used to maintain AV sync when using latency-pr...
Definition rmfAudioCapture.h:163
size_t threshold
FIFO data callback threshold in bytes. When the amount of data in the FIFO reaches this level,...
Definition rmfAudioCapture.h:160
void * cbBufferReadyParm
Caller context data passed back in buffer-ready callback; can be NULL.
Definition rmfAudioCapture.h:154
racFormat format
Format of captured data. Default is racFormat_e16BitStereThis value is ignored for compressed data,...
Definition rmfAudioCapture.h:161
Status of audio capture interface.
Definition rmfAudioCapture.h:170
float volume
Current capture volume.
Definition rmfAudioCapture.h:179
size_t fifoDepth
Number of bytes in local fifo.
Definition rmfAudioCapture.h:174
racFreq samplingFreq
Current capture sample rate.
Definition rmfAudioCapture.h:173
int paused
Indicates whether capture is paused.
Definition rmfAudioCapture.h:178
int muted
Indicates whether capture is muted.
Definition rmfAudioCapture.h:177
unsigned int overflows
Overflow count.
Definition rmfAudioCapture.h:175
int started
Indicates whether capture has started.
Definition rmfAudioCapture.h:171
unsigned int underflows
Underflow count.
Definition rmfAudioCapture.h:176
racFormat format
Current capture format (bit depth & channel)
Definition rmfAudioCapture.h:172