Beispiel #1
0
 private function handleConvertLiveSegmentJobFinished(BatchJob $dbBatchJob, kConvertLiveSegmentJobData $data)
 {
     $files = self::getAssetDataFilesArray($data);
     $amfArray = unserialize(file_get_contents($files[0]));
     $recordedVODDurationInMS = $amfArray[0];
     array_shift($amfArray);
     if (!unlink($files[0])) {
         KalturaLog::warning("failed to delete file " . $files[0]);
     }
     $amfArray = self::parseAmfArrayAndShift($amfArray, 0);
     self::copyCuePointsFromLiveToVodEntry($dbBatchJob->getEntry()->getRecordedEntryId(), $recordedVODDurationInMS, $recordedVODDurationInMS, $amfArray);
 }
 public function updatedJob(BatchJob $dbBatchJob, BatchJob $twinJob = null)
 {
     if ($dbBatchJob->getStatus() != BatchJob::BATCHJOB_STATUS_PENDING) {
         return true;
     }
     if ($dbBatchJob->getJobType() == BatchJobType::PROVISION_PROVIDE) {
         $entry = $dbBatchJob->getEntry(false, false);
         $partner = $entry->getPartner();
         $limeLightLiveParamsJSON = $partner->getLiveStreamProvisionParams();
         $limeLightLiveParams = json_decode($limeLightLiveParamsJSON);
         if (!isset($limeLightLiveParams->Limelight) || !isset($limeLightLiveParams->Limelight->limelightPrimaryPublishUrl) || !isset($limeLightLiveParams->Limelight->limelightSecondaryPublishUrl) || !isset($limeLightLiveParams->Limelight->limelightStreamUrl)) {
             kJobsManager::updateBatchJob($dbBatchJob, BatchJob::BATCHJOB_STATUS_FAILED);
             return true;
         }
         $data = $dbBatchJob->getData();
         $data->setPrimaryBroadcastingUrl($limeLightLiveParams->Limelight->limelightPrimaryPublishUrl);
         $data->setSecondaryBroadcastingUrl($limeLightLiveParams->Limelight->limelightSecondaryPublishUrl);
         $data->setRtmp($limeLightLiveParams->Limelight->limelightStreamUrl);
         $data->setStreamName($entry->getId() . '_%i');
         $dbBatchJob->setData($data);
     }
     kJobsManager::updateBatchJob($dbBatchJob, BatchJob::BATCHJOB_STATUS_FINISHED);
     return true;
 }
 /**
  * batch decideProfileConvert is the decision layer for a conversion profile
  * 
  * @param BatchJob $parentJob
  * @param BatchJob $convertProfileJob
  * @param int $mediaInfoId  
  * @return bool true if created all required conversions
  */
 public static function decideProfileConvert(BatchJob $parentJob, BatchJob $convertProfileJob, $mediaInfoId = null)
 {
     KalturaLog::log("Conversion decision layer used 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}");
         return false;
     }
     $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);
         return false;
     }
     $shouldConvert = true;
     // 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();
         return false;
     }
     $mediaInfo = null;
     if ($mediaInfoId) {
         $mediaInfo = mediaInfoPeer::retrieveByPK($mediaInfoId);
     }
     if ($profile->getCreationMode() == ConversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV) {
         KalturaLog::log("The profile created from old conversion profile with bypass flv");
         $isFlv = false;
         if ($mediaInfo) {
             $isFlv = KDLWrap::CDLIsFLV($mediaInfo);
         }
         if ($isFlv && $originalFlavorAsset->hasTag(flavorParams::TAG_MBR)) {
             KalturaLog::log("The source is mbr and flv, conversion will be bypassed");
             $shouldConvert = false;
         } else {
             KalturaLog::log("The source is NOT mbr or flv, conversion will NOT be bypassed");
         }
     }
     // 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();
     $sourceFlavor = null;
     $flavors = flavorParamsPeer::retrieveByPKs($flavorsIds);
     foreach ($flavors as $index => $flavor) {
         if (isset($dynamicFlavorAttributes[$flavor->getId()])) {
             foreach ($dynamicFlavorAttributes[$flavor->getId()] as $attributeName => $attributeValue) {
                 $flavor->setDynamicAttribute($attributeName, $attributeValue);
             }
         }
         if ($flavor->hasTag(flavorParams::TAG_SOURCE)) {
             $sourceFlavor = $flavor;
             unset($flavors[$index]);
         }
     }
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!$sourceFlavor) {
         KalturaLog::log("Source flavor params not found");
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_TEMP);
         $originalFlavorAsset->save();
     } elseif ($shouldConvert) {
         KalturaLog::log("Source flavor params [" . $sourceFlavor->getId() . "] found");
         $originalFlavorAsset->setFlavorParamsId($sourceFlavor->getId());
         if ($sourceFlavor->getOperators() || $sourceFlavor->getConversionEngines()) {
             KalturaLog::log("Source flavor asset requires conversion");
             $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
             $errDescription = null;
             $sourceFlavorOutput = self::validateFlavorAndMediaInfo($sourceFlavor, $mediaInfo, $errDescription);
             // save flavor params
             $sourceFlavorOutput->setPartnerId($sourceFlavorOutput->getPartnerId());
             $sourceFlavorOutput->setEntryId($entryId);
             $sourceFlavorOutput->setFlavorAssetId($originalFlavorAsset->getId());
             $sourceFlavorOutput->setFlavorAssetVersion($originalFlavorAsset->getVersion());
             $sourceFlavorOutput->save();
             if ($errDescription) {
                 $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}");
             }
             $errDescription = kBusinessConvertDL::parseFlavorDescription($sourceFlavorOutput);
             if ($errDescription) {
                 $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}");
             }
             // decided by the business logic layer
             if ($sourceFlavorOutput->_create_anyway) {
                 KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] selected to be created anyway");
             } else {
                 if (!$sourceFlavorOutput->IsValid()) {
                     KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is invalid");
                     $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR);
                     $originalFlavorAsset->save();
                     $errDescription = "Source flavor could not be converted";
                     KalturaLog::err($errDescription);
                     $convertProfileJob = kJobsManager::failBatchJob($convertProfileJob, $errDescription, BatchJobType::CONVERT_PROFILE);
                     kBatchManager::updateEntry($convertProfileJob, entryStatus::ERROR_CONVERTING);
                     return false;
                 }
                 if ($sourceFlavorOutput->_force) {
                     KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is forced");
                 } elseif ($sourceFlavorOutput->_isNonComply) {
                     KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is none-comply");
                 } else {
                     KalturaLog::log("Flavor [" . $sourceFlavorOutput->getFlavorParamsId() . "] is valid");
                 }
             }
             $originalFlavorAsset->incrementVersion();
             $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_QUEUED);
             $originalFlavorAsset->addTags($sourceFlavor->getTagsArray());
             $originalFlavorAsset->setFileExt($sourceFlavorOutput->getFileExt());
             $originalFlavorAsset->save();
             // save flavor params
             $sourceFlavorOutput->setFlavorAssetVersion($originalFlavorAsset->getVersion());
             $sourceFlavorOutput->save();
             kJobsManager::addFlavorConvertJob($srcSyncKey, $sourceFlavorOutput, $originalFlavorAsset->getId(), $mediaInfoId, $parentJob);
             return false;
         }
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_READY);
         $originalFlavorAsset->save();
         $entry->addFlavorParamsId($sourceFlavor->getId());
         $entry->save();
         kFlowHelper::generateThumbnailsFromFlavor($parentJob->getEntryId(), $parentJob);
     }
     if (!count($flavors)) {
         $shouldConvert = false;
     }
     if (!$shouldConvert) {
         self::bypassConversion($originalFlavorAsset, $entry, $convertProfileJob);
         return true;
     }
     return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $mediaInfo);
 }
Beispiel #4
0
 public static function handleProvisionProvideFinished(BatchJob $dbBatchJob, kProvisionJobData $data, BatchJob $twinJob = null)
 {
     $entry = $dbBatchJob->getEntry();
     $entry->setStreamUsername($data->getEncoderUsername());
     $entry->setStreamUrl($data->getRtmp());
     $entry->setStreamRemoteId($data->getStreamID());
     $entry->setStreamRemoteBackupId($data->getBackupStreamID());
     $entry->setPrimaryBroadcastingUrl($data->getPrimaryBroadcastingUrl());
     $entry->setSecondaryBroadcastingUrl($data->getSecondaryBroadcastingUrl());
     $entry->setStreamName($data->getStreamName());
     kBatchManager::updateEntry($dbBatchJob, entryStatus::READY);
     return $dbBatchJob;
 }
 /**
  * batch decideProfileConvert is the decision layer for a conversion profile
  *
  * @param BatchJob $parentJob
  * @param BatchJob $convertProfileJob
  * @param int $mediaInfoId
  * @return bool true if created all required conversions
  */
 public static function decideProfileConvert(BatchJob $parentJob, BatchJob $convertProfileJob, $mediaInfoId = null)
 {
     KalturaLog::log("Conversion decision layer used 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, $convertProfileJob->getEntryId());
         return false;
     }
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($entryId);
     if (is_null($originalFlavorAsset)) {
         $errDescription = 'Original flavor asset not found';
         self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $convertProfileJob->getEntryId());
         return false;
     }
     // 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, $convertProfileJob->getEntryId());
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_DELETED);
         $originalFlavorAsset->setDeletedAt(time());
         $originalFlavorAsset->save();
         return false;
     }
     $mediaInfo = null;
     if ($mediaInfoId) {
         $mediaInfo = mediaInfoPeer::retrieveByPK($mediaInfoId);
     }
     $shouldConvert = self::shouldConvertProfileFlavors($profile, $mediaInfo, $originalFlavorAsset);
     // gets the ids of the flavor params
     $flavorsIds = array();
     $conversionProfileFlavorParams = array();
     foreach ($list as $flavorParamsConversionProfile) {
         $flavorsId = $flavorParamsConversionProfile->getFlavorParamsId();
         $flavorsIds[] = $flavorsId;
         $conversionProfileFlavorParams[$flavorsId] = $flavorParamsConversionProfile;
     }
     KalturaLog::info("Flavors in conversion profile [" . implode(',', $flavorsIds) . "]");
     $sourceFlavor = null;
     $flavors = assetParamsPeer::retrieveFlavorsByPKs($flavorsIds);
     $ingestedNeeded = self::checkConvertProfileParams($flavors, $conversionProfileFlavorParams, $entry, $sourceFlavor);
     KalturaLog::log(count($flavors) . " destination flavors found for this profile[" . $profile->getId() . "]");
     if (!$sourceFlavor) {
         KalturaLog::log("Source flavor params not found");
         $originalFlavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_TEMP);
         $originalFlavorAsset->save();
         /*
          * Check for 'auto-intermediate-source
          */
         $res = self::decideSourceFlavorConvert($entryId, null, $originalFlavorAsset, $profile->getId(), $flavors, $mediaInfo, $parentJob, $convertProfileJob);
         if (!$res) {
             $originalFlavorAsset->incrementInterFlowCount();
             $originalFlavorAsset->save();
             return false;
         }
         $originalFlavorAsset->removeInterFlowCount();
         $originalFlavorAsset->save();
     } elseif ($shouldConvert) {
         KalturaLog::log("Source flavor params [" . $sourceFlavor->getId() . "] found");
         $originalFlavorAsset->setFlavorParamsId($sourceFlavor->getId());
         $res = self::decideSourceFlavorConvert($entryId, $sourceFlavor, $originalFlavorAsset, $profile->getId(), $flavors, $mediaInfo, $parentJob, $convertProfileJob);
         if (!$res) {
             $originalFlavorAsset->incrementInterFlowCount();
             $originalFlavorAsset->save();
             return false;
         }
         $originalFlavorAsset->removeInterFlowCount();
         $originalFlavorAsset->setStatusLocalReady();
         $originalFlavorAsset->save();
         $entry->save();
         kFlowHelper::generateThumbnailsFromFlavor($parentJob->getEntryId(), $parentJob);
     }
     if (!count($flavors)) {
         $shouldConvert = false;
     }
     if (!$shouldConvert) {
         if ($ingestedNeeded) {
             kJobsManager::updateBatchJob($convertProfileJob, BatchJob::BATCHJOB_STATUS_FINISHED);
             return false;
         } else {
             self::bypassConversion($originalFlavorAsset, $entry, $convertProfileJob);
             return true;
         }
     }
     try {
         return self::decideProfileFlavorsConvert($parentJob, $convertProfileJob, $flavors, $conversionProfileFlavorParams, $profile->getId(), $mediaInfo);
     } catch (Exception $e) {
         $code = $e->getCode();
         if ($code == KDLErrors::SanityInvalidFrameDim || $code == KDLErrors::NoValidMediaStream) {
             throw $e;
         }
     }
 }
 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;
 }
