4 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 #include "tizen-audio-internal.h"
25 #include "tizen-audio-impl.h"
27 audio_return_e _audio_pcm_init(audio_hal_s *ah)
29 AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
31 ah->device.pcm_in = NULL;
32 ah->device.pcm_out = NULL;
33 ah->device.fmradio_pcm_out = NULL;
34 pthread_mutex_init(&ah->device.pcm_lock, NULL);
35 pthread_mutex_init(&ah->device.device_lock, NULL);
36 pthread_cond_init(&ah->device.device_cond, NULL);
37 ah->device.pcm_count = 0;
42 audio_return_e _audio_pcm_deinit(audio_hal_s *ah)
44 AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
46 pthread_mutex_destroy(&ah->device.pcm_lock);
47 pthread_mutex_destroy(&ah->device.device_lock);
48 pthread_cond_destroy(&ah->device.device_cond);
53 audio_return_e audio_pcm_open(void *audio_handle, const char *card, const char *device, uint32_t direction, void *sample_spec,
54 uint32_t period_size, uint32_t periods, void **pcm_handle)
56 audio_return_e audio_ret = AUDIO_RET_OK;
57 audio_hal_s *ah = NULL;
59 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
60 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
61 AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER);
62 AUDIO_RETURN_VAL_IF_FAIL((period_size > 0), AUDIO_ERR_PARAMETER);
63 AUDIO_RETURN_VAL_IF_FAIL((periods > 0), AUDIO_ERR_PARAMETER);
65 if ((audio_ret = _pcm_open(card, device, direction, sample_spec, period_size, periods, pcm_handle)))
68 ah = (audio_hal_s*)audio_handle;
69 ah->device.pcm_count++;
70 AUDIO_LOG_INFO("Opening PCM handle %p", *pcm_handle);
75 audio_return_e audio_pcm_start(void *audio_handle, void *pcm_handle)
77 audio_return_e audio_ret = AUDIO_RET_OK;
79 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
80 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
82 audio_ret = _pcm_start(pcm_handle);
87 audio_return_e audio_pcm_stop(void *audio_handle, void *pcm_handle)
89 audio_return_e audio_ret = AUDIO_RET_OK;
91 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
92 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
94 audio_ret = _pcm_stop(pcm_handle);
99 audio_return_e audio_pcm_close(void *audio_handle, void *pcm_handle)
101 audio_return_e audio_ret = AUDIO_RET_OK;
102 audio_hal_s *ah = NULL;
104 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
105 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
107 if ((audio_ret = _pcm_close(pcm_handle)))
111 ah = (audio_hal_s*)audio_handle;
112 ah->device.pcm_count--;
114 AUDIO_LOG_INFO("PCM handle close success (count:%d)", ah->device.pcm_count);
119 audio_return_e audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *avail)
121 audio_return_e audio_ret = AUDIO_RET_OK;
123 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
124 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
125 AUDIO_RETURN_VAL_IF_FAIL(avail, AUDIO_ERR_PARAMETER);
127 audio_ret = _pcm_avail(pcm_handle, avail);
132 audio_return_e audio_pcm_write(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames)
134 audio_return_e audio_ret = AUDIO_RET_OK;
136 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
137 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
139 audio_ret = _pcm_write(pcm_handle, buffer, frames);
144 audio_return_e audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames)
146 audio_return_e audio_ret = AUDIO_RET_OK;
148 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
149 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
151 audio_ret = _pcm_read(pcm_handle, buffer, frames);
156 audio_return_e audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd)
158 audio_return_e audio_ret = AUDIO_RET_OK;
160 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
161 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
162 AUDIO_RETURN_VAL_IF_FAIL(fd, AUDIO_ERR_PARAMETER);
164 audio_ret = _pcm_get_fd(pcm_handle, fd);
169 audio_return_e audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents)
171 audio_return_e audio_ret = AUDIO_RET_OK;
173 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
174 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
176 audio_ret = _pcm_recover(pcm_handle, revents);
181 audio_return_e audio_pcm_get_params(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t *period_size, uint32_t *periods)
183 audio_return_e audio_ret = AUDIO_RET_OK;
185 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
186 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
187 AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER);
188 AUDIO_RETURN_VAL_IF_FAIL(period_size, AUDIO_ERR_PARAMETER);
189 AUDIO_RETURN_VAL_IF_FAIL(periods, AUDIO_ERR_PARAMETER);
191 audio_ret = _pcm_get_params(pcm_handle, direction, sample_spec, period_size, periods);
196 audio_return_e audio_pcm_set_params(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods)
198 audio_return_e audio_ret = AUDIO_RET_OK;
200 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
201 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
202 AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER);
203 AUDIO_RETURN_VAL_IF_FAIL(period_size, AUDIO_ERR_PARAMETER);
204 AUDIO_RETURN_VAL_IF_FAIL(periods, AUDIO_ERR_PARAMETER);
206 audio_ret = _pcm_set_params(pcm_handle, direction, sample_spec, period_size, periods);