mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
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.
This commit is contained in:
parent
e40fbf8cc4
commit
be53554def
3 changed files with 31 additions and 20 deletions
|
|
@ -176,14 +176,9 @@ on_filter_param_changed(void *_data, void *port_data, uint32_t id, const struct
|
||||||
Uint32 sdl_format;
|
Uint32 sdl_format;
|
||||||
void *d;
|
void *d;
|
||||||
|
|
||||||
if (id != SPA_PARAM_Format)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* NULL means to clear the format */
|
/* NULL means to clear the format */
|
||||||
if (param == NULL) {
|
if (param == NULL || id != SPA_PARAM_Format)
|
||||||
pw_filter_update_params(filter, port_data, 0, NULL, 0);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "got format:\n");
|
fprintf(stderr, "got format:\n");
|
||||||
spa_debug_format(2, NULL, param);
|
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;
|
sdl_format = SDL_PIXELFORMAT_UNKNOWN;
|
||||||
|
|
||||||
if (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;
|
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));
|
SPA_PARAM_BUFFERS_align, SPA_POD_Int(16));
|
||||||
|
|
||||||
/* we are done */
|
/* 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 */
|
/* these are the filter events we listen for */
|
||||||
|
|
|
||||||
|
|
@ -1386,29 +1386,41 @@ int pw_filter_remove_port(void *port_data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
SPA_EXPORT
|
||||||
int pw_filter_update_params(struct pw_filter *filter,
|
int pw_filter_update_params(struct pw_filter *filter,
|
||||||
void *port_data,
|
void *port_data,
|
||||||
int res,
|
|
||||||
const struct spa_pod **params,
|
const struct spa_pod **params,
|
||||||
uint32_t n_params)
|
uint32_t n_params)
|
||||||
{
|
{
|
||||||
struct filter *impl = SPA_CONTAINER_OF(filter, struct filter, this);
|
struct filter *impl = SPA_CONTAINER_OF(filter, struct filter, this);
|
||||||
struct port *port;
|
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;
|
port = port_data ? SPA_CONTAINER_OF(port_data, struct port, user_data) : NULL;
|
||||||
|
|
||||||
if (res < 0) {
|
return update_params(impl, port, SPA_ID_INVALID, params, n_params);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
|
|
|
||||||
|
|
@ -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,
|
int pw_filter_update_properties(struct pw_filter *filter,
|
||||||
void *port_data, const struct spa_dict *dict);
|
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 */
|
/** Update params, use NULL port_data for global filter params */
|
||||||
int
|
int
|
||||||
pw_filter_update_params(struct pw_filter *filter, /**< a \ref pw_filter */
|
pw_filter_update_params(struct pw_filter *filter, /**< a \ref pw_filter */
|
||||||
void *port_data, /**< data associated with port */
|
void *port_data, /**< data associated with port */
|
||||||
int res, /**< a result code */
|
|
||||||
const struct spa_pod **params, /**< an array of params. */
|
const struct spa_pod **params, /**< an array of params. */
|
||||||
uint32_t n_params /**< number of elements in \a params */);
|
uint32_t n_params /**< number of elements in \a params */);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue