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) { public function view($id = null) {
$this->loadMOdel('Config'); $this->loadModel('Config');
if (!$id) { if (!$id) {
throw new NotFoundException(__('Invalid monitor')); throw new NotFoundException(__('Invalid monitor'));
} }
@ -23,31 +23,20 @@
} }
$this->set('monitor', $monitor); $this->set('monitor', $monitor);
$zmBandwidth = $this->Cookie->read('zmBandwidth');
$bandwidth_short = strtoupper($zmBandwidth[0]);
$ZM_WEB_STREAM_METHOD = $this->Config->find('all', array( $zmBandwidth = $this->Cookie->read('zmBandwidth');
'fields' => array('Value'),
'conditions' => array('Category' => $zmBandwidth.'band', 'Name' => 'ZM_WEB_'.$bandwidth_short.'_STREAM_METHOD') $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'), $ZM_WEB_STREAM_METHOD = $this->Config->getWebOption('ZM_WEB_STREAM_METHOD', $zmBandwidth);
'conditions' => array('Name' => 'ZM_MPEG_LIVE_FORMAT') $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_WEB_VIDEO_BITRATE = $this->Config->find('all', array( $ZM_MPEG_LIVE_FORMAT = $ZM_MPEG_LIVE_FORMAT['Config']['Value'];
'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'];
$buffer = $monitor['Monitor']['StreamReplayBuffer']; $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"); $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 { } else {
$this->set('streamSrc', "/cgi-bin/nph-zms?mode=jpeg&scale=100&maxfps=$ZM_WEB_VIDEO_MAXFPS&buffer=$buffer"); $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 { class Config extends AppModel {
public $useTable = 'Config'; public $useTable = 'Config';
public $primaryKey = 'Name'; 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']);
}
} }
?> ?>