Exemplo n.º 1
0
 private function getAssetDataFilesArray(kConvertLiveSegmentJobData $data)
 {
     $amfFilesDir = dirname($data->getDestDataFilePath());
     $pattern = "/{$data->getEntryId()}_{$data->getAssetId()}_{$data->getMediaServerIndex()}_[0-9]*.data/";
     $files = kFile::recursiveDirList($amfFilesDir, true, false, $pattern);
     natsort($files);
     return $files;
 }
Exemplo n.º 2
0
 /**
  * @param BatchJob $parentJob
  * @param liveAsset $asset
  * @param int $mediaServerIndex
  * @param string $filePath
  * @param float $endTime
  */
 public static function addConvertLiveSegmentJob(BatchJob $parentJob = null, liveAsset $asset, $mediaServerIndex, $filePath, $endTime)
 {
     $keyType = liveAsset::FILE_SYNC_ASSET_SUB_TYPE_LIVE_PRIMARY;
     if ($mediaServerIndex == MediaServerIndex::SECONDARY) {
         $keyType = liveAsset::FILE_SYNC_ASSET_SUB_TYPE_LIVE_SECONDARY;
     }
     $key = $asset->getSyncKey($keyType);
     $files = array();
     if (kFileSyncUtils::fileSync_exists($key)) {
         $files = kFileSyncUtils::dir_get_files($key, false);
     }
     $jobData = new kConvertLiveSegmentJobData();
     $jobData->setEntryId($asset->getEntryId());
     $jobData->setAssetId($asset->getId());
     $jobData->setMediaServerIndex($mediaServerIndex);
     $jobData->setEndTime($endTime);
     $jobData->setSrcFilePath($filePath);
     $jobData->setFileIndex(count($files));
     $batchJob = null;
     if ($parentJob) {
         $batchJob = $parentJob->createChild(BatchJobType::CONVERT_LIVE_SEGMENT);
     } else {
         $batchJob = new BatchJob();
         $batchJob->setEntryId($asset->getEntryId());
         $batchJob->setPartnerId($asset->getPartnerId());
     }
     $batchJob->setObjectId($asset->getEntryId());
     $batchJob->setObjectType(BatchJobObjectType::ENTRY);
     return self::addJob($batchJob, $jobData, BatchJobType::CONVERT_LIVE_SEGMENT);
 }
Exemplo n.º 3
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kConvertLiveSegmentJobData $data
  * @return BatchJob
  */
 public static function handleConvertLiveSegmentFinished(BatchJob $dbBatchJob, kConvertLiveSegmentJobData $data)
 {
     $liveEntry = entryPeer::retrieveByPKNoFilter($dbBatchJob->getEntryId());
     /* @var $liveEntry LiveEntry */
     if (!$liveEntry) {
         KalturaLog::err("Live entry [" . $dbBatchJob->getEntryId() . "] not found");
         return $dbBatchJob;
     }
     $recordedEntry = entryPeer::retrieveByPKNoFilter($liveEntry->getRecordedEntryId());
     if (!$recordedEntry) {
         KalturaLog::err("Recorded entry [" . $liveEntry->getRecordedEntryId() . "] not found");
         return $dbBatchJob;
     }
     $asset = assetPeer::retrieveByIdNoFilter($data->getAssetId());
     /* @var $asset liveAsset */
     if (!$asset) {
         KalturaLog::err("Live asset [" . $data->getAssetId() . "] not found");
         return $dbBatchJob;
     }
     $keyType = liveAsset::FILE_SYNC_ASSET_SUB_TYPE_LIVE_PRIMARY;
     if ($data->getMediaServerIndex() == MediaServerIndex::SECONDARY) {
         $keyType = liveAsset::FILE_SYNC_ASSET_SUB_TYPE_LIVE_SECONDARY;
     }
     $key = $asset->getSyncKey($keyType);
     $baseName = $asset->getEntryId() . '_' . $asset->getId() . '.ts';
     kFileSyncUtils::moveFromFileToDirectory($key, $data->getDestFilePath(), $baseName);
     if ($data->getMediaServerIndex() == MediaServerIndex::SECONDARY) {
         return $dbBatchJob;
     }
     $files = kFileSyncUtils::dir_get_files($key, false);
     if (count($files) > 1) {
         // find replacing entry id
         $replacingEntry = kFlowHelper::getReplacingEntry($recordedEntry, $asset);
         if (is_null($replacingEntry)) {
             KalturaLog::err('Failed to retrieve replacing entry');
             return $dbBatchJob;
         }
         $flavorParams = assetParamsPeer::retrieveByPKNoFilter($asset->getFlavorParamsId());
         if (is_null($flavorParams)) {
             KalturaLog::err('Failed to retrieve asset params');
             return $dbBatchJob;
         }
         // create asset
         $replacingAsset = assetPeer::getNewAsset(assetType::FLAVOR);
         $replacingAsset->setPartnerId($replacingEntry->getPartnerId());
         $replacingAsset->setEntryId($replacingEntry->getId());
         $replacingAsset->setStatus(asset::FLAVOR_ASSET_STATUS_QUEUED);
         $replacingAsset->setFlavorParamsId($flavorParams->getId());
         $replacingAsset->setFromAssetParams($flavorParams);
         if ($flavorParams->hasTag(assetParams::TAG_SOURCE)) {
             $replacingAsset->setIsOriginal(true);
         }
         $replacingAsset->save();
         $job = kJobsManager::addConcatJob($dbBatchJob, $replacingAsset, $files);
     }
     return $dbBatchJob;
 }
