Commit 2ea0c408 authored by Mark Harding's avatar Mark Harding

(chore): fixes and changes when working with test site

1 merge request!414WIP: New transcoder
Pipeline #100684517 passed with stages
in 8 minutes and 14 seconds
......@@ -58,9 +58,7 @@ class upload implements Interfaces\Api
$lease->setGuid($guid)
->setMediaType($mediaType);
$manager
->setFullHD(Session::getLoggedinUser()->isPro())
->complete($lease);
$manager->complete($lease);
break;
}
return Factory::response([]);
......
......@@ -83,5 +83,9 @@ class MediaProvider extends Provider
$this->di->bind('Media\Video\Transcoder\Manager', function ($di) {
return new Video\Transcoder\Manager();
}, ['useFactory' => false]);
$this->di->bind('Media\Video\Transcode\TranscodeStorage', function ($di) {
return new Video\Transcoder\TranscodeStorage\S3Storage();
}, ['useFactory' => false]);
}
}
......@@ -158,13 +158,14 @@ class Manager
// Perform the transcode
try {
$ref = $this;
$success = $this->transcodeExecutor->transcode($transcode, function ($progress) use ($ref) {
$transcode->setProgress($pct);
$this->update($transcode, 'progress');
$success = $this->transcodeExecutor->transcode($transcode, function ($progress) use ($ref, $transcode) {
$transcode->setProgress($progress);
$this->update($transcode, [ 'progress' ]);
});
if (!$success) { // This is actually unkown as an exception should have been thrown
throw new TranscodeExecutors\FailedTranscodeException();
}
$transcode->setProgress(100); // If completed should be assumed 100%
$transcode->setStatus('completed');
} catch (TranscodeExecutors\FailedTranscodeException $e) {
$transcode->setStatus('failed');
......
......@@ -174,9 +174,9 @@ class Repository
}
// Convert our $set to statement
$statement .= " SET " . implode(' ', array_map(function ($field) {
$statement .= " SET " . implode(' , ', array_map(function ($field) {
return "$field = ?";
}, $set));
}, array_keys($set)));
// Move to values array
$values = array_values($set);
......@@ -236,6 +236,7 @@ class Repository
$transcode->setGuid((string) $row['guid'])
->setProfile(TranscodeProfiles\Factory::build((string) $row['profile_id']))
->setProgress($row['progress']->value())
->setStatus($row['status'])
->setLastEventTimestampMs(round($row['last_event_timestamp_ms']->microtime(true) * 1000))
->setLength($row['length_secs']->value())
->setBytes($row['bytes']->value());
......
......@@ -131,7 +131,7 @@ class FFMpegExecutor implements TranscodeExecutorInterface
// $this->logger->info("Transcoding: $path ({$transcode->getGuid()})");
// Update our progress
$formatMap[$format]->on('progress', function ($a, $b, $pct) {
$formatMap[$format]->on('progress', function ($a, $b, $pct) use ($progressCallback) {
// $this->logger->info("$pct% transcoded");
$progressCallback($pct);
});
......@@ -196,6 +196,7 @@ class FFMpegExecutor implements TranscodeExecutorInterface
// Cleanup tmp
@unlink($path);
}
$transcode->setProgress(100);
$transcode->setStatus('completed');
} catch (\Exception $e) {
$transcode->setStatus('failed');
......
......@@ -2,6 +2,7 @@
namespace Minds\Core\Queue\Runners;
use Minds\Core;
use Minds\Core\Di\Di;
use Minds\Core\Queue\Interfaces;
class Transcode implements Interfaces\QueueRunner
......@@ -17,8 +18,8 @@ class Transcode implements Interfaces\QueueRunner
$transcode = unserialize($d['transcode']);
echo "Received a transcode request \n";
$transcoderManeger = Di::_()->get('Media\Video\Transcoder\Manager');
$transcoderManager = Di::_()->get('Media\Video\Transcoder\Manager');
$transcoderManager->transcode($transcode);
}, [ 'max_messages' => 1 ]);
}
......
......@@ -4,23 +4,24 @@ namespace Spec\Minds\Core\Media\ClientUpload;
use Minds\Core\Media\ClientUpload\Manager;
use Minds\Core\Media\ClientUpload\ClientUploadLease;
use Minds\Core\Media\Services\FFMpeg;
use Minds\Core\Media\Video\Transcoder;
use Minds\Core\GuidBuilder;
use Minds\Core\Entities\Actions\Save;
use Minds\Entities\Video;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class ManagerSpec extends ObjectBehavior
{
private $ffmpeg;
private $transcoderManager;
private $guid;
private $save;
public function let(FFMpeg $FFMpeg, GuidBuilder $guid, Save $save)
public function let(Transcoder\Manager $transcoderManager, GuidBuilder $guid, Save $save)
{
$this->beConstructedWith($FFMpeg, $guid, $save);
$this->ffmpeg = $FFMpeg;
$this->beConstructedWith($transcoderManager, $guid, $save);
$this->transcoderManager = $transcoderManager;
$this->guid = $guid;
$this->save = $save;
}
......@@ -35,10 +36,8 @@ class ManagerSpec extends ObjectBehavior
$this->guid->build()
->willReturn(123);
$this->ffmpeg->setKey(123)
->shouldBeCalled();
$this->ffmpeg->getPresignedUrl()
$this->transcoderManager->getClientSideUploadUrl(Argument::type(Video::class))
->shouldBeCalled()
->willReturn('s3-url-here');
$lease = $this->prepare('video');
......@@ -69,17 +68,10 @@ class ManagerSpec extends ObjectBehavior
$this->save->save()
->shouldBeCalled();
$this->ffmpeg->setKey(456)
->shouldBeCalled();
$this->ffmpeg->setFullHD(false)
->shouldBeCalled();
$this->ffmpeg->transcode()
$this->transcoderManager->createTranscodes(Argument::type(Video::class))
->shouldBeCalled();
$this->setFullHD(false)
->complete($lease)
$this->complete($lease)
->shouldReturn(true);
}
}
......@@ -51,6 +51,15 @@ class ManagerSpec extends ObjectBehavior
->shouldReturn(true);
}
public function it_should_return_a_signed_url_for_client_upload()
{
$this->transcodeStorage->getClientSideUploadUrl(Argument::type(Transcode::class))
->shouldBeCalled()
->willReturn('signed-url-here');
$this->getClientSideUploadUrl(new Video())
->shouldBe('signed-url-here');
}
public function it_should_create_transcodes_from_video()
{
$video = new Video();
......
......@@ -59,6 +59,7 @@ class RepositorySpec extends ObjectBehavior
'profile_id' => 'X264_360p',
'last_event_timestamp_ms' => new Timestamp(microtime(true)),
'progress' => new Varint(0),
'status' => null,
'length_secs' => new Varint(0),
'bytes' => new Varint(0),
]
......@@ -81,6 +82,7 @@ class RepositorySpec extends ObjectBehavior
'profile_id' => 'X264_360p',
'last_event_timestamp_ms' => new Timestamp(microtime(true)),
'progress' => new Varint(0),
'status' => null,
'length_secs' => new Varint(0),
'bytes' => new Varint(0),
],
......@@ -89,6 +91,7 @@ class RepositorySpec extends ObjectBehavior
'profile_id' => 'X264_720p',
'last_event_timestamp_ms' => new Timestamp(microtime(true)),
'progress' => new Varint(0),
'status' => null,
'length_secs' => new Varint(0),
'bytes' => new Varint(0),
]
......
......@@ -80,6 +80,9 @@ class FFMpegExecutorSpec extends ObjectBehavior
$this->transcodeStorage->add($transcode, '/tmp/fake-path-for-source-thumbnails/thumbnail-00120.png')
->shouldBeCalled();
$transcode->setProgress(100)
->shouldBeCalled();
$transcode->setStatus('completed')
->shouldBeCalled();
......
......@@ -5,6 +5,7 @@ namespace Spec\Minds\Core\Media\Video\Transcoder\TranscodeStorage;
use Minds\Core\Media\Video\Transcoder\TranscodeStorage\S3Storage;
use Minds\Core\Media\Video\Transcoder\Transcode;
use Minds\Core\Media\Video\Transcoder\TranscodeProfiles;
use Psr\Http\Message\RequestInterface;
use Aws\S3\S3Client;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
......@@ -40,6 +41,33 @@ class S3StorageSpec extends ObjectBehavior
$this->add($transcode, tempnam(sys_get_temp_dir(), 'my-fake-path'));
}
public function it_should_return_a_signed_url_for_client_side_uploads(
Transcode $transcode,
\Aws\CommandInterface $cmd,
RequestInterface $request
) {
$transcode->getGuid()
->willReturn(123);
$transcode->getProfile()
->willReturn(new TranscodeProfiles\Source());
$this->s3->getCommand('PutObject', [
'Bucket' => 'cinemr',
'Key' => "/123/source",
])
->shouldBeCalled()
->willReturn($cmd);
$this->s3->createPresignedRequest(Argument::any(), Argument::any())
->willReturn($request);
$request->getUri()
->willReturn('aws-signed-url');
$this->getClientSideUploadUrl($transcode)
->shouldReturn('aws-signed-url');
}
public function it_should_download_file(Transcode $transcode)
{
$transcode->getGuid()
......
Please register or to comment