Moved some of the logic for determining video streaming options from the controller to the model

This commit is contained in:
Kyle Johnson 2013-05-07 11:15:06 -04:00
parent b5e15a1708
commit 74008dcb8b
2 changed files with 25 additions and 22 deletions

View File

@ -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");

View File

@ -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']);
}
}
?>