summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-08-13 19:55:17 +0000
committerLennart Poettering <lennart@poettering.net>2006-08-13 19:55:17 +0000
commita75e1ed9ef483c4c08f0fc963c0ea1a980f0c0e9 (patch)
tree1606249b18405428a9ebd7d2aa36678d0e38af22 /src
parente0f7e8614ce06f2b0a4bd5a38189cf97b07c0d30 (diff)
implement hook_source_ouput_new. For this I modified the pa_source_output_new constructor to take a struct similar to what I already did for pa_sink_input_new()
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1250 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src')
-rw-r--r--src/modules/rtp/module-rtp-send.c11
-rw-r--r--src/pulsecore/cli-text.c4
-rw-r--r--src/pulsecore/protocol-esound.c26
-rw-r--r--src/pulsecore/protocol-native.c17
-rw-r--r--src/pulsecore/protocol-simple.c19
-rw-r--r--src/pulsecore/sink-input.h5
-rw-r--r--src/pulsecore/source-output.c119
-rw-r--r--src/pulsecore/source-output.h35
8 files changed, 160 insertions, 76 deletions
diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c
index 5c47047f..52cd4052 100644
--- a/src/modules/rtp/module-rtp-send.c
+++ b/src/modules/rtp/module-rtp-send.c
@@ -168,6 +168,7 @@ int pa__init(pa_core *c, pa_module*m) {
struct timeval tv;
char hn[128], *n;
int loop = 0;
+ pa_source_output_new_data data;
assert(c);
assert(m);
@@ -263,8 +264,15 @@ int pa__init(pa_core *c, pa_module*m) {
pa_log(__FILE__": IP_MULTICAST_LOOP failed: %s", pa_cstrerror(errno));
goto fail;
}
+
+ pa_source_output_new_data_init(&data);
+ data.name = "RTP Monitor Stream";
+ data.driver = __FILE__;
+ data.module = m;
+ pa_source_output_new_data_set_sample_spec(&data, &ss);
+ pa_source_output_new_data_set_channel_map(&data, &cm);
- if (!(o = pa_source_output_new(s, __FILE__, "RTP Monitor Stream", &ss, &cm, PA_RESAMPLER_INVALID))) {
+ if (!(o = pa_source_output_new(c, &data, 0))) {
pa_log(__FILE__": failed to create source output.");
goto fail;
}
@@ -272,7 +280,6 @@ int pa__init(pa_core *c, pa_module*m) {
o->push = source_output_push;
o->kill = source_output_kill;
o->get_latency = source_output_get_latency;
- o->owner = m;
u = pa_xnew(struct userdata, 1);
m->userdata = u;
diff --git a/src/pulsecore/cli-text.c b/src/pulsecore/cli-text.c
index ff083dc3..49934c07 100644
--- a/src/pulsecore/cli-text.c
+++ b/src/pulsecore/cli-text.c
@@ -204,8 +204,8 @@ char *pa_source_output_list_to_string(pa_core *c) {
pa_sample_spec_snprint(ss, sizeof(ss), &o->sample_spec),
pa_channel_map_snprint(cm, sizeof(cm), &o->channel_map),
pa_resample_method_to_string(pa_source_output_get_resample_method(o)));
- if (o->owner)
- pa_strbuf_printf(s, "\towner module: <%u>\n", o->owner->index);
+ if (o->module)
+ pa_strbuf_printf(s, "\towner module: <%u>\n", o->module->index);
if (o->client)
pa_strbuf_printf(s, "\tclient: <%u> '%s'\n", o->client->index, o->client->name);
}
diff --git a/src/pulsecore/protocol-esound.c b/src/pulsecore/protocol-esound.c
index 724dccbc..f1a827bc 100644
--- a/src/pulsecore/protocol-esound.c
+++ b/src/pulsecore/protocol-esound.c
@@ -349,9 +349,11 @@ static int esd_proto_stream_play(struct connection *c, PA_GCC_UNUSED esd_proto_t
strncpy(name, data, sizeof(name));
name[sizeof(name)-1] = 0;
+
utf8_name = pa_utf8_filter(name);
-
pa_client_set_name(c->client, utf8_name);
+ pa_xfree(utf8_name);
+
c->original_name = pa_xstrdup(name);
assert(!c->sink_input && !c->input_memblockq);
@@ -359,15 +361,12 @@ static int esd_proto_stream_play(struct connection *c, PA_GCC_UNUSED esd_proto_t
pa_sink_input_new_data_init(&sdata);
sdata.sink = sink;
sdata.driver = __FILE__;
- sdata.name = utf8_name;
+ sdata.name = c->client->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);
-
CHECK_VALIDITY(c->sink_input, "Failed to create sink input.");
l = (size_t) (pa_bytes_per_second(&ss)*PLAYBACK_BUFFER_SECONDS);
@@ -402,6 +401,7 @@ static int esd_proto_stream_record(struct connection *c, esd_proto_t request, co
pa_source *source;
pa_sample_spec ss;
size_t l;
+ pa_source_output_new_data sdata;
assert(c && length == (sizeof(int32_t)*2+ESD_NAME_MAX));
@@ -450,10 +450,16 @@ static int esd_proto_stream_record(struct connection *c, esd_proto_t request, co
assert(!c->output_memblockq && !c->source_output);
- if (!(c->source_output = pa_source_output_new(source, __FILE__, c->client->name, &ss, NULL, -1))) {
- pa_log(__FILE__": failed to create source output");
- return -1;
- }
+ pa_source_output_new_data_init(&sdata);
+ sdata.source = source;
+ sdata.driver = __FILE__;
+ sdata.name = c->client->name;
+ pa_source_output_new_data_set_sample_spec(&sdata, &ss);
+ sdata.module = c->protocol->module;
+ sdata.client = c->client;
+
+ c->source_output = pa_source_output_new(c->protocol->core, &sdata, 9);
+ CHECK_VALIDITY(c->sink_input, "Failed to create source_output.");
l = (size_t) (pa_bytes_per_second(&ss)*RECORD_BUFFER_SECONDS);
c->output_memblockq = pa_memblockq_new(
@@ -467,8 +473,6 @@ static int esd_proto_stream_record(struct connection *c, esd_proto_t request, co
c->protocol->core->memblock_stat);
pa_iochannel_socket_set_sndbuf(c->io, l/RECORD_BUFFER_FRAGMENTS*2);
- c->source_output->owner = c->protocol->module;
- c->source_output->client = c->client;
c->source_output->push = source_output_push_cb;
c->source_output->kill = source_output_kill_cb;
c->source_output->get_latency = source_output_get_latency_cb;
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index e5344448..0b79892c 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -317,9 +317,20 @@ static struct record_stream* record_stream_new(
struct record_stream *s;
pa_source_output *source_output;
size_t base;
+ pa_source_output_new_data data;
+
assert(c && source && ss && name && maxlength);
- if (!(source_output = pa_source_output_new(source, __FILE__, name, ss, map, -1)))
+ pa_source_output_new_data_init(&data);
+ data.source = source;
+ data.driver = __FILE__;
+ data.name = name;
+ pa_source_output_new_data_set_sample_spec(&data, ss);
+ pa_source_output_new_data_set_channel_map(&data, map);
+ data.module = c->protocol->module;
+ data.client = c->client;
+
+ if (!(source_output = pa_source_output_new(source->core, &data, 0)))
return NULL;
s = pa_xnew(struct record_stream, 1);
@@ -329,8 +340,6 @@ static struct record_stream* record_stream_new(
s->source_output->kill = source_output_kill_cb;
s->source_output->get_latency = source_output_get_latency_cb;
s->source_output->userdata = s;
- s->source_output->owner = c->protocol->module;
- s->source_output->client = c->client;
s->memblockq = pa_memblockq_new(
0,
@@ -1356,7 +1365,7 @@ static void source_output_fill_tagstruct(pa_tagstruct *t, pa_source_output *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->source->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 5071191a..3705986d 100644
--- a/src/pulsecore/protocol-simple.c
+++ b/src/pulsecore/protocol-simple.c
@@ -379,22 +379,20 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
}
if (p->mode & RECORD) {
- pa_source *source;
+ pa_source_output_new_data data;
size_t l;
- if (!(source = pa_namereg_get(p->core, p->source_name, PA_NAMEREG_SOURCE, 1))) {
- pa_log(__FILE__": Failed to get source.");
- goto fail;
- }
+ pa_source_output_new_data_init(&data);
+ data.driver = __FILE__;
+ data.name = c->client->name;
+ pa_source_output_new_data_set_sample_spec(&data, &p->sample_spec);
+ data.module = p->module;
+ data.client = c->client;
- c->source_output = pa_source_output_new(source, __FILE__, c->client->name, &p->sample_spec, NULL, -1);
- if (!c->source_output) {
+ if (!(c->source_output = pa_source_output_new(p->core, &data, 0))) {
pa_log(__FILE__": Failed to create source output.");
goto fail;
}
- c->source_output->owner = p->module;
- c->source_output->client = c->client;
-
c->source_output->push = source_output_push_cb;
c->source_output->kill = source_output_kill_cb;
c->source_output->get_latency = source_output_get_latency_cb;
@@ -411,6 +409,7 @@ static void on_connection(pa_socket_server*s, pa_iochannel *io, void *userdata)
NULL,
p->core->memblock_stat);
pa_iochannel_socket_set_sndbuf(io, l/RECORD_BUFFER_FRAGMENTS*2);
+ pa_source_notify(c->source_output->source);
}
pa_iochannel_set_callback(c->io, io_callback, c);
diff --git a/src/pulsecore/sink-input.h b/src/pulsecore/sink-input.h
index da0c2662..2943dfae 100644
--- a/src/pulsecore/sink-input.h
+++ b/src/pulsecore/sink-input.h
@@ -106,7 +106,10 @@ void pa_sink_input_new_data_set_sample_spec(pa_sink_input_new_data *data, const
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);
+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/source-output.c b/src/pulsecore/source-output.c
index 36ea420c..7371474f 100644
--- a/src/pulsecore/source-output.c
+++ b/src/pulsecore/source-output.c
@@ -33,6 +33,7 @@
#include <pulsecore/core-subscribe.h>
#include <pulsecore/log.h>
+#include <pulsecore/namereg.h>
#include "source-output.h"
@@ -42,44 +43,82 @@ if (!(condition)) \
return NULL; \
} while (0)
+pa_source_output_new_data* pa_source_output_new_data_init(pa_source_output_new_data *data) {
+ assert(data);
+
+ memset(data, 0, sizeof(*data));
+ data->resample_method = PA_RESAMPLER_INVALID;
+ return data;
+}
+
+void pa_source_output_new_data_set_channel_map(pa_source_output_new_data *data, const pa_channel_map *map) {
+ assert(data);
+
+ if ((data->channel_map_is_set = !!map))
+ data->channel_map = *map;
+}
+
+void pa_source_output_new_data_set_sample_spec(pa_source_output_new_data *data, const pa_sample_spec *spec) {
+ assert(data);
+
+ if ((data->sample_spec_is_set = !!spec))
+ data->sample_spec = *spec;
+}
+
pa_source_output* pa_source_output_new(
- pa_source *s,
- const char *driver,
- const char *name,
- const pa_sample_spec *spec,
- const pa_channel_map *map,
- int resample_method) {
+ pa_core *core,
+ pa_source_output_new_data *data,
+ pa_source_output_flags_t flags) {
pa_source_output *o;
pa_resampler *resampler = NULL;
int r;
- char st[256];
- pa_channel_map tmap;
+ char st[PA_SAMPLE_SPEC_SNPRINT_MAX];
+
+ assert(core);
+ assert(data);
- assert(s);
- assert(spec);
- assert(s->state == PA_SOURCE_RUNNING);
+ if (!(flags & PA_SOURCE_OUTPUT_NO_HOOKS))
+ if (pa_hook_fire(&core->hook_source_output_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->source)
+ data->source = pa_namereg_get(core, NULL, PA_NAMEREG_SOURCE, 1);
- CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(spec));
+ CHECK_VALIDITY_RETURN_NULL(data->source);
+ CHECK_VALIDITY_RETURN_NULL(data->source->state == PA_SOURCE_RUNNING);
+
+ if (!data->sample_spec_is_set)
+ data->sample_spec = data->source->sample_spec;
+
+ CHECK_VALIDITY_RETURN_NULL(pa_sample_spec_valid(&data->sample_spec));
- if (!map)
- map = pa_channel_map_init_auto(&tmap, spec->channels, PA_CHANNEL_MAP_DEFAULT);
+ 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(map && pa_channel_map_valid(map));
- CHECK_VALIDITY_RETURN_NULL(map->channels == spec->channels);
- CHECK_VALIDITY_RETURN_NULL(!driver || pa_utf8_valid(driver));
- CHECK_VALIDITY_RETURN_NULL(pa_utf8_valid(name));
+ CHECK_VALIDITY_RETURN_NULL(pa_channel_map_valid(&data->channel_map));
+ CHECK_VALIDITY_RETURN_NULL(data->channel_map.channels == data->sample_spec.channels);
- if (pa_idxset_size(s->outputs) >= PA_MAX_OUTPUTS_PER_SOURCE) {
+ 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->source->outputs) >= PA_MAX_OUTPUTS_PER_SOURCE) {
pa_log(__FILE__": Failed to create source output: too many outputs per source.");
return NULL;
}
- if (resample_method == PA_RESAMPLER_INVALID)
- resample_method = s->core->resample_method;
-
- if (!pa_sample_spec_equal(&s->sample_spec, spec) || !pa_channel_map_equal(&s->channel_map, map))
- if (!(resampler = pa_resampler_new(&s->sample_spec, &s->channel_map, spec, map, s->core->memblock_stat, resample_method))) {
+ if (!pa_sample_spec_equal(&data->sample_spec, &data->source->sample_spec) ||
+ !pa_channel_map_equal(&data->channel_map, &data->source->channel_map))
+ if (!(resampler = pa_resampler_new(
+ &data->source->sample_spec, &data->source->channel_map,
+ &data->sample_spec, &data->channel_map,
+ core->memblock_stat,
+ data->resample_method))) {
pa_log_warn(__FILE__": Unsupported resampling operation.");
return NULL;
}
@@ -87,14 +126,14 @@ pa_source_output* pa_source_output_new(
o = pa_xnew(pa_source_output, 1);
o->ref = 1;
o->state = PA_SOURCE_OUTPUT_RUNNING;
- o->name = pa_xstrdup(name);
- o->driver = pa_xstrdup(driver);
- o->owner = NULL;
- o->source = s;
- o->client = NULL;
+ o->name = pa_xstrdup(data->name);
+ o->driver = pa_xstrdup(data->driver);
+ o->module = data->module;
+ o->source = data->source;
+ o->client = data->client;
- o->sample_spec = *spec;
- o->channel_map = *map;
+ o->sample_spec = data->sample_spec;
+ o->channel_map = data->channel_map;
o->push = NULL;
o->kill = NULL;
@@ -102,18 +141,20 @@ pa_source_output* pa_source_output_new(
o->userdata = NULL;
o->resampler = resampler;
- o->resample_method = resample_method;
+ o->resample_method = data->resample_method;
- assert(s->core);
- r = pa_idxset_put(s->core->source_outputs, o, &o->index);
- assert(r == 0 && o->index != PA_IDXSET_INVALID);
- r = pa_idxset_put(s->outputs, o, NULL);
+ r = pa_idxset_put(core->source_outputs, o, &o->index);
+ assert(r == 0);
+ r = pa_idxset_put(o->source->outputs, o, 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\"", o->index, o->name, s->index, st);
+ pa_log_info(__FILE__": created %u \"%s\" on %s with sample spec %s",
+ o->index,
+ o->name,
+ o->source->name,
+ pa_sample_spec_snprint(st, sizeof(st), &o->sample_spec));
- pa_subscription_post(s->core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_NEW, o->index);
+ pa_subscription_post(core, PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT|PA_SUBSCRIPTION_EVENT_NEW, o->index);
/* We do not call pa_source_notify() here, because the virtual
* functions have not yet been initialized */
diff --git a/src/pulsecore/source-output.h b/src/pulsecore/source-output.h
index acf53bd1..f7396a19 100644
--- a/src/pulsecore/source-output.h
+++ b/src/pulsecore/source-output.h
@@ -39,13 +39,17 @@ typedef enum {
PA_SOURCE_OUTPUT_DISCONNECTED
} pa_source_output_state_t;
+typedef enum pa_source_output_flags {
+ PA_SOURCE_OUTPUT_NO_HOOKS = 1
+} pa_source_output_flags_t;
+
struct pa_source_output {
int ref;
uint32_t index;
pa_source_output_state_t state;
char *name, *driver; /* may be NULL */
- pa_module *owner; /* may be NULL */
+ pa_module *module; /* may be NULL */
pa_source *source;
pa_client *client; /* may be NULL */
@@ -63,13 +67,30 @@ struct pa_source_output {
void *userdata;
};
+typedef struct pa_source_output_new_data {
+ const char *name, *driver;
+ pa_module *module;
+ pa_client *client;
+
+ pa_source *source;
+
+ pa_sample_spec sample_spec;
+ int sample_spec_is_set;
+ pa_channel_map channel_map;
+ int channel_map_is_set;
+
+ pa_resample_method_t resample_method;
+} pa_source_output_new_data;
+
+pa_source_output_new_data* pa_source_output_new_data_init(pa_source_output_new_data *data);
+void pa_source_output_new_data_set_sample_spec(pa_source_output_new_data *data, const pa_sample_spec *spec);
+void pa_source_output_new_data_set_channel_map(pa_source_output_new_data *data, const pa_channel_map *map);
+void pa_source_output_new_data_set_volume(pa_source_output_new_data *data, const pa_cvolume *volume);
+
pa_source_output* pa_source_output_new(
- pa_source *s,
- const char *driver,
- const char *name,
- const pa_sample_spec *spec,
- const pa_channel_map *map,
- int resample_method);
+ pa_core *core,
+ pa_source_output_new_data *data,
+ pa_source_output_flags_t flags);
void pa_source_output_unref(pa_source_output* o);
pa_source_output* pa_source_output_ref(pa_source_output *o);