ecore_audio: Add support for adding a custom callback
Very hackish implementation and probably not needed as libsndfile virtual IO can be used instead, though it's a little more complicated Signed-off-by: Daniel Willmann <d.willmann@samsung.com> SVN revision: 80998
This commit is contained in:
parent
94ccfd45e8
commit
d49fe90b18
|
@ -445,6 +445,8 @@ EAPI void ecore_audio_output_sndfile_vio_set(Ecore_Audio_Object *output, Ecore_A
|
||||||
EAPI void ecore_audio_input_tone_frequency_set(Ecore_Audio_Object *input, int frequency);
|
EAPI void ecore_audio_input_tone_frequency_set(Ecore_Audio_Object *input, int frequency);
|
||||||
EAPI void ecore_audio_input_tone_duration_set(Ecore_Audio_Object *input, double duration);
|
EAPI void ecore_audio_input_tone_duration_set(Ecore_Audio_Object *input, double duration);
|
||||||
|
|
||||||
|
EAPI void ecore_audio_input_callback_setup(Ecore_Audio_Object *input, Ecore_Audio_Read_Callback read_cb, void *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -91,6 +91,10 @@ ecore_audio_init(void)
|
||||||
if (mod)
|
if (mod)
|
||||||
ecore_audio_modules = eina_list_append(ecore_audio_modules, mod);
|
ecore_audio_modules = eina_list_append(ecore_audio_modules, mod);
|
||||||
|
|
||||||
|
mod = ecore_audio_custom_init();
|
||||||
|
if (mod)
|
||||||
|
ecore_audio_modules = eina_list_append(ecore_audio_modules, mod);
|
||||||
|
|
||||||
return _ecore_audio_init_count;
|
return _ecore_audio_init_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,6 +114,7 @@ ecore_audio_shutdown(void)
|
||||||
ecore_audio_sndfile_shutdown();
|
ecore_audio_sndfile_shutdown();
|
||||||
#endif
|
#endif
|
||||||
ecore_audio_tone_shutdown();
|
ecore_audio_tone_shutdown();
|
||||||
|
ecore_audio_custom_shutdown();
|
||||||
|
|
||||||
eina_list_free(ecore_audio_modules);
|
eina_list_free(ecore_audio_modules);
|
||||||
|
|
||||||
|
@ -575,6 +580,17 @@ ecore_audio_input_remaining_get(Ecore_Audio_Object *input)
|
||||||
return in->length - inmod->in_ops->input_seek(input, 0, SEEK_CUR);
|
return in->length - inmod->in_ops->input_seek(input, 0, SEEK_CUR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* XXX: Error checking!!! */
|
||||||
|
EAPI void
|
||||||
|
ecore_audio_input_callback_setup(Ecore_Audio_Object *input, Ecore_Audio_Read_Callback read_cb, void *data)
|
||||||
|
{
|
||||||
|
EINA_SAFETY_ON_NULL_RETURN(input);
|
||||||
|
struct _Ecore_Audio_Callback *cb = input->module_data;
|
||||||
|
|
||||||
|
cb->read_cb = read_cb;
|
||||||
|
cb->data = data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "Ecore.h"
|
||||||
|
#include "ecore_private.h"
|
||||||
|
#include "Ecore_Audio.h"
|
||||||
|
#include "ecore_audio_private.h"
|
||||||
|
|
||||||
|
static Ecore_Audio_Module *module = NULL;
|
||||||
|
|
||||||
|
static Ecore_Audio_Object *
|
||||||
|
_custom_input_new(Ecore_Audio_Object *input)
|
||||||
|
{
|
||||||
|
Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
|
||||||
|
struct _Ecore_Audio_Callback *cb = calloc(1, sizeof(struct _Ecore_Audio_Callback));
|
||||||
|
|
||||||
|
in->samplerate = 44100;
|
||||||
|
in->channels = 2;
|
||||||
|
|
||||||
|
in->module_data = cb;
|
||||||
|
|
||||||
|
return (Ecore_Audio_Object *)in;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_custom_input_del(Ecore_Audio_Object *input)
|
||||||
|
{
|
||||||
|
Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
|
||||||
|
free(in->module_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_custom_input_read(Ecore_Audio_Object *input, void *data, int len)
|
||||||
|
{
|
||||||
|
Ecore_Audio_Input *in = (Ecore_Audio_Input *)input;
|
||||||
|
struct _Ecore_Audio_Callback *cb = in->module_data;
|
||||||
|
|
||||||
|
if (in->paused)
|
||||||
|
{
|
||||||
|
memset(data, 0, len);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cb->read_cb(cb->data, data, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static double
|
||||||
|
_custom_input_seek(Ecore_Audio_Object *input EINA_UNUSED, double offs EINA_UNUSED, int mode EINA_UNUSED)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct input_api inops = {
|
||||||
|
.input_new = _custom_input_new,
|
||||||
|
.input_del = _custom_input_del,
|
||||||
|
.input_read = _custom_input_read,
|
||||||
|
.input_seek = _custom_input_seek,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize the Ecore_Audio sndfile module
|
||||||
|
*
|
||||||
|
* @return the initialized module on success, NULL on error
|
||||||
|
*/
|
||||||
|
Ecore_Audio_Module *
|
||||||
|
ecore_audio_custom_init(void)
|
||||||
|
{
|
||||||
|
module = calloc(1, sizeof(Ecore_Audio_Module));
|
||||||
|
if (!module)
|
||||||
|
{
|
||||||
|
ERR("Could not allocate memory for module.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ECORE_MAGIC_SET(module, ECORE_MAGIC_AUDIO_MODULE);
|
||||||
|
module->type = ECORE_AUDIO_TYPE_CUSTOM;
|
||||||
|
module->name = "custom";
|
||||||
|
module->inputs = NULL;
|
||||||
|
module->outputs = NULL;
|
||||||
|
module->in_ops = &inops;
|
||||||
|
module->out_ops = NULL;
|
||||||
|
|
||||||
|
DBG("Initialized");
|
||||||
|
return module;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Shut down the Ecore_Audio custom module
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ecore_audio_custom_shutdown(void)
|
||||||
|
{
|
||||||
|
free(module);
|
||||||
|
module = NULL;
|
||||||
|
|
||||||
|
DBG("Shutting down");
|
||||||
|
}
|
|
@ -348,6 +348,9 @@ struct _Ecore_Audio_Tone
|
||||||
Ecore_Audio_Module *ecore_audio_tone_init(void);
|
Ecore_Audio_Module *ecore_audio_tone_init(void);
|
||||||
void ecore_audio_tone_shutdown(void);
|
void ecore_audio_tone_shutdown(void);
|
||||||
|
|
||||||
|
Ecore_Audio_Module *ecore_audio_custom_init(void);
|
||||||
|
void ecore_audio_custom_shutdown(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue