]> code.delx.au - pulseaudio/blobdiff - polyp/sink.c
new features:
[pulseaudio] / polyp / sink.c
index c2c873c6dfa9df6de9cd0222deeb5f9f7de63022..43fd351cf67fa5a7ad39956b4a99db1422b7754f 100644 (file)
@@ -33,6 +33,8 @@
 #include "namereg.h"
 #include "util.h"
 #include "sample-util.h"
+#include "xmalloc.h"
+#include "subscribe.h"
 
 #define MAX_MIX_CHANNELS 32
 
@@ -43,15 +45,14 @@ struct pa_sink* pa_sink_new(struct pa_core *core, const char *name, int fail, co
     int r;
     assert(core && name && *name && spec);
 
-    s = malloc(sizeof(struct pa_sink));
-    assert(s);
+    s = pa_xmalloc(sizeof(struct pa_sink));
 
     if (!(name = pa_namereg_register(core, name, PA_NAMEREG_SINK, s, fail))) {
-        free(s);
+        pa_xfree(s);
         return NULL;
     }
     
-    s->name = strdup(name);
+    s->name = pa_xstrdup(name);
     s->description = NULL;
     
     s->owner = NULL;
@@ -62,8 +63,9 @@ struct pa_sink* pa_sink_new(struct pa_core *core, const char *name, int fail, co
     n = pa_sprintf_malloc("%s_monitor", name);
     s->monitor_source = pa_source_new(core, n, 0, spec);
     assert(s->monitor_source);
-    free(n);
+    pa_xfree(n);
     s->monitor_source->monitor_of = s;
+    s->monitor_source->description = pa_sprintf_malloc("Monitor source of sink '%s'", s->name);
     
     s->volume = PA_VOLUME_NORM;
 
@@ -74,8 +76,10 @@ struct pa_sink* pa_sink_new(struct pa_core *core, const char *name, int fail, co
     r = pa_idxset_put(core->sinks, s, &s->index);
     assert(s->index != PA_IDXSET_INVALID && r >= 0);
     
-    pa_sample_snprint(st, sizeof(st), spec);
+    pa_sample_spec_snprint(st, sizeof(st), spec);
     fprintf(stderr, "sink: created %u \"%s\" with sample spec \"%s\"\n", s->index, s->name, st);
+
+    pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_NEW, s->index);
     
     return s;
 }
@@ -97,10 +101,12 @@ void pa_sink_free(struct pa_sink *s) {
     pa_idxset_remove_by_data(s->core->sinks, s, NULL);
 
     fprintf(stderr, "sink: freed %u \"%s\"\n", s->index, s->name);
+
+    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK | PA_SUBSCRIPTION_EVENT_REMOVE, s->index);
     
-    free(s->name);
-    free(s->description);
-    free(s);
+    pa_xfree(s->name);
+    pa_xfree(s->description);
+    pa_xfree(s);
 }
 
 void pa_sink_notify(struct pa_sink*s) {
@@ -141,8 +147,8 @@ static void inputs_drop(struct pa_sink *s, struct pa_mix_info *info, unsigned ma
         struct pa_sink_input *i = info->userdata;
         assert(i && info->chunk.memblock);
         
+        pa_sink_input_drop(i, &info->chunk, length);
         pa_memblock_unref(info->chunk.memblock);
-        pa_sink_input_drop(i, length);
     }
 }
         
@@ -173,11 +179,11 @@ int pa_sink_render(struct pa_sink*s, size_t length, struct pa_memchunk *result)
             volume = pa_volume_multiply(s->volume, info[0].volume);
         
         if (volume != PA_VOLUME_NORM) {
-            pa_memchunk_make_writable(result);
+            pa_memchunk_make_writable(result, s->core->memblock_stat);
             pa_volume_memchunk(result, &s->sample_spec, volume);
         }
     } else {
-        result->memblock = pa_memblock_new(length);
+        result->memblock = pa_memblock_new(length, s->core->memblock_stat);
         assert(result->memblock);
 
         result->length = l = pa_mix(info, n, result->memblock->data, length, &s->sample_spec, s->volume);
@@ -270,23 +276,18 @@ uint32_t pa_sink_get_latency(struct pa_sink *s) {
     return s->get_latency(s);
 }
 
-struct pa_sink* pa_sink_get_default(struct pa_core *c) {
-    struct pa_sink *sink;
-    assert(c);
-
-    if ((sink = pa_idxset_get_by_index(c->sinks, c->default_sink_index)))
-        return sink;
-
-    if (!(sink = pa_idxset_first(c->sinks, &c->default_sink_index)))
-        return NULL;
-
-    fprintf(stderr, "core: default sink vanished, setting to %u.\n", sink->index);
-    return sink;
-}
-
 void pa_sink_set_owner(struct pa_sink *sink, struct pa_module *m) {
     sink->owner = m;
 
     if (sink->monitor_source)
         pa_source_set_owner(sink->monitor_source, m);
 }
+
+void pa_sink_set_volume(struct pa_sink *sink, pa_volume_t volume) {
+    assert(sink);
+    
+    if (sink->volume != volume) {
+        sink->volume = volume;
+        pa_subscription_post(sink->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, sink->index);
+    }
+}