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

                           uint8_t *buf, int buf_size, int64_t wait_end)

{

    RTSPState *rt = s->priv_data;

    RTSPStream *rtsp_st;

    int n, i, ret, timeout_cnt = 0;

    struct pollfd *p = rt->p;

    int *fds = NULL, fdsnum, fdsidx;



    if (!p) {

        p = rt->p = av_malloc_array(2 * (rt->nb_rtsp_streams + 1), sizeof(struct pollfd));

        if (!p)

            return AVERROR(ENOMEM);



        if (rt->rtsp_hd) {

            p[rt->max_p].fd = ffurl_get_file_handle(rt->rtsp_hd);

            p[rt->max_p++].events = POLLIN;

        }

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

            rtsp_st = rt->rtsp_streams[i];

            if (rtsp_st->rtp_handle) {

                if (ret = ffurl_get_multi_file_handle(rtsp_st->rtp_handle,

                                                      &fds, &fdsnum)) {

                    av_log(s, AV_LOG_ERROR, "Unable to recover rtp ports\n");

                    return ret;

                }

                if (fdsnum != 2) {

                    av_log(s, AV_LOG_ERROR,

                           "Number of fds %d not supported\n", fdsnum);

                    return AVERROR_INVALIDDATA;

                }

                for (fdsidx = 0; fdsidx < fdsnum; fdsidx++) {

                    p[rt->max_p].fd       = fds[fdsidx];

                    p[rt->max_p++].events = POLLIN;

                }

                av_free(fds);

            }

        }

    }



    for (;;) {

        if (ff_check_interrupt(&s->interrupt_callback))

            return AVERROR_EXIT;

        if (wait_end && wait_end - av_gettime_relative() < 0)

            return AVERROR(EAGAIN);

        n = poll(p, rt->max_p, POLL_TIMEOUT_MS);

        if (n > 0) {

            int j = rt->rtsp_hd ? 1 : 0;

            timeout_cnt = 0;

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

                rtsp_st = rt->rtsp_streams[i];

                if (rtsp_st->rtp_handle) {

                    if (p[j].revents & POLLIN || p[j+1].revents & POLLIN) {

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

                        if (ret > 0) {

                            *prtsp_st = rtsp_st;

                            return ret;

                        }

                    }

                    j+=2;

                }

            }

#if CONFIG_RTSP_DEMUXER

            if (rt->rtsp_hd && p[0].revents & POLLIN) {

                return parse_rtsp_message(s);

            }

#endif

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

            return AVERROR(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, int64_t wait_end)

{

    RTSPState *rt = s->priv_data;

    RTSPStream *rtsp_st;

    int n, i, ret, timeout_cnt = 0;

    struct pollfd *p = rt->p;

    int *fds = NULL, fdsnum, fdsidx;



    if (!p) {

        p = rt->p = av_malloc_array(2 * (rt->nb_rtsp_streams + 1), sizeof(struct pollfd));

        if (!p)

            return AVERROR(ENOMEM);



        if (rt->rtsp_hd) {

            p[rt->max_p].fd = ffurl_get_file_handle(rt->rtsp_hd);

            p[rt->max_p++].events = POLLIN;

        }

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

            rtsp_st = rt->rtsp_streams[i];

            if (rtsp_st->rtp_handle) {

                if (ret = ffurl_get_multi_file_handle(rtsp_st->rtp_handle,

                                                      &fds, &fdsnum)) {

                    av_log(s, AV_LOG_ERROR, "Unable to recover rtp ports\n");

                    return ret;

                }

                if (fdsnum != 2) {

                    av_log(s, AV_LOG_ERROR,

                           "Number of fds %d not supported\n", fdsnum);

                    return AVERROR_INVALIDDATA;

                }

                for (fdsidx = 0; fdsidx < fdsnum; fdsidx++) {

                    p[rt->max_p].fd       = fds[fdsidx];

                    p[rt->max_p++].events = POLLIN;

                }

                av_free(fds);

            }

        }

    }



    for (;;) {

        if (ff_check_interrupt(&s->interrupt_callback))

            return AVERROR_EXIT;

        if (wait_end && wait_end - av_gettime_relative() < 0)

            return AVERROR(EAGAIN);

        n = poll(p, rt->max_p, POLL_TIMEOUT_MS);

        if (n > 0) {

            int j = rt->rtsp_hd ? 1 : 0;

            timeout_cnt = 0;

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

                rtsp_st = rt->rtsp_streams[i];

                if (rtsp_st->rtp_handle) {

                    if (p[j].revents & POLLIN || p[j+1].revents & POLLIN) {

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

                        if (ret > 0) {

                            *prtsp_st = rtsp_st;

                            return ret;

                        }

                    }

                    j+=2;

                }

            }

#if CONFIG_RTSP_DEMUXER

            if (rt->rtsp_hd && p[0].revents & POLLIN) {

                return parse_rtsp_message(s);

            }

#endif

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

            return AVERROR(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, int64_t VAR_4)

{

    RTSPState *rt = VAR_0->priv_data;

    RTSPStream *rtsp_st;

    int VAR_5, VAR_6, VAR_7, VAR_8 = 0;

    struct pollfd *VAR_9 = rt->VAR_9;

    int *VAR_10 = NULL, VAR_11, VAR_12;



    if (!VAR_9) {

        VAR_9 = rt->VAR_9 = av_malloc_array(2 * (rt->nb_rtsp_streams + 1), sizeof(struct pollfd));

        if (!VAR_9)

            return AVERROR(ENOMEM);



        if (rt->rtsp_hd) {

            VAR_9[rt->max_p].fd = ffurl_get_file_handle(rt->rtsp_hd);

            VAR_9[rt->max_p++].events = POLLIN;

        }

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

            rtsp_st = rt->rtsp_streams[VAR_6];

            if (rtsp_st->rtp_handle) {

                if (VAR_7 = ffurl_get_multi_file_handle(rtsp_st->rtp_handle,

                                                      &VAR_10, &VAR_11)) {

                    av_log(VAR_0, AV_LOG_ERROR, "Unable to recover rtp ports\VAR_5");

                    return VAR_7;

                }

                if (VAR_11 != 2) {

                    av_log(VAR_0, AV_LOG_ERROR,

                           "Number of VAR_10 %d not supported\VAR_5", VAR_11);

                    return AVERROR_INVALIDDATA;

                }

                for (VAR_12 = 0; VAR_12 < VAR_11; VAR_12++) {

                    VAR_9[rt->max_p].fd       = VAR_10[VAR_12];

                    VAR_9[rt->max_p++].events = POLLIN;

                }

                av_free(VAR_10);

            }

        }

    }



    for (;;) {

        if (ff_check_interrupt(&VAR_0->interrupt_callback))

            return AVERROR_EXIT;

        if (VAR_4 && VAR_4 - av_gettime_relative() < 0)

            return AVERROR(EAGAIN);

        VAR_5 = poll(VAR_9, rt->max_p, POLL_TIMEOUT_MS);

        if (VAR_5 > 0) {

            int VAR_13 = rt->rtsp_hd ? 1 : 0;

            VAR_8 = 0;

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

                rtsp_st = rt->rtsp_streams[VAR_6];

                if (rtsp_st->rtp_handle) {

                    if (VAR_9[VAR_13].revents & POLLIN || VAR_9[VAR_13+1].revents & POLLIN) {

                        VAR_7 = ffurl_read(rtsp_st->rtp_handle, VAR_2, VAR_3);

                        if (VAR_7 > 0) {

                            *VAR_1 = rtsp_st;

                            return VAR_7;

                        }

                    }

                    VAR_13+=2;

                }

            }

#if CONFIG_RTSP_DEMUXER

            if (rt->rtsp_hd && VAR_9[0].revents & POLLIN) {

                return parse_rtsp_message(VAR_0);

            }

#endif

        } else if (VAR_5 == 0 && ++VAR_8 >= MAX_TIMEOUTS) {

            return AVERROR(ETIMEDOUT);

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

            return AVERROR(errno);

    }

}

static int FUNC_0(AVFormatContext *VAR_0, RTSPStream **VAR_1,
uint8_t *VAR_2, int VAR_3, int64_t VAR_4)
{ RTSPState *rt = VAR_0->priv_data; RTSPStream *rtsp_st; int VAR_5, VAR_6, VAR_7, VAR_8 = 0; struct pollfd *VAR_9 = rt->VAR_9; int *VAR_10 = NULL, VAR_11, VAR_12; if (!VAR_9) { VAR_9 = rt->VAR_9 = av_malloc_array(2 * (rt->nb_rtsp_streams + 1), sizeof(struct pollfd)); if (!VAR_9)
return AVERROR(ENOMEM); if (rt->rtsp_hd) { VAR_9[rt->max_p].fd = ffurl_get_file_handle(rt->rtsp_hd); VAR_9[rt->max_p++].events = POLLIN; } for (VAR_6 = 0; VAR_6 < rt->nb_rtsp_streams; VAR_6++) { rtsp_st = rt->rtsp_streams[VAR_6]; if (rtsp_st->rtp_handle) { if (VAR_7 = ffurl_get_multi_file_handle(rtsp_st->rtp_handle,
&VAR_10, &VAR_11)) { av_log(VAR_0, AV_LOG_ERROR, "Unable to recover rtp ports\VAR_5"); return VAR_7; } if (VAR_11 != 2) { av_log(VAR_0, AV_LOG_ERROR,
"Number of VAR_10 %d not supported\VAR_5", VAR_11); return AVERROR_INVALIDDATA; } for (VAR_12 = 0; VAR_12 < VAR_11; VAR_12++) { VAR_9[rt->max_p].fd       = VAR_10[VAR_12]; VAR_9[rt->max_p++].events = POLLIN; } av_free(VAR_10); } } } for (;;) { if (ff_check_interrupt(&VAR_0->interrupt_callback))
return AVERROR_EXIT; if (VAR_4 && VAR_4 - av_gettime_relative() < 0)
return AVERROR(EAGAIN); VAR_5 = poll(VAR_9, rt->max_p, POLL_TIMEOUT_MS); if (VAR_5 > 0) { int VAR_13 = rt->rtsp_hd ? 1 : 0; VAR_8 = 0; for (VAR_6 = 0; VAR_6 < rt->nb_rtsp_streams; VAR_6++) { rtsp_st = rt->rtsp_streams[VAR_6]; if (rtsp_st->rtp_handle) { if (VAR_9[VAR_13].revents & POLLIN || VAR_9[VAR_13+1].revents & POLLIN) { VAR_7 = ffurl_read(rtsp_st->rtp_handle, VAR_2, VAR_3); if (VAR_7 > 0) { *VAR_1 = rtsp_st; return VAR_7; } } VAR_13+=2; } } #if CONFIG_RTSP_DEMUXER
if (rt->rtsp_hd && VAR_9[0].revents & POLLIN) { return parse_rtsp_message(VAR_0); } #endif
} else if (VAR_5 == 0 && ++VAR_8 >= MAX_TIMEOUTS) { return AVERROR(ETIMEDOUT); } else if (VAR_5 < 0 && errno != EINTR) return AVERROR(errno); } }