fixes to new Storage Schemes code
parent
1fe597c9cc
commit
2922a86d23
|
@ -173,7 +173,7 @@ sub Path {
|
|||
$$event{Path} = join('/',
|
||||
$Storage->Path(),
|
||||
$event->{MonitorId},
|
||||
strftime( '%y-%m-%d', localtime($event->Time())),
|
||||
strftime( '%Y-%m-%d', localtime($event->Time())),
|
||||
$event->{Id},
|
||||
);
|
||||
} else {
|
||||
|
|
|
@ -102,7 +102,7 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
|
|||
struct stat statbuf;
|
||||
char id_file[PATH_MAX];
|
||||
|
||||
if ( storage->Scheme() == Storage::Schemes::DEEP ) {
|
||||
if ( storage->Scheme() == Storage::DEEP ) {
|
||||
char *path_ptr = path;
|
||||
path_ptr += snprintf( path_ptr, sizeof(path), "%s/%d", storage->Path(), monitor->Id() );
|
||||
|
||||
|
@ -136,10 +136,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 );
|
||||
if ( symlink( time_path, id_file ) < 0 )
|
||||
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;
|
||||
path_ptr += snprintf( path_ptr, sizeof(path), "%s/%d/%02d-%02d-%02d",
|
||||
storage->Path(), monitor->Id(), stime->tm_year-100, stime->tm_mon+1, stime->tm_mday
|
||||
path_ptr += snprintf( path_ptr, sizeof(path), "%s/%d/%04d-%02d-%02d",
|
||||
storage->Path(), monitor->Id(), stime->tm_year+1900, stime->tm_mon+1, stime->tm_mday
|
||||
);
|
||||
if ( mkdir( path, 0755 ) ) {
|
||||
// FIXME This should not be fatal. Should probably move to a different storage area.
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "zm_image.h"
|
||||
#include "zm_stream.h"
|
||||
#include "zm_video.h"
|
||||
#include "zm_storage.h"
|
||||
|
||||
class Zone;
|
||||
class Monitor;
|
||||
|
@ -93,6 +94,7 @@ class Event {
|
|||
int last_db_frame;
|
||||
|
||||
void createNotes( std::string ¬es );
|
||||
Storage::Schemes scheme;
|
||||
|
||||
public:
|
||||
static bool OpenFrameSocket( int );
|
||||
|
|
|
@ -103,7 +103,7 @@ bool EventStream::loadInitialEventData( int init_event_id, unsigned int init_fra
|
|||
bool EventStream::loadEventData( int event_id ) {
|
||||
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 ) ) {
|
||||
Error( "Can't run query: %s", mysql_error( &dbconn ) );
|
||||
|
@ -136,19 +136,36 @@ bool EventStream::loadEventData( int event_id ) {
|
|||
event_data->frame_count = dbrow[2] == NULL ? 0 : atoi(dbrow[2]);
|
||||
event_data->start_time = atoi(dbrow[3]);
|
||||
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 );
|
||||
|
||||
Storage * storage = new Storage( event_data->storage_id );
|
||||
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 );
|
||||
|
||||
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 );
|
||||
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 );
|
||||
} 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 {
|
||||
if ( storage_path[0] == '/' )
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "zm_video.h"
|
||||
#include "zm_ffmpeg_input.h"
|
||||
#include "zm_monitor.h"
|
||||
#include "zm_storage.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -63,6 +64,7 @@ class EventStream : public StreamBase {
|
|||
int n_frames;
|
||||
FrameData *frames;
|
||||
char video_file[PATH_MAX];
|
||||
Storage::Schemes scheme;
|
||||
};
|
||||
|
||||
protected:
|
||||
|
|
|
@ -36,8 +36,8 @@ Storage::Storage() {
|
|||
} else {
|
||||
strncpy(path, staticConfig.DIR_EVENTS.c_str(), sizeof(path)-1 );
|
||||
}
|
||||
scheme = Schemes::SHALLOW;
|
||||
scheme_str = "Shallow";
|
||||
scheme = DEEP;
|
||||
scheme_str = "Deep";
|
||||
}
|
||||
|
||||
Storage::Storage( MYSQL_ROW &dbrow ) {
|
||||
|
@ -48,11 +48,11 @@ Storage::Storage( MYSQL_ROW &dbrow ) {
|
|||
type_str = std::string(dbrow[index++]);
|
||||
scheme_str = std::string(dbrow[index++]);
|
||||
if ( scheme_str == "Deep" ) {
|
||||
scheme = Schemes::DEEP;
|
||||
scheme = DEEP;
|
||||
} else if ( scheme_str == "Medium" ) {
|
||||
scheme = Schemes::MEDIUM;
|
||||
scheme = MEDIUM;
|
||||
} else {
|
||||
scheme = Schemes::SHALLOW;
|
||||
scheme = SHALLOW;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,11 +75,11 @@ Storage::Storage( unsigned int p_id ) {
|
|||
type_str = std::string(dbrow[index++]);
|
||||
scheme_str = std::string(dbrow[index++]);
|
||||
if ( scheme_str == "Deep" ) {
|
||||
scheme = Schemes::DEEP;
|
||||
scheme = DEEP;
|
||||
} else if ( scheme_str == "Medium" ) {
|
||||
scheme = Schemes::MEDIUM;
|
||||
scheme = MEDIUM;
|
||||
} else {
|
||||
scheme = Schemes::SHALLOW;
|
||||
scheme = SHALLOW;
|
||||
}
|
||||
Debug( 1, "Loaded Storage area %d '%s'", id, this->Name() );
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ class Event {
|
|||
if ( $this->{'Scheme'} == 'Deep' ) {
|
||||
$event_path = $this->{'MonitorId'} .'/'.strftime( '%y/%m/%d/%H/%M/%S', $this->Time()) ;
|
||||
} 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 {
|
||||
$event_path = $this->{'MonitorId'} .'/'.$this->{'Id'};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue