-
Notifications
You must be signed in to change notification settings - Fork 10
/
Representation.php
executable file
·178 lines (150 loc) · 7.95 KB
/
Representation.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?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 construct_flags($period, $adaptation_set, $representation){
global $session_dir, $mpd_features, $dashif_conformance, $low_latency_dashif_conformance, $inband_event_stream_info, $current_period, $current_adaptation_set, $current_representation, $profiles;
## @minimumBufferTime
$timeSeconds = (string) time_parsing($mpd_features['minBufferTime']);
$processArguments = ' -minbuffertime ' . $timeSeconds;
## @bandwidth
$bandwidth = $representation['bandwidth'];
$processArguments .= ' -bandwidth ' . $bandwidth;
## @width
$width = ($adaptation_set['width'] == NULL) ? $representation['width'] : $adaptation_set['width'];
$width = (!$width) ? 0 : $width;
$processArguments .= ' -width ' . $width;
## @height
$height = ($adaptation_set['height'] == NULL) ? $representation['height'] : $adaptation_set['height'];
$height = (!$height) ? 0 : $height;
$processArguments .= ' -height ' . $height;
## @sar
$sar = ($adaptation_set['sar'] == NULL) ? $representation['sar'] : $adaptation_set['sar'];
if($sar != NULL){
$sar_x_y = explode(':', $sar);
$processArguments .= ' -sarx ' . $sar_x_y[0] . ' -sary ' . $sar_x_y[1];
}
## dynamic @type
$dynamic = ($mpd_features['type'] == 'dynamic') ? ' -dynamic' : '';
$processArguments .= $dynamic;
## @startWithSAP
$startWithSAP = ($adaptation_set['startWithSAP'] == NULL) ? $representation['startWithSAP'] : $adaptation_set['startWithSAP'];
if($startWithSAP != NULL)
$processArguments .= ' -startwithsap ' . $startWithSAP;
## @profiles
$ondemand = array('urn:mpeg:dash:profile:isoff-on-demand:2011', 'urn:mpeg:dash:profile:isoff-ext-on-demand:2014', 'http://dashif.org/guidelines/dash-if-ondemand', 'urn:dvb:dash:profile:dvb-dash:isoff-ext-on-demand:2014');
$live = array('urn:mpeg:dash:profile:isoff-live:2011', 'urn:mpeg:dash:profile:isoff-ext-live:2014', 'urn:dvb:dash:profile:dvb-dash:isoff-ext-live:2014');
$main = array('urn:mpeg:dash:profile:isoff-main:2011');
$dash264 = array('http://dashif.org/guidelines/dash264');
$dashif_ondemand = array('http://dashif.org/guidelines/dash-if-ondemand');
$dashif_mixed_ondemand = array('http://dashif.org/guidelines/dash-if-mixed');
$rep_profiles = explode(',', $profiles[$current_period][$current_adaptation_set][$current_representation]);
foreach($rep_profiles as $rep_profile){
if(strpos($rep_profile, ' ') !== FALSE)
$rep_profile = str_replace(' ', '', $rep_profile);
if(in_array($rep_profile, $ondemand))
$processArguments .= ' -isoondemand';
if(in_array($rep_profile, $live))
$processArguments .= ' -isolive';
if(in_array($rep_profile, $main))
$processArguments .= ' -isomain';
if(strpos($rep_profile, $dash264) !== FALSE || $dashif_conformance)
$processArguments .= ' -dash264base';
if(strpos($rep_profile, $dashif_ondemand) !== FALSE)
$processArguments .= ' -dashifondemand';
if(strpos($rep_profile, $dashif_mixed_ondemand) !== FALSE)
$processArguments .= ' -dashifmixed';
}
## ContentProtection
$content_protection_len = (!$adaptation_set['ContentProtection']) ? sizeof($representation['ContentProtection']) : sizeof($adaptation_set['ContentProtection']);
if($content_protection_len > 0 && strpos($processArguments, 'dash264base') !== FALSE)
$processArguments .= ' -dash264enc';
## @codecs
$codecs = ($adaptation_set['codecs'] == NULL) ? $representation['codecs'] : $adaptation_set['codecs'];
if($codecs == NULL)
$codecs = 0;
$processArguments .= ' -codecs ' . $codecs;
## @indexRange
$indexRange = find_attribute(array($period, $adaptation_set, $representation), 'indexRange');
if($indexRange != NULL)
$processArguments .= ' -indexrange ' . $indexRange;
## AudoChannelConfiguration
$audioChannelConfiguration = (empty($adaptation_set['AudioChannelConfiguration'])) ? $representation['AudioChannelConfiguration'][0]['value'] : $adaptation_set['AudioChannelConfiguration'][0]['value'];
$audioChannelConfiguration = ($audioChannelConfiguration == NULL) ? 0 : $audioChannelConfiguration;
$processArguments .= ' -audiochvalue ' . $audioChannelConfiguration;
## RepresentationIndex
$representationIndex = find_attribute(array($period, $adaptation_set, $representation), 'RepresentationIndex');
if($representationIndex != NULL)
$processArguments = $processArguments . " -repIndex";
## ContentProtection
$content_protections = $adaptation_set['ContentProtection'];
if(!empty($content_protections)){
foreach($content_protections as $content_protection){
if($content_protection['cenc:default_KID'])
$default_KID = $content_protection['cenc:default_KID'];
$cencNS="urn:mpeg:cenc:2013:pssh";
$cenc_pssh=$content_protection[$cencNS];
if(!empty($cenc_pssh))
$psshBox[]=$cenc_pssh;
$ContentProtect_arr = array('default_KID' => $default_KID, 'psshBox' => $psshBox);
}
if($default_KID !== null){
$processArguments = $processArguments . " -default_kid ";
$processArguments = $processArguments . $default_KID;
}
$psshCount=sizeof($psshBox);
if($psshCount>0){
$processArguments = $processArguments . " -pssh_count ";
$processArguments = $processArguments . $psshCount;
for($i=0; $i< $psshCount ; $i++){
$psshBox= $psshBox[$i];
$processArguments = $processArguments . " -psshbox ";
$pssh_file_loc=$session_dir."/psshBox".$i.".txt";
$pssh_file=fopen($pssh_file_loc, "w");
fwrite($pssh_file, $psshBox);
fclose($pssh_file);
$processArguments = $processArguments . $pssh_file_loc;
}
}
}
## Inband Event Stream for LL
if($low_latency_dashif_conformance){
$processArguments .= ' -dashifll';
if($inband_event_stream_info[$current_period] !== NULL &&
$inband_event_stream_info[$current_period][$current_adaptation_set] !== NULL &&
$inband_event_stream_info[$current_period][$current_adaptation_set][$current_representation] !== NULL) {
$processArguments .= ' -inbandeventstreamll';
}
}
return $processArguments;
}
function find_attribute($elements, $attribute){
$return_val = NULL;
foreach($elements as $element){
if($element['SegmentBase'] != NULL)
$temp_attribute = $element['SegmentBase'][0][$attribute];
elseif($element['SegmentTemplate'] != NULL){
$segment_template = $element['SegmentTemplate'][0];
$segment_base = $segment_template['SegmentBase'][0];
if($segment_base != NULL)
$temp_attribute = $segment_template['SegmentBase'][0][$attribute];
}
elseif($element['SegmentList'] != NULL){
$segment_list = $element['SegmentList'][0];
$segment_base = $segment_list['SegmentBase'][0];
if($segment_base != NULL)
$temp_attribute = $segment_template['SegmentBase'][0][$attribute];
}
if($temp_attribute != NULL)
$return_val = $temp_attribute;
}
return $return_val;
}