Ejemplo n.º 1
0
 /**
  * List media info objects by filter and pager
  * 
  * @action list
  * @param KalturaMediaInfoFilter $filter
  * @param KalturaFilterPager $pager
  * @return KalturaMediaInfoListResponse
  */
 function listAction(KalturaMediaInfoFilter $filter = null, KalturaFilterPager $pager = null)
 {
     myDbHelper::$use_alternative_con = myDbHelper::DB_HELPER_CONN_PROPEL2;
     if (!$filter) {
         $filter = new KalturaMediaInfoFilter();
     }
     if (!$pager) {
         $pager = new KalturaFilterPager();
     }
     $mediaInfoFilter = new MediaInfoFilter();
     $filter->toObject($mediaInfoFilter);
     if ($filter->flavorAssetIdEqual) {
         // Since media_info table does not have partner_id column, enforce partner by getting the asset
         if (!assetPeer::retrieveById($filter->flavorAssetIdEqual)) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $filter->flavorAssetIdEqual);
         }
     }
     $c = new Criteria();
     $mediaInfoFilter->attachToCriteria($c);
     $totalCount = mediaInfoPeer::doCount($c);
     $pager->attachToCriteria($c);
     $dbList = mediaInfoPeer::doSelect($c);
     $list = KalturaMediaInfoArray::fromDbArray($dbList, $this->getResponseProfile());
     $response = new KalturaMediaInfoListResponse();
     $response->objects = $list;
     $response->totalCount = $totalCount;
     return $response;
 }
 public static function handleFlavorReady(BatchJob $dbBatchJob, $flavorAssetId)
 {
     // verifies that flavor asset created
     if (!$flavorAssetId) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId);
     }
     $currentFlavorAsset = assetPeer::retrieveById($flavorAssetId);
     // verifies that flavor asset exists
     if (!$currentFlavorAsset) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId);
     }
     // if the flavor deleted then it shouldn't be taken into ready calculations
     if ($currentFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_DELETED) {
         return $currentFlavorAsset;
     }
     //		Remarked because we want the original flavor ready behavior to work the same as other flavors
     //
     //		$rootBatchJob = $dbBatchJob->getRootJob();
     //
     //		// happens in case of post convert on the original (in case of bypass)
     //		if($rootBatchJob && $currentFlavorAsset->getIsOriginal())
     //		{
     //			kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
     //			return $dbBatchJob;
     //		}
     $sourceMediaInfo = mediaInfoPeer::retrieveOriginalByEntryId($dbBatchJob->getEntryId());
     $productMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($currentFlavorAsset->getId());
     $targetFlavor = assetParamsOutputPeer::retrieveByAssetId($currentFlavorAsset->getId());
     $postConvertData = $dbBatchJob->getData();
     $postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_FLAVOR;
     if ($postConvertData instanceof kPostConvertJobData) {
         $postConvertAssetType = $postConvertData->getPostConvertAssetType();
     }
     // don't validate in case of bypass, in case target flavor or media info are null
     if ($postConvertAssetType != BatchJob::POSTCONVERT_ASSET_TYPE_BYPASS && $targetFlavor && $productMediaInfo) {
         try {
             $productFlavor = KDLWrap::CDLValidateProduct($sourceMediaInfo, $targetFlavor, $productMediaInfo);
         } catch (Exception $e) {
             KalturaLog::err('KDL Error: ' . print_r($e, true));
         }
         $err = kBusinessConvertDL::parseFlavorDescription($productFlavor);
         KalturaLog::debug("BCDL: job id [" . $dbBatchJob->getId() . "] flavor params output id [" . $targetFlavor->getId() . "] flavor asset id [" . $currentFlavorAsset->getId() . "] desc: {$err}");
         if (!$productFlavor->IsValid()) {
             $description = $currentFlavorAsset->getDescription() . "\n{$err}";
             // mark the asset as ready
             $currentFlavorAsset->setDescription($description);
             $currentFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
             $currentFlavorAsset->save();
             if (!kConf::get('ignore_cdl_failure')) {
                 kJobsManager::failBatchJob($dbBatchJob, $err);
                 return null;
             }
         }
     }
     // mark the asset as ready
     $currentFlavorAsset->setStatusLocalReady();
     $currentFlavorAsset->save();
     kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob, $currentFlavorAsset->getFlavorParamsId());
     return $currentFlavorAsset;
 }
Ejemplo n.º 3
0
 public function clearMemory()
 {
     accessControlPeer::clearInstancePool();
     BatchJobPeer::clearInstancePool();
     BulkUploadResultPeer::clearInstancePool();
     categoryPeer::clearInstancePool();
     EmailIngestionProfilePeer::clearInstancePool();
     entryPeer::clearInstancePool();
     FileSyncPeer::clearInstancePool();
     flavorAssetPeer::clearInstancePool();
     flavorParamsConversionProfilePeer::clearInstancePool();
     flavorParamsOutputPeer::clearInstancePool();
     flavorParamsPeer::clearInstancePool();
     kshowPeer::clearInstancePool();
     mediaInfoPeer::clearInstancePool();
     moderationFlagPeer::clearInstancePool();
     moderationPeer::clearInstancePool();
     notificationPeer::clearInstancePool();
     roughcutEntryPeer::clearInstancePool();
     SchedulerConfigPeer::clearInstancePool();
     SchedulerPeer::clearInstancePool();
     SchedulerStatusPeer::clearInstancePool();
     SchedulerWorkerPeer::clearInstancePool();
     StorageProfilePeer::clearInstancePool();
     syndicationFeedPeer::clearInstancePool();
     TrackEntryPeer::clearInstancePool();
     uiConfPeer::clearInstancePool();
     UploadTokenPeer::clearInstancePool();
     // TODO clear default filters
     // TODO call all memory cleaner plugins
     if (function_exists('gc_collect_cycles')) {
         // php 5.3 and above
         gc_collect_cycles();
     }
 }
Ejemplo n.º 4
0
 /**
  * @param string $entryId
  * @return mediaInfo
  */
 public static function retrieveOriginalByEntryId($entryId)
 {
     $sourceFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId);
     if (!$sourceFlavorAsset) {
         return null;
     }
     $criteria = new Criteria();
     $criteria->add(mediaInfoPeer::FLAVOR_ASSET_ID, $sourceFlavorAsset->getId());
     return mediaInfoPeer::doSelectOne($criteria);
 }
 /**
  * Creates instance of class and initializes properties
  * @param string $type
  * @param string $filePath
  * @param KSchedularTaskConfig $taskConfig
  */
 public function __construct($type, $filePath, KSchedularTaskConfig $taskConfig, KalturaBatchJob $job, $wamsAssetId)
 {
     $this->wamsAssetId = $wamsAssetId;
     $this->filePath = $filePath;
     $this->mediaInfoParser = parent::getParser($type, $filePath, $taskConfig, $job);
     $this->partnerId = $job->partnerId;
     DbManager::setConfig(kConf::getDB());
     DbManager::initialize();
     $fileSync = FileSyncPeer::retrieveByWamsAssetId($this->wamsAssetId);
     if ($fileSync) {
         $flavorAsset = kFileSyncUtils::retrieveObjectForFileSync($fileSync);
         if ($flavorAsset instanceof asset) {
             $this->originalMediaInfo = mediaInfoPeer::retrieveOriginalByEntryId($flavorAsset->getEntryId());
             $entry = $flavorAsset->getentry();
             if ($entry) {
                 $this->mediaType = $entry->getMediaType();
             }
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * List media info objects by filter and pager
  * 
  * @action list
  * @param KalturaMediaInfoFilter $filter
  * @param KalturaFilterPager $pager
  * @return KalturaMediaInfoListResponse
  */
 function listAction(KalturaMediaInfoFilter $filter = null, KalturaFilterPager $pager = null)
 {
     if (!$filter) {
         $filter = new KalturaMediaInfoFilter();
     }
     if (!$pager) {
         $pager = new KalturaFilterPager();
     }
     $mediaInfoFilter = new MediaInfoFilter();
     $filter->toObject($mediaInfoFilter);
     $c = new Criteria();
     $mediaInfoFilter->attachToCriteria($c);
     $totalCount = mediaInfoPeer::doCount($c);
     $pager->attachToCriteria($c);
     $dbList = mediaInfoPeer::doSelect($c);
     $list = KalturaMediaInfoArray::fromDbArray($dbList);
     $response = new KalturaMediaInfoListResponse();
     $response->objects = $list;
     $response->totalCount = $totalCount;
     return $response;
 }
Ejemplo n.º 7
0
 public function copyToEntry($entryId = null, $partnerId = null)
 {
     $newFlavorAsset = $this->copy();
     if ($partnerId) {
         $newFlavorAsset->setPartnerId($partnerId);
     }
     if ($entryId) {
         $newFlavorAsset->setEntryId($entryId);
     }
     $newFlavorAsset->save();
     $flavorParamsOutput = flavorParamsOutputPeer::retrieveByFlavorAssetId($this->getId());
     if ($flavorParamsOutput) {
         $newFlavorParamsOutput = $flavorParamsOutput->copy();
         $newFlavorParamsOutput->setPartnerId($newFlavorAsset->getPartnerId());
         $newFlavorParamsOutput->setEntryId($newFlavorAsset->getEntryId());
         $newFlavorParamsOutput->setFlavorAssetId($newFlavorAsset->getId());
         $newFlavorParamsOutput->save();
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($this->getId());
     if ($mediaInfo) {
         $newMediaInfo = $mediaInfo->copy();
         $newMediaInfo->setFlavorAssetId($newFlavorAsset->getId());
         $newMediaInfo->save();
     }
     $assetSyncKey = $this->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $convertLogSyncKey = $this->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
     $newAssetSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $newConvertLogSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
     if (kFileSyncUtils::file_exists($assetSyncKey, true)) {
         kFileSyncUtils::softCopy($assetSyncKey, $newAssetSyncKey);
     }
     if (kFileSyncUtils::file_exists($convertLogSyncKey, true)) {
         kFileSyncUtils::softCopy($convertLogSyncKey, $newConvertLogSyncKey);
     }
     return $newFlavorAsset;
 }
 /**
  * batch addMediaInfoAction action saves a media info object
  * 
  * @action addMediaInfo
  * @param KalturaMediaInfo $mediaInfo
  * @return KalturaMediaInfo 
  * @throws KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND
  */
 function addMediaInfoAction(KalturaMediaInfo $mediaInfo)
 {
     $mediaInfoDb = null;
     $flavorAsset = null;
     if ($mediaInfo->flavorAssetId) {
         $flavorAsset = assetPeer::retrieveByIdNoFilter($mediaInfo->flavorAssetId);
         if (!$flavorAsset) {
             throw new KalturaAPIException(KalturaErrors::FLAVOR_ASSET_ID_NOT_FOUND, $mediaInfo->flavorAssetId);
         }
         $mediaInfoDb = mediaInfoPeer::retrieveByFlavorAssetId($mediaInfo->flavorAssetId);
         if ($mediaInfoDb && $mediaInfoDb->getFlavorAssetVersion() == $flavorAsset->getVersion()) {
             $mediaInfoDb = $mediaInfo->toUpdatableObject($mediaInfoDb);
         } else {
             $mediaInfoDb = null;
         }
     }
     if (!$mediaInfoDb) {
         $mediaInfoDb = $mediaInfo->toInsertableObject();
     }
     if ($flavorAsset) {
         $mediaInfoDb->setFlavorAssetVersion($flavorAsset->getVersion());
     }
     $mediaInfoDb = kBatchManager::addMediaInfo($mediaInfoDb);
     $mediaInfo->fromObject($mediaInfoDb);
     return $mediaInfo;
 }
 /**
  * @param kFileSyncResource $resource
  * @param entry $dbEntry
  * @param asset $dbAsset
  * @return asset
  * @throws KalturaErrors::UPLOAD_ERROR
  * @throws KalturaErrors::INVALID_OBJECT_ID
  */
 protected function attachFileSyncResource(kFileSyncResource $resource, entry $dbEntry, asset $dbAsset = null)
 {
     $dbEntry->setSource(entry::ENTRY_MEDIA_SOURCE_KALTURA);
     $dbEntry->save();
     try {
         $syncable = kFileSyncObjectManager::retrieveObject($resource->getFileSyncObjectType(), $resource->getObjectId());
     } catch (kFileSyncException $e) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $resource->getObjectId());
     }
     $srcSyncKey = $syncable->getSyncKey($resource->getObjectSubType(), $resource->getVersion());
     $dbAsset = $this->attachFileSync($srcSyncKey, $dbEntry, $dbAsset);
     // Copy the media info from the old asset to the new one
     if ($syncable instanceof asset && $resource->getObjectSubType() == asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET) {
         $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($syncable->getId());
         if ($mediaInfo) {
             $newMediaInfo = $mediaInfo->copy();
             $newMediaInfo->setFlavorAssetId($dbAsset->getId());
             $newMediaInfo->save();
         }
     }
     return $dbAsset;
 }
Ejemplo n.º 10
0
 public function execute()
 {
     //entitlement should be disabled to serveFlavor action as we do not get ks on this action.
     KalturaCriterion::disableTag(KalturaCriterion::TAG_ENTITLEMENT_CATEGORY);
     requestUtils::handleConditionalGet();
     $flavorId = $this->getRequestParameter("flavorId");
     $shouldProxy = $this->getRequestParameter("forceproxy", false);
     $fileName = $this->getRequestParameter("fileName");
     $fileParam = $this->getRequestParameter("file");
     $fileParam = basename($fileParam);
     $pathOnly = $this->getRequestParameter("pathOnly", false);
     $referrer = base64_decode($this->getRequestParameter("referrer"));
     if (!is_string($referrer)) {
         // base64_decode can return binary data
         $referrer = '';
     }
     $flavorAsset = assetPeer::retrieveById($flavorId);
     if (is_null($flavorAsset)) {
         KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
     }
     $entryId = $this->getRequestParameter("entryId");
     if (!is_null($entryId) && $flavorAsset->getEntryId() != $entryId) {
         KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
     }
     if ($fileName) {
         header("Content-Disposition: attachment; filename=\"{$fileName}\"");
         header("Content-Type: application/force-download");
         header("Content-Description: File Transfer");
     }
     $clipTo = null;
     $entry = $flavorAsset->getentry();
     if (!$entry) {
         KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
     }
     KalturaMonitorClient::initApiMonitor(false, 'extwidget.serveFlavor', $flavorAsset->getPartnerId());
     myPartnerUtils::enforceDelivery($entry, $flavorAsset);
     $version = $this->getRequestParameter("v");
     if (!$version) {
         $version = $flavorAsset->getVersion();
     }
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET, $version);
     if ($pathOnly && kIpAddressUtils::isInternalIp($_SERVER['REMOTE_ADDR'])) {
         $path = null;
         list($file_sync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, false, false);
         if ($file_sync) {
             $parent_file_sync = kFileSyncUtils::resolve($file_sync);
             $path = $parent_file_sync->getFullPath();
             if ($fileParam && is_dir($path)) {
                 $path .= "/{$fileParam}";
             }
         }
         $renderer = new kRendererString('{"sequences":[{"clips":[{"type":"source","path":"' . $path . '"}]}]}', 'application/json');
         if ($path) {
             $this->storeCache($renderer, $flavorAsset->getPartnerId());
         }
         $renderer->output();
         KExternalErrors::dieGracefully();
     }
     if (kConf::hasParam('serve_flavor_allowed_partners') && !in_array($flavorAsset->getPartnerId(), kConf::get('serve_flavor_allowed_partners'))) {
         KExternalErrors::dieError(KExternalErrors::ACTION_BLOCKED);
     }
     if (!kFileSyncUtils::file_exists($syncKey, false)) {
         list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
         if (is_null($fileSync)) {
             KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]");
             KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
         }
         // always dump remote urls so they will be cached by the cdn transparently
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
         kFileUtils::dumpUrl($remoteUrl);
     }
     $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey);
     $isFlv = false;
     if (!$shouldProxy) {
         $flvWrapper = new myFlvHandler($path);
         $isFlv = $flvWrapper->isFlv();
     }
     $clipFrom = $this->getRequestParameter("clipFrom", 0);
     // milliseconds
     if (is_null($clipTo)) {
         $clipTo = $this->getRequestParameter("clipTo", self::NO_CLIP_TO);
     }
     // milliseconds
     if ($clipTo == 0) {
         $clipTo = self::NO_CLIP_TO;
     }
     if (!is_numeric($clipTo) || $clipTo < 0) {
         KExternalErrors::dieError(KExternalErrors::BAD_QUERY, 'clipTo must be a positive number');
     }
     $seekFrom = $this->getRequestParameter("seekFrom", -1);
     if ($seekFrom <= 0) {
         $seekFrom = -1;
     }
     $seekFromBytes = $this->getRequestParameter("seekFromBytes", -1);
     if ($seekFromBytes <= 0) {
         $seekFromBytes = -1;
     }
     if ($fileParam && is_dir($path)) {
         $path .= "/{$fileParam}";
         kFileUtils::dumpFile($path, null, null);
         KExternalErrors::dieGracefully();
     } else {
         if (!$isFlv || $clipTo == self::NO_CLIP_TO && $seekFrom < 0 && $seekFromBytes < 0) {
             $limit_file_size = 0;
             if ($clipTo != self::NO_CLIP_TO) {
                 if (strtolower($flavorAsset->getFileExt()) == 'mp4' && PermissionPeer::isValidForPartner(PermissionName::FEATURE_ACCURATE_SERVE_CLIPPING, $flavorAsset->getPartnerId())) {
                     $contentPath = myContentStorage::getFSContentRootPath();
                     $tempClipName = $version . '_' . $clipTo . '.mp4';
                     $tempClipPath = $contentPath . myContentStorage::getGeneralEntityPath("entry/tempclip", $flavorAsset->getIntId(), $flavorAsset->getId(), $tempClipName);
                     if (!file_exists($tempClipPath)) {
                         kFile::fullMkdir($tempClipPath);
                         $clipToSec = round($clipTo / 1000, 3);
                         $cmdLine = kConf::get("bin_path_ffmpeg") . " -i {$path} -vcodec copy -acodec copy -f mp4 -t {$clipToSec} -y {$tempClipPath} 2>&1";
                         KalturaLog::log("Executing {$cmdLine}");
                         $output = array();
                         $return_value = "";
                         exec($cmdLine, $output, $return_value);
                         KalturaLog::log("ffmpeg returned {$return_value}, output:" . implode("\n", $output));
                     }
                     if (file_exists($tempClipPath)) {
                         KalturaLog::log("Dumping {$tempClipPath}");
                         kFileUtils::dumpFile($tempClipPath);
                     } else {
                         KalturaLog::err('Failed to clip the file using ffmpeg, falling back to rough clipping');
                     }
                 }
                 $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
                 if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) {
                     $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration());
                     $limit_file_size = floor(@kFile::fileSize($path) * ($clipTo / $duration) * 1.2);
                 }
             }
             $renderer = kFileUtils::getDumpFileRenderer($path, null, null, $limit_file_size);
             if (!$fileName) {
                 $this->storeCache($renderer, $flavorAsset->getPartnerId());
             }
             $renderer->output();
             KExternalErrors::dieGracefully();
         }
     }
     $audioOnly = $this->getRequestParameter("audioOnly");
     // milliseconds
     if ($audioOnly === '0') {
         // audioOnly was explicitly set to 0 - don't attempt to make further automatic investigations
     } elseif ($flvWrapper->getFirstVideoTimestamp() < 0) {
         $audioOnly = true;
     }
     $bytes = 0;
     if ($seekFrom !== -1 && $seekFrom !== 0) {
         list($bytes, $duration, $firstTagByte, $toByte) = $flvWrapper->clip(0, -1, $audioOnly);
         list($bytes, $duration, $fromByte, $toByte, $seekFromTimestamp) = $flvWrapper->clip($seekFrom, -1, $audioOnly);
         $seekFromBytes = myFlvHandler::FLV_HEADER_SIZE + $flvWrapper->getMetadataSize($audioOnly) + $fromByte - $firstTagByte;
     } else {
         list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly);
     }
     $metadataSize = $flvWrapper->getMetadataSize($audioOnly);
     $dataOffset = $metadataSize + myFlvHandler::getHeaderSize();
     $totalLength = $dataOffset + $bytes;
     list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly);
     list($rangeFrom, $rangeTo, $rangeLength) = requestUtils::handleRangeRequest($totalLength);
     if ($totalLength < 1000) {
         // (actually $total_length is probably 13 or 143 - header + empty metadata tag) probably a bad flv maybe only the header - dont cache
         requestUtils::sendCdnHeaders("flv", $rangeLength, 0);
     } else {
         requestUtils::sendCdnHeaders("flv", $rangeLength);
     }
     // dont inject cuepoint into the stream
     $cuepointTime = 0;
     $cuepointPos = 0;
     try {
         Propel::close();
     } catch (Exception $e) {
         $this->logMessage("serveFlavor: error closing db {$e}");
     }
     header("Content-Type: video/x-flv");
     $flvWrapper->dump(self::CHUNK_SIZE, $fromByte, $toByte, $audioOnly, $seekFromBytes, $rangeFrom, $rangeTo, $cuepointTime, $cuepointPos);
     KExternalErrors::dieGracefully();
 }
