1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avformat/udp: add function to set remote address directly

This commit is contained in:
Timo Rothenpieler
2025-06-28 20:58:20 +02:00
parent 585cae13fa
commit 2604c86c1f
2 changed files with 31 additions and 0 deletions

View File

@ -339,5 +339,6 @@ int ff_connect_parallel(struct addrinfo *addrs, int timeout_ms_per_address,
int (*customize_fd)(void *, int, int), void *customize_ctx); int (*customize_fd)(void *, int, int), void *customize_ctx);
void ff_udp_get_last_recv_addr(URLContext *h, struct sockaddr_storage *addr, socklen_t *addr_len); void ff_udp_get_last_recv_addr(URLContext *h, struct sockaddr_storage *addr, socklen_t *addr_len);
int ff_udp_set_remote_addr(URLContext *h, const struct sockaddr *dest_addr, socklen_t dest_addr_len, int do_connect);
#endif /* AVFORMAT_NETWORK_H */ #endif /* AVFORMAT_NETWORK_H */

View File

@ -465,6 +465,36 @@ int ff_udp_set_remote_url(URLContext *h, const char *uri)
return 0; return 0;
} }
/**
* This function is identical to ff_udp_set_remote_url, except that it takes a sockaddr directly.
*/
int ff_udp_set_remote_addr(URLContext *h, const struct sockaddr *dest_addr, socklen_t dest_addr_len, int do_connect)
{
UDPContext *s = h->priv_data;
/* set the destination address */
if (dest_addr_len < 0 || dest_addr_len > sizeof(s->dest_addr))
return AVERROR(EIO);
s->dest_addr_len = dest_addr_len;
memcpy(&s->dest_addr, dest_addr, dest_addr_len);
s->is_multicast = ff_is_multicast_address((struct sockaddr*) &s->dest_addr);
if (do_connect >= 0) {
int was_connected = s->is_connected;
s->is_connected = do_connect;
if (s->is_connected && !was_connected) {
if (connect(s->udp_fd, (struct sockaddr *) &s->dest_addr,
s->dest_addr_len)) {
s->is_connected = 0;
ff_log_net_error(h, AV_LOG_ERROR, "connect");
return AVERROR(EIO);
}
}
}
return 0;
}
/** /**
* Return the local port used by the UDP connection * Return the local port used by the UDP connection
* @param h media file context * @param h media file context