65 changed files with 3843 additions and 781 deletions
-
30Projects/argus/argus.vpj
-
165Projects/argus/makefile
-
4lib/App/argus/ArgusBackend.h
-
10lib/App/argus/RGoose_Kernel.h
-
3lib/components/base/basicDualThread.cpp
-
8lib/components/base/basicLIBAV.h
-
3lib/components/base/basicMediaDestination.h
-
5lib/components/base/basicPosition.cpp
-
16lib/components/base/basicThread.cpp
-
2lib/components/base/basicTransport.cpp
-
4lib/components/base/basicTransport.h
-
61lib/components/base/basicTypes.h
-
62lib/data/media/video/videoAVLIBSource.cpp
-
7lib/data/media/video/videoAVLIBSource.h
-
6lib/data/mysql/database_class.cpp
-
4lib/data/mysql/database_class.h
-
116lib/data/ponvif/ponvif.cpp
-
17lib/data/ponvif/ponvif.h
-
2lib/data/protocol/onvifMediaObserver.h
-
6lib/data/protocol/protocol.cpp
-
4lib/data/protocol/protocol.h
-
4lib/data/protocol/protocolLGS2D.cpp
-
16lib/data/protocol/protocolPTZ_ONVIF.cpp
-
11lib/data/transport/transportSocket.cpp
-
2lib/data/transport/transportSocket.h
-
89lib/hardware/uart/serialSOL.cpp
-
3lib/hardware/uart/serialSOL.h
-
235lib/rgoose/rgooseCamera.cpp
-
33lib/rgoose/rgooseCamera.h
-
440lib/rgoose/rgooseDBConnector.cpp
-
16lib/rgoose/rgooseDBConnector.h
-
43lib/rgoose/rgooseFilterAPF.cpp
-
185lib/rgoose/rgooseHardwareManager.cpp
-
5lib/rgoose/rgooseHardwareManager.h
-
77lib/rgoose/rgooseHardwareResource.cpp
-
16lib/rgoose/rgooseHardwareResource.h
-
10lib/rgoose/rgooseHardwareResourceDryContactProvider.cpp
-
0lib/rgoose/rgooseHardwareResourceDryContactProvider.h
-
41lib/rgoose/rgooseHardwareResourceIpUART.cpp
-
17lib/rgoose/rgooseHardwareResourceIpUART.h
-
25lib/rgoose/rgooseHardwareResourceNetwork.cpp
-
12lib/rgoose/rgooseHardwareResourceNetwork.h
-
66lib/rgoose/rgooseHardwareResourceNetworkProvider.cpp
-
20lib/rgoose/rgooseHardwareResourceNetworkProvider.h
-
1052lib/rgoose/rgooseHardwareResourceSerialProvider.cpp
-
60lib/rgoose/rgooseHardwareResourceSerialProvider.h
-
0lib/rgoose/rgooseHardwareResourceVideoProvider.h
-
157lib/rgoose/rgooseKernel.cpp
-
10lib/rgoose/rgooseKernel.h
-
3lib/rgoose/rgooseModule.h
-
700lib/rgoose/rgooseModuleEmbedVideo.cpp
-
153lib/rgoose/rgooseModuleEmbedVideo.h
-
77lib/rgoose/rgooseModuleFactory.cpp
-
1lib/rgoose/rgooseModuleFactory.h
-
97lib/rgoose/rgooseModuleOnvifObserver.cpp
-
36lib/rgoose/rgooseModuleOnvifObserver.h
-
4lib/rgoose/rgooseModuleZLMedia.cpp
-
3lib/rgoose/rgooseNode.cpp
-
2lib/rgoose/rgooseNode.h
-
118lib/rgoose/rgooseNode2D.cpp
-
25lib/rgoose/rgooseNode3D.cpp
-
75lib/rgoose/rgooseNodeFactory.cpp
-
61lib/rgoose/rgooseNodePTZCamControl.cpp
-
2lib/rgoose/rgooseNodePTZCamControl.h
-
87lib/rgoose/rgooseTypes.h
@ -1,41 +0,0 @@ |
|||
#include "rgooseHardwareResourceIpUART.h"
|
|||
|
|||
#define LOG( X ) argusHardwareResource::m_pLog->Log( "HR_IPUART", this, X )
|
|||
|
|||
#ifdef DEBUG
|
|||
#define LOG_ERROR( X ) {\
|
|||
char _tBfrErrMSG2w34[256];\ |
|||
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ |
|||
argusHardwareResource::m_pLog->Log( "HR_IPUART", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) argusHardwareResource::m_pLog->Log( "HR_IPUART", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
argusHardwareResourceIpUART::argusHardwareResourceIpUART( uint32_t dbID ) : serialSOL(), argusHardwareResource( dbID, ARGUS_HARDWARE_IP_UART ){ |
|||
memset( &settingsUART, 0, sizeof(DBC_UART_DATA)); |
|||
}; |
|||
|
|||
argusHardwareResourceIpUART::~argusHardwareResourceIpUART(){ |
|||
m_pDBC->setNodeOffline( m_sSettings.node_id ); |
|||
}; |
|||
|
|||
bool argusHardwareResourceIpUART::create( void ){ |
|||
DBC_UART_DATA *tDATA = NULL; |
|||
tDATA = m_pDBC->getUartData( m_sSettings.aux_id ); |
|||
if( tDATA!= NULL ) { |
|||
memcpy( &settingsUART, tDATA, sizeof(DBC_UART_DATA)); |
|||
#ifdef DEBUG
|
|||
LOG( settingsUART.path ); |
|||
#endif
|
|||
free( tDATA ); |
|||
if( serialSOL::create( settingsUART.path, settingsUART.speed, settingsUART.mode ) ) { |
|||
return m_pDBC->setNodeOnline( m_sSettings.node_id ); |
|||
}; |
|||
}; |
|||
return false; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -1,17 +0,0 @@ |
|||
#ifndef __ARGUS_HARDWARE_UART_HEADER__ |
|||
#define __ARGUS_HARDWARE_UART_HEADER__ |
|||
|
|||
#include "../hardware/uart/serialSOL.h" |
|||
#include "rgooseHardwareResource.h" |
|||
|
|||
class argusHardwareResourceIpUART: public serialSOL, argusHardwareResource { |
|||
private: |
|||
DBC_UART_DATA settingsUART; |
|||
public: |
|||
explicit argusHardwareResourceIpUART( uint32_t dbID ); |
|||
virtual ~argusHardwareResourceIpUART(); |
|||
virtual bool create( void ); |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
@ -1,25 +0,0 @@ |
|||
#include "rgooseHardwareResourceNetwork.h"
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "HW_NET", this, 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( "HW_NET", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "HW_NET", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
argusHardwareResourceNetwork::argusHardwareResourceNetwork( uint32_t id ):argusHardwareResource( id, ARGUS_HARDWARE_NETWORK_IPV4 ){ |
|||
|
|||
}; |
|||
|
|||
argusHardwareResourceNetwork::~argusHardwareResourceNetwork(){ |
|||
|
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -1,12 +0,0 @@ |
|||
#ifndef __ARGUS_HARDWARE_RESOURCE_NETWORK_HEADER__ |
|||
#define __ARGUS_HARDWARE_RESOURCE_NETWORK_HEADER__ |
|||
|
|||
#include "rgooseHardwareResource.h" |
|||
|
|||
class argusHardwareResourceNetwork: public argusHardwareResource { |
|||
public: |
|||
explicit argusHardwareResourceNetwork( uint32_t id ); |
|||
virtual ~argusHardwareResourceNetwork(); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,66 @@ |
|||
#include "rgooseHardwareResourceNetworkProvider.h"
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "HWR_NETWORK", this, 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( "HWR_NETWORK", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "HWR_NETWORK", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
argusHardwareResourceNetwork::argusHardwareResourceNetwork( uint32_t id, ARGUS_HARDWARE_PROVIDERS type ):argusHardwareResource( id, type ){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
if( m_pDBC!= NULL ){ |
|||
DBC_NET_IF_DATA *tData = m_pDBC->getNetworkInterfaceData( m_sResourceSettings.aux_id ); |
|||
if( tData != NULL ) { |
|||
memcpy( &m_sNetworkData, tData, sizeof(DBC_NET_IF_DATA)); |
|||
m_bValid = true; |
|||
free( tData ); |
|||
} else { |
|||
memset( &m_sNetworkData, 0, sizeof(DBC_NET_IF_DATA)); |
|||
}; |
|||
} else { |
|||
memset( &m_sNetworkData, 0, sizeof(DBC_NET_IF_DATA)); |
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG( m_sNetworkData.address ); |
|||
LOG( m_sNetworkData.netmask ); |
|||
#endif
|
|||
}; |
|||
|
|||
argusHardwareResourceNetwork::~argusHardwareResourceNetwork(){ |
|||
|
|||
}; |
|||
|
|||
CSTR argusHardwareResourceNetwork::getAddress(){ |
|||
if( m_sNetworkData.address[0] != (char)0 ) { |
|||
return strdup( m_sNetworkData.address ); |
|||
}; |
|||
return NULL; |
|||
}; |
|||
CSTR argusHardwareResourceNetwork::getBroadcast(){ |
|||
if( m_sNetworkData.broadcast[0] != (char)0 ) { |
|||
return strdup( m_sNetworkData.broadcast ); |
|||
}; |
|||
return NULL; |
|||
}; |
|||
CSTR argusHardwareResourceNetwork::getMask(){ |
|||
if( m_sNetworkData.netmask[0] != (char)0 ) { |
|||
return strdup( m_sNetworkData.netmask ); |
|||
}; |
|||
return NULL; |
|||
}; |
|||
CSTR argusHardwareResourceNetwork::getGateway(){ |
|||
if( m_sNetworkData.gateway[0] != (char)0 ) { |
|||
return strdup( m_sNetworkData.gateway ); |
|||
}; |
|||
return NULL; |
|||
}; |
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
|
|||
@ -0,0 +1,20 @@ |
|||
#ifndef __ARGUS_HARDWARE_RESOURCE_NETWORK_HEADER__ |
|||
#define __ARGUS_HARDWARE_RESOURCE_NETWORK_HEADER__ |
|||
|
|||
#include "rgooseHardwareResource.h" |
|||
|
|||
class argusHardwareResourceNetwork: public argusHardwareResource { |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
DBC_NET_IF_DATA m_sNetworkData; |
|||
public: |
|||
explicit argusHardwareResourceNetwork( uint32_t id, ARGUS_HARDWARE_PROVIDERS type = ARGUS_HARDWARE_PROVIDER_NETWORK ); |
|||
virtual ~argusHardwareResourceNetwork(); |
|||
CSTR getAddress(); |
|||
CSTR getBroadcast(); |
|||
CSTR getMask(); |
|||
CSTR getGateway(); |
|||
virtual bool create( void ){ return true; }; |
|||
}; |
|||
|
|||
#endif |
|||
1052
lib/rgoose/rgooseHardwareResourceSerialProvider.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,60 @@ |
|||
#ifndef __ARGUS_HARDWARE_SERIAL_PROVIDER_HEADER__ |
|||
#define __ARGUS_HARDWARE_SERIAL_PROVIDER_HEADER__ |
|||
|
|||
#include "rgooseHardwareResource.h" |
|||
#include "../components/base/basicTransport.h" |
|||
#include "../components/base/basicDualThread.h" |
|||
|
|||
#include <stdio.h> // standard input / output functions |
|||
#include <stdlib.h> |
|||
#include <string.h> // string function definitions |
|||
#include <fcntl.h> // File control definitions |
|||
#include <errno.h> // Error number definitions |
|||
#ifdef __linux__ |
|||
#include <unistd.h> // UNIX standard function definitions |
|||
#include <termios.h> // POSIX terminal control definitions |
|||
#endif |
|||
|
|||
#define MAXIMAL_SOCKET_PACKET_LENGTH 102400 |
|||
#define MAXIMAL_SERIAL_PACKET_LENGTH MAXIMAL_SOCKET_PACKET_LENGTH |
|||
|
|||
class argusHardwareResourceSerialProvider: public argusHardwareResource, public basicTransport, public basicDualThread { |
|||
private: |
|||
basicLogCollection * m_pLog; |
|||
DBC_UART_DATA m_sUartData; |
|||
|
|||
int m_iDeviceFD; |
|||
int m_iMasterFD; |
|||
#ifdef __linux__ |
|||
struct termios m_sTTY; |
|||
int m_iInFID; |
|||
int m_iOutFID; |
|||
#else |
|||
DCB PortDCB; |
|||
HANDLE m_ioFID; |
|||
#endif |
|||
bool pingDevice(); |
|||
bool create_SOL(); |
|||
bool create_HW(); |
|||
bool closePort(); |
|||
int sendBlock(unsigned char *Data, int DataSize); |
|||
int recptBlock(unsigned char *Buffer, int *BufferLength); |
|||
protected: |
|||
U8 m_pInputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH]; |
|||
U8 m_pOutputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH]; |
|||
int m_nInputBufferSize; |
|||
int m_nOutputBufferSize; |
|||
|
|||
virtual void m_fThreadAProc(void); |
|||
virtual void m_fThreadBProc(void); |
|||
public: |
|||
explicit argusHardwareResourceSerialProvider( uint32_t dbID ); |
|||
virtual ~argusHardwareResourceSerialProvider(); |
|||
virtual bool create( void ); |
|||
virtual bool validate( void ); |
|||
virtual bool sendData( uint8_t *Data, int DataSize ); |
|||
virtual bool reconnect( void ); |
|||
}; |
|||
|
|||
#endif |
|||
|
|||
@ -0,0 +1,700 @@ |
|||
#include "rgooseModuleEmbedVideo.h"
|
|||
#include "rgooseHardwareResourceNetworkProvider.h"
|
|||
#include "../alg/generic/base64.h"
|
|||
|
|||
#include <ctype.h>
|
|||
#include <err.h>
|
|||
#include <errno.h>
|
|||
#include <getopt.h>
|
|||
#include <ifaddrs.h>
|
|||
#include <netdb.h>
|
|||
#include <paths.h>
|
|||
#include <poll.h>
|
|||
#include <stdio.h>
|
|||
#include <signal.h>
|
|||
#include <stdint.h>
|
|||
#include <stdlib.h>
|
|||
#include <string.h>
|
|||
#include <time.h>
|
|||
#include <unistd.h>
|
|||
#include <arpa/inet.h>
|
|||
#include <netinet/ip.h>
|
|||
#include <netinet/udp.h>
|
|||
#include <sys/param.h> /* MIN() */
|
|||
#include <sys/socket.h>
|
|||
#include <openssl/sha.h>
|
|||
|
|||
|
|||
#define LOG( X ) argusKernelModule::m_pLog->Log( "MOD_EVIDEO", this, X )
|
|||
|
|||
#ifdef DEBUG
|
|||
#define LOG_ERROR( X ) {\
|
|||
char _tBfrErrMSG2w34[256];\ |
|||
sprintf( _tBfrErrMSG2w34, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ |
|||
argusKernelModule::m_pLog->Log( "MOD_EVIDEO", this, _LOG_ERROR, _tBfrErrMSG2w34 );\ |
|||
} |
|||
#else
|
|||
#define LOG_ERROR( X ) argusKernelModule::m_pLog->Log( "MOD_EVIDEO", this, _LOG_ERROR, X );
|
|||
#endif
|
|||
|
|||
#define TLOG( X ) basicLogCollection::getInstance()->Log( "MOD_EVIDEO_T", CTX, X )
|
|||
#define TLOG_ERROR( X ) basicLogCollection::getInstance()->Log( "MOD_EVIDEO_T", CTX, _LOG_ERROR, X )
|
|||
|
|||
enum { |
|||
WEBRTC_REQ_SIGNIN = 0, |
|||
WEBRTC_REQ_WAIT = 1, |
|||
WEBRTC_REQ_SIGNOUT = 2, |
|||
WEBRTC_REQ_MESSAGE = 3 |
|||
}; |
|||
|
|||
static const char* kRequestPaths[] = { "/stream", "/sign_in", "/wait", "/sign_out", "/message" }; |
|||
|
|||
//buffer_data bd[1]={0};
|
|||
|
|||
argusModuleEmbedVideo::argusModuleEmbedVideo( uint32_t moduleID ): argusKernelModule( moduleID, ARGUS_MODULE_EMBED_VIDEO ), basicMediaDestination(), basicThread(){ |
|||
m_pEventHeap = basicEventHeap::getInstance(); |
|||
DBC_MODULE_EMBED_VIDEO_DATA *tDATA = m_pDBC->getEmbedVideoData( m_nDBAUXID ); |
|||
if( tDATA ) { |
|||
memcpy( &m_sEmbedVideoData, tDATA, sizeof(DBC_MODULE_EMBED_VIDEO_DATA) ); |
|||
free( tDATA ); |
|||
} else { |
|||
memset( &m_sEmbedVideoData, 0, sizeof(DBC_MODULE_EMBED_VIDEO_DATA) ); |
|||
m_sEmbedVideoData.port = 8972; |
|||
}; |
|||
char tB[64]; |
|||
sprintf( tB, "Web Streams Port: %d", m_sEmbedVideoData.port ); |
|||
LOG( tB ); |
|||
sprintf( tB, "Frame: [%dx%d]", m_sEmbedVideoData.width, m_sEmbedVideoData.height ); |
|||
LOG( tB ); |
|||
n_pNoSignalData = NULL; |
|||
m_nNoSignalSize = 0; |
|||
if( m_sEmbedVideoData.show_ts ) LOG("Show TimeStamp"); |
|||
if( m_sEmbedVideoData.show_label ) LOG("Show Label"); |
|||
if( m_sEmbedVideoData.show_logo ){ |
|||
LOG("Show Logo"); |
|||
LOG( m_sEmbedVideoData.logo_md5 ); |
|||
}; |
|||
}; |
|||
|
|||
argusModuleEmbedVideo::~argusModuleEmbedVideo(){ |
|||
if( n_pNoSignalData ) free( n_pNoSignalData ); |
|||
m_bEnabled = false; |
|||
stopService(); |
|||
}; |
|||
|
|||
void *argusModuleEmbedVideo::webClientProc( void *ptr ){ |
|||
static char *head = "HTTP/1.1 200 OK\r\n" |
|||
"Cache-Control: no-store, no-cache, post-check=0, pre-check=0\r\n" |
|||
"Pragma: no-cache\r\n" |
|||
"MIME-version: 1.0\r\n" |
|||
"Connection: close\r\n" |
|||
//"Keep-Alive: timeout=5, max=1\r\n"
|
|||
//"Connection: Keep-Alive\r\n"
|
|||
//"Content-Type: video/mp4\r\n"
|
|||
"Content-Transfer-Encoding: BINARY\r\n" |
|||
//"Transfer-Encoding: chunked\r\n"
|
|||
"Content-type: multipart/x-mixed-replace;boundary=MPFrame\r\n" |
|||
"\r\n"; |
|||
static char *abort = "HTTP/1.1 404 OK\r\n" |
|||
"Cache-Control: no-store, no-cache, post-check=0, pre-check=0\r\n" |
|||
"Pragma: no-cache\r\n" |
|||
"Connection: close\r\n\r\n"; |
|||
static char *no_signal ="HTTP/1.1 200 OK\r\n" |
|||
"MIME-version: 1.0\r\n" |
|||
"Connection: close\r\n" |
|||
"Content-Transfer-Encoding: BINARY\r\n" |
|||
//"Content-type: multipart/x-mixed-replace;boundary=MPFrame\r\n\r\n"
|
|||
"Content-Type: image/jpeg\r\nContent-length: %d\r\n\r\n"; |
|||
WEB_CLIENT_CTX * CTX = (WEB_CLIENT_CTX *) ptr; |
|||
argusModuleEmbedVideo * MODULE = CTX->ModulePtr; |
|||
|
|||
if( CTX ) { |
|||
char mesg[1024]; |
|||
size_t RecvSize; |
|||
struct pollfd pfd[1]; |
|||
char cGetURI[1024]; |
|||
bool m_bDeflatePerMessage = false; |
|||
bool m_pInit; |
|||
|
|||
#ifdef DEBUG_EXTRA
|
|||
pid_t pid = gettid(); |
|||
char pidBuf[16]; |
|||
sprintf( pidBuf, "pid:%d", pid); |
|||
TLOG( pidBuf ); |
|||
#endif
|
|||
|
|||
pfd->fd = CTX->m_iSocketFID; |
|||
pfd->events = POLLIN | POLLHUP; |
|||
|
|||
while( CTX->bValid ) { |
|||
if( !CTX->initDone ){ |
|||
int RetVal; |
|||
char * reqline[256]; |
|||
RetVal = poll( pfd, 1, 1000 ); |
|||
if( RetVal <= 0 ){ |
|||
if ( EINTR == errno ) continue; |
|||
TLOG_ERROR("Unrecoverable error"); |
|||
CTX->bValid = false; |
|||
continue; |
|||
}; |
|||
memset( mesg, 0, sizeof(mesg) ); |
|||
|
|||
RetVal = recv( CTX->m_iSocketFID, mesg, sizeof(mesg), 0 ); |
|||
|
|||
if ( RetVal <= 0 ) { |
|||
sprintf( mesg, "web recv() error: %s", strerror(errno)); |
|||
TLOG_ERROR( mesg ); |
|||
CTX->bValid = false; |
|||
continue; |
|||
}; |
|||
//TLOG( mesg );
|
|||
|
|||
uint32_t index = 0; |
|||
reqline[index] = strtok( mesg, "\n" ); |
|||
if( strncmp( reqline[index], "GET", 3 ) == 0 ) { |
|||
char * pPartURI; |
|||
char * pPartPROTO; |
|||
pPartURI = strstr( reqline[index], " " ); |
|||
if( pPartURI != NULL ) { |
|||
pPartURI++; |
|||
pPartPROTO = strstr( pPartURI, " " ); |
|||
pPartPROTO++; |
|||
int URILen = pPartPROTO - pPartURI; |
|||
strncpy( cGetURI, pPartURI, URILen ); |
|||
cGetURI[URILen] = (char)0; |
|||
if(strncmp( pPartPROTO, "HTTP/1.0", 8) != 0 && strncmp( pPartPROTO, "HTTP/1.1", 8) != 0) { |
|||
TLOG_ERROR("No HTTP version supplied in request!"); |
|||
if( write( CTX->m_iSocketFID, "HTTP/1.1 400 Bad Request\r\n", 26) < 0 ){ |
|||
sprintf( mesg, "Failed returning status 400 to client: %s", strerror(errno)); |
|||
TLOG_ERROR(mesg); |
|||
}; |
|||
CTX->bValid = false; |
|||
continue; |
|||
}; |
|||
}; |
|||
TLOG( cGetURI ); |
|||
}; |
|||
// parse rest of request
|
|||
while( ( reqline[++index] = strtok( NULL, "\n" ) )!= NULL ) { |
|||
if( strncmp( reqline[index], "Connection:", 11 ) == 0 ) { |
|||
char * pPart; |
|||
pPart = strcasestr( reqline[index], "Upgrade" ); |
|||
if( pPart != NULL ) { |
|||
TLOG("Upgrade Mode ON"); |
|||
//bUpgradeMode = true;
|
|||
}; |
|||
}; |
|||
if( strncmp( reqline[index], "Upgrade:", 8 ) == 0 ) { |
|||
/*
|
|||
if( bUpgradeMode ) { |
|||
char * pPart; |
|||
pPart = strcasestr( reqline[index], "websocket" ); |
|||
if( pPart != NULL ) { |
|||
TLOG("WebSocket Mode ON"); |
|||
//bWebSocketMode = true;
|
|||
}; |
|||
}; |
|||
*/ |
|||
}; |
|||
if( strncmp( reqline[index], "Sec-WebSocket-Version:", 22 ) == 0 ) { |
|||
char * pPart; |
|||
pPart = strstr( reqline[index], " " ); |
|||
if( pPart != NULL ) { |
|||
char tBuf[CTEXT]; |
|||
//nWebSocketVersion = atoi(pPart+1);
|
|||
sprintf( tBuf,"Web Socket Version: %d", 0 );//nWebSocketVersion );
|
|||
TLOG( tBuf ); |
|||
}; |
|||
}; |
|||
if( strncmp( reqline[index], "Sec-WebSocket-Key:", 18 ) == 0 ) { |
|||
/*char * pPart;
|
|||
pPart = strstr( reqline[index], " " ); |
|||
if( pPart != NULL ) { |
|||
char tGenStr[256]; |
|||
unsigned char * tBase64; |
|||
size_t nBase64; |
|||
int kLen; |
|||
unsigned char hash[SHA_DIGEST_LENGTH]; // == 20
|
|||
pPart++; |
|||
kLen = strstr(pPart,"\r") - pPart; |
|||
strncpy(cWSKey,pPart,kLen); |
|||
cWSKey[kLen]=(char)0; |
|||
TLOG( cWSKey ); |
|||
sprintf( tGenStr, "%s%s", cWSKey, ws_guid ); |
|||
SHA1( (const unsigned char*)tGenStr, strlen(tGenStr), hash ); |
|||
tBase64 = base64_encode( hash, SHA_DIGEST_LENGTH, &nBase64 ); |
|||
strncpy( cWSRep, (const char*)tBase64, nBase64 ); |
|||
free( tBase64 ); |
|||
cWSRep[nBase64] = (char)0; |
|||
TLOG( cWSRep ); |
|||
}; |
|||
*/ |
|||
}; |
|||
if( strncmp( reqline[index], "Sec-WebSocket-Protocol:", 23 ) == 0 ) { |
|||
char * pPart; |
|||
pPart = strstr( reqline[index], " " ); |
|||
if( pPart != NULL ) { |
|||
// Check for protos
|
|||
}; |
|||
}; |
|||
if( strncmp( reqline[index], "Sec-WebSocket-Extensions:", 25 ) == 0 ) { |
|||
char * pPart; |
|||
pPart = strstr( reqline[index], " " ); |
|||
if( pPart != NULL ) { |
|||
pPart++; |
|||
if(strncmp( pPart, "permessage-deflate", 18 ) == 0 ) { |
|||
m_bDeflatePerMessage = true; |
|||
TLOG("Using Deflate"); |
|||
}; |
|||
}; |
|||
}; |
|||
if( strncmp( reqline[index],"Accept-Encoding:", 16 ) == 0 ){ |
|||
char * pPart; |
|||
pPart = strstr( reqline[index], " " ); |
|||
if( pPart != NULL ) { |
|||
pPart++; |
|||
if(strncmp( pPart, "gzip, deflate", 13 ) == 0 ) { |
|||
m_bDeflatePerMessage = true; |
|||
TLOG("Using Deflate"); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
if( strncmp( cGetURI, "/stream", 7 ) == 0 ) { |
|||
uint32_t tStreamID = 0; |
|||
CSTR tP; |
|||
if( tP = strstr( cGetURI, "?" ) ) { |
|||
CSTR tB; |
|||
tP++; |
|||
if( tB = strstr( tP, "id=" ) ) { |
|||
tStreamID = atoi( tB+3 ); |
|||
}; |
|||
}; |
|||
if( tStreamID ) { |
|||
char tB[64]; |
|||
sprintf(tB,"StremID: %d", tStreamID ); |
|||
TLOG( tB ); |
|||
if( CTX->ModulePtr->registerForMediaStream( tStreamID, CTX ) ){ |
|||
// Send Header
|
|||
if( send( CTX->m_iSocketFID, head, strlen(head), 0 ) < 0 ){ |
|||
sprintf( mesg, "Failed sending file to client: %s", strerror(errno)); |
|||
TLOG_ERROR(mesg); |
|||
CTX->bValid = false; |
|||
}; |
|||
CTX->initDone = true; |
|||
continue; |
|||
} else { |
|||
TLOG("Stream id Not Online"); |
|||
}; |
|||
} else TLOG("No Stream ID"); |
|||
}; |
|||
if( CTX->ModulePtr->n_pNoSignalData ) { |
|||
sprintf( mesg, no_signal, CTX->ModulePtr->m_nNoSignalSize ); |
|||
send( CTX->m_iSocketFID, mesg, strlen(mesg), 0 ); |
|||
send( CTX->m_iSocketFID, CTX->ModulePtr->n_pNoSignalData, CTX->ModulePtr->m_nNoSignalSize, 0 ); |
|||
send( CTX->m_iSocketFID, "\r\n\r\n", 4, 0 ); |
|||
TLOG("Sent No Signal Image!"); |
|||
} else { |
|||
// Send 404 Header
|
|||
send( CTX->m_iSocketFID, abort, strlen(abort), 0 ); |
|||
TLOG("Aborted!"); |
|||
}; |
|||
CTX->bValid = false; |
|||
continue; |
|||
} else { |
|||
uint32_t msgSize; |
|||
int retVal; |
|||
retVal = read( CTX->m_iEncoderPipe[0], &msgSize, sizeof(uint32_t)); |
|||
if( retVal == -1 ){ |
|||
if( errno == EAGAIN || errno == EWOULDBLOCK ){ |
|||
continue; |
|||
}; |
|||
TLOG_ERROR("Pipe Communication Error[1]!"); |
|||
CTX->bValid = false; |
|||
continue; |
|||
}; |
|||
uint8_t *tBuf = (uint8_t *) malloc(msgSize); |
|||
if( tBuf ){ |
|||
retVal = read( CTX->m_iEncoderPipe[0], tBuf, msgSize ); |
|||
if( retVal == -1 ){ |
|||
free( tBuf ); |
|||
if( errno == EAGAIN || errno == EWOULDBLOCK ){ |
|||
continue; |
|||
}; |
|||
TLOG_ERROR("Pipe Communication Error[2]!"); |
|||
CTX->bValid = false; |
|||
continue; |
|||
}; |
|||
sprintf( mesg, "--MPFrame\r\nContent-type: image/jpeg\r\nContent-length: %d\r\n\r\n", msgSize ); |
|||
if( send( CTX->m_iSocketFID, mesg, strlen( mesg ), 0 )< 0 ){ |
|||
sprintf( mesg, "[1]Failed sending file to client: %s", strerror(errno)); |
|||
TLOG_ERROR(mesg); |
|||
CTX->bValid = false; |
|||
continue; |
|||
}; |
|||
if( send( CTX->m_iSocketFID, tBuf, msgSize, 0 ) < 0 ){ |
|||
sprintf( mesg, "[2]Failed sending file to client: %s", strerror(errno)); |
|||
TLOG_ERROR(mesg); |
|||
CTX->bValid = false; |
|||
continue; |
|||
}; |
|||
if( send( CTX->m_iSocketFID, "\r\n\r\n", 4, 0 )< 0 ){ |
|||
sprintf( mesg, "[3]Failed sending file to client: %s", strerror(errno)); |
|||
TLOG_ERROR(mesg); |
|||
CTX->bValid = false; |
|||
continue; |
|||
}; |
|||
free( tBuf ); |
|||
} else { |
|||
TLOG_ERROR("Mem Alloc Error!"); |
|||
CTX->bValid = false; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
CTX->bValid = false; |
|||
TLOG("WEB Client Handler Ended!"); |
|||
close( CTX->m_iEncoderPipe[0] ); |
|||
shutdown( CTX->m_iSocketFID, SHUT_RDWR); |
|||
close( CTX->m_iSocketFID ); |
|||
//pthread_exit( NULL );
|
|||
return NULL; |
|||
}; |
|||
|
|||
void argusModuleEmbedVideo::m_fThreadProc( void ){ |
|||
if( !m_bEnabled ) { |
|||
#ifdef DEBUG
|
|||
LOG("Module is Disabled!"); |
|||
#endif
|
|||
return; |
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG("Module Started!"); |
|||
#endif
|
|||
struct pollfd pfd[1]; |
|||
pfd->fd = m_nSocketDescriptor; |
|||
pfd->events = POLLIN | POLLHUP; |
|||
m_bThreadStatus = TH_WORKING; |
|||
while( m_bThreadStatus < TH_ENDED ) { |
|||
if( !m_bEnabled ) { |
|||
m_bThreadStatus = TH_ENDED; |
|||
continue; |
|||
}; |
|||
int RetVal = poll( pfd, 1, 1000 ); |
|||
if( RetVal < 0 ){ |
|||
if( EINTR == errno ) continue; |
|||
LOG_ERROR("Unrecoverable error"); |
|||
m_bThreadStatus = TH_ENDED; |
|||
continue; |
|||
}; |
|||
// Handle Connections
|
|||
if( RetVal != 0 ){ |
|||
if ( pfd[0].revents & POLLIN ) { |
|||
LOG("Handle New Client"); |
|||
int tSID = accept( pfd[0].fd, NULL, NULL); |
|||
if( tSID < 0 ){ |
|||
char tBuf[CTEXT]; |
|||
sprintf(tBuf, "Accept() error: %s", strerror(errno)); |
|||
LOG_ERROR(tBuf); |
|||
} else { |
|||
LOG("Accept OK"); |
|||
WEB_CLIENT_CTX *tCTX = (WEB_CLIENT_CTX *) malloc(sizeof(WEB_CLIENT_CTX)); |
|||
if( tCTX ) { |
|||
LOG("CTX OK"); |
|||
WEB_HANDLER *tHANDLER = (WEB_HANDLER *) malloc(sizeof(WEB_HANDLER)); |
|||
if( tHANDLER ) { |
|||
LOG("HANDLER OK"); |
|||
memset( tCTX, 0, sizeof(WEB_CLIENT_CTX) ); |
|||
memset( tHANDLER, 0, sizeof(WEB_HANDLER) ); |
|||
tCTX->m_iSocketFID = tSID; |
|||
tCTX->m_iEncoderPipe[0] = -1; |
|||
tCTX->m_iEncoderPipe[1] = -1; |
|||
tCTX->mediaStreamId = 0; |
|||
tCTX->bValid = true; |
|||
tCTX->ModulePtr = this; |
|||
LOG("Before Thread Create"); |
|||
int RetVal = pthread_create( &tHANDLER->m_hThreadHandle, NULL, webClientProc, ( void * ) tCTX ); |
|||
if( RetVal == -1 ) { |
|||
free(tCTX); |
|||
free(tHANDLER); |
|||
LOG_ERROR("Thread Creation Faled."); |
|||
shutdown( tSID, SHUT_RDWR ); |
|||
close( tSID ); |
|||
} else { |
|||
tHANDLER->CTX = tCTX; |
|||
m_mHandlersProtector.lock(); |
|||
m_vHandlersPool.push_back( tHANDLER ); |
|||
m_mHandlersProtector.unlock(); |
|||
LOG("Handler Pushed to a Pool"); |
|||
}; |
|||
} else { //https://stackoverflow.com/questions/18545077/image-fullscreen-on-click
|
|||
free(tCTX); |
|||
LOG_ERROR("CL_HANDLER Mem Allocation Failure!"); |
|||
shutdown( tSID, SHUT_RDWR ); |
|||
close( tSID ); |
|||
}; |
|||
} else { |
|||
LOG_ERROR("CL_CTX Mem Allocation Failure!"); |
|||
shutdown( tSID, SHUT_RDWR ); |
|||
close( tSID ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
// Handle Dead Clients
|
|||
if( m_vHandlersPool.size() ) { |
|||
for( vectorHANDLERS::iterator idx = m_vHandlersPool.begin(); idx < m_vHandlersPool.end(); idx++ ) { |
|||
if( !( (*idx)->CTX->bValid ) ) { |
|||
pthread_join( (*idx)->m_hThreadHandle, NULL ); |
|||
//close( (*idx)->CTX->m_iEncoderPipe[0] );
|
|||
close( (*idx)->CTX->m_iEncoderPipe[1] ); |
|||
free( (*idx)->CTX ); |
|||
free( (*idx) ); |
|||
m_mHandlersProtector.lock(); |
|||
m_vHandlersPool.erase(idx); |
|||
m_mHandlersProtector.unlock(); |
|||
#ifdef DEBUG
|
|||
LOG("Web Handler Ripped!"); |
|||
#endif
|
|||
}; |
|||
}; |
|||
|
|||
}; |
|||
|
|||
SLEEP( 50 ); |
|||
}; |
|||
}; |
|||
|
|||
#define ENABLE_SOCKOPT(sd, level, opt) \
|
|||
do { \ |
|||
int val = 1; \ |
|||
if (setsockopt(sd, level, opt, &val, sizeof(val)) < 0) \ |
|||
warn("Failed enabling %s for web service", #opt); \ |
|||
} while (0); |
|||
|
|||
|
|||
bool argusModuleEmbedVideo::startService(){ |
|||
LOG("Create"); |
|||
//Create NoSignal Image
|
|||
cv::Mat tMat( m_sEmbedVideoData.height, m_sEmbedVideoData.width, CV_8UC3 ); |
|||
cv::rectangle( tMat, cv::Point( 0, 0 ), cv::Point( m_sEmbedVideoData.width, m_sEmbedVideoData.height ), cv::Scalar( 255, 0, 0 ), cv::FILLED ); |
|||
cv::putText( tMat, "NO SIGNAL", cv::Point( 10, 30 ), cv::FONT_HERSHEY_SIMPLEX, 1, cv::Scalar( 0, 255, 255 ), 3 ); |
|||
|
|||
if( m_sEmbedVideoData.show_logo ) { |
|||
int a_x, a_y; |
|||
if( m_sEmbedVideoData.logo_x < 0 ) { |
|||
a_x = m_sEmbedVideoData.width + m_sEmbedVideoData.logo_x - m_sEmbedVideoData.logo_w; |
|||
if( a_x < 0 ) a_x = 0; |
|||
} else a_x = m_sEmbedVideoData.logo_x; |
|||
if( ( a_x + m_sEmbedVideoData.logo_w ) > m_sEmbedVideoData.width ) a_x = m_sEmbedVideoData.width - m_sEmbedVideoData.logo_w; |
|||
if( m_sEmbedVideoData.logo_y < 0 ) { |
|||
a_y = m_sEmbedVideoData.height + m_sEmbedVideoData.logo_y - m_sEmbedVideoData.logo_h; |
|||
if( a_y < 0 ) a_y = 0; |
|||
} else a_y = m_sEmbedVideoData.logo_y; |
|||
if( ( a_y + m_sEmbedVideoData.logo_h ) > m_sEmbedVideoData.height ) a_y = m_sEmbedVideoData.height - m_sEmbedVideoData.logo_h; |
|||
if( ( a_x > -1 ) && ( a_y > -1 ) ) { |
|||
char tName[256]; |
|||
m_sEmbedVideoData.logo_x = a_x; |
|||
m_sEmbedVideoData.logo_y = a_y; |
|||
sprintf( tName, "data/assets/images/%s.png", m_sEmbedVideoData.logo_md5 ); |
|||
cv::Mat T = cv::imread( tName, cv::IMREAD_UNCHANGED ); |
|||
if( T.cols > 0 ) { |
|||
cv::Mat mask; |
|||
vector<cv::Mat> layers; |
|||
|
|||
|
|||
cv::split( T, layers); // seperate channels
|
|||
cv::Mat rgb[3] = { layers[0], layers[1], layers[2] }; |
|||
mask = layers[3]; // png's alpha channel used as mask
|
|||
cv::merge( rgb, 3, T ); // put together the RGB channels, now transp insn't transparent
|
|||
|
|||
cv::resize( T, m_mLogoPic, cv::Size( m_sEmbedVideoData.logo_w, m_sEmbedVideoData.logo_h ), cv::INTER_CUBIC ); |
|||
cv::resize( mask, m_mLogoMask, cv::Size( m_sEmbedVideoData.logo_w, m_sEmbedVideoData.logo_h ), cv::INTER_CUBIC ); |
|||
|
|||
cv::Rect roi(cv::Point( m_sEmbedVideoData.logo_x, m_sEmbedVideoData.logo_y ), cv::Size( m_sEmbedVideoData.logo_w, m_sEmbedVideoData.logo_h )); |
|||
cv::Mat destinationROI = tMat( roi ); |
|||
m_mLogoPic.copyTo( destinationROI, m_mLogoMask ); |
|||
//m_sEmbedVideoData.show_logo = false;
|
|||
} else { |
|||
LOG("Logo Disabled - No Picture is Loaded"); |
|||
m_sEmbedVideoData.show_logo = false; |
|||
}; |
|||
} else { |
|||
LOG("Logo Disabled - Wrong Coords"); |
|||
m_sEmbedVideoData.show_logo = false; |
|||
}; |
|||
}; |
|||
|
|||
vector<int> compression_params; |
|||
//compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
|
|||
//compression_params.push_back(9);
|
|||
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); |
|||
compression_params.push_back(75); |
|||
vector<uchar> buf; |
|||
cv::imencode( ".jpg", tMat, buf, compression_params ); |
|||
m_nNoSignalSize = buf.size(); |
|||
n_pNoSignalData = (uint8_t *) malloc( m_nNoSignalSize ); |
|||
if( n_pNoSignalData ) { |
|||
memcpy( n_pNoSignalData, buf.data(), m_nNoSignalSize ); |
|||
} else m_nNoSignalSize =0; |
|||
buf.clear(); |
|||
|
|||
|
|||
struct sockaddr sa; |
|||
struct sockaddr_in *sin; |
|||
|
|||
memset(&sa, 0, sizeof(struct sockaddr)); |
|||
sa.sa_family = AF_INET; |
|||
sin = (struct sockaddr_in *)&sa; |
|||
sin->sin_addr.s_addr = htonl( INADDR_ANY ); |
|||
sin->sin_port = htons( m_sEmbedVideoData.port ); |
|||
|
|||
m_nSocketDescriptor = socket( sa.sa_family, SOCK_STREAM | SOCK_NONBLOCK, 0); |
|||
if( m_nSocketDescriptor == -1 ){ |
|||
LOG_ERROR("Failed creating ACC socket"); |
|||
return false; |
|||
}; |
|||
ENABLE_SOCKOPT( m_nSocketDescriptor, SOL_SOCKET, SO_REUSEADDR); |
|||
#ifdef SO_REUSEPORT
|
|||
ENABLE_SOCKOPT( m_nSocketDescriptor, SOL_SOCKET, SO_REUSEPORT); |
|||
#endif
|
|||
if( bind( m_nSocketDescriptor, &sa, sizeof(sa)) < 0 ){ |
|||
LOG_ERROR("Failed binding Socket"); |
|||
close( m_nSocketDescriptor ); |
|||
return false; |
|||
} else { |
|||
LOG("Bind Socessfull"); |
|||
}; |
|||
if( listen( m_nSocketDescriptor, 10) != 0 ){ |
|||
LOG_ERROR("Failed setting web listen backlog"); |
|||
close( m_nSocketDescriptor ); |
|||
return false; |
|||
} else { |
|||
LOG("Listen OK"); |
|||
}; |
|||
return init(); |
|||
}; |
|||
|
|||
bool argusModuleEmbedVideo::stopService(){ |
|||
waitThreadEnd( true ); |
|||
/*
|
|||
if( m_vThreads.size() ) { // Kill-Wait Started Probes
|
|||
#ifdef DEBUG
|
|||
LOG("Have to Wait Probes!"); |
|||
#endif
|
|||
for( vectorOBSERVER_CTX::iterator index = m_vThreads.begin(); index < m_vThreads.end(); index++ ) { |
|||
pthread_join( (*index)->m_hThreadHandle, NULL ); |
|||
}; |
|||
m_vThreads.clear(); |
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG("No More Probes!"); |
|||
#endif
|
|||
if (m_vResultPool.size()){ // Clear structures
|
|||
for( vectorOBSERVER_RESULT::iterator index = m_vResultPool.begin(); index < m_vResultPool.end(); index++){ |
|||
free(*index); |
|||
}; |
|||
m_vResultPool.clear(); |
|||
}; |
|||
#ifdef DEBUG
|
|||
LOG("Data is Cleared!"); |
|||
#endif
|
|||
*/ |
|||
return true; |
|||
}; |
|||
|
|||
bool argusModuleEmbedVideo::reloadSettings(){ |
|||
|
|||
return true; |
|||
}; |
|||
|
|||
void argusModuleEmbedVideo::dispatchEvent(EVENT_CONTAINER *Evt){ |
|||
}; |
|||
|
|||
bool argusModuleEmbedVideo::validate(){ |
|||
return true; |
|||
}; |
|||
|
|||
void argusModuleEmbedVideo::pushFrame( AVFrame *Frame, void* src){ |
|||
MEDIA_SOURCE_DESC * tMD = (MEDIA_SOURCE_DESC *) src; |
|||
if( tMD ) { |
|||
}; |
|||
}; |
|||
|
|||
void argusModuleEmbedVideo::pushFrame( cv::Mat &Frame, void* src ){ |
|||
MEDIA_SOURCE_DESC * tMD = (MEDIA_SOURCE_DESC *) src; |
|||
if( tMD ) { |
|||
if( m_vHandlersPool.size() ) { |
|||
cv::Mat RD; |
|||
cv::resize( Frame, RD, cv::Size( m_sEmbedVideoData.width, m_sEmbedVideoData.height ), cv::INTER_LINEAR ); |
|||
if( m_sEmbedVideoData.show_ts ){ |
|||
char DateStr[200]; |
|||
time_t t = time( NULL ); |
|||
struct tm * tmp = gmtime( &t ); |
|||
if( tmp ){ |
|||
if( strftime( DateStr, sizeof(DateStr), "%F %T GMT", tmp )!=0 ){ |
|||
cv::rectangle( RD, cv::Point( 10, 10 ), cv::Point( 490, 60 ), cv::Scalar( 0, 0, 0 ), cv::FILLED ); |
|||
cv::putText( RD, DateStr, cv::Point( 30, 45 ), |
|||
(cv::HersheyFonts) m_sEmbedVideoData.ts_font_face, |
|||
m_sEmbedVideoData.ts_font_scale, cv::Scalar( 0, 255, 255 ), |
|||
m_sEmbedVideoData.ts_font_thickness, |
|||
m_sEmbedVideoData.ts_line_type |
|||
); |
|||
}; |
|||
}; |
|||
}; |
|||
if( m_sEmbedVideoData.show_logo ){ |
|||
cv::Rect roi( cv::Point( m_sEmbedVideoData.logo_x, m_sEmbedVideoData.logo_y ), cv::Size( m_sEmbedVideoData.logo_w, m_sEmbedVideoData.logo_h )); |
|||
cv::Mat destinationROI = RD( roi ); |
|||
m_mLogoPic.copyTo( destinationROI, m_mLogoMask ); |
|||
}; |
|||
|
|||
vector<int> compression_params; |
|||
//compression_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
|
|||
//compression_params.push_back(9);
|
|||
compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); |
|||
compression_params.push_back(75); |
|||
vector<uchar> buf; |
|||
uint32_t DataSize; |
|||
cv::imencode( ".jpg", RD, buf, compression_params ); |
|||
DataSize = buf.size(); |
|||
uint8_t *pData = buf.data(); |
|||
for( vectorHANDLERS::iterator idx = m_vHandlersPool.begin(); idx < m_vHandlersPool.end(); idx++ ) { |
|||
if( (*idx)->CTX->mediaStreamId == tMD->mediaStreamId ) { |
|||
write( (*idx)->CTX->m_iEncoderPipe[1], &DataSize, sizeof(uint32_t)); |
|||
write( (*idx)->CTX->m_iEncoderPipe[1], pData, DataSize ); |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
bool argusModuleEmbedVideo::registerForMediaStream( uint32_t id, WEB_CLIENT_CTX *&CTX ){ |
|||
if( CTX ){ |
|||
if( id ){ |
|||
//Check if its Valid!
|
|||
DBC_MEDIA_STREAM_DATA *tSD = m_pDBC->getMediaStreamData( id ); |
|||
if( tSD ) { |
|||
if( ! tSD->valid ) { |
|||
free( tSD ); |
|||
return false; |
|||
}; |
|||
free( tSD ); |
|||
if( pipe( CTX->m_iEncoderPipe ) == -1 ){ |
|||
CTX->bValid = false; |
|||
return false; |
|||
}; |
|||
CTX->mediaStreamId = id; |
|||
return true; |
|||
}; |
|||
}; |
|||
} else LOG_ERROR("Client Context error!"); |
|||
return false; |
|||
}; |
|||
|
|||
|
|||
|
|||
#undef LOG
|
|||
#undef LOG_ERROR
|
|||
#undef TLOG
|
|||
#undef TLOG_ERROR
|
|||
@ -0,0 +1,153 @@ |
|||
#ifndef __ARGUS_MODULE_EMBED_VIDEO_HEADER__ |
|||
#define __ARGUS_MODULE_EMBED_VIDEO_HEADER__ |
|||
#include "rgooseModule.h" |
|||
#include "../components/base/basicMutex.h" |
|||
#include "../components/base/basicThread.h" |
|||
#include "../components/base/basicEventHeap.h" |
|||
//#include "../data/media/video/videoAVLIBDestination.h" |
|||
#include "../components/base/basicMediaDestination.h" |
|||
|
|||
class argusModuleEmbedVideo; |
|||
|
|||
#define FILESTREAMBUFFERSZ 1048576 |
|||
|
|||
/* Video CODECS */ |
|||
#define VC_VPX 0 |
|||
#define VC_X264 1 |
|||
#define VC_MP4 2 |
|||
#define VC_MJPEG 3 |
|||
#define VC_FLV 4 |
|||
|
|||
/* Video FORMATS */ |
|||
#define VF_WEBM 0 |
|||
#define VF_MP4 1 |
|||
#define VF_MP3 2 |
|||
#define VF_AAC 3 |
|||
#define VF_OGG 4 |
|||
#define VF_MJPEG 5 |
|||
#define VF_FLV 6 |
|||
|
|||
/* Encoder PROFILES */ |
|||
#define VP_ULTRAFAST 0 |
|||
#define VP_VERYFAST 1 |
|||
#define VP_FAST 2 |
|||
#define VP_MEDIUM 3 |
|||
#define VP_SLOW 4 |
|||
#define VP_VERYSLOW 5 |
|||
#define VP_ULTRASLOW 6 |
|||
|
|||
#define VIDEO_OUTPUT VO_MJPEG |
|||
//#define VIDEO_OUTPUT VO_MPEG4 |
|||
//#define VIDEO_OUTPUT VO_H264 |
|||
//#define VIDEO_OUTPUT VO_FLV |
|||
|
|||
#define VIDEO_OUTPUT_WIDTH 640 //1920 |
|||
#define VIDEO_OUTPUT_HEIGHT 480 //1080 |
|||
#define VIDEO_OUTPUT_FPS 10 |
|||
#define VIDEO_OUTPUT_GOP 30 |
|||
|
|||
#if( LIBAVCODEC_VERSION_MAJOR < 54 ) |
|||
//#define VIDEO_OUTPUT_CODEC CODEC_ID_MJPEG |
|||
//#define VIDEO_OUTPUT_PIX_FMT PIX_FMT_YUVJ422P |
|||
#else |
|||
//#if( VIDEO_OUTPUT == VO_MJPEG ) |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_MJPEG |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUVJ422P |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "mjpeg" |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER "mjpeg" |
|||
/* |
|||
#endif |
|||
#if( VIDEO_OUTPUT == VO_MPEG4 ) |
|||
|
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_MPEG4 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "mp4" |
|||
#define VIDEO_OUTPUT_BITRATE 100000000 |
|||
#define VIDEO_OUTPUT_CONTAINER "mp4" |
|||
//* |
|||
#endif |
|||
#if( VIDEO_OUTPUT == VO_H264 ) |
|||
//* / |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_H264 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_BITRATE 100000000 |
|||
#define VIDEO_OUTPUT_CONTAINER_LONG "matroska" |
|||
#define VIDEO_OUTPUT_CONTAINER "mkv" |
|||
/* |
|||
#endif |
|||
#if( VIDEO_OUTPUT == VO_FLV ) |
|||
#define VIDEO_OUTPUT_CODEC AV_CODEC_ID_FLV1 |
|||
#define VIDEO_OUTPUT_PIX_FMT AV_PIX_FMT_YUV420P |
|||
#define VIDEO_OUTPUT_BITRATE 4000000 |
|||
#define VIDEO_OUTPUT_CONTAINER "flv" |
|||
#endif |
|||
*/ |
|||
#endif |
|||
|
|||
typedef struct S_buffer_data { |
|||
uint8_t * buf; |
|||
int size; |
|||
uint8_t * ptr; |
|||
size_t room; ///< size left in the buffer |
|||
} buffer_data; |
|||
|
|||
#define NR_COLORS 4 |
|||
#define AVIO_BUFFER_SIZE 4096 |
|||
#define BD_BUFFER_SIZE 1024 |
|||
|
|||
typedef struct S_WEB_CLIENT_CTX{ |
|||
int m_iSocketFID; |
|||
int m_iEncoderPipe[2]; |
|||
bool bValid; |
|||
bool initDone; |
|||
bool headerIsSent; |
|||
uint32_t mediaStreamId; |
|||
argusModuleEmbedVideo * ModulePtr; |
|||
}WEB_CLIENT_CTX; |
|||
|
|||
|
|||
typedef struct S_WEB_HANDLER{ |
|||
DWORD m_dwThreadID; |
|||
#ifdef __linux__ |
|||
pthread_t m_hThreadHandle; |
|||
#else |
|||
HANDLE m_hThreadHandle; |
|||
#endif |
|||
WEB_CLIENT_CTX * CTX; |
|||
}WEB_HANDLER; |
|||
|
|||
typedef vector<WEB_HANDLER*> vectorHANDLERS; |
|||
//typedef vector<STREAM_CTX*> vectorSTREAMS; |
|||
|
|||
class argusModuleEmbedVideo: public argusKernelModule, public basicMediaDestination, public basicThread { |
|||
private: |
|||
basicEventHeap * m_pEventHeap; |
|||
static void * webClientProc( void *ptr ); |
|||
int m_nSocketDescriptor; |
|||
basicMutex m_mHandlersProtector; |
|||
vectorHANDLERS m_vHandlersPool; |
|||
DBC_MODULE_EMBED_VIDEO_DATA m_sEmbedVideoData; |
|||
uint8_t * n_pNoSignalData; |
|||
uint32_t m_nNoSignalSize; |
|||
cv::Mat m_mLogoPic; |
|||
cv::Mat m_mLogoMask; |
|||
bool registerForMediaStream( uint32_t id, WEB_CLIENT_CTX *&CTX ); |
|||
protected: |
|||
/* From Basic Thread */ |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
explicit argusModuleEmbedVideo( uint32_t moduleID ); |
|||
~argusModuleEmbedVideo(); |
|||
/* From Kernel Module */ |
|||
virtual bool reloadSettings(); |
|||
virtual bool startService(); |
|||
virtual bool stopService(); |
|||
virtual void dispatchEvent(EVENT_CONTAINER *Evt); |
|||
virtual bool validate(); |
|||
/* from Media Destination */ |
|||
virtual void pushFrame(AVFrame *Frame, void* src = NULL); |
|||
//virtual void pushFrame(cv::Mat* Frame, void* src = NULL); |
|||
virtual void pushFrame( cv::Mat &Frame, void* src = NULL); |
|||
}; |
|||
#endif |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue