2007-08-30 02:11:09 +08:00
|
|
|
//
|
|
|
|
// ZoneMinder Stream Interfaces, $Date$, $Revision$
|
2008-07-25 17:33:23 +08:00
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
2007-08-30 02:11:09 +08:00
|
|
|
//
|
|
|
|
// 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
|
2016-12-26 23:23:16 +08:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-08-30 02:11:09 +08:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ZM_STREAM_H
|
|
|
|
#define ZM_STREAM_H
|
|
|
|
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include "zm.h"
|
|
|
|
#include "zm_mpeg.h"
|
|
|
|
|
|
|
|
class Monitor;
|
|
|
|
|
|
|
|
#define TV_2_FLOAT( tv ) ( double((tv).tv_sec) + (double((tv).tv_usec) / 1000000.0) )
|
2020-04-15 05:01:12 +08:00
|
|
|
#define BOUNDARY "ZoneMinderFrame"
|
2007-08-30 02:11:09 +08:00
|
|
|
|
2017-07-06 02:11:58 +08:00
|
|
|
class StreamBase {
|
2007-08-30 02:11:09 +08:00
|
|
|
public:
|
2021-01-16 03:43:07 +08:00
|
|
|
typedef enum {
|
|
|
|
STREAM_JPEG,
|
|
|
|
STREAM_RAW,
|
|
|
|
STREAM_ZIP,
|
|
|
|
STREAM_SINGLE,
|
|
|
|
STREAM_MPEG
|
|
|
|
} StreamType;
|
2007-08-30 02:11:09 +08:00
|
|
|
|
|
|
|
protected:
|
2016-04-04 22:11:48 +08:00
|
|
|
static const int MAX_STREAM_DELAY = 5; // Seconds
|
2019-08-16 22:24:51 +08:00
|
|
|
static const int MAX_SLEEP_USEC = 500000; // .5 Seconds
|
2007-08-30 02:11:09 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
static const StreamType DEFAULT_TYPE = STREAM_JPEG;
|
|
|
|
enum { DEFAULT_RATE=ZM_RATE_BASE };
|
|
|
|
enum { DEFAULT_SCALE=ZM_SCALE_BASE };
|
|
|
|
enum { DEFAULT_ZOOM=ZM_SCALE_BASE };
|
|
|
|
enum { DEFAULT_MAXFPS=10 };
|
|
|
|
enum { DEFAULT_BITRATE=100000 };
|
2007-08-30 02:11:09 +08:00
|
|
|
|
|
|
|
protected:
|
2016-04-04 22:11:48 +08:00
|
|
|
typedef struct {
|
|
|
|
int msg_type;
|
|
|
|
char msg_data[16];
|
|
|
|
} CmdMsg;
|
2007-08-30 02:11:09 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
typedef struct {
|
|
|
|
int msg_type;
|
|
|
|
char msg_data[256];
|
|
|
|
} DataMsg;
|
2007-08-30 02:11:09 +08:00
|
|
|
|
2021-01-16 03:43:07 +08:00
|
|
|
typedef enum {
|
|
|
|
MSG_CMD=1,
|
|
|
|
MSG_DATA_WATCH,
|
|
|
|
MSG_DATA_EVENT
|
|
|
|
} MsgType;
|
|
|
|
|
2021-01-09 05:45:03 +08:00
|
|
|
typedef enum {
|
|
|
|
CMD_NONE=0,
|
|
|
|
CMD_PAUSE,
|
|
|
|
CMD_PLAY,
|
|
|
|
CMD_STOP,
|
|
|
|
CMD_FASTFWD,
|
|
|
|
CMD_SLOWFWD,
|
|
|
|
CMD_SLOWREV,
|
|
|
|
CMD_FASTREV,
|
|
|
|
CMD_ZOOMIN,
|
|
|
|
CMD_ZOOMOUT,
|
|
|
|
CMD_PAN,
|
|
|
|
CMD_SCALE,
|
|
|
|
CMD_PREV,
|
|
|
|
CMD_NEXT,
|
|
|
|
CMD_SEEK,
|
|
|
|
CMD_VARPLAY,
|
|
|
|
CMD_GET_IMAGE,
|
|
|
|
CMD_QUIT,
|
|
|
|
CMD_QUERY=99
|
|
|
|
} MsgCommand;
|
2007-08-30 02:11:09 +08:00
|
|
|
|
|
|
|
protected:
|
2020-09-03 04:36:05 +08:00
|
|
|
int monitor_id;
|
2016-04-04 22:11:48 +08:00
|
|
|
Monitor *monitor;
|
2007-08-30 02:11:09 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
StreamType type;
|
|
|
|
const char *format;
|
|
|
|
int replay_rate;
|
|
|
|
int scale;
|
2019-09-27 01:51:49 +08:00
|
|
|
int last_scale;
|
2016-04-04 22:11:48 +08:00
|
|
|
int zoom;
|
2019-09-27 01:51:49 +08:00
|
|
|
int last_zoom;
|
2016-04-04 22:11:48 +08:00
|
|
|
double maxfps;
|
|
|
|
int bitrate;
|
2019-09-27 01:51:49 +08:00
|
|
|
unsigned short last_x, last_y;
|
2016-04-04 22:11:48 +08:00
|
|
|
unsigned short x, y;
|
2020-04-21 20:28:44 +08:00
|
|
|
bool send_analysis;
|
|
|
|
bool send_objdetect;
|
2016-04-04 22:11:48 +08:00
|
|
|
int connkey;
|
|
|
|
int sd;
|
2020-04-25 06:03:00 +08:00
|
|
|
char loc_sock_path[108];
|
2016-04-04 22:11:48 +08:00
|
|
|
struct sockaddr_un loc_addr;
|
2020-04-25 06:03:00 +08:00
|
|
|
char rem_sock_path[108];
|
2016-04-04 22:11:48 +08:00
|
|
|
struct sockaddr_un rem_addr;
|
2020-04-25 06:03:00 +08:00
|
|
|
char sock_path_lock[108];
|
2016-04-04 22:11:48 +08:00
|
|
|
int lock_fd;
|
|
|
|
bool paused;
|
|
|
|
int step;
|
2007-08-30 02:11:09 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
struct timeval now;
|
2018-09-22 03:58:14 +08:00
|
|
|
struct timeval last_comm_update;
|
2007-08-30 02:11:09 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
double base_fps;
|
|
|
|
double effective_fps;
|
|
|
|
int frame_mod;
|
2007-08-30 02:11:09 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
double last_frame_sent;
|
|
|
|
struct timeval last_frame_timestamp;
|
2007-08-30 02:11:09 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
#if HAVE_LIBAVCODEC
|
|
|
|
VideoStream *vid_stream;
|
|
|
|
#endif // HAVE_LIBAVCODEC
|
2007-08-30 02:11:09 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
CmdMsg msg;
|
2007-08-30 02:11:09 +08:00
|
|
|
|
|
|
|
protected:
|
2020-07-25 03:27:05 +08:00
|
|
|
bool loadMonitor(int monitor_id);
|
2016-04-04 22:11:48 +08:00
|
|
|
bool checkInitialised();
|
2020-07-25 03:27:05 +08:00
|
|
|
void updateFrameRate(double fps);
|
|
|
|
Image *prepareImage(Image *image);
|
2016-04-04 22:11:48 +08:00
|
|
|
bool checkCommandQueue();
|
2020-07-25 03:27:05 +08:00
|
|
|
virtual void processCommand(const CmdMsg *msg)=0;
|
2007-08-30 02:11:09 +08:00
|
|
|
|
|
|
|
public:
|
2020-04-21 20:28:44 +08:00
|
|
|
StreamBase():
|
2020-09-03 04:36:05 +08:00
|
|
|
monitor_id(0),
|
2020-10-09 04:46:47 +08:00
|
|
|
monitor(nullptr),
|
2020-04-21 20:28:44 +08:00
|
|
|
type(DEFAULT_TYPE),
|
|
|
|
format(""),
|
|
|
|
replay_rate(DEFAULT_RATE),
|
|
|
|
scale(DEFAULT_SCALE),
|
|
|
|
last_scale(DEFAULT_SCALE),
|
|
|
|
zoom(DEFAULT_ZOOM),
|
|
|
|
last_zoom(DEFAULT_ZOOM),
|
|
|
|
maxfps(DEFAULT_MAXFPS),
|
|
|
|
bitrate(DEFAULT_BITRATE),
|
|
|
|
last_x(0),
|
|
|
|
last_y(0),
|
|
|
|
x(0),
|
|
|
|
y(0),
|
|
|
|
send_analysis(false),
|
|
|
|
send_objdetect(false),
|
|
|
|
connkey(0),
|
|
|
|
sd(-1),
|
|
|
|
lock_fd(0),
|
|
|
|
paused(false),
|
|
|
|
step(0)
|
2021-01-09 05:45:03 +08:00
|
|
|
{
|
2020-07-25 03:27:05 +08:00
|
|
|
memset(&loc_sock_path, 0, sizeof(loc_sock_path));
|
|
|
|
memset(&loc_addr, 0, sizeof(loc_addr));
|
|
|
|
memset(&rem_sock_path, 0, sizeof(rem_sock_path));
|
|
|
|
memset(&rem_addr, 0, sizeof(rem_addr));
|
|
|
|
memset(&sock_path_lock, 0, sizeof(sock_path_lock));
|
2016-04-04 22:11:48 +08:00
|
|
|
|
|
|
|
base_fps = 0.0;
|
|
|
|
effective_fps = 0.0;
|
|
|
|
frame_mod = 1;
|
|
|
|
|
|
|
|
#if HAVE_LIBAVCODEC
|
|
|
|
vid_stream = 0;
|
|
|
|
#endif // HAVE_LIBAVCODEC
|
2017-11-17 07:23:02 +08:00
|
|
|
last_frame_sent = 0.0;
|
2017-12-13 02:01:57 +08:00
|
|
|
last_frame_timestamp = (struct timeval){0};
|
2017-11-17 07:23:02 +08:00
|
|
|
msg = { 0, { 0 } };
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
|
|
|
virtual ~StreamBase();
|
|
|
|
|
2020-07-25 03:27:05 +08:00
|
|
|
void setStreamType(StreamType p_type) {
|
2016-04-04 22:11:48 +08:00
|
|
|
type = p_type;
|
2017-07-19 10:30:22 +08:00
|
|
|
#if ! HAVE_ZLIB_H
|
|
|
|
if ( type == STREAM_ZIP ) {
|
|
|
|
Error("zlib is required for zipped images. Falling back to raw image");
|
|
|
|
type = STREAM_RAW;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2020-07-25 03:27:05 +08:00
|
|
|
void setStreamFormat(const char *p_format) {
|
2016-04-04 22:11:48 +08:00
|
|
|
format = p_format;
|
|
|
|
}
|
2020-07-25 03:27:05 +08:00
|
|
|
void setStreamScale(int p_scale) {
|
2016-04-04 22:11:48 +08:00
|
|
|
scale = p_scale;
|
2020-07-25 03:27:05 +08:00
|
|
|
if ( !scale )
|
2017-07-06 02:11:17 +08:00
|
|
|
scale = DEFAULT_SCALE;
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2020-07-25 03:27:05 +08:00
|
|
|
void setStreamReplayRate(int p_rate) {
|
|
|
|
Debug(2, "Setting replay_rate %d", p_rate);
|
2016-04-04 22:11:48 +08:00
|
|
|
replay_rate = p_rate;
|
|
|
|
}
|
2020-07-25 03:27:05 +08:00
|
|
|
void setStreamMaxFPS(double p_maxfps) {
|
2016-04-04 22:11:48 +08:00
|
|
|
maxfps = p_maxfps;
|
|
|
|
}
|
2020-07-25 03:27:05 +08:00
|
|
|
void setStreamBitrate(int p_bitrate) {
|
2016-04-04 22:11:48 +08:00
|
|
|
bitrate = p_bitrate;
|
|
|
|
}
|
2020-07-25 03:27:05 +08:00
|
|
|
void setStreamQueue(int p_connkey) {
|
2016-04-04 22:11:48 +08:00
|
|
|
connkey = p_connkey;
|
|
|
|
}
|
2021-01-16 03:43:07 +08:00
|
|
|
bool sendTextFrame(const char *text);
|
2016-04-04 22:11:48 +08:00
|
|
|
virtual void openComms();
|
|
|
|
virtual void closeComms();
|
|
|
|
virtual void runStream()=0;
|
2007-08-30 02:11:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ZM_STREAM_H
|