static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,

                           uint8_t *buf, int buf_size)

{

    RTSPState *rt = s->priv_data;

    RTSPStream *rtsp_st;

    fd_set rfds;

    int fd, fd_max, n, i, ret, tcp_fd, timeout_cnt = 0;

    struct timeval tv;



    for (;;) {

        if (url_interrupt_cb())

            return AVERROR(EINTR);

        FD_ZERO(&rfds);

        if (rt->rtsp_hd) {

            tcp_fd = fd_max = url_get_file_handle(rt->rtsp_hd);

            FD_SET(tcp_fd, &rfds);

        } else {

            fd_max = 0;

            tcp_fd = -1;

        }

        for (i = 0; i < rt->nb_rtsp_streams; i++) {

            rtsp_st = rt->rtsp_streams[i];

            if (rtsp_st->rtp_handle) {

                /* currently, we cannot probe RTCP handle because of

                 * blocking restrictions */

                fd = url_get_file_handle(rtsp_st->rtp_handle);

                if (fd > fd_max)

                    fd_max = fd;

                FD_SET(fd, &rfds);

            }

        }

        tv.tv_sec = 0;

        tv.tv_usec = SELECT_TIMEOUT_MS * 1000;

        n = select(fd_max + 1, &rfds, NULL, NULL, &tv);

        if (n > 0) {

            timeout_cnt = 0;

            for (i = 0; i < rt->nb_rtsp_streams; i++) {

                rtsp_st = rt->rtsp_streams[i];

                if (rtsp_st->rtp_handle) {

                    fd = url_get_file_handle(rtsp_st->rtp_handle);

                    if (FD_ISSET(fd, &rfds)) {

                        ret = url_read(rtsp_st->rtp_handle, buf, buf_size);

                        if (ret > 0) {

                            *prtsp_st = rtsp_st;

                            return ret;

                        }

                    }

                }

            }

#if CONFIG_RTSP_DEMUXER

            if (tcp_fd != -1 && FD_ISSET(tcp_fd, &rfds)) {

                RTSPMessageHeader reply;



                ret = ff_rtsp_read_reply(s, &reply, NULL, 0);

                if (ret < 0)

                    return ret;

                /* XXX: parse message */

                if (rt->state != RTSP_STATE_STREAMING)

                    return 0;

            }

#endif

        } else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) {

            return FF_NETERROR(ETIMEDOUT);

        } else if (n < 0 && errno != EINTR)

            return AVERROR(errno);

    }

}

static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,

                           uint8_t *buf, int buf_size)

{

    RTSPState *rt = s->priv_data;

    RTSPStream *rtsp_st;

    fd_set rfds;

    int fd, fd_max, n, i, ret, tcp_fd, timeout_cnt = 0;

    struct timeval tv;



    for (;;) {

        if (url_interrupt_cb())

            return AVERROR(EINTR);

        FD_ZERO(&rfds);

        if (rt->rtsp_hd) {

            tcp_fd = fd_max = url_get_file_handle(rt->rtsp_hd);

            FD_SET(tcp_fd, &rfds);

        } else {

            fd_max = 0;

            tcp_fd = -1;

        }

        for (i = 0; i < rt->nb_rtsp_streams; i++) {

            rtsp_st = rt->rtsp_streams[i];

            if (rtsp_st->rtp_handle) {

                



                fd = url_get_file_handle(rtsp_st->rtp_handle);

                if (fd > fd_max)

                    fd_max = fd;

                FD_SET(fd, &rfds);

            }

        }

        tv.tv_sec = 0;

        tv.tv_usec = SELECT_TIMEOUT_MS * 1000;

        n = select(fd_max + 1, &rfds, NULL, NULL, &tv);

        if (n > 0) {

            timeout_cnt = 0;

            for (i = 0; i < rt->nb_rtsp_streams; i++) {

                rtsp_st = rt->rtsp_streams[i];

                if (rtsp_st->rtp_handle) {

                    fd = url_get_file_handle(rtsp_st->rtp_handle);

                    if (FD_ISSET(fd, &rfds)) {

                        ret = url_read(rtsp_st->rtp_handle, buf, buf_size);

                        if (ret > 0) {

                            *prtsp_st = rtsp_st;

                            return ret;

                        }

                    }

                }

            }

#if CONFIG_RTSP_DEMUXER

            if (tcp_fd != -1 && FD_ISSET(tcp_fd, &rfds)) {

                RTSPMessageHeader reply;



                ret = ff_rtsp_read_reply(s, &reply, NULL, 0);

                if (ret < 0)

                    return ret;

                

                if (rt->state != RTSP_STATE_STREAMING)

                    return 0;

            }

#endif

        } else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) {

            return FF_NETERROR(ETIMEDOUT);

        } else if (n < 0 && errno != EINTR)

            return AVERROR(errno);

    }

}

static int FUNC_0(AVFormatContext *VAR_0, RTSPStream **VAR_1,

                           uint8_t *VAR_2, int VAR_3)

