static int rtsp_listen(AVFormatContext *s)

{

    RTSPState *rt = s->priv_data;

    char proto[128], host[128], path[512], auth[128];

    char uri[500];

    int port;

    int default_port = RTSP_DEFAULT_PORT;

    char tcpname[500];

    const char *lower_proto = "tcp";

    unsigned char rbuf[4096];

    unsigned char method[10];

    int rbuflen = 0;

    int ret;

    enum RTSPMethod methodcode;



    if (!rt->protocols) {

        rt->protocols = ffurl_get_protocols(NULL, NULL);

        if (!rt->protocols)

            return AVERROR(ENOMEM);

    }



    /* extract hostname and port */

    av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host),

                 &port, path, sizeof(path), s->filename);



    /* ff_url_join. No authorization by now (NULL) */

    ff_url_join(rt->control_uri, sizeof(rt->control_uri), proto, NULL, host,

                port, "%s", path);



    if (!strcmp(proto, "rtsps")) {

        lower_proto  = "tls";

        default_port = RTSPS_DEFAULT_PORT;

    }



    if (port < 0)

        port = default_port;



    /* Create TCP connection */

    ff_url_join(tcpname, sizeof(tcpname), lower_proto, NULL, host, port,

                "?listen&listen_timeout=%d", rt->initial_timeout * 1000);



    if (ret = ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE,

                         &s->interrupt_callback, NULL, rt->protocols)) {

        av_log(s, AV_LOG_ERROR, "Unable to open RTSP for listening\n");

        return ret;

    }

    rt->state       = RTSP_STATE_IDLE;

    rt->rtsp_hd_out = rt->rtsp_hd;

    for (;;) { /* Wait for incoming RTSP messages */

        ret = read_line(s, rbuf, sizeof(rbuf), &rbuflen);

        if (ret < 0)

            return ret;

        ret = parse_command_line(s, rbuf, rbuflen, uri, sizeof(uri), method,

                                 sizeof(method), &methodcode);

        if (ret) {

            av_log(s, AV_LOG_ERROR, "RTSP: Unexpected Command\n");

            return ret;

        }



        if (methodcode == ANNOUNCE) {

            ret       = rtsp_read_announce(s);

            rt->state = RTSP_STATE_PAUSED;

        } else if (methodcode == OPTIONS) {

            ret = rtsp_read_options(s);

        } else if (methodcode == RECORD) {

            ret = rtsp_read_record(s);

            if (!ret)

                return 0; // We are ready for streaming

        } else if (methodcode == SETUP)

            ret = rtsp_read_setup(s, host, uri);

        if (ret) {

            ffurl_close(rt->rtsp_hd);

            return AVERROR_INVALIDDATA;

        }

    }

    return 0;

}

static int rtsp_listen(AVFormatContext *s)

