SM_INSTANCE_CHECK(stream_h);
SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&g_stream_info_count_mutex, MM_ERROR_SOUND_INTERNAL);
+ SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&stream_h->focus_state_mutex, MM_ERROR_SOUND_INTERNAL);
ret = _destroy_pa_connection_and_unregister_focus(stream_h);
+ SM_LEAVE_CRITICAL_SECTION(&stream_h->focus_state_mutex);
if (ret == MM_ERROR_NONE) {
SM_SAFE_FREE(stream_h);
SM_UNREF_FOR_STREAM_INFO(g_stream_info_count);
return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
}
+ SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&stream_h->focus_state_mutex, MM_ERROR_SOUND_INTERNAL);
+
if (stream_h->acquired_focus & focus_mask) {
LOGE("invalid state: focus_mask[0x%x], acquired_focus[0x%x]", focus_mask, stream_h->acquired_focus);
- return _convert_sound_manager_error_code(__func__, MM_ERROR_SOUND_INVALID_STATE);
+ ret = MM_ERROR_SOUND_INVALID_STATE;
+ goto LEAVE;
}
if (is_focus_cb_thread && ((stream_h->prev_acquired_focus | ~stream_h->acquired_focus) & SOUND_STREAM_FOCUS_FOR_BOTH) != focus_mask) {
LOGE("just lost focus in this callback, it is not allowed to acquire the focus[0x%x] again. acquired_focus[0x%x], prev[0x%x]",
focus_mask, stream_h->acquired_focus, stream_h->prev_acquired_focus);
- return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
+ ret = MM_ERROR_POLICY_INTERNAL;
+ goto LEAVE;
}
ret = mm_sound_acquire_focus_with_option(stream_h->index, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
LOGI("acquired_focus[0x%x], prev[0x%x]", stream_h->acquired_focus, stream_h->prev_acquired_focus);
+LEAVE:
+ SM_LEAVE_CRITICAL_SECTION(&stream_h->focus_state_mutex);
+
return _convert_sound_manager_error_code(__func__, ret);
}
if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
return _convert_sound_manager_error_code(__func__, ret);
+ SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&stream_h->focus_state_mutex, MM_ERROR_SOUND_INTERNAL);
+
if (!(stream_h->acquired_focus & focus_mask)) {
LOGE("invalid state: focus_mask[0x%x], acquired_focus[0x%x]", focus_mask, stream_h->acquired_focus);
- return _convert_sound_manager_error_code(__func__, MM_ERROR_SOUND_INVALID_STATE);
+ ret = MM_ERROR_SOUND_INVALID_STATE;
+ goto LEAVE;
}
if (is_focus_cb_thread && ((stream_h->prev_acquired_focus & stream_h->acquired_focus) != focus_mask)) {
LOGE("just acquired focus in this callback, it is not allowed to release the focus[0x%x] again. acquired_focus[0x%x], prev[0x%x]",
focus_mask, stream_h->acquired_focus, stream_h->prev_acquired_focus);
- return _convert_sound_manager_error_code(__func__, MM_ERROR_SOUND_INVALID_STATE);
+ ret = MM_ERROR_SOUND_INVALID_STATE;
+ goto LEAVE;
}
ret = mm_sound_release_focus_with_option(stream_h->index, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
LOGI("acquired_focus[0x%x], prev[0x%x]", stream_h->acquired_focus, stream_h->prev_acquired_focus);
+LEAVE:
+ SM_LEAVE_CRITICAL_SECTION(&stream_h->focus_state_mutex);
+
return _convert_sound_manager_error_code(__func__, ret);
}
return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
}
+ SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&stream_h->focus_state_mutex, MM_ERROR_SOUND_INTERNAL);
+
if (is_focus_cb_thread && (stream_h->prev_acquired_focus > stream_h->acquired_focus)) {
LOGE("just lost focus in this callback, it is not allowed to acquire all again. acquired_focus[0x%x], prev[0x%x]",
stream_h->acquired_focus, stream_h->prev_acquired_focus);
- return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
+ ret = MM_ERROR_POLICY_INTERNAL;
+ goto LEAVE;
}
focus_mask = SOUND_STREAM_FOCUS_FOR_BOTH & ~(stream_h->acquired_focus);
if (!focus_mask) {
LOGI("PLAYBACK/RECORDING focuses have already been ACQUIRED");
- return SOUND_MANAGER_ERROR_NONE;
+ ret = MM_ERROR_NONE;
+ goto LEAVE;
}
ret = mm_sound_acquire_focus_with_option(stream_h->index, (mm_sound_focus_type_e)focus_mask, sound_behavior, extra_info);
_update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
}
+LEAVE:
+ SM_LEAVE_CRITICAL_SECTION(&stream_h->focus_state_mutex);
+
return _convert_sound_manager_error_code(__func__, ret);
}
if ((ret = mm_sound_focus_is_cb_thread(&is_focus_cb_thread)))
return _convert_sound_manager_error_code(__func__, ret);
+ SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&stream_h->focus_state_mutex, MM_ERROR_SOUND_INTERNAL);
+
if (is_focus_cb_thread && (stream_h->prev_acquired_focus < stream_h->acquired_focus)) {
LOGE("just acquired focus in this callback, it is not allowed to release all again. acquired_focus[0x%x], prev[0x%x]",
stream_h->acquired_focus, stream_h->prev_acquired_focus);
- return _convert_sound_manager_error_code(__func__, MM_ERROR_POLICY_INTERNAL);
+ ret = MM_ERROR_POLICY_INTERNAL;
+ goto LEAVE;
}
if (!stream_h->acquired_focus) {
LOGI("PLAYBACK/RECORDING focuses have already been RELEASED");
- return SOUND_MANAGER_ERROR_NONE;
+ ret = MM_ERROR_NONE;
+ goto LEAVE;
}
ret = mm_sound_release_focus_with_option(stream_h->index, (mm_sound_focus_type_e)stream_h->acquired_focus, sound_behavior, extra_info);
_update_focus_status(stream_h->index, (unsigned int)stream_h->acquired_focus);
}
+LEAVE:
+ SM_LEAVE_CRITICAL_SECTION(&stream_h->focus_state_mutex);
+
return _convert_sound_manager_error_code(__func__, ret);
}
LOGI(">> enter");
SM_INSTANCE_CHECK(stream_h);
- if (!state_for_playback && !state_for_recording) {
- ret = MM_ERROR_INVALID_ARGUMENT;
- goto LEAVE;
- }
+ if (!state_for_playback && !state_for_recording)
+ return SOUND_MANAGER_ERROR_INVALID_PARAMETER;
+
+ SM_ENTER_CRITICAL_SECTION_WITH_RETURN(&stream_h->focus_state_mutex, MM_ERROR_SOUND_INTERNAL);
if (state_for_playback)
*state_for_playback = ((stream_h->acquired_focus & SOUND_STREAM_FOCUS_FOR_PLAYBACK) ? (SOUND_STREAM_FOCUS_STATE_ACQUIRED) : (SOUND_STREAM_FOCUS_STATE_RELEASED));
LOGI("acquired_focus(0x%x)", stream_h->acquired_focus);
-LEAVE:
+ SM_LEAVE_CRITICAL_SECTION(&stream_h->focus_state_mutex);
+
return _convert_sound_manager_error_code(__func__, ret);
}