merge Steve's updates, work on zmaudit

This commit is contained in:
Isaac Connor 2016-07-12 11:27:25 -04:00
commit 26369268bb
4 changed files with 96 additions and 45 deletions

View File

@ -113,6 +113,13 @@ sub getPath {
sub Path {
my $event = shift;
if ( @_ > 1 ) {
$$event{Path} = $_[1];
if ( ! -e $$event{Path} ) {
Error("Setting path for event $$event{Id} to $_[1] but does not exist!");
}
}
if ( ! $$event{Path} ) {
my $Storage = $event->Storage();

View File

@ -194,11 +194,12 @@ MAIN: while( $loop ) {
next if $monitor =~ /\D/;
Debug( "Found filesystem monitor '$monitor'" );
my $fs_events = $fs_monitors->{$monitor} = {};
$fs_monitors->{$monitor} = {} if ! $fs_monitors->{$monitor};
my $fs_events = $fs_monitors->{$monitor};
# De-taint
( my $monitor_dir ) = ( $monitor =~ /^(.*)$/ );
if ( $Config{ZM_USE_DEEP_STORAGE} ) {
foreach my $day_dir ( glob("$monitor_dir/*/*/*") ) {
Debug( "Checking $day_dir" );
@ -222,20 +223,27 @@ MAIN: while( $loop ) {
Debug( "Checking link $event_link" );
( my $event = $event_link ) =~ s/^.*\.//;
my $event_path = readlink( $event_link );
if ( $count++ > MAX_AGED_DIRS ) {
$fs_events->{$event} = -1;
if ( !-e $event_path ) {
aud_print( "Event link $day_dir/$event_link does not point to valid target" );
if ( confirm() ) {
( $event_link ) = ( $event_link =~ /^(.*)$/ ); # De-taint
unlink( $event_link );
$cleaned = 1;
}
} else {
if ( !-e $event_path ) {
aud_print( "Event link $day_dir/$event_link does not point to valid target" );
if ( confirm() ) {
( $event_link ) = ( $event_link =~ /^(.*)$/ ); # De-taint
unlink( $event_link );
$cleaned = 1;
}
my $Event = $fs_events->{$event} = new ZoneMinder::Event();
$$Event{Id} = $event;
$$Event{Path} = $event_path;
$Event->MonitorId( $monitor_dir );
$Event->StorageId( $Storage->Id() );
if ( $count++ > MAX_AGED_DIRS ) {
$Event->age( -1 );
} else {
$fs_events->{$event} = (time() - ($^T - ((-M $event_path) * 24*60*60)));
} # event path exists
}
$Event->age( (time() - ($^T - ((-M $event_path ) * 24*60*60))) );
}
} # event path exists
} # end foreach event_link
chdir( $Storage->Path() );
} # end foreach day dir
@ -252,11 +260,17 @@ MAIN: while( $loop ) {
closedir( DIR );
my $count = 0;
foreach my $event ( @temp_events ) {
my $Event = $fs_events->{$event} = new ZoneMinder::Event();
$$Event{Id} = $event;
#$$Event{Path} = $event_path;
$Event->MonitorId( $monitor_dir );
$Event->StorageId( $Storage->Id() );
if ( $count++ > MAX_AGED_DIRS ) {
$fs_events->{$event} = -1;
$Event->age( -1 );
} else {
$fs_events->{$event} = (time() - ($^T - ((-M $event) * 24*60*60)));
$Event->age( (time() - ($^T - ((-M $event ) * 24*60*60))) );
}
} # end foreach event
chdir( $Storage->Path() );
} # if USE_DEEP_STORAGE
@ -271,18 +285,18 @@ MAIN: while( $loop ) {
if ( my $db_events = $db_monitors->{$monitor_id} ) {
next if ! $fs_events;
foreach my $fs_event ( sort { $a <=> $b } keys %$fs_events ) {
my $age = $fs_events->{$fs_event};
if ( !defined($db_events->{$fs_event}) && ($age < 0 || ($age > $Config{ZM_AUDIT_MIN_AGE})) ) {
aud_print( "Filesystem event '$$Storage{Path}/$monitor_id/$fs_event' does not exist in database" );
foreach my $fs_event_id ( sort { $a <=> $b } keys %$fs_events ) {
my $Event = $fs_events->{$fs_event_id};
my $age = $$Event{age};
if ( !defined($db_events->{$fs_event_id}) && ($age < 0 || ($age > $Config{ZM_AUDIT_MIN_AGE})) ) {
aud_print( "Filesystem event '$$Storage{Path}/$monitor_id/$fs_event_id' does not exist in database" );
if ( confirm() ) {
my $Event = new ZoneMinder::Event( $fs_event );
# Must set these because the db event does not exist, however these are not enough.
$Event->MonitorId( $monitor_id );
$Event->StorageId( $Storage->Id() );
$Event->delete_files();
$cleaned = 1;
delete $fs_events->{$fs_event};
delete $fs_events->{$fs_event_id};
} # end if confirm
} # end if ! in db events and old enough
} # end foreach fs event

View File

@ -150,11 +150,14 @@ int SWScale::Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint
Error("NULL Input or output buffer");
return -1;
}
if(!width || !height) {
Error("Invalid width or height");
return -3;
}
// if(in_pf == 0 || out_pf == 0) {
// Error("Invalid input or output pixel formats");
// return -2;
// }
// if(!width || !height) {
// Error("Invalid width or height");
// return -3;
// }
#if LIBSWSCALE_VERSION_CHECK(0, 8, 0, 8, 0)
/* Warn if the input or output pixelformat is not supported */
@ -196,19 +199,22 @@ int SWScale::Convert(const uint8_t* in_buffer, const size_t in_buffer_size, uint
/* Fill in the buffers */
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
if(av_image_fill_arrays(input_avframe->data, input_avframe->linesize,
(uint8_t*)in_buffer, in_pf, width, height, 1) <= 0)
{
if (av_image_fill_arrays(input_avframe->data, input_avframe->linesize,
(uint8_t*) in_buffer, in_pf, width, height, 1) <= 0) {
#else
if(avpicture_fill( (AVPicture*)input_avframe, (uint8_t*)in_buffer,
in_pf, width, height ) <= 0)
{
if (avpicture_fill((AVPicture*) input_avframe, (uint8_t*) in_buffer,
in_pf, width, height) <= 0) {
#endif
Error("Failed filling input frame with input buffer");
return -7;
}
if(!avpicture_fill( (AVPicture*)output_avframe, out_buffer, out_pf, width, height ) ) {
#if LIBAVUTIL_VERSION_CHECK(54, 6, 0, 6, 0)
if (av_image_fill_arrays(output_avframe->data, output_avframe->linesize,
out_buffer, out_pf, width, height, 1) <= 0) {
#else
if (avpicture_fill((AVPicture*) output_avframe, out_buffer, out_pf, width,
height) <= 0) {
#endif
Error("Failed filling output frame with output buffer");
return -8;
}
@ -353,8 +359,7 @@ int hacked_up_context2_for_older_ffmpeg(AVFormatContext **avctx, AVOutputFormat
}
}
static void zm_log_fps(double d, const char *postfix)
{
static void zm_log_fps(double d, const char *postfix) {
uint64_t v = lrintf(d * 100);
if (!v) {
Debug(3, "%1.4f %s", d, postfix);

View File

@ -601,7 +601,16 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi
//Instantiate the video storage module
Debug(3, "recording and ! wasRecording %s", event_file);
videoStore = new VideoStore((const char *)event_file, "mp4", mFormatContext->streams[mVideoStreamId],mAudioStreamId==-1?NULL:mFormatContext->streams[mAudioStreamId],startTime, this->getMonitor()->getOrientation() );
if (mAudioStreamId == -1 && !record_audio) {
videoStore = new VideoStore((const char *) event_file, "mp4",
mFormatContext->streams[mVideoStreamId],
NULL, startTime, this->getMonitor()->getOrientation() );
} else {
videoStore = new VideoStore((const char *) event_file, "mp4",
mFormatContext->streams[mVideoStreamId],
mFormatContext->streams[mAudioStreamId],
startTime, this->getMonitor()->getOrientation() );
}
wasRecording = true;
strcpy(oldDirectory, event_file);
@ -626,7 +635,16 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi
videoStore = NULL;
}
videoStore = new VideoStore((const char *)event_file, "mp4", mFormatContext->streams[mVideoStreamId],mAudioStreamId==-1?NULL:mFormatContext->streams[mAudioStreamId],startTime, this->getMonitor()->getOrientation());
if (mAudioStreamId == -1 && !record_audio) {
videoStore = new VideoStore((const char *) event_file, "mp4",
mFormatContext->streams[mVideoStreamId],
NULL, startTime, this->getMonitor()->getOrientation() );
} else {
videoStore = new VideoStore((const char *) event_file, "mp4",
mFormatContext->streams[mVideoStreamId],
mFormatContext->streams[mAudioStreamId],
startTime, this->getMonitor()->getOrientation() );
}
strcpy(oldDirectory, event_file);
}
@ -641,13 +659,20 @@ int FfmpegCamera::CaptureAndRecord( Image &image, bool recording, char* event_fi
#if HAVE_LIBSWSCALE
if ( mConvertContext == NULL ) {
mConvertContext = sws_getContext( mCodecContext->width, mCodecContext->height, mCodecContext->pix_fmt, width, height, imagePixFormat, SWS_BICUBIC, NULL, NULL, NULL );
mConvertContext = sws_getContext(mCodecContext->width,
mCodecContext->height,
mCodecContext->pix_fmt,
width, height,
imagePixFormat, SWS_BICUBIC, NULL,
NULL, NULL);
if ( mConvertContext == NULL )
Fatal( "Unable to create conversion context for %s", mPath.c_str() );
}
if ( sws_scale( mConvertContext, mRawFrame->data, mRawFrame->linesize, 0, mCodecContext->height, mFrame->data, mFrame->linesize ) < 0 )
Fatal( "Unable to convert raw format %u to target format %u at frame %d", mCodecContext->pix_fmt, imagePixFormat, frameCount );
if (sws_scale(mConvertContext, mRawFrame->data, mRawFrame->linesize,
0, mCodecContext->height, mFrame->data, mFrame->linesize) < 0)
Fatal("Unable to convert raw format %u to target format %u at frame %d",
mCodecContext->pix_fmt, imagePixFormat, frameCount);
#else // HAVE_LIBSWSCALE
Fatal( "You must compile ffmpeg with the --enable-swscale option to use ffmpeg cameras" );
#endif // HAVE_LIBSWSCALE