4 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Sangchul Lee <sc11.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #include "include/mm_sound.h"
27 #include "include/mm_sound_client.h"
29 #define RETURN_ERROR_IF_FOCUS_CB_THREAD(x_thread) \
31 int ret = MM_ERROR_NONE; \
32 bool result = false; \
33 ret = mm_sound_client_is_focus_cb_thread(x_thread, &result, NULL); \
37 debug_error("it might be called in the thread of focus callback, it is not allowed"); \
38 return MM_ERROR_SOUND_INVALID_OPERATION; \
43 int mm_sound_focus_is_cb_thread(bool *result, bool *is_for_watching)
45 int ret = MM_ERROR_NONE;
50 debug_error("argument is not valid");
51 return MM_ERROR_INVALID_ARGUMENT;
54 ret = mm_sound_client_is_focus_cb_thread(g_thread_self(), result, is_for_watching);
57 debug_msg("it might be called in the thread of focus callback");
58 if (is_for_watching && *is_for_watching)
59 debug_msg("it's in the focus watch callback");
68 int mm_sound_register_focus(const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data, int *id)
70 int ret = MM_ERROR_NONE;
74 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
76 if (id == NULL || callback == NULL) {
77 debug_error("argument is not valid");
78 return MM_ERROR_INVALID_ARGUMENT;
81 ret = mm_sound_client_register_focus(getpid(), stream_type, callback, user_data, id);
83 debug_error("Could not register focus, ret[0x%x]", ret);
91 int mm_sound_unregister_focus(int id)
93 int ret = MM_ERROR_NONE;
99 debug_error("argument is not valid");
100 return MM_ERROR_INVALID_ARGUMENT;
103 mm_sound_client_is_focus_cb_thread(g_thread_self(), &result, NULL);
105 if ((ret = mm_sound_client_unregister_focus(id)))
106 debug_error("Could not unregister focus, ret = %x", ret);
108 ret = mm_sound_client_execute_focus_func_in_main_context(IDLE_EVENT_TYPE_UNREGISTER_FOCUS, id);
117 int mm_sound_set_focus_reacquisition(int id, bool reacquisition)
119 int ret = MM_ERROR_NONE;
124 debug_error("argument is not valid");
125 return MM_ERROR_INVALID_ARGUMENT;
128 if ((ret = mm_sound_client_set_focus_reacquisition(id, reacquisition)))
129 debug_error("Could not set focus reacquisition, ret[0x%x]", ret);
137 int mm_sound_get_focus_reacquisition(int id, bool *reacquisition)
139 int ret = MM_ERROR_NONE;
143 if (id < 0 || !reacquisition) {
144 debug_error("argument is not valid");
145 return MM_ERROR_INVALID_ARGUMENT;
148 ret = mm_sound_client_get_focus_reacquisition(id, reacquisition);
150 debug_error("Could not get focus reacquisition, ret[0x%x]", ret);
158 int mm_sound_get_stream_type_of_acquired_focus(int focus_type, char **stream_type, int *option, char **ext_info)
160 int ret = MM_ERROR_NONE;
164 if (stream_type == NULL) {
165 debug_error("argument is not valid");
166 return MM_ERROR_INVALID_ARGUMENT;
169 ret = mm_sound_client_get_acquired_focus_stream_type(focus_type, stream_type, option, ext_info);
171 debug_error("Could not get acquired focus stream type, ret[0x%x]", ret);
179 int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char *ext_info)
181 int ret = MM_ERROR_NONE;
185 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
188 debug_error("argument is not valid");
189 return MM_ERROR_INVALID_ARGUMENT;
191 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
192 debug_error("argument is not valid");
193 return MM_ERROR_INVALID_ARGUMENT;
196 ret = mm_sound_client_acquire_focus(id, focus_type, 0, ext_info);
198 debug_error("Could not acquire focus, ret[0x%x]", ret);
206 int mm_sound_release_focus(int id, mm_sound_focus_type_e focus_type, const char *ext_info)
208 int ret = MM_ERROR_NONE;
212 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
215 debug_error("argument is not valid");
216 return MM_ERROR_INVALID_ARGUMENT;
218 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
219 debug_error("argument is not valid");
220 return MM_ERROR_INVALID_ARGUMENT;
223 ret = mm_sound_client_release_focus(id, focus_type, 0, ext_info);
225 debug_error("Could not release focus, ret[0x%x]", ret);
233 int mm_sound_acquire_focus_with_option(int id, mm_sound_focus_type_e focus_type, int option, const char *ext_info)
235 int ret = MM_ERROR_NONE;
240 debug_error("id is not valid");
241 return MM_ERROR_INVALID_ARGUMENT;
245 debug_error("option is not valid");
246 return MM_ERROR_INVALID_ARGUMENT;
249 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
250 debug_error("focus type is not valid");
251 return MM_ERROR_INVALID_ARGUMENT;
254 ret = mm_sound_client_acquire_focus(id, focus_type, option, ext_info);
256 debug_error("Could not acquire focus, ret[0x%x]", ret);
264 int mm_sound_release_focus_with_option(int id, mm_sound_focus_type_e focus_type, int option, const char *ext_info)
266 int ret = MM_ERROR_NONE;
271 debug_error("id is not valid");
272 return MM_ERROR_INVALID_ARGUMENT;
276 debug_error("option is not valid");
277 return MM_ERROR_INVALID_ARGUMENT;
280 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
281 debug_error("focus type is not valid");
282 return MM_ERROR_INVALID_ARGUMENT;
285 ret = mm_sound_client_release_focus(id, focus_type, option, ext_info);
287 debug_error("Could not release focus, ret[0x%x]", ret);
295 int mm_sound_update_focus_status(int id, unsigned int status)
297 int ret = MM_ERROR_NONE;
299 if ((ret = mm_sound_client_update_stream_focus_status(id, status)))
300 debug_error("failed to mm_sound_client_update_stream_focus_status(), id(%d), status(%d, ret[0x%x]",
307 int mm_sound_deliver_focus(int src_id, int dst_id, mm_sound_focus_type_e focus_type)
309 int ret = MM_ERROR_NONE;
311 if ((ret = mm_sound_client_deliver_focus(src_id, dst_id, focus_type)))
312 debug_error("failed to mm_sound_client_deliver_focus(), ret[0x%x]", ret);
318 int mm_sound_set_focus_watch_callback(mm_sound_focus_type_e focus_type, mm_sound_focus_changed_watch_cb callback, void *user_data, int *id)
320 int ret = MM_ERROR_NONE;
324 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
326 if (callback == NULL || id == NULL) {
327 debug_error("argument is not valid");
328 return MM_ERROR_INVALID_ARGUMENT;
330 ret = mm_sound_client_set_focus_watch_callback(getpid(), focus_type, callback, user_data, id);
332 debug_error("Could not set focus watch callback, ret[0x%x]", ret);
340 int mm_sound_unset_focus_watch_callback(int id)
342 int ret = MM_ERROR_NONE;
348 debug_error("argument is not valid");
349 return MM_ERROR_INVALID_ARGUMENT;
352 if ((ret = mm_sound_client_request_unset_focus_watch_callback(id))) {
353 debug_error("failed to mm_sound_client_request_unset_focus_watch_callback, ret[0x%x]", ret);
357 mm_sound_client_is_focus_cb_thread(g_thread_self(), &result, NULL);
359 if ((ret = mm_sound_client_unset_focus_watch_callback(id)))
360 debug_error("Could not unset focus watch callback, id(%d), ret[0x%x]", id, ret);
362 ret = mm_sound_client_execute_focus_func_in_main_context(IDLE_EVENT_TYPE_UNSET_FOCUS_WATCH_CB, id);
363 debug_msg("mm_sound_client_execute_focus_func_in_main_context() is called, id(%d), ret[0x%x]", id, ret);