/**
  * Get flavor params output object by ID
  * 
  * @action get
  * @param int $id
  * @return KalturaFlavorParamsOutput
  * @throws KalturaErrors::FLAVOR_PARAMS_OUTPUT_ID_NOT_FOUND
  */
 public function getAction($id)
 {
     $flavorParamsOutputDb = assetParamsOutputPeer::retrieveByPK($id);
     if (!$flavorParamsOutputDb) {
         throw new KalturaAPIException(KalturaErrors::FLAVOR_PARAMS_OUTPUT_ID_NOT_FOUND, $id);
     }
     $flavorParamsOutput = KalturaFlavorParamsFactory::getFlavorParamsOutputInstance($flavorParamsOutputDb->getType());
     $flavorParamsOutput->fromObject($flavorParamsOutputDb);
     return $flavorParamsOutput;
 }
 /**
  * Get thumb params output object by ID
  * 
  * @action get
  * @param int $id
  * @return KalturaThumbParamsOutput
  * @throws KalturaErrors::THUMB_PARAMS_OUTPUT_ID_NOT_FOUND
  */
 public function getAction($id)
 {
     $thumbParamsOutputDb = assetParamsOutputPeer::retrieveByPK($id);
     if (!$thumbParamsOutputDb) {
         throw new KalturaAPIException(KalturaErrors::THUMB_PARAMS_OUTPUT_ID_NOT_FOUND, $id);
     }
     $thumbParamsOutput = new KalturaThumbParamsOutput();
     $thumbParamsOutput->fromObject($thumbParamsOutputDb);
     return $thumbParamsOutput;
 }
예제 #3
0
 public function objectCreated(BaseObject $object)
 {
     $entry = entryPeer::retrieveByPK($object->getEntryId());
     if ($entry && $entry->getReplacedEntryId()) {
         $entry = entryPeer::retrieveByPK($entry->getReplacedEntryId());
     }
     $wvFlavorParamsOutput = assetParamsOutputPeer::retrieveByPK($object->getId());
     if ($entry && $wvFlavorParamsOutput) {
         $wvFlavorParamsOutput->setWidevineDistributionStartDate($this->getLicenseStartDateFromEntry($entry));
         $wvFlavorParamsOutput->setWidevineDistributionEndDate($this->getLicenseEndDateFromEntry($entry));
         $wvFlavorParamsOutput->save();
     }
     return true;
 }
 /**
  * batch redecideFlavorConvert is the decision layer for a single flavor conversion 
  * 
  * @param string $srcFileSyncLocalPath
  * @param int $flavorAssetId
  * @param int $flavorParamsOutputId
  * @param int $mediaInfoId
  * @param BatchJob $parentJob
  * @param int $lastEngineType
  * @return BatchJob 
  */
 public static function redecideFlavorConvert($flavorAssetId, $flavorParamsOutputId, $mediaInfoId, BatchJob $parentJob, $lastEngineType)
 {
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($parentJob->getEntryId());
     if (is_null($originalFlavorAsset)) {
         KalturaLog::log('Original flavor asset not found');
         return null;
     }
     $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $flavor = assetParamsOutputPeer::retrieveByPK($flavorParamsOutputId);
     if (is_null($flavor)) {
         KalturaLog::log("Flavor params output not found [{$flavorParamsOutputId}]");
         return null;
     }
     return kJobsManager::addFlavorConvertJob($srcSyncKey, $flavor, $flavorAssetId, $mediaInfoId, $parentJob, $lastEngineType);
 }
예제 #5
0
 /**
  * batch redecideFlavorConvert is the decision layer for a single flavor conversion
  *
  * @param string $srcFileSyncLocalPath
  * @param int $flavorAssetId
  * @param int $flavorParamsOutputId
  * @param int $mediaInfoId
  * @param BatchJob $parentJob
  * @param int $lastEngineType
  * @return BatchJob
  */
 public static function redecideFlavorConvert($flavorAssetId, $flavorParamsOutputId, $mediaInfoId, BatchJob $parentJob, $lastEngineType)
 {
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($parentJob->getEntryId());
     if (is_null($originalFlavorAsset)) {
         KalturaLog::log('Original flavor asset not found');
         return null;
     }
     $flavor = assetParamsOutputPeer::retrieveByPK($flavorParamsOutputId);
     if (is_null($flavor)) {
         KalturaLog::log("Flavor params output not found [{$flavorParamsOutputId}]");
         return null;
     }
     $flavorAsset = assetPeer::retrieveById($flavorAssetId);
     if (is_null($flavorAsset)) {
         KalturaLog::log("Flavor asset not found [{$flavorAssetId}]");
         return null;
     }
     return self::decideFlavorConvert($flavorAsset, $flavor, $originalFlavorAsset, null, $mediaInfoId, $parentJob, $lastEngineType);
 }
