8447e309101e089fbf9c6327853719a11d1b35bd
[platform/core/api/tone-player.git] / src / tone_player.c
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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. 
15 */
16
17
18
19
20 #define LOG_TAG "CAPI_MEDIA_TONE_PLAYER"
21
22 #include <sound_manager.h>
23 #include <tone_player.h>
24 #include <mm_sound.h>
25 #include <mm_sound_private.h>
26 #include <stdio.h>
27 #include <limits.h>
28 #include <string.h>
29 #include <unistd.h>
30 #include <dlog.h>
31
32
33 static int __convert_tone_player_error_code(const char *func, int code){
34         int ret = TONE_PLAYER_ERROR_NONE;
35         char *errorstr = NULL;
36         switch(code)
37         {
38                 case MM_ERROR_NONE:
39                         ret = TONE_PLAYER_ERROR_NONE;
40                         errorstr = "ERROR_NONE";
41                         break;
42                 case TONE_PLAYER_ERROR_INVALID_PARAMETER:
43                 case MM_ERROR_INVALID_ARGUMENT: 
44                 case MM_ERROR_SOUND_INVALID_POINTER:
45                         ret = TONE_PLAYER_ERROR_INVALID_PARAMETER;
46                         errorstr = "INVALID_PARAMETER";
47                         break;
48                 case MM_ERROR_SOUND_INTERNAL:
49                         ret = TONE_PLAYER_ERROR_INVALID_OPERATION;
50                         errorstr = "INVALID_OPERATION";
51                         break;
52         }
53         LOGE( "[%s] %s(0x%08x) : core frameworks error code(0x%08x)",func, errorstr, ret, code);
54         return ret;
55 }
56
57 int tone_player_start(tone_type_e tone, sound_type_e type, int duration, int *id){
58         int ret;
59         int player;
60         if( tone < TONE_TYPE_DEFAULT || tone > TONE_TYPE_USER_DEFINED_HIGH_FRE )
61                 return __convert_tone_player_error_code(__func__, TONE_PLAYER_ERROR_INVALID_PARAMETER);
62
63         ret = mm_sound_play_tone(tone, type , 1, duration, &player);
64
65         if( ret == 0 && id != NULL)
66                 *id = player;
67         return __convert_tone_player_error_code(__func__, ret);
68 }
69
70
71 int tone_player_stop(int id){
72         return __convert_tone_player_error_code(__func__, mm_sound_stop_sound(id));
73 }
74