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>
34 #include <semaphore.h>
39 #include <mm_message.h>
42 #include <mm_sound_private.h>
44 #define KEYTONE_PATH "/tmp/keytone" /* Keytone pipe path */
45 #define FILE_FULL_PATH 1024 /* File path lenth */
47 #define RETRY_INTERVAL_USEC 50000
49 #define ROLE_NAME_LEN 64 /* Role name length */
50 #define VOLUME_GAIN_TYPE_LEN 64 /* Volume gain type length */
53 char filename[FILE_FULL_PATH];
54 char role[ROLE_NAME_LEN];
55 char volume_gain_type[VOLUME_GAIN_TYPE_LEN];
58 #define MMSOUND_STRNCPY(dst,src,size)\
60 if(src != NULL && dst != NULL && size > 0) {\
61 strncpy(dst,src,size); \
63 } else if(dst == NULL) { \
64 debug_error("STRNCPY ERROR: Destination String is NULL\n"); \
66 else if(size <= 0) { \
67 debug_error("STRNCPY ERROR: Destination String is NULL\n"); \
70 debug_error("STRNCPY ERROR: Destination String is NULL\n"); \
75 int mm_sound_boot_ready(int timeout_sec)
80 debug_msg("[BOOT] check for sync....");
81 if ((sem = sem_open ("booting-sound", O_CREAT, 0660, 0))== SEM_FAILED) {
82 debug_error ("error creating sem : %d", errno);
86 debug_msg("[BOOT] start to wait ready....timeout is set to %d sec", timeout_sec);
87 clock_gettime(CLOCK_REALTIME, &ts);
88 ts.tv_sec += timeout_sec;
90 if (sem_timedwait(sem, &ts) == -1) {
91 if (errno == ETIMEDOUT)
92 debug_warning("[BOOT] timeout!\n");
94 debug_msg("[BOOT] ready wait success!!!!");
102 int mm_sound_boot_play_sound(char* path)
107 ipc_t data = {{0,},{0,},{0,}};
109 debug_msg("[BOOT] play boot sound [%s]!!!!", path);
111 return MM_ERROR_SOUND_INVALID_FILE;
113 /* Check whether file exists */
114 fd = open(path, O_RDONLY);
116 debug_error("file open failed with [%s][%d]\n", strerror(errno), errno);
119 return MM_ERROR_SOUND_FILE_NOT_FOUND;
121 return MM_ERROR_SOUND_INTERNAL;
128 fd = open(KEYTONE_PATH, O_WRONLY | O_NONBLOCK);
130 debug_error("Fail to open pipe\n");
131 return MM_ERROR_SOUND_FILE_NOT_FOUND;
134 MMSOUND_STRNCPY(data.filename, path, FILE_FULL_PATH);
135 MMSOUND_STRNCPY(data.role, "system", ROLE_NAME_LEN);
136 MMSOUND_STRNCPY(data.volume_gain_type, "booting", VOLUME_GAIN_TYPE_LEN);
138 debug_msg("filepath=[%s], role=[%s], volume_gain_type=[%s]\n", data.filename, data.role, data.volume_gain_type);
139 size = sizeof(ipc_t);
142 err = write(fd, &data, size);
144 debug_error("Fail to write data: [%s][%d]\n", strerror(errno), errno);
146 return MM_ERROR_SOUND_INTERNAL;
151 return MM_ERROR_NONE;