4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Seungbae Shin <seungbae.shin@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
27 #include <sys/types.h>
36 #include <mm_message.h>
39 #include <mm_sound_private.h>
41 #include "include/mm_sound_common.h"
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 */
48 #define AUDIO_VOLUME_CONFIG_TYPE(vol) (vol & 0x00FF)
49 #define AUDIO_VOLUME_CONFIG_GAIN(vol) (vol & 0xFF00)
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];
57 static const char* convert_volume_type_to_role(int volume_type)
59 debug_warning ("volume_type(%d)", volume_type);
61 case VOLUME_TYPE_SYSTEM:
63 case VOLUME_TYPE_NOTIFICATION:
64 return "notification";
65 case VOLUME_TYPE_ALARM:
67 case VOLUME_TYPE_RINGTONE:
69 case VOLUME_TYPE_CALL:
71 case VOLUME_TYPE_VOIP:
73 case VOLUME_TYPE_VOICE:
80 static const char* convert_volume_gain_type_to_string(int volume_gain_type)
82 debug_warning ("volume_gain_type(0x%x)", volume_gain_type);
83 switch(volume_gain_type) {
84 case VOLUME_GAIN_DEFAULT:
86 case VOLUME_GAIN_DIALER:
88 case VOLUME_GAIN_TOUCH:
92 case VOLUME_GAIN_SHUTTER1:
94 case VOLUME_GAIN_SHUTTER2:
96 case VOLUME_GAIN_CAMCORDING:
98 case VOLUME_GAIN_MIDI:
100 case VOLUME_GAIN_BOOTING:
102 case VOLUME_GAIN_VIDEO:
104 case VOLUME_GAIN_TTS:
112 int mm_sound_play_keysound(const char *filename, int volume_config)
114 int err = MM_ERROR_NONE;
117 ipc_t data = {{0,},{0,},{0,}};
118 int capture_status = 0;
120 const char *vol_gain_type = NULL;
123 return MM_ERROR_SOUND_INVALID_FILE;
125 /* Check whether file exists */
126 fd = open(filename, O_RDONLY);
128 debug_error("file open failed with [%s][%d]\n", strerror(errno), errno);
131 return MM_ERROR_SOUND_FILE_NOT_FOUND;
133 return MM_ERROR_SOUND_INTERNAL;
140 fd = open(KEYTONE_PATH, O_WRONLY | O_NONBLOCK);
142 debug_error("Fail to open pipe\n");
143 return MM_ERROR_SOUND_FILE_NOT_FOUND;
146 /* convert volume type to role */
147 role = convert_volume_type_to_role(AUDIO_VOLUME_CONFIG_TYPE(volume_config));
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));
152 MMSOUND_STRNCPY(data.volume_gain_type, vol_gain_type, VOLUME_GAIN_TYPE_LEN);
154 MMSOUND_STRNCPY(data.filename, filename, FILE_FULL_PATH);
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);
160 err = write(fd, &data, size);
162 debug_error("Fail to write data: [%s][%d]\n", strerror(errno), errno);
164 return MM_ERROR_SOUND_INTERNAL;
169 return MM_ERROR_NONE;