Ejemplo n.º 11
0
 public function execute()
 {
     requestUtils::handleConditionalGet();
     $flavorId = $this->getRequestParameter("flavorId");
     $shouldProxy = $this->getRequestParameter("forceproxy", false);
     $ks = $this->getRequestParameter("ks");
     $fileParam = $this->getRequestParameter("file");
     $referrer = base64_decode($this->getRequestParameter("referrer"));
     if (!is_string($referrer)) {
         // base64_decode can return binary data
         $referrer = '';
     }
     $flavorAsset = flavorAssetPeer::retrieveById($flavorId);
     if (is_null($flavorAsset)) {
         KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
     }
     $entry = entryPeer::retrieveByPK($flavorAsset->getEntryId());
     if (is_null($entry)) {
         KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
     }
     myPartnerUtils::blockInactivePartner($flavorAsset->getPartnerId());
     myPartnerUtils::enforceDelivery($flavorAsset->getPartnerId());
     //disabled enforce cdn because of rtmp delivery
     //requestUtils::enforceCdnDelivery($flavorAsset->getPartnerId());
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     if (!kFileSyncUtils::file_exists($syncKey, false)) {
         list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
         if (is_null($fileSync)) {
             KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]");
             KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
         }
         // always dump remote urls so they will be cached by the cdn transparently
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
         kFile::dumpUrl($remoteUrl, true, true);
     }
     $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey);
     $flvWrapper = new myFlvHandler($path);
     $isFlv = $flvWrapper->isFlv();
     $clipFrom = $this->getRequestParameter("clipFrom", 0);
     // milliseconds
     $clipTo = $this->getRequestParameter("clipTo", 2147483647);
     // milliseconds
     if ($clipTo == 0) {
         $clipTo = 2147483647;
     }
     if (is_dir($path) && $fileParam) {
         $path .= "/{$fileParam}";
         //echo "path($path),file($fileParam)";
         kFile::dumpFile($path, null, null);
         die;
     } else {
         if (!$isFlv) {
             $limit_file_size = 0;
             if ($clipTo != 2147483647) {
                 $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
                 if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) {
                     $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration());
                     $limit_file_size = floor(@filesize($path) * ($clipTo / $duration));
                 }
             }
             kFile::dumpFile($path, null, null, $limit_file_size);
             die;
         }
     }
     $audioOnly = $this->getRequestParameter("audioOnly");
     // milliseconds
     if ($audioOnly === '0') {
         // audioOnly was explicitly set to 0 - don't attempt to make further automatic investigations
     } elseif ($flvWrapper->getFirstVideoTimestamp() < 0) {
         $audioOnly = true;
     }
     $seekFrom = $this->getRequestParameter("seekFrom", -1);
     if ($seekFrom <= 0) {
         $seekFrom = -1;
     }
     $seekFromBytes = $this->getRequestParameter("seekFromBytes", -1);
     if ($seekFromBytes <= 0) {
         $seekFromBytes = -1;
     }
     $bytes = 0;
     if ($seekFrom !== -1 && $seekFrom !== 0) {
         list($bytes, $duration, $firstTagByte, $toByte) = $flvWrapper->clip(0, -1, $audioOnly);
         list($bytes, $duration, $fromByte, $toByte, $seekFromTimestamp) = $flvWrapper->clip($seekFrom, -1, $audioOnly);
         $seekFromBytes = myFlvHandler::FLV_HEADER_SIZE + $flvWrapper->getMetadataSize($audioOnly) + $fromByte - $firstTagByte;
     } else {
         list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly);
     }
     $metadataSize = $flvWrapper->getMetadataSize($audioOnly);
     $dataOffset = $metadataSize + myFlvHandler::getHeaderSize();
     $totalLength = $dataOffset + $bytes;
     list($bytes, $duration, $fromByte, $toByte, $fromTs, $cuepointPos) = myFlvStaticHandler::clip($path, $clipFrom, $clipTo, $audioOnly);
     list($rangeFrom, $rangeTo, $rangeLength) = requestUtils::handleRangeRequest($totalLength);
     if ($totalLength < 1000) {
         // (actually $total_length is probably 13 or 143 - header + empty metadata tag) probably a bad flv maybe only the header - dont cache
         requestUtils::sendCdnHeaders("flv", $rangeLength, 0);
     } else {
         requestUtils::sendCdnHeaders("flv", $rangeLength);
     }
     header('Content-Disposition: attachment; filename="video.flv"');
     // dont inject cuepoint into the stream
     $cuepointTime = 0;
     $cuepointPos = 0;
     try {
         Propel::close();
     } catch (Exception $e) {
         $this->logMessage("serveFlavor: error closing db {$e}");
     }
     header("Content-Type: video/x-flv");
     $flvWrapper->dump(self::CHUNK_SIZE, $fromByte, $toByte, $audioOnly, $seekFromBytes, $rangeFrom, $rangeTo, $cuepointTime, $cuepointPos);
     die;
 }
Ejemplo n.º 12
0
 /**
  * @return int
  */
 private function initEntryDuration()
 {
     $this->duration = $this->entry->getDurationInt();
     $flavors = $this->deliveryAttributes->getFlavorAssets();
     foreach ($flavors as $flavorAsset) {
         /* @var $flavorAsset flavorAsset */
         $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
         if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) {
             $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration());
             $this->duration = $duration / 1000;
             break;
         }
     }
 }
 private function getValidVideoPath(KalturaDistributionJobData $distributionJobData)
 {
     $flavorAssets = array();
     $videoAssetFilePath = null;
     $isValidVideo = false;
     if (count($distributionJobData->entryDistribution->flavorAssetIds)) {
         $flavorAssets = assetPeer::retrieveByIds(explode(',', $distributionJobData->entryDistribution->flavorAssetIds));
     } else {
         $flavorAssets = assetPeer::retrieveReadyFlavorsByEntryId($distributionJobData->entryDistribution->entryId);
     }
     foreach ($flavorAssets as $flavorAsset) {
         $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
         if (kFileSyncUtils::fileSync_exists($syncKey)) {
             $videoAssetFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey, false);
             $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
             if ($mediaInfo) {
                 try {
                     FacebookGraphSdkUtils::validateVideoAttributes($videoAssetFilePath, $mediaInfo->getFileSize(), $mediaInfo->getVideoDuration());
                     $isValidVideo = true;
                 } catch (Exception $e) {
                     KalturaLog::debug('Asset [' . $flavorAsset->getId() . '] not valid for distribution: ' . $e->getMessage());
                 }
             }
             if ($isValidVideo) {
                 break;
             }
         }
     }
     return $videoAssetFilePath;
 }
Ejemplo n.º 14
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kStorageExportJobData $data
  * @return BatchJob
  */
 public static function handleStorageExportFailed(BatchJob $dbBatchJob, kStorageExportJobData $data)
 {
     if ($dbBatchJob->getErrType() == BatchJobErrorTypes::APP && $dbBatchJob->getErrNumber() == BatchJobAppErrors::FILE_ALREADY_EXISTS) {
         KalturaLog::notice("remote file already exists");
         return $dbBatchJob;
     }
     $fileSync = FileSyncPeer::retrieveByPK($data->getSrcFileSyncId());
     if (!$fileSync) {
         KalturaLog::err("FileSync [" . $data->getSrcFileSyncId() . "] not found");
         return $dbBatchJob;
     }
     $fileSync->setStatus(FileSync::FILE_SYNC_STATUS_ERROR);
     $fileSync->save();
     // if an asset was exported - check if should set its status to ERROR
     $asset = assetPeer::retrieveByFileSync($fileSync);
     if ($asset && $asset->getStatus() == asset::ASSET_STATUS_EXPORTING) {
         $asset->setStatus(asset::ASSET_STATUS_ERROR);
         $asset->save();
         if ($asset instanceof flavorAsset) {
             $flavorParamsOutput = $asset->getFlavorParamsOutput();
             $flavorParamsOutputId = $flavorParamsOutput ? $flavorParamsOutput->getId() : null;
             $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($asset->getId());
             $mediaInfoId = $mediaInfo ? $mediaInfo->getId() : null;
             kBusinessPostConvertDL::handleConvertFailed($dbBatchJob, null, $asset->getId(), $flavorParamsOutputId, $mediaInfoId);
         }
     }
     return $dbBatchJob;
 }
Ejemplo n.º 15
0
 function calculateEstimatedEffort(BatchJob $batchJob)
 {
     $mediaInfo = mediaInfoPeer::retrieveByPK($this->getMediaInfoId());
     if (is_null($mediaInfo)) {
         $sumEffort = 0;
         $fileSyncs = $this->getSrcFileSyncs();
         foreach ($fileSyncs as $fileSync) {
             $fileSize = filesize($fileSync->getFileSyncLocalPath());
             if ($fileSize !== False) {
                 $sumEffort += $fileSize;
             }
         }
         if ($sumEffort != 0) {
             return $sumEffort;
         }
         return self::MAX_ESTIMATED_EFFORT;
     } else {
         return max($mediaInfo->getVideoDuration(), $mediaInfo->getAudioDuration(), $mediaInfo->getContainerDuration());
     }
 }
Ejemplo n.º 16
0
 public function copyToEntry($entryId = null, $partnerId = null)
 {
     $newFlavorAsset = $this->copy();
     //this is the first version of the new asset.
     $newFlavorAsset->incrementVersion();
     if ($partnerId) {
         $newFlavorAsset->setPartnerId($partnerId);
     }
     if ($entryId) {
         $newFlavorAsset->setEntryId($entryId);
     }
     $newFlavorAsset->save();
     $flavorParamsOutput = assetParamsOutputPeer::retrieveByAssetId($this->getId());
     if ($flavorParamsOutput) {
         $newFlavorParamsOutput = $flavorParamsOutput->copy();
         $newFlavorParamsOutput->setPartnerId($newFlavorAsset->getPartnerId());
         $newFlavorParamsOutput->setEntryId($newFlavorAsset->getEntryId());
         $newFlavorParamsOutput->setFlavorAssetId($newFlavorAsset->getId());
         $newFlavorParamsOutput->save();
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($this->getId());
     if ($mediaInfo) {
         $newMediaInfo = $mediaInfo->copy();
         $newMediaInfo->setFlavorAssetId($newFlavorAsset->getId());
         $newMediaInfo->setFlavorAssetVersion($newFlavorAsset->getVersion());
         $newMediaInfo->save();
     }
     $assetSyncKey = $this->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $convertLogSyncKey = $this->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
     $ismSyncKey = $this->getSyncKey(self::FILE_SYNC_ASSET_SUB_TYPE_ISM);
     $ismcSyncKey = $this->getSyncKey(self::FILE_SYNC_ASSET_SUB_TYPE_ISMC);
     $newAssetSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $newConvertLogSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
     $newIsmSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_ASSET_SUB_TYPE_ISM);
     $newIsmcSyncKey = $newFlavorAsset->getSyncKey(self::FILE_SYNC_ASSET_SUB_TYPE_ISMC);
     if (kFileSyncUtils::fileSync_exists($assetSyncKey)) {
         kFileSyncUtils::softCopy($assetSyncKey, $newAssetSyncKey);
     }
     if (kFileSyncUtils::fileSync_exists($convertLogSyncKey)) {
         kFileSyncUtils::softCopy($convertLogSyncKey, $newConvertLogSyncKey);
     }
     if (kFileSyncUtils::fileSync_exists($ismSyncKey)) {
         kFileSyncUtils::softCopy($ismSyncKey, $newIsmSyncKey);
     }
     if (kFileSyncUtils::fileSync_exists($ismcSyncKey)) {
         kFileSyncUtils::softCopy($ismcSyncKey, $newIsmcSyncKey);
     }
     kEventsManager::raiseEvent(new kObjectAddedEvent($newFlavorAsset));
     return $newFlavorAsset;
 }
Ejemplo n.º 17
0
 public static function continueProfileConvert(BatchJob $parentJob)
 {
     $convertProfileJob = $parentJob->getRootJob();
     if ($convertProfileJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         throw new Exception("Root job [" . $convertProfileJob->getId() . "] is not profile conversion");
     }
     KalturaLog::log("Conversion decision layer continued for entry [" . $parentJob->getEntryId() . "]");
     $convertProfileData = $convertProfileJob->getData();
     $entryId = $convertProfileJob->getEntryId();
     $entry = $convertProfileJob->getEntry();
     if (!$entry) {
         throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId);
     }
     $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if (!$profile) {
         $errDescription = "Conversion profile for entryId [{$entryId}] not found";
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $entryId);
         throw new Exception($errDescription);
     }
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $entryId);
         throw new Exception($errDescription);
     }
     // gets the list of flavor params of the conversion profile
     $list = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     if (!count($list)) {
         $errDescription = "No flavors match the profile id [{$profile->getId()}]";
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $entryId);
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalFlavorAsset->setDeletedAt(time());
         $originalFlavorAsset->save();
         throw new Exception($errDescription);
     }
     // gets the ids of the flavor params
     $flavorsIds = array();
     $conversionProfileFlavorParams = array();
     foreach ($list as $flavorParamsConversionProfile) {
         $flavorsId = $flavorParamsConversionProfile->getFlavorParamsId();
         $flavorsIds[] = $flavorsId;
         $conversionProfileFlavorParams[$flavorsId] = $flavorParamsConversionProfile;
     }
     // gets the flavor params by the id
     $flavors = assetParamsPeer::retrieveFlavorsByPKs($flavorsIds);
     self::checkConvertProfileParams($flavors, $conversionProfileFlavorParams, $entry);
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!count($flavors)) {
         return false;
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     try {
         return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $profile->getId(), $mediaInfo);
     } catch (Exception $e) {
         KalturaLog::err('decideProfileFlavorsConvert - ' . $e->getMessage());
     }
 }
Ejemplo n.º 18
0
 /**
  * addFlavorConvertJob adds a single flavor conversion 
  * 
  * @param FileSyncKey $srcSyncKey
  * @param flavorParamsOutput $flavor
  * @param int $flavorAssetId
  * @param int $conversionProfileId
  * @param int $mediaInfoId
  * @param BatchJob $parentJob
  * @param int $lastEngineType  
  * @param bool $sameRoot
  * @return BatchJob 
  */
 public static function addFlavorConvertJob(array $srcSyncKeys, flavorParamsOutput $flavor, $flavorAssetId, $conversionProfileId = null, $mediaInfoId = null, BatchJob $parentJob = null, $lastEngineType = null, $sameRoot = true, $priority = 0)
 {
     KalturaLog::debug('Add convert job for [' . $flavorAssetId . ']');
     $flavorAsset = assetPeer::retrieveById($flavorAssetId);
     if (!$flavorAsset) {
         KalturaLog::err("No flavor asset found for id [{$flavorAssetId}]");
         return null;
     }
     $partner = PartnerPeer::retrieveByPK($flavorAsset->getPartnerId());
     $srcFileSyncs = array();
     $waitForImportComplete = false;
     foreach ($srcSyncKeys as $srcSyncKey) {
         $srcFileSyncDescriptor = new kSourceFileSyncDescriptor();
         $addImportJob = false;
         $fileSync = self::getFileSyncForKey($srcSyncKey, $flavor, $flavorAsset, $partner, $addImportJob);
         if (!$fileSync) {
             return null;
         }
         $srcFlavorAsset = assetPeer::retrieveById($srcSyncKey->getObjectId());
         if ($addImportJob) {
             KalturaLog::debug("Creates import job for remote file sync");
             $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT);
             $flavorAsset->setDescription("Source file sync is importing: {$srcSyncKey}");
             $flavorAsset->save();
             $url = $fileSync->getExternalUrl($flavorAsset->getEntryId());
             kJobsManager::addImportJob($parentJob, $flavorAsset->getEntryId(), $partner->getId(), $url, $srcFlavorAsset, null, null, true);
             $waitForImportComplete = true;
         } else {
             if ($flavor->getSourceRemoteStorageProfileId() == StorageProfile::STORAGE_KALTURA_DC) {
                 if ($fileSync->getFileType() != FileSync::FILE_SYNC_FILE_TYPE_URL) {
                     $srcFileSyncDescriptor->setFileSyncLocalPath($fileSync->getFullPath());
                 }
             } else {
                 $srcFileSyncDescriptor->setFileSyncLocalPath($fileSync->getFilePath());
             }
             $srcFileSyncDescriptor->setFileSyncRemoteUrl($fileSync->getExternalUrl($flavorAsset->getEntryId()));
             $srcFileSyncDescriptor->setAssetId($srcSyncKey->getObjectId());
             $srcFileSyncDescriptor->setAssetParamsId($srcFlavorAsset->getFlavorParamsId());
             $srcFileSyncDescriptor->setFileSyncObjectSubType($srcSyncKey->getObjectSubType());
             $srcFileSyncs[] = $srcFileSyncDescriptor;
         }
     }
     if ($waitForImportComplete) {
         return;
     }
     // creates convert data
     $convertData = new kConvertJobData();
     $convertData->setSrcFileSyncs($srcFileSyncs);
     $convertData->setMediaInfoId($mediaInfoId);
     $convertData->setFlavorParamsOutputId($flavor->getId());
     $convertData->setFlavorAssetId($flavorAssetId);
     $convertData->setConversionProfileId($conversionProfileId);
     $convertData->setPriority($priority);
     $dbCurrentConversionEngine = self::getNextConversionEngine($flavor, $parentJob, $lastEngineType, $convertData);
     if (!$dbCurrentConversionEngine) {
         return null;
     }
     // creats a child convert job
     if ($parentJob) {
         $dbConvertFlavorJob = $parentJob->createChild(BatchJobType::CONVERT, $dbCurrentConversionEngine, $sameRoot);
         KalturaLog::log("Created from parent job");
     } else {
         $dbConvertFlavorJob = new BatchJob();
         $dbConvertFlavorJob->setPartnerId($flavor->getPartnerId());
         $dbConvertFlavorJob->setJobType(BatchJobType::CONVERT);
         $dbConvertFlavorJob->setJobSubType($dbCurrentConversionEngine);
         KalturaLog::log("Created from flavor convert job");
     }
     $dbConvertFlavorJob->setEntryId($flavor->getEntryId());
     KalturaLog::log("Job created with entry id [" . $dbConvertFlavorJob->getEntryId() . "]");
     $mediaInfo = mediaInfoPeer::retrieveByPK($mediaInfoId);
     if ($mediaInfo === NULL) {
         // in case we don't know the estimatted info, we will set it to a big number.
         $estimatedEffort = kJobData::MAX_ESTIMATED_EFFORT;
     } else {
         $estimatedEffort = max($mediaInfo->getVideoDuration(), $mediaInfo->getAudioDuration(), $mediaInfo->getContainerDuration());
     }
     $dbConvertFlavorJob->setObjectId($flavorAssetId);
     $dbConvertFlavorJob->setObjectType(BatchJobObjectType::ASSET);
     return kJobsManager::addJob($dbConvertFlavorJob, $convertData, BatchJobType::CONVERT, $dbCurrentConversionEngine);
 }
