Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1202 from njam/wowza-bin-cm
Browse files Browse the repository at this point in the history
Import wowza thumbnails+archive to app with CLI tool
  • Loading branch information
njam committed May 12, 2014
2 parents 9ebb66e + 353ac3f commit f1e13c2
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 64 deletions.
10 changes: 10 additions & 0 deletions library/CM/Model/StreamChannel/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ public function getThumbnailCount() {
return (int) $this->_get('thumbnailCount');
}

/**
* @param int $index
* @return CM_File_UserContent
*/
public function getThumbnail($index) {
$index = (int) $index;
$filename = $this->getId() . '-' . $this->getHash() . '-thumbs' . DIRECTORY_SEPARATOR . $index . '.png';
return new CM_File_UserContent('streamChannels', $filename, $this->getId());
}

/**
* @return CM_Paging_FileUserContent_StreamChannelVideoThumbnails
*/
Expand Down
10 changes: 10 additions & 0 deletions library/CM/Model/StreamChannelArchive/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public function getThumbnailCount() {
return (int) $this->_get('thumbnailCount');
}

/**
* @param int $index
* @return CM_File_UserContent
*/
public function getThumbnail($index) {
$index = (int) $index;
$filename = $this->getId() . '-' . $this->getHash() . '-thumbs' . DIRECTORY_SEPARATOR . $index . '.png';
return new CM_File_UserContent('streamChannels', $filename, $this->getId());
}

/**
* @return CM_Paging_FileUserContent_StreamChannelArchiveVideoThumbnails
*/
Expand Down
21 changes: 0 additions & 21 deletions library/CM/Paging/FileUserContent/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,4 @@

