summaryrefslogtreecommitdiff
path: root/src/lib/ecore_audio
diff options
context:
space:
mode:
authorDaniel Willmann <d.willmann@samsung.com>2013-04-17 19:06:21 +0100
committerDaniel Willmann <d.willmann@samsung.com>2013-04-18 19:15:39 +0100
commite89153a21dabae4ce2c3aac870a58c2d20f3b95a (patch)
tree2fe58c978e21d11c0bd6959abd3981fa2bb1b3ca /src/lib/ecore_audio
parentf96ba47976bb5c7c2a8662129602ca1f8e998f28 (diff)
ecore_audio: Implement virtual IO for generic 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.h10
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj.c1
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj.h3
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj_in.c58
-rw-r--r--src/lib/ecore_audio/ecore_audio_private.h10
5 files changed, 74 insertions, 8 deletions
diff --git a/src/lib/ecore_audio/Ecore_Audio.h b/src/lib/ecore_audio/Ecore_Audio.h
index b87f6479cc..c40514091c 100644
--- a/src/lib/ecore_audio/Ecore_Audio.h
+++ b/src/lib/ecore_audio/Ecore_Audio.h
@@ -76,11 +76,11 @@ typedef struct _Ecore_Audio_Object Ecore_Audio_Object; /**< The audio object */
76typedef int (*Ecore_Audio_Read_Callback)(void *user_data, void *data, int len); 76typedef int (*Ecore_Audio_Read_Callback)(void *user_data, void *data, int len);
77 77
78struct _Ecore_Audio_Vio { 78struct _Ecore_Audio_Vio {
79 int (*get_length)(Ecore_Audio_Object *in); 79 int (*get_length)(void *data, Eo *eo_obj);
80 int (*seek)(Ecore_Audio_Object *in, int offset, int whence); 80 int (*seek)(void *data, Eo *eo_obj, int offset, int whence);
81 int (*tell)(Ecore_Audio_Object *in); 81 int (*tell)(void *data, Eo *eo_obj);
82 int (*read)(Ecore_Audio_Object *in, void *buffer, int length); 82 int (*read)(void *data, Eo *eo_obj, void *buffer, int length);
83 int (*write)(Ecore_Audio_Object *out, const void *buffer, int length); 83 int (*write)(void *data, Eo *eo_obj, const void *buffer, int length);
84}; 84};
85 85
86typedef struct _Ecore_Audio_Vio Ecore_Audio_Vio; /**< Functions to implement IO virtually */ 86typedef struct _Ecore_Audio_Vio Ecore_Audio_Vio; /**< Functions to implement IO virtually */
diff --git a/src/lib/ecore_audio/ecore_audio_obj.c b/src/lib/ecore_audio/ecore_audio_obj.c
index aa78c9ccbf..62a784e0f6 100644
--- a/src/lib/ecore_audio/ecore_audio_obj.c
+++ b/src/lib/ecore_audio/ecore_audio_obj.c
@@ -137,6 +137,7 @@ static const Eo_Op_Description op_desc[] = {
137 EO_OP_DESCRIPTION(ECORE_AUDIO_OBJ_SUB_ID_SOURCE_GET, "Gets the source of the object."), 137 EO_OP_DESCRIPTION(ECORE_AUDIO_OBJ_SUB_ID_SOURCE_GET, "Gets the source of the object."),
138 EO_OP_DESCRIPTION(ECORE_AUDIO_OBJ_SUB_ID_FORMAT_SET, "Sets the format of the object."), 138 EO_OP_DESCRIPTION(ECORE_AUDIO_OBJ_SUB_ID_FORMAT_SET, "Sets the format of the object."),
139 EO_OP_DESCRIPTION(ECORE_AUDIO_OBJ_SUB_ID_FORMAT_GET, "Gets the format of the object."), 139 EO_OP_DESCRIPTION(ECORE_AUDIO_OBJ_SUB_ID_FORMAT_GET, "Gets the format of the object."),
140 EO_OP_DESCRIPTION(ECORE_AUDIO_OBJ_SUB_ID_VIO_SET, "Sets virtual IO callbacks for this object."),
140 EO_OP_DESCRIPTION_SENTINEL 141 EO_OP_DESCRIPTION_SENTINEL
141}; 142};
142 143
diff --git a/src/lib/ecore_audio/ecore_audio_obj.h b/src/lib/ecore_audio/ecore_audio_obj.h
index e806e8afd7..87c08b8f25 100644
--- a/src/lib/ecore_audio/ecore_audio_obj.h
+++ b/src/lib/ecore_audio/ecore_audio_obj.h
@@ -51,6 +51,7 @@ enum Ecore_Audio_Obj_Sub_Ids
51 ECORE_AUDIO_OBJ_SUB_ID_SOURCE_GET, 51 ECORE_AUDIO_OBJ_SUB_ID_SOURCE_GET,
52 ECORE_AUDIO_OBJ_SUB_ID_FORMAT_SET, 52 ECORE_AUDIO_OBJ_SUB_ID_FORMAT_SET,
53 ECORE_AUDIO_OBJ_SUB_ID_FORMAT_GET, 53 ECORE_AUDIO_OBJ_SUB_ID_FORMAT_GET,
54 ECORE_AUDIO_OBJ_SUB_ID_VIO_SET,
54 ECORE_AUDIO_OBJ_SUB_ID_LAST 55 ECORE_AUDIO_OBJ_SUB_ID_LAST
55}; 56};
56 57
@@ -92,6 +93,8 @@ enum Ecore_Audio_Obj_Sub_Ids
92 93
93#define ecore_audio_obj_format_get(ret) ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_FORMAT_GET), EO_TYPECHECK(Ecore_Audio_Format *, ret) 94#define ecore_audio_obj_format_get(ret) ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_FORMAT_GET), EO_TYPECHECK(Ecore_Audio_Format *, ret)
94 95
96#define ecore_audio_obj_vio_set(vio, data, free_func) ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_VIO_SET), EO_TYPECHECK(Ecore_Audio_Vio *, vio), EO_TYPECHECK(void *, data), EO_TYPECHECK(eo_base_data_free_func, free_func)
97
95/** 98/**
96 * @} 99 * @}
97 */ 100 */
diff --git a/src/lib/ecore_audio/ecore_audio_obj_in.c b/src/lib/ecore_audio/ecore_audio_obj_in.c
index 983b310e5a..1528a04fa0 100644
--- a/src/lib/ecore_audio/ecore_audio_obj_in.c
+++ b/src/lib/ecore_audio/ecore_audio_obj_in.c
@@ -132,7 +132,9 @@ static void _remaining_get(Eo *eo_obj, void *_pd, va_list *list)
132 132
133 double *ret = va_arg(*list, double *); 133 double *ret = va_arg(*list, double *);
134 134
135 if (ret) { 135 if (!ea_obj->seekable && ret) {
136 *ret = -1;
137 } else if (ret) {
136 eo_do(eo_obj, ecore_audio_obj_in_seek(0, SEEK_CUR, ret)); 138 eo_do(eo_obj, ecore_audio_obj_in_seek(0, SEEK_CUR, ret));
137 *ret = obj->length - *ret; 139 *ret = obj->length - *ret;
138 } 140 }
@@ -154,7 +156,7 @@ static void _read(Eo *eo_obj, void *_pd, va_list *list)
154 } else { 156 } else {
155 eo_do(eo_obj, ecore_audio_obj_in_read_internal(buf, len, &len_read)); 157 eo_do(eo_obj, ecore_audio_obj_in_read_internal(buf, len, &len_read));
156 if (len_read == 0) { 158 if (len_read == 0) {
157 if (!obj->looped) { 159 if (!obj->looped || !ea_obj->seekable) {
158 eo_do(eo_obj, eo_event_callback_call(ECORE_AUDIO_EV_IN_STOPPED, NULL, NULL)); 160 eo_do(eo_obj, eo_event_callback_call(ECORE_AUDIO_EV_IN_STOPPED, NULL, NULL));
159 } else { 161 } else {
160 eo_do(eo_obj, ecore_audio_obj_in_seek(0, SEEK_SET, NULL)); 162 eo_do(eo_obj, ecore_audio_obj_in_seek(0, SEEK_SET, NULL));
@@ -169,6 +171,24 @@ static void _read(Eo *eo_obj, void *_pd, va_list *list)
169 *ret = len_read; 171 *ret = len_read;
170} 172}
171 173
174static void _read_internal(Eo *eo_obj, void *_pd, va_list *list)
175{
176 const Ecore_Audio_Input *obj = _pd;
177 ssize_t len_read = 0;
178 const Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
179
180 char *buf = va_arg(*list, char *);
181 size_t len = va_arg(*list, size_t);
182 ssize_t *ret = va_arg(*list, ssize_t *);
183
184 if (ea_obj->vio && ea_obj->vio->vio->read) {
185 len_read = ea_obj->vio->vio->read(ea_obj->vio->data, eo_obj, buf, len);
186 }
187
188 if (ret)
189 *ret = len_read;
190}
191
172static void _output_get(Eo *eo_obj, void *_pd, va_list *list) 192static void _output_get(Eo *eo_obj, void *_pd, va_list *list)
173{ 193{
174 const Ecore_Audio_Input *obj = _pd; 194 const Ecore_Audio_Input *obj = _pd;
@@ -179,6 +199,37 @@ static void _output_get(Eo *eo_obj, void *_pd, va_list *list)
179 *ret = obj->output; 199 *ret = obj->output;
180} 200}
181 201
202static void _free_vio(Ecore_Audio_Object *ea_obj)
203{
204 if (ea_obj->vio->free_func)
205 ea_obj->vio->free_func(ea_obj->vio->data);
206
207 free(ea_obj->vio);
208 ea_obj->vio = NULL;
209}
210
211static void _vio_set(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list)
212{
213 Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
214
215 Ecore_Audio_Vio *vio = va_arg(*list, Ecore_Audio_Vio *);
216 void *data = va_arg(*list, Ecore_Audio_Vio *);
217 eo_base_data_free_func free_func = va_arg(*list, eo_base_data_free_func);
218
219 if (ea_obj->vio)
220 _free_vio(ea_obj);
221
222 if (!vio)
223 return;
224
225 ea_obj->vio = calloc(1, sizeof(Ecore_Audio_Vio_Internal));
226 ea_obj->vio->vio = vio;
227 ea_obj->vio->data = data;
228 ea_obj->vio->free_func = free_func;
229 //FIXME: Save previous value
230 ea_obj->seekable = (vio->seek != NULL);
231}
232
182static void _constructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED) 233static void _constructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED)
183{ 234{
184 Ecore_Audio_Input *obj = _pd; 235 Ecore_Audio_Input *obj = _pd;
@@ -205,6 +256,8 @@ static void _class_constructor(Eo_Class *klass)
205 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor), 256 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
206 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor), 257 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
207 258
259 EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_VIO_SET), _vio_set),
260
208 /* Specific functions to this class */ 261 /* Specific functions to this class */
209 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_SPEED_SET), _speed_set), 262 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_SPEED_SET), _speed_set),
210 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_SPEED_GET), _speed_get), 263 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_SPEED_GET), _speed_get),
@@ -217,6 +270,7 @@ static void _class_constructor(Eo_Class *klass)
217 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_LENGTH_GET), _length_get), 270 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_LENGTH_GET), _length_get),
218 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_REMAINING_GET), _remaining_get), 271 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_REMAINING_GET), _remaining_get),
219 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_READ), _read), 272 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_READ), _read),
273 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_READ_INTERNAL), _read_internal),
220 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_OUTPUT_GET), _output_get), 274 EO_OP_FUNC(ECORE_AUDIO_OBJ_IN_ID(ECORE_AUDIO_OBJ_IN_SUB_ID_OUTPUT_GET), _output_get),
221 275
222 EO_OP_FUNC_SENTINEL 276 EO_OP_FUNC_SENTINEL
diff --git a/src/lib/ecore_audio/ecore_audio_private.h b/src/lib/ecore_audio/ecore_audio_private.h
index 7868b08b5f..e899a04254 100644
--- a/src/lib/ecore_audio/ecore_audio_private.h
+++ b/src/lib/ecore_audio/ecore_audio_private.h
@@ -91,6 +91,13 @@ struct _Ecore_Audio_Module
91 struct output_api *out_ops; 91 struct output_api *out_ops;
92}; 92};
93 93
94struct _Ecore_Audio_Vio_Internal {
95 Ecore_Audio_Vio *vio;
96 void *data;
97 eo_base_data_free_func free_func;
98};
99typedef struct _Ecore_Audio_Vio_Internal Ecore_Audio_Vio_Internal;
100
94/** 101/**
95 * @brief A common structure, could be input or output 102 * @brief A common structure, could be input or output
96 */ 103 */
@@ -99,10 +106,11 @@ struct _Ecore_Audio_Object
99 const char *name; 106 const char *name;
100 const char *source; 107 const char *source;
101 108
109 Eina_Bool seekable;
102 Eina_Bool paused; 110 Eina_Bool paused;
103 double volume; 111 double volume;
104 Ecore_Audio_Format format; 112 Ecore_Audio_Format format;
105 113 Ecore_Audio_Vio_Internal *vio;
106}; 114};
107 115
108/** 116/**