Skip to content

Commit

Permalink
Coverage test for Live
Browse files Browse the repository at this point in the history
  • Loading branch information
Phencys committed Jul 5, 2024
1 parent 07dfefe commit 689e137
Show file tree
Hide file tree
Showing 12 changed files with 246 additions and 112 deletions.
33 changes: 23 additions & 10 deletions HbbTV_DVB/impl/mpdUpdateConstraints.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,51 @@
$features = $mpd->getFeatures();
$nextFeatures = $nextMpd->getFeatures();

$logger->test(
$spec,
$section,
"MPD update is succesful",
$features && $nextFeatures,
"FAIL",
"We have valid features on both original and updated MPD",
"Either the original or updated MPD is invalid"
);
if (!$features || !$nextFeatures) {
return;
}


$logger->test(
$spec,
$section,
"The attribute MPD@timeShiftBufferDepth shall not change.",
$features["timeShiftBufferDepth"] == $nextFeatures["timeShiftBufferDepth"],
$mpd->getFeature("timeShiftBufferDepth") == $nextMpd->getFeature("timeShiftBufferDepth"),
"FAIL",
"MPD@timeShiftBufferDepth did not change",
"MPD@timeShiftBufferDepth did change (" . $features["timeShiftBufferDepth"] . " -> " .
$nextFeatures["timeShiftBufferDepth"] . ")"
"MPD@timeShiftBufferDepth did change (" . $mpd->getFeature("timeShiftBufferDepth") . " -> " .
$nextMpd->getFeature("timeShiftBufferDepth") . ")"
);

$logger->test(
$spec,
$section,
"The attribute MPD@availabilityStartTime shall not change.",
$features["availabilityStartTime"] == $nextFeatures["availabilityStartTime"],
$mpd->getFeature("availabilityStartTime") == $nextMpd->getFeature("availabilityStartTime"),
"FAIL",
"MPD@availabilityStartTime did not change",
"MPD@availabilityStartTime did change (" . $features["availabilityStartTime"] . " -> " .
$nextFeatures["availabilityStartTime"] . ")"
"MPD@availabilityStartTime did change (" . $mpd->getFeature("availabilityStartTime") . " -> " .
$nextMpd->getFeature("availabilityStartTime") . ")"
);

$logger->test(
$spec,
$section,
"The attribute MPD@maxSegmentDuration shall not change to a larger duration.",
$features["maxSegmentDuration"] >= $nextFeatures["maxSegmentDuration"],
$mpd->getFeature("maxSegmentDuration") <= $nextMpd->getFeature("maxSegmentDuration"),
"FAIL",
"Next MPD@maxSegmentDuration smaller or equal",
"MPD@maxSegmentDuration increased (" . $features["maxSegmentDuration"] . " -> " .
$nextFeatures["maxSegmentDuration"] . ")"
"MPD@maxSegmentDuration increased (" . $mpd->getFeature("maxSegmentDuration") . " -> " .
$nextMpd->getFeature("maxSegmentDuration") . ")"
);

$originalPeriods = $mpd->getPeriodIds();
Expand Down Expand Up @@ -70,7 +83,7 @@
$section,
"Period@id and @start for the same period and when MPD@type='dynamic' shall not change.",
$mpd->getPeriodAttribute($origIndex, "start") ==
$nextMpd->getPeriodAttribute($nextIndex, "start"),
$nextMpd->getPeriodAttribute($nextIndex, "start"),
"FAIL",
"Period@start for Period@id $origId identical",
"Period@start for Period@id $origId differs"
Expand Down
8 changes: 4 additions & 4 deletions HbbTV_DVB/impl/mpdUpdateConstraintsWithinAdaptationSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
$periodId = $mpd->getPeriodAttribute($periodIndex, 'id');
$nextPeriodId = $nextMpd->getPeriodAttribute($nextPeriodIndex, 'id');

