static int rtsp_write_packet(AVFormatContext *s, AVPacket *pkt)

{

    RTSPState *rt = s->priv_data;

    RTSPStream *rtsp_st;

    fd_set rfds;

    int n, tcp_fd;

    struct timeval tv;

    AVFormatContext *rtpctx;

    int ret;



    tcp_fd = url_get_file_handle(rt->rtsp_hd);



    while (1) {

        FD_ZERO(&rfds);

        FD_SET(tcp_fd, &rfds);

        tv.tv_sec = 0;

        tv.tv_usec = 0;

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

        if (n <= 0)

            break;

        if (FD_ISSET(tcp_fd, &rfds)) {

            RTSPMessageHeader reply;



            /* Don't let ff_rtsp_read_reply handle interleaved packets,

             * since it would block and wait for an RTSP reply on the socket

             * (which may not be coming any time soon) if it handles

             * interleaved packets internally. */

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

            if (ret < 0)

                return AVERROR(EPIPE);

            if (ret == 1)

                ff_rtsp_skip_packet(s);

            /* XXX: parse message */

            if (rt->state != RTSP_STATE_STREAMING)

                return AVERROR(EPIPE);

        }

    }



    if (pkt->stream_index < 0 || pkt->stream_index >= rt->nb_rtsp_streams)

        return AVERROR_INVALIDDATA;

    rtsp_st = rt->rtsp_streams[pkt->stream_index];

    rtpctx = rtsp_st->transport_priv;



    ret = ff_write_chained(rtpctx, 0, pkt, s);

    /* ff_write_chained does all the RTP packetization. If using TCP as

     * transport, rtpctx->pb is only a dyn_packet_buf that queues up the

     * packets, so we need to send them out on the TCP connection separately.

     */

    if (!ret && rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP)

        ret = tcp_write_packet(s, rtsp_st);

    return ret;

}

static int rtsp_write_packet(AVFormatContext *s, AVPacket *pkt)

{

    RTSPState *rt = s->priv_data;

    RTSPStream *rtsp_st;

    fd_set rfds;

    int n, tcp_fd;

    struct timeval tv;

    AVFormatContext *rtpctx;

    int ret;



    tcp_fd = url_get_file_handle(rt->rtsp_hd);



    while (1) {

        FD_ZERO(&rfds);

        FD_SET(tcp_fd, &rfds);

        tv.tv_sec = 0;

        tv.tv_usec = 0;

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

        if (n <= 0)

            break;

        if (FD_ISSET(tcp_fd, &rfds)) {

            RTSPMessageHeader reply;



            







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

            if (ret < 0)

                return AVERROR(EPIPE);

            if (ret == 1)

                ff_rtsp_skip_packet(s);

            

            if (rt->state != RTSP_STATE_STREAMING)

                return AVERROR(EPIPE);

        }

    }



    if (pkt->stream_index < 0 || pkt->stream_index >= rt->nb_rtsp_streams)

        return AVERROR_INVALIDDATA;

    rtsp_st = rt->rtsp_streams[pkt->stream_index];

    rtpctx = rtsp_st->transport_priv;



    ret = ff_write_chained(rtpctx, 0, pkt, s);

    







    if (!ret && rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP)

        ret = tcp_write_packet(s, rtsp_st);

    return ret;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)

{

    RTSPState *rt = VAR_0->priv_data;

    RTSPStream *rtsp_st;

    fd_set rfds;

    int VAR_2, VAR_3;

    struct timeval VAR_4;

    AVFormatContext *rtpctx;

    int VAR_5;



    VAR_3 = url_get_file_handle(rt->rtsp_hd);



    while (1) {

        FD_ZERO(&rfds);

        FD_SET(VAR_3, &rfds);

        VAR_4.tv_sec = 0;

        VAR_4.tv_usec = 0;

        VAR_2 = select(VAR_3 + 1, &rfds, NULL, NULL, &VAR_4);

        if (VAR_2 <= 0)

            break;

        if (FD_ISSET(VAR_3, &rfds)) {

            RTSPMessageHeader reply;



            







            VAR_5 = ff_rtsp_read_reply(VAR_0, &reply, NULL, 1, NULL);

            if (VAR_5 < 0)

                return AVERROR(EPIPE);

            if (VAR_5 == 1)

                ff_rtsp_skip_packet(VAR_0);

            

            if (rt->state != RTSP_STATE_STREAMING)

                return AVERROR(EPIPE);

        }

    }



    if (VAR_1->stream_index < 0 || VAR_1->stream_index >= rt->nb_rtsp_streams)

        return AVERROR_INVALIDDATA;

    rtsp_st = rt->rtsp_streams[VAR_1->stream_index];

    rtpctx = rtsp_st->transport_priv;



    VAR_5 = ff_write_chained(rtpctx, 0, VAR_1, VAR_0);

    







    if (!VAR_5 && rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP)

        VAR_5 = tcp_write_packet(VAR_0, rtsp_st);

    return VAR_5;

}

static int FUNC_0(AVFormatContext *VAR_0, AVPacket *VAR_1)
{ RTSPState *rt = VAR_0->priv_data; RTSPStream *rtsp_st; fd_set rfds; int VAR_2, VAR_3; struct timeval VAR_4; AVFormatContext *rtpctx; int VAR_5; VAR_3 = url_get_file_handle(rt->rtsp_hd); while (1) { FD_ZERO(&rfds); FD_SET(VAR_3, &rfds); VAR_4.tv_sec = 0; VAR_4.tv_usec = 0; VAR_2 = select(VAR_3 + 1, &rfds, NULL, NULL, &VAR_4); if (VAR_2 <= 0)
break; if (FD_ISSET(VAR_3, &rfds)) { RTSPMessageHeader reply; VAR_5 = ff_rtsp_read_reply(VAR_0, &reply, NULL, 1, NULL); if (VAR_5 < 0)
return AVERROR(EPIPE); if (VAR_5 == 1)
ff_rtsp_skip_packet(VAR_0); if (rt->state != RTSP_STATE_STREAMING)
return AVERROR(EPIPE); } } if (VAR_1->stream_index < 0 || VAR_1->stream_index >= rt->nb_rtsp_streams)
return AVERROR_INVALIDDATA; rtsp_st = rt->rtsp_streams[VAR_1->stream_index]; rtpctx = rtsp_st->transport_priv; VAR_5 = ff_write_chained(rtpctx, 0, VAR_1, VAR_0); if (!VAR_5 && rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP)
VAR_5 = tcp_write_packet(VAR_0, rtsp_st); return VAR_5; }