Changeset 1444 for pjproject/trunk
- Timestamp:
- Sep 20, 2007 11:30:59 AM (17 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/rtcp.h
r1417 r1444 59 59 struct pjmedia_rtcp_sr 60 60 { 61 pj_uint32_t ssrc; /**< SSRC identification. */62 61 pj_uint32_t ntp_sec; /**< NTP time, seconds part. */ 63 62 pj_uint32_t ntp_frac; /**< NTP time, fractions part. */ … … 118 117 #endif 119 118 unsigned length:16; /**< packet length */ 119 pj_uint32_t ssrc; /**< SSRC identification */ 120 120 }; 121 121 … … 130 130 * manually by application. 131 131 */ 132 struct pjmedia_rtcp_pkt132 typedef struct pjmedia_rtcp_sr_pkt 133 133 { 134 134 pjmedia_rtcp_common common; /**< Common header. */ 135 135 pjmedia_rtcp_sr sr; /**< Sender report. */ 136 136 pjmedia_rtcp_rr rr; /**< variable-length list */ 137 }; 138 139 /** 140 * @see pjmedia_rtcp_pkt 141 */ 142 typedef struct pjmedia_rtcp_pkt pjmedia_rtcp_pkt; 137 } pjmedia_rtcp_sr_pkt; 138 139 /** 140 * This structure declares RTCP RR (Receiver Report) packet. 141 */ 142 typedef struct pjmedia_rtcp_rr_pkt 143 { 144 pjmedia_rtcp_common common; /**< Common header. */ 145 pjmedia_rtcp_rr rr; /**< variable-length list */ 146 } pjmedia_rtcp_rr_pkt; 143 147 144 148 … … 251 255 { 252 256 char *name; /**< Name identification. */ 253 pjmedia_rtcp_pkt rtcp_pkt; /**< Cached RTCP packet. */ 257 pjmedia_rtcp_sr_pkt rtcp_sr_pkt;/**< Cached RTCP packet. */ 258 pjmedia_rtcp_rr_pkt rtcp_rr_pkt;/**< Cached RTCP RR packet. */ 254 259 255 260 pjmedia_rtp_seq_session seq_ctrl; /**< RTCP sequence number control. */ … … 364 369 365 370 /** 366 * Build a RTCP SR+RR packet to be transmitted to remote RTP peer. 371 * Build a RTCP packet to be transmitted to remote RTP peer. This will 372 * create RTCP Sender Report (SR) or Receiver Report (RR) depending on 373 * whether the endpoint has been transmitting RTP since the last interval. 367 374 * Note that this function will reset the interval counters (such as 368 375 * the ones to calculate fraction lost) in the session. … … 370 377 * @param session The RTCP session. 371 378 * @param rtcp_pkt Upon return, it will contain pointer to the 372 * RTCP packet .379 * RTCP packet, which can be RTCP SR or RR. 373 380 * @param len Upon return, it will indicate the size of 374 381 * the RTCP packet. 375 382 */ 376 383 PJ_DECL(void) pjmedia_rtcp_build_rtcp( pjmedia_rtcp_session *session, 377 pjmedia_rtcp_pkt **rtcp_pkt, 378 int *len); 384 void **rtcp_pkt, int *len); 379 385 380 386 -
pjproject/trunk/pjmedia/src/pjmedia/rtcp.c
r1266 r1444 131 131 pj_uint32_t ssrc) 132 132 { 133 pjmedia_rtcp_ pkt *rtcp_pkt = &sess->rtcp_pkt;133 pjmedia_rtcp_sr_pkt *sr_pkt = &sess->rtcp_sr_pkt; 134 134 pj_time_val now; 135 135 … … 147 147 sess->pkt_size = samples_per_frame; 148 148 149 /* Init common RTCP header */ 150 rtcp_pkt->common.version = 2; 151 rtcp_pkt->common.count = 1; 152 rtcp_pkt->common.pt = RTCP_SR; 153 rtcp_pkt->common.length = pj_htons(12); 154 155 /* Init SR */ 156 rtcp_pkt->sr.ssrc = pj_htonl(ssrc); 157 149 /* Init common RTCP SR header */ 150 sr_pkt->common.version = 2; 151 sr_pkt->common.count = 1; 152 sr_pkt->common.pt = RTCP_SR; 153 sr_pkt->common.length = pj_htons(12); 154 sr_pkt->common.ssrc = pj_htonl(ssrc); 155 156 /* Copy to RTCP RR header */ 157 pj_memcpy(&sess->rtcp_rr_pkt.common, &sr_pkt->common, 158 sizeof(pjmedia_rtcp_common)); 159 sess->rtcp_rr_pkt.common.pt = RTCP_RR; 160 sess->rtcp_rr_pkt.common.length = pj_htons(7); 161 158 162 /* Get time and timestamp base and frequency */ 159 163 pj_gettimeofday(&now); … … 341 345 if (common->pt == RTCP_SR) { 342 346 sr = (pjmedia_rtcp_sr*) (((char*)pkt) + sizeof(pjmedia_rtcp_common)); 343 if (common->count > 0 && size >= (sizeof(pjmedia_rtcp_ pkt))) {347 if (common->count > 0 && size >= (sizeof(pjmedia_rtcp_sr_pkt))) { 344 348 rr = (pjmedia_rtcp_rr*)(((char*)pkt) + (sizeof(pjmedia_rtcp_common) 345 349 + sizeof(pjmedia_rtcp_sr))); … … 530 534 531 535 PJ_DEF(void) pjmedia_rtcp_build_rtcp(pjmedia_rtcp_session *sess, 532 pjmedia_rtcp_pkt **ret_p_pkt, 533 int *len) 536 void **ret_p_pkt, int *len) 534 537 { 535 538 pj_uint32_t expected, expected_interval, received_interval, lost_interval; 536 pjmedia_rtcp_pkt *rtcp_pkt = &sess->rtcp_pkt; 539 pjmedia_rtcp_common *common; 540 pjmedia_rtcp_sr *sr; 541 pjmedia_rtcp_rr *rr; 537 542 pj_timestamp ts_now; 538 543 pjmedia_rtcp_ntp_rec ntp; 539 540 /* Packet count */ 541 rtcp_pkt->sr.sender_pcount = pj_htonl(sess->stat.tx.pkt); 542 543 /* Octets count */ 544 rtcp_pkt->sr.sender_bcount = pj_htonl(sess->stat.tx.bytes); 544 545 /* Get current NTP time. */ 546 pj_get_timestamp(&ts_now); 547 pjmedia_rtcp_get_ntp_time(sess, &ntp); 548 549 550 /* See if we have transmitted RTP packets since last time we 551 * sent RTCP SR. 552 */ 553 if (sess->stat.tx.pkt != pj_ntohl(sess->rtcp_sr_pkt.sr.sender_pcount)) { 554 555 /* So we should send RTCP SR */ 556 *ret_p_pkt = (void*) &sess->rtcp_sr_pkt; 557 *len = sizeof(pjmedia_rtcp_sr_pkt); 558 common = &sess->rtcp_sr_pkt.common; 559 rr = &sess->rtcp_sr_pkt.rr; 560 sr = &sess->rtcp_sr_pkt.sr; 561 562 /* Update packet count */ 563 sr->sender_pcount = pj_htonl(sess->stat.tx.pkt); 564 565 /* Update octets count */ 566 sr->sender_bcount = pj_htonl(sess->stat.tx.bytes); 567 568 /* Fill in NTP timestamp in SR. */ 569 sr->ntp_sec = pj_htonl(ntp.hi); 570 sr->ntp_frac = pj_htonl(ntp.lo); 571 572 TRACE_((sess->name, "TX RTCP SR: ntp_ts=%p", 573 ((ntp.hi & 0xFFFF) << 16) + ((ntp.lo & 0xFFFF0000) 574 >> 16))); 575 576 577 } else { 578 /* We should send RTCP RR then */ 579 *ret_p_pkt = (void*) &sess->rtcp_rr_pkt; 580 *len = sizeof(pjmedia_rtcp_rr_pkt); 581 common = &sess->rtcp_rr_pkt.common; 582 rr = &sess->rtcp_rr_pkt.rr; 583 sr = NULL; 584 } 545 585 546 586 /* SSRC and last_seq */ 547 rtcp_pkt->rr.ssrc = pj_htonl(sess->peer_ssrc); 548 rtcp_pkt->rr.last_seq = (sess->seq_ctrl.cycles & 0xFFFF0000L); 549 rtcp_pkt->rr.last_seq += sess->seq_ctrl.max_seq; 550 rtcp_pkt->rr.last_seq = pj_htonl(rtcp_pkt->rr.last_seq); 587 rr->ssrc = pj_htonl(sess->peer_ssrc); 588 rr->last_seq = (sess->seq_ctrl.cycles & 0xFFFF0000L); 589 /* Since this is an "+=" operation, make sure we update last_seq on 590 * both RR and SR. 591 */ 592 sess->rtcp_sr_pkt.rr.last_seq += sess->seq_ctrl.max_seq; 593 sess->rtcp_rr_pkt.rr.last_seq += sess->seq_ctrl.max_seq; 594 rr->last_seq = pj_htonl(rr->last_seq); 551 595 552 596 553 597 /* Jitter */ 554 r tcp_pkt->rr.jitter = pj_htonl(sess->jitter >> 4);598 rr->jitter = pj_htonl(sess->jitter >> 4); 555 599 556 600 557 601 /* Total lost. */ 558 expected = pj_ntohl(r tcp_pkt->rr.last_seq) - sess->seq_ctrl.base_seq;602 expected = pj_ntohl(rr->last_seq) - sess->seq_ctrl.base_seq; 559 603 560 604 /* This is bug: total lost already calculated on each incoming RTP! … … 565 609 */ 566 610 567 r tcp_pkt->rr.total_lost_2 = (sess->stat.rx.loss >> 16) & 0xFF;568 r tcp_pkt->rr.total_lost_1 = (sess->stat.rx.loss >> 8) & 0xFF;569 r tcp_pkt->rr.total_lost_0 = (sess->stat.rx.loss & 0xFF);611 rr->total_lost_2 = (sess->stat.rx.loss >> 16) & 0xFF; 612 rr->total_lost_1 = (sess->stat.rx.loss >> 8) & 0xFF; 613 rr->total_lost_0 = (sess->stat.rx.loss & 0xFF); 570 614 571 615 /* Fraction lost calculation */ … … 579 623 580 624 if (expected_interval==0 || lost_interval == 0) { 581 r tcp_pkt->rr.fract_lost = 0;625 rr->fract_lost = 0; 582 626 } else { 583 rtcp_pkt->rr.fract_lost = (lost_interval << 8) / expected_interval; 584 } 585 586 /* Get current NTP time. */ 587 pj_get_timestamp(&ts_now); 588 pjmedia_rtcp_get_ntp_time(sess, &ntp); 589 590 /* Fill in NTP timestamp in SR. */ 591 rtcp_pkt->sr.ntp_sec = pj_htonl(ntp.hi); 592 rtcp_pkt->sr.ntp_frac = pj_htonl(ntp.lo); 593 594 TRACE_((sess->name, "TX RTCP SR: ntp_ts=%p", 595 ((ntp.hi & 0xFFFF) << 16) + ((ntp.lo & 0xFFFF0000) 596 >> 16))); 597 627 rr->fract_lost = (lost_interval << 8) / expected_interval; 628 } 629 598 630 if (sess->rx_lsr_time.u64 == 0 || sess->rx_lsr == 0) { 599 r tcp_pkt->rr.lsr = 0;600 r tcp_pkt->rr.dlsr = 0;631 rr->lsr = 0; 632 rr->dlsr = 0; 601 633 } else { 602 634 pj_timestamp ts; … … 611 643 LSR is the middle 32bit of the last SR NTP time received. 612 644 */ 613 r tcp_pkt->rr.lsr = pj_htonl(lsr);645 rr->lsr = pj_htonl(lsr); 614 646 615 647 /* Fill in DLSR. … … 623 655 /* Get DLSR */ 624 656 dlsr = (pj_uint32_t)(ts.u64 - lsr_time); 625 r tcp_pkt->rr.dlsr = pj_htonl(dlsr);657 rr->dlsr = pj_htonl(dlsr); 626 658 627 659 TRACE_((sess->name,"Tx RTCP RR: lsr=%p, lsr_time=%p, now=%p, dlsr=%p" … … 638 670 pj_gettimeofday(&sess->stat.rx.update); 639 671 sess->stat.rx.update_cnt++; 640 641 642 /* Return pointer. */643 *ret_p_pkt = rtcp_pkt;644 *len = sizeof(pjmedia_rtcp_pkt);645 672 } 646 673 -
pjproject/trunk/pjmedia/src/pjmedia/stream.c
r1416 r1444 440 440 } else if (timestamp - stream->rtcp_last_tx >= stream->rtcp_interval) { 441 441 442 pjmedia_rtcp_pkt*rtcp_pkt;442 void *rtcp_pkt; 443 443 int len; 444 444 -
pjproject/trunk/pjsip-apps/src/samples/siprtp.c
r1405 r1444 1343 1343 * Time to send RTCP packet. 1344 1344 */ 1345 pjmedia_rtcp_pkt*rtcp_pkt;1345 void *rtcp_pkt; 1346 1346 int rtcp_len; 1347 1347 pj_ssize_t size;
Note: See TracChangeset
for help on using the changeset viewer.