tizen 2.3 release
[adaptation/ap_samsung/audio-hal-e4x12.git] / tizen-audio.c
1 /*
2  * audio-hal
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include "tizen-audio-internal.h"
25
26 int audio_get_revision (void)
27 {
28     return AUDIO_REVISION;
29 }
30
31 audio_return_t audio_init (void **userdata, void *platform_data)
32 {
33     audio_mgr_t *am;
34     audio_return_t ret = AUDIO_RET_OK;
35
36     if (!(am = malloc(sizeof(audio_mgr_t)))) {
37         AUDIO_LOG_ERROR("am malloc failed");
38         return AUDIO_ERR_RESOURCE;
39     }
40     am->platform_data = platform_data;
41     memset(&am->cb_intf, 0, sizeof(audio_cb_interface_t));
42     if (AUDIO_IS_ERROR((ret = _audio_session_init(am)))) {
43         AUDIO_LOG_ERROR("session init failed");
44         goto error_exit;
45     }
46     if (AUDIO_IS_ERROR((ret = _audio_device_init(am)))) {
47         AUDIO_LOG_ERROR("device init failed");
48         goto error_exit;
49     }
50     if (AUDIO_IS_ERROR((ret = _audio_stream_init(am)))) {
51         AUDIO_LOG_ERROR("stream init failed");
52         goto error_exit;
53     }
54     if (AUDIO_IS_ERROR((ret = _audio_ucm_init(am)))) {
55         AUDIO_LOG_ERROR("ucm init failed");
56         goto error_exit;
57     }
58     if (AUDIO_IS_ERROR((ret = _audio_util_init(am)))) {
59         AUDIO_LOG_ERROR("mixer init failed");
60         goto error_exit;
61     }
62
63     *userdata = (void *)am;
64     return AUDIO_RET_OK;
65
66 error_exit:
67     if (am)
68         free(am);
69
70     return ret;
71 }
72
73 audio_return_t audio_deinit (void **userdata)
74 {
75     audio_mgr_t *am = (audio_mgr_t *)*userdata;
76  
77     if (am) {
78         _audio_session_deinit(am);
79         _audio_device_deinit(am);
80         _audio_stream_deinit(am);
81         _audio_ucm_deinit(am);
82         _audio_util_deinit(am);
83         free(am);
84         *userdata = NULL;
85     }
86
87     return AUDIO_RET_OK;
88 }
89
90 /* this function is only called from audio tuning app for updating volume */
91 audio_return_t audio_reset (void **userdata)
92 {
93     audio_mgr_t *am = (audio_mgr_t *)*userdata;
94     audio_return_t ret = AUDIO_RET_OK;
95
96     if (am) {
97         _audio_stream_deinit(am);
98
99         if (AUDIO_IS_ERROR((ret = _audio_stream_init(am)))) {
100             AUDIO_LOG_ERROR("stream init failed");
101             goto error_exit;
102         }
103     }
104
105     return AUDIO_RET_OK;
106
107 error_exit:
108     if (am)
109         free(am);
110     *userdata = NULL;
111
112     return ret;
113 }
114
115 audio_return_t audio_set_callback (void *userdata, audio_cb_interface_t *cb_interface)
116 {
117     audio_mgr_t *am = (audio_mgr_t *)userdata;
118
119     if (am) {
120         memcpy(&am->cb_intf, cb_interface, sizeof(audio_cb_interface_t));
121         return AUDIO_RET_OK;
122     } else {
123         return AUDIO_ERR_PARAMETER;
124     }
125 }