/**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      mediaInfo $value A mediaInfo object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(mediaInfo $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
 /**
  * batch validateConversionProfile validates profile completion rules 
  * 
  * @param mediaInfo $mediaInfo
  * @param array $flavors is array of flavorParams
  * @param string $errDescription
  * @return array of flavorParamsOutput
  */
 protected static function validateConversionProfile($partnerId, $entryId, mediaInfo $mediaInfo = null, array $flavors, array $conversionProfileFlavorParams, &$errDescription)
 {
     // if there is no media info, the entire profile returned as is, decision layer ignored
     if (!$mediaInfo) {
         KalturaLog::log("Validate Conversion Profile, no media info supplied");
         //			$ret = array();
         //			foreach($flavors as $flavor)
         //			{
         //				$outFlavor = new flavorParamsOutputWrap();
         //				$ret[] = flavorParamsOutputPeer::doCopy($flavor, $outFlavor);
         //			}
         //			return $ret;
     } else {
         KalturaLog::log("Validate Conversion Profile, media info [" . $mediaInfo->getId() . "]");
     }
     // call the decision layer
     KalturaLog::log("Generate Target " . count($flavors) . " Flavors supplied");
     $cdl = KDLWrap::CDLGenerateTargetFlavors($mediaInfo, $flavors);
     KalturaLog::log("Generate Target " . count($cdl->_targetList) . " Flavors returned");
     // check for errors
     $errDescription = '';
     if (count($cdl->_errors)) {
         $errDesc = '';
         foreach ($cdl->_errors as $section => $errors) {
             $errDesc .= "{$section} errors: " . join(";", $errors) . "\n";
         }
         KalturaLog::log("Decision layer input errors: {$errDesc}");
         $errDescription .= "\nMedia err: {$errDesc}";
     }
     // check for warnings
     if (count($cdl->_warnings)) {
         $errDesc = '';
         foreach ($cdl->_warnings as $section => $errors) {
             $errDesc .= "{$section} warnings: " . join(";", $errors) . "\n";
         }
         KalturaLog::log("Decision layer input warnings: {$errDesc}");
         $errDescription .= "\nMedia warn: {$errDesc}";
     }
     // rv - returned value from the decision layer
     if (!$cdl->_rv) {
         KalturaLog::log("Decision layer returned false");
         return null;
     }
     // orgenizing the flavors by the tags
     $tagedFlavors = array();
     $hasInvalidRequired = false;
     foreach ($cdl->_targetList as $flavor) {
         // overwrite ready behavior from the conversion profile
         $flavorParamsConversionProfile = $conversionProfileFlavorParams[$flavor->getFlavorParamsId()];
         $flavor->_force = $flavorParamsConversionProfile->getForceNoneComplied();
         if ($flavorParamsConversionProfile->getReadyBehavior() != flavorParamsConversionProfile::READY_BEHAVIOR_INHERIT_FLAVOR_PARAMS) {
             $flavor->setReadyBehavior($flavorParamsConversionProfile->getReadyBehavior());
         }
         if (!$flavor->IsValid()) {
             KalturaLog::log("Flavor [" . $flavor->getFlavorParamsId() . "] is invalid");
             // if required - failing the profile
             if ($flavor->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
                 $errDescription = "Business decision layer, required flavor not valid: " . $flavor->getId();
                 $errDescription .= kBusinessConvertDL::parseFlavorDescription($flavor);
                 KalturaLog::log($errDescription);
                 kBatchManager::createErrorFlavorAsset($flavor, $partnerId, $entryId, $errDescription);
                 $hasInvalidRequired = true;
                 continue;
             }
         }
         // if required - failing the profile
         if ($flavor->_isNonComply) {
             KalturaLog::log("Flavor [" . $flavor->getFlavorParamsId() . "] is none complied");
             if ($flavor->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
                 $errDescription = "Business decision layer, required flavor none complied: id[" . $flavor->getId() . "] flavor params id [" . $flavor->getFlavorParamsId() . "]";
                 $errDescription .= kBusinessConvertDL::parseFlavorDescription($flavor);
                 KalturaLog::log($errDescription);
                 kBatchManager::createErrorFlavorAsset($flavor, $partnerId, $entryId, $errDescription);
                 $hasInvalidRequired = true;
                 continue;
             }
         }
         foreach ($flavor->getTagsArray() as $tag) {
             KalturaLog::log("Taged [{$tag}] flavor added [" . $flavor->getFlavorParamsId() . "]");
             $tagedFlavors[$tag][$flavor->getFlavorParamsId()] = $flavor;
         }
     }
     if ($hasInvalidRequired) {
         return null;
     }
     // filter out all not forced, none complied, and invalid flavors
     $finalTagedFlavors = array();
     foreach ($tagedFlavors as $tag => $tagedFlavorsArray) {
         KalturaLog::log("Filtering flavors by tag [{$tag}]");
         $finalTagedFlavors[$tag] = kBusinessConvertDL::filterTagFlavors($tagedFlavorsArray);
     }
     $finalFlavors = array();
     foreach ($finalTagedFlavors as $tag => $tagedFlavorsArray) {
         foreach ($tagedFlavorsArray as $flavorParamsId => $tagedFlavor) {
             $finalFlavors[$flavorParamsId] = $tagedFlavor;
         }
     }
     // sort the flavors to decide which one will be performed first
     usort($finalFlavors, array('kBusinessConvertDL', 'compareFlavors'));
     KalturaLog::log(count($finalFlavors) . " flavors sorted for execution");
     return $finalFlavors;
 }
 /**
  * batch validateConversionProfile validates profile completion rules
  *
  * @param mediaInfo $mediaInfo
  * @param array $flavors is array of flavorParams
  * @param string $errDescription
  * @return array of flavorParamsOutput
  */
 protected static function validateConversionProfile($partnerId, $entryId, mediaInfo $mediaInfo = null, array $flavors, array $conversionProfileFlavorParams, &$errDescription)
 {
     // if there is no media info, the entire profile returned as is, decision layer ignored
     if (!$mediaInfo) {
         KalturaLog::log("Validate Conversion Profile, no media info supplied");
         //			$ret = array();
         //			foreach($flavors as $flavor)
         //			{
         //				$outFlavor = new flavorParamsOutputWrap();
         //				$ret[] = flavorParamsOutputPeer::doCopy($flavor, $outFlavor);
         //			}
         //			return $ret;
     } else {
         KalturaLog::log("Validate Conversion Profile, media info [" . $mediaInfo->getId() . "]");
     }
     self::adjustAssetParams($entryId, $flavors);
     // call the decision layer
     KalturaLog::log("Generate Target " . count($flavors) . " Flavors supplied");
     $cdl = KDLWrap::CDLGenerateTargetFlavors($mediaInfo, $flavors);
     KalturaLog::log("Generate Target " . count($cdl->_targetList) . " Flavors returned");
     // check for errors
     $errDescription = '';
     if (count($cdl->_errors)) {
         $errDesc = '';
         foreach ($cdl->_errors as $section => $errors) {
             $errDesc .= "{$section} errors: " . join(";", $errors) . "\n";
             foreach ($errors as $error) {
                 if (strpos($error, 'Invalid File - No media content' !== false)) {
                     $errDescription .= "\nMedia err: {$errDesc}";
                     KalturaLog::err($error);
                     throw new kCoreException($error, KDLErrors::NoValidMediaStream);
                 }
                 if (strpos($error, 'Invalid frame dimensions') !== false) {
                     $errDescription .= "\nMedia err: {$errDesc}";
                     KalturaLog::err($error);
                     throw new kCoreException($error, KDLErrors::SanityInvalidFrameDim);
                 }
             }
         }
         KalturaLog::log("Decision layer input errors: {$errDesc}");
         $errDescription .= "\nMedia err: {$errDesc}";
     }
     // check for warnings
     if (count($cdl->_warnings)) {
         $errDesc = '';
         foreach ($cdl->_warnings as $section => $errors) {
             $errDesc .= "{$section} warnings: " . join(";", $errors) . "\n";
         }
         KalturaLog::log("Decision layer input warnings: {$errDesc}");
         $errDescription .= "\nMedia warn: {$errDesc}";
     }
     // rv - returned value from the decision layer
     if (!$cdl->_rv) {
         KalturaLog::log("Decision layer returned false");
         return null;
     }
     // orgenizing the flavors by the tags
     $tagedFlavors = array();
     $hasInvalidRequired = false;
     foreach ($cdl->_targetList as $flavor) {
         // Get conv.prof data for that flavor
         $flavorParamsConversionProfile = $conversionProfileFlavorParams[$flavor->getFlavorParamsId()];
         // Update force-transcode flag.
         // This flag might be set by the DL, therefore overide only if it is not set.
         if (!$flavor->_force) {
             $flavor->_force = $flavorParamsConversionProfile->getForceNoneComplied();
         }
         $flavor->setReadyBehavior($flavorParamsConversionProfile->getReadyBehavior());
         if (!$flavor->IsValid()) {
             KalturaLog::log("Flavor [" . $flavor->getFlavorParamsId() . "] is invalid");
             // if required - failing the profile
             if ($flavor->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED) {
                 $errDescription = "Business decision layer, required flavor not valid: " . $flavor->getId();
                 $errDescription .= kBusinessConvertDL::parseFlavorDescription($flavor);
                 KalturaLog::log($errDescription);
                 kBatchManager::createErrorFlavorAsset($flavor, $partnerId, $entryId, $errDescription);
                 $hasInvalidRequired = true;
                 continue;
             }
         }
         // if required - failing the profile
         if ($flavor->_isNonComply) {
             KalturaLog::log("Flavor [" . $flavor->getFlavorParamsId() . "] is none complied");
             // If the flavor is set to 'force' (generate the asset regardless of any Kaltura optimization),
             // don't fail it even if it is 'NonComply'
             if ($flavor->getReadyBehavior() == flavorParamsConversionProfile::READY_BEHAVIOR_REQUIRED && !$flavor->_force) {
                 $errDescription = "Business decision layer, required flavor none complied: id[" . $flavor->getId() . "] flavor params id [" . $flavor->getFlavorParamsId() . "]";
                 $errDescription .= kBusinessConvertDL::parseFlavorDescription($flavor);
                 KalturaLog::log($errDescription);
                 kBatchManager::createErrorFlavorAsset($flavor, $partnerId, $entryId, $errDescription);
                 $hasInvalidRequired = true;
                 continue;
             }
         }
         foreach ($flavor->getTagsArray() as $tag) {
             KalturaLog::log("Taged [{$tag}] flavor added [" . $flavor->getFlavorParamsId() . "]");
             $tagedFlavors[$tag][$flavor->getFlavorParamsId()] = $flavor;
         }
     }
     if ($hasInvalidRequired) {
         return null;
     }
     /*
      * For 'playset' collections (MBR & ISM) make sure that the flavor that
      * matches in the best way the source framee size, will be generated.
      * Optimally this procedure should be executed for EVERY tag. But this
      * might cause generation of unrequired flavors that might potentially
      * harm the entry playback.
      * Furthermore - we have duplicate iOS tagging (iphonenew and ipadnew),
      * therefore anyhow at least one ipad flavor will be always generated.
      * The other tags are less relevant for the framesize adjustment cases.
      */
     if (isset($mediaInfo)) {
         if (array_key_exists(flavorParams::TAG_MBR, $tagedFlavors)) {
             self::adjustToFramesize($mediaInfo, $tagedFlavors[flavorParams::TAG_MBR]);
         }
         if (array_key_exists(flavorParams::TAG_ISM, $tagedFlavors)) {
             self::adjustToFramesize($mediaInfo, $tagedFlavors[flavorParams::TAG_ISM]);
         }
     }
     // filter out all not forced, none complied, and invalid flavors
     $finalTagedFlavors = array();
     foreach ($tagedFlavors as $tag => $tagedFlavorsArray) {
         KalturaLog::log("Filtering flavors by tag [{$tag}]");
         /*
          * Digital-watermark tags should not participate in the 'tagged' flavor activation logic 
          */
         if (strstr($tag, "watermark_pair_") == false && strstr($tag, self::TAG_VARIANT_A) == false && strstr($tag, self::TAG_VARIANT_B) == false) {
             $finalTagedFlavors[$tag] = kBusinessConvertDL::filterTagFlavors($tagedFlavorsArray);
         } else {
             $finalTagedFlavors[$tag] = $tagedFlavorsArray;
         }
     }
     $finalFlavors = array();
     foreach ($finalTagedFlavors as $tag => $tagedFlavorsArray) {
         foreach ($tagedFlavorsArray as $flavorParamsId => $tagedFlavor) {
             $finalFlavors[$flavorParamsId] = $tagedFlavor;
         }
     }
     /*
      * Digital-watermark flavors go through 'find the matching pair' procedure
      */
     if (array_key_exists(self::TAG_VARIANT_A, $finalTagedFlavors) && array_key_exists(self::TAG_VARIANT_B, $finalTagedFlavors)) {
         $finalFlavors = self::adjustToPairedDigitalWatermarking(self::TAG_VARIANT_A, $finalTagedFlavors, $finalFlavors);
         $finalFlavors = self::adjustToPairedDigitalWatermarking(self::TAG_VARIANT_B, $finalTagedFlavors, $finalFlavors);
     }
     // sort the flavors to decide which one will be performed first
     usort($finalFlavors, array('kBusinessConvertDL', 'compareFlavors'));
     KalturaLog::log(count($finalFlavors) . " flavors sorted for execution");
     return $finalFlavors;
 }
