Remove unused files
[platform/core/multimedia/libmm-sound.git] / mm_sound_keysound.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 <memory.h>
24 #include <unistd.h>
25 #include <pthread.h>
26 #include <stdio.h>
27 #include <sys/types.h>
28 #include <fcntl.h>
29 #include <vconf.h>
30
31 #include <sys/stat.h>
32 #include <errno.h>
33
34 #include <mm_types.h>
35 #include <mm_error.h>
36 #include <mm_message.h>
37 #include <mm_debug.h>
38 #include <mm_sound.h>
39 #include <mm_sound_private.h>
40
41 #include "include/mm_sound_common.h"
42
43 #define KEYTONE_PATH "/tmp/keytone"             /* Keytone pipe path */
44 #define FILE_FULL_PATH 1024                             /* File path length */
45 #define ROLE_NAME_LEN 64                                /* Role name length */
46 #define VOLUME_GAIN_TYPE_LEN 64         /* Volume gain type length */
47
48 #define AUDIO_VOLUME_CONFIG_TYPE(vol) (vol & 0x00FF)
49 #define AUDIO_VOLUME_CONFIG_GAIN(vol) (vol & 0xFF00)
50
51 typedef struct ipc_data {
52     char filename[FILE_FULL_PATH];
53     char role[ROLE_NAME_LEN];
54     char volume_gain_type[VOLUME_GAIN_TYPE_LEN];
55 }ipc_t;
56
57 static const char* convert_volume_type_to_role(int volume_type)
58 {
59         debug_warning ("volume_type(%d)", volume_type);
60         switch(volume_type) {
61         case VOLUME_TYPE_SYSTEM:
62                 return "system";
63         case VOLUME_TYPE_NOTIFICATION:
64                 return "notification";
65         case VOLUME_TYPE_ALARM:
66                 return "alarm";
67         case VOLUME_TYPE_RINGTONE:
68                 return "ringtone";
69         case VOLUME_TYPE_CALL:
70                 return "call";
71         case VOLUME_TYPE_VOIP:
72                 return "voip";
73         case VOLUME_TYPE_VOICE:
74                 return "voice";
75         default:
76                 return NULL;
77         }
78 }
79
80 static const char* convert_volume_gain_type_to_string(int volume_gain_type)
81 {
82         debug_warning ("volume_gain_type(0x%x)", volume_gain_type);
83         switch(volume_gain_type) {
84         case VOLUME_GAIN_DEFAULT:
85                 return NULL;
86         case VOLUME_GAIN_DIALER:
87                 return "dialer";
88         case VOLUME_GAIN_TOUCH:
89                 return "touch";
90         case VOLUME_GAIN_AF:
91                 return "af";
92         case VOLUME_GAIN_SHUTTER1:
93                 return "shutter1";
94         case VOLUME_GAIN_SHUTTER2:
95                 return "shutter2";
96         case VOLUME_GAIN_CAMCORDING:
97                 return "camcording";
98         case VOLUME_GAIN_MIDI:
99                 return "midi";
100         case VOLUME_GAIN_BOOTING:
101                 return "booting";
102         case VOLUME_GAIN_VIDEO:
103                 return "video";
104         case VOLUME_GAIN_TTS:
105                 return "tts";
106         default:
107                 return NULL;
108         }
109 }
110
111 EXPORT_API
112 int mm_sound_play_keysound(const char *filename, int volume_config)
113 {
114         int err = MM_ERROR_NONE;
115         int fd = -1;
116         int size = 0;
117         ipc_t data = {{0,},{0,},{0,}};
118         int capture_status = 0;
119         char *role = NULL;
120         const char *vol_gain_type = NULL;
121
122         if (!filename)
123                 return MM_ERROR_SOUND_INVALID_FILE;
124
125         /* Check whether file exists */
126         fd = open(filename, O_RDONLY);
127         if (fd == -1) {
128                 debug_error("file open failed with [%s][%d]\n", strerror(errno), errno);
129                 switch (errno) {
130                 case ENOENT:
131                         return MM_ERROR_SOUND_FILE_NOT_FOUND;
132                 default:
133                         return MM_ERROR_SOUND_INTERNAL;
134                 }
135         }
136         close(fd);
137         fd = -1;
138
139         /* Open PIPE */
140         fd = open(KEYTONE_PATH, O_WRONLY | O_NONBLOCK);
141         if (fd == -1) {
142                 debug_error("Fail to open pipe\n");
143                 return MM_ERROR_SOUND_FILE_NOT_FOUND;
144         }
145
146         /* convert volume type to role */
147         role = convert_volume_type_to_role(AUDIO_VOLUME_CONFIG_TYPE(volume_config));
148         if (role) {
149                 MMSOUND_STRNCPY(data.role, role, ROLE_NAME_LEN);
150                 vol_gain_type = convert_volume_gain_type_to_string(AUDIO_VOLUME_CONFIG_GAIN(volume_config));
151                 if (vol_gain_type)
152                         MMSOUND_STRNCPY(data.volume_gain_type, vol_gain_type, VOLUME_GAIN_TYPE_LEN);
153         }
154         MMSOUND_STRNCPY(data.filename, filename, FILE_FULL_PATH);
155
156         debug_msg("filepath=[%s], role=[%s], volume_gain_type=[%s]\n", data.filename, data.role, data.volume_gain_type);
157         size = sizeof(ipc_t);
158
159         /* Write to PIPE */
160         err = write(fd, &data, size);
161         if (err < 0) {
162                 debug_error("Fail to write data: [%s][%d]\n", strerror(errno), errno);
163                 close(fd);
164                 return MM_ERROR_SOUND_INTERNAL;
165         }
166         /* Close PIPE */
167         close(fd);
168
169         return MM_ERROR_NONE;
170 }