summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2019-11-21 16:12:53 +0100
committerWim Taymans <wtaymans@redhat.com>2019-11-21 16:12:53 +0100
commitbe53554defe2bc935c0dc216872ed835f2307c05 (patch)
treeec93b12da36482495208bab7917e6f682c9e5e0b
parente40fbf8cc426ff8d6bcb4e28647105ed6a759642 (diff)
filter: add new method to set error state
Add a new set_error function that can also take a message instead of abusing the update_params method.
-rw-r--r--src/examples/video-dsp-play.c11
-rw-r--r--src/pipewire/filter.c34
-rw-r--r--src/pipewire/filter.h6
3 files changed, 31 insertions, 20 deletions
diff --git a/src/examples/video-dsp-play.c b/src/examples/video-dsp-play.c
index f1631108..4d251b8e 100644
--- a/src/examples/video-dsp-play.c
+++ b/src/examples/video-dsp-play.c
@@ -176,14 +176,9 @@ on_filter_param_changed(void *_data, void *port_data, uint32_t id, const struct
Uint32 sdl_format;
void *d;
- if (id != SPA_PARAM_Format)
- return;
-
/* NULL means to clear the format */
- if (param == NULL) {
- pw_filter_update_params(filter, port_data, 0, NULL, 0);
+ if (param == NULL || id != SPA_PARAM_Format)
return;
- }
fprintf(stderr, "got format:\n");
spa_debug_format(2, NULL, param);
@@ -197,7 +192,7 @@ on_filter_param_changed(void *_data, void *port_data, uint32_t id, const struct
sdl_format = SDL_PIXELFORMAT_UNKNOWN;
if (sdl_format == SDL_PIXELFORMAT_UNKNOWN) {
- pw_filter_update_params(filter, port_data, -EINVAL, NULL, 0);
+ pw_filter_set_error(filter, -EINVAL, "unknown format");
return;
}
@@ -225,7 +220,7 @@ on_filter_param_changed(void *_data, void *port_data, uint32_t id, const struct
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16));
/* we are done */
- pw_filter_update_params(filter, port_data, 0, params, 1);
+ pw_filter_update_params(filter, port_data, params, 1);
}
/* these are the filter events we listen for */
diff --git a/src/pipewire/filter.c b/src/pipewire/filter.c
index 2fd936d8..a832551d 100644
--- a/src/pipewire/filter.c
+++ b/src/pipewire/filter.c
@@ -1387,28 +1387,40 @@ int pw_filter_remove_port(void *port_data)
}
SPA_EXPORT
+int pw_filter_set_error(struct pw_filter *filter,
+ int res, const char *error, ...)
+{
+ if (res < 0) {
+ va_list args;
+ char *value;
+
+ va_start(args, error);
+ vasprintf(&value, error, args);
+
+ if (filter->proxy)
+ pw_proxy_error(filter->proxy, res, value);
+
+ filter_set_state(filter, PW_STREAM_STATE_ERROR, value);
+ va_end(args);
+ free(value);
+ }
+ return res;
+}
+
+SPA_EXPORT
int pw_filter_update_params(struct pw_filter *filter,
void *port_data,
- int res,
const struct spa_pod **params,
uint32_t n_params)
{
struct filter *impl = SPA_CONTAINER_OF(filter, struct filter, this);
struct port *port;
- pw_log_debug(NAME" %p: update params %d", filter, res);
+ pw_log_debug(NAME" %p: update params", filter);
port = port_data ? SPA_CONTAINER_OF(port_data, struct port, user_data) : NULL;
- if (res < 0) {
- pw_proxy_error(filter->proxy, res, "params failed");
- filter_set_state(filter, PW_FILTER_STATE_ERROR, "params error");
- return 0;
- }
-
- res = update_params(impl, port, SPA_ID_INVALID, params, n_params);
-
- return res;
+ return update_params(impl, port, SPA_ID_INVALID, params, n_params);
}
SPA_EXPORT
diff --git a/src/pipewire/filter.h b/src/pipewire/filter.h
index bfe6c025..4db4f575 100644
--- a/src/pipewire/filter.h
+++ b/src/pipewire/filter.h
@@ -189,11 +189,15 @@ const struct pw_properties *pw_filter_get_properties(struct pw_filter *filter,
int pw_filter_update_properties(struct pw_filter *filter,
void *port_data, const struct spa_dict *dict);
+/** Set the filter in error state */
+int pw_filter_set_error(struct pw_filter *filter, /**< a \ref pw_filter */
+ int res, /**< a result code */
+ const char *error, ... /**< an error message */) SPA_PRINTF_FUNC(3, 4);
+
/** Update params, use NULL port_data for global filter params */
int
pw_filter_update_params(struct pw_filter *filter, /**< a \ref pw_filter */
void *port_data, /**< data associated with port */
- int res, /**< a result code */
const struct spa_pod **params, /**< an array of params. */
uint32_t n_params /**< number of elements in \a params */);