diff options
author | Lennart Poettering <lennart@poettering.net> | 2009-02-03 03:14:20 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2009-02-03 03:14:20 +0100 |
commit | 08800c35b072820ba485a5a0a211ce91a1656390 (patch) | |
tree | b668580cc48f72e9e8568fbf58b70f4eaf71c11d /src/pulsecore | |
parent | 162e43b306eb28749f2ae1f9c51818e9ad427996 (diff) |
make a couple of functions return proper error codes
Diffstat (limited to 'src/pulsecore')
-rw-r--r-- | src/pulsecore/play-memblockq.c | 2 | ||||
-rw-r--r-- | src/pulsecore/protocol-esound.c | 4 | ||||
-rw-r--r-- | src/pulsecore/protocol-native.c | 26 | ||||
-rw-r--r-- | src/pulsecore/protocol-simple.c | 4 | ||||
-rw-r--r-- | src/pulsecore/sink-input.c | 90 | ||||
-rw-r--r-- | src/pulsecore/sink-input.h | 5 | ||||
-rw-r--r-- | src/pulsecore/sound-file-stream.c | 2 | ||||
-rw-r--r-- | src/pulsecore/source-output.c | 79 | ||||
-rw-r--r-- | src/pulsecore/source-output.h | 3 |
9 files changed, 116 insertions, 99 deletions
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); |