1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PhpM3u8 package. |
5
|
|
|
* |
6
|
|
|
* (c) Chrisyue <http://chrisyue.com/> |
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 Chrisyue\PhpM3u8\tests; |
13
|
|
|
|
14
|
|
|
use Chrisyue\PhpM3u8\M3u8; |
15
|
|
|
use Chrisyue\PhpM3u8\Segment; |
16
|
|
|
use Chrisyue\PhpM3u8\Tag\KeyTag; |
17
|
|
|
|
18
|
|
|
class DummyM3u8Factory |
19
|
|
|
{ |
20
|
1 |
|
public static function createM3u8($version = 3) |
21
|
|
|
{ |
22
|
1 |
|
$m3u8 = new M3u8(); |
23
|
1 |
|
$m3u8->getVersionTag()->setVersion($version); |
24
|
1 |
|
$m3u8->getMediaSequenceTag()->setMediaSequence(33); |
25
|
1 |
|
$m3u8->getDiscontinuitySequenceTag()->setDiscontinuitySequence(3); |
26
|
1 |
|
$m3u8->getTargetDurationTag()->setTargetDuration(12); |
27
|
1 |
|
$m3u8->getEndlistTag()->setEndless(true); |
28
|
|
|
|
29
|
1 |
|
$segment = new Segment($version); |
30
|
|
|
|
31
|
1 |
|
$keyTag = new KeyTag(); |
32
|
1 |
|
$keyTag->setMethod('AES-128')->setUri('key')->setIV('0xF85A5066CCB442181ACACA2E862A34DC'); |
33
|
1 |
|
$segment->getKeyTags()->add($keyTag); |
34
|
1 |
|
$keyTag = new KeyTag(); |
35
|
1 |
|
$keyTag->setMethod('SAMPLE-AES')->setUri('key2')->setIV('0xF85A5066CCB442181ACACA2E862A34DC') |
36
|
1 |
|
->setKeyFormat('com.apple')->setKeyFormatVersions([1]); |
37
|
1 |
|
$segment->getKeyTags()->add($keyTag); |
38
|
|
|
|
39
|
1 |
|
$segment->getExtinfTag()->setDuration(12)->setTitle('hello world'); |
40
|
1 |
|
$segment->getByteRangeTag()->setLength(10000)->setOffset(100); |
41
|
1 |
|
$segment->getUri()->setUri('stream33.ts'); |
42
|
1 |
|
$m3u8->getSegments()->add($segment); |
43
|
|
|
|
44
|
1 |
|
$segment = new Segment($version); |
45
|
1 |
|
$segment->getExtinfTag()->setDuration(10); |
46
|
1 |
|
$segment->getDiscontinuityTag()->setDiscontinuity(true); |
47
|
1 |
|
$segment->getUri()->setUri('video01.ts'); |
48
|
1 |
|
$m3u8->getSegments()->add($segment); |
49
|
|
|
|
50
|
1 |
|
return $m3u8; |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
public static function createM3u8Content($version = 3) |
54
|
|
|
{ |
55
|
2 |
|
if ($version < 3) { |
56
|
|
|
return <<<'M3U8' |
57
|
|
|
#EXTM3U |
58
|
|
|
#EXT-X-VERSION:2 |
59
|
|
|
#EXT-X-TARGETDURATION:12 |
60
|
|
|
#EXT-X-MEDIA-SEQUENCE:33 |
61
|
|
|
#EXT-X-DISCONTINUITY-SEQUENCE:3 |
62
|
|
|
#EXT-X-KEY:METHOD=AES-128,URI="key",IV=0xF85A5066CCB442181ACACA2E862A34DC |
63
|
|
|
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="key2",IV=0xF85A5066CCB442181ACACA2E862A34DC,KEYFORMAT="com.apple",KEYFORMATVERSIONS="1" |
64
|
|
|
#EXTINF:12,hello world |
65
|
|
|
#EXT-X-BYTERANGE:10000@100 |
66
|
|
|
stream33.ts |
67
|
|
|
#EXTINF:10, |
68
|
|
|
#EXT-X-DISCONTINUITY |
69
|
|
|
video01.ts |
70
|
1 |
|
M3U8; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return <<<'M3U8' |
74
|
|
|
#EXTM3U |
75
|
|
|
#EXT-X-VERSION:3 |
76
|
|
|
#EXT-X-TARGETDURATION:12 |
77
|
|
|
#EXT-X-MEDIA-SEQUENCE:33 |
78
|
|
|
#EXT-X-DISCONTINUITY-SEQUENCE:3 |
79
|
|
|
#EXT-X-KEY:METHOD=AES-128,URI="key",IV=0xF85A5066CCB442181ACACA2E862A34DC |
80
|
|
|
#EXT-X-KEY:METHOD=SAMPLE-AES,URI="key2",IV=0xF85A5066CCB442181ACACA2E862A34DC,KEYFORMAT="com.apple",KEYFORMATVERSIONS="1" |
81
|
|
|
#EXTINF:12.000,hello world |
82
|
|
|
#EXT-X-BYTERANGE:10000@100 |
83
|
|
|
stream33.ts |
84
|
|
|
#EXTINF:10.000, |
85
|
|
|
#EXT-X-DISCONTINUITY |
86
|
|
|
video01.ts |
87
|
1 |
|
M3U8; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|