/**
     * Test time parsing to seconds
    */
    function testParseTimeString() {
    	// Some time conversions:
    	$this->assertEquals( TimedMediaHandler::parseTimeString( 100 ), 100 );
    	$this->assertEquals( TimedMediaHandler::parseTimeString( '1:0:0' ), 3600 );
    	$this->assertEquals( TimedMediaHandler::parseTimeString( -1 ), 0 );
    	// Test longer than duration check ( should return time -1 ) 
    	$this->assertEquals( TimedMediaHandler::parseTimeString( 10, 9 ), 8 );
    	
    	// Test failures:
    	$this->assertEquals( TimedMediaHandler::parseTimeString( '1:1:1:1' ), false );
    	$this->assertEquals( TimedMediaHandler::parseTimeString( 'abc' ), false );
    	
    }
	static function getThumbTime( $options ){
		$length = $options['file']->getLength();
		$thumbtime = false;

		// If start time param isset use that for the thumb:
		if(  isset( $options['start'] ) ) {
			$thumbtime = TimedMediaHandler::parseTimeString( $options['start'], $length );
			if( $thumbtime )
		 		return $thumbtime;
		}
		// else use thumbtime
		if ( isset( $options['thumbtime'] ) ) {
		 	$thumbtime = TimedMediaHandler::parseTimeString( $options['thumbtime'], $length );
		 	if( $thumbtime )
		 		return $thumbtime;
		}
		// Seek to midpoint by default, it tends to be more interesting than the start
		return $length / 2;
	}
예제 #3
0
 function runCheckJobThreadsLoop()
 {
     global $IP, $wgTranscodeBackgroundTimeLimit;
     // Check if we have $threads number of webTranscode jobs running else sleep
     $runingJobsCount = 0;
     foreach ($this->getProcessList() as $pid => $proc) {
         // Check that the process is a "runJobs.php" action with type webVideoTranscode argument
         if (strpos($proc['args'], 'runJobs.php') !== false && strpos($proc['args'], '--type webVideoTranscode') !== false) {
             if (TimedMediaHandler::parseTimeString($proc['time']) > $wgTranscodeBackgroundTimeLimit) {
                 // should probably "kill" the process
                 $killSuccess = posix_kill($pid);
                 $this->output("Trying to expire transcode job: " . $pid . " result:" . $killSuccess);
             } else {
                 // Job is oky add to count:
                 $runingJobsCount++;
             }
         }
     }
     if ($runingJobsCount < $this->threads) {
         // Add one process:
         $parameters = array();
         if ($this->wiki) {
             $parameters[] = '--wiki';
             $parameters[] = $this->wiki;
         }
         $parameters[] = '--type';
         $parameters[] = 'webVideoTranscode';
         $parameters[] = '--maxjobs';
         $parameters[] = '1';
         $parameters[] = '--maxtime';
         $parameters[] = $wgTranscodeBackgroundTimeLimit;
         $cmd = wfShellMaintenanceCmd("{$IP}/maintenance/runJobs.php", $parameters);
         $status = $this->runBackgroundProc($cmd);
         $this->output("{$runingJobsCount} existing job runners, Check for new transcode jobs:  ");
     } else {
         // Just output a "tick"
         $this->output("{$runingJobsCount} transcode jobs active:\n");
     }
 }
	function getTemporalUrlHash(){
		if( $this->hashTime ){
			return $this->hashTime;
		}
		$hash ='';
		if( $this->start ){
			$startSec = TimedMediaHandler::parseTimeString( $this->start );
			if( $startSec !== false ){
				$hash.= '#t=' . TimedMediaHandler::seconds2npt( $startSec );
			}
		}
		if( $this->end ){
			if( $hash == '' ){
				$hash .= '#t=0';
			}
			$endSec = TimedMediaHandler::parseTimeString( $this->end );
			if( $endSec !== false ){
				$hash.= ',' . TimedMediaHandler::seconds2npt( $endSec );
			}
		}
		$this->hashTime = $hash;
		return $this->hashTime;
	}