예제 #6
0
 /**
  * @param BatchJob $parentJob
  * @param int $postConvertAssetType
  * @param string $srcFileSyncLocalPath
  * @param int $flavorAssetId
  * @param int $flavorParamsOutputId
  * @param bool $createThumb
  * @param int $thumbOffset
  * @param string $customData
  * @return BatchJob
  */
 public static function addPostConvertJob(BatchJob $parentJob = null, $postConvertAssetType, $srcFileSyncLocalPath, $flavorAssetId, $flavorParamsOutputId, $createThumb = false, $thumbOffset = 3)
 {
     $postConvertData = new kPostConvertJobData();
     $postConvertData->setPostConvertAssetType($postConvertAssetType);
     $postConvertData->setSrcFileSyncLocalPath($srcFileSyncLocalPath);
     $postConvertData->setFlavorParamsOutputId($flavorParamsOutputId);
     $postConvertData->setFlavorAssetId($flavorAssetId);
     $postConvertData->setThumbOffset($thumbOffset);
     $postConvertData->setCreateThumb($createThumb);
     if ($parentJob) {
         $parentData = $parentJob->getData();
         if ($parentData instanceof kConvartableJobData) {
             $postConvertData->setCurrentOperationSet($parentData->getCurrentOperationSet());
             $postConvertData->setCurrentOperationIndex($parentData->getCurrentOperationIndex());
         }
     }
     $flavorAsset = assetPeer::retrieveById($flavorAssetId);
     $flavorParamsOutput = null;
     if ($createThumb) {
         $flavorParamsOutput = assetParamsOutputPeer::retrieveByPK($flavorParamsOutputId);
         if (!$flavorParamsOutput) {
             if ($flavorAsset) {
                 $postConvertData->setThumbHeight($flavorAsset->getHeight());
                 $postConvertData->setThumbBitrate($flavorAsset->getBitrate());
             } else {
                 $postConvertData->setCreateThumb(false);
             }
         } elseif (!$flavorParamsOutput->getVideoBitrate()) {
             $postConvertData->setCreateThumb(false);
         } elseif ($flavorParamsOutput->getSourceRemoteStorageProfileId() != StorageProfile::STORAGE_KALTURA_DC) {
             $postConvertData->setCreateThumb(false);
         } elseif ($flavorAsset) {
             $entry = $flavorAsset->getentry();
             if ($entry) {
                 $thisFlavorHeight = $flavorParamsOutput->getHeight();
                 $thisFlavorBitrate = $flavorParamsOutput->getVideoBitrate();
                 $createThumb = false;
                 if ($entry->getThumbBitrate() < $thisFlavorBitrate) {
                     $createThumb = true;
                 } elseif ($entry->getThumbBitrate() == $thisFlavorBitrate && $entry->getThumbHeight() < $thisFlavorHeight) {
                     $createThumb = true;
                 }
                 if ($createThumb) {
                     $postConvertData->setCreateThumb(true);
                     $postConvertData->setThumbHeight($thisFlavorHeight);
                     $postConvertData->setThumbBitrate($thisFlavorBitrate);
                 }
             }
         }
     }
     $batchJob = null;
     $mediaParserType = $flavorParamsOutput ? $flavorParamsOutput->getMediaParserType() : mediaParserType::MEDIAINFO;
     if ($parentJob) {
         //Job will be created with parent job as his root job
         $useSameRoot = true;
         if ($parentJob->getJobType() == BatchJobType::CONVERT_PROFILE) {
             $useSameRoot = false;
         }
         $batchJob = $parentJob->createChild(BatchJobType::POSTCONVERT, $mediaParserType, $useSameRoot);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($flavorAsset->getEntryId());
         $batchJob->setPartnerId($flavorAsset->getPartnerId());
     }
     $batchJob->setObjectId($flavorAsset->getId());
     $batchJob->setObjectType(BatchJobObjectType::ASSET);
     KalturaLog::log("Post Convert created with file: " . $postConvertData->getSrcFileSyncLocalPath());
     return kJobsManager::addJob($batchJob, $postConvertData, BatchJobType::POSTCONVERT, $mediaParserType);
 }
 /**
  * @return the ready behavior
  */
 public function getReadyBehavior()
 {
     $flavorParamsOutput = assetParamsOutputPeer::retrieveByPK($this->flavorParamsOutputId);
     if ($flavorParamsOutput) {
         return $flavorParamsOutput->getReadyBehavior();
     }
     return null;
 }
