예제 #1
0
 /**
  * @param kLiveEntryResource $resource
  * @param entry $dbEntry
  * @param asset $dbAsset
  * @return array $operationAttributes
  * @return asset
  */
 protected function attachLiveEntryResource(kLiveEntryResource $resource, entry $dbEntry, asset $dbAsset = null, array $operationAttributes = null)
 {
     $dbEntry->setRootEntryId($resource->getEntry()->getId());
     $dbEntry->setSource(EntrySourceType::RECORDED_LIVE);
     $dbEntry->save();
     if (!$dbAsset) {
         $dbAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId());
     }
     $offset = null;
     $duration = null;
     $requiredDuration = null;
     $clipAttributes = null;
     if (is_array($operationAttributes)) {
         foreach ($operationAttributes as $operationAttributesItem) {
             if ($operationAttributesItem instanceof kClipAttributes) {
                 $clipAttributes = $operationAttributesItem;
                 // convert milliseconds to seconds
                 $offset = $operationAttributesItem->getOffset();
                 $duration = $operationAttributesItem->getDuration();
                 $requiredDuration = $offset + $duration;
             }
         }
     }
     $dbLiveEntry = $resource->getEntry();
     $dbRecordedEntry = entryPeer::retrieveByPK($dbLiveEntry->getRecordedEntryId());
     if (!$dbRecordedEntry || $requiredDuration && $requiredDuration > $dbRecordedEntry->getLengthInMsecs()) {
         $mediaServer = $dbLiveEntry->getMediaServer(true);
         if (!$mediaServer) {
             throw new KalturaAPIException(KalturaErrors::NO_MEDIA_SERVER_FOUND, $dbLiveEntry->getId());
         }
         $mediaServerLiveService = $mediaServer->getWebService($mediaServer->getLiveWebServiceName());
         if ($mediaServerLiveService && $mediaServerLiveService instanceof KalturaMediaServerLiveService) {
             $mediaServerLiveService->splitRecordingNow($dbLiveEntry->getId());
             $dbLiveEntry->attachPendingMediaEntry($dbEntry, $requiredDuration, $offset, $duration);
             $dbLiveEntry->save();
         } else {
             throw new KalturaAPIException(KalturaErrors::MEDIA_SERVER_SERVICE_NOT_FOUND, $mediaServer->getId(), $mediaServer->getLiveWebServiceName());
         }
         return $dbAsset;
     }
     $dbRecordedAsset = assetPeer::retrieveOriginalReadyByEntryId($dbRecordedEntry->getId());
     if (!$dbRecordedAsset) {
         $dbRecordedAssets = assetPeer::retrieveReadyFlavorsByEntryId($dbRecordedEntry->getId());
         $dbRecordedAsset = array_pop($dbRecordedAssets);
     }
     /* @var $dbRecordedAsset flavorAsset */
     $isNewAsset = false;
     if (!$dbAsset) {
         $isNewAsset = true;
         $dbAsset = kFlowHelper::createOriginalFlavorAsset($this->getPartnerId(), $dbEntry->getId());
     }
     if (!$dbAsset && $dbEntry->getStatus() == entryStatus::NO_CONTENT) {
         $dbEntry->setStatus(entryStatus::ERROR_CONVERTING);
         $dbEntry->save();
     }
     $sourceSyncKey = $dbRecordedAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $dbAsset->setFileExt($dbRecordedAsset->getFileExt());
     $dbAsset->save();
     $syncKey = $dbAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     try {
         kFileSyncUtils::createSyncFileLinkForKey($syncKey, $sourceSyncKey);
     } catch (Exception $e) {
         if ($dbEntry->getStatus() == entryStatus::NO_CONTENT) {
             $dbEntry->setStatus(entryStatus::ERROR_CONVERTING);
             $dbEntry->save();
         }
         $dbAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
         $dbAsset->save();
         throw $e;
     }
     if ($requiredDuration) {
         $errDescription = '';
         kBusinessPreConvertDL::decideAddEntryFlavor(null, $dbEntry->getId(), $clipAttributes->getAssetParamsId(), $errDescription, $dbAsset->getId(), array($clipAttributes));
     } else {
         if ($isNewAsset) {
             kEventsManager::raiseEvent(new kObjectAddedEvent($dbAsset));
         }
     }
     kEventsManager::raiseEvent(new kObjectDataChangedEvent($dbAsset));
     return $dbAsset;
 }
예제 #2
0
 public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     $this->validateForUsage($object_to_fill, $props_to_skip);
     $srcEntry = entryPeer::retrieveByPK($this->entryId);
     if (!$srcEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $this->entryId);
     }
     if ($srcEntry->getType() == entryType::LIVE_STREAM) {
         /* @var $srcEntry LiveEntry */
         if (!in_array($srcEntry->getSource(), array(EntrySourceType::LIVE_STREAM, EntrySourceType::LIVE_STREAM_ONTEXTDATA_CAPTIONS))) {
             throw new KalturaAPIException(KalturaErrors::RESOURCE_TYPE_NOT_SUPPORTED, get_class($this));
         }
         $mediaServer = $srcEntry->getMediaServer();
         if ($mediaServer && !is_null($mediaServer->getDc()) && $mediaServer->getDc() != kDataCenterMgr::getCurrentDcId()) {
             $remoteDCHost = kDataCenterMgr::getRemoteDcExternalUrlByDcId($mediaServer->getDc());
             if ($remoteDCHost) {
                 kFileUtils::dumpApiRequest($remoteDCHost);
             } else {
                 throw new KalturaAPIException(KalturaErrors::UPLOADED_FILE_NOT_FOUND_BY_TOKEN);
             }
         }
         if ($object_to_fill && !$object_to_fill instanceof kLiveEntryResource) {
             throw new KalturaAPIException(KalturaErrors::RESOURCE_TYPE_NOT_SUPPORTED, get_class($object_to_fill));
         }
         $object_to_fill = new kLiveEntryResource();
         $object_to_fill->setEntry($srcEntry);
         return $object_to_fill;
     }
     if (!$object_to_fill) {
         $object_to_fill = new kFileSyncResource();
     }
     if ($srcEntry->getMediaType() == KalturaMediaType::IMAGE) {
         $object_to_fill->setFileSyncObjectType(FileSyncObjectType::ENTRY);
         $object_to_fill->setObjectSubType(entry::FILE_SYNC_ENTRY_SUB_TYPE_DATA);
         $object_to_fill->setObjectId($srcEntry->getId());
         return $object_to_fill;
     }
     $srcFlavorAsset = null;
     if (is_null($this->flavorParamsId)) {
         $srcFlavorAsset = assetPeer::retrieveOriginalByEntryId($this->entryId);
         if (!$srcFlavorAsset) {
             throw new KalturaAPIException(KalturaErrors::ORIGINAL_FLAVOR_ASSET_IS_MISSING);
         }
     } else {
         $srcFlavorAsset = assetPeer::retrieveByEntryIdAndParams($this->entryId, $this->flavorParamsId);
         if (!$srcFlavorAsset) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_ID_NOT_FOUND, $this->flavorParamsId);
         }
     }
     $object_to_fill->setFileSyncObjectType(FileSyncObjectType::FLAVOR_ASSET);
     $object_to_fill->setObjectSubType(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $object_to_fill->setObjectId($srcFlavorAsset->getId());
     $object_to_fill->setOriginEntryId($this->entryId);
     return $object_to_fill;
 }