2 * Copyright (c) 2015 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__
20 #include <sys/types.h>
22 #include <sound_manager.h>
30 * @brief This file contains the Audio Input and Audio Output API.
34 * @addtogroup CAPI_MEDIA_AUDIO_IN_MODULE
39 * @brief The audio input handle.
40 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
42 typedef struct audio_io_s *audio_in_h;
49 * @addtogroup CAPI_MEDIA_AUDIO_OUT_MODULE
54 * @brief The audio output handle.
55 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
57 typedef struct audio_io_s *audio_out_h;
64 * @addtogroup CAPI_MEDIA_AUDIO_IO_MODULE
69 * @brief Enumeration for audio sample type with bit depth.
70 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
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_S24_LE, /**< Signed 24-bit audio samples (Since 5.0) */
76 AUDIO_SAMPLE_TYPE_S24_32_LE, /**< Signed 24-bit (packed in 32-bit) audio samples (Since 5.0) */
77 } audio_sample_type_e;
80 * @brief Enumeration for audio channel.
81 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
84 AUDIO_CHANNEL_MONO = 0x80, /**< 1 channel, mono */
85 AUDIO_CHANNEL_STEREO, /**< 2 channel, stereo */
89 * @brief Enumeration for audio input and output state.
93 AUDIO_IO_STATE_IDLE, /**< Audio-io handle is created, but not prepared */
94 AUDIO_IO_STATE_RUNNING, /**< Audio-io handle is ready and the stream is running */
95 AUDIO_IO_STATE_PAUSED, /**< Audio-io handle is ready and the stream is paused */
99 * @brief Enumeration for audio input and output error.
100 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
103 AUDIO_IO_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
104 AUDIO_IO_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
105 AUDIO_IO_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
106 AUDIO_IO_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */
107 AUDIO_IO_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Device open error by security */
108 AUDIO_IO_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
109 AUDIO_IO_ERROR_DEVICE_POLICY_RESTRICTION = TIZEN_ERROR_DEVICE_POLICY_RESTRICTION, /**< Device policy restriction (Since 3.0) */
110 AUDIO_IO_ERROR_DEVICE_NOT_OPENED = TIZEN_ERROR_AUDIO_IO | 0x01, /**< Device open error */
111 AUDIO_IO_ERROR_DEVICE_NOT_CLOSED = TIZEN_ERROR_AUDIO_IO | 0x02, /**< Device close error */
112 AUDIO_IO_ERROR_INVALID_BUFFER = TIZEN_ERROR_AUDIO_IO | 0x03, /**< Invalid buffer pointer */
113 AUDIO_IO_ERROR_SOUND_POLICY = TIZEN_ERROR_AUDIO_IO | 0x04, /**< Sound policy error */
114 AUDIO_IO_ERROR_INVALID_STATE = TIZEN_ERROR_AUDIO_IO | 0x05, /**< Invalid state (Since 3.0) */
115 AUDIO_IO_ERROR_NOT_SUPPORTED_TYPE = TIZEN_ERROR_AUDIO_IO | 0x06, /**< Not supported stream type (Since 3.0) */
123 * @addtogroup CAPI_MEDIA_AUDIO_IN_MODULE
128 * @brief Called when audio input data is available in asynchronous(event) mode.
130 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
132 * @remarks @a use audio_in_peek() to get audio in data inside callback, use audio_in_drop() after use of peeked data.
134 * @param[in] handle The handle to the audio input
135 * @param[in] nbytes The amount of available audio in data which can be peeked.
136 * @param[in] user_data The user data passed from the callback registration function
138 * @see audio_in_set_stream_cb()
140 typedef void (*audio_in_stream_cb)(audio_in_h handle, size_t nbytes, void *user_data);
143 * @brief Called when the state of audio input is changed.
147 * @param[in] handle The handle of the audio input
148 * @param[in] previous The previous state of the audio input
149 * @param[in] current The current state of the audio input
150 * @param[in] by_policy @c true if the state is changed by policy, otherwise @c false if the state is not changed by policy
151 * @param[in] user_data The user data passed from the callback registration function
153 * @see audio_in_set_state_changed_cb()
154 * @see audio_in_unset_state_changed_cb()
156 typedef void (*audio_in_state_changed_cb)(audio_in_h handle, audio_io_state_e previous, audio_io_state_e current, bool by_policy, void *user_data);
159 * @brief Creates an audio device instance and returns an input handle to record PCM (pulse-code modulation) data.
161 * @details This function is used for audio input initialization.
163 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
165 * @privilege %http://tizen.org/privilege/recorder
167 * @remarks @a input must be released using audio_in_destroy().
169 * @param[in] sample_rate The audio sample rate in 8000[Hz] ~ 48000[Hz] (Before 5.0), 8000[Hz] ~ 192000[Hz] (Since 5.0)
170 * @param[in] channel The audio channel type (mono or stereo)
171 * @param[in] type The type of audio sample (8- or 16-bit)
172 * @param[out] input An audio input handle is created on success
173 * @return @c 0 on success,
174 * otherwise a negative error value
175 * @retval #AUDIO_IO_ERROR_NONE Successful
176 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
177 * @retval #AUDIO_IO_ERROR_PERMISSION_DENIED Permission denied
178 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
179 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
180 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
181 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
183 * @post The state will be #AUDIO_IO_STATE_IDLE.\n
184 * audio_in_set_sound_stream_info() is recommended to be called after this API.
185 * @see audio_in_destroy()
187 int audio_in_create(int sample_rate, audio_channel_e channel, audio_sample_type_e type, audio_in_h *input);
190 * @brief Releases the audio input handle and all its resources associated with an audio stream.
192 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
194 * @param[in] input The handle to the audio input to destroy
195 * @return @c 0 on success,
196 * otherwise a negative error value
197 * @retval #AUDIO_IO_ERROR_NONE Successful
198 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
199 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_CLOSED Device not closed
200 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
202 * @see audio_in_create()
204 int audio_in_destroy(audio_in_h input);
207 * @brief Sets the sound stream information to the audio input.
211 * @remarks @a the sound stream information includes audio routing and volume type.
212 * For more details, you can refer to @ref CAPI_MEDIA_SOUND_MANAGER_MODULE
213 * System, Alarm, Notification, Emergency, Voice Information, Ringtone VOIP and Ringtone Call stream types are not supported in this API.
215 * @param[in] input The handle to the audio input
216 * @param[in] stream_info The handle of stream information
217 * @return @c 0 on success,
218 * otherwise a negative error value
219 * @retval #AUDIO_IO_ERROR_NONE Successful
220 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
221 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
222 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
223 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED_TYPE Not supported stream type
225 * @pre The state should be #AUDIO_IO_STATE_IDLE.\n
226 * Call audio_in_create() before calling this function.
227 * @post Call audio_in_prepare() after calling this function.
228 * @see sound_manager_create_stream_information()
229 * @see sound_manager_destroy_stream_information()
231 int audio_in_set_sound_stream_info(audio_in_h input, sound_stream_info_h stream_info);
234 * @brief Prepares the audio input for reading audio data by starting buffering of audio data from the device.
236 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
238 * @param[in] input The handle to the audio input
239 * @return @c 0 on success,
240 * otherwise a negative error value
241 * @retval #AUDIO_IO_ERROR_NONE Successful
242 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
243 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
244 * @retval #AUDIO_IO_ERROR_DEVICE_POLICY_RESTRICTION Device policy restriction
245 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
247 * @post The state will be #AUDIO_IO_STATE_RUNNING.
248 * @see audio_in_unprepare()
250 int audio_in_prepare(audio_in_h input);
253 * @brief Unprepares the audio input.
255 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
257 * @param[in] input The handle to the audio input
258 * @return @c 0 on success,
259 * otherwise a negative error value
260 * @retval #AUDIO_IO_ERROR_NONE Successful
261 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
262 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
263 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
265 * @post The state will be #AUDIO_IO_STATE_IDLE.
266 * @see audio_in_prepare()
268 int audio_in_unprepare(audio_in_h input);
271 * @brief Pauses buffering of audio data from the device.
275 * @param[in] input The handle to the audio input
276 * @return @c 0 on success,
277 * otherwise a negative error value
278 * @retval #AUDIO_IO_ERROR_NONE Successful
279 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
280 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
281 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
283 * @pre The state should be #AUDIO_IO_STATE_RUNNING.
284 * @post The state will be #AUDIO_IO_STATE_PAUSED.
285 * @see audio_in_resume()
287 int audio_in_pause(audio_in_h input);
290 * @brief Resumes buffering audio data from the device.
294 * @param[in] input The handle to the audio input
295 * @return @c 0 on success,
296 * otherwise a negative error value
297 * @retval #AUDIO_IO_ERROR_NONE Successful
298 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
299 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
300 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
302 * @pre The state should be #AUDIO_IO_STATE_PAUSED.
303 * @post The state will be #AUDIO_IO_STATE_RUNNING.
304 * @see audio_in_pause()
306 int audio_in_resume(audio_in_h input);
309 * @brief Flushes and discards buffered audio data from the input stream.
311 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
313 * @param[in] input The handle to the audio input
314 * @return @c 0 on success,
315 * otherwise a negative error value
316 * @retval #AUDIO_IO_ERROR_NONE Successful
317 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
318 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
319 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
321 * @pre The state should be #AUDIO_IO_STATE_RUNNING or #AUDIO_IO_STATE_PAUSED.
323 int audio_in_flush(audio_in_h input);
326 * @brief Reads audio data from the audio input buffer.
328 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
330 * @param[in] input The handle to the audio input
331 * @param[out] buffer The PCM buffer address
332 * @param[in] length The length of the PCM data buffer (in bytes)
333 * @return The number of read bytes on success,
334 * otherwise a negative error value
335 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
336 * @retval #AUDIO_IO_ERROR_INVALID_BUFFER Invalid buffer pointer
337 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
338 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
339 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
341 * @pre The state should be #AUDIO_IO_STATE_RUNNING.
343 int audio_in_read(audio_in_h input, void *buffer, unsigned int length);
346 * @brief Gets the size to be allocated for the audio input buffer.
348 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
350 * @param[in] input The handle to the audio input
351 * @param[out] size The buffer size (in bytes, the maximum size is 1 MB)
352 * @return @c 0 on success,
353 * otherwise a negative error value
354 * @retval #AUDIO_IO_ERROR_NONE Successful
355 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
356 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
357 * @see audio_in_read()
359 int audio_in_get_buffer_size(audio_in_h input, int *size);
362 * @brief Gets the sample rate of the audio input data stream.
364 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
366 * @param[in] input The handle to the audio input
367 * @param[out] sample_rate The audio sample rate in Hertz (8000 ~ 48000) (Before 5.0), (8000 ~ 192000) (Since 5.0)
368 * @return @c 0 on success,
369 * otherwise a negative error value
370 * @retval #AUDIO_IO_ERROR_NONE Successful
371 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
372 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
374 int audio_in_get_sample_rate(audio_in_h input, int *sample_rate);
377 * @brief Gets the channel type of the audio input data stream.
379 * @details The audio channel type defines whether the audio is mono or stereo.
381 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
383 * @param[in] input The handle to the audio input
384 * @param[out] channel The audio channel type
385 * @return @c 0 on success,
386 * otherwise a negative error value
387 * @retval #AUDIO_IO_ERROR_NONE Successful
388 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
389 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
391 int audio_in_get_channel(audio_in_h input, audio_channel_e *channel);
394 * @brief Gets the sample audio format (8-bit or 16-bit) of the audio input data stream.
396 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
398 * @param[in] input The handle to the audio input
399 * @param[out] type The audio sample type
400 * @return @c 0 on success,
401 * otherwise a negative error value
402 * @retval #AUDIO_IO_ERROR_NONE Successful
403 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
404 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
406 int audio_in_get_sample_type(audio_in_h input, audio_sample_type_e *type);
409 * @brief Sets an asynchronous(event) callback function to handle recording PCM (pulse-code modulation) data.
411 * @details @a callback will be called when you can read a PCM data.
412 * It might cause dead lock if change the state of audio handle in callback.
413 * (ex: audio_in_destroy, audio_in_prepare, audio_in_unprepare)
414 * Recommend to use as a VOIP only.
415 * Recommend not to hold callback too long.(it affects latency)
417 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
419 * @remarks @a input must be created using audio_in_create().
421 * @param[in] input An audio input handle
422 * @param[in] callback notify stream callback when user can read data (#audio_in_stream_cb)
423 * @param[in] user_data user data to be retrieved when callback is called
424 * @return @c 0 on success,
425 * otherwise a negative error value
426 * @retval #AUDIO_IO_ERROR_NONE Successful
427 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
428 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
429 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
430 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
431 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
433 * @see audio_in_unset_stream_cb()
435 int audio_in_set_stream_cb(audio_in_h input, audio_in_stream_cb callback, void* user_data);
438 * @brief Unregisters the callback function.
440 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
442 * @param[in] input The handle to the audio input
443 * @return @c 0 on success,
444 * otherwise a negative error value
445 * @retval #AUDIO_IO_ERROR_NONE Successful
446 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
447 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
448 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
450 * @see audio_in_set_stream_cb()
452 int audio_in_unset_stream_cb(audio_in_h input);
455 * @brief peek from audio in buffer
457 * @details This function works correctly only with read, write callback. Otherwise it won't operate as intended.
459 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
461 * @remarks @a Works only in asynchronous(event) mode. This will just retrieve buffer pointer from audio in buffer. Drop after use.
463 * @param[in] input The handle to the audio input
464 * @param[out] buffer start buffer pointer of peeked audio in data
465 * @param[out] length amount of audio in data to be peeked
466 * @return @c 0 on success,
467 * otherwise a negative error value
468 * @retval #AUDIO_IO_ERROR_NONE Successful
469 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
470 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
471 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
472 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
474 * @pre The state should be #AUDIO_IO_STATE_RUNNING.
475 * @see audio_in_drop()
477 int audio_in_peek(audio_in_h input, const void **buffer, unsigned int *length);
480 * @brief drop peeked audio buffer.
482 * @details This function works correctly only with read, write callback. Otherwise it won't operate as intended.
484 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
486 * @remarks @a Works only in asynchronous(event) mode. This will remove audio in data from actual stream buffer. Use this if peeked data is not needed anymore.
488 * @param[in] input The handle to the audio input
489 * @return 0 on success, otherwise a negative error value
490 * @retval #AUDIO_IO_ERROR_NONE Successful
491 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
492 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
493 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
494 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
496 * @pre The state should be #AUDIO_IO_STATE_RUNNING.
497 * @see audio_in_peek()
499 int audio_in_drop(audio_in_h input);
502 * @brief Sets the state changed callback function to the audio input handle.
506 * @remarks @a input must be created using audio_in_create().
508 * @param[in] input The audio input handle
509 * @param[in] callback the state changed callback called when the state of the handle is changed (#audio_in_state_changed_cb)
510 * @param[in] user_data user data to be retrieved when callback is called
511 * @return @c 0 on success,
512 * otherwise a negative error value
513 * @retval #AUDIO_IO_ERROR_NONE Successful
514 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
515 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
517 * @see audio_in_unset_state_changed_cb()
519 int audio_in_set_state_changed_cb(audio_in_h input, audio_in_state_changed_cb callback, void* user_data);
522 * @brief Unregisters the state changed callback function of the audio input handle.
526 * @param[in] input The handle to the audio input
527 * @return @c 0 on success,
528 * otherwise a negative error value
529 * @retval #AUDIO_IO_ERROR_NONE Successful
530 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
531 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
533 * @see audio_in_set_state_changed_cb()
535 int audio_in_unset_state_changed_cb(audio_in_h input);
542 * @addtogroup CAPI_MEDIA_AUDIO_OUT_MODULE
547 * @brief Called when audio out data can be written in asynchronous(event) mode.
549 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
551 * @remarks @a use audio_out_write() to write pcm data inside this callback.
552 * @param[in] handle The handle to the audio output
553 * @param[in] nbytes The amount of audio in data which can be written.
554 * @param[in] user_data The user data passed from the callback registration function
556 * @see audio_out_set_stream_cb()
558 typedef void (*audio_out_stream_cb)(audio_out_h handle, size_t nbytes, void *user_data);
561 * @brief Called when the state of audio output is changed.
565 * @param[in] handle The handle of the audio output
566 * @param[in] previous The previous state of the audio output
567 * @param[in] current The current state of the audio output
568 * @param[in] by_policy @c true if the state is changed by policy, otherwise @c false if the state is not changed by policy
569 * @param[in] user_data The user data passed from the callback registration function
571 * @see audio_out_set_state_changed_cb()
572 * @see audio_out_unset_state_changed_cb()
574 typedef void (*audio_out_state_changed_cb)(audio_out_h handle, audio_io_state_e previous, audio_io_state_e current, bool by_policy, void *user_data);
577 * @brief Creates an audio device instance and returns an output handle to play PCM (pulse-code modulation) data.
579 * @details This function is used for audio output initialization.
583 * @remarks @a output must be released by audio_out_destroy().
584 * It is recommended to call audio_out_set_sound_stream_info() after this API.
586 * @param[in] sample_rate The audio sample rate in 8000[Hz] ~ 48000[Hz] (Before 5.0), 8000[Hz] ~ 192000[Hz] (Since 5.0)
587 * @param[in] channel The audio channel type (mono or stereo)
588 * @param[in] type The type of audio sample (8-bit or 16-bit)
589 * @param[out] output An audio output handle is created on success
590 * @return @c 0 on success,
591 * otherwise a negative error value
592 * @retval #AUDIO_IO_ERROR_NONE Successful
593 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
594 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
595 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
596 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
598 * @post The state will be #AUDIO_IO_STATE_IDLE.\n
599 * audio_out_set_sound_stream_info() is recommended to be called after this API.
600 * @see audio_out_destroy()
602 int audio_out_create_new(int sample_rate, audio_channel_e channel, audio_sample_type_e type, audio_out_h *output);
605 * @brief Releases the audio output handle, along with all its resources.
607 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
609 * @param[in] output The handle to the audio output to destroy
610 * @return @c 0 on success,
611 * otherwise a negative error value
612 * @retval #AUDIO_IO_ERROR_NONE Successful
613 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
614 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
615 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_CLOSED Device not closed
617 * @see audio_out_create_new()
619 int audio_out_destroy(audio_out_h output);
622 * @brief Sets the sound stream information to the audio output.
626 * @remarks @a the sound stream information includes audio routing and volume type.
627 * For more details, you can refer to @ref CAPI_MEDIA_SOUND_MANAGER_MODULE
628 * Voice Recognition and Loopback stream types are not supported in this API.
630 * @param[in] output The handle to the audio output
631 * @param[in] stream_info The handle of stream information
632 * @return @c 0 on success,
633 * otherwise a negative error value
634 * @retval #AUDIO_IO_ERROR_NONE Successful
635 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
636 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
637 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
638 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED_TYPE Not supported stream type
640 * @pre The state should be #AUDIO_IO_STATE_IDLE.\n
641 * Call audio_out_create_new() before calling this function.
642 * @post Call audio_out_prepare() after calling this function.
643 * @see sound_manager_create_stream_information()
644 * @see sound_manager_destroy_stream_information()
646 int audio_out_set_sound_stream_info(audio_out_h output, sound_stream_info_h stream_info);
649 * @brief Prepares the audio output for playback, this must be called before audio_out_write().
651 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
653 * @param[in] output The handle to the audio output
654 * @return @c 0 on success,
655 * otherwise a negative error value
656 * @retval #AUDIO_IO_ERROR_NONE Successful
657 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
658 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
660 * @post The state will be #AUDIO_IO_STATE_RUNNING.
661 * @see audio_out_unprepare()
663 int audio_out_prepare(audio_out_h output);
666 * @brief Unprepares the audio output.
668 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
670 * @param[in] output The handle to the audio output
671 * @return @c 0 on success,
672 * otherwise a negative error value
673 * @retval #AUDIO_IO_ERROR_NONE Successful
674 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
675 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
677 * @post The state will be #AUDIO_IO_STATE_IDLE.
678 * @see audio_out_prepare()
680 int audio_out_unprepare(audio_out_h output);
683 * @brief Pauses feeding of audio data to the device.
687 * @param[in] output The handle to the audio output
688 * @return @c 0 on success,
689 * otherwise a negative error value
690 * @retval #AUDIO_IO_ERROR_NONE Successful
691 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
692 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
694 * @pre The state should be #AUDIO_IO_STATE_RUNNING.
695 * @post The state will be #AUDIO_IO_STATE_PAUSED.
696 * @see audio_out_resume()
698 int audio_out_pause(audio_out_h output);
701 * @brief Resumes feeding of audio data to the device.
705 * @param[in] output The handle to the audio output
706 * @return @c 0 on success,
707 * otherwise a negative error value
708 * @retval #AUDIO_IO_ERROR_NONE Successful
709 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
710 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
712 * @pre The state should be #AUDIO_IO_STATE_PAUSED.
713 * @post The state will be #AUDIO_IO_STATE_RUNNING.
714 * @see audio_out_pause()
716 int audio_out_resume(audio_out_h output);
719 * @brief Drains buffered audio data from the output stream.
721 * @details This function waits until drains stream buffer completely. (e.g end of playback)
723 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
725 * @param[in] output The handle to the audio output
726 * @return @c 0 on success,
727 * otherwise a negative error value
728 * @retval #AUDIO_IO_ERROR_NONE Successful
729 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
730 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
732 * @pre The state should be #AUDIO_IO_STATE_RUNNING or #AUDIO_IO_STATE_PAUSED.
733 * @see audio_out_flush()
735 int audio_out_drain(audio_out_h output);
738 * @brief Flushes and discards buffered audio data from the output stream.
740 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
742 * @param[in] output The handle to the audio output
743 * @return @c 0 on success,
744 * otherwise a negative error value
745 * @retval #AUDIO_IO_ERROR_NONE Successful
746 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
747 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
749 * @pre The state should be #AUDIO_IO_STATE_RUNNING or #AUDIO_IO_STATE_PAUSED.
750 * @see audio_out_drain()
752 int audio_out_flush(audio_out_h output);
755 * @brief Starts writing the audio data to the device.
757 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
759 * @param[in] output The handle to the audio output
760 * @param[in,out] buffer The PCM buffer address
761 * @param[in] length The length of the PCM buffer (in bytes)
762 * @return The written data size on success,
763 * otherwise a negative error value
764 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
765 * @retval #AUDIO_IO_ERROR_INVALID_BUFFER Invalid buffer pointer
766 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
767 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
769 * @pre The state should be #AUDIO_IO_STATE_RUNNING.
771 int audio_out_write(audio_out_h output, void *buffer, unsigned int length);
774 * @brief Gets the size to be allocated for the audio output buffer.
776 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
778 * @param[in] output The handle to the audio output
779 * @param[out] size The suggested buffer size (in bytes, the maximum size is 1 MB)
780 * @return @c 0 on success,
781 * otherwise a negative error value
782 * @retval #AUDIO_IO_ERROR_NONE Successful
783 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
785 * @see audio_out_write()
787 int audio_out_get_buffer_size(audio_out_h output, int *size);
790 * @brief Gets the sample rate of the audio output data stream.
792 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
794 * @param[in] output The handle to the audio output
795 * @param[out] sample_rate The audio sample rate in Hertz (8000 ~ 48000) (Before 5.0), (8000 ~ 192000) (Since 5.0)
796 * @return @c 0 on success,
797 * otherwise a negative error value
798 * @retval #AUDIO_IO_ERROR_NONE Successful
799 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
801 int audio_out_get_sample_rate(audio_out_h output, int *sample_rate);
804 * @brief Gets the channel type of the audio output data stream.
806 * @details The audio channel type defines whether the audio is mono or stereo.
808 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
810 * @param[in] output The handle to the audio output
811 * @param[out] channel The audio channel type
812 * @return @c 0 on success,
813 * otherwise a negative error value
814 * @retval #AUDIO_IO_ERROR_NONE Successful
815 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
817 int audio_out_get_channel(audio_out_h output, audio_channel_e *channel);
820 * @brief Gets the sample audio format (8-bit or 16-bit) of the audio output data stream.
822 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
824 * @param[in] output The handle to the audio output
825 * @param[out] type The audio sample type
826 * @return @c 0 on success,
827 * otherwise a negative error value
828 * @retval #AUDIO_IO_ERROR_NONE Successful
829 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
831 int audio_out_get_sample_type(audio_out_h output, audio_sample_type_e *type);
834 * @brief Gets the sound type supported by the audio output device.
836 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
838 * @param[in] output The handle to the audio output
839 * @param[out] type The sound type
840 * @return @c 0 on success,
841 * otherwise a negative error value
842 * @retval #AUDIO_IO_ERROR_NONE Successful
843 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
845 int audio_out_get_sound_type(audio_out_h output, sound_type_e *type);
848 * @brief Sets an asynchronous(event) callback function to handle playing PCM (pulse-code modulation) data.
850 * @details @a callback will be called when you can write a PCM data.
851 * It might cause dead lock if change the state of audio handle in callback.
852 * (ex: audio_out_destroy, audio_out_prepare, audio_out_unprepare)
853 * Recommend to use as a VOIP only.
854 * Recommend not to hold callback too long.(it affects latency)
856 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
858 * @remarks @a output must be created using audio_out_create_new().
860 * @param[in] output An audio output handle
861 * @param[in] callback notify stream callback when user can write data (#audio_out_stream_cb)
862 * @param[in] user_data user data to be retrieved when callback is called
863 * @return 0 on success, otherwise a negative error value
864 * @retval #AUDIO_IO_ERROR_NONE Successful
865 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
866 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
867 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
868 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
870 * @see audio_out_unset_stream_cb()
872 int audio_out_set_stream_cb(audio_out_h output, audio_out_stream_cb callback, void* user_data);
875 * @brief Unregisters the callback function.
877 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
879 * @param[in] output The handle to the audio output
880 * @return 0 on success, otherwise a negative error value
881 * @retval #AUDIO_IO_ERROR_NONE Successful
882 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
883 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
885 * @see audio_out_set_stream_cb()
887 int audio_out_unset_stream_cb(audio_out_h output);
890 * @brief Sets the state changed callback function to the audio output handle.
894 * @remarks @a input must be created using audio_out_create_new().
896 * @param[in] output The audio output handle
897 * @param[in] callback the state changed callback called when the state of the handle is changed (#audio_out_state_changed_cb)
898 * @param[in] user_data user data to be retrieved when callback is called
899 * @return @c 0 on success,
900 * otherwise a negative error value
901 * @retval #AUDIO_IO_ERROR_NONE Successful
902 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
904 * @see audio_out_unset_state_changed_cb()
906 int audio_out_set_state_changed_cb(audio_out_h output, audio_out_state_changed_cb callback, void* user_data);
909 * @brief Unregisters the state changed callback function of the audio output handle.
913 * @param[in] output The handle to the audio output
914 * @return @c 0 on success,
915 * otherwise a negative error value
916 * @retval #AUDIO_IO_ERROR_NONE Successful
917 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
919 * @see audio_out_set_state_changed_cb()
921 int audio_out_unset_state_changed_cb(audio_out_h output);
931 #endif /* __TIZEN_MEDIA_AUDIO_IO_H__ */