Ejemplo n.º 19
0
 public function execute()
 {
     requestUtils::handleConditionalGet();
     $entry_id = $this->getRequestParameter("entry_id");
     $ks_str = $this->getRequestParameter("ks");
     $base64_referrer = $this->getRequestParameter("referrer");
     $referrer = base64_decode($base64_referrer);
     if (!is_string($referrer)) {
         // base64_decode can return binary data
         $referrer = "";
     }
     $clip_from = $this->getRequestParameter("clip_from", 0);
     // milliseconds
     $clip_to = $this->getRequestParameter("clip_to", 2147483647);
     // milliseconds
     if ($clip_to == 0) {
         $clip_to = 2147483647;
     }
     $request = $_SERVER["REQUEST_URI"];
     // remove dynamic fields from the url so we'll request a single url from the cdn
     $request = str_replace("/referrer/{$base64_referrer}", "", $request);
     $request = str_replace("/ks/{$ks_str}", "", $request);
     $entry = null;
     if ($ks_str) {
         try {
             kCurrentContext::initKsPartnerUser($ks_str);
         } catch (Exception $ex) {
             KExternalErrors::dieError(KExternalErrors::INVALID_KS);
         }
     } else {
         $entry = kCurrentContext::initPartnerByEntryId($entry_id);
         if (!$entry) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     }
     kEntitlementUtils::initEntitlementEnforcement();
     // workaround the filter which hides all the deleted entries -
     // now that deleted entries are part of xmls (they simply point to the 'deleted' templates), we should allow them here
     if (!$entry) {
         $entry = entryPeer::retrieveByPKNoFilter($entry_id);
     } else {
         if (!kEntitlementUtils::isEntryEntitled($entry)) {
             KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
         }
     }
     if (!$entry) {
         KExternalErrors::dieError(KExternalErrors::ENTRY_NOT_FOUND);
     }
     KalturaMonitorClient::initApiMonitor(false, 'keditorservices.flvclipper', $entry->getPartnerId());
     myPartnerUtils::blockInactivePartner($entry->getPartnerId());
     if (PermissionPeer::isValidForPartner(PermissionName::FEATURE_BLOCK_FLVCLIPPER_ACTION, $entry->getPartnerId())) {
         KExternalErrors::dieError(KExternalErrors::ACTION_BLOCKED);
     }
     // set the memory size to be able to serve big files in a single chunk
     ini_set("memory_limit", "64M");
     // set the execution time to be able to serve big files in a single chunk
     ini_set("max_execution_time", 240);
     if ($entry->getType() == entryType::MIX && $entry->getStatus() == entryStatus::DELETED) {
         // because the fiter was turned off - a manual check for deleted entries must be done.
         KExternalErrors::dieGracefully();
     } else {
         if ($entry->getMediaType() == entry::ENTRY_MEDIA_TYPE_IMAGE) {
             $version = $this->getRequestParameter("version", null);
             $width = $this->getRequestParameter("width", -1);
             $height = $this->getRequestParameter("height", -1);
             $crop_provider = $this->getRequestParameter("crop_provider", null);
             $bgcolor = $this->getRequestParameter("bgcolor", "ffffff");
             $type = $this->getRequestParameter("type", 1);
             $quality = $this->getRequestParameter("quality", 0);
             $src_x = $this->getRequestParameter("src_x", 0);
             $src_y = $this->getRequestParameter("src_y", 0);
             $src_w = $this->getRequestParameter("src_w", 0);
             $src_h = $this->getRequestParameter("src_h", 0);
             $vid_sec = $this->getRequestParameter("vid_sec", -1);
             $vid_slice = $this->getRequestParameter("vid_slice", -1);
             $vid_slices = $this->getRequestParameter("vid_slices", -1);
             if ($width == -1 && $height == -1) {
                 $width = 640;
                 $height = 480;
             } else {
                 if ($width == -1) {
                     // if only either width or height is missing reset them to zero, and convertImage will handle them
                     $width = 0;
                 } else {
                     if ($height == -1) {
                         $height = 0;
                     }
                 }
             }
             $tempThumbPath = myEntryUtils::resizeEntryImage($entry, $version, $width, $height, $type, $bgcolor, $crop_provider, $quality, $src_x, $src_y, $src_w, $src_h, $vid_sec, $vid_slice, $vid_slices);
             kFileUtils::dumpFile($tempThumbPath, null, strpos($tempThumbPath, "_NOCACHE_") === false ? null : 0);
         }
     }
     $audio_only = $this->getRequestParameter("audio_only");
     // milliseconds
     $flavor = $this->getRequestParameter("flavor", 1);
     //
     $flavor_param_id = $this->getRequestParameter("flavor_param_id", null);
     //
     $streamer = $this->getRequestParameter("streamer");
     //
     if (substr($streamer, 0, 4) == "rtmp") {
         // the fms may add .mp4 to the end of the url
         $streamer = "rtmp";
     }
     // grab seek_from_bytes parameter and normalize url
     $seek_from_bytes = $this->getRequestParameter("seek_from_bytes", -1);
     $request = str_replace("/seek_from_bytes/{$seek_from_bytes}", "", $request);
     if ($seek_from_bytes <= 0) {
         $seek_from_bytes = -1;
     }
     // grab seek_from parameter and normalize url
     $seek_from = $this->getRequestParameter("seek_from", -1);
     $request = str_replace("/seek_from/{$seek_from}", "", $request);
     if ($seek_from <= 0) {
         $seek_from = -1;
     }
     $this->dump_from_byte = 0;
     // reset accurate seek from timestamp
     $seek_from_timestamp = -1;
     // backward compatibility
     if ($flavor === "0") {
         // for edit version
         $flavor = "edit";
     }
     if ($flavor === "1" || $flavor === 1) {
         // for play version
         $flavor = null;
     }
     // when flavor is null, we will get a default flavor
     if ($flavor == "edit") {
         $flavorAsset = assetPeer::retrieveBestEditByEntryId($entry->getId());
     } elseif (!is_null($flavor)) {
         $flavorAsset = assetPeer::retrieveById($flavor);
         // when specific asset was request, we don't validate its tags
         if ($flavorAsset && ($flavorAsset->getEntryId() != $entry->getId() || $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY)) {
             $flavorAsset = null;
         }
         // we will throw an error later
     } elseif (is_null($flavor) && !is_null($flavor_param_id)) {
         $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entry->getId(), $flavor_param_id);
         if ($flavorAsset && $flavorAsset->getStatus() != flavorAsset::FLAVOR_ASSET_STATUS_READY) {
             $flavorAsset = null;
         }
         // we will throw an error later
     } else {
         if ($entry->getSource() == entry::ENTRY_MEDIA_SOURCE_WEBCAM) {
             $flavorAsset = assetPeer::retrieveOriginalByEntryId($entry->getId());
         } else {
             $flavorAsset = assetPeer::retrieveBestPlayByEntryId($entry->getId());
         }
         if (!$flavorAsset) {
             $flavorAssets = assetPeer::retrieveReadyFlavorsByEntryIdAndTag($entry->getId(), flavorParams::TAG_WEB);
             if (count($flavorAssets) > 0) {
                 $flavorAsset = $flavorAssets[0];
             }
         }
     }
     if (is_null($flavorAsset)) {
         KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
     }
     $syncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     if (kFileSyncUtils::file_exists($syncKey, false)) {
         $path = kFileSyncUtils::getReadyLocalFilePathForKey($syncKey);
     } else {
         list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false);
         if (is_null($fileSync)) {
             KalturaLog::log("Error - no FileSync for flavor [" . $flavorAsset->getId() . "]");
             KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
         }
         if ($fileSync->getFileType() == FileSync::FILE_SYNC_FILE_TYPE_URL) {
             $urlManager = DeliveryProfilePeer::getRemoteDeliveryByStorageId(DeliveryProfileDynamicAttributes::init($fileSync->getDc(), $flavorAsset->getEntryId()), null, $flavorAsset);
             if (!$urlManager) {
                 KalturaLog::log("Error - failed to find an HTTP delivery for storage profile [" . $fileSync->getDc() . "]");
                 KExternalErrors::dieError(KExternalErrors::FILE_NOT_FOUND);
             }
             $url = rtrim($urlManager->getUrl(), '/') . '/' . ltrim($urlManager->getFileSyncUrl($fileSync), '/');
             header('location: ' . $url);
             die;
         }
         $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync);
         $this->redirect($remoteUrl);
     }
     $flv_wrapper = new myFlvHandler($path);
     $isFlv = $flv_wrapper->isFlv();
     // scrubbing is not allowed within mp4 files
     if (!$isFlv) {
         $seek_from = $seek_from_bytes = -1;
     }
     if ($seek_from !== -1 && $seek_from !== 0) {
         if ($audio_only === '0') {
             // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations
         } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) {
             $audio_only = true;
         }
         list($bytes, $duration, $first_tag_byte, $to_byte) = $flv_wrapper->clip(0, -1, $audio_only);
         list($bytes, $duration, $from_byte, $to_byte, $seek_from_timestamp) = $flv_wrapper->clip($seek_from, -1, $audio_only);
         $seek_from_bytes = myFlvHandler::FLV_HEADER_SIZE + $flv_wrapper->getMetadataSize($audio_only) + $from_byte - $first_tag_byte;
     }
     // the direct path without a cdn is "http://s3kaltura.s3.amazonaws.com".$entry->getDataPath();
     $extStorageUrl = $entry->getExtStorageUrl();
     if ($extStorageUrl && substr_count($extStorageUrl, 's3kaltura')) {
         // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from
         if ($seek_from_timestamp == -1) {
             $seek_from_timestamp = $seek_from;
         }
         $request_host = parse_url($extStorageUrl, PHP_URL_HOST);
         $akamai_url = str_replace($request_host, "cdns3akmi.kaltura.com", $extStorageUrl);
         $akamai_url .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000);
         header("Location: {$akamai_url}");
         KExternalErrors::dieGracefully();
     } elseif ($extStorageUrl) {
         // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from
         if ($seek_from_timestamp == -1) {
             $seek_from_timestamp = $seek_from;
         }
         $extStorageUrl .= $seek_from_bytes == -1 ? "" : "?aktimeoffset=" . floor($seek_from_timestamp / 1000);
         header("Location: {$extStorageUrl}");
         KExternalErrors::dieGracefully();
     }
     // use headers to detect cdn
     $cdn_name = "";
     $via_header = @$_SERVER["HTTP_VIA"];
     if (strpos($via_header, "llnw.net") !== false) {
         $cdn_name = "limelight";
     } else {
         if (strpos($via_header, "akamai") !== false) {
             $cdn_name = "akamai";
         } else {
             if (strpos($via_header, "Level3") !== false) {
                 $cdn_name = "level3";
             }
         }
     }
     // setting file extension - first trying frrom flavor asset
     $ext = $flavorAsset->getFileExt();
     // if failed, set extension according to file type (isFlv)
     if (!$ext) {
         $ext = $isFlv ? "flv" : "mp4";
     }
     $flv_extension = $streamer == "rtmp" ? "?" : "/a.{$ext}?novar=0";
     // dont check for rtmp / and for an already redirect url
     if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) {
         // check security using ks
         $securyEntryHelper = new KSecureEntryHelper($entry, $ks_str, $referrer, ContextType::PLAY);
         if ($securyEntryHelper->shouldPreview()) {
             $this->checkForPreview($securyEntryHelper, $clip_to);
         } else {
             $securyEntryHelper->validateForPlay($entry, $ks_str);
         }
     } else {
         // if needs security check using cdn authentication mechanism
         // for now assume this is a cdn request and don't check for security
     }
     // use limelight mediavault if either security policy requires it or if we're trying to seek within the video
     if ($entry->getSecurityPolicy() || $seek_from_bytes !== -1) {
         // we have three options:
         // arrived through limelight mediavault url - the url is secured
         // arrived directly through limelight (not secured through mediavault) - enforce ks and redirect to mediavault url
         // didnt use limelight - enforce ks
         // the cdns are configured to authenticate request for /s/....
         // check if we're already in a redirected secure link using the "/s/" prefix
         $secure_request = substr($request, 0, 3) == "/s/";
         if ($secure_request && ($cdn_name == "limelight" || $cdn_name == "level3")) {
             // request was validated by cdn let it through
         } else {
             // extract ks
             $ks_str = $this->getRequestParameter("ks", "");
             if ($entry->getSecurityPolicy()) {
                 if (!$ks_str) {
                     $this->logMessage("flvclipper - no KS");
                     KExternalErrors::dieGracefully();
                 }
                 $ks = kSessionUtils::crackKs($ks_str);
                 if (!$ks) {
                     $this->logMessage("flvclipper - invalid ks [{$ks_str}]");
                     KExternalErrors::dieGracefully();
                 }
                 $matched_privs = $ks->verifyPrivileges("sview", $entry_id);
                 $this->logMessage("flvclipper - verifyPrivileges name [sview], priv [{$entry_id}] [{$matched_privs}]");
                 if (!$matched_privs) {
                     $this->logMessage("flvclipper - doesnt not match required privlieges [{$ks_str}]");
                     KExternalErrors::dieGracefully();
                 }
             }
             if ($cdn_name == "limelight") {
                 $ll_url = requestUtils::getCdnHost() . "/s{$request}" . $flv_extension;
                 $secret = kConf::get("limelight_madiavault_password");
                 $expire = "&e=" . (time() + 120);
                 $ll_url .= $expire;
                 $fs = $seek_from_bytes == -1 ? "" : "&fs={$seek_from_bytes}";
                 $ll_url .= "&h=" . md5("{$secret}{$ll_url}") . $fs;
                 //header("Location: $ll_url");
                 $this->redirect($ll_url);
             } else {
                 if ($cdn_name == "level3") {
                     $level3_url = $request . $flv_extension;
                     if ($entry->getSecurityPolicy()) {
                         $level3_url = "/s{$level3_url}";
                         // set expire time in GMT hence the date("Z") offset
                         $expire = "&nva=" . strftime("%Y%m%d%H%M%S", time() - date("Z") + 30);
                         $level3_url .= $expire;
                         $secret = kConf::get("level3_authentication_key");
                         $hash = "0" . substr(self::hmac('sha1', $secret, $level3_url), 0, 20);
                         $level3_url .= "&h={$hash}";
                     }
                     $level3_url .= $seek_from_bytes == -1 ? "" : "&start={$seek_from_bytes}";
                     header("Location: {$level3_url}");
                     KExternalErrors::dieGracefully();
                 } else {
                     if ($cdn_name == "akamai") {
                         $akamai_url = $request . $flv_extension;
                         // if for some reason we didnt set our accurate $seek_from_timestamp reset it to the requested seek_from
                         if ($seek_from_timestamp == -1) {
                             $seek_from_timestamp = $seek_from;
                         }
                         $akamai_url .= $seek_from_bytes == -1 ? "" : "&aktimeoffset=" . floor($seek_from_timestamp / 1000);
                         header("Location: {$akamai_url}");
                         KExternalErrors::dieGracefully();
                     }
                 }
             }
             // a seek request without a supporting cdn - we need to send the answer from our server
             if ($seek_from_bytes !== -1 && $via_header === null) {
                 $this->dump_from_byte = $seek_from_bytes;
             }
         }
     }
     // always add the file suffix to the request (needed for scrubbing by some cdns,
     // and also breaks without extension on some corporate antivirus).
     // we add the the novar paramter since a leaving a trailing "?" will be trimmed
     // and then the /seek_from request will result in another url which level3
     // will try to refetch from the origin
     // note that for streamer we dont add the file extension
     if ($streamer != "rtmp" && strpos($request, $flv_extension) === false) {
         // a seek request without a supporting cdn - we need to send the answer from our server
         if ($seek_from_bytes !== -1 && $via_header === null) {
             $request .= "/seek_from_bytes/{$seek_from_bytes}";
         }
         requestUtils::sendCdnHeaders("flv", 0);
         header("Location: {$request}" . $flv_extension);
         KExternalErrors::dieGracefully();
     }
     // mp4
     if (!$isFlv) {
         $limit_file_size = 0;
         if ($clip_to != 2147483647) {
             $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
             if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) {
                 $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration());
                 $limit_file_size = floor(@kFile::fileSize($path) * ($clip_to / $duration) * 1.2);
             }
         }
         KalturaLog::info("serving file [{$path}] entry id [{$entry_id}] limit file size [{$limit_file_size}] clip_to [{$clip_to}]");
         kFileUtils::dumpFile($path, null, null, $limit_file_size);
     }
     $this->logMessage("flvclipperAction: serving file [{$path}] entry_id [{$entry_id}] clip_from [{$clip_from}] clip_to [{$clip_to}]", "warning");
     if ($audio_only === '0') {
         // audio_only was explicitly set to 0 - don't attempt to make further automatic investigations
     } elseif ($flv_wrapper->getFirstVideoTimestamp() < 0) {
         $audio_only = true;
     }
     //$start = microtime(true);
     list($bytes, $duration, $from_byte, $to_byte, $from_ts, $cuepoint_pos) = myFlvStaticHandler::clip($path, $clip_from, $clip_to, $audio_only);
     $metadata_size = $flv_wrapper->getMetadataSize($audio_only);
     $this->from_byte = $from_byte;
     $this->to_byte = $to_byte;
     //$end1 = microtime(true);
     //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" );
     //$this->logMessage( "flvclipperAction: serving file [$path] t1 [" . ( $end1-$start) . "]");
     $data_offset = $metadata_size + myFlvHandler::getHeaderSize();
     // if we're returning a partial file adjust the total size:
     // substract the metadata and bytes which are not delivered
     if ($this->dump_from_byte >= $data_offset && !$audio_only) {
         $bytes -= $metadata_size + max(0, $this->dump_from_byte - $data_offset);
     }
     $this->total_length = $data_offset + $bytes;
     //echo " $bytes , $duration ,$from_byte , $to_byte, $cuepoint_pos\n"; die;
     $this->cuepoint_time = 0;
     $this->cuepoint_pos = 0;
     if ($streamer == "chunked" && $clip_to != 2147483647) {
         $this->cuepoint_time = $clip_to - 1;
         $this->cuepoint_pos = $cuepoint_pos;
         $this->total_length += myFlvHandler::CUEPOINT_TAG_SIZE;
     }
     //$this->logMessage( "flvclipperAction: serving file [$path] entry_id [$entry_id] bytes with header & md [" . $this->total_length . "] bytes [$bytes] duration [$duration] [$from_byte]->[$to_byte]" , "warning" );
     $this->flv_wrapper = $flv_wrapper;
     $this->audio_only = $audio_only;
     try {
         Propel::close();
     } catch (Exception $e) {
         $this->logMessage("flvclipperAction: error closing db {$e}");
     }
     KExternalErrors::terminateDispatch();
     return sfView::SUCCESS;
 }
