Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for dtmf rtp events into rtpdump #110

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rtpdump.1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
.Op Fl o Ar outfile
.Op Fl t Ar minutes
.Op Fl x Ar bytes
.Op Fl d Ar event_payload_id
.Oo Ar address Oc Ns / Ns Ar port
.Sh DESCRIPTION
.Nm
Expand Down Expand Up @@ -225,6 +226,10 @@ This is only applicable for the
and
.Cm hex
formats.
.It Fl d Ar event_payload_id
Consider the dynamic payload id
.Ar event_payload_id
as the payload id for RTP Events
.El
.Sh EXAMPLES
.Bd -literal
Expand Down
37 changes: 34 additions & 3 deletions rtpdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,15 @@ typedef enum {
F_ascii
} t_format;


int dyn_payload_rtpevent = 101; /* Default payload type for RTPEvent packets */

static void usage(const char *argv0)
{
fprintf(stderr, "usage: %s "
"[-F hex|ascii|rtcp|short|payload|dump|header] "
"[-f infile] [-o outfile] [-t minutes] [-x bytes] "
"[address]/port > file\n", argv0);
"[-d event_payload_id] [address]/port > file\n", argv0);
}


Expand Down Expand Up @@ -264,6 +267,7 @@ static int parse_data(FILE *out, char *buf, int len)
rtp_hdr_ext_t *ext;
int i, ext_len;
int hlen = 0;
char *payload_data = NULL;

/* Show vat format packets. */
if (r->version == 0) {
Expand All @@ -289,6 +293,29 @@ static int parse_data(FILE *out, char *buf, int len)
for (i = 0; i < r->cc; i++) {
fprintf(out, "csrc[%d]=0x%0lx ", i, r->csrc[i]);
}

/* Check if it is an RTPEvent Packet */
if (dyn_payload_rtpevent == r->pt)
{

payload_data = (char*)buf + 12 + (r->cc*4);
if (payload_data[0] == 10)
{

payload_data[0] = '*';
}
else if (payload_data[0] == 11)
{
payload_data[0] = '#';
}
else
{
payload_data[0] += '0';
}
fprintf(out, "dtmf=%c duration=%dms end=%d ", payload_data[0], ntohs(*(short*)(payload_data+2))/8,(payload_data[1]>>7)&0x1);

}

if (r->x) { /* header extension */
ext = (rtp_hdr_ext_t *)((char *)buf + hlen);
ext_len = ntohs(ext->len);
Expand Down Expand Up @@ -532,7 +559,6 @@ void packet_handler(FILE *out, t_format format, int trunc,
double dnow = tdbl(&now);
int hlen; /* header length */
int offset;

switch(format) {
case F_header:
offset = (dnow - dstart) * 1000;
Expand Down Expand Up @@ -639,7 +665,7 @@ int main(int argc, char *argv[])
extern double tdbl(struct timeval *);

startupSocket();
while ((c = getopt(argc, argv, "F:f:o:t:x:h")) != EOF) {
while ((c = getopt(argc, argv, "F:f:o:t:x:d:h")) != EOF) {
switch(c) {
/* output format */
case 'F':
Expand Down Expand Up @@ -686,6 +712,11 @@ int main(int argc, char *argv[])
}
break;

/* Dynamic Payload Type for RTPEVENT packets */
case 'd':
dyn_payload_rtpevent = atoi(optarg);
break;

case '?':
case 'h':
usage(argv[0]);
Expand Down