diff options
author | Pablo Neira Ayuso <pablo@gnumonks.org> | 2012-08-06 17:35:26 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-08-06 21:04:21 +0200 |
commit | 33817320cbf6900fcfc08811a2c20cb739a2f398 (patch) | |
tree | 74c2bfd90b0c38d5c81d5e1892a95171f761596a | |
parent | f4b11c071766554b6ac74e8e91fc72cbaf138784 (diff) |
rtp: add osmo_rtp_snprintf
To print the RTP header and payload.
-rw-r--r-- | include/osmocom/netif/rtp.h | 2 | ||||
-rw-r--r-- | src/rtp.c | 40 |
2 files changed, 42 insertions, 0 deletions
diff --git a/include/osmocom/netif/rtp.h b/include/osmocom/netif/rtp.h index 4b290c6..1854d6c 100644 --- a/include/osmocom/netif/rtp.h +++ b/include/osmocom/netif/rtp.h @@ -62,6 +62,8 @@ void *osmo_rtp_get_payload(struct rtp_hdr *rtph, struct msgb *msg, uint32_t *ple struct msgb *osmo_rtp_build(struct osmo_rtp_handle *h, uint8_t payload_type, uint32_t payload_len, const void *data, uint32_t duration); +int osmo_rtp_snprintf(char *buf, size_t size, struct msgb *msg); + /* supported RTP payload types. */ #define RTP_PT_RTCP 72 /* RFC 3551: 72-76 for RTCP */ @@ -184,3 +184,43 @@ osmo_rtp_build(struct osmo_rtp_handle *h, uint8_t payload_type, return msg; } + +#define SNPRINTF_BUFFER_SIZE(ret, size, len, offset) \ + size += ret; \ + if (ret > len) \ + ret = len; \ + offset += ret; \ + len -= ret; + +int osmo_rtp_snprintf(char *buf, size_t size, struct msgb *msg) +{ + struct rtp_hdr *rtph; + int ret, i; + uint8_t *payload; + unsigned int len = size, offset = 0; + + rtph = osmo_rtp_get_hdr(msg); + if (rtph == NULL) + return -1; + + payload = (uint8_t *)rtph + sizeof(struct rtp_hdr); + + ret = snprintf(buf, len, "RTP ver=%01u ssrc=%u type=%02u " + "marker=%01u ext=%01u csrc_count=%01u " + "sequence=%u timestamp=%u [", rtph->version, + ntohl(rtph->ssrc), rtph->payload_type, + rtph->marker, rtph->extension, + rtph->csrc_count, ntohs(rtph->sequence), + ntohl(rtph->timestamp)); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + + for (i=0; i<msg->len - sizeof(struct rtp_hdr); i++) { + ret = snprintf(buf+offset, len, "%02x ", payload[i]); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + } + + ret = snprintf(buf+offset, len, "]"); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + + return ret; +} |