From 0ed29c8bb8f754f3da9ab16969513006ef406eb2 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sun, 19 Jan 2014 13:21:51 +0200 Subject: [PATCH] added a config option to disable server side image resizing --- src/config.py | 3 +++ src/handlers.py | 3 ++- src/mediafiles.py | 2 +- static/js/main.js | 34 +++++++++++++++++++++++++++++++--- templates/main.html | 5 +++++ 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/src/config.py b/src/config.py index 75f63cf..3f7f968 100644 --- a/src/config.py +++ b/src/config.py @@ -442,6 +442,7 @@ def camera_ui_to_dict(ui): 'webcam_maxrate': int(ui['streaming_framerate']), 'webcam_quality': max(1, int(ui['streaming_quality'])), '@webcam_resolution': max(1, int(ui['streaming_resolution'])), + '@webcam_server_resize': ui['streaming_server_resize'], 'webcam_motion': ui['streaming_motion'], # still images @@ -613,6 +614,7 @@ def camera_dict_to_ui(data): 'streaming_framerate': int(data['webcam_maxrate']), 'streaming_quality': int(data['webcam_quality']), 'streaming_resolution': int(data['@webcam_resolution']), + 'streaming_server_resize': int(data['@webcam_server_resize']), 'streaming_port': int(data['webcam_port']), 'streaming_motion': int(data['webcam_motion']), @@ -953,6 +955,7 @@ def _set_default_motion_camera(camera_id, data): data.setdefault('webcam_maxrate', 5) data.setdefault('webcam_quality', 85) data.setdefault('@webcam_resolution', 100) + data.setdefault('@webcam_server_resize', True) data.setdefault('webcam_motion', False) data.setdefault('text_left', data['@name']) diff --git a/src/handlers.py b/src/handlers.py index f4622f7..c3cb531 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -294,7 +294,8 @@ class ConfigHandler(BaseHandler): if camera_id is not None: if camera_id == 0: # multiple camera configs - logging.debug('setting multiple configs') + if len(ui_config) > 1: + logging.debug('setting multiple configs') so_far = [0] def check_finished(e, r): diff --git a/src/mediafiles.py b/src/mediafiles.py index 03538ba..af01a8f 100644 --- a/src/mediafiles.py +++ b/src/mediafiles.py @@ -378,7 +378,7 @@ def get_picture_cache(camera_id, sequence, width): cache = _current_pictures_cache.setdefault(camera_id, []) for (seq, w, content) in cache: - if (seq >= sequence) and (width >= w): + if (seq >= sequence) and ((width is w is None) or (width >= w)): return content return None diff --git a/static/js/main.js b/static/js/main.js index 61e6147..4b01724 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -77,6 +77,16 @@ Object.keys = Object.keys || (function () { }; })(); +Object.update = function (dest, source) { + for (var key in source) { + if (!source.hasOwnProperty(key)) { + continue; + } + + dest[key] = source[key]; + } +}; + Array.prototype.indexOf = Array.prototype.indexOf || function (obj) { for (var i = 0; i < this.length; i++) { if (this[i] === obj) { @@ -232,6 +242,7 @@ function initUI() { $('#videoDeviceSwitch').change(updateConfigUi); $('#textOverlaySwitch').change(updateConfigUi); $('#videoStreamingSwitch').change(updateConfigUi); + $('#streamingServerResizeSwitch').change(updateConfigUi); $('#stillImagesSwitch').change(updateConfigUi); $('#motionMoviesSwitch').change(updateConfigUi); $('#motionNotificationsSwitch').change(updateConfigUi); @@ -403,6 +414,11 @@ function updateConfigUi() { $('#videoStreamingSwitch').parent().next('table.settings').find('tr.settings-item').not('.local-streaming').each(markHide); } + /* streaming server resize switch */ + if (!$('#streamingServerResizeSwitch').get(0).checked) { + $('#streamingResolutionSlider').parents('tr:eq(0)').each(markHide); + } + /* still images switch */ if (!$('#stillImagesSwitch').get(0).checked) { $('#stillImagesSwitch').parent().next('table.settings').find('tr.settings-item').each(markHide); @@ -552,6 +568,7 @@ function cameraUi2Dict() { 'streaming_framerate': $('#streamingFramerateSlider').val(), 'streaming_quality': $('#streamingQualitySlider').val(), 'streaming_resolution': $('#streamingResolutionSlider').val(), + 'streaming_server_resize': $('#streamingServerResizeSwitch')[0].checked, 'streaming_port': $('#streamingPortEntry').val(), 'streaming_motion': $('#streamingMotion')[0].checked, @@ -683,6 +700,7 @@ function dict2CameraUi(dict) { $('#streamingFramerateSlider').val(dict['streaming_framerate']); $('#streamingQualitySlider').val(dict['streaming_quality']); $('#streamingResolutionSlider').val(dict['streaming_resolution']); + $('#streamingServerResizeSwitch')[0].checked = dict['streaming_server_resize']; $('#streamingPortEntry').val(dict['streaming_port']); $('#streamingMotion')[0].checked = dict['streaming_motion']; @@ -1068,6 +1086,9 @@ function pushCameraConfig() { if (!isApplyVisible()) { showApply(); } + + /* also update the config stored in the camera frame div */ + Object.update($('div.camera-frame#camera' + cameraId)[0].config, cameraConfig); } function pushPreview(control) { @@ -1929,7 +1950,7 @@ function doFullScreenCamera(cameraId) { } function refreshCameraFrames() { - function refreshCameraFrame(cameraId, img, fast) { + function refreshCameraFrame(cameraId, img, fast, serverSideResize) { if (refreshDisabled[cameraId]) { /* camera refreshing disabled, retry later */ @@ -1952,7 +1973,13 @@ function refreshCameraFrames() { timestamp /= 500; } timestamp = Math.round(timestamp); - img.src = '/picture/' + cameraId + '/current/?seq=' + timestamp + '&width=' + img.width; + + var uri = '/picture/' + cameraId + '/current/?seq=' + timestamp; + if (serverSideResize) { + uri += '&width=' + img.width; + } + + img.src = uri; img.loading = 1; } @@ -1967,6 +1994,7 @@ function refreshCameraFrames() { cameraFrames.each(function () { /* limit the refresh rate to 10 fps */ var count = Math.max(1, 10 / this.framerate); + var serverSideResize = this.config['streaming_server_resize']; var img = $(this).find('img.camera')[0]; if (img.error) { @@ -1979,7 +2007,7 @@ function refreshCameraFrames() { } else { var cameraId = this.id.substring(6); - refreshCameraFrame(cameraId, img, count <= 2); /* count <= 2 means at least 5 fps */ + refreshCameraFrame(cameraId, img, count <= 2, serverSideResize); /* count <= 2 means at least 5 fps */ this.refreshDivider = 0; } diff --git a/templates/main.html b/templates/main.html index b20fed6..89b54ef 100644 --- a/templates/main.html +++ b/templates/main.html @@ -250,6 +250,11 @@ ? + + Streaming Image Resizing + + ? + Streaming Resolution -- 2.39.5