XML Plugin: Added more XML Options along with H264 options. These will be disabled unless client ver >=1.2. Added ability to track client version in PHP

git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@3191 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
jaidhar 2010-11-12 04:26:31 +00:00
parent 3f1158c2a4
commit 78caa0adb0
8 changed files with 83 additions and 30 deletions

View File

@ -854,7 +854,8 @@ insert into Config set Id = 185, Name = 'ZM_DYN_LAST_CHECK', Value = '', Type =
insert into Config set Id = 186, Name = 'ZM_DYN_NEXT_REMINDER', Value = '', Type = 'string', DefaultValue = '', Hint = 'string', Pattern = '(?-xism:^(.+)$)', Format = ' $1 ', Prompt = 'When the earliest time to remind about versions will be', Help = '', Category = 'dynamic', Readonly = '1', Requires = '';
insert into Config set Id = 187, Name = 'ZM_DYN_DONATE_REMINDER_TIME', Value = '0', Type = 'integer', DefaultValue = '0', Hint = 'integer', Pattern = '(?-xism:^(\d+)$)', Format = ' $1 ', Prompt = 'When the earliest time to remind about donations will be', Help = '', Category = 'dynamic', Readonly = '1', Requires = '';
insert into Config set Id = 188, Name = 'ZM_DYN_SHOW_DONATE_REMINDER', Value = '1', Type = 'boolean', DefaultValue = 'yes', Hint = 'yes|no', Pattern = '(?i-xsm:^([yn]))', Format = ' ($1 =~ /^y/) ? \"yes\" : \"no\" ', Prompt = 'Remind about donations or not', Help = '', Category = 'dynamic', Readonly = '1', Requires = '';
insert into Config set Id = 189, Name = 'ZM_XML_H264_DEFAULT_BR', Value = '96k', Type = 'string', DefaultValue = '96k', Hint = 'string', Pattern = '(?-xism:^(.+)$)', Format = ' $1 ', Prompt = 'Default bit-rate to use with FFMPEG for H264 streaming', Help = 'When using the XML Plugin to stream H264 data, FFMPEG requires a bitrate to control the quality and bandwidth of the video. This should be specified in a format acceptable to FFMPEG. The default value is sufficient for most installations', Category = 'XML', Readonly = '0', Requires = '';
insert into Config set Id = 190, Name = 'ZM_XML_DEBUG', Value = '0', Type = 'boolean', DefaultValue = 'no', Hint = 'yes|no', Pattern = '(?i-xsm:^([yn]))', Format = ' ($1 =~ /^y/) ? \"yes\" : \"no\" ', Prompt = 'Switch additional debugging on for XML Plugin', Help = 'Enable or Disable extra debugging from the XML Plugin. Extra debugging information will be displayed in your Apache error log, or whichever location PHP errors are logged to', Category = 'XML', Readonly = '0', Requires = '';
insert into Config set Id = 191, Name = 'ZM_XML_EVENT_VCODEC', Value = 'mpeg4', Type = 'string', DefaultValue = 'mpeg4', Hint = 'string', Pattern = '(?-xism:^(.+)$)', Format = ' $1 ', Prompt = 'Default video-codec to use for encoding events', Help = 'The XML Plug calls FFMPEG externally to encode the captured images, and uses MPEG-4 has a default codec. If your FFMPEG is not built with support for MPEG-4, change this to MJPEG or something else FFMPEG supports.', Category = 'XML', Readonly = '0', Requires = '';
insert into Config set Id = 189, Name = 'ZM_XML_DEBUG', Value = '0', Type = 'boolean', DefaultValue = 'no', Hint = 'yes|no', Pattern = '(?i-xsm:^([yn]))', Format = ' ($1 =~ /^y/) ? \"yes\" : \"no\" ', Prompt = 'Switch additional debugging on for XML Plugin', Help = 'Enable or Disable extra debugging from the XML Plugin. Extra debugging information will be displayed in your Apache error log, or whichever location PHP errors are logged to', Category = 'XML', Readonly = '0', Requires = '';
insert into Config set Id = 190, Name = 'ZM_XML_EVENT_VCODEC', Value = 'mpeg4', Type = 'string', DefaultValue = 'mpeg4', Hint = 'mpeg4|h264|mjpeg', Pattern = '(?i-xsm:^([mh][pj2]))', Format = ' ($1 =~ /^mp/) ? \"mpeg4\" : ($1 =~ /^h/ ? \"h264\" : \"mjpeg\" ) ', Prompt = 'Default video-codec to use for encoding events', Help = 'The XML Plugin calls FFMPEG externally to encode the captured images. If your FFMPEG is not built with support for MPEG-4 or H264, change this to MJPEG. If using H264, please check http://www.eyezm.com for H264 requirements.', Category = 'XML', Readonly = '0', Requires = '';
insert into Config set Id = 191, Name = 'ZM_XML_FEED_VCODEC', Value = 'mjpeg', Type = 'string', DefaultValue = 'mjpeg', Hint = 'mjpeg|h264', Pattern = '(?i-xsm:^([mh]))', Format = ' $1 =~ /^m/ ? \"mjpeg\" : \"h264\" ', Prompt = 'Default video-codec to use for streaming the live feed', Help = 'Determines whether the live stream is generated using native MJPEG streaming with ZoneMinder, or H264 using FFMPEG and HTML-5 streaming. If using H264, please check http://www.eyezm.com for H264 requirements.', Category = 'XML', Readonly = '0', Requires = '';
insert into Config set Id = 192, Name = 'ZM_XML_H264_DEFAULT_BR', Value = '96k', Type = 'string', DefaultValue = '96k', Hint = 'string', Pattern = '(?-xism:^(.+)$)', Format = ' $1 ', Prompt = 'Default bit-rate to use with FFMPEG for H264 streaming', Help = 'When using the XML Plugin to stream H264 data, FFMPEG requires a bitrate to control the quality and bandwidth of the video. This should be specified in a format acceptable to FFMPEG. The default value is sufficient for most installations', Category = 'XML', Readonly = '0', Requires = '';

