#!/usr/local/bin/perl5.8.8 eval 'exec /usr/local/bin/perl5.8.8 -S $0 ${1+"$@"}' if 0; # not running under some shell # # Net::RTP example file # # Displays packet arrival timing # use Net::RTP; use Data::Dumper; use Time::HiRes qw/time/; use strict; my $DEFAULT_PORT = 5004; # Default RTP port # Create RTP socket my ($address, $port) = @ARGV; usage() unless (defined $address); $port = $DEFAULT_PORT unless (defined $port); my $rtp = new Net::RTP( LocalPort=>$port, LocalAddr=>$address ) || die "Failed to create RTP socket: $!"; my $start = time(); my $last = time(); my $ts_last = 0; while (my $packet = $rtp->recv()) { my $this = time(); # Calculate the difference from the last packet my $diff = sprintf("%2.2f", ($this-$last)*1000); $diff = "+$diff" if ($diff>0); # Calculate the difference from the last packet my $ts_diff = $packet->timestamp()-$ts_last; $ts_diff = "+$ts_diff" if ($ts_diff>0); # Display the packet printf("%2.2f", ($this-$start)*1000); printf(" (%s)", $diff); printf(" SRC=%s", $packet->source_ip()); printf(", LEN=%u", $packet->payload_size()); printf(", PT=%u", $packet->payload_type()); printf(", SEQ=%u", $packet->seq_num()); printf(", TS=%u", $packet->timestamp()); printf(" (%s)", $ts_diff); printf("\n"); # Store time of last packet that arrived $last = $this; $ts_last = $packet->timestamp(); } sub usage { print "usage: rtptimer.pl
[