int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count)

{

    ByteIOContext pb;

    uint8_t *buf;

    int len;

    int rtcp_bytes;



    if (!s->rtp_ctx || (count < 1))

        return -1;



    /* XXX: mpeg pts hardcoded. RTCP send every 0.5 seconds */

    s->octet_count += count;

    rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /

        RTCP_TX_RATIO_DEN;

    rtcp_bytes /= 50; // mmu_man: that's enough for me... VLC sends much less btw !?

    if (rtcp_bytes < 28)

        return -1;

    s->last_octet_count = s->octet_count;



    if (url_open_dyn_buf(&pb) < 0)

        return -1;



    // Receiver Report

    put_byte(&pb, (RTP_VERSION << 6) + 1); /* 1 report block */

    put_byte(&pb, 201);

    put_be16(&pb, 7); /* length in words - 1 */

    put_be32(&pb, s->ssrc); // our own SSRC

    put_be32(&pb, s->ssrc); // XXX: should be the server's here!

    // some placeholders we should really fill...

    put_be32(&pb, ((0 << 24) | (0 & 0x0ffffff))); /* 0% lost, total 0 lost */

    put_be32(&pb, (0 << 16) | s->seq);

    put_be32(&pb, 0x68); /* jitter */

    put_be32(&pb, -1); /* last SR timestamp */

    put_be32(&pb, 1); /* delay since last SR */



    // CNAME

    put_byte(&pb, (RTP_VERSION << 6) + 1); /* 1 report block */

    put_byte(&pb, 202);

    len = strlen(s->hostname);

    put_be16(&pb, (6 + len + 3) / 4); /* length in words - 1 */

    put_be32(&pb, s->ssrc);

    put_byte(&pb, 0x01);

    put_byte(&pb, len);

    put_buffer(&pb, s->hostname, len);

    // padding

    for (len = (6 + len) % 4; len % 4; len++) {

        put_byte(&pb, 0);

    }



    put_flush_packet(&pb);

    len = url_close_dyn_buf(&pb, &buf);

    if ((len > 0) && buf) {

#if defined(DEBUG)

        printf("sending %d bytes of RR\n", len);

#endif

        url_write(s->rtp_ctx, buf, len);

        av_free(buf);

    }

    return 0;

}

int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count)

{

    ByteIOContext pb;

    uint8_t *buf;

    int len;

    int rtcp_bytes;



    if (!s->rtp_ctx || (count < 1))

        return -1;



    

    s->octet_count += count;

    rtcp_bytes = ((s->octet_count - s->last_octet_count) * RTCP_TX_RATIO_NUM) /

        RTCP_TX_RATIO_DEN;

    rtcp_bytes /= 50; 

    if (rtcp_bytes < 28)

        return -1;

    s->last_octet_count = s->octet_count;



    if (url_open_dyn_buf(&pb) < 0)

        return -1;



    

    put_byte(&pb, (RTP_VERSION << 6) + 1); 

    put_byte(&pb, 201);

    put_be16(&pb, 7); 

    put_be32(&pb, s->ssrc); 

    put_be32(&pb, s->ssrc); 

    

    put_be32(&pb, ((0 << 24) | (0 & 0x0ffffff))); 

    put_be32(&pb, (0 << 16) | s->seq);

    put_be32(&pb, 0x68); 

    put_be32(&pb, -1); 

    put_be32(&pb, 1); 



    

    put_byte(&pb, (RTP_VERSION << 6) + 1); 

    put_byte(&pb, 202);

    len = strlen(s->hostname);

    put_be16(&pb, (6 + len + 3) / 4); 

    put_be32(&pb, s->ssrc);

    put_byte(&pb, 0x01);

    put_byte(&pb, len);

    put_buffer(&pb, s->hostname, len);

    

    for (len = (6 + len) % 4; len % 4; len++) {

        put_byte(&pb, 0);

    }



    put_flush_packet(&pb);

    len = url_close_dyn_buf(&pb, &buf);

    if ((len > 0) && buf) {

#if defined(DEBUG)

        printf("sending %d bytes of RR\n", len);

#endif

        url_write(s->rtp_ctx, buf, len);

        av_free(buf);

    }

    return 0;

}

int FUNC_0(RTPDemuxContext *VAR_0, int VAR_1)