View File

@ -1710,14 +1710,6 @@ body = "ZM alarm detected - %EL% secs, %EF%/%EFA% frames, t%EST%/m%ESM%/a%ESA% s
readonly => 1,
category => "dynamic",
},
{
name => "ZM_XML_H264_DEFAULT_BR",
default => "96k",
description => "Default bit-rate to use with FFMPEG for H264 streaming",
help => "When using the XML Plugin to stream H264 data, FFMPEG requires a bitrate to control the quality and bandwidth of the video. This should be specified in a format acceptable to FFMPEG. The default value is sufficient for most installations",
type => $types{string},
category => "XML",
},
{
name => "ZM_XML_DEBUG",
default => "no",
@ -1730,7 +1722,23 @@ body = "ZM alarm detected - %EL% secs, %EF%/%EFA% frames, t%EST%/m%ESM%/a%ESA% s
name => "ZM_XML_EVENT_VCODEC",
default => "mpeg4",
description => "Default video-codec to use for encoding events",
help => "The XML Plug calls FFMPEG externally to encode the captured images, and uses MPEG-4 has a default codec. If your FFMPEG is not built with support for MPEG-4, change this to MJPEG or something else FFMPEG supports.",
help => "The XML Plugin calls FFMPEG externally to encode the captured images. If your FFMPEG is not built with support for MPEG-4 or H264, change this to MJPEG. If using H264, please check http://www.eyezm.com for H264 requirements.",
type => { db_type=>"string", hint=>"mpeg4|h264|mjpeg", pattern=>qr|^([mh][pj2])|i, format=>q( ($1 =~ /^mp/) ? "mpeg4" : ($1 =~ /^h/ ? "h264" : "mjpeg" ) ) },
category => "XML",
},
{
name => "ZM_XML_FEED_VCODEC",
default => "mjpeg",
description => "Default video-codec to use for streaming the live feed",
help => "Determines whether the live stream is generated using native MJPEG streaming with ZoneMinder, or H264 using FFMPEG and HTML-5 streaming. If using H264, please check http://www.eyezm.com for H264 requirements.",
type => { db_type=>"string", hint=>"mjpeg|h264", pattern=>qr|^([mh])|i, format=>q( $1 =~ /^m/ ? "mjpeg" : "h264" ) },
category => "XML",
},
{
name => "ZM_XML_H264_DEFAULT_BR",
default => "96k",
description => "Default bit-rate to use with FFMPEG for H264 streaming",
help => "When using the XML Plugin to stream H264 data, FFMPEG requires a bitrate to control the quality and bandwidth of the video. This should be specified in a format acceptable to FFMPEG. The default value is sufficient for most installations",
type => $types{string},
category => "XML",
},

View File

