diff --git a/README.md b/README.md index b8e3f34fd..b0f4be37b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ZoneMinder [![Build Status](https://travis-ci.org/ZoneMinder/zoneminder.png)](https://travis-ci.org/ZoneMinder/zoneminder) [![Bountysource](https://api.bountysource.com/badge/team?team_id=204&style=bounties_received)](https://www.bountysource.com/teams/zoneminder/issues?utm_source=ZoneMinder&utm_medium=shield&utm_campaign=bounties_received) -[![Join Slack](https://github.com/ozonesecurity/ozonebase/blob/master/img/slacksm.png?raw=true)](https://zoneminder-chat.herokuapp.com) +[![Join Slack](https://github.com/ozonesecurity/ozonebase/blob/master/img/slacksm.png?raw=true)](https://join.slack.com/t/zoneminder-chat/shared_invite/enQtNTU0NDkxMDM5NDQwLTlhZDU2MGU4MmZmN2MxOTg1MmNmNmZjZGRmY2EzMThhNGQ0MWNmZTg1ZmYzNDQ4YjliMzVmYTQ3MDc5MTkzODE) All documentation for ZoneMinder is now online at https://zoneminder.readthedocs.org diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index 1d3c7446d..fd67c1323 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -790,6 +790,7 @@ INSERT INTO `Controls` VALUES (NULL,'Trendnet','Remote','Trendnet',1,1,1,0,0,0,0 INSERT INTO `Controls` VALUES (NULL,'PSIA','Remote','PSIA',0,0,0,1,0,0,1,0,0,0,0,0,0,0,100,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,20,0,1,1,1,0,0,1,0,1,0,0,0,0,1,-100,100,0,0,1,0,0,0,0,1,-100,100,0,0,0,0); INSERT INTO `Controls` VALUES (NULL,'Dahua','Remote','Dahua',0,0,0,1,0,0,1,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,20,0,1,1,1,0,0,1,0,1,0,0,0,0,1,1,8,0,0,1,0,0,0,0,1,1,8,0,0,0,0); INSERT INTO `Controls` VALUES (NULL,'FOSCAMR2C','Libvlc','FOSCAMR2C',1,1,1,0,0,0,0,0,NULL,NULL,NULL,NULL,0,NULL,NULL,0,0,0,0,0,NULL,NULL,NULL,NULL,0,NULL,NULL,0,0,0,0,0,NULL,NULL,NULL,NULL,0,NULL,NULL,0,0,0,0,0,NULL,NULL,NULL,NULL,0,NULL,NULL,0,0,0,0,0,NULL,NULL,NULL,NULL,0,NULL,NULL,1,12,0,1,1,1,0,0,0,1,1,NULL,NULL,NULL,NULL,1,0,4,0,NULL,1,NULL,NULL,NULL,NULL,1,0,4,0,NULL,0,0); +INSERT INTO `Controls` VALUES (NULL,'Amcrest HTTP API','Ffmpeg','Amcrest_HTTP',0,0,1,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,5,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,5); -- -- Add some monitor preset values diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Control/Amcrest_HTTP.pm b/scripts/ZoneMinder/lib/ZoneMinder/Control/Amcrest_HTTP.pm new file mode 100644 index 000000000..7a89f353e --- /dev/null +++ b/scripts/ZoneMinder/lib/ZoneMinder/Control/Amcrest_HTTP.pm @@ -0,0 +1,403 @@ +# ========================================================================== +# +# ZoneMinder Acrest HTTP API Control Protocol Module, 20180214, Rev 3.0 +# +# Change Log +# +# Rev 3.0: +# - Fixes incorrect method names +# - Updates control sequences to Amcrest HTTP Protocol API v 2.12 +# - Extends control features +# +# Rev 2.0: +# - Fixed installation instructions text, no changes to functionality. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# ========================================================================== + +package ZoneMinder::Control::Amcrest_HTTP; + +use 5.006; +use strict; +use warnings; + +use Time::HiRes qw( usleep ); + +require ZoneMinder::Base; +require ZoneMinder::Control; + +our @ISA = qw(ZoneMinder::Control); + +# ========================================================================== +# +# Amcrest HTTP API Control Protocol +# +# ========================================================================== + +use ZoneMinder::Logger qw(:all); +use ZoneMinder::Config qw(:all); + +sub new +{ + my $class = shift; + my $id = shift; + my $self = ZoneMinder::Control->new( $id ); + bless( $self, $class ); + srand( time() ); + return $self; +} + +our $AUTOLOAD; + +sub AUTOLOAD +{ + my $self = shift; + my $class = ref($self) || croak( "$self not object" ); + my $name = $AUTOLOAD; + $name =~ s/.*://; + Debug( "Received command: $name" ); + if ( exists($self->{$name}) ) + { + return( $self->{$name} ); + } + Fatal( "Can't access $name member of object of class $class" ); +} + +sub open +{ + my $self = shift; + + $self->loadMonitor(); + $self->{state} = 'open'; +} + +sub initUA +{ + my $self = shift; + my $user = undef; + my $password = undef; + my $address = undef; + + if ( $self->{Monitor}->{ControlAddress} =~ /(.*):(.*)@(.*)/ ) + { + $user = $1; + $password = $2; + $address = $3; + } + + use LWP::UserAgent; + $self->{ua} = LWP::UserAgent->new; + $self->{ua}->credentials("$address", "Login to " . $self->{Monitor}->{ControlDevice}, "$user", "$password"); + $self->{ua}->agent( "ZoneMinder Control Agent/".ZoneMinder::Base::ZM_VERSION ); +} + +sub destroyUA +{ + my $self = shift; + + $self->{ua} = undef; +} + +sub close +{ + my $self = shift; + $self->{state} = 'closed'; +} + +sub printMsg +{ + my $self = shift; + my $msg = shift; + my $msg_len = length($msg); + + Debug( $msg."[".$msg_len."]" ); +} + +sub sendCmd +{ + my $self = shift; + my $cmd = shift; + my $result = undef; + + destroyUA($self); + initUA($self); + + my $user = undef; + my $password = undef; + my $address = undef; + + if ( $self->{Monitor}->{ControlAddress} =~ /(.*):(.*)@(.*)/ ) + { + $user = $1; + $password = $2; + $address = $3; + } + + printMsg( $cmd, "Tx" ); + + my $req = HTTP::Request->new( GET=>"http://$address/$cmd" ); + my $res = $self->{ua}->request($req); + + if ( $res->is_success ) + { + $result = !undef; + # Command to camera appears successful, write Info item to log + Info( "Camera control: '".$res->status_line()."' for URL ".$self->{Monitor}->{ControlAddress}."/$cmd" ); + # TODO: Add code to retrieve $res->message_decode or some such. Then we could do things like check the camera status. + } + else + { + Error( "Camera control command FAILED: '".$res->status_line()."' for URL ".$self->{Monitor}->{ControlAddress}."/$cmd" ); + } + + return( $result ); +} + +sub reset +{ + my $self = shift; + # This reboots the camera effectively resetting it + Debug( "Camera Reset" ); + $self->sendCmd( 'cgi-bin/magicBox.cgi?action=reboot' ); + ##FIXME: Exit is a bad idea as it appears to cause zmc to run away. + #Exit (0); +} + +# NOTE: I'm putting this in, but absolute camera movement does not seem to be well supported in the classic skin ATM. +# Reading www/skins/classic/include/control_functions.php seems to indicate a faulty implementation, unless I'm +# reading it wrong. I see nowhere where the user is able to specify the absolute location to move to. Rather, +# the call is passed back movement in increments of 1 unit. At least with the Amcrest/Duhua API this would result +# in the camera moving to the 1* or 0* etc. position. + +sub moveAbs ## Up, Down, Left, Right, etc. ??? Doesn't make sense here... +{ + my $self = shift; + my $pan_degrees = shift || 0; + my $tilt_degrees = shift || 0; + my $speed = shift || 1; + Debug( "Move ABS" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=PositionABS&channel=0&arg1='.$pan_degress.'&arg2='.$tilt_degrees.'&arg3=0&arg4='.$speed ); +} + +sub moveConUp +{ + my $self = shift; + Debug( "Move Up" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=Up&channel=0&arg1=0&arg2=1&arg3=0' ); + usleep (500); ##XXX Should this be passed in as a "speed" parameter? + $self->sendCmd( 'cgi-bin/ptz.cgi?action=stop&code=Up&channel=0&arg1=0&arg2=1&arg3=0' ); +} + +sub moveConDown +{ + my $self = shift; + Debug( "Move Down" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=Down&channel=0&arg1=0&arg2=1&arg3=0' ); + usleep (500); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=stop&code=Down&channel=0&arg1=0&arg2=1&arg3=0' ); +} + +sub moveConLeft +{ + my $self = shift; + Debug( "Move Left" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=Left&channel=0&arg1=0&arg2=1&arg3=0' ); + usleep (500); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=stop&code=Left&channel=0&arg1=0&arg2=1&arg3=0' ); +} + +sub moveConRight +{ + my $self = shift; + Debug( "Move Right" ); +# $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=PositionABS&channel=0&arg1=270&arg2=5&arg3=0' ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=Right&channel=0&arg1=0&arg2=1&arg3=0' ); + usleep (500); + Debug( "Move Right Stop" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=stop&code=Right&channel=0&arg1=0&arg2=1&arg3=0' ); +} + +sub moveConUpRight +{ + my $self = shift; + Debug( "Move Diagonally Up Right" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=RightUp&channel=0&arg1=1&arg2=1&arg3=0' ); + usleep (500); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=stop&code=RightUp&channel=0&arg1=0&arg2=1&arg3=0' ); +} + +sub moveConDownRight +{ + my $self = shift; + Debug( "Move Diagonally Down Right" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=RightDown&channel=0&arg1=1&arg2=1&arg3=0' ); + usleep (500); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=stop&code=RightDown&channel=0&arg1=0&arg2=1&arg3=0' ); +} + +sub moveConUpLeft +{ + my $self = shift; + Debug( "Move Diagonally Up Left" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=LeftUp&channel=0&arg1=1&arg2=1&arg3=0' ); + usleep (500); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=stop&code=LeftUp&channel=0&arg1=0&arg2=1&arg3=0' ); +} + +sub moveConDownLeft +{ + my $self = shift; + Debug( "Move Diagonally Down Left" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=LeftDown&channel=0&arg1=1&arg2=1&arg3=0' ); + usleep (500); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=stop&code=LeftDown&channel=0&arg1=0&arg2=1&arg3=0' ); +} + +# Stop is not "correctly" implemented as control_functions.php translates this to "Center" +# So we'll just send the camera to 0* Horz, 0* Vert, zoom out; Also, Amcrest does not seem to +# support a generic stop-all-current-action command. + +sub moveStop +{ + my $self = shift; + Debug( "Move Stop/Center" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=PositionABS&channel=0&arg1=0&arg2=0&arg3=0&arg4=1' ); +} + +# Move Camera to Home Position +# The current API does not support a Home per se, so we'll just send the camera to preset #1 +# NOTE: It goes without saying that the user must have set up preset #1 for this to work. + +sub presetHome +{ + my $self = shift; + Debug( "Home Preset" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&&arg1=0&arg2=1&arg3=0&arg4=0' ); +} + +sub presetGoto +{ + my $self = shift; + my $params = shift; + my $preset = $self->getParam( $params, 'preset' ); + Debug( "Go To Preset $preset" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&channel=0&code=GotoPreset&&arg1=0&arg2='.$preset.'&arg3=0&arg4=0' ); +} + +sub presetSet +{ + my $self = shift; + my $params = shift; + my $preset = $self->getParam( $params, 'preset' ); + Debug( "Set Preset" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&channel=0&code=SetPreset&arg1=0&arg2='.$preset.'&arg3=0&arg4=0' ); +} + +# NOTE: This does not appear to be implemented in the classic skin. But we'll leave it here for later. + +sub moveMap +{ + my $self = shift; + my $params = shift; + + my $xcoord = $self->getParam( $params, 'xcoord', $self->{Monitor}{Width}/2 ); + my $ycoord = $self->getParam( $params, 'ycoord', $self->{Monitor}{Height}/2 ); + # if the camera is mounted upside down, you may have to inverse these coordinates + # just use 360 minus pan instead of pan, 90 minus tilt instead of tilt + # Convert xcoord into pan position 0 to 359 + my $pan = int(360 * $xcoord / $self->{Monitor}{Width}); + # Convert ycoord into tilt position 0 to 89 + my $tilt = 90 - int(90 * $ycoord / $self->{Monitor}{Height}); + # Now get the following url: + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&code=PositionABS&channel=0&arg1='.$pan.'&arg2='.$tilt.'&arg3=1&arg4=1'); +} + +sub zoomConTele +{ + my $self = shift; + Debug( "Zoom continuous tele" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&channel=0&code=ZoomTele&arg1=0&arg2=0&arg3=0&arg4=0' ); + usleep (100000); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=stop&channel=0&code=ZoomTele&arg1=0&arg2=0&arg3=0&arg4=0' ); +} + +sub zoomConWide +{ + my $self = shift; + Debug( "Zoom continuous wide" ); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=start&channel=0&code=ZoomWide&arg1=0&arg2=0&arg3=0&arg4=0' ); + usleep (100000); + $self->sendCmd( 'cgi-bin/ptz.cgi?action=stop&channel=0&code=ZoomWide&arg1=0&arg2=0&arg3=0&arg4=0' ); +} + +1; + +__END__ + +=pod + +=head1 NAME + +ZoneMinder::Control::Amcrest_HTTP - Amcrest camera control + +=head1 DESCRIPTION + +This module contains the implementation of the Amcrest Camera +controllable SDK API. + +NOTE: This module implements interaction with the camera in clear text. + +The login and password are transmitted from ZM to the camera in clear text, +and as such, this module should be used ONLY on a blind LAN implementation +where interception of the packets is very low risk. + +The "usleep (X);" lines throughout the script may need adjustments for your +situation. This is the time that the script waits between sending a "start" +and a "stop" signal to the camera. For example, the pan left arrow would +result in the camera panning full to its leftmost position if there were no +stop signal. So the usleep time sets how long the script waits to allow the +camera to start moving before issuing a stop. The X value of usleep is in +microseconds, so "usleep (100000);" is equivalent to wait one second. + +=head1 SEE ALSO + +https://s3.amazonaws.com/amcrest-files/Amcrest+HTTP+API+3.2017.pdf + +=head1 AUTHORS + +Herndon Elliott alabamatoy at gmail dot com +Chris Nighswonger chris dot nighswonger at gmail dot com + +=head1 COPYRIGHT AND LICENSE + +(C) 2016 Herndon Elliott alabamatoy at gmail dot com +(C) 2018 Chris Nighswonger chris dot nighswonger at gmail dot com + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +=cut diff --git a/src/zm_camera.cpp b/src/zm_camera.cpp index 43e97f26a..0f21826fd 100644 --- a/src/zm_camera.cpp +++ b/src/zm_camera.cpp @@ -57,14 +57,8 @@ Camera::Camera( imagesize = pixels * colours; Debug(2,"New camera id: %d width: %d height: %d colours: %d subpixelorder: %d capture: %d", - monitor_id,width,height,colours,subpixelorder,capture); + monitor_id, width, height, colours, subpixelorder, capture); - /* Because many loops are unrolled and work on 16 colours/time or 4 pixels/time, we have to meet requirements */ - if ( (colours == ZM_COLOUR_GRAY8 || colours == ZM_COLOUR_RGB32) && (imagesize % 64) != 0 ) { - Fatal("Image size is not multiples of 64"); - } else if ( colours == ZM_COLOUR_RGB24 && ((imagesize % 64) != 0 || (imagesize % 12) != 0) ) { - Fatal("Image size is not multiples of 12 and 64"); - } monitor = NULL; } diff --git a/src/zm_event.cpp b/src/zm_event.cpp index bf9902fd1..d3f79fbfb 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -242,30 +242,19 @@ Event::~Event() { videoStore = NULL; } - if ( frame_data.size() ) - WriteDbFrames(); - - // Should not be static because we are multi-threaded - char sql[ZM_SQL_MED_BUFSIZ]; struct DeltaTimeval delta_time; DELTA_TIMEVAL(delta_time, end_time, start_time, DT_PREC_2); Debug(2, "start_time:%d.%d end_time%d.%d", start_time.tv_sec, start_time.tv_usec, end_time.tv_sec, end_time.tv_usec); if ( frames > last_db_frame ) { Debug(1, "Adding closing frame %d to DB", frames); - snprintf(sql, sizeof(sql), - "INSERT INTO Frames ( EventId, FrameId, TimeStamp, Delta ) VALUES ( %" PRIu64 ", %d, from_unixtime( %ld ), %s%ld.%02ld )", - id, frames, end_time.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec); - db_mutex.lock(); - if ( mysql_query(&dbconn, sql) ) { - db_mutex.unlock(); - Error("Can't insert frame: %s", mysql_error(&dbconn)); - } else { - db_mutex.unlock(); - Debug(1,"Success writing last frame"); - } + frame_data.push(new Frame(id, frames, NORMAL, end_time, delta_time, 0)); } + if ( frame_data.size() ) + WriteDbFrames(); + // Should not be static because we might be multi-threaded + char sql[ZM_SQL_MED_BUFSIZ]; snprintf(sql, sizeof(sql), "UPDATE Events SET Name='%s %" PRIu64 "', EndTime = from_unixtime( %ld ), Length = %s%ld.%02ld, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d, DefaultVideo = '%s' WHERE Id = %" PRIu64, monitor->EventPrefix(), id, end_time.tv_sec, @@ -537,13 +526,12 @@ void Event::WriteDbFrames() { *(sql_ptr-2) = '\0'; db_mutex.lock(); if ( mysql_query(&dbconn, sql) ) { - Error("Can't insert frames: %s", mysql_error(&dbconn)); - Error("SQL was %s", sql); db_mutex.unlock(); + Error("Can't insert frames: %s, sql was %s", mysql_error(&dbconn), sql); return; } db_mutex.unlock(); -} +} // end void Event::WriteDbFrames() void Event::AddFrame(Image *image, struct timeval timestamp, int score, Image *alarm_image) { if ( !timestamp.tv_sec ) { @@ -591,10 +579,10 @@ void Event::AddFrame(Image *image, struct timeval timestamp, int score, Image *a static char sql[ZM_SQL_MED_BUFSIZ]; - frame_data.push( new Frame(id, frames, frame_type, timestamp, delta_time, score ) ); - if ( frame_data.size() > 10 ) { + frame_data.push(new Frame(id, frames, frame_type, timestamp, delta_time, score)); + if ( frame_data.size() > 20 ) { WriteDbFrames(); - Debug(1, "Adding 10 frames to DB"); + Debug(1, "Adding 20 frames to DB"); last_db_frame = frames; } diff --git a/src/zm_image.cpp b/src/zm_image.cpp index 377c84e68..3cecc0802 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -75,6 +75,32 @@ static deinterlace_4field_fptr_t fptr_deinterlace_4field_gray8; /* Pointer to image buffer memory copy function */ imgbufcpy_fptr_t fptr_imgbufcpy; +void Image::update_function_pointers() { + /* Because many loops are unrolled and work on 16 colours/time or 4 pixels/time, we have to meet requirements */ + if ( pixels % 16 || pixels % 12 ) { + // have to use non-loop unrolled functions + delta8_rgb = &std_delta8_rgb; + delta8_bgr = &std_delta8_bgr; + delta8_rgba = &std_delta8_rgba; + delta8_bgra = &std_delta8_bgra; + delta8_argb = &std_delta8_argb; + delta8_abgr = &std_delta8_abgr; + delta8_gray8 = &std_delta8_gray8; + blend = &std_blend; + } else { + // Use either sse or neon, or loop unrolled version + delta8_rgb = fptr_delta8_rgb; + delta8_bgr = fptr_delta8_bgr; + delta8_rgba = fptr_delta8_rgba; + delta8_bgra = fptr_delta8_bgra; + delta8_argb = fptr_delta8_argb; + delta8_abgr = fptr_delta8_abgr; + delta8_gray8 = fptr_delta8_gray8; + blend = fptr_blend; + } +} + +// This constructor is not used anywhere Image::Image() { if ( !initialised ) Initialise(); @@ -89,6 +115,7 @@ Image::Image() { buffertype = 0; holdbuffer = 0; text[0] = '\0'; + blend = fptr_blend; } Image::Image( const char *filename ) { @@ -104,8 +131,9 @@ Image::Image( const char *filename ) { buffer = 0; buffertype = 0; holdbuffer = 0; - ReadJpeg( filename, ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB); + ReadJpeg(filename, ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB); text[0] = '\0'; + update_function_pointers(); } Image::Image( int p_width, int p_height, int p_colours, int p_subpixelorder, uint8_t *p_buffer ) { @@ -127,6 +155,8 @@ Image::Image( int p_width, int p_height, int p_colours, int p_subpixelorder, uin AllocImgBuffer(size); } text[0] = '\0'; + + update_function_pointers(); } Image::Image( const AVFrame *frame ) { @@ -176,6 +206,7 @@ void Image::Assign( const AVFrame *frame ) { av_frame_free( &dest_frame ); sws_freeContext(mConvertContext); mConvertContext = NULL; + update_function_pointers(); } // end Image::Image( const AVFrame *frame ) Image::Image( const Image &p_image ) { @@ -192,6 +223,7 @@ Image::Image( const Image &p_image ) { AllocImgBuffer(size); (*fptr_imgbufcpy)(buffer, p_image.buffer, size); strncpy( text, p_image.text, sizeof(text) ); + update_function_pointers(); } Image::~Image() { @@ -327,20 +359,20 @@ void Image::Initialise() { #endif } else { /* No suitable SSE version available */ - fptr_delta8_rgba = &std_delta8_rgba; - fptr_delta8_bgra = &std_delta8_bgra; - fptr_delta8_argb = &std_delta8_argb; - fptr_delta8_abgr = &std_delta8_abgr; - fptr_delta8_gray8 = &std_delta8_gray8; + fptr_delta8_rgba = &fast_delta8_rgba; + fptr_delta8_bgra = &fast_delta8_bgra; + fptr_delta8_argb = &fast_delta8_argb; + fptr_delta8_abgr = &fast_delta8_abgr; + fptr_delta8_gray8 = &fast_delta8_gray8; Debug(4,"Delta: Using standard delta functions"); } } else { /* CPU extensions disabled */ - fptr_delta8_rgba = &std_delta8_rgba; - fptr_delta8_bgra = &std_delta8_bgra; - fptr_delta8_argb = &std_delta8_argb; - fptr_delta8_abgr = &std_delta8_abgr; - fptr_delta8_gray8 = &std_delta8_gray8; + fptr_delta8_rgba = &fast_delta8_rgba; + fptr_delta8_bgra = &fast_delta8_bgra; + fptr_delta8_argb = &fast_delta8_argb; + fptr_delta8_abgr = &fast_delta8_abgr; + fptr_delta8_gray8 = &fast_delta8_gray8; Debug(4,"Delta: CPU extensions disabled, using standard delta functions"); } @@ -1604,7 +1636,7 @@ void Image::Blend( const Image &image, int transparency ) { #endif /* Do the blending */ - (*fptr_blend)(buffer, image.buffer, new_buffer, size, transparency); + (*blend)(buffer, image.buffer, new_buffer, size, transparency); #ifdef ZM_IMAGE_PROFILING clock_gettime(CLOCK_THREAD_CPUTIME_ID,&end); @@ -1631,7 +1663,7 @@ Image *Image::Merge( unsigned int n_images, Image *images[] ) { } } - Image *result = new Image( width, height, images[0]->colours, images[0]->subpixelorder); + Image *result = new Image(width, height, images[0]->colours, images[0]->subpixelorder); unsigned int size = result->size; for ( unsigned int i = 0; i < size; i++ ) { unsigned int total = 0; @@ -1737,37 +1769,33 @@ void Image::Delta( const Image &image, Image* targetimage) const { clock_gettime(CLOCK_THREAD_CPUTIME_ID,&start); #endif - switch(colours) { + switch (colours) { case ZM_COLOUR_RGB24: - { - if(subpixelorder == ZM_SUBPIX_ORDER_BGR) { - /* BGR subpixel order */ - (*fptr_delta8_bgr)(buffer, image.buffer, pdiff, pixels); - } else { - /* Assume RGB subpixel order */ - (*fptr_delta8_rgb)(buffer, image.buffer, pdiff, pixels); - } - break; + if ( subpixelorder == ZM_SUBPIX_ORDER_BGR ) { + /* BGR subpixel order */ + (*delta8_bgr)(buffer, image.buffer, pdiff, pixels); + } else { + /* Assume RGB subpixel order */ + (*delta8_rgb)(buffer, image.buffer, pdiff, pixels); } + break; case ZM_COLOUR_RGB32: - { - if(subpixelorder == ZM_SUBPIX_ORDER_ARGB) { - /* ARGB subpixel order */ - (*fptr_delta8_argb)(buffer, image.buffer, pdiff, pixels); - } else if(subpixelorder == ZM_SUBPIX_ORDER_ABGR) { - /* ABGR subpixel order */ - (*fptr_delta8_abgr)(buffer, image.buffer, pdiff, pixels); - } else if(subpixelorder == ZM_SUBPIX_ORDER_BGRA) { - /* BGRA subpixel order */ - (*fptr_delta8_bgra)(buffer, image.buffer, pdiff, pixels); - } else { - /* Assume RGBA subpixel order */ - (*fptr_delta8_rgba)(buffer, image.buffer, pdiff, pixels); - } - break; + if ( subpixelorder == ZM_SUBPIX_ORDER_ARGB ) { + /* ARGB subpixel order */ + (*delta8_argb)(buffer, image.buffer, pdiff, pixels); + } else if(subpixelorder == ZM_SUBPIX_ORDER_ABGR) { + /* ABGR subpixel order */ + (*delta8_abgr)(buffer, image.buffer, pdiff, pixels); + } else if(subpixelorder == ZM_SUBPIX_ORDER_BGRA) { + /* BGRA subpixel order */ + (*delta8_bgra)(buffer, image.buffer, pdiff, pixels); + } else { + /* Assume RGBA subpixel order */ + (*delta8_rgba)(buffer, image.buffer, pdiff, pixels); } + break; case ZM_COLOUR_GRAY8: - (*fptr_delta8_gray8)(buffer, image.buffer, pdiff, pixels); + (*delta8_gray8)(buffer, image.buffer, pdiff, pixels); break; default: Panic("Delta called with unexpected colours: %d",colours); @@ -1780,7 +1808,7 @@ void Image::Delta( const Image &image, Image* targetimage) const { executetime = (1000000000ull * diff.tv_sec) + diff.tv_nsec; milpixels = (unsigned long)((long double)pixels)/((((long double)executetime)/1000)); - Debug(5, "Delta: %u delta pixels generated in %llu nanoseconds, %lu million pixels/s\n",pixels,executetime,milpixels); + Debug(5, "Delta: %u delta pixels generated in %llu nanoseconds, %lu million pixels/s",pixels,executetime,milpixels); #endif } @@ -2069,9 +2097,9 @@ void Image::DeColourise() { subpixelorder = ZM_SUBPIX_ORDER_NONE; size = width * height; - if(colours == ZM_COLOUR_RGB32 && config.cpu_extensions && sseversion >= 35) { + if ( colours == ZM_COLOUR_RGB32 && config.cpu_extensions && sseversion >= 35 ) { /* Use SSSE3 functions */ - switch(subpixelorder) { + switch (subpixelorder) { case ZM_SUBPIX_ORDER_BGRA: ssse3_convert_bgra_gray8(buffer,buffer,pixels); break; @@ -2089,40 +2117,70 @@ void Image::DeColourise() { } else { /* Use standard functions */ if ( colours == ZM_COLOUR_RGB32 ) { - switch(subpixelorder) { - case ZM_SUBPIX_ORDER_BGRA: - std_convert_bgra_gray8(buffer,buffer,pixels); - break; - case ZM_SUBPIX_ORDER_ARGB: - std_convert_argb_gray8(buffer,buffer,pixels); - break; - case ZM_SUBPIX_ORDER_ABGR: - std_convert_abgr_gray8(buffer,buffer,pixels); - break; - case ZM_SUBPIX_ORDER_RGBA: - default: - std_convert_rgba_gray8(buffer,buffer,pixels); - break; - } + if ( pixels % 16 ) { + switch (subpixelorder) { + case ZM_SUBPIX_ORDER_BGRA: + std_convert_bgra_gray8(buffer,buffer,pixels); + break; + case ZM_SUBPIX_ORDER_ARGB: + std_convert_argb_gray8(buffer,buffer,pixels); + break; + case ZM_SUBPIX_ORDER_ABGR: + std_convert_abgr_gray8(buffer,buffer,pixels); + break; + case ZM_SUBPIX_ORDER_RGBA: + default: + std_convert_rgba_gray8(buffer,buffer,pixels); + break; + } + } else { + switch (subpixelorder) { + case ZM_SUBPIX_ORDER_BGRA: + fast_convert_bgra_gray8(buffer,buffer,pixels); + break; + case ZM_SUBPIX_ORDER_ARGB: + fast_convert_argb_gray8(buffer,buffer,pixels); + break; + case ZM_SUBPIX_ORDER_ABGR: + fast_convert_abgr_gray8(buffer,buffer,pixels); + break; + case ZM_SUBPIX_ORDER_RGBA: + default: + fast_convert_rgba_gray8(buffer,buffer,pixels); + break; + } + } // end if pixels % 16 to use loop unrolled functions } else { /* Assume RGB24 */ - switch(subpixelorder) { - case ZM_SUBPIX_ORDER_BGR: - std_convert_bgr_gray8(buffer,buffer,pixels); - break; - case ZM_SUBPIX_ORDER_RGB: - default: - std_convert_rgb_gray8(buffer,buffer,pixels); - break; - } - } + if ( pixels % 12 ) { + switch (subpixelorder) { + case ZM_SUBPIX_ORDER_BGR: + std_convert_bgr_gray8(buffer,buffer,pixels); + break; + case ZM_SUBPIX_ORDER_RGB: + default: + std_convert_rgb_gray8(buffer,buffer,pixels); + break; + } + } else { + switch (subpixelorder) { + case ZM_SUBPIX_ORDER_BGR: + fast_convert_bgr_gray8(buffer,buffer,pixels); + break; + case ZM_SUBPIX_ORDER_RGB: + default: + fast_convert_rgb_gray8(buffer,buffer,pixels); + break; + } + } // end if pixels % 12 to use loop unrolled functions + } } } /* RGB32 compatible: complete */ void Image::Fill( Rgb colour, const Box *limits ) { if ( !(colours == ZM_COLOUR_GRAY8 || colours == ZM_COLOUR_RGB24 || colours == ZM_COLOUR_RGB32 ) ) { - Panic( "Attempt to fill image with unexpected colours %d", colours ); + Panic("Attempt to fill image with unexpected colours %d", colours); } /* Convert the colour's RGBA subpixel order into the image's subpixel order */ @@ -3279,7 +3337,7 @@ __attribute__((noinline)) void std_blend(const uint8_t* col1, const uint8_t* col /************************************************* DELTA FUNCTIONS *************************************************/ /* Grayscale */ -__attribute__((noinline)) void std_delta8_gray8(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_delta8_gray8(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { /* Loop unrolling is used to work on 16 bytes (16 grayscale pixels) at a time */ const uint8_t* const max_ptr = result + count; @@ -3307,8 +3365,20 @@ __attribute__((noinline)) void std_delta8_gray8(const uint8_t* col1, const uint8 } } +__attribute__((noinline)) void std_delta8_gray8(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + result[0] = abs(col1[0] - col2[0]); + + col1 += 1; + col2 += 1; + result += 1; + } +} + /* RGB24: RGB */ -__attribute__((noinline)) void std_delta8_rgb(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_delta8_rgb(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { /* Loop unrolling is used to work on 12 bytes (4 rgb24 pixels) at a time */ int r,g,b; const uint8_t* const max_ptr = result + count; @@ -3337,8 +3407,25 @@ __attribute__((noinline)) void std_delta8_rgb(const uint8_t* col1, const uint8_t } } +__attribute__((noinline)) void std_delta8_rgb(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { + /* Loop unrolling is used to work on 12 bytes (4 rgb24 pixels) at a time */ + int r,g,b; + const uint8_t* const max_ptr = result + count; + + while (result < max_ptr) { + r = abs(col1[0] - col2[0]); + g = abs(col1[1] - col2[1]); + b = abs(col1[2] - col2[2]); + result[0] = (r + r + b + g + g + g + g + g)>>3; + + col1 += 3; + col2 += 3; + result += 1; + } +} + /* RGB24: BGR */ -__attribute__((noinline)) void std_delta8_bgr(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_delta8_bgr(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { /* Loop unrolling is used to work on 12 bytes (4 rgb24 pixels) at a time */ int r,g,b; const uint8_t* const max_ptr = result + count; @@ -3367,8 +3454,25 @@ __attribute__((noinline)) void std_delta8_bgr(const uint8_t* col1, const uint8_t } } +__attribute__((noinline)) void std_delta8_bgr(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { + /* Loop unrolling is used to work on 12 bytes (4 rgb24 pixels) at a time */ + int r,g,b; + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + b = abs(col1[0] - col2[0]); + g = abs(col1[1] - col2[1]); + r = abs(col1[2] - col2[2]); + result[0] = (r + r + b + g + g + g + g + g)>>3; + + col1 += 3; + col2 += 3; + result += 1; + } +} + /* RGB32: RGBA */ -__attribute__((noinline)) void std_delta8_rgba(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_delta8_rgba(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { /* Loop unrolling is used to work on 16 bytes (4 rgb32 pixels) at a time */ int r,g,b; const uint8_t* const max_ptr = result + count; @@ -3397,8 +3501,25 @@ __attribute__((noinline)) void std_delta8_rgba(const uint8_t* col1, const uint8_ } } +__attribute__((noinline)) void std_delta8_rgba(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { + /* Loop unrolling is used to work on 16 bytes (4 rgb32 pixels) at a time */ + int r,g,b; + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + r = abs(col1[0] - col2[0]); + g = abs(col1[1] - col2[1]); + b = abs(col1[2] - col2[2]); + result[0] = (r + r + b + g + g + g + g + g)>>3; + + col1 += 4; + col2 += 4; + result += 1; + } +} + /* RGB32: BGRA */ -__attribute__((noinline)) void std_delta8_bgra(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_delta8_bgra(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { /* Loop unrolling is used to work on 16 bytes (4 rgb32 pixels) at a time */ int r,g,b; const uint8_t* const max_ptr = result + count; @@ -3426,9 +3547,25 @@ __attribute__((noinline)) void std_delta8_bgra(const uint8_t* col1, const uint8_ result += 4; } } +__attribute__((noinline)) void std_delta8_bgra(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { + /* Loop unrolling is used to work on 16 bytes (4 rgb32 pixels) at a time */ + int r,g,b; + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + b = abs(col1[0] - col2[0]); + g = abs(col1[1] - col2[1]); + r = abs(col1[2] - col2[2]); + result[0] = (r + r + b + g + g + g + g + g)>>3; + + col1 += 4; + col2 += 4; + result += 1; + } +} /* RGB32: ARGB */ -__attribute__((noinline)) void std_delta8_argb(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_delta8_argb(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { /* Loop unrolling is used to work on 16 bytes (4 rgb32 pixels) at a time */ int r,g,b; const uint8_t* const max_ptr = result + count; @@ -3456,9 +3593,25 @@ __attribute__((noinline)) void std_delta8_argb(const uint8_t* col1, const uint8_ result += 4; } } +__attribute__((noinline)) void std_delta8_argb(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { + /* Loop unrolling is used to work on 16 bytes (4 rgb32 pixels) at a time */ + int r,g,b; + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + r = abs(col1[1] - col2[1]); + g = abs(col1[2] - col2[2]); + b = abs(col1[3] - col2[3]); + result[0] = (r + r + b + g + g + g + g + g)>>3; + + col1 += 4; + col2 += 4; + result += 1; + } +} /* RGB32: ABGR */ -__attribute__((noinline)) void std_delta8_abgr(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_delta8_abgr(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { /* Loop unrolling is used to work on 16 bytes (4 rgb32 pixels) at a time */ int r,g,b; const uint8_t* const max_ptr = result + count; @@ -3486,6 +3639,21 @@ __attribute__((noinline)) void std_delta8_abgr(const uint8_t* col1, const uint8_ result += 4; } } +__attribute__((noinline)) void std_delta8_abgr(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count) { + int r,g,b; + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + b = abs(col1[1] - col2[1]); + g = abs(col1[2] - col2[2]); + r = abs(col1[3] - col2[3]); + result[0] = (r + r + b + g + g + g + g + g)>>3; + + col1 += 4; + col2 += 4; + result += 1; + } +} /* Grayscale Neon for AArch32 */ #if (defined(__arm__) && defined(__ARM_PCS_VFP) && !defined(ZM_STRIP_NEON)) @@ -4054,7 +4222,7 @@ void ssse3_delta8_abgr(const uint8_t* col1, const uint8_t* col2, uint8_t* result /************************************************* CONVERT FUNCTIONS *************************************************/ /* RGB24 to grayscale */ -__attribute__((noinline)) void std_convert_rgb_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_convert_rgb_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { unsigned int r,g,b; const uint8_t* const max_ptr = result + count; @@ -4080,9 +4248,23 @@ __attribute__((noinline)) void std_convert_rgb_gray8(const uint8_t* col1, uint8_ result += 4; } } +__attribute__((noinline)) void std_convert_rgb_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { + unsigned int r,g,b; + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + r = col1[0]; + g = col1[1]; + b = col1[2]; + result[0] = (r + r + b + g + g + g + g + g)>>3; + + col1 += 3; + result += 1; + } +} /* BGR24 to grayscale */ -__attribute__((noinline)) void std_convert_bgr_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_convert_bgr_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { unsigned int r,g,b; const uint8_t* const max_ptr = result + count; @@ -4108,9 +4290,23 @@ __attribute__((noinline)) void std_convert_bgr_gray8(const uint8_t* col1, uint8_ result += 4; } } +__attribute__((noinline)) void std_convert_bgr_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { + unsigned int r,g,b; + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + b = col1[0]; + g = col1[1]; + r = col1[2]; + result[0] = (r + r + b + g + g + g + g + g)>>3; + + col1 += 3; + result += 1; + } +} /* RGBA to grayscale */ -__attribute__((noinline)) void std_convert_rgba_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_convert_rgba_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { unsigned int r,g,b; const uint8_t* const max_ptr = result + count; @@ -4136,9 +4332,23 @@ __attribute__((noinline)) void std_convert_rgba_gray8(const uint8_t* col1, uint8 result += 4; } } +__attribute__((noinline)) void std_convert_rgba_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { + unsigned int r,g,b; + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + r = col1[0]; + g = col1[1]; + b = col1[2]; + result[0] = (r + r + b + g + g + g + g + g)>>3; + + col1 += 4; + result += 1; + } +} /* BGRA to grayscale */ -__attribute__((noinline)) void std_convert_bgra_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_convert_bgra_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { unsigned int r,g,b; const uint8_t* const max_ptr = result + count; @@ -4165,8 +4375,22 @@ __attribute__((noinline)) void std_convert_bgra_gray8(const uint8_t* col1, uint8 } } +__attribute__((noinline)) void std_convert_bgra_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { + unsigned int r,g,b; + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + b = col1[0]; + g = col1[1]; + r = col1[2]; + result[0] = (r + r + b + g + g + g + g + g)>>3; + + col1 += 4; + result += 1; + } +} /* ARGB to grayscale */ -__attribute__((noinline)) void std_convert_argb_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_convert_argb_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { unsigned int r,g,b; const uint8_t* const max_ptr = result + count; @@ -4192,9 +4416,23 @@ __attribute__((noinline)) void std_convert_argb_gray8(const uint8_t* col1, uint8 result += 4; } } +__attribute__((noinline)) void std_convert_argb_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { + unsigned int r,g,b; + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + r = col1[1]; + g = col1[2]; + b = col1[3]; + result[0] = (r + r + b + g + g + g + g + g)>>3; + + col1 += 4; + result += 1; + } +} /* ABGR to grayscale */ -__attribute__((noinline)) void std_convert_abgr_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_convert_abgr_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { unsigned int r,g,b; const uint8_t* const max_ptr = result + count; @@ -4220,9 +4458,23 @@ __attribute__((noinline)) void std_convert_abgr_gray8(const uint8_t* col1, uint8 result += 4; } } +__attribute__((noinline)) void std_convert_abgr_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { + unsigned int r,g,b; + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + b = col1[1]; + g = col1[2]; + r = col1[3]; + result[0] = (r + r + b + g + g + g + g + g)>>3; + + col1 += 4; + result += 1; + } +} /* Converts a YUYV image into grayscale by extracting the Y channel */ -__attribute__((noinline)) void std_convert_yuyv_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { +__attribute__((noinline)) void fast_convert_yuyv_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { const uint16_t* yuvbuf = (const uint16_t*)col1; const uint8_t* const max_ptr = result + count; @@ -4248,6 +4500,17 @@ __attribute__((noinline)) void std_convert_yuyv_gray8(const uint8_t* col1, uint8 result += 16; } } +__attribute__((noinline)) void std_convert_yuyv_gray8(const uint8_t* col1, uint8_t* result, unsigned long count) { + const uint16_t* yuvbuf = (const uint16_t*)col1; + const uint8_t* const max_ptr = result + count; + + while(result < max_ptr) { + result[0] = (uint8_t)yuvbuf[0]; + + yuvbuf += 1; + result += 1; + } +} /* RGB32 to grayscale SSSE3 */ #if defined(__i386__) || defined(__x86_64__) diff --git a/src/zm_image.h b/src/zm_image.h index 04725ac11..65b570b51 100644 --- a/src/zm_image.h +++ b/src/zm_image.h @@ -86,6 +86,19 @@ inline static void DumpBuffer(uint8_t* buffer, int buffertype) { // camera in raw form. // class Image { + private: + delta_fptr_t delta8_rgb; + delta_fptr_t delta8_bgr; + delta_fptr_t delta8_rgba; + delta_fptr_t delta8_bgra; + delta_fptr_t delta8_argb; + delta_fptr_t delta8_abgr; + delta_fptr_t delta8_gray8; + + // Per object function pointer that we can set once we know the image dimensions + blend_fptr_t blend; + + void update_function_pointers(); protected: struct Edge { @@ -297,6 +310,14 @@ void std_delta8_bgra(const uint8_t* col1, const uint8_t* col2, uint8_t* result, void std_delta8_argb(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); void std_delta8_abgr(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); +void fast_delta8_gray8(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); +void fast_delta8_rgb(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); +void fast_delta8_bgr(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); +void fast_delta8_rgba(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); +void fast_delta8_bgra(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); +void fast_delta8_argb(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); +void fast_delta8_abgr(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); + void neon32_armv7_delta8_gray8(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); void neon32_armv7_delta8_rgba(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); void neon32_armv7_delta8_bgra(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count); @@ -325,6 +346,15 @@ void std_convert_bgra_gray8(const uint8_t* col1, uint8_t* result, unsigned long void std_convert_argb_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); void std_convert_abgr_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); void std_convert_yuyv_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); + +void fast_convert_rgb_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); +void fast_convert_bgr_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); +void fast_convert_rgba_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); +void fast_convert_bgra_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); +void fast_convert_argb_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); +void fast_convert_abgr_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); +void fast_convert_yuyv_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); + void ssse3_convert_rgba_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); void ssse3_convert_bgra_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); void ssse3_convert_argb_gray8(const uint8_t* col1, uint8_t* result, unsigned long count); diff --git a/utils/do_debian_package.sh b/utils/do_debian_package.sh index a87c03379..b8688d57c 100755 --- a/utils/do_debian_package.sh +++ b/utils/do_debian_package.sh @@ -124,7 +124,11 @@ PPA=""; if [ "$RELEASE" != "" ]; then # We need to use our official tarball for the original source, so grab it and overwrite our generated one. IFS='.' read -r -a VERSION <<< "$RELEASE" - PPA="ppa:iconnor/zoneminder-${VERSION[0]}.${VERSION[1]}" + if [ "${VERSION[0]}.${VERSION[1]}" == "1.30" ]; then + PPA="ppa:iconnor/zoneminder-stable" + else + PPA="ppa:iconnor/zoneminder-${VERSION[0]}.${VERSION[1]}" + fi; else if [ "$BRANCH" == "" ]; then PPA="ppa:iconnor/zoneminder-master"; diff --git a/web/ajax/add_monitors.php b/web/ajax/add_monitors.php index eeee7f234..b7e3c376c 100644 --- a/web/ajax/add_monitors.php +++ b/web/ajax/add_monitors.php @@ -1,7 +1,7 @@ set(array( 'StorageId' => 1, 'ServerId' => 'auto', @@ -27,11 +27,11 @@ function probe( &$url_bits ) { $cam_list_html = file_get_contents('http://'.$url_bits['host'].':5000/monitoring/'); if ( $cam_list_html ) { - Logger::Debug("Have content at port 5000/monitoring"); + ZM\Logger::Debug("Have content at port 5000/monitoring"); $matches_count = preg_match_all( '/([^<]+)<\/a>/', $cam_list_html, $cam_list ); - Logger::Debug(print_r($cam_list,true)); + ZM\Logger::Debug(print_r($cam_list,true)); } if ( $matches_count ) { for( $index = 0; $index < $matches_count; $index ++ ) { @@ -41,10 +41,10 @@ function probe( &$url_bits ) { if ( ! isset($new_stream['scheme'] ) ) $new_stream['scheme'] = 'http'; $available_streams[] = $new_stream; -Logger::Debug("Have new stream " . print_r($new_stream,true) ); +ZM\Logger::Debug("Have new stream " . print_r($new_stream,true) ); } } else { - Info('No matches'); + ZM\Info('No matches'); } if ( 0 ) { // No port given, do a port scan @@ -65,7 +65,7 @@ Info("Testing connection to " . $url_bits['host'].':'.$port); $new_stream['port'] = $port; } else { socket_close($socket); - Info("No connection to ".$url_bits['host'] . " on port $port"); + ZM\Info("No connection to ".$url_bits['host'] . " on port $port"); continue; } if ( $new_stream ) { @@ -73,7 +73,7 @@ Info("Testing connection to " . $url_bits['host'].':'.$port); $new_stream['scheme'] = 'http'; $url = unparse_url($new_stream, array('path'=>'/', 'query'=>'action=snapshot')); list($width, $height, $type, $attr) = getimagesize( $url ); - Info("Got $width x $height from $url"); + ZM\Info("Got $width x $height from $url"); $new_stream['Width'] = $width; $new_stream['Height'] = $height; @@ -101,9 +101,9 @@ Info("Testing connection to " . $url_bits['host'].':'.$port); foreach ( $available_streams as &$stream ) { # check for existence in db. $stream['url'] = unparse_url( $stream, array('path'=>'/','query'=>'action=stream') ); - $monitors = Monitor::find( array('Path'=>$stream['url']) ); + $monitors = ZM\Monitor::find( array('Path'=>$stream['url']) ); if ( count($monitors) ) { - Info("Found monitors matching " . $stream['url'] ); + ZM\Info("Found monitors matching " . $stream['url'] ); $stream['Monitor'] = $monitors[0]; if ( isset( $stream['Width'] ) and ( $stream['Monitor']->Width() != $stream['Width'] ) ) { $stream['Warning'] .= 'Monitor width ('.$stream['Monitor']->Width().') and stream width ('.$stream['Width'].") do not match!\n"; @@ -143,9 +143,9 @@ if ( canEdit( 'Monitors' ) ) { if ( 0 ) { // Shortcut test - $monitors = Monitor::find( array('Path'=>$_REQUEST['url']) ); + $monitors = ZM\Monitor::find( array('Path'=>$_REQUEST['url']) ); if ( count( $monitors ) ) { - Info("Monitor found for " . $_REQUEST['url']); + ZM\Info("Monitor found for " . $_REQUEST['url']); $url_bits['url'] = $_REQUEST['url']; $url_bits['Monitor'] = $monitors[0]; $available_stream[] = $url_bits; @@ -182,7 +182,7 @@ if ( 0 ) { $name = $data[0]; $url = $data[1]; $group = $data[2]; - Info("Have the following line data $name $url $group"); + ZM\Info("Have the following line data $name $url $group"); $url_bits = null; if ( preg_match('/(\d+)\.(\d+)\.(\d+)\.(\d+)/', $url) ) { @@ -191,7 +191,7 @@ if ( 0 ) { $url_bits = parse_url( $url ); } if ( ! $url_bits ) { - Info("Bad url, skipping line $name $url $group"); + ZM\Info("Bad url, skipping line $name $url $group"); continue; } @@ -215,11 +215,11 @@ if ( 0 ) { } // end case import default: { - Warning("unknown action " . $_REQUEST['action'] ); + ZM\Warning("unknown action " . $_REQUEST['action'] ); } // end ddcase default } } else { - Warning("Cannot edit monitors" ); + ZM\Warning("Cannot edit monitors" ); } ajaxError( 'Unrecognised action or insufficient permissions' ); diff --git a/web/ajax/alarm.php b/web/ajax/alarm.php index 002f9f784..099bbf671 100644 --- a/web/ajax/alarm.php +++ b/web/ajax/alarm.php @@ -1,6 +1,6 @@ beginTransaction(); - $dbConn->exec( 'LOCK TABLES Monitors WRITE' ); + $dbConn->exec('LOCK TABLES Monitors WRITE'); for ( $i = 0; $i < count($monitor_ids); $i += 1 ) { $monitor_id = $monitor_ids[$i]; $monitor_id = preg_replace( '/^monitor_id-/', '', $monitor_id ); if ( ( ! $monitor_id ) or ! ( is_integer( $monitor_id ) or ctype_digit( $monitor_id ) ) ) { - Warning( "Got $monitor_id from " . $monitor_ids[$i] ); + Warning("Got $monitor_id from " . $monitor_ids[$i]); continue; } - dbQuery( 'UPDATE Monitors SET Sequence=? WHERE Id=?', array( $i, $monitor_id ) ); + dbQuery('UPDATE Monitors SET Sequence=? WHERE Id=?', array($i, $monitor_id)); } // end for each monitor_id $dbConn->commit(); $dbConn->exec('UNLOCK TABLES'); @@ -25,13 +24,12 @@ if ( canEdit( 'Monitors' ) ) { } // end case sort default: { - Warning("unknown action " . $_REQUEST['action'] ); + ZM\Warning('unknown action ' . $_REQUEST['action']); } // end ddcase default } } else { - Warning("Cannot edit monitors" ); + ZM\Warning('Cannot edit monitors'); } -ajaxError( 'Unrecognised action or insufficient permissions' ); - +ajaxError('Unrecognised action or insufficient permissions'); ?> diff --git a/web/ajax/control.php b/web/ajax/control.php index abdc8c8ef..ae7acac9e 100644 --- a/web/ajax/control.php +++ b/web/ajax/control.php @@ -8,7 +8,7 @@ if ( empty($_REQUEST['id']) ) if ( canView( 'Control', $_REQUEST['id'] ) ) { - $monitor = new Monitor( $_REQUEST['id'] ); + $monitor = new ZM\Monitor( $_REQUEST['id'] ); $ctrlCommand = buildControlCommand( $monitor ); diff --git a/web/ajax/log.php b/web/ajax/log.php index 2a5aa039e..e8caff6bd 100644 --- a/web/ajax/log.php +++ b/web/ajax/log.php @@ -9,7 +9,7 @@ switch ( $_REQUEST['task'] ) { { // Silently ignore bogus requests if ( !empty($_POST['level']) && !empty($_POST['message']) ) { - logInit(array('id'=>'web_js')); + ZM\logInit(array('id'=>'web_js')); $string = $_POST['message']; @@ -21,9 +21,9 @@ switch ( $_REQUEST['task'] ) { $levels = array_flip(Logger::$codes); if ( !isset($levels[$_POST['level']]) ) - Panic("Unexpected logger level '".$_POST['level']."'"); + ZM\Panic("Unexpected logger level '".$_POST['level']."'"); $level = $levels[$_POST['level']]; - Logger::fetch()->logPrint($level, $string, $file, $line); + ZM\Logger::fetch()->logPrint($level, $string, $file, $line); } ajaxResponse(); break; @@ -33,7 +33,7 @@ switch ( $_REQUEST['task'] ) { if ( !canView('System') ) ajaxError('Insufficient permissions to view log entries'); - $servers = Server::find(); + $servers = ZM\Server::find(); $servers_by_Id = array(); # There is probably a better way to do this. foreach ( $servers as $server ) { @@ -46,7 +46,7 @@ switch ( $_REQUEST['task'] ) { $limit = 100; if ( isset($_REQUEST['limit']) ) { if ( ( !is_integer($_REQUEST['limit']) and !ctype_digit($_REQUEST['limit']) ) ) { - Error('Invalid value for limit ' . $_REQUEST['limit']); + ZM\Error('Invalid value for limit ' . $_REQUEST['limit']); } else { $limit = $_REQUEST['limit']; } @@ -54,7 +54,7 @@ switch ( $_REQUEST['task'] ) { $sortField = 'TimeKey'; if ( isset($_REQUEST['sortField']) ) { if ( !in_array($_REQUEST['sortField'], $filterFields) and ( $_REQUEST['sortField'] != 'TimeKey' ) ) { - Error("Invalid sort field " . $_REQUEST['sortField']); + ZM\Error("Invalid sort field " . $_REQUEST['sortField']); } else { $sortField = $_REQUEST['sortField']; } @@ -76,7 +76,7 @@ switch ( $_REQUEST['task'] ) { foreach ( $filter as $field=>$value ) { if ( ! in_array($field, $filterFields) ) { - Error("$field is not in valid filter fields"); + ZM\Error("$field is not in valid filter fields"); continue; } if ( $field == 'Level' ){ @@ -105,8 +105,8 @@ switch ( $_REQUEST['task'] ) { $value = $log[$field]; if ( $field == 'Level' ) { - if ( $value <= Logger::INFO ) - $options[$field][$value] = Logger::$codes[$value]; + if ( $value <= ZM\Logger::INFO ) + $options[$field][$value] = ZM\Logger::$codes[$value]; else $options[$field][$value] = 'DB'.$value; } else if ( $field == 'ServerId' ) { @@ -146,14 +146,14 @@ switch ( $_REQUEST['task'] ) { $sortField = 'TimeKey'; if ( isset($_POST['sortField']) ) { if ( ! in_array( $_POST['sortField'], $filterFields ) and ( $_POST['sortField'] != 'TimeKey' ) ) { - Error("Invalid sort field " . $_POST['sortField'] ); + ZM\Error("Invalid sort field " . $_POST['sortField'] ); } else { $sortField = $_POST['sortField']; } } $sortOrder = (isset($_POST['sortOrder']) and $_POST['sortOrder']) == 'asc' ? 'asc':'desc'; - $servers = Server::find(); + $servers = ZM\Server::find(); $servers_by_Id = array(); # There is probably a better way to do this. foreach ( $servers as $server ) { @@ -164,11 +164,11 @@ switch ( $_REQUEST['task'] ) { $where = array(); $values = array(); if ( $minTime ) { - Logger::Debug("MinTime: $minTime"); + ZM\Logger::Debug("MinTime: $minTime"); if ( preg_match('/(.+)(\.\d+)/', $minTime, $matches) ) { # This handles sub second precision $minTime = strtotime($matches[1]).$matches[2]; - Logger::Debug("MinTime: $minTime"); + ZM\Logger::Debug("MinTime: $minTime"); } else { $minTime = strtotime($minTime); } @@ -214,27 +214,27 @@ switch ( $_REQUEST['task'] ) { $exportExt = 'xml'; break; default : - Fatal("Unrecognised log export format '$format'"); + ZM\Fatal("Unrecognised log export format '$format'"); } $exportKey = substr(md5(rand()),0,8); $exportFile = "zm-log.$exportExt"; if ( ! file_exists(ZM_DIR_EXPORTS) ) { - Logger::Debug('Creating ' . ZM_DIR_EXPORTS); + ZM\Logger::Debug('Creating ' . ZM_DIR_EXPORTS); if ( ! mkdir(ZM_DIR_EXPORTS) ) { - Fatal("Can't create exports dir at '".ZM_DIR_EXPORTS."'"); + ZM\Fatal("Can't create exports dir at '".ZM_DIR_EXPORTS."'"); } } $exportPath = ZM_DIR_EXPORTS."/zm-log-$exportKey.$exportExt"; - Logger::Debug("Exporting to $exportPath"); + ZM\Logger::Debug("Exporting to $exportPath"); if ( !($exportFP = fopen($exportPath, 'w')) ) - Fatal("Unable to open log export file $exportPath"); + ZM\Fatal("Unable to open log export file $exportPath"); $logs = array(); foreach ( dbFetchAll($sql, NULL, $values) as $log ) { $log['DateTime'] = preg_replace('/^\d+/', strftime( "%Y-%m-%d %H:%M:%S", intval($log['TimeKey']) ), $log['TimeKey']); $log['Server'] = ( $log['ServerId'] and isset($servers_by_Id[$log['ServerId']]) ) ? $servers_by_Id[$log['ServerId']]->Name() : ''; $logs[] = $log; } - Logger::Debug(count($logs)." lines being exported by $sql " . implode(',',$values)); + ZM\Logger::Debug(count($logs)." lines being exported by $sql " . implode(',',$values)); switch( $format ) { case 'text' : @@ -318,10 +318,10 @@ switch ( $_REQUEST['task'] ) { ' ); foreach ( $logs as $log ) { $classLevel = $log['Level']; - if ( $classLevel < Logger::FATAL ) - $classLevel = Logger::FATAL; - elseif ( $classLevel > Logger::DEBUG ) - $classLevel = Logger::DEBUG; + if ( $classLevel < ZM\Logger::FATAL ) + $classLevel = ZM\Logger::FATAL; + elseif ( $classLevel > ZM\Logger::DEBUG ) + $classLevel = ZM\Logger::DEBUG; $logClass = 'log-'.strtolower(Logger::$codes[$classLevel]); fprintf( $exportFP, " %s%s%s%d%s%s%s%s\n", $logClass, $log['DateTime'], $log['Component'], $log['Server'], $log['Pid'], $log['Code'], $log['Message'], $log['File'], $log['Line'] ); } @@ -384,10 +384,10 @@ switch ( $_REQUEST['task'] ) { ajaxError('Insufficient permissions to download logs'); if ( empty($_REQUEST['key']) ) - Fatal('No log export key given'); + ZM\Fatal('No log export key given'); $exportKey = $_REQUEST['key']; if ( empty($_REQUEST['format']) ) - Fatal('No log export format given'); + ZM\Fatal('No log export format given'); $format = $_REQUEST['format']; switch( $format ) { @@ -404,7 +404,7 @@ switch ( $_REQUEST['task'] ) { $exportExt = 'xml'; break; default : - Fatal("Unrecognised log export format '$format'"); + ZM\Fatal("Unrecognised log export format '$format'"); } $exportFile = "zm-log.$exportExt"; diff --git a/web/ajax/status.php b/web/ajax/status.php index b82c40736..f3a5208ad 100644 --- a/web/ajax/status.php +++ b/web/ajax/status.php @@ -284,7 +284,7 @@ function collectData() { if ( in_array($matches[1], $fieldSql) ) { $sql .= $matches[1]; } else { - Error('Sort field ' . $matches[1] . ' not in SQL Fields'); + ZM\Error('Sort field ' . $matches[1] . ' not in SQL Fields'); } if ( count($matches) > 2 ) { $sql .= ' '.strtoupper($matches[2]); @@ -292,7 +292,7 @@ function collectData() { $sql .= ' '.strtoupper($matches[3]); } } else { - Error("Sort field didn't match regexp $sort_field"); + ZM\Error("Sort field didn't match regexp $sort_field"); } } # end foreach sort field } # end if has sort @@ -323,7 +323,7 @@ function collectData() { } } } - #Logger::Debug(print_r($data, true)); + #ZM\Logger::Debug(print_r($data, true)); return $data; } diff --git a/web/ajax/stream.php b/web/ajax/stream.php index 356227529..7329c7bab 100644 --- a/web/ajax/stream.php +++ b/web/ajax/stream.php @@ -23,7 +23,7 @@ if ( sem_acquire($semaphore,1) !== false ) { $localSocketFile = ZM_PATH_SOCKS.'/zms-'.sprintf('%06d',$_REQUEST['connkey']).'w.sock'; if ( file_exists( $localSocketFile ) ) { - Warning("sock file $localSocketFile already exists?! Is someone else talking to zms?"); + ZM\Warning("sock file $localSocketFile already exists?! Is someone else talking to zms?"); // They could be. We can maybe have concurrent requests from a browser. } if ( ! socket_bind( $socket, $localSocketFile ) ) { @@ -32,23 +32,23 @@ if ( sem_acquire($semaphore,1) !== false ) { switch ( $_REQUEST['command'] ) { case CMD_VARPLAY : - Logger::Debug( 'Varplaying to '.$_REQUEST['rate'] ); + ZM\Logger::Debug( 'Varplaying to '.$_REQUEST['rate'] ); $msg = pack( 'lcn', MSG_CMD, $_REQUEST['command'], $_REQUEST['rate']+32768 ); break; case CMD_ZOOMIN : - Logger::Debug( 'Zooming to '.$_REQUEST['x'].",".$_REQUEST['y'] ); + ZM\Logger::Debug( 'Zooming to '.$_REQUEST['x'].",".$_REQUEST['y'] ); $msg = pack( 'lcnn', MSG_CMD, $_REQUEST['command'], $_REQUEST['x'], $_REQUEST['y'] ); break; case CMD_PAN : - Logger::Debug( 'Panning to '.$_REQUEST['x'].",".$_REQUEST['y'] ); + ZM\Logger::Debug( 'Panning to '.$_REQUEST['x'].",".$_REQUEST['y'] ); $msg = pack( 'lcnn', MSG_CMD, $_REQUEST['command'], $_REQUEST['x'], $_REQUEST['y'] ); break; case CMD_SCALE : - Logger::Debug( 'Scaling to '.$_REQUEST['scale'] ); + ZM\Logger::Debug( 'Scaling to '.$_REQUEST['scale'] ); $msg = pack( 'lcn', MSG_CMD, $_REQUEST['command'], $_REQUEST['scale'] ); break; case CMD_SEEK : - Logger::Debug( 'Seeking to '.$_REQUEST['offset'] ); + ZM\Logger::Debug( 'Seeking to '.$_REQUEST['offset'] ); $msg = pack( 'lcN', MSG_CMD, $_REQUEST['command'], $_REQUEST['offset'] ); break; default : @@ -84,18 +84,18 @@ if ( sem_acquire($semaphore,1) !== false ) { $numSockets = socket_select( $rSockets, $wSockets, $eSockets, intval($timeout/1000), ($timeout%1000)*1000 ); if ( $numSockets === false ) { - Error('socket_select failed: ' . socket_strerror(socket_last_error()) ); + ZM\Error('socket_select failed: ' . socket_strerror(socket_last_error()) ); ajaxError( 'socket_select failed: '.socket_strerror(socket_last_error()) ); } else if ( $numSockets < 0 ) { - Error( "Socket closed $remSockFile" ); + ZM\Error( "Socket closed $remSockFile" ); ajaxError( "Socket closed $remSockFile" ); } else if ( $numSockets == 0 ) { - Error( "Timed out waiting for msg $remSockFile" ); + ZM\Error( "Timed out waiting for msg $remSockFile" ); socket_Set_nonblock($socket); #ajaxError( "Timed out waiting for msg $remSockFile" ); } else if ( $numSockets > 0 ) { if ( count($rSockets) != 1 ) { - Error( 'Bogus return from select, '.count($rSockets).' sockets available' ); + ZM\Error( 'Bogus return from select, '.count($rSockets).' sockets available' ); ajaxError( 'Bogus return from select, '.count($rSockets).' sockets available' ); } } @@ -125,9 +125,9 @@ if ( sem_acquire($semaphore,1) !== false ) { case MSG_DATA_WATCH : { $data = unpack( "ltype/imonitor/istate/dfps/ilevel/irate/ddelay/izoom/Cdelayed/Cpaused/Cenabled/Cforced", $msg ); - Logger::Debug("FPS: " . $data['fps'] ); + ZM\Logger::Debug("FPS: " . $data['fps'] ); $data['fps'] = round( $data['fps'], 2 ); - Logger::Debug("FPS: " . $data['fps'] ); + ZM\Logger::Debug("FPS: " . $data['fps'] ); $data['rate'] /= RATE_BASE; $data['delay'] = round( $data['delay'], 2 ); $data['zoom'] = round( $data['zoom']/SCALE_BASE, 1 ); @@ -164,7 +164,7 @@ if ( sem_acquire($semaphore,1) !== false ) { } sem_release($semaphore); } else { - Logger::Debug("Couldn't get semaphore"); + ZM\Logger::Debug("Couldn't get semaphore"); ajaxResponse( array() ); } diff --git a/web/api/app/Controller/HostController.php b/web/api/app/Controller/HostController.php index db6f38523..74ea854a4 100644 --- a/web/api/app/Controller/HostController.php +++ b/web/api/app/Controller/HostController.php @@ -66,7 +66,7 @@ class HostController extends AppController { if ( $isZmAuth ) { // In future, we may want to completely move to AUTH_HASH_LOGINS and return &auth= for all cases - require_once __DIR__ ."../../../includes/auth.php"; # in the event we directly call getCredentials.json + require_once __DIR__ .'/../../../includes/auth.php'; # in the event we directly call getCredentials.json $this->Session->read('user'); # this is needed for command line/curl to recognize a session $zmAuthRelay = $this->Config->find('first',array('conditions' => array('Config.' . $this->Config->primaryKey => 'ZM_AUTH_RELAY')))['Config']['Value']; if ( $zmAuthRelay == 'hashed' ) { diff --git a/web/includes/Event.php b/web/includes/Event.php index a4f389aca..51995ac19 100644 --- a/web/includes/Event.php +++ b/web/includes/Event.php @@ -1,4 +1,5 @@ fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'MontageLayout'); - foreach ( $results as $row => $obj ) { - $filters[] = $obj; + $results = $result->fetchALL(); + foreach ( $results as $row ) { + $filters[] = new MontageLayout($row); } } return $filters; diff --git a/web/includes/Server.php b/web/includes/Server.php index ea633c4be..96d07e9c1 100644 --- a/web/includes/Server.php +++ b/web/includes/Server.php @@ -1,8 +1,10 @@ null, diff --git a/web/includes/Storage.php b/web/includes/Storage.php index a7372b15a..67264f298 100644 --- a/web/includes/Storage.php +++ b/web/includes/Storage.php @@ -1,5 +1,7 @@ delete(); } // end if monitor found in db } // end if canedit this monitor diff --git a/web/includes/actions/control.php b/web/includes/actions/control.php index d3a75a751..36f6b14fb 100644 --- a/web/includes/actions/control.php +++ b/web/includes/actions/control.php @@ -20,11 +20,11 @@ // Monitor control actions, require a monitor id and control view permissions for that monitor if ( empty($_REQUEST['mid']) ) { - Warning("Settings requires a monitor id"); + ZM\Warning('Settings requires a monitor id'); return; } if ( ! canView('Control', $_REQUEST['mid']) ) { - Warning("Settings requires the Control permission"); + ZM\Warning('Settings requires the Control permission'); return; } @@ -32,7 +32,7 @@ require_once('control_functions.php'); require_once('Monitor.php'); $mid = validInt($_REQUEST['mid']); if ( $action == 'control' ) { - $monitor = new Monitor($mid); + $monitor = new ZM\Monitor($mid); $ctrlCommand = buildControlCommand($monitor); sendControlCommand($monitor->Id(), $ctrlCommand); diff --git a/web/includes/actions/controlcap.php b/web/includes/actions/controlcap.php index 71b59e1b6..eec3ffd8b 100644 --- a/web/includes/actions/controlcap.php +++ b/web/includes/actions/controlcap.php @@ -20,13 +20,13 @@ if ( !canEdit('Control') ) { - Warning("Need Control permissions to edit control capabilities"); + ZM\Warning('Need Control permissions to edit control capabilities'); return; } // end if !canEdit Controls if ( $action == 'controlcap' ) { require_once('includes/Control.php'); - $Control = new Control( !empty($_REQUEST['cid']) ? $_REQUEST['cid'] : null ); + $Control = new ZM\Control( !empty($_REQUEST['cid']) ? $_REQUEST['cid'] : null ); //$changes = getFormChanges( $control, $_REQUEST['newControl'], $types, $columns ); $Control->save($_REQUEST['newControl']); diff --git a/web/includes/actions/controlcaps.php b/web/includes/actions/controlcaps.php index f67a37dad..3e5310d19 100644 --- a/web/includes/actions/controlcaps.php +++ b/web/includes/actions/controlcaps.php @@ -20,16 +20,15 @@ if ( !canEdit('Control') ) { - Warning("Need Control permissions to edit control capabilities"); + ZM\Warning('Need Control permissions to edit control capabilities'); return; } // end if !canEdit Controls -} if ( $action == 'delete' ) { if ( isset($_REQUEST['markCids']) ) { foreach( $_REQUEST['markCids'] as $markCid ) { - dbQuery('DELETE FROM Controls WHERE Id = ?', array($markCid)); dbQuery('UPDATE Monitors SET Controllable = 0, ControlId = 0 WHERE ControlId = ?', array($markCid)); + dbQuery('DELETE FROM Controls WHERE Id = ?', array($markCid)); $refreshParent = true; } } diff --git a/web/includes/actions/device.php b/web/includes/actions/device.php index a9d1f9e5a..c1a882d89 100644 --- a/web/includes/actions/device.php +++ b/web/includes/actions/device.php @@ -20,7 +20,7 @@ // Device view actions if ( !canEdit('Devices') ) { - Warning("No devices permission in editing device"); + ZM\Warning('No devices permission in editing device'); return; } // end if !canEdit(Devices) @@ -39,7 +39,7 @@ if ( $action == 'device' ) { $view = 'none'; } } else { - Error("Unknown action in device"); + ZM\Error('Unknown action in device'); } // end if action ?> diff --git a/web/includes/actions/devices.php b/web/includes/actions/devices.php index 4cb5d43a3..01c562370 100644 --- a/web/includes/actions/devices.php +++ b/web/includes/actions/devices.php @@ -20,7 +20,7 @@ // Device view actions if ( !canEdit('Devices') ) { - Warning("No devices permission in editing device"); + ZM\Warning('No devices permission in editing device'); return; } // end if !canEdit(Devices) diff --git a/web/includes/actions/donate.php b/web/includes/actions/donate.php index 74361c4e5..156491ede 100644 --- a/web/includes/actions/donate.php +++ b/web/includes/actions/donate.php @@ -19,7 +19,7 @@ // if ( !canEdit('System') ) { - Warning("Need System permissions to update donation"); + ZM\Warning('Need System permissions to update donation'); return; } diff --git a/web/includes/actions/event.php b/web/includes/actions/event.php index 89a2694c8..a3c6d56c3 100644 --- a/web/includes/actions/event.php +++ b/web/includes/actions/event.php @@ -20,7 +20,7 @@ // If there is an action on an event, then we must have an id. if ( !empty($_REQUEST['eid']) ) { - Warning("No eid in action on event view"); + ZM\Warning('No eid in action on event view'); return; } diff --git a/web/includes/actions/eventdetail.php b/web/includes/actions/eventdetail.php index 561c2cb78..20bd084ee 100644 --- a/web/includes/actions/eventdetail.php +++ b/web/includes/actions/eventdetail.php @@ -19,13 +19,13 @@ // if ( !isset($_REQUEST['markEids']) ) { - Warning('Events actions require eids'); + ZM\Warning('Events actions require eids'); return; } // Event scope actions, view permissions only required if ( !canEdit('Events') ) { - Warning("Events actions require Edit permissions"); + ZM\Warning('Events actions require Edit permissions'); return; } // end if ! canEdit(Events) diff --git a/web/includes/actions/events.php b/web/includes/actions/events.php index 2ed334d9c..0ed8f3865 100644 --- a/web/includes/actions/events.php +++ b/web/includes/actions/events.php @@ -19,13 +19,13 @@ // if ( !isset($_REQUEST['eids']) ) { - Warning('Events actions require eids'); + ZM\Warning('Events actions require eids'); return; } // Event scope actions, view permissions only required if ( !canEdit('Events') ) { - Warning("Events actions require Edit permissions"); + ZM\Warning('Events actions require Edit permissions'); return; } // end if ! canEdit(Events) diff --git a/web/includes/actions/filter.php b/web/includes/actions/filter.php index 4dc595470..a89938697 100644 --- a/web/includes/actions/filter.php +++ b/web/includes/actions/filter.php @@ -20,7 +20,7 @@ // Event scope actions, view permissions only required if ( !canView('Events') ) { - Warning('You do not have permission to view Events.'); + ZM\Warning('You do not have permission to view Events.'); return; } @@ -30,13 +30,9 @@ if ( isset($_REQUEST['object']) and ( $_REQUEST['object'] == 'filter' ) ) { } elseif ( $action == 'delterm' ) { $_REQUEST['filter'] = delFilterTerm($_REQUEST['filter'], $_REQUEST['line']); } else if ( canEdit('Events') ) { - if ( empty($_REQUEST['Id']) ) { - Error("No filter id specified."); - return; - } require_once('includes/Filter.php'); - $filter = new Filter($_REQUEST['Id']); + $filter = new ZM\Filter($_REQUEST['Id']); if ( $action == 'delete' ) { if ( !empty($_REQUEST['Id']) ) { @@ -46,7 +42,7 @@ if ( isset($_REQUEST['object']) and ( $_REQUEST['object'] == 'filter' ) ) { $filter->delete(); } else { - Error("No filter id passed when deleting"); + ZM\Error("No filter id passed when deleting"); } } else if ( ( $action == 'Save' ) or ( $action == 'SaveAs' ) or ( $action == 'execute' ) ) { @@ -102,7 +98,7 @@ if ( isset($_REQUEST['object']) and ( $_REQUEST['object'] == 'filter' ) ) { ) { $filter->control($_REQUEST['command'], $_REQUEST['ServerId']); } else { - Error('Invalid command for filter ('.$_REQUEST['command'].')'); + ZM\Error('Invalid command for filter ('.$_REQUEST['command'].')'); } } // end if save or execute } // end if canEdit(Events) diff --git a/web/includes/actions/function.php b/web/includes/actions/function.php index 5fca0d8a1..f60b98fda 100644 --- a/web/includes/actions/function.php +++ b/web/includes/actions/function.php @@ -21,12 +21,12 @@ // Monitor edit actions, require a monitor id and edit permissions for that monitor if ( empty($_REQUEST['mid']) ) { - Error("Must specify mid"); + ZM\Error('Must specify mid'); return; } $mid = validInt($_REQUEST['mid']); if ( !canEdit('Monitors', $mid) ) { - Error("You do not have permission to edit monitor $mid"); + ZM\Error("You do not have permission to edit monitor $mid"); return; } @@ -52,7 +52,7 @@ if ( $action == 'function' ) { } $refreshParent = true; } else { - Logger::Debug("No change to function, not doing anything."); + ZM\Logger::Debug('No change to function, not doing anything.'); } } // end if action $view = 'none'; diff --git a/web/includes/actions/group.php b/web/includes/actions/group.php index 36a3f8faa..ec4f28969 100644 --- a/web/includes/actions/group.php +++ b/web/includes/actions/group.php @@ -22,7 +22,7 @@ # Should probably verify that each monitor id is a valid monitor, that we have access to. # However at the moment, you have to have System permissions to do this if ( ! canEdit('Groups') ) { - Warning("Need group edit permissions to edit groups"); + ZM\Warning('Need group edit permissions to edit groups'); return; } diff --git a/web/includes/actions/groups.php b/web/includes/actions/groups.php index 22d138240..8e4522187 100644 --- a/web/includes/actions/groups.php +++ b/web/includes/actions/groups.php @@ -33,13 +33,13 @@ if ( ($action == 'setgroup') && canView('Groups')) { # Should probably verify that each monitor id is a valid monitor, that we have access to. # However at the moment, you have to have System permissions to do this if ( ! canEdit('Groups') ) { - Warning("Need group edit permissions to edit groups"); + ZM\Warning('Need group edit permissions to edit groups'); return; } if ( $action == 'delete' ) { if ( !empty($_REQUEST['gid']) ) { - foreach ( Group::find(array('Id'=>$_REQUEST['gid'])) as $Group ) { + foreach ( ZM\Group::find(array('Id'=>$_REQUEST['gid'])) as $Group ) { $Group->delete(); } } diff --git a/web/includes/actions/monitor.php b/web/includes/actions/monitor.php index 2e73e4184..815100e4e 100644 --- a/web/includes/actions/monitor.php +++ b/web/includes/actions/monitor.php @@ -25,10 +25,10 @@ if ( isset($_REQUEST['object']) and $_REQUEST['object'] == 'Monitor' ) { foreach ( $_REQUEST['mids'] as $mid ) { $mid = ValidInt($mid); if ( ! canEdit('Monitors', $mid) ) { - Warning("Cannot edit monitor $mid"); + ZM\Warning("Cannot edit monitor $mid"); continue; } - $Monitor = new Monitor($mid); + $Monitor = new ZM\Monitor($mid); if ( $Monitor->Type() != 'WebSite' ) { $Monitor->zmaControl('stop'); $Monitor->zmcControl('stop'); @@ -47,7 +47,7 @@ if ( isset($_REQUEST['object']) and $_REQUEST['object'] == 'Monitor' ) { // Monitor edit actions, monitor id derived, require edit permissions for that monitor if ( ! canEdit('Monitors') ) { - Warning("Monitor actions require Monitors Permissions"); + ZM\Warning("Monitor actions require Monitors Permissions"); return; } @@ -68,7 +68,7 @@ if ( $action == 'monitor' ) { $x10Monitor = array(); } } - $Monitor = new Monitor($monitor); + $Monitor = new ZM\Monitor($monitor); // Define a field type for anything that's not simple text equivalent $types = array( @@ -86,10 +86,10 @@ if ( $action == 'monitor' ) { if ( $_REQUEST['newMonitor']['ServerId'] == 'auto' ) { $_REQUEST['newMonitor']['ServerId'] = dbFetchOne( 'SELECT Id FROM Servers WHERE Status=\'Running\' ORDER BY FreeMem DESC, CpuLoad ASC LIMIT 1', 'Id'); - Logger::Debug('Auto selecting server: Got ' . $_REQUEST['newMonitor']['ServerId'] ); + ZM\Logger::Debug('Auto selecting server: Got ' . $_REQUEST['newMonitor']['ServerId'] ); if ( ( ! $_REQUEST['newMonitor'] ) and defined('ZM_SERVER_ID') ) { $_REQUEST['newMonitor']['ServerId'] = ZM_SERVER_ID; - Logger::Debug('Auto selecting server to ' . ZM_SERVER_ID); + ZM\Logger::Debug('Auto selecting server to ' . ZM_SERVER_ID); } } @@ -107,12 +107,12 @@ if ( $action == 'monitor' ) { dbQuery('UPDATE Monitors SET '.implode(', ', $changes).' WHERE Id=?', array($mid)); // Groups will be added below if ( isset($changes['Name']) or isset($changes['StorageId']) ) { - $OldStorage = new Storage($monitor['StorageId']); + $OldStorage = new ZM\Storage($monitor['StorageId']); $saferOldName = basename($monitor['Name']); if ( file_exists($OldStorage->Path().'/'.$saferOldName) ) unlink($OldStorage->Path().'/'.$saferOldName); - $NewStorage = new Storage($_REQUEST['newMonitor']['StorageId']); + $NewStorage = new ZM\Storage($_REQUEST['newMonitor']['StorageId']); if ( ! file_exists($NewStorage->Path().'/'.$mid) ) mkdir($NewStorage->Path().'/'.$mid, 0755); $saferNewName = basename($_REQUEST['newMonitor']['Name']); @@ -164,24 +164,24 @@ if ( $action == 'monitor' ) { $zoneArea = $_REQUEST['newMonitor']['Width'] * $_REQUEST['newMonitor']['Height']; dbQuery("INSERT INTO Zones SET MonitorId = ?, Name = 'All', Type = 'Active', Units = 'Percent', NumCoords = 4, Coords = ?, Area=?, AlarmRGB = 0xff0000, CheckMethod = 'Blobs', MinPixelThreshold = 25, MinAlarmPixels=?, MaxAlarmPixels=?, FilterX = 3, FilterY = 3, MinFilterPixels=?, MaxFilterPixels=?, MinBlobPixels=?, MinBlobs = 1", array( $mid, sprintf( "%d,%d %d,%d %d,%d %d,%d", 0, 0, $_REQUEST['newMonitor']['Width']-1, 0, $_REQUEST['newMonitor']['Width']-1, $_REQUEST['newMonitor']['Height']-1, 0, $_REQUEST['newMonitor']['Height']-1 ), $zoneArea, intval(($zoneArea*3)/100), intval(($zoneArea*75)/100), intval(($zoneArea*3)/100), intval(($zoneArea*75)/100), intval(($zoneArea*2)/100) ) ); //$view = 'none'; - $Storage = new Storage($_REQUEST['newMonitor']['StorageId']); + $Storage = new ZM\Storage($_REQUEST['newMonitor']['StorageId']); mkdir($Storage->Path().'/'.$mid, 0755); $saferName = basename($_REQUEST['newMonitor']['Name']); symlink($mid, $Storage->Path().'/'.$saferName); } else { - Error('Error saving new Monitor.'); + ZM\Error('Error saving new Monitor.'); $error_message = dbError($sql); return; } } else { - Error('Users with Monitors restrictions cannot create new monitors.'); + ZM\Error('Users with Monitors restrictions cannot create new monitors.'); return; } $restart = true; } else { - Logger::Debug('No action due to no changes to Monitor'); + ZM\Logger::Debug('No action due to no changes to Monitor'); } # end if count(changes) if ( @@ -220,7 +220,7 @@ if ( $action == 'monitor' ) { if ( $restart ) { - $new_monitor = new Monitor($mid); + $new_monitor = new ZM\Monitor($mid); //fixDevices(); if ( $new_monitor->Type() != 'WebSite' ) { @@ -238,6 +238,6 @@ if ( $action == 'monitor' ) { } // end if restart $view = 'none'; } else { - Warning("Unknown action $action in Monitor"); + ZM\Warning("Unknown action $action in Monitor"); } // end if action == Delete ?> diff --git a/web/includes/actions/montage.php b/web/includes/actions/montage.php index 3040fd83a..7ab105d0c 100644 --- a/web/includes/actions/montage.php +++ b/web/includes/actions/montage.php @@ -22,7 +22,7 @@ if ( isset($_REQUEST['object']) ) { if ( $_REQUEST['object'] == 'MontageLayout' ) { // System edit actions if ( ! canEdit('System') ) { - Warning("Need System permissions to edit layouts"); + ZM\Warning('Need System permissions to edit layouts'); return; } require_once('includes/MontageLayout.php'); diff --git a/web/includes/actions/options.php b/web/includes/actions/options.php index d7853ec9e..0c80bacf0 100644 --- a/web/includes/actions/options.php +++ b/web/includes/actions/options.php @@ -20,7 +20,7 @@ // System edit actions if ( !canEdit('System') ) { - Warning("Must have System permissions to perform options actions"); + ZM\Warning('Must have System permissions to perform options actions'); return; } diff --git a/web/includes/actions/privacy.php b/web/includes/actions/privacy.php index 99bbd7150..5877bb60d 100644 --- a/web/includes/actions/privacy.php +++ b/web/includes/actions/privacy.php @@ -19,18 +19,18 @@ // if ( !canEdit('System') ) { - Warning("Need System permissions to update privacy"); + ZM\Warning('Need System permissions to update privacy'); return; } -if ( ($action == 'privacy') && isset($_REQUEST['option']) ) { - switch( $_REQUEST['option'] ) { - case 'decline' : +if ( ($action == 'privacy') && isset($_POST['option']) ) { + switch( $_POST['option'] ) { + case '0' : dbQuery("UPDATE Config SET Value = '0' WHERE Name = 'ZM_SHOW_PRIVACY'"); dbQuery("UPDATE Config SET Value = '0' WHERE Name = 'ZM_TELEMETRY_DATA'"); $redirect = '?view=console'; break; - case 'accept' : + case '1' : dbQuery("UPDATE Config SET Value = '0' WHERE Name = 'ZM_SHOW_PRIVACY'"); dbQuery("UPDATE Config SET Value = '1' WHERE Name = 'ZM_TELEMETRY_DATA'"); $redirect = '?view=console'; diff --git a/web/includes/actions/server.php b/web/includes/actions/server.php index d991fd228..1ffe4933d 100644 --- a/web/includes/actions/server.php +++ b/web/includes/actions/server.php @@ -20,7 +20,7 @@ // System edit actions if ( ! canEdit('System') ) { - Warning("Need System permissions to add servers"); + ZM\Warning('Need System permissions to add servers'); return; } @@ -48,6 +48,6 @@ if ( $action == 'Save' ) { } $view = 'none'; } else { - Error("Unknown action $action in saving Server"); + ZM\Error("Unknown action $action in saving Server"); } ?> diff --git a/web/includes/actions/settings.php b/web/includes/actions/settings.php index 872dae95e..25c4f76d4 100644 --- a/web/includes/actions/settings.php +++ b/web/includes/actions/settings.php @@ -21,11 +21,11 @@ // Monitor control actions, require a monitor id and control view permissions for that monitor if ( empty($_REQUEST['mid']) ) { - Warning("Settings requires a monitor id"); + ZM\Warning('Settings requires a monitor id'); return; } if ( ! canView('Control', $_REQUEST['mid']) ) { - Warning("Settings requires the Control permission"); + ZM\Warning('Settings requires the Control permission'); return; } diff --git a/web/includes/actions/state.php b/web/includes/actions/state.php index 9cb5eb8c9..9799cdec3 100644 --- a/web/includes/actions/state.php +++ b/web/includes/actions/state.php @@ -20,7 +20,7 @@ // System edit actions if ( !canEdit('System') ) { - Warning('Need System Permission to edit states'); + ZM\Warning('Need System Permission to edit states'); return; } if ( $action == 'state' ) { diff --git a/web/includes/actions/storage.php b/web/includes/actions/storage.php index 94b76bae7..f60c8227d 100644 --- a/web/includes/actions/storage.php +++ b/web/includes/actions/storage.php @@ -20,7 +20,7 @@ // System edit actions if ( ! canEdit('System') ) { - Warning("Need System permission to edit Storage"); + ZM\Warning('Need System permission to edit Storage'); return; } @@ -43,7 +43,7 @@ if ( $action == 'Save' ) { } $view = 'none'; } else { - Error("Unknown action $action in saving Storage"); + ZM\Error("Unknown action $action in saving Storage"); } ?> diff --git a/web/includes/actions/version.php b/web/includes/actions/version.php index 0e89b2457..fde85427f 100644 --- a/web/includes/actions/version.php +++ b/web/includes/actions/version.php @@ -20,7 +20,7 @@ // System edit actions if ( !canEdit('System') ) { - Warning("Need System permissions to update version"); + ZM\Warning('Need System permissions to update version'); return; } if ( $action == 'version' && isset($_REQUEST['option']) ) { diff --git a/web/includes/actions/zones.php b/web/includes/actions/zones.php index f7ee15c9d..babb4fa7b 100644 --- a/web/includes/actions/zones.php +++ b/web/includes/actions/zones.php @@ -20,7 +20,7 @@ if ( !empty($_REQUEST['mid']) && canEdit('Monitors', $_REQUEST['mid']) ) { $mid = validInt($_REQUEST['mid']); - $monitor = new Monitor($mid); + $monitor = new ZM\Monitor($mid); if ( $action == 'delete' ) { if ( isset($_REQUEST['markZids']) ) { diff --git a/web/includes/auth.php b/web/includes/auth.php index bf8ed99ca..c16a1e7b8 100644 --- a/web/includes/auth.php +++ b/web/includes/auth.php @@ -89,7 +89,7 @@ function userLogin($username='', $password='', $passwordHashed=false) { } $_SESSION['remoteAddr'] = $_SERVER['REMOTE_ADDR']; // To help prevent session hijacking if ( $dbUser = dbFetchOne($sql, NULL, $sql_values) ) { - Info("Login successful for user \"$username\""); + ZM\Info("Login successful for user \"$username\""); $user = $dbUser; unset($_SESSION['loginFailed']); if ( ZM_AUTH_TYPE == 'builtin' ) { @@ -97,7 +97,7 @@ function userLogin($username='', $password='', $passwordHashed=false) { } zm_session_regenerate_id(); } else { - Warning("Login denied for user \"$username\""); + ZM\Warning("Login denied for user \"$username\""); $_SESSION['loginFailed'] = true; unset($user); } @@ -108,7 +108,7 @@ function userLogin($username='', $password='', $passwordHashed=false) { function userLogout() { global $user; - Info('User "'.$user['Username'].'" logged out'); + ZM\Info('User "'.$user['Username'].'" logged out'); unset($user); zm_session_clear(); } @@ -119,7 +119,7 @@ function getAuthUser($auth) { if ( ZM_AUTH_HASH_IPS ) { $remoteAddr = $_SERVER['REMOTE_ADDR']; if ( !$remoteAddr ) { - Error("Can't determine remote address for authentication, using empty string"); + ZM\Error("Can't determine remote address for authentication, using empty string"); $remoteAddr = ''; } } @@ -145,7 +145,7 @@ function getAuthUser($auth) { } // end foreach hour } // end foreach user } // end if using auth hash - Error("Unable to authenticate user from auth hash '$auth'"); + ZM\Error("Unable to authenticate user from auth hash '$auth'"); return false; } // end getAuthUser($auth) @@ -164,7 +164,7 @@ function generateAuthHash($useRemoteAddr, $force=false) { } else { $authKey = ZM_AUTH_HASH_SECRET.$_SESSION['username'].$_SESSION['passwordHash'].$local_time[2].$local_time[3].$local_time[4].$local_time[5]; } - #Logger::Debug("Generated using hour:".$local_time[2] . ' mday:' . $local_time[3] . ' month:'.$local_time[4] . ' year: ' . $local_time[5] ); + #ZM\Logger::Debug("Generated using hour:".$local_time[2] . ' mday:' . $local_time[3] . ' month:'.$local_time[4] . ' year: ' . $local_time[5] ); $auth = md5($authKey); if ( !$force ) { $close_session = 0; @@ -178,9 +178,9 @@ function generateAuthHash($useRemoteAddr, $force=false) { } else { return $auth; } - #Logger::Debug("Generated new auth $auth at " . $_SESSION['AuthHashGeneratedAt']. " using $authKey" ); + #ZM\Logger::Debug("Generated new auth $auth at " . $_SESSION['AuthHashGeneratedAt']. " using $authKey" ); #} else { - #Logger::Debug("Using cached auth " . $_SESSION['AuthHash'] ." beacuse generatedat:" . $_SESSION['AuthHashGeneratedAt'] . ' < now:'. $time . ' - ' . ZM_AUTH_HASH_TTL . ' * 1800 = '. $mintime); + #ZM\Logger::Debug("Using cached auth " . $_SESSION['AuthHash'] ." beacuse generatedat:" . $_SESSION['AuthHashGeneratedAt'] . ' < now:'. $time . ' - ' . ZM_AUTH_HASH_TTL . ' * 1800 = '. $mintime); } # end if AuthHash is not cached return $_SESSION['AuthHash'.$_SESSION['remoteAddr']]; } # end if using AUTH and AUTH_RELAY diff --git a/web/includes/config.php.in b/web/includes/config.php.in index bf4b24e0b..01382ad37 100644 --- a/web/includes/config.php.in +++ b/web/includes/config.php.in @@ -138,7 +138,7 @@ define( 'MYSQL_FMT_DATETIME_SHORT', '%y/%m/%d %H:%i:%S' ); // MySQL date_format require_once( 'database.php' ); require_once( 'logger.php' ); loadConfig(); -Logger::fetch()->initialise(); +ZM\Logger::fetch()->initialise(); $GLOBALS['defaultUser'] = array( 'Username' => 'admin', diff --git a/web/includes/database.php b/web/includes/database.php index 95fabee11..b567f6c6d 100644 --- a/web/includes/database.php +++ b/web/includes/database.php @@ -93,7 +93,7 @@ function dbLog( $sql, $update=false ) { global $dbLogLevel; $noExecute = $update && ($dbLogLevel >= DB_LOG_DEBUG); if ( $dbLogLevel > DB_LOG_OFF ) - Logger::Debug( "SQL-LOG: $sql".($noExecute?" (not executed)":"") ); + ZM\Logger::Debug( "SQL-LOG: $sql".($noExecute?" (not executed)":"") ); return( $noExecute ); } @@ -104,7 +104,7 @@ function dbError( $sql ) { return ''; $message = "SQL-ERR '".implode("\n",$dbConn->errorInfo())."', statement was '".$sql."'"; - Error($message); + ZM\Error($message); return $message; } @@ -130,32 +130,32 @@ function dbQuery( $sql, $params=NULL ) { try { if ( isset($params) ) { if ( ! $result = $dbConn->prepare( $sql ) ) { - Error("SQL: Error preparing $sql: " . $pdo->errorInfo); + ZM\Error("SQL: Error preparing $sql: " . $pdo->errorInfo); return NULL; } if ( ! $result->execute( $params ) ) { - Error("SQL: Error executing $sql: " . implode(',', $result->errorInfo() ) ); + ZM\Error("SQL: Error executing $sql: " . implode(',', $result->errorInfo() ) ); return NULL; } } else { if ( defined('ZM_DB_DEBUG') ) { - Logger::Debug("SQL: $sql values:" . ($params?implode(',',$params):'') ); + ZM\Logger::Debug("SQL: $sql values:" . ($params?implode(',',$params):'') ); } $result = $dbConn->query($sql); if ( ! $result ) { - Error("SQL: Error preparing $sql: " . $pdo->errorInfo); + ZM\Error("SQL: Error preparing $sql: " . $pdo->errorInfo); return NULL; } } if ( defined('ZM_DB_DEBUG') ) { if ( $params ) - Logger::Debug("SQL: $sql" . implode(',',$params) . ' rows: '.$result->rowCount() ); + ZM\Logger::Debug("SQL: $sql" . implode(',',$params) . ' rows: '.$result->rowCount() ); else - Logger::Debug("SQL: $sql: rows:" . $result->rowCount() ); + ZM\Logger::Debug("SQL: $sql: rows:" . $result->rowCount() ); } } catch(PDOException $e) { - Error( "SQL-ERR '".$e->getMessage()."', statement was '".$sql."' params:" . ($params?implode(',',$params):'') ); + ZM\Error( "SQL-ERR '".$e->getMessage()."', statement was '".$sql."' params:" . ($params?implode(',',$params):'') ); return NULL; } return $result; @@ -164,7 +164,7 @@ function dbQuery( $sql, $params=NULL ) { function dbFetchOne( $sql, $col=false, $params=NULL ) { $result = dbQuery( $sql, $params ); if ( ! $result ) { - Error( "SQL-ERR dbFetchOne no result, statement was '".$sql."'" . ( $params ? 'params: ' . join(',',$params) : '' ) ); + ZM\Error( "SQL-ERR dbFetchOne no result, statement was '".$sql."'" . ( $params ? 'params: ' . join(',',$params) : '' ) ); return false; } if ( ! $result->rowCount() ) { @@ -175,7 +175,7 @@ function dbFetchOne( $sql, $col=false, $params=NULL ) { if ( $result && $dbRow = $result->fetch(PDO::FETCH_ASSOC) ) { if ( $col ) { if ( ! array_key_exists($col, $dbRow) ) { - Warning("$col does not exist in the returned row " . print_r($dbRow, true)); + ZM\Warning("$col does not exist in the returned row " . print_r($dbRow, true)); } return $dbRow[$col]; } @@ -187,7 +187,7 @@ function dbFetchOne( $sql, $col=false, $params=NULL ) { function dbFetchAll( $sql, $col=false, $params=NULL ) { $result = dbQuery( $sql, $params ); if ( ! $result ) { - Error( "SQL-ERR dbFetchAll no result, statement was '".$sql."'" . ( $params ? 'params: ' .join(',', $params) : '' ) ); + ZM\Error( "SQL-ERR dbFetchAll no result, statement was '".$sql."'" . ( $params ? 'params: ' .join(',', $params) : '' ) ); return false; } @@ -294,7 +294,7 @@ function getTableDescription( $table, $asString=1 ) { //$desc['minLength'] = -128; break; default : - Error( "Unexpected text qualifier '".$matches[1]."' found for field '".$row['Field']."' in table '".$table."'" ); + ZM\Error( "Unexpected text qualifier '".$matches[1]."' found for field '".$row['Field']."' in table '".$table."'" ); break; } } elseif ( preg_match( "/^(enum|set)\((.*)\)$/", $row['Type'], $matches ) ) { @@ -326,7 +326,7 @@ function getTableDescription( $table, $asString=1 ) { //$desc['maxValue'] = 127; break; default : - Error( "Unexpected integer qualifier '".$matches[1]."' found for field '".$row['Field']."' in table '".$table."'" ); + ZM\Error( "Unexpected integer qualifier '".$matches[1]."' found for field '".$row['Field']."' in table '".$table."'" ); break; } if ( !empty($matches[1]) ) @@ -361,7 +361,7 @@ function getTableDescription( $table, $asString=1 ) { break; } } else { - Error( "Can't parse database type '".$row['Type']."' found for field '".$row['Field']."' in table '".$table."'" ); + ZM\Error( "Can't parse database type '".$row['Type']."' found for field '".$row['Field']."' in table '".$table."'" ); } if ( $asString ) diff --git a/web/includes/functions.php b/web/includes/functions.php index 54adda289..df6981fe8 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -90,12 +90,12 @@ function CORSHeaders() { # The following is left for future reference/use. $valid = false; - $Servers = Server::find(); + $Servers = ZM\Server::find(); if ( sizeof($Servers) < 1 ) { # Only need CORSHeaders in the event that there are multiple servers in use. # ICON: Might not be true. multi-port? if ( ZM_MIN_STREAMING_PORT ) { - Logger::Debug("Setting default Access-Control-Allow-Origin from " . $_SERVER['HTTP_ORIGIN']); + ZM\Logger::Debug('Setting default Access-Control-Allow-Origin from ' . $_SERVER['HTTP_ORIGIN']); header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); header('Access-Control-Allow-Headers: x-requested-with,x-request'); } @@ -108,14 +108,14 @@ function CORSHeaders() { preg_match('/^(https?:\/\/)?'.preg_quote($Server->Name(),'/').'/i', $_SERVER['HTTP_ORIGIN']) ) { $valid = true; - Logger::Debug("Setting Access-Control-Allow-Origin from " . $_SERVER['HTTP_ORIGIN']); + ZM\Logger::Debug("Setting Access-Control-Allow-Origin from " . $_SERVER['HTTP_ORIGIN']); header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); header('Access-Control-Allow-Headers: x-requested-with,x-request'); break; } } if ( !$valid ) { - Warning($_SERVER['HTTP_ORIGIN'] . ' is not found in servers list.'); + ZM\Warning($_SERVER['HTTP_ORIGIN'] . ' is not found in servers list.'); } } } @@ -409,7 +409,7 @@ function getZmuCommand( $args ) { } function getEventDefaultVideoPath( $event ) { - $Event = new Event( $event ); + $Event = new ZM\Event( $event ); return $Event->getStreamSrc( array( 'mode'=>'mpeg', 'format'=>'h264' ) ); } @@ -424,15 +424,15 @@ function deletePath( $path ) { function deleteEvent( $event ) { if ( empty($event) ) { - Error( 'Empty event passed to deleteEvent.'); + ZM\Error('Empty event passed to deleteEvent.'); return; } if ( gettype($event) != 'array' ) { # $event could be an eid, so turn it into an event hash - $event = new Event( $event ); + $event = new ZM\Event( $event ); } else { -Logger::Debug("Event type: " . gettype($event)); +ZM\Logger::Debug("Event type: " . gettype($event)); } global $user; @@ -527,7 +527,7 @@ function htmlOptions($contents, $values) { if ( isset($option['disabled']) ) { $disabled = $option['disabled']; - Error("Setting to disabled"); + ZM\Error("Setting to disabled"); } } else if ( is_object($option) ) { $text = $option->Name(); @@ -556,7 +556,7 @@ function buildSelect( $name, $contents, $behaviours=false ) { elseif ( isset($_REQUEST[$arr]) ) $value = $_REQUEST[$arr]; if ( !preg_match_all( '/\[\s*[\'"]?(\w+)["\']?\s*\]/', $matches[2], $matches ) ) { - Fatal( "Can't parse selector '$name'" ); + ZM\Fatal( "Can't parse selector '$name'" ); } for ( $i = 0; $i < count($matches[1]); $i++ ) { $idx = $matches[1][$i]; @@ -833,17 +833,17 @@ function daemonControl( $command, $daemon=false, $args=false ) { } $string = escapeshellcmd( $string ); #$string .= ' 2>/dev/null >&- <&- >/dev/null'; -Logger::Debug("daemonControl $string"); +ZM\Logger::Debug("daemonControl $string"); exec( $string ); } function zmcControl($monitor, $mode=false) { - $Monitor = new Monitor( $monitor ); + $Monitor = new ZM\Monitor( $monitor ); return $Monitor->zmcControl($mode); } function zmaControl($monitor, $mode=false) { - $Monitor = new Monitor($monitor); + $Monitor = new ZM\Monitor($monitor); return $Monitor->zmaControl($mode); } @@ -916,7 +916,7 @@ function zmaCheck( $monitor ) { } function getImageSrc( $event, $frame, $scale=SCALE_BASE, $captureOnly=false, $overwrite=false ) { - $Event = new Event( $event ); + $Event = new ZM\Event( $event ); return $Event->getImageSrc( $frame, $scale, $captureOnly, $overwrite ); } @@ -940,7 +940,7 @@ function createListThumbnail( $event, $overwrite=false ) { $scale = (SCALE_BASE*ZM_WEB_LIST_THUMB_HEIGHT)/$event['Height']; $thumbWidth = reScale( $event['Width'], $scale ); } else { - Fatal( "No thumbnail width or height specified, please check in Options->Web" ); + ZM\Fatal( "No thumbnail width or height specified, please check in Options->Web" ); } $imageData = getImageSrc( $event, $frame, $scale, false, $overwrite ); @@ -1196,11 +1196,11 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { if ( ! $StorageArea ) { for ( $j = 0; $j < count($terms); $j++ ) { if ( isset($terms[$j]['attr']) and $terms[$j]['attr'] == 'StorageId' and isset($terms[$j]['val']) ) { - $StorageArea = Storage::find_one(array('Id'=>$terms[$j]['val'])); + $StorageArea = ZM\Storage::find_one(array('Id'=>$terms[$j]['val'])); break; } } // end foreach remaining term - if ( ! $StorageArea ) $StorageArea = new Storage(); + if ( ! $StorageArea ) $StorageArea = new ZM\Storage(); } // end no StorageArea found yet $filter['sql'] .= getDiskPercent( $StorageArea->Path() ); @@ -1210,7 +1210,7 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { if ( ! $StorageArea ) { for ( $j = $i; $j < count($terms); $j++ ) { if ( isset($terms[$i]['attr']) and $terms[$i]['attr'] == 'StorageId' and isset($terms[$j]['val']) ) { - $StorageArea = Storage::find_one(array('Id'=>$terms[$j]['val'])); + $StorageArea = ZM\Storage::find_one(array('Id'=>$terms[$j]['val'])); } } // end foreach remaining term } // end no StorageArea found yet @@ -1242,7 +1242,7 @@ function parseFilter(&$filter, $saveToSession=false, $querySep='&') { } break; case 'StorageId': - $StorageArea = Storage::find_one(array('Id'=>$value)); + $StorageArea = ZM\Storage::find_one(array('Id'=>$value)); if ( $value != 'NULL' ) $value = dbEscape($value); break; @@ -1462,7 +1462,7 @@ function getDiskPercent($path = ZM_DIR_EVENTS) { } function getDiskBlocks() { - if ( ! $StorageArea ) $StorageArea = new Storage(); + if ( ! $StorageArea ) $StorageArea = new ZM\Storage(); $df = shell_exec( 'df '.escapeshellarg($StorageArea->Path() )); $space = -1; if ( preg_match( '/\s(\d+)\s+\d+\s+\d+%/ms', $df, $matches ) ) @@ -1847,17 +1847,17 @@ function coordsToPoints( $coords ) { function limitPoints( &$points, $min_x, $min_y, $max_x, $max_y ) { foreach ( $points as &$point ) { if ( $point['x'] < $min_x ) { - Logger::Debug('Limiting point x'.$point['x'].' to min_x ' . $min_x ); + ZM\Logger::Debug('Limiting point x'.$point['x'].' to min_x ' . $min_x ); $point['x'] = $min_x; } else if ( $point['x'] > $max_x ) { - Logger::Debug('Limiting point x'.$point['x'].' to max_x ' . $max_x ); + ZM\Logger::Debug('Limiting point x'.$point['x'].' to max_x ' . $max_x ); $point['x'] = $max_x; } if ( $point['y'] < $min_y ) { - Logger::Debug('Limiting point y'.$point['y'].' to min_y ' . $min_y ); + ZM\Logger::Debug('Limiting point y'.$point['y'].' to min_y ' . $min_y ); $point['y'] = $min_y; } else if ( $point['y'] > $max_y ) { - Logger::Debug('Limiting point y'.$point['y'].' to max_y ' . $max_y ); + ZM\Logger::Debug('Limiting point y'.$point['y'].' to max_y ' . $max_y ); $point['y'] = $max_y; } } // end foreach point @@ -1912,13 +1912,13 @@ function initX10Status() { if ( !isset($x10_status) ) { $socket = socket_create( AF_UNIX, SOCK_STREAM, 0 ); if ( $socket < 0 ) { - Fatal( 'socket_create() failed: '.socket_strerror($socket) ); + ZM\Fatal( 'socket_create() failed: '.socket_strerror($socket) ); } $sock_file = ZM_PATH_SOCKS.'/zmx10.sock'; if ( @socket_connect( $socket, $sock_file ) ) { $command = 'status'; if ( !socket_write( $socket, $command ) ) { - Fatal( "Can't write to control socket: ".socket_strerror(socket_last_error($socket)) ); + ZM\Fatal( "Can't write to control socket: ".socket_strerror(socket_last_error($socket)) ); } socket_shutdown( $socket, 1 ); $x10Output = ''; @@ -1954,13 +1954,13 @@ function getDeviceStatusX10( $key ) { function setDeviceStatusX10( $key, $status ) { $socket = socket_create( AF_UNIX, SOCK_STREAM, 0 ); if ( $socket < 0 ) { - Fatal( 'socket_create() failed: '.socket_strerror($socket) ); + ZM\Fatal( 'socket_create() failed: '.socket_strerror($socket) ); } $sock_file = ZM_PATH_SOCKS.'/zmx10.sock'; if ( @socket_connect( $socket, $sock_file ) ) { $command = "$status;$key"; if ( !socket_write( $socket, $command ) ) { - Fatal( "Can't write to control socket: ".socket_strerror(socket_last_error($socket)) ); + ZM\Fatal( "Can't write to control socket: ".socket_strerror(socket_last_error($socket)) ); } socket_shutdown( $socket, 1 ); $x10Response = socket_read( $socket, 256 ); @@ -1983,18 +1983,18 @@ function logState() { $state = 'ok'; $levelCounts = array( - Logger::FATAL => array( ZM_LOG_ALERT_FAT_COUNT, ZM_LOG_ALARM_FAT_COUNT ), - Logger::ERROR => array( ZM_LOG_ALERT_ERR_COUNT, ZM_LOG_ALARM_ERR_COUNT ), - Logger::WARNING => array( ZM_LOG_ALERT_WAR_COUNT, ZM_LOG_ALARM_WAR_COUNT ), + ZM\Logger::FATAL => array( ZM_LOG_ALERT_FAT_COUNT, ZM_LOG_ALARM_FAT_COUNT ), + ZM\Logger::ERROR => array( ZM_LOG_ALERT_ERR_COUNT, ZM_LOG_ALARM_ERR_COUNT ), + ZM\Logger::WARNING => array( ZM_LOG_ALERT_WAR_COUNT, ZM_LOG_ALARM_WAR_COUNT ), ); # This is an expensive request, as it has to hit every row of the Logs Table - $sql = 'SELECT Level, COUNT(Level) AS LevelCount FROM Logs WHERE Level < '.Logger::INFO.' AND TimeKey > unix_timestamp(now() - interval '.ZM_LOG_CHECK_PERIOD.' second) GROUP BY Level ORDER BY Level ASC'; + $sql = 'SELECT Level, COUNT(Level) AS LevelCount FROM Logs WHERE Level < '.ZM\Logger::INFO.' AND TimeKey > unix_timestamp(now() - interval '.ZM_LOG_CHECK_PERIOD.' second) GROUP BY Level ORDER BY Level ASC'; $counts = dbFetchAll($sql); if ( $counts ) { foreach ( $counts as $count ) { - if ( $count['Level'] <= Logger::PANIC ) - $count['Level'] = Logger::FATAL; + if ( $count['Level'] <= ZM\Logger::PANIC ) + $count['Level'] = ZM\Logger::FATAL; if ( !($levelCount = $levelCounts[$count['Level']]) ) { Error('Unexpected Log level '.$count['Level']); next; @@ -2026,15 +2026,15 @@ function checkJsonError($value) { $value = var_export($value,true); switch( json_last_error() ) { case JSON_ERROR_DEPTH : - Fatal( "Unable to decode JSON string '$value', maximum stack depth exceeded" ); + ZM\Fatal( "Unable to decode JSON string '$value', maximum stack depth exceeded" ); case JSON_ERROR_CTRL_CHAR : - Fatal( "Unable to decode JSON string '$value', unexpected control character found" ); + ZM\Fatal( "Unable to decode JSON string '$value', unexpected control character found" ); case JSON_ERROR_STATE_MISMATCH : - Fatal( "Unable to decode JSON string '$value', invalid or malformed JSON" ); + ZM\Fatal( "Unable to decode JSON string '$value', invalid or malformed JSON" ); case JSON_ERROR_SYNTAX : - Fatal( "Unable to decode JSON string '$value', syntax error" ); + ZM\Fatal( "Unable to decode JSON string '$value', syntax error" ); default : - Fatal( "Unable to decode JSON string '$value', unexpected error ".json_last_error() ); + ZM\Fatal( "Unable to decode JSON string '$value', unexpected error ".json_last_error() ); case JSON_ERROR_NONE: break; } @@ -2122,7 +2122,7 @@ define( 'HTTP_STATUS_BAD_REQUEST', 400 ); define( 'HTTP_STATUS_FORBIDDEN', 403 ); function ajaxError( $message, $code=HTTP_STATUS_OK ) { - Error( $message ); + ZM\Error( $message ); if ( function_exists( 'ajaxCleanup' ) ) ajaxCleanup(); if ( $code == HTTP_STATUS_OK ) { @@ -2168,7 +2168,7 @@ function cache_bust( $file ) { if ( file_exists(ZM_DIR_CACHE.'/'.$cacheFile) or symlink(ZM_PATH_WEB.'/'.$file, ZM_DIR_CACHE.'/'.$cacheFile) ) { return 'cache/'.$cacheFile; } else { - Warning("Failed linking $file to $cacheFile"); + ZM\Warning("Failed linking $file to $cacheFile"); } return $file; } @@ -2292,7 +2292,7 @@ function getStreamHTML( $monitor, $options = array() ) { $monitor->Name()); } else { if ( $options['mode'] == 'stream' ) { - Info( 'The system has fallen back to single jpeg mode for streaming. Consider enabling Cambozola or upgrading the client browser.' ); + ZM\Info( 'The system has fallen back to single jpeg mode for streaming. Consider enabling Cambozola or upgrading the client browser.' ); } $options['mode'] = 'single'; $streamSrc = $monitor->getStreamSrc( $options ); @@ -2308,7 +2308,7 @@ function getStreamMode( ) { $streamMode = 'jpeg'; } else { $streamMode = 'single'; - Info( 'The system has fallen back to single jpeg mode for streaming. Consider enabling Cambozola or upgrading the client browser.' ); + ZM\Info( 'The system has fallen back to single jpeg mode for streaming. Consider enabling Cambozola or upgrading the client browser.' ); } return $streamMode; } // end function getStreamMode @@ -2349,13 +2349,13 @@ function check_timezone() { #"); if ( $sys_tzoffset != $php_tzoffset ) - Fatal("ZoneMinder is not installed properly: php's date.timezone does not match the system timezone!"); + ZM\Fatal("ZoneMinder is not installed properly: php's date.timezone does not match the system timezone!"); if ( $sys_tzoffset != $mysql_tzoffset ) - Error("ZoneMinder is not installed properly: mysql's timezone does not match the system timezone! Event lists will display incorrect times."); + ZM\Error("ZoneMinder is not installed properly: mysql's timezone does not match the system timezone! Event lists will display incorrect times."); if (!ini_get('date.timezone') || !date_default_timezone_set(ini_get('date.timezone'))) - Fatal( "ZoneMinder is not installed properly: php's date.timezone is not set to a valid timezone" ); + ZM\Fatal( "ZoneMinder is not installed properly: php's date.timezone is not set to a valid timezone" ); } diff --git a/web/includes/logger.php b/web/includes/logger.php index 28d0ce902..1e37f708e 100644 --- a/web/includes/logger.php +++ b/web/includes/logger.php @@ -1,5 +1,6 @@ CanZoom() ) { if ( $monitor->CanZoomCon() ) - $cmds['ZoomRoot'] = "zoomCon"; + $cmds['ZoomRoot'] = 'zoomCon'; elseif ( $monitor->CanZoomRel() ) - $cmds['ZoomRoot'] = "zoomRel"; + $cmds['ZoomRoot'] = 'zoomRel'; elseif ( $monitor->CanZoomAbs() ) - $cmds['ZoomRoot'] = "zoomAbs"; - $cmds['ZoomTele'] = $cmds['ZoomRoot']."Tele"; - $cmds['ZoomWide'] = $cmds['ZoomRoot']."Wide"; - $cmds['ZoomStop'] = "zoomStop"; - $cmds['ZoomAuto'] = "zoomAuto"; - $cmds['ZoomMan'] = "zoomMan"; + $cmds['ZoomRoot'] = 'zoomAbs'; + $cmds['ZoomTele'] = $cmds['ZoomRoot'].'Tele'; + $cmds['ZoomWide'] = $cmds['ZoomRoot'].'Wide'; + $cmds['ZoomStop'] = 'zoomStop'; + $cmds['ZoomAuto'] = 'zoomAuto'; + $cmds['ZoomMan'] = 'zoomMan'; } if ( $monitor->CanFocus() ) { if ( $monitor->CanFocusCon() ) - $cmds['FocusRoot'] = "focusCon"; + $cmds['FocusRoot'] = 'focusCon'; elseif ( $monitor->CanFocusRel() ) - $cmds['FocusRoot'] = "focusRel"; + $cmds['FocusRoot'] = 'focusRel'; elseif ( $monitor->CanFocusAbs() ) - $cmds['FocusRoot'] = "focusAbs"; - $cmds['FocusFar'] = $cmds['FocusRoot']."Far"; - $cmds['FocusNear'] = $cmds['FocusRoot']."Near"; - $cmds['FocusStop'] = "focusStop"; - $cmds['FocusAuto'] = "focusAuto"; - $cmds['FocusMan'] = "focusMan"; + $cmds['FocusRoot'] = 'focusAbs'; + $cmds['FocusFar'] = $cmds['FocusRoot'].'Far'; + $cmds['FocusNear'] = $cmds['FocusRoot'].'Near'; + $cmds['FocusStop'] = 'focusStop'; + $cmds['FocusAuto'] = 'focusAuto'; + $cmds['FocusMan'] = 'focusMan'; } if ( $monitor->CanIris() ) { if ( $monitor->CanIrisCon() ) - $cmds['IrisRoot'] = "irisCon"; + $cmds['IrisRoot'] = 'irisCon'; elseif ( $monitor->CanIrisRel() ) - $cmds['IrisRoot'] = "irisRel"; + $cmds['IrisRoot'] = 'irisRel'; elseif ( $monitor->CanIrisAbs() ) - $cmds['IrisRoot'] = "irisAbs"; - $cmds['IrisOpen'] = $cmds['IrisRoot']."Open"; - $cmds['IrisClose'] = $cmds['IrisRoot']."Close"; - $cmds['IrisStop'] = "irisStop"; - $cmds['IrisAuto'] = "irisAuto"; - $cmds['IrisMan'] = "irisMan"; + $cmds['IrisRoot'] = 'irisAbs'; + $cmds['IrisOpen'] = $cmds['IrisRoot'].'Open'; + $cmds['IrisClose'] = $cmds['IrisRoot'].'Close'; + $cmds['IrisStop'] = 'irisStop'; + $cmds['IrisAuto'] = 'irisAuto'; + $cmds['IrisMan'] = 'irisMan'; } if ( $monitor->CanWhite() ) { if ( $monitor->CanWhiteCon() ) - $cmds['WhiteRoot'] = "whiteCon"; + $cmds['WhiteRoot'] = 'whiteCon'; elseif ( $monitor->CanWhiteRel() ) - $cmds['WhiteRoot'] = "whiteRel"; + $cmds['WhiteRoot'] = 'whiteRel'; elseif ( $monitor->CanWhiteAbs() ) - $cmds['WhiteRoot'] = "whiteAbs"; - $cmds['WhiteIn'] = $cmds['WhiteRoot']."In"; - $cmds['WhiteOut'] = $cmds['WhiteRoot']."Out"; - $cmds['WhiteAuto'] = "whiteAuto"; - $cmds['WhiteMan'] = "whiteMan"; + $cmds['WhiteRoot'] = 'whiteAbs'; + $cmds['WhiteIn'] = $cmds['WhiteRoot'].'In'; + $cmds['WhiteOut'] = $cmds['WhiteRoot'].'Out'; + $cmds['WhiteAuto'] = 'whiteAuto'; + $cmds['WhiteMan'] = 'whiteMan'; } if ( $monitor->CanGain() ) { if ( $monitor->CanGainCon() ) - $cmds['GainRoot'] = "gainCon"; + $cmds['GainRoot'] = 'gainCon'; elseif ( $monitor->CanGainRel() ) - $cmds['GainRoot'] = "gainRel"; + $cmds['GainRoot'] = 'gainRel'; elseif ( $monitor->CanGainAbs() ) - $cmds['GainRoot'] = "gainAbs"; - $cmds['GainUp'] = $cmds['GainRoot']."Up"; - $cmds['GainDown'] = $cmds['GainRoot']."Down"; - $cmds['GainAuto'] = "gainAuto"; - $cmds['GainMan'] = "gainMan"; + $cmds['GainRoot'] = 'gainAbs'; + $cmds['GainUp'] = $cmds['GainRoot'].'Up'; + $cmds['GainDown'] = $cmds['GainRoot'].'Down'; + $cmds['GainAuto'] = 'gainAuto'; + $cmds['GainMan'] = 'gainMan'; } if ( $monitor->CanMove() ) { if ( $monitor->CanMoveCon() ) { - $cmds['MoveRoot'] = "moveCon"; - $cmds['Center'] = "moveStop"; + $cmds['MoveRoot'] = 'moveCon'; + $cmds['Center'] = 'moveStop'; } elseif ( $monitor->CanMoveRel() ) { - $cmds['MoveRoot'] = "moveRel"; + $cmds['MoveRoot'] = 'moveRel'; $cmds['Center'] = $cmds['PresetHome']; } elseif ( $monitor->CanMoveAbs() ) { - $cmds['MoveRoot'] = "moveAbs"; + $cmds['MoveRoot'] = 'moveAbs'; $cmds['Center'] = $cmds['PresetHome']; } else { $cmds['MoveRoot'] = ''; } - $cmds['MoveUp'] = $cmds['MoveRoot']."Up"; - $cmds['MoveDown'] = $cmds['MoveRoot']."Down"; - $cmds['MoveLeft'] = $cmds['MoveRoot']."Left"; - $cmds['MoveRight'] = $cmds['MoveRoot']."Right"; - $cmds['MoveUpLeft'] = $cmds['MoveRoot']."UpLeft"; - $cmds['MoveUpRight'] = $cmds['MoveRoot']."UpRight"; - $cmds['MoveDownLeft'] = $cmds['MoveRoot']."DownLeft"; - $cmds['MoveDownRight'] = $cmds['MoveRoot']."DownRight"; + $cmds['MoveUp'] = $cmds['MoveRoot'].'Up'; + $cmds['MoveDown'] = $cmds['MoveRoot'].'Down'; + $cmds['MoveLeft'] = $cmds['MoveRoot'].'Left'; + $cmds['MoveRight'] = $cmds['MoveRoot'].'Right'; + $cmds['MoveUpLeft'] = $cmds['MoveRoot'].'UpLeft'; + $cmds['MoveUpRight'] = $cmds['MoveRoot'].'UpRight'; + $cmds['MoveDownLeft'] = $cmds['MoveRoot'].'DownLeft'; + $cmds['MoveDownRight'] = $cmds['MoveRoot'].'DownRight'; } return( $cmds ); } @@ -128,15 +128,15 @@ function controlFocus( $monitor, $cmds ) { ?>
-
-
CanFocusCon() ) { ?> onclick="controlCmd('')">
-
+ + +
CanAutoFocus() ) { ?> - - + + @@ -152,15 +152,15 @@ function controlZoom( $monitor, $cmds ) { ?>
-
-
CanZoomCon() ) { ?> onclick="controlCmd('')">
-
+ + +
CanAutoZoom() ) { ?> - - + + @@ -175,15 +175,15 @@ function controlIris( $monitor, $cmds ) { ?>
-
-
CanIrisCon() ) { ?> onclick="controlCmd('')">
-
+ + +
CanAutoIris() ) { ?> - - + + @@ -199,15 +199,15 @@ function controlWhite( $monitor, $cmds ) { ?>
-
-
CanWhiteCon() ) { ?> onclick="controlCmd('')">
-
+ + +
CanAutoWhite() ) { ?> - - + + @@ -229,19 +229,19 @@ function controlPanTilt( $monitor, $cmds ) { $hasTilt = $monitor->CanTilt(); $hasDiag = $hasPan && $hasTilt && $monitor->CanMoveDiag(); ?> -
-
-
-
+ + + + -
+ -
+ -
-
-
-
+ + + +
NumPresets(); $i++ ) { ?> - +
HasHomePreset() ) { ?> - + CanSleep() ) { ?> - + CanReset() ) { ?> - + diff --git a/web/skins/classic/includes/functions.php b/web/skins/classic/includes/functions.php index 04b87bd33..6b1187a5f 100644 --- a/web/skins/classic/includes/functions.php +++ b/web/skins/classic/includes/functions.php @@ -265,7 +265,7 @@ function getNavBarHTML($reload = null) {
  • Logger::NOLOG ) { + if ( ZM\logToDatabase() > ZM\Logger::NOLOG ) { if ( ! ZM_RUN_AUDIT ) { # zmaudit can clean the logs, but if we aren't running it, then we should clecan them regularly dbQuery('DELETE FROM Logs WHERE TimeKey < unix_timestamp( NOW() - interval '.ZM_LOG_DATABASE_LIMIT.') LIMIT 100'); @@ -355,13 +355,13 @@ if ($reload == 'reload') ob_start(); ?>
  • : Path()] = $area; } if ( ! isset($storage_paths[ZM_DIR_EVENTS]) ) { - array_push( $storage_areas, new Storage() ); + array_push( $storage_areas, new ZM\Storage() ); } $func = function($S){ $class = ''; diff --git a/web/skins/classic/js/base.js b/web/skins/classic/js/base.js index 87220a183..b0a28dc96 100644 --- a/web/skins/classic/js/base.js +++ b/web/skins/classic/js/base.js @@ -27,7 +27,7 @@ var popupSizes = { 'bandwidth': {'width': 300, 'height': 200}, 'console': {'width': 750, 'height': 312}, - 'control': {'width': 380, 'height': 480}, + 'control': {'width': 480, 'height': 480}, 'controlcaps': {'width': 780, 'height': 320}, 'controlcap': {'width': 400, 'height': 400}, 'cycle': {'addWidth': 32, 'minWidth': 384, 'addHeight': 62}, diff --git a/web/skins/classic/views/_monitor_filters.php b/web/skins/classic/views/_monitor_filters.php index 0656773f1..3e149cfba 100644 --- a/web/skins/classic/views/_monitor_filters.php +++ b/web/skins/classic/views/_monitor_filters.php @@ -18,7 +18,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -$servers = Server::find(null, array('order'=>'lower(Name)')); +$servers = ZM\Server::find(null, array('order'=>'lower(Name)')); $ServersById = array(); foreach ( $servers as $S ) { $ServersById[$S->Id()] = $S; @@ -37,7 +37,7 @@ foreach ( array('Group','Function','ServerId','StorageId','Status','MonitorId',' } session_write_close(); -$storage_areas = Storage::find(); +$storage_areas = ZM\Storage::find(); $StorageById = array(); foreach ( $storage_areas as $S ) { $StorageById[$S->Id()] = $S; @@ -52,7 +52,7 @@ $html = '; $GroupsById = array(); -foreach ( Group::find() as $G ) { +foreach ( ZM\Group::find() as $G ) { $GroupsById[$G->Id()] = $G; } @@ -61,14 +61,13 @@ if ( count($GroupsById) ) { $html .= ''; # This will end up with the group_id of the deepest selection $group_id = isset($_SESSION['Group']) ? $_SESSION['Group'] : null; - $html .= Group::get_group_dropdown(); - $groupSql = Group::get_group_sql($group_id); + $html .= ZM\Group::get_group_dropdown(); + $groupSql = ZM\Group::get_group_sql($group_id); $html .= ''; } $selected_monitor_ids = isset($_SESSION['MonitorId']) ? $_SESSION['MonitorId'] : array(); if ( ! is_array( $selected_monitor_ids ) ) { - Warning("Turning selected_monitor_ids into an array $selected_monitor_ids"); $selected_monitor_ids = array($selected_monitor_ids); } @@ -189,12 +188,12 @@ $html .= htmlSelect( 'Status[]', $status_options, for ( $i = 0; $i < count($monitors); $i++ ) { if ( !visibleMonitor($monitors[$i]['Id']) ) { - Warning('Monitor '.$monitors[$i]['Id'].' is not visible'); + ZM\Logger::Warning('Monitor '.$monitors[$i]['Id'].' is not visible'); continue; } if ( isset($_SESSION['MonitorName']) ) { - $Monitor = new Monitor($monitors[$i]); + $Monitor = new ZM\Monitor($monitors[$i]); ini_set('track_errors', 'on'); $php_errormsg = ''; $regexp = $_SESSION['MonitorName']; @@ -210,7 +209,7 @@ $html .= htmlSelect( 'Status[]', $status_options, } if ( isset($_SESSION['Source']) ) { - $Monitor = new Monitor($monitors[$i]); + $Monitor = new ZM\Monitor($monitors[$i]); ini_set('track_errors', 'on'); $php_errormsg = ''; $regexp = $_SESSION['Source']; diff --git a/web/skins/classic/views/add_monitors.php b/web/skins/classic/views/add_monitors.php index 403c643c9..3b2f7590f 100644 --- a/web/skins/classic/views/add_monitors.php +++ b/web/skins/classic/views/add_monitors.php @@ -18,7 +18,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -if ( !canEdit( 'Monitors' ) ) { +if ( !canEdit('Monitors') ) { $view = 'error'; return; } @@ -61,8 +61,8 @@ xhtmlHeaders(__FILE__, translate('AddMonitors')); Group - Example Name MN1-30 INQ37.01 - http://10.34.152.20:2001/?action=stream + Example Name Driveway + http://192.168.1.0/?action=stream MN1 @@ -80,7 +80,7 @@ xhtmlHeaders(__FILE__, translate('AddMonitors')); ?> Id()] = $S; @@ -92,7 +92,7 @@ xhtmlHeaders(__FILE__, translate('AddMonitors')); Id()] = $S; diff --git a/web/skins/classic/views/console.php b/web/skins/classic/views/console.php index f5164dc88..e617c1c1c 100644 --- a/web/skins/classic/views/console.php +++ b/web/skins/classic/views/console.php @@ -227,7 +227,7 @@ ob_end_clean(); echo $table_head; for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) { $monitor = $displayMonitors[$monitor_i]; - $Monitor = new Monitor($monitor); + $Monitor = new ZM\Monitor($monitor); if ( $monitor_i and ( $monitor_i % 100 == 0 ) ) { echo ''; @@ -272,7 +272,7 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) { ' : '>') . $monitor['Name'] ?>
    ', array_map(function($group_id){ - $Group = Group::find_one(array('Id'=>$group_id)); + $Group = ZM\Group::find_one(array('Id'=>$group_id)); if ( $Group ) { $Groups = $Group->Parents(); array_push( $Groups, $Group ); @@ -302,7 +302,7 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) {
    - Name(); ?> + Name(); ?> '. makePopupLink( '?view=monitor&mid='.$monitor['Id'], 'zmMonitor'.$monitor['Id'], 'monitor', ''.validHtmlStr($Monitor->Source()).'', canEdit('Monitors') ).''; diff --git a/web/skins/classic/views/control.php b/web/skins/classic/views/control.php index 0e5561544..fc8923d82 100644 --- a/web/skins/classic/views/control.php +++ b/web/skins/classic/views/control.php @@ -46,7 +46,7 @@ foreach ( dbFetchAll($sql, false, $params) as $row ) { foreach ( getSkinIncludes('includes/control_functions.php') as $includeFile ) require_once $includeFile; -$monitor = new Monitor($mid); +$monitor = new ZM\Monitor($mid); $focusWindow = true; diff --git a/web/skins/classic/views/cycle.php b/web/skins/classic/views/cycle.php index 2ea5e48ab..1e83e2c5b 100644 --- a/web/skins/classic/views/cycle.php +++ b/web/skins/classic/views/cycle.php @@ -50,7 +50,7 @@ foreach( $displayMonitors as &$row ) { $row['PopupScale'] = reScale(SCALE_BASE, $row['DefaultScale'], ZM_WEB_DEFAULT_SCALE); $row['connKey'] = generateConnKey(); - $monitors[] = new Monitor($row); + $monitors[] = new ZM\Monitor($row); } # end foreach Monitor if ( $monitors ) { diff --git a/web/skins/classic/views/event.php b/web/skins/classic/views/event.php index cbad14f02..6b657b2b0 100644 --- a/web/skins/classic/views/event.php +++ b/web/skins/classic/views/event.php @@ -26,7 +26,7 @@ if ( !canView('Events') ) { $eid = validInt( $_REQUEST['eid'] ); $fid = !empty($_REQUEST['fid'])?validInt($_REQUEST['fid']):1; -$Event = new Event( $eid ); +$Event = new ZM\Event( $eid ); if ( $user['MonitorIds'] ) { $monitor_ids = explode( ',', $user['MonitorIds'] ); if ( count($monitor_ids) and ! in_array( $Event->MonitorId(), $monitor_ids ) ) { diff --git a/web/skins/classic/views/events.php b/web/skins/classic/views/events.php index 3fd777ef6..703e67153 100644 --- a/web/skins/classic/views/events.php +++ b/web/skins/classic/views/events.php @@ -80,12 +80,12 @@ $focusWindow = true; if ( $_POST ) { // I think this is basically so that a refresh doesn't repost - Logger::Debug("Redirecting to " . $_SERVER['REQUEST_URI']); + ZM\Logger::Debug('Redirecting to ' . $_SERVER['REQUEST_URI']); header('Location: ?view=' . $view.htmlspecialchars_decode($filterQuery).htmlspecialchars_decode($sortQuery).$limitQuery.'&page='.$page); exit(); } -$storage_areas = Storage::find(); +$storage_areas = ZM\Storage::find(); $StorageById = array(); foreach ( $storage_areas as $S ) { $StorageById[$S->Id()] = $S; @@ -146,7 +146,7 @@ $disk_space_total = 0; $results = dbQuery($eventsSql); while ( $event_row = dbFetchNext($results) ) { - $event = new Event($event_row); + $event = new ZM\Event($event_row); if ( $event_row['Archived'] ) $archived = true; else @@ -248,7 +248,7 @@ while ( $event_row = dbFetchNext($results) ) { echo ''; } // end if ZM_WEB_LIST_THUMBS ?> - + Monitor(); if ( !empty($fid) ) { @@ -39,7 +39,7 @@ if ( !empty($fid) ) { } else { $frame = dbFetchOne( 'SELECT * FROM Frames WHERE EventId = ? AND Score = ?', NULL, array( $eid, $Event->MaxScore() ) ); } -$Frame = new Frame($frame); +$Frame = new ZM\Frame($frame); $maxFid = $Event->Frames(); @@ -63,7 +63,7 @@ $scale = $scale ?: "auto"; $imageData = $Event->getImageSrc( $frame, $scale, 0 ); if ( ! $imageData ) { - Error("No data found for Event $eid frame $fid"); + ZM\Error("No data found for Event $eid frame $fid"); $imageData = array(); } diff --git a/web/skins/classic/views/frames.php b/web/skins/classic/views/frames.php index 83e3f69dd..3e146c958 100644 --- a/web/skins/classic/views/frames.php +++ b/web/skins/classic/views/frames.php @@ -23,7 +23,7 @@ if ( !canView('Events') ) { return; } require_once('includes/Frame.php'); -$Event = new Event( $_REQUEST['eid'] ); +$Event = new ZM\Event($_REQUEST['eid']); $sql = 'SELECT *, unix_timestamp( TimeStamp ) AS UnixTimeStamp FROM Frames WHERE EventID = ? ORDER BY FrameId'; $frames = dbFetchAll( $sql, NULL, array( $_REQUEST['eid'] ) ); @@ -62,7 +62,7 @@ xhtmlHeaders(__FILE__, translate('Frames').' - '.$Event->Id() ); diff --git a/web/skins/classic/views/group.php b/web/skins/classic/views/group.php index ac689a176..3f7629a75 100644 --- a/web/skins/classic/views/group.php +++ b/web/skins/classic/views/group.php @@ -24,9 +24,9 @@ if ( !canEdit('Groups') ) { } if ( !empty($_REQUEST['gid']) ) { - $newGroup = new Group($_REQUEST['gid']); + $newGroup = new ZM\Group($_REQUEST['gid']); } else { - $newGroup = new Group(); + $newGroup = new ZM\Group(); } xhtmlHeaders(__FILE__, translate('Group').' - '.$newGroup->Name()); @@ -51,7 +51,7 @@ xhtmlHeaders(__FILE__, translate('Group').' - '.$newGroup->Name()); Id()] = $Group; } diff --git a/web/skins/classic/views/groups.php b/web/skins/classic/views/groups.php index 9a6bf9242..5ae28a40a 100644 --- a/web/skins/classic/views/groups.php +++ b/web/skins/classic/views/groups.php @@ -28,7 +28,7 @@ $group_id = 0; $max_depth = 0; $Groups = array(); -foreach ( Group::find() as $Group ) { +foreach ( ZM\Group::find() as $Group ) { $Groups[$Group->Id()] = $Group; } diff --git a/web/skins/classic/views/js/montagereview.js.php b/web/skins/classic/views/js/montagereview.js.php index c887bb0e3..7c529790b 100644 --- a/web/skins/classic/views/js/montagereview.js.php +++ b/web/skins/classic/views/js/montagereview.js.php @@ -120,21 +120,21 @@ echo " };\n"; echo "\nvar Storage = [];\n"; $have_storage_zero = 0; -foreach ( Storage::find() as $Storage ) { +foreach ( ZM\Storage::find() as $Storage ) { echo 'Storage[' . $Storage->Id() . '] = ' . $Storage->to_json(). ";\n"; if ( $Storage->Id() == 0 ) $have_storage_zero = true; } if ( !$have_storage_zero ) { - $Storage = new Storage(); + $Storage = new ZM\Storage(); echo 'Storage[0] = ' . $Storage->to_json(). ";\n"; } echo "\nvar Servers = [];\n"; // Fall back to get Server paths, etc when no using multi-server mode -$Server = new Server(); +$Server = new ZM\Server(); echo 'Servers[0] = new Server(' . $Server->to_json(). ");\n"; -foreach ( Server::find() as $Server ) { +foreach ( ZM\Server::find() as $Server ) { echo 'Servers[' . $Server->Id() . '] = new Server(' . $Server->to_json(). ");\n"; } diff --git a/web/skins/classic/views/js/privacy.js b/web/skins/classic/views/js/privacy.js deleted file mode 100644 index bbf17f864..000000000 --- a/web/skins/classic/views/js/privacy.js +++ /dev/null @@ -1,10 +0,0 @@ -function submitForm( element ) { - var form = element.form; - if ( form.option.selectedIndex == 0 ) { - form.view.value = currentView; - } else { - form.view.value = 'none'; - } - form.submit(); -} - diff --git a/web/skins/classic/views/js/server.js b/web/skins/classic/views/js/server.js index 3db028c66..1e123c2ec 100644 --- a/web/skins/classic/views/js/server.js +++ b/web/skins/classic/views/js/server.js @@ -1,11 +1,11 @@ function validateForm(form) { var errors = []; if ( !form.elements['newServer[Name]'].value ) { - errors[errors.length] = "You must supply a name"; + errors[errors.length] = 'You must supply a name'; } if ( errors.length ) { - alert( errors.join( "\n" ) ); - return ( false ); + alert(errors.join("\n")); + return false; } - return ( true ); + return true; } diff --git a/web/skins/classic/views/monitor.php b/web/skins/classic/views/monitor.php index 9ad1024dd..1e7185f1b 100644 --- a/web/skins/classic/views/monitor.php +++ b/web/skins/classic/views/monitor.php @@ -36,7 +36,7 @@ if ( ! $Server ) { $monitor = null; if ( ! empty($_REQUEST['mid']) ) { - $monitor = new Monitor( $_REQUEST['mid'] ); + $monitor = new ZM\Monitor( $_REQUEST['mid'] ); if ( $monitor and ZM_OPT_X10 ) $x10Monitor = dbFetchOne( 'SELECT * FROM TriggersX10 WHERE MonitorId = ?', NULL, array($_REQUEST['mid']) ); } @@ -44,7 +44,7 @@ if ( ! $monitor ) { $nextId = getTableAutoInc( 'Monitors' ); if ( isset( $_REQUEST['dupId'] ) ) { - $monitor = new Monitor( $_REQUEST['dupId'] ); + $monitor = new ZM\Monitor( $_REQUEST['dupId'] ); $monitor->GroupIds(); // have to load before we change the Id if ( ZM_OPT_X10 ) $x10Monitor = dbFetchOne( 'SELECT * FROM TriggersX10 WHERE MonitorId = ?', NULL, array($_REQUEST['dupId']) ); @@ -52,7 +52,7 @@ if ( ! $monitor ) { $monitor->Name( translate('Monitor').'-'.$nextId ); $monitor->Id( $nextId ); } else { - $monitor = new Monitor(); + $monitor = new ZM\Monitor(); $monitor->set( array( 'Id' => 0, 'Name' => translate('Monitor').'-'.$nextId, @@ -689,10 +689,8 @@ switch ( $tab ) { 'None','auto'=>'Auto'); - $result = dbQuery( 'SELECT * FROM Servers ORDER BY Name'); - $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Server' ); - foreach ( $results as $row => $server_obj ) { - $servers[$server_obj->Id()] = $server_obj->Name(); + foreach ( ZM\Server::find(NULL, array('order'=>'lower(Name)')) as $Server ) { + $servers[$Server->Id()] = $Server->Name(); } echo htmlSelect( 'newMonitor[ServerId]', $servers, $monitor->ServerId() ); ?> @@ -700,10 +698,8 @@ switch ( $tab ) { 'Default'); - $result = dbQuery( 'SELECT * FROM Storage ORDER BY Name'); - $results = $result->fetchALL(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'Storage' ); - foreach ( $results as $row => $storage_obj ) { - $storage_areas[$storage_obj->Id] = $storage_obj->Name(); + foreach ( ZM\Storage::find( NULL, array('order'=>'lower(Name)') ) as $Storage ) { + $storage_areas[$Storage->Id()] = $Storage->Name(); } echo htmlSelect( 'newMonitor[StorageId]', $storage_areas, $monitor->StorageId() ); ?> @@ -744,7 +740,7 @@ switch ( $tab ) { $i, @@ -247,13 +247,13 @@ function probeNetwork() { $arp_command = ZM_PATH_ARP; $result = explode(' ', $arp_command); if ( !is_executable($result[0]) ) { - Error("ARP compatible binary not found or not executable by the web user account. Verify ZM_PATH_ARP points to a valid arp tool."); + ZM\Error("ARP compatible binary not found or not executable by the web user account. Verify ZM_PATH_ARP points to a valid arp tool."); return; } $result = exec(escapeshellcmd($arp_command), $output, $status); if ( $status ) { - Error("Unable to probe network cameras, status is '$status'"); + ZM\Error("Unable to probe network cameras, status is '$status'"); return; } diff --git a/web/skins/classic/views/monitors.php b/web/skins/classic/views/monitors.php index a8d2e9d8d..3cf2f5edc 100644 --- a/web/skins/classic/views/monitors.php +++ b/web/skins/classic/views/monitors.php @@ -23,14 +23,14 @@ if ( !canEdit('Monitors') ) { return; } -$monitors = Monitor::find(array('Id' => $_REQUEST['mids'])); +$monitors = ZM\Monitor::find(array('Id' => $_REQUEST['mids'])); $monitor = $monitors[0]; -$servers = Server::find(); +$servers = ZM\Server::find(); $ServersById = array(); foreach ( $servers as $S ) { $ServersById[$S->Id()] = $S; } -$storage_areas = Storage::find(); +$storage_areas = ZM\Storage::find(); $StorageById = array(); foreach ( $storage_areas as $S ) { $StorageById[$S->Id()] = $S; diff --git a/web/skins/classic/views/montage.php b/web/skins/classic/views/montage.php index a413441f7..987810513 100644 --- a/web/skins/classic/views/montage.php +++ b/web/skins/classic/views/montage.php @@ -50,16 +50,16 @@ $scale = '100'; # actual if ( isset( $_REQUEST['scale'] ) ) { $scale = validInt($_REQUEST['scale']); - Logger::Debug("Setting scale from request to $scale"); + ZM\Logger::Debug("Setting scale from request to $scale"); } else if ( isset($_COOKIE['zmMontageScale']) ) { $scale = $_COOKIE['zmMontageScale']; - Logger::Debug("Setting scale from cookie to $scale"); + ZM\Logger::Debug("Setting scale from cookie to $scale"); } if ( ! $scale ) $scale = 100; -$layouts = MontageLayout::find(NULL, array('order'=>"lower('Name')")); +$layouts = ZM\MontageLayout::find(NULL, array('order'=>"lower('Name')")); $layoutsById = array(); foreach ( $layouts as $l ) { $layoutsById[$l->Id()] = $l; @@ -126,7 +126,7 @@ foreach( $displayMonitors as &$row ) { if ( ! isset($heights[$row['Height']]) ) { $heights[$row['Height']] = $row['Height']; } - $monitors[] = new Monitor($row); + $monitors[] = new ZM\Monitor($row); } # end foreach Monitor xhtmlHeaders(__FILE__, translate('Montage')); diff --git a/web/skins/classic/views/montagereview.php b/web/skins/classic/views/montagereview.php index 53e8b51cf..563c9b52b 100644 --- a/web/skins/classic/views/montagereview.php +++ b/web/skins/classic/views/montagereview.php @@ -223,7 +223,7 @@ $monitors = array(); foreach( $displayMonitors as $row ) { if ( $row['Function'] == 'None' || $row['Type'] == 'WebSite' ) continue; - $Monitor = new Monitor($row); + $Monitor = new ZM\Monitor($row); $monitors[] = $Monitor; } diff --git a/web/skins/classic/views/onvifprobe.php b/web/skins/classic/views/onvifprobe.php index e715ab950..ed4dce6e3 100644 --- a/web/skins/classic/views/onvifprobe.php +++ b/web/skins/classic/views/onvifprobe.php @@ -36,12 +36,12 @@ function execONVIF( $cmd ) { if ( $status ) { $html_output = implode( '
    ', $output ); - Fatal( "Unable to probe network cameras, status is '$status'. Output was:

    + ZM\Fatal( "Unable to probe network cameras, status is '$status'. Output was:

    $html_output

    Please the following command from a command line for more information:

    $shell_command" ); } else { - Logger::Debug( "Results from probe: " . implode( '
    ', $output ) ); + ZM\Logger::Debug( "Results from probe: " . implode( '
    ', $output ) ); } return $output; @@ -73,7 +73,7 @@ function probeCameras( $localIp ) { } elseif ( $tokens[1] == 'location' ) { // $camera['location'] = $tokens[2]; } else { - Logger::Debug('Unknown token ' . $tokens[1]); + ZM\Logger::Debug('Unknown token ' . $tokens[1]); } } } // end foreach token @@ -109,7 +109,7 @@ function probeProfiles( $device_ep, $soapversion, $username, $password ) { ); $profiles[] = $profile; } else { - Logger::Debug("Line did not match preg: $line"); + ZM\Logger::Debug("Line did not match preg: $line"); } } // end foreach line } // end if results from execONVIF @@ -190,7 +190,7 @@ if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) {

    - +

    @@ -206,12 +206,12 @@ if ( !isset($_REQUEST['step']) || ($_REQUEST['step'] == '1') ) { //==== STEP 2 ============================================================ } else if($_REQUEST['step'] == '2') { if ( empty($_REQUEST['probe']) ) - Fatal('No probe passed in request. Please go back and try again.'); + ZM\Fatal('No probe passed in request. Please go back and try again.'); #|| empty($_REQUEST['username']) || #empty($_REQUEST['password']) ) $probe = json_decode(base64_decode($_REQUEST['probe'])); - Logger::Debug(print_r($probe,true)); + ZM\Logger::Debug(print_r($probe,true)); foreach ( $probe as $name=>$value ) { if ( isset($value) ) { $monitor[$name] = $value; diff --git a/web/skins/classic/views/options.php b/web/skins/classic/views/options.php index 8503d1642..3078029d5 100644 --- a/web/skins/classic/views/options.php +++ b/web/skins/classic/views/options.php @@ -230,7 +230,7 @@ foreach ( array_map('basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI Id(), 'zmServer', 'server', validHtmlStr($Server->Name()), $canEdit) ?> @@ -287,7 +287,7 @@ foreach ( array_map('basename', glob('skins/'.$current_skin.'/css/*',GLOB_ONLYDI -'lower(Name)') ) as $Storage ) { ?> +'lower(Name)') ) as $Storage ) { ?> Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Id()), $canEdit ) ?> Id(), 'zmStorage', 'storage', validHtmlStr($Storage->Name()), $canEdit ) ?> diff --git a/web/skins/classic/views/privacy.php b/web/skins/classic/views/privacy.php index 21c0bdb59..d82e4327f 100644 --- a/web/skins/classic/views/privacy.php +++ b/web/skins/classic/views/privacy.php @@ -18,20 +18,19 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // -if ( !canEdit( 'System' ) ) -{ - $view = "error"; - return; +if ( !canEdit('System') ) { + $view = 'error'; + return; } $options = array( - "accept" => translate('Accept'), - "decline" => translate('Decline'), + '1' => translate('Accept'), + '0' => translate('Decline'), ); $focusWindow = true; -xhtmlHeaders(__FILE__, translate('Privacy') ); +xhtmlHeaders(__FILE__, translate('Privacy')); ?>
    @@ -41,31 +40,31 @@ xhtmlHeaders(__FILE__, translate('Privacy') );
    - +

    -
    +

    -
    +

    -
    +

    -
    +

    -

    +

    - +
    diff --git a/web/skins/classic/views/report_event_audit.php b/web/skins/classic/views/report_event_audit.php index 70808138e..c7517728e 100644 --- a/web/skins/classic/views/report_event_audit.php +++ b/web/skins/classic/views/report_event_audit.php @@ -62,7 +62,7 @@ if ( count($selected_monitor_ids) ) { } parseFilter($filter); $filterQuery = $filter['query']; -Logger::Debug($filterQuery); +ZM\Logger::Debug($filterQuery); $eventsSql = 'SELECT *, UNIX_TIMESTAMP(E.StartTime) AS StartTimeSecs, @@ -83,12 +83,12 @@ $eventsSql .= ' ORDER BY Id ASC'; $result = dbQuery($eventsSql); if ( !$result ) { - Fatal('SQL-ERR'); + ZM\Fatal('SQL-ERR'); return; } $EventsByMonitor = array(); while( $event = $result->fetch(PDO::FETCH_ASSOC) ) { - $Event = new Event($event); + $Event = new ZM\Event($event); if ( ! isset($EventsByMonitor[$event['MonitorId']]) ) $EventsByMonitor[$event['MonitorId']] = array( 'Events'=>array(), 'MinGap'=>0, 'MaxGap'=>0, 'FileMissing'=>array(), 'ZeroSize'=>array() ); @@ -147,7 +147,7 @@ while( $event = $result->fetch(PDO::FETCH_ASSOC) ) { ">
    ', array_map(function($group_id){ - $Group = new Group($group_id); + $Group = new ZM\Group($group_id); $Groups = $Group->Parents(); array_push($Groups, $Group); return implode(' > ', array_map(function($Group){ return ''.$Group->Name().''; }, $Groups )); diff --git a/web/skins/classic/views/server.php b/web/skins/classic/views/server.php index 0c028b8c1..67e15d71a 100644 --- a/web/skins/classic/views/server.php +++ b/web/skins/classic/views/server.php @@ -23,7 +23,7 @@ if ( !canEdit('System') ) { return; } -$Server = new Server($_REQUEST['id']); +$Server = new ZM\Server($_REQUEST['id']); if ( $_REQUEST['id'] and ! $Server->Id() ) { $view = 'error'; return; @@ -97,9 +97,8 @@ xhtmlHeaders(__FILE__, translate('Server').' - '.$Server->Name());
    - - - + +
    diff --git a/web/skins/classic/views/storage.php b/web/skins/classic/views/storage.php index 8da0ba5b5..93dd788b7 100644 --- a/web/skins/classic/views/storage.php +++ b/web/skins/classic/views/storage.php @@ -48,7 +48,7 @@ $scheme_options = array( 'Shallow' => translate('Shallow'), ); -$servers = Server::find( null, array('order'=>'lower(Name)') ); +$servers = ZM\Server::find( null, array('order'=>'lower(Name)') ); $ServersById = array(); foreach ( $servers as $S ) { $ServersById[$S->Id()] = $S; diff --git a/web/skins/classic/views/timeline.php b/web/skins/classic/views/timeline.php index acf4bcd11..8a55e607d 100644 --- a/web/skins/classic/views/timeline.php +++ b/web/skins/classic/views/timeline.php @@ -757,7 +757,6 @@ if ( $mode == 'overlay' ) { echo drawYGrid( $chart, $majYScale, 'majLabelY', 'majTickY', 'majGridY graphWidth' ); } echo drawXGrid( $chart, $majXScale, 'majLabelX', 'majTickX', 'majGridX graphHeight', 'zoom graphHeight' ); -Warning("Mode: $mode"); if ( $mode == 'overlay' ) { ?>
    diff --git a/web/skins/classic/views/watch.php b/web/skins/classic/views/watch.php index 085562512..902baaa1c 100644 --- a/web/skins/classic/views/watch.php +++ b/web/skins/classic/views/watch.php @@ -37,7 +37,7 @@ if ( ! visibleMonitor($mid) ) { return; } -$monitor = new Monitor($mid); +$monitor = new ZM\Monitor($mid); #Whether to show the controls button $showPtzControls = ( ZM_OPT_CONTROL && $monitor->Controllable() && canView('Control') && $monitor->Type() != 'WebSite' ); diff --git a/web/skins/classic/views/zone.php b/web/skins/classic/views/zone.php index 93c3aa886..5f03580f7 100644 --- a/web/skins/classic/views/zone.php +++ b/web/skins/classic/views/zone.php @@ -54,7 +54,7 @@ foreach ( getEnumValues( 'Zones', 'CheckMethod' ) as $optCheckMethod ) { $optCheckMethods[$optCheckMethod] = $optCheckMethod; } -$monitor = new Monitor( $mid ); +$monitor = new ZM\Monitor( $mid ); $minX = 0; $maxX = $monitor->Width()-1; diff --git a/web/views/archive.php b/web/views/archive.php index 5e3dbf2c7..2f6980eea 100644 --- a/web/views/archive.php +++ b/web/views/archive.php @@ -48,24 +48,23 @@ if ( $archivetype ) { if ( $mimetype ) { $filename = "zmExport_$connkey.$file_ext"; $filename_path = ZM_DIR_EXPORTS.'/'.$filename; - Logger::Debug("downloading archive from $filename_path"); + ZM\Logger::Debug("downloading archive from $filename_path"); if ( is_readable($filename_path) ) { - ob_clean(); header("Content-type: application/$mimetype" ); header("Content-Disposition: inline; filename=$filename"); header('Content-Length: ' . filesize($filename_path) ); set_time_limit(0); if ( ! @readfile($filename_path) ) { - Error("Error sending $filename_path"); + ZM\Error("Error sending $filename_path"); } } else { - Error("$filename_path does not exist or is not readable."); + ZM\Error("$filename_path does not exist or is not readable."); } } else { - Error("Unsupported archive type specified. Supported archives are tar and zip"); + ZM\Error("Unsupported archive type specified. Supported archives are tar and zip"); } } else { - Error("No archive type given to archive.php. Please specify a tar or zip archive."); + ZM\Error("No archive type given to archive.php. Please specify a tar or zip archive."); } ?> diff --git a/web/views/image.php b/web/views/image.php index b30d99ba6..672baf3f5 100644 --- a/web/views/image.php +++ b/web/views/image.php @@ -64,16 +64,16 @@ if ( empty($_REQUEST['path']) ) { if ( empty($_REQUEST['fid']) ) { header('HTTP/1.0 404 Not Found'); - Fatal('No Frame ID specified'); + ZM\Fatal('No Frame ID specified'); return; } if ( !empty($_REQUEST['eid']) ) { - Logger::Debug("Loading by eid"); - $Event = Event::find_one(array('Id'=>$_REQUEST['eid'])); + ZM\Logger::Debug("Loading by eid"); + $Event = ZM\Event::find_one(array('Id'=>$_REQUEST['eid'])); if ( !$Event ) { header('HTTP/1.0 404 Not Found'); - Fatal('Event '.$_REQUEST['eid'].' Not found'); + ZM\Fatal('Event '.$_REQUEST['eid'].' Not found'); return; } @@ -81,19 +81,19 @@ if ( empty($_REQUEST['path']) ) { $path = $Event->Path().'/objdetect.jpg'; if ( !file_exists($path) ) { header('HTTP/1.0 404 Not Found'); - Fatal("File $path does not exist. Please make sure store_frame_in_zm is enabled in the object detection config"); + ZM\Fatal("File $path does not exist. Please make sure store_frame_in_zm is enabled in the object detection config"); } - $Frame = new Frame(); + $Frame = new ZM\Frame(); $Frame->Id('objdetect'); } else if ( $_REQUEST['fid'] == 'alarm' ) { # look for first alarmed frame - $Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'Type'=>'Alarm'), + $Frame = ZM\Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'Type'=>'Alarm'), array('order'=>'FrameId ASC')); if ( !$Frame ) { # no alarms, get first one I find - $Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'])); + $Frame = ZM\Frame::find_one(array('EventId'=>$_REQUEST['eid'])); if ( !$Frame ) { - Warning('No frame found for event '.$_REQUEST['eid']); - $Frame = new Frame(); + ZM\Warning('No frame found for event '.$_REQUEST['eid']); + $Frame = new ZM\Frame(); $Frame->Delta(1); $Frame->FrameId(1); } @@ -106,12 +106,12 @@ if ( empty($_REQUEST['path']) ) { $path = $Event->Path().'/alarm.jpg'; } } else if ( $_REQUEST['fid'] == 'snapshot' ) { - $Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'Score'=>$Event->MaxScore())); + $Frame = ZM\Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'Score'=>$Event->MaxScore())); if ( !$Frame ) - $Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'])); + $Frame = ZM\Frame::find_one(array('EventId'=>$_REQUEST['eid'])); if ( !$Frame ) { - Warning('No frame found for event ' . $_REQUEST['eid']); - $Frame = new Frame(); + ZM\Warning('No frame found for event ' . $_REQUEST['eid']); + $Frame = new ZM\Frame(); $Frame->Delta(1); $Frame->FrameId('snapshot'); } @@ -124,7 +124,7 @@ if ( empty($_REQUEST['path']) ) { } } else { - $Frame = Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'FrameId'=>$_REQUEST['fid'])); + $Frame = ZM\Frame::find_one(array('EventId'=>$_REQUEST['eid'], 'FrameId'=>$_REQUEST['fid'])); if ( ! $Frame ) { $previousBulkFrame = dbFetchOne( 'SELECT * FROM Frames WHERE EventId=? AND FrameId < ? ORDER BY FrameID DESC LIMIT 1', @@ -135,72 +135,72 @@ if ( empty($_REQUEST['path']) ) { NULL, array($_REQUEST['eid'], $_REQUEST['fid']) ); if ( $previousBulkFrame and $nextBulkFrame ) { - $Frame = new Frame($previousBulkFrame); + $Frame = new ZM\Frame($previousBulkFrame); $Frame->FrameId($_REQUEST['fid']); $percentage = ($Frame->FrameId() - $previousBulkFrame['FrameId']) / ($nextBulkFrame['FrameId'] - $previousBulkFrame['FrameId']); $Frame->Delta($previousBulkFrame['Delta'] + floor( 100* ( $nextBulkFrame['Delta'] - $previousBulkFrame['Delta'] ) * $percentage )/100); - Logger::Debug("Got virtual frame from Bulk Frames previous delta: " . $previousBulkFrame['Delta'] . " + nextdelta:" . $nextBulkFrame['Delta'] . ' - ' . $previousBulkFrame['Delta'] . ' * ' . $percentage ); + ZM\Logger::Debug("Got virtual frame from Bulk Frames previous delta: " . $previousBulkFrame['Delta'] . " + nextdelta:" . $nextBulkFrame['Delta'] . ' - ' . $previousBulkFrame['Delta'] . ' * ' . $percentage ); } else { - Fatal('No Frame found for event('.$_REQUEST['eid'].') and frame id('.$_REQUEST['fid'].')'); + ZM\Fatal('No Frame found for event('.$_REQUEST['eid'].') and frame id('.$_REQUEST['fid'].')'); } } // Frame can be non-existent. We have Bulk frames. So now we should try to load the bulk frame $path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg'; - Logger::Debug("Path: $path"); + ZM\Logger::Debug("Path: $path"); } } else { # If we are only specifying fid, then the fid must be the primary key into the frames table. But when the event is specified, then it is the frame # - $Frame = Frame::find_one(array('Id'=>$_REQUEST['fid'])); + $Frame = ZM\Frame::find_one(array('Id'=>$_REQUEST['fid'])); if ( !$Frame ) { header('HTTP/1.0 404 Not Found'); - Fatal('Frame ' . $_REQUEST['fid'] . ' Not Found'); + ZM\Fatal('Frame ' . $_REQUEST['fid'] . ' Not Found'); return; } - $Event = Event::find_one(array('Id'=>$Frame->EventId())); + $Event = ZM\Event::find_one(array('Id'=>$Frame->EventId())); if ( !$Event ) { header('HTTP/1.0 404 Not Found'); - Fatal('Event ' . $Frame->EventId() . ' Not Found'); + ZM\Fatal('Event ' . $Frame->EventId() . ' Not Found'); return; } $path = $Event->Path().'/'.sprintf('%0'.ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-'.$show.'.jpg'; } # end if have eid if ( !file_exists($path) ) { - Logger::Debug("$path does not exist"); + ZM\Logger::Debug("$path does not exist"); # Generate the frame JPG if ( ($show == 'capture') and $Event->DefaultVideo() ) { if ( !file_exists($Event->Path().'/'.$Event->DefaultVideo()) ) { header('HTTP/1.0 404 Not Found'); - Fatal("Can't create frame images from video because there is no video file for this event at (".$Event->Path().'/'.$Event->DefaultVideo() ); + ZM\Fatal("Can't create frame images from video because there is no video file for this event at (".$Event->Path().'/'.$Event->DefaultVideo() ); } $command ='ffmpeg -ss '. $Frame->Delta() .' -i '.$Event->Path().'/'.$Event->DefaultVideo().' -frames:v 1 '.$path; #$command ='ffmpeg -ss '. $Frame->Delta() .' -i '.$Event->Path().'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$Frame->FrameId().'),setpts=PTS-STARTPTS" '.$path; #$command ='ffmpeg -v 0 -i '.$Storage->Path().'/'.$Event->Path().'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$Frame->FrameId().'),setpts=PTS-STARTPTS" '.$path; - Logger::Debug("Running $command"); + ZM\Logger::Debug("Running $command"); $output = array(); $retval = 0; exec( $command, $output, $retval ); - Logger::Debug("Command: $command, retval: $retval, output: " . implode("\n", $output)); + ZM\Logger::Debug("Command: $command, retval: $retval, output: " . implode("\n", $output)); if ( ! file_exists( $path ) ) { header('HTTP/1.0 404 Not Found'); - Fatal("Can't create frame images from video for this event (".$Event->DefaultVideo() ); + ZM\Fatal("Can't create frame images from video for this event (".$Event->DefaultVideo() ); } # Generating an image file will use up more disk space, so update the Event record. $Event->DiskSpace(null); $Event->save(); } else { header('HTTP/1.0 404 Not Found'); - Fatal("Can't create frame $show images from video because there is no video file for this event at ". + ZM\Fatal("Can't create frame $show images from video because there is no video file for this event at ". $Event->Path().'/'.$Event->DefaultVideo() ); } } # end if ! file_exists($path) } else { - Warning('Loading images by path is deprecated'); + ZM\Warning('Loading images by path is deprecated'); $dir_events = realpath(ZM_DIR_EVENTS); $path = realpath($dir_events . '/' . $_REQUEST['path']); $pos = strpos($path, $dir_events); @@ -223,7 +223,7 @@ if ( empty($_REQUEST['path']) ) { } if ( !file_exists($path) ) { header('HTTP/1.0 404 Not Found'); - Fatal("Image not found at $path"); + ZM\Fatal("Image not found at $path"); } } @@ -239,7 +239,7 @@ if ( !empty($_REQUEST['scale']) ) { $width = 0; if ( !empty($_REQUEST['width']) ) { -Logger::Debug("Setting width: " . $_REQUEST['width']); +ZM\Logger::Debug("Setting width: " . $_REQUEST['width']); if ( is_numeric($_REQUEST['width']) ) { $x = $_REQUEST['width']; if ( $x >= 10 and $x <= 8000 ) @@ -257,10 +257,8 @@ if ( !empty($_REQUEST['height']) ) { } if ( $errorText ) { - Error($errorText); + ZM\Error($errorText); } else { - # Clears the output buffer. Not sure what is there, but have had troubles. - ob_end_clean(); header('Content-type: image/jpeg'); if ( ( $scale==0 || $scale==100 ) && ($width==0) && ($height==0) ) { # This is so that Save Image As give a useful filename @@ -269,10 +267,10 @@ if ( $errorText ) { header('Content-Disposition: inline; filename="' . $filename . '"'); } if ( !readfile($path) ) { - Error('No bytes read from '. $path); + ZM\Error('No bytes read from '. $path); } } else { - Logger::Debug("Doing a scaled image: scale($scale) width($width) height($height)"); + ZM\Logger::Debug("Doing a scaled image: scale($scale) width($width) height($height)"); $i = 0; if ( ! ( $width && $height ) ) { $i = imagecreatefromjpeg($path); @@ -285,10 +283,10 @@ if ( $errorText ) { $width = ($height * $oldWidth) / $oldHeight; } elseif ( $width != 0 && $height == 0 ) { $height = ($width * $oldHeight) / $oldWidth; -Logger::Debug("Figuring out height using width: $height = ($width * $oldHeight) / $oldWidth"); +ZM\Logger::Debug("Figuring out height using width: $height = ($width * $oldHeight) / $oldWidth"); } if ( $width == $oldWidth && $height == $oldHeight ) { - Warning('No change to width despite scaling.'); + ZM\Warning('No change to width despite scaling.'); } } @@ -299,7 +297,7 @@ Logger::Debug("Figuring out height using width: $height = ($width * $oldHeight) header('Content-Disposition: inline; filename="' . $filename . '"'); } if ( !( file_exists($scaled_path) and readfile($scaled_path) ) ) { - Logger::Debug("Cached scaled image does not exist at $scaled_path or is no good.. Creating it"); + ZM\Logger::Debug("Cached scaled image does not exist at $scaled_path or is no good.. Creating it"); ob_start(); if ( !$i ) $i = imagecreatefromjpeg($path); @@ -309,15 +307,14 @@ Logger::Debug("Figuring out height using width: $height = ($width * $oldHeight) imagedestroy($iScale); $scaled_jpeg_data = ob_get_contents(); file_put_contents($scaled_path, $scaled_jpeg_data); - ob_end_clean(); echo $scaled_jpeg_data; } else { - Logger::Debug("Sending $scaled_path"); + ZM\Logger::Debug("Sending $scaled_path"); $bytes = readfile($scaled_path); if ( !$bytes ) { - Error('No bytes read from '. $scaled_path); + ZM\Error('No bytes read from '. $scaled_path); } else { - Logger::Debug("$bytes sent"); + ZM\Logger::Debug("$bytes sent"); } } } diff --git a/web/views/view_video.php b/web/views/view_video.php index 9bba64e69..011343dc3 100644 --- a/web/views/view_video.php +++ b/web/views/view_video.php @@ -38,19 +38,19 @@ $path = ''; $Event = null; if ( ! empty($_REQUEST['eid']) ) { - $Event = new Event($_REQUEST['eid']); + $Event = new ZM\Event($_REQUEST['eid']); $path = $Event->Path().'/'.$Event->DefaultVideo(); - Logger::Debug("Path: $path"); + ZM\Logger::Debug("Path: $path"); } else if ( ! empty($_REQUEST['event_id']) ) { - $Event = new Event($_REQUEST['event_id']); + $Event = new ZM\Event($_REQUEST['event_id']); $path = $Event->Path().'/'.$Event->DefaultVideo(); - Logger::Debug("Path: $path"); + ZM\Logger::Debug("Path: $path"); } else { $errorText = 'No video path'; } if ( $errorText ) { - Error($errorText); + ZM\Error($errorText); header('HTTP/1.0 404 Not Found'); die(); } @@ -68,14 +68,14 @@ $end = $size-1; $length = $size; if ( isset($_SERVER['HTTP_RANGE']) ) { - Logger::Debug('Using Range ' . $_SERVER['HTTP_RANGE']); + ZM\Logger::Debug('Using Range ' . $_SERVER['HTTP_RANGE']); if ( preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches) ) { $begin = intval($matches[1]); if ( ! empty($matches[2]) ) { $end = intval($matches[2]); } $length = $end - $begin + 1; - Logger::Debug("Using Range $begin $end size: $size, length: $length"); + ZM\Logger::Debug("Using Range $begin $end size: $size, length: $length"); } } # end if HTTP_RANGE @@ -98,7 +98,6 @@ if ( $begin > 0 || $end < $size-1 ) { } // Apparently without these we get a few extra bytes of output at the end... -ob_clean(); flush(); $cur = $begin;