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
|
|
|
|
{
|
|
|
|
private $directStreamer;
|
|
|
|
private $transcodingStreamer;
|
|
|
|
private $objectStorageStreamer;
|
2018-08-22 19:13:45 +00:00
|
|
|
private $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
|
2018-08-22 17:59:36 +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-22 17:59:36 +00:00
|
|
|
* @param Song $song
|
|
|
|
* @param bool|null $transcode
|
|
|
|
* @param int|null $bitRate
|
|
|
|
* @param int $startTime
|
2018-08-22 17:59:14 +00:00
|
|
|
*
|
|
|
|
* @return StreamerInterface
|
|
|
|
*/
|
|
|
|
public function createStreamer(Song $song, $transcode = null, $bitRate = null, $startTime = 0)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|