Exemplo n.º 4
0
 /**
  * @param BatchJob $dbBatchJob
  * @param kConvertLiveSegmentJobData $data
  * @return BatchJob
  */
 public static function handleConvertLiveSegmentFinished(BatchJob $dbBatchJob, kConvertLiveSegmentJobData $data)
 {
     $liveEntry = entryPeer::retrieveByPKNoFilter($dbBatchJob->getEntryId());
     /* @var $liveEntry LiveEntry */
     if (!$liveEntry) {
         KalturaLog::err("Live entry [" . $dbBatchJob->getEntryId() . "] not found");
         return $dbBatchJob;
     }
     $recordedEntry = entryPeer::retrieveByPKNoFilter($liveEntry->getRecordedEntryId());
     if (!$recordedEntry) {
         KalturaLog::err("Recorded entry [" . $liveEntry->getRecordedEntryId() . "] not found");
         return $dbBatchJob;
     }
     $asset = assetPeer::retrieveByIdNoFilter($data->getAssetId());
     /* @var $asset liveAsset */
     if (!$asset) {
         KalturaLog::err("Live asset [" . $data->getAssetId() . "] not found");
         return $dbBatchJob;
     }
     $keyType = liveAsset::FILE_SYNC_ASSET_SUB_TYPE_LIVE_PRIMARY;
     if ($data->getMediaServerIndex() == MediaServerIndex::SECONDARY) {
         $keyType = liveAsset::FILE_SYNC_ASSET_SUB_TYPE_LIVE_SECONDARY;
     }
     $key = $asset->getSyncKey($keyType);
     $baseName = $asset->getEntryId() . '_' . $asset->getId() . '.ts';
     kFileSyncUtils::moveFromFileToDirectory($key, $data->getDestFilePath(), $baseName);
     if ($data->getMediaServerIndex() == MediaServerIndex::SECONDARY) {
         return $dbBatchJob;
     }
     $files = kFileSyncUtils::dir_get_files($key, false);
     // If we have less files on disk than what we should have it means the output file will be missing segments.
     // don't generate it, and the next concat will do the work for us.
     if (count($files) != $data->getFileIndex() + 1) {
         KalturaLog::warning('number of segments on disk ' . count($files) . ' is not equal to segment index ' . $data->getFileIndex() . ' - not running the concat job');
         return $dbBatchJob;
     }
     if (count($files) > 1) {
         // find replacing entry id
         $replacingEntry = self::getReplacingEntry($recordedEntry, $asset);
         if (is_null($replacingEntry)) {
             KalturaLog::err("Failed to get replacing entry");
         }
         $flavorParams = assetParamsPeer::retrieveByPKNoFilter($asset->getFlavorParamsId());
         if (is_null($flavorParams)) {
             KalturaLog::err('Failed to retrieve asset params');
             return $dbBatchJob;
         }
         // create asset
         $replacingAsset = assetPeer::getNewAsset(assetType::FLAVOR);
         $replacingAsset->setPartnerId($replacingEntry->getPartnerId());
         $replacingAsset->setEntryId($replacingEntry->getId());
         $replacingAsset->setStatus(asset::FLAVOR_ASSET_STATUS_QUEUED);
         $replacingAsset->setFlavorParamsId($flavorParams->getId());
         $replacingAsset->setFromAssetParams($flavorParams);
         if ($flavorParams->hasTag(assetParams::TAG_SOURCE)) {
             $replacingAsset->setIsOriginal(true);
         }
         $replacingAsset->save();
         $job = kJobsManager::addConcatJob($dbBatchJob, $replacingAsset, $files);
     }
     return $dbBatchJob;
 }