[pulseaudio-commits] r1237 - in /trunk/src: modules/ modules/rtp/ pulsecore/

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sun Aug 13 09:19:58 PDT 2006


Author: lennart
Date: Sun Aug 13 18:19:56 2006
New Revision: 1237

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1237&root=pulseaudio&view=rev
Log:
allow hooking into the process of creating playback streams. To implement this I modified the pa_sink_input_new() signature to take a pa_sink_input_new_data structure instead of direct arguments.

Modified:
    trunk/src/modules/module-combine.c
    trunk/src/modules/module-sine.c
    trunk/src/modules/rtp/module-rtp-recv.c
    trunk/src/pulsecore/cli-text.c
    trunk/src/pulsecore/client.h
    trunk/src/pulsecore/core.c
    trunk/src/pulsecore/core.h
    trunk/src/pulsecore/module.h
    trunk/src/pulsecore/play-memblockq.c
    trunk/src/pulsecore/play-memchunk.c
    trunk/src/pulsecore/protocol-esound.c
    trunk/src/pulsecore/protocol-native.c
    trunk/src/pulsecore/protocol-simple.c
    trunk/src/pulsecore/sink-input.c
    trunk/src/pulsecore/sink-input.h
    trunk/src/pulsecore/sound-file-stream.c

Modified: trunk/src/modules/module-combine.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-combine.c?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/modules/module-combine.c (original)
+++ trunk/src/modules/module-combine.c Sun Aug 13 18:19:56 2006
@@ -220,6 +220,8 @@
 static struct output *output_new(struct userdata *u, pa_sink *sink, int resample_method) {
     struct output *o = NULL;
     char t[256];
+    pa_sink_input_new_data data;
+    
     assert(u && sink && u->sink);
     
     o = pa_xmalloc(sizeof(struct output));
@@ -237,7 +239,16 @@
             sink->core->memblock_stat);
 
     snprintf(t, sizeof(t), "%s: output #%u", u->sink->name, u->n_outputs+1);
-    if (!(o->sink_input = pa_sink_input_new(sink, __FILE__, t, &u->sink->sample_spec, &u->sink->channel_map, NULL, 1, resample_method)))
+
+    pa_sink_input_new_data_init(&data);
+    data.sink = sink;
+    data.driver = __FILE__;
+    data.name = t;
+    pa_sink_input_new_data_set_sample_spec(&data, &u->sink->sample_spec);
+    pa_sink_input_new_data_set_channel_map(&data, &u->sink->channel_map);
+    data.module = u->module;
+    
+    if (!(o->sink_input = pa_sink_input_new(u->core, &data, PA_SINK_INPUT_VARIABLE_RATE)))
         goto fail;
 
     o->sink_input->get_latency = sink_input_get_latency_cb;
@@ -245,7 +256,6 @@
     o->sink_input->drop = sink_input_drop_cb;
     o->sink_input->kill = sink_input_kill_cb;
     o->sink_input->userdata = o;
-    o->sink_input->owner = u->module;
     
     PA_LLIST_PREPEND(struct output, u->outputs, o);
     u->n_outputs++;

Modified: trunk/src/modules/module-sine.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/module-sine.c?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/modules/module-sine.c (original)
+++ trunk/src/modules/module-sine.c Sun Aug 13 18:19:56 2006
@@ -109,6 +109,7 @@
     pa_sample_spec ss;
     uint32_t frequency;
     char t[256];
+    pa_sink_input_new_data data;
 
     if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
         pa_log(__FILE__": Failed to parse module arguments");
@@ -142,14 +143,21 @@
     calc_sine(u->memblock->data, u->memblock->length, frequency);
 
     snprintf(t, sizeof(t), "Sine Generator at %u Hz", frequency);
-    if (!(u->sink_input = pa_sink_input_new(sink, __FILE__, t, &ss, NULL, NULL, 0, -1)))
+
+    pa_sink_input_new_data_init(&data);
+    data.sink = sink;
+    data.driver = __FILE__;
+    data.name = t;
+    pa_sink_input_new_data_set_sample_spec(&data, &ss);
+    data.module = m;
+
+    if (!(u->sink_input = pa_sink_input_new(c, &data, 0)))
         goto fail;
 
     u->sink_input->peek = sink_input_peek;
     u->sink_input->drop = sink_input_drop;
     u->sink_input->kill = sink_input_kill;
     u->sink_input->userdata = u;
