Exemplo n.º 1
0
 /**
  * @param string $vodEntryId
  */
 public static function copyCuePointsFromLiveToVodEntry($vodEntryId, $totalVODDuration, $lastSegmentDuration, $amfArray)
 {
     KalturaLog::debug("VOD entry ID: " . $vodEntryId . " totalVODDuration: " . $totalVODDuration . " lastSegmentDuration " . $lastSegmentDuration . " AMFs: " . print_r($amfArray, true));
     if (is_null($vodEntryId) || is_null($totalVODDuration) || is_null($lastSegmentDuration) || is_null($amfArray) || count($amfArray) == 0) {
         KalturaLog::warning('bad arguments passed to function. quiting');
         return;
     }
     $vodEntry = entryPeer::retrieveByPK($vodEntryId);
     if (!$vodEntry) {
         return;
     }
     $liveEntryId = $vodEntry->getRootEntryId();
     /** @var $liveEntry KalturaLiveEntry */
     $liveEntry = entryPeer::retrieveByPK($liveEntryId);
     if (!$liveEntry || !$liveEntry instanceof LiveEntry) {
         KalturaLog::err("Can't find live entry with id [{$liveEntryId}]");
         return;
     }
     $currentSegmentEndTime = self::getSegmentEndTime($amfArray, $lastSegmentDuration);
     $currentSegmentStartTime = self::getSegmentStartTime($amfArray);
     self::normalizeAMFTimes($amfArray, $totalVODDuration, $lastSegmentDuration);
     KalturaLog::log("Saving the live entry [{$liveEntry->getId()}] cue points into the associated VOD entry [{$vodEntry->getId()}]");
     // select up to MAX_CUE_POINTS_TO_COPY_TO_VOD to handle
     $c = new KalturaCriteria();
     $c->add(CuePointPeer::ENTRY_ID, $liveEntry->getId());
     $c->add(CuePointPeer::CREATED_AT, $currentSegmentEndTime, KalturaCriteria::LESS_EQUAL);
     // Don't copy future cuepoints
     $c->addAnd(CuePointPeer::CREATED_AT, $currentSegmentStartTime - self::CUE_POINT_TIME_EPSILON, KalturaCriteria::GREATER_EQUAL);
     // Don't copy cuepoints before segment begining
     $c->add(CuePointPeer::STATUS, CuePointStatus::READY);
     // READY, but not yet HANDLED
     $c->addAscendingOrderByColumn(CuePointPeer::CREATED_AT);
     $c->setLimit(self::MAX_CUE_POINTS_TO_COPY_TO_VOD);
     $liveCuePointsToCopy = CuePointPeer::doSelect($c);
     $numLiveCuePointsToCopy = count($liveCuePointsToCopy);
     KalturaLog::info("About to copy {$numLiveCuePointsToCopy} cuepoints from live entry [{$liveEntry->getId()}] to VOD entry [{$vodEntry->getId()}]");
     $processedCuePointIds = array();
     if ($numLiveCuePointsToCopy > 0) {
         foreach ($liveCuePointsToCopy as $liveCuePoint) {
             $processedCuePointIds[] = $liveCuePoint->getId();
             $cuePointCreationTime = $liveCuePoint->getCreatedAt(NULL) * 1000;
             $offsetForTS = self::getOffsetForTimestamp($cuePointCreationTime, $amfArray);
             $copyMsg = "cuepoint [{$liveCuePoint->getId()}] from live entry [{$liveEntry->getId()}] to VOD entry [{$vodEntry->getId()}] cuePointCreationTime= {$cuePointCreationTime} offsetForTS= {$offsetForTS}";
             KalturaLog::debug("Preparing to copy {$copyMsg}");
             if (!is_null($offsetForTS)) {
                 $liveCuePoint->copyFromLiveToVodEntry($vodEntry, $offsetForTS);
             } else {
                 KalturaLog::info("Not copying {$copyMsg}");
             }
         }
     }
     KalturaLog::info("Post processing cuePointIds for live entry [{$liveEntry->getId()}]: " . print_r($processedCuePointIds, true));
     if (count($processedCuePointIds)) {
         self::postProcessCuePoints($liveEntry, $processedCuePointIds);
     }
 }
Exemplo n.º 2
0
 /**
  * @param entry $vodEntry
  */
 public static function copyCuePointsFromLiveToVodEntry($mediaInfo)
 {
     $vodEntry = self::getVodEntryBasedOnMediaInfoFlavorAsset($mediaInfo);
     if (!$vodEntry) {
         return;
     }
     $liveEntryId = $vodEntry->getRootEntryId();
     /** @var $liveEntry KalturaLiveEntry */
     $liveEntry = entryPeer::retrieveByPK($liveEntryId);
     if (!$liveEntry || !$liveEntry instanceof LiveEntry) {
         KalturaLog::err("Can't find live entry with id [{$liveEntryId}]");
         return;
     }
     KalturaLog::log("Saving the live entry [{$liveEntry->getId()}] cue points into the associated VOD entry [{$vodEntry->getId()}]");
     // select up to MAX_CUE_POINTS_TO_COPY_TO_VOD to handle
     $c = new KalturaCriteria();
     $c->add(CuePointPeer::ENTRY_ID, $liveEntry->getId());
     $c->add(CuePointPeer::START_TIME, $liveEntry->getLengthInMsecs(), KalturaCriteria::LESS_EQUAL);
     // Don't copy future cuepoints
     $c->add(CuePointPeer::STATUS, CuePointStatus::READY);
     // READY, but not yet HANDLED
     $c->addAscendingOrderByColumn(CuePointPeer::START_TIME);
     $c->setLimit(self::MAX_CUE_POINTS_TO_COPY_TO_VOD);
     $liveCuePointsToCopy = CuePointPeer::doSelect($c);
     $numLiveCuePointsToCopy = count($liveCuePointsToCopy);
     KalturaLog::info("About to copy {$numLiveCuePointsToCopy} cuepoints from live entry [{$liveEntry->getId()}] to VOD entry [{$vodEntry->getId()}]");
     $processedCuePointIds = array();
     if ($numLiveCuePointsToCopy > 0) {
         $recordedSegmentsInfo = $liveEntry->getRecordedSegmentsInfo();
         foreach ($liveCuePointsToCopy as $liveCuePoint) {
             $processedCuePointIds[] = $liveCuePoint->getId();
             $startTime = $liveCuePoint->getStartTime();
             $copyMsg = "cuepoint [{$liveCuePoint->getId()}] from live entry [{$liveEntry->getId()}] to VOD entry [{$vodEntry->getId()}] with startTime [{$startTime}]";
             KalturaLog::info("Preparing to copy {$copyMsg}");
             $totalVodOffsetTime = $recordedSegmentsInfo->getTotalVodTimeOffset($startTime);
             if (!is_null($totalVodOffsetTime)) {
                 $adjustedStartTime = $startTime - $totalVodOffsetTime;
                 KalturaLog::info("Copying {$copyMsg} and adjustedStartTime [{$adjustedStartTime}] (totalVodOffsetTime [{$totalVodOffsetTime}])");
                 $liveCuePoint->copyFromLiveToVodEntry($vodEntry, $adjustedStartTime);
             } else {
                 KalturaLog::info("Not copying {$copyMsg}");
             }
         }
     }
     KalturaLog::info("Post processing cuePointIds for live entry [{$liveEntry->getId()}]: " . print_r($processedCuePointIds, true));
     if (count($processedCuePointIds)) {
         self::postProcessCuePoints($liveEntry, $processedCuePointIds);
     }
 }