Merge branch 'storageareas' into tesla

This commit is contained in:
Isaac Connor 2018-01-04 10:09:24 -08:00
commit 023e50af5c
7 changed files with 167 additions and 75 deletions

96
db/zm_update-1.31.19.sql Normal file
View File

@ -0,0 +1,96 @@
drop procedure if exists update_storage_stats;
delimiter //
create procedure update_storage_stats(IN StorageId smallint(5), IN space BIGINT)
sql security invoker
deterministic
begin
update Storage set DiskSpace = DiskSpace + space where Id = StorageId;
end;
//
delimiter ;
drop trigger if exists event_update_trigger;
delimiter //
create trigger event_update_trigger
after update
on Events
for each row
begin
declare diff BIGINT default 0;
set diff = NEW.DiskSpace - OLD.DiskSpace;
IF ( NEW.StorageId = OLD.StorageID ) THEN
call update_storage_stats(OLD.StorageId, diff);
ELSE
call update_storage_stats(NEW.StorageId, NEW.DiskSpace);
call update_storage_stats(OLD.StorageId, -OLD.DiskSpace);
END IF;
end;
//
delimiter ;
drop trigger if exists event_insert_trigger;
delimiter //
create trigger event_insert_trigger
after insert
on Events
for each row
begin
call update_storage_stats(NEW.StorageId, NEW.DiskSpace);
end;
//
delimiter ;
drop trigger if exists event_delete_trigger;
delimiter //
create trigger event_delete_trigger
before delete
on Events
for each row
begin
call update_storage_stats(OLD.StorageId, -OLD.DiskSpace);
end;
//
delimiter ;

View File

@ -31,9 +31,9 @@ if [ "$1" = "configure" ]; then
if ! $(echo quit | mysql --defaults-file=/etc/mysql/debian.cnf zm > /dev/null 2> /dev/null) ; then if ! $(echo quit | mysql --defaults-file=/etc/mysql/debian.cnf zm > /dev/null 2> /dev/null) ; then
cat /usr/share/zoneminder/db/zm_create.sql | mysql --defaults-file=/etc/mysql/debian.cnf cat /usr/share/zoneminder/db/zm_create.sql | mysql --defaults-file=/etc/mysql/debian.cnf
# This creates the user. # This creates the user.
echo "grant lock tables, alter,select,insert,update,delete,create,index on ${ZM_DB_NAME}.* to '${ZM_DB_USER}'@localhost identified by \"${ZM_DB_PASS}\";" | mysql --defaults-file=/etc/mysql/debian.cnf mysql echo "grant lock tables, alter,select,insert,update,delete,create,index,alter routine,create routine, trigger,execute on ${ZM_DB_NAME}.* to '${ZM_DB_USER}'@localhost identified by \"${ZM_DB_PASS}\";" | mysql --defaults-file=/etc/mysql/debian.cnf mysql
else else
echo "grant lock tables, alter,select,insert,update,delete,create,index on ${ZM_DB_NAME}.* to '${ZM_DB_USER}'@localhost;" | mysql --defaults-file=/etc/mysql/debian.cnf mysql echo "grant lock tables, alter,select,insert,update,delete,create,index,alter routine,create routine, trigger,execute on ${ZM_DB_NAME}.* to '${ZM_DB_USER}'@localhost;" | mysql --defaults-file=/etc/mysql/debian.cnf mysql
fi fi
zmupdate.pl --nointeractive zmupdate.pl --nointeractive

View File

@ -33,9 +33,9 @@ if [ "$1" = "configure" ]; then
if ! $(echo quit | mysql --defaults-file=/etc/mysql/debian.cnf zm > /dev/null 2> /dev/null) ; then if ! $(echo quit | mysql --defaults-file=/etc/mysql/debian.cnf zm > /dev/null 2> /dev/null) ; then
cat /usr/share/zoneminder/db/zm_create.sql | mysql --defaults-file=/etc/mysql/debian.cnf cat /usr/share/zoneminder/db/zm_create.sql | mysql --defaults-file=/etc/mysql/debian.cnf
# This creates the user. # This creates the user.
echo "grant lock tables,alter,select,insert,update,delete,create,index on ${ZM_DB_NAME}.* to '${ZM_DB_USER}'@localhost identified by \"${ZM_DB_PASS}\";" | mysql --defaults-file=/etc/mysql/debian.cnf mysql echo "grant lock tables,alter,select,insert,update,delete,create,index,alter routine,create routine, trigger,execute on ${ZM_DB_NAME}.* to '${ZM_DB_USER}'@localhost identified by \"${ZM_DB_PASS}\";" | mysql --defaults-file=/etc/mysql/debian.cnf mysql
else else
echo "grant lock tables,alter,select,insert,update,delete,create,index on ${ZM_DB_NAME}.* to '${ZM_DB_USER}'@localhost;" | mysql --defaults-file=/etc/mysql/debian.cnf mysql echo "grant lock tables,alter,select,insert,update,delete,create,index,alter routine,create routine, trigger,execute on ${ZM_DB_NAME}.* to '${ZM_DB_USER}'@localhost;" | mysql --defaults-file=/etc/mysql/debian.cnf mysql
fi fi
zmupdate.pl --nointeractive zmupdate.pl --nointeractive

View File

@ -201,16 +201,6 @@ while( 1 ) {
} # end foreach monitor } # end foreach monitor
$eventcounts_sth->finish(); $eventcounts_sth->finish();
my $diskspace_sql = 'UPDATE Storage SET DiskSpace =(SELECT SUM(DiskSpace) FROM Events WHERE StorageId=? AND DiskSpace IS NOT NULL)';
my $diskspace_sth = $dbh->prepare_cached( $diskspace_sql )
or Fatal( "Can't prepare '$diskspace_sql': ".$dbh->errstr() );
foreach my $Storage ( ZoneMinder::Storage->find() ) {
Debug("Updating disk space for $$Storage{Name} was $$Storage{DiskSpace}");
$diskspace_sth->execute( $$Storage{Id} ) or Error( "Can't execute: ".$diskspace_sth->errstr() );
$Storage->load();
Debug("Updated disk space for $$Storage{Name} to $$Storage{DiskSpace}");
}
$diskspace_sth->finish();
sleep( $Config{ZM_WATCH_CHECK_INTERVAL} ); sleep( $Config{ZM_WATCH_CHECK_INTERVAL} );
} # end while (1) } # end while (1)

View File

@ -313,6 +313,7 @@ bool VideoStore::open() {
if (ret < 0) { if (ret < 0) {
Error("Could not open out file '%s': %s\n", filename, Error("Could not open out file '%s': %s\n", filename,
av_make_error_string(ret).c_str()); av_make_error_string(ret).c_str());
return false; return false;
} }
} }
@ -346,68 +347,83 @@ bool VideoStore::open() {
} }
VideoStore::~VideoStore() { VideoStore::~VideoStore() {
if (audio_out_codec) {
// The codec queues data. We need to send a flush command and out
// whatever we get. Failures are not fatal.
AVPacket pkt;
av_init_packet(&pkt);
while (1) { if ( oc->pb ) {
if (audio_out_codec) {
// The codec queues data. We need to send a flush command and out
// whatever we get. Failures are not fatal.
AVPacket pkt;
av_init_packet(&pkt);
while (1) {
#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0)
// Put encoder into flushing mode // Put encoder into flushing mode
avcodec_send_frame(audio_out_ctx, NULL); avcodec_send_frame(audio_out_ctx, NULL);
ret = avcodec_receive_packet(audio_out_ctx, &pkt); ret = avcodec_receive_packet(audio_out_ctx, &pkt);
if (ret < 0) { if (ret < 0) {
if (AVERROR_EOF != ret) { if (AVERROR_EOF != ret) {
Error("ERror encoding audio while flushing (%d) (%s)", ret, Error("ERror encoding audio while flushing (%d) (%s)", ret,
av_err2str(ret)); av_err2str(ret));
}
break;
} }
break;
}
#else #else
int got_packet = 0; int got_packet = 0;
ret = ret =
avcodec_encode_audio2(audio_out_ctx, &pkt, NULL, &got_packet); avcodec_encode_audio2(audio_out_ctx, &pkt, NULL, &got_packet);
if (ret < 0) { if (ret < 0) {
Error("ERror encoding audio while flushing (%d) (%s)", ret, Error("ERror encoding audio while flushing (%d) (%s)", ret,
av_err2str(ret)); av_err2str(ret));
break; break;
} }
Debug(1, "Have audio encoder, need to flush it's out"); Debug(1, "Have audio encoder, need to flush it's out");
if (!got_packet) { if (!got_packet) {
break; break;
} }
#endif #endif
Debug(2, "writing flushed packet pts(%d) dts(%d) duration(%d)", pkt.pts, Debug(2, "writing flushed packet pts(%d) dts(%d) duration(%d)", pkt.pts,
pkt.dts, pkt.duration); pkt.dts, pkt.duration);
pkt.pts = audio_next_pts; pkt.pts = audio_next_pts;
pkt.dts = audio_next_dts; pkt.dts = audio_next_dts;
if (pkt.duration > 0) if (pkt.duration > 0)
pkt.duration = pkt.duration =
av_rescale_q(pkt.duration, audio_out_ctx->time_base, av_rescale_q(pkt.duration, audio_out_ctx->time_base,
audio_out_stream->time_base); audio_out_stream->time_base);
audio_next_pts += pkt.duration; audio_next_pts += pkt.duration;
audio_next_dts += pkt.duration; audio_next_dts += pkt.duration;
Debug(2, "writing flushed packet pts(%d) dts(%d) duration(%d)", pkt.pts, Debug(2, "writing flushed packet pts(%d) dts(%d) duration(%d)", pkt.pts,
pkt.dts, pkt.duration); pkt.dts, pkt.duration);
pkt.stream_index = audio_out_stream->index; pkt.stream_index = audio_out_stream->index;
av_interleaved_write_frame(oc, &pkt); av_interleaved_write_frame(oc, &pkt);
zm_av_packet_unref(&pkt); zm_av_packet_unref(&pkt);
} // while have buffered frames } // while have buffered frames
} // end if audio_out_codec } // end if audio_out_codec
// Flush Queues // Flush Queues
av_interleaved_write_frame(oc, NULL); av_interleaved_write_frame(oc, NULL);
/* Write the trailer before close */ /* Write the trailer before close */
if (int rc = av_write_trailer(oc)) { if (int rc = av_write_trailer(oc)) {
Error("Error writing trailer %s", av_err2str(rc)); Error("Error writing trailer %s", av_err2str(rc));
} else { } else {
Debug(3, "Sucess Writing trailer"); Debug(3, "Sucess Writing trailer");
}
// WHen will be not using a file ?
if ( !(out_format->flags & AVFMT_NOFILE) ) {
/* Close the out file. */
Debug(2, "Closing");
if (int rc = avio_close(oc->pb)) {
oc->pb = NULL;
Error("Error closing avio %s", av_err2str(rc));
}
} else {
Debug(3, "Not closing avio because we are not writing to a file.");
}
} }
// I wonder if we should be closing the file first. // I wonder if we should be closing the file first.
// I also wonder if we really need to be doing all the ctx // I also wonder if we really need to be doing all the ctx
// allocation/de-allocation constantly, or whether we can just re-use it. // allocation/de-allocation constantly, or whether we can just re-use it.
@ -463,16 +479,6 @@ VideoStore::~VideoStore() {
#endif #endif
} }
// WHen will be not using a file ?
if (!(out_format->flags & AVFMT_NOFILE)) {
/* Close the out file. */
if (int rc = avio_close(oc->pb)) {
Error("Error closing avio %s", av_err2str(rc));
}
} else {
Debug(3, "Not closing avio because we are not writing to a file.");
}
/* free the stream */ /* free the stream */
avformat_free_context(oc); avformat_free_context(oc);
} }

View File

@ -1 +1 @@
1.31.18 1.31.19

View File

@ -210,16 +210,16 @@ while ( $event_row = dbFetchNext( $results ) ) {
?> ?>
<td class="colThumbnail"> <td class="colThumbnail">
<?php <?php
if ( file_exists( $event->Path().'/snapshot.jpg' ) ) { if ( ( $event->SaveJPEGs() == 4 ) and file_exists($event->Path().'/snapshot.jpg') ) {
Warning("Using snapshot"); Logger::Debug("Using snapshot");
$imgSrc = '?view=image&amp;eid='.$event->Id().'&amp;fid=snapshot&amp;width='.$thumbData['Width'].'&amp;height='.$thumbData['Height']; $imgSrc = '?view=image&amp;eid='.$event->Id().'&amp;fid=snapshot&amp;width='.$thumbData['Width'].'&amp;height='.$thumbData['Height'];
} else { } else {
Warning("Not Using snapshot" . $event->Path().'/snapshot.jpg' ); Logger::Debug("Not Using snapshot" . $event->Path().'/snapshot.jpg' );
$imgSrc = '?view=image&amp;eid='.$event->Id().'&amp;fid='.$thumbData['FrameId'].'&amp;width='.$thumbData['Width'].'&amp;height='.$thumbData['Height']; $imgSrc = '?view=image&amp;eid='.$event->Id().'&amp;fid='.$thumbData['FrameId'].'&amp;width='.$thumbData['Width'].'&amp;height='.$thumbData['Height'];
} }
$streamSrc = $event->getStreamSrc( array( 'mode'=>'jpeg', 'scale'=>$scale, 'maxfps'=>ZM_WEB_VIDEO_MAXFPS, 'replay'=>'single') ); $streamSrc = $event->getStreamSrc( array( 'mode'=>'jpeg', 'scale'=>$scale, 'maxfps'=>ZM_WEB_VIDEO_MAXFPS, 'replay'=>'single') );
$imgHtml = '<img id="thumbnail'.$event->id().'" src="'.$imgSrc.'" alt="'. validHtmlStr('Event '.$event->Id()) .'" style="width:'. validInt($thumbData['Width']) .'px;height:'. validInt( $thumbData['Height'] ).'px;" onmouseover="this.src=\''.$streamSrc.'\';" onmouseout="this.src=\''.$imgSrc.'\';"/>'; $imgHtml = '<img id="thumbnail'.$event->id().'" src="'.$imgSrc.'" alt="'. validHtmlStr('Event '.$event->Id()) .'" style="width:'. validInt($thumbData['Width']) .'px;height:'. validInt($thumbData['Height']).'px;" onmouseover="this.src=\''.$streamSrc.'\';" onmouseout="this.src=\''.$imgSrc.'\';"/>';
echo makePopupLink( echo makePopupLink(
'?view=frame&amp;eid='.$event->Id().'&amp;fid='.$thumbData['FrameId'], '?view=frame&amp;eid='.$event->Id().'&amp;fid='.$thumbData['FrameId'],