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); \
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)
45 int ret = MM_ERROR_NONE;
49 ret = mm_sound_client_is_focus_cb_thread(g_thread_self(), result);
52 debug_msg("it might be called in the thread of focus callback");
61 int mm_sound_register_focus(const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data, int *id)
63 int ret = MM_ERROR_NONE;
67 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
69 if (id == NULL || callback == NULL) {
70 debug_error("argument is not valid");
71 return MM_ERROR_INVALID_ARGUMENT;
74 ret = mm_sound_client_register_focus(getpid(), stream_type, callback, user_data, id);
76 debug_error("Could not register focus, ret[0x%x]", ret);
84 int mm_sound_unregister_focus(int id)
86 int ret = MM_ERROR_NONE;
92 debug_error("argument is not valid");
93 return MM_ERROR_INVALID_ARGUMENT;
96 mm_sound_client_is_focus_cb_thread(g_thread_self(), &result);
98 if ((ret = mm_sound_client_unregister_focus(id)))
99 debug_error("Could not unregister focus, ret = %x", ret);
101 ret = mm_sound_client_execute_focus_func_in_main_context(IDLE_EVENT_TYPE_UNREGISTER_FOCUS, id);
110 int mm_sound_set_focus_reacquisition(int id, bool reacquisition)
112 int ret = MM_ERROR_NONE;
117 debug_error("argument is not valid");
118 return MM_ERROR_INVALID_ARGUMENT;
121 if ((ret = mm_sound_client_set_focus_reacquisition(id, reacquisition)))
122 debug_error("Could not set focus reacquisition, ret[0x%x]", ret);
130 int mm_sound_get_focus_reacquisition(int id, bool *reacquisition)
132 int ret = MM_ERROR_NONE;
136 if (id < 0 || !reacquisition) {
137 debug_error("argument is not valid");
138 return MM_ERROR_INVALID_ARGUMENT;
141 ret = mm_sound_client_get_focus_reacquisition(id, reacquisition);
143 debug_error("Could not get focus reacquisition, ret[0x%x]", ret);
151 int mm_sound_get_stream_type_of_acquired_focus(int focus_type, char **stream_type, int *option, char **ext_info)
153 int ret = MM_ERROR_NONE;
157 if (stream_type == NULL) {
158 debug_error("argument is not valid");
159 return MM_ERROR_INVALID_ARGUMENT;
162 ret = mm_sound_client_get_acquired_focus_stream_type(focus_type, stream_type, option, ext_info);
164 debug_error("Could not get acquired focus stream type, ret[0x%x]", ret);
172 int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char *ext_info)
174 int ret = MM_ERROR_NONE;
178 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
181 debug_error("argument is not valid");
182 return MM_ERROR_INVALID_ARGUMENT;
184 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
185 debug_error("argument is not valid");
186 return MM_ERROR_INVALID_ARGUMENT;
189 ret = mm_sound_client_acquire_focus(id, focus_type, 0, ext_info);
191 debug_error("Could not acquire focus, ret[0x%x]", ret);
199 int mm_sound_release_focus(int id, mm_sound_focus_type_e focus_type, const char *ext_info)
201 int ret = MM_ERROR_NONE;
205 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
208 debug_error("argument is not valid");
209 return MM_ERROR_INVALID_ARGUMENT;
211 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
212 debug_error("argument is not valid");
213 return MM_ERROR_INVALID_ARGUMENT;
216 ret = mm_sound_client_release_focus(id, focus_type, 0, ext_info);
218 debug_error("Could not release focus, ret[0x%x]", ret);
226 int mm_sound_acquire_focus_with_option(int id, mm_sound_focus_type_e focus_type, int option, const char *ext_info)
228 int ret = MM_ERROR_NONE;
233 debug_error("id is not valid");
234 return MM_ERROR_INVALID_ARGUMENT;
238 debug_error("option is not valid");
239 return MM_ERROR_INVALID_ARGUMENT;
242 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
243 debug_error("focus type is not valid");
244 return MM_ERROR_INVALID_ARGUMENT;
247 ret = mm_sound_client_acquire_focus(id, focus_type, option, ext_info);
249 debug_error("Could not acquire focus, ret[0x%x]", ret);
257 int mm_sound_release_focus_with_option(int id, mm_sound_focus_type_e focus_type, int option, const char *ext_info)
259 int ret = MM_ERROR_NONE;
264 debug_error("id is not valid");
265 return MM_ERROR_INVALID_ARGUMENT;
269 debug_error("option is not valid");
270 return MM_ERROR_INVALID_ARGUMENT;
273 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
274 debug_error("focus type is not valid");
275 return MM_ERROR_INVALID_ARGUMENT;
278 ret = mm_sound_client_release_focus(id, focus_type, option, ext_info);
280 debug_error("Could not release focus, ret[0x%x]", ret);
288 int mm_sound_update_focus_status(int id, unsigned int status)
290 int ret = MM_ERROR_NONE;
292 if ((ret = mm_sound_client_update_stream_focus_status(id, status)))
293 debug_error("failed to mm_sound_client_update_stream_focus_status(), id(%d), status(%d, ret[0x%x]",
300 int mm_sound_deliver_focus(int src_id, int dst_id, mm_sound_focus_type_e focus_type)
302 int ret = MM_ERROR_NONE;
304 if ((ret = mm_sound_client_deliver_focus(src_id, dst_id, focus_type)))
305 debug_error("failed to mm_sound_client_deliver_focus(), ret[0x%x]", ret);
311 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)
313 int ret = MM_ERROR_NONE;
317 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
319 if (callback == NULL || id == NULL) {
320 debug_error("argument is not valid");
321 return MM_ERROR_INVALID_ARGUMENT;
323 ret = mm_sound_client_set_focus_watch_callback(getpid(), focus_type, callback, user_data, id);
325 debug_error("Could not set focus watch callback, ret[0x%x]", ret);
333 int mm_sound_unset_focus_watch_callback(int id)
335 int ret = MM_ERROR_NONE;
341 debug_error("argument is not valid");
342 return MM_ERROR_INVALID_ARGUMENT;
345 if ((ret = mm_sound_client_request_unset_focus_watch_callback(id))) {
346 debug_error("failed to mm_sound_client_request_unset_focus_watch_callback, ret[0x%x]", ret);
350 mm_sound_client_is_focus_cb_thread(g_thread_self(), &result);
352 if ((ret = mm_sound_client_unset_focus_watch_callback(id)))
353 debug_error("Could not unset focus watch callback, id(%d), ret[0x%x]", id, ret);
355 ret = mm_sound_client_execute_focus_func_in_main_context(IDLE_EVENT_TYPE_UNSET_FOCUS_WATCH_CB, id);
356 debug_msg("mm_sound_client_execute_focus_func_in_main_context() is called, id(%d), ret[0x%x]", id, ret);