summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-08-13 16:19:56 +0000
committerLennart Poettering <lennart@poettering.net>2006-08-13 16:19:56 +0000
commita621d9028548723d13df64df06a4f4538504e7a3 (patch)
treeb488b3488a11516b3c594cc2c805d693a5d6c938
parentb5cbea940ea70b8ed92fa3be6b742e8a14897337 (diff)
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.
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1237 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r--src/modules/module-combine.c14
-rw-r--r--src/modules/module-sine.c12
-rw-r--r--src/modules/rtp/module-rtp-recv.c11
-rw-r--r--src/pulsecore/cli-text.c4
-rw-r--r--src/pulsecore/client.h10
-rw-r--r--src/pulsecore/core.c6
-rw-r--r--src/pulsecore/core.h13
-rw-r--r--src/pulsecore/module.h4
-rw-r--r--src/pulsecore/play-memblockq.c27
-rw-r--r--src/pulsecore/play-memchunk.c27
-rw-r--r--src/pulsecore/protocol-esound.c15
-rw-r--r--src/pulsecore/protocol-native.c41
-rw-r--r--src/pulsecore/protocol-simple.c19
-rw-r--r--src/pulsecore/sink-input.c160
-rw-r--r--src/pulsecore/sink-input.h47
-rw-r--r--src/pulsecore/sound-file-stream.c24
16 files changed, 296 insertions, 138 deletions
diff --git a/src/modules/module-combine.c b/src/modules/module-combine.c
index 9368aed8..008fe6e7 100644
--- a/src/modules/module-combine.c
+++ b/src/modules/module-combine.c
@@ -220,6 +220,8 @@ static pa_usec_t sink_get_latency_cb(pa_sink *s) {
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 @@ static struct output *output_new(struct userdata *u, pa_sink *sink, int resample
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 @@ static struct output *output_new(struct userdata *u, pa_sink *sink, int resample
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++;
diff --git a/src/modules/module-sine.c b/src/modules/module-sine.c
index f4392b9a..5ceddce0 100644
--- a/src/modules/module-sine.c
+++ b/src/modules/module-sine.c
@@ -109,6 +109,7 @@ int pa__init(pa_core *c, pa_module*m) {
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 @@ int pa__init(pa_core *c, pa_module*m) {
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;
diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c
index 0359a43b..df6f8c11 100644
--- a/src/modules/rtp/module-rtp-recv.c
+++ b/src/modules/rtp/module-rtp-recv.c
@@ -265,6 +265,7 @@ static struct session *session_new(struct userdata *u, const pa_sdp_info *sdp_in
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 @@ static struct session *session_new(struct userdata *u, const pa_sdp_info *sdp_in
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 @@ static struct session *session_new(struct userdata *u, const pa_sdp_info *sdp_in
}
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;
diff --git a/src/pulsecore/cli-text.c b/src/pulsecore/cli-text.c
index a1a2e564..ff083dc3 100644
--- a/src/pulsecore/cli-text.c
+++ b/src/pulsecore/cli-text.c
@@ -257,8 +257,8 @@ char *pa_sink_input_list_to_string(pa_core *c) {
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);
}
diff --git a/src/pulsecore/client.h b/src/pulsecore/client.h
index 1e72baf7..b28065e5 100644
--- a/src/pulsecore/client.h
+++ b/src/pulsecore/client.h
@@ -1,5 +1,5 @@
-#ifndef fooclienthfoo
-#define fooclienthfoo
+#ifndef foopulseclienthfoo
+#define foopulseclienthfoo
/* $Id$ */
@@ -22,6 +22,10 @@
USA.
***/
+#include <inttypes.h>
+
+typedef struct pa_client pa_client;
+
#include <pulsecore/core.h>
#include <pulsecore/module.h>
@@ -29,8 +33,6 @@
* 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;
diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c
index 710e00ad..24f835f7 100644
--- a/src/pulsecore/core.c
+++ b/src/pulsecore/core.c
@@ -92,6 +92,9 @@ pa_core* pa_core_new(pa_mainloop_api *m) {
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 @@ void pa_core_free(pa_core *c) {
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);
}
diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h
index 391ba9b8..fd92de61 100644
--- a/src/pulsecore/core.h
+++ b/src/pulsecore/core.h
@@ -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/core-subscribe.h>
#include <pulsecore/llist.h>
+#include <pulsecore/hook-list.h>
+
+typedef struct pa_core pa_core;
+
+#include <pulsecore/core-subscribe.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 @@ struct pa_core {
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);
diff --git a/src/pulsecore/module.h b/src/pulsecore/module.h
index 9bc5cb5d..8c320be8 100644
--- a/src/pulsecore/module.h
+++ b/src/pulsecore/module.h
@@ -25,11 +25,11 @@
#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;
char *name, *argument;
diff --git a/src/pulsecore/play-memblockq.c b/src/pulsecore/play-memblockq.c
index 7b796a8d..f459142a 100644
--- a/src/pulsecore/play-memblockq.c
+++ b/src/pulsecore/play-memblockq.c
@@ -79,14 +79,15 @@ static void sink_input_drop(pa_sink_input *i, const pa_memchunk*chunk, size_t le
}
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 @@ int pa_play_memblockq(
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 @@ int pa_play_memblockq(
si->userdata = q;
- pa_sink_notify(sink);
+ pa_sink_notify(si->sink);
return 0;
}
diff --git a/src/pulsecore/play-memchunk.c b/src/pulsecore/play-memchunk.c
index 7ac579e9..cde6a9ee 100644
--- a/src/pulsecore/play-memchunk.c
+++ b/src/pulsecore/play-memchunk.c
@@ -82,24 +82,33 @@ static void sink_input_drop(pa_sink_input *i, const pa_memchunk*chunk, size_t le
}
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 @@ int pa_play_memchunk(
pa_memblock_ref(chunk->memblock);
- pa_sink_notify(sink);
+ pa_sink_notify(si->sink);
return 0;
}
diff --git a/src/pulsecore/protocol-esound.c b/src/pulsecore/protocol-esound.c
index 0fa2c7f1..724dccbc 100644
--- a/src/pulsecore/protocol-esound.c
+++ b/src/pulsecore/protocol-esound.c
@@ -325,9 +325,10 @@ static int esd_proto_connect(struct connection *c, PA_GCC_UNUSED esd_proto_t req
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 @@ static int esd_proto_stream_play(struct connection *c, PA_GCC_UNUSED esd_proto_t
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 @@ static int esd_proto_stream_play(struct connection *c, PA_GCC_UNUSED esd_proto_t
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;
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 98212922..f922fb55 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -362,23 +362,24 @@ static void record_stream_free(struct record_stream* r) {
}
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 @@ static struct playback_stream* playback_stream_new(
/* 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 @@ static struct playback_stream* playback_stream_new(
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 @@ static void sink_input_fill_tagstruct(pa_tagstruct *t, pa_sink_input *s) {
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);
diff --git a/src/pulsecore/protocol-simple.c b/src/pulsecore/protocol-simple.c
index 4d73bd24..5071191a 100644
--- a/src/pulsecore/protocol-simple.c
+++ b/src/pulsecore/protocol-simple.c
@@ -340,22 +340,21 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
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;
- }
+ 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(sink, __FILE__, c->client->name, &p->sample_spec, NULL, NULL, 0, -1))) {
+ 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;
c->sink_input->kill = sink_input_kill_cb;
@@ -375,6 +374,8 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
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) {
diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index 701d7f6c..ff5213e1 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -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 @@ if (!(condition)) \
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 @@ pa_sink_input* pa_sink_input_new(
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 @@ pa_sink_input* pa_sink_input_new(
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);
+ r = pa_idxset_put(i->sink->inputs, i, NULL);
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);
+ 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 */
diff --git a/src/pulsecore/sink-input.h b/src/pulsecore/sink-input.h
index d33f382b..243978fe 100644
--- a/src/pulsecore/sink-input.h
+++ b/src/pulsecore/sink-input.h
@@ -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 @@ typedef enum pa_sink_input_state {
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 @@ struct pa_sink_input {
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);
diff --git a/src/pulsecore/sound-file-stream.c b/src/pulsecore/sound-file-stream.c
index 386f5bd0..6063b93e 100644
--- a/src/pulsecore/sound-file-stream.c
+++ b/src/pulsecore/sound-file-stream.c
@@ -120,13 +120,20 @@ static void sink_input_drop(pa_sink_input *i, const pa_memchunk*chunk, size_t le
}
}
-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);
+ pa_sink_input_new_data data;
+
+ assert(sink);
+ assert(fname);
- u = pa_xmalloc(sizeof(struct userdata));
+ 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 @@ int pa_play_file(pa_sink *sink, const char *fname, const pa_cvolume *volume) {
pa_log(__FILE__": Unsupported sample format in file %s", fname);
goto fail;
}
+
+ 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, __FILE__, fname, &ss, NULL, volume, 0, -1)))
+ 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 @@ int pa_play_file(pa_sink *sink, const char *fname, const pa_cvolume *volume) {
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;