Merge branch 'storageareas' into zma_to_thread

pull/3122/head
Isaac Connor 2017-12-19 14:06:58 -05:00
commit 0ea6fd9807
17 changed files with 93 additions and 31 deletions

View File

@ -173,7 +173,7 @@ sub Path {
$$event{Path} = join('/', $$event{Path} = join('/',
$Storage->Path(), $Storage->Path(),
$event->{MonitorId}, $event->{MonitorId},
strftime( '%y-%m-%d', localtime($event->Time())), strftime( '%Y-%m-%d', localtime($event->Time())),
$event->{Id}, $event->{Id},
); );
} else { } else {

View File

@ -101,7 +101,7 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
char id_file[PATH_MAX]; char id_file[PATH_MAX];
struct tm *stime = localtime( &start_time.tv_sec ); struct tm *stime = localtime( &start_time.tv_sec );
if ( storage->Scheme() == Storage::Schemes::DEEP ) { if ( storage->Scheme() == Storage::DEEP ) {
char *path_ptr = path; char *path_ptr = path;
path_ptr += snprintf( path_ptr, sizeof(path), "%s/%d", storage->Path(), monitor->Id() ); path_ptr += snprintf( path_ptr, sizeof(path), "%s/%d", storage->Path(), monitor->Id() );
@ -135,10 +135,10 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
snprintf( id_file, sizeof(id_file), "%s/.%d", date_path, id ); snprintf( id_file, sizeof(id_file), "%s/.%d", date_path, id );
if ( symlink( time_path, id_file ) < 0 ) if ( symlink( time_path, id_file ) < 0 )
Error( "Can't symlink %s -> %s: %s", id_file, path, strerror(errno)); Error( "Can't symlink %s -> %s: %s", id_file, path, strerror(errno));
} else if ( storage->Scheme() == Storage::Schemes::MEDIUM ) { } else if ( storage->Scheme() == Storage::MEDIUM ) {
char *path_ptr = path; char *path_ptr = path;
path_ptr += snprintf( path_ptr, sizeof(path), "%s/%d/%02d-%02d-%02d", path_ptr += snprintf( path_ptr, sizeof(path), "%s/%d/%04d-%02d-%02d",
storage->Path(), monitor->Id(), stime->tm_year-100, stime->tm_mon+1, stime->tm_mday storage->Path(), monitor->Id(), stime->tm_year+1900, stime->tm_mon+1, stime->tm_mday
); );
if ( mkdir( path, 0755 ) ) { if ( mkdir( path, 0755 ) ) {
// FIXME This should not be fatal. Should probably move to a different storage area. // FIXME This should not be fatal. Should probably move to a different storage area.

View File

@ -39,6 +39,7 @@
#include "zm_stream.h" #include "zm_stream.h"
#include "zm_video.h" #include "zm_video.h"
#include "zm_packet.h" #include "zm_packet.h"
#include "zm_storage.h"
class VideoStore; class VideoStore;
class Zone; class Zone;
@ -92,6 +93,7 @@ class Event {
bool have_video_keyframe; // a flag to tell us if we have had a video keyframe when writing an mp4. The first frame SHOULD be a video keyframe. bool have_video_keyframe; // a flag to tell us if we have had a video keyframe when writing an mp4. The first frame SHOULD be a video keyframe.
void createNotes( std::string &notes ); void createNotes( std::string &notes );
Storage::Schemes scheme;
public: public:
static bool OpenFrameSocket( int ); static bool OpenFrameSocket( int );

View File

@ -103,7 +103,7 @@ bool EventStream::loadInitialEventData( int init_event_id, unsigned int init_fra
bool EventStream::loadEventData( int event_id ) { bool EventStream::loadEventData( int event_id ) {
static char sql[ZM_SQL_MED_BUFSIZ]; static char sql[ZM_SQL_MED_BUFSIZ];
snprintf( sql, sizeof(sql), "SELECT MonitorId, StorageId, Frames, unix_timestamp( StartTime ) AS StartTimestamp, (SELECT max(Delta)-min(Delta) FROM Frames WHERE EventId=Events.Id) AS Duration, DefaultVideo FROM Events WHERE Id = %d", event_id ); snprintf( sql, sizeof(sql), "SELECT MonitorId, StorageId, Frames, unix_timestamp( StartTime ) AS StartTimestamp, (SELECT max(Delta)-min(Delta) FROM Frames WHERE EventId=Events.Id) AS Duration, DefaultVideo, Scheme FROM Events WHERE Id = %d", event_id );
if ( mysql_query( &dbconn, sql ) ) { if ( mysql_query( &dbconn, sql ) ) {
Error( "Can't run query: %s", mysql_error( &dbconn ) ); Error( "Can't run query: %s", mysql_error( &dbconn ) );
@ -137,18 +137,35 @@ bool EventStream::loadEventData( int event_id ) {
event_data->start_time = atoi(dbrow[3]); event_data->start_time = atoi(dbrow[3]);
event_data->duration = atof(dbrow[4]); event_data->duration = atof(dbrow[4]);
strncpy( event_data->video_file, dbrow[5], sizeof(event_data->video_file)-1 ); strncpy( event_data->video_file, dbrow[5], sizeof(event_data->video_file)-1 );
std::string scheme_str = std::string(dbrow[6]);
if ( scheme_str == "Deep" ) {
event_data->scheme = Storage::DEEP;
} else if ( scheme_str == "Medium" ) {
event_data->scheme = Storage::MEDIUM;
} else {
event_data->scheme = Storage::SHALLOW;
}
mysql_free_result( result ); mysql_free_result( result );
Storage * storage = new Storage( event_data->storage_id ); Storage * storage = new Storage( event_data->storage_id );
const char *storage_path = storage->Path(); const char *storage_path = storage->Path();
if ( config.use_deep_storage ) { if ( event_data->scheme == Storage::DEEP ) {
struct tm *event_time = localtime( &event_data->start_time ); struct tm *event_time = localtime( &event_data->start_time );
if ( storage_path[0] == '/' ) if ( storage_path[0] == '/' )
snprintf( event_data->path, sizeof(event_data->path), "%s/%ld/%02d/%02d/%02d/%02d/%02d/%02d", storage_path, event_data->monitor_id, event_time->tm_year-100, event_time->tm_mon+1, event_time->tm_mday, event_time->tm_hour, event_time->tm_min, event_time->tm_sec ); snprintf( event_data->path, sizeof(event_data->path), "%s/%ld/%02d/%02d/%02d/%02d/%02d/%02d", storage_path, event_data->monitor_id, event_time->tm_year-100, event_time->tm_mon+1, event_time->tm_mday, event_time->tm_hour, event_time->tm_min, event_time->tm_sec );
else else
snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%ld/%02d/%02d/%02d/%02d/%02d/%02d", staticConfig.PATH_WEB.c_str(), storage_path, event_data->monitor_id, event_time->tm_year-100, event_time->tm_mon+1, event_time->tm_mday, event_time->tm_hour, event_time->tm_min, event_time->tm_sec ); snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%ld/%02d/%02d/%02d/%02d/%02d/%02d", staticConfig.PATH_WEB.c_str(), storage_path, event_data->monitor_id, event_time->tm_year-100, event_time->tm_mon+1, event_time->tm_mday, event_time->tm_hour, event_time->tm_min, event_time->tm_sec );
} else if ( event_data->scheme == Storage::MEDIUM ) {
struct tm *event_time = localtime( &event_data->start_time );
if ( storage_path[0] == '/' )
snprintf( event_data->path, sizeof(event_data->path), "%s/%ld/%04d-%02d-%02d/%ld",
storage_path, event_data->monitor_id, event_time->tm_year+1900, event_time->tm_mon+1, event_time->tm_mday, event_data->event_id );
else
snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%ld/%04d-%02d-%02d/%ld",
staticConfig.PATH_WEB.c_str(), storage_path, event_data->monitor_id, event_time->tm_year+1900, event_time->tm_mon+1, event_time->tm_mday,
event_data->event_id );
} else { } else {
if ( storage_path[0] == '/' ) if ( storage_path[0] == '/' )

View File

@ -28,6 +28,7 @@
#include "zm_video.h" #include "zm_video.h"
#include "zm_ffmpeg_input.h" #include "zm_ffmpeg_input.h"
#include "zm_monitor.h" #include "zm_monitor.h"
#include "zm_storage.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -63,6 +64,7 @@ class EventStream : public StreamBase {
int n_frames; int n_frames;
FrameData *frames; FrameData *frames;
char video_file[PATH_MAX]; char video_file[PATH_MAX];
Storage::Schemes scheme;
}; };
protected: protected:

View File

@ -434,7 +434,7 @@ int zm_receive_frame( AVCodecContext *context, AVFrame *frame, AVPacket &packet
#endif #endif
return 1; return 1;
} // end int zm_receive_frame( AVCodecContext *context, AVFrame *frame, AVPacket &packet ) } // end int zm_receive_frame( AVCodecContext *context, AVFrame *frame, AVPacket &packet )
void dumpPacket(AVPacket *pkt) { void dumpPacket(AVPacket *pkt, const char *text) {
char b[10240]; char b[10240];
snprintf(b, sizeof(b), snprintf(b, sizeof(b),
@ -456,5 +456,5 @@ void dumpPacket(AVPacket *pkt) {
pkt->flags & AV_PKT_FLAG_KEY, pkt->flags & AV_PKT_FLAG_KEY,
pkt->pos, pkt->pos,
pkt->duration); pkt->duration);
Debug(1, "%s:%d:DEBUG: %s", __FILE__, __LINE__, b); Debug(1, "%s:%d:%s: %s", __FILE__, __LINE__, text, b);
} }

View File

@ -327,5 +327,5 @@ int check_sample_fmt(AVCodec *codec, enum AVSampleFormat sample_fmt);
bool is_video_stream( AVStream * stream ); bool is_video_stream( AVStream * stream );
bool is_audio_stream( AVStream * stream ); bool is_audio_stream( AVStream * stream );
int zm_receive_frame( AVCodecContext *context, AVFrame *frame, AVPacket &packet ); int zm_receive_frame( AVCodecContext *context, AVFrame *frame, AVPacket &packet );
void dumpPacket(AVPacket *); void dumpPacket(AVPacket *,const char *text="DEBUG");
#endif // ZM_FFMPEG_H #endif // ZM_FFMPEG_H

View File

@ -175,7 +175,11 @@ int FfmpegCamera::Capture( ZMPacket &zm_packet ) {
Error( "Unable to read packet from stream %d: error %d \"%s\".", packet.stream_index, ret, av_make_error_string(ret).c_str() ); Error( "Unable to read packet from stream %d: error %d \"%s\".", packet.stream_index, ret, av_make_error_string(ret).c_str() );
return -1; return -1;
} }
Debug( 5, "Got packet from stream %d dts (%d) pts(%d)", packet.stream_index, packet.pts, packet.dts ); dumpPacket(&packet, "ffmpeg_camera in");
if ( 0 && ( packet.dts < 0 ) ) {
zm_av_packet_unref( &packet );
return 0;
}
zm_packet.set_packet( &packet ); zm_packet.set_packet( &packet );
zm_av_packet_unref( &packet ); zm_av_packet_unref( &packet );

View File

@ -2777,7 +2777,7 @@ int Monitor::Capture() {
shared_data->last_read_index = image_buffer_count; shared_data->last_read_index = image_buffer_count;
} }
} else { } else {
Debug(2,"Current write index %d, last read index %d, current (%d)", shared_data->last_write_index, shared_data->last_read_index, index ); Debug(2,"Capture: Current write index %d, last read index %d, current (%d)", shared_data->last_write_index, shared_data->last_read_index, index );
} }
ZMPacket *packet = &image_buffer[index]; ZMPacket *packet = &image_buffer[index];
@ -2933,6 +2933,8 @@ int Monitor::Capture() {
} // end if report fps } // end if report fps
} else { // result == 0 } else { // result == 0
// Question is, do we update last_write_index etc? // Question is, do we update last_write_index etc?
packet->unlock();
return 0;
} // end if result } // end if result
} // end if deinterlacing } // end if deinterlacing

View File

@ -195,7 +195,7 @@ AVPacket *ZMPacket::set_packet( AVPacket *p ) {
if ( zm_av_packet_ref( &packet, p ) < 0 ) { if ( zm_av_packet_ref( &packet, p ) < 0 ) {
Error("error refing packet"); Error("error refing packet");
} }
dumpPacket(&packet); dumpPacket(&packet, "zmpacket:");
gettimeofday( timestamp, NULL ); gettimeofday( timestamp, NULL );
keyframe = p->flags & AV_PKT_FLAG_KEY; keyframe = p->flags & AV_PKT_FLAG_KEY;
return &packet; return &packet;

View File

@ -36,8 +36,8 @@ Storage::Storage() {
} else { } else {
strncpy(path, staticConfig.DIR_EVENTS.c_str(), sizeof(path)-1 ); strncpy(path, staticConfig.DIR_EVENTS.c_str(), sizeof(path)-1 );
} }
scheme = Schemes::SHALLOW; scheme = DEEP;
scheme_str = "Shallow"; scheme_str = "Deep";
} }
Storage::Storage( MYSQL_ROW &dbrow ) { Storage::Storage( MYSQL_ROW &dbrow ) {
@ -48,11 +48,11 @@ Storage::Storage( MYSQL_ROW &dbrow ) {
type_str = std::string(dbrow[index++]); type_str = std::string(dbrow[index++]);
scheme_str = std::string(dbrow[index++]); scheme_str = std::string(dbrow[index++]);
if ( scheme_str == "Deep" ) { if ( scheme_str == "Deep" ) {
scheme = Schemes::DEEP; scheme = DEEP;
} else if ( scheme_str == "Medium" ) { } else if ( scheme_str == "Medium" ) {
scheme = Schemes::MEDIUM; scheme = MEDIUM;
} else { } else {
scheme = Schemes::SHALLOW; scheme = SHALLOW;
} }
} }
@ -75,11 +75,11 @@ Storage::Storage( unsigned int p_id ) {
type_str = std::string(dbrow[index++]); type_str = std::string(dbrow[index++]);
scheme_str = std::string(dbrow[index++]); scheme_str = std::string(dbrow[index++]);
if ( scheme_str == "Deep" ) { if ( scheme_str == "Deep" ) {
scheme = Schemes::DEEP; scheme = DEEP;
} else if ( scheme_str == "Medium" ) { } else if ( scheme_str == "Medium" ) {
scheme = Schemes::MEDIUM; scheme = MEDIUM;
} else { } else {
scheme = Schemes::SHALLOW; scheme = SHALLOW;
} }
Debug( 1, "Loaded Storage area %d '%s'", id, this->Name() ); Debug( 1, "Loaded Storage area %d '%s'", id, this->Name() );
} }

View File

@ -1075,6 +1075,11 @@ int VideoStore::writeVideoFramePacket( ZMPacket * zm_packet ) {
return 0; return 0;
} }
#endif #endif
// Need to adjust pts/dts values from codec time to stream time
if ( opkt.pts != AV_NOPTS_VALUE)
opkt.pts = av_rescale_q(opkt.pts, video_out_ctx->time_base, video_out_stream->time_base);
if ( opkt.dts != AV_NOPTS_VALUE)
opkt.dts = av_rescale_q(opkt.dts, video_out_ctx->time_base, video_out_stream->time_base);
} else { } else {
AVPacket *ipkt = &zm_packet->packet; AVPacket *ipkt = &zm_packet->packet;
@ -1085,12 +1090,21 @@ int VideoStore::writeVideoFramePacket( ZMPacket * zm_packet ) {
opkt.size = ipkt->size; opkt.size = ipkt->size;
opkt.flags = ipkt->flags; opkt.flags = ipkt->flags;
if ( ! video_start_pts ) { if ( ! video_start_pts ) {
video_start_pts = ipkt->pts; // If video has b-frames, pts can be AV_NOPTS_VALUE so use dts intead
video_start_pts = ipkt->dts;
Debug(2, "No video_lsat_pts, set to (%" PRId64 ")", video_start_pts ); Debug(2, "No video_lsat_pts, set to (%" PRId64 ")", video_start_pts );
opkt.dts = opkt.pts = 0; opkt.dts = opkt.pts = 0;
} else { } else {
dumpPacket(ipkt); dumpPacket(ipkt);
opkt.dts = opkt.pts = av_rescale_q( ipkt->pts - video_start_pts, video_in_stream->time_base, video_out_stream->time_base ); if ( ipkt->pts != AV_NOPTS_VALUE )
opkt.pts = av_rescale_q( ipkt->pts - video_start_pts, video_in_stream->time_base, video_out_stream->time_base );
else
opkt.pts = 0;
if ( ipkt->dts != AV_NOPTS_VALUE )
opkt.dts = av_rescale_q( ipkt->dts - video_start_pts, video_in_stream->time_base, video_out_stream->time_base );
else
opkt.dts = 0;
Debug(2, "out_stream_time_base(%d/%d) in_stream_time_base(%d/%d) video_start_pts(%" PRId64 ")", Debug(2, "out_stream_time_base(%d/%d) in_stream_time_base(%d/%d) video_start_pts(%" PRId64 ")",
video_out_stream->time_base.num, video_out_stream->time_base.den, video_out_stream->time_base.num, video_out_stream->time_base.den,
video_in_stream->time_base.num, video_in_stream->time_base.den, video_in_stream->time_base.num, video_in_stream->time_base.den,

View File

@ -90,7 +90,7 @@ class Event {
if ( $this->{'Scheme'} == 'Deep' ) { if ( $this->{'Scheme'} == 'Deep' ) {
$event_path = $this->{'MonitorId'} .'/'.strftime( '%y/%m/%d/%H/%M/%S', $this->Time()) ; $event_path = $this->{'MonitorId'} .'/'.strftime( '%y/%m/%d/%H/%M/%S', $this->Time()) ;
} else if ( $this->{'Scheme'} == 'Medium' ) { } else if ( $this->{'Scheme'} == 'Medium' ) {
$event_path = $this->{'MonitorId'} .'/'.strftime( '%y-%m-%d', $this->Time() ) . '/'.$this->{'Id'}; $event_path = $this->{'MonitorId'} .'/'.strftime( '%Y-%m-%d', $this->Time() ) . '/'.$this->{'Id'};
} else { } else {
$event_path = $this->{'MonitorId'} .'/'.$this->{'Id'}; $event_path = $this->{'MonitorId'} .'/'.$this->{'Id'};
} }

View File

@ -66,8 +66,8 @@ function userLogin( $username, $password='', $passwordHashed=false ) {
$_SESSION['loginFailed'] = true; $_SESSION['loginFailed'] = true;
unset( $user ); unset( $user );
} }
if ( $cookies ) //if ( $cookies )
session_write_close(); //session_write_close();
} }
function userLogout() { function userLogout() {

View File

@ -122,8 +122,8 @@ function parseRows (rows) {
obrSelect.append('<option value="' + i + '">' + '('.repeat(i) + '</option>'); obrSelect.append('<option value="' + i + '">' + '('.repeat(i) + '</option>');
cbrSelect.append('<option value="' + i + '">' + ')'.repeat(i) + '</option>'); cbrSelect.append('<option value="' + i + '">' + ')'.repeat(i) + '</option>');
} }
let obrVal = inputTds.eq(1).children().val(); //Save currently selected bracket option let obrVal = inputTds.eq(1).children().val() != undefined ? inputTds.eq(1).children().val() : 0; //Save currently selected bracket option
let cbrVal = inputTds.eq(5).children().val(); let cbrVal = inputTds.eq(5).children().val() != undefined ? inputTds.eq(5).children().val() : 0;
inputTds.eq(1).html(obrSelect).children().val(obrVal); //Set bracket contents and assign saved value inputTds.eq(1).html(obrSelect).children().val(obrVal); //Set bracket contents and assign saved value
inputTds.eq(5).html(cbrSelect).children().val(cbrVal); inputTds.eq(5).html(cbrSelect).children().val(cbrVal);
} else { } else {

View File

@ -765,6 +765,27 @@ function initPage() {
//setFit(fitMode); // will redraw //setFit(fitMode); // will redraw
//setLive(liveMode); // will redraw //setLive(liveMode); // will redraw
redrawScreen(); redrawScreen();
$j('#minTime').datetimepicker({
timeFormat: "HH:mm:ss",
dateFormat: "yy-mm-dd",
maxDate: +0,
onClose: function (newDate, oldData) {
if (newDate !== oldData.lastVal) {
changeDateTime();
}
}
});
$j('#maxTime').datetimepicker({
timeFormat: "HH:mm:ss",
dateFormat: "yy-mm-dd",
minDate: $j('#minTime').val(),
maxDate: +0,
onClose: function (newDate, oldData) {
if (newDate !== oldData.lastVal) {
changeDateTime();
}
}
});
} }
window.addEventListener("resize",redrawScreen); window.addEventListener("resize",redrawScreen);
// Kick everything off // Kick everything off

View File

@ -219,8 +219,8 @@ xhtmlHeaders(__FILE__, translate('MontageReview') );
<div id="header"> <div id="header">
<?php echo $filter_bar ?> <?php echo $filter_bar ?>
<div id="DateTimeDiv"> <div id="DateTimeDiv">
<input type="datetime-local" name="minTime" id="minTime" value="<?php echo preg_replace('/ /', 'T', $minTime ) ?>" onchange="changeDateTime(this);"> to <input type="text" name="minTime" id="minTime" value="<?php echo preg_replace('/T/', ' ', $minTime ) ?>"> to
<input type="datetime-local" name="maxTime" id="maxTime" value="<?php echo preg_replace('/ /', 'T', $maxTime ) ?>" onchange="changeDateTime(this);"> <input type="text" name="maxTime" id="maxTime" value="<?php echo preg_replace('/T/', ' ', $maxTime ) ?>">
</div> </div>
<div id="ScaleDiv"> <div id="ScaleDiv">
<label for="scaleslider"><?php echo translate('Scale')?></label> <label for="scaleslider"><?php echo translate('Scale')?></label>