1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the PHP-FFmpeg-video-streaming package. |
5
|
|
|
* |
6
|
|
|
* (c) Amin Yazdanpanah <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Streaming; |
13
|
|
|
|
14
|
|
|
use Streaming\Filters\HLSFilter; |
15
|
|
|
use Streaming\Traits\Representations; |
16
|
|
|
use Streaming\Filters\Filter; |
17
|
|
|
|
18
|
|
|
class HLS extends Export |
19
|
|
|
{ |
20
|
|
|
use Representations; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
private $hls_time = 10; |
24
|
|
|
|
25
|
|
|
/** @var bool */ |
26
|
|
|
private $hls_allow_cache = true; |
27
|
|
|
|
28
|
|
|
/** @var string */ |
29
|
|
|
private $hls_key_info_file = ""; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
private $ts_sub_directory = ""; |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
private $hls_base_url = ""; |
36
|
|
|
|
37
|
|
|
/** @var bool */ |
38
|
|
|
public $tmp_key_info_file = false; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public function getTsSubDirectory(): string |
44
|
|
|
{ |
45
|
|
|
return $this->ts_sub_directory; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param string $ts_sub_directory |
50
|
|
|
* @return HLS |
51
|
|
|
*/ |
52
|
|
|
public function setTsSubDirectory(string $ts_sub_directory) |
53
|
|
|
{ |
54
|
|
|
$this->ts_sub_directory = $ts_sub_directory; |
55
|
|
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $hls_time |
60
|
|
|
* @return HLS |
61
|
|
|
*/ |
62
|
|
|
public function setHlsTime(string $hls_time): HLS |
63
|
|
|
{ |
64
|
|
|
$this->hls_time = $hls_time; |
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getHlsTime(): string |
72
|
|
|
{ |
73
|
|
|
return $this->hls_time; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param bool $hls_allow_cache |
78
|
|
|
* @return HLS |
79
|
|
|
*/ |
80
|
|
|
public function setHlsAllowCache(bool $hls_allow_cache): HLS |
81
|
|
|
{ |
82
|
|
|
$this->hls_allow_cache = $hls_allow_cache; |
83
|
|
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
public function isHlsAllowCache(): bool |
90
|
|
|
{ |
91
|
|
|
return $this->hls_allow_cache; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $hls_key_info_file |
96
|
|
|
* @return HLS |
97
|
|
|
*/ |
98
|
|
|
public function setHlsKeyInfoFile(string $hls_key_info_file): HLS |
99
|
|
|
{ |
100
|
|
|
$this->hls_key_info_file = $hls_key_info_file; |
101
|
|
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param string $save_to |
106
|
|
|
* @param string $url |
107
|
|
|
* @param int $length |
108
|
|
|
* @return HLS |
109
|
|
|
*/ |
110
|
|
|
public function encryption(string $save_to, string $url, int $length = 16): HLS |
111
|
|
|
{ |
112
|
|
|
$this->setHlsKeyInfoFile(KeyInfo::generate($url, $save_to, $length)); |
113
|
|
|
$this->tmp_key_info_file = true; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param string $url |
120
|
|
|
* @param string $path |
121
|
|
|
* @param int $length |
122
|
|
|
* @return HLS |
123
|
|
|
* @deprecated Please use encryption instead |
124
|
|
|
*/ |
125
|
|
|
public function generateRandomKeyInfo(string $url, string $path, int $length = 16): HLS |
126
|
|
|
{ |
127
|
|
|
@trigger_error('generateRandomKeyInfo method is deprecated and will be removed in a future release. Use encryption instead.', E_USER_DEPRECATED); |
128
|
|
|
return $this->encryption($path, $url, $length); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return string |
133
|
|
|
*/ |
134
|
|
|
public function getHlsKeyInfoFile(): string |
135
|
|
|
{ |
136
|
|
|
return $this->hls_key_info_file; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @param string $hls_base_url |
141
|
|
|
* @return HLS |
142
|
|
|
*/ |
143
|
|
|
public function setHlsBaseUrl(string $hls_base_url): HLS |
144
|
|
|
{ |
145
|
|
|
$this->hls_base_url = $hls_base_url; |
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
public function getHlsBaseUrl(): string |
153
|
|
|
{ |
154
|
|
|
return $this->hls_base_url; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return Filter |
159
|
|
|
*/ |
160
|
|
|
protected function getFilter(): Filter |
161
|
|
|
{ |
162
|
|
|
return new HLSFilter($this); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|