typedef struct {
int is_registered;
+ unsigned int subs_id; /* for internal device connected subscription */
void *user_data;
sound_session_interrupted_cb user_cb;
}_session_interrupt_info_s;
sound_device_information_changed_cb user_cb;
}_device_changed_info_s;
+void _focus_session_interrupt_cb (mm_sound_focus_state_e state, const char *reason_for_change, bool is_wcb, void *user_data);
+
+void _device_connected_cb(sound_device_h device, bool is_connected, void *user_data);
+
void _focus_state_change_callback (int index, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info, void *user_data);
void _focus_watch_callback (int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason_for_change, const char *additional_info, void *user_data);
Name: capi-media-sound-manager
Summary: Sound Manager library
-Version: 0.3.16
+Version: 0.3.17
Release: 0
Group: Multimedia/API
License: Apache-2.0
#define TMP_CODE
-_session_interrupt_info_s g_session_interrupt_cb_table = {0, NULL, NULL};
+_session_interrupt_info_s g_session_interrupt_cb_table = {0, 0, NULL, NULL};
_volume_changed_info_s g_volume_changed_cb_table = {0, NULL, NULL};
_focus_watch_info_s g_focus_watch_cb_table = {-1, NULL, NULL};
_device_connected_info_s g_device_connected_cb_table = {0, NULL, NULL};
/* These variables will be removed when session features are deprecated. */
extern int g_stream_info_count;
extern pthread_mutex_t g_stream_info_count_mutex;
-pthread_mutex_t g_device_info_cb_mutex, g_device_conn_cb_mutex, g_volume_cb_mutex;
+pthread_mutex_t g_interrupt_cb_mutex, g_device_info_cb_mutex, g_device_conn_cb_mutex, g_volume_cb_mutex;
#ifdef TMP_CODE
/*temporary variable for set/get voip session mode. When 2.4 feature for routing is fully implemented, it will be removed.*/
int sound_manager_set_session_interrupted_cb (sound_session_interrupted_cb callback, void *user_data)
{
int ret = MM_ERROR_NONE;
- if (callback == NULL)
- return __convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
+ unsigned int subs_id = 0;
+
+ SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_interrupt_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
+
+ if (callback == NULL) {
+ ret = MM_ERROR_INVALID_ARGUMENT;
+ goto finish;
+ }
/* it is not supported both session and stream feature at the same time */
- if (g_stream_info_count)
- return __convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
+ if (g_stream_info_count) {
+ ret = MM_ERROR_POLICY_INTERNAL;
+ goto finish;
+ }
if (g_session_interrupt_cb_table.is_registered == 0) {
- ret = mm_session_init_ex(SOUND_SESSION_TYPE_DEFAULT /*default*/ , __session_interrupt_cb, NULL);
- if (ret != 0)
- return __convert_sound_manager_error_code(__func__, ret);
+ ret = mm_sound_add_device_connected_callback(SOUND_DEVICE_ALL_MASK, (mm_sound_device_connected_cb)_device_connected_cb, NULL, &subs_id);
+ if (ret)
+ goto finish;
+ ret = mm_sound_focus_set_session_interrupt_callback((mm_sound_focus_session_interrupt_cb)_focus_session_interrupt_cb, NULL);
+ if (ret) {
+ if(mm_sound_remove_device_connected_callback(subs_id) != MM_ERROR_NONE)
+ LOGW("mm_sound_remove_device_connected_callback failed");
+ goto finish;
+ }
g_session_interrupt_cb_table.is_registered = 1;
+ g_session_interrupt_cb_table.subs_id = subs_id;
}
g_session_interrupt_cb_table.user_cb = (sound_session_interrupted_cb)callback;
g_session_interrupt_cb_table.user_data = user_data;
- return SOUND_MANAGER_ERROR_NONE;
+
+finish:
+ SM_LEAVE_CRITICAL_SECTION(&g_interrupt_cb_mutex);
+ return __convert_sound_manager_error_code(__func__, ret);
}
int sound_manager_unset_session_interrupted_cb (void)
{
int ret = MM_ERROR_NONE;
+
+ SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_interrupt_cb_mutex, SOUND_MANAGER_ERROR_INTERNAL);
+
if (g_session_interrupt_cb_table.user_cb) {
+ ret = mm_sound_focus_unset_session_interrupt_callback();
+ if (ret) {
+ if(mm_sound_remove_device_connected_callback(g_session_interrupt_cb_table.subs_id) != MM_ERROR_NONE)
+ LOGW("mm_sound_remove_device_connected_callback failed");
+ goto finish;
+ }
+ ret = mm_sound_remove_device_connected_callback(g_session_interrupt_cb_table.subs_id);
+ if (ret)
+ goto finish;
+ g_session_interrupt_cb_table.subs_id = 0;
g_session_interrupt_cb_table.user_cb = NULL;
g_session_interrupt_cb_table.user_data = NULL;
+ g_session_interrupt_cb_table.is_registered = 0;
} else {
ret = MM_ERROR_SOUND_INTERNAL;
}
+
+finish:
+ SM_LEAVE_CRITICAL_SECTION(&g_interrupt_cb_mutex);
return __convert_sound_manager_error_code(__func__, ret);
}
return ret;
}
+static int __convert_stream_type_to_interrupt_reason (const char *stream_type, sound_session_interrupted_code_e *change_reason)
+{
+ int ret = MM_ERROR_NONE;
+
+ SM_NULL_ARG_CHECK(stream_type);
+ SM_NULL_ARG_CHECK(change_reason);
+
+ if (!strncmp(stream_type, "media", SOUND_STREAM_TYPE_LEN) ||
+ !strncmp(stream_type, "radio", SOUND_STREAM_TYPE_LEN) ||
+ !strncmp(stream_type, "system", SOUND_STREAM_TYPE_LEN) ||
+ !strncmp(stream_type, "voice-information", SOUND_STREAM_TYPE_LEN) ||
+ !strncmp(stream_type, "voice-recognition", SOUND_STREAM_TYPE_LEN) ||
+ !strncmp(stream_type, "loopback", SOUND_STREAM_TYPE_LEN)) {
+ *change_reason = SOUND_SESSION_INTERRUPTED_BY_MEDIA;
+
+ } else if (!strncmp(stream_type, "alarm", SOUND_STREAM_TYPE_LEN)) {
+ *change_reason = SOUND_SESSION_INTERRUPTED_BY_ALARM;
+
+ } else if (!strncmp(stream_type, "notification", SOUND_STREAM_TYPE_LEN)) {
+ *change_reason = SOUND_SESSION_INTERRUPTED_BY_NOTIFICATION;
+
+ } else if (!strncmp(stream_type, "emergency", SOUND_STREAM_TYPE_LEN)) {
+ *change_reason = SOUND_SESSION_INTERRUPTED_BY_EMERGENCY;
+
+ } else if (!strncmp(stream_type, "ringtone-voip", SOUND_STREAM_TYPE_LEN) ||
+ !strncmp(stream_type, "ringtone-call", SOUND_STREAM_TYPE_LEN) ||
+ !strncmp(stream_type, "voip", SOUND_STREAM_TYPE_LEN) ||
+ !strncmp(stream_type, "call-voice", SOUND_STREAM_TYPE_LEN) ||
+ !strncmp(stream_type, "call-video", SOUND_STREAM_TYPE_LEN)) {
+ *change_reason = SOUND_SESSION_INTERRUPTED_BY_CALL;
+
+ } else {
+ ret = MM_ERROR_INVALID_ARGUMENT;
+ LOGE("not supported stream_type(%s), err(0x%08x)", stream_type, ret);
+ }
+ return ret;
+}
+
int __convert_sound_type (sound_type_e sound_type, const char **volume_type)
{
int ret = MM_ERROR_NONE;
}
}
+void _focus_session_interrupt_cb (mm_sound_focus_state_e state, const char *reason_for_change, bool is_wcb, void *user_data)
+{
+ sound_session_interrupted_code_e e;
+ LOGE("session interrupted by [%s]", reason_for_change);
+ if (g_session_interrupt_cb_table.user_cb) {
+ if (is_wcb) {
+ if (state == FOCUS_IS_RELEASED) {
+ e = SOUND_SESSION_INTERRUPTED_COMPLETED;
+ } else {
+ __convert_stream_type_to_interrupt_reason(reason_for_change, &e);
+ }
+ } else {
+ if (state == FOCUS_IS_ACQUIRED) {
+ e = SOUND_SESSION_INTERRUPTED_COMPLETED;
+ } else {
+ __convert_stream_type_to_interrupt_reason(reason_for_change, &e);
+ }
+ }
+ g_session_interrupt_cb_table.user_cb(e, g_session_interrupt_cb_table.user_data);
+ }
+}
+
+void _device_connected_cb(sound_device_h device, bool is_connected, void *user_data)
+{
+ sound_device_type_e type;
+ if (sound_manager_get_device_type (device, &type) != MM_ERROR_NONE) {
+ LOGE("getting device type failed");
+ } else {
+ switch (type) {
+ case SOUND_DEVICE_AUDIO_JACK:
+ case SOUND_DEVICE_BLUETOOTH:
+ case SOUND_DEVICE_HDMI:
+ case SOUND_DEVICE_MIRRORING:
+ case SOUND_DEVICE_USB_AUDIO:
+ if (!is_connected) {
+ LOGI("sound device unplugged");
+ g_session_interrupt_cb_table.user_cb(SOUND_SESSION_INTERRUPTED_BY_EARJACK_UNPLUG, g_session_interrupt_cb_table.user_data);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+}
+
int __set_session_mode (_session_mode_e mode)
{
int ret = MM_ERROR_NONE;