Browse Source

Togo Version Semifinale

AGP
Evgeny Gagua 4 years ago
parent
commit
06c3f822c5
  1. 14
      Projects/argus/argus.vpj
  2. 4
      Projects/argus/build
  3. 90
      Projects/argus/makefile
  4. 4
      lib/alg/generic/Transform.cpp
  5. 7
      lib/components/base/basicFunctionality.cpp
  6. 3
      lib/components/base/basicFunctionality.h
  7. 2
      lib/components/base/basicLIBAV.h
  8. 2
      lib/components/base/basicMediaSource.h
  9. 4
      lib/components/base/basicPosition.h
  10. 93
      lib/components/object/objectSystemAnchor.cpp
  11. 32
      lib/data/curl/curlRequest.cpp
  12. 2
      lib/data/curl/curlRequest.h
  13. 102
      lib/data/media/video/videoAVLIBSource.cpp
  14. 12
      lib/data/media/video/videoAVLIBSource.h
  15. 597
      lib/data/media/video/videoLive555AVLibSource.cpp
  16. 180
      lib/data/media/video/videoLive555AVLibSource.h
  17. 132
      lib/data/ponvif/ponvif.cpp
  18. 6
      lib/data/ponvif/ponvif.h
  19. 286
      lib/data/protocol/protocolLGS2D.cpp
  20. 22
      lib/data/protocol/protocolLGS2D.h
  21. 6
      lib/data/protocol/protocolLGS_data.h
  22. 0
      lib/data/protocol/protocolPTZ_APIX.cpp
  23. 11
      lib/data/protocol/protocolPTZ_APIX.h
  24. 11
      lib/data/protocol/protocolPTZ_ONVIF.cpp
  25. 4
      lib/data/protocol/protocolPTZ_ONVIF.h
  26. 66
      lib/rgoose/rgooseCamera.cpp
  27. 7
      lib/rgoose/rgooseCamera.h
  28. 186
      lib/rgoose/rgooseDBConnector.cpp
  29. 4
      lib/rgoose/rgooseDBConnector.h
  30. 10
      lib/rgoose/rgooseHardwareManager.cpp
  31. 5
      lib/rgoose/rgooseHardwareResourceSerialProvider.cpp
  32. 4
      lib/rgoose/rgooseHardwareResourceSerialProvider.h
  33. 17
      lib/rgoose/rgooseKernel.cpp
  34. 1
      lib/rgoose/rgooseKernel.h
  35. 124
      lib/rgoose/rgooseModuleOnvifObserver.cpp
  36. 1161
      lib/rgoose/rgooseNode2D.cpp
  37. 85
      lib/rgoose/rgooseNode2D.h
  38. 20
      lib/rgoose/rgooseNodeSensor.cpp
  39. 5
      lib/rgoose/rgooseNodeSensor.h
  40. 29
      lib/rgoose/rgooseTypes.h

14
Projects/argus/argus.vpj

@ -26,7 +26,7 @@
RunFromDir="%rw">
<Exec
CmdLine='g++ -c %xup -x c++ %defd -O0 -g3 -ggdb %~other -o "%bd%n%oe" %i %f'
OtherOptions="-std=c++11 -Wno-write-strings -I../../lib/include `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags`"/>
OtherOptions="-std=c++11 -Wno-write-strings -I../../lib/include -I/usr/local/include/liveMedia `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags`"/>
</Target>
<Target
Name="Link"
@ -131,6 +131,10 @@
<Lib File="opencv4"/>
<Lib File="rdkafka++`"/>
<Lib File="-lwiringPi"/>
<Lib File="-lliveMedia"/>
<Lib File="-lgroupsock"/>
<Lib File="-lBasicUsageEnvironment"/>
<Lib File="-lUsageEnvironment"/>
</Libs>
</Config>
<Config
@ -153,7 +157,7 @@
RunFromDir="%rw">
<Exec
CmdLine='g++ -c %xup -x c++ %defd -O3 %~other -o "%bd%n%oe" %i %f'
OtherOptions="-std=c++11 -Wno-write-strings -I../../lib/include `pkg-config libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags`"/>
OtherOptions="-std=c++11 -Wno-write-strings -I../../lib/include -I/usr/local/include/liveMedia `pkg-config opencv4 libavcodec libavdevice libavfilter libavformat libavutil libpostproc libswresample libswscale --cflags`"/>
</Target>
<Target
Name="Link"
@ -259,6 +263,10 @@
<Lib File="opencv4"/>
<Lib File="rdkafka++`"/>
<Lib File="-lwiringPi"/>
<Lib File="-lliveMedia"/>
<Lib File="-lgroupsock"/>
<Lib File="-lBasicUsageEnvironment"/>
<Lib File="-lUsageEnvironment"/>
</Libs>
</Config>
<Files>
@ -362,6 +370,7 @@
<F N="../../lib/data/transport/transportSocket.cpp"/>
<F N="../../lib/alg/generic/utm.cpp"/>
<F N="../../lib/data/media/video/videoAVLIBSource.cpp"/>
<F N="../../lib/data/media/video/videoLive555AVLibSource.cpp"/>
<F N="../../lib/data/protocol/xmlParser.cpp"/>
</Folder>
<Folder
@ -445,6 +454,7 @@
<F N="../../lib/data/transport/transportSerial.h"/>
<F N="../../lib/data/transport/transportSocket.h"/>
<F N="../../lib/alg/generic/utm.h"/>
<F N="../../lib/data/media/video/videoLive555AVLibSource.h"/>
</Folder>
<Folder
Name="Resource Files"

4
Projects/argus/build

@ -1,9 +1,9 @@
#! /bin/sh
#make clean -e "CFG=Debug"
make clean -e "CFG=Debug"
#make -j4 -e "CFG=Debug"
#make clean -e "CFG=Release"
make clean -e "CFG=Release"
#make -j4 -e "CFG=Release"

90
Projects/argus/makefile
File diff suppressed because it is too large
View File

4
lib/alg/generic/Transform.cpp

