Skip to content

Commit

Permalink
MythZoneMinder: Add support for the deep filesystem hierarchy for eve…
Browse files Browse the repository at this point in the history
…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
Paul Harrison committed Feb 29, 2012
1 parent a6b1e3a commit 4a2420e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 34 deletions.
55 changes: 43 additions & 12 deletions mythplugins/mythzoneminder/mythzmserver/zmserver.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions mythplugins/mythzoneminder/mythzmserver/zmserver.h
Expand Up @@ -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;
Expand Down
21 changes: 10 additions & 11 deletions mythplugins/mythzoneminder/mythzoneminder/zmclient.cpp
Expand Up @@ -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)

Expand Down Expand Up @@ -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++)
Expand All @@ -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);
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions mythplugins/mythzoneminder/mythzoneminder/zmclient.h
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion mythplugins/mythzoneminder/mythzoneminder/zmdefines.h
Expand Up @@ -19,6 +19,7 @@

// qt
#include <QString>
#include <QDateTime>

// event details
typedef struct
Expand All @@ -27,7 +28,7 @@ typedef struct
int eventID;
QString eventName;
QString monitorName;
QString startTime;
QDateTime startTime;
QString length;
} Event;

Expand Down
11 changes: 5 additions & 6 deletions mythplugins/mythzoneminder/mythzoneminder/zmevents.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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");
}

Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions mythplugins/mythzoneminder/mythzoneminder/zmplayer.cpp
Expand Up @@ -28,6 +28,7 @@ using namespace std;
#include <mythdbcon.h>
#include <mythuihelper.h>
#include <mythmainwindow.h>
#include <util.h>

// zoneminder
#include "zmplayer.h"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 4a2420e

Please sign in to comment.