Beispiel #7
0
 public static function handleProvisionProvideFinished(BatchJob $dbBatchJob, kProvisionJobData $data)
 {
     kBatchManager::updateEntry($dbBatchJob->getEntryId(), entryStatus::READY);
     $entry = $dbBatchJob->getEntry();
     if (!$entry) {
         return $dbBatchJob;
     }
     $data->populateEntryFromData($entry);
     $liveAssets = assetPeer::retrieveByEntryId($entry->getId(), array(assetType::LIVE));
     foreach ($liveAssets as $liveAsset) {
         /* @var $liveAsset liveAsset */
         $liveAsset->setStatus(asset::ASSET_STATUS_READY);
         $liveAsset->save();
     }
     $entry->save();
     return $dbBatchJob;
 }
 public static function exportSourceAssetFromJob(BatchJob $dbBatchJob)
 {
     // convert profile finished - export source flavor
     if ($dbBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
         $externalStorages = StorageProfilePeer::retrieveAutomaticByPartnerId($dbBatchJob->getPartnerId());
         $sourceFlavor = assetPeer::retrieveOriginalByEntryId($dbBatchJob->getEntryId());
         if (!$sourceFlavor) {
             KalturaLog::debug('Cannot find source flavor for entry id [' . $dbBatchJob->getEntryId() . ']');
         } else {
             if (!$sourceFlavor->isLocalReadyStatus()) {
                 KalturaLog::debug('Source flavor id [' . $sourceFlavor->getId() . '] has status [' . $sourceFlavor->getStatus() . '] - not ready for export');
             } else {
                 foreach ($externalStorages as $externalStorage) {
                     if ($externalStorage->triggerFitsReadyAsset($dbBatchJob->getEntryId())) {
                         self::exportFlavorAsset($sourceFlavor, $externalStorage);
                     }
                 }
             }
         }
     }
     // convert collection finished - export ism and ismc files
     if ($dbBatchJob->getJobType() == BatchJobType::CONVERT_COLLECTION && $dbBatchJob->getJobSubType() == conversionEngineType::EXPRESSION_ENCODER3) {
         $entry = $dbBatchJob->getEntry();
         $externalStorages = StorageProfilePeer::retrieveAutomaticByPartnerId($dbBatchJob->getPartnerId());
         foreach ($externalStorages as $externalStorage) {
             if ($externalStorage->triggerFitsReadyAsset($entry->getId())) {
                 $ismKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
                 if (kFileSyncUtils::fileSync_exists($ismKey)) {
                     self::export($entry, $externalStorage, $ismKey);
                 }
                 $ismcKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
                 if (kFileSyncUtils::fileSync_exists($ismcKey)) {
                     self::export($entry, $externalStorage, $ismcKey);
                 }
             }
         }
     }
     return true;
 }