@ -127,12 +127,12 @@ void spherical2onvif(C3D_SPH_DEGREES in, C3D_ORIENT_ONVIF &out, float maxR, uint
switch( panMode ){
case 1:{
out.pan = ( 2.0f / panAngles ) * in.fi - 1.0f;
out.pan = 1.0f - (( 2.0f / panAngles ) * in.fi );
break;
};
case 2:
default:{
out.pan = ( 2.0f / 360.0f ) * in.fi - 1.0f;
out.pan = ( 2.0f / panAngles ) * in.fi - 1.0f;
};
};

7
lib/components/base/basicFunctionality.cpp

@ -248,6 +248,13 @@ CSTR getUniqID_MD5( void ){
};
CSTR getUniqID_SHA256(void){ return NULL;};
int rand( int a, int b ){
if( b > a ){
return a + (rand() *( b - a )) / RAND_MAX;
};
return b + ( rand() * ( a - b )) / RAND_MAX;
};
CSTR getUniqID_UUID( uint32_t SEED ){
/*
char buf[46];

3
lib/components/base/basicFunctionality.h

@ -53,6 +53,9 @@ CArray * explode( char Delim, CSTR S_Str );
CSTR implode( CArray *Data, CSTR S_Str, U8 Start, U8 End );
CSTR getTStr( CSTR Fmt = NULL );
CSTR getUniqID_SHA256(void);
int rand( int a, int b );
CSTR getUniqID_MD5(void);
CSTR getUniqID_UUID( uint32_t SEED = 0);
CSTR strReplace( CSTR orig, CSTR rep, CSTR with );

2
lib/components/base/basicLIBAV.h

@ -20,8 +20,6 @@
#include "basicTypes.h"
#include "basicLogCollection.h"
#ifdef __linux__
#ifndef UINT64_C

2
lib/components/base/basicMediaSource.h

@ -26,6 +26,8 @@ class basicMediaSource {
};
bool isAttached( void ) { return ( m_pMediaDestination != NULL ); };
void setStreaming(bool T){ m_bStreamingSource = T; };
virtual bool _open( CSTR URI, bool ShowDeviceMenu = false, float framerate=-1.0f, int inputPin = -1, int width = -1, int height = -1 , int s_width=-1, int s_height=-1 ){ return false; };
virtual bool _close( void ){ return true; };
virtual bool _stop(void){ return true; };
MediaStateStatus getStatus( void ){ return m_eMediaStatus;};
};

4
lib/components/base/basicPosition.h

@ -68,8 +68,10 @@ class basicPosition: public position3D{
S_TRANS_MATRIX m_sMatrix;
transform_3 *m_pTransform;
int m_nZoneID;
void updateMatrix( void );
public:
void updateMatrix( void );
// Constructor
basicPosition();

93
lib/components/object/objectSystemAnchor.cpp

@ -202,11 +202,24 @@ bool systemAnchor::convertToLocal(basicPosition *SP, C3D_WGS84_LOC POS, C3D_SPH_
C3D_DECART tDec;
vector_3 A, B;
tDec.z = POS.alt;
#ifdef DEBUG
char tB[256];
sprintf(tB, "Global WGS: %.3f %.3f %.3f", POS.lat, POS.lon, POS.alt );
LOG( tB );
#endif
m_SCC.LatLonToUTMXY(POS.lat, POS.lon, getUTMZone(), tDec.x, tDec.y);
A[0] = tDec.x;// - SP->getX();
A[1] = tDec.y;// - SP->getY();
A[2] = tDec.z;// - SP->getZ();
#ifdef DEBUG
sprintf( tB, "Global Decart: %.3f %.3f %.3f", A[0], A[1], A[2] );
LOG( tB );
#endif
pTF->get_vector_local( A, B );
#ifdef DEBUG
sprintf( tB, "Local Decart: %.3f %.3f %.3f", B[0], B[1], B[2] );
LOG( tB );
#endif
tDec.x = B[0];
tDec.y = B[1];
tDec.z = B[2];
@ -219,23 +232,38 @@ bool systemAnchor::convertToLocal( basicPosition *SP, C3D_DECART POS, C3D_SPH_DE
transform_3* pTF = SP->getTransform();
C3D_DECART tDec;
vector_3 A, B;
#ifdef DEBUG
char tB[256];
sprintf(tB, "System Decart: %.3f %.3f %.3f", POS.x, POS.y, POS.z );
LOG( tB );
#endif
// POS - is Relative to System Anchore!!
if( m_bUseJustLocalDiffCoords ) {
A[0] = POS.x - getX(); // in general getX() = 0 as other coords of anchore
A[1] = POS.y - getY();
A[2] = POS.z - getZ();
A[0] = POS.x;// - getX(); // in general getX() = 0 as other coords of anchore
A[1] = POS.y;// - getY();
A[2] = POS.z;// - getZ();
} else {
A[0] = POS.x;
A[1] = POS.y;
A[2] = POS.z;
A[0] = POS.x + getX();
A[1] = POS.y + getY();
A[2] = POS.z + getZ();
};
#ifdef DEBUG
sprintf(tB, "Prepared Global Decart: %.3f %.3f %.3f", A[0], A[1], A[2] );
LOG( tB );
#endif
//A[0] = getX() + POS.x;
//A[1] = getY() + POS.y;
//A[2] = getZ() + POS.z;
pTF->get_vector_local( A, B );
tDec.x = B[0];
tDec.y = B[1];
tDec.z = B[2];
tDec.x = B[0] + getX() - SP->getX();
tDec.y = B[1] + getY() - SP->getY();
tDec.z = B[2] + getZ() - SP->getZ();
#ifdef DEBUG
sprintf(tB, "Local Decart: %.3f %.3f %.3f", B[0], B[1], B[2] );
LOG( tB );
sprintf(tB, "Local Decart: %.3f %.3f %.3f", tDec.x, tDec.y, tDec.z );
LOG( tB );
#endif
decart2spherical(tDec, LOC);
return true;
};
@ -277,27 +305,27 @@ bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_D
A[0] = tDec.x;
A[1] = tDec.y;
A[2] = tDec.z;
#ifdef DEBUG_EXTRA
#ifdef DEBUG
char tB[256];
sprintf( tB, "Local Decart: %.3f %.3f %.3f", A[0], A[1], A[2] );
LOG( tB );
#endif
pTF->get_vector_world( A, B );
#ifdef DEBUG_EXTRA
#ifdef DEBUG
sprintf( tB, "World Decart: %.3f %.3f %.3f", B[0], B[1], B[2] );
LOG( tB );
#endif
#ifdef DEBUG_EXTRA
#ifdef DEBUG
sprintf( tB, "Systen Decart: %.3f %.3f %.3f", getX(), getY(), getZ() );
LOG( tB );
#endif
//LOC.x = B[0] - getX();
LOC.x = B[0] + SP->getX() - getX();
//LOC.y = B[1] - getY();
LOC.y = B[1] + SP->getY() - getY();
//LOC.z = B[2] - getZ();
LOC.z = B[2] + SP->getZ() - getZ();
#ifdef DEBUG_EXTRA
LOC.x = B[0] - getX();
//LOC.x = B[0] + SP->getX() - getX();
LOC.y = B[1] - getY();
//LOC.y = B[1] + SP->getY() - getY();
LOC.z = B[2] - getZ();
//LOC.z = B[2] + SP->getZ() - getZ();
#ifdef DEBUG
sprintf( tB, "Final System Decart: %.3f %.3f %.3f", LOC.x, LOC.y, LOC.z );
LOG( tB );
#endif
@ -314,9 +342,12 @@ bool systemAnchor::convertToSystem(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_D
A[1] = tDec.y;
A[2] = tDec.z;
pTF->get_vector_world(A, B);
LOC.x = B[0] + SP->getX() - getX();
LOC.y = B[1] + SP->getY() - getY();
LOC.z = B[2] + SP->getZ() - getZ();
//LOC.x = B[0] + SP->getX() - getX();
LOC.x = B[0] - getX();
//LOC.y = B[1] + SP->getY() - getY();
LOC.y = B[1] - getY();
//LOC.z = B[2] + SP->getZ() - getZ();
LOC.z = B[2] - getZ();
return true;
};
@ -330,9 +361,12 @@ bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_DEGREES POS, C3D_W
A[1] = tDec.y;
A[2] = tDec.z;
pTF->get_vector_world(A, B);
tDec.x = B[0] + SP->getX();
tDec.y = B[1] + SP->getY();
tDec.z = B[2] + SP->getZ();
//tDec.x = B[0] + SP->getX();
tDec.x = B[0] + SP->getX() - getX();
//tDec.y = B[1] + SP->getY();
tDec.y = B[1] + SP->getY() - getY();
//tDec.z = B[2] + SP->getZ();
tDec.z = B[2] + SP->getZ() - getZ();
m_SCC.UTMXYToLatLon( tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
LOC.alt = tDec.z;
return true;
@ -348,9 +382,12 @@ bool systemAnchor::convertToGlobal(basicPosition *SP, C3D_SPH_RADIANS POS, C3D_W
A[1] = tDec.y;
A[2] = tDec.z;
pTF->get_vector_world(A, B);
tDec.x = B[0] + SP->getX();
tDec.y = B[1] + SP->getY();
tDec.z = B[2] + SP->getZ();
//tDec.x = B[0] + SP->getX();
tDec.x = B[0] + SP->getX() - getX();
//tDec.y = B[1] + SP->getY();
tDec.y = B[1] + SP->getY() - getY();
//tDec.z = B[2] + SP->getZ();
tDec.z = B[2] + SP->getZ() - getZ();
m_SCC.UTMXYToLatLon(tDec.x, tDec.y, getUTMZone(), m_bSouthHemisphere, LOC.lat, LOC.lon);
LOC.alt = tDec.z;
return true;

32
lib/data/curl/curlRequest.cpp

@ -146,22 +146,30 @@ void curlRequest::init_CURL(){
};
};
void curlRequest::setCredentials( CSTR user, CSTR password, bool use_digest ){
void curlRequest::setCredentials( CSTR user, CSTR password, uint8_t AuthMode ){
if( !strlen(user) || !strlen(password) ) return;
sprintf(m_cUserPassword, "%s:%s", user, password );
curl_easy_setopt( m_pCURL, CURLOPT_USERPWD, m_cUserPassword );
if( use_digest ) {
curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST );
} else {
curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC );
switch ( AuthMode ) {
case 0: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); break;
case 1: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST ); break;
case 2: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST_IE ); break;
case 3: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BEARER ); break;
case 4: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NEGOTIATE ); break;
case 5: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM ); break;
case 6: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM_WB ); break;
case 7: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANY ); break;
case 8: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE ); break;
case 9: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ONLY ); break;
//case 10: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_AWS_SIGV4 ); break;
};
};
static char *EmptyExpectConstant = (CSTR)"Expect:";
static char *EmptyAcceptConstant = (CSTR)"Accept: */*";
static char *AcceptEncoding = (CSTR)"Accept-Encoding: gzip, deflate";
void curlRequest::setPOST( CSTR postDATA, int size ){
if( m_pCURL != NULL ){
void curlRequest::setPOST( CSTR postDATA, int size ){
if( m_pCURL != NULL ){
if( !postDATA ){
#ifdef DEBUG
LOG_ERROR("No Post Data Supplied In Post Request!");
@ -169,13 +177,13 @@ void curlRequest::setPOST( CSTR postDATA, int size ){
return;
};
if( !size ) size = strlen( postDATA );
m_pPostData = (CSTR) malloc( size+1 );
m_pPostData = (CSTR) malloc( size+1 );
if( !m_pPostData ){
LOG_ERROR("Memory Allocation Error!");
return;
};
memcpy( m_pPostData, postDATA, size );
m_pPostData[size] = (char)0;
memcpy( m_pPostData, postDATA, size );
m_pPostData[size] = (char)0;
sprintf( m_cContentLength, "Content-Length: %d", size );
m_HeaderList = curl_slist_append( m_HeaderList, EmptyExpectConstant );
m_HeaderList = curl_slist_append( m_HeaderList, EmptyAcceptConstant );
@ -183,9 +191,9 @@ void curlRequest::setPOST( CSTR postDATA, int size ){
m_HeaderList = curl_slist_append( m_HeaderList, m_cContentLength );
curl_easy_setopt( m_pCURL, CURLOPT_HTTPHEADER, m_HeaderList );
curl_easy_setopt( m_pCURL, CURLOPT_POST, 1 );
curl_easy_setopt( m_pCURL, CURLOPT_POSTFIELDS, m_pPostData );
curl_easy_setopt( m_pCURL, CURLOPT_POSTFIELDS, m_pPostData );
} else LOG_ERROR("Wrong CURL handle!");
};
};
void curlRequest::setHandler(void *baseObject, void *(*start_routine) (void *, void*), void* ptr ){
#ifdef DEBUG_EXTRA

2
lib/data/curl/curlRequest.h

@ -52,7 +52,7 @@ class curlRequest{
size_t getSize(void){ return m_nMemorySize; };
CSTR getURL(void){ return m_pURL; };
void setHandler(void *baseObject, void *(*start_routine) (void *, void*), void *ptr );
void setCredentials( CSTR user, CSTR password, bool use_digest = true );
void setCredentials( CSTR user, CSTR password, uint8_t AuthMode = 0 );
void setPOST( CSTR postDATA , int size = 0 );
void issue(void);
bool isFinished(void){ return m_bRequestComplete; };

102
lib/data/media/video/videoAVLIBSource.cpp

@ -25,8 +25,7 @@ videoAVLIBSource::videoAVLIBSource( void *opaque ): basicMediaSource(), basicThr
m_pLog = basicLogCollection::getInstance();
m_bStreamingSource = true;
m_bSizeIsAutomatic = false;
m_nWidth = 640;
m_nHeight = 480;
m_nOutWidth = m_nInWidth = m_nOutHeight = m_nInHeight = -1;
m_bSrcType = AVLIB_SOURCE_NOTDEF;
if( opaque ) {
m_pOpaque = opaque;
@ -62,8 +61,7 @@ videoAVLIBSource::videoAVLIBSource( char *Source, void *opaque ) : basicMediaSou
m_pLog = basicLogCollection::getInstance();
m_bStreamingSource = true;
m_bSizeIsAutomatic = false;
m_nWidth = 640;
m_nHeight = 480;
m_nOutWidth = m_nInWidth = m_nOutHeight = m_nInHeight = -1;
m_bSrcType = AVLIB_SOURCE_NOTDEF;
if( opaque ) {
m_pOpaque = opaque;
@ -122,13 +120,13 @@ videoAVLIBSource::~videoAVLIBSource(){
};
};
bool videoAVLIBSource::setSize( int Width, int Height ){
bool videoAVLIBSource::setOutputSize( int Width, int Height ){
if( m_pVideoState ){
if( m_pVideoState->m_bStatus == MS_INIT ) {
if( Width && Height ) {
m_bSizeIsAutomatic = false;
m_nWidth = Width;
m_nHeight = Height;
m_nOutWidth = Width;
m_nOutHeight = Height;
return true;
};
};
@ -141,7 +139,7 @@ bool videoAVLIBSource::setProportionalByWidth(int Width){
if( m_pVideoState->m_bStatus == MS_INIT ) {
if( Width > 0 ) {
m_bSizeIsAutomatic = true;
m_nWidth = Width;
m_nOutWidth = Width;
return true;
};
};
@ -154,7 +152,7 @@ bool videoAVLIBSource::setProportionalByHeight(int Height){
if( m_pVideoState->m_bStatus == MS_INIT ) {
if( Height > 0 ) {
m_bSizeIsAutomatic = true;
m_nHeight = Height;
m_nOutHeight = Height;
return true;
};
};
@ -201,7 +199,7 @@ bool videoAVLIBSource::_stop(void){
};
//https://www.youtube.com/watch?v=Lu3LZmhC_DY
bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, int inputPin, int width, int height, bool scaled, int s_width, int s_height ){
bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, int inputPin, int width, int height, int s_width, int s_height ){
if (m_pVideoState == NULL) return false;
if (m_bThreadStatus > TH_PRE_INIT ) return false;
if (m_pVideoState->m_bStatus == MS_INIT) {
@ -300,6 +298,20 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
av_dict_set(&m_pVideoState->m_pFormatOpts, "rtsp_transport", "tcp", 0);
av_dict_set(&m_pVideoState->m_pFormatOpts, "stimeout", "5000000", 0);
av_dict_set(&m_pVideoState->m_pFormatOpts, "buffer_size", "1024000", 0);
/*
av_dict_set_int(&opts, "rw_timeout", 5000000, 0);
av_dict_set_int(&opts, "tcp_nodelay", 1, 0);
av_dict_set_int(&opts, "stimeout", 10000000, 0);
av_dict_set(&opts, "user_agent", "Mozilla/5.0", 0);
av_dict_set(&opts, "rtsp_transport", "tcp", 0);
av_dict_set(&opts, "rtsp_flags", "prefer_tcp", 0);
av_dict_set_int(&opts, "buffer_size", BUFSIZE, 0);
pFormatCtx->flags |= AVFMT_FLAG_NONBLOCK;
pFormatCtx->flags |= AVFMT_FLAG_DISCARD_CORRUPT;
pFormatCtx->flags |= AVFMT_FLAG_NOBUFFER;
*/
} else {
#ifdef DEBUG
LOG("Linux Video Device");
@ -331,7 +343,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
//av_dict_set(&options, "timeout", "8000", 0);
int RetVal = 0;
strncpy( m_pVideoState->m_pFileName, URI, MAX_PATH_LEN );
LOG("Before Open1");
//LOG("Before Open1");
if( ( RetVal = avformat_open_input(&m_pVideoState->m_pFormatCtx, m_pVideoState->m_pFileName, NULL, &m_pVideoState->m_pFormatOpts) ) != 0 ){
//av_dict_free(&options);
char tBuffer[1024];
@ -340,7 +352,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
LOG_ERROR(Buffer);
return false;
};
LOG("After Open1");
//LOG("After Open1");
AVDictionaryEntry *e;
if( e = av_dict_get( m_pVideoState->m_pFormatOpts, "", NULL, AV_DICT_IGNORE_SUFFIX )){
sprintf(Buffer, "Option %s not recognized by the demuxer", e->key);
@ -398,7 +410,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
//m_pVideoState->m_pFormatCtx->streams[m_pVideoState->m_iVideoStreamID]->codecpar->codec_id
m_pVideoState->m_pVideoCodec = avcodec_find_decoder( m_pVideoState->m_pCodecCtx->codec_id );
#else
# ifdef DEBUG
# ifdef DEBUG_EXTRA
LOG("YABABA-2!");
# endif
/* find the video stream information */
@ -442,7 +454,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
*/
//m_pVideoState->m_pCodecCtx->thread_count = 2;
//m_pVideoState->m_pCodecCtx->thread_type = FF_THREAD_FRAME;
#ifdef DEBUG
#ifdef DEBUG_EXTRA
LOG("Before Open2");
#endif
if( avcodec_open2( m_pVideoState->m_pCodecCtx, m_pVideoState->m_pVideoCodec, NULL ) < 0 ){
@ -467,58 +479,56 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
return false;
};
#endif
#ifdef DEBUG
#ifdef DEBUG_EXTRA
char tB[256];
sprintf( tB, "Setting Frame [%dx%d]", m_nWidth, m_nHeight );
LOG( tB );
sprintf( tB, "Source Frame [%dx%d]", m_pVideoState->m_pCodecCtx->width, m_pVideoState->m_pCodecCtx->height );
LOG( tB );
#endif
if( scaled ){
#ifdef DEBUG
LOG("Size is Scaled");
#endif
m_nWidth = s_width;
m_nHeight = s_height;
if( ( s_width > 0 ) && ( s_height > 0 ) ){
m_nOutWidth = s_width;
m_nOutHeight = s_height;
} else {
if( m_bSizeIsAutomatic ){
#ifdef DEBUG
#ifdef DEBUG_EXTRA
LOG("Size is Automatic");
#endif
if(( m_nWidth == -1 )&&( m_nHeight == -1 )){
m_nWidth = m_pVideoState->m_pCodecCtx->width;
m_nHeight = m_pVideoState->m_pCodecCtx->height;
if(( m_nOutWidth == -1 )&&( m_nOutHeight == -1 )){
m_nOutWidth = m_pVideoState->m_pCodecCtx->width;
m_nOutHeight = m_pVideoState->m_pCodecCtx->height;
} else {
// Proportional
if( m_nHeight == -1 ){
if( m_nOutHeight == -1 ){
float k = ((float)m_pVideoState->m_pCodecCtx->height) / ((float)m_pVideoState->m_pCodecCtx->width);
m_nHeight = (int)(((float)m_nWidth ) * k );
m_nOutHeight = (int)(((float)m_nOutWidth ) * k );
} else {
float k = ((float)m_pVideoState->m_pCodecCtx->width) / ((float)m_pVideoState->m_pCodecCtx->height);
m_nWidth = (int)(((float)m_nHeight ) * k );
m_nOutWidth = (int)(((float)m_nOutHeight ) * k );
};
};
} else {
#ifdef DEBUG
#ifdef DEBUG_EXTRA
LOG("Size is Manual");
#endif
if( width > 0 ){
m_nWidth = width;
};
if( height > 0 ){
m_nHeight = height;
if( ( width > 0 ) && ( height > 0 ) ){
m_nOutWidth = width;
m_nOutHeight = height;
} else {
m_nOutWidth = m_pVideoState->m_pCodecCtx->width;
m_nOutHeight = m_pVideoState->m_pCodecCtx->height;
};
};
};
#ifdef DEBUG
sprintf( tB, "Using Size [%dx%d]", m_nWidth, m_nHeight );
#ifdef DEBUG_EXTRA
sprintf( tB, "Using Size [%dx%d]", m_nOutWidth, m_nOutHeight );
LOG( tB );
sprintf(tB,"swsPar: IN: %dx%d [%d] OUT: %dx%d [%d] {%d}", m_pVideoState->m_pCodecCtx->width,
m_pVideoState->m_pCodecCtx->height,
m_pVideoState->m_pCodecCtx->pix_fmt,
m_nWidth,
m_nHeight,
m_nOutWidth,
m_nOutHeight,
AV_PIX_FMT_BGR24,
SWS_BICUBIC );
LOG( tB );
@ -527,8 +537,8 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
m_pVideoState->m_pCodecCtx->width,
m_pVideoState->m_pCodecCtx->height,
m_pVideoState->m_pCodecCtx->pix_fmt,
m_nWidth,
m_nHeight,
m_nOutWidth,
m_nOutHeight,
AV_PIX_FMT_BGR24,
SWS_BICUBIC, //SWS_FAST_BILINEAR,// | SWS_ACCURATE_RND,//SWS_BILINEAR,//SWS_BICUBIC,
NULL,
@ -540,7 +550,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
LOG_ERROR("Error Allocating SwsCtx!");
return false;
};
#ifdef DEBUG
#ifdef DEBUG_EXTRA
LOG("Allocation Done->Start Thread!");
#endif
return init();
@ -550,7 +560,7 @@ bool videoAVLIBSource::_open(char *URI, bool ShowDeviceMenu, float framerate, in
void videoAVLIBSource::m_fThreadProc( void ){
AVPacket * pPacket = NULL;
cv::Mat mRGB( m_nHeight, m_nWidth, CV_8UC3, cv::Scalar( 255, 0, 255 ) );
cv::Mat mRGB( m_nOutHeight, m_nOutWidth, CV_8UC3, cv::Scalar( 255, 0, 255 ) );
AVFrame * pFrame = NULL;
AVFrame * pFrameBGR = NULL;
uint8_t * pBGRbuffer = NULL;
@ -574,7 +584,7 @@ void videoAVLIBSource::m_fThreadProc( void ){
m_bThreadStatus = TH_ENDED;
LOG_ERROR("Error allocating BGR AVFrame!");
} else {
dec_ret = av_image_alloc ( pFrameBGR->data, pFrameBGR->linesize, m_nWidth, m_nHeight, AV_PIX_FMT_BGR24, BUFFER_ALIGN );
dec_ret = av_image_alloc ( pFrameBGR->data, pFrameBGR->linesize, m_nOutWidth, m_nOutHeight, AV_PIX_FMT_BGR24, BUFFER_ALIGN );
sprintf( tB, "Allocated: %d bytes to Frame", dec_ret );
LOG( tB );
if ( dec_ret < 0 ) {
@ -604,7 +614,7 @@ void videoAVLIBSource::m_fThreadProc( void ){
m_pVideoState->m_bStatus = MS_STOPED;
while( m_pMediaDestination == NULL && m_bThreadStatus == TH_WORKING ){
SLEEP(20);
#ifdef DEBUG
#ifdef DEBUG_EXTRA
LOG("Waiting Destination");
#endif
};
@ -612,7 +622,7 @@ void videoAVLIBSource::m_fThreadProc( void ){
if( m_bSrcType == AVLIB_SOURCE_IPSTREAM ){
//av_read_play( m_pVideoState->m_pFormatCtx );
};
#ifdef DEBUG
#ifdef DEBUG_EXTRA
LOG("Presentation Started.");
#endif
while( m_pVideoState->m_bStatus < MS_CLOSING && m_bThreadStatus != TH_ENDED ){
@ -653,7 +663,7 @@ void videoAVLIBSource::m_fThreadProc( void ){
try{
//sprintf( tB, "Try to copy %d[%dx%d] bytes to %d[%dx%d]", pFrameBGR->linesize[0] * m_nHeight, pFrameBGR->width, pFrameBGR->height, mRGB.total() * mRGB.elemSize(), mRGB.cols, mRGB.rows );
//LOG(tB);
memcpy( mRGB.data, pFrameBGR->data[0], pFrameBGR->linesize[0] * m_nHeight );
memcpy( mRGB.data, pFrameBGR->data[0], pFrameBGR->linesize[0] * m_nOutHeight );
//LOG("13");
if(!m_pMediaDestination->pushFrame( mRGB, m_pOpaque )){
m_pMediaDestination = NULL;

12
lib/data/media/video/videoAVLIBSource.h

@ -22,8 +22,10 @@ class videoAVLIBSource : public basicMediaSource, public basicThread {
void * m_pOpaque;
uint8_t m_bSrcType;
//uint8_t * m_pOut_buffer;
int m_nWidth;
int m_nHeight;
int m_nInWidth;
int m_nInHeight;
int m_nOutWidth;
int m_nOutHeight;
int m_iY_size;
#ifndef _NOAUDIO_
mediaBus * m_pAudioBus;
@ -33,8 +35,8 @@ class videoAVLIBSource : public basicMediaSource, public basicThread {
protected:
void m_fThreadProc( void );
public:
bool _open( CSTR URI, bool ShowDeviceMenu = false, float framerate=-1.f, int inputPin = -1, int width = -1, int height = -1 , bool scaled=false, int s_width=-1, int s_height=-1 );
bool _close( void );
virtual bool _open( CSTR URI, bool ShowDeviceMenu = false, float framerate=-1.0f, int inputPin = -1, int width = -1, int height = -1 , int s_width=-1, int s_height=-1 );
virtual bool _close( void );
virtual bool _stop( void );
bool isFinished( void );
MediaStateStatus getStatus( void );
@ -42,7 +44,7 @@ class videoAVLIBSource : public basicMediaSource, public basicThread {
videoAVLIBSource( CSTR URI, void *opaque=NULL );
//videoAVLIBSource( config_setting_t *CFG, void *opaque=NULL );
virtual ~videoAVLIBSource();
bool setSize( int Width,
bool setOutputSize( int Width,
int Height );
bool setProportionalByWidth( int Width );
bool setProportionalByHeight( int Height );

597
lib/data/media/video/videoLive555AVLibSource.cpp

@ -0,0 +1,597 @@
#include "videoLive555AVLibSource.h"
StreamClientState::StreamClientState()
: iter(NULL), session(NULL), subsession(NULL), streamTimerTask(NULL), duration(0.0) {
};
StreamClientState::~StreamClientState() {
delete iter;
if( session != NULL ){
// We also need to delete "session", and unschedule "streamTimerTask" (if set)
UsageEnvironment& env = session->envir(); // alias
env.taskScheduler().unscheduleDelayedTask(streamTimerTask);
Medium::close(session);
};
};
CustomRTSPClient* CustomRTSPClient::createNew(
videoLIVE555Source *session,
UsageEnvironment& env,
char const* rtspURL,
int verbosityLevel,
char const* applicationName,
portNumBits tunnelOverHTTPPortNum) {
return new CustomRTSPClient(session, env, rtspURL, verbosityLevel, applicationName, tunnelOverHTTPPortNum);
};
CustomRTSPClient::CustomRTSPClient(
videoLIVE555Source *session,
UsageEnvironment& env,
char const* rtspURL,
int verbosityLevel,
char const* applicationName,
portNumBits tunnelOverHTTPPortNum)
: RTSPClient(env,rtspURL, verbosityLevel, applicationName, tunnelOverHTTPPortNum, -1) ,
session(session){
};
CustomRTSPClient::~CustomRTSPClient() {
};
#define LOG( X ) m_pLog->Log( "LIVE555_SIN", this, X )
#define MLOG( X ) ME->m_pLog->Log( "LIVE555_SIN", ME, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG2w34[256];\
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "LIVE555_SIN", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "LIVE555_SIN", this, _LOG_ERROR, X );
#endif
DummySink* DummySink::createNew( videoLIVE555Source* session, UsageEnvironment& env, MediaSubsession& subsession, char const* streamId, int w, int h, int ww, int hh ) {
return new DummySink( session, env, subsession, streamId, w, h, ww, hh );
}
DummySink::DummySink(videoLIVE555Source* session, UsageEnvironment& env, MediaSubsession& subsession, char const* streamId, int w, int h, int ww, int hh )
: MediaSink(env),
session(session),
frameIndex(0),
fSubsession(subsession) {
m_pLog = basicLogCollection::getInstance();
fStreamId = strDup(streamId);
m_nInWidth = w;
m_nInHeight = h;
m_nOutWidth = ww;
m_nOutHeight = hh;
fReceiveBuffer = new u_int8_t[DUMMY_SINK_RECEIVE_BUFFER_SIZE];
fReceiveBufferAV = new u_int8_t[DUMMY_SINK_RECEIVE_BUFFER_SIZE + 4];
fReceiveBufferAV[0] = 0;
fReceiveBufferAV[1] = 0;
fReceiveBufferAV[2] = 0;
fReceiveBufferAV[3] = 1;
av_init_packet(&avpkt);
avpkt.flags |= AV_PKT_FLAG_KEY;
avpkt.pts = avpkt.dts = 0;
memset(inbuf + INBUF_SIZE, 0, AV_INPUT_BUFFER_PADDING_SIZE);
LOG( subsession.codecName() );
m_eCodecProbe = AV_CODEC_ID_NONE;
if( strcmp(fSubsession.codecName(),"H264") == 0 ){
m_eCodecProbe = AV_CODEC_ID_H264;
};
if( strcmp(fSubsession.codecName(),"JPEG") == 0 ){
m_eCodecProbe = AV_CODEC_ID_MJPEG;
};
if( strcmp(fSubsession.codecName(),"H265") == 0 ){
m_eCodecProbe = AV_CODEC_ID_HEVC;
};
codec = avcodec_find_decoder( m_eCodecProbe );
if (!codec) {
LOG_ERROR( "codec not found!" );
};
codecContext = avcodec_alloc_context3(codec);
frame = av_frame_alloc();
rgbFrame = av_frame_alloc();
//avpicture_alloc( ( AVPicture *) rgbFrame, AV_PIX_FMT_RGB24, 1920, 1080);
avpicture_alloc( ( AVPicture *) rgbFrame, AV_PIX_FMT_BGR24, 1280, 720 );
if (codec->capabilities & AV_CODEC_CAP_TRUNCATED) {
codecContext->flags |= AV_CODEC_FLAG_TRUNCATED; // we do not send complete frames
}
if ( ( fSubsession.videoWidth() > 0 ) && ( fSubsession.videoHeight() > 0 ) ) {
m_nInWidth = fSubsession.videoWidth();
m_nInHeight = fSubsession.videoHeight();
};
codecContext->width = m_nInWidth;
codecContext->height = m_nInHeight;
codecContext->pix_fmt = AV_PIX_FMT_YUV420P;
if (avcodec_open2(codecContext,codec,NULL) < 0) {
LOG_ERROR( "could not open codec" );
}
//this->swsContext = sws_getContext( codecContext->width, codecContext->height, codecContext->pix_fmt, 1920, 1080, AV_PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);
this->swsContext = sws_getContext( codecContext->width, codecContext->height, codecContext->pix_fmt, m_nOutWidth, m_nOutHeight, AV_PIX_FMT_BGR24, SWS_BICUBIC, NULL, NULL, NULL);
m_pRGB = new cv::Mat( m_nOutHeight, m_nOutWidth, CV_8UC3, cv::Scalar( 255, 0, 255 ) );
char tB[128];
sprintf( tB, "Created Sink [%dx%d]->[1280x720]", codecContext->width,codecContext->height );
LOG( tB );
};
DummySink::~DummySink() {
delete[] fReceiveBuffer;
delete [] fReceiveBufferAV;
delete[] fStreamId;
}
void DummySink::afterGettingFrame(void* clientData, unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned durationInMicroseconds ) {
DummySink* sink = (DummySink*)clientData;
sink->afterGettingFrame(frameSize, numTruncatedBytes, presentationTime, durationInMicroseconds);
};
void DummySink::afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes, struct timeval presentationTime, unsigned /*durationInMicroseconds*/) {
// We've just received a frame of data. (Optionally) print out information about it:
//if (strcmp(fSubsession.codecName(),"H264") == 0) {
if( m_eCodecProbe != AV_CODEC_ID_NONE ) {
avpkt.data = fReceiveBufferAV;
avpkt.size = frameSize + 4;
memcpy (fReceiveBufferAV + 4, fReceiveBuffer, frameSize);
avpkt.data = fReceiveBufferAV;
len = avcodec_decode_video2 (codecContext, frame, &got_picture, &avpkt);
if (len < 0) {
//LOG_ERROR( "Error while decoding frame " );// << frameIndex << "\n";
} else if (got_picture) {
//envir() << "->Picture decoded :" << frameIndex << "\n";
//LOG( "Picture decoded" );
sws_scale( this->swsContext, this->frame->data,this->frame->linesize, 0, this->codecContext->height, this->rgbFrame->data, this->rgbFrame->linesize );
memcpy( m_pRGB->data, this->rgbFrame->data[0], this->rgbFrame->linesize[0] * m_nOutHeight );
this->session->consumeFrame( m_pRGB );
frameIndex ++;
};
} else{
LOG("Codec Not Handled!");
LOG( fSubsession.codecName() );
};
// Then continue, to request the next frame of data:
continuePlaying();
}
Boolean DummySink::continuePlaying() {
if (fSource == NULL) return False; // sanity check (should not happen)
// Request the next frame of data from our input source. "afterGettingFrame()" will get called later, when it arrives:
fSource->getNextFrame(fReceiveBuffer, DUMMY_SINK_RECEIVE_BUFFER_SIZE,
afterGettingFrame, this,
onSourceClosure, this);
return True;
}
void DummySink::setSprop(u_int8_t const* prop, unsigned size) {
uint8_t *buf;
uint8_t *buf_start;
buf = (uint8_t *)malloc(1000);
buf_start = buf + 4;
avpkt.data = buf;
avpkt.data[0] = 0;
avpkt.data[1] = 0;
avpkt.data[2] = 0;
avpkt.data[3] = 1;
memcpy (buf_start, prop, size);
avpkt.size = size + 4;
len = avcodec_decode_video2 (codecContext, frame, &got_picture, &avpkt);
if (len < 0) {
//envir() << "Error while decoding frame" << frame;
LOG_ERROR( "Error while decoding frame" );
// exit(6);
};
LOG( "after setSprop" );
// exit (111);
};
#undef LOG_ERROR
#undef MLOG
#undef LOG
#define LOG( X ) m_pLog->Log( "LIVE555_SRC", this, X )
#define MLOG( X ) ME->m_pLog->Log( "LIVE555_SRC", ME, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG2w34[256];\
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\
m_pLog->Log( "LIVE555_SRC", this, _LOG_ERROR, _tBfrErrMSG2w34 );\
}
#else
#define LOG_ERROR( X ) m_pLog->Log( "LIVE555_SRC", this, _LOG_ERROR, X );
#endif
videoLIVE555Source::videoLIVE555Source( void *opaque ):
m_pScheduler(BasicTaskScheduler::createNew()),
m_pUsageEnvironment(BasicUsageEnvironment::createNew(*m_pScheduler)),
basicMediaSource(),
//MediaSink(*m_pUsageEnvironment),
basicThread(),
m_pLog(basicLogCollection::getInstance()),
m_pOpaque(opaque){
m_nOutWidth = m_nInWidth = m_nOutHeight = m_nInHeight = -1;
if( !initLibAV() ) return;
};
videoLIVE555Source::videoLIVE555Source( CSTR URI, void *opaque ):
m_pScheduler(BasicTaskScheduler::createNew()),
m_pUsageEnvironment(BasicUsageEnvironment::createNew(*m_pScheduler)),
basicMediaSource(),
//MediaSink(*m_pUsageEnvironment),
basicThread(),
m_pLog(basicLogCollection::getInstance()),
m_pOpaque(opaque){
m_nOutWidth = m_nInWidth = m_nOutHeight = m_nInHeight = -1;
if( !initLibAV() ) return;
_open( URI );
};
videoLIVE555Source::~videoLIVE555Source(){
_stop();
//if ( m_pSink ) delete( m_pSink );
};
void videoLIVE555Source::m_fThreadProc( void ){
_eventLoopWatchVariable = 0;
m_pScheduler->doEventLoop( &_eventLoopWatchVariable );
LOG( "Rtsp event finished" );
m_pUsageEnvironment->reclaim();
m_pUsageEnvironment = NULL;
delete m_pScheduler;
m_pScheduler = NULL;
};
Boolean videoLIVE555Source::continuePlaying(){
return False;
};
void videoLIVE555Source::continueAfterDESCRIBE( RTSPClient* rtspClient, int resultCode, char* resultString){
CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
MLOG("After Describe EVT");
do {
UsageEnvironment& env = rtspClient->envir(); // alias
StreamClientState& scs = MM->getStreamClientState(); // alias
if (resultCode != 0) {
MLOG( "Failed to get a SDP description: ");
MLOG( resultString );
delete[] resultString;
break;
};
char* const sdpDescription = resultString;
MLOG( "Got a SDP description:" );
MLOG( sdpDescription );
// Create a media session object from this SDP description:
scs.session = MediaSession::createNew(env, sdpDescription);
delete[] sdpDescription; // because we don't need it anymore
if (scs.session == NULL) {
MLOG( "Failed to create a MediaSession object from the SDP description:" );
MLOG( env.getResultMsg() );
break;
} else if (!scs.session->hasSubsessions()) {
MLOG( "This session has no media subsessions (i.e., no \"m=\" lines)" );
break;
};
// Then, create and set up our data source objects for the session. We do this by iterating over the session's 'subsessions',
// calling "MediaSubsession::initiate()", and then sending a RTSP "SETUP" command, on each one.
// (Each 'subsession' will have its own data source.)
scs.iter = new MediaSubsessionIterator(*scs.session);
ME->setupNextSubsession(rtspClient);
return;
} while (0);
// An unrecoverable error occurred with this stream.
ME->shutdownStream( rtspClient );
};
void videoLIVE555Source::continueAfterSETUP( RTSPClient* rtspClient, int resultCode, char* resultString){
CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
MLOG("After Setup EVT");
do {
UsageEnvironment& env = rtspClient->envir(); // alias
StreamClientState& streamClientState = MM->getStreamClientState(); // alias
if( resultCode != 0 ){
MLOG( "Failed to set up the subsession:");
MLOG( streamClientState.subsession->mediumName() );
MLOG( streamClientState.subsession->codecName() );
MLOG( resultString );
break;
};
MLOG( "Set up the subsession" );
MLOG( streamClientState.subsession->mediumName() );
MLOG( streamClientState.subsession->codecName() );
if (streamClientState.subsession->rtcpIsMuxed()) {
char tB[128];
sprintf( tB, "client port %d", streamClientState.subsession->clientPortNum() );
MLOG( tB );
} else {
char tB[128];
sprintf( tB, "client ports %d-%d", streamClientState.subsession->clientPortNum(), streamClientState.subsession->clientPortNum()+1 );
MLOG( tB );
};
const char *sprop = streamClientState.subsession->fmtp_spropparametersets();
uint8_t const* sps = NULL;
unsigned spsSize = 0;
uint8_t const* pps = NULL;
unsigned ppsSize = 0;
if (sprop != NULL) {
unsigned numSPropRecords;
SPropRecord* sPropRecords = parseSPropParameterSets(sprop, numSPropRecords);
for (unsigned i = 0; i < numSPropRecords; ++i) {
if (sPropRecords[i].sPropLength == 0) continue; // bad data
u_int8_t nal_unit_type = (sPropRecords[i].sPropBytes[0])&0x1F;
if (nal_unit_type == 7/*SPS*/) {
sps = sPropRecords[i].sPropBytes;
spsSize = sPropRecords[i].sPropLength;
} else if (nal_unit_type == 8/*PPS*/) {
pps = sPropRecords[i].sPropBytes;
ppsSize = sPropRecords[i].sPropLength;
}
}
}
// Having successfully setup the subsession, create a data sink for it, and call "startPlaying()" on it.
// (This will prepare the data sink to receive data; the actual flow of data from the client won't start happening until later,
// after we've sent a RTSP "PLAY" command.)
streamClientState.subsession->sink = DummySink::createNew(ME, env, *streamClientState.subsession, rtspClient->url(), ME->m_nInWidth, ME->m_nInHeight, ME->m_nOutWidth, ME->m_nOutHeight );
// perhaps use your own custom "MediaSink" subclass instead
if (streamClientState.subsession->sink == NULL) {
MLOG( "Failed to create a data sink for the subsession" );
MLOG( streamClientState.subsession->mediumName() );
MLOG( streamClientState.subsession->codecName() );
MLOG( env.getResultMsg() );
break;
};
MLOG( "Created a data sink for the subsession" );
MLOG( streamClientState.subsession->mediumName() );
MLOG( streamClientState.subsession->codecName() );
streamClientState.subsession->miscPtr = rtspClient; // a hack to let subsession handler functions get the "RTSPClient" from the subsession
if (sps != NULL) {
((DummySink *)streamClientState.subsession->sink)->setSprop(sps, spsSize);
}
if (pps != NULL) {
((DummySink *)streamClientState.subsession->sink)->setSprop(pps, ppsSize);
}
streamClientState.subsession->sink->startPlaying(*(streamClientState.subsession->readSource()),
subsessionAfterPlaying, streamClientState.subsession);
// Also set a handler to be called if a RTCP "BYE" arrives for this subsession:
if (streamClientState.subsession->rtcpInstance() != NULL) {
streamClientState.subsession->rtcpInstance()->setByeHandler( subsessionByeHandler, streamClientState.subsession );
}
} while (0);
delete[] resultString;
// Set up the next subsession, if any:
ME->setupNextSubsession(rtspClient);
};
void videoLIVE555Source::continueAfterPLAY( RTSPClient* rtspClient, int resultCode, char* resultString){
Boolean success = False;
CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
MLOG("After Play EVT");
do {
UsageEnvironment& env = rtspClient->envir(); // alias
StreamClientState& scs = ((CustomRTSPClient*)rtspClient)->getStreamClientState(); // alias
if (resultCode != 0) {
MLOG( "Failed to start playing session: " );
MLOG( resultString );
break;
};
// Set a timer to be handled at the end of the stream's expected duration (if the stream does not already signal its end
// using a RTCP "BYE"). This is optional. If, instead, you want to keep the stream active - e.g., so you can later
// 'seek' back within it and do another RTSP "PLAY" - then you can omit this code.
// (Alternatively, if you don't want to receive the entire stream, you could set this timer for some shorter value.)
if (scs.duration > 0) {
unsigned const delaySlop = 2; // number of seconds extra to delay, after the stream's expected duration. (This is optional.)
scs.duration += delaySlop;
unsigned uSecsToDelay = (unsigned)(scs.duration*1000000);
scs.streamTimerTask = env.taskScheduler().scheduleDelayedTask(uSecsToDelay, (TaskFunc*)streamTimerHandler, rtspClient);
}
MLOG( "Started playing session" );
//if (scs.duration > 0) {
// env << " (for up to " << scs.duration << " seconds)";
// }
success = True;
} while (0);
delete[] resultString;
if (!success) {
// An unrecoverable error occurred with this stream.
ME->shutdownStream(rtspClient);
};
};
// Other event handler functions:
// called when a stream's subsession (e.g., audio or video substream) ends
void videoLIVE555Source::subsessionAfterPlaying( void* clientData ){
MediaSubsession* subsession = (MediaSubsession*)clientData;
RTSPClient* rtspClient = (RTSPClient*)(subsession->miscPtr);
CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
// Begin by closing this subsession's stream:
Medium::close(subsession->sink);
subsession->sink = NULL;
// Next, check whether *all* subsessions' streams have now been closed:
MediaSession& session = subsession->parentSession();
MediaSubsessionIterator iter(session);
while ((subsession = iter.next()) != NULL) {
if (subsession->sink != NULL) return; // this subsession is still active
}
// All subsessions' streams have now been closed, so shutdown the client:
ME->shutdownStream(rtspClient);
};
// called when a RTCP "BYE" is received for a subsession
void videoLIVE555Source::subsessionByeHandler( void* clientData ){//, char const* reason ){
MediaSubsession* subsession = (MediaSubsession*)clientData;
RTSPClient* rtspClient = (RTSPClient*)subsession->miscPtr;
CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
UsageEnvironment& env = rtspClient->envir(); // alias
MLOG( "Received RTCP \"BYE\" on subsession" );
MLOG( subsession->mediumName() );
MLOG( subsession->codecName() );
// Now act as if the subsession had closed:
subsessionAfterPlaying(subsession);
};
void videoLIVE555Source::streamTimerHandler( void* clientData ){
CustomRTSPClient* rtspClient = (CustomRTSPClient*)clientData;
StreamClientState& scs = rtspClient->getStreamClientState(); // alias
videoLIVE555Source * ME = (videoLIVE555Source *) rtspClient->getSession();
scs.streamTimerTask = NULL;
// Shut down the stream:
ME->shutdownStream(rtspClient);
};
// The main streaming routine (for each "rtsp://" URL):
void videoLIVE555Source::openURL(UsageEnvironment& env, char const* progName, char const* rtspURL){
LOG("openURL Called!");
};
// Used to iterate through each stream's 'subsessions', setting up each one:
void videoLIVE555Source::setupNextSubsession(RTSPClient* rtspClient){
CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
MLOG("Next Subsession EVT");
UsageEnvironment& env = rtspClient->envir(); // alias
StreamClientState& scs = MM->getStreamClientState(); // alias
scs.subsession = scs.iter->next();
if (scs.subsession != NULL) {
if (!scs.subsession->initiate()) {
MLOG( "Failed to initiate the subsession:" );
MLOG( scs.subsession->mediumName() );
MLOG( scs.subsession->codecName() );
MLOG( env.getResultMsg() );
setupNextSubsession(rtspClient); // give up on this subsession; go to the next one
} else {
MLOG( "Initiated the subsession");
MLOG( scs.subsession->mediumName() );
MLOG( scs.subsession->codecName() );
if (scs.subsession->rtcpIsMuxed()) {
char tB[64];
sprintf( tB, "client port %d", scs.subsession->clientPortNum() );
MLOG( tB );
} else {
char tB[64];
sprintf( tB, "client ports %d-%d", scs.subsession->clientPortNum(), scs.subsession->clientPortNum()+1 );
MLOG( tB );
};
// Continue setting up this subsession, by sending a RTSP "SETUP" command:
rtspClient->sendSetupCommand(*scs.subsession, continueAfterSETUP, False, REQUEST_STREAMING_OVER_TCP);
}
return;
};
// We've finished setting up all of the subsessions. Now, send a RTSP "PLAY" command to start the streaming:
if (scs.session->absStartTime() != NULL) {
// Special case: The stream is indexed by 'absolute' time, so send an appropriate "PLAY" command:
rtspClient->sendPlayCommand(*scs.session, continueAfterPLAY, scs.session->absStartTime(), scs.session->absEndTime());
} else {
scs.duration = scs.session->playEndTime() - scs.session->playStartTime();
rtspClient->sendPlayCommand(*scs.session, continueAfterPLAY);
};
};
// Used to shut down and close a stream (including its "RTSPClient" object):
void videoLIVE555Source::shutdownStream(RTSPClient* rtspClient, int exitCode ){
CustomRTSPClient * MM = (CustomRTSPClient *) rtspClient;
videoLIVE555Source * ME = (videoLIVE555Source *) MM->getSession();
MLOG("Shutdown EVT");
};
// https://chowdera.com/2021/01/20210102084512591N.html
// https://github.com/drriguz/Kamera
bool videoLIVE555Source::_open( CSTR URI, bool ShowDeviceMenu, float framerate, int inputPin, int width, int height, int s_width, int s_height ){
m_nInHeight = height;
m_nInWidth = width;
m_nOutHeight = s_height;
m_nOutWidth = s_width;
m_pRtspClient = CustomRTSPClient::createNew( this, *m_pUsageEnvironment, URI, RTSP_CLIENT_VERBOSITY_LEVEL, "ARGUS CLIENT" );
if( m_pRtspClient == NULL) {
char tB[256];
sprintf( tB, "Failed to create a RTSP client for URL \"%s\":%s", URI, m_pUsageEnvironment->getResultMsg() );
LOG_ERROR( tB );
return false;
};
m_pRtspClient->sendDescribeCommand(continueAfterDESCRIBE);
return init();
};
void videoLIVE555Source::consumeFrame( cv::Mat *frm ){
if ( m_pMediaDestination == NULL ) return;
if(!m_pMediaDestination->pushFrame( *frm, m_pOpaque )){
m_pMediaDestination = NULL;
};
};
bool videoLIVE555Source::_close( void ){
return _stop();
};
bool videoLIVE555Source::_stop( void ){
shutdownStream( m_pRtspClient );
_eventLoopWatchVariable = 1;
basicThread::waitThreadEnd( true );
return true;
};
bool videoLIVE555Source::isFinished( void ){ return false;};
MediaStateStatus videoLIVE555Source::getStatus( void ){ return MS_UNDEFINED; };
bool videoLIVE555Source::setSize( int Width, int Height ){ return false; };
bool videoLIVE555Source::setProportionalByWidth( int Width ){ return false; };
bool videoLIVE555Source::setProportionalByHeight( int Height ){ return false; };
bool videoLIVE555Source::setFPS( int ){ return false; };
bool videoLIVE555Source::setName( CSTR Name ){ return false; };
bool videoLIVE555Source::setFrameAspectRatio( FrameAspectRatio AspectRatio ){ return false; };
#undef MLOG
#undef LOG
#undef LOG_ERROR

180
lib/data/media/video/videoLive555AVLibSource.h

@ -0,0 +1,180 @@
#ifndef __VIDEOLIVE555AVLIBSOURCE_H_INCL__
#define __VIDEOLIVE555AVLIBSOURCE_H_INCL__
#include "../../../components/base/basicLIBAV.h"
#include "../../../components/base/basicMediaSource.h"
#include "../../../components/base/basicSettings.h"
#include "../../../components/base/basicThread.h"
#include "../../../components/base/basicLogCollection.h"
#include "../../../alg/generic/md5.h"
#include <liveMedia/liveMedia.hh>
#include <BasicUsageEnvironment.hh>
#define RTSP_CLIENT_VERBOSITY_LEVEL 1
#define INBUF_SIZE 40960
#define AUDIO_INBUF_SIZE 20480
#define AUDIO_REFILL_THRESH 4096
#define DUMMY_SINK_RECEIVE_BUFFER_SIZE 400000
#define REQUEST_STREAMING_OVER_TCP True
class videoLIVE555Source;
class StreamClientState{
public:
StreamClientState();
virtual ~StreamClientState();
public:
MediaSubsessionIterator * iter;
MediaSession * session;
MediaSubsession * subsession;
TaskToken streamTimerTask;
double duration;
};
class CustomRTSPClient: public RTSPClient {
private:
videoLIVE555Source * session;
StreamClientState streamClientState;
public:
static CustomRTSPClient * createNew(
videoLIVE555Source *session,
UsageEnvironment& env,
char const* rtspURL,
int verbosityLevel = 0,
char const* applicationName = NULL,
portNumBits tunnelOverHTTPPortNum = 0);
StreamClientState& getStreamClientState() { return this->streamClientState; }
videoLIVE555Source * getSession() { return this->session; }
protected:
CustomRTSPClient( videoLIVE555Source *session,
UsageEnvironment& env,
char const* rtspURL,
int verbosityLevel,
char const* applicationName,
portNumBits tunnelOverHTTPPortNum );
virtual ~CustomRTSPClient();
};
class DummySink: public MediaSink {
public:
static DummySink* createNew( videoLIVE555Source *session,
UsageEnvironment& env,
MediaSubsession& subsession, // identifies the kind of data that's being received
char const* streamId = NULL, int w = -1, int h = -1, int ww = -1, int hh = -1 ); // identifies the stream itself (optional)
virtual ~DummySink();
private:
basicLogCollection * m_pLog;
AVCodecID m_eCodecProbe;
cv::Mat * m_pRGB;
int m_nInWidth;
int m_nInHeight;
int m_nOutWidth;
int m_nOutHeight;
DummySink( videoLIVE555Source *session, UsageEnvironment& env, MediaSubsession& subsession, char const* streamId, int w, int h, int ww, int hh );
// called only by "createNew()"
static void afterGettingFrame(void* clientData, unsigned frameSize,
unsigned numTruncatedBytes,
struct timeval presentationTime,
unsigned durationInMicroseconds);
void afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes,
struct timeval presentationTime, unsigned durationInMicroseconds);
//void saveFrameToFile()
private:
// redefined virtual functions:
virtual Boolean continuePlaying();
public:
void setSprop(u_int8_t const* prop, unsigned size);
private:
videoLIVE555Source* session;
private:
u_int8_t* fReceiveBuffer;
u_int8_t* fReceiveBufferAV;
MediaSubsession& fSubsession;
char* fStreamId;
private:
AVCodec *codec;
AVCodecContext *codecContext;
int frameIndex;
int got_picture;
int len;
AVFrame *frame;
AVFrame *rgbFrame;
SwsContext* swsContext;
uint8_t inbuf[INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
char buf[1024];
AVPacket avpkt;
};
class videoLIVE555Source : public basicMediaSource, public basicThread {
private:
basicLogCollection * m_pLog;
void * m_pOpaque;
int m_nInWidth;
int m_nInHeight;
int m_nOutWidth;
int m_nOutHeight;
StreamClientState streamClientState;
virtual Boolean continuePlaying();
uint8_t * fReceiveBuffer;
TaskScheduler * m_pScheduler;
UsageEnvironment * m_pUsageEnvironment;
char _eventLoopWatchVariable;
CustomRTSPClient * m_pRtspClient;
DummySink * m_pSink;
MediaSubsession * fSubsession;
char * fStreamId;
static void continueAfterDESCRIBE( RTSPClient* rtspClient, int resultCode, char* resultString);
static void continueAfterSETUP( RTSPClient* rtspClient, int resultCode, char* resultString);
static void continueAfterPLAY( RTSPClient* rtspClient, int resultCode, char* resultString);
// Other event handler functions:
static void subsessionAfterPlaying( void* clientData );
// called when a stream's subsession (e.g., audio or video substream) ends
static void subsessionByeHandler( void* clientData );//, char const* reason );
// called when a RTCP "BYE" is received for a subsession
static void streamTimerHandler( void* clientData );
// The main streaming routine (for each "rtsp://" URL):
void openURL(UsageEnvironment& env, char const* progName, char const* rtspURL);
// Used to iterate through each stream's 'subsessions', setting up each one:
void setupNextSubsession( RTSPClient* rtspClient );
// Used to shut down and close a stream (including its "RTSPClient" object):
void shutdownStream( RTSPClient* rtspClient, int exitCode = 1);
protected:
void m_fThreadProc( void );
public:
virtual bool _open( CSTR URI, bool ShowDeviceMenu = false, float framerate=-1.0f, int inputPin = -1, int width = -1, int height = -1 , int s_width=-1, int s_height=-1 );
virtual bool _close( void );
virtual bool _stop( void );
bool isFinished( void );
MediaStateStatus getStatus( void );
videoLIVE555Source( void *opaque=NULL );
videoLIVE555Source( CSTR URI, void *opaque=NULL );
virtual ~videoLIVE555Source();
bool setSize( int Width,
int Height );
bool setProportionalByWidth( int Width );
bool setProportionalByHeight( int Height );
bool setFPS( int );
bool setName( CSTR Name );
bool setFrameAspectRatio( FrameAspectRatio AspectRatio );
void consumeFrame( cv::Mat *frm );
};
#endif

132
lib/data/ponvif/ponvif.cpp

@ -73,6 +73,7 @@ pOnvif::pOnvif(){
m_sCapabilities.Media = NULL;
m_sCapabilities.PTZ = NULL;
m_sCapabilities.Extension = NULL;
m_bAuthMode = 0;
LOG("Constructor Done!");
};
@ -461,8 +462,22 @@ bool pOnvif::create( void ) {
struct tm * tTS;
tTS = core_GetSystemDateAndTime();
if( tTS != NULL ){
char tB[128];
sprintf( tB, "TS from dev: %04d-%02d-%02d %02d:%02d:%02d",
tTS->tm_year, tTS->tm_mon, tTS->tm_mday,
tTS->tm_hour, tTS->tm_min, tTS->tm_sec );
LOG( tB );
// WTF ??!!
tTS->tm_year -= 1900;
tTS->tm_mon -= 1;
time_t tTimeStamp = mktime( tTS );
m_nDeltaTime = time(NULL) - tTimeStamp;// -5;
m_nDeltaTime = time(NULL) - tTimeStamp;
sprintf( tB,"TS:[%d] D:[%d]", tTimeStamp, m_nDeltaTime );
LOG(tB);
free( tTS );
} else return false;
} catch ( exception e ) {
@ -518,37 +533,51 @@ struct tm *pOnvif::core_GetSystemDateAndTime( void ) {
if( RetVal!= NULL ) {
memset( RetVal, 0, sizeof(struct tm) );
XMLNode zNode = response.getChildNode("Body", 0);
XMLNode fNode = zNode.getChildNode("GetSystemDateAndTimeResponse", 0);
XMLNode hNode = fNode.getChildNode("SystemDateAndTime", 0);
XMLNode tNode = hNode.getChildNode("UTCDateTime", 0);
if( !tNode.isEmpty() ) {
RetVal->tm_isdst = 0;
XMLNode ttNode = tNode.getChildNode( "Time", 0 );
XMLNode dtNode = tNode.getChildNode( "Date", 0 );
{
XMLNode t = ttNode.getChildNode("Hour",0);
RetVal->tm_hour = atoi( t.getText(0) );
}
{
XMLNode t = ttNode.getChildNode("Minute",0);
RetVal->tm_min = atoi( t.getText(0) );
}
{
XMLNode t = ttNode.getChildNode("Second",0);
RetVal->tm_sec = atoi( t.getText(0) );
}
{
XMLNode t = dtNode.getChildNode("Year",0);
RetVal->tm_year = atoi( t.getText(0) );
}
{
XMLNode t = dtNode.getChildNode("Month",0);
RetVal->tm_mon = atoi( t.getText(0) );
}
{
XMLNode t = dtNode.getChildNode("Day",0);
RetVal->tm_mday = atoi( t.getText(0) );
}
if ( !zNode.isEmpty() ) {
XMLNode fNode = zNode.getChildNode("GetSystemDateAndTimeResponse", 0);
if ( !fNode.isEmpty() ) {
XMLNode hNode = fNode.getChildNode("SystemDateAndTime", 0);
if ( !hNode.isEmpty() ) {
XMLNode tNode = hNode.getChildNode("UTCDateTime", 0);
if( !tNode.isEmpty() ) {
RetVal->tm_isdst = 0;
XMLNode ttNode = tNode.getChildNode( "Time", 0 );
XMLNode dtNode = tNode.getChildNode( "Date", 0 );
{
XMLNode t = ttNode.getChildNode("Hour",0);
RetVal->tm_hour = atoi( t.getText(0) );
}
{
XMLNode t = ttNode.getChildNode("Minute",0);
RetVal->tm_min = atoi( t.getText(0) );
}
{
XMLNode t = ttNode.getChildNode("Second",0);
RetVal->tm_sec = atoi( t.getText(0) );
}
{
XMLNode t = dtNode.getChildNode("Year",0);
RetVal->tm_year = atoi( t.getText(0) );
}
{
XMLNode t = dtNode.getChildNode("Month",0);
RetVal->tm_mon = atoi( t.getText(0) );
}
{
XMLNode t = dtNode.getChildNode("Day",0);
RetVal->tm_mday = atoi( t.getText(0) );
}
} else {
LOG_ERROR("UTCDateTime is Not Found!");
};
} else {
LOG_ERROR("SystemDateAndTime is Not Found!");
};
} else {
LOG_ERROR("GetSystemDateAndTimeResponse is Not Found!");
};
} else {
LOG_ERROR("Body is Not Found!");
};
};
return RetVal;
@ -1690,7 +1719,7 @@ accessToken pOnvif::_passwordDigest( CSTR username, CSTR password, time_t timest
if( tmp == NULL ){
LOG_ERROR("gmtime Error!");
};
if( strftime( tTS, 200, "%FT%T.000Z", tmp )==0 ){
if( strftime( tTS, 200, "%FT%TZ", tmp )==0 ){
LOG_ERROR("strftime returned 0!");
};
} else {
@ -1699,7 +1728,7 @@ accessToken pOnvif::_passwordDigest( CSTR username, CSTR password, time_t timest
if( tmp == NULL ){
LOG_ERROR("gmtime Error!");
};
if( strftime( tTS, 200, "%FT%T.000Z", tmp )==0 ){
if( strftime( tTS, 200, "%FT%TZ", tmp )==0 ){
LOG_ERROR("strftime returned 0!");
};
};
@ -1783,7 +1812,7 @@ bool pOnvif::_send_request( CSTR url, CSTR post_string, bool mustReturnData ){
fclose(tf);
mustReturnData = true; //In Debug Allways Read Return
#endif
tRC->setCredentials( m_pUsername, m_pPassword, false );
tRC->setCredentials( m_pUsername, m_pPassword, m_bAuthMode );
tRC->setPOST( post_string, strlen(post_string) );
if( mustReturnData ) {
tRC->setHandler( (void*)this, pOnvif::parser, (void*)tRC );
@ -1844,6 +1873,19 @@ bool pOnvif::_send_request( CSTR url, CSTR post_string, bool mustReturnData ){
curl_easy_setopt( m_pCURL, CURLOPT_POSTFIELDS, post_string);
sprintf( tBuffer,"%s:%s", m_pUsername, m_pPassword );
curl_easy_setopt( m_pCURL, CURLOPT_USERPWD, tBuffer );
switch ( m_bAuthMode ) {
case 0: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ); break;
case 1: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST ); break;
case 2: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST_IE ); break;
case 3: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_BEARER ); break;
case 4: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NEGOTIATE ); break;
case 5: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM ); break;
case 6: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_NTLM_WB ); break;
case 7: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANY ); break;
case 8: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE ); break;
case 9: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_ONLY ); break;
//case 10: curl_easy_setopt( m_pCURL, CURLOPT_HTTPAUTH, CURLAUTH_AWS_SIGV4 ); break;
};
#ifdef DEBUG
char tErrorBuffer[CURL_ERROR_SIZE];
curl_easy_setopt( m_pCURL, CURLOPT_ERRORBUFFER, tErrorBuffer );
@ -1874,6 +1916,26 @@ int pOnvif::_writer( char *data, size_t size, size_t nmemb, pOnvif *Ptr ){
};
#endif
bool pOnvif::setAuthMode( uint8_t Mode ){
m_bAuthMode = Mode;
#ifdef DEBUG
switch ( m_bAuthMode ) {
case 0: LOG("Set Auth CURLAUTH_BASIC" ); break;
case 1: LOG("Set Auth CURLAUTH_DIGEST" ); break;
case 2: LOG("Set Auth CURLAUTH_DIGEST_IE" ); break;
case 3: LOG("Set Auth CURLAUTH_BEARER" ); break;
case 4: LOG("Set Auth CURLAUTH_NEGOTIATE" ); break;
case 5: LOG("Set Auth CURLAUTH_NTLM" ); break;
case 6: LOG("Set Auth CURLAUTH_NTLM_WB" ); break;
case 7: LOG("Set Auth CURLAUTH_ANY" ); break;
case 8: LOG("Set Auth CURLAUTH_ANYSAFE" ); break;
case 9: LOG("Set Auth CURLAUTH_ONLY" ); break;
case 10: LOG("Set Auth CURLAUTH_AWS_SIGV4" ); break;
};
#endif
return true;
};
#undef LOG
#undef TLOG
#undef LOG_ERROR

6
lib/data/ponvif/ponvif.h

@ -49,9 +49,9 @@
#define PONVIF_PACK_RELATIVE_MOVE (CSTR)"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header><Security s:mustUnderstand=\"1\" xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><UsernameToken><Username>%s</Username><Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">%s</Password><Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">%s</Nonce><Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">%s</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><RelativeMove xmlns=\"http://www.onvif.org/ver20/ptz/wsdl\"><ProfileToken>%s</ProfileToken><Translation><PanTilt x=\"%%TRANSLATIONPANTILTX%%\" y=\"%%TRANSLATIONPANTILTY%%\" space=\"http://www.onvif.org/ver10/tptz/PanTiltSpaces/TranslationGenericSpace\" xmlns=\"http://www.onvif.org/ver10/schema\"/></Translation><Speed><PanTilt x=\"%0.2f\" y=\"%0.2f\" space=\"http://www.onvif.org/ver10/tptz/PanTiltSpaces/GenericSpeedSpace\" xmlns=\"http://www.onvif.org/ver10/schema\"/></Speed></RelativeMove></s:Body></s:Envelope>"
#define PONVIF_PACK_RELATIVE_ZOOM (CSTR)"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header><Security s:mustUnderstand=\"1\" xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><UsernameToken><Username>%s</Username><Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">%s</Password><Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">%s</Nonce><Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">%s</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><RelativeMove xmlns=\"http://www.onvif.org/ver20/ptz/wsdl\"><ProfileToken>%s</ProfileToken><Translation><Zoom x=\"%0.2f\" xmlns=\"http://www.onvif.org/ver10/schema\"/></Translation><Speed><Zoom x=\"%0.2f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/ZoomGenericSpeedSpace\" xmlns=\"http://www.onvif.org/ver10/schema\"/></Speed></RelativeMove></s:Body></s:Envelope>"
#define PONVIF_PACK_ABSOLUTE_MOVE (CSTR)"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header><Security s:mustUnderstand=\"1\" xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><UsernameToken><Username>%s</Username><Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">%s</Password><Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">%s</Nonce><Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">%s</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><AbsoluteMove xmlns=\"http://www.onvif.org/ver20/ptz/wsdl\"><ProfileToken>%s</ProfileToken><Position><PanTilt x=\"%0.6f\" y=\"%0.6f\" xmlns=\"http://www.onvif.org/ver10/schema\"/><Zoom x=\"%0.6f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/PositionGenericSpace\" xmlns=\"http://www.onvif.org/ver10/schema\"/></Position><Speed><PanTilt x=\"1\" y=\"1\" xmlns=\"http://www.onvif.org/ver10/schema\"/><Zoom x=\"1\" xmlns=\"http://www.onvif.org/ver10/schema\"/></Speed></AbsoluteMove></s:Body></s:Envelope>"
#define PONVIF_PACK_CONTINUOUS_MOVE (CSTR)"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header><Security s:mustUnderstand=\"1\" xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><UsernameToken><Username>%s</Username><Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">%s</Password><Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">%s</Nonce><Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">%s</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><ContinuousMove xmlns=\"http://www.onvif.org/ver10/ptz/wsdl\"><ProfileToken>%s</ProfileToken><Velocity><PanTilt x=\"%0.2f\" y=\"%0.2f\" xmlns=\"http://www.onvif.org/ver10/schema\"/></Velocity></ContinuousMove></s:Body></s:Envelope>"
#define PONVIF_PACK_CONTINUOUS_MOVE (CSTR)"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header><Security s:mustUnderstand=\"1\" xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><UsernameToken><Username>%s</Username><Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">%s</Password><Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">%s</Nonce><Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">%s</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><ContinuousMove xmlns=\"http://www.onvif.org/ver20/ptz/wsdl\"><ProfileToken>%s</ProfileToken><Velocity><PanTilt x=\"%0.2f\" y=\"%0.2f\" space=\"http://www.onvif.org/ver10/tptz/PanTiltSpaces/VelocityGenericSpace\" xmlns=\"http://www.onvif.org/ver10/schema\"/></Velocity></ContinuousMove></s:Body></s:Envelope>"
//#define PONVIF_PACK_CONTINUOUS_MOVE_A (CSTR)"<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tptz=\"http://www.onvif.org/ver20/ptz/wsdl\" xmlns:tt=\"http://www.onvif.org/ver10/schema\"><soap:Body><tptz:ContinuousMove><tptz:ProfileToken>Profile_1</tptz:ProfileToken><tptz:Velocity><tt:PanTilt x=\"1\" y=\"1\"/><tt:Zoom x=\"1\"/></tptz:Velocity></tptz:ContinuousMove></soap:Body></soap:Envelope>"
#define PONVIF_PACK_CONTINUOUS_ZOOM (CSTR)"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header><Security s:mustUnderstand=\"1\" xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><UsernameToken><Username>%s</Username><Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">%s</Password><Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">%s</Nonce><Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">%s</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><ContinuousMove xmlns=\"http://www.onvif.org/ver10/ptz/wsdl\"><ProfileToken>%s</ProfileToken><Velocity><Zoom x=\"%0.2f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/VelocityGenericSpace\" xmlns=\"http://www.onvif.org/ver10/schema\"/></Velocity></ContinuousMove></s:Body></s:Envelope>"
#define PONVIF_PACK_CONTINUOUS_ZOOM (CSTR)"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header><Security s:mustUnderstand=\"1\" xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><UsernameToken><Username>%s</Username><Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">%s</Password><Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">%s</Nonce><Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">%s</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><ContinuousMove xmlns=\"http://www.onvif.org/ver20/ptz/wsdl\"><ProfileToken>%s</ProfileToken><Velocity><Zoom x=\"%0.2f\" space=\"http://www.onvif.org/ver10/tptz/ZoomSpaces/VelocityGenericSpace\" xmlns=\"http://www.onvif.org/ver10/schema\"/></Velocity></ContinuousMove></s:Body></s:Envelope>"
#define PONVIF_PACK_PTZ_STOP (CSTR)"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\"><s:Header><Security s:mustUnderstand=\"1\" xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><UsernameToken><Username>%s</Username><Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest\">%s</Password><Nonce EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\">%s</Nonce><Created xmlns=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">%s</Created></UsernameToken></Security></s:Header><s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Stop xmlns=\"http://www.onvif.org/ver20/ptz/wsdl\"><ProfileToken>%s</ProfileToken><PanTilt>true</PanTilt><Zoom>true</Zoom></Stop></s:Body></s:Envelope>"
#define PONVIF_ENVELOPE_EXT (CSTR)"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><e:Envelope xmlns:e=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:w=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:d=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:dn=\"http://www.onvif.org/ver10/network/wsdl\">%s%s</e:Envelope>"
@ -444,6 +444,7 @@ class pOnvif{
int m_nDiscoveryMCastPort;
bool m_bDiscoveryHideDuplicates;
bool parser_done;
uint8_t m_bAuthMode;
#ifndef CURL_MANAGER
static int _writer( char *data, size_t size, size_t nmemb, pOnvif *Ptr );
#endif
@ -462,6 +463,7 @@ class pOnvif{
bool setUsername( CSTR username );
CSTR getUsername( void );
bool setPassword( CSTR password );
bool setAuthMode( uint8_t Mode );
CSTR getPassword( void );
CSTR getDeviceUri( void );
bool setDeviceUri( CSTR deviceUri );

286
lib/data/protocol/protocolLGS2D.cpp

@ -42,7 +42,19 @@ int protocolLGS_2D::FinishUpPackage( uint8_t *Buffer, size_t Size, uint8_t Devic
Buffer[SIZE_IDX] = ((Size - 2) & 0xFF) | SEND_TAG;
Buffer[DEV_ID_IDX] = DeviceID;
Buffer[Size] = checksumLGS( Buffer, Size );
return (int)(Size + 1);
#ifdef LEGACY_2ZEROS_BEFORE_PACKAGE
uint8_t ZUBBI[1024];
memcpy( ZUBBI, Buffer, Size+1 );
memcpy( Buffer+2, ZUBBI, Size+1 );
Buffer[0]=0;
Buffer[1]=0;
Buffer[Size+3]=0;
Buffer[Size+4]=0;
return (int)(Size + 5);
#else
return (int)(Size + 1);
#endif
};
int protocolLGS_2D::packetChecker(U8 *Buffer, size_t BufferSize ){
@ -222,15 +234,36 @@ bool protocolLGS_2D::getParameters( bool MASTER ){
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID));
};
bool protocolLGS_2D::getShadowPoly( uint8_t PolyID ){
bool protocolLGS_2D::getShadowPoly( uint16_t PolyID ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_GET_HZ_POLY;
Buffer[SUB_CMD_IDX] = PolyID;
Buffer[CMD_IDX] = CMD_GET_HZ_DATA;
Buffer[SUB_CMD_IDX] = sizeof( HZ_CMD_GET_POLYGON ) - sizeof( HZ_PACKET );
Buffer[5] = HZIT_CMD_GET_POLYGON;
Buffer[6] = 0;
Buffer[7] = PolyID & 0xff;
Buffer[8] = ( PolyID >> 8 ) & 0xff;
#ifdef DEBUG
LOG("getShadowPoly");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID));
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 9, m_bDeviceID));
};
bool protocolLGS_2D::getShadowPolyPoint( uint16_t PolyID, uint16_t PointID ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_GET_HZ_DATA;
Buffer[SUB_CMD_IDX] = sizeof( HZ_CMD_GET_POLYGON_POINT ) - sizeof( HZ_PACKET );
Buffer[5] = HZIT_CMD_GET_POLYGON_POINT;
Buffer[6] = 0;
Buffer[7] = PolyID & 0xff;
Buffer[8] = ( PolyID >> 8 ) & 0xff;
Buffer[9] = PointID & 0xff;
Buffer[10] = ( PointID >> 8 ) & 0xff;
#ifdef DEBUG
LOG("getShadowPolyPoint");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 11, m_bDeviceID));
};
bool protocolLGS_2D::getShadowStatus( uint8_t MaskID ){
@ -247,13 +280,124 @@ bool protocolLGS_2D::getShadowStatus( uint8_t MaskID ){
bool protocolLGS_2D::getShadowInfo( void ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_GET_HZ_INFO;
Buffer[CMD_IDX] = CMD_GET_HZ_DATA;
Buffer[SUB_CMD_IDX] = 0;
Buffer[5] = HZIT_CMD_GET_HEADER;
Buffer[6] = 0;
#ifdef DEBUG
LOG("getShadowInfo");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 4, m_bDeviceID));
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID));
};
bool protocolLGS_2D::setShadowInfo( SHADOW & SH ){
uint8_t Buffer[20];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_SET_HZ_DATA;
Buffer[SUB_CMD_IDX] = 8;
Buffer[5] = HZIT_CMD_SET_HEADER;
Buffer[6] = 0;
Buffer[7] = SH.m_nPolygonCount & 0xFF;
Buffer[8] = ( SH.m_nPolygonCount >> 8 ) & 0xFF;
Buffer[9] = 360 & 0xFF;
Buffer[10] = ( 360 >> 8 ) & 0xFF;
Buffer[11] = SH.m_nEnabled & 0xFF;
Buffer[12] = ( SH.m_nEnabled >> 8 ) & 0xFF;
Buffer[13] = ( SH.m_nEnabled >> 16 ) & 0xFF;
Buffer[14] = ( SH.m_nEnabled >> 24 ) & 0xFF;
#ifdef DEBUG
LOG("setShadowInfo");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 15, m_bDeviceID ) );
};
bool protocolLGS_2D::setShadowPoly( SHADOW & SH, uint16_t PolyID ){
uint8_t Buffer[16];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_SET_HZ_DATA;
Buffer[SUB_CMD_IDX] = 5;
Buffer[5] = HZIT_CMD_SET_POLYGON;
Buffer[6] = 0;
Buffer[7] = PolyID & 0xFF;
Buffer[8] = ( PolyID >> 8 ) & 0xFF;
Buffer[9] = SH.pPolygones[PolyID].bType;
Buffer[10] = SH.pPolygones[PolyID].wCount & 0xFF;
Buffer[11] = ( SH.pPolygones[PolyID].wCount >> 8 ) & 0xFF;
#ifdef DEBUG
LOG("sendShadowPoly");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 12, m_bDeviceID ) );
};
bool protocolLGS_2D::setShadowPolyPoint( SHADOW & SH, uint16_t PolyID, uint16_t PointID ){
uint8_t Buffer[20];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_SET_HZ_DATA;
Buffer[SUB_CMD_IDX] = 8;
Buffer[5] = HZIT_CMD_SET_POLYGON_POINT;
Buffer[6] = 0;
Buffer[7] = PolyID & 0xFF;
Buffer[8] = ( PolyID >> 8 ) & 0xFF;
Buffer[9] = PointID & 0xFF;
Buffer[10] = ( PointID >> 8 ) & 0xFF;
Buffer[11] = SH.pPolygones[PolyID].pPoint[PointID].wX & 0xFF;
Buffer[12] = (SH.pPolygones[PolyID].pPoint[PointID].wX >> 8) & 0xFF;
Buffer[13] = SH.pPolygones[PolyID].pPoint[PointID].wY & 0xFF;
Buffer[14] = (SH.pPolygones[PolyID].pPoint[PointID].wY >> 8) & 0xFF;
#ifdef DEBUG
LOG("sendShadowPolyPoint");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 15, m_bDeviceID ) );
};
bool protocolLGS_2D::setShadowRayLine( SHADOW & SH, uint16_t RLID ){
uint8_t Buffer[16];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_SET_HZ_DATA;
Buffer[SUB_CMD_IDX] = 4;
Buffer[5] = HZIT_CMD_SET_RAY;
Buffer[6] = 0;
Buffer[7] = RLID & 0xFF;
Buffer[8] = ( RLID >> 8 ) & 0xFF;
Buffer[9] = SH.ray_lines[RLID].nCount & 0xFF;
Buffer[10] = ( SH.ray_lines[RLID].nCount >> 8 ) & 0xFF;
#ifdef DEBUG
LOG("setShadowRayLine");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 11, m_bDeviceID ) );
};
bool protocolLGS_2D::setShadowRay( SHADOW & SH, uint16_t RLID, uint16_t RayID ){
uint8_t Buffer[20];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_SET_HZ_DATA;
Buffer[SUB_CMD_IDX] = 9;
Buffer[5] = HZIT_CMD_SET_RAY_LINE;
Buffer[6] = 0;
Buffer[7] = RLID & 0xFF;
Buffer[8] = ( RLID >> 8 ) & 0xFF;
Buffer[9] = RayID & 0xFF;
Buffer[10] = ( RayID >> 8 ) & 0xFF;
Buffer[11] = SH.ray_lines[RLID].rays[RayID].bType;
Buffer[12] = SH.ray_lines[RLID].rays[RayID].nMin & 0xFF;
Buffer[13] = ( SH.ray_lines[RLID].rays[RayID].nMin >> 8 ) & 0xFF;
Buffer[14] = SH.ray_lines[RLID].rays[RayID].nMax & 0xFF;
Buffer[15] = ( SH.ray_lines[RLID].rays[RayID].nMax >> 8 ) & 0xFF;
#ifdef DEBUG
LOG("setShadowRay");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 16, m_bDeviceID ) );
};
bool protocolLGS_2D::setShadowDone( void ){
uint8_t Buffer[10];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_SET_HZ_DATA;
Buffer[SUB_CMD_IDX] = 0;
Buffer[5] = HZIT_CMD_SET_DONE;
Buffer[6] = 0;
#ifdef DEBUG
LOG("setShadowDone");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 7, m_bDeviceID ) );
};
bool protocolLGS_2D::getState( void ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
@ -301,41 +445,6 @@ bool protocolLGS_2D::getMode( void ){
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID));
};
bool protocolLGS_2D::setShadowPoly( simplePolygone *SP ){
if( m_oDataTransport == NULL ) return false;
if ( SP == NULL ){
uint8_t Buffer[16];
Buffer[CMD_IDX] = CMD_SET_HZ_POLY;
Buffer[SUB_CMD_IDX] = 0;
#ifdef DEBUG
LOG("clearShadowPoly");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 5, m_bDeviceID));
};
U8 counter;
U8 Buffer[PROTOCOL_PARSER_BUFFER_SIZE];
Buffer[CMD_IDX] = CMD_SET_HZ_POLY;
Buffer[SUB_CMD_IDX] = SP->count;
Buffer[SUB_CMD_IDX+1] = SP->color[0];
Buffer[SUB_CMD_IDX+2] = SP->color[1];
Buffer[SUB_CMD_IDX+3] = SP->color[2];
counter = SUB_CMD_IDX+4;
for( uint8_t i = 0; i < SP->count; i++ ){
uint16_t x,y;
x = SP->points[i].x();
y = SP->points[i].y();
Buffer[counter++] = ( x >> 8 ) & 0xFF;
Buffer[counter++] = x & 0xFF;
Buffer[counter++] = ( y >> 8 ) & 0xFF;
Buffer[counter++] = y & 0xFF;
};
#ifdef DEBUG
LOG("sendShadowPoly");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID ) );
};
bool protocolLGS_2D::setShadowStatus( bool Status, uint8_t MaskID ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
@ -347,7 +456,7 @@ bool protocolLGS_2D::setShadowStatus( bool Status, uint8_t MaskID ){
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID));
};
/*
bool protocolLGS_2D::setShadowTrace( vectorZoneMask *VM ){
if( VM == NULL ) return false;
if( m_oDataTransport == NULL ) return false;
@ -381,6 +490,41 @@ bool protocolLGS_2D::setShadowTrace( vectorZoneMask *VM ){
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID ) );
};
*/
bool protocolLGS_2D::setComSpeed( uint32_t spd ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_SET_COMM_SPEED;
Buffer[4] = spd & 0xFF;
Buffer[5] = ( spd >> 8 ) & 0xFF;
Buffer[6] = ( spd >> 16 ) & 0xFF;
Buffer[7] = ( spd >> 24 ) & 0xFF;
#ifdef DEBUG
LOG("setComSpeed");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 8, m_bDeviceID));
};
bool protocolLGS_2D::setDeviceAddress( uint8_t DeviceID, CSTR Serial ){
U8 Buffer[16];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_SET_ADDRESS;
Buffer[4] = DeviceID;
#ifdef DEBUG
LOG("setComSpeed");
#endif
if ( Serial ) {
uint8_t len = strlen(Serial);
Buffer[5] = len;
for( uint8_t i=0; i< len; i++ ) {
Buffer[6+i] = Serial[i];
};
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6+len, m_bDeviceID));
} else {
Buffer[5] = 0;
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 6, m_bDeviceID));
};
};
bool protocolLGS_2D::setDetectionProfile( uint8_t profile ){
U8 Buffer[16];
@ -395,24 +539,31 @@ bool protocolLGS_2D::setDetectionProfile( uint8_t profile ){
bool protocolLGS_2D::setParameters( PLGS_2D_PARAMETERS ptr, bool MASTER, uint8_t profile ){
U8 counter;
U8 Buffer[64];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_SET_PARAMETERS;
Buffer[CMD_IDX] = CMD_PARAMETERS;
if(MASTER) {
Buffer[4] = 0x80;
} else {
Buffer[4] = 0xC0;
};
counter = 5;
for( int i=0; i < sizeof( LGS_2D_PARAMETERS ); i++ ){
Buffer[counter] = *(((U8*)ptr)+i);
counter++;
};
Buffer[5] = ( ptr->nOrder >> 8 ) & 0xFF;
Buffer[6] = ptr->nOrder & 0xFF;
Buffer[7] = (ptr->nOffset >> 8) & 0xFF;
Buffer[8] = ptr->nOffset & 0xFF;
Buffer[9] = (ptr->nDelta >> 8) & 0xFF;
Buffer[10] = ptr->nDelta & 0xFF;
Buffer[11] = (ptr->nWidth >> 8) & 0xFF;
Buffer[12] = ptr->nWidth & 0xFF;
Buffer[13] = (ptr->nFlip >> 8) & 0xFF;
Buffer[14] = ptr->nFlip & 0xFF;
Buffer[15] = (ptr->nSun >> 8) & 0xFF;
Buffer[16] = ptr->nSun & 0xFF;
Buffer[17] = ptr->bSST & 0xFF;
#ifdef DEBUG
LOG("setParameters");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, counter, m_bDeviceID));
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 18, m_bDeviceID));
};
bool protocolLGS_2D::getSerialNumber( void ){
@ -445,6 +596,39 @@ bool protocolLGS_2D::getDetectionProfile( void ){
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, 4, m_bDeviceID));
};
bool protocolLGS_2D::sendFS_package( PFS_DATA pFSData ){
U8 Buffer[1024];
uint32_t nCnt = 1;
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_FS_SUB_PACKET;
switch ( pFSData->nCommand ) {
case FS_CMD_SEND_CMD: nCnt += sizeof(FS_SEND_CMD) + pFSData->sendcmd.nSubSize; break;
case FS_CMD_SEND_EVT: nCnt += sizeof(FS_SEND_EVT); break;
case FS_CMD_RECEIVE_CMD: nCnt += sizeof(FS_RECEIVE_CMD); break;
case FS_CMD_RECEIVE_EVT: nCnt += sizeof(FS_RECEIVE_EVT) + pFSData->receiveevt.nSubSize; break;
default: break;
};
for( int i = 0; i < nCnt; i++ ) Buffer[SUB_CMD_IDX + i] = ((uint8_t *)pFSData )[i];
#ifdef DEBUG
LOG("sendFS_package");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, SUB_CMD_IDX + nCnt, m_bDeviceID));
};
bool protocolLGS_2D::sendGF_package( uint8_t CMD, uint8_t cnt, uint8_t *Data ){
U8 Buffer[300];
if( m_oDataTransport == NULL ) return false;
Buffer[CMD_IDX] = CMD_GETFILE;
Buffer[SUB_CMD_IDX] = CMD;
Buffer[DATA_BEGIN_IDX] = cnt;
for( uint8_t i = 0; i < cnt; i ++ ) Buffer[DATA_BEGIN_IDX+1]=Data[i];
#ifdef DEBUG
LOG("sendGF_package");
#endif
return m_oDataTransport->sendData(Buffer, FinishUpPackage(Buffer, DATA_BEGIN_IDX+1+cnt, m_bDeviceID));
};
#undef SIZE_IDX
#undef DEV_ID_IDX
#undef CMD_IDX