{

    ByteIOContext pb;

    uint8_t *buf;

    int VAR_2;

    int VAR_3;



    if (!VAR_0->rtp_ctx || (VAR_1 < 1))

        return -1;



    

    VAR_0->octet_count += VAR_1;

    VAR_3 = ((VAR_0->octet_count - VAR_0->last_octet_count) * RTCP_TX_RATIO_NUM) /

        RTCP_TX_RATIO_DEN;

    VAR_3 /= 50; 

    if (VAR_3 < 28)

        return -1;

    VAR_0->last_octet_count = VAR_0->octet_count;



    if (url_open_dyn_buf(&pb) < 0)

        return -1;



    

    put_byte(&pb, (RTP_VERSION << 6) + 1); 

    put_byte(&pb, 201);

    put_be16(&pb, 7); 

    put_be32(&pb, VAR_0->ssrc); 

    put_be32(&pb, VAR_0->ssrc); 

    

    put_be32(&pb, ((0 << 24) | (0 & 0x0ffffff))); 

    put_be32(&pb, (0 << 16) | VAR_0->seq);

    put_be32(&pb, 0x68); 

    put_be32(&pb, -1); 

    put_be32(&pb, 1); 



    

    put_byte(&pb, (RTP_VERSION << 6) + 1); 

    put_byte(&pb, 202);

    VAR_2 = strlen(VAR_0->hostname);

    put_be16(&pb, (6 + VAR_2 + 3) / 4); 

    put_be32(&pb, VAR_0->ssrc);

    put_byte(&pb, 0x01);

    put_byte(&pb, VAR_2);

    put_buffer(&pb, VAR_0->hostname, VAR_2);

    

    for (VAR_2 = (6 + VAR_2) % 4; VAR_2 % 4; VAR_2++) {

        put_byte(&pb, 0);

    }



    put_flush_packet(&pb);

    VAR_2 = url_close_dyn_buf(&pb, &buf);

    if ((VAR_2 > 0) && buf) {

#if defined(DEBUG)

        printf("sending %d bytes of RR\n", VAR_2);

#endif

        url_write(VAR_0->rtp_ctx, buf, VAR_2);

        av_free(buf);

    }

    return 0;

}

int FUNC_0(RTPDemuxContext *VAR_0, int VAR_1)
{ ByteIOContext pb; uint8_t *buf; int VAR_2; int VAR_3; if (!VAR_0->rtp_ctx || (VAR_1 < 1))
return -1; VAR_0->octet_count += VAR_1; VAR_3 = ((VAR_0->octet_count - VAR_0->last_octet_count) * RTCP_TX_RATIO_NUM) /
RTCP_TX_RATIO_DEN; VAR_3 /= 50; if (VAR_3 < 28)
return -1; VAR_0->last_octet_count = VAR_0->octet_count; if (url_open_dyn_buf(&pb) < 0)
return -1; put_byte(&pb, (RTP_VERSION << 6) + 1); put_byte(&pb, 201); put_be16(&pb, 7); put_be32(&pb, VAR_0->ssrc); put_be32(&pb, VAR_0->ssrc); put_be32(&pb, ((0 << 24) | (0 & 0x0ffffff))); put_be32(&pb, (0 << 16) | VAR_0->seq); put_be32(&pb, 0x68); put_be32(&pb, -1); put_be32(&pb, 1); put_byte(&pb, (RTP_VERSION << 6) + 1); put_byte(&pb, 202); VAR_2 = strlen(VAR_0->hostname); put_be16(&pb, (6 + VAR_2 + 3) / 4); put_be32(&pb, VAR_0->ssrc); put_byte(&pb, 0x01); put_byte(&pb, VAR_2); put_buffer(&pb, VAR_0->hostname, VAR_2); for (VAR_2 = (6 + VAR_2) % 4; VAR_2 % 4; VAR_2++) { put_byte(&pb, 0); } put_flush_packet(&pb); VAR_2 = url_close_dyn_buf(&pb, &buf); if ((VAR_2 > 0) && buf) { #if defined(DEBUG)
printf("sending %d bytes of RR\n", VAR_2); #endif
url_write(VAR_0->rtp_ctx, buf, VAR_2); av_free(buf); } return 0; }