2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __TIZEN_MEDIA_AUDIO_IO_H__
18 #define __TIZEN_MEDIA_AUDIO_IO_H__
21 #include <sound_manager.h>
28 #define AUDIO_IO_ERROR_CLASS TIZEN_ERROR_MULTIMEDIA_CLASS | 0x40
32 * @brief This file contains the Audio Input and Output API.
36 * @addtogroup CAPI_MEDIA_AUDIO_IN_MODULE
41 * @brief Audio input handle type.
43 typedef struct audio_in_s *audio_in_h;
50 * @addtogroup CAPI_MEDIA_AUDIO_OUT_MODULE
55 * @brief Audio output handle type.
57 typedef struct audio_out_s *audio_out_h;
64 * @addtogroup CAPI_MEDIA_AUDIO_IO_MODULE
69 * @brief Enumerations of audio sample type with bit depth
73 AUDIO_SAMPLE_TYPE_U8 = 0x70, /**< Unsigned 8-bit audio samples */
74 AUDIO_SAMPLE_TYPE_S16_LE, /**< Signed 16-bit audio samples */
75 } audio_sample_type_e;
78 * @brief Enumerations of audio channel
81 AUDIO_CHANNEL_MONO = 0x80, /**< 1 channel, mono */
82 AUDIO_CHANNEL_STEREO, /**< 2 channel, stereo */
86 * @brief Enumerations of audio input and output error code
89 AUDIO_IO_ERROR_NONE = TIZEN_ERROR_NONE, /**<Successful */
90 AUDIO_IO_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
91 AUDIO_IO_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
92 AUDIO_IO_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */
93 AUDIO_IO_ERROR_DEVICE_NOT_OPENED = AUDIO_IO_ERROR_CLASS | 0x01, /**< Device open error */
94 AUDIO_IO_ERROR_DEVICE_NOT_CLOSED = AUDIO_IO_ERROR_CLASS | 0x02, /**< Device close error */
95 AUDIO_IO_ERROR_INVALID_BUFFER = AUDIO_IO_ERROR_CLASS | 0x03, /**< Invalid buffer pointer */
96 AUDIO_IO_ERROR_SOUND_POLICY = AUDIO_IO_ERROR_CLASS | 0x04, /**< Sound policy error */
100 * @brief Enumerations of audio io interrupted type
104 AUDIO_IO_INTERRUPTED_COMPLETED = 0, /**< Interrupt completed*/
105 AUDIO_IO_INTERRUPTED_BY_MEDIA, /**< Interrupted by non-resumable media application*/
106 AUDIO_IO_INTERRUPTED_BY_CALL, /**< Interrupted by incoming call*/
107 AUDIO_IO_INTERRUPTED_BY_EARJACK_UNPLUG, /**< Interrupted by unplugging headphone*/
108 AUDIO_IO_INTERRUPTED_BY_RESOURCE_CONFLICT, /**< Interrupted by resource conflict*/
109 AUDIO_IO_INTERRUPTED_BY_ALARM, /**< Interrupted by alarm*/
110 AUDIO_IO_INTERRUPTED_BY_EMERGENCY, /**< Interrupted by emergency*/
111 AUDIO_IO_INTERRUPTED_BY_RESUMABLE_MEDIA, /**< Interrupted by resumable media application*/
112 } audio_io_interrupted_code_e;
115 * @brief Called when the audio input or output is interrupted.
116 * @param[in] error_code The interrupted error code
117 * @param[in] user_data The user data passed from the callback registration function
118 * @see audio_in_set_interrupted_cb()
119 * @see audio_out_set_interrupted_cb()
120 * @see audio_in_unset_interrupted_cb()
121 * @see audio_out_unset_interrupted_cb()
123 typedef void (*audio_io_interrupted_cb)(audio_io_interrupted_code_e code, void *user_data);
130 * @addtogroup CAPI_MEDIA_AUDIO_IN_MODULE
141 * @brief Creates an audio device instance and returns an input handle to record PCM (pulse-code modulation) data
142 * @details This function is used for audio input initialization.
144 * @remarks @a input must be release audio_in_destroy() by you.
146 * @param[in] sample_rate The audio sample rate in 8000[Hz] ~ 48000[Hz]
147 * @param[in] channel The audio channel type, mono, or stereo
148 * @param[in] type The type of audio sample (8- or 16-bit)
149 * @param[out] input An audio input handle will be created, if successful
151 * @return 0 on success, otherwise a negative error value.
152 * @retval #AUDIO_IO_ERROR_NONE Successful
153 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
154 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
155 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
156 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
157 * @see audio_in_destroy()
159 int audio_in_create(int sample_rate, audio_channel_e channel, audio_sample_type_e type , audio_in_h *input);
164 * @brief Releases the audio input handle and all its resources associated with an audio stream
166 * @param[in] input The handle to the audio input to destroy
168 * @return 0 on success, otherwise a negative error value.
169 * @retval #AUDIO_IO_ERROR_NONE Successful
170 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
171 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_CLOSED Device not closed
172 * @see audio_in_create()
174 int audio_in_destroy(audio_in_h input);
179 * @brief Prepare reading audio in by starting buffering the audio data from the device
180 * @param[in] input The handle to the audio input
181 * @return 0 on success, otherwise a negative error value.
182 * @retval #AUDIO_IO_ERROR_NONE Successful
183 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
184 * @see audio_in_unprepare()
186 int audio_in_prepare(audio_in_h input);
191 * @brief Unprepare reading audio in by stopping buffering the audio data from the device
192 * @param[in] input The handle to the audio input
193 * @return 0 on success, otherwise a negative error value.
194 * @retval #AUDIO_IO_ERROR_NONE Successful
195 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
196 * @see audio_in_prepare()
198 int audio_in_unprepare(audio_in_h input);
203 * @brief Reads audio data from the audio input buffer
205 * @param[in] input The handle to the audio input
206 * @param[out] buffer The PCM buffer address
207 * @param[in] length The length of PCM data buffer (in bytes)
209 * @return Number of read bytes on success, otherwise a negative error value.
210 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
211 * @retval #AUDIO_IO_ERROR_INVALID_BUFFER Invalid buffer pointer
212 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
213 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
214 * @pre audio_in_start_recording()
216 int audio_in_read(audio_in_h input, void *buffer, unsigned int length);
221 * @brief Gets the size to be allocated for audio input buffer
222 * @param[in] input The handle to the audio input
223 * @param[out] size The buffer size (in bytes). \n The maximum size is 1 MB.
225 * @return 0 on success, otherwise a negative error value.
226 * @retval #AUDIO_IO_ERROR_NONE Successful
227 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
228 * @see audio_in_read()
230 int audio_in_get_buffer_size(audio_in_h input, int *size);
235 * @brief Gets the sample rate of the audio input data stream
237 * @param[in] input The handle to the audio input
238 * @param[out] sample_rate The audio sample rate in Hertz (8000 ~ 48000)
240 * @return 0 on success, otherwise a negative error value.
241 * @retval #AUDIO_IO_ERROR_NONE Successful
242 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
244 int audio_in_get_sample_rate(audio_in_h input, int *sample_rate);
249 * @brief Gets the channel type of audio input data stream
251 * @details The audio channel type defines whether the audio is mono or stereo.
253 * @param[in] input The handle to the audio input
254 * @param[out] channel The audio channel type
256 * @return 0 on success, otherwise a negative error value.
257 * @retval #AUDIO_IO_ERROR_NONE Successful
258 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
260 int audio_in_get_channel(audio_in_h input, audio_channel_e *channel);
265 * @brief Gets the sample audio format (8-bit or 16-bit) of audio input data stream
267 * @param[in] input The handle to the audio input
268 * @param[out] type The audio sample type
270 * @return 0 on success, otherwise a negative error value.
271 * @retval #AUDIO_IO_ERROR_NONE Successful
272 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
274 int audio_in_get_sample_type(audio_in_h input, audio_sample_type_e *type);
278 * @brief Registers a callback function to be invoked when the audio input handle is interrupted or interrupt completed.
279 * @param[in] input The handle to the audio input
280 * @param[in] callback The callback function to register
281 * @param[in] user_data The user data to be passed to the callback function
282 * @return 0 on success, otherwise a negative error value.
283 * @retval #AUDIO_IO_ERROR_NONE Successful
284 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
285 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
286 * @post audio_io_interrupted_cb() will be invoked
287 * @see audio_in_unset_interrupted_cb()
288 * @see audio_io_interrupted_cb()
290 int audio_in_set_interrupted_cb(audio_in_h input, audio_io_interrupted_cb callback, void *user_data);
293 * @brief Unregisters the callback function.
294 * @param[in] output The handle to the audio output
295 * @return 0 on success, otherwise a negative error value.
296 * @retval #AUDIO_IO_ERROR_NONE Successful
297 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
298 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
299 * @see audio_in_set_interrupted_cb()
301 int audio_in_unset_interrupted_cb(audio_in_h input);
314 * @addtogroup CAPI_MEDIA_AUDIO_OUT_MODULE
319 * @brief Creates an audio device instance and returns an output handle to play PCM (pulse-code modulation) data
320 * @details This function is used for audio output initialization.
321 * @remarks @a output must be released audio_out_destroy() by you.
323 * @param[in] sample_rate The audio sample rate in 8000[Hz] ~ 48000[Hz]
324 * @param[in] channel The audio channel type, mono, or stereo
325 * @param[in] type The type of audio sample (8- or 16-bit)
326 * @param[in] sound_type The type of sound (#sound_type_e)
327 * @param[out] output An audio output handle will be created, if successful
329 * @return 0 on success, otherwise a negative error value.
330 * @retval #AUDIO_IO_ERROR_NONE Successful
331 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
332 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
333 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
334 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
336 * @see audio_out_destroy()
338 int audio_out_create(int sample_rate, audio_channel_e channel, audio_sample_type_e type, sound_type_e sound_type, audio_out_h *output);
343 * @brief Releases the audio output handle, along with all its resources
345 * @param[in] output The handle to the audio output to destroy
347 * @return 0 on success, otherwise a negative error value.
348 * @retval #AUDIO_IO_ERROR_NONE Successful
349 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
350 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
351 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_CLOSED Device not closed
353 * @see audio_out_create()
355 int audio_out_destroy(audio_out_h output);
358 * @brief Prepare playing audio out, this must be called before audio_out_write()
359 * @param[in] input The handle to the audio output
360 * @return 0 on success, otherwise a negative error value.
361 * @retval #AUDIO_IO_ERROR_NONE Successful
362 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
363 * @see audio_out_unprepare()
365 int audio_out_prepare(audio_out_h output);
370 * @brief Unprepare playing audio out.
371 * @param[in] input The handle to the audio output
372 * @return 0 on success, otherwise a negative error value.
373 * @retval #AUDIO_IO_ERROR_NONE Successful
374 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
375 * @see audio_out_prepare()
377 int audio_out_unprepare(audio_out_h output);
383 * @brief Starts writing the audio data to the device
385 * @param[in] output The handle to the audio output
386 * @param[in,out] buffer The PCM buffer address
387 * @param[in] length The length of PCM buffer (in bytes)
389 * @return Written data size on success, otherwise a negative error value.
390 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
391 * @retval #AUDIO_IO_ERROR_INVALID_BUFFER Invalid buffer pointer
392 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
394 int audio_out_write(audio_out_h output, void *buffer, unsigned int length);
399 * @brief Gets the size to be allocated for audio output buffer
400 * @param[in] output The handle to the audio output
401 * @param[out] size The suggested buffer size (in bytes). \n The maximum size is 1 MB.
403 * @return 0 on success, otherwise a negative error value.
404 * @retval #AUDIO_IO_ERROR_NONE Successful
405 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
406 * @see audio_out_write()
409 int audio_out_get_buffer_size(audio_out_h output, int *size);
414 * @brief Gets the sample rate of audio output data stream
416 * @param[in] output The handle to the audio output
417 * @param[out] sample_rate The audio sample rate in Hertz (8000 ~ 48000)
419 * @return 0 on success, otherwise a negative error value.
420 * @retval #AUDIO_IO_ERROR_NONE Successful
421 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
423 int audio_out_get_sample_rate(audio_out_h output, int *sample_rate);
428 * @brief Gets the channel type of audio output data stream
430 * @details The audio channel type defines whether the audio is mono or stereo.
432 * @param[in] output The handle to the audio output
433 * @param[out] channel The audio channel type
435 * @return 0 on success, otherwise a negative error value.
436 * @retval #AUDIO_IO_ERROR_NONE Successful
437 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
439 int audio_out_get_channel(audio_out_h output, audio_channel_e *channel);
444 * @brief Gets the sample audio format (8-bit or 16-bit) of audio output data stream
446 * @param[in] output The handle to the audio output
447 * @param[out] type The audio sample type
448 * @return 0 on success, otherwise a negative error value.
449 * @retval #AUDIO_IO_ERROR_NONE Successful
450 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
452 int audio_out_get_sample_type(audio_out_h output, audio_sample_type_e *type);
457 * @brief Gets the sound type supported by the audio output device
458 * @param[in] output The handle to the audio output
459 * @param[out] type The sound type
461 * @return 0 on success, otherwise a negative error value.
462 * @retval #AUDIO_IO_ERROR_NONE Successful
463 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
465 int audio_out_get_sound_type(audio_out_h output, sound_type_e *type);
469 * @brief Registers a callback function to be invoked when the audio out handle is interrupted or interrupt completed.
470 * @param[in] output The handle to the audio output
471 * @param[in] callback The callback function to register
472 * @param[in] user_data The user data to be passed to the callback function
473 * @return 0 on success, otherwise a negative error value.
474 * @retval #AUDIO_IO_ERROR_NONE Successful
475 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
476 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
477 * @post audio_io_interrupted_cb() will be invoked
478 * @see audio_out_unset_interrupted_cb()
479 * @see audio_io_interrupted_cb()
481 int audio_out_set_interrupted_cb(audio_out_h output, audio_io_interrupted_cb callback, void *user_data);
484 * @brief Unregisters the callback function.
485 * @param[in] output The handle to the audio output
486 * @return 0 on success, otherwise a negative error value.
487 * @retval #AUDIO_IO_ERROR_NONE Successful
488 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
489 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
490 * @see audio_out_set_interrupted_cb()
492 int audio_out_unset_interrupted_cb(audio_out_h output);
504 #endif /* __TIZEN_MEDIA_AUDIO_IO_H__ */