static int tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st)

{

    RTSPState *rt = s->priv_data;

    AVFormatContext *rtpctx = rtsp_st->transport_priv;

    uint8_t *buf, *ptr;

    int size;

    uint8_t *interleave_header, *interleaved_packet;



    size = avio_close_dyn_buf(rtpctx->pb, &buf);

    ptr = buf;

    while (size > 4) {

        uint32_t packet_len = AV_RB32(ptr);

        int id;

        /* The interleaving header is exactly 4 bytes, which happens to be

         * the same size as the packet length header from

         * url_open_dyn_packet_buf. So by writing the interleaving header

         * over these bytes, we get a consecutive interleaved packet

         * that can be written in one call. */

        interleaved_packet = interleave_header = ptr;

        ptr += 4;

        size -= 4;

        if (packet_len > size || packet_len < 2)

            break;

        if (ptr[1] >= RTCP_SR && ptr[1] <= RTCP_APP)

            id = rtsp_st->interleaved_max; /* RTCP */

        else

            id = rtsp_st->interleaved_min; /* RTP */

        interleave_header[0] = '$';

        interleave_header[1] = id;

        AV_WB16(interleave_header + 2, packet_len);

        url_write(rt->rtsp_hd_out, interleaved_packet, 4 + packet_len);

        ptr += packet_len;

        size -= packet_len;

    }

    av_free(buf);

    url_open_dyn_packet_buf(&rtpctx->pb, RTSP_TCP_MAX_PACKET_SIZE);

    return 0;

}

static int tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st)

{

    RTSPState *rt = s->priv_data;

    AVFormatContext *rtpctx = rtsp_st->transport_priv;

    uint8_t *buf, *ptr;

    int size;

    uint8_t *interleave_header, *interleaved_packet;



    size = avio_close_dyn_buf(rtpctx->pb, &buf);

    ptr = buf;

    while (size > 4) {

        uint32_t packet_len = AV_RB32(ptr);

        int id;

        









        interleaved_packet = interleave_header = ptr;

        ptr += 4;

        size -= 4;

        if (packet_len > size || packet_len < 2)

            break;

        if (ptr[1] >= RTCP_SR && ptr[1] <= RTCP_APP)

            id = rtsp_st->interleaved_max; 

        else

            id = rtsp_st->interleaved_min; 

        interleave_header[0] = '$';

        interleave_header[1] = id;

        AV_WB16(interleave_header + 2, packet_len);

        url_write(rt->rtsp_hd_out, interleaved_packet, 4 + packet_len);

        ptr += packet_len;

        size -= packet_len;

    }

    av_free(buf);

    url_open_dyn_packet_buf(&rtpctx->pb, RTSP_TCP_MAX_PACKET_SIZE);

    return 0;

}

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

{

    RTSPState *rt = VAR_0->priv_data;

    AVFormatContext *rtpctx = VAR_1->transport_priv;

    uint8_t *buf, *ptr;

    int VAR_2;

    uint8_t *interleave_header, *interleaved_packet;



    VAR_2 = avio_close_dyn_buf(rtpctx->pb, &buf);

    ptr = buf;

    while (VAR_2 > 4) {

        uint32_t packet_len = AV_RB32(ptr);

        int VAR_3;

        









        interleaved_packet = interleave_header = ptr;

        ptr += 4;

        VAR_2 -= 4;

        if (packet_len > VAR_2 || packet_len < 2)

            break;

        if (ptr[1] >= RTCP_SR && ptr[1] <= RTCP_APP)

            VAR_3 = VAR_1->interleaved_max; 

        else

            VAR_3 = VAR_1->interleaved_min; 

        interleave_header[0] = '$';

        interleave_header[1] = VAR_3;

        AV_WB16(interleave_header + 2, packet_len);

        url_write(rt->rtsp_hd_out, interleaved_packet, 4 + packet_len);

        ptr += packet_len;

        VAR_2 -= packet_len;

    }

    av_free(buf);

    url_open_dyn_packet_buf(&rtpctx->pb, RTSP_TCP_MAX_PACKET_SIZE);

    return 0;

}

static int FUNC_0(AVFormatContext *VAR_0, RTSPStream *VAR_1)
{ RTSPState *rt = VAR_0->priv_data; AVFormatContext *rtpctx = VAR_1->transport_priv; uint8_t *buf, *ptr; int VAR_2; uint8_t *interleave_header, *interleaved_packet; VAR_2 = avio_close_dyn_buf(rtpctx->pb, &buf); ptr = buf; while (VAR_2 > 4) { uint32_t packet_len = AV_RB32(ptr); int VAR_3; interleaved_packet = interleave_header = ptr; ptr += 4; VAR_2 -= 4; if (packet_len > VAR_2 || packet_len < 2)
break; if (ptr[1] >= RTCP_SR && ptr[1] <= RTCP_APP)
VAR_3 = VAR_1->interleaved_max; else
VAR_3 = VAR_1->interleaved_min; interleave_header[0] = '$'; interleave_header[1] = VAR_3; AV_WB16(interleave_header + 2, packet_len); url_write(rt->rtsp_hd_out, interleaved_packet, 4 + packet_len); ptr += packet_len; VAR_2 -= packet_len; } av_free(buf); url_open_dyn_packet_buf(&rtpctx->pb, RTSP_TCP_MAX_PACKET_SIZE); return 0; }