Remove useless parameters(route_info, priority) regarding audio path routing since...
[platform/core/multimedia/libmm-sound.git] / server / mm_sound_mgr_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 <pthread.h>
26 #include <sys/shm.h>
27 #include <sys/msg.h>
28 #include <sys/mman.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31
32 #include <errno.h>
33 #include "include/mm_sound_mgr_common.h"
34 #include "include/mm_sound_mgr_ipc.h"
35 #include "include/mm_sound_mgr_ipc_dbus.h"
36
37 #include "../include/mm_sound_common.h"
38 #include "include/mm_sound_mgr_codec.h"
39 #include <mm_debug.h>
40
41 #define SHM_OPEN
42
43 /******************************************************************************************
44         Functions For handling request from client
45 ******************************************************************************************/
46 // except msgid
47 int _MMSoundMgrIpcPlayFile(char* filename,int tone, int repeat, int volume, int volume_config,
48                            int session_type, int session_options, int client_pid, gboolean enable_session,
49                            int *codechandle, char *stream_type, int stream_index)
50 {
51         mmsound_mgr_codec_param_t param = {0,};
52         MMSourceType *source = NULL;
53         int ret = MM_ERROR_NONE;
54
55         /* Set source */
56         source = (MMSourceType*)malloc(sizeof(MMSourceType));
57         if (!source) {
58                 debug_error("malloc fail!!\n");
59                 return MM_ERROR_OUT_OF_MEMORY;
60         }
61
62         ret = mm_source_open_file(filename, source, MM_SOURCE_CHECK_DRM_CONTENTS);
63         if(ret != MM_ERROR_NONE) {
64                 debug_error("Fail to open file\n");
65                 if (source) {
66                         free(source);
67                 }
68                 return ret;
69         }
70
71         /* Set sound player parameter */
72         param.tone = tone;
73         param.repeat_count = repeat;
74         param.volume = volume;
75         param.volume_config = volume_config;
76         param.session_type = session_type;
77         param.session_options = session_options;
78         param.param = (void*)client_pid;
79         param.source = source;
80         param.enable_session = enable_session;
81         param.stream_index = stream_index;
82         MMSOUND_STRNCPY(param.stream_type, stream_type, MM_SOUND_STREAM_TYPE_LEN);
83
84 /*
85         debug_msg("File[%s] DTMF[%d] Loop[%d] Volume[%f] VolCfg[0x%x] callback[%p] param[%d] src_type[%d] src_ptr[%p] keytone[%d] enable_session[%d]",
86                         filename,
87                         param.tone, param.repeat_count, param.volume, param.volume_config, param.callback,
88                         (int)param.param, param.source->type, param.source->ptr, param.keytone, param.enable_session);
89                         */
90
91         ret = MMSoundMgrCodecPlay(codechandle, &param);
92         if (ret != MM_ERROR_NONE) {
93                 debug_error("Will be closed a sources, codechandle : 0x%08X\n", *codechandle);
94                 mm_source_close(source);
95                 if (source) {
96                         free(source);
97                         source = NULL;
98                 }
99                 return ret;
100         }
101
102         return MM_ERROR_NONE;
103 }
104
105 int _MMSoundMgrIpcStop(int handle)
106 {
107         int ret = MM_ERROR_NONE;
108
109         ret = MMSoundMgrCodecStop(handle);
110
111         if (ret != MM_ERROR_NONE) {
112                 debug_error("Fail to stop sound\n");
113                 return ret;
114         }
115
116         return MM_ERROR_NONE;
117 }
118
119 #ifdef FOCUS_INTEGRATION
120 int _MMSoundMgrIpcClearFocus(int pid)
121 {
122         int ret = MM_ERROR_NONE;
123
124         ret = MMSoundMgrCodecClearFocus(pid);
125
126         if (ret != MM_ERROR_NONE) {
127                 debug_error("Fail to clear focus\n");
128                 return ret;
129         }
130
131         return MM_ERROR_NONE;
132 }
133 #endif
134
135 int _MMSoundMgrIpcPlayFileWithStreamInfo(char* filename, int repeat, int volume,
136                            int client_pid, int *codechandle, char *stream_type, int stream_index)
137 {
138         mmsound_mgr_codec_param_t param = {0,};
139         MMSourceType *source = NULL;
140         int ret = MM_ERROR_NONE;
141
142         /* Set source */
143         source = (MMSourceType*)malloc(sizeof(MMSourceType));
144         if (!source) {
145                 debug_error("malloc fail!!\n");
146                 return MM_ERROR_OUT_OF_MEMORY;
147         }
148
149         ret = mm_source_open_file(filename, source, MM_SOURCE_CHECK_DRM_CONTENTS);
150         if(ret != MM_ERROR_NONE) {
151                 debug_error("Fail to open file\n");
152                 if (source) {
153                         free(source);
154                 }
155                 return ret;
156         }
157
158         /* Set sound player parameter */
159         param.repeat_count = repeat;
160         param.volume = volume;
161         param.param = (void*)client_pid;
162         param.source = source;
163         param.stream_index = stream_index;
164         MMSOUND_STRNCPY(param.stream_type, stream_type, MM_SOUND_STREAM_TYPE_LEN);
165
166         ret = MMSoundMgrCodecPlayWithStreamInfo(codechandle, &param);
167         if (ret != MM_ERROR_NONE) {
168                 debug_error("Will be closed a sources, codechandle : 0x%08X\n", *codechandle);
169                 mm_source_close(source);
170                 if (source) {
171                         free(source);
172                         source = NULL;
173                 }
174                 return ret;
175         }
176
177         return MM_ERROR_NONE;
178
179 }
180
181 int _MMSoundMgrIpcPlayDTMF(int tone, int repeat, int volume, int volume_config,
182                            int session_type, int session_options, int client_pid,
183                            gboolean enable_session, int *codechandle, char *stream_type, int stream_index)
184 {
185         mmsound_mgr_codec_param_t param = {0,};
186         int ret = MM_ERROR_NONE;
187
188         /* Set sound player parameter */
189         param.tone = tone;
190         param.repeat_count = repeat;
191         param.volume = volume;
192         param.volume_config = volume_config;
193         param.param = (void*)client_pid;
194         param.session_type = session_type;
195         param.session_options = session_options;
196         param.enable_session = enable_session;
197         param.stream_index = stream_index;
198         MMSOUND_STRNCPY(param.stream_type, stream_type, MM_SOUND_STREAM_TYPE_LEN);
199
200         debug_msg("DTMF %d\n", param.tone);
201         debug_msg("Loop %d\n", param.repeat_count);
202         debug_msg("Volume %d\n",param.volume);
203         debug_msg("VolumeConfig %x\n",param.volume_config);
204         debug_msg("session %d\n", param.session_type);
205         debug_msg("session options %x\n", param.session_options);
206         debug_msg("enable_session %d\n", param.enable_session);
207
208         ret = MMSoundMgrCodecPlayDtmf(codechandle, &param);
209         if ( ret != MM_ERROR_NONE) {
210                 debug_error("Will be closed a sources, codec handle : [0x%d]\n", *codechandle);
211                 return ret;
212         }
213
214         return ret;
215 }
216
217 int _MMSoundMgrIpcPlayDTMFWithStreamInfo(int tone, int repeat, int volume, int client_pid, int *codechandle, char *stream_type, int stream_index)
218 {
219         mmsound_mgr_codec_param_t param = {0,};
220         int ret = MM_ERROR_NONE;
221
222         /* Set sound player parameter */
223         param.tone = tone;
224         param.repeat_count = repeat;
225         param.volume = volume;
226         param.param = (void*)client_pid;
227         param.stream_index = stream_index;
228         MMSOUND_STRNCPY(param.stream_type, stream_type, MM_SOUND_STREAM_TYPE_LEN);
229
230         debug_msg("DTMF %d\n", param.tone);
231         debug_msg("Loop %d\n", param.repeat_count);
232         debug_msg("Volume %d\n",param.volume);
233         debug_msg("stream type %s\n", param.stream_type);
234         debug_msg("stream index %d\n", param.stream_index);
235
236
237         ret = MMSoundMgrCodecPlayDtmfWithStreamInfo(codechandle, &param);
238         if ( ret != MM_ERROR_NONE) {
239                 debug_error("Will be closed a sources, codec handle : [0x%d]\n", *codechandle);
240                 return ret;
241         }
242
243         return ret;
244 }
245
246 int __mm_sound_mgr_ipc_get_current_connected_device_list(int device_flags, mm_sound_device_t **device_list, int *total_num)
247 {
248         int ret = MM_ERROR_NONE;
249
250 //      ret = _mm_sound_mgr_device_get_current_connected_dev_list(device_flags, device_list, total_num);
251
252         return ret;
253 }
254
255 /******************************************************************************************
256         Functions For Server-Side to notify Clients
257 ******************************************************************************************/
258
259 int __mm_sound_mgr_ipc_notify_play_file_end (int handle)
260 {
261         return __mm_sound_mgr_ipc_dbus_notify_play_file_end(handle);
262 }
263
264 int __mm_sound_mgr_ipc_notify_device_connected (mm_sound_device_t *device, gboolean is_connected)
265 {
266         return __mm_sound_mgr_ipc_dbus_notify_device_connected(device, is_connected);
267 }
268
269 int __mm_sound_mgr_ipc_notify_device_info_changed (mm_sound_device_t *device, int changed_device_info_type)
270 {
271         return __mm_sound_mgr_ipc_dbus_notify_device_info_changed(device, changed_device_info_type);
272 }
273
274 int __mm_sound_mgr_ipc_notify_volume_changed(unsigned int vol_type, unsigned int value)
275 {
276         return __mm_sound_mgr_ipc_dbus_notify_volume_changed(vol_type, value);
277 }
278
279 int __mm_sound_mgr_ipc_notify_active_device_changed(int device_in, int device_out)
280 {
281         /* Not Implemented */
282         return __mm_sound_mgr_ipc_dbus_notify_active_device_changed(device_in, device_out);
283 }
284
285 int __mm_sound_mgr_ipc_notify_available_device_changed(int device_in, int device_out, int available)
286 {
287         /* Not Implemented */
288         return __mm_sound_mgr_ipc_dbus_notify_available_device_changed(device_in, device_out, available);
289 }
290
291 int MMSoundMgrIpcInit(void)
292 {
293         return MM_ERROR_NONE;
294 }
295
296 int MMSoundMgrIpcFini(void)
297 {
298         return MM_ERROR_NONE;
299 }