2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #define LOG_TAG "CAPI_MEDIA_WAV_PLAYER"
21 #include <mm_sound_private.h>
27 #include <wav_player.h>
31 typedef struct _cb_data_{
32 wav_player_playback_completed_cb cb;
38 static int __convert_wav_player_error_code(const char *func, int code)
40 int ret = WAV_PLAYER_ERROR_INVALID_OPERATION;
41 char *errorstr = NULL;
45 ret = WAV_PLAYER_ERROR_NONE;
46 errorstr = "ERROR_NONE";
48 case MM_ERROR_INVALID_ARGUMENT:
49 case MM_ERROR_SOUND_INVALID_POINTER:
50 case WAV_PLAYER_ERROR_INVALID_PARAMETER:
51 ret = WAV_PLAYER_ERROR_INVALID_PARAMETER;
52 errorstr = "INVALID_PARAMETER";
54 case MM_ERROR_SOUND_INTERNAL:
55 ret = WAV_PLAYER_ERROR_INVALID_OPERATION;
56 errorstr = "INVALID_OPERATION";
58 case MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE:
59 ret = WAV_PLAYER_ERROR_FORMAT_NOT_SUPPORTED;
60 errorstr = "FORMAT_NOT_SUPPORTED";
63 ret = WAV_PLAYER_ERROR_INVALID_OPERATION;
64 errorstr = "INVALID_OPERATION";
67 LOGE( "[%s] %s(0x%08x)",func, errorstr, ret);
72 static void __internal_complete_cb(void *user_data, int id)
74 _cb_data * cb_data = (_cb_data*)user_data;
79 LOGD( "user callback for handle %d call", id);
80 cb_data->cb(id, cb_data->user_data);
86 int wav_player_start(const char *path, sound_type_e type, wav_player_playback_completed_cb cb, void *user_data, int * id)
90 char m_path[PATH_MAX];
91 void (*_completed_cb)(void *, int);
93 _cb_data *cb_data = NULL;
97 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_PARAMETER);
99 if( type < SOUND_TYPE_SYSTEM || type > SOUND_TYPE_FIXED_CAMCORDING )
100 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_PARAMETER);
101 if (type >= SOUND_TYPE_FIXED ) {
102 LOGW( "type is %d, we force to set SOUND_TYPE_FIXED", type);
103 type = VOLUME_TYPE_FIXED;
107 if( path[0] != '/' ){
109 if( getcwd(m_path, PATH_MAX) != NULL){
110 strncat(m_path, "/",PATH_MAX-strlen(m_path) );
113 strncat(m_path, path, PATH_MAX-strlen(m_path));
116 _completed_cb = __internal_complete_cb;
117 cb_data = (_cb_data *)malloc(sizeof(_cb_data));
119 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_OPERATION);
121 cb_data->user_data = user_data;
125 ret = mm_sound_play_sound(m_path, type, _completed_cb , cb_data, &player);
127 if( ret == 0 && id != NULL){
131 if( ret != 0 && cb_data != NULL)
134 return __convert_wav_player_error_code(__func__, ret);
137 int wav_player_start_solo(const char *path, sound_type_e type, bool force_to_route_spk, wav_player_playback_completed_cb cb, void *user_data, int * id)
141 char m_path[PATH_MAX];
142 void (*_completed_cb)(void *, int);
143 _completed_cb = NULL;
144 _cb_data *cb_data = NULL;
148 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_PARAMETER);
151 if( type < SOUND_TYPE_SYSTEM || type > SOUND_TYPE_FIXED_CAMCORDING ) {
152 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_PARAMETER);
156 if( path[0] != '/' ){
157 if( getcwd(m_path, PATH_MAX) != NULL){
158 strncat(m_path, "/",PATH_MAX-strlen(m_path) );
161 strncat(m_path, path, PATH_MAX-strlen(m_path));
164 _completed_cb = __internal_complete_cb;
165 cb_data = (_cb_data *)malloc(sizeof(_cb_data));
167 return __convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_OPERATION);
169 cb_data->user_data = user_data;
172 if( type < SOUND_TYPE_FIXED ) {
173 ret = mm_sound_play_solo_sound(m_path, type, _completed_cb , cb_data, &player);
175 int volume_config = VOLUME_TYPE_FIXED;
177 case SOUND_TYPE_FIXED:
178 volume_config |= VOLUME_GAIN_DEFAULT;
180 case SOUND_TYPE_FIXED_AF:
181 volume_config |= VOLUME_GAIN_AF;
183 case SOUND_TYPE_FIXED_SHUTTER1:
184 volume_config |= VOLUME_GAIN_SHUTTER1;
186 case SOUND_TYPE_FIXED_SHUTTER2:
187 volume_config |= VOLUME_GAIN_SHUTTER2;
189 case SOUND_TYPE_FIXED_CAMCORDING:
190 volume_config |= VOLUME_GAIN_CAMCORDING;
195 if (force_to_route_spk) {
196 ret = mm_sound_play_loud_solo_sound(m_path, volume_config, _completed_cb , cb_data, &player);
198 ret = mm_sound_play_solo_sound(m_path, volume_config, _completed_cb , cb_data, &player);
201 if( ret == 0 && id != NULL) {
205 if( ret != 0 && cb_data != NULL) {
209 return __convert_wav_player_error_code(__func__, ret);
212 int wav_player_stop(int id)
214 return __convert_wav_player_error_code(__func__, mm_sound_stop_sound(id));