summaryrefslogtreecommitdiff
path: root/src/lib/ecore_audio
diff options
context:
space:
mode:
authorDaniel Willmann <d.willmann@samsung.com>2013-04-17 20:34:18 +0100
committerDaniel Willmann <d.willmann@samsung.com>2013-04-18 19:16:40 +0100
commitd2326d229e163821b97669145a5dd2741d264bfe (patch)
treed8f2ed225ffd7e61be9aaaba8722536d6720e8b7 /src/lib/ecore_audio
parent6df9640c10f080baf9917bc65de1fba81bc9cf15 (diff)
ecore_audio: Support VIO in sndfile input
Signed-off-by: Daniel Willmann <d.willmann@samsung.com>
Diffstat (limited to 'src/lib/ecore_audio')
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj_in_sndfile.c141
1 files changed, 140 insertions, 1 deletions
diff --git a/src/lib/ecore_audio/ecore_audio_obj_in_sndfile.c b/src/lib/ecore_audio/ecore_audio_obj_in_sndfile.c
index 75eafbdf20..92d7f10a89 100644
--- a/src/lib/ecore_audio/ecore_audio_obj_in_sndfile.c
+++ b/src/lib/ecore_audio/ecore_audio_obj_in_sndfile.c
@@ -23,11 +23,82 @@ struct _Ecore_Audio_Sndfile
23{ 23{
24 SNDFILE *handle; 24 SNDFILE *handle;
25 SF_INFO sfinfo; 25 SF_INFO sfinfo;
26 Ecore_Audio_Vio *vio;
27}; 26};
28 27
29typedef struct _Ecore_Audio_Sndfile Ecore_Audio_Sndfile; 28typedef struct _Ecore_Audio_Sndfile Ecore_Audio_Sndfile;
30 29
30/* Virtual IO wrapper functions */
31
32static sf_count_t _wrap_get_filelen(void *data)
33{
34 Eo *eo_obj = data;
35 Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
36
37 if (!ea_obj->vio->vio)
38 goto error;
39
40 if (ea_obj->vio->vio->get_length)
41 return ea_obj->vio->vio->get_length(ea_obj->vio->data, eo_obj);
42
43error:
44 return -1;
45}
46
47static sf_count_t _wrap_seek(sf_count_t offset, int whence, void *data)
48{
49 Eo *eo_obj = data;
50 Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
51
52 if (!ea_obj->vio->vio)
53 goto error;
54
55 if (ea_obj->vio->vio->seek)
56 return ea_obj->vio->vio->seek(ea_obj->vio->data, eo_obj, offset, whence);
57
58error:
59 return -1;
60}
61
62static sf_count_t _wrap_read(void *buffer, sf_count_t count, void *data)
63{
64 Eo *eo_obj = data;
65 Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
66
67 if (!ea_obj->vio->vio)
68 goto error;
69
70 if (ea_obj->vio->vio->read)
71 return ea_obj->vio->vio->read(ea_obj->vio->data, eo_obj, buffer, count);
72
73error:
74 return 0;
75}
76
77static sf_count_t _wrap_tell(void *data)
78{
79 Eo *eo_obj = data;
80 Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
81
82 if (!ea_obj->vio->vio)
83 goto error;
84
85 if (ea_obj->vio->vio->tell)
86 return ea_obj->vio->vio->tell(ea_obj->vio->data, eo_obj);
87
88error:
89 return -1;
90}
91
92static SF_VIRTUAL_IO vio_wrapper = {
93 .get_filelen = _wrap_get_filelen,
94 .seek = _wrap_seek,
95 .read = _wrap_read,
96 .write = NULL,
97 .tell = _wrap_tell,
98};
99
100/* End virtual IO wrapper functions */
101
31static void _read(Eo *eo_obj, void *_pd, va_list *list) 102static void _read(Eo *eo_obj, void *_pd, va_list *list)
32{ 103{
33 Ecore_Audio_Sndfile *obj = _pd; 104 Ecore_Audio_Sndfile *obj = _pd;
@@ -85,6 +156,7 @@ static void _source_set(Eo *eo_obj, void *_pd, va_list *list)
85 return; 156 return;
86 } 157 }
87 158
159 ea_obj->seekable = EINA_TRUE;
88 in_obj->length = (double)obj->sfinfo.frames / obj->sfinfo.samplerate; 160 in_obj->length = (double)obj->sfinfo.frames / obj->sfinfo.samplerate;
89 161
90 in_obj->samplerate = obj->sfinfo.samplerate; 162 in_obj->samplerate = obj->sfinfo.samplerate;
@@ -151,6 +223,72 @@ static void _format_get(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list)
151 *ret = obj->format; 223 *ret = obj->format;
152} 224}
153 225
226static void _free_vio(Ecore_Audio_Object *ea_obj)
227{
228 if (ea_obj->vio->free_func)
229 ea_obj->vio->free_func(ea_obj->vio->data);
230
231 free(ea_obj->vio);
232 ea_obj->vio = NULL;
233}
234
235static void _vio_set(Eo *eo_obj, void *_pd, va_list *list)
236{
237 Ecore_Audio_Sndfile *obj = _pd;
238 Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
239 Ecore_Audio_Input *in_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_IN_CLASS);
240
241 Ecore_Audio_Vio *vio = va_arg(*list, Ecore_Audio_Vio *);
242 void *data = va_arg(*list, Ecore_Audio_Vio *);
243 eo_base_data_free_func free_func = va_arg(*list, eo_base_data_free_func);
244
245 if (obj->handle) {
246 sf_close(obj->handle);
247 obj->handle = NULL;
248 }
249
250 eina_stringshare_replace(&ea_obj->source, "VIO");
251
252 if (!ea_obj->source)
253 return;
254 if (ea_obj->vio)
255 _free_vio(ea_obj);
256
257 ea_obj->seekable = EINA_FALSE;
258
259 if (!vio)
260 return;
261
262 ea_obj->vio = calloc(1, sizeof(Ecore_Audio_Vio_Internal));
263 ea_obj->vio->vio = vio;
264 ea_obj->vio->data = data;
265 ea_obj->vio->free_func = free_func;
266 ea_obj->seekable = (vio->seek != NULL);
267
268 obj->handle = sf_open_virtual(&vio_wrapper, SFM_READ, &obj->sfinfo, eo_obj);
269
270 if (!obj->handle) {
271 eina_stringshare_del(ea_obj->source);
272 ea_obj->source = NULL;
273 return;
274 }
275
276 ea_obj->seekable = EINA_TRUE;
277 in_obj->length = (double)obj->sfinfo.frames / obj->sfinfo.samplerate;
278
279 in_obj->samplerate = obj->sfinfo.samplerate;
280 in_obj->channels = obj->sfinfo.channels;
281
282 if (obj->sfinfo.format& SF_FORMAT_WAV)
283 ea_obj->format = ECORE_AUDIO_FORMAT_WAV;
284 else if (obj->sfinfo.format& SF_FORMAT_OGG)
285 ea_obj->format = ECORE_AUDIO_FORMAT_OGG;
286 else if (obj->sfinfo.format& SF_FORMAT_FLAC)
287 ea_obj->format = ECORE_AUDIO_FORMAT_FLAC;
288 else
289 ea_obj->format = ECORE_AUDIO_FORMAT_AUTO;
290}
291
154static void _constructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED) 292static void _constructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED)
155{ 293{
156 eo_do_super(eo_obj, MY_CLASS, eo_constructor()); 294 eo_do_super(eo_obj, MY_CLASS, eo_constructor());
@@ -171,6 +309,7 @@ static void _class_constructor(Eo_Class *klass)
171 309
172 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_SEEK), _seek), 310 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_SEEK), _seek),
173 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_READ_INTERNAL), _read), 311 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_READ_INTERNAL), _read),
312 EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_VIO_SET), _vio_set),
174 313
175 EO_OP_FUNC_SENTINEL 314 EO_OP_FUNC_SENTINEL
176 }; 315 };