abstract class CM_Paging_FileUserContent_Abstract extends CM_Paging_Abstract {

/**
* @param mixed $item
* @return string
*/
abstract protected function _getFilename($item);

/**
* @param mixed $item
* @return string
*/
abstract protected function _getFileNamespace($item);

/**
* @param mixed $item
* @return int
*/
abstract protected function _getSequence($item);

protected function _processItem($item) {
return new CM_File_UserContent($this->_getFileNamespace($item), $this->_getFilename($item), $this->_getSequence($item));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ public function __construct(CM_Model_StreamChannelArchive_Video $streamChannelAr
parent::__construct($source);
}

protected function _getFilename($item) {
return
$this->_streamChannelArchive->getId() . '-' . $this->_streamChannelArchive->getHash() . '-thumbs' . DIRECTORY_SEPARATOR . $item . '.png';
}

protected function _getFileNamespace($item) {
return 'streamChannels';
}

protected function _getSequence($item) {
return (int) $this->_streamChannelArchive->getId();
protected function _processItem($item) {
return $this->_streamChannelArchive->getThumbnail($item);
}
}
12 changes: 2 additions & 10 deletions library/CM/Paging/FileUserContent/StreamChannelVideoThumbnails.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,7 @@ public function __construct(CM_Model_StreamChannel_Video $streamChannel) {
parent::__construct($source);
}

protected function _getFilename($item) {
return $this->_streamChannel->getId() . '-' . $this->_streamChannel->getHash() . '-thumbs' . DIRECTORY_SEPARATOR . $item . '.png';
}

protected function _getFileNamespace($item) {
return 'streamChannels';
}

protected function _getSequence($item) {
return (int) $this->_streamChannel->getId();
protected function _processItem($item) {
return $this->_streamChannel->getThumbnail($item);
}
}
14 changes: 3 additions & 11 deletions library/CM/Stream/Adapter/Video/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,18 @@ public function stopStream(CM_Model_Stream_Abstract $stream) {
* @param int $width
* @param int $height
* @param int $serverId
* @param int $thumbnailCount
* @param string $data
* @throws CM_Exception
* @throws CM_Exception_NotAllowed
* @return int
*/
public function publish($streamName, $clientKey, $start, $width, $height, $serverId, $thumbnailCount, $data) {
public function publish($streamName, $clientKey, $start, $width, $height, $serverId, $data) {
$streamName = (string) $streamName;
$clientKey = (string) $clientKey;
$start = (int) $start;
$width = (int) $width;
$height = (int) $height;
$serverId = (int) $serverId;
$thumbnailCount = (int) $thumbnailCount;
$data = (string) $data;
$params = CM_Params::factory(CM_Params::decode($data, true));
$streamChannelType = $params->getInt('streamChannelType');
Expand All @@ -97,7 +95,7 @@ public function publish($streamName, $clientKey, $start, $width, $height, $serve
'width' => $width,
'height' => $height,
'serverId' => $serverId,
'thumbnailCount' => $thumbnailCount,
'thumbnailCount' => 0,
));
try {
CM_Model_Stream_Publish::createStatic(array(
Expand All @@ -115,22 +113,16 @@ public function publish($streamName, $clientKey, $start, $width, $height, $serve

/**
* @param string $streamName
* @param int|null $thumbnailCount
* @return null
*/
public function unpublish($streamName, $thumbnailCount = null) {
public function unpublish($streamName) {
$streamName = (string) $streamName;
$thumbnailCount = (int) $thumbnailCount;
/** @var CM_Model_StreamChannel_Abstract $streamChannel */
$streamChannel = CM_Model_StreamChannel_Abstract::findByKeyAndAdapter($streamName, $this->getType());
if (!$streamChannel) {
return;
}

if (null !== $thumbnailCount && $streamChannel instanceof CM_Model_StreamChannel_Video) {
/** @var CM_Model_StreamChannel_Video $streamChannel */
$streamChannel->setThumbnailCount($thumbnailCount);
}
$streamChannel->getStreamPublish()->delete();
if (!$streamChannel->hasStreams()) {
$streamChannel->delete();
Expand Down
5 changes: 0 additions & 5 deletions library/CM/Stream/Adapter/Video/Wowza.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ public function synchronize() {
$this->_stopClient($publish['clientId'], $publish['serverHost']);
}

if ($streamChannel instanceof CM_Model_StreamChannel_Video) {
/** @var CM_Model_StreamChannel_Video $streamChannel */
$streamChannel->setThumbnailCount($publish['thumbnailCount']);
}

foreach ($publish['subscribers'] as $clientId => $subscribe) {
if (!$streamChannel || !$streamChannel->getStreamSubscribes()->findKey($clientId)) {
$this->_stopClient($clientId, $publish['serverHost']);
Expand Down
26 changes: 26 additions & 0 deletions library/CM/Stream/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@ public function startMessageSynchronization() {
CM_Stream_Message::getInstance()->startSynchronization();
}

/**
* @param int $streamChannelId
* @param CM_File $thumbnailSource
*/
public function importVideoThumbnail($streamChannelId, CM_File $thumbnailSource) {
$streamChannel = CM_Model_StreamChannel_Video::factory($streamChannelId);
$thumbnailCount = $streamChannel->getThumbnailCount();
$thumbnailDestination = $streamChannel->getThumbnail($thumbnailCount + 1);
if (0 == $thumbnailCount) {
$thumbnailDestination->ensureParentDirectory();
}
$thumbnailSource->copyToFile($thumbnailDestination);
$streamChannel->setThumbnailCount($thumbnailCount + 1);
}

/**
* @param int $streamChannelId
* @param CM_File $archiveSource
*/
public function importVideoArchive($streamChannelId, CM_File $archiveSource) {
$streamChannelArchive = new CM_Model_StreamChannelArchive_Video($streamChannelId);
$archiveDestination = $streamChannelArchive->getVideo();
$archiveDestination->ensureParentDirectory();
$archiveSource->copyToFile($archiveDestination);
}

public static function getPackageName() {
return 'stream';
}
Expand Down
10 changes: 4 additions & 6 deletions library/CM/Stream/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,25 @@ public function getAdapter() {
* @param int $start
* @param int $width
* @param int $height
* @param int $thumbnailCount
* @param string $data
* @return int
*/
public static function rpc_publish($streamName, $clientKey, $start, $width, $height, $thumbnailCount, $data) {
public static function rpc_publish($streamName, $clientKey, $start, $width, $height, $data) {
$request = CM_Request_Abstract::getInstance();
$serverId = self::getInstance()->getAdapter()->getServerId($request);

$channelId = self::getInstance()->getAdapter()->publish($streamName, $clientKey, $start, $width, $height, $serverId, $thumbnailCount, $data);
$channelId = self::getInstance()->getAdapter()->publish($streamName, $clientKey, $start, $width, $height, $serverId, $data);
return $channelId;
}

/**
* @param string $streamName
* @param int $thumbnailCount
* @return bool
*/
public static function rpc_unpublish($streamName, $thumbnailCount) {
public static function rpc_unpublish($streamName) {
$adapter = self::getInstance()->getAdapter();
$adapter->getServerId(CM_Request_Abstract::getInstance());
$adapter->unpublish($streamName, $thumbnailCount);
$adapter->unpublish($streamName);
return true;
}

Expand Down
11 changes: 11 additions & 0 deletions tests/library/CM/Model/StreamChannel/VideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,16 @@ public function testGetThumbnails() {
$streamChannel->getId() . '-' . $streamChannel->getHash() . '-thumbs/2.png', $streamChannel->getId());
$this->assertEquals(array($thumb1, $thumb2), $streamChannel->getThumbnails()->getItems());
}

public function testGetThumbnail() {
/** @var CM_Model_StreamChannel_Video $streamChannel */
$streamChannel = CMTest_TH::createStreamChannel();
CMTest_TH::createStreamPublish(null, $streamChannel);
$thumbnail = $streamChannel->getThumbnail(3);
$this->assertInstanceOf('CM_File_UserContent', $thumbnail);
$this->assertSame(
'streamChannels/' . $streamChannel->getId() . '/' . $streamChannel->getId() . '-' . $streamChannel->getHash() . '-thumbs/3.png',
$thumbnail->getPathRelative());
}
}

9 changes: 9 additions & 0 deletions tests/library/CM/Model/StreamChannelArchive/VideoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ public function testGetThumbnails() {
$this->assertEquals(array($thumb1, $thumb2), $archive->getThumbnails()->getItems());
}

public function testGetThumbnail() {
$archive = CMTest_TH::createStreamChannelVideoArchive();
$thumbnail = $archive->getThumbnail(3);
$this->assertInstanceOf('CM_File_UserContent', $thumbnail);
$this->assertSame(
'streamChannels/' . $archive->getId() . '/' . $archive->getId() . '-' . $archive->getHash() . '-thumbs/3.png',
$thumbnail->getPathRelative());
}

public function testOnDelete() {
/** @var CM_Model_StreamChannel_Video $streamChannel */
$streamChannel = CMTest_TH::createStreamChannel();
Expand Down

0 comments on commit f1e13c2

Please sign in to comment.