📄 rtcp-packet.c
字号:
+ rtcp_packet_get_length(packet)); rtp_source *source; sd = (Rtcp_SDES_Header) rtcp_packet_get_content(packet); while (--count >= 0) { rsp = &sd -> item[0]; if (rsp >= end) break; source = find_member(g_ntohl(sd -> src)); while (rsp -> type != RTCP_SDES_END) { member_sdes(source, rsp -> type, rsp -> data, rsp -> length); rsp = (SDES_Item) ((gint8 *) rsp + rsp -> length + 2); if (rsp >= end) { break; } } sd = (Rtcp_SDES_Header) ((guint32 *) sd + (((gint8 *) rsp - (gint8 *) sd) / 4) + 1); } if (count >= 0) { g_warning("Trouble parsing an RTCP SDES packet."); }}voidrtcp_compound_add_sr(Rtcp_Compound compound, guint32 ssrc, guint32 timestamp, guint32 packets_sent, guint32 octets_sent){ Rtcp_Packet packet; Rtcp_SR_Header header; struct timeval now; g_return_if_fail(compound != NULL); g_return_if_fail(compound -> max_len - compound -> data_len > sizeof (struct Rtcp_Common_Header) + 24); packet = rtcp_packet_new(); packet -> data = (gint8 *) compound -> data + rtcp_compound_get_length(compound); rtcp_packet_set_version(packet, RTP_VERSION); rtcp_packet_set_padding(packet, 0); rtcp_packet_set_count(packet, 0); /* FIX */ rtcp_packet_set_packet_type(packet, RTCP_SR); rtcp_packet_set_content_length(packet, 24); /* FIX */ header = (Rtcp_SR_Header) rtcp_packet_get_content(packet); header -> ssrc = g_htonl(ssrc); if (gettimeofday(&now, 0) < 0) { gphone_perror_exit("*** send_rtcp_sr : gettimeofday", 1); } header -> ntp_sec = g_htonl((guint32) now.tv_sec); header -> ntp_frac = g_htonl((guint32) now.tv_usec * 1.0e6); header -> rtp_ts = g_htonl(timestamp); header -> psent = g_htonl(packets_sent); header -> osent = g_htonl(octets_sent); rtcp_compound_set_length(compound, rtcp_compound_get_length(compound) + rtcp_packet_get_length(packet)); rtcp_packet_free(packet);}voidrtcp_compound_add_sdes(Rtcp_Compound compound, guint32 ssrc, guint nsdes, Rtcp_Sdes_Type type[], char *value[], gint8 length[]){ Rtcp_Packet packet; Rtcp_SDES_Header header; SDES_Item item; int i; int pad; gint8 *padloc; g_return_if_fail(compound != NULL); /* FIX: should check if there's space left in the compound here */ packet = rtcp_packet_new(); packet -> data = (gint8 *) compound -> data + rtcp_compound_get_length(compound); rtcp_packet_set_version(packet, RTP_VERSION); rtcp_packet_set_padding(packet, 0); rtcp_packet_set_count(packet, nsdes); rtcp_packet_set_packet_type(packet, RTCP_SDES); header = (Rtcp_SDES_Header) rtcp_packet_get_content(packet); header -> src = g_htonl(ssrc); item = &header -> item[0]; for (i = 0; i < nsdes; i++) { item -> type = type[i]; item -> length = length[i]; g_memmove(item -> data, value[i], length[i]); item = (SDES_Item) &item -> data[length[i]]; } padloc = (gint8 *) item; for (pad = 4 - ((gint8 *) item - (gint8 *) header) % 4; pad > 0; pad--) { *padloc++ = RTCP_SDES_END; } rtcp_packet_set_content_length(packet, padloc - (gint8 *) header); rtcp_compound_set_length(compound, rtcp_compound_get_length(compound) + rtcp_packet_get_length(packet)); rtcp_packet_free(packet);}voidrtcp_compound_add_app(Rtcp_Compound compound, guint32 ssrc, const gchar name[4], gpointer data, guint data_len){ Rtcp_Packet packet; Rtcp_APP_Header header; int padlen; int i; g_return_if_fail(compound != NULL); padlen = 4 - data_len % 4; g_return_if_fail(compound -> max_len - compound -> data_len > sizeof (struct Rtcp_Common_Header) + 4 + data_len + padlen); packet = rtcp_packet_new(); packet -> data = (gint8 *) compound -> data + rtcp_compound_get_length(compound); rtcp_packet_set_version(packet, RTP_VERSION); rtcp_packet_set_padding(packet, 0); rtcp_packet_set_count(packet, 0); rtcp_packet_set_packet_type(packet, RTCP_APP); rtcp_packet_set_content_length(packet, 4 + data_len + padlen); header = (Rtcp_APP_Header) rtcp_packet_get_content(packet); header -> ssrc = g_htonl(ssrc); for (i = 0; i < 4; i++) { header -> name[i] = name[i]; } g_memmove(header -> data, data, data_len); for (i = 0; i < padlen; i++) { header -> data[data_len + i] = 0; } rtcp_compound_set_length(compound, rtcp_compound_get_length(compound) + rtcp_packet_get_length(packet)); rtcp_packet_free(packet);}/* Functions for getting and setting packet fields*/guint16rtcp_compound_get_length(Rtcp_Compound compound){ g_return_val_if_fail(compound != NULL, 0); return compound -> data_len;}voidrtcp_compound_set_length(Rtcp_Compound compound, guint16 len){ g_return_if_fail(compound != NULL); compound -> data_len = len;}guint8rtcp_packet_get_version(Rtcp_Packet packet){ g_return_val_if_fail(packet != NULL, 0); return ((Rtcp_Common_Header) packet -> data) -> version;}voidrtcp_packet_set_version(Rtcp_Packet packet, guint8 version){ g_return_if_fail(packet != NULL); g_return_if_fail(version < 0x04); ((Rtcp_Common_Header) packet -> data) -> version = version;}guint8rtcp_packet_get_padding(Rtcp_Packet packet){ g_return_val_if_fail(packet != NULL, 0); return ((Rtcp_Common_Header) packet -> data) -> padding;}voidrtcp_packet_set_padding(Rtcp_Packet packet, guint8 padding){ g_return_if_fail(packet != NULL); g_return_if_fail(padding < 0x02); ((Rtcp_Common_Header) packet -> data) -> padding = padding;}guint8rtcp_packet_get_count(Rtcp_Packet packet){ g_return_val_if_fail(packet != NULL, 0); return ((Rtcp_Common_Header) packet -> data) -> count;}voidrtcp_packet_set_count(Rtcp_Packet packet, guint8 count){ g_return_if_fail(packet != NULL); g_return_if_fail(count < 0x20); ((Rtcp_Common_Header) packet -> data) -> count = count;}guint8rtcp_packet_get_packet_type(Rtcp_Packet packet){ g_return_val_if_fail(packet != NULL, 0); return ((Rtcp_Common_Header) packet -> data) -> packet_type;}voidrtcp_packet_set_packet_type(Rtcp_Packet packet, guint8 packet_type){ g_return_if_fail(packet != NULL); ((Rtcp_Common_Header) packet -> data) -> packet_type = packet_type;}guint16rtcp_packet_get_length(Rtcp_Packet packet){ g_return_val_if_fail(packet != NULL, 0); return 4 + 4 * g_ntohs(((Rtcp_Common_Header) packet -> data) -> length);}voidrtcp_packet_set_content_length(Rtcp_Packet packet, guint16 length){ g_return_if_fail(packet != NULL); g_assert(length % 4 == 0); ((Rtcp_Common_Header) packet -> data) -> length = g_htons(length / 4);}gpointerrtcp_packet_get_data(Rtcp_Packet packet){ g_return_val_if_fail(packet != NULL, NULL); return packet -> data;}gpointerrtcp_packet_get_content(Rtcp_Packet packet){ g_return_val_if_fail(packet != NULL, NULL); return (gint8 *) packet -> data + sizeof (struct Rtcp_Common_Header);}gchar *rtcp_app_packet_get_name(Rtcp_Packet packet){ g_return_val_if_fail(packet != NULL, NULL); g_return_val_if_fail(rtcp_packet_get_packet_type(packet) == RTCP_APP, NULL); return (gchar *) &((Rtcp_APP_Header) rtcp_packet_get_content(packet)) -> name;}gpointerrtcp_app_packet_get_data(Rtcp_Packet packet){ g_return_val_if_fail(packet != NULL, NULL); g_return_val_if_fail(rtcp_packet_get_packet_type(packet) == RTCP_APP, NULL); return (gchar *) &((Rtcp_APP_Header) rtcp_packet_get_content(packet)) -> data;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -