Skip to content
Browse files

MythZoneMinder: Add support for the deep filesystem hierarchy for eve…

…nts.

ZoneMinder can use 2 different filesystem layouts to store the event images.
This adds support for the layout you get when you turn on USE_DEEP_STORAGE.

This also changes the date/times in the event and event player screens to use
MythDateTimeToString() for consistency with other screens.

NOTE: This bumps the mythzmserver protocol version so both the server and all
clients need to be updated.

Fixes #10151.
  • Loading branch information...
1 parent a6b1e3a commit 4a2420ed195015173978efde9f1babed45cdc263 Paul Harrison committed Feb 29, 2012
View
55 mythplugins/mythzoneminder/mythzmserver/zmserver.cpp
@@ -52,7 +52,7 @@
#include "zmserver.h"
// the version of the protocol we understand
-#define ZM_PROTOCOL_VERSION "6"
+#define ZM_PROTOCOL_VERSION "7"
// the maximum image size we are ever likely to get from ZM
#define MAX_IMAGE_SIZE (2048*1536*3)
@@ -243,6 +243,16 @@ ZMServer::ZMServer(int sock, bool debug)
if (m_debug)
cout << "Analyse file format is: " << m_analyseFileFormat << endl;
+ // is ZM using the deep storage directory format?
+ m_useDeepStorage = (getZMSetting("ZM_USE_DEEP_STORAGE") == "1");
+ if (m_debug)
+ {
+ if (m_useDeepStorage)
+ cout << "using deep storage directory structure" << endl;
+ else
+ cout << "using flat directory structure" << endl;
+ }
+
getMonitorList();
}
@@ -771,9 +781,8 @@ void ZMServer::getMonitorStatus(string id, string type, string device, string ho
void ZMServer::handleGetEventFrame(vector<string> tokens)
{
static unsigned char buffer[MAX_IMAGE_SIZE];
- char str[100];
- if (tokens.size() != 4)
+ if (tokens.size() != 5)
{
sendError(ERROR_TOKEN_COUNT);
return;
@@ -782,20 +791,32 @@ void ZMServer::handleGetEventFrame(vector<string> tokens)
string monitorID(tokens[1]);
string eventID(tokens[2]);
int frameNo = atoi(tokens[3].c_str());
+ string eventTime(tokens[4]);
if (m_debug)
cout << "Getting frame " << frameNo << " for event " << eventID
- << " on monitor " << monitorID << endl;
+ << " on monitor " << monitorID << " event time is " << eventTime << endl;
string outStr("");
ADD_STR(outStr, "OK")
// try to find the frame file
string filepath("");
- filepath = g_webPath + "/events/" + monitorID + "/" + eventID + "/";
- sprintf(str, m_eventFileFormat.c_str(), frameNo);
- filepath += str;
+ char str[100];
+
+ if (m_useDeepStorage)
+ {
+ filepath = g_webPath + "/events/" + monitorID + "/" + eventTime + "/";
+ sprintf(str, m_eventFileFormat.c_str(), frameNo);
+ filepath += str;
+ }
+ else
+ {
+ filepath = g_webPath + "/events/" + monitorID + "/" + eventID + "/";
+ sprintf(str, m_eventFileFormat.c_str(), frameNo);
+ filepath += str;
+ }
FILE *fd;
int fileSize = 0;
@@ -827,7 +848,7 @@ void ZMServer::handleGetAnalyseFrame(vector<string> tokens)
static unsigned char buffer[MAX_IMAGE_SIZE];
char str[100];
- if (tokens.size() != 4)
+ if (tokens.size() != 5)
{
sendError(ERROR_TOKEN_COUNT);
return;
@@ -836,10 +857,11 @@ void ZMServer::handleGetAnalyseFrame(vector<string> tokens)
string monitorID(tokens[1]);
string eventID(tokens[2]);
int frameNo = atoi(tokens[3].c_str());
+ string eventTime(tokens[4]);
if (m_debug)
cout << "Getting anaylse frame " << frameNo << " for event " << eventID
- << " on monitor " << monitorID << endl;
+ << " on monitor " << monitorID << " event time is " << eventTime << endl;
// get the 'alarm' frames from the Frames table for this event
MYSQL_RES *res;
@@ -889,9 +911,18 @@ void ZMServer::handleGetAnalyseFrame(vector<string> tokens)
// try to find the analyse frame file
string filepath("");
- filepath = g_webPath + "/events/" + monitorID + "/" + eventID + "/";
- sprintf(str, m_analyseFileFormat.c_str(), frameID);
- filepath += str;
+ if (m_useDeepStorage)
+ {
+ filepath = g_webPath + "/events/" + monitorID + "/" + eventTime + "/";
+ sprintf(str, m_analyseFileFormat.c_str(), frameID);
+ filepath += str;
+ }
+ else
+ {
+ filepath = g_webPath + "/events/" + monitorID + "/" + eventID + "/";
+ sprintf(str, m_analyseFileFormat.c_str(), frameID);
+ filepath += str;
+ }
FILE *fd;
int fileSize = 0;
View
1 mythplugins/mythzoneminder/mythzmserver/zmserver.h
@@ -189,6 +189,7 @@ class ZMServer
bool m_debug;
int m_sock;
map<int, MONITOR *> m_monitors;
+ bool m_useDeepStorage;
string m_eventFileFormat;
string m_analyseFileFormat;
key_t m_shmKey;
View
21 mythplugins/mythzoneminder/mythzoneminder/zmclient.cpp
@@ -18,7 +18,7 @@
#include "zmclient.h"
// the protocol version we understand
-#define ZM_PROTOCOL_VERSION "6"
+#define ZM_PROTOCOL_VERSION "7"
#define BUFFER_SIZE (2048*1536*3)
@@ -322,9 +322,6 @@ void ZMClient::getEventList(const QString &monitorName, bool oldestFirst,
return;
}
- QString dateFormat = gCoreContext->GetSetting("ZoneMinderDateFormat", "ddd - dd/MM");
- QString timeFormat = gCoreContext->GetSetting("ZoneMinderTimeFormat", "hh:mm:ss");
-
QStringList::Iterator it = strList.begin();
it++; it++;
for (int x = 0; x < eventCount; x++)
@@ -336,7 +333,7 @@ void ZMClient::getEventList(const QString &monitorName, bool oldestFirst,
item->monitorName = *it++;
QString sDate = *it++;
QDateTime dt = QDateTime::fromString(sDate, Qt::ISODate);
- item->startTime = dt.toString(dateFormat + " " + timeFormat);
+ item->startTime = dt;
item->length = *it++;
eventList->push_back(item);
}
@@ -510,7 +507,7 @@ bool ZMClient::readData(unsigned char *data, int dataSize)
return true;
}
-void ZMClient::getEventFrame(int monitorID, int eventID, int frameNo, MythImage **image)
+void ZMClient::getEventFrame(Event *event, int frameNo, MythImage **image)
{
if (*image)
{
@@ -519,9 +516,10 @@ void ZMClient::getEventFrame(int monitorID, int eventID, int frameNo, MythImage
}
QStringList strList("GET_EVENT_FRAME");
- strList << QString::number(monitorID);
- strList << QString::number(eventID);
+ strList << QString::number(event->monitorID);
+ strList << QString::number(event->eventID);
strList << QString::number(frameNo);
+ strList << event->startTime.toString("yy/MM/dd/hh/mm/ss");
if (!sendReceiveStringList(strList))
return;
@@ -552,12 +550,13 @@ void ZMClient::getEventFrame(int monitorID, int eventID, int frameNo, MythImage
delete [] data;
}
-void ZMClient::getAnalyseFrame(int monitorID, int eventID, int frameNo, QImage &image)
+void ZMClient::getAnalyseFrame(Event *event, int frameNo, QImage &image)
{
QStringList strList("GET_ANALYSE_FRAME");
- strList << QString::number(monitorID);
- strList << QString::number(eventID);
+ strList << QString::number(event->monitorID);
+ strList << QString::number(event->eventID);
strList << QString::number(frameNo);
+ strList << event->startTime.toString("yy/MM/dd/hh/mm/ss");
if (!sendReceiveStringList(strList))
{
image = QImage();
View
4 mythplugins/mythzoneminder/mythzoneminder/zmclient.h
@@ -43,8 +43,8 @@ class MPUBLIC ZMClient : public QObject
void getMonitorStatus(vector<Monitor*> *monitorList);
void getEventList(const QString &monitorName, bool oldestFirst,
QString date, vector<Event*> *eventList);
- void getEventFrame(int monitorID, int eventID, int frameNo, MythImage **image);
- void getAnalyseFrame(int monitorID, int eventID, int frameNo, QImage &image);
+ void getEventFrame(Event *event, int frameNo, MythImage **image);
+ void getAnalyseFrame(Event *event, int frameNo, QImage &image);
int getLiveFrame(int monitorID, QString &status, unsigned char* buffer, int bufferSize);
void getFrameList(int eventID, vector<Frame*> *frameList);
void deleteEvent(int eventID);
View
3 mythplugins/mythzoneminder/mythzoneminder/zmdefines.h
@@ -19,6 +19,7 @@
// qt
#include <QString>
+#include <QDateTime>
// event details
typedef struct
@@ -27,7 +28,7 @@ typedef struct
int eventID;
QString eventName;
QString monitorName;
- QString startTime;
+ QDateTime startTime;
QString length;
} Event;
View
11 mythplugins/mythzoneminder/mythzoneminder/zmevents.cpp
@@ -19,9 +19,10 @@
#include <QKeyEvent>
// myth
-#include "mythtv/mythcontext.h"
-#include "mythtv/mythdbcon.h"
+#include <mythcontext.h>
+#include <mythdbcon.h>
#include <mythmainwindow.h>
+#include <util.h>
// zoneminder
#include "zmevents.h"
@@ -203,7 +204,7 @@ void ZMEvents::updateUIList()
item->SetText(event->eventName);
item->SetText(event->monitorName, "camera" );
- item->SetText(event->startTime, "time");
+ item->SetText(MythDateTimeToString(event->startTime, kDateTimeFull | kSimplify), "time");
item->SetText(event->length, "length");
}
@@ -263,9 +264,7 @@ void ZMEvents::eventChanged(MythUIButtonListItem *item)
QImage image;
if (class ZMClient *zm = ZMClient::get())
{
- zm->getAnalyseFrame(event->monitorID,
- event->eventID,
- 0, image);
+ zm->getAnalyseFrame(event, 0, image);
if (!image.isNull())
{
MythImage *mimage = GetMythPainter()->GetFormatImage();
View
5 mythplugins/mythzoneminder/mythzoneminder/zmplayer.cpp
@@ -28,6 +28,7 @@ using namespace std;
#include <mythdbcon.h>
#include <mythuihelper.h>
#include <mythmainwindow.h>
+#include <util.h>
// zoneminder
#include "zmplayer.h"
@@ -173,7 +174,7 @@ void ZMPlayer::getEventInfo()
.arg((*m_currentEvent) + 1)
.arg(m_eventList->size()));
m_cameraText->SetText(event->monitorName);
- m_dateText->SetText(event->startTime);
+ m_dateText->SetText(MythDateTimeToString(event->startTime, kDateTimeFull | kSimplify));
// get frames data
m_frameList->clear();
@@ -387,7 +388,7 @@ void ZMPlayer::getFrame(void)
if (event)
{
if (class ZMClient *zm = ZMClient::get())
- zm->getEventFrame(event->monitorID, event->eventID, m_curFrame, &m_image);
+ zm->getEventFrame(event, m_curFrame, &m_image);
if (m_image)
{

0 comments on commit 4a2420e

Please sign in to comment.
Something went wrong with that request. Please try again.