4 * Copyright (c) 2023 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.
28 #include <sys/types.h>
30 #include <tizen-audio.h>
31 #include <tizen-audio-internal.h>
32 #include <hal/hal-common-interface.h>
33 #include <tizen-audio-file.h>
35 audio_return_e audio_file_open(const char *type, const char *filename, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods, void **handle)
38 audio_pcm_sample_spec_s ss;
40 AUDIO_RETURN_VAL_IF_FAIL(type, AUDIO_ERR_PARAMETER);
41 AUDIO_RETURN_VAL_IF_FAIL(filename, AUDIO_ERR_PARAMETER);
42 AUDIO_RETURN_VAL_IF_FAIL(sample_spec, AUDIO_ERR_PARAMETER);
43 AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER);
45 /* TODO: FIXME format will contains a wrong value */
46 ss = *(audio_pcm_sample_spec_s *)sample_spec;
48 if (ss.rate != 16000) {
49 AUDIO_LOG_ERROR("Not support rate. rate(%d)", ss.rate);
50 return AUDIO_ERR_PARAMETER;
53 if (ss.channels != 1) {
54 AUDIO_LOG_ERROR("Not support channels. channels(%d)", ss.channels);
55 return AUDIO_ERR_PARAMETER;
59 if (ss.format != SND_PCM_FORMAT_S16_LE) {
60 AUDIO_LOG_ERROR("Not support format");
61 return AUDIO_ERR_PARAMETER;
65 f = fopen(filename, "r");
67 AUDIO_LOG_ERROR("Failed to open file name(%s)", filename);
68 return AUDIO_ERR_INTERNAL;
76 audio_return_e audio_file_start(void *handle)
78 AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER);
80 AUDIO_LOG_DEBUG("file start was called");
85 audio_return_e audio_file_stop(void *handle)
87 AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER);
89 AUDIO_LOG_DEBUG("file stop was called");
94 audio_return_e audio_file_close(void *handle)
98 AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER);
107 audio_return_e audio_file_avail(void *handle, uint32_t *avail)
112 AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER);
118 AUDIO_LOG_ERROR("Failed to get ftell(%s)", strerror(errno));
119 return AUDIO_ERR_INTERNAL;
122 if (fseek(f, 0L, SEEK_END) < 0) {
123 AUDIO_LOG_ERROR("Failed to seek. err(%s)", strerror(errno));
124 return AUDIO_ERR_INTERNAL;
129 AUDIO_LOG_ERROR("Failed to get ftell(%s)", strerror(errno));
130 return AUDIO_ERR_INTERNAL;
133 if (fseek(f, cur, SEEK_SET) < 0) {
134 AUDIO_LOG_ERROR("Failed to seek. err(%s)", strerror(errno));
135 return AUDIO_ERR_INTERNAL;
143 audio_return_e audio_file_write(void *handle, const void *buffer, uint32_t frames)
148 AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER);
152 ret = fwrite(buffer, sizeof(short), frames, f);
154 AUDIO_LOG_ERROR("Failed to write(%s)", strerror(errno));
155 return AUDIO_ERR_INTERNAL;
161 audio_return_e audio_file_read(void *handle, void *buffer, uint32_t frames)
166 AUDIO_RETURN_VAL_IF_FAIL(handle, AUDIO_ERR_PARAMETER);
170 ret = fread(buffer, sizeof(short), frames, f);
172 AUDIO_LOG_ERROR("Failed to read(%s)", strerror(errno));
173 return AUDIO_ERR_INTERNAL;
179 audio_return_e audio_file_get_fd(void *handle, int *fd)
181 return AUDIO_ERR_IOCTL;
184 audio_return_e audio_file_recover(void *handle, int revents)
186 return AUDIO_ERR_IOCTL;
189 audio_return_e audio_file_get_params(void *handle, uint32_t direction, void *sample_spec, uint32_t *period_size, uint32_t *periods)
191 return AUDIO_ERR_IOCTL;
194 audio_return_e audio_file_set_params(void *handle, uint32_t direction, void *sample_spec, uint32_t period_size, uint32_t periods)
196 return AUDIO_ERR_IOCTL;