rtcpparse.c 18.7 KB
Newer Older
aymeric's avatar
aymeric committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
  The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
  Copyright (C) 2001  Simon MORLAT simon.morlat@linphone.org

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/


#include "ortp/ortp.h"
#include "utils.h"

Simon Morlat's avatar
Simon Morlat committed
24 25 26 27 28
static int rtcp_get_size(const mblk_t *m){
	const rtcp_common_header_t *ch=rtcp_get_common_header(m);
	if (ch==NULL) return -1;
	return (1+rtcp_common_header_get_length(ch))*4;
}
aymeric's avatar
aymeric committed
29 30 31 32

/*in case of coumpound packet, set read pointer of m to the beginning of the next RTCP
packet */
bool_t rtcp_next_packet(mblk_t *m){
Simon Morlat's avatar
Simon Morlat committed
33 34
	int nextlen=rtcp_get_size(m);
	if (nextlen>=0){
aymeric's avatar
aymeric committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
		if (m->b_rptr+nextlen<m->b_wptr){
			m->b_rptr+=nextlen;
			return TRUE;
		}
	}
	return FALSE;
}

void rtcp_rewind(mblk_t *m){
	m->b_rptr=m->b_datap->db_base;
}

/* get common header; this function will also check the sanity of the packet*/
const rtcp_common_header_t * rtcp_get_common_header(const mblk_t *m){
	int size=msgdsize(m);
	rtcp_common_header_t *ch;
	if (m->b_cont!=NULL){
		ortp_fatal("RTCP parser does not work on fragmented mblk_t. Use msgpullup() before to re-assemble the packet.");
		return NULL;
	}
	if (size<sizeof(rtcp_common_header_t)){
		ortp_warning("Bad RTCP packet, too short.");
		return NULL;
	}
	ch=(rtcp_common_header_t*)m->b_rptr;
	return ch;
}

bool_t rtcp_is_SR(const mblk_t *m){
	const rtcp_common_header_t *ch=rtcp_get_common_header(m);
	if (ch!=NULL && rtcp_common_header_get_packet_type(ch)==RTCP_SR){
66
		if (msgdsize(m)<(sizeof(rtcp_sr_t)-sizeof(report_block_t))){
aymeric's avatar
aymeric committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
			ortp_warning("Too short RTCP SR packet.");
			return FALSE;
		}
		return TRUE;
	}
	return FALSE;
}

/*Sender Report accessors */
uint32_t rtcp_SR_get_ssrc(const mblk_t *m){
	rtcp_sr_t *sr=(rtcp_sr_t*)m->b_rptr;
	return ntohl(sr->ssrc);
}

const sender_info_t * rtcp_SR_get_sender_info(const mblk_t *m){
	rtcp_sr_t *sr=(rtcp_sr_t*)m->b_rptr;
	return &sr->si;
}

const report_block_t * rtcp_SR_get_report_block(const mblk_t *m, int idx){
	rtcp_sr_t *sr=(rtcp_sr_t*)m->b_rptr;
	report_block_t *rb=&sr->rb[idx];
Simon Morlat's avatar
Simon Morlat committed
89
	int size=rtcp_get_size(m);
aymeric's avatar
aymeric committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
	if ( ( (uint8_t*)rb)+sizeof(report_block_t) <= m->b_rptr + size ) {
		return rb;
	}else{
		if (idx<rtcp_common_header_get_rc(&sr->ch)){
			ortp_warning("RTCP packet should include a report_block_t at pos %i but has no space for it.",idx);
		}
	}
	return NULL;
}

/*Receiver report accessors*/
bool_t rtcp_is_RR(const mblk_t *m){
	const rtcp_common_header_t *ch=rtcp_get_common_header(m);
	if (ch!=NULL && rtcp_common_header_get_packet_type(ch)==RTCP_RR){
		if (msgdsize(m)<sizeof(rtcp_rr_t)){
			ortp_warning("Too short RTCP RR packet.");
			return FALSE;
		}
		return TRUE;
	}
	return FALSE;
}

uint32_t rtcp_RR_get_ssrc(const mblk_t *m){
	rtcp_rr_t *rr=(rtcp_rr_t*)m->b_rptr;
	return ntohl(rr->ssrc);
}

const report_block_t * rtcp_RR_get_report_block(const mblk_t *m,int idx){
	rtcp_rr_t *rr=(rtcp_rr_t*)m->b_rptr;
	report_block_t *rb=&rr->rb[idx];
Simon Morlat's avatar
Simon Morlat committed
121
	int size=rtcp_get_size(m);
aymeric's avatar
aymeric committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135
	if ( ( (uint8_t*)rb)+sizeof(report_block_t) <= (m->b_rptr + size ) ){
		return rb;
	}else{
		if (idx<rtcp_common_header_get_rc(&rr->ch)){
			ortp_warning("RTCP packet should include a report_block_t at pos %i but has no space for it.",idx);
		}
	}
	return NULL;
}

/*SDES accessors */
bool_t rtcp_is_SDES(const mblk_t *m){
	const rtcp_common_header_t *ch=rtcp_get_common_header(m);
	if (ch && rtcp_common_header_get_packet_type(ch)==RTCP_SDES){
Simon Morlat's avatar
Simon Morlat committed
136
		if (msgdsize(m)<rtcp_get_size(m)){
aymeric's avatar
aymeric committed
137 138 139 140 141 142 143 144 145 146 147
			ortp_warning("Too short RTCP SDES packet.");
			return FALSE;
		}
		return TRUE;
	}
	return FALSE;
}

void rtcp_sdes_parse(const mblk_t *m, SdesItemFoundCallback cb, void *user_data){
	uint8_t *rptr=(uint8_t*)m->b_rptr+sizeof(rtcp_common_header_t);
	const rtcp_common_header_t *ch=(rtcp_common_header_t*)m->b_rptr;
Simon Morlat's avatar
Simon Morlat committed
148
	uint8_t *end=rptr+(4*(rtcp_common_header_get_length(ch)+1));
aymeric's avatar
aymeric committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
	uint32_t ssrc=0;
	int nchunk=0;
	bool_t chunk_start=TRUE;

	if (end>(uint8_t*)m->b_wptr) end=(uint8_t*)m->b_wptr;

	while(rptr<end){
		if (chunk_start){
			if (rptr+4<=end){
				ssrc=ntohl(*(uint32_t*)rptr);
				rptr+=4;
			}else{
				ortp_warning("incorrect chunk start in RTCP SDES");
				break;
			}
			chunk_start=FALSE;
		}else{
			if (rptr+2<=end){
				uint8_t type=rptr[0];
				uint8_t len=rptr[1];

				if (type==RTCP_SDES_END){
					/* pad to next 32bit boundary*/
					rptr=(uint8_t*)(((unsigned long)rptr+4) & ~0x3);
					nchunk++;
					if (nchunk<rtcp_common_header_get_rc(ch)){
						chunk_start=TRUE;
						continue;
					}else break;
				}
				rptr+=2;
				if (rptr+len<=end){
					cb(user_data,ssrc,type,(char*)rptr,len);
					rptr+=len;
				}else{
					ortp_warning("bad item length in RTCP SDES");
					break;
				}
			}else{
				/*end of packet */
				break;
			}
		}
	}
}

/*BYE accessors */
bool_t rtcp_is_BYE(const mblk_t *m){
	const rtcp_common_header_t *ch=rtcp_get_common_header(m);
	if (ch && rtcp_common_header_get_packet_type(ch)==RTCP_BYE){
Simon Morlat's avatar
Simon Morlat committed
199
		if (msgdsize(m)<rtcp_get_size(m)){
aymeric's avatar
aymeric committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
			ortp_warning("Too short RTCP BYE packet.");
			return FALSE;
		}
		return TRUE;
	}
	return FALSE;
}

bool_t rtcp_BYE_get_ssrc(const mblk_t *m, int idx, uint32_t *ssrc){
	rtcp_bye_t *bye=(rtcp_bye_t*)m->b_rptr;
	int rc=rtcp_common_header_get_rc(&bye->ch);
	int len=rtcp_common_header_get_length(&bye->ch);
	if (idx<rc){
		if ((uint8_t*)&bye->ssrc[idx]<=(m->b_rptr
				+sizeof(rtcp_common_header_t)+len-4)) {
			*ssrc=ntohl(bye->ssrc[idx]);
			return TRUE;
		}else{
218
			ortp_warning("RTCP BYE should contain %i ssrc, but there is not enough room for it.",rc);
aymeric's avatar
aymeric committed
219 220 221 222 223 224 225 226 227
		}
	}
	return FALSE;
}

bool_t rtcp_BYE_get_reason(const mblk_t *m, const char **reason, int *reason_len){
	rtcp_bye_t *bye=(rtcp_bye_t*)m->b_rptr;
	int rc=rtcp_common_header_get_rc(&bye->ch);
	uint8_t *rptr=(uint8_t*)m->b_rptr+sizeof(rtcp_common_header_t)+rc*4;
Simon Morlat's avatar
Simon Morlat committed
228
	uint8_t *end=(uint8_t*)(m->b_rptr+rtcp_get_size(m));
aymeric's avatar
aymeric committed
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
	if (rptr<end){
		uint8_t content_len=rptr[0];
		if (rptr+1+content_len<=end){
			*reason=(char*)rptr+1;
			*reason_len=content_len;
			return TRUE;
		}else{
			ortp_warning("RTCP BYE has not enough space for reason phrase.");
			return FALSE;
		}
	}
	return FALSE;
}

/*APP accessors */
bool_t rtcp_is_APP(const mblk_t *m){
	const rtcp_common_header_t *ch=rtcp_get_common_header(m);
Simon Morlat's avatar
Simon Morlat committed
246
	int size=rtcp_get_size(m);
aymeric's avatar
aymeric committed
247
	if (ch!=NULL && rtcp_common_header_get_packet_type(ch)==RTCP_APP){
Simon Morlat's avatar
Simon Morlat committed
248
		if (msgdsize(m)<size){
aymeric's avatar
aymeric committed
249 250 251
			ortp_warning("Too short RTCP APP packet.");
			return FALSE;
		}
Simon Morlat's avatar
Simon Morlat committed
252
		if (size < sizeof(rtcp_app_t)){
aymeric's avatar
aymeric committed
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
			ortp_warning("Bad RTCP APP packet.");
			return FALSE;
		}
		return TRUE;
	}
	return FALSE;
}

int rtcp_APP_get_subtype(const mblk_t *m){
	rtcp_app_t *app=(rtcp_app_t*)m->b_rptr;
	return rtcp_common_header_get_rc(&app->ch);
}

uint32_t rtcp_APP_get_ssrc(const mblk_t *m){
	rtcp_app_t *app=(rtcp_app_t*)m->b_rptr;
	return ntohl(app->ssrc);
}
/* name argument is supposed to be at least 4 characters (note: no '\0' written)*/
void rtcp_APP_get_name(const mblk_t *m, char *name){
	rtcp_app_t *app=(rtcp_app_t*)m->b_rptr;
	memcpy(name,app->name,4);
}
/* retrieve the data. when returning, data points directly into the mblk_t */
void rtcp_APP_get_data(const mblk_t *m, uint8_t **data, int *len){
Simon Morlat's avatar
Simon Morlat committed
277
	int datalen=rtcp_get_size(m)-sizeof(rtcp_app_t);
aymeric's avatar
aymeric committed
278 279 280 281 282 283 284 285
	if (datalen>0){
		*data=(uint8_t*)m->b_rptr+sizeof(rtcp_app_t);
		*len=datalen;
	}else{
		*len=0;
		*data=NULL;
	}
}
Ghislain MARY's avatar
Ghislain MARY committed
286 287 288 289 290 291 292 293 294 295 296 297 298 299


/* RTCP XR accessors */
bool_t rtcp_is_XR(const mblk_t *m) {
	const rtcp_common_header_t *ch = rtcp_get_common_header(m);
	if ((ch != NULL) && (rtcp_common_header_get_packet_type(ch) == RTCP_XR)) {
		if (msgdsize(m) < MIN_RTCP_XR_PACKET_SIZE) {
			ortp_warning("Too short RTCP XR packet.");
			return FALSE;
		}
		return TRUE;
	}
	return FALSE;
}
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508

