Browse Source

MJPEG Support Stage 1

master
Evgeny Gagua 3 years ago
parent
commit
fdbcdcee8c
  1. 1
      .gitignore
  2. BIN
      lib/controller/data/mysqlitedb.db
  3. 80
      lib/controller/getLocationItems.php
  4. 81
      lib/controller/getLocationNodeProps.php
  5. 20
      lib/controller/getLocationNodes.php
  6. 103
      lib/controller/updateLocation.php
  7. 142
      lib/javascript/clipchamp/jquery.clipchamp.mjpeg.player.js
  8. 142
      lib/javascript/clipchamp/player.js
  9. 28
      lib/javascript/jsapi_dynamic/mojo_reports.js
  10. 3
      lib/php/ui/UI_functions.php

1
.gitignore

@ -1,2 +1,3 @@
error.log
lib/controller/data/*

BIN
lib/controller/data/mysqlitedb.db

Binary file not shown.

80
lib/controller/getLocationItems.php

@ -0,0 +1,80 @@
<?php
require_once('../ajax_asm.php');
require_once('../php/utm/gPoint.php');
if( $CUser->Data['id'] > 1 ){
$GID = intval($_POST['SITE']);
$QS = "SELECT * FROM `system_props` LIMIT 1";
$R = $DATABASE->Query( $QS, false );
$SLAT = $R[0]['anchor_lat'];
$SLON = $R[0]['anchor_lon'];
$SALT = $R[0]['anchor_alt'];
$A = new gPoint();
$A->setLongLat( $SLON, $SLAT );
$A->convertLLtoTM();
$XC = $A->E();
$YC = $A->N();
$ZC = $A->Z();
$QS = "SELECT * FROM nodes";
$Result = $DATABASE->Query( $QS, false );
foreach( $Result as $CD ){
$cnode['id'] = intval($CD['id']);
$cnode['type'] = intval($CD['type']);
$index++;
$PUPA = false;
$CC = new gPoint();
switch( $CD['type'] ){
case ARGUS_ALS_SENSOR:
case ARGUS_LFS_SENSOR:
case ARGUS_PLS_200_SENSOR:
case ARGUS_PLS_360_SENSOR:
case ARGUS_3D_SENSOR:
case ARGUS_NET_PLS_200:
$QS="SELECT x, y FROM lrf_sensors WHERE id={$CD['aux_id']}";
$RV = $DATABASE->Query( $QS );
$CC->setUTM( $XC + floatval($RV[0]['x']), $YC+floatval($RV[0]['y']), $ZC );
$CC->convertTMtoLL();
$cnode['lat'] = $CC->Lat();
$cnode['lon'] = $CC->Long();
//if( floatval($RV[0]['x']) == 0 && floatval($RV[0]['y']) == 0 ){
// $cnode['lat'] = $SLAT;
// $cnode['lon'] = $SLON;
//} else {
// $CC->setUTM( floatval($RV[0]['x']), floatval($RV[0]['y']), $ZC );
// $CC->convertTMtoLL();
// $cnode['lat']= $CC->Lat();
// $cnode['lon']= $CC->Long();
//};
$PUPA = true;
break;
case ARGUS_ANALOG_STATIC_CAMERA:
case ARGUS_ANALOG_PTZ_CAMERA:
case ARGUS_IP_STATIC_CAMERA:
case ARGUS_IP_PTZ_CAMERA:
$QS="SELECT x, y FROM cameras WHERE id={$CD['aux_id']}";
$RV = $DATABASE->Query( $QS );
$CC->setUTM( $XC + floatval($RV[0]['x']), $YC+floatval($RV[0]['y']), $ZC );
$CC->convertTMtoLL();
$cnode['lat'] = $CC->Lat();
$cnode['lon'] = $CC->Long();
//if( floatval($RV[0]['x']) == 0 && floatval($RV[0]['y']) == 0 ){
// $cnode['lat'] = $SLAT;
// $cnode['lon'] = $SLON;
//} else {
// $CC->setUTM( floatval($RV[0]['x']), floatval($RV[0]['y']), $ZC );
// $CC->convertTMtoLL();
// $cnode['lat']= $CC->Lat();
// $cnode['lon']= $CC->Long();
//};
$PUPA = true;
break;
};
if( $PUPA ) $Data[] = $cnode;
};
echo json_encode( $Data );
} else {
echo "[]";
};
?>

81
lib/controller/getLocationNodeProps.php

@ -0,0 +1,81 @@
<?php
require_once('../ajax_asm.php');
require_once('../php/utm/gPoint.php');
if( $CUser->Data['id'] > 1 ){
$Node = intval( $_POST['NODE'] );
$QS = "SELECT * FROM `nodes` WHERE id = {$Node}";
$Result = $DATABASE->Query( $QS, false );
if( count( $Result ) ){
$Props = $Result[0];
$Type = intval( $Props['type'] );
$TName = 'props/loc_prop.js';
$QS = "SELECT * FROM `system_props`";
$R = $DATABASE->Query($QS);
$SLAT = $R[0]['anchor_lat'];
$SLON = $R[0]['anchor_lon'];
$SALT = $R[0]['anchor_alt'];
$A = new gPoint();
$A->setLongLat( $SLON, $SLAT );
$A->convertLLtoTM();
$XC = $A->E();
$YC = $A->N();
$Zo = floatval( $SALT );
$ZC = $A->Z();
$Data = file_get_contents( $TName );
$Data = str_replace('%%%NODEID%%%', ''.$Node, $Data );
$Data = str_replace('%%%TYPE%%%', $Type, $Data );
$Data = str_replace('%%%NAME%%%', $Props['name'] , $Data );
switch( $Type ){
case 1:
case 2:
case 3:
case 4:
case ARGUS_3D_SENSOR:
case 6:{
$QS = "SELECT * FROM lrf_sensors WHERE id={$Props['aux_id']}";
$RR = $DATABASE->Query( $QS );
$C = $RR[0];
break;
};
case 10:
case 11:
case 12:
case 13:{
$QS="SELECT * FROM cameras WHERE id={$Props['aux_id']}";
$RR = $DATABASE->Query( $QS );
$C = $RR[0];
break;
};
default: $Data = '{}';
};
$DX = floatval( $C['x'] );
$DY = floatval( $C['y'] );
$DZ = floatval( $C['z'] );
$CC = new gPoint();
$CC->setUTM( $XC + $DX, $YC + $DY, $ZC );
$CC->convertTMtoLL();
$LAT = $CC->Lat();
$LON = $CC->Long();
$ALT = $Zo + $DZ;
$ROLL = floatval( $C['x_rot'] );
$PITCH = floatval( $C['y_rot'] );
$YAW = floatval( $C['z_rot'] );
$Data = str_replace( '%%%LAT%%%', $LAT, $Data );
$Data = str_replace( '%%%LON%%%', $LON, $Data );
$Data = str_replace( '%%%ALT%%%', $ALT, $Data );
$Data = str_replace( '%%%ROLL%%%', $ROLL, $Data );
$Data = str_replace( '%%%PITCH%%%', $PITCH, $Data );
$Data = str_replace( '%%%YAW%%%', $YAW, $Data );
$Data = str_replace( '%%%DX%%%', $DX, $Data );
$Data = str_replace( '%%%DY%%%', $DY, $Data );
$Data = str_replace( '%%%DZ%%%', $DZ, $Data );
echo $Data;
} else {
echo '{ html: \'Node '.$_POST['NODE'].' Loadded\'}';
};
} else {
header('location: /');
};
?>

20
lib/controller/getLocationNodes.php

@ -0,0 +1,20 @@
<?php
require_once('../ajax_asm.php');
if( $CUser->Data['id'] > 1 ){
$GID = intval($_POST['SITE']);
$QS = "SELECT * FROM nodes";
$Result = $DATABASE->Query( $QS, false );
$Data = "{ xtype: 'panel', frame: false, bodyStyle:'padding:5px 5px 0', items: [";
$DL = array();
foreach( $Result as $CD ){
$cid = intval($CD['id']);
$ct = intval($CD['type']);
if( in_array( $ct, array( 1, 2, 3, 5, 6, 10, 11, 12, 13 ) ) ){
$DL[] = "{ xtype: 'button', text: '{$CD['name']}', width: '100%', handler: function(){ locationSelectedNode={$cid}; loadNodeLocationProps({$cid}); } }";
};
};
echo $Data . implode(',',$DL) ."] }";
} else {
echo "{}";
};
?>

103
lib/controller/updateLocation.php

@ -0,0 +1,103 @@
<?php
require_once('../ajax_asm.php');
require_once('../php/utm/gPoint.php');
if( $CUser->Data['id'] > 1 ){
$SITE = 0; $NID = 0;
//if( isset( $_POST['SITE'] ) ) $SITE = intval($_POST['SITE']);
$TYP = intval($_POST['TYPE']);
if( isset( $_POST['NODE'] ) ) $NID = intval($_POST['NODE']);
$LAT = floatval( $_POST['LAT'] );
$LON = floatval( $_POST['LON'] );
if( $TYP > 0 ){
$ALT = floatval( $_POST['ALT'] );
if( $TYP == 2 ){
$PITCH = floatval( $_POST['PITCH'] );
$ROLL = floatval( $_POST['ROLL'] );
$YAW = floatval( $_POST['YAW'] );
};
};
if( $TYP != 1 ){
$QS="SELECT `anchor_lat`, `anchor_lon`, `anchor_alt`, `local_binding` FROM `system_props` LIMIT 1";
$R = $DATABASE->Query( $QS );
$SLAT = $R[0]['anchor_lat'];
$SLON = $R[0]['anchor_lon'];
$SALT = $R[0]['anchor_alt'];
$DIFF =intval( $R[0]['local_binding'] );
$A = new gPoint();
$A->setLongLat( $SLON, $SLAT );
$A->convertLLtoTM();
$XC = $A->E();
$YC = $A->N();
$ZC = $A->Z();
$QS = "SELECT * FROM nodes WHERE id ={$NID}";
$Result = $DATABASE->Query( $QS, false );
$CD = $Result[0];
switch( $CD['type'] ){
case ARGUS_ALS_SENSOR:
case ARGUS_LFS_SENSOR:
case ARGUS_PLS_200_SENSOR:
case ARGUS_PLS_360_SENSOR:
case ARGUS_3D_SENSOR:
case ARGUS_NET_PLS_200:
$TBL = 'lrf_sensors';
break;
case ARGUS_ANALOG_STATIC_CAMERA:
case ARGUS_ANALOG_PTZ_CAMERA:
case ARGUS_IP_STATIC_CAMERA:
case ARGUS_IP_PTZ_CAMERA:
$TBL = 'cameras';
break;
};
};
switch( $TYP ){
case 0://Short update
$CC = new gPoint();
$CC->setLongLat( $LON, $LAT );
$CC->convertLLtoTM();
$XX = $CC->E();
$YY = $CC->N();
$ZZ = $CC->Z();
if( $DIFF ){
$DX = $XX - $XC;
$DY = $YY - $YC;
$DZ = $ZZ - $ZC;
} else {
$DX = $XX;
$DY = $YY;
$DZ = $ZZ;
};
$QS="UPDATE `{$TBL}` SET `x`={$DX}, `y`={$DY}, `z`={$DZ} WHERE `id`={$CD['aux_id']}";
break;
case 1://Anchore update
$QS="UPDATE `system_props` SET `anchor_lat`={$LAT}, `anchor_lon`={$LON}, `anchor_alt`={$ALT} ";
break;
case 2://long update
$CC = new gPoint();
$CC->setLongLat( $LON, $LAT );
$CC->convertLLtoTM();
$XX = $CC->E();
$YY = $CC->N();
$ZZ = $CC->Z();
if( $DIFF ){
$DX = $XX - $XC;
$DY = $YY - $YC;
$DZ = $ZZ - $ZC;
} else {
$DX = $XX;
$DY = $YY;
$DZ = $ZZ;
};
$QS="UPDATE `{$TBL}` SET `x`={$DX}, `y`={$DY}, `z`={$DZ}, `x_rot`={$ROLL}, `y_rot`={$PITCH}, `z_rot`={$YAW} WHERE `id`={$CD['aux_id']}";
break;
case 3://update by cords -> no convert
$QS="UPDATE `{$TBL}` SET `x`={$LAT}, `y`={$LON}, `z`={$ALT} WHERE `id`={$CD['aux_id']}";
break;
};
$DATABASE->Query( $QS );
echo "{ nid: {$NID}, QS:'{$QS}' }";
} else {
echo "[]";
};
?>

142
lib/javascript/clipchamp/jquery.clipchamp.mjpeg.player.js

@ -0,0 +1,142 @@
/*!
* jQuery Clipchamp MJPEG Player Plugin v0.0.1
* https://github.com/clipchamp/jquery-clipchamp-mjpeg-player-plugin
*
* Plays back MJPEG files produced by the clipchamp
* online video converter, online video compressor, and
* webcam recorder.
*
* Copyright 2015 zfaas Pty Ltd (clipchamp.com)
* https://clipchamp.com
* https://zfaas.com
*
* Released under the MIT license
*/
(function($) {
var DEFAULT_FPS = 24,
DEFAULT_AUTOLOOP = true,
JPEG_MAGIG_NUMBER = [0xff, 0xd8, 0xff];
var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || window.setTimeout;
function splitMJPEG(mjpegUrl, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', mjpegUrl, true);
xhr.overrideMimeType('application/octet-stream');
xhr.responseType = 'arraybuffer';
xhr.onload = function(event) {
var array = new Uint8Array(xhr.response),
startIndex,
jpegs = [];
for (var i=0, ii=array.length; i<ii; ++i) {
if (array[i] === JPEG_MAGIG_NUMBER[0] && array[i+1] === JPEG_MAGIG_NUMBER[1] && array[i+2] === JPEG_MAGIG_NUMBER[2]) {
if (i>0 && typeof startIndex === 'number') {
jpegs.push(new Blob([array.subarray(startIndex, i)], {type: 'image/jpeg'}));
}
startIndex = i;
}
}
callback(jpegs);
};
xhr.send();
};
function playMJPEGInternal(wrapperElement, mjpegUrl, fps, autoloop) {
fps = (typeof fps === 'number') ? fps : DEFAULT_FPS;
autoloop = (typeof autoloop === 'boolean') ? autoloop : DEFAULT_AUTOLOOP;
var playbackFinished = false,
imageElement = document.createElement('img'),
jpegUrl;
imageElement.setAttribute('style', 'width:100%;');
wrapperElement.appendChild(imageElement);
splitMJPEG(mjpegUrl, function(jpegFiles) {
if (jpegFiles.length > 0) {
var nextFrameIndex = 0;
function showNextFrame() {
if (imageElement) {
if (jpegUrl) {
URL.revokeObjectURL(jpegUrl);
}
jpegUrl = URL.createObjectURL(jpegFiles[nextFrameIndex++]);
imageElement.onload = function() {
if (imageElement) {
if (autoloop || nextFrameIndex < jpegFiles.length) {
nextFrameIndex = (nextFrameIndex === jpegFiles.length) ? 0 : nextFrameIndex;
setTimeout(function() {
requestAnimationFrame(showNextFrame);
}, 1000/fps);
}
}
};
imageElement.setAttribute('src', jpegUrl);
}
};
setTimeout(function() {
requestAnimationFrame(showNextFrame);
}, 1000/fps);
}
});
return {
finish: function() {
if (imageElement) {
imageElement.src = '';
wrapperElement.removeChild(imageElement);
imageElement = undefined;
}
}
};
};
// optionally make available as jQuery plugin
if (typeof $ === 'function') {
$.fn.clipchamp_mjpeg_player = function(mjpegUrl, fps, autoloop, callback) {
if (typeof mjpegUrl === 'string') {
if (typeof callback === 'function') {
return this.each(function() {
callback($(this)[0], playMJPEGInternal($(this)[0], mjpegUrl, fps, autoloop));
});
} else {
throw new Error('Callback must be given and must be a function');
}
} else {
throw new Error('MJPEG URL must be a string');
}
}
}
// optionally provide AMD module definition
if (typeof define === 'function') {
define('jquery.clipchamp.mjpeg.player', [], function() {
return {
playMJPEG: function(wrapperElement, mjpegUrl, fps, autoloop) {
if (wrapperElement instanceof Element) {
if (typeof mjpegUrl === 'string') {
return playMJPEGInternal(wrapperElement, mjpegUrl, fps, autoloop);
} else {
throw new Error('MJPEG URL must be a string');
}
} else {
throw new Error('No parent element was given');
}
}
};
});
}
} )
(typeof jQuery === 'function' ? jQuery : undefined);

