Statistics
| Branch: | Revision:

psnr-tools / QoE.pl @ 304e363b

History | View | Annotate | Download (2.95 KB)

1
#!/usr/bin/perl
2

    
3
use strict;
4
use Statistics::Descriptive;
5
use POSIX qw(ceil floor);
6

    
7
($#ARGV + 1 == 2) or die;
8
my $inputfolder=$ARGV[0];
9
my $video=$ARGV[1];
10

    
11

    
12
#a value of 'src' for the peer creates an empty lost file
13
sub peer_chunks_lost ($) {
14
  my ($peer)=@_;
15

    
16
  my @losts;
17
  if ($peer=='src') {
18
    @losts=`echo -n > lost.txt`;
19
  } else {
20
    @losts=`./chunks_lost.sh $peer $inputfolder| tee lost.txt`;
21
  }
22
  chomp @losts;
23
  return @losts;
24
}
25

    
26
sub peer_qoe ($$) {
27
  my ($peer,$chunksize)=@_;
28

    
29
  my @losts = peer_chunks_lost($peer);
30

    
31
  my %qoe;
32
  #$qoe{ 'chunkloss' } = peer_chunkloss($peer,@losts);
33

    
34
  my $q;
35
  if ($chunksize=='gop') {
36
  	$q=`./psnr.sh calc 0 lost.txt`;
37
  } else {
38
  	$q=`./psnr.sh calc $chunksize lost.txt`;
39
  }
40

    
41
  $q =~ m/psnr: ([\d\.]+)/;
42
  $qoe{ 'psnr' } = $1;
43

    
44
  $q =~ m/bytes: ([\d\.]+)/;
45
  $qoe{ 'bytes' } = $1;
46

    
47
  $q =~ m/chunks: ([\d\.]+)/;
48
  $qoe{ 'chunks' } = $1;
49

    
50
  $q =~ m/chunkslost: ([\d\.]+)/;
51
  $qoe{ 'chunkslost' } = $1;
52

    
53
  $qoe{ 'chunkloss' } = $qoe{ 'chunkslost' } / $qoe{ 'chunks' } ;
54

    
55
  return %qoe;  
56
}
57

    
58
#sub num_chunks() {
59
#  return 1000;
60
#}
61
#
62
#sub peer_chunkloss ($@) {
63
#  my ($peer,@losts)=@_;
64
#  return (scalar @losts) / num_chunks();
65
#}
66

    
67
sub peers_of_class ($) {
68
  my ($peerclass)=@_;
69

    
70
  my @peers=`./peers_of_class.sh $peerclass $inputfolder`;
71
  chomp @peers;
72
  return @peers;
73
}
74

    
75
sub print_stats($@) {
76
  my ($name,@values)=@_;
77

    
78
  my $stat = Statistics::Descriptive::Full->new();
79
  $stat->add_data(\@values);
80
  print "$name: ";
81
  print " mean=".$stat->mean(); 
82
  print " var=".$stat->variance();
83
  print " count=".$stat->count();
84
  print "\n";
85

    
86
  #my $mean = $stat->mean();
87
  #my $variance  = $stat->variance();
88
  #my $num  = $stat->count();
89
  #print "Number of Values = $num\n",
90
  #      "Mean             = $mean\n",
91
  #      "Variance         = $variance\n";
92
}
93

    
94

    
95
sub qoe($){
96
  my ($chunksize)=@_;
97

    
98
  my @peerclasses=(1,2,3,4);
99

    
100
  my @psnrs;
101
  my @chunklosses;
102
  
103
  foreach my $peerclass (@peerclasses) {
104

    
105
    print "Peer class = $peerclass\n";
106

    
107
    my @peers=peers_of_class($peerclass);
108

    
109
    my @psnrs_class;
110
    my @chunklosses_class;
111
    foreach my $peer (@peers) {
112
      my %qoe = peer_qoe($peer,$chunksize);
113

    
114
      push(@psnrs,$qoe{'psnr'});
115
      push(@psnrs_class,$qoe{'psnr'});
116
      push(@chunklosses,$qoe{'chunkloss'});
117
      push(@chunklosses_class,$qoe{'chunkloss'});
118
    }
119

    
120
    print_stats("psnr(uncompressed->received)",@psnrs_class);
121
    print_stats("chunkloss",@chunklosses_class);
122
    print "\n";
123
  }
124

    
125
  print "All peers\n";
126
  print_stats("psnr(uncompressed->received)",@psnrs);
127
  print_stats("chunkloss",@chunklosses);
128
}
129

    
130
#--------------------------------------------------
131

    
132
my $tmp=`./psnr.sh init $video`;
133
my %srcqoe = peer_qoe('src','gop');
134
print "psnr(uncompressed->compressed): ".$srcqoe{'psnr'}."\n";
135

    
136
my $chunksize = ceil($srcqoe{'bytes'}/$srcqoe{'chunks'}); 
137

    
138
print "\nQuality with GOP size chunks (avg chunk size = $srcqoe{'bytes'}/$srcqoe{'chunks'} bytes )\n";
139
qoe('gop');
140
print "\nQuality with $chunksize bytes chunks\n";
141
qoe('$chunksize');