#define SM_ENTER_CRITICAL_SECTION_WITH_RETURN(x_mutex, x_return) \
switch (pthread_mutex_lock(x_mutex)) { \
case EINVAL: \
- LOGW("try mutex init..\n"); \
- if (0 > pthread_mutex_init(x_mutex, NULL)) { \
+ LOGW("try mutex init.."); \
+ if (pthread_mutex_init(x_mutex, NULL)) { \
return x_return; \
} else { \
+ if (pthread_mutex_lock(x_mutex)) { \
+ LOGE("mutex lock failed"); \
+ return x_return; \
+ } \
break; \
} \
return x_return; \
return x_return; \
}
+#define SM_ENTER_CRITICAL_SECTION(x_mutex) \
+switch (pthread_mutex_lock(x_mutex)) { \
+case EINVAL: \
+ LOGW("try mutex init.."); \
+ if (pthread_mutex_init(x_mutex, NULL)) { \
+ return; \
+ } else { \
+ if (pthread_mutex_lock(x_mutex)) { \
+ LOGE("mutex lock failed"); \
+ return; \
+ } \
+ break; \
+ } \
+ return; \
+case 0: \
+ break; \
+default: \
+ LOGE("mutex lock failed"); \
+ return; \
+}
+
#define SM_LEAVE_CRITICAL_SECTION(x_mutex) \
if (pthread_mutex_unlock(x_mutex)) { \
- LOGE("mutex unlock failed\n"); \
+ LOGE("mutex unlock failed"); \
}
#define SM_REF_FOR_STREAM_INFO(x_count, x_return) \
sound_stream_focus_state_changed_cb user_cb;
void *user_data;
manual_route_info_s manual_route_info;
+ pthread_mutex_t focus_cb_mutex;
} sound_stream_info_s;
typedef enum {
int sound_manager_acquire_focus(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, int sound_behavior, const char *extra_info)
{
int ret = MM_ERROR_NONE;
+ bool is_focus_cb_thread = false;
sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
LOGI(">> enter");
SM_INSTANCE_CHECK(stream_h);
+ if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
+ return _convert_sound_manager_error_code(__func__, ret);
+
if (stream_h->is_focus_unavailable) {
LOGE("acquiring focus is not allowed for this strema type(%s)", stream_h->stream_type);
return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
}
+ if (!is_focus_cb_thread)
+ SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&stream_h->focus_cb_mutex, MM_ERROR_SOUND_INTERNAL);
+
ret = mm_sound_acquire_focus_with_option(stream_h->index, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
if (ret == MM_ERROR_NONE) {
stream_h->acquired_focus |= focus_mask;
_update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
}
+ if (!is_focus_cb_thread)
+ SM_LEAVE_CRITICAL_SECTION(&stream_h->focus_cb_mutex);
+
return _convert_sound_manager_error_code(__func__, ret);
}
int sound_manager_release_focus(sound_stream_info_h stream_info, sound_stream_focus_mask_e focus_mask, int sound_behavior, const char *extra_info)
{
int ret = MM_ERROR_NONE;
+ bool is_focus_cb_thread = false;
sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
LOGI(">> enter");
SM_INSTANCE_CHECK(stream_h);
+ if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
+ return _convert_sound_manager_error_code(__func__, ret);
+
+ if (!is_focus_cb_thread)
+ SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&stream_h->focus_cb_mutex, MM_ERROR_SOUND_INTERNAL);
+
ret = mm_sound_release_focus_with_option(stream_h->index, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
if (ret == MM_ERROR_NONE) {
stream_h->acquired_focus &= ~focus_mask;
_update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
}
+ if (!is_focus_cb_thread)
+ SM_LEAVE_CRITICAL_SECTION(&stream_h->focus_cb_mutex);
+
return _convert_sound_manager_error_code(__func__, ret);
}