From 08800c35b072820ba485a5a0a211ce91a1656390 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 3 Feb 2009 03:14:20 +0100 Subject: make a couple of functions return proper error codes --- src/modules/module-combine.c | 2 +- src/modules/module-ladspa-sink.c | 2 +- src/modules/module-remap-sink.c | 2 +- src/modules/module-sine.c | 2 +- src/modules/rtp/module-rtp-recv.c | 2 +- src/modules/rtp/module-rtp-send.c | 2 +- src/pulsecore/play-memblockq.c | 2 +- src/pulsecore/protocol-esound.c | 4 +- src/pulsecore/protocol-native.c | 26 +++++++---- src/pulsecore/protocol-simple.c | 4 +- src/pulsecore/sink-input.c | 90 ++++++++++++++++++++------------------- src/pulsecore/sink-input.h | 5 ++- src/pulsecore/sound-file-stream.c | 2 +- src/pulsecore/source-output.c | 79 +++++++++++++++++----------------- src/pulsecore/source-output.h | 3 +- 15 files changed, 122 insertions(+), 105 deletions(-) (limited to 'src') diff --git a/src/modules/module-combine.c b/src/modules/module-combine.c index 82c88711..7f1ef24c 100644 --- a/src/modules/module-combine.c +++ b/src/modules/module-combine.c @@ -799,7 +799,7 @@ static int output_create_sink_input(struct output *o) { data.module = o->userdata->module; data.resample_method = o->userdata->resample_method; - o->sink_input = pa_sink_input_new(o->userdata->core, &data, PA_SINK_INPUT_VARIABLE_RATE|PA_SINK_INPUT_DONT_MOVE); + pa_sink_input_new(&o->sink_input, o->userdata->core, &data, PA_SINK_INPUT_VARIABLE_RATE|PA_SINK_INPUT_DONT_MOVE); pa_sink_input_new_data_done(&data); diff --git a/src/modules/module-ladspa-sink.c b/src/modules/module-ladspa-sink.c index e746f342..a4007b1a 100644 --- a/src/modules/module-ladspa-sink.c +++ b/src/modules/module-ladspa-sink.c @@ -732,7 +732,7 @@ int pa__init(pa_module*m) { pa_sink_input_new_data_set_sample_spec(&sink_input_data, &ss); pa_sink_input_new_data_set_channel_map(&sink_input_data, &map); - u->sink_input = pa_sink_input_new(m->core, &sink_input_data, PA_SINK_INPUT_DONT_MOVE); + pa_sink_input_new(&u->sink_input, m->core, &sink_input_data, PA_SINK_INPUT_DONT_MOVE); pa_sink_input_new_data_done(&sink_input_data); if (!u->sink_input) diff --git a/src/modules/module-remap-sink.c b/src/modules/module-remap-sink.c index e17fef03..89ddf953 100644 --- a/src/modules/module-remap-sink.c +++ b/src/modules/module-remap-sink.c @@ -381,7 +381,7 @@ int pa__init(pa_module*m) { pa_sink_input_new_data_set_sample_spec(&sink_input_data, &ss); pa_sink_input_new_data_set_channel_map(&sink_input_data, &stream_map); - u->sink_input = pa_sink_input_new(m->core, &sink_input_data, PA_SINK_INPUT_DONT_MOVE | (remix ? 0 : PA_SINK_INPUT_NO_REMIX)); + pa_sink_input_new(&u->sink_input, m->core, &sink_input_data, PA_SINK_INPUT_DONT_MOVE | (remix ? 0 : PA_SINK_INPUT_NO_REMIX)); pa_sink_input_new_data_done(&sink_input_data); if (!u->sink_input) diff --git a/src/modules/module-sine.c b/src/modules/module-sine.c index b0782c3c..ce08c01d 100644 --- a/src/modules/module-sine.c +++ b/src/modules/module-sine.c @@ -163,7 +163,7 @@ int pa__init(pa_module*m) { pa_proplist_setf(data.proplist, "sine.hz", "%u", frequency); pa_sink_input_new_data_set_sample_spec(&data, &ss); - u->sink_input = pa_sink_input_new(m->core, &data, 0); + pa_sink_input_new(&u->sink_input, m->core, &data, 0); pa_sink_input_new_data_done(&data); if (!u->sink_input) diff --git a/src/modules/rtp/module-rtp-recv.c b/src/modules/rtp/module-rtp-recv.c index 00d21255..baf3532f 100644 --- a/src/modules/rtp/module-rtp-recv.c +++ b/src/modules/rtp/module-rtp-recv.c @@ -453,7 +453,7 @@ static struct session *session_new(struct userdata *u, const pa_sdp_info *sdp_in 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->module->core, &data, 0); + pa_sink_input_new(&s->sink_input, u->module->core, &data, 0); pa_sink_input_new_data_done(&data); if (!s->sink_input) { diff --git a/src/modules/rtp/module-rtp-send.c b/src/modules/rtp/module-rtp-send.c index a6d682bb..762cdc1e 100644 --- a/src/modules/rtp/module-rtp-send.c +++ b/src/modules/rtp/module-rtp-send.c @@ -321,7 +321,7 @@ int pa__init(pa_module*m) { pa_source_output_new_data_set_sample_spec(&data, &ss); pa_source_output_new_data_set_channel_map(&data, &cm); - o = pa_source_output_new(m->core, &data, PA_SOURCE_OUTPUT_DONT_INHIBIT_AUTO_SUSPEND); + pa_source_output_new(&o, m->core, &data, PA_SOURCE_OUTPUT_DONT_INHIBIT_AUTO_SUSPEND); pa_source_output_new_data_done(&data); if (!o) { diff --git a/src/pulsecore/play-memblockq.c b/src/pulsecore/play-memblockq.c index eac21de5..d1631264 100644 --- a/src/pulsecore/play-memblockq.c +++ b/src/pulsecore/play-memblockq.c @@ -200,7 +200,7 @@ pa_sink_input* pa_memblockq_sink_input_new( pa_sink_input_new_data_set_virtual_volume(&data, volume); pa_proplist_update(data.proplist, PA_UPDATE_REPLACE, p); - u->sink_input = pa_sink_input_new(sink->core, &data, 0); + pa_sink_input_new(&u->sink_input, sink->core, &data, 0); pa_sink_input_new_data_done(&data); if (!u->sink_input) diff --git a/src/pulsecore/protocol-esound.c b/src/pulsecore/protocol-esound.c index 1311e678..e1643cbb 100644 --- a/src/pulsecore/protocol-esound.c +++ b/src/pulsecore/protocol-esound.c @@ -424,7 +424,7 @@ static int esd_proto_stream_play(connection *c, esd_proto_t request, const void sdata.sink = sink; pa_sink_input_new_data_set_sample_spec(&sdata, &ss); - c->sink_input = pa_sink_input_new(c->protocol->core, &sdata, 0); + pa_sink_input_new(&c->sink_input, c->protocol->core, &sdata, 0); pa_sink_input_new_data_done(&sdata); CHECK_VALIDITY(c->sink_input, "Failed to create sink input."); @@ -526,7 +526,7 @@ static int esd_proto_stream_record(connection *c, esd_proto_t request, const voi sdata.source = source; pa_source_output_new_data_set_sample_spec(&sdata, &ss); - c->source_output = pa_source_output_new(c->protocol->core, &sdata, 0); + pa_source_output_new(&c->source_output, c->protocol->core, &sdata, 0); pa_source_output_new_data_done(&sdata); CHECK_VALIDITY(c->source_output, "Failed to create source output."); diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index e8080bfe..21a2cfbc 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -591,7 +591,8 @@ static record_stream* record_stream_new( pa_proplist *p, pa_bool_t adjust_latency, pa_sink_input *direct_on_input, - pa_bool_t early_requests) { + pa_bool_t early_requests, + int *ret) { record_stream *s; pa_source_output *source_output; @@ -602,6 +603,7 @@ static record_stream* record_stream_new( pa_assert(ss); pa_assert(maxlength); pa_assert(p); + pa_assert(ret); pa_source_output_new_data_init(&data); @@ -616,7 +618,7 @@ static record_stream* record_stream_new( if (peak_detect) data.resample_method = PA_RESAMPLER_PEAKS; - source_output = pa_source_output_new(c->protocol->core, &data, flags); + *ret = pa_source_output_new(&source_output, c->protocol->core, &data, flags); pa_source_output_new_data_done(&data); @@ -965,7 +967,8 @@ static playback_stream* playback_stream_new( pa_sink_input_flags_t flags, pa_proplist *p, pa_bool_t adjust_latency, - pa_bool_t early_requests) { + pa_bool_t early_requests, + int *ret) { playback_stream *s, *ssync; pa_sink_input *sink_input; @@ -982,6 +985,7 @@ static playback_stream* playback_stream_new( pa_assert(minreq); pa_assert(missing); pa_assert(p); + pa_assert(ret); /* Find syncid group */ for (ssync = pa_idxset_first(c->output_streams, &idx); ssync; ssync = pa_idxset_next(c->output_streams, &idx)) { @@ -998,8 +1002,10 @@ static playback_stream* playback_stream_new( if (!sink) sink = ssync->sink_input->sink; - else if (sink != ssync->sink_input->sink) + else if (sink != ssync->sink_input->sink) { + *ret = PA_ERR_INVALID; return NULL; + } } pa_sink_input_new_data_init(&data); @@ -1017,7 +1023,7 @@ static playback_stream* playback_stream_new( pa_sink_input_new_data_set_muted(&data, muted); data.sync_base = ssync ? ssync->sink_input : NULL; - sink_input = pa_sink_input_new(c->protocol->core, &data, flags); + *ret = pa_sink_input_new(&sink_input, c->protocol->core, &data, flags); pa_sink_input_new_data_done(&data); @@ -1696,6 +1702,7 @@ static void command_create_playback_stream(pa_pdispatch *pd, uint32_t command, u pa_sink_input_flags_t flags = 0; pa_proplist *p; pa_bool_t volume_set = TRUE; + int ret = PA_ERR_INVALID; pa_native_connection_assert_ref(c); pa_assert(t); @@ -1822,10 +1829,10 @@ static void command_create_playback_stream(pa_pdispatch *pd, uint32_t command, u * flag. For older versions we synthesize it here */ muted_set = muted_set || muted; - s = playback_stream_new(c, sink, &ss, &map, &maxlength, &tlength, &prebuf, &minreq, volume_set ? &volume : NULL, muted, muted_set, syncid, &missing, flags, p, adjust_latency, early_requests); + s = playback_stream_new(c, sink, &ss, &map, &maxlength, &tlength, &prebuf, &minreq, volume_set ? &volume : NULL, muted, muted_set, syncid, &missing, flags, p, adjust_latency, early_requests, &ret); pa_proplist_free(p); - CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_INVALID); + CHECK_VALIDITY(c->pstream, s, tag, ret); reply = reply_new(tag); pa_tagstruct_putu32(reply, s->index); @@ -1950,6 +1957,7 @@ static void command_create_record_stream(pa_pdispatch *pd, uint32_t command, uin pa_proplist *p; uint32_t direct_on_input_idx = PA_INVALID_INDEX; pa_sink_input *direct_on_input = NULL; + int ret = PA_ERR_INVALID; pa_native_connection_assert_ref(c); pa_assert(t); @@ -2071,10 +2079,10 @@ static void command_create_record_stream(pa_pdispatch *pd, uint32_t command, uin (dont_inhibit_auto_suspend ? PA_SOURCE_OUTPUT_DONT_INHIBIT_AUTO_SUSPEND : 0) | (fail_on_suspend ? PA_SOURCE_OUTPUT_FAIL_ON_SUSPEND : 0); - s = record_stream_new(c, source, &ss, &map, peak_detect, &maxlength, &fragment_size, flags, p, adjust_latency, direct_on_input, early_requests); + s = record_stream_new(c, source, &ss, &map, peak_detect, &maxlength, &fragment_size, flags, p, adjust_latency, direct_on_input, early_requests, &ret); pa_proplist_free(p); - CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_INVALID); + CHECK_VALIDITY(c->pstream, s, tag, ret); reply = reply_new(tag); pa_tagstruct_putu32(reply, s->index); diff --git a/src/pulsecore/protocol-simple.c b/src/pulsecore/protocol-simple.c index dd8002a3..e149c40d 100644 --- a/src/pulsecore/protocol-simple.c +++ b/src/pulsecore/protocol-simple.c @@ -539,7 +539,7 @@ void pa_simple_protocol_connect(pa_simple_protocol *p, pa_iochannel *io, pa_simp pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist); pa_sink_input_new_data_set_sample_spec(&data, &o->sample_spec); - c->sink_input = pa_sink_input_new(p->core, &data, 0); + pa_sink_input_new(&c->sink_input, p->core, &data, 0); pa_sink_input_new_data_done(&data); if (!c->sink_input) { @@ -591,7 +591,7 @@ void pa_simple_protocol_connect(pa_simple_protocol *p, pa_iochannel *io, pa_simp pa_proplist_update(data.proplist, PA_UPDATE_MERGE, c->client->proplist); pa_source_output_new_data_set_sample_spec(&data, &o->sample_spec); - c->source_output = pa_source_output_new(p->core, &data, 0); + pa_source_output_new(&c->source_output, p->core, &data, 0); pa_source_output_new_data_done(&data); if (!c->source_output) { diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c index cc3e108a..a3a29e9b 100644 --- a/src/pulsecore/sink-input.c +++ b/src/pulsecore/sink-input.c @@ -120,7 +120,8 @@ static void reset_callbacks(pa_sink_input *i) { } /* Called from main context */ -pa_sink_input* pa_sink_input_new( +int pa_sink_input_new( + pa_sink_input **_i, pa_core *core, pa_sink_input_new_data *data, pa_sink_input_flags_t flags) { @@ -129,32 +130,31 @@ pa_sink_input* pa_sink_input_new( pa_resampler *resampler = NULL; char st[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX]; pa_channel_map original_cm; + int r; + pa_assert(_i); pa_assert(core); pa_assert(data); - if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], data) < 0) - return NULL; + if ((r = pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_INPUT_NEW], data)) < 0) + return r; - pa_return_null_if_fail(!data->driver || pa_utf8_valid(data->driver)); + pa_return_val_if_fail(!data->driver || pa_utf8_valid(data->driver), -PA_ERR_INVALID); if (!data->sink) { data->sink = pa_namereg_get(core, NULL, PA_NAMEREG_SINK); data->save_sink = FALSE; } - pa_return_null_if_fail(data->sink); - pa_return_null_if_fail(PA_SINK_IS_LINKED(pa_sink_get_state(data->sink))); - pa_return_null_if_fail(!data->sync_base || (data->sync_base->sink == data->sink && pa_sink_input_get_state(data->sync_base) == PA_SINK_INPUT_CORKED)); - - if ((flags & PA_SINK_INPUT_FAIL_ON_SUSPEND) && - pa_sink_get_state(data->sink) == PA_SINK_SUSPENDED) - return NULL; + pa_return_val_if_fail(data->sink, -PA_ERR_NOENTITY); + pa_return_val_if_fail(PA_SINK_IS_LINKED(pa_sink_get_state(data->sink)), -PA_ERR_BADSTATE); + pa_return_val_if_fail(!data->sync_base || (data->sync_base->sink == data->sink && pa_sink_input_get_state(data->sync_base) == PA_SINK_INPUT_CORKED), -PA_ERR_INVALID); + pa_return_val_if_fail(!(flags & PA_SINK_INPUT_FAIL_ON_SUSPEND) || pa_sink_get_state(data->sink) != PA_SINK_SUSPENDED, -PA_ERR_BADSTATE); if (!data->sample_spec_is_set) data->sample_spec = data->sink->sample_spec; - pa_return_null_if_fail(pa_sample_spec_valid(&data->sample_spec)); + pa_return_val_if_fail(pa_sample_spec_valid(&data->sample_spec), -PA_ERR_INVALID); if (!data->channel_map_is_set) { if (pa_channel_map_compatible(&data->sink->channel_map, &data->sample_spec)) @@ -163,8 +163,8 @@ pa_sink_input* pa_sink_input_new( pa_channel_map_init_extend(&data->channel_map, data->sample_spec.channels, PA_CHANNEL_MAP_DEFAULT); } - pa_return_null_if_fail(pa_channel_map_valid(&data->channel_map)); - pa_return_null_if_fail(pa_channel_map_compatible(&data->channel_map, &data->sample_spec)); + pa_return_val_if_fail(pa_channel_map_valid(&data->channel_map), -PA_ERR_INVALID); + pa_return_val_if_fail(pa_channel_map_compatible(&data->channel_map, &data->sample_spec), -PA_ERR_INVALID); if (!data->virtual_volume_is_set) { @@ -187,14 +187,14 @@ pa_sink_input* pa_sink_input_new( } } - pa_return_null_if_fail(pa_cvolume_valid(&data->virtual_volume)); - pa_return_null_if_fail(pa_cvolume_compatible(&data->virtual_volume, &data->sample_spec)); + pa_return_val_if_fail(pa_cvolume_valid(&data->virtual_volume), -PA_ERR_INVALID); + pa_return_val_if_fail(pa_cvolume_compatible(&data->virtual_volume, &data->sample_spec), -PA_ERR_INVALID); if (!data->soft_volume_is_set) data->soft_volume = data->virtual_volume; - pa_return_null_if_fail(pa_cvolume_valid(&data->soft_volume)); - pa_return_null_if_fail(pa_cvolume_compatible(&data->soft_volume, &data->sample_spec)); + pa_return_val_if_fail(pa_cvolume_valid(&data->soft_volume), -PA_ERR_INVALID); + pa_return_val_if_fail(pa_cvolume_compatible(&data->soft_volume, &data->sample_spec), -PA_ERR_INVALID); if (!data->muted_is_set) data->muted = FALSE; @@ -222,17 +222,17 @@ pa_sink_input* pa_sink_input_new( if (data->resample_method == PA_RESAMPLER_INVALID) data->resample_method = core->resample_method; - pa_return_null_if_fail(data->resample_method < PA_RESAMPLER_MAX); + pa_return_val_if_fail(data->resample_method < PA_RESAMPLER_MAX, -PA_ERR_INVALID); if (data->client) pa_proplist_update(data->proplist, PA_UPDATE_MERGE, data->client->proplist); - if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], data) < 0) - return NULL; + if ((r = pa_hook_fire(&core->hooks[PA_CORE_HOOK_SINK_INPUT_FIXATE], data)) < 0) + return r; if (pa_idxset_size(data->sink->inputs) >= PA_MAX_INPUTS_PER_SINK) { pa_log_warn("Failed to create sink input: too many inputs per sink."); - return NULL; + return -PA_ERR_TOOLARGE; } if ((flags & PA_SINK_INPUT_VARIABLE_RATE) || @@ -249,7 +249,7 @@ pa_sink_input* pa_sink_input_new( (core->disable_remixing || (flags & PA_SINK_INPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0) | (core->disable_lfe_remixing ? PA_RESAMPLER_NO_LFE : 0)))) { pa_log_warn("Unsupported resampling operation."); - return NULL; + return -PA_ERR_NOTSUPPORTED; } } @@ -334,7 +334,8 @@ pa_sink_input* pa_sink_input_new( /* Don't forget to call pa_sink_input_put! */ - return i; + *_i = i; + return 0; } /* Called from main context */ @@ -957,7 +958,7 @@ void pa_sink_input_cork(pa_sink_input *i, pa_bool_t b) { int pa_sink_input_set_rate(pa_sink_input *i, uint32_t rate) { pa_sink_input_assert_ref(i); pa_assert(PA_SINK_INPUT_IS_LINKED(i->state)); - pa_return_val_if_fail(i->thread_info.resampler, -1); + pa_return_val_if_fail(i->thread_info.resampler, -PA_ERR_BADSTATE); if (i->sample_spec.rate == rate) return 0; @@ -1045,16 +1046,17 @@ pa_bool_t pa_sink_input_may_move_to(pa_sink_input *i, pa_sink *dest) { int pa_sink_input_start_move(pa_sink_input *i) { pa_source_output *o, *p = NULL; pa_sink *origin; + int r; pa_sink_input_assert_ref(i); pa_assert(PA_SINK_INPUT_IS_LINKED(i->state)); pa_assert(i->sink); if (!pa_sink_input_may_move(i)) - return -1; + return -PA_ERR_NOTSUPPORTED; - if (pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_START], i) < 0) - return -1; + if ((r = pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_START], i)) < 0) + return r; origin = i->sink; @@ -1096,14 +1098,7 @@ int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, pa_bool_t save) { pa_sink_assert_ref(dest); if (!pa_sink_input_may_move_to(i, dest)) - return -1; - - i->sink = dest; - i->save_sink = save; - pa_idxset_put(dest->inputs, i, NULL); - - if (pa_sink_input_get_state(i) == PA_SINK_INPUT_CORKED) - i->sink->n_corked++; + return -PA_ERR_NOTSUPPORTED; if (i->thread_info.resampler && pa_sample_spec_equal(pa_resampler_output_sample_spec(i->thread_info.resampler), &dest->sample_spec) && @@ -1127,11 +1122,18 @@ int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, pa_bool_t save) { ((i->flags & PA_SINK_INPUT_NO_REMAP) ? PA_RESAMPLER_NO_REMAP : 0) | (i->core->disable_remixing || (i->flags & PA_SINK_INPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0)))) { pa_log_warn("Unsupported resampling operation."); - return -1; + return -PA_ERR_NOTSUPPORTED; } } else new_resampler = NULL; + i->sink = dest; + i->save_sink = save; + pa_idxset_put(dest->inputs, i, NULL); + + if (pa_sink_input_get_state(i) == PA_SINK_INPUT_CORKED) + i->sink->n_corked++; + /* Replace resampler and render queue */ if (new_resampler != i->thread_info.resampler) { @@ -1177,6 +1179,8 @@ int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, pa_bool_t save) { /* Called from main context */ int pa_sink_input_move_to(pa_sink_input *i, pa_sink *dest, pa_bool_t save) { + int r; + pa_sink_input_assert_ref(i); pa_assert(PA_SINK_INPUT_IS_LINKED(i->state)); pa_assert(i->sink); @@ -1186,13 +1190,13 @@ int pa_sink_input_move_to(pa_sink_input *i, pa_sink *dest, pa_bool_t save) { return 0; if (!pa_sink_input_may_move_to(i, dest)) - return -1; + return -PA_ERR_NOTSUPPORTED; - if (pa_sink_input_start_move(i) < 0) - return -1; + if ((r = pa_sink_input_start_move(i)) < 0) + return r; - if (pa_sink_input_finish_move(i, dest, save) < 0) - return -1; + if ((r = pa_sink_input_finish_move(i, dest, save)) < 0) + return r; return 0; } @@ -1307,7 +1311,7 @@ int pa_sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t } } - return -1; + return -PA_ERR_NOTIMPLEMENTED; } /* Called from main thread */ diff --git a/src/pulsecore/sink-input.h b/src/pulsecore/sink-input.h index c27f6253..d82a3a62 100644 --- a/src/pulsecore/sink-input.h +++ b/src/pulsecore/sink-input.h @@ -257,7 +257,8 @@ void pa_sink_input_new_data_done(pa_sink_input_new_data *data); /* To be called by the implementing module only */ -pa_sink_input* pa_sink_input_new( +int pa_sink_input_new( + pa_sink_input **i, pa_core *core, pa_sink_input_new_data *data, pa_sink_input_flags_t flags); @@ -313,7 +314,7 @@ pa_usec_t pa_sink_input_get_requested_latency(pa_sink_input *i); /* To be used exclusively by the sink driver IO thread */ -int pa_sink_input_peek(pa_sink_input *i, size_t length, pa_memchunk *chunk, pa_cvolume *volume); +void pa_sink_input_peek(pa_sink_input *i, size_t length, pa_memchunk *chunk, pa_cvolume *volume); void pa_sink_input_drop(pa_sink_input *i, size_t length); void pa_sink_input_process_rewind(pa_sink_input *i, size_t nbytes /* in the sink's sample spec */); void pa_sink_input_update_max_rewind(pa_sink_input *i, size_t nbytes /* in the sink's sample spec */); diff --git a/src/pulsecore/sound-file-stream.c b/src/pulsecore/sound-file-stream.c index 1be421f1..67b072b6 100644 --- a/src/pulsecore/sound-file-stream.c +++ b/src/pulsecore/sound-file-stream.c @@ -326,7 +326,7 @@ int pa_play_file( pa_proplist_sets(data.proplist, PA_PROP_MEDIA_NAME, pa_path_get_filename(fname)); pa_proplist_sets(data.proplist, PA_PROP_MEDIA_FILENAME, fname); - u->sink_input = pa_sink_input_new(sink->core, &data, 0); + pa_sink_input_new(&u->sink_input, sink->core, &data, 0); pa_sink_input_new_data_done(&data); if (!u->sink_input) diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c index 0204e300..c5cb16d8 100644 --- a/src/pulsecore/source-output.c +++ b/src/pulsecore/source-output.c @@ -95,7 +95,8 @@ static void reset_callbacks(pa_source_output *o) { } /* Called from main context */ -pa_source_output* pa_source_output_new( +int pa_source_output_new( + pa_source_output**_o, pa_core *core, pa_source_output_new_data *data, pa_source_output_flags_t flags) { @@ -103,32 +104,31 @@ pa_source_output* pa_source_output_new( pa_source_output *o; pa_resampler *resampler = NULL; char st[PA_SAMPLE_SPEC_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX]; + int r; + pa_assert(_o); pa_assert(core); pa_assert(data); - if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_NEW], data) < 0) - return NULL; + if ((r = pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_NEW], data)) < 0) + return r; - pa_return_null_if_fail(!data->driver || pa_utf8_valid(data->driver)); + pa_return_val_if_fail(!data->driver || pa_utf8_valid(data->driver), -PA_ERR_INVALID); if (!data->source) { data->source = pa_namereg_get(core, NULL, PA_NAMEREG_SOURCE); data->save_source = FALSE; } - pa_return_null_if_fail(data->source); - pa_return_null_if_fail(PA_SOURCE_IS_LINKED(pa_source_get_state(data->source))); - pa_return_null_if_fail(!data->direct_on_input || data->direct_on_input->sink == data->source->monitor_of); - - if ((flags & PA_SOURCE_OUTPUT_FAIL_ON_SUSPEND) && - pa_source_get_state(data->source) == PA_SOURCE_SUSPENDED) - return NULL; + pa_return_val_if_fail(data->source, -PA_ERR_NOENTITY); + pa_return_val_if_fail(PA_SOURCE_IS_LINKED(pa_source_get_state(data->source)), -PA_ERR_BADSTATE); + pa_return_val_if_fail(!data->direct_on_input || data->direct_on_input->sink == data->source->monitor_of, -PA_ERR_INVALID); + pa_return_val_if_fail(!(flags & PA_SOURCE_OUTPUT_FAIL_ON_SUSPEND) || pa_source_get_state(data->source) != PA_SOURCE_SUSPENDED, -PA_ERR_BADSTATE); if (!data->sample_spec_is_set) data->sample_spec = data->source->sample_spec; - pa_return_null_if_fail(pa_sample_spec_valid(&data->sample_spec)); + pa_return_val_if_fail(pa_sample_spec_valid(&data->sample_spec), -PA_ERR_INVALID); if (!data->channel_map_is_set) { if (pa_channel_map_compatible(&data->source->channel_map, &data->sample_spec)) @@ -137,8 +137,8 @@ pa_source_output* pa_source_output_new( pa_channel_map_init_extend(&data->channel_map, data->sample_spec.channels, PA_CHANNEL_MAP_DEFAULT); } - pa_return_null_if_fail(pa_channel_map_valid(&data->channel_map)); - pa_return_null_if_fail(pa_channel_map_compatible(&data->channel_map, &data->sample_spec)); + pa_return_val_if_fail(pa_channel_map_valid(&data->channel_map), -PA_ERR_INVALID); + pa_return_val_if_fail(pa_channel_map_compatible(&data->channel_map, &data->sample_spec), -PA_ERR_INVALID); if (flags & PA_SOURCE_OUTPUT_FIX_FORMAT) data->sample_spec.format = data->source->sample_spec.format; @@ -157,17 +157,17 @@ pa_source_output* pa_source_output_new( if (data->resample_method == PA_RESAMPLER_INVALID) data->resample_method = core->resample_method; - pa_return_null_if_fail(data->resample_method < PA_RESAMPLER_MAX); + pa_return_val_if_fail(data->resample_method < PA_RESAMPLER_MAX, -PA_ERR_INVALID); if (data->client) pa_proplist_update(data->proplist, PA_UPDATE_MERGE, data->client->proplist); - if (pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_FIXATE], data) < 0) - return NULL; + if ((r = pa_hook_fire(&core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_FIXATE], data)) < 0) + return r; if (pa_idxset_size(data->source->outputs) >= PA_MAX_OUTPUTS_PER_SOURCE) { pa_log("Failed to create source output: too many outputs per source."); - return NULL; + return -PA_ERR_TOOLARGE; } if ((flags & PA_SOURCE_OUTPUT_VARIABLE_RATE) || @@ -184,7 +184,7 @@ pa_source_output* pa_source_output_new( (core->disable_remixing || (flags & PA_SOURCE_OUTPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0) | (core->disable_lfe_remixing ? PA_RESAMPLER_NO_LFE : 0)))) { pa_log_warn("Unsupported resampling operation."); - return NULL; + return -PA_ERR_NOTSUPPORTED; } } @@ -248,7 +248,8 @@ pa_source_output* pa_source_output_new( /* Don't forget to call pa_source_output_put! */ - return o; + *_o = o; + return 0; } /* Called from main context */ @@ -576,7 +577,7 @@ void pa_source_output_cork(pa_source_output *o, pa_bool_t b) { int pa_source_output_set_rate(pa_source_output *o, uint32_t rate) { pa_source_output_assert_ref(o); pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state)); - pa_return_val_if_fail(o->thread_info.resampler, -1); + pa_return_val_if_fail(o->thread_info.resampler, -PA_ERR_BADSTATE); if (o->sample_spec.rate == rate) return 0; @@ -676,16 +677,17 @@ pa_bool_t pa_source_output_may_move_to(pa_source_output *o, pa_source *dest) { /* Called from main context */ int pa_source_output_start_move(pa_source_output *o) { pa_source *origin; + int r; pa_source_output_assert_ref(o); pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state)); pa_assert(o->source); if (!pa_source_output_may_move(o)) - return -1; + return -PA_ERR_NOTSUPPORTED; - if (pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_START], o) < 0) - return -1; + if ((r = pa_hook_fire(&o->core->hooks[PA_CORE_HOOK_SOURCE_OUTPUT_MOVE_START], o)) < 0) + return r; origin = o->source; @@ -714,13 +716,6 @@ int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, pa_bool_t if (!pa_source_output_may_move_to(o, dest)) return -1; - o->source = dest; - o->save_source = save; - pa_idxset_put(o->source->outputs, o, NULL); - - if (pa_source_output_get_state(o) == PA_SOURCE_OUTPUT_CORKED) - o->source->n_corked++; - if (o->thread_info.resampler && pa_sample_spec_equal(pa_resampler_input_sample_spec(o->thread_info.resampler), &dest->sample_spec) && pa_channel_map_equal(pa_resampler_input_channel_map(o->thread_info.resampler), &dest->channel_map)) @@ -743,11 +738,18 @@ int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, pa_bool_t ((o->flags & PA_SOURCE_OUTPUT_NO_REMAP) ? PA_RESAMPLER_NO_REMAP : 0) | (o->core->disable_remixing || (o->flags & PA_SOURCE_OUTPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0)))) { pa_log_warn("Unsupported resampling operation."); - return -1; + return -PA_ERR_NOTSUPPORTED; } } else new_resampler = NULL; + o->source = dest; + o->save_source = save; + pa_idxset_put(o->source->outputs, o, NULL); + + if (pa_source_output_get_state(o) == PA_SOURCE_OUTPUT_CORKED) + o->source->n_corked++; + /* Replace resampler */ if (new_resampler != o->thread_info.resampler) { if (o->thread_info.resampler) @@ -784,6 +786,7 @@ int pa_source_output_finish_move(pa_source_output *o, pa_source *dest, pa_bool_t /* Called from main context */ int pa_source_output_move_to(pa_source_output *o, pa_source *dest, pa_bool_t save) { + int r; pa_source_output_assert_ref(o); pa_assert(PA_SOURCE_OUTPUT_IS_LINKED(o->state)); @@ -794,13 +797,13 @@ int pa_source_output_move_to(pa_source_output *o, pa_source *dest, pa_bool_t sav return 0; if (!pa_source_output_may_move_to(o, dest)) - return -1; + return -PA_ERR_NOTSUPPORTED; - if (pa_source_output_start_move(o) < 0) - return -1; + if ((r = pa_source_output_start_move(o)) < 0) + return r; - if (pa_source_output_finish_move(o, dest, save) < 0) - return -1; + if ((r = pa_source_output_finish_move(o, dest, save)) < 0) + return r; return 0; } @@ -864,5 +867,5 @@ int pa_source_output_process_msg(pa_msgobject *mo, int code, void *userdata, int } } - return -1; + return -PA_ERR_NOTIMPLEMENTED; } diff --git a/src/pulsecore/source-output.h b/src/pulsecore/source-output.h index f4f94623..91f28f94 100644 --- a/src/pulsecore/source-output.h +++ b/src/pulsecore/source-output.h @@ -205,7 +205,8 @@ void pa_source_output_new_data_done(pa_source_output_new_data *data); /* To be called by the implementing module only */ -pa_source_output* pa_source_output_new( +int pa_source_output_new( + pa_source_output**o, pa_core *core, pa_source_output_new_data *data, pa_source_output_flags_t flags); -- cgit