{

    RTSPState *rt = s->priv_data;

    char proto[128], host[128], path[512], auth[128];

    char uri[500];

    int port;

    int default_port = RTSP_DEFAULT_PORT;

    char tcpname[500];

    const char *lower_proto = "tcp";

    unsigned char rbuf[4096];

    unsigned char method[10];

    int rbuflen = 0;

    int ret;

    enum RTSPMethod methodcode;



    if (!rt->protocols) {

        rt->protocols = ffurl_get_protocols(NULL, NULL);

        if (!rt->protocols)

            return AVERROR(ENOMEM);

    }



    

    av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host),

                 &port, path, sizeof(path), s->filename);



    

    ff_url_join(rt->control_uri, sizeof(rt->control_uri), proto, NULL, host,

                port, "%s", path);



    if (!strcmp(proto, "rtsps")) {

        lower_proto  = "tls";

        default_port = RTSPS_DEFAULT_PORT;

    }



    if (port < 0)

        port = default_port;



    

    ff_url_join(tcpname, sizeof(tcpname), lower_proto, NULL, host, port,

                "?listen&listen_timeout=%d", rt->initial_timeout * 1000);



    if (ret = ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE,

                         &s->interrupt_callback, NULL, rt->protocols)) {

        av_log(s, AV_LOG_ERROR, "Unable to open RTSP for listening\n");

        return ret;

    }

    rt->state       = RTSP_STATE_IDLE;

    rt->rtsp_hd_out = rt->rtsp_hd;

    for (;;) { 

        ret = read_line(s, rbuf, sizeof(rbuf), &rbuflen);

        if (ret < 0)

            return ret;

        ret = parse_command_line(s, rbuf, rbuflen, uri, sizeof(uri), method,

                                 sizeof(method), &methodcode);

        if (ret) {

            av_log(s, AV_LOG_ERROR, "RTSP: Unexpected Command\n");

            return ret;

        }



        if (methodcode == ANNOUNCE) {

            ret       = rtsp_read_announce(s);

            rt->state = RTSP_STATE_PAUSED;

        } else if (methodcode == OPTIONS) {

            ret = rtsp_read_options(s);

        } else if (methodcode == RECORD) {

            ret = rtsp_read_record(s);

            if (!ret)

                return 0; 

        } else if (methodcode == SETUP)

            ret = rtsp_read_setup(s, host, uri);

        if (ret) {

            ffurl_close(rt->rtsp_hd);

            return AVERROR_INVALIDDATA;

        }

    }

    return 0;

}

        rt->protocols = ffurl_get_protocols(NULL, NULL);         rt->protocols = ffurl_get_protocols(NULL, NULL);         rt->protocols = ffurl_get_protocols(NULL, NULL);         rt->protocols = ffurl_get_protocols(NULL, NULL);
static int FUNC_0(AVFormatContext *VAR_0)

