|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Uxmp\Core\Component\Io; |
|
6
|
|
|
|
|
7
|
|
|
use GuzzleHttp\Psr7\PumpStream; |
|
8
|
|
|
use Nyholm\Psr7\Factory\Psr17Factory; |
|
9
|
|
|
use Psr\Http\Message\StreamInterface; |
|
10
|
|
|
use Psr\Log\LoggerInterface; |
|
11
|
|
|
use Uxmp\Core\Component\Config\ConfigProviderInterface; |
|
12
|
|
|
use Uxmp\Core\Component\Io\Lib\PopenWrapperInterface; |
|
13
|
|
|
use Uxmp\Core\Component\Io\Transcoder\FfmpegTranscoder; |
|
14
|
|
|
use Uxmp\Core\Component\Io\Transcoder\TranscoderInterface; |
|
15
|
|
|
use Uxmp\Core\Component\Io\Transcoder\TranscodingHandler; |
|
16
|
|
|
|
|
17
|
|
|
final readonly class IoFactory implements IoFactoryInterface |
|
|
|
|
|
|
18
|
|
|
{ |
|
19
|
4 |
|
public function __construct( |
|
20
|
|
|
private Psr17Factory $psr17Factory, |
|
21
|
|
|
private ConfigProviderInterface $configProvider, |
|
22
|
|
|
private PopenWrapperInterface $popenWrapper, |
|
23
|
|
|
private LoggerInterface $logger, |
|
24
|
|
|
) { |
|
25
|
4 |
|
} |
|
26
|
|
|
|
|
27
|
1 |
|
public function createSimpleFileStreamable(): StreamableInterface |
|
28
|
|
|
{ |
|
29
|
1 |
|
return new SimpleFileStreamable( |
|
30
|
1 |
|
$this->psr17Factory |
|
31
|
1 |
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
1 |
|
public function createTranscodingStreamable( |
|
35
|
|
|
TranscoderInterface $transcoder |
|
36
|
|
|
): StreamableInterface { |
|
37
|
1 |
|
return new TranscodingStreamable( |
|
38
|
1 |
|
$this, |
|
39
|
1 |
|
$transcoder |
|
40
|
1 |
|
); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
1 |
|
public function createPumpStream( |
|
44
|
|
|
TranscoderInterface $transcoder |
|
45
|
|
|
): StreamInterface { |
|
46
|
|
|
/** @var callable(int):mixed $handler */ |
|
47
|
1 |
|
$handler = new TranscodingHandler( |
|
48
|
1 |
|
$this->logger, |
|
49
|
1 |
|
$transcoder |
|
50
|
1 |
|
); |
|
51
|
|
|
|
|
52
|
1 |
|
return new PumpStream($handler); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Creates a ffmpeg transcoder |
|
57
|
|
|
* |
|
58
|
|
|
* If the given transcoding options aren't allowed, the default config will be used |
|
59
|
|
|
*/ |
|
60
|
1 |
|
public function createFfmpegTranscoder( |
|
61
|
|
|
string $codec, |
|
62
|
|
|
int $bitrate, |
|
63
|
|
|
): TranscoderInterface { |
|
64
|
1 |
|
return new FfmpegTranscoder( |
|
65
|
1 |
|
$this->configProvider, |
|
66
|
1 |
|
$this->popenWrapper, |
|
67
|
1 |
|
$codec, |
|
68
|
1 |
|
$bitrate, |
|
69
|
1 |
|
); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|