asdfuser pushed a commit to branch master.
commit 6c7dbf67afb12ba8e1c1b7f9433b14e0dc00a94c
Author: Daniel Willmann <[email protected]>
Date: Fri Apr 26 18:32:18 2013 +0100
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 <[email protected]>
---
src/lib/ecore_audio/ecore_audio_obj_out.c | 77 +++++++++++++++++++++--
src/lib/ecore_audio/ecore_audio_obj_out_pulse.c | 3 +
src/lib/ecore_audio/ecore_audio_obj_out_sndfile.c | 5 ++
src/lib/ecore_audio/ecore_audio_private.h | 1 +
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;
#define MY_CLASS ECORE_AUDIO_OBJ_OUT_CLASS
#define MY_CLASS_NAME "ecore_audio_obj_out"
+static Eina_Bool _write_cb(void *data)
+{
+ Eo *eo_obj = data;
+ Eo *in;
+
+ Ecore_Audio_Output *out_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_OUT_CLASS);
+ Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
+
+ ssize_t written, bread;
+ float buf[1024];
+
+ if (!ea_obj->vio || !ea_obj->vio->vio->write)
+ return EINA_FALSE;
+
+ /* FIXME: Multiple inputs */
+ in = eina_list_data_get(out_obj->inputs);
+
+ eo_do(in, ecore_audio_obj_in_read(buf, 4*1024, &bread));
+
+ if (bread == 0) {
+ ea_obj->paused = EINA_TRUE;
+ out_obj->write_idler = NULL;
+ return EINA_FALSE;
+ }
+ written = ea_obj->vio->vio->write(ea_obj->vio->data, eo_obj, buf, bread);
+
+ if (written != bread)
+ ERR("Short write");
+
+ return EINA_TRUE;
+}
+
static void _input_attach(Eo *eo_obj, void *_pd, va_list *list)
{
Ecore_Audio_Output *obj = _pd;
Ecore_Audio_Input *in;
+ Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
+
Eo *input = va_arg(*list, Eo *);
Eina_Bool *ret = va_arg(*list, Eina_Bool *);
@@ -38,12 +72,15 @@ static void _input_attach(Eo *eo_obj, void *_pd, va_list
*list)
if (in->output) eo_do(in->output, ecore_audio_obj_out_input_detach(input,
NULL));
in->output = eo_obj;
- /* TODO: Check type is input
- * Get private data
- * Send event */
+ /* TODO: Send event */
obj->inputs = eina_list_append(obj->inputs, input);
+ if (obj->need_writer &&
+ ea_obj->vio && ea_obj->vio->vio->write)
+ obj->write_idler = ecore_idler_add(_write_cb, eo_obj);
+
+
if (ret)
*ret = EINA_TRUE;
}
@@ -86,11 +123,42 @@ static void _inputs_get(Eo *eo_obj EINA_UNUSED, void *_pd,
va_list *list)
*inputs = obj->inputs;
}
+static void _free_vio(Ecore_Audio_Object *ea_obj)
+{
+ if (ea_obj->vio->free_func)
+ ea_obj->vio->free_func(ea_obj->vio->data);
+
+ free(ea_obj->vio);
+ ea_obj->vio = NULL;
+}
+
+static void _vio_set(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list)
+{
+ Ecore_Audio_Object *ea_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_CLASS);
+
+ Ecore_Audio_Vio *vio = va_arg(*list, Ecore_Audio_Vio *);
+ void *data = va_arg(*list, Ecore_Audio_Vio *);
+ eo_base_data_free_func free_func = va_arg(*list, eo_base_data_free_func);
+
+ if (ea_obj->vio)
+ _free_vio(ea_obj);
+
+ if (!vio)
+ return;
+
+ ea_obj->vio = calloc(1, sizeof(Ecore_Audio_Vio_Internal));
+ ea_obj->vio->vio = vio;
+ ea_obj->vio->data = data;
+ ea_obj->vio->free_func = free_func;
+}
-static void _constructor(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list
EINA_UNUSED)
+static void _constructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED)
{
+ Ecore_Audio_Output *obj = _pd;
+
eo_do_super(eo_obj, MY_CLASS, eo_constructor());
+ obj->need_writer = EINA_TRUE;
}
static void _destructor(Eo *eo_obj, void *_pd, va_list *list EINA_UNUSED)
@@ -113,6 +181,7 @@ static void _class_constructor(Eo_Class *klass)
EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
+ EO_OP_FUNC(ECORE_AUDIO_OBJ_ID(ECORE_AUDIO_OBJ_SUB_ID_VIO_SET), _vio_set),
/* Specific functions to this class */
EO_OP_FUNC(ECORE_AUDIO_OBJ_OUT_ID(ECORE_AUDIO_OBJ_OUT_SUB_ID_INPUT_ATTACH),
_input_attach),
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
{
int argc;
char **argv;
+ Ecore_Audio_Output *out_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_OUT_CLASS);
eo_do_super(eo_obj, MY_CLASS, eo_constructor());
+ out_obj->need_writer = EINA_FALSE;
+
if (!class_vars.context) {
ecore_app_args_get(&argc, &argv);
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)
static void _constructor(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list
EINA_UNUSED)
{
+ Ecore_Audio_Output *out_obj = eo_data_get(eo_obj, ECORE_AUDIO_OBJ_OUT_CLASS);
+
eo_do_super(eo_obj, MY_CLASS, eo_constructor());
eo_do(eo_obj, ecore_audio_obj_format_set(ECORE_AUDIO_FORMAT_OGG, NULL));
+
+ // FIXME: Use writer from output
+ out_obj->need_writer = EINA_FALSE;
}
static 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
{
Eina_List *inputs; /**< The inputs that are connected to this
output */
Ecore_Idler *write_idler;
+ Eina_Bool need_writer;
};
/**
--
------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr