metartc5_jz源码阅读-yang_rtcconn_on_rtcp

该代码片段展示了如何在YangRtcSession中处理接收到的加密RTCP数据,包括解密、解析和执行rtcp指令,确保了实时通信的安全性。
摘要由CSDN通过智能技术生成
int32_t yang_rtcconn_on_rtcp(YangRtcSession *session, char *data,int32_t nb_data) {
	int32_t err = Yang_Ok;
	int32_t nb_unprotected_buf = nb_data;

	//根据context.srtp解密data,解密成功后data指向解密后的rtcp数据,nb_unprotected_buf表示要解密的字节数,解密后此字段将保存解密后的字节数。
	if ((err = yang_dec_rtcp(&session->context.srtp, data, &nb_unprotected_buf))!= Yang_Ok) {
		if (err == srtp_err_status_replay_fail)	return Yang_Ok;
		return yang_error_wrap(err, "rtcp unprotect");
	}

	//将解密后的数据放到buffer中。
	char *unprotected_buf = data;
	YangBuffer buffer;
	yang_init_buffer(&buffer, unprotected_buf, nb_unprotected_buf);

	//解析buffer到rtcp_compound的rtcpVector数组中,这里看出buffer中单次可以存放很多YangRtcpCommon。
	if (Yang_Ok != (err = yang_decode_rtcpCompound(&session->rtcp_compound, &buffer))) {
		return yang_error_wrap(err, "decode rtcp plaintext=%u",	nb_unprotected_buf);
	}

	//遍历rtcpVector中的所有YangRtcpCommon对象
	YangRtcpCommon *rtcp = NULL;
	for (int i = 0; i < session->rtcp_compound.rtcpVector.vsize; i++) {
		rtcp = &session->rtcp_compound.rtcpVector.payload[i];
		//执行rtcp相应指令。
		err = yang_rtcconn_dispatch_rtcp(session, rtcp);
		if (Yang_Ok != err) {
			//一旦出错,把rtcpVector中所有rtcp命令清空。
			yang_rtcpCompound_clear(&session->rtcp_compound);
			return yang_error_wrap(err,
					"cipher=%u, plaintext=%u,  rtcp=(%u,%u,%u,%u)", nb_data,
					nb_unprotected_buf, rtcp->nb_data, rtcp->header.rc,
					rtcp->header.type, rtcp->ssrc);
		}
	}
	//所有命令执行完毕后把rtcpVector中所有rtcp命令清空。
	yang_rtcpCompound_clear(&session->rtcp_compound);
	return err;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王方帅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值