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.
29 #include "include/mm_sound.h"
30 #include "include/mm_sound_client.h"
31 #include "include/mm_sound_focus.h"
32 #include "focus_server/include/mm_sound_mgr_focus.h"
34 #define RETURN_ERROR_IF_FOCUS_CB_THREAD(x_thread) \
36 int ret = MM_ERROR_NONE; \
37 bool result = false; \
38 ret = mm_sound_client_is_focus_cb_thread(x_thread, &result); \
42 debug_error("it might be called in the thread of focus callback, it is not allowed\n"); \
43 return MM_ERROR_SOUND_INVALID_OPERATION; \
48 int mm_sound_focus_set_session_interrupt_callback(mm_sound_focus_session_interrupt_cb callback, void *user_data)
50 int ret = MM_ERROR_NONE;
53 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
56 return MM_ERROR_INVALID_ARGUMENT;
58 ret = mm_sound_client_set_session_interrupt_callback (callback, user_data);
66 int mm_sound_focus_unset_session_interrupt_callback(void)
68 int ret = MM_ERROR_NONE;
71 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
73 ret = mm_sound_client_unset_session_interrupt_callback ();
75 debug_error("Failed to mm_sound_client_unset_session_interrupt_callback(), ret[0x%x]\n", ret);
84 int mm_sound_focus_get_id(int *id)
86 int ret = MM_ERROR_NONE;
90 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
92 ret = mm_sound_client_get_unique_id(id);
94 debug_error("Failed to mm_sound_client_get_unique_id(), ret[0x%x]\n", ret);
103 int mm_sound_focus_is_cb_thread(bool *result)
105 int ret = MM_ERROR_NONE;
109 ret = mm_sound_client_is_focus_cb_thread(g_thread_self(), result);
112 debug_error("it might be called in the thread of focus callback, it is not allowed\n");
121 int mm_sound_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data)
123 int ret = MM_ERROR_NONE;
127 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
129 if (id < 0 || callback == NULL) {
130 debug_error("argument is not valid\n");
131 return MM_ERROR_INVALID_ARGUMENT;
134 ret = mm_sound_client_register_focus(id, getpid(), stream_type, callback, false, user_data);
136 debug_error("Could not register focus, ret[0x%x]\n", ret);
145 int mm_sound_register_focus_for_session(int id, int pid, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data)
147 int ret = MM_ERROR_NONE;
151 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
153 if (id < 0 || callback == NULL) {
154 debug_error("argument is not valid\n");
155 return MM_ERROR_INVALID_ARGUMENT;
158 ret = mm_sound_client_register_focus(id, pid, stream_type, callback, true, user_data);
160 debug_error("Could not register focus for session, ret[0x%x]\n", ret);
169 int mm_sound_unregister_focus(int id)
171 int ret = MM_ERROR_NONE;
175 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
178 debug_error("argument is not valid\n");
179 return MM_ERROR_INVALID_ARGUMENT;
182 ret = mm_sound_client_unregister_focus(id);
184 debug_error("Could not unregister focus, ret = %x\n", ret);
193 int mm_sound_set_focus_reacquisition(int id, bool reacquisition)
195 int ret = MM_ERROR_NONE;
200 debug_error("argument is not valid\n");
201 return MM_ERROR_INVALID_ARGUMENT;
204 ret = mm_sound_client_set_focus_reacquisition(id, reacquisition);
207 debug_error("Could not set focus reacquisition, ret[0x%x]\n", ret);
216 int mm_sound_get_focus_reacquisition(int id, bool *reacquisition)
218 int ret = MM_ERROR_NONE;
222 if (id < 0 || !reacquisition) {
223 debug_error("argument is not valid\n");
224 return MM_ERROR_INVALID_ARGUMENT;
227 ret = mm_sound_client_get_focus_reacquisition(id, reacquisition);
230 debug_error("Could not get focus reacquisition, ret[0x%x]\n", ret);
239 int mm_sound_get_stream_type_of_acquired_focus(int focus_type, char **stream_type, char **additional_info)
241 int ret = MM_ERROR_NONE;
245 if (stream_type == NULL) {
246 debug_error("argument is not valid\n");
247 return MM_ERROR_INVALID_ARGUMENT;
250 ret = mm_sound_client_get_acquired_focus_stream_type(focus_type, stream_type, additional_info);
253 debug_error("Could not get acquired focus stream type, ret[0x%x]\n", ret);
262 int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
264 int ret = MM_ERROR_NONE;
268 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
271 debug_error("argument is not valid\n");
272 return MM_ERROR_INVALID_ARGUMENT;
274 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
275 debug_error("argument is not valid\n");
276 return MM_ERROR_INVALID_ARGUMENT;
279 ret = mm_sound_client_acquire_focus(id, focus_type, additional_info);
281 debug_error("Could not acquire focus, ret[0x%x]\n", ret);
290 int mm_sound_release_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
292 int ret = MM_ERROR_NONE;
296 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
299 debug_error("argument is not valid\n");
300 return MM_ERROR_INVALID_ARGUMENT;
302 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
303 debug_error("argument is not valid\n");
304 return MM_ERROR_INVALID_ARGUMENT;
307 ret = mm_sound_client_release_focus(id, focus_type, additional_info);
309 debug_error("Could not release focus, ret[0x%x]\n", 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\n");
328 return MM_ERROR_INVALID_ARGUMENT;
330 ret = mm_sound_client_set_focus_watch_callback(getpid(), focus_type, callback, false, user_data, id);
332 debug_error("Could not set focus watch callback, ret[0x%x]\n", ret);
341 int mm_sound_set_focus_watch_callback_for_session(int pid, mm_sound_focus_type_e focus_type, mm_sound_focus_changed_watch_cb callback, void *user_data, int *id)
343 int ret = MM_ERROR_NONE;
347 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
349 if (callback == NULL || id == NULL) {
350 debug_error("argument is not valid\n");
351 return MM_ERROR_INVALID_ARGUMENT;
353 ret = mm_sound_client_set_focus_watch_callback(pid, focus_type, callback, true, user_data, id);
355 debug_error("Could not set focus watch callback, ret[0x%x]\n", ret);
364 int mm_sound_unset_focus_watch_callback(int id)
366 int ret = MM_ERROR_NONE;
370 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
372 ret = mm_sound_client_unset_focus_watch_callback(id);
374 debug_error("Could not unset focus watch callback, id(%d), ret = %x\n", id, ret);