module-rtp: handle state change errors better

Make a new function to set the rtp stream in the error state.

When we fail to start the stream, set the error state. Otherwise (like
when we try to use an invalid interface name) the socket create will
fail but the stream will still try to send data to the invalid socket.
This commit is contained in:
Wim Taymans 2024-03-25 12:22:11 +01:00
parent 6e7b893448
commit 4ffd74ef46
4 changed files with 14 additions and 3 deletions

View File

@ -307,6 +307,7 @@ static void stream_state_changed(void *data, bool started, const char *error)
impl->mcast_loop, impl->ttl, impl->dscp,
impl->ifname)) < 0) {
pw_log_error("can't make socket: %s", spa_strerror(res));
rtp_stream_set_error(impl->stream, res, "Can't make socket");
return;
}
impl->rtp_fd = res;

View File

@ -305,7 +305,7 @@ static int stream_start(struct impl *impl)
if ((fd = make_socket((const struct sockaddr *)&impl->src_addr,
impl->src_len, impl->ifname)) < 0) {
pw_log_error("failed to create socket: %m");
return fd;
return -errno;
}
impl->source = pw_loop_add_io(impl->data_loop, fd,
@ -338,13 +338,16 @@ static void stream_destroy(void *d)
static void stream_state_changed(void *data, bool started, const char *error)
{
struct impl *impl = data;
int res;
if (error) {
pw_log_error("stream error: %s", error);
pw_impl_module_schedule_destroy(impl->module);
} else if (started) {
if ((errno = -stream_start(impl)) < 0)
pw_log_error("failed to start RTP stream: %m");
if ((res = stream_start(impl)) < 0) {
pw_log_error("failed to start RTP stream: %s", spa_strerror(res));
rtp_stream_set_error(impl->stream, res, "Can't start RTP stream");
}
} else {
if (!impl->always_process)
stream_stop(impl);

View File

@ -642,6 +642,12 @@ void rtp_stream_set_first(struct rtp_stream *s)
impl->first = true;
}
void rtp_stream_set_error(struct rtp_stream *s, int res, const char *error)
{
struct impl *impl = (struct impl*)s;
pw_stream_set_error(impl->stream, res, "%s: %s", error, spa_strerror(res));
}
enum pw_stream_state rtp_stream_get_state(struct rtp_stream *s, const char **error)
{
struct impl *impl = (struct impl*)s;

View File

@ -54,6 +54,7 @@ uint16_t rtp_stream_get_seq(struct rtp_stream *s);
void rtp_stream_set_first(struct rtp_stream *s);
void rtp_stream_set_error(struct rtp_stream *s, int res, const char *error);
enum pw_stream_state rtp_stream_get_state(struct rtp_stream *s, const char **error);
int rtp_stream_set_param(struct rtp_stream *s, uint32_t id, const struct spa_pod *param);