예제 #8
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kConvertJobData $data
  * @return BatchJob
  */
 public static function handleConvertFailed(BatchJob $dbBatchJob, kConvertJobData $data)
 {
     if ($dbBatchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED) {
         return $dbBatchJob;
     }
     // verifies that flavor asset created
     if (!$data->getFlavorAssetId()) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $data->getFlavorAssetId());
     }
     $flavorAsset = assetPeer::retrieveById($data->getFlavorAssetId());
     // verifies that flavor asset exists
     if (!$flavorAsset) {
         throw new APIException(APIErrors::INVALID_FLAVOR_ASSET_ID, $data->getFlavorAssetId());
     }
     if (!is_null($data->getEngineMessage())) {
         $flavorAsset->setDescription($flavorAsset->getDescription() . "\n" . $data->getEngineMessage());
         $flavorAsset->save();
     }
     // creats the file sync
     if (file_exists($data->getLogFileSyncLocalPath())) {
         $logSyncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_CONVERT_LOG);
         try {
             kFileSyncUtils::moveFromFile($data->getLogFileSyncLocalPath(), $logSyncKey);
         } catch (Exception $e) {
             $err = 'Saving conversion log: ' . $e->getMessage();
             KalturaLog::err($err);
             $desc = $dbBatchJob->getDescription() . "\n" . $err;
             $dbBatchJob->getDescription($desc);
         }
     }
     //		$flavorAsset->incrementVersion();
     //		$flavorAsset->save();
     $fallbackCreated = kBusinessPostConvertDL::handleConvertFailed($dbBatchJob, $dbBatchJob->getJobSubType(), $data->getFlavorAssetId(), $data->getFlavorParamsOutputId(), $data->getMediaInfoId());
     if (!$fallbackCreated) {
         $rootBatchJob = $dbBatchJob->getRootJob();
         if ($rootBatchJob && $rootBatchJob->getJobType() == BatchJobType::BULKDOWNLOAD) {
             $entryId = $dbBatchJob->getEntryId();
             $flavorParamsId = $data->getFlavorParamsOutputId();
             $flavorParamsOutput = assetParamsOutputPeer::retrieveByPK($flavorParamsId);
             $fileFormat = $flavorParamsOutput->getFileExt();
             $entry = $dbBatchJob->getEntry();
             if (!$entry) {
                 return $dbBatchJob;
             }
             $notificationData = array("puserId" => $entry->getPuserId(), "entryId" => $entry->getId(), "entryIntId" => $entry->getIntId(), "entryVersion" => $entry->getVersion(), "fileFormat" => $flavorAsset->getFileExt(), "conversionQuality" => $entry->getConversionQuality());
             $extraData = array("data" => json_encode($notificationData), "partner_id" => $entry->getPartnerId(), "puser_id" => $entry->getPuserId(), "entry_id" => $entry->getId(), "entry_int_id" => $entry->getIntId(), "entry_version" => $entry->getVersion(), "conversion_quality" => $entry->getConversionQuality(), "status" => $entry->getStatus(), "abort" => $dbBatchJob->getExecutionStatus() == BatchJobExecutionStatus::ABORTED, "message" => $dbBatchJob->getMessage(), "description" => $dbBatchJob->getDescription(), "job_type" => BatchJobType::DOWNLOAD, "conversion_error" => "Error while converting [{$entryId}] [{$fileFormat}]", "status" => BatchJob::BATCHJOB_STATUS_FAILED, "progress" => 0, "debug" => __LINE__);
             myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_BATCH_JOB_FAILED, $dbBatchJob, $dbBatchJob->getPartnerId(), null, null, $extraData, $entryId);
         }
     }
     return $dbBatchJob;
 }
예제 #9
0
 /**
  * batch getExclusiveConvertJob action allows to get a BatchJob of type CONVERT 
  * 
  * @action getExclusiveConvertJobs
  * @param KalturaExclusiveLockKey $lockKey The unique lock key from the batch-process. Is used for the locking mechanism  
  * @param int $maxExecutionTime The maximum time in seconds the job reguarly take. Is used for the locking mechanism when determining an unexpected termination of a batch-process.
  * @param int $numberOfJobs The maximum number of jobs to return. 
  * @param KalturaBatchJobFilter $filter Set of rules to fetch only rartial list of jobs  
  * @return KalturaBatchJobArray 
  */
 function getExclusiveConvertJobsAction(KalturaExclusiveLockKey $lockKey, $maxExecutionTime, $numberOfJobs, KalturaBatchJobFilter $filter = null)
 {
     $jobs = $this->getExclusiveJobs($lockKey, $maxExecutionTime, $numberOfJobs, $filter, BatchJobType::CONVERT);
     if ($jobs) {
         foreach ($jobs as &$job) {
             $data = $job->getData();
             assetParamsOutputPeer::resetInstanceCriteriaFilter();
             $flavorParamsOutput = assetParamsOutputPeer::retrieveByPK($data->getFlavorParamsOutputId());
             $data->setFlavorParamsOutput($flavorParamsOutput);
             $job->setData($data);
         }
     }
     return KalturaBatchJobArray::fromBatchJobArray($jobs);
 }
예제 #10
0
 /**
  * @return flavorParamsOutput the $flavorParamsOutput
  */
 public function getFlavorParamsOutput()
 {
     if ($this->flavorParamsOutput) {
         return $this->flavorParamsOutput;
     }
     if (is_null($this->flavorParamsOutputId)) {
         return null;
     }
     assetParamsOutputPeer::resetInstanceCriteriaFilter();
     return assetParamsOutputPeer::retrieveByPK($this->flavorParamsOutputId);
 }