|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2019 Amin Yazdanpanah<http://www.aminyazdanpanah.com>. |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the MIT License; |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* https://opensource.org/licenses/MIT |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace AYazdanpanah\FFMpegStreaming; |
|
20
|
|
|
|
|
21
|
|
|
use AYazdanpanah\FFMpegStreaming\Filters\HLSFilter; |
|
22
|
|
|
use AYazdanpanah\FFMpegStreaming\Traits\Representation; |
|
|
|
|
|
|
23
|
|
|
use AYazdanpanah\FFMpegStreaming\Filters\Filter; |
|
24
|
|
|
|
|
25
|
|
|
class HLS extends Export |
|
26
|
|
|
{ |
|
27
|
|
|
use Representation; |
|
28
|
|
|
|
|
29
|
|
|
/** @var string */ |
|
30
|
|
|
private $hls_time = 5; |
|
31
|
|
|
|
|
32
|
|
|
/** @var bool */ |
|
33
|
|
|
private $hls_allow_cache = true; |
|
34
|
|
|
|
|
35
|
|
|
/** @var string */ |
|
36
|
|
|
private $hls_key_info_file = ""; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param string $hls_time |
|
40
|
|
|
* @return HLS |
|
41
|
|
|
*/ |
|
42
|
|
|
public function setHlsTime(string $hls_time): HLS |
|
43
|
|
|
{ |
|
44
|
|
|
$this->hls_time = $hls_time; |
|
45
|
|
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getHlsTime(): string |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->hls_time; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param bool $hls_allow_cache |
|
58
|
|
|
* @return HLS |
|
59
|
|
|
*/ |
|
60
|
|
|
public function setHlsAllowCache(bool $hls_allow_cache): HLS |
|
61
|
|
|
{ |
|
62
|
|
|
$this->hls_allow_cache = $hls_allow_cache; |
|
63
|
|
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return bool |
|
68
|
|
|
*/ |
|
69
|
|
|
public function isHlsAllowCache(): bool |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->hls_allow_cache; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param string $hls_key_info_file |
|
76
|
|
|
* @return HLS |
|
77
|
|
|
*/ |
|
78
|
|
|
public function setHlsKeyInfoFile(string $hls_key_info_file): HLS |
|
79
|
|
|
{ |
|
80
|
|
|
$this->hls_key_info_file = $hls_key_info_file; |
|
81
|
|
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return string |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getHlsKeyInfoFile(): string |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->hls_key_info_file; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return Filter |
|
94
|
|
|
*/ |
|
95
|
|
|
protected function getFilter(): Filter |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->filter; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @return mixed|void |
|
102
|
|
|
*/ |
|
103
|
|
|
protected function setFilter() |
|
104
|
|
|
{ |
|
105
|
|
|
$this->filter = new HLSFilter($this); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: