Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLAT-9262 handle thumb and volume mapped with encryption at rest #7625

Merged
merged 4 commits into from Oct 7, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -4,6 +4,7 @@ class myEntryUtils
{
const TEMP_FILE_POSTFIX = "temp_1.jpg";
const MP4_FILENAME_PARAMETER = "/name/a.mp4";
const DEFAULT_THUMB_SEC_LIVE = 1;
static private $liveSourceType = array
@@ -1007,12 +1008,36 @@ public static function captureThumbUsingPackager($entry, $capturedThumbPath, $ca
{
if (myEntryUtils::shouldServeVodFromLive($entry))
return self::captureLiveThumbUsingPackager($entry, 'recording', $capturedThumbPath, $calc_vid_sec, $width, $height);
$mappedThumbEntryTypes = array(entryType::PLAYLIST);
if(in_array($entry->getType(), $mappedThumbEntryTypes))
return self::captureMappedThumbUsingPackager($entry, $capturedThumbPath, $calc_vid_sec, $flavorAssetId, $width, $height);
$isPlayList = in_array($entry->getType(), $mappedThumbEntryTypes);
if($isPlayList)
{
$firstEntry = myPlaylistUtils::getFirstEntryFromPlaylist($entry);
if (!$firstEntry)
{
return false;
}
$flavorAsset = self::getFlavorSupportedByPackagerForThumbCapture($firstEntry->getId());
}
else
{
$flavorAsset = self::getFlavorSupportedByPackagerForThumbCapture($entry->getId());
}
if(!$flavorAsset)
{
return false;
}
return self::captureLocalThumbUsingPackager($entry, $capturedThumbPath, $calc_vid_sec, $flavorAssetId, $width, $height);
if ($isPlayList || $flavorAsset->getEncryptionKey())
{
return self::captureMappedThumbUsingPackager($entry, $flavorAsset, $capturedThumbPath, $calc_vid_sec, $flavorAssetId, $width, $height);
}
else
{
return self::captureLocalThumbUsingPackager( $flavorAsset, $capturedThumbPath, $calc_vid_sec, $flavorAssetId, $width, $height);
}
}
private static function captureLiveThumbUsingPackager(entry $entry, $liveType, $destThumbPath, $calc_vid_sec, $width = null, $height = null)
@@ -1039,17 +1064,12 @@ private static function getLiveEntryDcId($entryId, $type)
return $entryServerNode->getDCId();
}
private static function captureMappedThumbUsingPackager($entry, $capturedThumbPath, $calc_vid_sec, &$flavorAssetId, $width, $height)
private static function captureMappedThumbUsingPackager($entry, $flavorAsset, $capturedThumbPath, $calc_vid_sec, &$flavorAssetId, $width, $height)
{
$packagerCaptureUrl = kConf::get('packager_mapped_thumb_capture_url', 'local', null);
if (!$packagerCaptureUrl)
return false;
$firstEntry = myPlaylistUtils::getFirstEntryFromPlaylist($entry);
if (!$firstEntry)
return false;
$flavorAsset = self::getFlavorSupportedByPackagerForThumbCapture($firstEntry->getId());
if(!$flavorAsset)
return false;
@@ -1058,12 +1078,26 @@ private static function captureMappedThumbUsingPackager($entry, $capturedThumbPa
if(!$flavorParamsId)
return false;
$flavorUrl = myPlaylistUtils::buildPlaylistThumbPath($entry, $flavorAsset);
$flavorUrl = self::buildThumbUrl($entry, $flavorAsset);
return self::curlThumbUrlWithOffset($flavorUrl, $calc_vid_sec, $packagerCaptureUrl, $capturedThumbPath, $width, $height);
}
protected static function buildThumbUrl($entry, $flavorAsset)
{
$partnerId = $flavorAsset->getPartnerId();
$subpId = $entry->getSubpId();
$partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId);
$entryVersion = $entry->getVersion();
$url = "$partnerPath/serveFlavor/entryId/".$entry->getId();
$url .= ($entryVersion ? "/v/$entryVersion" : '');
$url .= "/flavorParamIds/" . $flavorAsset->getFlavorParamsId().self::MP4_FILENAME_PARAMETER;
return $url;
}
private static function curlThumbUrlWithOffset($url, $calc_vid_sec, $packagerCaptureUrl, $capturedThumbPath, $width = null, $height = null, $offsetPrefix = '')
{
$offset = floor($calc_vid_sec*1000);
@@ -1142,16 +1176,12 @@ public static function captureLocalThumb($entry, $capturedThumbPath, $calc_vid_s
return true;
}
public static function captureLocalThumbUsingPackager($entry, $capturedThumbPath, $calc_vid_sec, &$flavorAssetId, $width, $height)
protected static function captureLocalThumbUsingPackager($flavorAsset, $capturedThumbPath, $calc_vid_sec, &$flavorAssetId, $width, $height)
{
$packagerCaptureUrl = kConf::get('packager_local_thumb_capture_url', 'local', null);
if (!$packagerCaptureUrl)
return false;
$flavorAsset = self::getFlavorSupportedByPackagerForThumbCapture($entry->getId());
if(!$flavorAsset)
return false;
$flavorAssetId = $flavorAsset->getId();
$fileSyncKey = $flavorAsset->getSyncKey(flavorAsset::FILE_SYNC_ASSET_SUB_TYPE_ASSET);
$entry_data_path = kFileSyncUtils::getRelativeFilePathForKey($fileSyncKey);
@@ -1185,8 +1215,6 @@ private static function getFlavorSupportedByPackagerForThumbCapture($entryId)
public static function isFlavorSupportedByPackager($flavorAsset, $excludeAudioFlavors = true)
{
if($flavorAsset->getEncryptionKey())
return false;
if($excludeAudioFlavors)
{
if (!$flavorAsset->getVideoCodecId() || ($flavorAsset->getWidth() == 0) || ($flavorAsset->getHeight() == 0))
@@ -2112,7 +2140,7 @@ public static function getVolumeMapContent($flavorAsset)
$content = null;
while ($packagerRetries && !$content)
{
$content = self::retrieveLocalVolumeMapFromPackager($flavorAsset);
$content = self::retrieveVolumeMapFromPackager($flavorAsset);
$packagerRetries--;
}
if(!$content)
@@ -2122,6 +2150,39 @@ public static function getVolumeMapContent($flavorAsset)
return new kRendererString($content, 'text/csv');
}
private static function retrieveVolumeMapFromPackager($flavorAsset)
{
if ($flavorAsset->getEncryptionKey())
{
return self::retrieveMappedVolumeMapFromPackager($flavorAsset);
}
return self::retrieveLocalVolumeMapFromPackager($flavorAsset);
}
private static function retrieveMappedVolumeMapFromPackager($flavorAsset)
{
$packagerVolumeMapUrlPattern = kConf::get('packager_mapped_volume_map_url', 'local', null);
if (!$packagerVolumeMapUrlPattern)
{
throw new KalturaAPIException(KalturaErrors::VOLUME_MAP_NOT_CONFIGURED);
This conversation was marked as resolved by gotlieb

This comment has been minimized.

Copy link
@MosheMaorKaltura

MosheMaorKaltura Oct 4, 2018

Contributor

Add brackets even on single line

This comment has been minimized.

Copy link
@gotlieb

gotlieb Oct 4, 2018

Author Contributor

done

}
$entry = entryPeer::retrieveByPK($flavorAsset->getEntryId());
if (!$entry)
{
throw new KalturaAPIException(KalturaErrors::ENTRY_ID_NOT_FOUND);
}
$volumeMapUrl = self::buildVolumeMapPath($entry, $flavorAsset);
$content = self::curlVolumeMapUrl($volumeMapUrl, $packagerVolumeMapUrlPattern);
if(!$content)
{
return false;
}
return $content;
}
private static function retrieveLocalVolumeMapFromPackager($flavorAsset)
{
@@ -2135,14 +2196,14 @@ private static function retrieveLocalVolumeMapFromPackager($flavorAsset)
if (!$entry_data_path)
return null;
$content = self::curlLocalVolumeMapUrl($entry_data_path, $packagerVolumeMapUrlPattern);
$content = self::curlVolumeMapUrl($entry_data_path, $packagerVolumeMapUrlPattern);
if(!$content)
return false;
return $content;
}
private static function curlLocalVolumeMapUrl($url, $packagerVolumeMapUrlPattern)
private static function curlVolumeMapUrl($url, $packagerVolumeMapUrlPattern)
{
$packagerVolumeMapUrl = str_replace(array("{url}"), array($url), $packagerVolumeMapUrlPattern);
kFile::closeDbConnections();
@@ -2167,4 +2228,18 @@ public static function addTrackEntryInfo(entry $entry,$message)
$trackEntry->setDescription($message);
TrackEntry::addTrackEntry($trackEntry);
}
private static function buildVolumeMapPath($entry, $flavorAsset)
{
$partnerId = $flavorAsset->getPartnerId();
$subpId = $entry->getSubpId();
$partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId);
$entryVersion = $entry->getVersion();
$url = "$partnerPath/serveFlavor/entryId/".$entry->getId();
$url .= ($entryVersion ? "/v/$entryVersion" : '');
$url .= "/flavorId/".$flavorAsset->getId();
$url .= self::MP4_FILENAME_PARAMETER;
return $url;
}
}
@@ -14,7 +14,6 @@ class myPlaylistUtils
const CAPTION_FILES_LABEL = "label";
const CAPTION_FILES_PATH = "path";
const CAPTION_FILES_ID = "captionId";
const MP4_FILENAME_PARAMETER = "/name/a.mp4";
private static $user_cache = null;
@@ -1197,16 +1196,4 @@ public static function getFirstEntryFromPlaylist($playlist)
return $entryList[0];
}
public static function buildPlaylistThumbPath($entry, $flavorAsset)
{
$partnerId = $flavorAsset->getPartnerId();
$subpId = $entry->getSubpId();
$partnerPath = myPartnerUtils::getUrlForPartner($partnerId, $subpId);
$entryVersion = $entry->getVersion();
$url = "$partnerPath/serveFlavor/entryId/".$entry->getId();
$url .= ($entryVersion ? "/v/$entryVersion" : '');
$url .= "/flavorParamIds/" . $flavorAsset->getFlavorParamsId().self::MP4_FILENAME_PARAMETER;
return $url;
}
}
@@ -21,6 +21,7 @@ live_packager_secure_token = @LIVE_PACKAGER_TOKEN@
packager_local_thumb_capture_url = @VOD_PACKAGER_HOST@:@VOD_PACKAGER_PORT@/localthumb/{url}/thumb-{offset}.jpg
packager_mapped_thumb_capture_url = @VOD_PACKAGER_HOST@:@VOD_PACKAGER_PORT@/mappedthumb/{url}/thumb-{offset}.jpg
packager_local_volume_map_url = @VOD_PACKAGER_HOST@:@VOD_PACKAGER_PORT@/localvolume/{url}/volume_map.csv
packager_mapped_volume_map_url = @VOD_PACKAGER_HOST@:@VOD_PACKAGER_PORT@/mappedthumb/{url}/volume_map.csv
packager_local_live_thumb_capture_url = @VOD_PACKAGER_HOST@:@VOD_PACKAGER_PORT@/dc-{dc}/{liveType}/thumb/{url}/thumb-{offset}.jpg

;CDN URLs
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.