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

                           uint8_t *buf, int buf_size)

{

    RTSPState *rt = s->priv_data;

    int id, len, i, ret;

    RTSPStream *rtsp_st;



#ifdef DEBUG_RTP_TCP

    dprintf(s, "tcp_read_packet:\n");

#endif

 redo:

    for(;;) {

        RTSPMessageHeader reply;



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

        if (ret == -1)

            return -1;

        if (ret == 1) /* received '$' */

            break;

        /* XXX: parse message */

        if (rt->state != RTSP_STATE_PLAYING)

            return 0;

    }

    ret = url_read_complete(rt->rtsp_hd, buf, 3);

    if (ret != 3)

        return -1;

    id = buf[0];

    len = AV_RB16(buf + 1);

#ifdef DEBUG_RTP_TCP

    dprintf(s, "id=%d len=%d\n", id, len);

#endif

    if (len > buf_size || len < 12)

        goto redo;

    /* get the data */

    ret = url_read_complete(rt->rtsp_hd, buf, len);

    if (ret != len)

        return -1;

    if (rt->transport == RTSP_TRANSPORT_RDT &&

        ff_rdt_parse_header(buf, len, &id, NULL, NULL, NULL, NULL) < 0)

        return -1;



    /* find the matching stream */

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

        rtsp_st = rt->rtsp_streams[i];

        if (id >= rtsp_st->interleaved_min &&

            id <= rtsp_st->interleaved_max)

            goto found;

    }

    goto redo;

 found:

    *prtsp_st = rtsp_st;

    return len;

}

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

                           uint8_t *buf, int buf_size)

{

    RTSPState *rt = s->priv_data;

    int id, len, i, ret;

    RTSPStream *rtsp_st;



#ifdef DEBUG_RTP_TCP

    dprintf(s, "tcp_read_packet:\n");

#endif

 redo:

    for(;;) {

        RTSPMessageHeader reply;



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

        if (ret == -1)

            return -1;

        if (ret == 1) 

            break;

        

        if (rt->state != RTSP_STATE_PLAYING)

            return 0;

    }

    ret = url_read_complete(rt->rtsp_hd, buf, 3);

    if (ret != 3)

        return -1;

    id = buf[0];

    len = AV_RB16(buf + 1);

#ifdef DEBUG_RTP_TCP

    dprintf(s, "id=%d len=%d\n", id, len);

#endif

    if (len > buf_size || len < 12)

        goto redo;

    

    ret = url_read_complete(rt->rtsp_hd, buf, len);

    if (ret != len)

        return -1;

    if (rt->transport == RTSP_TRANSPORT_RDT &&

        ff_rdt_parse_header(buf, len, &id, NULL, NULL, NULL, NULL) < 0)

        return -1;



    

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

        rtsp_st = rt->rtsp_streams[i];

        if (id >= rtsp_st->interleaved_min &&

            id <= rtsp_st->interleaved_max)

            goto found;

    }

    goto redo;

 found:

    *prtsp_st = rtsp_st;

    return len;

}

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

                           uint8_t *VAR_2, int VAR_3)

{

    RTSPState *rt = VAR_0->priv_data;

    int VAR_4, VAR_5, VAR_6, VAR_7;

    RTSPStream *rtsp_st;



#ifdef DEBUG_RTP_TCP

    dprintf(VAR_0, "FUNC_0:\n");

#endif

 redo:

    for(;;) {

        RTSPMessageHeader reply;



        VAR_7 = rtsp_read_reply(VAR_0, &reply, NULL, 1);

        if (VAR_7 == -1)

            return -1;

        if (VAR_7 == 1) 

            break;

        

        if (rt->state != RTSP_STATE_PLAYING)

            return 0;

    }

    VAR_7 = url_read_complete(rt->rtsp_hd, VAR_2, 3);

    if (VAR_7 != 3)

        return -1;

    VAR_4 = VAR_2[0];

    VAR_5 = AV_RB16(VAR_2 + 1);

#ifdef DEBUG_RTP_TCP

    dprintf(VAR_0, "VAR_4=%d VAR_5=%d\n", VAR_4, VAR_5);

#endif

    if (VAR_5 > VAR_3 || VAR_5 < 12)

        goto redo;

    

    VAR_7 = url_read_complete(rt->rtsp_hd, VAR_2, VAR_5);

    if (VAR_7 != VAR_5)

        return -1;

    if (rt->transport == RTSP_TRANSPORT_RDT &&

        ff_rdt_parse_header(VAR_2, VAR_5, &VAR_4, NULL, NULL, NULL, NULL) < 0)

        return -1;



    

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

        rtsp_st = rt->rtsp_streams[VAR_6];

        if (VAR_4 >= rtsp_st->interleaved_min &&

            VAR_4 <= rtsp_st->interleaved_max)

            goto found;

    }

    goto redo;

 found:

    *VAR_1 = rtsp_st;

    return VAR_5;

}

static int FUNC_0(AVFormatContext *VAR_0, RTSPStream **VAR_1,
uint8_t *VAR_2, int VAR_3)
{ RTSPState *rt = VAR_0->priv_data; int VAR_4, VAR_5, VAR_6, VAR_7; RTSPStream *rtsp_st; #ifdef DEBUG_RTP_TCP
dprintf(VAR_0, "FUNC_0:\n"); #endif
redo:
for(;;) { RTSPMessageHeader reply; VAR_7 = rtsp_read_reply(VAR_0, &reply, NULL, 1); if (VAR_7 == -1)
return -1; if (VAR_7 == 1)
break; if (rt->state != RTSP_STATE_PLAYING)
return 0; } VAR_7 = url_read_complete(rt->rtsp_hd, VAR_2, 3); if (VAR_7 != 3)
return -1; VAR_4 = VAR_2[0]; VAR_5 = AV_RB16(VAR_2 + 1); #ifdef DEBUG_RTP_TCP
dprintf(VAR_0, "VAR_4=%d VAR_5=%d\n", VAR_4, VAR_5); #endif
if (VAR_5 > VAR_3 || VAR_5 < 12)
goto redo; VAR_7 = url_read_complete(rt->rtsp_hd, VAR_2, VAR_5); if (VAR_7 != VAR_5)
return -1; if (rt->transport == RTSP_TRANSPORT_RDT &&
ff_rdt_parse_header(VAR_2, VAR_5, &VAR_4, NULL, NULL, NULL, NULL) < 0)
return -1; for(VAR_6 = 0; VAR_6 < rt->nb_rtsp_streams; VAR_6++) { rtsp_st = rt->rtsp_streams[VAR_6]; if (VAR_4 >= rtsp_st->interleaved_min &&
VAR_4 <= rtsp_st->interleaved_max)
goto found; } goto redo; found:
*VAR_1 = rtsp_st; return VAR_5; }