summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Willmann <d.willmann@samsung.com>2013-04-26 18:32:18 +0100
committerDaniel Willmann <d.willmann@samsung.com>2013-04-26 18:49:24 +0100
commit6c7dbf67afb12ba8e1c1b7f9433b14e0dc00a94c (patch)
treec4201b1f317c3a79f20d5e73d85be5770d81c9f1 /src
parent72870c0b6ebc564cff283ce7549972bccd79e6df (diff)
ecore_audio: Add vio_set method / write cb to output
ecore_audio_obj_out now also supports VIO. Add attribute need_writer so we can generalize the idler creation for subclasses at a later time. Signed-off-by: Daniel Willmann <d.willmann@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj_out.c77
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj_out_pulse.c3
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj_out_sndfile.c5
-rw-r--r--src/lib/ecore_audio/ecore_audio_private.h1
4 files changed, 82 insertions, 4 deletions
diff --git a/src/lib/ecore_audio/ecore_audio_obj_out.c b/src/lib/ecore_audio/ecore_audio_obj_out.c
index c463240..4707c4e 100644
--- a/src/lib/ecore_audio/ecore_audio_obj_out.c
+++ b/src/lib/ecore_audio/ecore_audio_obj_out.c
@@ -19,11 +19,45 @@ EAPI Eo_Op ECORE_AUDIO_OBJ_OUT_BASE_ID = EO_NOOP;
19#define MY_CLASS ECORE_AUDIO_OBJ_OUT_CLASS 19#define MY_CLASS ECORE_AUDIO_OBJ_OUT_CLASS
20#define MY_CLASS_NAME "ecore_audio_obj_out" 20#define MY_CLASS_NAME "ecore_audio_obj_out"
21 21
22static Eina_Bool _write_cb(void *data)
23{
24 Eo *eo_obj = data;
25 Eo *in;
26
27 Ecore_Audio_Output *out_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_OUT_CLASS);
28 Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
29
30 ssize_t written, bread;
31 float buf[1024];
32
33 if (!ea_obj->vio || !ea_obj->vio->vio->write)
34 return EINA_FALSE;
35
36 /* FIXME: Multiple inputs */
37 in = eina_list_data_get(out_obj->inputs);
38
39 eo_do(in, ecore_audio_obj_in_read(buf, 4*1024, &bread));
40
41 if (bread == 0) {
42 ea_obj->paused = EINA_TRUE;
43 out_obj->write_idler = NULL;
44 return EINA_FALSE;
45 }
46 written = ea_obj->vio->vio->write(ea_obj->vio->data, eo_obj, buf, bread);
47
48 if (written != bread)
49 ERR("Short write");
50
51 return EINA_TRUE;
52}
53
22static void _input_attach(Eo *eo_obj, void *_pd, va_list *list) 54static void _input_attach(Eo *eo_obj, void *_pd, va_list *list)
23{ 55{
24 Ecore_Audio_Output *obj = _pd; 56 Ecore_Audio_Output *obj = _pd;
25 Ecore_Audio_Input *in; 57 Ecore_Audio_Input *in;
26 58
59 Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
60
27 Eo *input = va_arg(*list, Eo *); 61 Eo *input = va_arg(*list, Eo *);
28 Eina_Bool *ret = va_arg(*list, Eina_Bool *); 62 Eina_Bool *ret = va_arg(*list, Eina_Bool *);
29 63
@@ -38,12 +72,15 @@ static void _input_attach(Eo *eo_obj, void *_pd, va_list *list)
38 if (in->output) eo_do(in->output, ecore_audio_obj_out_input_detach(input, NULL)); 72 if (in->output) eo_do(in->output, ecore_audio_obj_out_input_detach(input, NULL));
39 in->output = eo_obj; 73 in->output = eo_obj;
40 74
41 /* TODO: Check type is input 75 /* TODO: Send event */
42 * Get private data
43 * Send event */
44 76
45 obj->inputs = eina_list_append(obj->inputs, input); 77 obj->inputs = eina_list_append(obj->inputs, input);
46 78
79 if (obj->need_writer &&
80 ea_obj->vio && ea_obj->vio->vio->write)
81 obj->write_idler = ecore_idler_add(_write_cb, eo_obj);
82
83
47 if (ret) 84 if (ret)
48 *ret = EINA_TRUE; 85 *ret = EINA_TRUE;
49} 86}
@@ -86,11 +123,42 @@ static void _inputs_get(Eo *eo_obj EINA_UNUSED, void *_pd, va_list *list)
86 *inputs = obj->inputs; 123 *inputs = obj->inputs;
87} 124}
88 125
126static void _free_vio(Ecore_Audio_Object *ea_obj)
127{
128 if (ea_obj->vio->free_func)
129 ea_obj->vio->free_func(ea_obj->vio->data);
130
131 free(ea_obj->vio);
132 ea_obj->vio = NULL;
133}
134
135static void _vio_set(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list)
136{
137 Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
138
139 Ecore_Audio_Vio *vio = va_arg(*list, Ecore_Audio_Vio *);
140 void *data = va_arg(*list, Ecore_Audio_Vio *);
141 eo_base_data_free_func free_func = va_arg(*list, eo_base_data_free_func);
142
143 if (ea_obj->vio)
144 _free_vio(ea_obj);
145
146 if (!vio)
147 return;
148
149 ea_obj->vio = calloc(1, sizeof(Ecore_Audio_Vio_Internal));
150 ea_obj->vio->vio = vio;
151 ea_obj->vio->data = data;
152 ea_obj->vio->free_func = free_func;
153}
89 154
90static void _constructor(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED) 155static void _constructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED)
91{ 156{
157 Ecore_Audio_Output *obj = _pd;
158
92 eo_do_super(eo_obj, MY_CLASS, eo_constructor()); 159 eo_do_super(eo_obj, MY_CLASS, eo_constructor());
93 160
161 obj->need_writer = EINA_TRUE;
94} 162}
95 163
96static void _destructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED) 164static void _destructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED)
@@ -113,6 +181,7 @@ static void _class_constructor(Eo_Class *klass)
113 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor), 181 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
114 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor), 182 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
115 183
184 EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_VIO_SET), _vio_set),
116 /* Specific functions to this class */ 185 /* Specific functions to this class */
117 EO_OP_FUNC(ECORE_AUDIO_OBJ_OUT_ID(ECORE_AUDIO_OBJ_OUT_SUB_ID_INPUT_ATTACH), _input_attach), 186 EO_OP_FUNC(ECORE_AUDIO_OBJ_OUT_ID(ECORE_AUDIO_OBJ_OUT_SUB_ID_INPUT_ATTACH), _input_attach),
118 EO_OP_FUNC(ECORE_AUDIO_OBJ_OUT_ID(ECORE_AUDIO_OBJ_OUT_SUB_ID_INPUT_DETACH), _input_detach), 187 EO_OP_FUNC(ECORE_AUDIO_OBJ_OUT_ID(ECORE_AUDIO_OBJ_OUT_SUB_ID_INPUT_DETACH), _input_detach),
diff --git a/src/lib/ecore_audio/ecore_audio_obj_out_pulse.c b/src/lib/ecore_audio/ecore_audio_obj_out_pulse.c
index bdb193d..eebb9cb 100644
--- a/src/lib/ecore_audio/ecore_audio_obj_out_pulse.c
+++ b/src/lib/ecore_audio/ecore_audio_obj_out_pulse.c
@@ -230,9 +230,12 @@ static void _constructor(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list EINA_U
230{ 230{
231 int argc; 231 int argc;
232 char **argv; 232 char **argv;
233 Ecore_Audio_Output *out_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_OUT_CLASS);
233 234
234 eo_do_super(eo_obj, MY_CLASS, eo_constructor()); 235 eo_do_super(eo_obj, MY_CLASS, eo_constructor());
235 236
237 out_obj->need_writer = EINA_FALSE;
238
236 if (!class_vars.context) { 239 if (!class_vars.context) {
237 ecore_app_args_get(&argc, &argv); 240 ecore_app_args_get(&argc, &argv);
238 if (!argc) { 241 if (!argc) {
diff --git a/src/lib/ecore_audio/ecore_audio_obj_out_sndfile.c b/src/lib/ecore_audio/ecore_audio_obj_out_sndfile.c
index 3e90590..2545164 100644
--- a/src/lib/ecore_audio/ecore_audio_obj_out_sndfile.c
+++ b/src/lib/ecore_audio/ecore_audio_obj_out_sndfile.c
@@ -190,9 +190,14 @@ static void _format_get(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list)
190 190
191static void _constructor(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED) 191static void _constructor(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
192{ 192{
193 Ecore_Audio_Output *out_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_OUT_CLASS);
194
193 eo_do_super(eo_obj, MY_CLASS, eo_constructor()); 195 eo_do_super(eo_obj, MY_CLASS, eo_constructor());
194 196
195 eo_do(eo_obj, ecore_audio_obj_format_set(ECORE_AUDIO_FORMAT_OGG, NULL)); 197 eo_do(eo_obj, ecore_audio_obj_format_set(ECORE_AUDIO_FORMAT_OGG, NULL));
198
199 // FIXME: Use writer from output
200 out_obj->need_writer = EINA_FALSE;
196} 201}
197 202
198static void _destructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED) 203static void _destructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED)
diff --git a/src/lib/ecore_audio/ecore_audio_private.h b/src/lib/ecore_audio/ecore_audio_private.h
index a7a8915..ee809aa 100644
--- a/src/lib/ecore_audio/ecore_audio_private.h
+++ b/src/lib/ecore_audio/ecore_audio_private.h
@@ -119,6 +119,7 @@ struct _Ecore_Audio_Output
119{ 119{
120 Eina_List *inputs; /**< The inputs that are connected to this output */ 120 Eina_List *inputs; /**< The inputs that are connected to this output */
121 Ecore_Idler *write_idler; 121 Ecore_Idler *write_idler;
122 Eina_Bool need_writer;
122}; 123};
123 124
124/** 125/**