Beispiel #4
0
 /**
  * batch addMediaInfo adds a media info and updates the flavor asset 
  * 
  * @param mediaInfo $mediaInfoDb  
  * @return mediaInfo 
  */
 public static function addMediaInfo(mediaInfo $mediaInfoDb)
 {
     $mediaInfoDb->save();
     KalturaLog::log("Added media info [" . $mediaInfoDb->getId() . "] for flavor asset [" . $mediaInfoDb->getFlavorAssetId() . "]");
     if (!$mediaInfoDb->getFlavorAssetId()) {
         return $mediaInfoDb;
     }
     $flavorAsset = assetPeer::retrieveById($mediaInfoDb->getFlavorAssetId());
     if (!$flavorAsset) {
         return $mediaInfoDb;
     }
     if ($flavorAsset->getIsOriginal()) {
         KalturaLog::log("Media info is for the original flavor asset");
         $tags = null;
         $profile = myPartnerUtils::getConversionProfile2ForEntry($flavorAsset->getEntryId());
         if ($profile) {
             $tags = $profile->getInputTagsMap();
         }
         KalturaLog::log("Flavor asset tags from profile [{$tags}]");
         if (!is_null($tags)) {
             $tagsArray = explode(',', $tags);
             // support for old migrated profiles
             if ($profile->getCreationMode() == conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV) {
                 if (!KDLWrap::CDLIsFLV($mediaInfoDb)) {
                     $key = array_search(flavorParams::TAG_MBR, $tagsArray);
                     if ($key !== false) {
                         unset($tagsArray[$key]);
                     }
                 }
             }
             $finalTagsArray = KDLWrap::CDLMediaInfo2Tags($mediaInfoDb, $tagsArray);
             $finalTags = join(',', array_unique($finalTagsArray));
             KalturaLog::log("Flavor asset tags from KDL [{$finalTags}]");
             //KalturaLog::log("Flavor asset tags [".print_r($flavorAsset->setTags(),1)."]");
             $flavorAsset->addTags($finalTagsArray);
         }
     } else {
         KalturaLog::log("Media info is for the destination flavor asset");
         $tags = null;
         $flavorParams = assetParamsPeer::retrieveByPK($flavorAsset->getFlavorParamsId());
         if ($flavorParams) {
             $tags = $flavorParams->getTags();
         }
         KalturaLog::log("Flavor asset tags from flavor params [{$tags}]");
         if (!is_null($tags)) {
             $tagsArray = explode(',', $tags);
             $assetTagsArray = $flavorAsset->getTagsArray();
             foreach ($assetTagsArray as $tag) {
                 $tagsArray[] = $tag;
             }
             $maxMbrBitrate = 8000;
             if (kConf::hasParam('max_mbr_flavor_bitrate')) {
                 $maxMbrBitrate = kConf::get('max_mbr_flavor_bitrate');
             }
             if ($mediaInfoDb->getContainerBitRate() >= $maxMbrBitrate) {
                 $tagsArray = array_unique($tagsArray);
                 $key = array_search(flavorParams::TAG_MBR, $tagsArray);
                 if ($key !== false) {
                     unset($tagsArray[$key]);
                 }
             }
             $finalTagsArray = $tagsArray;
             //				bypass, KDLWrap::CDLMediaInfo2Tags doesn't support destination flavors and mobile tags
             //				$finalTagsArray = KDLWrap::CDLMediaInfo2Tags($mediaInfoDb, $tagsArray);
             $finalTags = join(',', array_unique($finalTagsArray));
             KalturaLog::log("Flavor asset tags from KDL [{$finalTags}]");
             $flavorAsset->setTags($finalTags);
         }
     }
     KalturaLog::log("KDLWrap::ConvertMediainfoCdl2FlavorAsset(" . $mediaInfoDb->getId() . ", " . $flavorAsset->getId() . ");");
     KDLWrap::ConvertMediainfoCdl2FlavorAsset($mediaInfoDb, $flavorAsset);
     $flavorAsset->save();
     //		if(!$flavorAsset->hasTag(flavorParams::TAG_MBR))
     //			return $mediaInfoDb;
     $entry = entryPeer::retrieveByPK($flavorAsset->getEntryId());
     if (!$entry) {
         return $mediaInfoDb;
     }
     $contentDuration = $mediaInfoDb->getContainerDuration();
     if (!$contentDuration) {
         $contentDuration = $mediaInfoDb->getVideoDuration();
         if (!$contentDuration) {
             $contentDuration = $mediaInfoDb->getAudioDuration();
         }
     }
     if ($contentDuration && $entry->getCalculateDuration()) {
         $entry->setLengthInMsecs($contentDuration);
     }
     if ($mediaInfoDb->getVideoWidth() && $mediaInfoDb->getVideoHeight()) {
         $entry->setDimensionsIfBigger($mediaInfoDb->getVideoWidth(), $mediaInfoDb->getVideoHeight());
     }
     $entry->save();
     return $mediaInfoDb;
 }
