Rewrote the way that monitor streams are created.

No longer need LiveStreamHelper, and the logic of which image to
display (live or placeholder) has been moved to the Moniors model.
This way should be much easier to understand and support.  This also
fixes my 'ugly hack' in commit eed6c81287
pull/177/merge
Kyle Johnson 2013-09-24 08:56:04 -04:00
parent 22f9ba5c38
commit 2fa0d3a284
4 changed files with 29 additions and 27 deletions

View File

@ -5,13 +5,15 @@
public function index() {
$zmBandwidth = $this->Cookie->read('zmBandwidth');
$this->set('width', Configure::read('ZM_WEB_LIST_THUMB_WIDTH'));
$monitoroptions = array('fields' => array('Name', 'Id', 'Function', 'Enabled', 'Sequence', 'Function', 'Width'), 'order' => 'Sequence ASC', 'recursive' => -1);
$this->set('monitors', $this->Monitor->find('all', $monitoroptions));
$monitors = $this->Monitor->find('all', array('recursive' => -1, 'fields' => array('Id', 'StreamReplayBuffer')));
foreach ($monitors as $monitor => $mon) {
$streamSrc[$mon['Monitor']['Id']] = $this->Monitor->getStreamSrc($mon['Monitor']['Id'], $zmBandwidth, $monitor['Monitor']['StreamReplayBuffer']);
$monitoroptions = array('fields' => array('Name', 'Id', 'Function', 'Enabled', 'Sequence', 'Function', 'Width', 'StreamReplayBuffer'), 'order' => 'Sequence ASC', 'recursive' => -1);
$monitors = $this->Monitor->find('all', $monitoroptions);
foreach ($monitors as $key => $value) {
$monitors[$key]['img'] = $this->Monitor->getStreamSrc($value['Monitor']['Id'], $zmBandwidth, $value['Monitor']['StreamReplayBuffer'], $value['Monitor']['Function'], $value['Monitor']['Enabled'], $value['Monitor']['Name']);
}
$this->set('streamSrc', $streamSrc);
$this->set('monitors', $monitors);
}
public function view($id = null) {
@ -28,8 +30,7 @@
$zmBandwidth = $this->Cookie->read('zmBandwidth');
$buffer = $monitor['Monitor']['StreamReplayBuffer'];
$this->set('streamSrc', $this->Monitor->getStreamSrc($id, $zmBandwidth, $buffer));
$this->set('streamSrc', $this->Monitor->getStreamSrc($id, $zmBandwidth, $buffer, $monitor['Monitor']['Function'], $monitor['Monitor']['Enabled'], $monitor['Monitor']['Name']));
}
public function edit($id = null) {

View File

@ -15,7 +15,8 @@
)
);
public function getStreamSrc($id = null, $zmBandwidth, $buffer) {
public function getStreamSrc($id = null, $zmBandwidth, $buffer, $function, $enabled, $name) {
$img['id'] = "livestream_$id";
$ZM_MPEG_LIVE_FORMAT = Configure::read('ZM_MPEG_LIVE_FORMAT');
$ZM_WEB_STREAM_METHOD = ClassRegistry::init('Config')->getWebOption('ZM_WEB_STREAM_METHOD', $zmBandwidth);
@ -23,12 +24,18 @@
$ZM_WEB_VIDEO_MAXFPS = ClassRegistry::init('Config')->getWebOption('ZM_WEB_VIDEO_MAXFPS', $zmBandwidth);
$ZM_MPEG_LIVE_FORMAT = $ZM_MPEG_LIVE_FORMAT;
if (Configure::read('daemonStatus') && $function != "None" && $enabled) {
$img['alt'] = "Live stream of $name";
if ($ZM_WEB_STREAM_METHOD == 'mpeg' && $ZM_MPEG_LIVE_FORMAT) {
return "/cgi-bin/nph-zms?mode=mpeg&scale=100&maxfps=$ZM_WEB_VIDEO_MAXFPS&bitrate=$ZM_WEB_VIDEO_BITRATE&format=$ZM_MPEG_LIVE_FORMAT&monitor=$id";
$img['src'] = "/cgi-bin/nph-zms?mode=mpeg&scale=100&maxfps=$ZM_WEB_VIDEO_MAXFPS&bitrate=$ZM_WEB_VIDEO_BITRATE&format=$ZM_MPEG_LIVE_FORMAT&monitor=$id";
} else {
return "/cgi-bin/nph-zms?mode=jpeg&scale=100&maxfps=$ZM_WEB_VIDEO_MAXFPS&buffer=$buffer&monitor=$id";
$img['src'] = "/cgi-bin/nph-zms?mode=jpeg&scale=100&maxfps=$ZM_WEB_VIDEO_MAXFPS&buffer=$buffer&monitor=$id";
}
} else {
$img['src'] = "/img/no-image.png";
$img['alt'] = "No live stream available for $name";
}
return $img;
}
}
?>

View File

@ -9,14 +9,11 @@
<div class="col-md-4" id="Monitor_<?= $mon['Monitor']['Id']; ?>">
<div class="thumbnail">
<?php
if($daemonStatus && $mon['Monitor']['Function'] != "None" && $mon['Monitor']['Enabled']) {
echo $this->Html->image($streamSrc[$mon['Monitor']['Id']], array(
'alt' => 'Live stream of ' . $mon['Monitor']['Name'],
'id' => 'liveStream_' . $mon['Monitor']['Id'],
));
} else {
echo $this->LiveStream->showNoImage($mon['Monitor']['Name'], $streamSrc[$monitor], $mon['Monitor']['Id'], $width);
}
debug($mon);
echo $this->Html->image($mon['img']['src'], array(
'alt' => $mon['img']['alt'],
'id' => $mon['img']['id']
));
?>
<div class="caption">
<h4><?php echo $this->Html->link($mon['Monitor']['Name'],array('controller' => 'monitors', 'action' => 'view', $mon['Monitor']['Id'])); ?></h4>

View File

@ -1,11 +1,8 @@
<h2><?php echo $monitor['Monitor']['Name']; ?> Live Stream</h2>
<?php
if($daemonStatus && $monitor['Monitor']['Function'] != "None" && $monitor['Monitor']['Enabled'])
echo $this->Html->image($streamSrc, array(
'alt' => 'Live stream of ' . $monitor['Monitor']['Name'],
'id' => 'liveStream_' . $monitor['Monitor']['Id']
));
else
echo $this->LiveStream->showNoImage($monitor['Monitor']['Name'], $streamSrc, $monitor['Monitor']['Id']);
echo $this->Html->image($streamSrc['src'], array(
'alt' => $streamSrc['alt'],
'id' => $streamSrc['id']
));
?>