[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/video/includes/ -> conversion.inc (source)

   1  <?php
   2  
   3  /*
   4   * @file
   5   * Class file to handle video conversion using ffmpeg and webservices.
   6   *
   7   */
   8  defined('VIDEO_RENDERING_PENDING') ||
   9      define('VIDEO_RENDERING_PENDING', 1);
  10  defined('VIDEO_RENDERING_ACTIVE') ||
  11      define('VIDEO_RENDERING_ACTIVE', 5);
  12  defined('VIDEO_RENDERING_COMPLETE') ||
  13      define('VIDEO_RENDERING_COMPLETE', 10);
  14  defined('VIDEO_RENDERING_FAILED') ||
  15      define('VIDEO_RENDERING_FAILED', 20);
  16  
  17  class video_conversion {
  18  
  19    protected $transcoder;
  20  
  21    public function __construct() {
  22      module_load_include('inc', 'video', '/includes/transcoder');
  23      $this->transcoder = new video_transcoder;
  24    }
  25  
  26    /**
  27     * Our main function to call when converting queued up jobs.
  28     */
  29    public function run_queue() {
  30      if ($videos = $this->load_job_queue()) {
  31        foreach ($videos as $video) {
  32          $this->process($video);
  33        }
  34        //clear cache once completed the conversion to update the file paths
  35        cache_clear_all('*', 'cache_content', true);
  36      }
  37    }
  38  
  39    /**
  40     * Select videos from our queue
  41     *
  42     * @return
  43     *   An array containing all the videos to be proccessed.
  44     */
  45    private function load_job_queue() {
  46      // @TODO : allow only limited jobs to process
  47      return $this->transcoder->load_job_queue();
  48    }
  49  
  50    /**
  51     * Process the video through ffmpeg.
  52     *
  53     * @param $video
  54     *   This can either be the file object or the file id (fid)
  55     *
  56     * @return
  57     *   TRUE of FALSE if video was converted successfully.
  58     */
  59    public function process($video) {
  60      if (is_object($video) && isset($video->fid)) {
  61        $return = $this->render($video);
  62      } else {
  63        $video_object = $this->load_job($video);
  64        $return = $this->render($video_object);
  65      }
  66      return $return;
  67    }
  68  
  69    private function render($video) {
  70      if (!is_object($video)) {
  71        watchdog('video_conversion', 'Video object is not present', array(), WATCHDOG_ERROR);
  72        return FALSE;
  73      }
  74      // Make sure this video is pending or do nothing.
  75      if ($video->video_status == VIDEO_RENDERING_PENDING) {
  76        return $this->transcoder->convert_video($video);
  77      }
  78      return NULL;
  79    }
  80  
  81    /**
  82     * Load a converted video based on the file id ($fid)
  83     *
  84     * @todo: Need to figure something out here for multiple files (HTML 5)
  85     * @param $fid
  86     *   Integer of the file id to be loaded.
  87     */
  88    public function load_completed_job($video) {
  89      return $this->transcoder->load_completed_job($video);
  90    }
  91  
  92    public function create_job($video) {
  93      return $this->transcoder->create_job($video);
  94    }
  95  
  96    public function update_job($video) {
  97      return $this->transcoder->update_job($video);
  98    }
  99  
 100    public function delete_job($video) {
 101      return $this->transcoder->delete_job($video);
 102    }
 103  
 104    /**
 105     * Load a file based on the file id ($fid)
 106     *
 107     * @param $fid
 108     *   Integer of the file id to be loaded.
 109     */
 110    public function load_job($fid) {
 111      return $this->transcoder->load_job($fid);
 112    }
 113  
 114  }
 115  
 116  ?>


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7