/** * @param LiveEntry $dbEntry * @return entry */ private function createRecordedEntry(LiveEntry $dbEntry, $mediaServerIndex) { $lock = kLock::create("live_record_" . $dbEntry->getId()); if ($lock && !$lock->lock(self::KLOCK_CREATE_RECORDED_ENTRY_GRAB_TIMEOUT, self::KLOCK_CREATE_RECORDED_ENTRY_HOLD_TIMEOUT)) { return; } // If while we were waiting for the lock, someone has updated the recorded entry id - we should use it. $dbEntry->reload(); if ($dbEntry->getRecordStatus() != RecordStatus::PER_SESSION && $dbEntry->getRecordedEntryId()) { $lock->unlock(); $recordedEntry = entryPeer::retrieveByPK($dbEntry->getRecordedEntryId()); return $recordedEntry; } $recordedEntry = null; try { $recordedEntryName = $dbEntry->getName(); if ($dbEntry->getRecordStatus() == RecordStatus::PER_SESSION) { $recordedEntryName .= ' ' . ($dbEntry->getRecordedEntryIndex() + 1); } $recordedEntry = new entry(); $recordedEntry->setType(entryType::MEDIA_CLIP); $recordedEntry->setMediaType(entry::ENTRY_MEDIA_TYPE_VIDEO); $recordedEntry->setRootEntryId($dbEntry->getId()); $recordedEntry->setName($recordedEntryName); $recordedEntry->setDescription($dbEntry->getDescription()); $recordedEntry->setSourceType(EntrySourceType::RECORDED_LIVE); $recordedEntry->setAccessControlId($dbEntry->getAccessControlId()); $recordedEntry->setConversionProfileId($dbEntry->getConversionProfileId()); $recordedEntry->setKuserId($dbEntry->getKuserId()); $recordedEntry->setPartnerId($dbEntry->getPartnerId()); $recordedEntry->setModerationStatus($dbEntry->getModerationStatus()); $recordedEntry->setIsRecordedEntry(true); $recordedEntry->setTags($dbEntry->getTags()); $recordedEntry->save(); $dbEntry->setRecordedEntryId($recordedEntry->getId()); $dbEntry->save(); $assets = assetPeer::retrieveByEntryId($dbEntry->getId(), array(assetType::LIVE)); foreach ($assets as $asset) { /* @var $asset liveAsset */ $asset->incLiveSegmentVersion($mediaServerIndex); $asset->save(); } } catch (Exception $e) { $lock->unlock(); throw $e; } $lock->unlock(); return $recordedEntry; }
private static function createReplacigEntry($recordedEntry) { $advancedOptions = new kEntryReplacementOptions(); $advancedOptions->setKeepManualThumbnails(true); $recordedEntry->setReplacementOptions($advancedOptions); $replacingEntry = new entry(); $replacingEntry->setType(entryType::MEDIA_CLIP); $replacingEntry->setMediaType(entry::ENTRY_MEDIA_TYPE_VIDEO); $replacingEntry->setConversionProfileId($recordedEntry->getConversionProfileId()); $replacingEntry->setName($recordedEntry->getPartnerId() . '_' . time()); $replacingEntry->setKuserId($recordedEntry->getKuserId()); $replacingEntry->setAccessControlId($recordedEntry->getAccessControlId()); $replacingEntry->setPartnerId($recordedEntry->getPartnerId()); $replacingEntry->setSubpId($recordedEntry->getPartnerId() * 100); $replacingEntry->setDefaultModerationStatus(); $replacingEntry->setDisplayInSearch(mySearchUtils::DISPLAY_IN_SEARCH_SYSTEM); $replacingEntry->setReplacedEntryId($recordedEntry->getId()); $replacingEntry->save(); $recordedEntry->setReplacingEntryId($replacingEntry->getId()); $recordedEntry->setReplacementStatus(entryReplacementStatus::APPROVED_BUT_NOT_READY); $affectedRows = $recordedEntry->save(); return $replacingEntry; }
protected static function getReplacingEntry($recordedEntry, $asset, $retries = 1) { $replacingEntryId = $recordedEntry->getReplacingEntryId(); $replacingEntry = null; // in replacement if ($replacingEntryId) { $replacingEntry = entryPeer::retrieveByPKNoFilter($replacingEntryId); // check if asset already ingested $replacingAsset = assetPeer::retrieveByEntryIdAndParams($replacingEntryId, $asset->getFlavorParamsId()); if ($replacingAsset) { KalturaLog::err('Asset with params [' . $asset->getFlavorParamsId() . '] already replaced'); return null; } } else { $advancedOptions = new kEntryReplacementOptions(); $advancedOptions->setKeepManualThumbnails(true); $recordedEntry->setReplacementOptions($advancedOptions); $replacingEntry = new entry(); $replacingEntry->setType(entryType::MEDIA_CLIP); $replacingEntry->setMediaType(entry::ENTRY_MEDIA_TYPE_VIDEO); $replacingEntry->setConversionProfileId($recordedEntry->getConversionProfileId()); $replacingEntry->setName($recordedEntry->getPartnerId() . '_' . time()); $replacingEntry->setKuserId($recordedEntry->getKuserId()); $replacingEntry->setAccessControlId($recordedEntry->getAccessControlId()); $replacingEntry->setPartnerId($recordedEntry->getPartnerId()); $replacingEntry->setSubpId($recordedEntry->getPartnerId() * 100); $replacingEntry->setDefaultModerationStatus(); $replacingEntry->setDisplayInSearch(mySearchUtils::DISPLAY_IN_SEARCH_SYSTEM); $replacingEntry->setReplacedEntryId($recordedEntry->getId()); $replacingEntry->save(); $recordedEntry->setReplacingEntryId($replacingEntry->getId()); $recordedEntry->setReplacementStatus(entryReplacementStatus::APPROVED_BUT_NOT_READY); $affectedRows = $recordedEntry->save(); if (!$affectedRows) { $replacingEntry->delete(); $replacingEntry = null; if ($retries) { sleep(10); $recordedEntry = entryPeer::retrieveByPKNoFilter($recordedEntry->getId()); return kFlowHelper::getReplacingEntry($recordedEntry, $asset, 0); } else { KalturaLog::err("Failed to update replacing entry"); return null; } } } return $replacingEntry; }
/** * @param entry $entry * @param entry $tempEntry */ public static function replaceEntry(entry $entry, entry $tempEntry = null) { KalturaLog::debug("in replaceEntry"); if (!$tempEntry) { $tempEntry = entryPeer::retrieveByPK($entry->getReplacingEntryId()); } if (!$tempEntry) { KalturaLog::err("Temp entry id [" . $entry->getReplacingEntryId() . "] not found"); return; } //Extract all assets of the temp entry $tempAssets = assetPeer::retrieveByEntryId($tempEntry->getId()); //Extract all assets of the existing entry $oldAssets = assetPeer::retrieveByEntryId($entry->getId()); KalturaLog::debug("num of old assets: " . count($oldAssets)); $newAssets = array(); //Loop which creates a mapping between the new assets' paramsId and their type to the asset itself foreach ($tempAssets as $newAsset) { if ($newAsset->getStatus() != asset::FLAVOR_ASSET_STATUS_READY) { KalturaLog::debug("Do not add new asset [" . $newAsset->getId() . "] to flavor [" . $newAsset->getFlavorParamsId() . "] status [" . $newAsset->getStatus() . "]"); continue; } //If doesn't exist - create a new array for the current asset's type. if (!isset($newAssets[$newAsset->getType()])) { $newAssets[$newAsset->getType()] = array(); } if ($newAsset->getFlavorParamsId() || $newAsset instanceof flavorAsset) { $newAssets[$newAsset->getType()][$newAsset->getFlavorParamsId()] = $newAsset; KalturaLog::debug("Added new asset [" . $newAsset->getId() . "] for asset params [" . $newAsset->getFlavorParamsId() . "]"); } else { $newAssets[$newAsset->getType()]['asset_' . count($newAssets[$newAsset->getType()])] = $newAsset; KalturaLog::debug("Added new asset [" . $newAsset->getId() . "] with no asset params"); } } $saveEntry = false; $defaultThumbAssetNew = null; foreach ($oldAssets as $oldAsset) { /* @var $oldAsset asset */ kFileSyncUtils::clearWAMSDataForKey($oldAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET)); //If the newAssets map contains an asset of the same type and paramsId as the current old asset, // re-link the old asset to the new asset. if (isset($newAssets[$oldAsset->getType()]) && isset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()])) { $newAsset = $newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()]; /* @var $newAsset asset */ KalturaLog::debug("Create link from new asset [" . $newAsset->getId() . "] to old asset [" . $oldAsset->getId() . "] for flavor [" . $oldAsset->getFlavorParamsId() . "]"); if ($oldAsset instanceof flavorAsset) { $oldAsset->setBitrate($newAsset->getBitrate()); $oldAsset->setFrameRate($newAsset->getFrameRate()); $oldAsset->setVideoCodecId($newAsset->getVideoCodecId()); } $oldAsset->setWidth($newAsset->getWidth()); $oldAsset->setHeight($newAsset->getHeight()); $oldAsset->setContainerFormat($newAsset->getContainerFormat()); $oldAsset->setSize($newAsset->getSize()); $oldAsset->setFileExt($newAsset->getFileExt()); $oldAsset->setTags($newAsset->getTags()); $oldAsset->setDescription($newAsset->getDescription()); $oldAsset->incrementVersion(); $oldAsset->setStatusLocalReady(); $oldAsset->save(); $oldFileSync = $oldAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $newFileSync = $newAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); kFileSyncUtils::createSyncFileLinkForKey($oldFileSync, $newFileSync); $newFlavorMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($newAsset->getId()); if ($newFlavorMediaInfo) { $oldFlavorNewMediaInfo = $newFlavorMediaInfo->copy(); $oldFlavorNewMediaInfo->setFlavorAssetId($oldAsset->getId()); $oldFlavorNewMediaInfo->setFlavorAssetVersion($oldAsset->getVersion()); $oldFlavorNewMediaInfo->save(); } unset($newAssets[$oldAsset->getType()][$oldAsset->getFlavorParamsId()]); if ($oldAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { $defaultThumbAssetNew = $oldAsset; KalturaLog::debug("Nominating ThumbAsset [" . $oldAsset->getId() . "] as the default ThumbAsset after replacent"); } } elseif ($oldAsset instanceof flavorAsset || $oldAsset instanceof thumbAsset) { KalturaLog::debug("Delete old asset [" . $oldAsset->getId() . "] for paramsId [" . $oldAsset->getFlavorParamsId() . "]"); $oldAsset->setStatus(flavorAsset::ASSET_STATUS_DELETED); $oldAsset->setDeletedAt(time()); $oldAsset->save(); $entry->removeFlavorParamsId($oldAsset->getFlavorParamsId()); $saveEntry = true; } } foreach ($newAssets as $newAssetsByTypes) { foreach ($newAssetsByTypes as $newAsset) { $createdAsset = $newAsset->copyToEntry($entry->getId(), $entry->getPartnerId()); KalturaLog::debug("Copied from new asset [" . $newAsset->getId() . "] to copied asset [" . $createdAsset->getId() . "] for flavor [" . $newAsset->getFlavorParamsId() . "]"); if ($createdAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) { $defaultThumbAssetNew = $newAsset; KalturaLog::debug("Nominating ThumbAsset [" . $newAsset->getId() . "] as the default ThumbAsset after replacent"); } } } if ($defaultThumbAssetNew) { kBusinessConvertDL::setAsDefaultThumbAsset($defaultThumbAssetNew); kalturalog::debug("Setting ThumbAsset [" . $defaultThumbAssetNew->getId() . "] as the default ThumbAsset"); } else { kalturalog::debug("No default ThumbAsset found for replacing entry [" . $tempEntry->getId() . "]"); $entry->setThumbnail(".jpg"); // thumbnailversion++ $entry->save(); $tempEntrySyncKey = $tempEntry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); $realEntrySyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB); kFileSyncUtils::createSyncFileLinkForKey($realEntrySyncKey, $tempEntrySyncKey); } $entry->setDimensions($tempEntry->getWidth(), $tempEntry->getHeight()); $entry->setLengthInMsecs($tempEntry->getLengthInMsecs()); $entry->setConversionProfileId($tempEntry->getConversionProfileId()); $entry->setConversionQuality($tempEntry->getConversionQuality()); $entry->setReplacingEntryId(null); $entry->setReplacementStatus(entryReplacementStatus::NONE); $entry->setStatus($tempEntry->getStatus()); $entry->save(); myEntryUtils::deleteEntry($tempEntry, null, true); $te = new TrackEntry(); $te->setTrackEventTypeId(TrackEntry::TRACK_ENTRY_EVENT_TYPE_REPLACED_ENTRY); $te->setEntryId($entry->getId()); $te->setParam1Str($tempEntry->getId()); $te->setDescription(__METHOD__ . "[" . __LINE__ . "]"); TrackEntry::addTrackEntry($te); }