142
lib/javascript/clipchamp/player.js

@ -0,0 +1,142 @@
/*!
* jQuery Clipchamp MJPEG Player Plugin v0.0.1
* https://github.com/clipchamp/jquery-clipchamp-mjpeg-player-plugin
*
* Plays back MJPEG files produced by the clipchamp
* online video converter, online video compressor, and
* webcam recorder.
*
* Copyright 2015 zfaas Pty Ltd (clipchamp.com)
* https://clipchamp.com
* https://zfaas.com
*
* Released under the MIT license
*/
(function($) {
var DEFAULT_FPS = 24,
DEFAULT_AUTOLOOP = true,
JPEG_MAGIG_NUMBER = [0xff, 0xd8, 0xff];
var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || window.setTimeout;
function splitMJPEG(mjpegUrl, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', mjpegUrl, true);
xhr.overrideMimeType('application/octet-stream');
xhr.responseType = 'arraybuffer';
xhr.onload = function(event) {
var array = new Uint8Array(xhr.response),
startIndex,
jpegs = [];
for (var i=0, ii=array.length; i<ii; ++i) {
if (array[i] === JPEG_MAGIG_NUMBER[0] && array[i+1] === JPEG_MAGIG_NUMBER[1] && array[i+2] === JPEG_MAGIG_NUMBER[2]) {
if (i>0 && typeof startIndex === 'number') {
jpegs.push(new Blob([array.subarray(startIndex, i)], {type: 'image/jpeg'}));
}
startIndex = i;
}
}
callback(jpegs);
};
xhr.send();
};
function playMJPEGInternal(wrapperElement, mjpegUrl, fps, autoloop) {
fps = (typeof fps === 'number') ? fps : DEFAULT_FPS;
autoloop = (typeof autoloop === 'boolean') ? autoloop : DEFAULT_AUTOLOOP;
var playbackFinished = false,
imageElement = document.createElement('img'),
jpegUrl;
imageElement.setAttribute('style', 'width:100%;');
wrapperElement.appendChild(imageElement);
splitMJPEG(mjpegUrl, function(jpegFiles) {
if (jpegFiles.length > 0) {
var nextFrameIndex = 0;
function showNextFrame() {
if (imageElement) {
if (jpegUrl) {
URL.revokeObjectURL(jpegUrl);
}
jpegUrl = URL.createObjectURL(jpegFiles[nextFrameIndex++]);
imageElement.onload = function() {
if (imageElement) {
if (autoloop || nextFrameIndex < jpegFiles.length) {
nextFrameIndex = (nextFrameIndex === jpegFiles.length) ? 0 : nextFrameIndex;
setTimeout(function() {
requestAnimationFrame(showNextFrame);
}, 1000/fps);
}
}
};
imageElement.setAttribute('src', jpegUrl);
}
};
setTimeout(function() {
requestAnimationFrame(showNextFrame);
}, 1000/fps);
}
});
return {
finish: function() {
if (imageElement) {
imageElement.src = '';
wrapperElement.removeChild(imageElement);
imageElement = undefined;
}
}
};
};
// optionally make available as jQuery plugin
if (typeof $ === 'function') {
$.fn.clipchamp_mjpeg_player = function(mjpegUrl, fps, autoloop, callback) {
if (typeof mjpegUrl === 'string') {
if (typeof callback === 'function') {
return this.each(function() {
callback($(this)[0], playMJPEGInternal($(this)[0], mjpegUrl, fps, autoloop));
});
} else {
throw new Error('Callback must be given and must be a function');
}
} else {
throw new Error('MJPEG URL must be a string');
}
}
}
// optionally provide AMD module definition
if (typeof define === 'function') {
define('jquery.clipchamp.mjpeg.player', [], function() {
return {
playMJPEG: function(wrapperElement, mjpegUrl, fps, autoloop) {
if (wrapperElement instanceof Element) {
if (typeof mjpegUrl === 'string') {
return playMJPEGInternal(wrapperElement, mjpegUrl, fps, autoloop);
} else {
throw new Error('MJPEG URL must be a string');
}
} else {
throw new Error('No parent element was given');
}
}
};
});
}
} )
(typeof jQuery === 'function' ? jQuery : undefined);

