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

Changes

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