Initial
BIN
CapServer/20051130220909421.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220911609.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220913750.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220915921.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220918187.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220920453.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220922703.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220924875.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/2005113022092715.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220929187.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220931453.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220933703.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220935968.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220938156.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220940296.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220942468.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130220944734.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221457468.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221459734.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221501984.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221504156.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221506296.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221508484.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221510734.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221512984.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221515156.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221517296.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221519468.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221521750.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/2005113022152415.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221526250.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221528421.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221530578.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221532765.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/2005113022153515.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221537390.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221539531.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221541703.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221543843.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/2005113022154631.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221548265.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130221550437.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130222002343.bmp
Normal file
|
After Width: | Height: | Size: 226 KiB |
BIN
CapServer/20051130222445656.bmp
Normal file
|
After Width: | Height: | Size: 226 KiB |
BIN
CapServer/20051130223038812tmp.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130224123468tmp.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130224729375.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/20051130224729453.bmp
Normal file
|
After Width: | Height: | Size: 226 KiB |
BIN
CapServer/20051130225022656.jpg
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
CapServer/CapServer.aps
Normal file
133
CapServer/CapServer.dsp
Normal file
@@ -0,0 +1,133 @@
|
||||
# Microsoft Developer Studio Project File - Name="CapServer" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=CapServer - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "CapServer.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "CapServer.mak" CFG="CapServer - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "CapServer - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "CapServer - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "CapServer - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "NDEBUG"
|
||||
# ADD RSC /l 0x409 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
|
||||
!ELSEIF "$(CFG)" == "CapServer - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Gz /MTd /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "STRICT" /D "__FLAT__" /D "_COMMON_USENLS_" /YX /FD /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib winmm.lib vfw32.lib wsock32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "CapServer - Win32 Release"
|
||||
# Name "CapServer - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\gensrv.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Main.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MainApplication.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\MonitorThread.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Params.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SocketHeader.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\SocketServer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\WDMCap.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\CapServer.rc
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
134
CapServer/CapServer.dsw
Normal file
@@ -0,0 +1,134 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "CapServer"=.\CapServer.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name bsptree
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name codec
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name common
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name jpeg6b
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name socket
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name vidcaplib
|
||||
End Project Dependency
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name thread
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "bsptree"=..\bsptree\bsptree.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "codec"=..\codec\codec.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "common"=..\common\common.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "jpeg6b"="..\..\parts\jpeg-6b\jpeg6b.dsp" - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "socket"=..\socket\socket.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "thread"=..\thread\thread.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "vidcaplib"=..\vidcap\vidcaplib.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
4
CapServer/CapServer.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef _CAPSEVER_CAPSERVER_H_
|
||||
#define _CAPSEVER_CAPSERVER_H_
|
||||
|
||||
#endif
|
||||
BIN
CapServer/CapServer.ncb
Normal file
BIN
CapServer/CapServer.opt
Normal file
55
CapServer/CapServer.plg
Normal file
@@ -0,0 +1,55 @@
|
||||
<html>
|
||||
<body>
|
||||
<pre>
|
||||
<h1>Build Log</h1>
|
||||
<h3>
|
||||
--------------------Configuration: vidcaplib - Win32 Debug--------------------
|
||||
</h3>
|
||||
<h3>Command Lines</h3>
|
||||
Creating temporary file "C:\DOCUME~1\sean\LOCALS~1\Temp\RSP251.tmp" with contents
|
||||
[
|
||||
/nologo /Gz /MTd /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /D "STRICT" /D "__FLAT__" /Fp"debug/vidcaplib.pch" /YX /Fo"debug/" /Fd"debug/" /FD /GZ /c
|
||||
"D:\work\vidcap\BMPCAP.CPP"
|
||||
]
|
||||
Creating command line "cl.exe @C:\DOCUME~1\sean\LOCALS~1\Temp\RSP251.tmp"
|
||||
Creating command line "link.exe -lib /nologo /out:"debug\vidcaplib.lib" .\debug\BMPCAP.OBJ .\debug\VIDCAP.OBJ .\debug\VidReg.obj "
|
||||
<h3>Output Window</h3>
|
||||
Compiling...
|
||||
BMPCAP.CPP
|
||||
Creating library...
|
||||
<h3>
|
||||
--------------------Configuration: CapServer - Win32 Debug--------------------
|
||||
</h3>
|
||||
<h3>Command Lines</h3>
|
||||
Creating temporary file "C:\DOCUME~1\sean\LOCALS~1\Temp\RSP252.tmp" with contents
|
||||
[
|
||||
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib winmm.lib vfw32.lib wsock32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/CapServer.pdb" /debug /machine:I386 /out:"Debug/CapServer.exe" /pdbtype:sept
|
||||
.\Debug\gensrv.obj
|
||||
.\Debug\Main.obj
|
||||
.\Debug\MainApplication.obj
|
||||
.\Debug\MonitorThread.obj
|
||||
.\Debug\Params.obj
|
||||
.\Debug\SocketHeader.obj
|
||||
.\Debug\SocketServer.obj
|
||||
.\Debug\WDMCap.obj
|
||||
.\Debug\CapServer.res
|
||||
\work\exe\msbsp.lib
|
||||
\work\codec\Debug\codec.lib
|
||||
\work\exe\mscommon.lib
|
||||
"\parts\jpeg-6b\lib\jpeg6b.lib"
|
||||
\work\exe\mssocket.lib
|
||||
\work\vidcap\debug\vidcaplib.lib
|
||||
\work\exe\msthread.lib
|
||||
]
|
||||
Creating command line "link.exe @C:\DOCUME~1\sean\LOCALS~1\Temp\RSP252.tmp"
|
||||
<h3>Output Window</h3>
|
||||
Linking...
|
||||
Creating library Debug/CapServer.lib and object Debug/CapServer.exp
|
||||
|
||||
|
||||
|
||||
<h3>Results</h3>
|
||||
CapServer.exe - 0 error(s), 0 warning(s)
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
2
CapServer/CapServer.rc
Normal file
@@ -0,0 +1,2 @@
|
||||
#include <CapServer/CapServer.h>
|
||||
|
||||
BIN
CapServer/Debug/CapServer.exe
Normal file
BIN
CapServer/Debug/CapServer.exp
Normal file
BIN
CapServer/Debug/CapServer.ilk
Normal file
BIN
CapServer/Debug/CapServer.lib
Normal file
BIN
CapServer/Debug/CapServer.pdb
Normal file
BIN
CapServer/Debug/CapServer.res
Normal file
BIN
CapServer/Debug/Main.obj
Normal file
BIN
CapServer/Debug/MainApplication.obj
Normal file
BIN
CapServer/Debug/MonitorThread.obj
Normal file
BIN
CapServer/Debug/Params.obj
Normal file
BIN
CapServer/Debug/SocketHeader.obj
Normal file
BIN
CapServer/Debug/SocketServer.obj
Normal file
BIN
CapServer/Debug/WDMCap.obj
Normal file
BIN
CapServer/Debug/gensrv.obj
Normal file
BIN
CapServer/Debug/image.jpg
Normal file
|
After Width: | Height: | Size: 26 KiB |
3
CapServer/Debug/read.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
:loop
|
||||
capserver client
|
||||
goto loop
|
||||
BIN
CapServer/Debug/vc60.idb
Normal file
BIN
CapServer/Debug/vc60.pdb
Normal file
25
CapServer/Main.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <common/windows.hpp>
|
||||
#include <common/string.hpp>
|
||||
#include <CapServer/MainApplication.hpp>
|
||||
|
||||
int handlerRoutine(DWORD ctrlType);
|
||||
|
||||
bool running=true;
|
||||
|
||||
MainApplication mainApplication;
|
||||
|
||||
void main(int argc,char **argv)
|
||||
{
|
||||
mainApplication.run(argc,argv);
|
||||
}
|
||||
|
||||
int handlerRoutine(DWORD eventType) // this is connected ad-hoc to generic server, could be cleaner
|
||||
{
|
||||
if(CTRL_C_EVENT==eventType)
|
||||
{
|
||||
::printf("Caught Ctrl-C...\n");
|
||||
running=false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
125
CapServer/MainApplication.cpp
Normal file
@@ -0,0 +1,125 @@
|
||||
#include <CapServer/MainApplication.hpp>
|
||||
|
||||
MainApplication::MainApplication()
|
||||
{
|
||||
}
|
||||
|
||||
MainApplication::~MainApplication()
|
||||
{
|
||||
}
|
||||
|
||||
int MainApplication::run(int argc,char **argv)
|
||||
{
|
||||
String command;
|
||||
|
||||
mParams.setArgs(argc,argv);
|
||||
switch(mParams.getRequest())
|
||||
{
|
||||
case Params::Client :
|
||||
mParams.showParams();
|
||||
handleClient(mParams.getServer(),mParams.getPort().toInt());
|
||||
break;
|
||||
case Params::Server :
|
||||
mParams.showParams();
|
||||
handleServer(mParams.getHost(),mParams.getPort().toInt(),mParams.getTimeout().toInt(),mParams.getDevice().toInt(),mParams.getRetain(),mParams.getDebug(),mParams.getShowSrcDlg());
|
||||
break;
|
||||
case Params::Settings :
|
||||
mParams.showParams();
|
||||
handleSettings(mParams.getShowSrcDlg());
|
||||
break;
|
||||
case Params::None :
|
||||
displayUsage();
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MainApplication::handleServer(const String &host,int port,int timeout,int deviceIndex,bool retain,bool debug,bool showSrcDlg)
|
||||
{
|
||||
message("[MainApplication::handleServer]starting server");
|
||||
SocketServer socketServer(host,port,deviceIndex,retain,debug,showSrcDlg,timeout);
|
||||
socketServer.listen(host,port);
|
||||
}
|
||||
|
||||
void MainApplication::handleClient(const String &host,int port)
|
||||
{
|
||||
INETSocketAddress internetSocketAddress;
|
||||
InternetAddress internetAddress(127,0,0,1);
|
||||
Socket socket;
|
||||
SocketHeader socketHeader;
|
||||
Array<BYTE> content;
|
||||
|
||||
message("[MainApplication::handleClient]starting client");
|
||||
internetSocketAddress.family(PF_INET);
|
||||
internetSocketAddress.port(1024);
|
||||
internetSocketAddress.internetAddress(internetAddress);
|
||||
if(!socket.create())
|
||||
{
|
||||
message("[MainApplication::handleClient]create failed...");
|
||||
return;
|
||||
}
|
||||
if(!socket.connect(internetSocketAddress))
|
||||
{
|
||||
message("[MainApplication::handleClient]connect failed...");
|
||||
return;
|
||||
}
|
||||
message("[MainApplication::handleClient]reading socket header...");
|
||||
socketHeader.unmarshall(socket);
|
||||
message("[MainApplication::handleClient]header length",socketHeader.getSizeHeader());
|
||||
message("[MainApplication::handleClient]version",socketHeader.getVersion());
|
||||
message("[MainApplication::handleClient]content length",socketHeader.getContentLength());
|
||||
message("[MainApplication::handleClient]content type",(int)socketHeader.getContentType());
|
||||
content.size(socketHeader.getContentLength());
|
||||
message("[MainApplication::handleClient]reading content...");
|
||||
socket.receive((char*)&content[0],content.size());
|
||||
message("[MainApplication::handleClient]done...");
|
||||
socket.destroy();
|
||||
}
|
||||
|
||||
void MainApplication::handleSettings(bool showSrcDlg)
|
||||
{
|
||||
VidReg vidReg;
|
||||
Block<DriverInfo> driverInfoBlock;
|
||||
|
||||
VidCap::getDrivers(driverInfoBlock);
|
||||
message("[MainApplication::handleSettings]Capture File",vidReg.getCaptureFile());
|
||||
message("[MainApplication::handleSettings]Sequencing",vidReg.getSequencing()?"true":"false");
|
||||
message("[MainApplication::handleSettings]Preview Rate",vidReg.getPreviewRate());
|
||||
message("[MainApplication::handleSettings]Preview Width",vidReg.getPreviewWidth());
|
||||
message("[MainApplication::handleSettings]Preview Height",vidReg.getPreviewHeight());
|
||||
message("[MainApplication::handleSettings]Capture Width",vidReg.getCaptureWidth());
|
||||
message("[MainApplication::handleSettings]Capture Height",vidReg.getCaptureHeight());
|
||||
message("[MainApplication::handleSettings]Capture Quality",vidReg.getQuality());
|
||||
message("[MainApplication::handleSettings]***********CAPTURE DEVICE LIST*********");
|
||||
if(!driverInfoBlock.size())message("[MainApplication::handleSettings]No capture devices on system.");
|
||||
for(int index=0;index<driverInfoBlock.size();index++)
|
||||
{
|
||||
WDMCap wdmCap(index);
|
||||
if(wdmCap.isConnected())
|
||||
{
|
||||
message(String("[MainApplication::handleSettings]")+driverInfoBlock[index].driverName()+String(" ***Available"));
|
||||
if(showSrcDlg)wdmCap.dialogVideoSource();
|
||||
}
|
||||
else message(String("[MainApplication::handleSettings]")+driverInfoBlock[index].driverName()+String(" ***Unavailable"));
|
||||
}
|
||||
}
|
||||
|
||||
void MainApplication::displayUsage(void)
|
||||
{
|
||||
message("CapServer [run host port device retain debug showsrcdlg]");
|
||||
message(" run={server} | {client} | {settings}");
|
||||
message(" server=<servername> | <serveraddress>");
|
||||
message(" host=<hostname> | <hostaddress>");
|
||||
message(" port=<port>");
|
||||
message(" device=<index>");
|
||||
message(" retain={true} | {false}");
|
||||
message(" debug={true} | {false}");
|
||||
message(" showsrcdlg={true} | {false}");
|
||||
message(" timeout=<value> (Delay between frame grab for retain mode. (ms))");
|
||||
message(" ");
|
||||
message(" CapServer run=server host=127.0.0.1 port=1024");
|
||||
message(" CapServer run=server host=127.0.0.1 port=1024 device=0");
|
||||
message(" CapServer run=client server=127.0.0.1 port=1024");
|
||||
message(" CapServer run=settings");
|
||||
}
|
||||
|
||||
55
CapServer/MainApplication.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef _CAPSERVER_MAINAPPLICATION_HPP_
|
||||
#define _CAPSERVER_MAINAPPLICATION_HPP_
|
||||
#ifndef _CAPSERVER_SOCKET_HEADER_HPP_
|
||||
#include <capserver/socketheader.hpp>
|
||||
#endif
|
||||
#ifndef _SOCKET_WSADATA_HPP_
|
||||
#include <socket/wsadata.hpp>
|
||||
#endif
|
||||
#ifndef _CAPSERVER_SOCKETSERVER_HPP_
|
||||
#include <CapServer/SocketServer.hpp>
|
||||
#endif
|
||||
#ifndef _CAPSERVER_PARAMS_HPP_
|
||||
#include <CapServer/Params.hpp>
|
||||
#endif
|
||||
#ifndef _VIDCAP_VIDREG_HPP_
|
||||
#include <vidcap/vidreg.hpp>
|
||||
#endif
|
||||
|
||||
class MainApplication
|
||||
{
|
||||
public:
|
||||
MainApplication();
|
||||
virtual ~MainApplication();
|
||||
int run(int argc,char **argv);
|
||||
private:
|
||||
void message(const String &message);
|
||||
void message(const String &message,int arg);
|
||||
void message(const String &message,const String &arg);
|
||||
void handleServer(const String &host,int port,int timeout,int deviceIndex,bool retain,bool debug,bool showSrcDlg);
|
||||
void handleClient(const String &server,int port);
|
||||
void handleSettings(bool showSrcDlg);
|
||||
void displayUsage(void);
|
||||
|
||||
WSASystem mWSASystem;
|
||||
Params mParams;
|
||||
};
|
||||
|
||||
inline
|
||||
void MainApplication::message(const String &message)
|
||||
{
|
||||
printf("%s\n",message.str());
|
||||
}
|
||||
|
||||
inline
|
||||
void MainApplication::message(const String &message,int arg)
|
||||
{
|
||||
printf("%s=%d\n",message.str(),arg);
|
||||
}
|
||||
|
||||
inline
|
||||
void MainApplication::message(const String &message,const String &arg)
|
||||
{
|
||||
printf("%s=%s\n",message.str(),arg.str());
|
||||
}
|
||||
#endif
|
||||
161
CapServer/MonitorThread.cpp
Normal file
@@ -0,0 +1,161 @@
|
||||
#include <common/windows.hpp>
|
||||
#include <common/array.hpp>
|
||||
#include <common/openfile.hpp>
|
||||
#include <CapServer/MonitorThread.hpp>
|
||||
#include <CapServer/SocketHeader.hpp>
|
||||
#include <socket/socket.hpp>
|
||||
#include <socket/hostent.hpp>
|
||||
|
||||
MonitorThread::MonitorThread()
|
||||
: mIsRunning(false), mTimeout(DefaultTimeout)
|
||||
{
|
||||
mCallback.setCallback(this,&MonitorThread::threadCallback);
|
||||
insertHandler(&mCallback);
|
||||
}
|
||||
|
||||
MonitorThread::~MonitorThread()
|
||||
{
|
||||
stop();
|
||||
removeHandler(&mCallback);
|
||||
}
|
||||
|
||||
void MonitorThread::startMonitor(const String &host,int port,DWORD timeout)
|
||||
{
|
||||
message("MonitorThread::startMonitor");
|
||||
ThreadMessage threadMessage(ThreadMessage::TM_USER,MsgMonitorStart);
|
||||
mHost=host;
|
||||
mPort=port;
|
||||
mTimeout=timeout;
|
||||
getHostAddress();
|
||||
postMessage(threadMessage);
|
||||
}
|
||||
|
||||
void MonitorThread::stopMonitor(void)
|
||||
{
|
||||
message("MonitorThread::startMonitor");
|
||||
ThreadMessage threadMessage(ThreadMessage::TM_USER,MsgMonitorStop);
|
||||
postMessage(threadMessage);
|
||||
mMonitorEvent.waitEvent();
|
||||
}
|
||||
|
||||
DWORD MonitorThread::threadCallback(ThreadMessage &threadMessage)
|
||||
{
|
||||
switch(threadMessage.message())
|
||||
{
|
||||
case ThreadMessage::TM_CREATE :
|
||||
break;
|
||||
case ThreadMessage::TM_DESTROY :
|
||||
break;
|
||||
case ThreadMessage::TM_USER :
|
||||
switch(MonitorThMsg(threadMessage.userDataOne()))
|
||||
{
|
||||
case MsgMonitorStart :
|
||||
handleMonitorStart();
|
||||
break;
|
||||
case MsgMonitorStop :
|
||||
handleMonitorStop();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MonitorThread::handleMonitorStart()
|
||||
{
|
||||
DWORD elapsedTime;
|
||||
message("[MonitorThread::handleMonitorStart]ENTER");
|
||||
mIsRunning=true;
|
||||
message(String("[MonitorThread::handleMonitorStart]InitDelay=")+String().fromInt(InitDelay)+String(" (ms)."));
|
||||
::Sleep(InitDelay);
|
||||
while(mIsRunning)
|
||||
{
|
||||
elapsedTime=::GetTickCount();
|
||||
getImage();
|
||||
elapsedTime=::GetTickCount()-elapsedTime;
|
||||
message("[MonitorThread::handleMonitorStart]GetImage Took "+String().fromInt(elapsedTime)+String(" (ms)."));
|
||||
::Sleep(mTimeout);
|
||||
}
|
||||
message("]MonitorThread::handleMonitorStart]LEAVE");
|
||||
}
|
||||
|
||||
void MonitorThread::handleMonitorStop()
|
||||
{
|
||||
message("[MonitorThread::handleMonitorStop]ENTER");
|
||||
message("[MonitorThread::handleMonitorStop]LEAVE");
|
||||
mIsRunning=false;
|
||||
}
|
||||
|
||||
void MonitorThread::getHostAddress()
|
||||
{
|
||||
Block<InternetAddress> internetAddresses;
|
||||
HostEnt hostEnt;
|
||||
|
||||
hostEnt.hostByName(mHost);
|
||||
internetAddresses=hostEnt.addresses();
|
||||
if(!internetAddresses.size())return;
|
||||
for(int index=0;index<internetAddresses.size();index++)
|
||||
{
|
||||
message(String("[MonitorThread::getHostAddress]")+mHost+String("->")+internetAddresses[0].toString());
|
||||
}
|
||||
mInternetAddress=internetAddresses[0];
|
||||
}
|
||||
|
||||
void MonitorThread::getImage()
|
||||
{
|
||||
INETSocketAddress internetSocketAddress;
|
||||
Socket socket;
|
||||
SocketHeader socketHeader;
|
||||
Array<BYTE> content;
|
||||
|
||||
message("[MonitorThread::getImage]starting client");
|
||||
internetSocketAddress.family(PF_INET);
|
||||
internetSocketAddress.port(mPort);
|
||||
internetSocketAddress.internetAddress(mInternetAddress);
|
||||
if(!socket.create())
|
||||
{
|
||||
message("[MonitorThread::getImage]create socket failed...");
|
||||
return;
|
||||
}
|
||||
if(!socket.connect(internetSocketAddress))
|
||||
{
|
||||
message(String("[MonitorThread::getImage]connect to '")+internetSocketAddress.toString()+String("' failed..."));
|
||||
return;
|
||||
}
|
||||
message("[MonitorThread::getImage]reading socket header...");
|
||||
socketHeader.unmarshall(socket);
|
||||
message("[MonitorThread::getImage]header length",socketHeader.getSizeHeader());
|
||||
message("[MonitorThread::getImage]version",socketHeader.getVersion());
|
||||
message("[MonitorThread::getImage]content length",socketHeader.getContentLength());
|
||||
message("[MonitorThread::getImage]content type",(int)socketHeader.getContentType());
|
||||
content.size(socketHeader.getContentLength());
|
||||
message("[MonitorThread::getImage]reading content...");
|
||||
socket.receive((char*)&content[0],content.size());
|
||||
saveImage(content);
|
||||
message("[MonitorThread::getImage]done...");
|
||||
socket.destroy();
|
||||
}
|
||||
|
||||
bool MonitorThread::saveImage(Array<BYTE> &imageData)
|
||||
{
|
||||
SystemTime systemTime;
|
||||
String strPathImageFile;
|
||||
FileHandle openFile;
|
||||
|
||||
if(!imageData.size())return message("[MonitorThread::saveImage] No Data"),false;
|
||||
strPathImageFile.reserve(1024);
|
||||
::sprintf(strPathImageFile,"%04d%02d%02d%02d%02d%02d%02d.jpg",
|
||||
systemTime.year(),systemTime.month(),systemTime.day(),
|
||||
systemTime.hour(),systemTime.minute(),systemTime.second(),
|
||||
systemTime.milliseconds());
|
||||
if(!openFile.open(strPathImageFile,FileHandle::Write,FileHandle::ShareRead,FileHandle::Overwrite))
|
||||
{
|
||||
message(String("[MonitorThread::saveImage]Open '")+strPathImageFile+String("' for write Failed."));
|
||||
return false;
|
||||
}
|
||||
openFile.write(&imageData[0],imageData.size());
|
||||
openFile.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
50
CapServer/MonitorThread.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#ifndef _CAPSERVER_MONITORTHREAD_HPP_
|
||||
#define _CAPSERVER_MONITORTHREAD_HPP_
|
||||
#ifndef _SOCKET_SOCKET_HPP_
|
||||
#include <socket/socket.hpp>
|
||||
#endif
|
||||
#ifndef _THREAD_MESSAGETHREAD_HPP_
|
||||
#include <thread/mthread.hpp>
|
||||
#endif
|
||||
|
||||
class MonitorThread : private MessageThread
|
||||
{
|
||||
public:
|
||||
MonitorThread();
|
||||
virtual ~MonitorThread();
|
||||
void startMonitor(const String &host,int port,DWORD timeout);
|
||||
void stopMonitor(void);
|
||||
private:
|
||||
typedef enum MonitorThMsg{MsgMonitorStart,MsgMonitorStop};
|
||||
enum{DefaultTimeout=1000,InitDelay=0}; // InitDelay=10000
|
||||
DWORD threadCallback(ThreadMessage &threadMessage);
|
||||
void handleMonitorStart(void);
|
||||
void handleMonitorStop(void);
|
||||
void message(const String &string);
|
||||
void message(const String &string,int value);
|
||||
void getHostAddress(void);
|
||||
void getImage(void);
|
||||
bool saveImage(Array<BYTE> &imageData);
|
||||
|
||||
ThreadCallback<MonitorThread> mCallback;
|
||||
InternetAddress mInternetAddress;
|
||||
Event mMonitorEvent;
|
||||
bool mIsRunning;
|
||||
String mHost;
|
||||
int mPort;
|
||||
DWORD mTimeout;
|
||||
};
|
||||
|
||||
inline
|
||||
void MonitorThread::message(const String &string)
|
||||
{
|
||||
::printf("%s\n",string.str());
|
||||
}
|
||||
|
||||
inline
|
||||
void MonitorThread::message(const String &string,int value)
|
||||
{
|
||||
::printf("%s=%d\n",string.str(),value);
|
||||
}
|
||||
#endif
|
||||
|
||||
72
CapServer/NameValuePair.hpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef _CAPSERVER_NAMEVALUE_HPP_
|
||||
#define _CAPSERVER_NAMEVALUE_HPP_
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
|
||||
class NameValuePair
|
||||
{
|
||||
public:
|
||||
NameValuePair();
|
||||
NameValuePair(const String &name,const String &value);
|
||||
const String &getName(void)const;
|
||||
void setName(const String &name);
|
||||
const String &getValue(void)const;
|
||||
void setValue(const String &value);
|
||||
bool fromString(const String &string);
|
||||
String toString(void)const;
|
||||
private:
|
||||
String mName;
|
||||
String mValue;
|
||||
};
|
||||
|
||||
inline
|
||||
NameValuePair::NameValuePair()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
NameValuePair::NameValuePair(const String &name,const String &value)
|
||||
: mName(name), mValue(value)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
const String &NameValuePair::getName(void)const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
inline
|
||||
void NameValuePair::setName(const String &name)
|
||||
{
|
||||
mName=name;
|
||||
}
|
||||
|
||||
inline
|
||||
const String &NameValuePair::getValue(void)const
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
inline
|
||||
void NameValuePair::setValue(const String &value)
|
||||
{
|
||||
mValue=value;
|
||||
}
|
||||
|
||||
inline
|
||||
bool NameValuePair::fromString(const String &string)
|
||||
{
|
||||
if(string.isNull())return false;
|
||||
mName=string.betweenString(0,'=');
|
||||
mValue=string.betweenString('=',0);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline
|
||||
String NameValuePair::toString(void)const
|
||||
{
|
||||
return mName+String("=")+mValue;
|
||||
}
|
||||
#endif
|
||||
86
CapServer/Params.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#include <common/stdio.hpp>
|
||||
#include <CapServer/Params.hpp>
|
||||
|
||||
void Params::setArgs(int argc,char **argv)
|
||||
{
|
||||
String strArg;
|
||||
getParams(argc,argv);
|
||||
if(getServer().isNull())setServer("127.0.0.1");
|
||||
if(getHost().isNull())setHost("127.0.0.1");
|
||||
if(getPort().isNull())setPort("1024");
|
||||
if(getTimeout().isNull())setTimeout("1000");
|
||||
if(getDevice().isNull())setDevice("0");
|
||||
strArg=getValue(mRetainKey);
|
||||
strArg.lower();
|
||||
if(!(strArg==String("true")) && !(strArg==String("false")))setRetain(false);
|
||||
else if(strArg==String("true"))setRetain(true);
|
||||
else setRetain(false);
|
||||
strArg=getValue(mDebugKey);
|
||||
strArg.lower();
|
||||
if(!(strArg==String("true")) && !(strArg==String("false")))setDebug(false);
|
||||
else if(strArg==String("true"))setDebug(true);
|
||||
else setDebug(false);
|
||||
strArg=getValue(mShowSrcDlgKey);
|
||||
strArg.lower();
|
||||
if(!(strArg==String("true")) && !(strArg==String("false")))setShowSrcDlg(false);
|
||||
else if(strArg==String("true"))setShowSrcDlg(true);
|
||||
else setShowSrcDlg(false);
|
||||
}
|
||||
|
||||
int Params::getParams(int argc,char**argv)
|
||||
{
|
||||
mNameValuePairs.remove();
|
||||
for(int index=0;index<argc;index++)
|
||||
{
|
||||
NameValuePair nameValuePair;
|
||||
nameValuePair.fromString(argv[index]);
|
||||
mNameValuePairs.insert(&nameValuePair);
|
||||
::OutputDebugString(nameValuePair.toString()+String("\n"));
|
||||
}
|
||||
return mNameValuePairs.size();
|
||||
}
|
||||
|
||||
String Params::getValue(const String &key)const
|
||||
{
|
||||
for(int index=0;index<mNameValuePairs.size();index++)
|
||||
{
|
||||
NameValuePair &nameValuePair=((Params&)*this).mNameValuePairs[index];
|
||||
if(nameValuePair.getName()==key)return nameValuePair.getValue();
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
void Params::setValue(const String &key,const String &value)
|
||||
{
|
||||
for(int index=0;index<mNameValuePairs.size();index++)
|
||||
{
|
||||
NameValuePair &nameValuePair=mNameValuePairs[index];
|
||||
if(nameValuePair.getName()==key)
|
||||
{
|
||||
nameValuePair.setValue(value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
mNameValuePairs.insert(&NameValuePair(key,value));
|
||||
}
|
||||
|
||||
Params::Request Params::getRequest(void)const
|
||||
{
|
||||
String strRequest(getRun());
|
||||
if(strRequest=="client")return Client;
|
||||
else if(strRequest=="server")return Server;
|
||||
else if(strRequest=="settings")return Settings;
|
||||
return None;
|
||||
}
|
||||
|
||||
void Params::showParams(void)
|
||||
{
|
||||
for(int index=0;index<mNameValuePairs.size();index++)
|
||||
{
|
||||
NameValuePair &nameValuePair=mNameValuePairs[index];
|
||||
::printf("[Params::showParams]arg[%d]%s=%s\n",
|
||||
index,
|
||||
nameValuePair.getName().str(),
|
||||
nameValuePair.getValue().str());
|
||||
}
|
||||
}
|
||||
184
CapServer/Params.hpp
Normal file
@@ -0,0 +1,184 @@
|
||||
#ifndef _CAPSERVER_PARAMS_HPP_
|
||||
#define _CAPSERVER_PARAMS_HPP_
|
||||
#ifndef _COMMON_BLOCK_HPP_
|
||||
#include <common/block.hpp>
|
||||
#endif
|
||||
#ifndef _CAPSERVER_NAMEVALUE_HPP_
|
||||
#include <CapServer/NameValuePair.hpp>
|
||||
#endif
|
||||
|
||||
class Params
|
||||
{
|
||||
public:
|
||||
typedef enum Request{Server,Client,Settings,None};
|
||||
Params(int argc,char **argv);
|
||||
Params();
|
||||
virtual ~Params();
|
||||
Request getRequest(void)const;
|
||||
String getServer(void)const;
|
||||
String getHost(void)const;
|
||||
String getPort(void)const;
|
||||
String getDevice(void)const;
|
||||
bool getRetain(void)const;
|
||||
bool getDebug(void)const;
|
||||
String getTimeout(void)const;
|
||||
bool getShowSrcDlg(void)const;
|
||||
void setArgs(int argc,char **argv);
|
||||
void showParams(void);
|
||||
private:
|
||||
int getParams(int argc,char **argv);
|
||||
String getValue(const String &key)const;
|
||||
void setValue(const String &key,const String &value);
|
||||
String getRun(void)const;
|
||||
void setServer(const String &server);
|
||||
void setHost(const String &host);
|
||||
void setPort(const String &port);
|
||||
void setDevice(const String &device);
|
||||
void setRetain(bool retain);
|
||||
void setDebug(bool debug);
|
||||
void setTimeout(const String &timeout);
|
||||
void setShowSrcDlg(bool showSrcDlg);
|
||||
|
||||
Block<NameValuePair> mNameValuePairs;
|
||||
String mRunKey;
|
||||
String mServerKey;
|
||||
String mHostKey;
|
||||
String mPortKey;
|
||||
String mDeviceKey;
|
||||
String mRetainKey;
|
||||
String mDebugKey;
|
||||
String mShowSrcDlgKey;
|
||||
String mTimeoutKey;
|
||||
};
|
||||
|
||||
inline
|
||||
Params::Params(int argc,char **argv)
|
||||
: mRunKey("run"), mServerKey("server"), mHostKey("host"), mPortKey("port"), mDeviceKey("device"),
|
||||
mRetainKey("retain"), mDebugKey("debug"), mShowSrcDlgKey("showsrcdlg"), mTimeoutKey("timeout")
|
||||
{
|
||||
getParams(argc,argv);
|
||||
}
|
||||
|
||||
inline
|
||||
Params::Params()
|
||||
: mRunKey("run"), mServerKey("server"), mHostKey("host"), mPortKey("port"), mDeviceKey("device"),
|
||||
mRetainKey("retain"), mDebugKey("debug"), mShowSrcDlgKey("showsrcdlg"), mTimeoutKey("timeout")
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Params::~Params()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
String Params::getRun(void)const
|
||||
{
|
||||
return getValue(mRunKey);
|
||||
}
|
||||
|
||||
inline
|
||||
String Params::getServer(void)const
|
||||
{
|
||||
return getValue(mServerKey);
|
||||
}
|
||||
|
||||
inline
|
||||
String Params::getHost(void)const
|
||||
{
|
||||
return getValue(mHostKey);
|
||||
}
|
||||
|
||||
inline
|
||||
String Params::getPort(void)const
|
||||
{
|
||||
return getValue(mPortKey);
|
||||
}
|
||||
|
||||
inline
|
||||
String Params::getDevice(void)const
|
||||
{
|
||||
return getValue(mDeviceKey);
|
||||
}
|
||||
|
||||
inline
|
||||
bool Params::getRetain(void)const
|
||||
{
|
||||
String strRetain(getValue(mRetainKey));
|
||||
if(strRetain=="true")return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline
|
||||
bool Params::getDebug(void)const
|
||||
{
|
||||
String strDebug(getValue(mDebugKey));
|
||||
if(strDebug=="true")return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline
|
||||
bool Params::getShowSrcDlg(void)const
|
||||
{
|
||||
String strValue(getValue(mShowSrcDlgKey));
|
||||
if(strValue=="true")return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setServer(const String &server)
|
||||
{
|
||||
setValue(mServerKey,server);
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setHost(const String &host)
|
||||
{
|
||||
setValue(mHostKey,host);
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setPort(const String &port)
|
||||
{
|
||||
setValue(mPortKey,port);
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setDevice(const String &device)
|
||||
{
|
||||
setValue(mDeviceKey,device);
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setRetain(bool retain)
|
||||
{
|
||||
if(retain)setValue(mRetainKey,"true");
|
||||
else setValue(mRetainKey,"false");
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setDebug(bool debug)
|
||||
{
|
||||
if(debug)setValue(mDebugKey,"true");
|
||||
else setValue(mDebugKey,"false");
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setShowSrcDlg(bool showSrcDlg)
|
||||
{
|
||||
if(showSrcDlg)setValue(mShowSrcDlgKey,"true");
|
||||
else setValue(mShowSrcDlgKey,"false");
|
||||
}
|
||||
|
||||
inline
|
||||
String Params::getTimeout(void)const
|
||||
{
|
||||
return getValue(mTimeoutKey);
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setTimeout(const String &timeout)
|
||||
{
|
||||
setValue(mTimeoutKey,timeout);
|
||||
}
|
||||
#endif
|
||||
64
CapServer/SocketHeader.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include <CapServer/SocketHeader.hpp>
|
||||
|
||||
SocketHeader::SocketHeader()
|
||||
: mSizeHeader(sizeof(mSizeHeader)+sizeof(mVersion)+sizeof(mContentLength)+sizeof(mContentType)),
|
||||
mVersion(0), mContentLength(0), mContentType(Unknown)
|
||||
{
|
||||
}
|
||||
|
||||
SocketHeader::~SocketHeader()
|
||||
{
|
||||
}
|
||||
|
||||
int SocketHeader::getSizeHeader(void)const
|
||||
{
|
||||
return mSizeHeader;
|
||||
}
|
||||
|
||||
int SocketHeader::getVersion(void)const
|
||||
{
|
||||
return mVersion;
|
||||
}
|
||||
|
||||
void SocketHeader::setVersion(int version)
|
||||
{
|
||||
mVersion=version;
|
||||
}
|
||||
|
||||
int SocketHeader::getContentLength(void)const
|
||||
{
|
||||
return mContentLength;
|
||||
}
|
||||
|
||||
void SocketHeader::setContentLength(int contentLength)
|
||||
{
|
||||
mContentLength=contentLength;
|
||||
}
|
||||
|
||||
SocketHeader::ContentType SocketHeader::getContentType(void)const
|
||||
{
|
||||
return (ContentType)mContentType;
|
||||
}
|
||||
|
||||
void SocketHeader::setContentType(int contentType)
|
||||
{
|
||||
mContentType=(ContentType)contentType;
|
||||
}
|
||||
|
||||
bool SocketHeader::marshall(Socket &socket)
|
||||
{
|
||||
if(!socket.send((char*)&mSizeHeader,sizeof(int)))return false;
|
||||
if(!socket.send((char*)&mVersion,sizeof(int)))return false;
|
||||
if(!socket.send((char*)&mContentLength,sizeof(int)))return false;
|
||||
if(!socket.send((char*)&mContentType,sizeof(int)))return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SocketHeader::unmarshall(Socket &socket)
|
||||
{
|
||||
if(!socket.receive((char*)&mSizeHeader,sizeof(int)))return false;
|
||||
if(!socket.receive((char*)&mVersion,sizeof(int)))return false;
|
||||
if(!socket.receive((char*)&mContentLength,sizeof(int)))return false;
|
||||
if(!socket.receive((char*)&mContentType,sizeof(int)))return false;
|
||||
return true;
|
||||
}
|
||||
31
CapServer/SocketHeader.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef _CAPSERVER_SOCKET_HEADER_HPP_
|
||||
#define _CAPSERVER_SOCKET_HEADER_HPP_
|
||||
#ifndef _COMMON_WINDOWS_HPP_
|
||||
#include <common/windows.hpp>
|
||||
#endif
|
||||
#ifndef _SOCKET_SOCKET_HPP_
|
||||
#include <socket/socket.hpp>
|
||||
#endif
|
||||
|
||||
class SocketHeader
|
||||
{
|
||||
public:
|
||||
typedef enum ContentType{Unknown,ImageJPG};
|
||||
SocketHeader();
|
||||
virtual ~SocketHeader();
|
||||
int getSizeHeader(void)const;
|
||||
int getVersion(void)const;
|
||||
void setVersion(int version);
|
||||
int getContentLength(void)const;
|
||||
void setContentLength(int contentLength);
|
||||
ContentType getContentType(void)const;
|
||||
void setContentType(int contentType);
|
||||
bool marshall(Socket &socket);
|
||||
bool unmarshall(Socket &socket);
|
||||
private:
|
||||
int mSizeHeader;
|
||||
int mVersion;
|
||||
int mContentLength;
|
||||
int mContentType;
|
||||
};
|
||||
#endif
|
||||
105
CapServer/SocketServer.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include <common/OpenFile.hpp>
|
||||
#include <common/systime.hpp>
|
||||
#include <common/diskinfo.hpp>
|
||||
#include <CapServer/SocketServer.hpp>
|
||||
#include <CapServer/SocketHeader.hpp>
|
||||
|
||||
SocketServer::SocketServer(const String &host,int port,int deviceIndex,bool retain,bool debug,bool showSrcDlg,int timeout)
|
||||
: mWDMCap(deviceIndex), mDebug(debug)
|
||||
{
|
||||
if(showSrcDlg)mWDMCap.dialogVideoSource();
|
||||
if(retain)mMonitorThread.startMonitor(host,port,timeout);
|
||||
}
|
||||
|
||||
SocketServer::~SocketServer()
|
||||
{
|
||||
mMonitorThread.stopMonitor();
|
||||
}
|
||||
|
||||
void SocketServer::acceptHandler(SmartPointer<Socket> &socketControl)
|
||||
{
|
||||
if(mDebug)sendDebugFrame(*socketControl);
|
||||
else sendFrame(*socketControl);
|
||||
|
||||
}
|
||||
|
||||
void SocketServer::message(const String &string)
|
||||
{
|
||||
::printf("%s\n",string.str());
|
||||
}
|
||||
|
||||
void SocketServer::sendFrame(Socket &socketControl)
|
||||
{
|
||||
DiskInfo diskInfo;
|
||||
SystemTime systemTime;
|
||||
String strPathCaptureFile;
|
||||
SocketHeader socketHeader;
|
||||
Array<BYTE> charBytes;
|
||||
FileHandle openFile;
|
||||
DWORD elapsedTime;
|
||||
|
||||
socketHeader.setVersion(1);
|
||||
socketHeader.setContentType(SocketHeader::ImageJPG);
|
||||
socketHeader.setContentLength(0);
|
||||
strPathCaptureFile.reserve(1024);
|
||||
::sprintf(strPathCaptureFile,"%04d%02d%02d%02d%02d%02d%02d.jpg",
|
||||
systemTime.year(),systemTime.month(),systemTime.day(),
|
||||
systemTime.hour(),systemTime.minute(),systemTime.second(),
|
||||
systemTime.milliseconds());
|
||||
elapsedTime=::GetTickCount();
|
||||
mWDMCap.setCaptureFileName(strPathCaptureFile);
|
||||
mWDMCap.grabFrameNoStop();
|
||||
elapsedTime=::GetTickCount()-elapsedTime;
|
||||
message(String("[SocketServer::sendFrame] Grab frame took ")+String().fromInt(elapsedTime)+String(" (ms)"));
|
||||
if(!openFile.open(strPathCaptureFile,FileHandle::Read,FileHandle::ShareRead))
|
||||
{
|
||||
socketHeader.marshall(socketControl);
|
||||
}
|
||||
else
|
||||
{
|
||||
charBytes.size(openFile.size());
|
||||
socketHeader.setContentLength(charBytes.size());
|
||||
elapsedTime=::GetTickCount();
|
||||
openFile.read((BYTE*)&charBytes[0],charBytes.size());
|
||||
elapsedTime=::GetTickCount()-elapsedTime;
|
||||
message(String("[SocketServer::sendFrame] Read ")+String().fromInt(charBytes.size())+String(" bytes took ")+String().fromInt(elapsedTime)+String(" (ms)"));
|
||||
elapsedTime=::GetTickCount();
|
||||
socketHeader.marshall(socketControl);
|
||||
socketControl.send((char*)&charBytes[0],charBytes.size());
|
||||
elapsedTime=::GetTickCount()-elapsedTime;
|
||||
message(String("[SocketServer::sendFrame] Send ")+String().fromInt(charBytes.size())+String(" bytes took ")+String().fromInt(elapsedTime)+String(" (ms)"));
|
||||
openFile.close();
|
||||
diskInfo.unlink(strPathCaptureFile);
|
||||
}
|
||||
message(String("[SocketServer::sendFrame]Sent ")+String().fromInt(charBytes.size())+String(" bytes"));
|
||||
return;
|
||||
}
|
||||
|
||||
void SocketServer::sendDebugFrame(Socket &socketControl)
|
||||
{
|
||||
DiskInfo diskInfo;
|
||||
Array<BYTE> charBytes;
|
||||
FileHandle openFile;
|
||||
SocketHeader socketHeader;
|
||||
String strPathFileName;
|
||||
|
||||
strPathFileName="./image.jpg";
|
||||
socketHeader.setVersion(1);
|
||||
socketHeader.setContentType(SocketHeader::ImageJPG);
|
||||
socketHeader.setContentLength(0);
|
||||
if(!openFile.open(strPathFileName,FileHandle::Read,FileHandle::ShareRead))
|
||||
{
|
||||
message("[SocketServer::sendDebugFrame] 'image.jpg' was not found, sending empty content");
|
||||
socketHeader.marshall(socketControl);
|
||||
}
|
||||
else
|
||||
{
|
||||
charBytes.size(openFile.size());
|
||||
socketHeader.setContentLength(charBytes.size());
|
||||
openFile.read((BYTE*)&charBytes[0],charBytes.size());
|
||||
socketHeader.marshall(socketControl);
|
||||
socketControl.send((char*)&charBytes[0],charBytes.size());
|
||||
message(String("[SocketServer::sendDebugFrame] Send ")+String().fromInt(charBytes.size()));
|
||||
openFile.close();
|
||||
}
|
||||
}
|
||||
36
CapServer/SocketServer.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef _CAPSERVER_SOCKETSERVER_HPP_
|
||||
#define _CAPSERVER_SOCKETSERVER_HPP_
|
||||
#ifndef _COMMON_BLOCK_HPP_
|
||||
#include <common/block.hpp>
|
||||
#endif
|
||||
#ifndef _THREAD_MONITOR_HPP_
|
||||
#include <thread/monitor.hpp>
|
||||
#endif
|
||||
#ifndef _CAPSERVER_WDMCAP_HPP_
|
||||
#include <CapServer/WDMCap.hpp>
|
||||
#endif
|
||||
#ifndef _CAPSERVER_GENERICSERVER_HPP_
|
||||
#include <CapServer/GenSrv.hpp>
|
||||
#endif
|
||||
#ifndef _CAPSERVER_MONITORTHREAD_HPP_
|
||||
#include <CapServer/MonitorThread.hpp>
|
||||
#endif
|
||||
|
||||
class SocketServer : public GenericServer
|
||||
{
|
||||
public:
|
||||
SocketServer(const String &host,int port,int deviceIndex=0,bool retain=false,bool debug=false,bool showSrcDlg=false,int timeout=1000);
|
||||
virtual ~SocketServer();
|
||||
protected:
|
||||
virtual void acceptHandler(SmartPointer<Socket> &socketControl);
|
||||
virtual void message(const String &message);
|
||||
private:
|
||||
void sendFrame(Socket &socketControl);
|
||||
void sendDebugFrame(Socket &socketControl);
|
||||
|
||||
MonitorThread mMonitorThread;
|
||||
WDMCap mWDMCap;
|
||||
VidCap mVidCap;
|
||||
bool mDebug;
|
||||
};
|
||||
#endif
|
||||
101
CapServer/WDMCap.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
#include <CapServer/WDMCap.hpp>
|
||||
#include <VidCap/VidReg.hpp>
|
||||
|
||||
WDMCap::WDMCap(int deviceIndex)
|
||||
: mDriverIndex(deviceIndex)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
|
||||
WDMCap::~WDMCap()
|
||||
{
|
||||
}
|
||||
|
||||
void WDMCap::setCaptureFileName(const String &strPathCaptureFile)
|
||||
{
|
||||
BmpCap::setCaptureFileName(strPathCaptureFile);
|
||||
}
|
||||
|
||||
const String &WDMCap::getCaptureFileName(void)const
|
||||
{
|
||||
return BmpCap::getCaptureFileName();
|
||||
}
|
||||
|
||||
bool WDMCap::initialize(void)
|
||||
{
|
||||
String pathOutputFileName="capture.jpg";
|
||||
VidReg vidReg;
|
||||
|
||||
vidReg.setCaptureFile(pathOutputFileName);
|
||||
vidReg.setSequencing(false);
|
||||
VidCap::getDrivers(mDriverInfoBlock);
|
||||
if(!mDriverInfoBlock.size())
|
||||
{
|
||||
message("No drivers found! drivercount",mDriverInfoBlock.size());
|
||||
return false;
|
||||
}
|
||||
if(mDriverIndex>=mDriverInfoBlock.size())
|
||||
{
|
||||
message("[WDMCap::initilialize]Driver not found! device",mDriverIndex);
|
||||
return false;
|
||||
}
|
||||
showSettings();
|
||||
mControl=::new Control();
|
||||
mControl.disposition(PointerDisposition::Delete);
|
||||
mControl->createControl("BUTTON","",0,Rect(0,0,vidReg.getCaptureWidth(),vidReg.getCaptureHeight()),::GetDesktopWindow(),ControlID);
|
||||
BmpCap::initialize(mControl->getHandle(),mDriverIndex);
|
||||
if(!connect(mDriverIndex))
|
||||
{
|
||||
::printf("\007");
|
||||
message("[WDMCap::initilialize]Failed to connect to device",mDriverInfoBlock[mDriverIndex].driverName());
|
||||
return false;
|
||||
}
|
||||
saveFrames(true);
|
||||
return isConnected();
|
||||
}
|
||||
|
||||
void WDMCap::showSettings(void)
|
||||
{
|
||||
VidReg vidReg;
|
||||
|
||||
message("[WDMCap::initilialize]Capture File",vidReg.getCaptureFile());
|
||||
message("[WDMCap::initilialize]Sequencing",vidReg.getSequencing()?"true":"false");
|
||||
message("[WDMCap::initilialize]Preview Rate",vidReg.getPreviewRate());
|
||||
message("[WDMCap::initilialize]Preview Width",vidReg.getPreviewWidth());
|
||||
message("[WDMCap::initilialize]Preview Height",vidReg.getPreviewHeight());
|
||||
message("[WDMCap::initilialize]Capture Width",vidReg.getCaptureWidth());
|
||||
message("[WDMCap::initilialize]Capture Height",vidReg.getCaptureHeight());
|
||||
message("[WDMCap::initilialize]Capture Quality",vidReg.getQuality());
|
||||
for(int index=0;index<mDriverInfoBlock.size();index++)
|
||||
{
|
||||
if(index==mDriverIndex)message(String("[WDMCap::initilialize](*)")+mDriverInfoBlock[index].driverName());
|
||||
else message(String("[WDMCap::initilialize]")+mDriverInfoBlock[index].driverName());
|
||||
}
|
||||
}
|
||||
|
||||
bool WDMCap::grabFrame(void)
|
||||
{
|
||||
if(!isConnected())return false;
|
||||
mGrabTime=::GetTickCount();
|
||||
if(!BmpCap::grabFrame())return false;
|
||||
mFrameEvent.waitEvent();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WDMCap::grabFrameNoStop(void)
|
||||
{
|
||||
if(!isConnected())return false;
|
||||
mGrabTime=::GetTickCount();
|
||||
if(!BmpCap::grabFrameNoStop())return false;
|
||||
mFrameEvent.waitEvent();
|
||||
return true;
|
||||
}
|
||||
|
||||
void WDMCap::frameHandler(VIDEOHDR &videoHeader)
|
||||
{
|
||||
mGrabTime=::GetTickCount()-mGrabTime;
|
||||
message("[WDMCap::frameHandler] Device grabbed frame (ms)",mGrabTime);
|
||||
BmpCap::frameHandler(videoHeader);
|
||||
mFrameEvent.setEvent();
|
||||
}
|
||||
|
||||
90
CapServer/WDMCap.hpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#ifndef _CAPSERVER_WDMCAP_HPP_
|
||||
#define _CAPSERVER_WDMCAP_HPP_
|
||||
#ifndef _COMMON_SMARTPOINTER_HPP_
|
||||
#include <common/pointer.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_BLOCK_HPP_
|
||||
#include <common/block.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_CONTROL_HPP_
|
||||
#include <common/control.hpp>
|
||||
#endif
|
||||
#ifndef _THREAD_EVENT_HPP_
|
||||
#include <thread/event.hpp>
|
||||
#endif
|
||||
#ifndef _VIDCAP_BMPCAP_HPP_
|
||||
#include <VidCap/BmpCap.hpp>
|
||||
#endif
|
||||
|
||||
class WDMCap : private BmpCap
|
||||
{
|
||||
public:
|
||||
WDMCap(int deviceIndex=0);
|
||||
virtual ~WDMCap();
|
||||
bool grabFrame(void);
|
||||
bool grabFrameNoStop(void);
|
||||
bool dialogVideoSource(void);
|
||||
bool isConnected(void)const;
|
||||
bool getDriverCaps(DriverCaps &someDriverCaps);
|
||||
bool getCaptureParams(CaptureParams &someCaptureParams);
|
||||
void setCaptureFileName(const String &strPathCaptureFile);
|
||||
const String &getCaptureFileName(void)const;
|
||||
protected:
|
||||
virtual void frameHandler(VIDEOHDR &videoHeader);
|
||||
private:
|
||||
enum{ControlID=100};
|
||||
bool initialize(void);
|
||||
void showSettings(void);
|
||||
void message(const String &message);
|
||||
void message(const String &message,const String &arg);
|
||||
void message(const String &message,int arg);
|
||||
|
||||
SmartPointer<Control> mControl;
|
||||
Block<DriverInfo> mDriverInfoBlock;
|
||||
Event mFrameEvent;
|
||||
DWORD mDriverIndex;
|
||||
DWORD mGrabTime;
|
||||
};
|
||||
|
||||
inline
|
||||
bool WDMCap::dialogVideoSource(void)
|
||||
{
|
||||
return BmpCap::dialogVideoSource();
|
||||
}
|
||||
|
||||
inline
|
||||
bool WDMCap::isConnected(void)const
|
||||
{
|
||||
return BmpCap::isConnected();
|
||||
}
|
||||
|
||||
inline
|
||||
bool WDMCap::getDriverCaps(DriverCaps &someDriverCaps)
|
||||
{
|
||||
return BmpCap::getDriverCaps(someDriverCaps);
|
||||
}
|
||||
|
||||
inline
|
||||
bool WDMCap::getCaptureParams(CaptureParams &someCaptureParams)
|
||||
{
|
||||
return BmpCap::getCaptureParams(someCaptureParams);
|
||||
}
|
||||
|
||||
inline
|
||||
void WDMCap::message(const String &message,int arg)
|
||||
{
|
||||
::printf("%s=%d\n",message.str(),arg);
|
||||
}
|
||||
|
||||
inline
|
||||
void WDMCap::message(const String &message,const String &arg)
|
||||
{
|
||||
::printf("%s=%s\n",message.str(),arg.str());
|
||||
}
|
||||
|
||||
inline
|
||||
void WDMCap::message(const String &message)
|
||||
{
|
||||
::printf("%s\n",message.str());
|
||||
}
|
||||
#endif
|
||||
96
CapServer/gensrv.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include <capserver/gensrv.hpp>
|
||||
#include <common/string.hpp>
|
||||
#include <common/systime.hpp>
|
||||
|
||||
extern bool running;
|
||||
|
||||
GenericServer::GenericServer(void)
|
||||
: mIsRunning(TRUE)
|
||||
{
|
||||
}
|
||||
|
||||
GenericServer::~GenericServer()
|
||||
{
|
||||
message("[GenericServer::~GenericServer]Server is destructing...");
|
||||
}
|
||||
|
||||
void GenericServer::close(void)
|
||||
{
|
||||
mIsRunning=FALSE;
|
||||
}
|
||||
|
||||
WORD GenericServer::listen(const String &hostName,short portNum)
|
||||
{
|
||||
HostEnt hostEntry;
|
||||
ServEnt serverEntry;
|
||||
String stringData;
|
||||
SystemTime systemTime;
|
||||
DWORD elapsedTime;
|
||||
|
||||
message(String("[GenericServer::listen]trying host'")+hostName+String("'..."));
|
||||
if(!mWSASystem.isInitialized()){message("[GenericServer::listen]WINSOCK initialization failure.");return FALSE;}
|
||||
InternetAddress internetAddress(hostName);
|
||||
if(!internetAddress.isZero()){if(!hostEntry.hostByAddress(internetAddress)){message(String("[GenericServer::listen]no DNS entry for ")+hostName);return FALSE;}}
|
||||
else if(!hostEntry.hostByName(hostName)){message(String("[GenericServer::listen]no DNS entry for ")+hostName);return FALSE;}
|
||||
message(String("[GenericServer::listen]connect...")+String("'")+hostEntry.hostName()+String("' (")+(String)(hostEntry.addresses())[0]+String(")"));
|
||||
mInternetSocketAddress.internetAddress((hostEntry.addresses())[0]);
|
||||
mInternetSocketAddress.family(PF_INET);
|
||||
mInternetSocketAddress.port(portNum);
|
||||
if(!mGenericControl.create()){message("[GenericServer::listen]socket initialization failure.");return FALSE;}
|
||||
mGenericControl.reuseAddress();
|
||||
if(!mGenericControl.bind(mInternetSocketAddress)){message("[GenericServer::listen]bind failed");return FALSE;}
|
||||
while(mIsRunning&&running)
|
||||
{
|
||||
SmartPointer<Socket> socketControl;
|
||||
socketControl=::new Socket();
|
||||
// socketControl.disposition(PointerDisposition::Assume);
|
||||
socketControl.disposition(PointerDisposition::Delete);
|
||||
INETSocketAddress internetSocketAddress;
|
||||
message(String("[GenericServer::listen]host='")+(hostEntry.addresses())[0]+String("' port=")+String().fromInt(portNum));
|
||||
String strLocalHost((String)mInternetSocketAddress.internetAddress());
|
||||
message(String("[GenericServer::listen]local address is ")+strLocalHost);
|
||||
if(!mGenericControl.listen()){message("[GenericServer::listen]listen failed");return FALSE;}
|
||||
message("[GenericServer::listen]waiting for connection...");
|
||||
if(!mGenericControl.accept(*socketControl,internetSocketAddress)){message("[GenericServer::listen]accept returned FALSE;");return FALSE;}
|
||||
|
||||
// socketControl->setLinger(0);
|
||||
// socketControl->bind(internetSocketAddress);
|
||||
|
||||
systemTime.refresh();
|
||||
message(String("[GenericServer::listen]service started from ")+internetSocketAddress.internetAddress().toString()+String(" on ")+systemTime.toString());
|
||||
elapsedTime=::GetTickCount();
|
||||
acceptHandler(socketControl);
|
||||
socketControl->destroy();
|
||||
socketControl.destroy();
|
||||
elapsedTime=::GetTickCount()-elapsedTime;
|
||||
message(String("[GenericServer::listen]service took ")+String().fromInt(elapsedTime)+String("(ms)"));
|
||||
}
|
||||
mGenericControl.destroy();
|
||||
message("[GenericServer::listen]terminating connection");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// virtuals
|
||||
|
||||
void GenericServer::message(const String &message)
|
||||
{
|
||||
::OutputDebugString(message+String("\n"));
|
||||
}
|
||||
|
||||
void GenericServer::message(Block<String> &msgData)
|
||||
{
|
||||
for(int msgIndex=0;msgIndex<msgData.size();msgIndex++)message(msgData[msgIndex]);
|
||||
}
|
||||
|
||||
void GenericServer::acceptHandler(SmartPointer<Socket> &socket)
|
||||
{
|
||||
SmartPointer<Socket> socketControl;
|
||||
|
||||
socketControl=socket;
|
||||
socketControl.disposition(PointerDisposition::Delete);
|
||||
String acceptString("[GenericServer::acceptHandler]200 GenericServer::acceptHandler accepting connection.");
|
||||
socketControl->send(acceptString);
|
||||
message(acceptString);
|
||||
return;
|
||||
}
|
||||
|
||||
42
CapServer/gensrv.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef _CAPSERVER_GENERICSERVER_HPP_
|
||||
#define _CAPSERVER_GENERICSERVER_HPP_
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
#ifndef _COMMON_SMARTPOINTER_HPP_
|
||||
#include <common/pointer.hpp>
|
||||
#endif
|
||||
#ifndef _SOCKET_HOSTENT_HPP_
|
||||
#include <socket/hostent.hpp>
|
||||
#endif
|
||||
#ifndef _SOCKET_SERVENT_HPP_
|
||||
#include <socket/servent.hpp>
|
||||
#endif
|
||||
#ifndef _SOCKET_INETSOCKETADDRESS_HPP_
|
||||
#include <socket/intsaddr.hpp>
|
||||
#endif
|
||||
#ifndef _SOCKET_SOCKET_HPP_
|
||||
#include <socket/socket.hpp>
|
||||
#endif
|
||||
|
||||
class GenericServer
|
||||
{
|
||||
public:
|
||||
GenericServer(void);
|
||||
virtual ~GenericServer();
|
||||
WORD listen(const String &hostName,short portNum);
|
||||
WORD receive(char &charData,BOOL waitForData=TRUE);
|
||||
void close(void);
|
||||
protected:
|
||||
virtual void acceptHandler(SmartPointer<Socket> &socketControl);
|
||||
virtual void message(const String &message);
|
||||
virtual void message(Block<String> &msgData);
|
||||
private:
|
||||
enum{TimeOut=1000};
|
||||
INETSocketAddress mInternetSocketAddress;
|
||||
Socket mGenericControl;
|
||||
WSASystem mWSASystem;
|
||||
BOOL mIsRunning;
|
||||
};
|
||||
|
||||
#endif
|
||||
25
CapServer/hold/Main.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <common/windows.hpp>
|
||||
#include <common/string.hpp>
|
||||
#include <CapServer/MainApplication.hpp>
|
||||
|
||||
int handlerRoutine(DWORD ctrlType);
|
||||
|
||||
bool running=true;
|
||||
|
||||
MainApplication mainApplication;
|
||||
|
||||
void main(int argc,char **argv)
|
||||
{
|
||||
mainApplication.run(argc,argv);
|
||||
}
|
||||
|
||||
int handlerRoutine(DWORD eventType) // this is connected ad-hoc to generic server, could be cleaner
|
||||
{
|
||||
if(CTRL_C_EVENT==eventType)
|
||||
{
|
||||
::printf("Caught Ctrl-C...\n");
|
||||
running=false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
124
CapServer/hold/MainApplication.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
#include <CapServer/MainApplication.hpp>
|
||||
|
||||
MainApplication::MainApplication()
|
||||
{
|
||||
}
|
||||
|
||||
MainApplication::~MainApplication()
|
||||
{
|
||||
}
|
||||
|
||||
int MainApplication::run(int argc,char **argv)
|
||||
{
|
||||
String command;
|
||||
|
||||
mParams.setArgs(argc,argv);
|
||||
switch(mParams.getRequest())
|
||||
{
|
||||
case Params::Client :
|
||||
mParams.showParams();
|
||||
handleClient(mParams.getServer(),mParams.getPort().toInt());
|
||||
break;
|
||||
case Params::Server :
|
||||
mParams.showParams();
|
||||
handleServer(mParams.getHost(),mParams.getPort().toInt(),mParams.getDevice().toInt(),mParams.getRetain(),mParams.getDebug(),mParams.getShowSrcDlg());
|
||||
break;
|
||||
case Params::Settings :
|
||||
mParams.showParams();
|
||||
handleSettings(mParams.getShowSrcDlg());
|
||||
break;
|
||||
case Params::None :
|
||||
displayUsage();
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MainApplication::handleServer(const String &host,int port,int deviceIndex,bool retain,bool debug,bool showSrcDlg)
|
||||
{
|
||||
message("[MainApplication::handleServer]starting server");
|
||||
SocketServer socketServer(deviceIndex,retain,debug,showSrcDlg);
|
||||
socketServer.listen(host,port);
|
||||
}
|
||||
|
||||
void MainApplication::handleClient(const String &host,int port)
|
||||
{
|
||||
INETSocketAddress internetSocketAddress;
|
||||
InternetAddress internetAddress(127,0,0,1);
|
||||
Socket socket;
|
||||
SocketHeader socketHeader;
|
||||
Array<BYTE> content;
|
||||
|
||||
message("[MainApplication::handleClient]starting client");
|
||||
internetSocketAddress.family(PF_INET);
|
||||
internetSocketAddress.port(1024);
|
||||
internetSocketAddress.internetAddress(internetAddress);
|
||||
if(!socket.create())
|
||||
{
|
||||
message("[MainApplication::handleClient]create failed...");
|
||||
return;
|
||||
}
|
||||
if(!socket.connect(internetSocketAddress))
|
||||
{
|
||||
message("[MainApplication::handleClient]connect failed...");
|
||||
return;
|
||||
}
|
||||
message("[MainApplication::handleClient]reading socket header...");
|
||||
socketHeader.unmarshall(socket);
|
||||
message("[MainApplication::handleClient]header length",socketHeader.getSizeHeader());
|
||||
message("[MainApplication::handleClient]version",socketHeader.getVersion());
|
||||
message("[MainApplication::handleClient]content length",socketHeader.getContentLength());
|
||||
message("[MainApplication::handleClient]content type",(int)socketHeader.getContentType());
|
||||
content.size(socketHeader.getContentLength());
|
||||
message("[MainApplication::handleClient]reading content...");
|
||||
socket.receive((char*)&content[0],content.size());
|
||||
message("[MainApplication::handleClient]done...");
|
||||
socket.destroy();
|
||||
}
|
||||
|
||||
void MainApplication::handleSettings(bool showSrcDlg)
|
||||
{
|
||||
VidReg vidReg;
|
||||
Block<DriverInfo> driverInfoBlock;
|
||||
|
||||
VidCap::getDrivers(driverInfoBlock);
|
||||
message("[MainApplication::handleSettings]Capture File",vidReg.getCaptureFile());
|
||||
message("[MainApplication::handleSettings]Sequencing",vidReg.getSequencing()?"true":"false");
|
||||
message("[MainApplication::handleSettings]Preview Rate",vidReg.getPreviewRate());
|
||||
message("[MainApplication::handleSettings]Preview Width",vidReg.getPreviewWidth());
|
||||
message("[MainApplication::handleSettings]Preview Height",vidReg.getPreviewHeight());
|
||||
message("[MainApplication::handleSettings]Capture Width",vidReg.getCaptureWidth());
|
||||
message("[MainApplication::handleSettings]Capture Height",vidReg.getCaptureHeight());
|
||||
message("[MainApplication::handleSettings]Capture Quality",vidReg.getQuality());
|
||||
message("[MainApplication::handleSettings]***********CAPTURE DEVICE LIST*********");
|
||||
if(!driverInfoBlock.size())message("[MainApplication::handleSettings]No capture devices on system.");
|
||||
for(int index=0;index<driverInfoBlock.size();index++)
|
||||
{
|
||||
WDMCap wdmCap(index);
|
||||
if(wdmCap.isConnected())
|
||||
{
|
||||
message(String("[MainApplication::handleSettings]")+driverInfoBlock[index].driverName()+String(" ***Available"));
|
||||
if(showSrcDlg)wdmCap.dialogVideoSource();
|
||||
}
|
||||
else message(String("[MainApplication::handleSettings]")+driverInfoBlock[index].driverName()+String(" ***Unavailable"));
|
||||
}
|
||||
}
|
||||
|
||||
void MainApplication::displayUsage(void)
|
||||
{
|
||||
message("CapServer [run host port device retain debug showsrcdlg]");
|
||||
message(" run={server} | {client} | {settings}");
|
||||
message(" server=<servername> | <serveraddress>");
|
||||
message(" host=<hostname> | <hostaddress>");
|
||||
message(" port=<port>");
|
||||
message(" device=<index>");
|
||||
message(" retain={true} | {false}");
|
||||
message(" debug={true} | {false}");
|
||||
message(" showsrcdlg={true} | {false}");
|
||||
message(" ");
|
||||
message(" CapServer run=server host=127.0.0.1 port=1024");
|
||||
message(" CapServer run=server host=127.0.0.1 port=1024 device=0");
|
||||
message(" CapServer run=client server=127.0.0.1 port=1024");
|
||||
message(" CapServer run=settings");
|
||||
}
|
||||
|
||||
55
CapServer/hold/MainApplication.hpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef _CAPSERVER_MAINAPPLICATION_HPP_
|
||||
#define _CAPSERVER_MAINAPPLICATION_HPP_
|
||||
#ifndef _CAPSERVER_SOCKET_HEADER_HPP_
|
||||
#include <capserver/socketheader.hpp>
|
||||
#endif
|
||||
#ifndef _SOCKET_WSADATA_HPP_
|
||||
#include <socket/wsadata.hpp>
|
||||
#endif
|
||||
#ifndef _CAPSERVER_SOCKETSERVER_HPP_
|
||||
#include <CapServer/SocketServer.hpp>
|
||||
#endif
|
||||
#ifndef _CAPSERVER_PARAMS_HPP_
|
||||
#include <CapServer/Params.hpp>
|
||||
#endif
|
||||
#ifndef _VIDCAP_VIDREG_HPP_
|
||||
#include <vidcap/vidreg.hpp>
|
||||
#endif
|
||||
|
||||
class MainApplication
|
||||
{
|
||||
public:
|
||||
MainApplication();
|
||||
virtual ~MainApplication();
|
||||
int run(int argc,char **argv);
|
||||
private:
|
||||
void message(const String &message);
|
||||
void message(const String &message,int arg);
|
||||
void message(const String &message,const String &arg);
|
||||
void handleServer(const String &host,int port,int deviceIndex,bool retain,bool debug,bool showSrcDlg);
|
||||
void handleClient(const String &server,int port);
|
||||
void handleSettings(bool showSrcDlg);
|
||||
void displayUsage(void);
|
||||
|
||||
WSASystem mWSASystem;
|
||||
Params mParams;
|
||||
};
|
||||
|
||||
inline
|
||||
void MainApplication::message(const String &message)
|
||||
{
|
||||
printf("%s\n",message.str());
|
||||
}
|
||||
|
||||
inline
|
||||
void MainApplication::message(const String &message,int arg)
|
||||
{
|
||||
printf("%s=%d\n",message.str(),arg);
|
||||
}
|
||||
|
||||
inline
|
||||
void MainApplication::message(const String &message,const String &arg)
|
||||
{
|
||||
printf("%s=%s\n",message.str(),arg.str());
|
||||
}
|
||||
#endif
|
||||
65
CapServer/hold/NameValuePair.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef _CAPSERVER_NAMEVALUE_HPP_
|
||||
#define _CAPSERVER_NAMEVALUE_HPP_
|
||||
#ifndef _COMMON_STRING_HPP_
|
||||
#include <common/string.hpp>
|
||||
#endif
|
||||
|
||||
class NameValuePair
|
||||
{
|
||||
public:
|
||||
NameValuePair();
|
||||
NameValuePair(const String &name,const String &value);
|
||||
const String &getName(void)const;
|
||||
void setName(const String &name);
|
||||
const String &getValue(void)const;
|
||||
void setValue(const String &value);
|
||||
bool fromString(const String &string);
|
||||
private:
|
||||
String mName;
|
||||
String mValue;
|
||||
};
|
||||
|
||||
inline
|
||||
NameValuePair::NameValuePair()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
NameValuePair::NameValuePair(const String &name,const String &value)
|
||||
: mName(name), mValue(value)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
const String &NameValuePair::getName(void)const
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
inline
|
||||
void NameValuePair::setName(const String &name)
|
||||
{
|
||||
mName=name;
|
||||
}
|
||||
|
||||
inline
|
||||
const String &NameValuePair::getValue(void)const
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
inline
|
||||
void NameValuePair::setValue(const String &value)
|
||||
{
|
||||
mValue=value;
|
||||
}
|
||||
|
||||
inline
|
||||
bool NameValuePair::fromString(const String &string)
|
||||
{
|
||||
if(string.isNull())return false;
|
||||
mName=string.betweenString(0,'=');
|
||||
mValue=string.betweenString('=',0);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
84
CapServer/hold/Params.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include <common/stdio.hpp>
|
||||
#include <CapServer/Params.hpp>
|
||||
|
||||
void Params::setArgs(int argc,char **argv)
|
||||
{
|
||||
String strArg;
|
||||
getParams(argc,argv);
|
||||
if(getServer().isNull())setServer("127.0.0.1");
|
||||
if(getHost().isNull())setHost("127.0.0.1");
|
||||
if(getPort().isNull())setPort("1024");
|
||||
if(getDevice().isNull())setDevice("0");
|
||||
strArg=getValue(mRetainKey);
|
||||
strArg.lower();
|
||||
if(!(strArg==String("true")) && !(strArg==String("false")))setRetain(false);
|
||||
else if(strArg==String("true"))setRetain(true);
|
||||
else setRetain(false);
|
||||
strArg=getValue(mDebugKey);
|
||||
strArg.lower();
|
||||
if(!(strArg==String("true")) && !(strArg==String("false")))setDebug(false);
|
||||
else if(strArg==String("true"))setDebug(true);
|
||||
else setDebug(false);
|
||||
strArg=getValue(mShowSrcDlgKey);
|
||||
strArg.lower();
|
||||
if(!(strArg==String("true")) && !(strArg==String("false")))setShowSrcDlg(false);
|
||||
else if(strArg==String("true"))setShowSrcDlg(true);
|
||||
else setShowSrcDlg(false);
|
||||
}
|
||||
|
||||
int Params::getParams(int argc,char**argv)
|
||||
{
|
||||
mNameValuePairs.remove();
|
||||
for(int index=0;index<argc;index++)
|
||||
{
|
||||
NameValuePair nameValuePair;
|
||||
nameValuePair.fromString(argv[index]);
|
||||
mNameValuePairs.insert(&nameValuePair);
|
||||
}
|
||||
return mNameValuePairs.size();
|
||||
}
|
||||
|
||||
String Params::getValue(const String &key)const
|
||||
{
|
||||
for(int index=0;index<mNameValuePairs.size();index++)
|
||||
{
|
||||
NameValuePair &nameValuePair=((Params&)*this).mNameValuePairs[index];
|
||||
if(nameValuePair.getName()==key)return nameValuePair.getValue();
|
||||
}
|
||||
return String();
|
||||
}
|
||||
|
||||
void Params::setValue(const String &key,const String &value)
|
||||
{
|
||||
for(int index=0;index<mNameValuePairs.size();index++)
|
||||
{
|
||||
NameValuePair &nameValuePair=mNameValuePairs[index];
|
||||
if(nameValuePair.getName()==key)
|
||||
{
|
||||
nameValuePair.setValue(value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
mNameValuePairs.insert(&NameValuePair(key,value));
|
||||
}
|
||||
|
||||
Params::Request Params::getRequest(void)const
|
||||
{
|
||||
String strRequest(getRun());
|
||||
if(strRequest=="client")return Client;
|
||||
else if(strRequest=="server")return Server;
|
||||
else if(strRequest=="settings")return Settings;
|
||||
return None;
|
||||
}
|
||||
|
||||
void Params::showParams(void)
|
||||
{
|
||||
for(int index=0;index<mNameValuePairs.size();index++)
|
||||
{
|
||||
NameValuePair &nameValuePair=mNameValuePairs[index];
|
||||
::printf("[Params::showParams]arg[%d]%s=%s\n",
|
||||
index,
|
||||
nameValuePair.getName().str(),
|
||||
nameValuePair.getValue().str());
|
||||
}
|
||||
}
|
||||
169
CapServer/hold/Params.hpp
Normal file
@@ -0,0 +1,169 @@
|
||||
#ifndef _CAPSERVER_PARAMS_HPP_
|
||||
#define _CAPSERVER_PARAMS_HPP_
|
||||
#ifndef _COMMON_BLOCK_HPP_
|
||||
#include <common/block.hpp>
|
||||
#endif
|
||||
#ifndef _CAPSERVER_NAMEVALUE_HPP_
|
||||
#include <CapServer/NameValuePair.hpp>
|
||||
#endif
|
||||
|
||||
class Params
|
||||
{
|
||||
public:
|
||||
typedef enum Request{Server,Client,Settings,None};
|
||||
Params(int argc,char **argv);
|
||||
Params();
|
||||
virtual ~Params();
|
||||
Request getRequest(void)const;
|
||||
String getServer(void)const;
|
||||
String getHost(void)const;
|
||||
String getPort(void)const;
|
||||
String getDevice(void)const;
|
||||
bool getRetain(void)const;
|
||||
bool getDebug(void)const;
|
||||
bool getShowSrcDlg(void)const;
|
||||
void setArgs(int argc,char **argv);
|
||||
void showParams(void);
|
||||
private:
|
||||
int getParams(int argc,char **argv);
|
||||
String getValue(const String &key)const;
|
||||
void setValue(const String &key,const String &value);
|
||||
String getRun(void)const;
|
||||
void setServer(const String &server);
|
||||
void setHost(const String &host);
|
||||
void setPort(const String &port);
|
||||
void setDevice(const String &device);
|
||||
void setRetain(bool retain);
|
||||
void setDebug(bool debug);
|
||||
void setShowSrcDlg(bool showSrcDlg);
|
||||
|
||||
Block<NameValuePair> mNameValuePairs;
|
||||
String mRunKey;
|
||||
String mServerKey;
|
||||
String mHostKey;
|
||||
String mPortKey;
|
||||
String mDeviceKey;
|
||||
String mRetainKey;
|
||||
String mDebugKey;
|
||||
String mShowSrcDlgKey;
|
||||
};
|
||||
|
||||
inline
|
||||
Params::Params(int argc,char **argv)
|
||||
: mRunKey("run"), mServerKey("server"), mHostKey("host"), mPortKey("port"), mDeviceKey("device"),
|
||||
mRetainKey("retain"), mDebugKey("debug"), mShowSrcDlgKey("showsrcdlg")
|
||||
{
|
||||
getParams(argc,argv);
|
||||
}
|
||||
|
||||
inline
|
||||
Params::Params()
|
||||
: mRunKey("run"), mServerKey("server"), mHostKey("host"), mPortKey("port"), mDeviceKey("device"),
|
||||
mRetainKey("retain"), mDebugKey("debug"), mShowSrcDlgKey("showsrcdlg")
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
Params::~Params()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
String Params::getRun(void)const
|
||||
{
|
||||
return getValue(mRunKey);
|
||||
}
|
||||
|
||||
inline
|
||||
String Params::getServer(void)const
|
||||
{
|
||||
return getValue(mServerKey);
|
||||
}
|
||||
|
||||
inline
|
||||
String Params::getHost(void)const
|
||||
{
|
||||
return getValue(mHostKey);
|
||||
}
|
||||
|
||||
inline
|
||||
String Params::getPort(void)const
|
||||
{
|
||||
return getValue(mPortKey);
|
||||
}
|
||||
|
||||
inline
|
||||
String Params::getDevice(void)const
|
||||
{
|
||||
return getValue(mDeviceKey);
|
||||
}
|
||||
|
||||
inline
|
||||
bool Params::getRetain(void)const
|
||||
{
|
||||
String strRetain(getValue(mRetainKey));
|
||||
if(strRetain=="true")return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline
|
||||
bool Params::getDebug(void)const
|
||||
{
|
||||
String strDebug(getValue(mDebugKey));
|
||||
if(strDebug=="true")return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline
|
||||
bool Params::getShowSrcDlg(void)const
|
||||
{
|
||||
String strValue(getValue(mShowSrcDlgKey));
|
||||
if(strValue=="true")return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setServer(const String &server)
|
||||
{
|
||||
setValue(mServerKey,server);
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setHost(const String &host)
|
||||
{
|
||||
setValue(mHostKey,host);
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setPort(const String &port)
|
||||
{
|
||||
setValue(mPortKey,port);
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setDevice(const String &device)
|
||||
{
|
||||
setValue(mDeviceKey,device);
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setRetain(bool retain)
|
||||
{
|
||||
if(retain)setValue(mRetainKey,"true");
|
||||
else setValue(mRetainKey,"false");
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setDebug(bool debug)
|
||||
{
|
||||
if(debug)setValue(mDebugKey,"true");
|
||||
else setValue(mDebugKey,"false");
|
||||
}
|
||||
|
||||
inline
|
||||
void Params::setShowSrcDlg(bool showSrcDlg)
|
||||
{
|
||||
if(showSrcDlg)setValue(mShowSrcDlgKey,"true");
|
||||
else setValue(mShowSrcDlgKey,"false");
|
||||
}
|
||||
#endif
|
||||
105
CapServer/hold/SocketHeader.hpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#ifndef _CAPSERVER_SOCKET_HEADER_HPP_
|
||||
#define _CAPSERVER_SOCKET_HEADER_HPP_
|
||||
#ifndef _COMMON_WINDOWS_HPP_
|
||||
#include <common/windows.hpp>
|
||||
#endif
|
||||
#ifndef _SOCKET_SOCKET_HPP_
|
||||
#include <socket/socket.hpp>
|
||||
#endif
|
||||
|
||||
class SocketHeader
|
||||
{
|
||||
public:
|
||||
typedef enum ContentType{Unknown,ImageJPG};
|
||||
SocketHeader();
|
||||
virtual ~SocketHeader();
|
||||
int getSizeHeader(void)const;
|
||||
int getVersion(void)const;
|
||||
void setVersion(int version);
|
||||
int getContentLength(void)const;
|
||||
void setContentLength(int contentLength);
|
||||
ContentType getContentType(void)const;
|
||||
void setContentType(int contentType);
|
||||
bool marshall(Socket &socket);
|
||||
bool unmarshall(Socket &socket);
|
||||
private:
|
||||
int mSizeHeader;
|
||||
int mVersion;
|
||||
int mContentLength;
|
||||
int mContentType;
|
||||
};
|
||||
|
||||
inline
|
||||
SocketHeader::SocketHeader()
|
||||
: mSizeHeader(sizeof(int)+sizeof(int)+sizeof(int)+sizeof(int)),
|
||||
mVersion(0), mContentLength(0), mContentType(Unknown)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
SocketHeader::~SocketHeader()
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
int SocketHeader::getSizeHeader(void)const
|
||||
{
|
||||
return mSizeHeader;
|
||||
}
|
||||
|
||||
inline
|
||||
int SocketHeader::getVersion(void)const
|
||||
{
|
||||
return mVersion;
|
||||
}
|
||||
|
||||
inline
|
||||
void SocketHeader::setVersion(int version)
|
||||
{
|
||||
mVersion=version;
|
||||
}
|
||||
|
||||
inline
|
||||
int SocketHeader::getContentLength(void)const
|
||||
{
|
||||
return mContentLength;
|
||||
}
|
||||
|
||||
inline
|
||||
void SocketHeader::setContentLength(int contentLength)
|
||||
{
|
||||
mContentLength=contentLength;
|
||||
}
|
||||
|
||||
inline
|
||||
SocketHeader::ContentType SocketHeader::getContentType(void)const
|
||||
{
|
||||
return (ContentType)mContentType;
|
||||
}
|
||||
|
||||
inline
|
||||
void SocketHeader::setContentType(int contentType)
|
||||
{
|
||||
mContentType=(ContentType)contentType;
|
||||
}
|
||||
|
||||
inline
|
||||
bool SocketHeader::marshall(Socket &socket)
|
||||
{
|
||||
if(!socket.send((char*)&mSizeHeader,sizeof(int)))return false;
|
||||
if(!socket.send((char*)&mVersion,sizeof(int)))return false;
|
||||
if(!socket.send((char*)&mContentLength,sizeof(int)))return false;
|
||||
if(!socket.send((char*)&mContentType,sizeof(int)))return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline
|
||||
bool SocketHeader::unmarshall(Socket &socket)
|
||||
{
|
||||
if(!socket.receive((char*)&mSizeHeader,sizeof(int)))return false;
|
||||
if(!socket.receive((char*)&mVersion,sizeof(int)))return false;
|
||||
if(!socket.receive((char*)&mContentLength,sizeof(int)))return false;
|
||||
if(!socket.receive((char*)&mContentType,sizeof(int)))return false;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
103
CapServer/hold/SocketServer.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#include <common/OpenFile.hpp>
|
||||
#include <common/systime.hpp>
|
||||
#include <common/diskinfo.hpp>
|
||||
#include <CapServer/SocketServer.hpp>
|
||||
#include <CapServer/SocketHeader.hpp>
|
||||
|
||||
SocketServer::SocketServer(int deviceIndex,bool retain,bool debug,bool showSrcDlg)
|
||||
: mWDMCap(deviceIndex), mRetainImage(retain), mDebug(debug)
|
||||
{
|
||||
if(showSrcDlg)mWDMCap.dialogVideoSource();
|
||||
}
|
||||
|
||||
SocketServer::~SocketServer()
|
||||
{
|
||||
}
|
||||
|
||||
void SocketServer::acceptHandler(SmartPointer<Socket> &socketControl)
|
||||
{
|
||||
if(mDebug)sendDebugFrame(*socketControl);
|
||||
else sendFrame(*socketControl);
|
||||
|
||||
}
|
||||
|
||||
void SocketServer::message(const String &string)
|
||||
{
|
||||
::printf("%s\n",string.str());
|
||||
}
|
||||
|
||||
void SocketServer::sendFrame(Socket &socketControl)
|
||||
{
|
||||
DiskInfo diskInfo;
|
||||
SystemTime systemTime;
|
||||
String strPathCaptureFile;
|
||||
SocketHeader socketHeader;
|
||||
Array<BYTE> charBytes;
|
||||
FileHandle openFile;
|
||||
DWORD elapsedTime;
|
||||
|
||||
socketHeader.setVersion(1);
|
||||
socketHeader.setContentType(SocketHeader::ImageJPG);
|
||||
socketHeader.setContentLength(0);
|
||||
strPathCaptureFile.reserve(1024);
|
||||
::sprintf(strPathCaptureFile,"%04d%02d%02d%02d%02d%02d%02d.jpg",
|
||||
systemTime.year(),systemTime.month(),systemTime.day(),
|
||||
systemTime.hour(),systemTime.minute(),systemTime.second(),
|
||||
systemTime.milliseconds());
|
||||
elapsedTime=::GetTickCount();
|
||||
mWDMCap.setCaptureFileName(strPathCaptureFile);
|
||||
mWDMCap.grabFrameNoStop();
|
||||
elapsedTime=::GetTickCount()-elapsedTime;
|
||||
message(String("[SocketServer::sendFrame] Grab frame took ")+String().fromInt(elapsedTime)+String(" (ms)"));
|
||||
if(!openFile.open(strPathCaptureFile,FileHandle::Read,FileHandle::ShareRead))
|
||||
{
|
||||
socketHeader.marshall(socketControl);
|
||||
}
|
||||
else
|
||||
{
|
||||
charBytes.size(openFile.size());
|
||||
socketHeader.setContentLength(charBytes.size());
|
||||
elapsedTime=::GetTickCount();
|
||||
openFile.read((BYTE*)&charBytes[0],charBytes.size());
|
||||
elapsedTime=::GetTickCount()-elapsedTime;
|
||||
message(String("[SocketServer::sendFrame] Read ")+String().fromInt(charBytes.size())+String(" bytes took ")+String().fromInt(elapsedTime)+String(" (ms)"));
|
||||
elapsedTime=::GetTickCount();
|
||||
socketHeader.marshall(socketControl);
|
||||
socketControl.send((char*)&charBytes[0],charBytes.size());
|
||||
elapsedTime=::GetTickCount()-elapsedTime;
|
||||
message(String("[SocketServer::sendFrame] Send ")+String().fromInt(charBytes.size())+String(" bytes took ")+String().fromInt(elapsedTime)+String(" (ms)"));
|
||||
openFile.close();
|
||||
if(!mRetainImage)diskInfo.unlink(strPathCaptureFile);
|
||||
}
|
||||
message(String("[SocketServer::sendFrame]Sent ")+String().fromInt(charBytes.size())+String(" bytes"));
|
||||
return;
|
||||
}
|
||||
|
||||
void SocketServer::sendDebugFrame(Socket &socketControl)
|
||||
{
|
||||
DiskInfo diskInfo;
|
||||
Array<BYTE> charBytes;
|
||||
FileHandle openFile;
|
||||
SocketHeader socketHeader;
|
||||
String strPathFileName;
|
||||
|
||||
strPathFileName="./image.jpg";
|
||||
socketHeader.setVersion(1);
|
||||
socketHeader.setContentType(SocketHeader::ImageJPG);
|
||||
socketHeader.setContentLength(0);
|
||||
if(!openFile.open(strPathFileName,FileHandle::Read,FileHandle::ShareRead))
|
||||
{
|
||||
message("[SocketServer::sendDebugFrame] 'image.jpg' was not found, sending empty content");
|
||||
socketHeader.marshall(socketControl);
|
||||
}
|
||||
else
|
||||
{
|
||||
charBytes.size(openFile.size());
|
||||
socketHeader.setContentLength(charBytes.size());
|
||||
openFile.read((BYTE*)&charBytes[0],charBytes.size());
|
||||
socketHeader.marshall(socketControl);
|
||||
socketControl.send((char*)&charBytes[0],charBytes.size());
|
||||
message(String("[SocketServer::sendDebugFrame] Send ")+String().fromInt(charBytes.size()));
|
||||
openFile.close();
|
||||
}
|
||||
}
|
||||
32
CapServer/hold/SocketServer.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef _CAPSERVER_SOCKETSERVER_HPP_
|
||||
#define _CAPSERVER_SOCKETSERVER_HPP_
|
||||
#ifndef _COMMON_BLOCK_HPP_
|
||||
#include <common/block.hpp>
|
||||
#endif
|
||||
#ifndef _THREAD_MONITOR_HPP_
|
||||
#include <thread/monitor.hpp>
|
||||
#endif
|
||||
#ifndef _CAPSERVER_WDMCAP_HPP_
|
||||
#include <CapServer/WDMCap.hpp>
|
||||
#endif
|
||||
#ifndef _CAPSERVER_GENERICSERVER_HPP_
|
||||
#include <CapServer/GenSrv.hpp>
|
||||
#endif
|
||||
|
||||
class SocketServer : public GenericServer
|
||||
{
|
||||
public:
|
||||
SocketServer(int deviceIndex=0,bool retain=false,bool debug=false,bool showSrcDlg=false);
|
||||
virtual ~SocketServer();
|
||||
protected:
|
||||
virtual void acceptHandler(SmartPointer<Socket> &socketControl);
|
||||
virtual void message(const String &message);
|
||||
private:
|
||||
void sendFrame(Socket &socketControl);
|
||||
void sendDebugFrame(Socket &socketControl);
|
||||
|
||||
WDMCap mWDMCap;
|
||||
bool mRetainImage;
|
||||
bool mDebug;
|
||||
};
|
||||
#endif
|
||||