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.
29 #include <semaphore.h>
34 #define KEYTONE_PATH "/tmp/keytone" /* Keytone pipe path */
35 #define FILE_FULL_PATH 1024 /* File path lenth */
37 #define RETRY_INTERVAL_USEC 50000
39 #define ROLE_NAME_LEN 64 /* Role name length */
40 #define VOLUME_GAIN_TYPE_LEN 64 /* Volume gain type length */
43 char filename[FILE_FULL_PATH];
44 char role[ROLE_NAME_LEN];
45 char volume_gain_type[VOLUME_GAIN_TYPE_LEN];
48 #define MMSOUND_STRNCPY(dst, src, size) \
50 if (src != NULL && dst != NULL && size > 0) { \
51 strncpy(dst, src, size - 1); \
52 dst[size - 1] = '\0'; \
53 } else if (dst == NULL) { \
54 debug_error("STRNCPY ERROR: Destination String is NULL"); \
56 else if (size <= 0) { \
57 debug_error("STRNCPY ERROR: Destination String is NULL"); \
60 debug_error("STRNCPY ERROR: Destination String is NULL"); \
65 int mm_sound_boot_ready(int timeout_sec)
70 debug_msg("[BOOT] check for sync....");
71 if ((sem = sem_open("booting-sound", O_CREAT, 0660, 0)) == SEM_FAILED) {
72 debug_error("error creating sem : %d", errno);
76 debug_msg("[BOOT] start to wait ready....timeout is set to %d sec", timeout_sec);
77 clock_gettime(CLOCK_REALTIME, &ts);
78 ts.tv_sec += timeout_sec;
80 if (sem_timedwait(sem, &ts) == -1) {
81 if (errno == ETIMEDOUT)
82 debug_warning("[BOOT] timeout!");
84 debug_msg("[BOOT] ready wait success!!!!");
92 int mm_sound_boot_play_sound(char* path)
97 ipc_t data = { { 0, }, { 0, }, { 0, } };
99 debug_msg("[BOOT] play boot sound [%s]!!!!", path);
101 return MM_ERROR_SOUND_INVALID_FILE;
103 /* Check whether file exists */
104 fd = open(path, O_RDONLY);
107 strerror_r(errno, str_error, sizeof(str_error));
108 debug_error("file open failed with [%s][%d]", str_error, errno);
111 return MM_ERROR_SOUND_FILE_NOT_FOUND;
113 return MM_ERROR_SOUND_INTERNAL;
120 fd = open(KEYTONE_PATH, O_WRONLY | O_NONBLOCK);
122 debug_error("Fail to open pipe");
123 return MM_ERROR_SOUND_FILE_NOT_FOUND;
126 MMSOUND_STRNCPY(data.filename, path, FILE_FULL_PATH);
127 MMSOUND_STRNCPY(data.role, "system", ROLE_NAME_LEN);
128 MMSOUND_STRNCPY(data.volume_gain_type, "booting", VOLUME_GAIN_TYPE_LEN);
130 debug_msg("filepath=[%s], role=[%s], volume_gain_type=[%s]", data.filename, data.role, data.volume_gain_type);
131 size = sizeof(ipc_t);
134 err = write(fd, &data, size);
137 strerror_r(errno, str_error, sizeof(str_error));
138 debug_error("Fail to write data: [%s][%d]", str_error, errno);
140 return MM_ERROR_SOUND_INTERNAL;
145 return MM_ERROR_NONE;