Skip to content

Commit

Permalink
MythZoneMinder: get a normal frame image if an analysis image is not …
Browse files Browse the repository at this point in the history
…available

Continuous (record) events don't produce any alarm frames so no analysis images
are produced.  It is also possible to turn analysis image creation off even for
alarm events so fall back to returning a normal frame image if no analysis
image is found.

Refs #8912
  • Loading branch information
Paul Harrison committed Oct 29, 2013
1 parent 68f9833 commit f7d0552
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
51 changes: 43 additions & 8 deletions mythplugins/mythzoneminder/mythzmserver/zmserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,11 @@ ZMServer::ZMServer(int sock, bool debug)
if (m_debug)
cout << "Event file format is: " << m_eventFileFormat << endl;

// get the analyse filename format
// get the analysis filename format
snprintf(buf, sizeof(buf), "%%0%dd-analyse.jpg", eventDigits);
m_analyseFileFormat = buf;
m_analysisFileFormat = buf;
if (m_debug)
cout << "Analyse file format is: " << m_analyseFileFormat << endl;
cout << "Analysis file format is: " << m_analysisFileFormat << endl;

// is ZM using the deep storage directory format?
m_useDeepStorage = (getZMSetting("ZM_USE_DEEP_STORAGE") == "1");
Expand All @@ -445,6 +445,16 @@ ZMServer::ZMServer(int sock, bool debug)
cout << "using flat directory structure" << endl;
}

// is ZM creating analysis images?
m_useAnalysisImages = (getZMSetting("ZM_CREATE_ANALYSIS_IMAGES") == "1");
if (m_debug)
{
if (m_useAnalysisImages)
cout << "using analysis images" << endl;
else
cout << "not using analysis images" << endl;
}

getMonitorList();
}

Expand Down Expand Up @@ -530,7 +540,7 @@ bool ZMServer::processRequest(char* buf, int nbytes)
else if (tokens[0] == "GET_EVENT_FRAME")
handleGetEventFrame(tokens);
else if (tokens[0] == "GET_ANALYSE_FRAME")
handleGetAnalyseFrame(tokens);
handleGetAnalysisFrame(tokens);
else if (tokens[0] == "GET_LIVE_FRAME")
handleGetLiveFrame(tokens);
else if (tokens[0] == "GET_FRAME_LIST")
Expand Down Expand Up @@ -1057,7 +1067,7 @@ void ZMServer::handleGetEventFrame(vector<string> tokens)
send(outStr, buffer, fileSize);
}

void ZMServer::handleGetAnalyseFrame(vector<string> tokens)
void ZMServer::handleGetAnalysisFrame(vector<string> tokens)
{
static unsigned char buffer[MAX_IMAGE_SIZE];
char str[100];
Expand All @@ -1074,7 +1084,7 @@ void ZMServer::handleGetAnalyseFrame(vector<string> tokens)
string eventTime(tokens[4]);

if (m_debug)
cout << "Getting anaylse frame " << frameNo << " for event " << eventID
cout << "Getting analysis frame " << frameNo << " for event " << eventID
<< " on monitor " << monitorID << " event time is " << eventTime << endl;

// get the 'alarm' frames from the Frames table for this event
Expand All @@ -1097,6 +1107,29 @@ void ZMServer::handleGetAnalyseFrame(vector<string> tokens)
res = mysql_store_result(&g_dbConn);
int frameCount = mysql_num_rows(res);
int frameID;
string fileFormat = m_analysisFileFormat;

// if we didn't find any analysis frames look for a normal frame instead
if (frameCount == 0 || m_useAnalysisImages == false)
{
mysql_free_result(res);

frameNo = 0;
fileFormat = m_eventFileFormat;
sql = "SELECT FrameId FROM Frames ";
sql += "WHERE EventID = " + eventID + " ";
sql += "ORDER BY FrameID";

if (mysql_query(&g_dbConn, sql.c_str()))
{
fprintf(stderr, "%s\n", mysql_error(&g_dbConn));
sendError(ERROR_MYSQL_QUERY);
return;
}

res = mysql_store_result(&g_dbConn);
frameCount = mysql_num_rows(res);
}

// if the required frame mumber is 0 or out of bounds then use the middle frame
if (frameNo == 0 || frameNo < 0 || frameNo > frameCount)
Expand All @@ -1119,6 +1152,8 @@ void ZMServer::handleGetAnalyseFrame(vector<string> tokens)
return;
}

mysql_free_result(res);

string outStr("");

ADD_STR(outStr, "OK")
Expand All @@ -1128,13 +1163,13 @@ void ZMServer::handleGetAnalyseFrame(vector<string> tokens)
if (m_useDeepStorage)
{
filepath = g_webPath + "/events/" + monitorID + "/" + eventTime + "/";
sprintf(str, m_analyseFileFormat.c_str(), frameID);
sprintf(str, fileFormat.c_str(), frameID);
filepath += str;
}
else
{
filepath = g_webPath + "/events/" + monitorID + "/" + eventID + "/";
sprintf(str, m_analyseFileFormat.c_str(), frameID);
sprintf(str, fileFormat.c_str(), frameID);
filepath += str;
}

Expand Down
5 changes: 3 additions & 2 deletions mythplugins/mythzoneminder/mythzmserver/zmserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class ZMServer
void handleGetCameraList(void);
void handleGetEventList(vector<string> tokens);
void handleGetEventFrame(vector<string> tokens);
void handleGetAnalyseFrame(vector<string> tokens);
void handleGetAnalysisFrame(vector<string> tokens);
void handleGetLiveFrame(vector<string> tokens);
void handleGetFrameList(vector<string> tokens);
void handleDeleteEvent(vector<string> tokens);
Expand All @@ -231,8 +231,9 @@ class ZMServer
int m_sock;
map<int, MONITOR *> m_monitors;
bool m_useDeepStorage;
bool m_useAnalysisImages;
string m_eventFileFormat;
string m_analyseFileFormat;
string m_analysisFileFormat;
key_t m_shmKey;
string m_mmapPath;
};
Expand Down

0 comments on commit f7d0552

Please sign in to comment.