-    u->sink_input->owner = m;
 
     u->peek_index = 0;
     

Modified: trunk/src/modules/rtp/module-rtp-recv.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/modules/rtp/module-rtp-recv.c?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/modules/rtp/module-rtp-recv.c (original)
+++ trunk/src/modules/rtp/module-rtp-recv.c Sun Aug 13 18:19:56 2006
@@ -265,6 +265,7 @@
     pa_sink *sink;
     int fd = -1;
     pa_memblock *silence;
+    pa_sink_input_new_data data;
 
     if (u->n_sessions >= MAX_SESSIONS) {
         pa_log(__FILE__": session limit reached.");
@@ -289,7 +290,14 @@
                           sdp_info->session_name ? sdp_info->session_name : "", 
                           sdp_info->session_name ? ")" : "");
 
-    s->sink_input = pa_sink_input_new(sink, __FILE__, c, &sdp_info->sample_spec, NULL, NULL, 0, PA_RESAMPLER_INVALID);
+    pa_sink_input_new_data_init(&data);
+    data.sink = sink;
+    data.driver = __FILE__;
+    data.name = c;
+    data.module = u->module;
+    pa_sink_input_new_data_set_sample_spec(&data, &sdp_info->sample_spec);
+    
+    s->sink_input = pa_sink_input_new(u->core, &data, 0);
     pa_xfree(c);
         
     if (!s->sink_input) {
@@ -298,7 +306,6 @@
     }
 
     s->sink_input->userdata = s;
-    s->sink_input->owner = u->module;
 
     s->sink_input->peek = sink_input_peek;
     s->sink_input->drop = sink_input_drop;

Modified: trunk/src/pulsecore/cli-text.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/cli-text.c?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/cli-text.c (original)
+++ trunk/src/pulsecore/cli-text.c Sun Aug 13 18:19:56 2006
@@ -257,8 +257,8 @@
             pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
             pa_resample_method_to_string(pa_sink_input_get_resample_method(i)));
 
-        if (i->owner)
-            pa_strbuf_printf(s, "\towner module: <%u>\n", i->owner->index);
+        if (i->module)
+            pa_strbuf_printf(s, "\towner module: <%u>\n", i->module->index);
         if (i->client)
             pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", i->client->index, i->client->name);
     }

Modified: trunk/src/pulsecore/client.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/client.h?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/client.h (original)
+++ trunk/src/pulsecore/client.h Sun Aug 13 18:19:56 2006
@@ -1,5 +1,5 @@
-#ifndef fooclienthfoo
-#define fooclienthfoo
+#ifndef foopulseclienthfoo
+#define foopulseclienthfoo
 
 /* $Id$ */
 
@@ -22,14 +22,16 @@
   USA.
 ***/
 
+#include <inttypes.h>
+
+typedef struct pa_client pa_client;
+
 #include <pulsecore/core.h>
 #include <pulsecore/module.h>
 
 /* Every connection to the server should have a pa_client
  * attached. That way the user may generate a listing of all connected
  * clients easily and kill them if he wants.*/
-
-typedef struct pa_client pa_client;
 
 struct pa_client {
     uint32_t index;

Modified: trunk/src/pulsecore/core.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/core.c?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/core.c (original)
+++ trunk/src/pulsecore/core.c Sun Aug 13 18:19:56 2006
@@ -92,6 +92,9 @@
 
     c->is_system_instance = 0;
 
+    pa_hook_init(&c->hook_sink_input_new, c);
+    pa_hook_init(&c->hook_sink_input_disconnect, c);
+
     pa_property_init(c);
 
     pa_random(&c->cookie, sizeof(c->cookie));
@@ -137,6 +140,9 @@
     pa_memblock_stat_unref(c->memblock_stat);
 
     pa_property_cleanup(c);
+
+    pa_hook_free(&c->hook_sink_input_new);
+    pa_hook_free(&c->hook_sink_input_disconnect);
     
     pa_xfree(c);    
 }

Modified: trunk/src/pulsecore/core.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/core.h?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/core.h (original)
+++ trunk/src/pulsecore/core.h Sun Aug 13 18:19:56 2006
@@ -22,17 +22,21 @@
   USA.
 ***/
 
-typedef struct pa_core pa_core;
-
 #include <pulse/mainloop-api.h>
 #include <pulse/sample.h>