$adaptationId = $mpd->getRepresentationAttribute($periodIndex, $adaptationIndex, 'id');
$nextAdaptationId = $nextMpd->getRepresentationAttribute($nextPeriodIndex, $nextAdaptationIndex, 'id');
$adaptationId = $mpd->getAdaptationSetAttribute($periodIndex, $adaptationIndex, 'id');
$nextAdaptationId = $nextMpd->getAdaptationSetAttribute($nextPeriodIndex, $nextAdaptationIndex, 'id');

$originalRepresentations = $mpd->getRepresentationSetIds($periodId, $adaptationId);
$nextRepresentations = $nextMpd->getRepresentationSetIds($nextPeriodId, $nextAdaptationId);
$originalRepresentations = $mpd->getRepresentationIds($periodId, $adaptationId);
$nextRepresentations = $nextMpd->getRepresentationIds($nextPeriodId, $nextAdaptationId);

$identicalMsg = "within period $periodId and adaptation $adaptationId identical";
$differentMsg = "within period $periodId and adaptation $adaptationId differs";
Expand Down
14 changes: 8 additions & 6 deletions HbbTV_DVB/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function __construct()
$this->HbbTvEnabled = false;
$this->DVBEnabled = false;

$this->hasJPGraph = include_once __DIR__ . '/../external/jpgraph/src/jpgraph.php';
$this->hasJPBarGraph = include_once __DIR__ . '/../external/jpgraph/src/jpgraph_bar.php';
$this->hasJPGraph = false;//include_once __DIR__ . '/../external/jpgraph/src/jpgraph.php';
$this->hasJPBarGraph = false;//include_once __DIR__ . '/../external/jpgraph/src/jpgraph_bar.php';
}
public function isEnabled()
{
Expand Down Expand Up @@ -70,9 +70,11 @@ public function setEnabled($newVal)
protected function addCLIArguments()
{
global $argumentParser;
$argumentParser->addOption("hbbtv", "H", "hbbtv", "Enable HBBTV checking");
$argumentParser->addOption("dvb", "D", "dvb", "Enable DVB checking (2018 xsd)");
$argumentParser->addOption("dvb2019", "", "dvb_2019", "Enable DVB checking (2019 xsd)");
if ($argumentParser){
$argumentParser->addOption("hbbtv", "H", "hbbtv", "Enable HBBTV checking");
$argumentParser->addOption("dvb", "D", "dvb", "Enable DVB checking (2018 xsd)");
$argumentParser->addOption("dvb2019", "", "dvb_2019", "Enable DVB checking (2019 xsd)");
}
}

public function handleArguments()
Expand Down Expand Up @@ -100,7 +102,7 @@ public function hookLiveMpd($mpd, $nextMpd)
$this->mpdUpdateConstraints($mpd, $nextMpd);
}

private function mpdUpdateConstraints($mpd, $nextMpd)
public function mpdUpdateConstraints($mpd, $nextMpd)
{
include 'impl/mpdUpdateConstraints.php';
}
Expand Down
90 changes: 90 additions & 0 deletions HbbTV_DVB/test/liveUpdateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

use PHPUnit\Framework\TestCase;

require_once __DIR__ . '/../module.php';
require_once __DIR__ . '/../../Utils/moduleLogger.php';

$mpdLead = '<?xml version="1.0" encoding="UTF-8"?>
<MPD type="dynamic" minimumUpdatePeriod="PT2.0S" availabilityStartTime="2024-07-05T06:50:32" timeShiftBufferDepth="PT1M23.560S" suggestedPresentationDelay="PT5.0S" minBufferTime="PT2.0S" publishTime="2024-07-05T06:52:35" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="urn:mpeg:DASH:schema:MPD:2011 http://standards.iso.org/ittf/PubliclyAvailableStandards/MPEG-DASH_schema_files/DASH-MPD.xsd" profiles="urn:mpeg:dash:profile:isoff-live:2011" xmlns="urn:mpeg:dash:schema:mpd:2011" >';
$mpdClose = '</MPD>';

$periodNoId = '<Period start="PT0.0S">';
$periodWithId = '<Period id="1" start="PT0.0S">';
$periodClose = '</Period>';


