You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

240 lines
8.9 KiB

#ifndef __ONVIF_MEDIA_OBSERVER_HEADER__
#define __ONVIF_MEDIA_OBSERVER_HEADER__
#ifdef __linux__
#include <fcntl.h>
#else
#include <winsock2.h>
#endif
#include <iostream>
#include <string>
#include <vector>
#include "../../components/base/basicLogCollection.h"
#include "../../components/base/basicSettingsProvider.h"
#include "../protocol/xmlParser.h"
#pragma warning(disable: 4251)
#define MAX_BUFF_SIZE 102400 //100K
#define HTTPMU_HOST_ADDRESS "239.255.255.250"
#define HTTPMU_HOST_PORT 3702
/*
#define SEARCH_REQUEST_STRING "M-SEARCH * HTTP/1.1\r\nST:ssdp:all\r\nMX: 3\r\nMAN:\"ssdp:discover\"\r\nHOST: 239.255.255.250:1900\r\n\r\n"
//*/
/*
#define SEARCH_REQUEST_STRING "M-SEARCH * HTTP/1.1\r\n" \
"ST:ssdp:all\r\n" \
"MX: 3\r\n" \
"MAN:\"ssdp:discover\"\r\n" \
"HOST: 239.255.255.250:3702\r\n" \
"\r\n"
//*/
#define SEARCH_REQUEST_STRING_0 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" \
"<SOAP:Envelope xmlns:SOAP=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:DISCOVERY=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:ssdp=\"http://example.com/wsdp/sample/print\">\n" \
"<SOAP:Header>\n" \
"<wsa:MessageID>urn:uuid:ac9823ee-6813-498c-8c1b-6272a22353f7</wsa:MessageID>\n" \
"<wsa:Action>\n" \
"http ://schemas.xmlsoap.org/ws/2005/04/discovery/Probe\n" \
"</wsa:Action>\n" \
"<wsa:To>urn:schemas-xmlsoap-org:ws:2005:04:discovery</wsa:To>\n" \
"</SOAP:Header>\n" \
"<SOAP:Body>\n" \
"<DISCOVERY:Probe>\n" \
"<DISCOVERY:Types>ssdp:any</DISCOVERY:Types>\n" \
"</DISCOVERY:Probe>\n" \
"</SOAP:Body>\n" \
"</SOAP:Envelope>\r\n\r\n"
#define SEARCH_REQUEST_STRING_1 "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" \
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:SOAP-ENC=\"http://www.w3.org/2003/05/soap-encoding\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:wsdd=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\" xmlns:tds=\"http://www.onvif.org/ver10/device/wsdl\" xmlns:dn=\"http://www.onvif.org/ver10/network/wsdl\">" \
"<SOAP-ENV:Header>" \
"<wsa:MessageID>urn:uuid:ac9823ee-6813-498c-8c1b-6272a22353f7</wsa:MessageID>" \
"<wsa:To SOAP-ENV:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>\n" \
"<wsa:Action SOAP-ENV:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2005/04/discovery/ProbeMatches</wsa:Action>" \
"</SOAP-ENV:Header>" \
"<SOAP-ENV:Body>" \
"<wsdd:ProbeMatches>" \
"<wsdd:ProbeMatch>" \
"<wsdd:Types>dn:NetworkVideoTransmitter tds:Device</wsdd:Types>" \
"<wsdd:Scopes>onvif://www.onvif.org/Profile/Streaming onvif://www.onvif.org/type/video_encoder onvif://www.onvif.org/type/audio_encoder onvif://www.onvif.org/type/ptz onvif://www.onvif.org/hardware/HD_PREDATOR onvif://www.onvif.org/name/PREDATOR onvif://www.onvif.org/location/</wsdd:Scopes>" \
"<wsdd:XAddrs>SERVICE_URI</wsdd:XAddrs>" \
"<wsdd:MetadataVersion>1</wsdd:MetadataVersion>" \
"</wsdd:ProbeMatch>" \
"</wsdd:ProbeMatches>" \
"<DISCOVERY:Probe>\n" \
"<DISCOVERY:Types>dn:NetworkVideoTransmitter tds:Device</DISCOVERY:Types>\n" \
"</DISCOVERY:Probe>\n" \
"</SOAP-ENV:Body>" \
"</SOAP-ENV:Envelope>"
#define SEARCH_REQUEST_STRING "<? xml version=\"1.0\" encoding=\"UTF-8\" ?>" \
"<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\"> " \
"<e:Header>" \
"<w:MessageID>uuid:84ede3de-7dec-11d0-c360-f01234567890</w:MessageID>" \
"<w:To e:mustUnderstand=\"true\">urn:schemas-xmlsoap-org:ws:2005:04:discovery</w:To>" \
"<w:Action a:mustUnderstand=\"true\">http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</w:Action>" \
"</e:Header>" \
"<e:Body><d:Probe><d:Types>dn:NetworkVideoTransmitter</d:Types></d:Probe></e:Body></e:Envelope>"
#define HTTP_OK "200 OK"
#define DEFAULT_HTTP_PORT 80
/******************************************************************
** Action Defines *
*******************************************************************/
#define HTTP_HEADER_ACTION "POST %s HTTP/1.1\r\n" \
"HOST: %s:%u\r\n" \
"SOAPACTION:\"%s#%s\"\r\n" \
"CONTENT-TYPE: text/xml ; charset=\"utf-8\"\r\n"\
"Content-Length: %d \r\n\r\n"
#define SOAP_ACTION "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" \
"<s:Envelope xmlns:s=" \
"\"http://schemas.xmlsoap.org/soap/envelope/\" " \
"s:encodingStyle=" \
"\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n" \
"<s:Body>\r\n" \
"<u:%s xmlns:u=\"%s\">\r\n%s" \
"</u:%s>\r\n" \
"</s:Body>\r\n" \
"</s:Envelope>\r\n"
#define PORT_MAPPING_LEASE_TIME "63072000" //two year
#define ADD_PORT_MAPPING_PARAMS "<NewRemoteHost></NewRemoteHost>\r\n" \
"<NewExternalPort>%u</NewExternalPort>\r\n"\
"<NewProtocol>%s</NewProtocol>\r\n" \
"<NewInternalPort>%u</NewInternalPort>\r\n"\
"<NewInternalClient>%s</NewInternalClient>\r\n" \
"<NewEnabled>1</NewEnabled>\r\n" \
"<NewPortMappingDescription>%s</NewPortMappingDescription>\r\n" \
"<NewLeaseDuration>" \
PORT_MAPPING_LEASE_TIME \
"</NewLeaseDuration>\r\n"
class onvifMediaObserver;
typedef struct S_resultWoWo{
int wowoID;
char Types[256];
char XAddrs[1024];
}resultWoWo;
typedef vector<resultWoWo*> vectorWoWoResults;
typedef struct S_probeWoWo{
int AddressID;
char IpAddress[16];
int Port;
int socketFD;
char buff[MAX_BUFF_SIZE + 1];
CSTR send_buff;
CSTR recv_buff;
struct sockaddr_in r_address;
bool bOptVal;
int bOptLen;
int iOptLen;
int RetVal;
int index;
int step;
onvifMediaObserver *observer;
}probeWoWo;
typedef struct S_onvifObserverThread{
#ifdef __linux__
int m_dwThreadID;
pthread_t m_hThreadHandle;
#else
DWORD m_dwThreadID;
HANDLE m_hThreadHandle;
#endif
probeWoWo *context;
}onvifObserverThread;
typedef vector<onvifObserverThread*> onvifObserverThreads;
/**
* TODO: Add class description
*
* @author Gagua
*/
class onvifMediaObserver{
private:
basicLogCollection *m_pLog;
basicSettingsProvider *m_pSettings;
config_setting_t *m_pSettingsNode;
enumeratorInfo m_vLocalDevices;
localIpAddresses *m_pIpAddresses;
sourcePool m_vUsedDevices;
vectorWoWoResults m_vResultPool;
onvifObserverThreads m_vThreads;
bool m_bWSAOK;
int m_nStatus;
//OnvifClientDevice *m_pDevice;
public:
// Method to fetch singleton instance.
static onvifMediaObserver* getInstance();
// Destructor
virtual ~onvifMediaObserver();
int getNetworkCounts(){ return m_pIpAddresses->size(); };
bool startDiscovery( void );
localIpAddresses *getNetworks(void){ return m_pIpAddresses; };
vectorWoWoResults *getResults(void){ return &m_vResultPool; };
int getStatus(){ return m_nStatus; };
protected:
// Constructor - protected so users cannot call it.
onvifMediaObserver();
private:
bool startProbe(CSTR IP, int ID, int stp);
bool loadAssignedSources(void);
static void *probeThreadProc(void *);
probeWoWo *init_WoWo(CSTR ADR, int ID, int stp = 1);
// private static member referencing the single instance of the object
// TODO: Replace mediaVideoSourceManager with the type of object you want to
// return the single instance of
static onvifMediaObserver* _instance;
// Copy constructor
// Declared but not defined to prevent auto-generated
// copy constructor. Refer to "Effective C++" by Meyers
onvifMediaObserver(const onvifMediaObserver& src);
// Assignment operator
// Declared but not defined to prevent auto-generated
// assignment operator. Refer to "Effective C++" by Meyers
onvifMediaObserver& operator=(const onvifMediaObserver& src);
};
// Destructor implementation
inline onvifMediaObserver::~onvifMediaObserver(){
};
// TODO: Uncomment the copy constructor when you need it.
//inline mediaVideoSourceManager::mediaVideoSourceManager(const mediaVideoSourceManager& src)
//{
// // TODO: copy
//}
// TODO: Uncomment the assignment operator when you need it.
//inline mediaVideoSourceManager& mediaVideoSourceManager::operator=(const mediaVideoSourceManager& rhs)
//{
// if (this == &rhs) {
// return *this;
// }
//
// // TODO: assignment
//
// return *this;
//}
#endif