Ejemplo n.º 20
0
 /**
  * @param entry $entry
  * @param entry $tempEntry
  */
 public static function replaceEntry(entry $entry, entry $tempEntry = null)
 {
     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());
     $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::info("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::info("Added new asset [" . $newAsset->getId() . "] for asset params [" . $newAsset->getFlavorParamsId() . "]");
         } else {
             $newAssets[$newAsset->getType()]['asset_' . count($newAssets[$newAsset->getType()])] = $newAsset;
             KalturaLog::info("Added new asset [" . $newAsset->getId() . "] with no asset params");
         }
     }
     $defaultThumbAssetNew = null;
     $defaultThumbAssetOld = null;
     foreach ($oldAssets as $oldAsset) {
         /* @var $oldAsset 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()];
             if ($oldAsset->hasTag(assetParams::TAG_RECORDING_ANCHOR)) {
                 $newAsset->addTags(array(assetParams::TAG_RECORDING_ANCHOR));
             }
             /* @var $newAsset asset */
             KalturaLog::info("Create link from new asset [" . $newAsset->getId() . "] to old asset [" . $oldAsset->getId() . "] for flavor [" . $oldAsset->getFlavorParamsId() . "]");
             $oldAsset->linkFromAsset($newAsset);
             $oldAsset->save();
             self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_ASSET_SUB_TYPE_ISM);
             self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_ASSET_SUB_TYPE_ISMC);
             self::createFileSyncLinkFromReplacingAsset($oldAsset, $newAsset, asset::FILE_SYNC_ASSET_SUB_TYPE_MPD);
             $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::info("Nominating ThumbAsset [" . $oldAsset->getId() . "] as the default ThumbAsset after replacent");
             }
         } elseif ($oldAsset instanceof flavorAsset || $oldAsset instanceof thumbAsset) {
             if ($oldAsset instanceof thumbAsset && $oldAsset->keepOnEntryReplacement()) {
                 KalturaLog::info("KeepManualThumbnails ind is set, manual thumbnail is not deleted [" . $oldAsset->getId() . "]");
                 if ($oldAsset->hasTag(thumbParams::TAG_DEFAULT_THUMB)) {
                     $defaultThumbAssetOld = $oldAsset;
                 }
             } else {
                 KalturaLog::info("Delete old asset [" . $oldAsset->getId() . "] for paramsId [" . $oldAsset->getFlavorParamsId() . "]");
                 $oldAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
                 $oldAsset->setDeletedAt(time());
                 $oldAsset->save();
             }
         }
     }
     foreach ($newAssets as $newAssetsByTypes) {
         foreach ($newAssetsByTypes as $newAsset) {
             $createdAsset = $newAsset->copyToEntry($entry->getId(), $entry->getPartnerId());
             KalturaLog::info("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::info("Nominating ThumbAsset [" . $newAsset->getId() . "] as the default ThumbAsset after replacent");
             }
         }
     }
     if ($defaultThumbAssetOld) {
         KalturaLog::info("Kepping ThumbAsset [" . $defaultThumbAssetOld->getId() . "] as the default ThumbAsset");
     } elseif ($defaultThumbAssetNew) {
         kBusinessConvertDL::setAsDefaultThumbAsset($defaultThumbAssetNew);
         KalturaLog::info("Setting ThumbAsset [" . $defaultThumbAssetNew->getId() . "] as the default ThumbAsset");
     } else {
         KalturaLog::info("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);
     }
     self::createIsmManifestFileSyncLinkFromReplacingEntry($tempEntry, $entry);
     $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->setReplacementOptions(null);
     $entry->setStatus($tempEntry->getStatus());
     $entry->save();
     //flush deffered events to re-index sphinx before temp entry deletion
     kEventsManager::flushEvents();
     kBusinessConvertDL::checkForPendingLiveClips($entry);
     kEventsManager::raiseEvent(new kObjectReplacedEvent($entry, $tempEntry));
     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);
 }
Ejemplo n.º 21
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kPostConvertJobData $data
  */
 protected static function createThumbnail(BatchJob $dbBatchJob, kPostConvertJobData $data)
 {
     KalturaLog::debug("Post Convert finished with thumnail: " . $data->getThumbPath());
     $ignoreThumbnail = false;
     // this logic decide when this thumbnail should be used
     $rootBatchJob = $dbBatchJob->getRootJob();
     if ($rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
         $thisFlavorHeight = $data->getThumbHeight();
         $thisFlavorBitrate = $data->getThumbBitrate();
         $rootBatchJobData = $rootBatchJob->getData();
         if (!$rootBatchJobData->getCreateThumb() || $rootBatchJobData->getThumbBitrate() > $thisFlavorBitrate) {
             $ignoreThumbnail = true;
         } elseif ($rootBatchJobData->getThumbBitrate() == $thisFlavorBitrate && $rootBatchJobData->getThumbHeight() > $thisFlavorHeight) {
             $ignoreThumbnail = true;
         } else {
             $rootBatchJobData->setThumbHeight($thisFlavorHeight);
             $rootBatchJobData->setThumbBitrate($thisFlavorBitrate);
             $rootBatchJob->setData($rootBatchJobData);
             $rootBatchJob->save();
         }
     }
     if (!$ignoreThumbnail) {
         KalturaLog::debug("Saving thumbnail from: " . $data->getThumbPath());
         // creats thumbnail the file sync
         $entry = $dbBatchJob->getEntry(false, false);
         if (!$entry) {
             KalturaLog::err("Entry not found [" . $dbBatchJob->getEntryId() . "]");
             return;
         }
         KalturaLog::debug("Entry duration: " . $entry->getLengthInMsecs());
         if (!$entry->getLengthInMsecs()) {
             KalturaLog::debug("Copy duration from flvor asset: " . $data->getFlavorAssetId());
             $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($data->getFlavorAssetId());
             if ($mediaInfo) {
                 KalturaLog::debug("Set duration to: " . $mediaInfo->getContainerDuration());
                 $entry->setDimensions($mediaInfo->getVideoWidth(), $mediaInfo->getVideoHeight());
                 $entry->setLengthInMsecs($mediaInfo->getContainerDuration());
             }
         }
         $entry->reload();
         // make sure that the thumbnail version is the latest
         $entry->setThumbnail(".jpg");
         $entry->save();
         $syncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_THUMB);
         kFileSyncUtils::moveFromFile($data->getThumbPath(), $syncKey);
     }
 }
