/**
  * Append recorded video to live entry
  * 
  * @action appendRecording
  * @param string $entryId Live entry id
  * @param string $assetId Live asset id
  * @param KalturaMediaServerIndex $mediaServerIndex
  * @param KalturaDataCenterContentResource $resource
  * @param float $duration in seconds
  * @param bool $isLastChunk Is this the last recorded chunk in the current session (i.e. following a stream stop event)
  * @return KalturaLiveEntry The updated live entry
  * 
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  */
 function appendRecordingAction($entryId, $assetId, $mediaServerIndex, KalturaDataCenterContentResource $resource, $duration, $isLastChunk = false)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry || !$dbEntry instanceof LiveEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $dbAsset = assetPeer::retrieveById($assetId);
     if (!$dbAsset || !$dbAsset instanceof liveAsset) {
         throw new KalturaAPIException(KalturaErrors::ASSET_ID_NOT_FOUND, $assetId);
     }
     $lastDuration = $dbEntry->getLengthInMsecs();
     if (!$lastDuration) {
         $lastDuration = 0;
     }
     $liveSegmentDurationInMsec = (int) ($duration * 1000);
     $currentDuration = $lastDuration + $liveSegmentDurationInMsec;
     $maxRecordingDuration = (kConf::get('max_live_recording_duration_hours') + 1) * 60 * 60 * 1000;
     if ($currentDuration > $maxRecordingDuration) {
         KalturaLog::err("Entry [{$entryId}] duration [" . $dbEntry->getLengthInMsecs() . "] and current duration [{$currentDuration}] is more than max allwoed duration [{$maxRecordingDuration}]");
         throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_EXCEEDED_MAX_RECORDED_DURATION, $entryId);
     }
     $kResource = $resource->toObject();
     $filename = $kResource->getLocalFilePath();
     if (!$resource instanceof KalturaServerFileResource) {
         $filename = kConf::get('uploaded_segment_destination') . basename($kResource->getLocalFilePath());
         kFile::moveFile($kResource->getLocalFilePath(), $filename);
         chgrp($filename, kConf::get('content_group'));
         chmod($filename, 0640);
     }
     if ($dbAsset->hasTag(assetParams::TAG_RECORDING_ANCHOR) && $mediaServerIndex == KalturaMediaServerIndex::PRIMARY) {
         KalturaLog::debug("Appending assetId {$assetId} to entryId {$entryId}");
         $dbEntry->setLengthInMsecs($currentDuration);
         // Extract the exact video segment duration from the recorded file
         $mediaInfoParser = new KMediaInfoMediaParser($filename, kConf::get('bin_path_mediainfo'));
         $recordedSegmentDurationInMsec = $mediaInfoParser->getMediaInfo()->videoDuration;
         $currentSegmentVodToLiveDeltaTime = $liveSegmentDurationInMsec - $recordedSegmentDurationInMsec;
         $recordedSegmentsInfo = $dbEntry->getRecordedSegmentsInfo();
         $recordedSegmentsInfo->addSegment($lastDuration, $recordedSegmentDurationInMsec, $currentSegmentVodToLiveDeltaTime);
         $dbEntry->setRecordedSegmentsInfo($recordedSegmentsInfo);
         if ($isLastChunk) {
             // Save last elapsed recording time
             $dbEntry->setLastElapsedRecordingTime($currentDuration);
         }
         $dbEntry->save();
     }
     kJobsManager::addConvertLiveSegmentJob(null, $dbAsset, $mediaServerIndex, $filename, $currentDuration);
     if ($mediaServerIndex == KalturaMediaServerIndex::PRIMARY) {
         if (!$dbEntry->getRecordedEntryId()) {
             $this->createRecordedEntry($dbEntry, $mediaServerIndex);
         }
         $recordedEntry = entryPeer::retrieveByPK($dbEntry->getRecordedEntryId());
         if ($recordedEntry) {
             $this->ingestAsset($recordedEntry, $dbAsset, $filename);
         }
     }
     $entry = KalturaEntryFactory::getInstanceByType($dbEntry->getType());
     $entry->fromObject($dbEntry, $this->getResponseProfile());
     return $entry;
 }
 public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     throw new KalturaAPIException(KalturaErrors::RESOURCE_TYPE_NOT_SUPPORTED, get_class($this));
     if (is_null($object_to_fill)) {
         $object_to_fill = new kConcatAttributes();
     }
     $resource = $this->resource->toObject();
     if ($resource instanceof kLocalFileResource) {
         $object_to_fill->setFilePath($resource->getLocalFilePath());
     }
     return parent::toObject($object_to_fill, $props_to_skip);
 }
 public function entryHandled(entry $dbEntry)
 {
     parent::entryHandled($dbEntry);
     $originalFlavorAsset = assetPeer::retrieveOriginalByEntryId($dbEntry->getId());
     $syncKey = $originalFlavorAsset->getSyncKey(asset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET);
     $sourceFilePath = kFileSyncUtils::getLocalFilePathForKey($syncKey);
     // call mediaInfo for file
     $dbMediaInfo = new mediaInfo();
     try {
         $mediaInfoParser = new KMediaInfoMediaParser($sourceFilePath, kConf::get('bin_path_mediainfo'));
         $mediaInfo = $mediaInfoParser->getMediaInfo();
         $dbMediaInfo = $mediaInfo->toInsertableObject($dbMediaInfo);
         $dbMediaInfo->setFlavorAssetId($originalFlavorAsset->getId());
         $dbMediaInfo->save();
     } catch (Exception $e) {
         KalturaLog::err("Getting media info: " . $e->getMessage());
         $dbMediaInfo = null;
     }
     // fix flavor asset according to mediainfo
     if ($dbMediaInfo) {
         KDLWrap::ConvertMediainfoCdl2FlavorAsset($dbMediaInfo, $originalFlavorAsset);
         $flavorTags = KDLWrap::CDLMediaInfo2Tags($dbMediaInfo, array(flavorParams::TAG_WEB, flavorParams::TAG_MBR));
         $originalFlavorAsset->setTags(implode(',', array_unique($flavorTags)));
     }
     $originalFlavorAsset->setStatusLocalReady();
     $originalFlavorAsset->save();
     $dbEntry->setStatus(entryStatus::READY);
     $dbEntry->save();
 }
 public function entryHandled(entry $dbEntry)
 {
     parent::entryHandled($dbEntry);
     $dbUploadToken = UploadTokenPeer::retrieveByPK($this->token);
     if (is_null($dbUploadToken)) {
         throw new KalturaAPIException(KalturaErrors::UPLOAD_TOKEN_NOT_FOUND);
     }
     if ($dbUploadToken->getStatus() == UploadToken::UPLOAD_TOKEN_FULL_UPLOAD) {
         kUploadTokenMgr::closeUploadTokenById($this->token);
     }
 }
 public function toObject($object_to_fill = null, $props_to_skip = array())
 {
     if (!$object_to_fill) {
         $object_to_fill = new kLocalFileResource();
     }
     $object_to_fill->setKeepOriginalFile(true);
     $ret = parent::toObject($object_to_fill, $props_to_skip);
     /* @var $ret kLocalFileResource */
     if (!file_exists($ret->getLocalFilePath())) {
         throw new KalturaAPIException(KalturaErrors::LOCAL_FILE_NOT_FOUND, $ret->getLocalFilePath());
     }
     return $ret;
 }
 public function validateForUsage($sourceObject, $propertiesToSkip = array())
 {
     parent::validateForUsage($sourceObject, $propertiesToSkip);
     $this->validatePropertyNotNull('fileData');
 }
Example #7
0
 /**
  * Append recorded video to live entry
  * 
  * @param string $entryId Live entry id
  * @param int $mediaServerIndex 
  * @param KalturaDataCenterContentResource $resource 
  * @param float $duration 
  * @return KalturaLiveEntry
  */
 function appendRecording($entryId, $mediaServerIndex, KalturaDataCenterContentResource $resource, $duration)
 {
     $kparams = array();
     $this->client->addParam($kparams, "entryId", $entryId);
     $this->client->addParam($kparams, "mediaServerIndex", $mediaServerIndex);
     $this->client->addParam($kparams, "resource", $resource->toParams());
     $this->client->addParam($kparams, "duration", $duration);
     $this->client->queueServiceActionCall("livestream", "appendRecording", $kparams);
     if ($this->client->isMultiRequest()) {
         return $this->client->getMultiRequestResult();
     }
     $resultObject = $this->client->doQueue();
     $this->client->throwExceptionIfError($resultObject);
     $this->client->validateObjectType($resultObject, "KalturaLiveEntry");
     return $resultObject;
 }
 /**
  * Append recorded video to live entry
  *
  * @action appendRecording
  * @param string $entryId Live entry id
  * @param string $assetId Live asset id
  * @param KalturaMediaServerIndex $mediaServerIndex
  * @param KalturaDataCenterContentResource $resource
  * @param float $duration in seconds
  * @param bool $isLastChunk Is this the last recorded chunk in the current session (i.e. following a stream stop event)
  * @return KalturaLiveEntry The updated live entry
  *
  * @throws KalturaErrors::ENTRY_ID_NOT_FOUND
  */
 function appendRecordingAction($entryId, $assetId, $mediaServerIndex, KalturaDataCenterContentResource $resource, $duration, $isLastChunk = false)
 {
     $dbEntry = entryPeer::retrieveByPK($entryId);
     if (!$dbEntry || !$dbEntry instanceof LiveEntry) {
         throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND, $entryId);
     }
     $dbAsset = assetPeer::retrieveById($assetId);
     if (!$dbAsset || !$dbAsset instanceof liveAsset) {
         throw new KalturaAPIException(KalturaErrors::ASSET_ID_NOT_FOUND, $assetId);
     }
     $lastDuration = 0;
     $recordedEntry = null;
     if ($dbEntry->getRecordedEntryId()) {
         $recordedEntry = entryPeer::retrieveByPK($dbEntry->getRecordedEntryId());
         if ($recordedEntry) {
             if ($recordedEntry->getReachedMaxRecordingDuration()) {
                 KalturaLog::err("Entry [{$entryId}] has already reached its maximal recording duration.");
                 throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_EXCEEDED_MAX_RECORDED_DURATION, $entryId);
             }
             // if entry is in replacement, the replacement duration is more accurate
             if ($recordedEntry->getReplacedEntryId()) {
                 $replacementRecordedEntry = entryPeer::retrieveByPK($recordedEntry->getReplacedEntryId());
                 if ($replacementRecordedEntry) {
                     $lastDuration = $replacementRecordedEntry->getLengthInMsecs();
                 }
             } else {
                 $lastDuration = $recordedEntry->getLengthInMsecs();
             }
         }
     }
     $liveSegmentDurationInMsec = (int) ($duration * 1000);
     $currentDuration = $lastDuration + $liveSegmentDurationInMsec;
     $maxRecordingDuration = (kConf::get('max_live_recording_duration_hours') + 1) * 60 * 60 * 1000;
     if ($currentDuration > $maxRecordingDuration) {
         if ($recordedEntry) {
             $recordedEntry->setReachedMaxRecordingDuration(true);
             $recordedEntry->save();
         }
         KalturaLog::err("Entry [{$entryId}] duration [" . $lastDuration . "] and current duration [{$currentDuration}] is more than max allwoed duration [{$maxRecordingDuration}]");
         throw new KalturaAPIException(KalturaErrors::LIVE_STREAM_EXCEEDED_MAX_RECORDED_DURATION, $entryId);
     }
     $kResource = $resource->toObject();
     $filename = $kResource->getLocalFilePath();
     if (!$resource instanceof KalturaServerFileResource) {
         $filename = kConf::get('uploaded_segment_destination') . basename($kResource->getLocalFilePath());
         kFile::moveFile($kResource->getLocalFilePath(), $filename);
         chgrp($filename, kConf::get('content_group'));
         chmod($filename, 0640);
     }
     if ($dbAsset->hasTag(assetParams::TAG_RECORDING_ANCHOR) && $mediaServerIndex == KalturaMediaServerIndex::PRIMARY) {
         $dbEntry->setLengthInMsecs($currentDuration);
         if ($isLastChunk) {
             // Save last elapsed recording time
             $dbEntry->setLastElapsedRecordingTime($currentDuration);
         }
         $dbEntry->save();
     }
     kJobsManager::addConvertLiveSegmentJob(null, $dbAsset, $mediaServerIndex, $filename, $currentDuration);
     if ($mediaServerIndex == KalturaMediaServerIndex::PRIMARY) {
         if (!$dbEntry->getRecordedEntryId()) {
             $this->createRecordedEntry($dbEntry, $mediaServerIndex);
         }
         $recordedEntry = entryPeer::retrieveByPK($dbEntry->getRecordedEntryId());
         if ($recordedEntry) {
             $this->ingestAsset($recordedEntry, $dbAsset, $filename);
         }
     }
     $entry = KalturaEntryFactory::getInstanceByType($dbEntry->getType());
     $entry->fromObject($dbEntry, $this->getResponseProfile());
     return $entry;
 }
 public function entryHandled(entry $dbEntry)
 {
     parent::entryHandled($dbEntry);
     $dropFolderFile = DropFolderFilePeer::retrieveByPK($this->dropFolderFileId);
     if (is_null($dropFolderFile)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $this->dropFolderFileId);
     }
     if ($dropFolderFile->getStatus() != DropFolderFileStatus::DOWNLOADING) {
         $dropFolderFile->setStatus(DropFolderFileStatus::HANDLED);
         $dropFolderFile->save();
     }
 }
 public function validateEntry(entry $dbEntry)
 {
     parent::validateEntry($dbEntry);
     $this->validatePropertyNotNull('fileData');
 }
 public function entryHandled(entry $dbEntry)
 {
     parent::entryHandled($dbEntry);
     $dropFolderFile = DropFolderFilePeer::retrieveByPK($this->dropFolderFileId);
     if (is_null($dropFolderFile)) {
         throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $this->dropFolderFileId);
     }
     if ($dropFolderFile->getStatus() != DropFolderFileStatus::DOWNLOADING) {
         $dropFolder = DropFolderPeer::retrieveByPK($dropFolderFile->getDropFolderId());
         if (!$dropFolder) {
             throw new KalturaAPIException(KalturaErrors::INVALID_OBJECT_ID, $dropFolderFile->getDropFolderId());
         }
         if ($dropFolder->getFileDeletePolicy() == DropFolderFileDeletePolicy::AUTO_DELETE && $dropFolder->getAutoFileDeleteDays() == 0) {
             $dropFolderFile->setStatus(DropFolderFileStatus::PURGED);
         } else {
             $dropFolderFile->setStatus(DropFolderFileStatus::HANDLED);
         }
     }
     $dropFolderFile->setEntryId($dbEntry->getId());
     $dropFolderFile->save();
 }