28
lib/javascript/jsapi_dynamic/mojo_reports.js

@ -635,16 +635,28 @@ function loadEventData( record ){
cEventETS = ( ddd.ts + ddd.ms/1000 ) - ( data.uts+data.uts_ms/1000 );
} else {
cEventETS = 0;
};
VideoPlayer = videojs( video_t );
var tVL = '/lib/controller/data/reports/'+data.base+'/'+data.md5+'.'+data.ext;
};
var tVL = '/lib/controller/data/reports/'+data.base+'/'+data.md5+'.'+data.ext;
if( tVL != VideoLinks[data.node_id] ){
VideoLinks[data.node_id] = tVL;
VideoPlayer.src({
type: 'video/mp4',
src: VideoLinks[data.node_id]
});
VideoPlayer.poster('/style/assets/no-signal.png');
alert( tVL );
switch( data.ext ){
case 'mp4':{
ctype = 'video/mp4';
VideoPlayer = videojs( video_t );
VideoPlayer.src({
type: ctype,
fps: data.fps,
src: VideoLinks[data.node_id]
});
VideoPlayer.poster('/style/assets/no-signal.png');
break;
};
case 'mjpeg':{
ctype = 'video/x-motion-jpeg';
break;
};
};
};
var CT = cEventTSS - ( data.uts+data.uts_ms/1000 );
VideoPlayer.currentTime( CT );

3
lib/php/ui/UI_functions.php

@ -223,7 +223,8 @@ function UI_PageHeaderExt($Static_Scoop = '', $Dynamic_Scoop = ''){
<script type="text/javascript" src="lib/javascript/videojs/videojs-offset.min.js"></script>
<script type="text/javascript" src="lib/javascript/videojs/videojs-ie8.min.js"></script>
<script type="text/javascript" src="lib/javascript/videojs/videojs-contrib-hls.js"></script>
<script type="text/javascript" src="lib/javascript/clipchamp/player.js"></script>
<script type="text/javascript" src="lib/javascript/extjs/adapter/jquery/ext-jquery-adapter.js"></script>
<!--script type="text/javascript" src="lib/javascript/extjs/adapter/ext/ext-base.js"></script-->
<script type="text/javascript" src="lib/javascript/extjs/ext-all.js"></script>

Loading…
Cancel
Save