@ -190,12 +190,13 @@
#define ZM_DYN_NEXT_REMINDER 186
#define ZM_DYN_DONATE_REMINDER_TIME 187
#define ZM_DYN_SHOW_DONATE_REMINDER 188
#define ZM_XML_H264_DEFAULT_BR 189
#define ZM_XML_DEBUG 190
#define ZM_XML_EVENT_VCODEC 191
#define ZM_XML_DEBUG 189
#define ZM_XML_EVENT_VCODEC 190
#define ZM_XML_FEED_VCODEC 191
#define ZM_XML_H264_DEFAULT_BR 192
#define ZM_MAX_CFG_ID 191
#define ZM_MAX_CFG_ID 192
#define ZM_CFG_DECLARE_LIST \
const char *lang_default;\
@ -387,9 +388,10 @@
const char *dyn_next_reminder;\
int dyn_donate_reminder_time;\
bool dyn_show_donate_reminder;\
const char *xml_h264_default_br;\
bool xml_debug;\
const char *xml_event_vcodec;\
const char *xml_feed_vcodec;\
const char *xml_h264_default_br;\
#define ZM_CFG_ASSIGN_LIST \
@ -582,8 +584,9 @@
dyn_next_reminder = (const char *)config.Item( ZM_DYN_NEXT_REMINDER );\
dyn_donate_reminder_time = (int)config.Item( ZM_DYN_DONATE_REMINDER_TIME );\
dyn_show_donate_reminder = (bool)config.Item( ZM_DYN_SHOW_DONATE_REMINDER );\
xml_h264_default_br = (const char *)config.Item( ZM_XML_H264_DEFAULT_BR );\
xml_debug = (bool)config.Item( ZM_XML_DEBUG );\
xml_event_vcodec = (const char *)config.Item( ZM_XML_EVENT_VCODEC );\
xml_feed_vcodec = (const char *)config.Item( ZM_XML_FEED_VCODEC );\
xml_h264_default_br = (const char *)config.Item( ZM_XML_H264_DEFAULT_BR );\

View File

@ -25,6 +25,7 @@ define ( "ZM_XML_FEATURE_SET", "1");
/* Dynamic defines, check if they are already defined */
if (!defined("ZM_XML_EVENT_FPS")) define ( "ZM_XML_EVENT_FPS", "10");
if (!defined("ZM_XML_EVENT_VCODEC")) define ( "ZM_XML_EVENT_VCODEC", "mpeg4");
if (!defined("ZM_XML_FEED_VCODEC")) define ( "ZM_XML_FEED_VCODEC", "mjpeg");
if (!defined("ZM_XML_SEG_DURATION")) define ( "ZM_XML_SEG_DURATION", "3");
if (!defined("ZM_XML_DEBUG")) define ( "ZM_XML_DEBUG", "0" );
if (!defined("ZM_XML_H264_MAX_DURATION")) define ( "ZM_XML_H264_MAX_DURATION", "120" );

View File

