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_t _audio_pcm_init(audio_hal_t *ah)
29 AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
31 ah->device.pcm_in = NULL;
32 ah->device.pcm_out = NULL;
33 pthread_mutex_init(&ah->device.pcm_lock, NULL);
34 ah->device.pcm_count = 0;
39 audio_return_t _audio_pcm_deinit(audio_hal_t *ah)
41 AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
43 pthread_mutex_destroy(&ah->device.pcm_lock);
48 audio_return_t audio_pcm_open(void *audio_handle, const char *card, const char *device, uint32_t direction, void *sample_spec,
49 uint32_t period_size, uint32_t periods, void **pcm_handle)
51 audio_return_t audio_ret = AUDIO_RET_OK;
52 audio_hal_t *ah = NULL;
54 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
55 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
56 AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER);
57 AUDIO_RETURN_VAL_IF_FAIL((period_size > 0), AUDIO_ERR_PARAMETER);
58 AUDIO_RETURN_VAL_IF_FAIL((periods > 0), AUDIO_ERR_PARAMETER);
60 if ((audio_ret = _pcm_open(card, device, direction, sample_spec, period_size, periods, pcm_handle)))
63 ah = (audio_hal_t*)audio_handle;
64 ah->device.pcm_count++;
65 AUDIO_LOG_INFO("Opening PCM handle %p", *pcm_handle);
70 audio_return_t audio_pcm_start(void *audio_handle, void *pcm_handle)
72 audio_return_t audio_ret = AUDIO_RET_OK;
74 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
75 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
77 audio_ret = _pcm_start(pcm_handle);
82 audio_return_t audio_pcm_stop(void *audio_handle, void *pcm_handle)
84 audio_return_t audio_ret = AUDIO_RET_OK;
86 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
87 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
89 audio_ret = _pcm_stop(pcm_handle);
94 audio_return_t audio_pcm_close(void *audio_handle, void *pcm_handle)
96 audio_return_t audio_ret = AUDIO_RET_OK;
97 audio_hal_t *ah = NULL;
99 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
100 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
102 if ((audio_ret = _pcm_close(pcm_handle)))
106 ah = (audio_hal_t*)audio_handle;
107 ah->device.pcm_count--;
109 AUDIO_LOG_INFO("PCM handle close success (count:%d)", ah->device.pcm_count);
114 audio_return_t audio_pcm_avail(void *audio_handle, void *pcm_handle, uint32_t *avail)
116 audio_return_t audio_ret = AUDIO_RET_OK;
118 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
119 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
120 AUDIO_RETURN_VAL_IF_FAIL(avail, AUDIO_ERR_PARAMETER);
122 audio_ret = _pcm_avail(pcm_handle, avail);
127 audio_return_t audio_pcm_write(void *audio_handle, void *pcm_handle, const void *buffer, uint32_t frames)
129 audio_return_t audio_ret = AUDIO_RET_OK;
131 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
132 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
134 audio_ret = _pcm_write(pcm_handle, buffer, frames);
139 audio_return_t audio_pcm_read(void *audio_handle, void *pcm_handle, void *buffer, uint32_t frames)
141 audio_return_t audio_ret = AUDIO_RET_OK;
143 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
144 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
146 audio_ret = _pcm_read(pcm_handle, buffer, frames);
151 audio_return_t audio_pcm_get_fd(void *audio_handle, void *pcm_handle, int *fd)
153 audio_return_t audio_ret = AUDIO_RET_OK;
155 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
156 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
157 AUDIO_RETURN_VAL_IF_FAIL(fd, AUDIO_ERR_PARAMETER);
159 audio_ret = _pcm_get_fd(pcm_handle, fd);
164 audio_return_t audio_pcm_recover(void *audio_handle, void *pcm_handle, int revents)
166 audio_return_t audio_ret = AUDIO_RET_OK;
168 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
169 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
171 audio_ret = _pcm_recover(pcm_handle, revents);
176 audio_return_t audio_pcm_get_params(void *audio_handle, void *pcm_handle, uint32_t direction, void **sample_spec, uint32_t *period_size, uint32_t *periods)
178 audio_return_t audio_ret = AUDIO_RET_OK;
180 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
181 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
182 AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER);
183 AUDIO_RETURN_VAL_IF_FAIL(period_size, AUDIO_ERR_PARAMETER);
184 AUDIO_RETURN_VAL_IF_FAIL(periods, AUDIO_ERR_PARAMETER);
186 audio_ret = _pcm_get_params(pcm_handle, direction, sample_spec, period_size, periods);
191 audio_return_t audio_pcm_set_params(void *audio_handle, void *pcm_handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods)
193 audio_return_t audio_ret = AUDIO_RET_OK;
195 AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
196 AUDIO_RETURN_VAL_IF_FAIL(pcm_handle, AUDIO_ERR_PARAMETER);
197 AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER);
198 AUDIO_RETURN_VAL_IF_FAIL(period_size, AUDIO_ERR_PARAMETER);
199 AUDIO_RETURN_VAL_IF_FAIL(periods, AUDIO_ERR_PARAMETER);
201 audio_ret = _pcm_set_params(pcm_handle, direction, sample_spec, period_size, periods);