summaryrefslogtreecommitdiff
path: root/src/lib/ecore_audio
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2013-08-27 23:42:24 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2013-08-27 23:44:53 +0900
commit12981b168e9fc094cc47bdd8c5eebfc5bbdc4001 (patch)
tree47e92db63652951289a1d63fdac89f76ebdedf68 /src/lib/ecore_audio
parent041e3af3e55e28bedf955ebd098813a049040f08 (diff)
ecore-audio - expose ready and fail events so multisense can avoid leaks
well well well. i WASN'T crazy. there WAS a leak. it was ecore-audio+multisense. if a pulse audio output doesn't connect... NO ONE KNOWS. all audio streams keep being appended to it forever just consuming more memory indefinitely. there is no way to handle it. expose events so it CAN be handled.
Diffstat (limited to 'src/lib/ecore_audio')
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj_out_pulse.c34
-rw-r--r--src/lib/ecore_audio/ecore_audio_obj_out_pulse.h22
2 files changed, 54 insertions, 2 deletions
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 5c413050b7..80f7fb0227 100644
--- a/src/lib/ecore_audio/ecore_audio_obj_out_pulse.c
+++ b/src/lib/ecore_audio/ecore_audio_obj_out_pulse.c
@@ -25,13 +25,19 @@ EAPI Eo_Op ECORE_AUDIO_OBJ_OUT_PULSE_BASE_ID = EO_NOOP;
25#define MY_CLASS ECORE_AUDIO_OBJ_OUT_PULSE_CLASS 25#define MY_CLASS ECORE_AUDIO_OBJ_OUT_PULSE_CLASS
26#define MY_CLASS_NAME "ecore_audio_obj_out_pulse" 26#define MY_CLASS_NAME "ecore_audio_obj_out_pulse"
27 27
28const Eo_Event_Description _ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY; 28EAPI const Eo_Event_Description _ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY =
29 EO_EVENT_DESCRIPTION("context,ready", "Called when the output is ready for playback.");
29#define ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY (&(_ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY)) 30#define ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY (&(_ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY))
31EAPI const Eo_Event_Description _ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_FAIL =
32 EO_EVENT_DESCRIPTION("context,fail", "Called when context fails.");
33#define ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_FAIL (&(_ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_FAIL))
34
30 35
31struct _Ecore_Audio_Pulse_Class { 36struct _Ecore_Audio_Pulse_Class {
32 pa_mainloop_api *api; 37 pa_mainloop_api *api;
33 pa_context *context; 38 pa_context *context;
34 pa_context_state_t state; 39 pa_context_state_t state;
40 Ecore_Job *state_job;
35 Eina_List *outputs; 41 Eina_List *outputs;
36}; 42};
37 43
@@ -213,17 +219,38 @@ static void _state_cb(pa_context *context, void *data EINA_UNUSED)
213 pa_context_state_t state; 219 pa_context_state_t state;
214 220
215 state = pa_context_get_state(context); 221 state = pa_context_get_state(context);
222 class_vars.state = state;
216 223
217 if (state == PA_CONTEXT_READY) { 224 if (state == PA_CONTEXT_READY) {
218 DBG("PA context ready."); 225 DBG("PA context ready.");
219 EINA_LIST_FOREACH(class_vars.outputs, out, eo_obj) { 226 EINA_LIST_FOREACH(class_vars.outputs, out, eo_obj) {
220 eo_do(eo_obj, eo_event_callback_call(ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY, NULL, NULL)); 227 eo_do(eo_obj, eo_event_callback_call(ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY, NULL, NULL));
221 } 228 }
229 } else if ((state == PA_CONTEXT_FAILED) || (state == PA_CONTEXT_TERMINATED)) {
230 DBG("PA context fail.");
231 EINA_LIST_FOREACH(class_vars.outputs, out, eo_obj) {
232 eo_do(eo_obj, eo_event_callback_call(ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_FAIL, NULL, NULL));
233 }
222 } else { 234 } else {
223 DBG("Connection state %i", state); 235 DBG("Connection state %i", state);
224 } 236 }
225 237
226 class_vars.state = state; 238}
239
240static void _state_job(void *data EINA_UNUSED)
241{
242 if ((class_vars.state == PA_CONTEXT_FAILED) ||
243 (class_vars.state == PA_CONTEXT_TERMINATED))
244 {
245 Eo *eo_obj;
246 Eina_List *out;
247
248 DBG("PA context fail.");
249 EINA_LIST_FOREACH(class_vars.outputs, out, eo_obj) {
250 eo_do(eo_obj, eo_event_callback_call(ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_FAIL, NULL, NULL));
251 }
252 }
253 class_vars.state_job = NULL;
227} 254}
228 255
229static void _constructor(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED) 256static void _constructor(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
@@ -249,6 +276,8 @@ static void _constructor(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list EINA_U
249 } 276 }
250 277
251 class_vars.outputs = eina_list_append(class_vars.outputs, eo_obj); 278 class_vars.outputs = eina_list_append(class_vars.outputs, eo_obj);
279 if (class_vars.state_job) eo_del(class_vars.state_job);
280 class_vars.state_job = ecore_job_add(_state_job, NULL);
252} 281}
253 282
254static void _destructor(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED) 283static void _destructor(Eo *eo_obj, void *_pd EINA_UNUSED, va_list *list EINA_UNUSED)
@@ -281,6 +310,7 @@ static const Eo_Op_Description op_desc[] = {
281 310
282static const Eo_Event_Description *event_desc[] = { 311static const Eo_Event_Description *event_desc[] = {
283 ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY, 312 ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY,
313 ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_FAIL,
284 NULL 314 NULL
285}; 315};
286 316
diff --git a/src/lib/ecore_audio/ecore_audio_obj_out_pulse.h b/src/lib/ecore_audio/ecore_audio_obj_out_pulse.h
index b12526cc3c..a0318316d1 100644
--- a/src/lib/ecore_audio/ecore_audio_obj_out_pulse.h
+++ b/src/lib/ecore_audio/ecore_audio_obj_out_pulse.h
@@ -52,6 +52,28 @@ enum _Ecore_Audio_Obj_Out_Pulse_Sub_Ids
52 52
53#define ECORE_AUDIO_OBJ_OUT_PULSE_ID(sub_id) (ECORE_AUDIO_OBJ_OUT_PULSE_BASE_ID + EO_TYPECHECK(enum _Ecore_Audio_Obj_Out_Pulse_Sub_Ids, sub_id)) 53#define ECORE_AUDIO_OBJ_OUT_PULSE_ID(sub_id) (ECORE_AUDIO_OBJ_OUT_PULSE_BASE_ID + EO_TYPECHECK(enum _Ecore_Audio_Obj_Out_Pulse_Sub_Ids, sub_id))
54 54
55extern EAPI const Eo_Event_Description _ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY;
56
57/**
58 * @brief The output context is ready
59 *
60 * @since 1.8
61 *
62 * Emitted when the outout context is ready for playback
63 */
64#define ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY (&(_ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_READY))
65
66extern EAPI const Eo_Event_Description _ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_FAIL;
67
68/**
69 * @brief The output context has failed
70 *
71 * @since 1.8
72 *
73 * Emitted when the outout context has failed. At this point the output is unusable and will never work, so it is advisable to delete it.
74 */
75#define ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_FAIL (&(_ECORE_AUDIO_EV_OUT_PULSE_CONTEXT_FAIL))
76
55/** 77/**
56 * @} 78 * @}
57 */ 79 */