Skip to content

Commit

Permalink
Fixed errors and warnings triggered by issue #707
Browse files Browse the repository at this point in the history
  • Loading branch information
Phencys committed Sep 16, 2024
1 parent a064931 commit 226213d
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 86 deletions.
10 changes: 5 additions & 5 deletions HbbTV_DVB/impl/dvbAudioChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@

if ($role->getAttribute('value') == 'main') {
$this->mainAudioFound = true;
$this->mainAudios[] = $adaptations;
$this->mainAudios[] = $adaptation;
}
}
}

$accesibilityRoles = array();
$accesibilities = $adaptation->getElementsByTagName("Accessibility");
foreach ($accesibilities as $accesibility) {
$accessibilityRoles = array();
$accessibilities = $adaptation->getElementsByTagName("Accessibility");
foreach ($accessibilities as $accessibility) {
if ($accessibility->getAttribute('schemeIdUri') == 'urn:tva:metadata:cs:AudioPurposeCS:2007') {
$accessibilityRoles[] = $accesibility->getAttribute('value');
$accessibilityRoles[] = $accessibility->getAttribute('value');
}
}

Expand Down
2 changes: 1 addition & 1 deletion HbbTV_DVB/impl/dvbEventChecks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
if ($eventStream->getAttribute('schemeIdUri') != 'urn:dvb:iptv:cpm:2014') {
return;
}
if ($eventStream->getAttribute('value') = '1') {
if ($eventStream->getAttribute('value') != '1') {
return;
}

Expand Down
21 changes: 11 additions & 10 deletions HbbTV_DVB/impl/dvbMPDValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function ($v, $k) {
if ($child->nodeName == 'EventStream') {
$this->dvbEventChecks($child);
}
if ($child->nodename == 'SegmentTemplate') {
if ($child->nodeName == 'SegmentTemplate') {
if (DASHIF\Utility\mpdContainsProfile('urn:dvb:dash:profile:dvb-dash:isoff-ext-on-demand:2014')) {
$invalidSegmentTemplateFound = true;
}
Expand Down Expand Up @@ -250,8 +250,8 @@ function ($v, $k) {
$adaptationSetProfileExists,
"WARN",
"Check succeeded",
"Check failed: Contains clause 4.1: " . ($adaptationSetContainsDVBDash ? "Yes" : "No") .
", contains either 4.2.5 or 4.2.8: " . ($adaptationSetContainsExtension ? "Yes" : "No"),
"Check failed: Contains clause 4.1: " . ($adaptationContainsDVBDash ? "Yes" : "No") .
", contains either 4.2.5 or 4.2.8: " . ($adaptationContainsExtension ? "Yes" : "No"),
);

$representations = $adaptationSet->getElementsByTagName("Representation");
Expand All @@ -270,7 +270,7 @@ function ($v, $k) {
$videoComponentFound = false;
$audioComponentFound = false;

if ($ch) {
if (isset($ch) && $ch) {
$contentComponents = $ch->getElementsByTagName("ContentComponent");
foreach ($contentComponents as $component) {
$contentType = $component->getAttribute("contentType");
Expand Down Expand Up @@ -393,18 +393,18 @@ function ($v, $k) {
"$this->adaptationVideoCount adaptations found, none labeled as main for period $this->periodCount"
);

$this->dvbContentProtection($adaptationSet, $representations, $i, $cenc);
$this->dvbContentProtection($adaptationSet, $representations, $i, $cencAttribute);
}

if ($hasVideoService) {
$this->streamBandwidthCheck();
}

if ($audioAdaptations->length > 1) {
if (count($audioAdaptations) > 1) {
$this->fallbackOperationChecks($audioAdaptations);
}

if ($mainAudioFound && !empty($hoh_subtitle_lang)) {
if ($this->mainAudioFound && !empty($hoh_subtitle_lang)) {
$mainLanguage = array();
foreach ($main_audios as $main_audio) {
if ($main_audio->getAttribute('lang') != '') {
Expand Down Expand Up @@ -443,13 +443,14 @@ function ($v, $k) {

$this->dvbAssociatedAdaptationSetsCheck();

$audioCount = count($audioAdaptations);
$logger->test(
"HbbTV-DVB DASH Validation Requirements",
"DVB: Section 6.1.2",
"If there is more than one audio Adaptation Set in a DASH Presentation then at least one of them SHALL be " .
"tagged with an @value set to \"main\"",
$audioAdaptations->length <= 1 || $this->mainAudioFound,
$audioCount <= 1 || $this->mainAudioFound,
"FAIL",
"$audioAdaptations->length adaptation(s) found with main label if needed in Presentation",
"$audioAdaptations->length adaptations found but none of them are labeled as main in Presentation"
"$audioCount adaptation(s) found with main label if needed in Presentation",
"$audioCount adaptations found but none of them are labeled as main in Presentation"
);
3 changes: 3 additions & 0 deletions HbbTV_DVB/impl/dvbMpdAnchorCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
global $mpdHandler, $logger;
$allowedKeys = array('t', 'period', 'track', 'group');

if (!array_key_exists("urlcode", $_POST)) {
return;
}
$anchors = explode('#', json_decode($_POST['urlcode'])[0]);
if (sizeof($anchors) <= 1) {
return;
Expand Down
2 changes: 1 addition & 1 deletion HbbTV_DVB/impl/fallbackOperationChecks.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

$adaptationCount = sizeof($audioAdaptations);
for ($i = 0; $i < $len; $i++) {
for ($i = 0; $i < $adaptationCount; $i++) {
$adaptation = $audioAdaptations[$i];
$supplementalProperties = $adaptation->getElementsByTagName('SupplementalProperty');

Expand Down
4 changes: 2 additions & 2 deletions HbbTV_DVB/impl/mpdUpdateConstraintsWithinPeriod.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
$spec,
$section,
"A Role Element " . $shallNotChangeInPeriod,
$mpd->getAdaptationSetAttribute($periodIndex, $origIndex, "Role") ==
$nextMpd->getAdaptationSetAttribute($nextPeriodIndex, $nextIndex, "Role"),
$mpd->getAdaptationSetChild($periodIndex, $origIndex, "Role") ==
$nextMpd->getAdaptationSetChild($nextPeriodIndex, $nextIndex, "Role"),
"FAIL",
"Role for AdaptationSet@id $origId within period $periodId identical",
"Role for AdaptationSet@id $origId within period $periodId differs"
Expand Down
27 changes: 14 additions & 13 deletions Utils/ArgumentsParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function parseAll()
$this->parsedOptions = getopt($this->getShortOpts(), $this->getLongOpts(), $restidx);

global $argv;
if ($argv){
$this->extraArguments = array_slice($argv, $restidx);
if ($argv) {
$this->extraArguments = array_slice($argv, $restidx);
}


Expand All @@ -37,21 +37,22 @@ public function parseAll()

public function getOption($name)
{
if ($_REQUEST[$name]) {
if (array_key_exists($name, $_REQUEST) && $_REQUEST[$name]) {
return true;
}
if ($this->parsedOptions){
foreach ($this->allOptions as $option) {
if ($option->label == $name) {
if (
array_key_exists($option->short[0], $this->parsedOptions) ||
array_key_exists($option->long, $this->parsedOptions)
) {
return true;
if ($this->parsedOptions) {
foreach ($this->allOptions as $option) {
if ($option->label == $name) {
if (
(strlen($option->short) > 0 &&
array_key_exists($option->short[0], $this->parsedOptions)) ||
array_key_exists($option->long, $this->parsedOptions)
) {
return true;
}
}
}
}
}
return false;
}

Expand Down Expand Up @@ -80,7 +81,7 @@ public function addOption($label, $short, $long, $desc)

public function getPositionalArgument($argname)
{
if ($argname == "url" && $_REQUEST["url"]) {
if ($argname == "url" && array_key_exists("url", $_REQUEST) && $_REQUEST["url"]) {
return urldecode($_REQUEST["url"]);
}
switch ($argname) {
Expand Down
13 changes: 10 additions & 3 deletions Utils/MPDHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ public function getAdaptationSetAttribute($idx, $aIdx, $attr): string | null
}
return $adaptationSetFeatures[$attr];
}
public function getAdaptationSetChild($idx, $aIdx, $childName)
{
$adaptationSetFeatures = $this->features["Period"][$idx]["AdaptationSet"][$aIdx];
if (!array_key_exists($childName, $adaptationSetFeatures)) {
return null;
}
return $adaptationSetFeatures[$childName];
}
public function getRepresentationAttribute($idx, $aIdx, $rIdx, $attr): string | null
{
$representationFeatures = $this->features["Period"][$idx]["AdaptationSet"][$aIdx]['Representation'][$rIdx];
Expand Down Expand Up @@ -156,7 +164,7 @@ public function getRepresentationIds($periodId, $adaptationSetId)
{
return include 'impl/MPDHandler/getRepresentationIds.php';
}


public function selectPeriod($period)
{
Expand Down Expand Up @@ -229,7 +237,7 @@ private function recursiveExtractFeatures($node)

public function getPeriodTimingInfo($periodIndex = null)
{
return include 'impl/MPDHandler/getPeriodTimingInfo.php';
return $this->getPeriodDurationInfo($periodIndex ? $periodIndex : $this->selectedPeriod);
}

private function getPeriodDurationInfo($period)
Expand Down Expand Up @@ -321,7 +329,6 @@ public function getMPD()
return $this->mpd;
}


public function getDom()
{
return $this->dom;
Expand Down
6 changes: 3 additions & 3 deletions Utils/MPDUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function in_array_at_least_one($options, $array)
function isAbsoluteURL($URL)
{
$parsedUrl = parse_url($URL);
return $parsedUrl['scheme'] && $parsedUrl['host'];
return array_key_exists("scheme", $parsedUrl) && array_key_exists("host", $parsedUrl);
}

function inString($option, $string)
Expand Down Expand Up @@ -163,9 +163,9 @@ function mergeSegmentAccess($highLevel, $lowLevel)
function formSegmentAccess($highLevel, $lowLevel)
{
foreach ($highLevel as $key => $highValue) {
$lowValue = $lowLevel[$key];
$lowValue = array_key_exists($key, $lowLevel) ? $lowLevel[$key] : array();
foreach ($highValue as $k => $v) {
if (!$lowValue[$k]) {
if (!array_key_exists($k, $lowValue) || !$lowValue[$k]) {
$lowValue[$k] = $v;
} elseif (gettype($lowValue[$k]) == 'array') {
//$v would also work, but this is more clear in meaning
Expand Down
19 changes: 9 additions & 10 deletions Utils/Process_cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
*/


if(!defined('STDIN')) define('STDIN', fopen('php://stdin', 'rb'));
if(!defined('STDOUT')) define('STDOUT', fopen('php://stdout', 'wb'));
if(!defined('STDERR')) define('STDERR', fopen('php://stderr', 'wb'));
if (!defined('STDIN')) {
define('STDIN', fopen('php://stdin', 'rb'));
}
if (!defined('STDOUT')) {
define('STDOUT', fopen('php://stdout', 'wb'));
}
if (!defined('STDERR')) {
define('STDERR', fopen('php://stderr', 'wb'));
}

ini_set('memory_limit', '-1');
ini_set('display_errors', 'stderr');
Expand All @@ -33,9 +39,6 @@
require __DIR__ . '/moduleInterface.php';
include __DIR__ . '/moduleLogger.php';

include __DIR__ . '/Session.php'; //#Session Functions, No Direct Executable Code
//#Document loading functions, mostly xml. Some assertion options and error initialization
include __DIR__ . '/Load.php';
include __DIR__ . '/FileOperations.php'; //#Filesystem and XML checking functions. No Direct Executable Code.
//#Global variables. Direct evaluation of post/session vars to define conditionals,
//#conditional extra includes for module initialization
Expand Down Expand Up @@ -77,13 +80,9 @@

//#Cross repo includes. These should be made optional at the very least.
include __DIR__ . '/../DASH/processMPD.php';
include __DIR__ . '/../DASH/MPDFeatures.php';
include __DIR__ . '/../DASH/validateMPD.php';
include __DIR__ . '/../DASH/MPDInfo.php';
include __DIR__ . '/../DASH/SchematronIssuesAnalyzer.php';
include __DIR__ . '/../DASH/cross_validation.php';
include __DIR__ . '/../DASH/Representation.php';
include __DIR__ . '/../DASH/SegmentURLs.php';
include __DIR__ . '/../HLS/HLSProcessing.php';
include __DIR__ . '/Featurelist.php';

Expand Down
11 changes: 9 additions & 2 deletions Utils/impl/MPDHandler/computeDynamicIntervals.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
DASHIF\Utility\timeParsing($this->features['timeShiftBufferDepth']) : INF;

$AST = $this->features['availabilityStartTime'];
$segmentduration = 0;
if ($segmentAccess['SegmentTimeline'] != null) {
$segmentduration = ($segmentTimings[$segmentCount - 1] - $segmentTimings[0]) / ((float)($segmentCount - 1));
if (count($segmentTimings) > 1) {
$segmentduration = ($segmentTimings[$segmentCount - 1] - $segmentTimings[0]) / ((float)($segmentCount - 1));
}
} else {
$segmentduration = ($segmentAccess['duration'] != null) ? $segmentAccess['duration'] : 0;
}
$timescale = ($segmentAccess['timescale'] != null) ? $segmentAccess['timescale'] : 1;
$availabilityTimeOffset = ($segmentAccess['availabilityTimeOffset'] != null &&
$availabilityTimeOffset = (array_key_exists("availabilityTimeOffset", $segmentAccess) &&
$segmentAccess['availabilityTimeOffset'] != 'INF') ? $segmentAccess['availabilityTimeOffset'] : 0;

$pto = ($segmentAccess['presentationTimeOffset'] != '') ?
Expand All @@ -40,6 +43,10 @@
$avgsum = array_sum($avgsum) / sizeof($avgsum);
$percent = $avgsum / $sumbandwidth;

if ($segmentduration == 0) {
$segmentduration = 1;
}

$buffercapacity = $bufferduration / $segmentduration; //actual buffer capacity

date_default_timezone_set("UTC"); //Set default timezone to UTC
Expand Down
12 changes: 6 additions & 6 deletions Utils/impl/MPDHandler/computeTiming.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@
$start = 0;

$duration = 0;
if ($segmentAccess['duration'] != null) {
if (array_key_exists("duration", $segmentAccess)) {
$duration = $segmentAccess['duration'];
}

$timescale = 1;
if ($segmentAccess['timescale'] != null) {
if (array_key_exists("timescale", $segmentAccess)) {
$timescale = $segmentAccess['timescale'];
}

$availabilityTimeOffset = 0;
if ($segmentAccess['availabilityTimeOffset'] != null && $segmentAccess['availabilityTimeOffset'] != 'INF') {
if (array_key_exists("availabilityTimeOffset", $segmentAccess) && $segmentAccess['availabilityTimeOffset'] != 'INF') {
$availabilityTimeOffset = $segmentAccess['availabilityTimeOffset'];
}

$presentationTimeOffset = 0;
if ($segmentAccess['presentationTimeOffset'] != '') {
if (array_key_exists("presentationTimeOffset", $segmentAccess) && $segmentAccess['presentationTimeOffset'] != '') {
$presentationTimeOffset = (int)($segmentAccess['presentationTimeOffset']) / $timescale;
}

Expand Down Expand Up @@ -69,11 +69,11 @@
foreach ($segmentEntries as $index => $segmentEntry) {
$d = $segmentEntry['d'];
$r = 0;
if ($segmentEntry['r']) {
if (array_key_exists("r", $segmentEntry)) {
$r = $segmentEntry['r'];
}
$t = 0;
if ($segmentEntry['t']) {
if (array_key_exists("t", $segmentEntry)) {
$t = $segmentEntry['t'];
}
$t -= $timeOffset;
Expand Down
8 changes: 6 additions & 2 deletions Utils/impl/MPDHandler/computeUrls.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
$id = $representation['id'];

$startNumber = 1;
if ($segmentAccess['startNumber'] != null) {
if (array_key_exists("startNumber", $segmentAccess)) {
$startNumber = $segmentAccess['startNumber'];
}

Expand Down Expand Up @@ -44,9 +44,13 @@

///\Todo translate checks below into actual "check"
while ($index < $segmentCount) {
$timeReplace = 0;
if (array_key_exists($currentTime, $segmentInfo)) {
$timeReplace = $segmentInfo[$currentTime];
}
$segmentUrl = str_replace(
array('$Bandwidth$', '$Number$', '$RepresentationID$', '$Time$'),
array($bandwidth, $index + $startNumber, $id, $segmentInfo[$currentTime]),
array($bandwidth, $index + $startNumber, $id, $timeReplace),
$media
);

Expand Down
Loading

0 comments on commit 226213d

Please sign in to comment.