koel/app/Factories/StreamerFactory.php

51 lines
1.5 KiB
PHP
Raw Normal View History

2018-08-22 17:59:14 +00:00
<?php
namespace App\Factories;
use App\Models\Song;
use App\Services\Streamers\DirectStreamerInterface;
use App\Services\Streamers\ObjectStorageStreamerInterface;
use App\Services\Streamers\StreamerInterface;
use App\Services\Streamers\TranscodingStreamerInterface;
2018-08-22 19:13:45 +00:00
use App\Services\TranscodingService;
2018-08-22 17:59:14 +00:00
class StreamerFactory
{
public function __construct(
2022-07-29 06:47:10 +00:00
private DirectStreamerInterface $directStreamer,
private TranscodingStreamerInterface $transcodingStreamer,
private ObjectStorageStreamerInterface $objectStorageStreamer,
private TranscodingService $transcodingService
2019-07-04 19:50:53 +00:00
) {
2018-08-22 17:59:14 +00:00
}
2018-08-24 15:27:19 +00:00
public function createStreamer(
Song $song,
?bool $transcode = null,
?int $bitRate = null,
2019-06-30 14:22:53 +00:00
float $startTime = 0.0
2019-07-04 19:50:53 +00:00
): StreamerInterface {
2018-08-22 17:59:14 +00:00
if ($song->s3_params) {
$this->objectStorageStreamer->setSong($song);
return $this->objectStorageStreamer;
}
2018-08-22 19:13:45 +00:00
if ($transcode === null && $this->transcodingService->songShouldBeTranscoded($song)) {
2018-08-22 17:59:14 +00:00
$transcode = true;
}
if ($transcode) {
$this->transcodingStreamer->setSong($song);
$this->transcodingStreamer->setBitRate($bitRate ?: config('koel.streaming.bitrate'));
$this->transcodingStreamer->setStartTime($startTime);
return $this->transcodingStreamer;
}
$this->directStreamer->setSong($song);
return $this->directStreamer;
}
}