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.
20 #define LOG_TAG "CAPI_MEDIA_TONE_PLAYER"
22 #include <sound_manager.h>
23 #include <sound_manager_internal.h>
24 #include <tone_player.h>
26 #include <mm_sound_private.h>
34 static int __convert_tone_player_error_code(const char *func, int code){
35 int ret = TONE_PLAYER_ERROR_NONE;
36 char *errorstr = NULL;
40 ret = TONE_PLAYER_ERROR_NONE;
41 errorstr = "ERROR_NONE";
43 case TONE_PLAYER_ERROR_INVALID_PARAMETER:
44 case MM_ERROR_INVALID_ARGUMENT:
45 case MM_ERROR_SOUND_INVALID_POINTER:
46 ret = TONE_PLAYER_ERROR_INVALID_PARAMETER;
47 errorstr = "INVALID_PARAMETER";
49 case MM_ERROR_SOUND_INTERNAL:
50 ret = TONE_PLAYER_ERROR_INVALID_OPERATION;
51 errorstr = "INVALID_OPERATION";
54 LOGE( "[%s] %s(0x%08x) : core frameworks error code(0x%08x)",func, errorstr, ret, code);
58 int tone_player_start(tone_type_e tone, sound_type_e type, int duration, int *id){
61 if( tone < TONE_TYPE_DEFAULT || tone > TONE_TYPE_USER_DEFINED_HIGH_FRE )
62 return __convert_tone_player_error_code(__func__, TONE_PLAYER_ERROR_INVALID_PARAMETER);
64 ret = mm_sound_play_tone(tone, type , 1, duration, &player);
66 if( ret == 0 && id != NULL)
68 return __convert_tone_player_error_code(__func__, ret);
71 int tone_player_start_with_stream_info(tone_type_e tone, sound_stream_info_h stream_info, int duration, int * id){
75 char *stream_type = NULL;
78 if( tone < TONE_TYPE_DEFAULT || tone > TONE_TYPE_USER_DEFINED_HIGH_FRE )
79 return __convert_tone_player_error_code(__func__, TONE_PLAYER_ERROR_INVALID_PARAMETER);
81 ret = sound_manager_get_type_from_stream_information(stream_info, &stream_type);
83 return __convert_tone_player_error_code(__func__, ret);
84 ret = sound_manager_get_index_from_stream_information(stream_info, &stream_id);
86 return __convert_tone_player_error_code(__func__, ret);
88 ret = mm_sound_play_tone_with_stream_info(tone, stream_type, stream_id, vol, duration, &player);
90 if( ret == 0 && id != NULL)
93 return __convert_tone_player_error_code(__func__, ret);
98 int tone_player_stop(int id){
99 return __convert_tone_player_error_code(__func__, mm_sound_stop_sound(id));