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