+
 #include <pulsecore/idxset.h>
 #include <pulsecore/hashmap.h>
 #include <pulsecore/memblock.h>
 #include <pulsecore/resampler.h>
 #include <pulsecore/queue.h>
+#include <pulsecore/llist.h>
+#include <pulsecore/hook-list.h>
+
+typedef struct pa_core pa_core;
+
 #include <pulsecore/core-subscribe.h>
-#include <pulsecore/llist.h>
+#include <pulsecore/sink-input.h>
 
 /* The core structure of PulseAudio. Every PulseAudio daemon contains
  * exactly one of these. It is used for storing kind of global
@@ -75,6 +79,9 @@
     pa_resample_method_t resample_method;
 
     int is_system_instance;
+
+    /* hooks */
+    pa_hook hook_sink_input_new, hook_sink_input_disconnect;
 };
 
 pa_core* pa_core_new(pa_mainloop_api *m);

Modified: trunk/src/pulsecore/module.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/module.h?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/module.h (original)
+++ trunk/src/pulsecore/module.h Sun Aug 13 18:19:56 2006
@@ -25,10 +25,10 @@
 #include <inttypes.h>
 #include <ltdl.h>
 
+typedef struct pa_module pa_module;
+
 #include <pulsecore/core.h>
 #include <pulsecore/modinfo.h>
-
-typedef struct pa_module pa_module;
 
 struct pa_module {
     pa_core *core;

Modified: trunk/src/pulsecore/play-memblockq.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/play-memblockq.c?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/play-memblockq.c (original)
+++ trunk/src/pulsecore/play-memblockq.c Sun Aug 13 18:19:56 2006
@@ -79,14 +79,15 @@
 }
 
 int pa_play_memblockq(
-    pa_sink *sink,
-    const char *name,
-    const pa_sample_spec *ss,
-    const pa_channel_map *map,
-    pa_memblockq *q,
-    pa_cvolume *cvolume) {
+        pa_sink *sink,
+        const char *name,
+        const pa_sample_spec *ss,
+        const pa_channel_map *map,
+        pa_memblockq *q,
+        pa_cvolume *volume) {
     
     pa_sink_input *si;
+    pa_sink_input_new_data data;
 
     assert(sink);
     assert(ss);
@@ -97,12 +98,20 @@
         return 0;
     }
 
-    if (cvolume && pa_cvolume_is_muted(cvolume)) {
+    if (volume && pa_cvolume_is_muted(volume)) {
         pa_memblockq_free(q);
         return 0;
     }
 
-    if (!(si = pa_sink_input_new(sink, name, __FILE__, ss, map, cvolume, 0, PA_RESAMPLER_INVALID)))
+    pa_sink_input_new_data_init(&data);
+    data.sink = sink;
+    data.name = name;
+    data.driver = __FILE__;
+    pa_sink_input_new_data_set_channel_map(&data, map);
+    pa_sink_input_new_data_set_sample_spec(&data, ss);
+    pa_sink_input_new_data_set_volume(&data, volume);
+    
+    if (!(si = pa_sink_input_new(sink->core, &data, 0)))
         return -1;
 
     si->peek = sink_input_peek;
@@ -111,7 +120,7 @@
     
     si->userdata = q;
 
-    pa_sink_notify(sink);
+    pa_sink_notify(si->sink);
     
     return 0;
 }

Modified: trunk/src/pulsecore/play-memchunk.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/play-memchunk.c?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/play-memchunk.c (original)
+++ trunk/src/pulsecore/play-memchunk.c Sun Aug 13 18:19:56 2006
@@ -82,24 +82,33 @@
 }
 
 int pa_play_memchunk(
-    pa_sink *sink,
-    const char *name,
-    const pa_sample_spec *ss,
-    const pa_channel_map *map,
-    const pa_memchunk *chunk,
-    pa_cvolume *cvolume) {
+        pa_sink *sink,
+        const char *name,
+        const pa_sample_spec *ss,
+        const pa_channel_map *map,
+        const pa_memchunk *chunk,
+        pa_cvolume *volume) {
     
     pa_sink_input *si;
     pa_memchunk *nchunk;
+    pa_sink_input_new_data data;
 
     assert(sink);
     assert(ss);
     assert(chunk);
 
-    if (cvolume && pa_cvolume_is_muted(cvolume))
+    if (volume && pa_cvolume_is_muted(volume))
         return 0;
 
-    if (!(si = pa_sink_input_new(sink, name, __FILE__, ss, map, cvolume, 0, PA_RESAMPLER_INVALID)))
+    pa_sink_input_new_data_init(&data);
+    data.sink = sink;
+    data.name = name;
+    data.driver = __FILE__;
+    pa_sink_input_new_data_set_sample_spec(&data, ss);
+    pa_sink_input_new_data_set_channel_map(&data, map);
+    pa_sink_input_new_data_set_volume(&data, volume);
+        
+    if (!(si = pa_sink_input_new(sink->core, &data, 0)))
         return -1;
 
     si->peek = sink_input_peek;
@@ -111,7 +120,7 @@
     
     pa_memblock_ref(chunk->memblock);
 
-    pa_sink_notify(sink);
+    pa_sink_notify(si->sink);
     
     return 0;
 }

