Initialize Tizen 2.3
[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  * Contact: Hyunseok Lee <hs7388.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include "tizen-audio-internal.h"
27
28 int audio_get_revision (void)
29 {
30     return AUDIO_REVISION;
31 }
32
33 audio_return_t audio_init (void **userdata)
34 {
35     audio_mgr_t *am;
36     audio_return_t ret = AUDIO_RET_OK;
37
38     if (!(am = malloc(sizeof(audio_mgr_t)))) {
39         AUDIO_LOG_ERROR("am malloc failed");
40         return AUDIO_ERR_RESOURCE;
41     }
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_util_init(am)))) {
55         AUDIO_LOG_ERROR("mixer init failed");
56         goto error_exit;
57     }
58
59     *userdata = (void *)am;
60     return AUDIO_RET_OK;
61
62 error_exit:
63     if (am)
64         free(am);
65
66     return ret;
67 }
68
69 audio_return_t audio_deinit (void **userdata)
70 {
71     audio_mgr_t *am = (audio_mgr_t *)*userdata;
72  
73     if (am) {
74         _audio_session_deinit(am);
75         _audio_device_deinit(am);
76         _audio_stream_deinit(am);
77         _audio_util_deinit(am);
78         free(am);
79         *userdata = NULL;
80     }
81
82     return AUDIO_RET_OK;
83 }
84
85 audio_return_t audio_reset (void **userdata)
86 {
87     audio_mgr_t *am = (audio_mgr_t *)*userdata;
88     audio_return_t ret = AUDIO_RET_OK;
89
90     if (am) {
91         _audio_device_deinit(am);
92         _audio_stream_deinit(am);
93         _audio_util_deinit(am);
94
95         if (AUDIO_IS_ERROR((ret = _audio_session_init(am)))) {
96             AUDIO_LOG_ERROR("session init failed");
97             goto error_exit;
98         }
99         if (AUDIO_IS_ERROR((ret = _audio_device_init(am)))) {
100             AUDIO_LOG_ERROR("device init failed");
101             goto error_exit;
102         }
103         if (AUDIO_IS_ERROR((ret = _audio_stream_init(am)))) {
104             AUDIO_LOG_ERROR("stream init failed");
105             goto error_exit;
106         }
107         if (AUDIO_IS_ERROR((ret = _audio_util_init(am)))) {
108             AUDIO_LOG_ERROR("mixer init failed");
109             goto error_exit;
110         }
111     }
112
113     return AUDIO_RET_OK;
114
115 error_exit:
116     if (am)
117         free(am);
118     *userdata = NULL;
119
120     return ret;
121 }