Skip to content

Commit

Permalink
Add timeouts and some basic "HEALTH" checks on segment validator.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phencys committed Nov 18, 2022
1 parent 7f54b79 commit c0e6ef0
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 12 deletions.
29 changes: 23 additions & 6 deletions DASH/processMPD.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function process_MPD($parseSegments = false)
## If only MPD validation is requested or inferred, stop
## If any error is found in the MPD validation process, stop
## If no error is found, then proceed with segment validation below
//$valid_mpd = validate_MPD();
// $valid_mpd = validate_MPD();



Expand All @@ -64,16 +64,17 @@ function process_MPD($parseSegments = false)
}

if (!$parseSegments) {
fwrite(STDERR,($parseSegments ? "DO " : "DO NOT ") . "parse segments\n");
fwrite(STDERR, ($parseSegments ? "DO " : "DO NOT ") . "parse segments\n");
return;
}

//------------------------------------------------------------------------//
## Perform Segment Validation for each representation in each adaptation set within the current period
if (!checkBeforeSegmentValidation()) {
return;
return;
}
if ($mpd_features['type'] !== 'dynamic') {
$mpdHandler->selectPeriod(0);
$current_period = 0;
}
while ($current_period < sizeof($mpd_features['Period'])) {
Expand Down Expand Up @@ -111,13 +112,19 @@ function processAdaptationSetOfCurrentPeriod($period, $ResultXML, $segment_urls)

$adaptation_sets = $period['AdaptationSet'];
while ($current_adaptation_set < sizeof($adaptation_sets)) {
if ($logger->getModuleVerdict("HEALTH") == "FAIL") {
break;
}
$adaptation_set = $adaptation_sets[$current_adaptation_set];
$representations = $adaptation_set['Representation'];

$adaptationDirectory = $session->getAdaptationDir($current_period, $current_adaptation_set);


while ($current_representation < sizeof($representations)) {
if ($logger->getModuleVerdict("HEALTH") == "FAIL") {
break;
}
$representation = $representations[$current_representation];
$segment_url = $segment_urls[$current_adaptation_set][$current_representation];

Expand All @@ -131,7 +138,12 @@ function processAdaptationSetOfCurrentPeriod($period, $ResultXML, $segment_urls)
}
}

$logger->setModule("HEALTH");
validate_segment($adaptationDirectory, $representationDirectory, $period, $adaptation_set, $representation, $segment_url, $is_subtitle_rep);
$logger->write();
if ($logger->getModuleVerdict("HEALTH") == "FAIL") {
break;
}

foreach ($modules as $module) {
if ($module->isEnabled()) {
Expand All @@ -141,6 +153,9 @@ function processAdaptationSetOfCurrentPeriod($period, $ResultXML, $segment_urls)

$current_representation++;
}
if ($logger->getModuleVerdict("HEALTH") == "FAIL") {
break;
}

## Representations in current Adaptation Set finished
crossRepresentationProcess();
Expand All @@ -155,10 +170,12 @@ function processAdaptationSetOfCurrentPeriod($period, $ResultXML, $segment_urls)
$current_adaptation_set++;
}

if ($logger->getModuleVerdict("HEALTH") != "FAIL") {
## Adaptation Sets in current Period finished
foreach ($modules as $module) {
if ($module->isEnabled()) {
$module->hookAdaptationSet();
foreach ($modules as $module) {
if ($module->isEnabled()) {
$module->hookAdaptationSet();
}
}
}
//err_file_op(2);
Expand Down
9 changes: 8 additions & 1 deletion Utils/moduleLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public function setModule($moduleName)
$this->currentHook = '';
}

public function getModuleVerdict($moduleName){
if (!array_key_exists($moduleName, $this->entries)) {
return "PASS";
}
return $this->entries[$moduleName]['verdict'];
}

public function setHook($hookName)
{
$this->currentHook = $hookName;
Expand Down Expand Up @@ -243,7 +250,7 @@ public function hasFeature($feature)
return false;
}

private function write()
public function write()
{
$this->entries['Stats']['LastWritten'] = date("Y-m-d h:i:s");
file_put_contents($this->logfile, \json_encode($this->asArray()));
Expand Down
63 changes: 58 additions & 5 deletions Utils/segment_validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ function run_backend($configFile, $representationDirectory = "")

$sessionDirectory = $session->getDir();

fwrite(STDERR, "Going to run segment validator with config file $configFile\n");

## Select the executable version
## Copy segment validation tool to session folder
Expand All @@ -188,14 +187,68 @@ function run_backend($configFile, $representationDirectory = "")
chmod("$sessionDirectory/$validatemp4", 0777);

## Execute backend conformance software
$command = "$sessionDirectory/$validatemp4 -logconsole -atomxml -configfile " . $configFile;
$command = "timeout -k 30s 30s $sessionDirectory/$validatemp4 -logconsole -atomxml -configfile " . $configFile;
$output = [];
$returncode = 0;
chdir($sessionDirectory);
exec($command, $output, $returncode);

if ($representationDirectory != "") {
rename("$sessionDirectory/atominfo.xml", "$representationDirectory/atomInfo.xml");

$t = time();
exec($command, $output, $returncode);
$et = time();

$moveAtom = true;

$moveAtom &= $logger->test(
"Health Checks",
"Segment Validation",
"ISOSegmentValidator runs successful",
$returncode == 0,
"FAIL",
"Ran succesful on $configFile; took ". ($et - $t) . "seconds",
"Issues with $configFile; Returncode $returncode; took " . ($et - $t) . " seconds"
);

$moveAtom &= $logger->test(
"Health Checks",
"Segment Validation",
"AtomInfo written",
file_exists("$sessionDirectory/atominfo.xml"),
"FAIL",
"Atominfo for $representationDirectory exists",
"Atominfo for $representationDirectory missing"
);

$xml = get_DOM("$sessionDirectory/atominfo.xml", 'atomlist');
$moveAtom &= $logger->test(
"Health Checks",
"Segment Validation",
"AtomInfo contains valid xml",
$xml !== false,
"FAIL",
"Atominfo for $representationDirectory has valid xml",
"Atominfo for $representationDirectory has invalid xml"
);

$moveAtom &= $logger->test(
"Health Checks",
"Segment Validation",
"AtomInfo < 100Mb",
filesize("$sessionDirectory/atominfo.xml") < (100 * 1024 * 1024),
"FAIL",
"Atominfo for $representationDirectory < 100Mb",
"Atominfo for $representationDirectory is ". filesize("$sessionDirectory/atominfo.xml")
);


if (!$moveAtom){
fwrite(STDERR, "Ignoring atomfile for $representationDirectory\n");
unlink("$sessionDirectory/atominfo.xml");
}else{
fwrite(STDERR, "Using atomfile for $representationDirectory\n");
if ($representationDirectory != "") {
rename("$sessionDirectory/atominfo.xml", "$representationDirectory/atomInfo.xml");
}
}

return $returncode;
Expand Down

0 comments on commit c0e6ef0

Please sign in to comment.