/**
  * @param string $type
  * @return KalturaTypeReflector
  */
 static function get($type)
 {
     if (!self::$_enabled) {
         return new KalturaTypeReflector($type);
     }
     if (!array_key_exists($type, self::$_loadedTypeReflectors)) {
         $cachedDir = KAutoloader::buildPath(kConf::get("cache_root_path"), "api_v3", "typeReflector");
         if (!is_dir($cachedDir)) {
             mkdir($cachedDir);
             chmod($cachedDir, 0755);
         }
         $cachedFilePath = $cachedDir . DIRECTORY_SEPARATOR . $type . ".cache";
         $typeReflector = null;
         if (file_exists($cachedFilePath)) {
             $cachedData = file_get_contents($cachedFilePath);
             $typeReflector = unserialize($cachedData);
         }
         if (!$typeReflector) {
             $typeReflector = new KalturaTypeReflector($type);
             $cachedData = serialize($typeReflector);
             $bytesWritten = kFile::safeFilePutContents($cachedFilePath, $cachedData);
             if (!$bytesWritten) {
                 $folderPermission = substr(decoct(fileperms(dirname($cachedFilePath))), 2);
                 error_log("Kaltura type reflector could not be saved to path [{$cachedFilePath}] type [{$type}] folder permisisons [{$folderPermission}]");
             }
         }
         self::$_loadedTypeReflectors[$type] = $typeReflector;
     }
     return self::$_loadedTypeReflectors[$type];
 }
예제 #2
0
 public function write()
 {
     $amfSerializer = new FLV_Util_AMFSerialize();
     $metadata_data = array();
     // theses will be used as placeholders for dynamic data
     $metadata_data["canSeekToEnd"] = true;
     $metadata_data["duration"] = (int) ($this->duration / 1000);
     $metadata_data["timeOffset"] = 0;
     $metadata_data["bytesOffset"] = 0;
     // because of akamai seek limitation we want to limit metadata size to 16kb
     // 15K / 2 (times & positions arrays ) / 8 (bytes each) ~ 850
     // we will skip keyframes in order to use at most 850 of them
     $kf_cnt = count($this->keyframeTimes);
     // if there are more than 1 keyframe per second and file size < 100MB its probably and edit flavor and we should maintain all KF
     // we serve the file from our server and not the cdn anyway because the cdn cant clip the file
     $lastKF = $lastKFPos = 0;
     if ($kf_cnt) {
         $lastKF = $this->keyframeTimes[$kf_cnt - 1] / 1000;
         $lastKFPos = $this->keyframeBytes[$kf_cnt - 1] / (1000 * 1000);
     }
     if ($kf_cnt > $lastKF && ($lastKFPos < 100 && !$this instanceof FlvMetadataAudio)) {
         $new_kf_step = 1;
     } else {
         $new_kf_step = max(1, $kf_cnt / 850);
     }
     $new_kf = array();
     $new_fp = array();
     $i = 0;
     $new_kf_pos = 0;
     while ($i < $kf_cnt) {
         $new_kf[] = $this->keyframeTimes[$i];
         $new_fp[] = $this->keyframeBytes[$i];
         $new_kf_pos += $new_kf_step;
         $i = floor($new_kf_pos);
     }
     $metadata_data["times"] = $new_kf;
     $metadata_data["filepositions"] = $new_fp;
     $data = $amfSerializer->serialize('onMetaData') . $amfSerializer->serialize($metadata_data);
     $data_len = strlen($data);
     $metatagSize = myFlvHandler::TAG_WRAPPER_SIZE + $data_len;
     for ($i = 0; $i < count($new_kf); ++$i) {
         $metadata_data["filepositions"][$i] += $metatagSize;
     }
     $res = $amfSerializer->serialize('onMetaData') . $amfSerializer->serialize($metadata_data);
     $meta_tag = myFlvHandler::createMetadataTag($data);
     kFile::safeFilePutContents($this->info_file_name, $meta_tag);
     // sync - OK
     $meta_tag = null;
     $amfSerializer = null;
 }