$videoAdaptationSet = '<AdaptationSet group="1" mimeType="video/mp4" width="800" height="600" frameRate="25" segmentAlignment="true" id="0" startWithSAP="1" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
<SegmentTemplate timescale="1000" media="$RepresentationID$/chunk_$Time$.m4s" initialization="$RepresentationID$/init.m4s"><SegmentTimeline>
<S t="60023" d="10000" />
<S d="10000" />
<S d="10000" />
<S d="10000" />
<S d="10000" />
<S d="10000" />
</SegmentTimeline></SegmentTemplate>
<Representation id="0" bandwidth="169920" codecs="avc1.42c01e" /></AdaptationSet>';

$audioAdaptationSet = '<AdaptationSet group="2" mimeType="audio/mp4" segmentAlignment="true" id="1" startWithSAP="1" subsegmentAlignment="true" subsegmentStartsWithSAP="1">
<SegmentTemplate timescale="1000" media="$RepresentationID$/chunk_$Time$.m4s" initialization="$RepresentationID$/init.m4s"><SegmentTimeline>
<S t="60023" d="10000" />
<S d="10000" />
<S d="10000" />
<S d="10000" />
<S d="10000" />
<S d="10000" />
</SegmentTimeline></SegmentTemplate>
<Representation id="1" bandwidth="72312" codecs="mp4a.40.2" audioSamplingRate="44100"> <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="1" /></Representation>
</AdaptationSet>';


$mpdOnly = "${mpdLead}${mpdClose}";

$noPeriodId = "${mpdLead}${periodNoId}${videoAdaptationSet}${audioAdaptationSet}${periodClose}${mpdClose}";
$withPeriodId = "${mpdLead}${periodWithId}${videoAdaptationSet}${audioAdaptationSet}${periodClose}${mpdClose}";


class LiveUpdateTestModule extends DASHIF\ModuleHbbTVDVB
{
public function __construct()
{
parent::__construct();
}
}

final class HbbTVLiveUpdateTest extends TestCase
{
protected function setUp(): void
{
$GLOBALS['logger'] = new DASHIF\ModuleLogger();
$this->module = new LiveUpdateTestModule();
}



public function caseProvider(){
global $mpdOnly;
global $noPeriodId, $withPeriodId;
return [
[null, null, 'FAIL'],
[$mpdOnly, $mpdOnly, 'PASS'],
[$noPeriodId, $noPeriodId, 'FAIL'],
[$withPeriodId, $withPeriodId, 'PASS']
];
}


/**
* @dataProvider caseProvider
* @large
*/
public function testMPD($mpdContent1, $mpdContent2, $expectedResult): void
{
$mpd1 = new DASHIF\MPDHandler(null);
$mpd2 = new DASHIF\MPDHandler(null);
$mpd1->refresh($mpdContent1);
$mpd2->refresh($mpdContent2);
$this->module->mpdUpdateConstraints($mpd1, $mpd2);
$this->assertEquals($expectedResult, $GLOBALS['logger']->asArray()['verdict']);
}
}
46 changes: 39 additions & 7 deletions Utils/MPDHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function __construct($url)
$this->segmentUrls = array();

$this->load();
$this->parseXML();
if ($this->mpd) {
$this->features = $this->recursiveExtractFeatures($this->dom);
$this->extractProfiles();
Expand All @@ -57,18 +58,26 @@ public function __construct($url)
}
}

public function refresh()

public function refresh($content = null)
{
$tmpMpd = $this->mpd;
$this->load();
if (!$content) {
$this->load();
} else {
$this->mpd = $content;
}
$this->parseXML();
if ($this->mpd == $tmpMpd) {
return false;
}
$this->features = $this->recursiveExtractFeatures($this->dom);
$this->extractProfiles();
$this->runSchematron();
$this->validateSchematron();
$this->loadSegmentUrls();
if (!$content) {
$this->runSchematron();
$this->validateSchematron();
$this->loadSegmentUrls();
}
return true;
}

Expand All @@ -79,16 +88,27 @@ public function getEarliestUpdate(): \DateTimeImmutable | null