Ejemplo n.º 22
0
 public static function continueProfileConvert(BatchJob $parentJob)
 {
     $convertProfileJob = $parentJob->getRootJob();
     if ($convertProfileJob->getJobType() != BatchJobType::CONVERT_PROFILE) {
         throw new Exception("Root job [" . $convertProfileJob->getId() . "] is not profile conversion");
     }
     KalturaLog::log("Conversion decision layer continued for entry [" . $parentJob->getEntryId() . "]");
     $convertProfileData = $convertProfileJob->getData();
     $entryId = $convertProfileJob->getEntryId();
     $entry = $convertProfileJob->getEntry();
     if (!$entry) {
         throw new APIException(APIErrors::INVALID_ENTRY, $convertProfileJob, $entryId);
     }
     $profile = myPartnerUtils::getConversionProfile2ForEntry($entryId);
     if (!$profile) {
         $errDescription = "Conversion profile for entryId [{$entryId}] not found";
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         KalturaLog::err("No flavors created: {$errDescription}");
         throw new Exception($errDescription);
     }
     $originalFlavorAsset = flavorAssetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         KalturaLog::err($errDescription);
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         throw new Exception($errDescription);
     }
     // gets the list of flavor params of the conversion profile
     $list = flavorParamsConversionProfilePeer::retrieveByConversionProfile($profile->getId());
     if (!count($list)) {
         $errDescription = "No flavors match the profile id [{$profile->getId()}]";
         KalturaLog::err($errDescription);
         $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
         kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalFlavorAsset->setDeletedAt(time());
         $originalFlavorAsset->save();
         throw new Exception($errDescription);
     }
     // gets the ids of the flavor params
     $flavorsIds = array();
     $conversionProfileFlavorParams = array();
     foreach ($list as $flavorParamsConversionProfile) {
         $flavorsId = $flavorParamsConversionProfile->getFlavorParamsId();
         $flavorsIds[] = $flavorsId;
         $conversionProfileFlavorParams[$flavorsId] = $flavorParamsConversionProfile;
     }
     $dynamicFlavorAttributes = $entry->getDynamicFlavorAttributes();
     // gets the flavor params by the id
     $flavors = flavorParamsPeer::retrieveByPKs($flavorsIds);
     foreach ($flavors as $index => $flavor) {
         if ($flavor->hasTag(flavorParams::TAG_SOURCE)) {
             unset($flavors[$index]);
             continue;
         }
         if (isset($dynamicFlavorAttributes[$flavor->getId()])) {
             foreach ($dynamicFlavorAttributes[$flavor->getId()] as $attributeName => $attributeValue) {
                 $flavor->setDynamicAttribute($attributeName, $attributeValue);
             }
         }
     }
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!count($flavors)) {
         return false;
     }
     $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($originalFlavorAsset->getId());
     return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $mediaInfo);
 }
Ejemplo n.º 23
0
 /**
  * @param kFileSyncResource $resource
  * @param entry $dbEntry
  * @param asset $dbAsset
  * @return asset | NULL in case of IMAGE entry
  * @throws KalturaErrors::UPLOAD_ERROR
  * @throws KalturaErrors::INVALID_OBJECT_ID
  */
 protected function attachFileSyncResource(kFileSyncResource $resource, entry $dbEntry, asset $dbAsset = null)
 {
     $dbEntry->setSource(entry::ENTRY_MEDIA_SOURCE_KALTURA);
     $dbEntry->save();
     try {
         $syncable = kFileSyncObjectManager::retrieveObject($resource->getFileSyncObjectType(), $resource->getObjectId());
     } catch (kFileSyncException $e) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $resource->getObjectId());
     }
     $srcSyncKey = $syncable->getSyncKey($resource->getObjectSubType(), $resource->getVersion());
     $dbAsset = $this->attachFileSync($srcSyncKey, $dbEntry, $dbAsset);
     //In case the target entry's media type is image no asset is created and the image is set on a entry level file sync
     if (!$dbAsset && $dbEntry->getMediaType() == KalturaMediaType::IMAGE) {
         return null;
     }
     // Copy the media info from the old asset to the new one
     if ($syncable instanceof asset && $resource->getObjectSubType() == asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET) {
         $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($syncable->getId());
         if ($mediaInfo) {
             $newMediaInfo = $mediaInfo->copy();
             $newMediaInfo->setFlavorAssetId($dbAsset->getId());
             $newMediaInfo->save();
         }
         if ($dbAsset->getStatus() == asset::ASSET_STATUS_READY) {
             $dbEntry->syncFlavorParamsIds();
             $dbEntry->save();
         }
     }
     return $dbAsset;
 }
