2013-04-11 10:23:57 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_FEATURES_H
|
|
|
|
#include <features.h>
|
|
|
|
#endif
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "ecore_audio_private.h"
|
|
|
|
|
2014-06-02 06:47:59 -07:00
|
|
|
#define MY_CLASS ECORE_AUDIO_OUT_CLASS
|
2013-11-07 03:16:01 -08:00
|
|
|
#define MY_CLASS_NAME "Ecore_Audio_Out"
|
2013-04-11 10:23:57 -07:00
|
|
|
|
2013-04-26 10:32:18 -07:00
|
|
|
static Eina_Bool _write_cb(void *data)
|
|
|
|
{
|
|
|
|
Eo *eo_obj = data;
|
|
|
|
Eo *in;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
Ecore_Audio_Output *out_obj = efl_data_scope_get(eo_obj, ECORE_AUDIO_OUT_CLASS);
|
|
|
|
Ecore_Audio_Object *ea_obj = efl_data_scope_get(eo_obj, ECORE_AUDIO_CLASS);
|
2013-04-26 10:32:18 -07:00
|
|
|
|
2014-04-02 06:21:57 -07:00
|
|
|
ssize_t written, bread = 0;
|
2013-04-26 10:32:18 -07:00
|
|
|
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);
|
|
|
|
|
2016-03-01 10:06:28 -08:00
|
|
|
bread = ecore_audio_obj_in_read(in, buf, 4*1024);
|
2013-04-26 10:32:18 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-26 09:01:36 -07:00
|
|
|
EOLIAN static Eina_Bool
|
|
|
|
_ecore_audio_out_input_attach(Eo *eo_obj, Ecore_Audio_Output *obj, Eo *input)
|
2013-04-11 10:23:57 -07:00
|
|
|
{
|
|
|
|
Ecore_Audio_Input *in;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
Ecore_Audio_Object *ea_obj = efl_data_scope_get(eo_obj, ECORE_AUDIO_CLASS);
|
2013-04-26 10:32:18 -07:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
in = efl_data_scope_get(input, ECORE_AUDIO_IN_CLASS);
|
2013-04-11 10:23:57 -07:00
|
|
|
|
2013-04-19 08:41:17 -07:00
|
|
|
if (in->output == eo_obj)
|
2014-03-26 09:01:36 -07:00
|
|
|
return EINA_FALSE;
|
2013-04-19 08:41:17 -07:00
|
|
|
|
2016-03-01 10:06:28 -08:00
|
|
|
if (in->output) ecore_audio_obj_out_input_detach(in->output, input);
|
2013-04-11 10:23:57 -07:00
|
|
|
in->output = eo_obj;
|
|
|
|
|
2013-04-26 10:32:18 -07:00
|
|
|
/* TODO: Send event */
|
2013-04-11 10:23:57 -07:00
|
|
|
|
|
|
|
obj->inputs = eina_list_append(obj->inputs, input);
|
|
|
|
|
2013-04-26 10:32:18 -07:00
|
|
|
if (obj->need_writer &&
|
|
|
|
ea_obj->vio && ea_obj->vio->vio->write)
|
|
|
|
obj->write_idler = ecore_idler_add(_write_cb, eo_obj);
|
|
|
|
|
|
|
|
|
2014-03-26 09:01:36 -07:00
|
|
|
return EINA_TRUE;
|
2013-04-11 10:23:57 -07:00
|
|
|
}
|
|
|
|
|
2014-03-26 09:01:36 -07:00
|
|
|
EOLIAN static Eina_Bool
|
|
|
|
_ecore_audio_out_input_detach(Eo *eo_obj, Ecore_Audio_Output *obj, Eo *input)
|
2013-04-11 10:23:57 -07:00
|
|
|
{
|
|
|
|
Ecore_Audio_Input *in;
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
in = efl_data_scope_get(input, ECORE_AUDIO_IN_CLASS);
|
2013-04-11 10:23:57 -07:00
|
|
|
|
2013-04-23 09:10:16 -07:00
|
|
|
if (in->output != eo_obj)
|
2014-03-26 09:01:36 -07:00
|
|
|
return EINA_FALSE;
|
2013-04-23 09:10:16 -07:00
|
|
|
|
2013-04-11 10:23:57 -07:00
|
|
|
in->output = NULL;
|
|
|
|
|
|
|
|
/* TODO: Check type is input
|
|
|
|
* Get private data
|
|
|
|
* Send event */
|
|
|
|
|
|
|
|
obj->inputs = eina_list_remove(obj->inputs, input);
|
|
|
|
|
2014-03-26 09:01:36 -07:00
|
|
|
return EINA_TRUE;
|
2013-04-11 10:23:57 -07:00
|
|
|
}
|
|
|
|
|
2014-03-26 09:01:36 -07:00
|
|
|
EOLIAN static Eina_List *
|
|
|
|
_ecore_audio_out_inputs_get(Eo *eo_obj EINA_UNUSED, Ecore_Audio_Output *obj)
|
2013-04-11 10:23:57 -07:00
|
|
|
{
|
2014-03-26 09:01:36 -07:00
|
|
|
return obj->inputs;
|
2013-04-11 10:23:57 -07:00
|
|
|
}
|
|
|
|
|
2013-04-26 10:32:18 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-03-26 09:01:36 -07:00
|
|
|
EOLIAN static void
|
2016-08-10 07:23:04 -07:00
|
|
|
_ecore_audio_out_ecore_audio_vio_set(Eo *eo_obj, Ecore_Audio_Output *_pd EINA_UNUSED, Ecore_Audio_Vio *vio, void *data, efl_key_data_free_func free_func)
|
2013-04-26 10:32:18 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
Ecore_Audio_Object *ea_obj = efl_data_scope_get(eo_obj, ECORE_AUDIO_CLASS);
|
2013-04-26 10:32:18 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2013-04-11 10:23:57 -07:00
|
|
|
|
2015-05-19 03:41:27 -07:00
|
|
|
EOLIAN static Eo *
|
2016-08-10 07:23:04 -07:00
|
|
|
_ecore_audio_out_efl_object_constructor(Eo *eo_obj, Ecore_Audio_Output *obj)
|
2013-04-11 10:23:57 -07:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
eo_obj = efl_constructor(efl_super(eo_obj, MY_CLASS));
|
2013-04-11 10:23:57 -07:00
|
|
|
|
2013-04-26 10:32:18 -07:00
|
|
|
obj->need_writer = EINA_TRUE;
|
2015-05-19 03:41:27 -07:00
|
|
|
|
|
|
|
return eo_obj;
|
2013-04-11 10:23:57 -07:00
|
|
|
}
|
|
|
|
|
2014-03-26 09:01:36 -07:00
|
|
|
EOLIAN static void
|
2016-08-10 07:23:04 -07:00
|
|
|
_ecore_audio_out_efl_object_destructor(Eo *eo_obj, Ecore_Audio_Output *obj)
|
2013-04-11 10:23:57 -07:00
|
|
|
{
|
|
|
|
Eina_List *cur, *tmp;
|
|
|
|
Eo *in;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH_SAFE(obj->inputs, cur, tmp, in) {
|
2016-03-01 10:06:28 -08:00
|
|
|
ecore_audio_obj_out_input_detach(eo_obj, in);
|
2013-04-11 10:23:57 -07:00
|
|
|
}
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_destructor(efl_super(eo_obj, MY_CLASS));
|
2013-04-11 10:23:57 -07:00
|
|
|
}
|
|
|
|
|
2014-03-26 09:01:36 -07:00
|
|
|
#include "ecore_audio_out.eo.c"
|