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; }
/** * batch createFlavorAsset orgenize a convert job data * * @param flavorParamsOutputWrap $flavor * @param int $partnerId * @param int $entryId * @param string $flavorAssetId * @return flavorAsset */ public static function createFlavorAsset(flavorParamsOutputWrap $flavor, $partnerId, $entryId, $flavorAssetId = null) { $description = kBusinessConvertDL::parseFlavorDescription($flavor); $flavorAsset = null; if ($flavorAssetId) { $flavorAsset = flavorAssetPeer::retrieveById($flavorAssetId); } if (!$flavorAsset) { $flavorAsset = flavorAssetPeer::retrieveByEntryIdAndFlavorParams($entryId, $flavor->getFlavorParamsId()); } if ($flavorAsset) { $description = $flavorAsset->getDescription() . "\n" . $description; $flavorAsset->setDescription($description); $flavorAsset->incrementVersion(); } else { // creates the flavor asset $flavorAsset = new flavorAsset(); $flavorAsset->setPartnerId($partnerId); $flavorAsset->setEntryId($entryId); $flavorAsset->setDescription($description); } $flavorAsset->setTags($flavor->getTags()); $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_QUEUED); $flavorAsset->setFlavorParamsId($flavor->getFlavorParamsId()); $flavorAsset->setFileExt($flavor->getFileExt()); // decided by the business logic layer if ($flavor->_create_anyway) { KalturaLog::log("Flavor [" . $flavor->getFlavorParamsId() . "] selected to be created anyway"); } else { if (!$flavor->IsValid()) { KalturaLog::log("Flavor [" . $flavor->getFlavorParamsId() . "] is invalid"); $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->save(); return null; } if ($flavor->_force) { KalturaLog::log("Flavor [" . $flavor->getFlavorParamsId() . "] is forced"); } else { if ($flavor->_isNonComply) { KalturaLog::log("Flavor [" . $flavor->getFlavorParamsId() . "] is none-comply"); $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE); $flavorAsset->save(); return null; } KalturaLog::log("Flavor [" . $flavor->getFlavorParamsId() . "] is valid"); } } $flavorAsset->save(); // save flavor params $flavor->setPartnerId($partnerId); $flavor->setEntryId($entryId); $flavor->setFlavorAssetId($flavorAsset->getId()); $flavor->setFlavorAssetVersion($flavorAsset->getVersion()); $flavor->save(); return $flavorAsset; }
/** * 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); }
private static function decideSourceFlavorConvert($entryId, assetParams $sourceFlavor = null, flavorAsset $originalFlavorAsset, $conversionProfileId, $flavors, mediaInfo $mediaInfo = null, BatchJob $parentJob, BatchJob $convertProfileJob) { if ($sourceFlavor && ($sourceFlavor->getOperators() || $sourceFlavor->getConversionEngines()) && $originalFlavorAsset->getInterFlowCount() == null) { KalturaLog::log("Source flavor asset requires conversion"); self::adjustAssetParams($entryId, array($sourceFlavor)); $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $errDescription = null; $sourceFlavorOutput = self::validateFlavorAndMediaInfo($sourceFlavor, $mediaInfo, $errDescription); if (!$sourceFlavorOutput) { if (!$errDescription) { $errDescription = "Failed to create flavor params output from source flavor"; } $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}"); $originalFlavorAsset->setStatus(flavorAsset::ASSET_STATUS_ERROR); $originalFlavorAsset->save(); kBatchManager::updateEntry($entryId, entryStatus::ERROR_CONVERTING); kJobsManager::updateBatchJob($convertProfileJob, BatchJob::BATCHJOB_STATUS_FAILED); return false; } } elseif ($mediaInfo) { /* * Check whether there is a need for an intermediate source pre-processing */ $sourceFlavorOutput = KDLWrap::GenerateIntermediateSource($mediaInfo, $flavors); if (!$sourceFlavorOutput) { return true; } $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $errDescription = null; /* * Save the original source asset in another asset, in order * to prevent its liquidated by the inter-source asset. * But, do it only if the conversion profile contains source flavor */ if ($sourceFlavor) { $sourceAsset = assetPeer::retrieveById($mediaInfo->getFlavorAssetId()); $copyFlavorParams = assetParamsPeer::retrieveBySystemName(self::SAVE_ORIGINAL_SOURCE_FLAVOR_PARAM_SYS_NAME); if (!$copyFlavorParams) { throw new APIException(APIErrors::OBJECT_NOT_FOUND); } $asset = $sourceAsset->copy(); $asset->setFlavorParamsId($copyFlavorParams->getId()); $asset->setFromAssetParams($copyFlavorParams); $asset->setStatus(flavorAsset::ASSET_STATUS_READY); $asset->setIsOriginal(0); $asset->setTags($copyFlavorParams->getTags()); $asset->incrementVersion(); $asset->save(); kFileSyncUtils::createSyncFileLinkForKey($asset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET), $sourceAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET)); $origFileSync = kFileSyncUtils::getLocalFileSyncForKey($sourceAsset->getSyncKey(asset::FILE_SYNC_ASSET_SUB_TYPE_ASSET)); $asset->setSize(intval($origFileSync->getFileSize() / 1000)); $asset->save(); } } /* * '_passthrough' controls whether the source is to be 'passthrough' although there * is a source flavor that contains transcoder settings. * Looks for a '_passthrough' flag on the source's flavor params output. */ if (!$sourceFlavorOutput || $sourceFlavorOutput->_passthrough == true) { return true; } // 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"; self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $convertProfileJob->getEntryId()); 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->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING); if (isset($sourceFlavor)) { $originalFlavorAsset->addTags($sourceFlavor->getTagsArray()); $originalFlavorAsset->setFileExt($sourceFlavorOutput->getFileExt()); $originalFlavorAsset->save(); } // save flavor params $sourceFlavorOutput->setFlavorAssetVersion($originalFlavorAsset->getVersion()); $sourceFlavorOutput->save(); $mediaInfoId = null; if ($mediaInfo) { $mediaInfoId = $mediaInfo->getId(); } kJobsManager::addFlavorConvertJob(array($srcSyncKey), $sourceFlavorOutput, $originalFlavorAsset->getId(), $conversionProfileId, $mediaInfoId, $parentJob); return false; }
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; }
/** * batch createFlavorAsset orgenize a convert job data * * @param flavorParamsOutputWrap $flavor * @param int $partnerId * @param int $entryId * @param string $flavorAssetId * @return flavorAsset */ public static function createFlavorAsset(flavorParamsOutputWrap $flavor, $partnerId, $entryId, $flavorAssetId = null) { $description = kBusinessConvertDL::parseFlavorDescription($flavor); $flavorAsset = null; if ($flavorAssetId) { $flavorAsset = assetPeer::retrieveById($flavorAssetId); } if (!$flavorAsset) { $flavorAsset = assetPeer::retrieveByEntryIdAndParams($entryId, $flavor->getFlavorParamsId()); } if ($flavorAsset) { $description = $flavorAsset->getDescription() . "\n" . $description; $flavorAsset->setDescription($description); // $flavorAsset->incrementVersion(); } else { // creates the flavor asset $flavorAsset = flavorAsset::getInstance($flavor->getType()); $flavorAsset->setPartnerId($partnerId); $flavorAsset->setEntryId($entryId); $flavorAsset->setDescription($description); } $flavorAsset->setTags($flavor->getTags()); $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_QUEUED); $flavorAsset->setFlavorParamsId($flavor->getFlavorParamsId()); $flavorAsset->setFileExt($flavor->getFileExt()); // decided by the business logic layer if ($flavor->_create_anyway) { KalturaLog::log("Flavor [" . $flavor->getFlavorParamsId() . "] selected to be created anyway"); } else { if (!$flavor->IsValid()) { KalturaLog::err("Flavor [" . $flavor->getFlavorParamsId() . "] is invalid"); $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_ERROR); $flavorAsset->save(); return null; } if ($flavor->_force) { KalturaLog::log("Flavor [" . $flavor->getFlavorParamsId() . "] is forced"); } else { if ($flavor->_isNonComply) { KalturaLog::err("Flavor [" . $flavor->getFlavorParamsId() . "] is none-comply"); $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE); $flavorAsset->save(); return null; } $vidCodec = $flavor->getVideoCodec(); $audCodec = $flavor->getAudioCodec(); $sourceAssetParamsIds = $flavor->getSourceAssetParamsIds(); /* * Added check for 'sourceAssetParamsIds' to conditions for setting * of 'FLAVOR_ASSET_STATUS_NOT_APPLICABLE' - * - flavors that are dependent on other assets/sources can not be * redundant (evaluated by 'KDL' from bitrate's), * they should be activated upon completion of dependee asset * The usecase - PlayReady audio-only flavors */ if ($flavor->_isRedundant && !isset($vidCodec) && isset($audCodec) && !(isset($sourceAssetParamsIds) && strlen($sourceAssetParamsIds) > 0)) { KalturaLog::err("Flavor [" . $flavor->getFlavorParamsId() . "] is redandant audio-only"); $flavorAsset->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_NOT_APPLICABLE); $flavorAsset->save(); return null; } KalturaLog::log("Flavor [" . $flavor->getFlavorParamsId() . "] is valid"); } } $flavorAsset->save(); // save flavor params $flavor->setPartnerId($partnerId); $flavor->setEntryId($entryId); $flavor->setFlavorAssetId($flavorAsset->getId()); $flavor->setFlavorAssetVersion($flavorAsset->getVersion()); $flavor->save(); return $flavorAsset; }
private static function decideSourceFlavorConvert($entryId, assetParams $sourceFlavor = null, flavorAsset $originalFlavorAsset, $conversionProfileId, $flavors, mediaInfo $mediaInfo = null, BatchJob $parentJob, BatchJob $convertProfileJob) { if ($sourceFlavor && ($sourceFlavor->getOperators() || $sourceFlavor->getConversionEngines()) && $originalFlavorAsset->getInterFlowCount() == null) { KalturaLog::log("Source flavor asset requires conversion"); self::adjustAssetParams($entryId, array($sourceFlavor)); $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $errDescription = null; $sourceFlavorOutput = self::validateFlavorAndMediaInfo($sourceFlavor, $mediaInfo, $errDescription); if (!$sourceFlavorOutput) { if (!$errDescription) { $errDescription = "Failed to create flavor params output from source flavor"; } $originalFlavorAsset->setDescription($originalFlavorAsset->getDescription() . "\n{$errDescription}"); $originalFlavorAsset->setStatus(flavorAsset::ASSET_STATUS_ERROR); $originalFlavorAsset->save(); kBatchManager::updateEntry($entryId, entryStatus::ERROR_CONVERTING); kJobsManager::updateBatchJob($convertProfileJob, BatchJob::BATCHJOB_STATUS_FAILED); return false; } /* * If the conversion profile contains source flavor and the source is tagged with 'save_source' ==> * save the original source asset in another asset, in order * to prevent its liquidated by the inter-source asset. */ if (isset($sourceFlavor) && strstr($sourceFlavor->getTagsArray(), assetParams::TAG_SAVE_SOURCE) !== false) { self::saveOriginalSource($mediaInfo); } } elseif ($mediaInfo) { /* * Check whether there is a need for an intermediate source pre-processing */ $sourceFlavorOutput = KDLWrap::GenerateIntermediateSource($mediaInfo, $flavors); if (!$sourceFlavorOutput) { return true; } $srcSyncKey = $originalFlavorAsset->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET); $errDescription = null; /* * Save the original source asset in another asset, in order * to prevent its liquidated by the inter-source asset. * But, do it only if the conversion profile contains source flavor */ if (isset($sourceFlavor)) { self::saveOriginalSource($mediaInfo); } } /* * '_passthrough' controls whether the source is to be 'passthrough' although there * is a source flavor that contains transcoder settings. * Looks for a '_passthrough' flag on the source's flavor params output. */ if (!isset($sourceFlavorOutput) || $sourceFlavorOutput->_passthrough == true) { return true; } // 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"; self::setError($errDescription, $convertProfileJob, BatchJobType::CONVERT_PROFILE, $convertProfileJob->getEntryId()); 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->setStatus(flavorAsset::FLAVOR_ASSET_STATUS_CONVERTING); if (isset($sourceFlavor)) { $tagsArr = $sourceFlavor->getTagsArray(); // No need for 'save_source' tag on the inter-src asset, remove it. if (($key = array_search(assetParams::TAG_SAVE_SOURCE, $tagsArr)) !== false) { unset($tagsArr[$key]); } $originalFlavorAsset->addTags($tagsArr); $originalFlavorAsset->setFileExt($sourceFlavorOutput->getFileExt()); $originalFlavorAsset->save(); } // save flavor params $sourceFlavorOutput->setFlavorAssetVersion($originalFlavorAsset->getVersion()); $sourceFlavorOutput->save(); $mediaInfoId = null; if ($mediaInfo) { $mediaInfoId = $mediaInfo->getId(); } kJobsManager::addFlavorConvertJob(array($srcSyncKey), $sourceFlavorOutput, $originalFlavorAsset->getId(), $conversionProfileId, $mediaInfoId, $parentJob); return false; }