/*
Librtp - a library for the RTP/RTCP protocol
Copyright (C) 2000 Roland Dreier
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: rtcp-packet.c,v 1.3 2001/05/07 18:55:05 dreier Exp $
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "rtcp-packet.h"
#include "rtp.h"
#include <glib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <string.h>
#include <errno.h>
struct Rtcp_Packet_Struct {
gpointer data;
guint data_len;
gboolean free_data;
};
struct Rtcp_Compound_Struct {
gpointer data;
guint data_len;
guint max_len;
};
typedef struct Rtcp_Common_Header *Rtcp_Common_Header;
typedef struct Rtcp_RR_Header *Rtcp_RR_Header;
typedef struct Rtcp_SR_Header *Rtcp_SR_Header;
typedef struct Rtcp_SDES_Header *Rtcp_SDES_Header;
typedef struct Rtcp_BYE_Header *Rtcp_BYE_Header;
typedef struct Rtcp_APP_Header *Rtcp_APP_Header;
typedef struct SDES_Item *SDES_Item;
typedef struct Rtcp_RR *Rtcp_RR;
struct Rtcp_Common_Header {
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
unsigned int count:5; /* varies by packet type */
unsigned int padding:1; /* padding flag */
unsigned int version:2; /* protocol version */
#elif G_BYTE_ORDER == G_BIG_ENDIAN
unsigned int version:2; /* protocol version */
unsigned int padding:1; /* padding flag */
unsigned int count:5; /* varies by packet type */
#else
#error "G_BYTE_ORDER should be big or little endian."
#endif
unsigned int packet_type:8; /* RTCP packet type */
guint16 length; /* pkt len in words, w/o this word */
};
struct Rtcp_RR {
guint32 ssrc; /* data source being reported */
unsigned int fraction:8; /* fraction lost since last SR/RR */
int lost:24; /* cumul. no. pkts lost (signed!) */
guint32 last_seq; /* extended last seq. no. received */
guint32 jitter; /* interarrival jitter */
guint32 lsr; /* last SR packet from this source */
guint32 dlsr; /* delay since last SR packet */
};
struct Rtcp_SR_Header {
guint32 ssrc; /* sender generating this report */
guint32 ntp_sec; /* NTP timestamp */
guint32 ntp_frac;
guint32 rtp_ts; /* RTP timestamp */
guint32 psent; /* packets sent */
guint32 osent; /* octets sent */
struct Rtcp_RR rr[1]; /* variable-length list */
};
struct Rtcp_RR_Header {
guint32 ssrc; /* receiver generating this report */
struct Rtcp_RR rr[1]; /* variable-length list */
};
struct SDES_Item {
guint8 type; /* type of item (Rtcp_Sdes_Type) */
guint8 length; /* length of item (in octets) */
gchar data[1]; /* text, not null-terminated */
};
struct Rtcp_SDES_Header {
guint32 src; /* first SSRC/CSRC */
struct SDES_Item item[1]; /* list of SDES items */
};
struct Rtcp_BYE_Header {
guint32 src[1]; /* list of sources */
gchar data[1]; /* reason for leaving */
};
struct Rtcp_APP_Header {
guint32 ssrc; /* source */
gchar name[4]; /* name */
gchar data[1]; /* application data */
};
/*
Functions for allocating and freeing packets
*/
Rtcp_Compound
rtcp_compound_new(void)
{
Rtcp_Compound compound;
compound = g_malloc(sizeof *compound);
compound -> data = NULL;
compound -> data_len = 0;
compound -> max_len = 0;
return compound;
}
Rtcp_Compound
rtcp_compound_new_allocate(guint len)
{
Rtcp_Compound compound;
compound = g_malloc(sizeof *compound);
compound -> max_len = len;
compound -> data_len = 0;
compound -> data = g_malloc(len);
return compound;
}
Rtcp_Compound
rtcp_compound_new_take_data(gpointer data, guint data_len)
{
Rtcp_Compound compound;
g_return_val_if_fail(data_len < RTP_MTU, NULL);
compound = g_malloc(sizeof *compound);
compound -> data = data;
compound -> data_len = data_len;
compound -> max_len = data_len;
return compound;
}
Rtcp_Compound
rtcp_compound_new_copy_data(gpointer data, guint data_len)
{
Rtcp_Compound compound;
g_return_val_if_fail(data_len < RTP_MTU, NULL);
compound = g_malloc(sizeof *compound);
compound -> data = g_memdup(data, data_len);
compound -> data_len = data_len;
compound -> max_len = data_len;
return compound;
}
void
rtcp_compound_free(Rtcp_Compound compound)
{
g_return_if_fail(compound != NULL);
if (compound -> data != NULL) {
g_free(compound -> data);
}
g_free(compound);
}
Rtcp_Compound
rtcp_compound_read(int fd, struct sockaddr *fromaddr, socklen_t *fromlen)
{
int packlen;
gpointer buf;
buf = g_malloc(RTP_MTU);
packlen = recvfrom(fd, buf, RTP_MTU, 0, fromaddr, fromlen);
if (packlen < 0) {
g_error("rtcp_compound_read: recvfrom: %s", strerror(errno));
exit(1);
}
return rtcp_compound_new_take_data(buf, packlen);
}
void
rtcp_compound_send(Rtcp_Compound compound, int fd, struct sockaddr *toaddr, socklen_t tolen)
{
g_return_if_fail(compound != NULL);
sendto(fd, (void *) compound -> data,
compound -> data_len, 0,
toaddr, tolen);
}
Rtcp_Packet
rtcp_packet_new(void)
{
Rtcp_Packet packet;
packet = g_malloc(sizeof *packet);
packet -> free_data = FALSE;
packet -> data = NULL;
packet -> data_len = 0;
return packet;
}
Rtcp_Packet
rtcp_packet_new_take_data(gpointer data, guint data_len)
{
Rtcp_Packet packet;
g_return_val_if_fail(data_len < RTP_MTU, NULL);
packet = g_malloc(sizeof *packet);
packet -> free_data = TRUE;
packet -> data = data;
packet -> data_len = data_len;
return packet;
}
Rtcp_Packet
rtcp_packet_new_copy_data(gpointer data, guint data_len)
{
Rtcp_Packet packet;
g_return_val_if_fail(data_len < RTP_MTU, NULL);
packet = g_malloc(sizeof *packet);
packet -> free_data = TRUE;
packet -> data = g_memdup(data, data_len);
packet -> data_len = data_len;
return packet;
}
void
rtcp_packet_free(Rtcp_Packet packet)
{
g_return_if_fail(packet != NULL);
if (packet -> free_data) {
g_free(packet -> data);
}
g_free(packet);
}
/*
Functions for processing packets
*/
void rtcp_compound_foreach(Rtcp_Compound compound,
Rtcp_Foreach_Func func,
gpointer data)
{
Rtcp_Packet packet;
g_return_if_fail(compound != NULL);
packet = rtcp_packet_new();
packet -> data = compound -> data;
packet -> data_len = rtcp_packet_get_length(packet);
while ((gint8 *) packet -> data
- (gint8 *) compound -> data < compound -> data_len) {
func(packet, data);
packet -> data = (gpointer) ((gint8 *) packet -> data
+ packet -> data_len);
packet -> data_len = rtcp_packet_get_length(packet);
}
rtcp_packet_free(packet);
}
void
rtcp_read_sdes(Rtcp_Packet packet,
Rtcp_Find_Member_Func find_member,
Rtcp_Member_SDES_Func member_sdes)
{
int count = rtcp_packet_get_count(packet);
Rtcp_SDES_Header sd;
SDES_Item rsp;
SDES_Item end = (SDES_Item) ((gint8 *) rtcp_packet_get_data(packet)
+ rtcp_packet_get_length(packet));
Rtp_Source *source;
sd = (Rtcp_SDES_Header
没有合适的资源?快使用搜索试试~ 我知道了~
librtp-0.1.tar.gz
4星 · 超过85%的资源 需积分: 12 158 下载量 27 浏览量
2008-07-29
11:39:38
上传
评论 2
收藏 130KB GZ 举报
温馨提示
共37个文件
in:7个
h:5个
c:5个
librtp-0.1,学习rtp的好东西
资源推荐
资源详情
资源评论
收起资源包目录
librtp-0.1.tar.gz (37个子文件)
librtp-0.1
missing 6KB
ltmain.sh 107KB
COPYING 18KB
aclocal.m4 26KB
INSTALL 8KB
config.h.in 913B
librtp.spec 2KB
include
md5.h 2KB
rtp-packet.h 3KB
Makefile.in 6KB
rtp.h 2KB
rtcp-packet.h 4KB
rtp-audio.h 1KB
Makefile.am 160B
mkinstalldirs 722B
configure 91KB
ChangeLog 1KB
install-sh 5KB
Makefile.in 11KB
TODO 180B
stamp-h.in 10B
librtp.spec.in 2KB
configure.in 609B
ltconfig 92KB
AUTHORS 31B
src
md5c.c 11KB
rtp-packet.c 7KB
Makefile.in 8KB
random.c 2KB
rtp.c 5KB
rtcp-packet.c 16KB
Makefile.am 227B
config.guess 30KB
README 1KB
config.sub 24KB
NEWS 232B
Makefile.am 246B
共 37 条
- 1
overocean
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页