nuttx/libs/libc
wangchen 146767a8a2 netdb:netdb code support ffmpeg rtsp(getaddrinfo & getnameinfo)
Related Codes:
1.ffmpeg/libavformat/ip.c
struct addrinfo *ff_ip_resolve_host(void *log_ctx,
                                    const char *hostname, int port,
                                    int type, int family, int flags)
{
    struct addrinfo hints = { 0 }, *res = 0;
    int error;
    char sport[16];
    const char *node = 0, *service = "0";

    if (port > 0) {
        snprintf(sport, sizeof(sport), "%d", port);
        service = sport;
    }
    if ((hostname) && (hostname[0] != '\0') && (hostname[0] != '?')) {
        node = hostname;
    }
    hints.ai_socktype = type;
    hints.ai_family   = family;
    hints.ai_flags    = flags;
    if ((error = getaddrinfo(node, service, &hints, &res))) {
        res = NULL;
        av_log(log_ctx, AV_LOG_ERROR, "getaddrinfo(%s, %s): %s\n",
               node ? node : "unknown",
               service,
               gai_strerror(error));
    }

    return res;
}
2.ffmpeg/libavformat/rtsp.c
static int sdp_read_header(AVFormatContext *s)
{
    RTSPState *rt = s->priv_data;
    RTSPStream *rtsp_st;
    int i, err;
    char url[MAX_URL_SIZE];
    AVBPrint bp;

    if (!ff_network_init())
        return AVERROR(EIO);

    if (s->max_delay < 0) /* Not set by the caller */
        s->max_delay = DEFAULT_REORDERING_DELAY;
    if (rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)
        rt->lower_transport = RTSP_LOWER_TRANSPORT_CUSTOM;

    /* read the whole sdp file */
    av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
    err = avio_read_to_bprint(s->pb, &bp, INT_MAX);
    if (err < 0 ) {
        ff_network_close();
        av_bprint_finalize(&bp, NULL);
        return err;
    }
    err = ff_sdp_parse(s, bp.str);
    av_bprint_finalize(&bp, NULL);
    if (err) goto fail;

    /* open each RTP stream */
    for (i = 0; i < rt->nb_rtsp_streams; i++) {
        char namebuf[50];
        rtsp_st = rt->rtsp_streams[i];

        if (!(rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)) {
            AVDictionary *opts = map_to_opts(rt);
            char buf[MAX_URL_SIZE];
            const char *p;

            err = getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip,
                              sizeof(rtsp_st->sdp_ip),
                              namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
            if (err) {
                av_log(s, AV_LOG_ERROR, "getnameinfo: %s\n", gai_strerror(err));
                err = AVERROR(EIO);
                av_dict_free(&opts);
                goto fail;
            }
            ff_url_join(url, sizeof(url), "rtp", NULL,
                        namebuf, rtsp_st->sdp_port,
                        "?localport=%d&ttl=%d&connect=%d&write_to_source=%d",
                        rtsp_st->sdp_port, rtsp_st->sdp_ttl,
                        rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0,
                        rt->rtsp_flags & RTSP_FLAG_RTCP_TO_SOURCE ? 1 : 0);

            p = strchr(s->url, '?');
            if (p && av_find_info_tag(buf, sizeof(buf), "localaddr", p))
                av_strlcatf(url, sizeof(url), "&localaddr=%s", buf);
            else if (rt->localaddr && rt->localaddr[0])
                av_strlcatf(url, sizeof(url), "&localaddr=%s", rt->localaddr);
            append_source_addrs(url, sizeof(url), "sources",
                                rtsp_st->nb_include_source_addrs,
                                rtsp_st->include_source_addrs);
            append_source_addrs(url, sizeof(url), "block",
                                rtsp_st->nb_exclude_source_addrs,
                                rtsp_st->exclude_source_addrs);
            err = ffurl_open_whitelist(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ,
                           &s->interrupt_callback, &opts, s->protocol_whitelist, s->protocol_blacklist, NULL);

            av_dict_free(&opts);

            if (err < 0) {
                err = AVERROR_INVALIDDATA;
                goto fail;
            }
        }
        if ((err = ff_rtsp_open_transport_ctx(s, rtsp_st)))
            goto fail;
    }
    return 0;
fail:
    ff_rtsp_close_streams(s);
    ff_network_close();
    return err;
}

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-08-20 10:33:18 -03:00
..
aio
assert cmake:bugfix fix CMake LTO build block 2024-08-15 18:01:50 +08:00
audio audio/libsrc: fix build warning 2024-03-26 09:40:42 +08:00
bin
builtin libs/libc: adapt the cmake script from the makefile 2023-11-07 17:39:03 +01:00
ctype Add basic support for locales in order to C++ streams to build and work for simple cases (POSIX / C locale). 2024-04-29 17:34:10 +08:00
dirent
dlfcn dlfcn: Fix indent issue in lib_dlopen.c 2024-07-27 03:11:39 +08:00
errno
eventfd
fdt CMake:init arm64 CMake qemu-armv8a build 2023-12-27 07:27:17 -08:00
fixedmath
gdbstub gdbstub: Minor style fix 2024-06-26 10:19:14 -03:00
gpsutils libs/libc: adapt the cmake script from the makefile 2023-11-07 17:39:03 +01:00
grp
hex2bin
inttypes libs/libc/inttypes: add support for imaxdiv 2024-04-23 10:26:48 -03:00
kbin
libgen
locale Add basic support for locales in order to C++ streams to build and work for simple cases (POSIX / C locale). 2024-04-29 17:34:10 +08:00
lzf
machine cmake:bugfix enable ARCH_STRING_FUNCTION CMake build fail 2024-08-14 20:58:59 +08:00
misc idr:New idr_find interface 2024-08-19 11:05:40 -03:00
modlib greenhills: fix the moblib asm compile error 2024-08-11 14:28:12 -03:00
net libc/net: Fix indent issue in lib_base64.c 2024-07-27 03:11:39 +08:00
netdb netdb:netdb code support ffmpeg rtsp(getaddrinfo & getnameinfo) 2024-08-20 10:33:18 -03:00
obstack compiler/tasking: fix compiler warning on tasking 2024-01-31 05:02:56 -08:00
pthread libs: fix the default value of process-shared attribute 2024-08-18 19:44:56 +08:00
pwd build: Fix libc/pwd CMakeLists.txt 2024-08-07 08:45:19 +08:00
queue
regex Replace all asserts in kernel code with ASSERT 2024-05-17 10:18:16 -03:00
sched task/pthread_cancelpt: Move cancel point handling to libc, data to TLS 2023-11-15 08:52:04 -08:00
search hsearch_r: add DELETE action 2024-02-21 13:29:36 -03:00
semaphore sem_open: return error code, sem returned by parameter 2024-06-06 02:40:50 +08:00
signal
spawn cmake: fix compilation 2024-06-02 09:27:36 -03:00
stdio lib_remove.c:fix code style error 2024-08-20 13:50:15 +08:00
stdlib mkstemp: permission 0666 to 0600 2024-07-02 02:56:05 +08:00
stream libc/stream: add file out stream 2023-12-25 16:54:16 -03:00
string libc:add missing source to fix windows build error 2024-08-14 22:36:57 +08:00
symtab libs: fix the problem that the address obtained in thumb mode cannot be executed. 2024-01-04 09:22:57 -08:00
syslog
termios
time
tls sched/tls: inline group info in flat mode to improve performance 2024-03-01 17:27:26 +08:00
uio
unistd getrlimit:implement RLIMIT_STACK return limit stack size 2024-08-19 19:55:59 +08:00
userfs
uuid
wchar
wctype compiler/tasking: fix unreachable code on tasking toolchain 2024-01-30 20:53:00 -08:00
wqueue semaphore/_SEM_XX: Remove the _SEM redirection macros as unnecessary 2023-11-27 04:52:54 -08:00
zoneinfo
.gitignore
CMakeLists.txt
Kconfig
libc.csv pthread: add pthread_self/pthread_gettid_np function 2024-06-26 17:40:55 +08:00
libc.h
Makefile api: add simple hashtable api 2024-02-21 13:29:36 -03:00