From f385db2d801dfbd43096cf3b0120c73c97bb0c5d Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Tue, 24 Sep 2013 12:54:37 -0400 Subject: [PATCH] Moved the scaling of streams from JS to PHP The Monitor model is now smart enough to change the stream's scale. It also has the option of not scaling at all (in the case of the single monitor view). --- web/app/Controller/MonitorsController.php | 6 ++---- web/app/Model/Monitor.php | 11 ++++++++--- web/app/View/Monitors/index.ctp | 7 ++++--- web/app/webroot/js/main.js | 12 ------------ 4 files changed, 14 insertions(+), 22 deletions(-) diff --git a/web/app/Controller/MonitorsController.php b/web/app/Controller/MonitorsController.php index 98c2da920..d6364536b 100755 --- a/web/app/Controller/MonitorsController.php +++ b/web/app/Controller/MonitorsController.php @@ -4,14 +4,12 @@ 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', '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']); + $monitors[$key]['img'] = $this->Monitor->getStreamSrc($value['Monitor']['Id'], $zmBandwidth, $value['Monitor']['StreamReplayBuffer'], $value['Monitor']['Function'], $value['Monitor']['Enabled'], $value['Monitor']['Name'], $value['Monitor']['Width']); } $this->set('monitors', $monitors); } @@ -30,7 +28,7 @@ $zmBandwidth = $this->Cookie->read('zmBandwidth'); $buffer = $monitor['Monitor']['StreamReplayBuffer']; - $this->set('streamSrc', $this->Monitor->getStreamSrc($id, $zmBandwidth, $buffer, $monitor['Monitor']['Function'], $monitor['Monitor']['Enabled'], $monitor['Monitor']['Name'])); + $this->set('streamSrc', $this->Monitor->getStreamSrc($id, $zmBandwidth, $buffer, $monitor['Monitor']['Function'], $monitor['Monitor']['Enabled'], $monitor['Monitor']['Name'], $monitor['Monitor']['Width'], false)); } public function edit($id = null) { diff --git a/web/app/Model/Monitor.php b/web/app/Model/Monitor.php index 6730d48d5..b48d02cb1 100644 --- a/web/app/Model/Monitor.php +++ b/web/app/Model/Monitor.php @@ -15,8 +15,9 @@ ) ); - public function getStreamSrc($id = null, $zmBandwidth, $buffer, $function, $enabled, $name) { + public function getStreamSrc($id = null, $zmBandwidth, $buffer, $function, $enabled, $name, $width, $scale = true) { $img['id'] = "livestream_$id"; + $img['width'] = $width; $ZM_MPEG_LIVE_FORMAT = Configure::read('ZM_MPEG_LIVE_FORMAT'); $ZM_WEB_STREAM_METHOD = ClassRegistry::init('Config')->getWebOption('ZM_WEB_STREAM_METHOD', $zmBandwidth); @@ -27,10 +28,14 @@ if (Configure::read('daemonStatus') && $function != "None" && $enabled) { $img['alt'] = "Live stream of $name"; if ($ZM_WEB_STREAM_METHOD == 'mpeg' && $ZM_MPEG_LIVE_FORMAT) { - $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"; + $img['src'] = "/cgi-bin/nph-zms?mode=mpeg&maxfps=$ZM_WEB_VIDEO_MAXFPS&bitrate=$ZM_WEB_VIDEO_BITRATE&format=$ZM_MPEG_LIVE_FORMAT&monitor=$id"; } else { - $img['src'] = "/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&maxfps=$ZM_WEB_VIDEO_MAXFPS&buffer=$buffer&monitor=$id"; } + if ($scale) { + $scale = (Configure::read('ZM_WEB_LIST_THUMB_WIDTH') / $width) * 100; + $img['src'] .= '&scale=' . $scale; + } } else { $img['src'] = "/img/no-image.png"; $img['alt'] = "No live stream available for $name"; diff --git a/web/app/View/Monitors/index.ctp b/web/app/View/Monitors/index.ctp index 6574eae31..49aa45d65 100755 --- a/web/app/View/Monitors/index.ctp +++ b/web/app/View/Monitors/index.ctp @@ -4,13 +4,14 @@ $this->end(); ?> -
+
$mon): ?> -
+
Html->image($mon['img']['src'], array( 'alt' => $mon['img']['alt'], - 'id' => $mon['img']['id'] + 'id' => $mon['img']['id'], + 'width' => Configure::read('ZM_WEB_LIST_THUMB_WIDTH') )); ?>

Html->link($mon['Monitor']['Name'],array('controller' => 'monitors', 'action' => 'view', $mon['Monitor']['Id'])); ?>

diff --git a/web/app/webroot/js/main.js b/web/app/webroot/js/main.js index 5d57f92cd..69aec75ef 100755 --- a/web/app/webroot/js/main.js +++ b/web/app/webroot/js/main.js @@ -211,18 +211,6 @@ $(document).ready(function() { }); }); - - $(".livestream_resize").each(function(index, element){ - if($(element).attr('src').indexOf('scale=') >= 0){ - var newScale = Math.ceil(($(element).width() / $(element).attr('width')) * 100); - var src = $(element).attr('src').replace('scale=100', 'scale='+newScale); - $(element).attr('src', src); - console.log("resized"); - } - }); - - return false; - // Monitors // });