bb3c43234642cf638b4e075c5faabe89f934b7b0
[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 "include/mm_sound_mgr_ipc.h"
23 #include "include/mm_sound_mgr_ipc_dbus.h"
24
25 #include "../include/mm_sound_common.h"
26 #include "include/mm_sound_mgr_codec.h"
27 #include <mm_debug.h>
28 #include <mm_error.h>
29
30 /******************************************************************************************
31         Functions For handling request from client
32 ******************************************************************************************/
33 // except msgid
34 int _MMSoundMgrIpcPlayFile(char* filename, int tone, int repeat, int volume, int volume_config,
35                                                 int session_type, int session_options, int client_pid, gboolean enable_session,
36                                                 int *codechandle, char *stream_type, int stream_index)
37 {
38         mmsound_mgr_codec_param_t param = { 0, };
39         int ret = MM_ERROR_NONE;
40
41         /* Set sound player parameter */
42         param.tone = tone;
43         param.repeat_count = repeat;
44         param.volume = volume;
45         param.volume_config = volume_config;
46         param.session_type = session_type;
47         param.session_options = session_options;
48         param.param = (void*)client_pid;
49         param.pfilename = filename;
50         param.enable_session = enable_session;
51         param.stream_index = stream_index;
52         MMSOUND_STRNCPY(param.stream_type, stream_type, MAX_STREAM_TYPE_LEN);
53
54         ret = MMSoundMgrCodecPlay(codechandle, &param);
55         if (ret != MM_ERROR_NONE) {
56                 debug_error("Will be closed a sources, codechandle : 0x%08X", *codechandle);
57                 return ret;
58         }
59
60         return MM_ERROR_NONE;
61 }
62
63 int _MMSoundMgrIpcStop(int handle)
64 {
65         int ret = MM_ERROR_NONE;
66
67         ret = MMSoundMgrCodecStop(handle);
68
69         if (ret != MM_ERROR_NONE) {
70                 debug_error("Fail to stop sound");
71                 return ret;
72         }
73
74         return MM_ERROR_NONE;
75 }
76
77 #ifdef FOCUS_INTEGRATION
78 int _MMSoundMgrIpcClearFocus(int pid)
79 {
80         int ret = MM_ERROR_NONE;
81
82         ret = MMSoundMgrCodecClearFocus(pid);
83
84         if (ret != MM_ERROR_NONE) {
85                 debug_error("Fail to clear focus");
86                 return ret;
87         }
88
89         return MM_ERROR_NONE;
90 }
91 #endif
92
93 int _MMSoundMgrIpcPlayFileWithStreamInfo(char *filename, int repeat, int volume,
94                            int client_pid, int *codechandle, char *stream_type, int stream_index)
95 {
96         mmsound_mgr_codec_param_t param = { 0, };
97         int ret = MM_ERROR_NONE;
98
99         /* Set sound player parameter */
100         param.repeat_count = repeat;
101         param.volume = volume;
102         param.param = (void*)client_pid;
103         param.pfilename = filename;
104         param.stream_index = stream_index;
105         MMSOUND_STRNCPY(param.stream_type, stream_type, MAX_STREAM_TYPE_LEN);
106
107         ret = MMSoundMgrCodecPlayWithStreamInfo(codechandle, &param);
108         if (ret != MM_ERROR_NONE) {
109                 debug_error("Will be closed a sources, codechandle : 0x%08X", *codechandle);
110                 return ret;
111         }
112
113         return MM_ERROR_NONE;
114
115 }
116
117 int _MMSoundMgrIpcPlayDTMF(int tone, int repeat, int volume, int volume_config,
118                                                 int session_type, int session_options, int client_pid,
119                                                 gboolean enable_session, int *codechandle,
120                                                 char *stream_type, int stream_index)
121 {
122         mmsound_mgr_codec_param_t param = { 0, };
123         int ret = MM_ERROR_NONE;
124
125         /* Set sound player parameter */
126         param.tone = tone;
127         param.repeat_count = repeat;
128         param.volume = volume;
129         param.volume_config = volume_config;
130         param.param = (void*)client_pid;
131         param.session_type = session_type;
132         param.session_options = session_options;
133         param.enable_session = enable_session;
134         param.stream_index = stream_index;
135         MMSOUND_STRNCPY(param.stream_type, stream_type, MAX_STREAM_TYPE_LEN);
136
137         debug_msg("DTMF %d", param.tone);
138         debug_msg("Loop %d", param.repeat_count);
139         debug_msg("Volume %f", param.volume);
140         debug_msg("VolumeConfig %x", param.volume_config);
141         debug_msg("session %d", param.session_type);
142         debug_msg("session options %x", param.session_options);
143         debug_msg("enable_session %d", param.enable_session);
144
145         ret = MMSoundMgrCodecPlayDtmf(codechandle, &param);
146         if (ret != MM_ERROR_NONE) {
147                 debug_error("Will be closed a sources, codec handle : [0x%d]", *codechandle);
148                 return ret;
149         }
150
151         return ret;
152 }
153
154 int _MMSoundMgrIpcPlayDTMFWithStreamInfo(int tone, int repeat, int volume, int client_pid, int *codechandle,
155                                                                                 char *stream_type, int stream_index)
156 {
157         mmsound_mgr_codec_param_t param = { 0, };
158         int ret = MM_ERROR_NONE;
159
160         /* Set sound player parameter */
161         param.tone = tone;
162         param.repeat_count = repeat;
163         param.volume = volume;
164         param.param = (void*)client_pid;
165         param.stream_index = stream_index;
166         MMSOUND_STRNCPY(param.stream_type, stream_type, MAX_STREAM_TYPE_LEN);
167
168         debug_msg("DTMF %d", param.tone);
169         debug_msg("Loop %d", param.repeat_count);
170         debug_msg("Volume %f", param.volume);
171         debug_msg("stream type %s", param.stream_type);
172         debug_msg("stream index %d", param.stream_index);
173
174
175         ret = MMSoundMgrCodecPlayDtmfWithStreamInfo(codechandle, &param);
176         if (ret != MM_ERROR_NONE) {
177                 debug_error("Will be closed a sources, codec handle : [0x%d]", *codechandle);
178                 return ret;
179         }
180
181         return ret;
182 }
183
184 /******************************************************************************************
185         Functions For Server-Side to notify Clients
186 ******************************************************************************************/
187
188 int __mm_sound_mgr_ipc_notify_play_file_end(int handle)
189 {
190         return __mm_sound_mgr_ipc_dbus_notify_play_file_end(handle);
191 }
192