-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMPDValidation.php
executable file
·143 lines (115 loc) · 5.24 KB
/
MPDValidation.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
<?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 validate_MPD(){
global $main_dir, $mpd_dom, $mpd_url, $session_dir, $mpd_log, $featurelist_log_html, $mpd_xml, $mpd_xml_string, $mpd_xml_report;
$schematronIssuesReport = NULL;
$mpd_xml = simplexml_load_string($mpd_xml_string);
$mpd_xml->asXml($session_dir . '/' . $mpd_xml_report);
if(!$mpd_xml) {
exit;
}
chdir('../DASH/mpdvalidator');
$dash_schema_location = download_schema();
$mpdvalidator = syscall('java -cp "saxon9he.jar:xercesImpl.jar:bin" Validator ' . '"' . explode('#', $mpd_url)[0] . '"' . " " . "$session_dir" . "/resolved.xml $dash_schema_location $session_dir/$mpd_xml_report");
$result = extract_relevant_text($mpdvalidator);
delete_schema($dash_schema_location);
## Generate mpd report
$mpdreport = fopen($session_dir . '/' . $mpd_log . '.txt', 'a+b');
fwrite($mpdreport, $result);
## Check the PASS/FAIL status
$exit = false;
$string = '';
$mpd_rep_loc = 'temp/' . basename($session_dir) . '/' . $mpd_log . '.html';
$mpd_xml = simplexml_load_file($session_dir.'/'.$mpd_xml_report);
if (!is_valid($mpdvalidator, 'XLink resolving successful')){ $string .= $mpd_rep_loc; $exit = true; $mpd_xml->xlink = "error"; $mpd_xml->schema = "error"; $mpd_xml->schematron = "error"; $mpd_xml->asXml($session_dir . '/' . $mpd_xml_report); }
else { $string .= 'true '; }
if(!is_valid($mpdvalidator, 'MPD validation successful')){ $string .= $mpd_rep_loc; $exit = true; }
else { $string .= 'true '; }
if(!is_valid($mpdvalidator, 'Schematron validation successful')){ $string .= $mpd_rep_loc; $exit = true; }
else { $string .= 'true '; }
## Featurelist generate
if(!is_valid($mpdvalidator, 'Schematron validation successful'))
$schematronIssuesReport = analyzeSchematronIssues($mpdvalidator);
#copy($main_dir . "/" . $featurelist_log_html, $session_dir . '/' . $featurelist_log_html);
createMpdFeatureList($mpd_dom, $schematronIssuesReport);
convertToHtml();
chdir('../');
return array(!$exit, $string);
}
function download_schema(){
global $session_id, $schema_url, $dvb_conformance, $dvb_conformance_2018, $dvb_conformance_2019, $low_latency_dashif_conformance;
$default_schema_loc = 'schemas/DASH-MPD.xsd';
if($dvb_conformance && $dvb_conformance_2018) {
$default_schema_loc = 'schemas/DASH-MPD-2nd.xsd';
}
elseif($dvb_conformance && $dvb_conformance_2019) {
$default_schema_loc = 'schemas/DASH-MPD-4th-amd1.xsd';
}
elseif($low_latency_dashif_conformance) {
$default_schema_loc = 'schemas/DASH-MPD-4th-amd1.xsd';
}
if($schema_url == '') {
return $default_schema_loc;
}
if(pathinfo($schema_url, PATHINFO_EXTENSION) != 'xsd'){
return $default_schema_loc;
}
$saveTo = "schemas/DASH-MPD_CustomSchema_$session_id.xsd";
$fp = fopen($saveTo, 'w+');
if($fp === FALSE){
return NULL;
}
$ch = curl_init($schema_url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_exec($ch);
if(curl_errno($ch)){
return NULL;
}
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
fclose($fp);
if($statusCode == 200){
//
} else{
delete_schema($saveTo);
return $default_schema_loc;
}
chmod($saveTo, 0777);
return $saveTo;
}
function delete_schema($dash_schema_location){
global $session_id;
if($dash_schema_location === "schemas/DASH-MPD_CustomSchema_$session_id.xsd")
shell_exec("sudo rm $dash_schema_location");
}
function extract_relevant_text($result){
$needle = 'Start XLink resolving';
$temp_result = str_replace('[java]', "", $result);
return substr($temp_result, strpos($temp_result, $needle));
}
function is_valid($haystack, $needle){
return strpos($haystack, $needle) !== FALSE;
}
function MPD_report($string){
global $session_dir, $progress_report, $progress_xml, $mpd_url, $mpd_log, $string_info;
## Save results to progress report
$progress_xml->MPDConformance = $string;
$progress_xml->MPDConformance->addAttribute('url', str_replace($_SERVER['DOCUMENT_ROOT'], 'http://' . $_SERVER['SERVER_NAME'], $session_dir . '/' . $mpd_log . '.txt'));
$progress_xml->MPDConformance->addAttribute('MPDLocation', $mpd_url);
$progress_xml->asXml(trim($session_dir . '/' . $progress_report));
## Put the report in html
$temp_string = str_replace(array('$Template$'), array("mpdreport"), $string_info);
file_put_contents($session_dir . '/' . $mpd_log . '.html', $temp_string);
}