Modified: trunk/src/pulsecore/protocol-esound.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/protocol-esound.c?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/protocol-esound.c (original)
+++ trunk/src/pulsecore/protocol-esound.c Sun Aug 13 18:19:56 2006
@@ -325,9 +325,10 @@
 static int esd_proto_stream_play(struct connection *c, PA_GCC_UNUSED esd_proto_t request, const void *data, size_t length) {
     char name[ESD_NAME_MAX], *utf8_name;
     int32_t format, rate;
-    pa_sink *sink;
     pa_sample_spec ss;
     size_t l;
+    pa_sink *sink;
+    pa_sink_input_new_data sdata;
 
     assert(c && length == (sizeof(int32_t)*2+ESD_NAME_MAX));
     
@@ -355,7 +356,15 @@
 
     assert(!c->sink_input && !c->input_memblockq);
 
-    c->sink_input = pa_sink_input_new(sink, __FILE__, utf8_name, &ss, NULL, NULL, 0, -1);
+    pa_sink_input_new_data_init(&sdata);
+    sdata.sink = sink;
+    sdata.driver = __FILE__;
+    sdata.name = utf8_name;
+    pa_sink_input_new_data_set_sample_spec(&sdata, &ss);
+    sdata.module = c->protocol->module;
+    sdata.client = c->client;
+    
+    c->sink_input = pa_sink_input_new(c->protocol->core, &sdata, 0);
 
     pa_xfree(utf8_name);
 
@@ -374,8 +383,6 @@
     pa_iochannel_socket_set_rcvbuf(c->io, l/PLAYBACK_BUFFER_FRAGMENTS*2);
     c->playback.fragment_size = l/10;
 
-    c->sink_input->owner = c->protocol->module;
-    c->sink_input->client = c->client;
     c->sink_input->peek = sink_input_peek_cb;
     c->sink_input->drop = sink_input_drop_cb;
     c->sink_input->kill = sink_input_kill_cb;

Modified: trunk/src/pulsecore/protocol-native.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/protocol-native.c?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/protocol-native.c (original)
+++ trunk/src/pulsecore/protocol-native.c Sun Aug 13 18:19:56 2006
@@ -362,23 +362,24 @@
 }
 
 static struct playback_stream* playback_stream_new(
-    struct connection *c,
-    pa_sink *sink,
-    const pa_sample_spec *ss,
-    const pa_channel_map *map,
-    const char *name,
-    size_t maxlength,
-    size_t tlength,
-    size_t prebuf,
-    size_t minreq,
-    pa_cvolume *volume,
-    uint32_t syncid) {
+        struct connection *c,
+        pa_sink *sink,
+        const pa_sample_spec *ss,
+        const pa_channel_map *map,
+        const char *name,
+        size_t maxlength,
+        size_t tlength,
+        size_t prebuf,
+        size_t minreq,
+        pa_cvolume *volume,
+        uint32_t syncid) {
     
     struct playback_stream *s, *ssync;
     pa_sink_input *sink_input;
     pa_memblock *silence;
     uint32_t idx;
     int64_t start_index;
+    pa_sink_input_new_data data;
     
     assert(c && sink && ss && name && maxlength);
 
@@ -395,8 +396,18 @@
     /* Synced streams must connect to the same sink */
     if (ssync && ssync->sink_input->sink != sink)
         return NULL;
-    
-    if (!(sink_input = pa_sink_input_new(sink, __FILE__, name, ss, map, volume, 0, -1)))
+
+    pa_sink_input_new_data_init(&data);
+    data.sink = sink;
+    data.driver = __FILE__;
+    data.name = name;
+    pa_sink_input_new_data_set_sample_spec(&data, ss);
+    pa_sink_input_new_data_set_channel_map(&data, map);
+    pa_sink_input_new_data_set_volume(&data, volume);
+    data.module = c->protocol->module;
+    data.client = c->client;
+
+    if (!(sink_input = pa_sink_input_new(sink->core, &data, 0)))
         return NULL;
     
     s = pa_xnew(struct playback_stream, 1);
@@ -411,8 +422,6 @@
     s->sink_input->kill = sink_input_kill_cb;
     s->sink_input->get_latency = sink_input_get_latency_cb;
     s->sink_input->userdata = s;
-    s->sink_input->owner = c->protocol->module;
-    s->sink_input->client = c->client;
 
     if (ssync) {
         /* Sync id found, now find head of list */
@@ -1331,7 +1340,7 @@
     assert(t && s);
     pa_tagstruct_putu32(t, s->index);
     pa_tagstruct_puts(t, s->name);
-    pa_tagstruct_putu32(t, s->owner ? s->owner->index : PA_INVALID_INDEX);
+    pa_tagstruct_putu32(t, s->module ? s->module->index : PA_INVALID_INDEX);
     pa_tagstruct_putu32(t, s->client ? s->client->index : PA_INVALID_INDEX);
     pa_tagstruct_putu32(t, s->sink->index);
     pa_tagstruct_put_sample_spec(t, &s->sample_spec);

Modified: trunk/src/pulsecore/protocol-simple.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/protocol-simple.c?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/protocol-simple.c (original)
+++ trunk/src/pulsecore/protocol-simple.c Sun Aug 13 18:19:56 2006
@@ -340,21 +340,20 @@
     c->client->userdata = c;
 
     if (p->mode & PLAYBACK) {
-        pa_sink *sink;
+        pa_sink_input_new_data data;
         size_t l;
 
-        if (!(sink = pa_namereg_get(p->core, p->sink_name, PA_NAMEREG_SINK, 1))) {
-            pa_log(__FILE__": Failed to get sink.");
-            goto fail;
-        }
-
-        if (!(c->sink_input = pa_sink_input_new(sink, __FILE__, c->client->name, &p->sample_spec, NULL, NULL, 0, -1))) {
+        pa_sink_input_new_data_init(&data);
+        data.driver = __FILE__;
+        data.name = c->client->name;
+        pa_sink_input_new_data_set_sample_spec(&data, &p->sample_spec);
+        data.module = p->module;
+        data.client = c->client;
+
+        if (!(c->sink_input = pa_sink_input_new(p->core, &data, 0))) {
             pa_log(__FILE__": Failed to create sink input.");
             goto fail;
         }
-        
-        c->sink_input->owner = p->module;
-        c->sink_input->client = c->client;
         
         c->sink_input->peek = sink_input_peek_cb;
         c->sink_input->drop = sink_input_drop_cb;
@@ -375,6 +374,8 @@
         assert(c->input_memblockq);
         pa_iochannel_socket_set_rcvbuf(io, l/PLAYBACK_BUFFER_FRAGMENTS*5);
         c->playback.fragment_size = l/10;
+
+        pa_sink_notify(c->sink_input->sink);
     }
 
     if (p->mode & RECORD) {

Modified: trunk/src/pulsecore/sink-input.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/sink-input.c?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/sink-input.c (original)
+++ trunk/src/pulsecore/sink-input.c Sun Aug 13 18:19:56 2006
@@ -35,6 +35,7 @@
 #include <pulsecore/core-subscribe.h>
 #include <pulsecore/log.h>
 #include <pulsecore/play-memblockq.h>
+#include <pulsecore/namereg.h>
 
 #include "sink-input.h"
 
@@ -48,51 +49,96 @@
     return NULL; \
 } while (0)
 
+pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data) {
+    assert(data);
+    
+    memset(data, 0, sizeof(*data));
+    data->resample_method = PA_RESAMPLER_INVALID;
+    return data;
+}
+
+void pa_sink_input_new_data_set_channel_map(pa_sink_input_new_data *data, const pa_channel_map *map) {
+    assert(data);
+
+    if ((data->channel_map_is_set = !!map))
+        data->channel_map = *map;
+}
+
+void pa_sink_input_new_data_set_volume(pa_sink_input_new_data *data, const pa_cvolume *volume) {
+    assert(data);
+
+    if ((data->volume_is_set = !!volume))
+        data->volume = *volume;
+}
+
+void pa_sink_input_new_data_set_sample_spec(pa_sink_input_new_data *data, const pa_sample_spec *spec) {
+    assert(data);
+
+    if ((data->sample_spec_is_set = !!spec))
+        data->sample_spec = *spec;
+}
+
 pa_sink_input* pa_sink_input_new(
-        pa_sink *s,
-        const char *driver,
-        const char *name,
-        const pa_sample_spec *spec,
-        const pa_channel_map *map,
-        const pa_cvolume *volume, 
-        int variable_rate,
-        int resample_method) {
+        pa_core *core,
+        pa_sink_input_new_data *data,
+        pa_sink_input_flags_t flags) {
     
     pa_sink_input *i;
     pa_resampler *resampler = NULL;
     int r;
-    char st[256];
-    pa_channel_map tmap;
-    pa_cvolume tvol;
-
-    assert(s);
-    assert(spec);
-    assert(s->state == PA_SINK_RUNNING);
-
-    CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(spec));
-
-    if (!map)
-        map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT);
-    if (!volume)
-        volume = pa_cvolume_reset(&tvol, spec->channels);
-
-    CHECK_VALIDITY_RETURN_NULL(map && pa_channel_map_valid(map));
-    CHECK_VALIDITY_RETURN_NULL(volume && pa_cvolume_valid(volume));
-    CHECK_VALIDITY_RETURN_NULL(map->channels == spec->channels);
-    CHECK_VALIDITY_RETURN_NULL(volume->channels == spec->channels);
-    CHECK_VALIDITY_RETURN_NULL(!driver || pa_utf8_valid(driver));
-    CHECK_VALIDITY_RETURN_NULL(pa_utf8_valid(name));
-            
-    if (pa_idxset_size(s->inputs) >= PA_MAX_INPUTS_PER_SINK) {
+    char st[PA_SAMPLE_SPEC_SNPRINT_MAX];
+
+    assert(core);
+    assert(data);
+
+    if (!(flags & PA_SINK_INPUT_NO_HOOKS))
+        if (pa_hook_fire(&core->hook_sink_input_new, data) < 0)
+            return NULL;
+
+    CHECK_VALIDITY_RETURN_NULL(!data->driver || pa_utf8_valid(data->driver));
+    CHECK_VALIDITY_RETURN_NULL(!data->name || pa_utf8_valid(data->name));
+
+    if (!data->sink)
+        data->sink = pa_namereg_get(core, NULL, PA_NAMEREG_SINK, 1);
+    
+    CHECK_VALIDITY_RETURN_NULL(data->sink && data->sink->state == PA_SINK_RUNNING);
+
+    if (!data->sample_spec_is_set)
+        data->sample_spec = data->sink->sample_spec;
+    
+    CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(&data->sample_spec));
+    
+    if (!data->channel_map_is_set)
+        pa_channel_map_init_auto(&data->channel_map, data->sample_spec.channels, PA_CHANNEL_MAP_DEFAULT);
+    
+    CHECK_VALIDITY_RETURN_NULL(pa_channel_map_valid(&data->channel_map));
+    CHECK_VALIDITY_RETURN_NULL(data->channel_map.channels == data->sample_spec.channels);
+    
+    if (!data->volume_is_set)
+        pa_cvolume_reset(&data->volume, data->sample_spec.channels);
+
+    CHECK_VALIDITY_RETURN_NULL(pa_cvolume_valid(&data->volume));
+    CHECK_VALIDITY_RETURN_NULL(data->volume.channels == data->sample_spec.channels);
+
+    if (data->resample_method == PA_RESAMPLER_INVALID)
+        data->resample_method = core->resample_method;
+
+    CHECK_VALIDITY_RETURN_NULL(data->resample_method < PA_RESAMPLER_MAX);
+
+    if (pa_idxset_size(data->sink->inputs) >= PA_MAX_INPUTS_PER_SINK) {
         pa_log_warn(__FILE__": Failed to create sink input: too many inputs per sink.");
         return NULL;
     }
 
-    if (resample_method == PA_RESAMPLER_INVALID)
-        resample_method = s->core->resample_method;
-    
-    if (variable_rate || !pa_sample_spec_equal(spec, &s->sample_spec) || !pa_channel_map_equal(map, &s->channel_map))
-        if (!(resampler = pa_resampler_new(spec, map, &s->sample_spec, &s->channel_map, s->core->memblock_stat, resample_method))) {
+    if ((flags & PA_SINK_INPUT_VARIABLE_RATE) ||
+        !pa_sample_spec_equal(&data->sample_spec, &data->sink->sample_spec) ||
+        !pa_channel_map_equal(&data->channel_map, &data->sink->channel_map))
+        
+        if (!(resampler = pa_resampler_new(
+                      &data->sample_spec, &data->channel_map,
+                      &data->sink->sample_spec, &data->sink->channel_map,
+                      core->memblock_stat,
+                      data->resample_method))) {
             pa_log_warn(__FILE__": Unsupported resampling operation.");
             return NULL;
         }
@@ -100,15 +146,16 @@
     i = pa_xnew(pa_sink_input, 1);
     i->ref = 1;
     i->state = PA_SINK_INPUT_DRAINED;
-    i->name = pa_xstrdup(name);
-    i->driver = pa_xstrdup(driver);
-    i->owner = NULL;
-    i->sink = s;
-    i->client = NULL;
-
-    i->sample_spec = *spec;
-    i->channel_map = *map;
-    i->volume = *volume;
+    i->flags = flags;
+    i->name = pa_xstrdup(data->name);
+    i->driver = pa_xstrdup(data->driver);
+    i->module = data->module;
+    i->sink = data->sink;
+    i->client = data->client;
+
+    i->sample_spec = data->sample_spec;
+    i->channel_map = data->channel_map;
+    i->volume = data->volume;
         
     i->peek = NULL;
     i->drop = NULL;
@@ -116,25 +163,26 @@
     i->get_latency = NULL;
     i->underrun = NULL;
     i->userdata = NULL;
+    
     i->move_silence = 0;
 
     pa_memchunk_reset(&i->resampled_chunk);
     i->resampler = resampler;
-    i->resample_method = resample_method;
-    i->variable_rate = variable_rate;
-
+    i->resample_method = data->resample_method;
     i->silence_memblock = NULL;
     
-    assert(s->core);
-    r = pa_idxset_put(s->core->sink_inputs, i, &i->index);
-    assert(r == 0 && i->index != PA_IDXSET_INVALID);
-    r = pa_idxset_put(s->inputs, i, NULL);
+    r = pa_idxset_put(core->sink_inputs, i, &i->index);
     assert(r == 0);
-
-    pa_sample_spec_snprint(st, sizeof(st), spec);
-    pa_log_info(__FILE__": created %u \"%s\" on %u with sample spec \"%s\"", i->index, i->name, s->index, st);
-
-    pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW, i->index);
+    r = pa_idxset_put(i->sink->inputs, i, NULL);
+    assert(r == 0);
+
+    pa_log_info(__FILE__": created %u \"%s\" on %s with sample spec %s",
+                i->index,
+                i->name,
+                i->sink->name,
+                pa_sample_spec_snprint(st, sizeof(st), &i->sample_spec));
+    
+    pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_NEW, i->index);
 
     /* We do not call pa_sink_notify() here, because the virtual
      * functions have not yet been initialized */