Ejemplo n.º 24
0
 /**
  * Returns the number of related mediaInfo objects.
  *
  * @param      Criteria $criteria
  * @param      boolean $distinct
  * @param      PropelPDO $con
  * @return     int Count of related mediaInfo objects.
  * @throws     PropelException
  */
 public function countmediaInfos(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
 {
     if ($criteria === null) {
         $criteria = new Criteria(assetPeer::DATABASE_NAME);
     } else {
         $criteria = clone $criteria;
     }
     if ($distinct) {
         $criteria->setDistinct();
     }
     $count = null;
     if ($this->collmediaInfos === null) {
         if ($this->isNew()) {
             $count = 0;
         } else {
             $criteria->add(mediaInfoPeer::FLAVOR_ASSET_ID, $this->id);
             $count = mediaInfoPeer::doCount($criteria, false, $con);
         }
     } else {
         // criteria has no effect for a new object
         if (!$this->isNew()) {
             // the following code is to determine if a new query is
             // called for.  If the criteria is the same as the last
             // one, just return count of the collection.
             $criteria->add(mediaInfoPeer::FLAVOR_ASSET_ID, $this->id);
             if (!isset($this->lastmediaInfoCriteria) || !$this->lastmediaInfoCriteria->equals($criteria)) {
                 $count = mediaInfoPeer::doCount($criteria, false, $con);
             } else {
                 $count = count($this->collmediaInfos);
             }
         } else {
             $count = count($this->collmediaInfos);
         }
     }
     return $count;
 }
Ejemplo n.º 25
0
 protected function getAudioLanguage($flavor)
 {
     $mediaInfoObj = mediaInfoPeer::retrieveByFlavorAssetId($flavor->getId());
     if (!$mediaInfoObj) {
         return null;
     }
     $contentStreams = $mediaInfoObj->getContentStreams();
     if (!isset($contentStreams)) {
         return null;
     }
     $parsedJson = json_decode($contentStreams, true);
     if (!isset($parsedJson['audio'][0]['audioLanguage'])) {
         return null;
     }
     $audioLanguage = $parsedJson['audio'][0]['audioLanguage'];
     if (defined('LanguageKey::' . strtoupper($audioLanguage))) {
         $audioLanguageName = constant('LanguageKey::' . strtoupper($audioLanguage));
     } else {
         $audioLanguageName = "Unknown ({$audioLanguage})";
         KalturaLog::info("Language code [{$audioLanguage}] was not found. Setting [{$audioLanguageName}] instead");
     }
     return array($audioLanguage, $audioLanguageName);
 }
 /**
  * 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(mediaInfoPeer::DATABASE_NAME);
     $criteria->add(mediaInfoPeer::ID, $this->id);
     if ($this->alreadyInSave && count($this->modifiedColumns) == 2 && $this->isColumnModified(mediaInfoPeer::UPDATED_AT)) {
         $theModifiedColumn = null;
         foreach ($this->modifiedColumns as $modifiedColumn) {
             if ($modifiedColumn != mediaInfoPeer::UPDATED_AT) {
                 $theModifiedColumn = $modifiedColumn;
             }
         }
         $atomicColumns = mediaInfoPeer::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(mediaInfoPeer::DATABASE_NAME);
         $criteria->add(mediaInfoPeer::ID, $pks, Criteria::IN);
         $objs = mediaInfoPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
Ejemplo n.º 28
0
 private function serveRtmp()
 {
     switch ($this->entry->getType()) {
         case entryType::MEDIA_CLIP:
             $duration = $this->entry->getDurationInt();
             $flavorAssets = array();
             if ($this->flavorId) {
                 $flavorAsset = flavorAssetPeer::retrieveById($this->flavorId);
                 if (!$flavorAsset->hasTag(flavorParams::TAG_WEB)) {
                     KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
                 }
                 if (!$flavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_READY) {
                     KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
                 }
                 $flavorAssets[] = $flavorAsset;
             } else {
                 $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, flavorParams::TAG_MBR);
                 if (!count($flavorAssets)) {
                     $flavorAssets = flavorAssetPeer::retreiveReadyByEntryIdAndTag($this->entryId, flavorParams::TAG_WEB);
                 }
             }
             $flavorAssets = $this->removeMaxBitrateFlavors($flavorAssets);
             if (!$this->storageId) {
                 $partner = $this->entry->getPartner();
                 $finalFlavors = array();
                 if ($partner->getStorageServePriority() == StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_FIRST) {
                     foreach ($flavorAssets as $flavorAsset) {
                         $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                         $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($key);
                         if ($fileSync) {
                             $finalFlavors[] = $flavorAsset;
                         }
                     }
                 }
                 if (!count($finalFlavors) && $partner->getStorageServePriority() && $partner->getStorageServePriority() != StorageProfile::STORAGE_SERVE_PRIORITY_KALTURA_ONLY) {
                     $storages = StorageProfilePeer::retrieveExternalByPartnerId($partner->getId());
                     if (count($storages) == 1) {
                         $this->storageId = $storages[0]->getId();
                     } elseif (count($storages)) {
                         $storagesFlavors = array();
                         foreach ($storages as $storage) {
                             $storagesFlavors[$storage->getId()] = array();
                             foreach ($flavorAssets as $flavorAsset) {
                                 $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                                 $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $storage->getId());
                                 if ($fileSync) {
                                     $storagesFlavors[$storage->getId()][] = $flavorAsset;
                                 }
                             }
                         }
                         $maxCount = 0;
                         foreach ($storagesFlavors as $storageId => $storageFlavors) {
                             $count = count($storageFlavors);
                             if ($count > $maxCount) {
                                 $maxCount = $count;
                                 $this->storageId = $storageId;
                                 $finalFlavors = $storageFlavors;
                             }
                         }
                         $flavorAssets = $finalFlavors;
                     } else {
                         foreach ($flavorAssets as $flavorAsset) {
                             $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                             $fileSync = kFileSyncUtils::getReadyInternalFileSyncForKey($key);
                             if ($fileSync) {
                                 $finalFlavors[] = $flavorAsset;
                             }
                         }
                     }
                 }
             }
             foreach ($flavorAssets as $flavorAsset) {
                 $mediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAsset->getId());
                 if ($mediaInfo && ($mediaInfo->getVideoDuration() || $mediaInfo->getAudioDuration() || $mediaInfo->getContainerDuration())) {
                     $duration = $mediaInfo->getVideoDuration() ? $mediaInfo->getVideoDuration() : ($mediaInfo->getAudioDuration() ? $mediaInfo->getAudioDuration() : $mediaInfo->getContainerDuration());
                     $duration /= 1000;
                     break;
                 }
             }
             $baseUrl = null;
             $flavors = array();
             if ($this->storageId) {
                 $storage = StorageProfilePeer::retrieveByPK($this->storageId);
                 if (!$storage) {
                     die;
                 }
                 $baseUrl = $storage->getDeliveryRmpBaseUrl();
                 // get all flavors with external urls
                 foreach ($flavorAssets as $flavorAsset) {
                     $key = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
                     $fileSync = kFileSyncUtils::getReadyExternalFileSyncForKey($key, $this->storageId);
                     if (!$fileSync) {
                         continue;
                     }
                     $urlManager = kUrlManager::getUrlManagerByStorageProfile($fileSync->getDc());
                     $urlManager->setClipTo($this->clipTo);
                     $urlManager->setFileExtension($flavorAsset->getFileExt());
                     $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_RTMP);
                     $url = $urlManager->getFileSyncUrl($fileSync);
                     $url = preg_replace('/^\\//', '', $url);
                     $flavors[] = array('url' => $url, 'bitrate' => $flavorAsset->getBitrate(), 'width' => $flavorAsset->getWidth(), 'height' => $flavorAsset->getHeight());
                 }
             } else {
                 $partnerId = $this->entry->getPartnerId();
                 $subpId = $this->entry->getSubpId();
                 $partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId);
                 $baseUrl = myPartnerUtils::getRtmpUrl($partnerId);
                 $urlManager = kUrlManager::getUrlManagerByCdn($this->cdnHost);
                 // get all flavors with kaltura urls
                 foreach ($flavorAssets as $flavorAsset) {
                     $urlManager->setClipTo($this->clipTo);
                     $urlManager->setFileExtension($flavorAsset->getFileExt());
                     $urlManager->setProtocol(StorageProfile::PLAY_FORMAT_RTMP);
                     $url = $urlManager->getFlavorAssetUrl($flavorAsset);
                     $url = preg_replace('/^\\//', '', $url);
                     $flavors[] = array('url' => $url, 'bitrate' => $flavorAsset->getBitrate(), 'width' => $flavorAsset->getWidth(), 'height' => $flavorAsset->getHeight());
                 }
             }
             if (!count($flavors)) {
                 KExternalErrors::dieError(KExternalErrors::FLAVOR_NOT_FOUND);
             }
             if (strpos($this->protocol, "rtmp") === 0) {
                 $baseUrl = $this->protocol . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl);
             }
             return $this->buildXml(self::PLAY_STREAM_TYPE_RECORDED, $flavors, 'video/x-flv', $duration, $baseUrl);
         case entryType::LIVE_STREAM:
             $streamId = $this->entry->getStreamRemoteId();
             $streamUsername = $this->entry->getStreamUsername();
             $baseUrl = $this->entry->getStreamUrl();
             $baseUrl = rtrim($baseUrl, '/');
             $flavors = $this->entry->getStreamBitrates();
             if (count($flavors)) {
                 foreach ($flavors as $index => $flavor) {
                     $brIndex = $index + 1;
                     $flavors[$index]['url'] = str_replace('%i', $brIndex, $this->entry->getStreamName());
                 }
             } else {
                 $flavors[0]['url'] = str_replace('%i', '1', $this->entry->getStreamName());
             }
             if (strpos($this->protocol, "rtmp") === 0) {
                 $baseUrl = $this->protocol . '://' . preg_replace('/^rtmp.*?:\\/\\//', '', $baseUrl);
             }
             return $this->buildXml(self::PLAY_STREAM_TYPE_LIVE, $flavors, 'video/x-flv', null, $baseUrl);
     }
     KExternalErrors::dieError(KExternalErrors::INVALID_ENTRY_TYPE);
 }
Ejemplo n.º 29
0
 /**
  * @param string $id
  * @return mediaInfo
  */
 public static function retrieveById($id)
 {
     $criteria = new Criteria();
     $criteria->add(mediaInfoPeer::ID, $id);
     return mediaInfoPeer::doSelectOne($criteria);
 }
Ejemplo n.º 30
0
 public static function handleFlavorReady(BatchJob $dbBatchJob, $flavorAssetId)
 {
     // verifies that flavor asset created
     if (!$flavorAssetId) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId);
     }
     $currentFlavorAsset = assetPeer::retrieveById($flavorAssetId);
     // verifies that flavor asset exists
     if (!$currentFlavorAsset) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $flavorAssetId);
     }
     // if the flavor deleted then it shouldn't be taken into ready calculations
     if ($currentFlavorAsset->getStatus() == flavorAsset::FLAVOR_ASSET_STATUS_DELETED) {
         return $currentFlavorAsset;
     }
     //		Remarked because we want the original flavor ready behavior to work the same as other flavors
     //
     //		$rootBatchJob = $dbBatchJob->getRootJob();
     //
     //		// happens in case of post convert on the original (in case of bypass)
     //		if($rootBatchJob && $currentFlavorAsset->getIsOriginal())
     //		{
     //			kJobsManager::updateBatchJob($rootBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
     //			return $dbBatchJob;
     //		}
     $sourceMediaInfo = mediaInfoPeer::retrieveOriginalByEntryId($dbBatchJob->getEntryId());
     /*
      * For intermediate source generation, both the source and the asset have the same asset id.
      * In this case sourceMediaInfo should be retrieved as the first version of source asset mediaInfo 
      */
     if (isset($sourceMediaInfo) && $sourceMediaInfo->getFlavorAssetId() == $flavorAssetId) {
         $productMediaInfo = $sourceMediaInfo;
         $entry = $dbBatchJob->getEntry();
         $operationAttributes = $entry->getOperationAttributes();
         // if in clipping operation - take the latest created mediainfo object
         $ascending = empty($operationAttributes) ? 1 : 0;
         $sourceMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($flavorAssetId, $ascending);
         KalturaLog::log("Intermediate source generation - assetId(" . $flavorAssetId . "),src MdInf id(" . $sourceMediaInfo->getId() . "),product MdInf id(" . $productMediaInfo->getId()) . ")";
     } else {
         $productMediaInfo = mediaInfoPeer::retrieveByFlavorAssetId($currentFlavorAsset->getId());
     }
     $targetFlavor = assetParamsOutputPeer::retrieveByAssetId($currentFlavorAsset->getId());
     //Retrieve convert job executing engien
     $convertEngineType = null;
     if ($dbBatchJob->getParentJob()) {
         $dbParentBatchJob = $dbBatchJob->getParentJob();
         if ($dbParentBatchJob->getJobType() == BatchJobType::CONVERT) {
             $convertEngineType = $dbParentBatchJob->getJobSubType();
         }
     }
     $postConvertData = $dbBatchJob->getData();
     $postConvertAssetType = BatchJob::POSTCONVERT_ASSET_TYPE_FLAVOR;
     if ($postConvertData instanceof kPostConvertJobData) {
         $postConvertAssetType = $postConvertData->getPostConvertAssetType();
     }
     // don't validate in case of bypass, in case target flavor or media info are null
     // or ISM/ISMC manifest assets
     if ($postConvertAssetType != BatchJob::POSTCONVERT_ASSET_TYPE_BYPASS && $targetFlavor && $productMediaInfo && !$targetFlavor->hasTag(assetParams::TAG_ISM_MANIFEST)) {
         try {
             $productFlavor = KDLWrap::CDLValidateProduct($sourceMediaInfo, $targetFlavor, $productMediaInfo, $convertEngineType);
         } catch (Exception $e) {
             KalturaLog::err('KDL Error: ' . print_r($e, true));
         }
         $err = kBusinessConvertDL::parseFlavorDescription($productFlavor);
         KalturaLog::debug("BCDL: job id [" . $dbBatchJob->getId() . "] flavor params output id [" . $targetFlavor->getId() . "] flavor asset id [" . $currentFlavorAsset->getId() . "] desc: {$err}");
         if (!$productFlavor->IsValid()) {
             $description = $currentFlavorAsset->getDescription() . "\n{$err}";
             // mark the asset as ready
             $currentFlavorAsset->setDescription($description);
             $currentFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
             $currentFlavorAsset->save();
             if (!kConf::get('ignore_cdl_failure')) {
                 kJobsManager::failBatchJob($dbBatchJob, $err);
                 return null;
             }
         }
     }
     // mark the asset as ready
     $currentFlavorAsset->setStatusLocalReady();
     $currentFlavorAsset->save();
     $waitingFlavorAssets = assetPeer::retrieveByEntryIdAndStatus($currentFlavorAsset->getEntryId(), flavorAsset::FLAVOR_ASSET_STATUS_WAIT_FOR_CONVERT);
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($currentFlavorAsset->getEntryId());
     foreach ($waitingFlavorAssets as $waitingFlavorAsset) {
         $flavor = assetParamsOutputPeer::retrieveByAsset($waitingFlavorAsset);
         KalturaLog::debug('Check waiting flavor asset [' . $waitingFlavorAsset->getId() . ']');
         if ($dbBatchJob->getParentJob()) {
             $parentJob = $dbBatchJob->getParentJob();
         } else {
             $parentJob = $dbBatchJob;
         }
         kBusinessPreConvertDL::decideFlavorConvert($waitingFlavorAsset, $flavor, $originalFlavorAsset, null, null, $parentJob);
     }
     kFlowHelper::generateThumbnailsFromFlavor($dbBatchJob->getEntryId(), $dbBatchJob, $currentFlavorAsset->getFlavorParamsId());
     if ($currentFlavorAsset->getIsOriginal()) {
         $entry = $currentFlavorAsset->getentry();
         if ($entry) {
             kBusinessConvertDL::checkForPendingLiveClips($entry);
         }
     }
     return $currentFlavorAsset;
 }