Beispiel #5
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      mediaInfo $value A mediaInfo object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(mediaInfo $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) {
             self::$instances[$key] = $obj;
             kMemoryManager::registerPeer('mediaInfoPeer');
         }
     }
 }
Beispiel #6
0
 /**
  * batch addMediaInfo adds a media info and updates the flavor asset 
  * 
  * @param mediaInfo $mediaInfoDb  
  * @return mediaInfo 
  */
 public static function addMediaInfo(mediaInfo $mediaInfoDb)
 {
     $mediaInfoDb->save();
     KalturaLog::log("Added media info [" . $mediaInfoDb->getId() . "] for flavor asset [" . $mediaInfoDb->getFlavorAssetId() . "]");
     if (!$mediaInfoDb->getFlavorAssetId()) {
         return $mediaInfoDb;
     }
     $flavorAsset = flavorAssetPeer::retrieveById($mediaInfoDb->getFlavorAssetId());
     if (!$flavorAsset) {
         return $mediaInfoDb;
     }
     if ($flavorAsset->getIsOriginal()) {
         KalturaLog::log("Media info is for the original flavor asset");
         $tags = null;
         $profile = myPartnerUtils::getConversionProfile2ForEntry($flavorAsset->getEntryId());
         if ($profile) {
             $tags = $profile->getInputTagsMap();
         }
         KalturaLog::log("Flavor asset tags from profile [{$tags}]");
         if (!is_null($tags)) {
             $tagsArray = explode(',', $tags);
             // support for old migrated profiles
             if ($profile->getCreationMode() == conversionProfile2::CONVERSION_PROFILE_2_CREATION_MODE_AUTOMATIC_BYPASS_FLV) {
                 if (!KDLWrap::CDLIsFLV($mediaInfoDb)) {
                     $key = array_search(flavorParams::TAG_MBR, $tagsArray);
                     unset($tagsArray[$key]);
                 }
             }
             $finalTagsArray = KDLWrap::CDLMediaInfo2Tags($mediaInfoDb, $tagsArray);
             $finalTags = join(',', $finalTagsArray);
             KalturaLog::log("Flavor asset tags from KDL [{$finalTags}]");
             $flavorAsset->setTags($finalTags);
         }
     }
     KalturaLog::log("KDLWrap::ConvertMediainfoCdl2FlavorAsset(" . $mediaInfoDb->getId() . ", " . $flavorAsset->getId() . ");");
     KDLWrap::ConvertMediainfoCdl2FlavorAsset($mediaInfoDb, $flavorAsset);
     $flavorAsset->save();
     //		if(!$flavorAsset->hasTag(flavorParams::TAG_MBR))
     //			return $mediaInfoDb;
     $entry = entryPeer::retrieveByPK($flavorAsset->getEntryId());
     if (!$entry) {
         return $mediaInfoDb;
     }
     $contentDuration = $mediaInfoDb->getContainerDuration();
     if (!$contentDuration) {
         $contentDuration = $mediaInfoDb->getVideoDuration();
         if (!$contentDuration) {
             $contentDuration = $mediaInfoDb->getAudioDuration();
         }
     }
     $entry->setLengthInMsecs($contentDuration);
     if ($mediaInfoDb->getVideoWidth() && $mediaInfoDb->getVideoHeight()) {
         $entry->setDimensions($mediaInfoDb->getVideoWidth(), $mediaInfoDb->getVideoHeight());
     }
     $entry->save();
     return $mediaInfoDb;
 }