use enum values to make code more readable. Better error message on event insertion failure

This commit is contained in:
Isaac Connor 2017-05-20 08:34:46 -04:00
parent 7ecbcd8f12
commit 1ab8530aed
1 changed files with 9 additions and 8 deletions

View File

@ -82,7 +82,7 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
struct tm *stime = localtime( &start_time.tv_sec );
snprintf( sql, sizeof(sql), "insert into Events ( MonitorId, Name, StartTime, Width, Height, Cause, Notes, Videoed ) values ( %d, 'New Event', from_unixtime( %ld ), %d, %d, '%s', '%s', '%d' )", monitor->Id(), start_time.tv_sec, monitor->Width(), monitor->Height(), cause.c_str(), notes.c_str(), videoEvent );
if ( mysql_query( &dbconn, sql ) ) {
Error( "Can't insert event: %s", mysql_error( &dbconn ) );
Error( "Can't insert event: %s. sql was (%s)", mysql_error( &dbconn ), sql );
exit( mysql_errno( &dbconn ) );
}
id = mysql_insert_id( &dbconn );
@ -163,11 +163,9 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
if ( monitor->GetOptVideoWriter() != 0 ) {
snprintf( video_name, sizeof(video_name), "%d-%s", id, "video.mp4" );
snprintf( video_file, sizeof(video_file), video_file_format, path, video_name );
snprintf( timecodes_name, sizeof(timecodes_name), "%d-%s", id, "video.timecodes" );
snprintf( timecodes_file, sizeof(timecodes_file), video_file_format, path, timecodes_name );
/* X264 MP4 video writer */
if(monitor->GetOptVideoWriter() == 1) {
if ( monitor->GetOptVideoWriter() == X264ENCODE ) {
#if ZM_HAVE_VIDEOWRITER_X264MP4
videowriter = new X264MP4Writer(video_file, monitor->Width(), monitor->Height(), monitor->Colours(), monitor->SubpixelOrder(), monitor->GetOptEncoderParams());
#else
@ -175,7 +173,7 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
#endif
}
if(videowriter != NULL) {
if ( videowriter != NULL ) {
/* Open the video stream */
int nRet = videowriter->Open();
if(nRet != 0) {
@ -184,9 +182,12 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
videowriter = NULL;
}
/* Create timecodes file */
timecodes_fd = fopen(timecodes_file, "wb");
if(timecodes_fd == NULL) {
snprintf( timecodes_name, sizeof(timecodes_name), "%d-%s", id, "video.timecodes" );
snprintf( timecodes_file, sizeof(timecodes_file), video_file_format, path, timecodes_name );
/* Create timecodes file */
timecodes_fd = fopen(timecodes_file, "wb");
if ( timecodes_fd == NULL ) {
Error("Failed creating timecodes file");
}
}