1#!/usr/bin/perl 2# 3# Net::RTP example file 4# 5# Displays packet arrival timing 6# 7 8use Net::RTP; 9use Data::Dumper; 10use Time::HiRes qw/time/; 11use strict; 12 13 14my $DEFAULT_PORT = 5004; # Default RTP port 15 16 17# Create RTP socket 18my ($address, $port) = @ARGV; 19usage() unless (defined $address); 20$port = $DEFAULT_PORT unless (defined $port); 21 22my $rtp = new Net::RTP( 23 LocalPort=>$port, 24 LocalAddr=>$address 25) || die "Failed to create RTP socket: $!"; 26 27 28my $start = time(); 29my $last = time(); 30my $ts_last = 0; 31while (my $packet = $rtp->recv()) { 32 my $this = time(); 33 34 # Calculate the difference from the last packet 35 my $diff = sprintf("%2.2f", ($this-$last)*1000); 36 $diff = "+$diff" if ($diff>0); 37 38 # Calculate the difference from the last packet 39 my $ts_diff = $packet->timestamp()-$ts_last; 40 $ts_diff = "+$ts_diff" if ($ts_diff>0); 41 42 # Display the packet 43 printf("%2.2f", ($this-$start)*1000); 44 printf(" (%s)", $diff); 45 printf(" SRC=%s", $packet->source_ip()); 46 printf(", LEN=%u", $packet->payload_size()); 47 printf(", PT=%u", $packet->payload_type()); 48 printf(", SEQ=%u", $packet->seq_num()); 49 printf(", TS=%u", $packet->timestamp()); 50 printf(" (%s)", $ts_diff); 51 printf("\n"); 52 53 # Store time of last packet that arrived 54 $last = $this; 55 $ts_last = $packet->timestamp(); 56} 57 58 59sub usage { 60 print "usage: rtptimer.pl <address> [<port>]\n"; 61 exit -1; 62} 63 64 65__END__ 66 67=pod 68 69=head1 NAME 70 71rtptimer.pl - Displays arrival times of incoming RTP packet headers 72 73=head1 SYNOPSIS 74 75rtptimer.pl <address> [<port>] 76 77Displays arrival times for incoming RTP packets. 78The first column is the time in milliseconds since the tool started, 79followed by the time in milliseconds since the last packet. 80This is then followed by the source IP, packet length in bytes, 81payload type, sequence number and the packet timestamp. The timestamp 82is then followed by the difference between it and the previous packet. 83 84=head1 SEE ALSO 85 86L<Net::RTP> 87 88L<Net::RTP::Packet> 89 90L<http://www.iana.org/assignments/rtp-parameters> 91 92 93=head1 BUGS 94 95Unicast addresses aren't currently detected and fail when trying to join 96multicast group. 97 98=head1 AUTHOR 99 100Nicholas J Humfrey, njh@cpan.org 101 102=head1 COPYRIGHT AND LICENSE 103 104Copyright (C) 2007 University of Southampton 105 106This script is free software; you can redistribute it and/or modify 107it under the same terms as Perl itself, either Perl version 5.005 or, 108at your option, any later version of Perl 5 you may have available. 109 110=cut 111