2017-06-23 05:58:32 +08:00
|
|
|
//
|
|
|
|
// ZoneMinder Core Interfaces, $Date$, $Revision$
|
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ZM_EVENTSTREAM_H
|
|
|
|
#define ZM_EVENTSTREAM_H
|
|
|
|
|
2021-02-05 02:58:29 +08:00
|
|
|
#include "zm_define.h"
|
2017-06-27 04:55:49 +08:00
|
|
|
#include "zm_ffmpeg_input.h"
|
2017-11-07 22:34:47 +08:00
|
|
|
#include "zm_monitor.h"
|
2017-12-20 00:01:03 +08:00
|
|
|
#include "zm_storage.h"
|
2021-02-05 02:58:29 +08:00
|
|
|
#include "zm_stream.h"
|
2017-06-23 05:58:32 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
#include "libavformat/avformat.h"
|
|
|
|
#include "libavformat/avio.h"
|
|
|
|
#include "libavcodec/avcodec.h"
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class EventStream : public StreamBase {
|
|
|
|
public:
|
2018-09-29 00:31:53 +08:00
|
|
|
typedef enum { MODE_NONE, MODE_SINGLE, MODE_ALL, MODE_ALL_GAPLESS } StreamMode;
|
2021-01-27 01:21:21 +08:00
|
|
|
static const std::string StreamMode_Strings[4];
|
2017-06-23 05:58:32 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
struct FrameData {
|
|
|
|
//unsigned long id;
|
2018-09-12 01:20:41 +08:00
|
|
|
double timestamp;
|
|
|
|
double offset;
|
2017-06-23 05:58:32 +08:00
|
|
|
double delta;
|
|
|
|
bool in_db;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct EventData {
|
2018-04-18 01:51:20 +08:00
|
|
|
uint64_t event_id;
|
2020-07-24 07:32:30 +08:00
|
|
|
unsigned int monitor_id;
|
2017-06-23 05:58:32 +08:00
|
|
|
unsigned long storage_id;
|
2020-10-08 21:06:56 +08:00
|
|
|
unsigned long frame_count; // Value of Frames column in Event
|
|
|
|
unsigned long last_frame_id; // Highest frame id known about. Can be < frame_count in incomplete events
|
2017-06-23 05:58:32 +08:00
|
|
|
time_t start_time;
|
2020-10-08 21:06:56 +08:00
|
|
|
time_t end_time;
|
2017-06-23 05:58:32 +08:00
|
|
|
double duration;
|
2021-02-10 03:23:34 +08:00
|
|
|
double frames_duration;
|
2017-06-23 05:58:32 +08:00
|
|
|
char path[PATH_MAX];
|
2020-10-08 21:06:56 +08:00
|
|
|
int n_frames; // # of frame rows returned from database
|
2017-06-23 05:58:32 +08:00
|
|
|
FrameData *frames;
|
|
|
|
char video_file[PATH_MAX];
|
2017-12-20 00:01:03 +08:00
|
|
|
Storage::Schemes scheme;
|
2018-11-07 00:45:34 +08:00
|
|
|
int SaveJPEGs;
|
2020-02-11 05:22:01 +08:00
|
|
|
Monitor::Orientation Orientation;
|
2017-06-23 05:58:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static const int STREAM_PAUSE_WAIT = 250000; // Microseconds
|
|
|
|
|
|
|
|
static const StreamMode DEFAULT_MODE = MODE_SINGLE;
|
|
|
|
|
|
|
|
StreamMode mode;
|
|
|
|
bool forceEventChange;
|
|
|
|
|
2020-11-03 01:45:19 +08:00
|
|
|
long curr_frame_id;
|
2017-06-23 05:58:32 +08:00
|
|
|
double curr_stream_time;
|
2017-11-17 20:52:26 +08:00
|
|
|
bool send_frame;
|
2019-01-16 05:44:58 +08:00
|
|
|
struct timeval start; // clock time when started the event
|
2017-06-23 05:58:32 +08:00
|
|
|
|
|
|
|
EventData *event_data;
|
|
|
|
|
|
|
|
protected:
|
2021-01-27 01:21:21 +08:00
|
|
|
bool loadEventData(uint64_t event_id);
|
|
|
|
bool loadInitialEventData(uint64_t init_event_id, unsigned int init_frame_id);
|
|
|
|
bool loadInitialEventData(int monitor_id, time_t event_time);
|
2017-06-23 05:58:32 +08:00
|
|
|
|
2019-12-03 04:51:08 +08:00
|
|
|
bool checkEventLoaded();
|
2021-02-22 21:15:36 +08:00
|
|
|
void processCommand(const CmdMsg *msg) override;
|
2021-01-27 01:21:21 +08:00
|
|
|
bool sendFrame(int delta_us);
|
2017-06-23 05:58:32 +08:00
|
|
|
|
|
|
|
public:
|
2020-04-21 20:28:44 +08:00
|
|
|
EventStream() :
|
|
|
|
mode(DEFAULT_MODE),
|
|
|
|
forceEventChange(false),
|
|
|
|
curr_frame_id(0),
|
|
|
|
curr_stream_time(0.0),
|
|
|
|
send_frame(false),
|
2020-08-26 07:45:48 +08:00
|
|
|
event_data(nullptr),
|
|
|
|
storage(nullptr),
|
2021-04-11 20:26:37 +08:00
|
|
|
ffmpeg_input(nullptr)
|
2020-04-21 20:28:44 +08:00
|
|
|
{}
|
2020-04-27 06:19:30 +08:00
|
|
|
~EventStream() {
|
|
|
|
if ( event_data ) {
|
2020-05-01 21:56:27 +08:00
|
|
|
if ( event_data->frames ) {
|
|
|
|
delete[] event_data->frames;
|
2020-08-26 07:45:48 +08:00
|
|
|
event_data->frames = nullptr;
|
2020-05-01 21:56:27 +08:00
|
|
|
}
|
2020-04-27 06:19:30 +08:00
|
|
|
delete event_data;
|
2020-08-26 07:45:48 +08:00
|
|
|
event_data = nullptr;
|
2020-04-27 06:19:30 +08:00
|
|
|
}
|
|
|
|
if ( storage ) {
|
|
|
|
delete storage;
|
2020-08-26 07:45:48 +08:00
|
|
|
storage = nullptr;
|
2020-04-27 06:19:30 +08:00
|
|
|
}
|
|
|
|
if ( ffmpeg_input ) {
|
|
|
|
delete ffmpeg_input;
|
2020-08-26 07:45:48 +08:00
|
|
|
ffmpeg_input = nullptr;
|
2020-04-27 06:19:30 +08:00
|
|
|
}
|
2017-06-23 05:58:32 +08:00
|
|
|
}
|
2021-01-27 01:21:21 +08:00
|
|
|
void setStreamStart(uint64_t init_event_id, unsigned int init_frame_id);
|
|
|
|
void setStreamStart(int monitor_id, time_t event_time);
|
|
|
|
void setStreamMode(StreamMode p_mode) { mode = p_mode; }
|
2020-11-02 06:15:17 +08:00
|
|
|
void runStream() override;
|
2017-06-23 05:58:32 +08:00
|
|
|
Image *getImage();
|
|
|
|
private:
|
2020-11-03 01:45:19 +08:00
|
|
|
bool send_file(const char *filepath);
|
|
|
|
bool send_buffer(uint8_t * buffer, int size);
|
2020-04-27 06:43:39 +08:00
|
|
|
Storage *storage;
|
2020-04-21 20:28:44 +08:00
|
|
|
FFmpeg_Input *ffmpeg_input;
|
2017-06-23 05:58:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ZM_EVENTSTREAM_H
|