forked from Dash-Industry-Forum/DASH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMPDFeatures.php
executable file
·73 lines (64 loc) · 2.28 KB
/
MPDFeatures.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
<?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/>.
*/
###############################################################################
/*
* This PHP script is responsible for MPD feature extracting.
* @name: MPDFeatures.php
* @entities:
* @functions{
* MPD_features($mpd_xml),
* extract_features($xml),
* is_element($element)
* }
*/
###############################################################################
/*
* Extract the features of MPD from $mpd_xml
* @name: MPD_features
* @input: $mpd_xml - DOM XML of the MPD, to extract the attributes
* @output: array version of the provided $mpd_xml
*/
function MPD_features($mpd_xml){
return extract_features($mpd_xml);
}
/*
* Recursively extract the features of MPD from $mpd_xml and store into an array
* @name: extract_features
* @input: $xml - The MPD XML file
* @output: array of MPD
*/
function extract_features($xml){
$array = array();
$attributes = $xml->attributes;
$children = $xml->childNodes;
foreach($attributes as $attribute)
$array[$attribute->nodeName] = $attribute->nodeValue;
foreach($children as $child){
if(is_element($child))
$array[$child->nodeName][] = extract_features($child);
if($child->nodeName == 'BaseURL')
$array['BaseURL'][sizeof($array['BaseURL'])-1]['anyURI'] = $child->firstChild->nodeValue;
}
return $array;
}
/*
* Check if the node is a DOM ELEMENT node
* @name: is_element
* @input: $element - DOMNode to be checked
* @output: true or false
*/
function is_element($element){
if(!empty($element->nodeName) && $element->nodeType == XML_ELEMENT_NODE)
return true;
return false;
}