2005-10-18 05:55:02 +08:00
|
|
|
//
|
|
|
|
// ZoneMinder File Camera Class Implementation, $Date$, $Revision$
|
2008-07-25 17:33:23 +08:00
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
2005-10-18 05:55:02 +08:00
|
|
|
//
|
|
|
|
// 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
|
2016-12-26 23:23:16 +08:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-10-18 05:55:02 +08:00
|
|
|
//
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "zm.h"
|
|
|
|
#include "zm_file_camera.h"
|
|
|
|
|
2017-12-13 01:37:04 +08:00
|
|
|
FileCamera::FileCamera(
|
|
|
|
int p_id,
|
|
|
|
const char *p_path,
|
|
|
|
int p_width,
|
|
|
|
int p_height,
|
|
|
|
int p_colours,
|
|
|
|
int p_brightness,
|
|
|
|
int p_contrast,
|
|
|
|
int p_hue,
|
|
|
|
int p_colour,
|
|
|
|
bool p_capture,
|
|
|
|
bool p_record_audio
|
|
|
|
) : Camera( p_id, FILE_SRC, p_width, p_height, p_colours, ZM_SUBPIX_ORDER_DEFAULT_FOR_COLOUR(p_colours), p_brightness, p_contrast, p_hue, p_colour, p_capture, p_record_audio )
|
2005-10-18 05:55:02 +08:00
|
|
|
{
|
2017-12-13 01:37:04 +08:00
|
|
|
strncpy( path, p_path, sizeof(path)-1 );
|
|
|
|
if ( capture ) {
|
2016-06-22 00:21:18 +08:00
|
|
|
Initialise();
|
|
|
|
}
|
2005-10-18 05:55:02 +08:00
|
|
|
}
|
|
|
|
|
2017-12-13 01:37:04 +08:00
|
|
|
FileCamera::~FileCamera() {
|
|
|
|
if ( capture ) {
|
2016-06-22 00:21:18 +08:00
|
|
|
Terminate();
|
|
|
|
}
|
2005-10-18 05:55:02 +08:00
|
|
|
}
|
|
|
|
|
2017-12-13 01:37:04 +08:00
|
|
|
void FileCamera::Initialise() {
|
|
|
|
if ( !path[0] ) {
|
2016-06-22 00:21:18 +08:00
|
|
|
Error( "No path specified for file image" );
|
|
|
|
exit( -1 );
|
|
|
|
}
|
2005-10-18 05:55:02 +08:00
|
|
|
}
|
|
|
|
|
2017-12-13 01:37:04 +08:00
|
|
|
void FileCamera::Terminate() {
|
2005-10-18 05:55:02 +08:00
|
|
|
}
|
|
|
|
|
2017-12-13 01:37:04 +08:00
|
|
|
int FileCamera::PreCapture() {
|
2016-06-22 00:21:18 +08:00
|
|
|
struct stat statbuf;
|
2017-12-13 01:37:04 +08:00
|
|
|
if ( stat( path, &statbuf ) < 0 ) {
|
2016-06-22 00:21:18 +08:00
|
|
|
Error( "Can't stat %s: %s", path, strerror(errno) );
|
|
|
|
return( -1 );
|
|
|
|
}
|
2005-10-18 05:55:02 +08:00
|
|
|
|
2017-12-13 01:37:04 +08:00
|
|
|
while ( (time(0) - statbuf.st_mtime) < 1 ) {
|
2016-06-22 00:21:18 +08:00
|
|
|
usleep( 100000 );
|
|
|
|
}
|
|
|
|
return( 0 );
|
2005-10-18 05:55:02 +08:00
|
|
|
}
|
|
|
|
|
2017-12-13 01:37:04 +08:00
|
|
|
int FileCamera::Capture( Image &image ) {
|
2016-06-22 00:21:18 +08:00
|
|
|
return( image.ReadJpeg( path, colours, subpixelorder )?0:-1 );
|
2005-10-18 05:55:02 +08:00
|
|
|
}
|
2009-01-28 17:48:06 +08:00
|
|
|
|
2017-12-13 01:37:04 +08:00
|
|
|
int FileCamera::PostCapture() {
|
2009-01-28 17:48:06 +08:00
|
|
|
return( 0 );
|
|
|
|
}
|