Beispiel #9
0
 public static function exportSourceAssetFromJob(BatchJob $dbBatchJob)
 {
     // convert collection finished - export ism and ismc files
     if ($dbBatchJob->getJobType() == BatchJobType::CONVERT_COLLECTION && $dbBatchJob->getJobSubType() == conversionEngineType::EXPRESSION_ENCODER3) {
         $entry = $dbBatchJob->getEntry();
         $externalStorages = StorageProfilePeer::retrieveAutomaticByPartnerId($dbBatchJob->getPartnerId());
         foreach ($externalStorages as $externalStorage) {
             if ($externalStorage->triggerFitsReadyAsset($entry->getId())) {
                 $ismKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
                 if (kFileSyncUtils::fileSync_exists($ismKey)) {
                     self::export($entry, $externalStorage, $ismKey);
                 }
                 $ismcKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
                 if (kFileSyncUtils::fileSync_exists($ismcKey)) {
                     self::export($entry, $externalStorage, $ismcKey);
                 }
             }
         }
     }
     return true;
 }
Beispiel #10
0
 /**
  * @param BatchJob $dbBatchJob
  * @param BatchJob $twinJob
  * @return bool true if should continue to the next consumer
  */
 public function updatedJob(BatchJob $dbBatchJob, BatchJob $twinJob = null)
 {
     if ($dbBatchJob->getStatus() != BatchJob::BATCHJOB_STATUS_FINISHED) {
         return true;
     }
     // convert profile finished - export source flavor
     if ($dbBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
         $externalStorages = StorageProfilePeer::retrieveAutomaticByPartnerId($dbBatchJob->getPartnerId());
         foreach ($externalStorages as $externalStorage) {
             if ($externalStorage->getTrigger() == StorageProfile::STORAGE_TEMP_TRIGGER_FLAVOR_READY || $externalStorage->getTrigger() == StorageProfile::STORAGE_TEMP_TRIGGER_MODERATION_APPROVED && $dbBatchJob->getEntry()->getModerationStatus() == entry::ENTRY_MODERATION_STATUS_APPROVED) {
                 $sourceFlavor = flavorAssetPeer::retrieveOriginalReadyByEntryId($dbBatchJob->getEntryId());
                 if ($sourceFlavor) {
                     $this->exportFlavorAsset($sourceFlavor, $externalStorage);
                 }
             }
         }
     }
     // convert collection finished - export ism and ismc files
     if ($dbBatchJob->getJobType() == BatchJobType::CONVERT_COLLECTION && $dbBatchJob->getJobSubType() == conversionEngineType::EXPRESSION_ENCODER3) {
         $entry = $dbBatchJob->getEntry();
         $externalStorages = StorageProfilePeer::retrieveAutomaticByPartnerId($dbBatchJob->getPartnerId());
         foreach ($externalStorages as $externalStorage) {
             if ($externalStorage->getTrigger() == StorageProfile::STORAGE_TEMP_TRIGGER_FLAVOR_READY || $externalStorage->getTrigger() == StorageProfile::STORAGE_TEMP_TRIGGER_MODERATION_APPROVED && $entry->getModerationStatus() == entry::ENTRY_MODERATION_STATUS_APPROVED) {
                 $ismKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISM);
                 if (kFileSyncUtils::fileSync_exists($ismKey)) {
                     $this->export($entry, $externalStorage, $ismKey);
                 }
                 $ismcKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_ISMC);
                 if (kFileSyncUtils::fileSync_exists($ismcKey)) {
                     $this->export($entry, $externalStorage, $ismcKey);
                 }
             }
         }
     }
     return true;
 }
