Skip to content

Commit

Permalink
Merge pull request #12617 from kaltura/PLAT-24606-Multi-Entry-Package…
Browse files Browse the repository at this point in the history
…r-clipping-API

Plat 24606: Multi entry packager clipping API
  • Loading branch information
zoharsKaltura committed Apr 9, 2024
2 parents dc63c97 + b54c1fc commit dbd2823
Showing 1 changed file with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,27 @@ public static function serveLiveMediaSet($durations, $sequences, $playlistStartT

return $mediaSet;
}

// if the entry has clip attributes returns the offsets and updated durations, otherwise returns zeros and original durations
protected function retrievePlaylistAttributesData($entry, $durations)
{
$offsets = array_fill(0, count($durations), 0);
if ($entry->getMediaType() == PlaylistType::STATIC_LIST && $entry->getOperationAttributes())
{
$filterClipAttributes = function($obj) { return $obj instanceof kClipAttributes; };
$clipAttributes = array_filter($entry->getOperationAttributes(), $filterClipAttributes);
for ($i = 0; $i < min(count($durations), count($clipAttributes)); $i++)
{
$offset = $clipAttributes[$i]->getOffset();
$duration = $clipAttributes[$i]->getDuration();
if ($offset >= 0 && $duration > 0 && $durations[$i] - $offset >= $duration)
{
$offsets[$i] = $offset;
$durations[$i] = $duration;
}
}
}
return array($offsets, $durations);
}
protected function servePlaylist($entry, $captionLanguages)
{
// allow only manual playlist
Expand All @@ -187,14 +207,16 @@ protected function servePlaylist($entry, $captionLanguages)
}

list($entryIds, $durations, $referenceEntry, $captionFiles) = myPlaylistUtils::executeStitchedPlaylist($entry, $captionLanguages);
list($offsets, $durations) = $this->retrievePlaylistAttributesData($entry, $durations);
$this->serveEntriesAsPlaylist($entryIds, $durations, $referenceEntry, $entry, null,
$captionFiles, $captionLanguages, $isLive, 0, 0, 0, 0);
$captionFiles, $captionLanguages, $isLive, 0, 0, 0, 0, $offsets);
}

protected function serveEntriesAsPlaylist($entryIds, $durations, $referenceEntry, $origEntry, $flavorParamIds,
$captionFiles, $captionLanguages, $isLive,
$playlistStartTime, $firstClipStartTime, $initialClipIndex, $initialSegmentIndex)
$playlistStartTime, $firstClipStartTime, $initialClipIndex, $initialSegmentIndex, $offsets=null)
{
$offsets = $offsets ? $offsets : array_fill(0, count($entryIds), 0);
// get request parameters
if (!$flavorParamIds)
{
Expand Down Expand Up @@ -242,6 +264,7 @@ protected function serveEntriesAsPlaylist($entryIds, $durations, $referenceEntry

unset($entryIds[$i]);
unset($durations[$i]);
unset($offsets[$i]);
}
$durations = array_values($durations); // if some duration was unset, this makes sure that durations will be rendered as an array in the json

Expand Down Expand Up @@ -272,7 +295,7 @@ protected function serveEntriesAsPlaylist($entryIds, $durations, $referenceEntry
$origEntryFlavor = $referenceFlavor;
// build the clips of the current sequence
$clips = array();
foreach ($entryIds as $entryId)
foreach ($entryIds as $index => $entryId)
{
if (isset($groupedFlavors[$entryId][$flavorParamsId]))
{
Expand All @@ -298,8 +321,11 @@ protected function serveEntriesAsPlaylist($entryIds, $durations, $referenceEntry
$path = '';
$storeCache = false;
}

$clips[] = self::getClipData($path, $flavor, $sourceType);
$clipData = self::getClipData($path, $flavor, $sourceType);
if ($offsets[$index]){
$clipData['clipFrom'] = $offsets[$index];
}
$clips[] = $clipData;
}
$sequences[] = array('clips' => $clips, 'id' => $this->getServeUrlForFlavor($origEntryFlavor->getId(), $origEntry->getId()));
}
Expand Down

0 comments on commit dbd2823

Please sign in to comment.