예제 #3
0
 public final function fromObject($srcObj, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if (!is_object($srcObj)) {
         KalturaLog::err("expected an object, got " . print_r($srcObj, true));
         return;
     }
     $thisClass = get_class($this);
     $srcObjClass = get_class($srcObj);
     $fromObjectClass = "Map_{$thisClass}_{$srcObjClass}";
     if (!class_exists($fromObjectClass)) {
         $cacheFileName = kConf::get("cache_root_path") . "/api_v3/fromObject/{$fromObjectClass}.php";
         if (!file_exists($cacheFileName)) {
             $cacheDir = dirname($cacheFileName);
             if (!is_dir($cacheDir)) {
                 mkdir($cacheDir);
                 chmod($cacheDir, 0755);
             }
             $fromObjectClassCode = $this->generateFromObjectClass($srcObj, $fromObjectClass);
             if (!$fromObjectClassCode) {
                 return;
             }
             kFile::safeFilePutContents($cacheFileName, $fromObjectClassCode);
         }
         require_once $cacheFileName;
     }
     $fromObjectClass::fromObject($this, $srcObj, $responseProfile);
     $this->doFromObject($srcObj, $responseProfile);
     if ($srcObj instanceof IRelatedObject) {
         KalturaResponseProfileCacher::onPersistentObjectLoaded($srcObj);
         if ($responseProfile && $responseProfile->relatedProfiles) {
             // trigger validation
             $responseProfile->validateNestedObjects();
             $this->relatedObjects = KalturaResponseProfileCacher::start($srcObj, $responseProfile);
             if (!$this->relatedObjects) {
                 $this->loadRelatedObjects($responseProfile);
                 KalturaResponseProfileCacher::stop($srcObj, $this);
             }
         }
     }
 }