rtcp_xr_block_type_t rtcp_XR_get_block_type(const mblk_t *m) {
	rtcp_xr_generic_block_header_t *bh = (rtcp_xr_generic_block_header_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return bh->bt;
}

uint32_t rtcp_XR_get_ssrc(const mblk_t *m) {
	rtcp_xr_header_t *xh = (rtcp_xr_header_t *)m->b_rptr;
	return ntohl(xh->ssrc);
}

uint64_t rtcp_XR_rcvr_rtt_get_ntp_timestamp(const mblk_t *m) {
	uint64_t ts = 0;
	rtcp_xr_rcvr_rtt_report_block_t *b = (rtcp_xr_rcvr_rtt_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	ts = ntohl(b->ntp_timestamp_msw);
	ts <<= 32;
	ts |= ntohl(b->ntp_timestamp_lsw);
	return ts;
}

uint32_t rtcp_XR_dlrr_get_ssrc(const mblk_t *m) {
	rtcp_xr_dlrr_report_subblock_t *b = (rtcp_xr_dlrr_report_subblock_t *)(m->b_rptr + sizeof(rtcp_xr_header_t) + sizeof(rtcp_xr_generic_block_header_t));
	return ntohl(b->ssrc);
}

uint32_t rtcp_XR_dlrr_get_lrr(const mblk_t *m) {
	rtcp_xr_dlrr_report_subblock_t *b = (rtcp_xr_dlrr_report_subblock_t *)(m->b_rptr + sizeof(rtcp_xr_header_t) + sizeof(rtcp_xr_generic_block_header_t));
	return ntohl(b->lrr);
}

uint32_t rtcp_XR_dlrr_get_dlrr(const mblk_t *m) {
	rtcp_xr_dlrr_report_subblock_t *b = (rtcp_xr_dlrr_report_subblock_t *)(m->b_rptr + sizeof(rtcp_xr_header_t) + sizeof(rtcp_xr_generic_block_header_t));
	return ntohl(b->dlrr);
}

uint8_t rtcp_XR_stat_summary_get_flags(const mblk_t *m) {
	rtcp_xr_generic_block_header_t *bh = (rtcp_xr_generic_block_header_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return bh->flags;
}

uint32_t rtcp_XR_stat_summary_get_ssrc(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohl(b->ssrc);
}

uint16_t rtcp_XR_stat_summary_get_begin_seq(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohs(b->begin_seq);
}

uint16_t rtcp_XR_stat_summary_get_end_seq(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohs(b->end_seq);
}

uint32_t rtcp_XR_stat_summary_get_lost_packets(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohl(b->lost_packets);
}

uint32_t rtcp_XR_stat_summary_get_dup_packets(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohl(b->dup_packets);
}

uint32_t rtcp_XR_stat_summary_get_min_jitter(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohl(b->min_jitter);
}

uint32_t rtcp_XR_stat_summary_get_max_jitter(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohl(b->max_jitter);
}

uint32_t rtcp_XR_stat_summary_get_mean_jitter(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohl(b->mean_jitter);
}

uint32_t rtcp_XR_stat_summary_get_dev_jitter(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohl(b->dev_jitter);
}

uint8_t rtcp_XR_stat_summary_get_min_ttl_or_hl(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->min_ttl_or_hl;
}

uint8_t rtcp_XR_stat_summary_get_max_ttl_or_hl(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->max_ttl_or_hl;
}

uint8_t rtcp_XR_stat_summary_get_mean_ttl_or_hl(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->mean_ttl_or_hl;
}

uint8_t rtcp_XR_stat_summary_get_dev_ttl_or_hl(const mblk_t *m) {
	rtcp_xr_stat_summary_report_block_t *b = (rtcp_xr_stat_summary_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->dev_ttl_or_hl;
}

uint32_t rtcp_XR_voip_metrics_get_ssrc(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohl(b->ssrc);
}

uint8_t rtcp_XR_voip_metrics_get_loss_rate(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->loss_rate;
}

uint8_t rtcp_XR_voip_metrics_get_discard_rate(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->discard_rate;
}

uint8_t rtcp_XR_voip_metrics_get_burst_density(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->burst_density;
}

uint8_t rtcp_XR_voip_metrics_get_gap_density(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->gap_density;
}

uint16_t rtcp_XR_voip_metrics_get_burst_duration(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohs(b->burst_duration);
}

uint16_t rtcp_XR_voip_metrics_get_gap_duration(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohs(b->gap_duration);
}

uint16_t rtcp_XR_voip_metrics_get_round_trip_delay(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohs(b->round_trip_delay);
}

uint16_t rtcp_XR_voip_metrics_get_end_system_delay(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohs(b->end_system_delay);
}

uint8_t rtcp_XR_voip_metrics_get_signal_level(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->signal_level;
}

uint8_t rtcp_XR_voip_metrics_get_noise_level(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->noise_level;
}

uint8_t rtcp_XR_voip_metrics_get_rerl(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->rerl;
}

uint8_t rtcp_XR_voip_metrics_get_gmin(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->gmin;
}

uint8_t rtcp_XR_voip_metrics_get_r_factor(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->r_factor;
}

uint8_t rtcp_XR_voip_metrics_get_ext_r_factor(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->ext_r_factor;
}

uint8_t rtcp_XR_voip_metrics_get_mos_lq(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->mos_lq;
}

uint8_t rtcp_XR_voip_metrics_get_mos_cq(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->mos_cq;
}

uint8_t rtcp_XR_voip_metrics_get_rx_config(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return b->rx_config;
}

uint16_t rtcp_XR_voip_metrics_get_jb_nominal(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohs(b->jb_nominal);
}

uint16_t rtcp_XR_voip_metrics_get_jb_maximum(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohs(b->jb_maximum);
}

uint16_t rtcp_XR_voip_metrics_get_jb_abs_max(const mblk_t *m) {
	rtcp_xr_voip_metrics_report_block_t *b = (rtcp_xr_voip_metrics_report_block_t *)(m->b_rptr + sizeof(rtcp_xr_header_t));
	return ntohs(b->jb_abs_max);
}
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540


/* RTCP PSFB accessors */
bool_t rtcp_is_PSFB(const mblk_t *m) {
	const rtcp_common_header_t *ch = rtcp_get_common_header(m);
	if ((ch != NULL) && (rtcp_common_header_get_packet_type(ch) == RTCP_PSFB)) {
		if (msgdsize(m) < MIN_RTCP_PSFB_PACKET_SIZE) {
			ortp_warning("Too short RTCP PSFB packet.");
			return FALSE;
		}
		return TRUE;
	}
	return FALSE;
}

rtcp_psfb_type_t rtcp_PSFB_get_type(const mblk_t *m) {
	rtcp_common_header_t *ch = (rtcp_common_header_t *)m->b_rptr;
	return (rtcp_psfb_type_t)rtcp_common_header_get_rc(ch);
}

uint32_t rtcp_PSFB_get_packet_sender_ssrc(const mblk_t *m) {
	rtcp_fb_header_t *fbh = (rtcp_fb_header_t *)(m->b_rptr + sizeof(rtcp_common_header_t));
	return ntohl(fbh->packet_sender_ssrc);
}

uint32_t rtcp_PSFB_get_media_source_ssrc(const mblk_t *m) {
	rtcp_fb_header_t *fbh = (rtcp_fb_header_t *)(m->b_rptr + sizeof(rtcp_common_header_t));
	return ntohl(fbh->media_source_ssrc);
}

rtcp_fb_fir_fci_t * rtcp_PSFB_fir_get_fci(const mblk_t *m, unsigned int idx) {
	unsigned int size = sizeof(rtcp_common_header_t) + sizeof(rtcp_fb_header_t) + ((idx + 1) * sizeof(rtcp_fb_fir_fci_t));
541 542
	unsigned int rtcp_size = rtcp_get_size(m);
	if (size > rtcp_size) {
543 544 545 546 547
		return NULL;
	}
	return (rtcp_fb_fir_fci_t *)(m->b_rptr + size - sizeof(rtcp_fb_fir_fci_t));
}

548 549 550 551 552 553 554 555 556 557 558
rtcp_fb_sli_fci_t * rtcp_PSFB_sli_get_fci(const mblk_t *m, unsigned int idx) {
	unsigned int size = sizeof(rtcp_common_header_t) + sizeof(rtcp_fb_header_t) + ((idx + 1) * sizeof(rtcp_fb_sli_fci_t));
	unsigned int rtcp_size = rtcp_get_size(m);
	if (size > rtcp_size) {
		return NULL;
	}
	return (rtcp_fb_sli_fci_t *)(m->b_rptr + size - sizeof(rtcp_fb_sli_fci_t));
}

rtcp_fb_rpsi_fci_t * rtcp_PSFB_rpsi_get_fci(const mblk_t *m) {
	return (rtcp_fb_rpsi_fci_t *)(m->b_rptr + sizeof(rtcp_common_header_t) + sizeof(rtcp_fb_header_t));
559 560
}

561 562 563 564
uint16_t rtcp_PSFB_rpsi_get_fci_bit_string_len(const mblk_t *m) {
	rtcp_fb_rpsi_fci_t *fci = rtcp_PSFB_rpsi_get_fci(m);
	uint16_t bit_string_len_in_bytes = rtcp_get_size(m) - (sizeof(rtcp_common_header_t) + sizeof(rtcp_fb_header_t) + 2);
	return ((bit_string_len_in_bytes * 8) - fci->pb);
565
}