{

    RTSPState *rt = VAR_0->priv_data;

    RTSPStream *rtsp_st;

    fd_set rfds;

    int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10 = 0;

    struct timeval VAR_11;



    for (;;) {

        if (url_interrupt_cb())

            return AVERROR(EINTR);

        FD_ZERO(&rfds);

        if (rt->rtsp_hd) {

            VAR_9 = VAR_5 = url_get_file_handle(rt->rtsp_hd);

            FD_SET(VAR_9, &rfds);

        } else {

            VAR_5 = 0;

            VAR_9 = -1;

        }

        for (VAR_7 = 0; VAR_7 < rt->nb_rtsp_streams; VAR_7++) {

            rtsp_st = rt->rtsp_streams[VAR_7];

            if (rtsp_st->rtp_handle) {

                



                VAR_4 = url_get_file_handle(rtsp_st->rtp_handle);

                if (VAR_4 > VAR_5)

                    VAR_5 = VAR_4;

                FD_SET(VAR_4, &rfds);

            }

        }

        VAR_11.tv_sec = 0;

        VAR_11.tv_usec = SELECT_TIMEOUT_MS * 1000;

        VAR_6 = select(VAR_5 + 1, &rfds, NULL, NULL, &VAR_11);

        if (VAR_6 > 0) {

            VAR_10 = 0;

            for (VAR_7 = 0; VAR_7 < rt->nb_rtsp_streams; VAR_7++) {

                rtsp_st = rt->rtsp_streams[VAR_7];

                if (rtsp_st->rtp_handle) {

                    VAR_4 = url_get_file_handle(rtsp_st->rtp_handle);

                    if (FD_ISSET(VAR_4, &rfds)) {

                        VAR_8 = url_read(rtsp_st->rtp_handle, VAR_2, VAR_3);

                        if (VAR_8 > 0) {

                            *VAR_1 = rtsp_st;

                            return VAR_8;

                        }

                    }

                }

            }

#if CONFIG_RTSP_DEMUXER

            if (VAR_9 != -1 && FD_ISSET(VAR_9, &rfds)) {

                RTSPMessageHeader reply;



                VAR_8 = ff_rtsp_read_reply(VAR_0, &reply, NULL, 0);

                if (VAR_8 < 0)

                    return VAR_8;

                

                if (rt->state != RTSP_STATE_STREAMING)

                    return 0;

            }

#endif

        } else if (VAR_6 == 0 && ++VAR_10 >= MAX_TIMEOUTS) {

            return FF_NETERROR(ETIMEDOUT);

        } else if (VAR_6 < 0 && errno != EINTR)

            return AVERROR(errno);

    }

}

static int FUNC_0(AVFormatContext *VAR_0, RTSPStream **VAR_1,
uint8_t *VAR_2, int VAR_3)
{ RTSPState *rt = VAR_0->priv_data; RTSPStream *rtsp_st; fd_set rfds; int VAR_4, VAR_5, VAR_6, VAR_7, VAR_8, VAR_9, VAR_10 = 0; struct timeval VAR_11; for (;;) { if (url_interrupt_cb())
return AVERROR(EINTR); FD_ZERO(&rfds); if (rt->rtsp_hd) { VAR_9 = VAR_5 = url_get_file_handle(rt->rtsp_hd); FD_SET(VAR_9, &rfds); } else { VAR_5 = 0; VAR_9 = -1; } for (VAR_7 = 0; VAR_7 < rt->nb_rtsp_streams; VAR_7++) { rtsp_st = rt->rtsp_streams[VAR_7]; if (rtsp_st->rtp_handle) { VAR_4 = url_get_file_handle(rtsp_st->rtp_handle); if (VAR_4 > VAR_5)
VAR_5 = VAR_4; FD_SET(VAR_4, &rfds); } } VAR_11.tv_sec = 0; VAR_11.tv_usec = SELECT_TIMEOUT_MS * 1000; VAR_6 = select(VAR_5 + 1, &rfds, NULL, NULL, &VAR_11); if (VAR_6 > 0) { VAR_10 = 0; for (VAR_7 = 0; VAR_7 < rt->nb_rtsp_streams; VAR_7++) { rtsp_st = rt->rtsp_streams[VAR_7]; if (rtsp_st->rtp_handle) { VAR_4 = url_get_file_handle(rtsp_st->rtp_handle); if (FD_ISSET(VAR_4, &rfds)) { VAR_8 = url_read(rtsp_st->rtp_handle, VAR_2, VAR_3); if (VAR_8 > 0) { *VAR_1 = rtsp_st; return VAR_8; } } } } #if CONFIG_RTSP_DEMUXER
if (VAR_9 != -1 && FD_ISSET(VAR_9, &rfds)) { RTSPMessageHeader reply; VAR_8 = ff_rtsp_read_reply(VAR_0, &reply, NULL, 0); if (VAR_8 < 0)
return VAR_8; if (rt->state != RTSP_STATE_STREAMING)
return 0; } #endif
} else if (VAR_6 == 0 && ++VAR_10 >= MAX_TIMEOUTS) { return FF_NETERROR(ETIMEDOUT); } else if (VAR_6 < 0 && errno != EINTR) return AVERROR(errno); } }