25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.5KB

  1. // RFC3550 6.4.2 RR: Receiver Report RTCP Packet
  2. #include "rtp-internal.h"
  3. #include "rtp-util.h"
  4. void rtcp_rr_unpack(struct rtp_context *ctx, const rtcp_header_t *header, const uint8_t* ptr, size_t bytes)
  5. {
  6. uint32_t i;
  7. rtcp_rb_t *rb;
  8. struct rtcp_msg_t msg;
  9. struct rtp_member *receiver;
  10. assert(24 == sizeof(rtcp_rb_t) && 4 == sizeof(rtcp_rr_t));
  11. if (bytes < 4/*sizeof(rtcp_rr_t)*/ + header->rc * 24/*sizeof(rtcp_rb_t)*/) // RR SSRC + Report Block
  12. {
  13. assert(0);
  14. return;
  15. }
  16. msg.ssrc = nbo_r32(ptr);
  17. msg.type = RTCP_RR;
  18. receiver = rtp_member_fetch(ctx, msg.ssrc);
  19. if(!receiver) return; // error
  20. assert(receiver != ctx->self);
  21. assert(receiver->rtcp_sr.ssrc == msg.ssrc);
  22. //assert(receiver->rtcp_rb.ssrc == msg.ssrc);
  23. receiver->rtcp_clock = rtpclock(); // last received clock, for keep-alive
  24. ptr += 4;
  25. // report block
  26. for(i = 0; i < header->rc; i++, ptr+=24/*sizeof(rtcp_rb_t)*/)
  27. {
  28. msg.u.rr.ssrc = nbo_r32(ptr);
  29. //if(msg.u.rr.ssrcssrc != ctx->self->ssrc)
  30. // continue; // ignore
  31. //rb = &receiver->rtcp_rb;
  32. rb = &msg.u.rr;
  33. rb->fraction = ptr[4];
  34. rb->cumulative = (((uint32_t)ptr[5])<<16) | (((uint32_t)ptr[6])<<8)| ptr[7];
  35. rb->exthsn = nbo_r32(ptr+8);
  36. rb->jitter = nbo_r32(ptr+12);
  37. rb->lsr = nbo_r32(ptr+16);
  38. rb->dlsr = nbo_r32(ptr+20);
  39. ctx->handler.on_rtcp(ctx->cbparam, &msg);
  40. }
  41. }
  42. int rtcp_rr_pack(struct rtp_context *ctx, uint8_t* ptr, int bytes)
  43. {
  44. // RFC3550 6.1 RTCP Packet Format
  45. // An individual RTP participant should send only one compound RTCP packet per report interval
  46. // in order for the RTCP bandwidth per participant to be estimated correctly (see Section 6.2),
  47. // except when the compound RTCP packet is split for partial encryption as described in Section 9.1.
  48. uint32_t i;
  49. rtcp_header_t header;
  50. assert(4 == sizeof(rtcp_rr_t));
  51. assert(24 == sizeof(rtcp_rb_t));
  52. assert(rtp_member_list_count(ctx->senders) < 32);
  53. header.v = 2;
  54. header.p = 0;
  55. header.pt = RTCP_RR;
  56. header.rc = MIN(31, rtp_member_list_count(ctx->senders));
  57. header.length = (4/*sizeof(rtcp_rr_t)*/ + header.rc*24/*sizeof(rtcp_rb_t)*/) / 4;
  58. if((uint32_t)bytes < 4 + header.length * 4)
  59. return 4 + header.length * 4;
  60. nbo_write_rtcp_header(ptr, &header);
  61. // receiver SSRC
  62. nbo_w32(ptr+4, ctx->self->ssrc);
  63. ptr += 8;
  64. // report block
  65. for(i = 0; i < header.rc; i++)
  66. {
  67. struct rtp_member *sender;
  68. sender = rtp_member_list_get(ctx->senders, i);
  69. if(0 == sender->rtp_packets || sender->ssrc == ctx->self->ssrc)
  70. continue; // don't receive any packet
  71. ptr += rtcp_report_block(sender, ptr, 24);
  72. }
  73. return (header.length+1) * 4;
  74. }