-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCrossValidation.php
executable file
·173 lines (140 loc) · 10.7 KB
/
CrossValidation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/* This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
function loadLeafInfoFile($fileName, $PresTimeOffset){
global $session_dir;
$info = array();
$leafInfoFile = open_file($session_dir . '/' . $fileName, 'rt');
if (!$leafInfoFile)
return;
fscanf($leafInfoFile, "%lu\n", $accessUnitDurationNonIndexedTrack);
fscanf($leafInfoFile, "%u\n", $info['numTracks']);
$info['leafInfo'] = array();
$info['numLeafs'] = array();
$info['trackTypeInfo'] = array();
for ($i = 0; $i < $info['numTracks']; $i++)
fscanf($leafInfoFile, "%lu %lu\n", $info['trackTypeInfo'][$i]['track_ID'], $info['trackTypeInfo'][$i]['componentSubType']);
for ($i = 0; $i < $info['numTracks']; $i++){
fscanf($leafInfoFile, "%u\n", $info['numLeafs'][$i]);
$info['leafInfo'][$i] = array();
for ($j = 0; $j < $info['numLeafs'][$i]; $j++){
fscanf($leafInfoFile, "%d %f %f\n", $info['leafInfo'][$i][$j]['firstInSegment'], $info['leafInfo'][$i][$j]['earliestPresentationTime'], $info['leafInfo'][$i][$j]['lastPresentationTime']);
$info['leafInfo'][$i][$j]['earliestPresentationTime'] = $info['leafInfo'][$i][$j]['earliestPresentationTime'] - $PresTimeOffset;
$info['leafInfo'][$i][$j]['lastPresentationTime'] = $info['leafInfo'][$i][$j]['lastPresentationTime'] - $PresTimeOffset;
}
}
close_file($leafInfoFile);
return $info;
}
function checkAlignment($leafInfoA, $leafInfoB, $opfile, $segmentAlignment, $subsegmentAlignment, $bitstreamSwitching){
if ($leafInfoA['numTracks'] != $leafInfoB['numTracks']){
fprintf($opfile, "Error: Number of tracks logged %d for representation with id \"%s\" not equal to the number of indexed tracks %d for representation id \"%s\"\n", $leafInfoA['numTracks'], $leafInfoA['id'], $leafInfoB['numTracks'], $leafInfoB['id']);
if ($bitstreamSwitching == "true")
fprintf($opfile, "Bitstream switching not possible, validation failed for bitstreamSwitching\n");
return;
}
if ($bitstreamSwitching == "true"){
for ($i = 0; $i < $leafInfoA['numTracks']; $i++){
$correspondingTrackFound = false;
for ($j = 0; $j < $leafInfoB['numTracks']; $j++){
if ($leafInfoA['trackTypeInfo'][$i]['track_ID'] == $leafInfoB['trackTypeInfo'][$j]['track_ID'] && $leafInfoA['trackTypeInfo'][$i]['componentSubType'] == $leafInfoB['trackTypeInfo'][$j]['componentSubType']){
$correspondingTrackFound = true;
break;
}
}
if (!$correspondingTrackFound)
fprintf($opfile, "Error: No corresponding track found in representation id \"%s\" for representation id \"%s\" track ID \"%s\" with type \"%s\", bitstream switching is not possible: ISO/IEC 23009-1:2012(E), 7.3.3.2: The track IDs for the same media content component are identical for each Representation in each Adaptation Set \n", $leafInfoB['id'], $leafInfoA['id'], $leafInfoA['trackTypeInfo'][$i]['track_ID'], $leafInfoA['trackTypeInfo'][$i]['componentSubType']);
}
}
if ($segmentAlignment != "true" && $subsegmentAlignment != "true")
return;
for ($i = 0; $i < $leafInfoA['numTracks']; $i++){
if ($leafInfoA['numLeafs'][$i] != $leafInfoB['numLeafs'][$i]){
fprintf($opfile, "Error: Number of leafs %d for track %d for representation id \"%s\" not equal to the number of leafs %d for track %d for representation id \"%s\"\n", $leafInfoA['numLeafs'][$i], $i + 1, $leafInfoA['id'], $leafInfoB['numLeafs'][$i], $i + 1, $leafInfoB['id']);
continue;
}
for ($j = 0; $j < ($leafInfoA['numLeafs'][$i] - 1); $j++){
if ($subsegmentAlignment == "true" || ($leafInfoA['leafInfo'][$i][$j + 1]['firstInSegment'] > 0)){
if ($leafInfoA['leafInfo'][$i][$j + 1]['earliestPresentationTime'] <= $leafInfoB['leafInfo'][$i][$j]['lastPresentationTime']){
if ($leafInfoA['leafInfo'][$i][$j + 1]['firstInSegment'] > 0)
fprintf($opfile, "Error: Overlapping segment: EPT of leaf %f for leaf number %d for representation id \"%s\" is <= the latest presentation time %f corresponding leaf for representation id \"%s\"\n", $leafInfoA['leafInfo'][$i][$j + 1]['earliestPresentationTime'], $j + 2, $leafInfoA['id'], $leafInfoB['leafInfo'][$i][$j]['lastPresentationTime'], $leafInfoB['id']);
else
fprintf($opfile, "Error: Overlapping sub-segment: EPT of leaf %f for leaf number %d for representation id \"%s\" is <= the latest presentation time %f corresponding leaf for representation id \"%s\"\n", $leafInfoA['leafInfo'][$i][$j + 1]['earliestPresentationTime'], $j + 2, $leafInfoA['id'], $leafInfoB['leafInfo'][$i][$j]['lastPresentationTime'], $leafInfoB['id']);
}
if ($leafInfoB['leafInfo'][$i][$j + 1]['earliestPresentationTime'] <= $leafInfoA['leafInfo'][$i][$j]['lastPresentationTime']) {
if ($leafInfoB['leafInfo'][$i][$j + 1]['firstInSegment'] > 0)
fprintf($opfile, "Error: Overlapping segment: EPT of leaf %f for leaf number %d for representation id \"%s\" is <= the latest presentation time %f corresponding leaf for representation id \"%s\"\n", $leafInfoB['leafInfo'][$i][$j + 1]['earliestPresentationTime'], $j + 2, $leafInfoB['id'], $leafInfoA['leafInfo'][$i][$j]['lastPresentationTime'], $leafInfoA['id']);
else
fprintf($opfile, "Error: Overlapping sub-segment: EPT of leaf %f for leaf number %d for representation id \"%s\" is <= the latest presentation time %f corresponding leaf for representation id \"%s\"\n", $leafInfoB['leafInfo'][$i][$j + 1]['earliestPresentationTime'], $j + 2, $leafInfoB['id'], $leafInfoA['leafInfo'][$i][$j]['lastPresentationTime'], $leafInfoA['id']);
}
}
}
}
}
function crossRepresentationProcess(){
global $mpd_features, $current_period, $current_adaptation_set, $session_dir, $adaptation_set_error_log_template, $reprsentation_info_log_template, $string_info, $progress_xml, $progress_report;
$adaptation_set = $mpd_features['Period'][$current_period]['AdaptationSet'][$current_adaptation_set];
$timeoffset = 0;
$timescale = 1;
$file_path = str_replace('$AS$', $current_adaptation_set, $adaptation_set_error_log_template) . '.txt';
$opfile = open_file($session_dir . '/Period' .$current_period.'/' . $file_path, 'w');
$segmentAlignment = ($adaptation_set['segmentAlignment']) ? $adaptation_set['segmentAlignment'] : 'false';
$subsegmentAlignment = ($adaptation_set['subsegmentAlignment']) ? $adaptation_set['subsegmentAlignment'] : 'false';
$bitstreamSwitching = ($adaptation_set['bitstreamSwitching']) ? $adaptation_set['bitstreamSwitching'] : 'false';
if ($segmentAlignment == "true" || $subsegmentAlignment == "true" || $bitstreamSwitching == "true"){
$leafInfo = array();
$representations = $adaptation_set['Representation'];
for ($j = 0; $j < sizeof($representations); $j++){
$timeoffset = 0;
$timescale = 1;
$representation = $representations[$j];
if (!empty($adaptation_set['SegmentTemplate']['timescale']))
$timescale = $adaptation_set['SegmentTemplate']['timescale'];
if (!empty($adaptation_set['SegmentTemplate']['presentationTimeOffset']))
$timeoffset = $adaptation_set['SegmentTemplate']['presentationTimeOffset'];
if (!empty($representation['SegmentTemplate']['timescale']))
$timescale = $representation['SegmentTemplate']['timescale'];
if (!empty($representation['SegmentTemplate']['presentationTimeOffset']))
$timeoffset = $representation['SegmentTemplate']['presentationTimeOffset'];
if (!empty($representation['presentationTimeOffset']))
$timeoffset = $representation['presentationTimeOffset'];
$offsetmod = $timeoffset / $timescale;
$leafInfo[$j] = loadLeafInfoFile('Period' . $current_period . '/' . str_replace(array('$AS$', '$R$'), array($current_adaptation_set, $j), $reprsentation_info_log_template) . '.txt', $offsetmod);
$leafInfo[$j]['id'] = $representation['id'];
}
for ($j = 0; $j < sizeof($representations)-1; $j++){
for ($k = $j + 1; $k < sizeof($representations); $k++){
checkAlignment($leafInfo[$j], $leafInfo[$k], $opfile, $segmentAlignment, $subsegmentAlignment, $bitstreamSwitching);
}
}
}
close_file($opfile);
if (file_exists($session_dir . '/Period' . $current_period . '/' . $file_path . '.txt')){
$searchadapt = file_get_contents($session_dir . '/Period' . $current_period . '/' . $file_path . '.txt');
if(strpos($searchadapt, "Error") == false && strpos($searchadapt, "violated") == false){
$progress_xml->Results[0]->Period[$current_period]->Adaptation[$current_adaptation_set]->addChild('CrossRepresentation', 'noerror');
$file_error[] = "noerror";
}
else{
$progress_xml->Results[0]->Period[$current_period]->Adaptation[$current_adaptation_set]->addChild('CrossRepresentation', 'error');
$file_error[] = relative_path($session_dir . '/Period' . $current_period . '/' . $file_path . '.html');
}
}
else{
$progress_xml->Results[0]->Period[$current_period]->Adaptation[$current_adaptation_set]->addChild('CrossRepresentation', 'noerror');
$file_error[] = "noerror";
}
$progress_xml->Results[0]->Period[$current_period]->Adaptation[$current_adaptation_set]->CrossRepresentation->addAttribute('url', str_replace($_SERVER['DOCUMENT_ROOT'], 'http://' . $_SERVER['SERVER_NAME'], $session_dir . '/' . $file_path . '.txt'));
$progress_xml->asXml(trim($session_dir . '/' . $progress_report));
tabulateResults($session_dir . '/Period' .$current_period.'/' . explode('.', $file_path)[0] . '.txt', 'Cross');
print_console($session_dir . '/Period' .$current_period.'/' . $file_path, "Period " . ($current_period+1) . " Adaptation Set " . ($current_adaptation_set+1) . " DASH Cross Validation Results");
}