Let's start tizen audio 3.0
[platform/core/multimedia/libmm-sound.git] / mm_sound_focus.c
1 /*
2  * libmm-sound
3  *
4  * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Sangchul Lee <sc11.lee@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <stdio.h>
25 #include <vconf.h>
26
27 #include <mm_debug.h>
28
29 #include "include/mm_sound.h"
30 #include "include/mm_sound_focus.h"
31 #include "server/include/mm_sound_mgr_focus.h"
32
33 EXPORT_API
34 int mm_sound_focus_get_id(int *id)
35 {
36         int ret = MM_ERROR_NONE;
37
38         debug_fenter();
39
40         ret = mm_sound_client_get_uniq_id(id);
41         if (ret) {
42                 debug_error("Failed to mm_sound_client_get_uniq_id(), ret[0x%x]\n", ret);
43         }
44
45         debug_fleave();
46
47         return ret;
48 }
49
50 EXPORT_API
51 int mm_sound_register_focus(int id, const char *stream_type, mm_sound_focus_changed_cb callback, void *user_data)
52 {
53         int ret = MM_ERROR_NONE;
54
55         debug_fenter();
56
57         if (id < 0 || callback == NULL) {
58                 debug_error("argument is not valid\n");
59                 return MM_ERROR_INVALID_ARGUMENT;
60         }
61
62         ret = mm_sound_client_register_focus(id, stream_type, callback, user_data);
63         if (ret) {
64                 debug_error("Could not register focus, ret[0x%x]\n", ret);
65         }
66
67         debug_fleave();
68
69         return ret;
70 }
71
72 EXPORT_API
73 int mm_sound_unregister_focus(int id)
74 {
75         int ret = MM_ERROR_NONE;
76
77         debug_fenter();
78
79         if (id < 0) {
80                 debug_error("argument is not valid\n");
81                 return MM_ERROR_INVALID_ARGUMENT;
82         }
83
84         ret = mm_sound_client_unregister_focus(id);
85         if (ret) {
86                 debug_error("Could not unregister focus, ret = %x\n", ret);
87         }
88
89         debug_fleave();
90
91         return ret;
92 }
93
94 EXPORT_API
95 int mm_sound_acquire_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
96 {
97         int ret = MM_ERROR_NONE;
98
99         debug_fenter();
100
101         if (id < 0) {
102                 debug_error("argument is not valid\n");
103                 return MM_ERROR_INVALID_ARGUMENT;
104         }
105         if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
106                 debug_error("argument is not valid\n");
107                 return MM_ERROR_INVALID_ARGUMENT;
108         }
109
110         ret = mm_sound_client_acquire_focus(id, focus_type, additional_info);
111         if (ret) {
112                 debug_error("Could not acquire focus, ret[0x%x]\n", ret);
113         }
114
115         debug_fleave();
116
117         return ret;
118 }
119
120 EXPORT_API
121 int mm_sound_release_focus(int id, mm_sound_focus_type_e focus_type, const char *additional_info)
122 {
123         int ret = MM_ERROR_NONE;
124
125         debug_fenter();
126
127         if (id < 0) {
128                 debug_error("argument is not valid\n");
129                 return MM_ERROR_INVALID_ARGUMENT;
130         }
131         if (focus_type < FOCUS_FOR_PLAYBACK || focus_type > FOCUS_FOR_BOTH) {
132                 debug_error("argument is not valid\n");
133                 return MM_ERROR_INVALID_ARGUMENT;
134         }
135
136         ret = mm_sound_client_release_focus(id, focus_type, additional_info);
137         if (ret) {
138                 debug_error("Could not release focus, ret[0x%x]\n", ret);
139         }
140
141         debug_fleave();
142
143         return ret;
144 }
145
146 EXPORT_API
147 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)
148 {
149         int ret = MM_ERROR_NONE;
150
151         debug_fenter();
152
153         if (callback == NULL || id == NULL) {
154                 debug_error("argument is not valid\n");
155                 return MM_ERROR_INVALID_ARGUMENT;
156         }
157         ret = mm_sound_client_set_focus_watch_callback(focus_type, callback, user_data, id);
158         if (ret) {
159                 debug_error("Could not set focus watch callback, ret[0x%x]\n", ret);
160         }
161
162         debug_fleave();
163
164         return ret;
165 }
166
167 EXPORT_API
168 int mm_sound_unset_focus_watch_callback(int id)
169 {
170         int ret = MM_ERROR_NONE;
171
172         debug_fenter();
173
174         ret = mm_sound_client_unset_focus_watch_callback(id);
175         if (ret) {
176                 debug_error("Could not unset focus watch callback, id(%d), ret = %x\n", id, ret);
177         }
178
179         debug_fleave();
180
181         return ret;
182 }