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_e;
78 * @brief Enumeration for audio channel.
79 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
82 AUDIO_CHANNEL_MONO = 0x80, /**< 1 channel, mono */
83 AUDIO_CHANNEL_STEREO, /**< 2 channel, stereo */
87 * @brief Enumeration for audio input and output state.
91 AUDIO_IO_STATE_IDLE, /**< Audio-io handle is created, but not prepared */
92 AUDIO_IO_STATE_RUNNING, /**< Audio-io handle is ready and the stream is running */
93 AUDIO_IO_STATE_PAUSED, /**< Audio-io handle is ready and the stream is paused */
97 * @brief Enumeration for audio input and output error.
98 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
101 AUDIO_IO_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
102 AUDIO_IO_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
103 AUDIO_IO_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
104 AUDIO_IO_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */
105 AUDIO_IO_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Device open error by security */
106 AUDIO_IO_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
107 AUDIO_IO_ERROR_DEVICE_NOT_OPENED = TIZEN_ERROR_AUDIO_IO | 0x01, /**< Device open error */
108 AUDIO_IO_ERROR_DEVICE_NOT_CLOSED = TIZEN_ERROR_AUDIO_IO | 0x02, /**< Device close error */
109 AUDIO_IO_ERROR_INVALID_BUFFER = TIZEN_ERROR_AUDIO_IO | 0x03, /**< Invalid buffer pointer */
110 AUDIO_IO_ERROR_SOUND_POLICY = TIZEN_ERROR_AUDIO_IO | 0x04, /**< Sound policy error */
111 AUDIO_IO_ERROR_INVALID_STATE = TIZEN_ERROR_AUDIO_IO | 0x05, /**< Invalid state (Since 3.0) */
112 AUDIO_IO_ERROR_NOT_SUPPORTED_TYPE = TIZEN_ERROR_AUDIO_IO | 0x06, /**< Not supported stream type (Since 3.0) */
116 * @deprecated Deprecated since 3.0
117 * @brief Enumeration for audio IO interrupted messages.
118 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
121 AUDIO_IO_INTERRUPTED_COMPLETED = 0, /**< Interrupt completed */
122 AUDIO_IO_INTERRUPTED_BY_MEDIA, /**< Interrupted by a media application */
123 AUDIO_IO_INTERRUPTED_BY_CALL, /**< Interrupted by an incoming call */
124 AUDIO_IO_INTERRUPTED_BY_EARJACK_UNPLUG, /**< Interrupted by unplugging headphones */
125 AUDIO_IO_INTERRUPTED_BY_RESOURCE_CONFLICT, /**< Interrupted by a resource conflict */
126 AUDIO_IO_INTERRUPTED_BY_ALARM, /**< Interrupted by an alarm */
127 AUDIO_IO_INTERRUPTED_BY_EMERGENCY, /**< Interrupted by an emergency */
128 AUDIO_IO_INTERRUPTED_BY_NOTIFICATION, /**< Interrupted by a notification */
129 } audio_io_interrupted_code_e;
132 * @deprecated Deprecated since 3.0. Use sound_stream_focus_state_changed_cb instead.
133 * @brief Called when audio input or output is interrupted.
135 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
136 * @param[in] error_code The interrupted error code
137 * @param[in] user_data The user data passed from the callback registration function
139 * @see audio_in_set_interrupted_cb()
140 * @see audio_out_set_interrupted_cb()
141 * @see audio_in_unset_interrupted_cb()
142 * @see audio_out_unset_interrupted_cb()
144 typedef void (*audio_io_interrupted_cb)(audio_io_interrupted_code_e code, void *user_data);
151 * @addtogroup CAPI_MEDIA_AUDIO_IN_MODULE
156 * @brief Called when audio input data is available in asynchronous(event) mode.
158 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
160 * @remarks @a use audio_in_peek() to get audio in data inside callback, use audio_in_drop() after use of peeked data.
162 * @param[in] handle The handle to the audio input
163 * @param[in] nbytes The amount of available audio in data which can be peeked.
164 * @param[in] user_data The user data passed from the callback registration function
166 * @see audio_in_set_stream_cb()
168 typedef void (*audio_in_stream_cb)(audio_in_h handle, size_t nbytes, void *user_data);
171 * @brief Called when the state of audio input is changed.
175 * @param[in] handle The handle of the audio input
176 * @param[in] previous The previous state of the audio input
177 * @param[in] current The current state of the audio input
178 * @param[in] by_policy @c true if the state is changed by policy, otherwise @c false if the state is not changed by policy
179 * @param[in] user_data The user data passed from the callback registration function
181 * @see audio_in_set_state_changed_cb()
182 * @see audio_in_unset_state_changed_cb()
184 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);
187 * @brief Creates an audio device instance and returns an input handle to record PCM (pulse-code modulation) data.
189 * @details This function is used for audio input initialization.
191 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
193 * @privilege %http://tizen.org/privilege/recorder
195 * @remarks @a input must be released using audio_in_destroy().
197 * @param[in] sample_rate The audio sample rate in 8000[Hz] ~ 48000[Hz]
198 * @param[in] channel The audio channel type (mono or stereo)
199 * @param[in] type The type of audio sample (8- or 16-bit)
200 * @param[out] input An audio input handle is created on success
201 * @return @c 0 on success,
202 * otherwise a negative error value
203 * @retval #AUDIO_IO_ERROR_NONE Successful
204 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
205 * @retval #AUDIO_IO_ERROR_PERMISSION_DENIED Permission denied
206 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
207 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
208 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
209 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
211 * @post The state will be #AUDIO_IO_STATE_IDLE.\n
212 * audio_in_set_stream_info() is recommended to be called after this API.
213 * @see audio_in_destroy()
215 int audio_in_create(int sample_rate, audio_channel_e channel, audio_sample_type_e type, audio_in_h *input);
218 * @deprecated Deprecated since 3.0. Use sound_manager_create_stream_information() instead.
219 * @brief Creates an audio loopback device instance and returns an input handle to record PCM (pulse-code modulation) data.
221 * @details This function is used for audio loopback input initialization.
223 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
225 * @privilege %http://tizen.org/privilege/recorder
227 * @remarks @a input must be released using audio_in_destroy().
229 * @param[in] sample_rate The audio sample rate in 8000[Hz] ~ 48000[Hz]
230 * @param[in] channel The audio channel type, mono, or stereo
231 * @param[in] type The type of audio sample (8- or 16-bit)
232 * @param[out] input An audio input handle will be created, if successful
233 * @return @c 0 on success,
234 * otherwise a negative error value
235 * @retval #AUDIO_IO_ERROR_NONE Successful
236 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
237 * @retval #AUDIO_IO_ERROR_PERMISSION_DENIED Permission denied
238 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
239 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
240 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
241 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
243 * @see audio_in_destroy()
245 int audio_in_create_loopback(int sample_rate, audio_channel_e channel, audio_sample_type_e type , audio_in_h* input);
248 * @brief Releases the audio input handle and all its resources associated with an audio stream.
250 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
252 * @param[in] input The handle to the audio input to destroy
253 * @return @c 0 on success,
254 * otherwise a negative error value
255 * @retval #AUDIO_IO_ERROR_NONE Successful
256 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
257 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_CLOSED Device not closed
258 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
260 * @see audio_in_create()
262 int audio_in_destroy(audio_in_h input);
265 * @brief Sets the sound stream information to the audio input.
269 * @remarks @a the sound stream information includes audio routing and volume type.
270 * For more details, you can refer to @ref CAPI_MEDIA_SOUND_MANAGER_MODULE
271 * System, Alarm, Notification, Emergency, Voice Information, Ringtone VOIP and Ringtone Call stream types are not supported in this API.
273 * @param[in] input The handle to the audio input
274 * @param[in] stream_info The handle of stream information
275 * @return @c 0 on success,
276 * otherwise a negative error value
277 * @retval #AUDIO_IO_ERROR_NONE Successful
278 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
279 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
280 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
281 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED_TYPE Not supported stream type
283 * @pre The state should be #AUDIO_IO_STATE_IDLE.\n
284 * Call audio_in_create() before calling this function.
285 * @post Call audio_in_prepare() after calling this function.
286 * @see sound_manager_create_stream_information()
287 * @see sound_manager_destroy_stream_information()
289 int audio_in_set_stream_info(audio_in_h input, sound_stream_info_h stream_info);
292 * @brief Prepares the audio input for reading audio data by starting buffering of audio data from the device.
294 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
296 * @param[in] input The handle to the audio input
297 * @return @c 0 on success,
298 * otherwise a negative error value
299 * @retval #AUDIO_IO_ERROR_NONE Successful
300 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
301 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
302 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
304 * @post The state will be #AUDIO_IO_STATE_RUNNING.
305 * @see audio_in_unprepare()
307 int audio_in_prepare(audio_in_h input);
310 * @brief Unprepares the audio input.
312 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
314 * @param[in] input The handle to the audio input
315 * @return @c 0 on success,
316 * otherwise a negative error value
317 * @retval #AUDIO_IO_ERROR_NONE Successful
318 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
319 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
320 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
322 * @post The state will be #AUDIO_IO_STATE_IDLE.
323 * @see audio_in_prepare()
325 int audio_in_unprepare(audio_in_h input);
328 * @brief Pauses buffering of audio data from the device.
332 * @param[in] input The handle to the audio input
333 * @return @c 0 on success,
334 * otherwise a negative error value
335 * @retval #AUDIO_IO_ERROR_NONE Successful
336 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
337 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
338 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
340 * @pre The state should be #AUDIO_IO_STATE_RUNNING.
341 * @post The state will be #AUDIO_IO_STATE_PAUSED.
342 * @see audio_in_resume()
344 int audio_in_pause(audio_in_h input);
347 * @brief Resumes buffering audio data from the device.
351 * @param[in] input The handle to the audio input
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 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
359 * @pre The state should be #AUDIO_IO_STATE_PAUSED.
360 * @post The state will be #AUDIO_IO_STATE_RUNNING.
361 * @see audio_in_pause()
363 int audio_in_resume(audio_in_h input);
366 * @brief Flushes and discards buffered audio data from the input stream.
370 * @param[in] input The handle to the audio input
371 * @return @c 0 on success,
372 * otherwise a negative error value
373 * @retval #AUDIO_IO_ERROR_NONE Successful
374 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
375 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
376 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
378 * @pre The state should be #AUDIO_IO_STATE_RUNNING or #AUDIO_IO_STATE_PAUSED.
380 int audio_in_flush(audio_in_h input);
383 * @brief Reads audio data from the audio input buffer.
385 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
387 * @param[in] input The handle to the audio input
388 * @param[out] buffer The PCM buffer address
389 * @param[in] length The length of the PCM data buffer (in bytes)
390 * @return The number of read bytes on success,
391 * otherwise a negative error value
392 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
393 * @retval #AUDIO_IO_ERROR_INVALID_BUFFER Invalid buffer pointer
394 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
395 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
396 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
398 * @pre The state should be #AUDIO_IO_STATE_RUNNING.
400 int audio_in_read(audio_in_h input, void *buffer, unsigned int length);
403 * @brief Gets the size to be allocated for the audio input buffer.
405 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
407 * @param[in] input The handle to the audio input
408 * @param[out] size The buffer size (in bytes, the maximum size is 1 MB)
409 * @return @c 0 on success,
410 * otherwise a negative error value
411 * @retval #AUDIO_IO_ERROR_NONE Successful
412 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
413 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
414 * @see audio_in_read()
416 int audio_in_get_buffer_size(audio_in_h input, int *size);
419 * @brief Gets the sample rate of the audio input data stream.
421 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
423 * @param[in] input The handle to the audio input
424 * @param[out] sample_rate The audio sample rate in Hertz (8000 ~ 48000)
425 * @return @c 0 on success,
426 * otherwise a negative error value
427 * @retval #AUDIO_IO_ERROR_NONE Successful
428 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
429 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
431 int audio_in_get_sample_rate(audio_in_h input, int *sample_rate);
434 * @brief Gets the channel type of the audio input data stream.
436 * @details The audio channel type defines whether the audio is mono or stereo.
438 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
440 * @param[in] input The handle to the audio input
441 * @param[out] channel The audio channel type
442 * @return @c 0 on success,
443 * otherwise a negative error value
444 * @retval #AUDIO_IO_ERROR_NONE Successful
445 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
446 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
448 int audio_in_get_channel(audio_in_h input, audio_channel_e *channel);
451 * @brief Gets the sample audio format (8-bit or 16-bit) of the audio input data stream.
453 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
455 * @param[in] input The handle to the audio input
456 * @param[out] type The audio sample type
457 * @return @c 0 on success,
458 * otherwise a negative error value
459 * @retval #AUDIO_IO_ERROR_NONE Successful
460 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
461 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
463 int audio_in_get_sample_type(audio_in_h input, audio_sample_type_e *type);
466 * @deprecated Deprecated since 3.0. Use sound_manager_create_stream_information() instead.
467 * @brief Registers a callback function to be invoked when the audio input handle is interrupted or the interrupt is completed.
469 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
471 * @param[in] input The handle to the audio input
472 * @param[in] callback The callback function to register
473 * @param[in] user_data The user data to be passed to the callback function
474 * @return @c 0 on success,
475 * otherwise a negative error value
476 * @retval #AUDIO_IO_ERROR_NONE Successful
477 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
478 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
479 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
480 * @post audio_io_interrupted_cb() will be invoked.
482 * @see audio_in_unset_interrupted_cb()
483 * @see audio_io_interrupted_cb()
485 int audio_in_set_interrupted_cb(audio_in_h input, audio_io_interrupted_cb callback, void *user_data);
488 * @deprecated Deprecated since 3.0
489 * @brief Unregisters the callback function.
491 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
493 * @param[in] input The handle to the audio input
494 * @return @c 0 on success,
495 * 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 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
501 * @see audio_in_set_interrupted_cb()
503 int audio_in_unset_interrupted_cb(audio_in_h input);
506 * @deprecated Deprecated since 3.0
507 * @brief Ignores session for input.
509 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
511 * @param[in] input The handle to the audio input
512 * @return @c 0 on success,
513 * otherwise a negative error value
514 * @retval #AUDIO_IO_ERROR_NONE Successful
515 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
516 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
517 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
519 int audio_in_ignore_session(audio_in_h input);
522 * @brief Sets an asynchronous(event) callback function to handle recording PCM (pulse-code modulation) data.
524 * @details @a callback will be called when you can read a PCM data.
525 * It might cause dead lock if change the state of audio handle in callback.
526 * (ex: audio_in_destroy, audio_in_prepare, audio_in_unprepare)
527 * Recommend to use as a VOIP only.
528 * Recommend not to hold callback too long.(it affects latency)
530 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
532 * @remarks @a input must be created using audio_in_create().
534 * @param[in] input An audio input handle
535 * @param[in] callback notify stream callback when user can read data (#audio_in_stream_cb)
536 * @param[in] user_data user data to be retrieved when callback is called
537 * @return @c 0 on success,
538 * otherwise a negative error value
539 * @retval #AUDIO_IO_ERROR_NONE Successful
540 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
541 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
542 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
543 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
544 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
546 * @see audio_out_set_stream_cb()
548 int audio_in_set_stream_cb(audio_in_h input, audio_in_stream_cb callback, void* user_data);
551 * @brief Unregisters the callback function.
553 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
555 * @param[in] input The handle to the audio input
556 * @return @c 0 on success,
557 * otherwise a negative error value
558 * @retval #AUDIO_IO_ERROR_NONE Successful
559 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
560 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
561 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
563 * @see audio_in_set_interrupted_cb()
565 int audio_in_unset_stream_cb(audio_in_h input);
568 * @brief peek from audio in buffer
570 * @details This function works correctly only with read, write callback. Otherwise it won't operate as intended.
572 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
574 * @remarks @a Works only in asynchronous(event) mode. This will just retrieve buffer pointer from audio in buffer. Drop after use.
576 * @param[in] input The handle to the audio input
577 * @param[out] buffer start buffer pointer of peeked audio in data
578 * @param[in,out] length amount of audio in data to be peeked
579 * @return @c 0 on success,
580 * otherwise a negative error value
581 * @retval #AUDIO_IO_ERROR_NONE Successful
582 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
583 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
584 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
585 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
587 * @pre The state should be #AUDIO_IO_STATE_RUNNING.
588 * @see audio_in_drop()
590 int audio_in_peek(audio_in_h input, const void **buffer, unsigned int *length);
593 * @brief drop peeked audio buffer.
595 * @details This function works correctly only with read, write callback. Otherwise it won't operate as intended.
597 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
599 * @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.
601 * @param[in] input The handle to the audio input
602 * @return 0 on success, otherwise a negative error value
603 * @retval #AUDIO_IO_ERROR_NONE Successful
604 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
605 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
606 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
607 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
609 * @pre The state should be #AUDIO_IO_STATE_RUNNING.
610 * @see audio_in_peek()
612 int audio_in_drop(audio_in_h input);
615 * @brief Sets the state changed callback function to the audio input handle.
619 * @remarks @a input must be created using audio_in_create().
621 * @param[in] input The audio input handle
622 * @param[in] callback the state changed callback called when the state of the handle is changed (#audio_in_state_changed_cb)
623 * @param[in] user_data user data to be retrieved when callback is called
624 * @return @c 0 on success,
625 * otherwise a negative error value
626 * @retval #AUDIO_IO_ERROR_NONE Successful
627 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
628 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
630 * @see audio_in_unset_state_changed_cb()
632 int audio_in_set_state_changed_cb(audio_in_h input, audio_in_state_changed_cb callback, void* user_data);
635 * @brief Unregisters the state changed callback function of the audio input handle.
639 * @param[in] input The handle to the audio input
640 * @return @c 0 on success,
641 * otherwise a negative error value
642 * @retval #AUDIO_IO_ERROR_NONE Successful
643 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
644 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
646 * @see audio_in_set_state_changed_cb()
648 int audio_in_unset_state_changed_cb(audio_in_h input);
655 * @addtogroup CAPI_MEDIA_AUDIO_OUT_MODULE
660 * @brief Called when audio out data can be written in asynchronous(event) mode.
662 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
664 * @remarks @a use audio_out_write() to write pcm data inside this callback.
665 * @param[in] handle The handle to the audio output
666 * @param[in] nbytes The amount of audio in data which can be written.
667 * @param[in] user_data The user data passed from the callback registration function
669 * @see audio_out_set_stream_cb()
671 typedef void (*audio_out_stream_cb)(audio_out_h handle, size_t nbytes, void *user_data);
674 * @brief Called when the state of audio output is changed.
678 * @param[in] handle The handle of the audio output
679 * @param[in] previous The previous state of the audio output
680 * @param[in] current The current state of the audio output
681 * @param[in] by_policy @c true if the state is changed by policy, otherwise @c false if the state is not changed by policy
682 * @param[in] user_data The user data passed from the callback registration function
684 * @see audio_out_set_state_changed_cb()
685 * @see audio_out_unset_state_changed_cb()
687 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);
690 * @deprecated Deprecated since 3.0. Use audio_out_create_new() instead.
691 * @brief Creates an audio device instance and returns an output handle to play PCM (pulse-code modulation) data.
693 * @details This function is used for audio output initialization.
695 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
697 * @remarks @a output must be released by audio_out_destroy().
699 * @param[in] sample_rate The audio sample rate in 8000[Hz] ~ 48000[Hz]
700 * @param[in] channel The audio channel type (mono or stereo)
701 * @param[in] type The type of audio sample (8-bit or 16-bit)
702 * @param[in] sound_type The type of sound (#sound_type_e)
703 * @param[out] output An audio output handle is created on success
704 * @return @c 0 on success,
705 * otherwise a negative error value
706 * @retval #AUDIO_IO_ERROR_NONE Successful
707 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
708 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
709 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
710 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
712 * @see audio_out_destroy()
714 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);
717 * @brief Creates an audio device instance and returns an output handle to play PCM (pulse-code modulation) data.
719 * @details This function is used for audio output initialization.
723 * @remarks @a output must be released by audio_out_destroy().
724 * It is recommended to call audio_out_set_stream_info() after this API.
726 * @param[in] sample_rate The audio sample rate in 8000[Hz] ~ 48000[Hz]
727 * @param[in] channel The audio channel type (mono or stereo)
728 * @param[in] type The type of audio sample (8-bit or 16-bit)
729 * @param[out] output An audio output handle is created on success
730 * @return @c 0 on success,
731 * otherwise a negative error value
732 * @retval #AUDIO_IO_ERROR_NONE Successful
733 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
734 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
735 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
736 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
738 * @post The state will be #AUDIO_IO_STATE_IDLE.\n
739 * audio_out_set_stream_info() is recommended to be called after this API.
740 * @see audio_out_destroy()
742 int audio_out_create_new(int sample_rate, audio_channel_e channel, audio_sample_type_e type, audio_out_h *output);
745 * @brief Releases the audio output handle, along with all its resources.
747 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
749 * @param[in] output The handle to the audio output to destroy
750 * @return @c 0 on success,
751 * otherwise a negative error value
752 * @retval #AUDIO_IO_ERROR_NONE Successful
753 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
754 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
755 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_CLOSED Device not closed
757 * @see audio_out_create()
759 int audio_out_destroy(audio_out_h output);
762 * @brief Sets the sound stream information to the audio output.
766 * @remarks @a the sound stream information includes audio routing and volume type.
767 * For more details, you can refer to @ref CAPI_MEDIA_SOUND_MANAGER_MODULE
768 * Voice Recognition and Loopback stream types are not supported in this API.
770 * @param[in] output The handle to the audio output
771 * @param[in] stream_info The handle of stream information
772 * @return @c 0 on success,
773 * otherwise a negative error value
774 * @retval #AUDIO_IO_ERROR_NONE Successful
775 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
776 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED Not supported
777 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
778 * @retval #AUDIO_IO_ERROR_NOT_SUPPORTED_TYPE Not supported stream type
780 * @pre The state should be #AUDIO_IO_STATE_IDLE.\n
781 * Call audio_out_create_new() before calling this function.
782 * @post Call audio_out_prepare() after calling this function.
783 * @see sound_manager_create_stream_information()
784 * @see sound_manager_destroy_stream_information()
786 int audio_out_set_stream_info(audio_out_h output, sound_stream_info_h stream_info);
789 * @brief Prepares the audio output for playback, this must be called before audio_out_write().
791 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
793 * @param[in] output The handle to the audio output
794 * @return @c 0 on success,
795 * otherwise a negative error value
796 * @retval #AUDIO_IO_ERROR_NONE Successful
797 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
798 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
800 * @post The state will be #AUDIO_IO_STATE_RUNNING.
801 * @see audio_out_unprepare()
803 int audio_out_prepare(audio_out_h output);
806 * @brief Unprepares the audio output.
808 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
810 * @param[in] output The handle to the audio output
811 * @return @c 0 on success,
812 * otherwise a negative error value
813 * @retval #AUDIO_IO_ERROR_NONE Successful
814 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
815 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
817 * @post The state will be #AUDIO_IO_STATE_IDLE.
818 * @see audio_out_prepare()
820 int audio_out_unprepare(audio_out_h output);
823 * @brief Pauses feeding of audio data to the device.
827 * @param[in] output The handle to the audio output
828 * @return @c 0 on success,
829 * otherwise a negative error value
830 * @retval #AUDIO_IO_ERROR_NONE Successful
831 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
832 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
834 * @pre The state should be #AUDIO_IO_STATE_RUNNING.
835 * @post The state will be #AUDIO_IO_STATE_PAUSED.
836 * @see audio_out_resume()
838 int audio_out_pause(audio_out_h output);
841 * @brief Resumes feeding of audio data to the device.
845 * @param[in] output The handle to the audio output
846 * @return @c 0 on success,
847 * otherwise a negative error value
848 * @retval #AUDIO_IO_ERROR_NONE Successful
849 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
850 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
852 * @pre The state should be #AUDIO_IO_STATE_PAUSED.
853 * @post The state will be #AUDIO_IO_STATE_RUNNING.
854 * @see audio_out_pause()
856 int audio_out_resume(audio_out_h output);
859 * @brief Drains buffered audio data from the output stream.
861 * @details This function waits until drains stream buffer completely. (e.g end of playback)
865 * @param[in] output The handle to the audio output
866 * @return @c 0 on success,
867 * otherwise a negative error value
868 * @retval #AUDIO_IO_ERROR_NONE Successful
869 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
870 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
872 * @pre The state should be #AUDIO_IO_STATE_RUNNING or #AUDIO_IO_STATE_PAUSED.
873 * @see audio_out_flush()
875 int audio_out_drain(audio_out_h output);
878 * @brief Flushes and discards buffered audio data from the output stream.
882 * @param[in] output The handle to the audio output
883 * @return @c 0 on success,
884 * otherwise a negative error value
885 * @retval #AUDIO_IO_ERROR_NONE Successful
886 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
887 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
889 * @pre The state should be #AUDIO_IO_STATE_RUNNING or #AUDIO_IO_STATE_PAUSED.
890 * @see audio_out_drain()
892 int audio_out_flush(audio_out_h output);
895 * @brief Starts writing the audio data to the device.
897 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
899 * @param[in] output The handle to the audio output
900 * @param[in,out] buffer The PCM buffer address
901 * @param[in] length The length of the PCM buffer (in bytes)
902 * @return The written data size on success,
903 * otherwise a negative error value
904 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
905 * @retval #AUDIO_IO_ERROR_INVALID_BUFFER Invalid buffer pointer
906 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
907 * @retval #AUDIO_IO_ERROR_INVALID_STATE Invalid state
909 * @pre The state should be #AUDIO_IO_STATE_RUNNING.
911 int audio_out_write(audio_out_h output, void *buffer, unsigned int length);
914 * @brief Gets the size to be allocated for the audio output buffer.
916 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
918 * @param[in] output The handle to the audio output
919 * @param[out] size The suggested buffer size (in bytes, the maximum size is 1 MB)
920 * @return @c 0 on success,
921 * otherwise a negative error value
922 * @retval #AUDIO_IO_ERROR_NONE Successful
923 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
925 * @see audio_out_write()
927 int audio_out_get_buffer_size(audio_out_h output, int *size);
930 * @brief Gets the sample rate of the audio output data stream.
932 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
934 * @param[in] output The handle to the audio output
935 * @param[out] sample_rate The audio sample rate in Hertz (8000 ~ 48000)
936 * @return @c 0 on success,
937 * otherwise a negative error value
938 * @retval #AUDIO_IO_ERROR_NONE Successful
939 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
941 int audio_out_get_sample_rate(audio_out_h output, int *sample_rate);
944 * @brief Gets the channel type of the audio output data stream.
946 * @details The audio channel type defines whether the audio is mono or stereo.
948 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
950 * @param[in] output The handle to the audio output
951 * @param[out] channel The audio channel type
952 * @return @c 0 on success,
953 * otherwise a negative error value
954 * @retval #AUDIO_IO_ERROR_NONE Successful
955 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
957 int audio_out_get_channel(audio_out_h output, audio_channel_e *channel);
960 * @brief Gets the sample audio format (8-bit or 16-bit) of the audio output data stream.
962 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
964 * @param[in] output The handle to the audio output
965 * @param[out] type The audio sample type
966 * @return @c 0 on success,
967 * otherwise a negative error value
968 * @retval #AUDIO_IO_ERROR_NONE Successful
969 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
971 int audio_out_get_sample_type(audio_out_h output, audio_sample_type_e *type);
974 * @brief Gets the sound type supported by the audio output device.
976 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
978 * @param[in] output The handle to the audio output
979 * @param[out] type The sound type
980 * @return @c 0 on success,
981 * otherwise a negative error value
982 * @retval #AUDIO_IO_ERROR_NONE Successful
983 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
985 int audio_out_get_sound_type(audio_out_h output, sound_type_e *type);
988 * @deprecated Deprecated since 3.0. Use sound_manager_create_stream_information() instead.
989 * @brief Registers a callback function to be invoked when the audio output handle is interrupted or the interrupt is completed.
991 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
993 * @param[in] output The handle to the audio output
994 * @param[in] callback The callback function to register
995 * @param[in] user_data The user data to be passed to the callback function
996 * @return @c 0 on success,
997 * otherwise a negative error value
998 * @retval #AUDIO_IO_ERROR_NONE Successful
999 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
1000 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
1002 * @post audio_io_interrupted_cb() will be invoked.
1003 * @see audio_out_unset_interrupted_cb()
1004 * @see audio_io_interrupted_cb()
1006 int audio_out_set_interrupted_cb(audio_out_h output, audio_io_interrupted_cb callback, void *user_data);
1009 * @deprecated Deprecated since 3.0
1010 * @brief Unregisters the callback function.
1012 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
1014 * @param[in] output The handle to the audio output
1015 * @return @c 0 on success,
1016 * otherwise a negative error value
1017 * @retval #AUDIO_IO_ERROR_NONE Successful
1018 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
1019 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
1021 * @see audio_out_set_interrupted_cb()
1023 int audio_out_unset_interrupted_cb(audio_out_h output);
1026 * @deprecated Deprecated since 3.0
1027 * @brief Ignores session for output.
1029 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
1031 * @param[in] output The handle to the audio output
1032 * @return @c 0 on success,
1033 * otherwise a negative error value
1034 * @retval #AUDIO_IO_ERROR_NONE Successful
1035 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
1036 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
1038 int audio_out_ignore_session(audio_out_h output);
1041 * @brief Sets an asynchronous(event) callback function to handle playing PCM (pulse-code modulation) data.
1043 * @details @a callback will be called when you can write a PCM data.
1044 * It might cause dead lock if change the state of audio handle in callback.
1045 * (ex: audio_out_destroy, audio_out_prepare, audio_out_unprepare)
1046 * Recommend to use as a VOIP only.
1047 * Recommend not to hold callback too long.(it affects latency)
1049 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
1051 * @remarks @a output must be created using audio_out_create().
1053 * @param[in] output An audio output handle
1054 * @param[in] callback notify stream callback when user can write data (#audio_out_stream_cb)
1055 * @param[in] user_data user data to be retrieved when callback is called
1056 * @return 0 on success, otherwise a negative error value
1057 * @retval #AUDIO_IO_ERROR_NONE Successful
1058 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
1059 * @retval #AUDIO_IO_ERROR_OUT_OF_MEMORY Out of memory
1060 * @retval #AUDIO_IO_ERROR_DEVICE_NOT_OPENED Device not opened
1061 * @retval #AUDIO_IO_ERROR_SOUND_POLICY Sound policy error
1063 * @see audio_out_unset_stream_cb()
1065 int audio_out_set_stream_cb(audio_out_h output, audio_out_stream_cb callback, void* user_data);
1068 * @brief Unregisters the callback function.
1070 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
1072 * @param[in] output The handle to the audio output
1073 * @return 0 on success, otherwise a negative error value
1074 * @retval #AUDIO_IO_ERROR_NONE Successful
1075 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
1076 * @retval #AUDIO_IO_ERROR_INVALID_OPERATION Invalid operation
1078 * @see audio_out_set_stream_cb()
1080 int audio_out_unset_stream_cb(audio_out_h output);
1083 * @brief Sets the state changed callback function to the audio output handle.
1087 * @remarks @a input must be created using audio_out_create_new().
1089 * @param[in] output The audio output handle
1090 * @param[in] callback the state changed callback called when the state of the handle is changed (#audio_out_state_changed_cb)
1091 * @param[in] user_data user data to be retrieved when callback is called
1092 * @return @c 0 on success,
1093 * otherwise a negative error value
1094 * @retval #AUDIO_IO_ERROR_NONE Successful
1095 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
1097 * @see audio_out_unset_state_changed_cb()
1099 int audio_out_set_state_changed_cb(audio_out_h output, audio_out_state_changed_cb callback, void* user_data);
1102 * @brief Unregisters the state changed callback function of the audio output handle.
1106 * @param[in] output The handle to the audio output
1107 * @return @c 0 on success,
1108 * otherwise a negative error value
1109 * @retval #AUDIO_IO_ERROR_NONE Successful
1110 * @retval #AUDIO_IO_ERROR_INVALID_PARAMETER Invalid parameter
1112 * @see audio_out_set_state_changed_cb()
1114 int audio_out_unset_state_changed_cb(audio_out_h output);
1124 #endif /* __TIZEN_MEDIA_AUDIO_IO_H__ */