Exemplo n.º 1
0
 /**
  * here we'll manipulate the video asset and set the from_byte & to_byte from the milliseconds
  *
  */
 private static function fixMetadataImpl(&$xml_doc, &$total_duration, $timeline)
 {
     self::log(__METHOD__);
     /*
     	$xml_doc = new DOMDocument();
     	$xml_doc->loadXML( $content );
     */
     //		$meatadata_elem_list = $xml_doc->getElementsByTagName( "MetaData" );
     //		if ( $meatadata_elem_list != null && $meatadata_elem_list->length > 0 )
     $duration_list = $xml_doc->getElementsByTagName("SeqDuration");
     if ($duration_list != null && $duration_list->length > 0) {
         $total_duration = $duration_list->item(0)->nodeValue;
     }
     $xpath = new DOMXPath($xml_doc);
     $assets = $xpath->query($timeline == "video" ? "//VideoAssets/vidAsset" : ($timeline == "audio" ? "//AudioAssets/AudAsset" : "//VoiceAssets/voiAsset"));
     $lastTimestamp = 0;
     $real_start_byte = 0;
     // the start byte of the current clip in the final merged stream
     $calculated_total_bytes = 0;
     // use the entryPool and a 2-pass iteration to reduce the hits to the DB
     $id_list = array();
     $entry_pool = new entryPool();
     // first pass - populate the entryPool in a single request to the DB
     self::log(__METHOD__, "Before assets");
     foreach ($assets as $asset) {
         $type = $asset->getAttribute("type");
         if ($type != "VIDEO" && $type != "AUDIO") {
             continue;
         }
         // fetch the file name from the DB
         $asset_id = $asset->getAttribute("k_id");
         $id_list[] = $asset_id;
     }
     self::log(__METHOD__, "After assets", count($id_list), $id_list);
     if ($id_list) {
         $entry_pool->addEntries(entryPeer::retrieveByPKsNoFilter($id_list));
     }
     // second pass - the entryPool is supposed to already be populated
     $was_modified = false;
     foreach ($assets as $asset) {
         // fix only VIDEO assets
         $type = $asset->getAttribute("type");
         if ($type != "VIDEO" && $type != "AUDIO") {
             continue;
         }
         // fetch the file name from the DB
         $asset_id = $asset->getAttribute("k_id");
         self::log(__METHOD__, "in loop", $asset_id);
         //$entry = entryPeer::retrieveByPKNoFilter( $asset_id );
         $entry = $entry_pool->retrieveByPK($asset_id);
         // is supposed to exist already in the pool
         if ($entry == NULL) {
             // set an error on the asset element
             $asset->setAttribute("fix_status", "error in k_id [{$asset_id}]");
             $was_modified = true;
             continue;
         } elseif ($entry->getStatus() == entryStatus::DELETED) {
             // set an error on the asset element
             $asset->setAttribute("fix_status", "error in k_id [{$asset_id}] - asset was deleted");
             $was_modified = true;
             continue;
         }
         $file_name = null;
         //TODO: need to work on only an FLV asset
         $flavor_asset_play = assetPeer::retrieveBestPlayByEntryId($entry->getId());
         if (!$flavor_asset_play) {
             KalturaLog::log(__METHOD__ . ' ' . __LINE__ . ' no play flavor asset for entry ' . $entry->getId());
         } else {
             $file_name = kFileSyncUtils::getReadyLocalFilePathForKey($flavor_asset_play->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET));
         }
         $use_multi_flavor = false;
         $flv_file_name_edit = false;
         $flavor_asset_edit = assetPeer::retrieveBestEditByEntryId($entry->getId());
         if (!$flavor_asset_edit) {
             KalturaLog::log(__METHOD__ . ' ' . __LINE__ . ' no edit flavor asset for entry ' . $entry->getId());
         } else {
             $flv_file_name_edit = kFileSyncUtils::getReadyLocalFilePathForKey($flavor_asset_edit->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET));
             $use_multi_flavor = $flv_file_name_edit && file_exists($flv_file_name_edit) && $timeline == "video";
         }
         if (!$flv_file_name_edit && !$file_name) {
             KalturaLog::log(__METHOD__ . ' ' . __LINE__ . ' no edit & play flavor assets for entry ' . $entry->getId());
             continue;
         }
         $flv_file_name = kFile::fixPath($file_name);
         $stream_info_list = $asset->getElementsByTagName("StreamInfo");
         foreach ($stream_info_list as $stream_info) {
             $file_name = "?";
             try {
                 $stream_info->setAttribute("file_name", kFileSyncUtils::getReadyLocalFilePathForKey($flavor_asset_play->getSyncKey(flavorAsset::FILE_SYNC_FLAVOR_ASSET_SUB_TYPE_ASSET)));
                 // replaced__getDataPath
                 $start_byte = $stream_info->getAttribute("start_byte");
                 $end_byte = $stream_info->getAttribute("end_byte");
                 $total_bytes = $stream_info->getAttribute("total_bytes");
                 if ($start_byte == NULL) {
                     $start_byte = self::MISSING_VALUE;
                 }
                 if ($end_byte == NULL) {
                     $end_byte = self::MISSING_VALUE;
                 }
                 if ($total_bytes == NULL) {
                     $total_bytes = self::MISSING_VALUE;
                 }
                 $len_time = floor(1000 * $stream_info->getAttribute("len_time"));
                 if (1 || $start_byte == self::MISSING_VALUE || $end_byte == self::MISSING_VALUE || $total_bytes == self::MISSING_VALUE) {
                     // set the values from start_time & len_time - the original numbers are in seconds (with a decimal point)
                     $start_time = floor(1000 * $stream_info->getAttribute("start_time"));
                     $end_time = $start_time + $len_time;
                     $real_start_byte += $calculated_total_bytes;
                     $calculated_start_byte = 0;
                     $calculated_end_byte = 0;
                     $calculated_total_bytes = 0;
                     $calculated_real_seek_time = 0;
                     $calculated_start_byte_play = 0;
                     $calculated_end_byte_play = 0;
                     $calculated_total_bytes_play = 0;
                     /*		  				$file_name = $stream_info->getAttribute ( "file_name" );
                     						$flv_file_name = kFile::fixPath( myContentStorage::getFSContentRootPath() . $file_name );
                     						$ext = pathinfo ($flv_file_name, PATHINFO_EXTENSION);
                     						if ( $ext == NULL  )
                     							$flv_file_name .= ".flv";
                     	*/
                     try {
                         self::log(__METHOD__, "before findBytesFromTimestamps", $flv_file_name);
                         //$use_multi_flavor = myFlvStaticHandler::isMultiFlavor ( $flv_file_name  ) && $timeline == "video";
                         $calculated_real_seek_time = $lastTimestamp;
                         $start_time_play = null;
                         if ($use_multi_flavor) {
                             $start_time_play = $start_time;
                             // play
                             // $start_time_play - will be modified according to the first keyframe's time stamp AFTER (not before) the requested timestamp
                             $result = myFlvStaticHandler::findBytesFromTimestamps($flv_file_name, $start_time_play, $end_time, $calculated_start_byte_play, $calculated_end_byte_play, $calculated_total_bytes_play, $lastTimestamp, $timeline != "video", 1);
                             KalturaLog::log(__METHOD__ . ' ' . __LINE__ . " play {$result} = findBytesFromTimestamps({$flv_file_name} , {$start_time_play} , {$end_time} , {$calculated_start_byte_play} , {$calculated_end_byte_play} , {$calculated_total_bytes_play}, {$lastTimestamp}, {$timeline})");
                             if ($result) {
                                 if ($start_time_play != $start_time) {
                                     // we need to fill the gap between the user requested keyframe and the one actually found in the play (low res) flavor
                                     // 	edit - more keyfrmaes !
                                     $result = myFlvStaticHandler::findBytesFromTimestamps($flv_file_name_edit, $start_time, $start_time_play, $calculated_start_byte, $calculated_end_byte, $calculated_total_bytes, $lastTimestamp, $timeline != "video", 2);
                                     KalturaLog::log(__METHOD__ . ' ' . __LINE__ . " edit {$result} = findBytesFromTimestamps({$flv_file_name} , {$start_time_play} , {$end_time} , {$calculated_start_byte_play} , {$calculated_end_byte_play} , {$calculated_total_bytes_play}, {$lastTimestamp}, {$timeline})");
                                 }
                             }
                         } else {
                             // no reason to have multi-flavor files
                             // either because NOT video or because the edit flavor does not exist
                             $result = myFlvStaticHandler::findBytesFromTimestamps($flv_file_name, $start_time, $end_time, $calculated_start_byte, $calculated_end_byte, $calculated_total_bytes, $lastTimestamp, $timeline != "video", 0);
                             KalturaLog::log(__METHOD__ . ' ' . __LINE__ . " only play {$result} = findBytesFromTimestamps({$flv_file_name} , {$start_time_play} , {$end_time} , {$calculated_start_byte_play} , {$calculated_end_byte_play} , {$calculated_total_bytes_play}, {$lastTimestamp}, {$timeline})");
                         }
                         self::log(__METHOD__, "after findBytesFromTimestamps", $flv_file_name);
                     } catch (Exception $ex1) {
                         debugUtils::log("Error while converting time2bytes in file [{$file_name}]\n{$ex1}");
                         echo "Error while converting time2bytes in file [{$file_name}]\n{$ex1}";
                     }
                     $calculated_total_bytes += $calculated_total_bytes_play;
                     if ($result) {
                         if (1 || $start_byte == self::MISSING_VALUE) {
                             $stream_info->setAttribute("start_byte", $calculated_start_byte);
                             $stream_info->setAttribute("start_byte_play", $calculated_start_byte_play);
                         }
                         if (1 || $end_byte == self::MISSING_VALUE) {
                             $stream_info->setAttribute("end_byte", $calculated_end_byte);
                             $stream_info->setAttribute("end_byte_play", $calculated_end_byte_play);
                         }
                         if (1 || $calculated_total_bytes == self::MISSING_VALUE) {
                             $stream_info->setAttribute("total_bytes", $calculated_total_bytes);
                             $stream_info->setAttribute("real_start_byte", $real_start_byte);
                             $stream_info->setAttribute("real_end_byte", $real_start_byte + $calculated_total_bytes);
                         }
                         if (1 || $calculated_real_seek_time == self::MISSING_VALUE) {
                             // retrun the calculated_real_seek_time in seconds with 2 decimal points
                             $stream_info->setAttribute("real_seek_time", number_format($calculated_real_seek_time / 1000, 3, '.', ''));
                         }
                         if ($asset->hasAttribute("fix_status")) {
                             $asset->removeAttribute("fix_status");
                         }
                     } elseif (!$result) {
                         // set an error on the asset element
                         $asset->setAttribute("fix_status", "Missing file or invalid FLV structure");
                     }
                     $was_modified = true;
                 }
             } catch (Exception $ex2) {
                 echo "Error parsing file [{$file_name}]\n{$ex2}";
             }
         }
     }
     return $xml_doc;
     /*
       		if ( $was_modified )
       		{
       			return $xml_doc->saveXML();
       		}
       		else
       		{
       			// nothing was modified - use the original string
       			return $content;
       		}
     */
 }
Exemplo n.º 2
0
 /**
  * Derived classes can override this logic and have different constrainst on the field names and values.
  * Here we can also add complex validaitons as long as the order of thefields doesn't matter at this point -
  * only the name and the value of a single filed.
  * Relationships between other fileds ought to be verified after the whole object is full
  * because no assumption can be made on the order of the field filling.
  * The basic implementation verifies that the field_name already exists in the fields array (meaning - part of the object's schema).
  *
  * @param string $field_name
  * @param any $field_value
  */
 protected function isFieldValid($field_name, $field_value)
 {
     //		echo "isFieldValid: $field_name , $field_value , <br>" . print_r ( $this->fields  , false );
     if (!array_key_exists($field_name, $this->fields)) {
         debugUtils::DEBUG("", "Cannot set field [" . $field_name . "] in object of type - TODO - how to display current object's class ??");
         return false;
     }
     return true;
 }
 /**
  * @param int $paramIndex
  * @param int $value
  * @return void
  */
 function setInt($paramIndex, $value)
 {
     $this->sql_cache_valid = false;
     if ($value === null) {
         $this->setNull($paramIndex);
     } else {
         if (is_object($value)) {
             echo debugUtils::st(true, "<br>");
         }
         $this->boundInVars[$paramIndex] = (int) $value;
     }
 }