@ -11,13 +11,42 @@
/* There appears to be some discrepancy btw. 1.24.1/2 and .3 for EventPaths, to escape them here */
function getEventPathSafe($event)
{
if (strcmp(ZM_VERSION, "1.24.3") == 0) {
$ret = ZM_DIR_EVENTS."/".getEventPath($event);
} else {
if (!strcmp(ZM_VERSION, "1.24.1") || !strcmp(ZM_VERSION, "1.24.2")) {
$ret = getEventPath($event);
} else {
$ret = ZM_DIR_EVENTS."/".getEventPath($event);
}
return $ret;
}
function updateClientVer()
{
$str = $_SERVER['HTTP_USER_AGENT'];
/* Check if it starts with eyeZm */
if (!strcmp(substr($str, 0, 5),"eyeZm")) {
/* Found eyeZm */
$ver = substr($str, 6);
$verarray = explode(".", $ver);
$_SESSION['vermaj']=$verarray[0];
$_SESSION['vermin']=$verarray[1];
$_SESSION['verbuild']=$verarray[2];
}
}
function getClientVerMaj()
{
if (isset($_SESSION['vermaj'])) return $_SESSION['vermaj'];
return "0";
}
function getClientVerMin()
{
if (isset($_SESSION['vermin'])) return $_SESSION['vermin'];
return "0";
}
function requireVer($maj, $min)
{
if (getClientVerMaj() > $maj) return 1;
if ((getClientVerMaj() == $maj) && (getClientVerMin() >= $min)) return 1;
return 0;
}
function logXml($str)
{
if (!defined("ZM_XML_DEBUG")) define ( "ZM_XML_DEBUG", "0" );

View File

@ -35,4 +35,6 @@ if ( !isset($user) && ZM_OPT_USE_AUTH )
echo "Invalid Login";
exit;
}
/* Get version info from client */
updateClientVer();
?>

View File

@ -84,34 +84,37 @@ if (isset($_GET['action'])) {
exit;
} else if (strcmp($action, "feed") == 0) {
/* ACTION: View a feed. Parms: <monitor><img. width><img. height> [fps|scale|h264|br] */
/* ACTION: View a feed. Parms: <monitor>> [height|width|fps|scale|vcodec|br] */
if (!canView('Stream')) {
error_log("User ".$user['Username']. " doesn't have view Stream perms");
exit;
}
/* Check that required variables are set */
if (!isset($_REQUEST['monitor']) || !isset($_GET['width']) || !isset($_GET['height'])) {
if (!isset($_REQUEST['monitor'])) {
error_log("Not all parameters set for action view-feed");
exit;
}
$width = validInt($_GET['width']);
$height = validInt($_GET['height']);
$monitor = validInt($_REQUEST['monitor']);
if (isset($_GET['fps'])) $fps = $_GET['fps'];
else $fps = ZM_WEB_VIDEO_MAXFPS;
if (isset($_GET['scale'])) $scale = $_GET['scale'];
else $scale = 100;
$h264 = getset('h264', ZM_XML_H264_DEFAULT_ON);
if (($h264 == "1") && canStream264()) {
$fps = getset('fps', ZM_WEB_VIDEO_MAXFPS);
$scale = getset('scale', 100);
$vcodec = getset('vcodec', ZM_XML_FEED_VCODEC);
/* Only allow H264 as of v1.2 and greater */
if (!requireVer("1","2") && !strcmp($vcodec,"h264")) {
logXml("Version 1.2 required for H264 Streaming");
}
if (!strcmp($vcodec, "h264") && canStream264() && requireVer("1","2")) {
$br = getset('br', ZM_XML_H264_DEFAULT_BR);
/* H264 processing */
noCacheHeaders();
/* Kill any existing processes and files */
kill264proc($monitor);
eraseH264Files($monitor);
logXml("Streaming H264 on Monitor ".$monitor.", ".$width."x".$height." @".$br);
/* Generate H264 Web-page */
h264vidHtml($width, $height, $monitor, $br);
} else {
} else if (!strcmp($vcodec, "mjpeg")) {
/* MJPEG streaming */
$streamSrc =
getStreamSrc( array(
@ -123,10 +126,13 @@ if (isset($_GET['action'])) {
) );
noCacheHeaders();
xhtmlHeaders( __FILE__, "Stream" );
logXml("Streaming MJPEG on Monitor ".$monitor.", ".$width."x".$height." @".$fps."fps");
echo "<body>\n";
echo "<div style=\"border: 0px solid; padding: 0px; background-color: black; position: absolute; top: 0px; left; 0px; margin: 0px; width: ".$width."px; height: ".$height."px;\">\n";
outputImageStream("liveStream", $streamSrc, $width, $height, "stream");
echo "</div></body></html>";
} else {
error_log("Unsupported codec ".$vcodec." selected for streaming");
}
exit;
@ -149,6 +155,7 @@ if (isset($_GET['action'])) {
$relativeURL = getEventPath($event);
$baseURL = ZM_PATH_WEB."/".getEventPathSafe($event);
$shellCmd = "ffmpeg -y -r ".$fps." -i ".$baseURL."/%03d-capture.jpg -vcodec ".$vcodec." -r ".ZM_XML_EVENT_FPS." ".$baseURL."/capture.mov 2> /dev/null";
logXml("Encoding event with command: ".$shellCmd);
$shellOutput = shell_exec($shellCmd);
$url = "./".getEventPathSafe($event)."/capture.mov";
header("Location: ".$url);

View File

@ -156,6 +156,7 @@ xml_tag_val("VERSION", ZM_VERSION);
xml_tag_val("CANSTR264", canStream264());
xml_tag_val("USER", $user['Username']);
xml_tag_val("UID", $user['Id']);
/* Permissions block */
xml_tag_sec("PERMS", 1);
xml_tag_val("STREAM", $user['Stream']);
xml_tag_val("EVENTS", $user['Events']);
@ -164,6 +165,7 @@ xml_tag_val("MONITORS", $user['Monitors']);
xml_tag_val("DEVICES", $user['Devices']);
xml_tag_val("SYSTEM", $user['System']);
xml_tag_sec("PERMS", 0);
/* End permissions block */
if (canEdit('System')) {
if ($running) {
xml_tag_val("STATE", "stop");