2 * Copyright (c) 2011-2016 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.
17 #define LOG_TAG "TIZEN_N_WAV_PLAYER"
20 #include <mm_sound_private.h>
27 #include "wav_player_private.h"
29 int _convert_wav_player_error_code(const char *func, int code)
31 int ret = WAV_PLAYER_ERROR_INVALID_OPERATION;
32 char *errorstr = NULL;
35 ret = WAV_PLAYER_ERROR_NONE;
36 errorstr = "ERROR_NONE";
38 case MM_ERROR_INVALID_ARGUMENT:
39 case MM_ERROR_SOUND_INVALID_POINTER:
40 case WAV_PLAYER_ERROR_INVALID_PARAMETER:
41 ret = WAV_PLAYER_ERROR_INVALID_PARAMETER;
42 errorstr = "INVALID_PARAMETER";
44 case MM_ERROR_SOUND_INTERNAL:
45 ret = WAV_PLAYER_ERROR_INVALID_OPERATION;
46 errorstr = "INVALID_OPERATION";
48 case MM_ERROR_SOUND_UNSUPPORTED_MEDIA_TYPE:
49 ret = WAV_PLAYER_ERROR_FORMAT_NOT_SUPPORTED;
50 errorstr = "FORMAT_NOT_SUPPORTED";
52 case WAV_PLAYER_ERROR_NOT_SUPPORTED_TYPE:
53 ret = WAV_PLAYER_ERROR_NOT_SUPPORTED_TYPE;
54 errorstr = "NOT_SUPPORTED_TYPE";
57 ret = WAV_PLAYER_ERROR_INVALID_OPERATION;
58 errorstr = "INVALID_OPERATION";
61 LOGE("[%s] %s(0x%08x)", func, errorstr, ret);
65 void _internal_complete_cb(void *user_data, int id)
67 _cb_data *cb_data = (_cb_data*)user_data;
72 LOGD("user callback for handle %d call %p", id, cb_data->cb);
73 cb_data->cb(id, cb_data->user_data);
78 int _start_with_stream_info(const char *path, sound_stream_info_h stream_info, unsigned loop_count, wav_player_playback_completed_cb callback, void *user_data, int *id)
80 int ret = MM_ERROR_NONE;
82 char m_path[PATH_MAX];
83 void (*_completed_cb)(void *, int);
85 _cb_data *cb_data = NULL;
86 char *stream_type = NULL;
90 if (path == NULL || stream_info == NULL)
91 return _convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_PARAMETER);
93 ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_WAV_PLAYER, &result);
95 return _convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_NOT_SUPPORTED_TYPE);
97 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
99 return _convert_wav_player_error_code(__func__, ret); //LCOV_EXCL_LINE
100 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_id);
102 return _convert_wav_player_error_code(__func__, ret); //LCOV_EXCL_LINE
105 if (path[0] != '/') {
107 if (getcwd(m_path, PATH_MAX) != NULL)
108 strncat(m_path, "/", PATH_MAX - strlen(m_path) - 1);
110 strncat(m_path, path, PATH_MAX - strlen(m_path) - 1);
113 _completed_cb = _internal_complete_cb;
114 cb_data = (_cb_data *)malloc(sizeof(_cb_data));
116 return _convert_wav_player_error_code(__func__, WAV_PLAYER_ERROR_INVALID_OPERATION); //LCOV_EXCL_LINE
117 cb_data->cb = callback;
118 cb_data->user_data = user_data;
121 ret = mm_sound_play_sound_with_stream_info(m_path, stream_type, stream_id, loop_count, _completed_cb , cb_data, &player);
123 if (ret == 0 && id != NULL)
126 if (ret != 0 && cb_data != NULL)
129 return _convert_wav_player_error_code(__func__, ret);