Exemplo n.º 4
0
 public static function setChildElement(DOMDocument &$xml_doc, $parent_element, $element_name, $element_value, $remove_element_if_empty_value = false)
 {
     $modified = true;
     $elem = self::getFirstElement($xml_doc, $element_name);
     if ($elem) {
         // element aleardy exists
         if (empty($element_value) && $remove_element_if_empty_value) {
             // new value is empty - and should remove - remove !
             $parent_element->removeChild($elem);
         } else {
             if ($elem->nodeValue != $element_value) {
                 $elem->nodeValue = $element_value;
             } else {
                 $modified = false;
             }
         }
     } else {
         // element does not exist - and no reason to create it
         if (empty($element_value) && $remove_element_if_empty_value) {
             $modified = false;
         } else {
             if (!$parent_element) {
                 debugUtils::st();
                 return false;
             }
             // need to create and set the value
             $elem = $xml_doc->createElement($element_name, $element_value);
             $parent_element->appendChild($elem);
         }
     }
     return $modified;
 }
 /**
  * Override the basic implementation of the field validation so there will be no need to define each and every field name in the fields schema.
  * IMPORTANT - the restriction will be based on several parameters mainly to protect againt injection of arbitrary data in large quantities.
  * 1. the prefix of the field_name is FIELD_NAME_PREFIX 
  * 2. the length of the field_name is less than or equal MAX_FIELD_NAME_LENGTH 
  * 3. the length of the field_value  is less than or equal MAX_FIELD_VALUE_LENGTH
  * 4. the total number of fields is less tham or equal MAX_NUMBER_OF_FIELDS
  *
  * @param stirng  $field_name
  * @param any $field_value
  * @return true if the field (name & value) fit the constraints, false otherwise
  */
 protected function isFieldValid($field_name, $field_value)
 {
     /*		if ( ! kString::beginsWith( $field_name , skinContainer::FIELD_NAME_PREFIX ) )
     		{
     			debugUtils::DEBUG( "Field [" . $field_name . "] invalid. Every field shouild start with the prefix "  , skinContainer::FIELD_NAME_PREFIX );
     			return false;
     		}
     */
     if (strlen($field_name) > skinContainer::MAX_FIELD_NAME_LENGTH) {
         debugUtils::DEBUG("Field [" . $field_name . "] invalid. Field name should not be longer than ", skinContainer::MAX_FIELD_NAME_LENGTH);
         return false;
     }
     if (strlen($field_value) > skinContainer::MAX_FIELD_VALUE_LENGTH) {
         debugUtils::DEBUG("Field [" . $field_name . "] invalid. Field value is [" . $field_value . "] and should not be longer than ", skinContainer::MAX_FIELD_VALUE_LENGTH);
         return false;
     }
     if (count($this->fields) > skinContainer::MAX_NUMBER_OF_FIELDS) {
         debugUtils::DEBUG("Too many fields. Number should not exceed [" . skinContainer::MAX_NUMBER_OF_FIELDS . "]", "");
         return false;
     }
     return true;
 }
