+ AUDIO_IO_NULL_ARG_CHECK(input);
+
+ int ret = AUDIO_IO_ERROR_NONE;
+ int source_type = SUPPORT_SOURCE_TYPE_DEFAULT;
+ audio_in_s* handle = (audio_in_s*)input;
+
+ // at first, release existing audio handle
+ if (handle->is_async) {
+ ret = mm_sound_pcm_capture_close_async(handle->mm_handle);
+ } else {
+ ret = mm_sound_pcm_capture_close(handle->mm_handle);
+ }
+
+ if (ret != MM_ERROR_NONE) {
+ return __convert_audio_io_error_code(ret, (char*)__FUNCTION__);
+ }
+
+ // Initialize flags
+ handle->stream_cb = NULL;
+ handle->stream_userdata = NULL;
+ handle->is_async = 0;
+
+ // Checks loopback type
+ if (handle->is_loopback == 1) {
+ source_type = SUPPORT_SOURCE_TYPE_LOOPBACK;
+ }
+
+ /* Async (callback exists) or Sync (otherwise) */
+ if (callback != NULL) {
+ handle->stream_cb = callback;
+ handle->stream_userdata = userdata;
+ handle->is_async = 1;
+
+ /* Capture open */
+ if ((ret = mm_sound_pcm_capture_open_async(&handle->mm_handle, handle->_sample_rate, handle->_channel, handle->_type, source_type,
+ (mm_sound_pcm_stream_cb_t)__audio_in_stream_cb, handle)) < 0) {
+ LOGE("mm_sound_pcm_capture_open_async() failed [0x%x]", ret);
+ return __convert_audio_io_error_code(ret, (char*)__FUNCTION__);
+ }
+ LOGI("mm_sound_pcm_capture_open_async() success");
+ } else {
+ /* Capture open */
+ if ((ret = mm_sound_pcm_capture_open_ex(&handle->mm_handle, handle->_sample_rate, handle->_channel, handle->_type, source_type)) < 0) {
+ LOGE("mm_sound_pcm_capture_open_ex() failed [0x%x]", ret);
+ return __convert_audio_io_error_code(ret, (char*)__FUNCTION__);
+ }
+ LOGI("mm_sound_pcm_capture_open_ex() success");
+ }
+
+ handle->_buffer_size = ret; /* return by pcm_open */