Beispiel #11
0
 public static function updateEntry(BatchJob $dbBatchJob, $status)
 {
     $entry = $dbBatchJob->getEntry();
     if (!$entry) {
         KalturaLog::debug("Entry was not found for job id [{$dbBatchJob->getId}()]");
         return null;
     }
     // entry status didn't change - no need to send notification
     if ($entry->getStatus() == $status) {
         return $entry;
     }
     // backward compatibility
     // if entry has kshow, and this is the first entry in the mix,
     // the thumbnail of the entry should be copied into the mix entry
     if ($status == entryStatus::READY) {
         myEntryUtils::createRoughcutThumbnailFromEntry($entry, false);
     }
     // entry status is ready and above, not changing status through batch job
     if ($entry->getStatus() >= entryStatus::READY) {
         return $entry;
     }
     $entry->setStatus($status);
     $entry->save();
     kFlowHelper::createEntryUpdateNotification($dbBatchJob);
     return $entry;
 }
Beispiel #12
0
 /**
  * @param BatchJob $parentJob
  * @param int $jobSubType
  * @param string $srcFileSyncLocalPath
  * @param int $flavorAssetId
  * @param int $flavorParamsOutputId
  * @param bool $createThumb
  * @param int $thumbOffset
  * @return BatchJob
  */
 public static function addPostConvertJob(BatchJob $parentJob, $jobSubType, $srcFileSyncLocalPath, $flavorAssetId, $flavorParamsOutputId, $createThumb = false, $thumbOffset = 3)
 {
     $postConvertData = new kPostConvertJobData();
     $postConvertData->setSrcFileSyncLocalPath($srcFileSyncLocalPath);
     $postConvertData->setFlavorParamsOutputId($flavorParamsOutputId);
     $postConvertData->setFlavorAssetId($flavorAssetId);
     $postConvertData->setThumbOffset($thumbOffset);
     $postConvertData->setCreateThumb($createThumb);
     $parentData = $parentJob->getData();
     if ($parentData instanceof kConvartableJobData) {
         $postConvertData->setCurrentOperationSet($parentData->getCurrentOperationSet());
         $postConvertData->setCurrentOperationIndex($parentData->getCurrentOperationIndex());
     }
     if ($createThumb) {
         $flavorParamsOutput = flavorParamsOutputPeer::retrieveByPK($flavorParamsOutputId);
         if (!$flavorParamsOutput) {
             $flavorAsset = flavorAssetPeer::retrieveById($flavorAssetId);
             if ($flavorAsset) {
                 $postConvertData->setThumbHeight($flavorAsset->getHeight());
                 $postConvertData->setThumbBitrate($flavorAsset->getBitrate());
             } else {
                 $postConvertData->setCreateThumb(false);
             }
         } elseif (!$flavorParamsOutput->getVideoBitrate()) {
             $postConvertData->setCreateThumb(false);
         } else {
             $entry = $parentJob->getEntry();
             $rootBatchJob = $parentJob->getRootJob();
             if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
                 $thisFlavorHeight = $flavorParamsOutput->getHeight();
                 $thisFlavorBitrate = $flavorParamsOutput->getVideoBitrate();
                 $rootBatchJobData = $rootBatchJob->getData();
                 $createThumb = false;
                 if ($rootBatchJobData->getThumbBitrate() < $thisFlavorBitrate) {
                     $createThumb = true;
                 } elseif ($rootBatchJobData->getThumbBitrate() == $thisFlavorBitrate && $rootBatchJobData->getThumbHeight() < $thisFlavorHeight) {
                     $createThumb = true;
                 }
                 if ($createThumb) {
                     $postConvertData->setCreateThumb(true);
                     $postConvertData->setThumbHeight($thisFlavorHeight);
                     $postConvertData->setThumbBitrate($thisFlavorBitrate);
                 }
             } elseif (!$entry->getThumbnailVersion()) {
                 $thisFlavorHeight = $flavorParamsOutput->getHeight();
                 $thisFlavorBitrate = $flavorParamsOutput->getVideoBitrate();
                 $postConvertData->setCreateThumb(true);
                 $postConvertData->setThumbHeight($thisFlavorHeight);
                 $postConvertData->setThumbBitrate($thisFlavorBitrate);
             }
         }
     }
     KalturaLog::log("Post Convert created with file: " . $postConvertData->getSrcFileSyncLocalPath());
     return kJobsManager::addJob($parentJob->createChild(), $postConvertData, BatchJobType::POSTCONVERT, $jobSubType);
 }