22
lib/data/protocol/protocolLGS2D.h

@ -5,7 +5,9 @@
#include "protocolLGS_data.h"
#include "../../alg/lgs/detectorStructures.h"
#include "../../alg/lgs/mask.h"
#include "../../rgoose/rgooseTypes.h"
#define LEGACY_2ZEROS_BEFORE_PACKAGE
class protocolLGS_2D: public protocolParser{
private:
@ -32,22 +34,32 @@ class protocolLGS_2D: public protocolParser{
bool getParameters( bool MASTER = true );
bool getSerialNumber( void );
bool getShadowInfo( void );
bool getShadowPoly( uint8_t PolyID );
bool getShadowPoly( uint16_t PolyID );
bool getShadowPolyPoint( uint16_t PolyID, uint16_t PointID );
bool getShadowStatus( uint8_t MaskID = 0 );
bool getState( void );
bool getState2( void );
bool getVersionString( void );
bool getVoltage(void);
bool setComSpeed( uint32_t spd );
bool setDetectionProfile( uint8_t profile );
bool setDeviceID( uint8_t DeviceID ){ m_bDeviceID = DeviceID; return true; };
bool setDeviceAddress( uint8_t DeviceID, CSTR Serial = NULL );
bool setMode( U8 Mode );
bool setParameters( PLGS_2D_PARAMETERS ptr, bool MASTER = true, uint8_t profile = 0 );
bool setShadowPoly( simplePolygone *SP );
bool setShadowInfo( SHADOW & SH );
bool setShadowPoly( SHADOW & SH, uint16_t PolyID );
bool setShadowPolyPoint( SHADOW & SH, uint16_t PolyID, uint16_t PointID );
bool setShadowRayLine( SHADOW & SH, uint16_t RLID );
bool setShadowRay( SHADOW & SH, uint16_t RLID, uint16_t RayID );
bool setShadowDone( void );
bool setShadowStatus( bool Status, uint8_t MaskID = 0 );
bool setShadowTrace( vectorZoneMask *VM );
bool sendFile( CSTR FileName );
bool sendGF_package( uint8_t CMD, uint8_t cnt, uint8_t *Data );
bool sendFS_package( PFS_DATA pFSData );
};
#endif

6
lib/data/protocol/protocolLGS_data.h

@ -800,9 +800,11 @@ typedef enum E_HZ_INFO_TYPE{
HZIT_EVT_ERROR = 255,
}HZ_INFO_TYPE;
#define MAX_2D_SHADOW_RAY_LINES 360
typedef struct S_HZ_POINT{
U16 wX; // 0..4095
U16 wY; // 0..4095
int16_t wX; //-2047 .. 2047 // 0..4095
int16_t wY; //-2047 .. 2047 // 0..4095
}HZ_POINT, *LPHZ_POINT;
typedef struct S_HZ_LINE{

0
lib/data/protocol/protocolPTZ_APIX.cpp

11
lib/data/protocol/protocolPTZ_APIX.h

@ -0,0 +1,11 @@
#ifndef __PROTOCOL_PTZ_AXIS_APIX__
#define __PROTOCOL_PTZ_AXIS_APIX__
//https://www.axis.com/vapix-library/subjects/t10175981/section/t10036011/display
#endif

11
lib/data/protocol/protocolPTZ_ONVIF.cpp

@ -8,6 +8,7 @@ protocolPTZ_ONVIF::protocolPTZ_ONVIF( config_setting_t *Settings ) :protocolPTZ(
m_pLog = basicLogCollection::getInstance();
m_bLastCommandIssued = CMD_PTZ_NOOP;
m_pSettings = Settings;
m_bAuthMode = 0;
#ifdef USE_PONVIF
m_pOnVif = NULL;
m_pProfile = NULL;
@ -20,7 +21,7 @@ protocolPTZ_ONVIF::protocolPTZ_ONVIF( config_setting_t *Settings ) :protocolPTZ(
memset( m_pPassword, 0, MAX_CRED_LEN );
};
protocolPTZ_ONVIF::protocolPTZ_ONVIF( CSTR ip, CSTR username, CSTR password ) :protocolPTZ(), m_mInquiryMutex(){
protocolPTZ_ONVIF::protocolPTZ_ONVIF( CSTR ip, CSTR username, CSTR password, uint8_t AuthMode ) :protocolPTZ(), m_mInquiryMutex(){
m_pLog = basicLogCollection::getInstance();
m_bLastCommandIssued = CMD_PTZ_NOOP;
m_pSettings = NULL;
@ -34,6 +35,9 @@ protocolPTZ_ONVIF::protocolPTZ_ONVIF( CSTR ip, CSTR username, CSTR password ) :p
LOG( ip );
LOG( username );
LOG( password );
m_bAuthMode = AuthMode;
sprintf( m_pDeviceURI, "Auth Mode: [%d]", m_bAuthMode );
LOG( m_pDeviceURI );
sprintf( m_pDeviceURI, "http://%s/onvif/device_service", ip );
//strncpy( m_pDeviceURI, ip, MAX_PATH_LEN );
strncpy( m_pUser, username, MAX_CRED_LEN );
@ -65,6 +69,10 @@ bool protocolPTZ_ONVIF::setPassword( CSTR password ){
return true;
};
bool protocolPTZ_ONVIF::setAuthMode( uint8_t Mode ){
m_bAuthMode = Mode;
return true;
};
bool protocolPTZ_ONVIF::create( void ){
if (!protocolPTZ::create()) return false;
@ -96,6 +104,7 @@ bool protocolPTZ_ONVIF::create( void ){
m_pOnVif->setDeviceUri( m_pDeviceURI );
m_pOnVif->setUsername( m_pUser );
m_pOnVif->setPassword( m_pPassword );
m_pOnVif->setAuthMode( m_bAuthMode );
if( m_pOnVif->create() ){
m_pProfile = m_pOnVif->getProfiles()->at(0);
return true;

4
lib/data/protocol/protocolPTZ_ONVIF.h

@ -16,6 +16,7 @@ class protocolPTZ_ONVIF: public protocolPTZ{
char m_pUser[MAX_CRED_LEN];
char m_pPassword[MAX_CRED_LEN];
char m_pDeviceURI[MAX_PATH_LEN];
uint8_t m_bAuthMode;
#ifdef USE_PONVIF
pOnvif * m_pOnVif;
videoSourceProfile * m_pProfile;
@ -29,7 +30,7 @@ class protocolPTZ_ONVIF: public protocolPTZ{
basicMutex m_mInquiryMutex;
public:
explicit protocolPTZ_ONVIF( config_setting_t *Settings = NULL );
protocolPTZ_ONVIF( CSTR ip, CSTR username, CSTR password );
protocolPTZ_ONVIF( CSTR ip, CSTR username, CSTR password, uint8_t AuthMode = 0 );
virtual ~protocolPTZ_ONVIF();
virtual bool create( void );
#ifndef USE_PONVIF
@ -41,6 +42,7 @@ class protocolPTZ_ONVIF: public protocolPTZ{
bool setIPAddress( CSTR ip );
bool setUsername( CSTR username );
bool setPassword( CSTR password );
bool setAuthMode( uint8_t Mode );
};

66
lib/rgoose/rgooseCamera.cpp

@ -272,24 +272,21 @@ bool ARGUS_Camera::create(){
LOG( tB );
#endif
if( tSYS->beLocal() ){
m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z );
m_oPosition.setPositionXYZ( m_sCamData.x, m_sCamData.y, m_sCamData.z, 0 );
} else {
int Zone = tSYS->getUTMZone();
C3D_DECART tpp = tSYS->getXYZ();
m_oPosition.setPositionXYZ( tpp.x + m_sCamData.x, tpp.y + m_sCamData.y, tpp.z + m_sCamData.z, Zone );
#ifdef DEBUG
sprintf( tB, "Finalized Sensor Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() );
LOG( tB );
sprintf( tB, "Finalized Sensor Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() );
LOG( tB );
#endif
m_oPosition.setPositionXYZ( tpp.x + m_sCamData.x, tpp.y + m_sCamData.y, tpp.z + m_sCamData.z, tSYS->getUTMZone() );
};
m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
m_oPosition.updateMatrix();
#ifdef DEBUG
sprintf( tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
sprintf( tB, "Finalized Sensor Location: Lat:%.3f Lon:%.3f Alt:%.3f", m_oPosition.getLat(), m_oPosition.getLon(), m_oPosition.getAlt() );
LOG( tB );
sprintf( tB, "Finalized Sensor Location: x:%.3f y:%.3f z:%.3f", m_oPosition.getX(), m_oPosition.getY(), m_oPosition.getZ() );
LOG( tB );
sprintf( tB, "Orientation: x:%.3f y:%.3f z:%.3f", m_oPosition.getRotX_deg(), m_oPosition.getRotY_deg(), m_oPosition.getRotZ_deg() );
LOG( tB );
#endif
m_oPosition.setOrientationDeg( m_sCamData.x_rot , m_sCamData.y_rot, m_sCamData.z_rot );
if( m_pProtocol != NULL ){
LOG_ERROR("Cannot Start: Service Already Running!");
@ -399,7 +396,7 @@ bool ARGUS_Camera::create(){
#ifdef DEBUG
LOG("ONVIF");
#endif
m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.username, m_sCamData.password );
m_pProtocol = (protocolPTZ *) new protocolPTZ_ONVIF( m_sCamData.ip, m_sCamData.username, m_sCamData.password, m_sCamData.auth_mode );
if( m_pProtocol!=NULL ) {
if( !m_pProtocol->create() ) {
LOG_ERROR("Error Creating Proto!");
@ -814,7 +811,7 @@ void ARGUS_Camera::m_fThreadProc( void ){
LOG("INIT GO -1 -1 -1");
#endif
//setBusy( true );
if( m_pProtocol->goAbsolute( -1, -1, -1 ) ) setWM( CAM_WS_READY );
if( m_pProtocol->goAbsolute( -1, 0, -1 ) ) setWM( CAM_WS_READY );
//setBusy( false );
break;
};
@ -1065,6 +1062,9 @@ bool ARGUS_Camera::testFOV( C3D_DECART L ){
systemAnchor* tSystem = systemAnchor::getInstance();
if ( tSystem == NULL ) return false;
C3D_SPH_DEGREES SL;
#ifdef DEBUG
LOG("Test FOV local Decart coords");
#endif
if( !tSystem->convertToLocal( &m_oPosition, L, SL ) ) return false;
return testFOV( SL );
};
@ -1074,6 +1074,9 @@ bool ARGUS_Camera::testFOV( C3D_WGS84_LOC L ){
systemAnchor* tSystem = systemAnchor::getInstance();
if ( tSystem == NULL ) return false;
C3D_SPH_DEGREES SL;
#ifdef DEBUG
LOG("Test FOV WGS coords");
#endif
if( !tSystem->convertToLocal( &m_oPosition, L, SL ) ) return false;
return testFOV( SL );
};
@ -1081,6 +1084,9 @@ bool ARGUS_Camera::testFOV( C3D_WGS84_LOC L ){
bool ARGUS_Camera::testFOV( C3D_SPH_RADIANS L ){
//Local Coords
C3D_SPH_DEGREES SL;
#ifdef DEBUG
LOG("Test FOV local Spherical(rad) coords");
#endif
spherical2spherical( L, SL );
return testFOV( SL );
};
@ -1089,7 +1095,9 @@ bool ARGUS_Camera::testFOV( C3D_SPH_DEGREES SL ){
#ifdef DEBUG
char tB[128];
#endif
#ifdef DEBUG
LOG("Test FOV local Spherical(deg) coords");
#endif
switch ( m_sCamData.triggering_mode ) {
case CAM_TRIGGER_STRICT:{
if( SL.r > m_fMaxRange || SL.r < m_fMinRange ){
@ -1190,6 +1198,9 @@ bool ARGUS_Camera::lookAt( uint32_t TargetRefID, C3D_WGS84_LOC L ){
systemAnchor* tSystem = systemAnchor::getInstance();
if( tSystem == NULL ) return false;
C3D_SPH_DEGREES SL;
#ifdef DEBUG
LOG("Look at WGS coords!");
#endif
tSystem->convertToLocal(&m_oPosition, L, SL );
return lookAt(TargetRefID, SL );
};
@ -1198,12 +1209,18 @@ bool ARGUS_Camera::lookAt( uint32_t TargetRefID, C3D_DECART L ){
systemAnchor* tSystem = systemAnchor::getInstance();
if( tSystem == NULL ) return false;
C3D_SPH_DEGREES SL;
#ifdef DEBUG
LOG("Look at System Decart coords!");
#endif
tSystem->convertToLocal( &m_oPosition, L, SL );
return lookAt(TargetRefID, SL );
};
bool ARGUS_Camera::lookAt( uint32_t TargetRefID, C3D_SPH_RADIANS L ){
C3D_SPH_DEGREES SL;
#ifdef DEBUG
LOG("Look at spherical(rad) 2 spherical(deg) coords!");
#endif
spherical2spherical( L, SL );
return lookAt(TargetRefID, SL );
};
@ -1214,7 +1231,9 @@ bool ARGUS_Camera::lookAt( uint32_t TargetRefID, C3D_SPH_DEGREES L ){
//LOG( tB );
//sprintf( tB, "Cam GoTo %.3f %.3f %.3f", fP, fT, fZ );
//LOG( tB );
#ifdef DEBUG
LOG("Look at local spherical deg. coords!(final)");
#endif
//if( getWM() == CAM_WS_READY ){
// C3D_ORIENT_ONVIF LL;
// spherical2onvif( L, LL, m_fMaxRange, m_sCamData.pan_model, m_sCamData.pan_angles, m_sCamData.tilt_model, m_sCamData.tilt_angles );
@ -1265,12 +1284,15 @@ bool ARGUS_Camera::connectToStream( uint32_t id ){
if( tKM ) {
DBC_MEDIA_STREAM_DATA *tDATA = m_pDBC->getMediaStreamData( id );
if( tDATA ) {
LOG( tDATA->mrl_proto );
m_sMediaSource.mediaStreamId = id;
if( strncmp(tDATA->mrl_proto, "v4l2", 4) == 0 ) {
if (m_pSource != NULL) delete((videoAVLIBSource*)m_pSource);
m_pSource = (basicMediaSource *) new videoAVLIBSource(&m_sMediaSource);
} else {
if (m_pSource != NULL) delete((videoLIVE555Source*)m_pSource);
m_pSource = (basicMediaSource *) new videoLIVE555Source(&m_sMediaSource);
};
if( m_pSource != NULL ) delete( m_pSource );
m_pSource = new videoAVLIBSource(&m_sMediaSource);
if( m_pSource != NULL ) {
char tMRL[1024];
#ifdef DEBUG
@ -1311,7 +1333,7 @@ bool ARGUS_Camera::connectToStream( uint32_t id ){
};
};
LOG( tMRL );
if( m_pSource->_open( tMRL, false, -1, pix, tDATA->width, tDATA->height, true, tW, tH ) ){
if( m_pSource->_open( tMRL, false, -1.0f, pix, tDATA->width, tDATA->height, tW, tH ) ){
m_bSourceConnected = m_pSource->attachDestination( (argusModuleEmbedVideo*) tKM );
if ( !m_bSourceConnected ) {
delete( m_pSource );
@ -1356,7 +1378,7 @@ bool ARGUS_Camera::validateStream( void ){
if( m_bSourceConnected ) {
if( m_pSource ) {
if( m_pSource->isAttached() ){
if( !m_pSource->isFinished() ) return true;
if( m_pSource->getStatus() < MS_STOPED ) return true;
#ifdef DEBUG
LOG("Source is Finished!");
#endif

7
lib/rgoose/rgooseCamera.h

@ -21,6 +21,7 @@
#include "../components/base/basicMutex.h"
#include "../data/protocol/protocolPTZ.h"
#include "../data/media/video/videoAVLIBSource.h"
#include "../data/media/video/videoLive555AVLibSource.h"
#include "../components/base/basicEventHeap.h"
#include "rgooseDBConnector.h"
#include "rgooseNode.h"
@ -108,7 +109,7 @@ typedef struct S_CAM_ROI{
typedef std::vector<CAM_ROI *> vCAM_ROIS;
#define LOSE_INTERES_TIME_MS 10000
#define LOSE_INTERES_TIME_MS 2000
class ARGUS_Camera: public argusNetNode, public basicThread {
private:
@ -141,7 +142,9 @@ class ARGUS_Camera: public argusNetNode, public basicThread {
CAM_TASK_QUEUE m_qCAM_TASK;
basicMutex m_mQPROTECTOR;
videoAVLIBSource * m_pSource;
//videoAVLIBSource * m_pSource;
//videoLIVE555Source * m_pSource;
basicMediaSource * m_pSource;
uint32_t m_nRelativeMoveCounter;
uint8_t m_bRelativeMoveMatrix;
float m_fSpeedRise;

186
lib/rgoose/rgooseDBConnector.cpp

@ -732,23 +732,23 @@ bool argusDBC::getAllCamRecords( uint32_t SiteID, vectorCamRecords &VR ){
};
it = cArr->find("access_login");
if( it != cArr->end() ){
strncpy( tVal->username, it->second.c_str(), 16 );
strncpy( tVal->username, it->second.c_str(), 32 );
};
it = cArr->find("access_pass");
if( it != cArr->end() ){
strncpy( tVal->password, it->second.c_str(), 16 );
strncpy( tVal->password, it->second.c_str(), 32 );
};
it = cArr->find("uuid");
if( it != cArr->end() ){
strncpy( tVal->uuid, it->second.c_str(), CLOG );
strncpy( tVal->uuid, it->second.c_str(), 64 );
};
it = cArr->find("mac");
if( it != cArr->end() ){
strncpy( tVal->mac, it->second.c_str(), 16 );
strncpy( tVal->mac, it->second.c_str(), 17 );
};
it = cArr->find("ip");
if( it != cArr->end() ){
strncpy( tVal->ip, it->second.c_str(), 16 );
strncpy( tVal->ip, it->second.c_str(), 17 );
};
it = cArr->find("port");
if( it != cArr->end() ){
@ -1463,6 +1463,74 @@ DBC_FH_DATA *argusDBC::getFlyHunterData( uint32_t ID ){
};
return tVal;
};
bool argusDBC::fillShadow2D( uint32_t ID, SHADOW & SH ){
if( m_bIsConnected ){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT `lv`.`id`, `lm`.`layer`, `lm`.`status` FROM `lrf_mask_vertexes` `lv` LEFT JOIN `lrf_masks` `lm` ON (`lm`.`id` = `lv`.`mask_id`) WHERE `lm`.`sensor_id`=%d ORDER BY `lv`.`id`", ID );
LOG(tQBuf);
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
SH.m_nEnabled = 0xFFFFFFFF;
SH.m_nPolygonCount = result->size();
SH.pPolygones = (SHADOW_POLY *) calloc( SH.m_nPolygonCount, sizeof( SHADOW_POLY ) );
if ( SH.pPolygones ) {
Assoc * cArr;
for ( uint8_t idx = 0; idx < result->size(); idx++ ) {
Assoc::iterator it;
cArr = result->at(idx);
it = cArr->find("id");
if( it != cArr->end() ){
SH.pPolygones[idx].m_nDBID = atoi(it->second.c_str());
};
it = cArr->find("layer");
if( it != cArr->end() ){
SH.pPolygones[idx].bType = atoi(it->second.c_str());
};
it = cArr->find("status");
if( it != cArr->end() ){
SH.m_nEnabled &= ( it->second.c_str()[0] == 'E' )?0xFFFFFFFF:~(1<<SH.pPolygones[idx].bType);
};
sprintf(tQBuf, "SELECT * FROM `lrf_mask_vertex_points` WHERE `vertex_id`=%d ORDER BY `id`", SH.pPolygones[idx].m_nDBID );
LOG(tQBuf);
AAssoc *v_result = m_pDatabase->Query( tQBuf );
if( v_result!= NULL ) {
if( v_result->size() > 0 ) {
SH.pPolygones[idx].wCount = v_result->size();
SH.pPolygones[idx].pPoint = (HZ_POINT *) calloc( SH.pPolygones[idx].wCount, sizeof( HZ_POINT ) );
if(SH.pPolygones[idx].pPoint ) {
for ( uint32_t zdx =0; zdx < SH.pPolygones[idx].wCount; zdx++ ) {
cArr = v_result->at(zdx);
it = cArr->find("x");
if( it != cArr->end() ){
SH.pPolygones[idx].pPoint[zdx].wX = atoi(it->second.c_str());
};
it = cArr->find("y");
if( it != cArr->end() ){
SH.pPolygones[idx].pPoint[zdx].wY = atoi(it->second.c_str());
};
LOG("Point Added!");
};
} else {
LOG("No mem for Points!");
};
} else {
LOG("No Points!");
SH.pPolygones[idx].wCount = 0;
SH.pPolygones[idx].pPoint = NULL;
};
deleteResult( v_result );
};
};
};
};
deleteResult( result );
};
return true;
};
return false;
};
DBC_SITE_DATA *argusDBC::getSiteData( uint32_t ID ){
DBC_SITE_DATA * tVal = NULL;
@ -1733,6 +1801,58 @@ uint8_t argusDBC::getLRFDataStatus( uint32_t ID ){
return RetVal;
};
PLGS_2D_PARAMETERS argusDBC::getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master ){
PLGS_2D_PARAMETERS retVal = NULL;
if(m_bIsConnected){
char tQBuf[CTEXT];
AAssoc *result;
sprintf(tQBuf, "SELECT * FROM `lrf_detection_profiles` WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'%c'", lrfID, profileID,((master)?'1':'0') );
#ifdef DEBUG
LOG(tQBuf);
#endif
result = m_pDatabase->Query( tQBuf );
if( result!= NULL ) {
if( result->size() > 0 ) {
retVal = (PLGS_2D_PARAMETERS) malloc(sizeof(LGS_2D_PARAMETERS));
memset( retVal, 0, sizeof(LGS_2D_PARAMETERS));
Assoc *cArr;
Assoc::iterator it;
cArr = result->at(0);
it = cArr->find("order");
if( it != cArr->end() ){
retVal->nOrder = atoi(it->second.c_str());
};
it = cArr->find("offset");
if( it != cArr->end() ){
retVal->nOffset = atoi(it->second.c_str());
};
it = cArr->find("delta");
if( it != cArr->end() ){
retVal->nDelta = atoi(it->second.c_str());
};
it = cArr->find("flip");
if( it != cArr->end() ){
retVal->nFlip = atoi(it->second.c_str());
};
it = cArr->find("width");
if( it != cArr->end() ){
retVal->nWidth = atoi(it->second.c_str());
};
it = cArr->find("sst");
if( it != cArr->end() ){
retVal->bSST = atoi(it->second.c_str());
};
it = cArr->find("sun");
if( it != cArr->end() ){
retVal->nSun = atoi(it->second.c_str());
};
};
};
deleteResult( result );
};
return retVal;
};
CSTR argusDBC::getLRFDraw( uint32_t DBID ){
CSTR RetVal = NULL;
if(m_bIsConnected){
@ -2426,11 +2546,11 @@ DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){
if( it != cArr->end() ){
tVal->x_rot = atof( it->second.c_str() );
};
it = cArr->find("x_rot");
it = cArr->find("y_rot");
if( it != cArr->end() ){
tVal->y_rot = atof( it->second.c_str() );
};
it = cArr->find("x_rot");
it = cArr->find("z_rot");
if( it != cArr->end() ){
tVal->z_rot = atof( it->second.c_str() );
};
@ -2515,6 +2635,10 @@ DBC_CAM_DATA *argusDBC::getCamData( uint32_t ID ){
if( it != cArr->end() ){
tVal->triggering_mode = atoi( it->second.c_str() );
};
it = cArr->find("auth_mode");
if( it != cArr->end() ){
tVal->auth_mode = atoi( it->second.c_str() );
};
};
};
};
@ -3247,11 +3371,12 @@ uint32_t argusDBC::addResource( uint32_t NodeID, uint8_t type, CSTR devName, uin
uint32_t RetVal = 0;
if( m_bIsConnected ){
char tQBuf[2048];
//CSTR tMD5 = MD5String( devName );
//if( tMD5 ) {
//sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `md5`='%s', `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, tMD5, auxID, devName, auxID, devName );
sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, auxID, devName, auxID, devName );
// free( tMD5 );
sprintf( tQBuf, "%d:%d:%s", NodeID, type, devName );
CSTR tMD5 = MD5String( tQBuf );
if( tMD5 ) {
sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `md5`='%s', `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d", NodeID, type, tMD5, auxID, devName, auxID );
//sprintf( tQBuf, "INSERT INTO `resources` SET `node_id`=%d, `type`=%d, `aux_id`=%d, `device`='%s', `active`=1 ON DUPLICATE KEY UPDATE `active`=1, `aux_id`=%d, `device`='%s'", NodeID, type, auxID, devName, auxID, devName );
free( tMD5 );
#ifdef DEBUG_ALL
LOG(tQBuf);
#endif
@ -3259,7 +3384,7 @@ uint32_t argusDBC::addResource( uint32_t NodeID, uint8_t type, CSTR devName, uin
if( RetVal == 0 ) {
RetVal = getResourceID( NodeID, type, auxID );
};
//};
};
};
return RetVal;
};
@ -3678,7 +3803,7 @@ uint32_t argusDBC::addLocalWiFi( uint32_t NIF_ID, ARGUS_WIFI_MODE mode, CSTR SSI
};
uint32_t argusDBC::addLRFMask( uint32_t devID, uint8_t lrfID, uint8_t layerID ){
uint32_t RetVal = 0;
uint32_t RetVal = 0;
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "INSERT INTO `lrf_masks` SET `sensor_id`=%d, `lrf_id`=%d, `layer`=%d ON DUPLICATE KEY UPDATE `id`=`id`",
@ -3715,7 +3840,7 @@ uint32_t argusDBC::addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, ui
return RetVal;
};
bool argusDBC::addLRFMaskPolygonePoint( uint32_t polyID, uint16_t x, uint16_t y ){
bool argusDBC::addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y ){
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
sprintf( tQBuf, "INSERT INTO `lrf_mask_vertex_points` SET `vertex_id`=%d, `x`=%d, `y`=%d",
@ -3949,6 +4074,7 @@ bool argusDBC::addDeviceDraw( uint32_t DBID, uint8_t type, uint8_t lrf, void *th
m_pDatabase->SilentQuery( tQBuf );
sprintf( tQBuf, "INSERT INTO lrf_draw(node_id,ts,lrf_id,type,size,data) VALUES(%d,NOW(),%d,%d,%d,'%s')", DBID, lrf, type, th_size, tPData );
m_pDatabase->SilentQuery( tQBuf );
LOG( "Inserted Draw OK!" );
free( tQBuf );
rVal = true;
} else {
@ -4040,7 +4166,9 @@ bool argusDBC::updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, boo
if( m_bIsConnected ) {
char tQBuf[MAX_PATH_LEN];
if( master ) {
sprintf( tQBuf, "UPDATE `lrf_detection_profiles` SET `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'1'",
sprintf( tQBuf, "INSERT INTO `lrf_detection_profiles` SET `aux_id`=%d, `profile_id`=%d, `master`=b'1', `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d ON DUPLICATE KEY UPDATE `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d",
lrfID,
profileID,
nOrder,
nOffset,
nDelta,
@ -4050,10 +4178,19 @@ bool argusDBC::updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, boo
nSun,
GP,
spikes,
lrfID,
profileID );
nOrder,
nOffset,
nDelta,
nFlip,
nWidth,
bSST,
nSun,
GP,
spikes );
} else {
sprintf( tQBuf, "UPDATE `lrf_detection_profiles` SET `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d WHERE `aux_id`=%d AND `profile_id`=%d AND `master`=b'0'",
sprintf( tQBuf, "INSERT INTO `lrf_detection_profiles` SET `aux_id`=%d, `profile_id`=%d, `master`=b'0', `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d ON DUPLICATE KEY UPDATE `order`=%d, `offset`=%d, `delta`=%d, `flip`=%d, `width`=%d, `sst`=%d, `sun`=%d, `gp`=%d, `spikes`=%d",
lrfID,
profileID,
nOrder,
nOffset,
nDelta,
@ -4063,8 +4200,15 @@ bool argusDBC::updateLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, boo
nSun,
GP,
spikes,
lrfID,
profileID );
nOrder,
nOffset,
nDelta,
nFlip,
nWidth,
bSST,
nSun,
GP,
spikes );
};
#ifdef DEBUG_ALL
LOG(tQBuf);

4
lib/rgoose/rgooseDBConnector.h

@ -42,7 +42,7 @@ class argusDBC{
bool addLRFDraw( uint32_t DBID, uint32_t SIZE, CSTR ID, uint8_t kID =0, uint8_t type = 0, bool rendered = false );
uint32_t addLRFMask( uint32_t devID, uint8_t lrfID = 0, uint8_t layerID = 0 );
uint32_t addLRFMaskPolygone( uint32_t maskID, uint8_t r, uint8_t g, uint8_t b );
bool addLRFMaskPolygonePoint( uint32_t polyID, uint16_t x, uint16_t y );
bool addLRFMaskPolygonePoint( uint32_t polyID, int16_t x, int16_t y );
//bool addIPCam( uint32_t SiteID, resultWoWo *tPtr );
bool addIPCam( uint32_t SiteID, OBSERVER_RESULT *tPtr );
@ -103,6 +103,7 @@ class argusDBC{
//bool getLastEvents( vectorEventRecords &VR, uint32_t tss, uint32_t tsms );
DBC_LRF_DATA * getLRFData( uint32_t ID );
uint8_t getLRFDataStatus( uint32_t ID );
PLGS_2D_PARAMETERS getLRFDetectionProfile( uint32_t lrfID, uint8_t profileID, bool master );
CSTR getLRFDraw( uint32_t DBID );
uint32_t getLRFMaskID( uint32_t deviceID, uint8_t lrfID = 0, uint8_t layer = 0 );
DBC_MEDIA_STREAM_DATA * getMediaStreamData( uint32_t ID );
@ -134,6 +135,7 @@ class argusDBC{
DBC_UART_DATA * getUartData( uint32_t UartID );
uint32_t getUartID( uint32_t NodeID, uint8_t Type, CSTR path );
uint32_t getWiFi_ID( uint32_t nif_id );
bool fillShadow2D( uint32_t ID, SHADOW & SH );
void deleteCamCapPicture( uint32_t PicID );
void deleteNode( uint32_t NodeID );

10
lib/rgoose/rgooseHardwareManager.cpp

@ -1091,28 +1091,28 @@ argusHardwareResource *argusHardwareManager::requestResource( ARGUS_HARDWARE_PRO
DBC_INT_LIST *argusHardwareManager::requestResourcesByType( ARGUS_HARDWARE_PROVIDERS type ){
DBC_INT_LIST *RetVal = NULL;
#ifdef DEBUG_EXTRA
#ifdef DEBUG
char tBuffer[128];
sprintf( tBuffer, "Requested Resource type: %d", type );
LOG( tBuffer );
#endif
m_mVectorProtector.lock();
if( m_vResources.size() ) {
#ifdef DEBUG_EXTRA
#ifdef DEBUG
LOG("Have Some Resources!");
#endif
RetVal = new DBC_INT_LIST();
if( RetVal ) {
#ifdef DEBUG_EXTRA
#ifdef DEBUG
LOG("RetVal Created!");
#endif
for( VECTOR_HW_RESOURCES::iterator idx = m_vResources.begin(); idx < m_vResources.end(); idx++ ) {
#ifdef DEBUG_EXTRA
#ifdef DEBUG
sprintf( tBuffer, "Have Resource type: %d", (*idx)->getHardwareType() );
LOG( tBuffer );
#endif
if( (*idx)->getProviderType() == type ) {
#ifdef DEBUG_EXTRA
#ifdef DEBUG
LOG("Matched!");
#endif
RetVal->push_back((*idx)->getDbId());

5
lib/rgoose/rgooseHardwareResourceSerialProvider.cpp

@ -1,3 +1,4 @@
//#define DEBUG_EXTRA
#include "rgooseHardwareResourceSerialProvider.h"
#include "../data/protocol/protocol.h"
#include "rgooseDBConnector.h"
@ -429,11 +430,13 @@ bool argusHardwareResourceSerialProvider::create_HW(){
//m_iFID = open( DevicePath, O_RDWR| O_NONBLOCK | O_NDELAY );
if( strstr( m_sUartData.path, "USB" ) == NULL ){
LOG("MANUAL RTS CTL");
m_bManualRTS = true;
wiringPiSetup();
//Set RTS Pin
pinMode( 0, OUTPUT );
} else {
LOG("NO RTS CTL");
m_bManualRTS = false;
};
@ -950,7 +953,7 @@ int argusHardwareResourceSerialProvider::recptBlock( unsigned char *Buffer, int
return -1;
};
}
#ifdef DEBUG_EXTRA
#ifdef DEBUG
else LOG( "Port is not Ready to Receive" )
#endif
;

4
lib/rgoose/rgooseHardwareResourceSerialProvider.h

@ -20,8 +20,8 @@
#endif
#ifdef DEBUG
//#define DEBUG_SERIAL_COMMUNICATION
#ifdef DEBUG_EXTRA
#define DEBUG_SERIAL_COMMUNICATION
#endif
#ifndef MAXIMAL_SOCKET_PACKET_LENGTH

17
lib/rgoose/rgooseKernel.cpp

@ -15,6 +15,7 @@
#include <sys/types.h>
#include <sys/sysinfo.h>
#include <sys/statvfs.h>
#include <time.h>
#include "../data/json/json_tool.h"
#include <strings.h>
@ -471,11 +472,10 @@ void argusKernel::m_fThreadProc( void ){
};
case ARGUS_CMD_KRNL_DELNODE:{
uint32_t tNodeID = atoi( tCMD->PARAM );
if( tNodeID == 0 ) break;
if (tNodeID == 0) break;
if( m_pNodeFactory == NULL) break;
// Turn Off Node
m_pNodeFactory->deleteNode( tNodeID );
break;
};
case ARGUS_CMD_KRNL_RESET_SITE:{
@ -495,6 +495,18 @@ void argusKernel::m_fThreadProc( void ){
m_bExitCause = 4; // Go -> Detect Hardware in BACKEND
break;
};
case ARGUS_CMD_KRNL_SYNC_TIME:{
uint32_t uts = atoi( tCMD->PARAM );
if( uts ){
time_t ts = (time_t)uts;
if( stime( &ts ) == 0 ){
// Restert Server;
m_bThreadStatus = TH_ENDED;
m_bExitCause = 0;
};
};
break;
};
case ARGUS_CMD_KRNL_SYSTEM_TASK:{
try{
Json::Value root;
@ -1009,6 +1021,7 @@ void argusKernel::dispatchEvent( EVENT_CONTAINER *Evt ){
};
break;
};
case EVT_ROI_ACTIVE:
case EVT_TARGET_2D_BLACK:
case EVT_TARGET_2D_WHITE:{
TARGET_DATA *tDATA = (TARGET_DATA *)Evt->m_pEvtData;

1
lib/rgoose/rgooseKernel.h

@ -100,6 +100,7 @@ struct serial_struct {
#define ARGUS_CMD_KRNL_RESET_SITE 245
#define ARGUS_CMD_KRNL_RESTART 250
#define ARGUS_CMD_KRNL_PNP 251
#define ARGUS_CMD_KRNL_SYNC_TIME 252
#define ARGUS_CMD_KRNL_SHUTDOWN 255
#define ARGUS_CMD_KRNL_SYSTEM_TASK 120
#define ARGUS_CMD_MODULES_RELOAD 60

124
lib/rgoose/rgooseModuleOnvifObserver.cpp

@ -125,7 +125,7 @@ void argusModuleOnvifObserver::m_fThreadProc(){
bool bOptVal;
int bOptLen;
int iOptLen;
uint8_t bCounterTO = 100; // 1 second
uint16_t bCounterTO = 600; // 3 second
char rBuffer[MAX_BUFF_SIZE];
#ifdef DEBUG
char tB[128];
@ -143,9 +143,11 @@ void argusModuleOnvifObserver::m_fThreadProc(){
struct sockaddr src_addr;
socklen_t addrlen = sizeof( src_addr );
RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, &src_addr, &addrlen );
sprintf( tB, "(%d){%d}MSG[%d] from %s", bCounterTO, socketFD, RetVal, inet_ntoa(((struct sockaddr_in *)&src_addr)->sin_addr) );
LOG( tB );
#else
if ( RetVal > -1 ) {
sprintf(tB, "(%d){%d}MSG[%d] from %s", bCounterTO, socketFD, RetVal, inet_ntoa(((struct sockaddr_in *)&src_addr)->sin_addr));
LOG( tB );
};
#else //http://192.168.200.127/axis-cgi/com/ptz.cgi?info=1&camera=1
RetVal = recvfrom( socketFD, rBuffer, MAX_BUFF_SIZE, 0, NULL, NULL );
#endif
if ((RetVal == -1) && /*(errno != EAGAIN) &&*/ (errno != EINTR) && (errno != EWOULDBLOCK)) {
@ -155,6 +157,7 @@ void argusModuleOnvifObserver::m_fThreadProc(){
continue; // Error ocured but continue to next address
};
if( RetVal < 1 ){
//LOG("SLEEP");
SLEEP(DEFAULT_THREAD_SLEEP_TIME);
continue; // No Data - wait to next time
};
@ -171,6 +174,7 @@ void argusModuleOnvifObserver::m_fThreadProc(){
LOG("Probe Finished with unrecognized data!");
#endif
};
continue; //To Fetch Another responces
} else {
#ifdef DEBUG
LOG("Probe Finished By Timeout!");
@ -185,13 +189,13 @@ void argusModuleOnvifObserver::m_fThreadProc(){
m_bProbeIsActive = false;
//Sleep 5 minutes if done all scans
if ( m_bCurrentNIF == 0 ){
for( int i=30000; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
for( int i=12000; i, m_bThreadStatus < TH_ENDED; i-- ) SLEEP( DEFAULT_THREAD_SLEEP_TIME );
};
} else {
// start new probe;
m_mNIFMUTEX.lock();
if ( m_vNIFIPS.size() ) {
#ifdef DEBUG_EXTRA
#ifdef DEBUG
sprintf( tB, "Starting probe on %s address", m_vNIFIPS.at(m_bCurrentNIF) );
LOG( tB );
#endif
@ -203,9 +207,97 @@ void argusModuleOnvifObserver::m_fThreadProc(){
r_address.sin_addr.s_addr = inet_addr(m_vNIFIPS.at(m_bCurrentNIF));
bOptVal = true;
#ifdef DEBUG_EXTRA
LOG("Sending Probe Request");
LOG("Set Broadcast Flag");
#endif
RetVal = setsockopt( socketFD, SOL_SOCKET, SO_BROADCAST, (char*)&bOptVal, bOptLen );
struct group_req req;
req.gr_interface = 0;
memcpy( &req.gr_group, &r_address, sizeof(r_address));
RetVal = setsockopt( socketFD, IPPROTO_IP, MCAST_JOIN_GROUP, (char*)&req, sizeof(req) );
/*
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/in.h>
#include <linux/if_ether.h>
#include <net/if.h>
#include <errno.h>
// Join multicast group, support both IPv4 and IPv6. * @param sockfd socket descripter * @param grp sockaddr * @param grplen sockaddr length * @return 0:on success; non-zero:on failed
static int mcast_join(int sockfd, const struct sockaddr *grp, socklen_t grplen){
#if MCAST_JOIN_GROUP
struct group_req req;
req.gr_interface = 0;
if (grplen > sizeof(req.gr_group)) {
errno = EINVAL;
return -1;
}
memcpy(&req.gr_group, grp, grplen);
return (setsockopt(sockfd, IPPROTO_IP, MCAST_JOIN_GROUP, &req, sizeof(req)));
#else
switch (grp->sa_family) {
case AF_INET: {
struct ip_mreq mreq;
struct ifreq ifreq;
memcpy(&mreq.imr_multiaddr, &((const struct sockaddr_in *) grp)->sin_addr, sizeof(struct in_addr));
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
return (setsockopt(sockfd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
&mreq, sizeof(mreq)));
}
#ifdef IPV6
#ifndef IPV6_JOIN_GROUP // APIv0 compatibility
#define IPV6_JOIN_GROUP IPV6_ADD_MEMBERSHIP
#endif
case AF_INET6: {
struct ipv6_mreq mreq6;
memcpy(&mreq6.ipv6mr_multiaddr, &((const struct sockaddr_in6 *) grp)->sin6_addr, sizeof(struct in6_addr));
mreq6.ipv6mr_interface = 0;
return (setsockopt(sockfd, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq6, sizeof(mreq6)));
}
#endif
default:
errno = EAFNOSUPPORT;
return -1;
}
#endif
};
int main(int argc, char **argv){
int fd = socket(AF_INET, SOCK_DGRAM, 0);
struct sockaddr_in grp;
bzero(&grp, sizeof(grp));
grp.sin_family = AF_INET;
grp.sin_addr.s_addr = inet_addr("224.0.0.1");;
if (mcast_join(fd, (struct sockaddr*)(&grp), sizeof(grp)))
perror("Join multicast group failed");
}
*/
//The broadcast address to be used may be determined by issuing an ioctl() with the SIOCGIFBRDADDR request.
if ( RetVal > -1 ) {
LOG_ERROR("Setting Socked as Broadcasted Error!");
};
//
struct sockaddr_in tServerAddr;
memset( &tServerAddr, 0, sizeof(tServerAddr) );
tServerAddr.sin_family = AF_INET; // IPv4
tServerAddr.sin_addr.s_addr = inet_addr( "0.0.0.0" ); //INADDR_ANY;
tServerAddr.sin_port = htons(rand( 20000, 40000));
// Bind the socket with the server address
RetVal = bind( socketFD, (const struct sockaddr *)&tServerAddr, sizeof(tServerAddr));
if ( RetVal > -1 ) {
LOG_ERROR("Bind Socked Error!");
};
#ifdef DEBUG_EXTRA
LOG("Sending Probe Request");
#endif
RetVal = sendto( socketFD, send_buff, strlen(send_buff), 0, (struct sockaddr*)&r_address, sizeof(struct sockaddr_in));
if ( RetVal > -1 ) {
#ifdef DEBUG_EXTRA
@ -219,7 +311,7 @@ void argusModuleOnvifObserver::m_fThreadProc(){
u_long val = 1;
ioctlsocket( socketFD, FIONBIO, &val );//none block
#endif
bCounterTO = 100;
bCounterTO = 600;
m_bProbeIsActive = true;
} else {
#ifdef DEBUG
@ -270,11 +362,23 @@ bool argusModuleOnvifObserver::reloadSettings(){
#endif
argusHardwareManager *tHWM = m_pKernel->getHardwareManager();
if( tHWM != NULL ) {
#ifdef DEBUG
LOG("Check IPS 11");
#endif
DBC_INT_LIST *rIDS = tHWM->requestResourcesByType( ARGUS_HARDWARE_PROVIDER_NETWORK );
if( rIDS != NULL ) {
#ifdef DEBUG
LOG("Check IPS 22");
#endif
for( DBC_INT_LIST::iterator idx = rIDS->begin(); idx < rIDS->end(); idx++ ){
#ifdef DEBUG
LOG("Check IPS 33");
#endif
argusHardwareResourceNetwork *tRES = (argusHardwareResourceNetwork *) tHWM->requestResource( ARGUS_HARDWARE_PROVIDER_NETWORK, *idx );
if( tRES != NULL ) {
#ifdef DEBUG
LOG("Have NIF Resource");
#endif
CSTR BC = tRES->getBroadcast();
if( BC!= NULL ) {
#ifdef DEBUG
@ -315,13 +419,13 @@ bool argusModuleOnvifObserver::reloadSettings(){
#endif
CSTR tBC = (CSTR) malloc(16);
if ( tBC ) {
strncpy(tBC, HTTPMU_HOST_ADDRESS, 16);
sprintf(tBC, HTTPMU_HOST_ADDRESS );
m_mNIFMUTEX.lock();
m_vNIFIPS.push_back( tBC );
m_mNIFMUTEX.unlock();
} else {
LOG_ERROR("Malloc Error!");
};
};
return true;
};

1161
lib/rgoose/rgooseNode2D.cpp
File diff suppressed because it is too large
View File

85
lib/rgoose/rgooseNode2D.h

@ -15,8 +15,8 @@
#include "../data/protocol/protocolLGS2D.h"
#define LGS_DEFAULT_SLEEP_TIME 333
#define LGS_ALERT_SLEEP_TIME 30
#define LGS_DEFAULT_TO_COUNTER 30
#define LGS_ALERT_SLEEP_TIME 1
#define LGS_DEFAULT_TO_COUNTER 2
#define LGS_INITIAL_FLIPS 8
#define ANODE_WM_2D_BEFORE_START 0
@ -24,43 +24,69 @@
#define ANODE_WM_2D_CONNECT 2
#define ANODE_WM_2D_WAIT_CONNECT 3
#define ANODE_WM_2D_SET_INIT_MODE 4
#define ANODE_WM_2D_WAIT_INIT_MODE 5
#define ANODE_WM_2D_GET_SERIAL_NUM 6
#define ANODE_WM_2D_WAIT_SERIAL_NUM 7
#define ANODE_WM_2D_GET_VERSION 8
#define ANODE_WM_2D_WAIT_VERSION 9
#define ANODE_WM_2D_GET_DETECTION_PROFILE 10
#define ANODE_WM_2D_WAIT_DETECTION_PROFILE 11
#define ANODE_WM_2D_GET_MASTER_PARAM 12
#define ANODE_WM_2D_WAIT_MASTER_PARAM 13
#define ANODE_WM_2D_GET_SLAVE_PARAM 14
#define ANODE_WM_2D_WAIT_SLAVE_PARAM 15
#define ANODE_WM_2D_SET_BORDER_MODE 16
#define ANODE_WM_2D_WAIT_BORDER_MODE 17
#define ANODE_WM_2D_GET_FAST_DRAW 18
#define ANODE_WM_2D_WAIT_FAST_DRAW 19
#define ANODE_WM_2D_SET_DETECTION_MODE 20
#define ANODE_WM_2D_WAIT_DETECTION_MODE 21
#define ANODE_WM_2D_SET_FILESYSTEM_MODE 22
#define ANODE_WM_2D_WAIT_FILESYSTEM_MODE 23
#define ANODE_WM_2D_FS_TRANSFER_MODE 24
#define ANODE_WM_2D_GET_MASK_INFO 16
#define ANODE_WM_2D_SET_MASK_INFO 18
#define ANODE_WM_2D_SET_BORDER_MODE 32
#define ANODE_WM_2D_GET_FAST_DRAW 34
#define ANODE_WM_2D_SET_DETECTION_MODE 36
#define ANODE_WM_2D_SET_FILESYSTEM_MODE 38
#define ANODE_WM_2D_FS_TRANSFER_MODE 39
#define ANODE_WM_2D_SET_SHADOW_DONE 40
#define ANODE_WM_2D_GET_SHADOW_POLY_INFO 41
#define ANODE_WM_2D_GET_SHADOW_POLY_POINT 43
#define ANODE_WM_2D_SET_SHADOW_POLY_INFO 45
#define ANODE_WM_2D_SET_SHADOW_POLY_POINT 47
#define ANODE_WM_2D_SET_SHADOW_RAY_LINE 48
#define ANODE_WM_2D_SET_SHADOW_RAY 49
#define ANODE_WM_2D_SET_GETFILE_MODE 50
#define ANODE_WM_2D_SEND_GETFILE_MODE 52
#define ANODE_WM_2D_SET_MASTER_PARAM 58
#define ANODE_WM_2D_SET_SLAVE_PARAM 59
#define ANODE_WM_2D_ISSUE_FULL_RESET 64
#define ANODE_WM_2D_WAIT_FULL_RESET 65
#define ANODE_WM_2D_ISSUE_RESET 66
#define ANODE_WM_2D_WAIT_RESET 67
#define ANODE_WM_2D_PING 128
#define ANODE_WM_2D_PONG 129
#define ANODE_WM_2D_SLEEP_AND_RECONNECT 130
#define ANODE_WM_2D_WAIT_DEVICE_REPLAY 254
#define ANODE_WM_2D_WAIT_CHECK_REPLAY 255
#define ANODE_2D_MAX_DRAW_ANGLES 6000
typedef struct S_SHADOW_IO_HELPER{
uint16_t m_nCurrentPolygon;
uint16_t m_nCurrentPoint;
uint16_t m_nCurrentRayLine;
uint16_t m_nCurrentRay;
}SHADOW_IO_HELPER;
typedef struct S_GETFILE_IO_HELPER{
uint32_t fileSize;
uint32_t index;
char destName[33];
char sourceName[33];
uint8_t state;
FILE * fd;
uint8_t data[250];
uint8_t data_size;
}GETFILE_IO_HELPER;
typedef struct S_TEST_POINT{
float x;
float y;
}TEST_POINT;
class ARGUS_2DSensor: public argusNodeSensor, public basicThread, public protocolLGS_2D{
private:
@ -71,12 +97,13 @@ class ARGUS_2DSensor: public argusNodeSensor, public basicThread, public protoco
uint8_t m_bPortType;
basicTransport * m_pPort;
uint8_t m_bWM;
uint8_t m_bOWM;
basicMutex m_mWMProtector;
uint8_t m_bDeviceWM;
uint32_t m_nSleepTime;
uint16_t m_bTimeOutCounter;
uint8_t m_bInitialFlips;
uint16_t m_nCurrentAngle;
uint16_t m_nCurrentAngle;
uint8_t m_bDrawType;
uint8_t m_bOpRetryCnt;
uint32_t m_nProcessingCmdId;
@ -88,6 +115,11 @@ class ARGUS_2DSensor: public argusNodeSensor, public basicThread, public protoco
char m_sCurrentFile[MAX_PATH];
uint32_t m_nUploadID;
uint8_t m_nActiveDetectionProfile;
//Shadow
SHADOW_IO_HELPER m_sShadowHelper;
SHADOW m_sShadow;
//GetFile
GETFILE_IO_HELPER m_sGetFileHelper;
TARGET_DATA * prepareTargetData( uint16_t AZ, uint16_t RANGE, uint32_t WIDTH, uint8_t LRFID = 0 );
//void saveRawDrawData( uint16_t alngles );
@ -95,6 +127,13 @@ class ARGUS_2DSensor: public argusNodeSensor, public basicThread, public protoco
void setWM( uint8_t MD );
void cleanupDeviceStructures();
CSTR generateSettingFile();
void cleanShadowStructs();
bool PtInPolygons( TEST_POINT& point, uint8_t F );
bool PtInPolygon( SHADOW_POLY& Poly, TEST_POINT& point );
bool rasterizeShadow();
#ifdef DEBUG_EXTRA
void makeShadowPic( CSTR picname );
#endif
protected:
virtual bool packetHandler( protocolPackage *Package );
virtual void m_fThreadProc( void );

20
lib/rgoose/rgooseNodeSensor.cpp

@ -43,8 +43,10 @@ argusNodeSensor::~argusNodeSensor(){
uint8_t *argusNodeSensor::create2dDraw( uint32_t *out_size, uint32_t *th_data, size_t th_size, uint16_t max_digital, int radial_shift, CSTR tpl, bool byMinimum ){
uint8_t *RetVal = NULL;
*out_size = 0;
LOG("C2DD");
if( th_data != NULL && th_size != 0 ) {
if ( fileExist( tpl ) ) {
LOG(tpl);
cv::Mat tImage = cv::imread( tpl, cv::IMREAD_UNCHANGED );
int psize = th_size / ( sizeof( uint32_t ));
float stp = 2.0f * ( M_PI / (float) psize );
@ -53,7 +55,7 @@ uint8_t *argusNodeSensor::create2dDraw( uint32_t *out_size, uint32_t *th_data, s
int x0 = (tImage.cols >> 1);
int y0 = (tImage.rows >> 1);
float maxR = ((float) x0 ) * 0.98f;
LOG("C2DD - Start");
cv::Point pts[(psize << 1)];
cv::Point ptt[(psize+2)];
@ -103,11 +105,23 @@ uint8_t *argusNodeSensor::create2dDraw( uint32_t *out_size, uint32_t *th_data, s
ppz[0] = ptt;
npz[0] = ( rpt - 1);
LOG("C2DD -> draw finish");
cv::Mat ttMOMO = cv::imread( tpl, cv::IMREAD_UNCHANGED );
LOG("C2DD -> read tpl2 finish");
cv::fillPoly( ttMOMO, ppt, npp, 1, cv::Scalar( 0, 128, 255, 50 ), cv::LINE_8 );
cv::fillPoly( ttMOMO, ppz, npz, 1, cv::Scalar( 0, 0, 0, 100 ), cv::LINE_8 );
LOG("C2DD -> poly1 finish");
//try {
// cv::fillPoly(ttMOMO, ppz, npz, 1, cv::Scalar(0, 0, 0, 100), cv::LINE_8);
// LOG("C2DD -> poly2 finish");
//} catch ( cv::Exception& e ) {
// LOG("C2DD -> poly2 Error!");
// LOG( e.what() );
//};
cv::addWeighted( tImage, 0.5, ttMOMO, 0.5, 0.0, tImage );
LOG("C2DD -> add img finish");
ttMOMO.release();
LOG("C2DD -> img release finish");
vector<int> compression_params;
compression_params.push_back( cv::IMWRITE_PNG_COMPRESSION );
compression_params.push_back(9);
@ -116,7 +130,7 @@ uint8_t *argusNodeSensor::create2dDraw( uint32_t *out_size, uint32_t *th_data, s
vector<uchar> buf;
cv::imencode( ".png", tImage, buf, compression_params );
tImage.release();
LOG("C2DD -> compress finish");
*out_size = buf.size();
RetVal = (uint8_t *) malloc( *out_size );
if( RetVal ) {

5
lib/rgoose/rgooseNodeSensor.h

@ -62,6 +62,11 @@
#define NODE_CMD_GET_DEVICE_DRAW 100
#define NODE_CMD_ROI_ACTIVE 65
#define NODE_CMD_ALARM 66
#define NODE_CMD_UPDATE_SHADOW 67
#define NODE_CMD_UPLOAD_SETTINGS_0 80
#define NODE_CMD_UPLOAD_SETTINGS_1 81
#define NODE_CMD_UPLOAD_SETTINGS_2 82
#define NODE_CMD_UPLOAD_SETTINGS_3 83
class argusNodeSensor: public argusNetNode{
private:

29
lib/rgoose/rgooseTypes.h

@ -16,6 +16,8 @@
#include <winsock.h>
#include <iostream>
#endif
#include "../alg/lgs/detectorStructures.h"
#include "../data/protocol/protocolLGS_data.h"
#define ONE_DAY_HISTORY 86400
#define ONE_HOUR_HISTORY 3600
@ -237,6 +239,7 @@ typedef struct S_DBC_CAM_DATA{
char onvif_ctrl[251];
char ptz_token[65];
uint8_t triggering_mode;
uint8_t auth_mode;
}DBC_CAM_DATA;
typedef struct S_DBC_NETWORK_DATA{
@ -628,5 +631,31 @@ typedef struct S_DBC_SNAPSHOT_DATA{
#define ARGUS_NODE_STATUS_TROUBLE 3
#define ARGUS_NODE_STATUS_ALARM 4
typedef struct S_SHADOW_RAY{
uint8_t bType;
uint16_t nMin;
uint16_t nMax;
} SHADOW_RAY;
typedef struct S_SHADOW_RAY_LINE{
uint16_t nCount;
SHADOW_RAY * rays;
}SHADOW_RAY_LINE;
typedef struct S_SHADOW_POLY{
uint8_t bType;
uint16_t wCount;
HZ_POINT * pPoint;
uint32_t m_nDBID;
}SHADOW_POLY;
typedef struct S_SHADOW{
uint16_t m_nPolygonCount;
SHADOW_POLY * pPolygones;
SHADOW_RAY_LINE ray_lines[MAX_2D_SHADOW_RAY_LINES];
uint32_t m_nEnabled;
}SHADOW;
#endif
Loading…
Cancel
Save