From 74008dcb8b8b9400ad440e4ecfc7d75160590f15 Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Tue, 7 May 2013 11:15:06 -0400 Subject: [PATCH] Moved some of the logic for determining video streaming options from the controller to the model --- web/app/Controller/MonitorsController.php | 33 ++++++++--------------- web/app/Model/Config.php | 14 ++++++++++ 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/web/app/Controller/MonitorsController.php b/web/app/Controller/MonitorsController.php index e8cbb1b09..58b7852d2 100644 --- a/web/app/Controller/MonitorsController.php +++ b/web/app/Controller/MonitorsController.php @@ -12,7 +12,7 @@ } public function view($id = null) { - $this->loadMOdel('Config'); + $this->loadModel('Config'); if (!$id) { throw new NotFoundException(__('Invalid monitor')); } @@ -23,31 +23,20 @@ } $this->set('monitor', $monitor); - $zmBandwidth = $this->Cookie->read('zmBandwidth'); - $bandwidth_short = strtoupper($zmBandwidth[0]); - $ZM_WEB_STREAM_METHOD = $this->Config->find('all', array( - 'fields' => array('Value'), - 'conditions' => array('Category' => $zmBandwidth.'band', 'Name' => 'ZM_WEB_'.$bandwidth_short.'_STREAM_METHOD') + $zmBandwidth = $this->Cookie->read('zmBandwidth'); + + $ZM_MPEG_LIVE_FORMAT = $this->Config->find('first', array( + 'fields' => array('Value'), 'conditions' => array('Name' => 'ZM_MPEG_LIVE_FORMAT') )); - $ZM_MPEG_LIVE_FORMAT = $this->Config->find('all', array( - 'fields' => array('Value'), - 'conditions' => array('Name' => 'ZM_MPEG_LIVE_FORMAT') - )); - $ZM_WEB_VIDEO_BITRATE = $this->Config->find('all', array( - 'fields' => array('Value'), - 'conditions' => array('Category' => $zmBandwidth.'band', 'Name' => 'ZM_WEB_'.$bandwidth_short.'_VIDEO_BITRATE') - )); - $ZM_WEB_VIDEO_MAXFPS = $this->Config->find('all', array( - 'fields' => array('Value'), - 'conditions' => array('Category' => $zmBandwidth.'band', 'Name' => 'ZM_WEB_'.$bandwidth_short.'_VIDEO_MAXFPS') - )); - $ZM_WEB_VIDEO_MAXFPS = $ZM_WEB_VIDEO_MAXFPS[0]['Config']['Value']; - $ZM_WEB_VIDEO_BITRATE = $ZM_WEB_VIDEO_BITRATE[0]['Config']['Value']; - $ZM_MPEG_LIVE_FORMAT = $ZM_MPEG_LIVE_FORMAT[0]['Config']['Value']; + + $ZM_WEB_STREAM_METHOD = $this->Config->getWebOption('ZM_WEB_STREAM_METHOD', $zmBandwidth); + $ZM_WEB_VIDEO_BITRATE = $this->Config->getWebOption('ZM_WEB_VIDEO_BITRATE', $zmBandwidth); + $ZM_WEB_VIDEO_MAXFPS = $this->Config->getWebOption('ZM_WEB_VIDEO_MAXFPS', $zmBandwidth); + $ZM_MPEG_LIVE_FORMAT = $ZM_MPEG_LIVE_FORMAT['Config']['Value']; $buffer = $monitor['Monitor']['StreamReplayBuffer']; - if ($ZM_WEB_STREAM_METHOD[0]['Config']['Value'] == 'mpeg' && $ZM_MPEG_LIVE_FORMAT) { + if ($ZM_WEB_STREAM_METHOD == 'mpeg' && $ZM_MPEG_LIVE_FORMAT) { $this->set('streamSrc', "/cgi-bin/nph-zms?mode=mpeg&scale=100&maxfps=$ZM_WEB_VIDEO_MAXFPS&bitrate=$ZM_WEB_VIDEO_BITRATE&format=$ZM_MPEG_LIVE_FORMAT"); } else { $this->set('streamSrc', "/cgi-bin/nph-zms?mode=jpeg&scale=100&maxfps=$ZM_WEB_VIDEO_MAXFPS&buffer=$buffer"); diff --git a/web/app/Model/Config.php b/web/app/Model/Config.php index cd3a4adc6..083d243f5 100644 --- a/web/app/Model/Config.php +++ b/web/app/Model/Config.php @@ -2,5 +2,19 @@ class Config extends AppModel { public $useTable = 'Config'; public $primaryKey = 'Name'; + + public function getWebOption($name, $zmBandwidth) { + $name_begin = substr($name, 0, 7); + $name_end = substr($name, 6); + $bandwidth_short = strtoupper($zmBandwidth[0]); + $option = $name_begin . $bandwidth_short . $name_end; + + $ZM_OPTIONS = $this->find('first', array( + 'fields' => array('Value'), + 'conditions' => array('Category' => $zmBandwidth.'band', 'Name' => $option) + )); + + return($ZM_OPTIONS['Config']['Value']); + } } ?>