Exemplo n.º 6
0
 private function forcePermissionsDoCheckOrRedirect($kshow, $kshow_id, $verification_mode, $allow_redirect = true)
 {
     $this->setCredentialByName("requestKshowName", $kshow->getName());
     $force_auth = false;
     if ($verification_mode == self::VERIFICATION_MODE_CONTRIB) {
         $permissions = $kshow->getContribPermissions();
         $pwd = $kshow->getContribPassword();
     } else {
         if ($verification_mode == self::VERIFICATION_MODE_EDIT) {
             $permissions = $kshow->getEditPermissions();
             $pwd = $kshow->getEditPassword();
             // in this case - force authentication when not for everyone
             $force_auth = true;
         } else {
             if ($verification_mode == self::VERIFICATION_MODE_VIEW) {
                 $permissions = $kshow->getViewPermissions();
                 $pwd = $kshow->getViewPassword();
             } else {
                 if ($verification_mode == self::VERIFICATION_MODE_CUSTOMIZE) {
                     // only the producer can customize
                     if (!$this->isProducer($kshow)) {
                         $this->playDead(NULL);
                     }
                     return true;
                 } else {
                     throw new Exception("Cannot force permission for type {$verification_mode}");
                 }
             }
         }
     }
     /*		
     		echo "kshow_id: $kshow_id, verification_mode: $verification_mode<br>" .
     			"producer: " . $kshow->getProducerId() . ", likuser id: " . $this->likuser_id . "<br>". 
     			"permission: $permissions, pwd: $pwd<br>";
     */
     /*
     const KSHOW_PERMISSION_EVERYONE = 1;
     const KSHOW_PERMISSION_JUST_ME = 2;
     const KSHOW_PERMISSION_INVITE_ONLY = 3;
     const KSHOW_PERMISSION_REGISTERED = 4;
     */
     //		echo ( "$kshow_id , $verification_mode , $allow_redirect , $permissions\n" );
     $res = true;
     debugUtils::log("kshow_id [{$kshow_id}], verification_mode: " . $verification_mode . " permissions: {$permissions}");
     switch ($permissions) {
         case kshow::KSHOW_PERMISSION_EVERYONE:
             break;
         case kshow::KSHOW_PERMISSION_REGISTERED:
             // if users are authenticated already - there will be no work here
             $res = $this->forceAuthentication($allow_redirect);
             break;
         case kshow::KSHOW_PERMISSION_JUST_ME:
             if ($force_auth) {
                 $res = $this->forceAuthentication($allow_redirect);
                 if (!$res) {
                     break;
                 }
                 // user was not authenticated but was supposed to be - don't continue
             }
             if (!$this->isProducer($kshow)) {
                 $res = $this->justMe($allow_redirect);
             }
             break;
         case kshow::KSHOW_PERMISSION_INVITE_ONLY:
             if ($force_auth) {
                 $res = $this->forceAuthentication($allow_redirect);
                 if (!$res) {
                     break;
                 }
                 // user was not authenticated but was supposed to be - don't continue
             }
             // no need to force verification on producer himself
             if (!$this->isProducer($kshow)) {
                 $res = $this->inviteOnly($kshow, $verification_mode, $allow_redirect);
             }
             break;
         case kshow::KSHOW_PERMISSION_NONE:
             // do nothing - exit
             throw new sfStopException();
             break;
     }
     return $res;
 }
Exemplo n.º 7
0
 /**
  * Sets Error Information
  * @return void
  */
 function setError($error)
 {
     $msg = !empty($error) ? $this->getErrorInfo($error) : null;
     $this->errorCount++;
     $this->errorInfo = $msg;
     $this->log("setError: " . $msg);
     $this->log(debugUtils::st(true));
 }