Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Jack Lau <jacklau1222gm-at-gmail.com@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Jack Lau <jacklau1222@qq.com>
Subject: [FFmpeg-devel] [PATCH v2 4/4] avformat/udp: fix udp server mode haven't dest_addr
Date: Fri, 11 Jul 2025 21:20:49 +0800
Message-ID: <20250711132120.38507-5-jacklau1222@qq.com> (raw)
In-Reply-To: <20250711132120.38507-1-jacklau1222@qq.com>

If udp is in server mode(init local addr and port through url),
then it maybe haven't dest_addr, so we should set it after udp_read
get the client addr and port

This feature only enable when the new udp option autodetect_dest is specified

Signed-off-by: Jack Lau <jacklau1222@qq.com>
---
 libavformat/udp.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libavformat/udp.c b/libavformat/udp.c
index 0fde3548e7..7d05e18dcd 100644
--- a/libavformat/udp.c
+++ b/libavformat/udp.c
@@ -99,6 +99,7 @@ typedef struct UDPContext {
     struct sockaddr_storage dest_addr;
     int dest_addr_len;
     int is_connected;
+    int autodetect_dest;
 
     /* Circular Buffer variables for use in UDP receive code */
     int circular_buffer_size;
@@ -143,6 +144,7 @@ static const AVOption options[] = {
     { "broadcast", "explicitly allow or disallow broadcast destination",   OFFSET(is_broadcast),   AV_OPT_TYPE_BOOL,   { .i64 = 0  },     0, 1,       E },
     { "ttl",            "Time to live (multicast only)",                   OFFSET(ttl),            AV_OPT_TYPE_INT,    { .i64 = 16 },     0, 255,     E },
     { "connect",        "set if connect() should be called on socket",     OFFSET(is_connected),   AV_OPT_TYPE_BOOL,   { .i64 =  0 },     0, 1,       .flags = D|E },
+    { "autodetect_dest", "Auto detect destination from last received addr", OFFSET(autodetect_dest), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,    D|E },
     { "fifo_size",      "set the UDP receiving circular buffer size, expressed as a number of packets with size of 188 bytes", OFFSET(circular_buffer_size), AV_OPT_TYPE_INT, {.i64 = 7*4096}, 0, INT_MAX, D },
     { "overrun_nonfatal", "survive in case of UDP receiving circular buffer overrun", OFFSET(overrun_nonfatal), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1,    D },
     { "timeout",        "set raise error timeout, in microseconds (only in read mode)",OFFSET(timeout),         AV_OPT_TYPE_INT,  {.i64 = 0}, 0, INT_MAX, D },
@@ -1144,6 +1146,8 @@ static int udp_write(URLContext *h, const uint8_t *buf, int size)
     }
 
     if (!s->is_connected) {
+        if (s->autodetect_dest && !s->dest_addr_len && !s->dest_addr.ss_family)
+            ff_udp_get_last_recv_addr(h, &s->dest_addr, &s->dest_addr_len);
         ret = sendto (s->udp_fd, buf, size, 0,
                       (struct sockaddr *) &s->dest_addr,
                       s->dest_addr_len);
-- 
2.49.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

      parent reply	other threads:[~2025-07-11 13:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-11 13:20 [FFmpeg-devel] [PATCH v2 0/4] Fix some issues in tls_openssl and udp Jack Lau
2025-07-11 13:20 ` [FFmpeg-devel] [PATCH v2 1/4] avformat/tls_openssl: add record trace function Jack Lau
2025-07-11 15:03   ` Steven Liu
2025-07-11 13:20 ` [FFmpeg-devel] [PATCH v2 2/4] avformat/tls_openssl: fix dtls_handshake return code Jack Lau
2025-07-11 15:05   ` Steven Liu
2025-07-11 13:20 ` [FFmpeg-devel] [PATCH v2 3/4] avformat/tls_openssl: remove all redundant "TLS: " in log with AVClass Jack Lau
2025-07-11 15:05   ` Steven Liu
2025-07-11 13:20 ` Jack Lau [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250711132120.38507-5-jacklau1222@qq.com \
    --to=jacklau1222gm-at-gmail.com@ffmpeg.org \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=jacklau1222@qq.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git