summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Ceolin <flavio.ceolin@gmail.com>2014-08-28 16:45:24 -0300
committerFlavio Ceolin <flavio.ceolin@gmail.com>2014-08-29 23:36:28 -0300
commit2d22c2f9ba7dd94748290e86622bae1eba3fd5ff (patch)
tree1c11d5fd2d2bc993c4ea50ca562b5eb81b645217
parent0a8136c3cdb2444f141504d0201180701fb7526f (diff)
pulse: Added a timer on reconnect
It avoids the overload of cpu
-rw-r--r--src/lib/backends/pulseaudio/pulse.c62
1 files changed, 44 insertions, 18 deletions
diff --git a/src/lib/backends/pulseaudio/pulse.c b/src/lib/backends/pulseaudio/pulse.c
index 74dc101..d38bd9f 100644
--- a/src/lib/backends/pulseaudio/pulse.c
+++ b/src/lib/backends/pulseaudio/pulse.c
@@ -23,9 +23,11 @@ typedef struct _Context {
23 source_event_cb source_cb; 23 source_event_cb source_cb;
24 disconnect_event_cb disconnect_cb; 24 disconnect_event_cb disconnect_cb;
25 ready_event_cb ready_cb; 25 ready_event_cb ready_cb;
26 Ecore_Timer *connect;
26 int default_sink; 27 int default_sink;
27 28
28 Eina_List *sinks, *sources, *inputs; 29 Eina_List *sinks, *sources, *inputs;
30 Eina_Bool connected;
29} Context; 31} Context;
30 32
31typedef struct _Sink { 33typedef struct _Sink {
@@ -663,6 +665,8 @@ _pulse_pa_state_cb(pa_context *context, void *data)
663 665
664 case PA_CONTEXT_READY: 666 case PA_CONTEXT_READY:
665 { 667 {
668 ctx->connect = NULL;
669 ctx->connected = EINA_TRUE;
666 pa_context_set_subscribe_callback(context, _subscribe_cb, ctx); 670 pa_context_set_subscribe_callback(context, _subscribe_cb, ctx);
667 if (!(o = pa_context_subscribe(context, (pa_subscription_mask_t) 671 if (!(o = pa_context_subscribe(context, (pa_subscription_mask_t)
668 (PA_SUBSCRIPTION_MASK_SINK| 672 (PA_SUBSCRIPTION_MASK_SINK|
@@ -715,16 +719,29 @@ _pulse_pa_state_cb(pa_context *context, void *data)
715 719
716 case PA_CONTEXT_FAILED: 720 case PA_CONTEXT_FAILED:
717 WRN("PA_CONTEXT_FAILED"); 721 WRN("PA_CONTEXT_FAILED");
718 _disconnect_cb(); 722 if (!ctx->connect)
719 _pulse_connect(data); 723 ctx->connect = ecore_timer_add(1.0, _pulse_connect, data);
720 return; 724 goto err;
721
722 case PA_CONTEXT_TERMINATED: 725 case PA_CONTEXT_TERMINATED:
723 ERR("PA_CONTEXT_TERMINATE:"); 726 ERR("PA_CONTEXT_TERMINATE:");
724 default: 727 default:
725 exit(0); 728 if (ctx->connect)
726 return; 729 {
730 ecore_timer_del(ctx->connect);
731 ctx->connect = NULL;
732 }
733 goto err;
734 }
735 return;
736
737err:
738 if (ctx->connected)
739 {
740 _disconnect_cb();
741 ctx->connected = EINA_FALSE;
727 } 742 }
743 pa_context_unref(ctx->context);
744 ctx->context = NULL;
728} 745}
729 746
730static Eina_Bool 747static Eina_Bool
@@ -760,6 +777,25 @@ _pulse_connect(void *data)
760 return ECORE_CALLBACK_RENEW; 777 return ECORE_CALLBACK_RENEW;
761} 778}
762 779
780static void
781_shutdown(void)
782{
783 if (!ctx)
784 return;
785
786 if (ctx->connect)
787 {
788 ecore_timer_del(ctx->connect);
789 ctx->connect = NULL;
790 }
791 if (ctx->context)
792 pa_context_unref(ctx->context);
793 if (ctx->connected)
794 _disconnect_cb();
795 free(ctx);
796 ctx = NULL;
797}
798
763static Eina_Bool 799static Eina_Bool
764_init(sink_event_cb sink_cb, sink_input_event_cb input_cb, 800_init(sink_event_cb sink_cb, sink_input_event_cb input_cb,
765 source_event_cb source_cb, disconnect_event_cb disconnect_cb, 801 source_event_cb source_cb, disconnect_event_cb disconnect_cb,
@@ -790,9 +826,8 @@ _init(sink_event_cb sink_cb, sink_input_event_cb input_cb,
790 */ 826 */
791 if (_pulse_connect(ctx) == EINA_TRUE) 827 if (_pulse_connect(ctx) == EINA_TRUE)
792 { 828 {
793 free(ctx); 829 _shutdown();
794 ctx = NULL; 830 return EINA_FALSE;
795 return EINA_FALSE;
796 } 831 }
797 832
798 return EINA_TRUE; 833 return EINA_TRUE;
@@ -817,15 +852,6 @@ _disconnect_cb()
817} 852}
818 853
819static void 854static void
820_shutdown(void)
821{
822 pa_context_unref(ctx->context);
823 _disconnect_cb();
824 free(ctx);
825 ctx = NULL;
826}
827
828static void
829_source_volume_set(Emix_Source *source, Emix_Volume volume) 855_source_volume_set(Emix_Source *source, Emix_Volume volume)
830{ 856{
831 pa_operation* o; 857 pa_operation* o;