public function getPeriodAttribute($idx, $attr): string | null
{
if (!array_key_exists($attr, $this->features["Period"][$idx])) {
return null;
}
return $this->features["Period"][$idx][$attr];
}

public function getAdaptationSetAttribute($idx, $aIdx, $attr): string | null
{
return $this->features["Period"][$idx]["AdaptationSet"][$aIdx][$attr];
$adaptationSetFeatures = $this->features["Period"][$idx]["AdaptationSet"][$aIdx];
if (!array_key_exists($attr, $adaptationSetFeatures)) {
return null;
}
return $adaptationSetFeatures[$attr];
}
public function getRepresentationAttribute($idx, $aIdx, $rIdx, $attr): string | null
{
return $this->features["Period"][$idx]["AdaptationSet"][$aIdx]['Representation'][$rIdx][$attr];
$representationFeatures = $this->features["Period"][$idx]["AdaptationSet"][$aIdx]['Representation'][$rIdx];
if (!array_key_exists($attr, $representationFeatures)) {
return null;
}
return $representationFeatures[$attr];
}


Expand Down Expand Up @@ -267,6 +287,11 @@ private function load()
include 'impl/MPDHandler/load.php';
}

private function parseXML()
{
include 'impl/MPDHandler/parseXML.php';
}

public function getUrl()
{
return $this->url;
Expand All @@ -292,6 +317,13 @@ public function getFeatures()
{
return $this->features;
}
public function getFeature($featureName)
{
if (!array_key_exists($featureName, $this->features)) {
return null;
}
return $this->features[$featureName];
}

public function getProfiles()
{
Expand Down
3 changes: 3 additions & 0 deletions Utils/impl/MPDHandler/extractProfiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
if (!$this->features) {
return;
}
if (!array_key_exists("Period", $this->features)) {
return;
}

$this->profiles = array();
$periods = $this->features['Period'];
Expand Down
4 changes: 2 additions & 2 deletions Utils/impl/MPDHandler/getRepresentationIds.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
if (!$a->hasAttribute("id")) {
continue;
}
if ($adaptationId != $a->getAttribute("id")) {
if ($adaptationSetId != $a->getAttribute("id")) {
continue;
}
$representationElements = $a->getElementsByTagName("Representaion");
$representationElements = $a->getElementsByTagName("Representation");
foreach ($representationElements as $r) {
if ($r->hasAttribute("id")) {
$result[] = $r->getAttribute("id");
Expand Down
39 changes: 4 additions & 35 deletions Utils/impl/MPDHandler/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
}

if ($this->url && $this->url != '') {
if ($isLocal){
$this->mpd = file_get_contents($localManifestLocation);
}else{
$this->mpd = file_get_contents($this->url);
if ($isLocal) {
$this->mpd = file_get_contents($localManifestLocation);
} else {
$this->mpd = file_get_contents($this->url);
}
} elseif (isset($_REQUEST['mpd'])) {
$this->mpd = $_REQUEST['mpd'];
Expand All @@ -36,34 +36,3 @@
if (!$this->mpd) {
return;
}

$simpleXML = simplexml_load_string($this->mpd);
if (!$simpleXML) {
fwrite(STDERR, "Invalid xml string as mpd\n");
fwrite(STDERR, "$this->mpd\n");
return;
}

$domSxe = dom_import_simplexml($simpleXML);
if (!$domSxe) {
fwrite(STDERR, "Unable to import xml");
return;
}

$dom = new \DOMDocument('1.0');
$domSxe = $dom->importNode($domSxe, true);
if (!$domSxe) {
return;
}

$dom->appendChild($domSxe);
$main_element_nodes = $dom->getElementsByTagName('MPD');
if ($main_element_nodes->length == 0) {
fwrite(STDERR, "No MPD in xml");
$this->dom = null;
return;
}

fwrite(STDERR, "Valid mpd\n");

$this->dom = $main_element_nodes->item(0);
Loading

0 comments on commit 689e137

Please sign in to comment.