Commit 9765f110 authored by Jon Kåre Hellan's avatar Jon Kåre Hellan

Changes

parent 9fde964b
...@@ -9,6 +9,8 @@ $Version="1.0"; ...@@ -9,6 +9,8 @@ $Version="1.0";
# XML, RTMP, TCP support, Pål Moen Møst, 2011 # XML, RTMP, TCP support, Pål Moen Møst, 2011
# use Socket; # use Socket;
use Net::RTP;
use IO::Socket qw(:DEFAULT :crlf); use IO::Socket qw(:DEFAULT :crlf);
use IO::Socket::INET; use IO::Socket::INET;
use IO::Socket::Multicast; use IO::Socket::Multicast;
...@@ -19,7 +21,7 @@ use NetPacket::IP; ...@@ -19,7 +21,7 @@ use NetPacket::IP;
use NetPacket::IP qw(:strip :protos);; use NetPacket::IP qw(:strip :protos);;
use NetPacket::UDP; use NetPacket::UDP;
use NetPacket::TCP; use NetPacket::TCP;
use Net::IPv6Addr; #use Net::IPv6Addr;
#use NetPacket::IPv6 qw(ipv6_strip); #use NetPacket::IPv6 qw(ipv6_strip);
#use Net::RTP; #use Net::RTP;
use Net::RTP::Packet; use Net::RTP::Packet;
...@@ -39,7 +41,7 @@ use constant MTU => 1580; ...@@ -39,7 +41,7 @@ use constant MTU => 1580;
use XML::DOM; use XML::DOM;
use XML::Twig; use XML::Twig;
#use mpegpackets; #use mpegpackets;
$DEFAULT_PORT = 1955; $DEFAULT_PORT = 1234;
#my oh my,more globals #my oh my,more globals
my ($rtmp,$period,$last,$debug,$swfurl,$pageurl,$flash_version,$reconnect); my ($rtmp,$period,$last,$debug,$swfurl,$pageurl,$flash_version,$reconnect);
...@@ -51,7 +53,7 @@ require "newgetopt.pl"; ...@@ -51,7 +53,7 @@ require "newgetopt.pl";
&NGetOpt(@opts) || die pod2usage(1); &NGetOpt(@opts) || die pod2usage(1);
die pod2usage(1) if $opt_h; die pod2usage(1) if $opt_h;
die 'Version is $Rev$' if $opt_version; die 'Version is $Rev: 46 $' if $opt_version;
$continous= ! $opt_packets; $continous= ! $opt_packets;
$opt_v=$opt_v or $opt_verbose; $opt_v=$opt_v or $opt_verbose;
my $codec = $opt_codec || 'G.711'; my $codec = $opt_codec || 'G.711';
...@@ -1421,13 +1423,16 @@ sub xml_dump { ...@@ -1421,13 +1423,16 @@ sub xml_dump {
$max_pts = $pts_stats{$f}{$pid}{'num'}; $max_pts = $pts_stats{$f}{$pid}{'num'};
} }
} }
my $delay_factor = ((($mpeg_stats{$f}{$mpeg_pid}{'avg_packets_1s'} * $pts_stats{$f}{$pts_pid}{'dwell_avg'}*(10**-3))*188)/$mpeg_stats{$f}{$mpeg_pid}{'media_bandwidth'})*(10**2); my $delay_factor = 0;
if ( $mpeg_stats{$f}{$mpeg_pid}{'media_bandwidth'} > 0 ){
$delay_factor = ((($mpeg_stats{$f}{$mpeg_pid}{'avg_packets_1s'} * $pts_stats{$f}{$pts_pid}{'dwell_avg'}*(10**-3))*188)/$mpeg_stats{$f}{$mpeg_pid}{'media_bandwidth'})*(10**2);
}
$pid_XML->addText($mpeg_pid); $pid_XML->addText($mpeg_pid);
#PES and PTS_stats #PES and PTS_stats
$stream_id_XML->addText($pts_stats{$f}{$pts_pid}{'stream_id'}); $stream_id_XML->addText($pts_stats{$f}{$pts_pid}{'stream_id'});
$stream_id_type_XML->addText($pts_stats{$f}{$pts_pid}{'stream_id_type'}); $stream_id_type_XML->addText($pts_stats{$f}{$pts_pid}{'stream_id_type'});
#mpeg #mpeg
$num_packets_XML->addText($mpeg_stats{$f}{$mpeg_pid}{'num'}); $num_packets_XML->addText(&format_numbers($mpeg_stats{$f}{$mpeg_pid}{'num'}));
$lost_packets_XML->addText(&format_numbers($mpeg_stats{$f}{$mpeg_pid}{'lost_packets'})); $lost_packets_XML->addText(&format_numbers($mpeg_stats{$f}{$mpeg_pid}{'lost_packets'}));
$media_loss_rate_XML->addText(&format_numbers($mpeg_stats{$f}{$mpeg_pid}{'media_loss_rate'})); $media_loss_rate_XML->addText(&format_numbers($mpeg_stats{$f}{$mpeg_pid}{'media_loss_rate'}));
$delay_factor_XML->addText(&format_numbers($delay_factor)); $delay_factor_XML->addText(&format_numbers($delay_factor));
...@@ -2433,63 +2438,68 @@ sub pcr_update_stats ...@@ -2433,63 +2438,68 @@ sub pcr_update_stats
# We might have wrapped around, which creates weird results. # We might have wrapped around, which creates weird results.
# this is just a work-around... - reset pcr_checks if large values # this is just a work-around... - reset pcr_checks if large values
if (($pcr_stats{$f}{$TS}{'last_pcr'} > $tspack->pcr_s()) and #ok it is not right to reset everything if there is a reorder :
($pcr_stats{$f}{$TS}{'last_pcr'} > 47000) and # if (($pcr_stats{$f}{$TS}{'last_pcr'} > $tspack->pcr_s()) and
($tspack->pcr_s() < 10000)) { # ($pcr_stats{$f}{$TS}{'last_pcr'} > 47000) and
$pcr_stats{$f}{$TS}{'initialized'} = 0; # ($tspack->pcr_s() < 10000)) {
} # $pcr_stats{$f}{$TS}{'initialized'} = 0;
# }
# #
if ($pcr_stats{$f}{$TS}{'initialized'}) { if ($pcr_stats{$f}{$TS}{'initialized'}) {
$d_pcr = (($tspack->pcr_s() - $pcr_stats{$f}{$TS}{'last_pcr'}) + $PCR_MAX) % $PCR_MAX; $d_pcr = (($tspack->pcr_s() - $pcr_stats{$f}{$TS}{'last_pcr'}) + $PCR_MAX) % $PCR_MAX;
# Time between our local clocks # Time between our local clocks
$d_t = time() - $pcr_stats{$f}{$TS}{'real_last_time'}; $d_t = time() - $pcr_stats{$f}{$TS}{'real_last_time'};
$pcr_stats{$f}{$TS}{'real_last_time'} = time(); $pcr_stats{$f}{$TS}{'real_last_time'} = time();
# ++$pcr_stats{$f}{$TS}{'num'}; # ++$pcr_stats{$f}{$TS}{'num'};
if($d_pcr < 0){ # resequenced
if($d_pcr > ($PCR_MAX/2)){ # massively resequenced
$late{$f}++; $late{$f}++;
} } else { # normal pcr update
#print "TS value ",$TS, ".... PCR ", $tspack->pcr_s(), "\n"; #print "TS value ",$TS, ".... PCR ", $tspack->pcr_s(), "\n";
#time gap in miliseconds between recived PCR values. #time gap in miliseconds between recived PCR values.
if ($d_t > $pcr_stats{$f}{$TS}{'max_pcr_gap'}) { if ($d_t > $pcr_stats{$f}{$TS}{'max_pcr_gap'}) {
$pcr_stats{$f}{$TS}{'max_pcr_gap'} = ($d_t); #in MS $pcr_stats{$f}{$TS}{'max_pcr_gap'} = ($d_t); #in MS
} }
if ($d_t < $pcr_stats{$f}{$TS}{'min_pcr_gap'}) { if ($d_t < $pcr_stats{$f}{$TS}{'min_pcr_gap'}) {
$pcr_stats{$f}{$TS}{'min_pcr_gap'} = ($d_t); #in MS $pcr_stats{$f}{$TS}{'min_pcr_gap'} = ($d_t); #in MS
} }
my $sample = abs($d_pcr - $d_t); my $sample = abs($d_pcr - $d_t);
my $k = $pcr_stats{$f}{$TS}{'num'}; my $k = $pcr_stats{$f}{$TS}{'num'};
$pcr_stats{$f}{$TS}{'pcr_jitter_sum'} += $sample; $pcr_stats{$f}{$TS}{'pcr_jitter_sum'} += $sample;
$pcr_stats{$f}{$TS}{'pcr_jitter_square'} += ($sample**2); $pcr_stats{$f}{$TS}{'pcr_jitter_square'} += ($sample**2);
++$pcr_stats{$f}{$TS}{'num'}; ++$pcr_stats{$f}{$TS}{'num'};
#Max/Min-checks for PCR jitter #Max/Min-checks for PCR jitter
if ($sample > $pcr_stats{$f}{$TS}{'max_jit'}) { if ($sample > $pcr_stats{$f}{$TS}{'max_jit'}) {
$pcr_stats{$f}{$TS}{'max_jit'} = $sample; $pcr_stats{$f}{$TS}{'max_jit'} = $sample;
} }
if ($sample < $pcr_stats{$f}{$TS}{'min_jit'}) { if ($sample < $pcr_stats{$f}{$TS}{'min_jit'}) {
$pcr_stats{$f}{$TS}{'min_jit'} = $sample; $pcr_stats{$f}{$TS}{'min_jit'} = $sample;
} }
#This calculates the PCR arrival difference mean and std #This calculates the PCR arrival difference mean and std
#$sample = $d_pcr; #$sample = $d_pcr;
$tm = $pcr_stats{$f}{$TS}{'running_dpcr_mean'}; $tm = $pcr_stats{$f}{$TS}{'running_dpcr_mean'};
$ts = $pcr_stats{$f}{$TS}{'running_dpcr_std'}; $ts = $pcr_stats{$f}{$TS}{'running_dpcr_std'};
$pcr_stats{$f}{$TS}{'running_dpcr_mean'} = $tm + (($sample - $tm)/$k); $pcr_stats{$f}{$TS}{'running_dpcr_mean'} = $tm + (($sample - $tm)/$k);
$tm2 = $pcr_stats{$f}{$TS}{'running_dpcr_mean'}; $tm2 = $pcr_stats{$f}{$TS}{'running_dpcr_mean'};
$pcr_stats{$f}{$TS}{'running_dpcr_std'} = $ts + (($sample - $tm)*($sample - $tm2)); $pcr_stats{$f}{$TS}{'running_dpcr_std'} = $ts + (($sample - $tm)*($sample - $tm2));
#Max/Min-checks for delta-PCR #Max/Min-checks for delta-PCR
if ($sample > $pcr_stats{$f}{$TS}{'max_dpcr'}) { if ($sample > $pcr_stats{$f}{$TS}{'max_dpcr'}) {
$pcr_stats{$f}{$TS}{'max_dpcr'} = $sample; $pcr_stats{$f}{$TS}{'max_dpcr'} = $sample;
} }
if ($sample < $pcr_stats{$f}{$TS}{'min_jit'}) { if ($sample < $pcr_stats{$f}{$TS}{'min_jit'}) {
} }
$pcr_stats{$f}{$TS}{'last_pcr'} = $tspack->pcr_s(); $pcr_stats{$f}{$TS}{'last_pcr'} = $tspack->pcr_s();
$pcr_stats{$f}{$TS}{'last_pcrb'} = $tspack->pcrb_s(); $pcr_stats{$f}{$TS}{'last_pcrb'} = $tspack->pcrb_s();
$packets_between_pcr = 0; $packets_between_pcr = 0;
}
#Got a new PCR-value, so synch the clocks #Got a new PCR-value, so synch the clocks
} else { } else {
...@@ -2654,20 +2664,28 @@ sub check_continuity ...@@ -2654,20 +2664,28 @@ sub check_continuity
$mpeg_stats{$f}{$pid}{'lost_packets'} = 0; $mpeg_stats{$f}{$pid}{'lost_packets'} = 0;
} }
if (not exists $last_ccs{$pid}) { if ( exists $last_ccs{$pid}) {
return; my $d_cc = ( $cc - $last_ccs{$pid} + 16 ) % 16;
}
if ($last_ccs{$pid} == $cc and $payload == 0) { if ( $payload ){ # cc is valid use heuristic cc_max / 2
return; if ( $d_cc == 0 ) {
} $mpeg_stats{$f}{$pid}{'duplicate_packets'}++;
if (($last_ccs{$pid} + 1)%16 == $cc) { } elsif ( $d_cc == 1 ) { # normal
return;
}
if ($last_ccs{$pid} == $cc) {
return; return;
# wrap around too fast and single 2 packets loss is anticipated more likely
# } elsif ( $d_cc > 8 ) { # reordered
# $mpeg_stats{$f}{$pid}{'reordered_packets'}++;
} else { # gap
$discontinuities++;
$mpeg_stats{$f}{$pid}{'lost_packets'}++;
}
} elsif ( $d_cc != 0 ){
# too many packets hit this test, should be zero when no payload
$discontinuities++;
# $mpeg_stats{$f}{$pid}{'lost_packets'}++;
}
} }
$discontinuities++;
$mpeg_stats{$f}{$pid}{'lost_packets'}++;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment