Fix float->int(short) clipping issue when playing ogg content
[platform/core/multimedia/libmm-sound.git] / focus_server / mm_sound_mgr_focus_ipc.c
1 /*
2  * libmm-sound
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Seungbae Shin <seungbae.shin@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 <string.h>
24
25 #include "include/mm_sound_mgr_focus_ipc.h"
26 #include "include/mm_sound_mgr_focus_dbus.h"
27
28 #include "../include/mm_sound_common.h"
29 #include "include/mm_sound_mgr_focus.h"
30 #include <mm_debug.h>
31
32 int __mm_sound_mgr_focus_ipc_register_focus(int client_pid, int handle_id, const char* stream_type)
33 {
34         _mm_sound_mgr_focus_param_t param;
35         int ret = MM_ERROR_NONE;
36
37         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
38         param.pid = client_pid;
39         param.handle_id = handle_id;
40         MMSOUND_STRNCPY(param.stream_type, stream_type, MAX_STREAM_TYPE_LEN);
41
42         ret = mm_sound_mgr_focus_create_node(&param);
43
44         return ret;
45 }
46
47 // method + remove callback
48 int __mm_sound_mgr_focus_ipc_unregister_focus(int pid, int handle_id)
49 {
50         _mm_sound_mgr_focus_param_t param;
51         int ret = MM_ERROR_NONE;
52
53         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
54         param.pid = pid;
55         param.handle_id = handle_id;
56
57         ret = mm_sound_mgr_focus_destroy_node(&param);
58
59         return ret;
60 }
61
62 // method -> callback
63 int __mm_sound_mgr_focus_ipc_set_focus_reacquisition(int pid, int handle_id, bool reacquisition)
64 {
65         _mm_sound_mgr_focus_param_t param;
66         int ret = MM_ERROR_NONE;
67
68         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
69         param.pid = pid;
70         param.handle_id = handle_id;
71         param.reacquisition = reacquisition;
72
73         ret = mm_sound_mgr_focus_set_reacquisition(&param);
74
75         return ret;
76 }
77
78 // method
79 int __mm_sound_mgr_focus_ipc_get_acquired_focus_stream_type(int focus_type, char **stream_type, int *option, char **ext_info)
80 {
81         int ret = MM_ERROR_NONE;
82         char *stream_type_str = NULL;
83         char *ext_info_str = NULL;
84
85         if (!stream_type || !option)
86                 return MM_ERROR_INVALID_ARGUMENT;
87
88         ret = mm_sound_mgr_focus_get_stream_type_of_acquired_focus(focus_type, &stream_type_str, option, &ext_info_str);
89         if (ret == MM_ERROR_NONE) {
90                 *stream_type = stream_type_str;
91                 if (ext_info)
92                         *ext_info = ext_info_str;
93         }
94
95         return ret;
96 }
97
98 // method -> callback
99 int __mm_sound_mgr_focus_ipc_acquire_focus(int pid, int handle_id, int focus_type, int option, const char *ext_info, bool is_in_thread)
100 {
101         _mm_sound_mgr_focus_param_t param;
102         int ret = MM_ERROR_NONE;
103
104         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
105         param.pid = pid;
106         param.handle_id = handle_id;
107         param.request_type = focus_type;
108         param.option = option;
109         param.is_in_thread = is_in_thread;
110         MMSOUND_STRNCPY(param.ext_info, ext_info, MM_SOUND_NAME_NUM);
111
112         ret = mm_sound_mgr_focus_request_acquire(&param);
113
114         return ret;
115 }
116
117 // method -> callback
118 int __mm_sound_mgr_focus_ipc_release_focus(int pid, int handle_id, int focus_type, int option, const char *ext_info, bool is_in_thread)
119 {
120         _mm_sound_mgr_focus_param_t param;
121         int ret = MM_ERROR_NONE;
122
123         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
124         param.pid = pid;
125         param.handle_id = handle_id;
126         param.request_type = focus_type;
127         param.option = option;
128         param.is_in_thread = is_in_thread;
129         MMSOUND_STRNCPY(param.ext_info, ext_info, MM_SOUND_NAME_NUM);
130
131         ret = mm_sound_mgr_focus_request_release(&param);
132
133         return ret;
134 }
135
136 int __mm_sound_mgr_focus_ipc_watch_focus(int pid, int handle_id, int focus_type)
137 {
138         _mm_sound_mgr_focus_param_t param;
139         int ret = MM_ERROR_NONE;
140
141         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
142         param.pid = pid;
143         param.handle_id = handle_id;
144         param.request_type = focus_type;
145
146         ret = mm_sound_mgr_focus_set_watch_cb(&param);
147
148         return ret;
149 }
150
151 // method + remove callback
152 int __mm_sound_mgr_focus_ipc_unwatch_focus(int pid, int handle_id)
153 {
154         _mm_sound_mgr_focus_param_t param;
155         int ret = MM_ERROR_NONE;
156
157         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
158         param.pid = pid;
159         param.handle_id = handle_id;
160
161         ret = mm_sound_mgr_focus_unset_watch_cb(&param);
162
163         return ret;
164 }
165
166 int __mm_sound_mgr_focus_ipc_deliver_focus(int pid, int src_handle_id, int dst_handle_id, int focus_type)
167 {
168         _mm_sound_mgr_focus_param_t param;
169         int ret = MM_ERROR_NONE;
170
171         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
172         param.pid = pid;
173         param.handle_id = src_handle_id;
174         param.handle_id_dst = dst_handle_id;
175         param.request_type = focus_type;
176
177         ret = mm_sound_mgr_focus_deliver(&param);
178
179         return ret;
180 }
181
182 int __mm_sound_mgr_focus_ipc_emergent_exit(int pid)
183 {
184         _mm_sound_mgr_focus_param_t param;
185         int ret = MM_ERROR_NONE;
186
187         memset(&param, 0x00, sizeof(_mm_sound_mgr_focus_param_t));
188         param.pid = pid;
189
190         ret = mm_sound_mgr_focus_emergent_exit(&param);
191
192         return ret;
193 }
194