2002-09-24 06:08:50 +08:00
|
|
|
//
|
2002-12-10 21:21:41 +08:00
|
|
|
// ZoneMinder Streaming Server, $Date$, $Revision$
|
2008-07-25 17:33:23 +08:00
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
2019-07-26 22:53:48 +08:00
|
|
|
//
|
2002-09-24 06:08:50 +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.
|
2019-07-26 22:53:48 +08:00
|
|
|
//
|
2002-09-24 06:08:50 +08:00
|
|
|
// 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.
|
2019-07-26 22:53:48 +08:00
|
|
|
//
|
2002-09-24 06:08:50 +08:00
|
|
|
// 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.
|
2019-07-26 22:53:48 +08:00
|
|
|
//
|
2002-09-24 06:08:50 +08:00
|
|
|
|
2007-08-30 02:11:09 +08:00
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/msg.h>
|
2018-04-25 01:16:19 +08:00
|
|
|
#include <cinttypes>
|
2019-07-26 22:53:48 +08:00
|
|
|
#include <string>
|
2007-08-30 02:11:09 +08:00
|
|
|
|
2002-09-16 17:19:24 +08:00
|
|
|
#include "zm.h"
|
2003-03-26 20:00:16 +08:00
|
|
|
#include "zm_db.h"
|
2005-01-19 09:50:24 +08:00
|
|
|
#include "zm_user.h"
|
2006-04-05 20:22:27 +08:00
|
|
|
#include "zm_signal.h"
|
2003-03-26 20:00:16 +08:00
|
|
|
#include "zm_monitor.h"
|
2017-04-11 09:52:29 +08:00
|
|
|
#include "zm_monitorstream.h"
|
2017-06-23 05:58:32 +08:00
|
|
|
#include "zm_eventstream.h"
|
2019-05-17 03:37:03 +08:00
|
|
|
#include "zm_fifo.h"
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2019-07-26 22:53:48 +08:00
|
|
|
bool ValidateAccess(User *user, int mon_id) {
|
2016-04-04 22:11:48 +08:00
|
|
|
bool allowed = true;
|
2004-12-30 02:03:13 +08:00
|
|
|
|
2017-07-06 02:10:09 +08:00
|
|
|
if ( mon_id > 0 ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
if ( user->getStream() < User::PERM_VIEW )
|
|
|
|
allowed = false;
|
2019-07-26 22:53:48 +08:00
|
|
|
if ( !user->canAccess(mon_id) )
|
2016-04-04 22:11:48 +08:00
|
|
|
allowed = false;
|
2016-09-28 21:08:00 +08:00
|
|
|
} else {
|
2016-04-04 22:11:48 +08:00
|
|
|
if ( user->getEvents() < User::PERM_VIEW )
|
|
|
|
allowed = false;
|
|
|
|
}
|
2017-07-06 02:10:09 +08:00
|
|
|
if ( !allowed ) {
|
2019-07-26 22:53:48 +08:00
|
|
|
Error("Insufficient privileges for request user %d %s for monitor %d",
|
2019-07-20 01:55:35 +08:00
|
|
|
user->Id(), user->getUsername(), mon_id);
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2018-07-05 02:50:47 +08:00
|
|
|
return allowed;
|
2004-12-30 02:03:13 +08:00
|
|
|
}
|
|
|
|
|
2020-09-10 00:13:28 +08:00
|
|
|
int main(int argc, const char *argv[], char **envp) {
|
2016-04-04 22:11:48 +08:00
|
|
|
self = argv[0];
|
2013-10-07 07:37:50 +08:00
|
|
|
|
2020-08-26 07:45:48 +08:00
|
|
|
srand(getpid() * time(nullptr));
|
2009-04-15 04:18:57 +08:00
|
|
|
|
2019-05-17 03:37:03 +08:00
|
|
|
enum { ZMS_UNKNOWN, ZMS_MONITOR, ZMS_EVENT, ZMS_FIFO } source = ZMS_UNKNOWN;
|
2016-04-04 22:11:48 +08:00
|
|
|
enum { ZMS_JPEG, ZMS_MPEG, ZMS_RAW, ZMS_ZIP, ZMS_SINGLE } mode = ZMS_JPEG;
|
|
|
|
char format[32] = "";
|
|
|
|
int monitor_id = 0;
|
|
|
|
time_t event_time = 0;
|
2018-04-18 01:57:19 +08:00
|
|
|
uint64_t event_id = 0;
|
2016-04-28 21:20:56 +08:00
|
|
|
unsigned int frame_id = 1;
|
2016-04-04 22:11:48 +08:00
|
|
|
unsigned int scale = 100;
|
|
|
|
unsigned int rate = 100;
|
|
|
|
double maxfps = 10.0;
|
|
|
|
unsigned int bitrate = 100000;
|
|
|
|
unsigned int ttl = 0;
|
2018-09-29 00:31:53 +08:00
|
|
|
EventStream::StreamMode replay = EventStream::MODE_NONE;
|
2017-03-20 23:16:39 +08:00
|
|
|
std::string username;
|
|
|
|
std::string password;
|
2016-04-04 22:11:48 +08:00
|
|
|
char auth[64] = "";
|
2019-07-26 22:53:48 +08:00
|
|
|
std::string jwt_token_str = "";
|
2016-09-27 08:08:45 +08:00
|
|
|
unsigned int connkey = 0;
|
|
|
|
unsigned int playback_buffer = 0;
|
2003-06-09 04:24:52 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
bool nph = false;
|
2018-06-01 23:27:53 +08:00
|
|
|
const char *basename = strrchr(argv[0], '/');
|
2019-07-26 22:53:48 +08:00
|
|
|
if ( basename ) // if we found a / lets skip past it
|
2016-04-04 22:11:48 +08:00
|
|
|
basename++;
|
2019-07-26 22:53:48 +08:00
|
|
|
else // argv[0] might not contain the full path, but just the script name
|
2016-04-04 22:11:48 +08:00
|
|
|
basename = argv[0];
|
|
|
|
const char *nph_prefix = "nph-";
|
2018-06-01 23:27:53 +08:00
|
|
|
if ( basename && !strncmp(basename, nph_prefix, strlen(nph_prefix)) ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
nph = true;
|
|
|
|
}
|
2019-07-26 22:53:48 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
zmLoadConfig();
|
2019-02-14 00:34:47 +08:00
|
|
|
char log_id_string[32] = "zms";
|
2019-07-26 22:53:48 +08:00
|
|
|
logInit(log_id_string);
|
2020-09-10 00:13:28 +08:00
|
|
|
for (char **env = envp; *env != 0; env++) {
|
|
|
|
char *thisEnv = *env;
|
|
|
|
Debug(1, "env: %s", thisEnv);
|
|
|
|
}
|
2004-12-29 00:46:48 +08:00
|
|
|
|
2018-06-01 23:27:53 +08:00
|
|
|
const char *query = getenv("QUERY_STRING");
|
2017-07-06 02:10:09 +08:00
|
|
|
if ( query ) {
|
2018-06-01 23:27:53 +08:00
|
|
|
Debug(1, "Query: %s", query);
|
2019-07-26 22:53:48 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
char temp_query[1024];
|
2020-04-15 05:01:50 +08:00
|
|
|
strncpy(temp_query, query, sizeof(temp_query)-1);
|
2016-04-04 22:11:48 +08:00
|
|
|
char *q_ptr = temp_query;
|
2019-07-26 22:53:48 +08:00
|
|
|
char *parms[16]; // Shouldn't be more than this
|
2016-04-04 22:11:48 +08:00
|
|
|
int parm_no = 0;
|
2019-02-14 00:34:47 +08:00
|
|
|
while ( (parm_no < 16) && (parms[parm_no] = strtok(q_ptr, "&")) ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
parm_no++;
|
2020-08-26 07:45:48 +08:00
|
|
|
q_ptr = nullptr;
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2019-07-26 22:53:48 +08:00
|
|
|
|
2017-07-06 02:10:09 +08:00
|
|
|
for ( int p = 0; p < parm_no; p++ ) {
|
2018-06-01 23:27:53 +08:00
|
|
|
char *name = strtok(parms[p], "=");
|
2020-08-26 07:45:48 +08:00
|
|
|
char const *value = strtok(nullptr, "=");
|
2016-09-27 08:08:45 +08:00
|
|
|
if ( !value )
|
2020-03-05 00:02:21 +08:00
|
|
|
value = "";
|
2018-06-01 23:27:53 +08:00
|
|
|
if ( !strcmp(name, "source") ) {
|
|
|
|
source = !strcmp(value, "event")?ZMS_EVENT:ZMS_MONITOR;
|
2019-07-26 22:53:48 +08:00
|
|
|
if ( !strcmp(value, "fifo") )
|
2019-05-17 03:37:03 +08:00
|
|
|
source = ZMS_FIFO;
|
2018-06-01 23:27:53 +08:00
|
|
|
} else if ( !strcmp(name, "mode") ) {
|
|
|
|
mode = !strcmp(value, "jpeg")?ZMS_JPEG:ZMS_MPEG;
|
|
|
|
mode = !strcmp(value, "raw")?ZMS_RAW:mode;
|
|
|
|
mode = !strcmp(value, "zip")?ZMS_ZIP:mode;
|
|
|
|
mode = !strcmp(value, "single")?ZMS_SINGLE:mode;
|
2019-07-26 22:53:48 +08:00
|
|
|
} else if ( !strcmp(name, "format") ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
strncpy( format, value, sizeof(format) );
|
2019-07-26 22:53:48 +08:00
|
|
|
} else if ( !strcmp(name, "monitor") ) {
|
|
|
|
monitor_id = atoi(value);
|
2017-08-24 22:13:46 +08:00
|
|
|
if ( source == ZMS_UNKNOWN )
|
|
|
|
source = ZMS_MONITOR;
|
2019-07-26 22:53:48 +08:00
|
|
|
} else if ( !strcmp(name, "time") ) {
|
|
|
|
event_time = atoi(value);
|
|
|
|
} else if ( !strcmp(name, "event") ) {
|
2020-08-26 07:45:48 +08:00
|
|
|
event_id = strtoull(value, nullptr, 10);
|
2017-08-24 03:05:44 +08:00
|
|
|
source = ZMS_EVENT;
|
2019-07-26 22:53:48 +08:00
|
|
|
} else if ( !strcmp(name, "frame") ) {
|
2020-08-26 07:45:48 +08:00
|
|
|
frame_id = strtoull(value, nullptr, 10);
|
2017-08-24 03:05:44 +08:00
|
|
|
source = ZMS_EVENT;
|
2019-07-26 22:53:48 +08:00
|
|
|
} else if ( !strcmp(name, "scale") ) {
|
|
|
|
scale = atoi(value);
|
|
|
|
} else if ( !strcmp(name, "rate") ) {
|
|
|
|
rate = atoi(value);
|
|
|
|
} else if ( !strcmp(name, "maxfps") ) {
|
|
|
|
maxfps = atof(value);
|
|
|
|
} else if ( !strcmp(name, "bitrate") ) {
|
|
|
|
bitrate = atoi(value);
|
|
|
|
} else if ( !strcmp(name, "ttl") ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
ttl = atoi(value);
|
2019-07-26 22:53:48 +08:00
|
|
|
} else if ( !strcmp(name, "replay") ) {
|
2018-09-29 00:31:53 +08:00
|
|
|
if ( !strcmp(value, "gapless") ) {
|
|
|
|
replay = EventStream::MODE_ALL_GAPLESS;
|
|
|
|
} else if ( !strcmp(value, "all") ) {
|
|
|
|
replay = EventStream::MODE_ALL;
|
|
|
|
} else if ( !strcmp(value, "none") ) {
|
|
|
|
replay = EventStream::MODE_NONE;
|
|
|
|
} else if ( !strcmp(value, "single") ) {
|
|
|
|
replay = EventStream::MODE_SINGLE;
|
|
|
|
} else {
|
|
|
|
Error("Unsupported value %s for replay, defaulting to none", value);
|
|
|
|
}
|
2019-07-26 22:53:48 +08:00
|
|
|
} else if ( !strcmp(name, "connkey") ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
connkey = atoi(value);
|
2019-07-26 22:53:48 +08:00
|
|
|
} else if ( !strcmp(name, "buffer") ) {
|
2016-04-04 22:11:48 +08:00
|
|
|
playback_buffer = atoi(value);
|
2019-07-26 22:53:48 +08:00
|
|
|
} else if ( !strcmp(name, "auth") ) {
|
2020-03-05 00:02:21 +08:00
|
|
|
strncpy(auth, value, sizeof(auth)-1);
|
2019-07-26 22:53:48 +08:00
|
|
|
} else if ( !strcmp(name, "token") ) {
|
2019-05-08 22:55:32 +08:00
|
|
|
jwt_token_str = value;
|
2019-07-20 01:55:35 +08:00
|
|
|
Debug(1, "ZMS: JWT token found: %s", jwt_token_str.c_str());
|
2019-07-26 22:53:48 +08:00
|
|
|
} else if ( !strcmp(name, "user") ) {
|
|
|
|
username = UriDecode(value);
|
|
|
|
} else if ( !strcmp(name, "pass") ) {
|
2019-03-05 02:35:36 +08:00
|
|
|
password = UriDecode(value);
|
|
|
|
Debug(1, "Have %s for password", password.c_str());
|
|
|
|
} else {
|
|
|
|
Debug(1, "Unknown parameter passed to zms %s=%s", name, value);
|
2019-07-26 22:53:48 +08:00
|
|
|
} // end if possible parameter names
|
|
|
|
} // end foreach parm
|
2019-02-14 00:34:47 +08:00
|
|
|
} else {
|
|
|
|
Fatal("No query string.");
|
2019-07-26 22:53:48 +08:00
|
|
|
} // end if query
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2017-11-22 12:55:53 +08:00
|
|
|
if ( monitor_id ) {
|
|
|
|
snprintf(log_id_string, sizeof(log_id_string), "zms_m%d", monitor_id);
|
|
|
|
} else {
|
2018-04-18 01:57:19 +08:00
|
|
|
snprintf(log_id_string, sizeof(log_id_string), "zms_e%" PRIu64, event_id);
|
2017-11-22 12:55:53 +08:00
|
|
|
}
|
2019-07-20 01:55:35 +08:00
|
|
|
logInit(log_id_string);
|
2017-11-22 12:55:53 +08:00
|
|
|
|
2017-07-06 02:10:09 +08:00
|
|
|
if ( config.opt_use_auth ) {
|
2020-08-26 07:45:48 +08:00
|
|
|
User *user = nullptr;
|
2005-10-20 23:42:41 +08:00
|
|
|
|
2019-07-20 01:55:35 +08:00
|
|
|
if ( jwt_token_str != "" ) {
|
2019-07-26 22:53:48 +08:00
|
|
|
// user = zmLoadTokenUser(jwt_token_str, config.auth_hash_ips);
|
2019-05-09 00:11:32 +08:00
|
|
|
user = zmLoadTokenUser(jwt_token_str, false);
|
2019-07-20 01:55:35 +08:00
|
|
|
} else if ( strcmp(config.auth_relay, "none") == 0 ) {
|
2019-02-13 23:40:43 +08:00
|
|
|
if ( checkUser(username.c_str()) ) {
|
2018-06-01 23:27:53 +08:00
|
|
|
user = zmLoadUser(username.c_str());
|
2019-02-13 23:40:43 +08:00
|
|
|
} else {
|
2019-05-08 22:55:32 +08:00
|
|
|
Error("Bad username");
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2017-07-06 02:10:09 +08:00
|
|
|
} else {
|
2020-04-27 06:19:30 +08:00
|
|
|
if ( *auth ) {
|
|
|
|
user = zmLoadAuthUser(auth, config.auth_hash_ips);
|
|
|
|
} else if ( username.length() && password.length() ) {
|
|
|
|
user = zmLoadUser(username.c_str(), password.c_str());
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
|
|
|
}
|
2017-07-06 02:10:09 +08:00
|
|
|
if ( !user ) {
|
2019-07-27 00:22:04 +08:00
|
|
|
fputs("HTTP/1.0 403 Forbidden\r\n\r\n", stdout);
|
2020-09-10 00:13:28 +08:00
|
|
|
|
|
|
|
const char *referer = getenv("HTTP_REFERER");
|
|
|
|
Error("Unable to authenticate user from %s", referer);
|
2016-04-04 22:11:48 +08:00
|
|
|
logTerm();
|
|
|
|
zmDbClose();
|
2019-07-27 00:22:04 +08:00
|
|
|
return 0;
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2019-07-20 01:55:35 +08:00
|
|
|
if ( !ValidateAccess(user, monitor_id) ) {
|
2020-04-27 06:19:30 +08:00
|
|
|
delete user;
|
2020-08-26 07:45:48 +08:00
|
|
|
user = nullptr;
|
2019-07-27 00:22:04 +08:00
|
|
|
fputs("HTTP/1.0 403 Forbidden\r\n\r\n", stdout);
|
2019-07-20 01:55:35 +08:00
|
|
|
logTerm();
|
|
|
|
zmDbClose();
|
2019-07-27 00:22:04 +08:00
|
|
|
return 0;
|
2019-07-20 01:55:35 +08:00
|
|
|
}
|
2020-04-27 06:19:30 +08:00
|
|
|
delete user;
|
2020-08-26 07:45:48 +08:00
|
|
|
user = nullptr;
|
2019-07-26 22:53:48 +08:00
|
|
|
} // end if config.opt_use_auth
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2017-11-22 12:55:53 +08:00
|
|
|
hwcaps_detect();
|
|
|
|
zmSetDefaultTermHandler();
|
|
|
|
zmSetDefaultDieHandler();
|
|
|
|
|
2020-08-26 07:45:48 +08:00
|
|
|
setbuf(stdout, nullptr);
|
2017-07-06 02:10:09 +08:00
|
|
|
if ( nph ) {
|
2019-07-26 22:53:48 +08:00
|
|
|
fputs("HTTP/1.0 200 OK\r\n", stdout);
|
2016-04-04 22:11:48 +08:00
|
|
|
}
|
2019-07-26 22:53:48 +08:00
|
|
|
fprintf(stdout, "Server: ZoneMinder Video Server/%s\r\n", ZM_VERSION);
|
|
|
|
|
2020-08-26 07:45:48 +08:00
|
|
|
time_t now = time(nullptr);
|
2016-04-04 22:11:48 +08:00
|
|
|
char date_string[64];
|
2020-03-05 00:02:21 +08:00
|
|
|
strftime(date_string, sizeof(date_string)-1,
|
|
|
|
"%a, %d %b %Y %H:%M:%S GMT", gmtime(&now));
|
2004-03-04 23:05:54 +08:00
|
|
|
|
2020-03-05 00:02:21 +08:00
|
|
|
fputs("Last-Modified: ", stdout);
|
|
|
|
fputs(date_string, stdout);
|
2019-07-26 22:53:48 +08:00
|
|
|
fputs(
|
2020-03-05 00:02:21 +08:00
|
|
|
"\r\nExpires: Mon, 26 Jul 1997 05:00:00 GMT\r\n"
|
2019-07-26 22:53:48 +08:00
|
|
|
"Cache-Control: no-store, no-cache, must-revalidate\r\n"
|
|
|
|
"Cache-Control: post-check=0, pre-check=0\r\n"
|
|
|
|
"Pragma: no-cache\r\n",
|
|
|
|
stdout);
|
2004-03-04 23:05:54 +08:00
|
|
|
|
2017-07-06 02:10:09 +08:00
|
|
|
if ( source == ZMS_MONITOR ) {
|
2016-09-27 08:08:45 +08:00
|
|
|
MonitorStream stream;
|
2019-07-26 22:53:48 +08:00
|
|
|
stream.setStreamScale(scale);
|
|
|
|
stream.setStreamReplayRate(rate);
|
|
|
|
stream.setStreamMaxFPS(maxfps);
|
|
|
|
stream.setStreamTTL(ttl);
|
|
|
|
stream.setStreamQueue(connkey);
|
|
|
|
stream.setStreamBuffer(playback_buffer);
|
2020-09-03 04:37:11 +08:00
|
|
|
stream.setStreamStart(monitor_id);
|
2002-09-16 17:19:24 +08:00
|
|
|
|
2016-09-27 08:08:45 +08:00
|
|
|
if ( mode == ZMS_JPEG ) {
|
2019-07-26 22:53:48 +08:00
|
|
|
stream.setStreamType(MonitorStream::STREAM_JPEG);
|
2016-09-27 08:08:45 +08:00
|
|
|
} else if ( mode == ZMS_RAW ) {
|
2019-07-26 22:53:48 +08:00
|
|
|
stream.setStreamType(MonitorStream::STREAM_RAW);
|
2017-07-06 02:10:09 +08:00
|
|
|
} else if ( mode == ZMS_ZIP ) {
|
2019-07-26 22:53:48 +08:00
|
|
|
stream.setStreamType(MonitorStream::STREAM_ZIP);
|
2017-07-06 02:10:09 +08:00
|
|
|
} else if ( mode == ZMS_SINGLE ) {
|
2019-07-26 22:53:48 +08:00
|
|
|
stream.setStreamType(MonitorStream::STREAM_SINGLE);
|
2016-09-27 08:08:45 +08:00
|
|
|
} else {
|
2004-03-04 23:05:54 +08:00
|
|
|
#if HAVE_LIBAVCODEC
|
2019-07-26 22:53:48 +08:00
|
|
|
stream.setStreamFormat(format);
|
|
|
|
stream.setStreamBitrate(bitrate);
|
|
|
|
stream.setStreamType(MonitorStream::STREAM_MPEG);
|
|
|
|
#else // HAVE_LIBAVCODEC
|
|
|
|
Error("MPEG streaming of '%s' attempted while disabled", query);
|
2020-03-05 00:02:21 +08:00
|
|
|
fprintf(stderr, "MPEG streaming is disabled.\n"
|
|
|
|
"You should configure with the --with-ffmpeg"
|
|
|
|
" option and rebuild to use this functionality.\n");
|
2016-09-27 08:08:45 +08:00
|
|
|
logTerm();
|
|
|
|
zmDbClose();
|
2019-07-26 22:53:48 +08:00
|
|
|
return -1;
|
|
|
|
#endif // HAVE_LIBAVCODEC
|
2016-09-27 08:08:45 +08:00
|
|
|
}
|
|
|
|
stream.runStream();
|
2019-07-26 22:53:48 +08:00
|
|
|
} else if ( source == ZMS_FIFO ) {
|
2019-05-17 03:37:03 +08:00
|
|
|
FifoStream stream;
|
2019-07-26 22:53:48 +08:00
|
|
|
stream.setStreamMaxFPS(maxfps);
|
|
|
|
stream.setStreamStart(monitor_id, format);
|
2019-05-17 03:37:03 +08:00
|
|
|
stream.runStream();
|
2016-09-27 08:08:45 +08:00
|
|
|
} else if ( source == ZMS_EVENT ) {
|
2019-07-26 22:53:48 +08:00
|
|
|
if ( !event_id ) {
|
|
|
|
Fatal("Can't view an event without specifying an event_id.");
|
2016-09-27 08:08:45 +08:00
|
|
|
}
|
|
|
|
EventStream stream;
|
2019-07-26 22:53:48 +08:00
|
|
|
stream.setStreamScale(scale);
|
|
|
|
stream.setStreamReplayRate(rate);
|
|
|
|
stream.setStreamMaxFPS(maxfps);
|
|
|
|
stream.setStreamMode(replay);
|
|
|
|
stream.setStreamQueue(connkey);
|
2016-09-27 08:08:45 +08:00
|
|
|
if ( monitor_id && event_time ) {
|
2018-03-03 10:27:03 +08:00
|
|
|
stream.setStreamStart(monitor_id, event_time);
|
2016-09-27 08:08:45 +08:00
|
|
|
} else {
|
2017-08-24 03:05:44 +08:00
|
|
|
Debug(3, "Setting stream start to frame (%d)", frame_id);
|
2018-03-03 10:27:03 +08:00
|
|
|
stream.setStreamStart(event_id, frame_id);
|
2016-09-27 08:08:45 +08:00
|
|
|
}
|
|
|
|
if ( mode == ZMS_JPEG ) {
|
2019-07-26 22:53:48 +08:00
|
|
|
stream.setStreamType(EventStream::STREAM_JPEG);
|
2016-09-27 08:08:45 +08:00
|
|
|
} else {
|
2007-08-30 02:11:09 +08:00
|
|
|
#if HAVE_LIBAVCODEC
|
2019-07-26 22:53:48 +08:00
|
|
|
stream.setStreamFormat(format);
|
|
|
|
stream.setStreamBitrate(bitrate);
|
|
|
|
stream.setStreamType(EventStream::STREAM_MPEG);
|
|
|
|
#else // HAVE_LIBAVCODEC
|
|
|
|
Error("MPEG streaming of '%s' attempted while disabled", query);
|
|
|
|
fprintf(stderr, "MPEG streaming is disabled.\n"
|
|
|
|
"You should ensure the ffmpeg libraries are installed and detected"
|
|
|
|
" and rebuild to use this functionality.\n");
|
2016-09-27 08:08:45 +08:00
|
|
|
logTerm();
|
|
|
|
zmDbClose();
|
2019-07-26 22:53:48 +08:00
|
|
|
return -1;
|
|
|
|
#endif // HAVE_LIBAVCODEC
|
|
|
|
} // end if jpeg or mpeg
|
2016-09-27 08:08:45 +08:00
|
|
|
stream.runStream();
|
2017-08-24 03:05:44 +08:00
|
|
|
} else {
|
|
|
|
Error("Neither a monitor or event was specified.");
|
2019-07-26 22:53:48 +08:00
|
|
|
} // end if monitor or event
|
2014-11-15 05:17:44 +08:00
|
|
|
|
2016-09-27 08:08:45 +08:00
|
|
|
logTerm();
|
|
|
|
zmDbClose();
|
2014-11-15 05:17:44 +08:00
|
|
|
|
2020-04-27 06:19:30 +08:00
|
|
|
return 0;
|
2002-09-16 17:19:24 +08:00
|
|
|
}
|