Modified: trunk/src/pulsecore/sink-input.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/sink-input.h?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/sink-input.h (original)
+++ trunk/src/pulsecore/sink-input.h Sun Aug 13 18:19:56 2006
@@ -27,11 +27,13 @@
 typedef struct pa_sink_input pa_sink_input;
 
 #include <pulse/sample.h>
-#include <pulsecore/sink.h>
+#include <pulsecore/hook-list.h>
 #include <pulsecore/memblockq.h>
 #include <pulsecore/resampler.h>
 #include <pulsecore/module.h>
 #include <pulsecore/client.h>
+#include <pulsecore/sink.h>
+#include <pulsecore/core.h>
 
 typedef enum pa_sink_input_state {
     PA_SINK_INPUT_RUNNING,      /*< The stream is alive and kicking */
@@ -40,20 +42,25 @@
     PA_SINK_INPUT_DISCONNECTED  /*< The stream is dead */
 } pa_sink_input_state_t;
 
+typedef enum pa_sink_input_flags {
+    PA_SINK_INPUT_VARIABLE_RATE = 1,
+    PA_SINK_INPUT_NO_HOOKS = 2
+} pa_sink_input_flags_t;
+
 struct pa_sink_input {
     int ref;
     uint32_t index;
     pa_sink_input_state_t state;
+    pa_sink_input_flags_t flags;
     
     char *name, *driver;                /* may be NULL */
-    pa_module *owner;                   /* may be NULL */  
+    pa_module *module;                  /* may be NULL */  
+    pa_client *client;                  /* may be NULL */ 
 
     pa_sink *sink;
-    pa_client *client;                  /* may be NULL */
     
     pa_sample_spec sample_spec;
     pa_channel_map channel_map;
-
     pa_cvolume volume;
 
     /* Some silence to play before the actual data. This is used to
@@ -78,15 +85,29 @@
     pa_memblock *silence_memblock;               /* may be NULL */
 };
 
-pa_sink_input* pa_sink_input_new(
-    pa_sink *s,
-    const char *driver,
-    const char *name,
-    const pa_sample_spec *spec,
-    const pa_channel_map *map,
-    const pa_cvolume *volume,
-    int variable_rate,
-    pa_resample_method_t resample_method);
+typedef struct pa_sink_input_new_data {
+    const char *name, *driver;
+    pa_module *module;
+    pa_client *client;
+    
+    pa_sink *sink;
+    
+    pa_sample_spec sample_spec;
+    int sample_spec_is_set;
+    pa_channel_map channel_map;
+    int channel_map_is_set;
+    pa_cvolume volume;
+    int volume_is_set;
+    
+    pa_resample_method_t resample_method;
+} pa_sink_input_new_data;
+
+pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data);
+void pa_sink_input_new_data_set_sample_spec(pa_sink_input_new_data *data, const pa_sample_spec *spec);
+void pa_sink_input_new_data_set_channel_map(pa_sink_input_new_data *data, const pa_channel_map *map);
+void pa_sink_input_new_data_set_volume(pa_sink_input_new_data *data, const pa_cvolume *volume);
+
+pa_sink_input* pa_sink_input_new(pa_core *core, pa_sink_input_new_data *data, pa_sink_input_flags_t flags);
 
 void pa_sink_input_unref(pa_sink_input* i);
 pa_sink_input* pa_sink_input_ref(pa_sink_input* i);