예제 #4
0
 public final function fromObject($srcObj, KalturaDetachedResponseProfile $responseProfile = null)
 {
     if (!is_object($srcObj)) {
         KalturaLog::err("expected an object, got " . print_r($srcObj, true));
         return;
     }
     if ($srcObj instanceof IRelatedObject && $responseProfile && $responseProfile->relatedProfiles) {
         if (KalturaResponseProfileCacher::start($this, $srcObj, $responseProfile)) {
             return;
         }
     }
     $thisClass = get_class($this);
     $srcObjClass = get_class($srcObj);
     $fromObjectClass = "Map_{$thisClass}_{$srcObjClass}";
     if (!class_exists($fromObjectClass)) {
         $cacheFileName = kConf::get("cache_root_path") . "/api_v3/fromObject/{$fromObjectClass}.php";
         $max_include_retries = 10;
         $fromObjectClassCode = null;
         while (!@(include_once $cacheFileName) and $max_include_retries--) {
             if (!$fromObjectClassCode) {
                 $fromObjectClassCode = $this->generateFromObjectClass($srcObj, $fromObjectClass);
                 if (!$fromObjectClassCode) {
                     return;
                 }
             }
             $cacheDir = dirname($cacheFileName);
             if (!is_dir($cacheDir)) {
                 mkdir($cacheDir);
                 chmod($cacheDir, 0775);
             }
             kFile::safeFilePutContents($cacheFileName, $fromObjectClassCode, 0644);
         }
         if (!class_exists($fromObjectClass)) {
             throw new Exception("Could not include cached code file - {$cacheFileName}");
         }
     }
     $fromObjectClass::fromObject($this, $srcObj, $responseProfile);
     $this->doFromObject($srcObj, $responseProfile);
     if ($srcObj instanceof IRelatedObject) {
         KalturaResponseProfileCacher::onPersistentObjectLoaded($srcObj);
         if ($responseProfile && $responseProfile->relatedProfiles) {
             $responseProfile->validateNestedObjects();
             $this->loadRelatedObjects($responseProfile);
             KalturaResponseProfileCacher::stop($srcObj, $this);
         }
     }
 }
 static function cacheMap($servicePath, $cacheFilePath)
 {
     if (!is_dir($servicePath)) {
         throw new Exception('Invalid directory [' . $servicePath . ']');
     }
     $servicePath = realpath($servicePath);
     $serviceMap = array();
     $classMap = KAutoloader::getClassMap();
     $checkedClasses = array();
     //Retrieve all service classes from the classMap.
     $serviceClasses = array();
     foreach ($classMap as $class => $classFilePath) {
         $classFilePath = realpath($classFilePath);
         if (strpos($classFilePath, $servicePath) === 0) {
             $reflectionClass = new ReflectionClass($class);
             if ($reflectionClass->isSubclassOf('KalturaBaseService')) {
                 $serviceDoccomment = new KalturaDocCommentParser($reflectionClass->getDocComment());
                 $serviceClasses[$serviceDoccomment->serviceName] = $class;
             }
         }
     }
     //Retrieve all plugin service classes.
     $pluginInstances = KalturaPluginManager::getPluginInstances('IKalturaServices');
     foreach ($pluginInstances as $pluginName => $pluginInstance) {
         $pluginServices = $pluginInstance->getServicesMap();
         foreach ($pluginServices as $serviceName => $serviceClass) {
             $serviceName = strtolower($serviceName);
             $serviceId = "{$pluginName}_{$serviceName}";
             $serviceClasses[$serviceId] = $serviceClass;
         }
     }
     //Add core & plugin services to the services map
     $aliasActions = array();
     foreach ($serviceClasses as $serviceId => $serviceClass) {
         $serviceReflectionClass = KalturaServiceReflector::constructFromClassName($serviceClass);
         $serviceMapEntry = new KalturaServiceActionItem();
         $serviceMapEntry->serviceId = $serviceId;
         $serviceMapEntry->serviceClass = $serviceClass;
         $serviceMapEntry->serviceInfo = $serviceReflectionClass->getServiceInfo();
         $actionMap = array();
         $nativeActions = $serviceReflectionClass->getActions();
         foreach ($nativeActions as $actionId => $actionName) {
             $actionMap[strtolower($actionId)] = array("serviceClass" => $serviceClass, "actionMethodName" => $actionName, "serviceId" => $serviceId, "actionName" => $actionId);
         }
         $serviceMapEntry->actionMap = $actionMap;
         $serviceMap[strtolower($serviceId)] = $serviceMapEntry;
         foreach ($serviceReflectionClass->getAliasActions() as $alias => $methodName) {
             $aliasActions[$alias] = "{$serviceId}.{$methodName}";
         }
     }
     // add aliases
     foreach ($aliasActions as $aliasAction => $sourceAction) {
         list($aliasService, $aliasAction) = explode('.', $aliasAction);
         list($sourceService, $sourceAction) = explode('.', $sourceAction);
         $aliasService = strtolower($aliasService);
         $sourceService = strtolower($sourceService);
         $extServiceClass = $serviceClasses[$sourceService];
         $serviceMap[$aliasService]->actionMap[strtolower($aliasAction)] = array("serviceClass" => $extServiceClass, "actionMethodName" => $sourceAction, "serviceId" => $sourceService, "actionName" => $aliasAction);
     }
     // filter out services that have no actions
     $serviceMap = array_filter($serviceMap, array('KalturaServicesMap', 'filterEmptyServices'));
     if (!is_dir(dirname($cacheFilePath))) {
         mkdir(dirname($cacheFilePath));
         chmod(dirname($cacheFilePath), 0755);
     }
     kFile::safeFilePutContents($cacheFilePath, serialize($serviceMap), 0644);
 }
예제 #6
0
 public final function fromObject($srcObj, KalturaDetachedResponseProfile $responseProfile = null)
 {
     $thisClass = get_class($this);
     $srcObjClass = get_class($srcObj);
     $fromObjectClass = "Map_{$thisClass}_{$srcObjClass}";
     if (!class_exists($fromObjectClass)) {
         $cacheFileName = kConf::get("cache_root_path") . "/api_v3/fromObject/{$fromObjectClass}.php";
         if (!file_exists($cacheFileName)) {
             $cacheDir = dirname($cacheFileName);
             if (!is_dir($cacheDir)) {
                 mkdir($cacheDir);
                 chmod($cacheDir, 0755);
             }
             $fromObjectClassCode = $this->generateFromObjectClass($srcObj, $fromObjectClass);
             if (!$fromObjectClassCode) {
                 return;
             }
             kFile::safeFilePutContents($cacheFileName, $fromObjectClassCode);
         }
         require_once $cacheFileName;
     }
     $fromObjectClass::fromObject($this, $srcObj, $responseProfile);
     $this->doFromObject($srcObj, $responseProfile);
     if ($responseProfile) {
         $this->loadRelatedObjects($responseProfile);
     }
 }