Skip to content

Commit

Permalink
Merge pull request kaltura#1344 from kaltura/IX-9.17.0-PLAT-1234
Browse files Browse the repository at this point in the history
Reject entries that already broadcasting
  • Loading branch information
sharonadar committed Jun 17, 2014
2 parents 856a094 + fd226be commit 4c50045
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
11 changes: 7 additions & 4 deletions alpha/lib/model/LiveEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,9 @@ public function setLiveStreamConfigurations(array $v)
$this->putInCustomData('live_stream_configurations', $v);
}

public function getLiveStreamConfigurationByProtocol($format, $protocol, $tag = null)
public function getLiveStreamConfigurationByProtocol($format, $protocol, $tag = null, $currentDcOnly = false)
{
$configurations = $this->getLiveStreamConfigurations($protocol, $tag);
$configurations = $this->getLiveStreamConfigurations($protocol, $tag, $currentDcOnly);
foreach($configurations as $configuration)
{
/* @var $configuration kLiveStreamConfiguration */
Expand All @@ -267,7 +267,7 @@ public function getLiveStreamConfigurationByProtocol($format, $protocol, $tag =
return null;
}

public function getLiveStreamConfigurations($protocol = 'http', $tag = null)
public function getLiveStreamConfigurations($protocol = 'http', $tag = null, $currentDcOnly = false)
{
$configurations = array();
if (!in_array($this->getSource(), self::$kalturaLiveSourceTypes))
Expand Down Expand Up @@ -302,12 +302,15 @@ public function getLiveStreamConfigurations($protocol = 'http', $tag = null)

if(!$primaryMediaServer)
{
if($currentDcOnly)
return array();

$kMediaServer = array_shift($kMediaServers);
if($kMediaServer && $kMediaServer instanceof kLiveMediaServer)
$primaryMediaServer = $kMediaServer->getMediaServer();
}

if(count($kMediaServers))
if(!$currentDcOnly && count($kMediaServers))
{
$kMediaServer = reset($kMediaServers);
if($kMediaServer && $kMediaServer instanceof kLiveMediaServer)
Expand Down
2 changes: 2 additions & 0 deletions api_v3/lib/KalturaErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,8 @@ class KalturaErrors extends APIErrors

const LIVE_STREAM_EXCEEDED_MAX_RECORDED_DURATION = "LIVE_STREAM_EXCEEDED_MAX_RECORDED_DURATION;ENTRY_ID;Entry exceeded max recorded live stream duration in entry[@ENTRY_ID@]";

const LIVE_STREAM_ALREADY_BROADCASTING = "LIVE_STREAM_ALREADY_BROADCASTING;ENTRY_ID,MEDIA_SERVER;Entry [@ENTRY_ID@] already broadcasting to server [@MEDIA_SERVER@]";

/*
* BaseEntry Service
*/
Expand Down
28 changes: 27 additions & 1 deletion api_v3/services/LiveStreamService.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,33 @@ function authenticateAction($entryId, $token)
if ($dbEntry->getStreamPassword() != $token)
throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_INVALID_TOKEN, $entryId);

// TODO count entries and not flavors
$mediaServer = $dbEntry->getMediaServer(true);
if($mediaServer)
{
$url = null;
$protocol = null;
foreach (array(KalturaPlaybackProtocol::HLS, KalturaPlaybackProtocol::APPLE_HTTP) as $hlsProtocol)
{
$config = $dbEntry->getLiveStreamConfigurationByProtocol($hlsProtocol, requestUtils::PROTOCOL_HTTP, null, true);
if ($config)
{
$url = $config->getUrl();
$protocol = $hlsProtocol;
break;
}
}

if($url)
{
KalturaLog::info('Determining status of live stream URL [' .$url. ']');
$urlManager = kUrlManager::getUrlManagerByCdn(parse_url($url, PHP_URL_HOST), $entryId);
$urlManager->setProtocol($protocol);
if($urlManager->isLive($url))
{
throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_ALREADY_BROADCASTING, $entryId, $mediaServer->getHostname());
}
}
}

// fetch current stream live params
$liveParamsIds = flavorParamsConversionProfilePeer::getFlavorIdsByProfileId($dbEntry->getConversionProfileId());
Expand Down

0 comments on commit 4c50045

Please sign in to comment.