forked from ZoneMinder/zoneminder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzm_stream.h
More file actions
181 lines (152 loc) · 4.13 KB
/
Copy pathzm_stream.h
File metadata and controls
181 lines (152 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
//
// ZoneMinder Stream 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#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) )
class StreamBase
{
public:
typedef enum { STREAM_JPEG, STREAM_RAW, STREAM_ZIP, STREAM_SINGLE, STREAM_MPEG } StreamType;
protected:
static const int MAX_STREAM_DELAY = 5; // Seconds
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 };
protected:
typedef struct {
int msg_type;
char msg_data[16];
} CmdMsg;
typedef struct {
int msg_type;
char msg_data[256];
} DataMsg;
typedef enum { MSG_CMD=1, MSG_DATA_WATCH, MSG_DATA_EVENT } MsgType;
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;
protected:
Monitor *monitor;
StreamType type;
const char *format;
int replay_rate;
int scale;
int zoom;
double maxfps;
int bitrate;
unsigned short x, y;
protected:
int connkey;
int sd;
char loc_sock_path[PATH_MAX];
struct sockaddr_un loc_addr;
char rem_sock_path[PATH_MAX];
struct sockaddr_un rem_addr;
char sock_path_lock[PATH_MAX];
int lock_fd;
protected:
bool paused;
int step;
struct timeval now;
double base_fps;
double effective_fps;
int frame_mod;
double last_frame_sent;
struct timeval last_frame_timestamp;
#if HAVE_LIBAVCODEC
VideoStream *vid_stream;
#endif // HAVE_LIBAVCODEC
CmdMsg msg;
protected:
bool loadMonitor( int monitor_id );
bool checkInitialised();
void updateFrameRate( double fps );
Image *prepareImage( Image *image );
bool sendTextFrame( const char *text );
bool checkCommandQueue();
virtual void processCommand( const CmdMsg *msg )=0;
public:
StreamBase()
{
monitor = 0;
type = DEFAULT_TYPE;
format = "";
replay_rate = DEFAULT_RATE;
scale = DEFAULT_SCALE;
zoom = DEFAULT_ZOOM;
maxfps = DEFAULT_MAXFPS;
bitrate = DEFAULT_BITRATE;
paused = false;
step = 0;
x = 0;
y = 0;
connkey = 0;
sd = -1;
lock_fd = 0;
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) );
base_fps = 0.0;
effective_fps = 0.0;
frame_mod = 1;
#if HAVE_LIBAVCODEC
vid_stream = 0;
#endif // HAVE_LIBAVCODEC
}
virtual ~StreamBase();
void setStreamType( StreamType p_type )
{
type = p_type;
}
void setStreamFormat( const char *p_format )
{
format = p_format;
}
void setStreamScale( int p_scale )
{
scale = p_scale;
}
void setStreamReplayRate( int p_rate )
{
replay_rate = p_rate;
}
void setStreamMaxFPS( double p_maxfps )
{
maxfps = p_maxfps;
}
void setStreamBitrate( int p_bitrate )
{
bitrate = p_bitrate;
}
void setStreamQueue( int p_connkey )
{
connkey = p_connkey;
}
virtual void openComms();
virtual void closeComms();
virtual void runStream()=0;
};
#endif // ZM_STREAM_H