commit 6fdffc08b4b818719611791f6947edca60b650d8
Author: jimmy <jimmy@netivism.com.tw>
Date:   Thu Jul 18 16:59:54 2013 +0800

    Add support for multiple server encoding. Every server can run one
    encode process at the same time.

diff --git includes/jobs.inc includes/jobs.inc
index fb4b0d2..f084b7e 100644
--- includes/jobs.inc
+++ includes/jobs.inc
@@ -75,6 +75,7 @@ class video_jobs {
     foreach ($result as $row) {
       $row->video_status = VIDEO_RENDERING_INQUEUE;
       $row->statusupdated = $now;
+      $row->encodeserver = gethostname();
       $row->data = empty($row->data) ? NULL : unserialize($row->data);
       self::update($row);
       $videos[] = $row;
diff --git video.drush.inc video.drush.inc
index a75b9dc..f756eb4 100644
--- video.drush.inc
+++ video.drush.inc
@@ -18,6 +18,13 @@ function video_drush_command() {
     ),
   );
 
+  $items['video-scheduler-multi-server'] = array(
+    'aliases' => array('video-scheduler-m'),
+    'description' => 'Run video transcoder scheduler, limit number based on server',
+    'callback' => 'drush_video_scheduler_multi_server',
+    'drupal dependencies' => array('video'),
+  );
+
   return $items;
 }
 
@@ -32,3 +39,32 @@ function drush_video_scheduler() {
   $transcoder = new Transcoder();
   $transcoder->runQueue();
 }
+
+function drush_video_scheduler_multi_server(){
+  // this number will allow many process in different server
+  $GLOBALS['conf']['video_ffmpeg_instances'] = 99;
+
+  // now test if our server already running ffmpeg.
+  $lines = array();
+  exec('ps aux', $lines);
+  foreach($lines as $l){
+    if(strstr($l, 'ffmpeg')){
+      // previous encoder is running.
+      // drush_log('Previous encoding in process list. Abort.');
+      return;
+    }
+  }
+
+  // check server record again
+  $hostname = gethostname(); 
+  $inqueue = db_query("SELECT status FROM {video_queue} WHERE status = ".VIDEO_RENDERING_INQUEUE." and encodeserver = :server", array(':server' => $hostname))->fetchField();
+
+  if($inqueue) {
+    // drush_log('Previous encoding in queue table and rending. Abort.');
+    return;
+  }
+
+  // if ok, runQueue
+  $transcoder = new Transcoder();
+  $transcoder->runQueue();
+}
diff --git video.info video.info
index f2d11d5..f439ff2 100644
--- video.info
+++ video.info
@@ -23,7 +23,7 @@ files[] = tests/PHPVideoToolkit.test
 files[] = tests/VideoScheduling.test
 
 ; Information added by drupal.org packaging script on 2013-04-23
-version = "7.x-peopo"
+version = "7.x-2.11-peopo"
 core = "7.x"
 project = "video"
 datestamp = "1366693516"
diff --git video.install video.install
index 8db28db..0513ce6 100644
--- video.install
+++ video.install
@@ -77,6 +77,12 @@ function video_schema() {
         'default' => 0,
         'unsigned' => TRUE,
       ),
+      'encodeserver' => array(
+        'type' => 'varchar',
+        'length' => 64,
+        'not null' => FALSE,
+        'description' => 'Stores encoding server address.',
+      ),
       'data' => array(
         'type' => 'blob',
         'not null' => FALSE,
@@ -88,6 +94,7 @@ function video_schema() {
     'indexes' => array(
       'status' => array('status'),
       'file' => array('fid'),
+      'encodeserver' => array('encodeserver'),
     ),
     'primary key' => array('vid'),
   );
@@ -548,3 +555,16 @@ function video_update_7210(&$sandbox) {
   );
   db_add_field('video_queue', 'statusupdated', $new_field);
 }
+
+function video_update_7211(&$sandbox){
+  $new_field = array(
+    'type' => 'varchar',
+    'length' => 64,
+    'not null' => FALSE,
+    'description' => 'Stores encoding server address.',
+  );
+  $index = array(
+    'indexes' => array('encodeserver' => array('encodeserver')),
+  );
+  db_add_field('video_queue', 'encodeserver', $new_field);
+}
