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.
27 #include "include/mm_sound.h"
28 #include "include/mm_sound_client.h"
30 #define RETURN_ERROR_IF_FOCUS_CB_THREAD(x_thread) \
32 int ret = MM_ERROR_NONE; \
33 bool result = false; \
34 ret = mm_sound_client_is_focus_cb_thread(x_thread, &result); \
38 debug_error("it might be called in the thread of focus callback, it is not allowed\n"); \
39 return MM_ERROR_SOUND_INVALID_OPERATION; \
44 int mm_sound_focus_set_session_interrupt_callback(mm_sound_focus_session_interrupt_cb callback, void *user_data)
46 int ret = MM_ERROR_NONE;
49 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
52 return MM_ERROR_INVALID_ARGUMENT;
54 ret = mm_sound_client_set_session_interrupt_callback (callback, user_data);
62 int mm_sound_focus_unset_session_interrupt_callback(void)
64 int ret = MM_ERROR_NONE;
67 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
69 ret = mm_sound_client_unset_session_interrupt_callback ();
71 debug_error("Failed to mm_sound_client_unset_session_interrupt_callback(), ret[0x%x]\n", ret);
80 int mm_sound_focus_get_id(int *id)
82 int ret = MM_ERROR_NONE;
86 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
88 ret = mm_sound_client_get_unique_id(id);
90 debug_error("Failed to mm_sound_client_get_unique_id(), ret[0x%x]\n", ret);
99 int mm_sound_focus_is_cb_thread(bool *result)
101 int ret = MM_ERROR_NONE;
105 ret = mm_sound_client_is_focus_cb_thread(g_thread_self(), result);
108 debug_msg("it might be called in the thread of focus callback\n");
117 int mm_sound_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data)
119 int ret = MM_ERROR_NONE;
123 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
125 if (id < 0 || callback == NULL) {
126 debug_error("argument is not valid\n");
127 return MM_ERROR_INVALID_ARGUMENT;
130 ret = mm_sound_client_register_focus(id, getpid(), stream_type, callback, false, user_data);
132 debug_error("Could not register focus, ret[0x%x]\n", ret);
141 int mm_sound_register_focus_for_session(int id, int pid, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data)
143 int ret = MM_ERROR_NONE;
147 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
149 if (id < 0 || callback == NULL) {
150 debug_error("argument is not valid\n");
151 return MM_ERROR_INVALID_ARGUMENT;
154 ret = mm_sound_client_register_focus(id, pid, stream_type, callback, true, user_data);
156 debug_error("Could not register focus for session, ret[0x%x]\n", ret);
165 int mm_sound_unregister_focus(int id)
167 int ret = MM_ERROR_NONE;
171 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
174 debug_error("argument is not valid\n");
175 return MM_ERROR_INVALID_ARGUMENT;
178 ret = mm_sound_client_unregister_focus(id);
180 debug_error("Could not unregister focus, ret = %x\n", ret);
189 int mm_sound_set_focus_reacquisition(int id, bool reacquisition)
191 int ret = MM_ERROR_NONE;
196 debug_error("argument is not valid\n");
197 return MM_ERROR_INVALID_ARGUMENT;
200 ret = mm_sound_client_set_focus_reacquisition(id, reacquisition);
203 debug_error("Could not set focus reacquisition, ret[0x%x]\n", ret);
212 int mm_sound_get_focus_reacquisition(int id, bool *reacquisition)
214 int ret = MM_ERROR_NONE;
218 if (id < 0 || !reacquisition) {
219 debug_error("argument is not valid\n");
220 return MM_ERROR_INVALID_ARGUMENT;
223 ret = mm_sound_client_get_focus_reacquisition(id, reacquisition);
225 debug_error("Could not get focus reacquisition, ret[0x%x]\n", ret);
234 int mm_sound_get_stream_type_of_acquired_focus(int focus_type, char **stream_type, int *option, char **ext_info)
236 int ret = MM_ERROR_NONE;
240 if (stream_type == NULL) {
241 debug_error("argument is not valid\n");
242 return MM_ERROR_INVALID_ARGUMENT;
245 ret = mm_sound_client_get_acquired_focus_stream_type(focus_type, stream_type, option, ext_info);
247 debug_error("Could not get acquired focus stream type, ret[0x%x]\n", ret);
256 int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char *ext_info)
258 int ret = MM_ERROR_NONE;
262 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
265 debug_error("argument is not valid\n");
266 return MM_ERROR_INVALID_ARGUMENT;
268 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
269 debug_error("argument is not valid\n");
270 return MM_ERROR_INVALID_ARGUMENT;
273 ret = mm_sound_client_acquire_focus(id, focus_type, 0, ext_info);
275 debug_error("Could not acquire focus, ret[0x%x]\n", ret);
284 int mm_sound_release_focus(int id, mm_sound_focus_type_e focus_type, const char *ext_info)
286 int ret = MM_ERROR_NONE;
290 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
293 debug_error("argument is not valid\n");
294 return MM_ERROR_INVALID_ARGUMENT;
296 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
297 debug_error("argument is not valid\n");
298 return MM_ERROR_INVALID_ARGUMENT;
301 ret = mm_sound_client_release_focus(id, focus_type, 0, ext_info);
303 debug_error("Could not release focus, ret[0x%x]\n", ret);
312 int mm_sound_acquire_focus_with_option(int id, mm_sound_focus_type_e focus_type, int option, const char *ext_info)
314 int ret = MM_ERROR_NONE;
318 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
321 debug_error("id is not valid\n");
322 return MM_ERROR_INVALID_ARGUMENT;
326 debug_error("option is not valid\n");
327 return MM_ERROR_INVALID_ARGUMENT;
330 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
331 debug_error("focus type is not valid\n");
332 return MM_ERROR_INVALID_ARGUMENT;
335 ret = mm_sound_client_acquire_focus(id, focus_type, option, ext_info);
337 debug_error("Could not acquire focus, ret[0x%x]\n", ret);
346 int mm_sound_release_focus_with_option(int id, mm_sound_focus_type_e focus_type, int option, const char *ext_info)
348 int ret = MM_ERROR_NONE;
352 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
355 debug_error("id is not valid\n");
356 return MM_ERROR_INVALID_ARGUMENT;
360 debug_error("option is not valid\n");
361 return MM_ERROR_INVALID_ARGUMENT;
364 if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
365 debug_error("focus type is not valid\n");
366 return MM_ERROR_INVALID_ARGUMENT;
369 ret = mm_sound_client_release_focus(id, focus_type, option, ext_info);
371 debug_error("Could not release focus, ret[0x%x]\n", ret);
380 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)
382 int ret = MM_ERROR_NONE;
386 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
388 if (callback == NULL || id == NULL) {
389 debug_error("argument is not valid\n");
390 return MM_ERROR_INVALID_ARGUMENT;
392 ret = mm_sound_client_set_focus_watch_callback(getpid(), focus_type, callback, false, user_data, id);
394 debug_error("Could not set focus watch callback, ret[0x%x]\n", ret);
403 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)
405 int ret = MM_ERROR_NONE;
409 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
411 if (callback == NULL || id == NULL) {
412 debug_error("argument is not valid\n");
413 return MM_ERROR_INVALID_ARGUMENT;
415 ret = mm_sound_client_set_focus_watch_callback(pid, focus_type, callback, true, user_data, id);
417 debug_error("Could not set focus watch callback, ret[0x%x]\n", ret);
426 int mm_sound_unset_focus_watch_callback(int id)
428 int ret = MM_ERROR_NONE;
432 RETURN_ERROR_IF_FOCUS_CB_THREAD(g_thread_self());
434 ret = mm_sound_client_unset_focus_watch_callback(id);
436 debug_error("Could not unset focus watch callback, id(%d), ret = %x\n", id, ret);