/** * Update media server status * * @action reportStatus * @param string $hostname * @param KalturaMediaServerStatus $mediaServerStatus * @return KalturaMediaServer */ function reportStatusAction($hostname, KalturaMediaServerStatus $mediaServerStatus) { $dbMediaServer = MediaServerPeer::retrieveByHostname($hostname); if (!$dbMediaServer) { $dbMediaServer = new MediaServer(); $dbMediaServer->setHostname($hostname); $dbMediaServer->setDc(kDataCenterMgr::getCurrentDcId()); } $mediaServerStatus->toUpdatableObject($dbMediaServer); $dbMediaServer->save(); $mediaServer = new KalturaMediaServer(); $mediaServer->fromObject($dbMediaServer, $this->getResponseProfile()); return $mediaServer; }
/** * Serve XML rendition of the Kaltura Live Transcoding Profile usable by the Wowza transcoding add-on * * @action serve * @param string $streamName the id of the live entry with it's stream suffix * @param string $hostname the media server host name * @return file * * @throws KalturaErrors::ENTRY_ID_NOT_FOUND * @throws WowzaErrors::INVALID_STREAM_NAME */ public function serveAction($streamName, $hostname = null) { $matches = null; if (!preg_match('/^(\\d_.{8})_(\\d+)$/', $streamName, $matches)) { throw new KalturaAPIException(WowzaErrors::INVALID_STREAM_NAME, $streamName); } $entryId = $matches[1]; $suffix = $matches[2]; $entry = null; if (!kCurrentContext::$ks) { kEntitlementUtils::initEntitlementEnforcement(null, false); $entry = kCurrentContext::initPartnerByEntryId($entryId); if (!$entry || $entry->getStatus() == entryStatus::DELETED) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } // enforce entitlement $this->setPartnerFilters(kCurrentContext::getCurrentPartnerId()); } else { $entry = entryPeer::retrieveByPK($entryId); } if (!$entry || $entry->getType() != KalturaEntryType::LIVE_STREAM || !in_array($entry->getSource(), array(KalturaSourceType::LIVE_STREAM, KalturaSourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) { throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId); } $mediaServer = null; if ($hostname) { $mediaServer = MediaServerPeer::retrieveByHostname($hostname); } $conversionProfileId = $entry->getConversionProfileId(); $liveParams = assetParamsPeer::retrieveByProfile($conversionProfileId); $liveParamsInput = null; $disableIngested = true; foreach ($liveParams as $liveParamsItem) { /* @var $liveParamsItem liveParams */ if ($liveParamsItem->getStreamSuffix() == $suffix) { $liveParamsInput = $liveParamsItem; if (!$liveParamsInput->hasTag(assetParams::TAG_SOURCE)) { $liveParams = array($liveParamsInput); $disableIngested = false; } break; } } $ignoreLiveParamsIds = array(); if ($disableIngested) { $conversionProfileAssetParams = flavorParamsConversionProfilePeer::retrieveByConversionProfile($conversionProfileId); foreach ($conversionProfileAssetParams as $conversionProfileAssetParamsItem) { /* @var $conversionProfileAssetParamsItem flavorParamsConversionProfile */ if ($conversionProfileAssetParamsItem->getOrigin() == assetParamsOrigin::INGEST) { $ignoreLiveParamsIds[] = $conversionProfileAssetParamsItem->getFlavorParamsId(); } } } // translate the $liveParams to XML according to doc: http://www.wowza.com/forums/content.php?304#configTemplate $root = new SimpleXMLElement('<Root/>'); $transcode = $root->addChild('Transcode'); $encodes = $transcode->addChild('Encodes'); $groups = array(); foreach ($liveParams as $liveParamsItem) { /* @var $liveParamsItem liveParams */ if (!$liveParamsItem->hasTag(assetParams::TAG_SOURCE) && in_array($liveParamsItem->getId(), $ignoreLiveParamsIds)) { continue; } $this->appendLiveParams($entry, $mediaServer, $encodes, $liveParamsItem); $tags = $liveParamsItem->getTagsArray(); $tags[] = 'all'; foreach ($tags as $tag) { if (!isset($groups[$tag])) { $groups[$tag] = array(); } $systemName = $liveParamsItem->getSystemName() ? $liveParamsItem->getSystemName() : $liveParamsItem->getId(); $groups[$tag][] = $systemName; } } $decode = $transcode->addChild('Decode'); $video = $decode->addChild('Video'); $video->addChild('Deinterlace', 'false'); $streamNameGroups = $transcode->addChild('StreamNameGroups'); foreach ($groups as $groupName => $groupMembers) { $streamNameGroup = $streamNameGroups->addChild('StreamNameGroup'); $streamNameGroup->addChild('Name', $groupName); $streamNameGroup->addChild('StreamName', '${SourceStreamName}_' . $groupName); $members = $streamNameGroup->addChild('Members'); foreach ($groupMembers as $groupMember) { $member = $members->addChild('Member'); $member->addChild('EncodeName', $groupMember); } } $properties = $transcode->addChild('Properties'); $dom = new DOMDocument("1.0"); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->loadXML($root->asXML()); return new kRendererString($dom->saveXML(), 'text/xml'); }
public function setMediaServer($index, $hostname, $applicationName = null) { if (is_null($this->getFirstBroadcast())) { $this->setFirstBroadcast(kApiCache::getTime()); } $mediaServer = MediaServerPeer::retrieveByHostname($hostname); if (!$mediaServer) { KalturaLog::info("External media server with hostname [{$hostname}] is being used to stream this entry"); } $key = $this->getId() . "_{$hostname}_{$index}"; if ($this->storeInCache($key) && $this->isMediaServerRegistered($index, $hostname)) { return; } $this->setLastBroadcast(kApiCache::getTime()); $server = new kLiveMediaServer($index, $hostname, $mediaServer ? $mediaServer->getDc() : null, $mediaServer ? $mediaServer->getId() : null, $applicationName ? $applicationName : MediaServer::DEFAULT_APPLICATION); $this->putInCustomData("server-{$index}", $server, LiveEntry::CUSTOM_DATA_NAMESPACE_MEDIA_SERVERS); }
/** * @return MediaServer */ public function getMediaServer() { return MediaServerPeer::retrieveByPK($this->mediaServerId); }
/** * Builds a Criteria object containing the primary key for this object. * * Unlike buildCriteria() this method includes the primary key values regardless * of whether or not they have been modified. * * @return Criteria The Criteria object containing value(s) for primary key(s). */ public function buildPkeyCriteria() { $criteria = new Criteria(MediaServerPeer::DATABASE_NAME); $criteria->add(MediaServerPeer::ID, $this->id); if ($this->alreadyInSave) { if ($this->isColumnModified(MediaServerPeer::CUSTOM_DATA)) { if (!is_null($this->custom_data_md5)) { $criteria->add(MediaServerPeer::CUSTOM_DATA, "MD5(cast(" . MediaServerPeer::CUSTOM_DATA . " as char character set latin1)) = '{$this->custom_data_md5}'", Criteria::CUSTOM); } else { $criteria->add(MediaServerPeer::CUSTOM_DATA, NULL, Criteria::ISNULL); } } if (count($this->modifiedColumns) == 2 && $this->isColumnModified(MediaServerPeer::UPDATED_AT)) { $theModifiedColumn = null; foreach ($this->modifiedColumns as $modifiedColumn) { if ($modifiedColumn != MediaServerPeer::UPDATED_AT) { $theModifiedColumn = $modifiedColumn; } } $atomicColumns = MediaServerPeer::getAtomicColumns(); if (in_array($theModifiedColumn, $atomicColumns)) { $criteria->add($theModifiedColumn, $this->getByName($theModifiedColumn, BasePeer::TYPE_COLNAME), Criteria::NOT_EQUAL); } } } return $criteria; }
/** * Retrieve multiple objects by pkey. * * @param array $pks List of primary keys * @param PropelPDO $con the connection to use * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function retrieveByPKs($pks, PropelPDO $con = null) { $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(MediaServerPeer::DATABASE_NAME); $criteria->add(MediaServerPeer::ID, $pks, Criteria::IN); $objs = MediaServerPeer::doSelect($criteria, $con); } return $objs; }
/** * Retrieve a single server by its hostname * * @param string $hostname * @param PropelPDO $con the connection to use * @return MediaServer */ public static function retrieveByHostname($hostname, PropelPDO $con = null) { $criteria = new Criteria(); $criteria->add(MediaServerPeer::HOSTNAME, $hostname); return MediaServerPeer::doSelectOne($criteria, $con); }