{

    RTSPState *rt = VAR_0->priv_data;

    char VAR_1[128], VAR_2[128], VAR_3[512], VAR_4[128];

    char VAR_5[500];

    int VAR_6;

    int VAR_7 = RTSP_DEFAULT_PORT;

    char VAR_8[500];

    const char *VAR_9 = "tcp";

    unsigned char VAR_10[4096];

    unsigned char VAR_11[10];

    int VAR_12 = 0;

    int VAR_13;

    enum RTSPMethod VAR_14;



    if (!rt->protocols) {

        rt->protocols = ffurl_get_protocols(NULL, NULL);

        if (!rt->protocols)

            return AVERROR(ENOMEM);

    }



    

    av_url_split(VAR_1, sizeof(VAR_1), VAR_4, sizeof(VAR_4), VAR_2, sizeof(VAR_2),

                 &VAR_6, VAR_3, sizeof(VAR_3), VAR_0->filename);



    

    ff_url_join(rt->control_uri, sizeof(rt->control_uri), VAR_1, NULL, VAR_2,

                VAR_6, "%VAR_0", VAR_3);



    if (!strcmp(VAR_1, "rtsps")) {

        VAR_9  = "tls";

        VAR_7 = RTSPS_DEFAULT_PORT;

    }



    if (VAR_6 < 0)

        VAR_6 = VAR_7;



    

    ff_url_join(VAR_8, sizeof(VAR_8), VAR_9, NULL, VAR_2, VAR_6,

                "?listen&listen_timeout=%d", rt->initial_timeout * 1000);



    if (VAR_13 = ffurl_open(&rt->rtsp_hd, VAR_8, AVIO_FLAG_READ_WRITE,

                         &VAR_0->interrupt_callback, NULL, rt->protocols)) {

        av_log(VAR_0, AV_LOG_ERROR, "Unable to open RTSP for listening\n");

        return VAR_13;

    }

    rt->state       = RTSP_STATE_IDLE;

    rt->rtsp_hd_out = rt->rtsp_hd;

    for (;;) { 

        VAR_13 = read_line(VAR_0, VAR_10, sizeof(VAR_10), &VAR_12);

        if (VAR_13 < 0)

            return VAR_13;

        VAR_13 = parse_command_line(VAR_0, VAR_10, VAR_12, VAR_5, sizeof(VAR_5), VAR_11,

                                 sizeof(VAR_11), &VAR_14);

        if (VAR_13) {

            av_log(VAR_0, AV_LOG_ERROR, "RTSP: Unexpected Command\n");

            return VAR_13;

        }



        if (VAR_14 == ANNOUNCE) {

            VAR_13       = rtsp_read_announce(VAR_0);

            rt->state = RTSP_STATE_PAUSED;

        } else if (VAR_14 == OPTIONS) {

            VAR_13 = rtsp_read_options(VAR_0);

        } else if (VAR_14 == RECORD) {

            VAR_13 = rtsp_read_record(VAR_0);

            if (!VAR_13)

                return 0; 

        } else if (VAR_14 == SETUP)

            VAR_13 = rtsp_read_setup(VAR_0, VAR_2, VAR_5);

        if (VAR_13) {

            ffurl_close(rt->rtsp_hd);

            return AVERROR_INVALIDDATA;

        }

    }

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0)
{ RTSPState *rt = VAR_0->priv_data; char VAR_1[128], VAR_2[128], VAR_3[512], VAR_4[128]; char VAR_5[500]; int VAR_6; int VAR_7 = RTSP_DEFAULT_PORT; char VAR_8[500]; const char *VAR_9 = "tcp"; unsigned char VAR_10[4096]; unsigned char VAR_11[10]; int VAR_12 = 0; int VAR_13; enum RTSPMethod VAR_14; if (!rt->protocols) { rt->protocols = ffurl_get_protocols(NULL, NULL); if (!rt->protocols)
return AVERROR(ENOMEM); } av_url_split(VAR_1, sizeof(VAR_1), VAR_4, sizeof(VAR_4), VAR_2, sizeof(VAR_2),
&VAR_6, VAR_3, sizeof(VAR_3), VAR_0->filename); ff_url_join(rt->control_uri, sizeof(rt->control_uri), VAR_1, NULL, VAR_2,
VAR_6, "%VAR_0", VAR_3); if (!strcmp(VAR_1, "rtsps")) { VAR_9  = "tls"; VAR_7 = RTSPS_DEFAULT_PORT; } if (VAR_6 < 0)
VAR_6 = VAR_7; ff_url_join(VAR_8, sizeof(VAR_8), VAR_9, NULL, VAR_2, VAR_6,
"?listen&listen_timeout=%d", rt->initial_timeout * 1000); if (VAR_13 = ffurl_open(&rt->rtsp_hd, VAR_8, AVIO_FLAG_READ_WRITE,
&VAR_0->interrupt_callback, NULL, rt->protocols)) { av_log(VAR_0, AV_LOG_ERROR, "Unable to open RTSP for listening\n"); return VAR_13; } rt->state       = RTSP_STATE_IDLE; rt->rtsp_hd_out = rt->rtsp_hd; for (;;) { VAR_13 = read_line(VAR_0, VAR_10, sizeof(VAR_10), &VAR_12); if (VAR_13 < 0)
return VAR_13; VAR_13 = parse_command_line(VAR_0, VAR_10, VAR_12, VAR_5, sizeof(VAR_5), VAR_11,
sizeof(VAR_11), &VAR_14); if (VAR_13) { av_log(VAR_0, AV_LOG_ERROR, "RTSP: Unexpected Command\n"); return VAR_13; } if (VAR_14 == ANNOUNCE) { VAR_13       = rtsp_read_announce(VAR_0); rt->state = RTSP_STATE_PAUSED; } else if (VAR_14 == OPTIONS) { VAR_13 = rtsp_read_options(VAR_0); } else if (VAR_14 == RECORD) { VAR_13 = rtsp_read_record(VAR_0); if (!VAR_13)
return 0; } else if (VAR_14 == SETUP) VAR_13 = rtsp_read_setup(VAR_0, VAR_2, VAR_5); if (VAR_13) { ffurl_close(rt->rtsp_hd); return AVERROR_INVALIDDATA; } } return 0; }