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] input The handle to the audio input
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);
304 * @brief Ignore session for input
305 * @param[in] input The handle to the audio input
306 * @return 0 on success, otherwise a negative error value.
307 * @retval #AUDIO_IO_ERROR_NONE Successful
308 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
309 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
312 int audio_in_ignore_session(audio_in_h input);
323 * @addtogroup CAPI_MEDIA_AUDIO_OUT_MODULE
328 * @brief Creates an audio device instance and returns an output handle to play PCM (pulse-code modulation) data
329 * @details This function is used for audio output initialization.
330 * @remarks @a output must be released audio_out_destroy() by you.
332 * @param[in] sample_rate The audio sample rate in 8000[Hz] ~ 48000[Hz]
333 * @param[in] channel The audio channel type, mono, or stereo
334 * @param[in] type The type of audio sample (8- or 16-bit)
335 * @param[in] sound_type The type of sound (#sound_type_e)
336 * @param[out] output An audio output handle will be created, if successful
338 * @return 0 on success, otherwise a negative error value.
339 * @retval #AUDIO_IO_ERROR_NONE Successful
340 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
341 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
342 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
343 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
345 * @see audio_out_destroy()
347 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);
352 * @brief Releases the audio output handle, along with all its resources
354 * @param[in] output The handle to the audio output to destroy
356 * @return 0 on success, otherwise a negative error value.
357 * @retval #AUDIO_IO_ERROR_NONE Successful
358 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
359 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
360 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_CLOSED Device not closed
362 * @see audio_out_create()
364 int audio_out_destroy(audio_out_h output);
367 * @brief Prepare playing audio out, this must be called before audio_out_write()
368 * @param[in] output The handle to the audio output
369 * @return 0 on success, otherwise a negative error value.
370 * @retval #AUDIO_IO_ERROR_NONE Successful
371 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
372 * @see audio_out_unprepare()
374 int audio_out_prepare(audio_out_h output);
379 * @brief Unprepare playing audio out.
380 * @param[in] output The handle to the audio output
381 * @return 0 on success, otherwise a negative error value.
382 * @retval #AUDIO_IO_ERROR_NONE Successful
383 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
384 * @see audio_out_prepare()
386 int audio_out_unprepare(audio_out_h output);
392 * @brief Starts writing the audio data to the device
394 * @param[in] output The handle to the audio output
395 * @param[in,out] buffer The PCM buffer address
396 * @param[in] length The length of PCM buffer (in bytes)
398 * @return Written data size on success, otherwise a negative error value.
399 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
400 * @retval #AUDIO_IO_ERROR_INVALID_BUFFER Invalid buffer pointer
401 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
403 int audio_out_write(audio_out_h output, void *buffer, unsigned int length);
408 * @brief Gets the size to be allocated for audio output buffer
409 * @param[in] output The handle to the audio output
410 * @param[out] size The suggested buffer size (in bytes). \n The maximum size is 1 MB.
412 * @return 0 on success, otherwise a negative error value.
413 * @retval #AUDIO_IO_ERROR_NONE Successful
414 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
415 * @see audio_out_write()
418 int audio_out_get_buffer_size(audio_out_h output, int *size);
423 * @brief Gets the sample rate of audio output data stream
425 * @param[in] output The handle to the audio output
426 * @param[out] sample_rate The audio sample rate in Hertz (8000 ~ 48000)
428 * @return 0 on success, otherwise a negative error value.
429 * @retval #AUDIO_IO_ERROR_NONE Successful
430 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
432 int audio_out_get_sample_rate(audio_out_h output, int *sample_rate);
437 * @brief Gets the channel type of audio output data stream
439 * @details The audio channel type defines whether the audio is mono or stereo.
441 * @param[in] output The handle to the audio output
442 * @param[out] channel The audio channel type
444 * @return 0 on success, otherwise a negative error value.
445 * @retval #AUDIO_IO_ERROR_NONE Successful
446 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
448 int audio_out_get_channel(audio_out_h output, audio_channel_e *channel);
453 * @brief Gets the sample audio format (8-bit or 16-bit) of audio output data stream
455 * @param[in] output The handle to the audio output
456 * @param[out] type The audio sample type
457 * @return 0 on success, otherwise a negative error value.
458 * @retval #AUDIO_IO_ERROR_NONE Successful
459 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
461 int audio_out_get_sample_type(audio_out_h output, audio_sample_type_e *type);
466 * @brief Gets the sound type supported by the audio output device
467 * @param[in] output The handle to the audio output
468 * @param[out] type The sound type
470 * @return 0 on success, otherwise a negative error value.
471 * @retval #AUDIO_IO_ERROR_NONE Successful
472 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
474 int audio_out_get_sound_type(audio_out_h output, sound_type_e *type);
478 * @brief Registers a callback function to be invoked when the audio out handle is interrupted or interrupt completed.
479 * @param[in] output The handle to the audio output
480 * @param[in] callback The callback function to register
481 * @param[in] user_data The user data to be passed to the callback function
482 * @return 0 on success, otherwise a negative error value.
483 * @retval #AUDIO_IO_ERROR_NONE Successful
484 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
485 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
486 * @post audio_io_interrupted_cb() will be invoked
487 * @see audio_out_unset_interrupted_cb()
488 * @see audio_io_interrupted_cb()
490 int audio_out_set_interrupted_cb(audio_out_h output, audio_io_interrupted_cb callback, void *user_data);
493 * @brief Unregisters the callback function.
494 * @param[in] output The handle to the audio output
495 * @return 0 on success, otherwise a negative error value.
496 * @retval #AUDIO_IO_ERROR_NONE Successful
497 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
498 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
499 * @see audio_out_set_interrupted_cb()
501 int audio_out_unset_interrupted_cb(audio_out_h output);
504 * @brief Ignore session for output
505 * @param[in] output The handle to the audio output
506 * @return 0 on success, otherwise a negative error value.
507 * @retval #AUDIO_IO_ERROR_NONE Successful
508 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
509 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
512 int audio_out_ignore_session(audio_out_h output);
523 #endif /* __TIZEN_MEDIA_AUDIO_IO_H__ */