3 * Copyright 2012 Samsung Electronics S.LSI Co. LTD
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 * @author Yunji Kim (yunji.kim@samsung.com)
27 #include <sys/types.h>
29 #include <sys/ioctl.h>
42 #define LOG_TAG "libsrpapi"
44 #ifndef TIZEN_FEATURE_E3250 /* build env */
45 #include <utils/Log.h>
47 #include "Exynos_OSAL_Log.h"
50 static struct srp_buf_info ibuf_info;
51 static struct srp_buf_info obuf_info;
52 static struct srp_buf_info pcm_info;
54 static int srp_dev = -1;
55 static int srp_block_mode = SRP_INIT_BLOCK_MODE;
57 int SRP_Create(int block_mode)
60 srp_block_mode = block_mode;
61 srp_dev = open(SRP_DEV_NAME, O_RDWR |
62 ((block_mode == SRP_INIT_NONBLOCK_MODE) ? O_NDELAY : 0));
66 return SRP_ERROR_OPEN_FAIL;
69 ALOGE("%s: Device is already opened", __func__);
70 return SRP_ERROR_ALREADY_OPEN;
75 int ret = SRP_RETURN_OK;
76 unsigned int mmapped_size = 0;
79 ret = ioctl(srp_dev, SRP_INIT);
84 ret = ioctl(srp_dev, SRP_GET_MMAP_SIZE, &mmapped_size);
86 ALOGE("%s: SRP_GET_MMAP_SIZE is failed", __func__);
87 return SRP_ERROR_OBUF_MMAP;
89 obuf_info.mmapped_addr = mmap(0, mmapped_size,
90 PROT_READ | PROT_WRITE, MAP_SHARED, srp_dev, 0);
91 if (!obuf_info.mmapped_addr) {
92 ALOGE("%s: mmap is failed", __func__);
93 return SRP_ERROR_OBUF_MMAP;
95 obuf_info.mmapped_size = mmapped_size;
99 ALOGE("%s: Device is not ready", __func__);
100 ret = SRP_ERROR_NOT_READY; /* device is not created */
106 int SRP_Decode(void *buff, int size_byte)
108 int ret = SRP_RETURN_OK;
112 ALOGV("%s: Send data to RP (%d bytes)", __func__, size_byte);
114 ret = write(srp_dev, buff, size_byte); /* Write Buffer to RP Driver */
116 #ifdef TIZEN_FEATURE_E3250
117 /* ret value is different from android. this is caused from glib. android uses bionic libc. */
120 if (ret != SRP_ERROR_IBUF_OVERFLOW)
121 ALOGE("SRP_Decode returned error code: %d", ret);
123 return ret; /* Write Success */
129 ALOGE("%s: Device is not ready", __func__);
130 return SRP_ERROR_NOT_READY;
133 int SRP_Send_EOS(void)
136 return ioctl(srp_dev, SRP_SEND_EOS);
138 return SRP_ERROR_NOT_READY;
141 int SRP_SetParams(int id, unsigned long val)
144 return 0; /* not yet */
146 return SRP_ERROR_NOT_READY;
149 int SRP_GetParams(int id, unsigned long *pval)
152 return ioctl(srp_dev, id, pval);
154 return SRP_ERROR_NOT_READY;
160 return ioctl(srp_dev, SRP_FLUSH);
162 return SRP_ERROR_NOT_READY;
165 int SRP_Get_PCM(void **addr, unsigned int *size)
167 int ret = SRP_RETURN_OK;
170 ret = read(srp_dev, &pcm_info, 0);
173 ALOGE("%s: PCM read fail", __func__);
174 return SRP_ERROR_OBUF_READ;
177 *addr = pcm_info.addr;
178 *size = pcm_info.size;
180 return SRP_ERROR_NOT_READY;
183 return ret; /* Read Success */
186 int SRP_Get_Dec_Info(struct srp_dec_info *dec_info)
191 ret = ioctl(srp_dev, SRP_GET_DEC_INFO, dec_info);
193 ALOGE("%s: Failed to get dec info", __func__);
194 return SRP_ERROR_GETINFO_FAIL;
197 ALOGV("numChannels(%d), samplingRate(%d)", dec_info->channels, dec_info->sample_rate);
201 ret = SRP_ERROR_NOT_READY;
207 int SRP_Get_Ibuf_Info(void **addr, unsigned int *size, unsigned int *num)
209 int ret = SRP_RETURN_OK;
212 ret = ioctl(srp_dev, SRP_GET_IBUF_INFO, &ibuf_info);
214 ALOGE("%s: Failed to get Ibuf info", __func__);
215 return SRP_ERROR_IBUF_INFO;
218 *addr = ibuf_info.addr;
219 *size = ibuf_info.size;
220 *num = ibuf_info.num;
223 ALOGE("%s: IBUF num is 0", __func__);
224 return SRP_ERROR_INVALID_SETTING;
229 ret = SRP_ERROR_NOT_READY;
235 int SRP_Get_Obuf_Info(void **addr, unsigned int *size, unsigned int *num)
237 int ret = SRP_RETURN_OK;
240 if (obuf_info.addr == NULL) {
241 ret = ioctl(srp_dev, SRP_GET_OBUF_INFO, &obuf_info);
243 ALOGE("%s: SRP_GET_OBUF_INFO is failed", __func__);
244 return SRP_ERROR_OBUF_INFO;
248 *addr = obuf_info.addr;
249 *size = obuf_info.size;
250 *num = obuf_info.num;
253 ALOGE("%s: OBUF num is 0", __func__);
254 return SRP_ERROR_INVALID_SETTING;
259 ret = SRP_ERROR_NOT_READY;
268 munmap(obuf_info.mmapped_addr, obuf_info.mmapped_size);
269 return ioctl(srp_dev, SRP_DEINIT);
272 return SRP_ERROR_NOT_READY;
275 int SRP_Terminate(void)
280 ret = close(srp_dev);
283 srp_dev = -1; /* device closed */
284 return SRP_RETURN_OK;
288 return SRP_ERROR_NOT_READY;
294 ALOGV("%s: Device is not opened", __func__);
298 ALOGV("%s: Device is opened", __func__);