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
|
|
|
|
{
|
2021-06-05 10:47:56 +00:00
|
|
|
private DirectStreamerInterface $directStreamer;
|
|
|
|
private TranscodingStreamerInterface $transcodingStreamer;
|
|
|
|
private ObjectStorageStreamerInterface $objectStorageStreamer;
|
|
|
|
private TranscodingService $transcodingService;
|
2018-08-22 17:59:14 +00:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
DirectStreamerInterface $directStreamer,
|
|
|
|
TranscodingStreamerInterface $transcodingStreamer,
|
2018-08-22 19:13:45 +00:00
|
|
|
ObjectStorageStreamerInterface $objectStorageStreamer,
|
|
|
|
TranscodingService $transcodingService
|
2019-07-04 19:50:53 +00:00
|
|
|
) {
|
2018-08-22 17:59:14 +00:00
|
|
|
$this->directStreamer = $directStreamer;
|
|
|
|
$this->transcodingStreamer = $transcodingStreamer;
|
|
|
|
$this->objectStorageStreamer = $objectStorageStreamer;
|
2018-08-22 19:13:45 +00:00
|
|
|
$this->transcodingService = $transcodingService;
|
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;
|
|
|
|
}
|
|
|
|
}
|