Modified: trunk/src/pulsecore/sound-file-stream.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/sound-file-stream.c?rev=1237&root=pulseaudio&r1=1236&r2=1237&view=diff
==============================================================================
--- trunk/src/pulsecore/sound-file-stream.c (original)
+++ trunk/src/pulsecore/sound-file-stream.c Sun Aug 13 18:19:56 2006
@@ -120,13 +120,20 @@
     }
 }
 
-int pa_play_file(pa_sink *sink, const char *fname, const pa_cvolume *volume) {
+int pa_play_file(
+        pa_sink *sink,
+        const char *fname,
+        const pa_cvolume *volume) {
+    
     struct userdata *u = NULL;
     SF_INFO sfinfo;
     pa_sample_spec ss;
-    assert(sink && fname);
-
-    u = pa_xmalloc(sizeof(struct userdata));
+    pa_sink_input_new_data data;
+    
+    assert(sink);
+    assert(fname);
+
+    u = pa_xnew(struct userdata, 1);
     u->sink_input = NULL;
     u->memchunk.memblock = NULL;
     u->memchunk.index = u->memchunk.length = 0;
@@ -171,8 +178,15 @@
         pa_log(__FILE__": Unsupported sample format in file %s", fname);
         goto fail;
     }
-    
-    if (!(u->sink_input = pa_sink_input_new(sink, __FILE__, fname, &ss, NULL, volume, 0, -1)))
+
+    pa_sink_input_new_data_init(&data);
+    data.sink = sink;
+    data.driver = __FILE__;
+    data.name = fname;
+    pa_sink_input_new_data_set_sample_spec(&data, &ss);
+    pa_sink_input_new_data_set_volume(&data, volume);
+    
+    if (!(u->sink_input = pa_sink_input_new(sink->core, &data, 0)))
         goto fail;
 
     u->sink_input->peek = sink_input_peek;
@@ -180,7 +194,7 @@
     u->sink_input->kill = sink_input_kill;
     u->sink_input->userdata = u;
     
-    pa_sink_notify(sink);
+    pa_sink_notify(u->sink_input->sink);
 
     return 0;
 




More information about the pulseaudio-commits mailing list