You are on page 1of 13

JPGView ActiveX control

JPGView is an ActiveX control, which can connect to iCAMView and get the JPG
image data from it. It contains the Socket interface, network protocol and image
display. It tries to make the connection to iCAMView transparent to the ActiveX
user. There is no need to know JPEG encoding/decoding after using this JPGView
to display the image from iCAMView. We believed that this is a pretty powerful
control for user interface when applied to iCAMView.

Although the JPGView is programmed in Visual C++, it uses ActiveX on OCX. So


any Windows programming tool can use it. For example, VC, VB, can easily use
this control to connect to iCAMView and display the image on the user application
interface.

1: Take VC++ as an example.


Before you start programming, please install the OCX_ install utility. This will
register OCX and insert the OCX into your VC project. The control will generate
the Class CJpgView for you. And all the member data and methods are ready.

2: Using the control


One CJpgView is mapped to one camera. And the CJpgView control has a set of
“Set” and “Get” methods. User can get the current status using “Get” and control
the ActiveX using “Set”.

3. Connection Procedure
The correct Account/Password for accessing the image data is required for
iCAMView. Use the following methods to configure.

SetStrUserName
SetStrPassword

After that, you have to configure the IP address of the iCAMView, port, camera A
or B. Using the following command to set these information into.

SetIPAddr(IPAddr,m_Port, nCamera),

The JPGView is now able to get the image from iCAMView. But many of the
configurations are in default state. If you need to change something on it, you have
to set the parameters of the control.

For instance, to control the maximum pictures per second, you can use the method
SetDelayTime(nnn). Which pass the parameter into the control in 0.01FPS unit. If
we want to limit the FPS in 10, we can use SetDelayTime(1000) to limit it.

If we want to change the sensitivity of the motion detection, we can use the
SetSense(nnn) to set the sens itivity.

4. API List.

GetAutoStatus
GetConnectionCount
GetCamPosition
GetConnectStatus
GetDriverNum
GetDriverStr
GetFilename
GetFilePathAndName
GetStreamFps
GetStrIpAddr
GetStrPassword
GetStrUserName
IsMoveJpg
RefreshDraw
SetAVIParam
SetAviSerial
SetCamCmd
SetDelayTime
SetFilename
SetImageState
SetIPAddr
SetIPAddrStr
SetLeftTop
SetRadio
SetRevAngle
SetSense
SetStrIpAddr
SetStrPassword
SetStrUserName
CloseAVI

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL GetAutoStatus()
Argument None
Return TRUE. The camera is auto-scanning.
FALSE. The camera is not auto-scanning.
Description Return the current status of iCAMView auto-scanning function.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
long GetConnectionCount()
Argument None
Return Total connection number of the iCAMView camera
Description Get the current connection number of this iCAMView camera.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CString GetCamPosition()
Argument None
Return The location of the iCAMView camera A or camera B.
Description Get the location information of the iCAMView camera A or B.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
long GetConnectStatus()
Argument None
Return 0 Connection Success
1 Invalid Account/Password
2 Over maximum connection number
3 No image returned
4 Connection failed
-1 Unknown error
Description Get the current connection status with the iCAMView.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
short GetDriverNum()
Argument None
Return Get the number of image compress method in the system
Description Get the number of image compress method in the local system
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CString GetDriverStr(short nDriver)
Argument nDriver, image compressor index number.
Return image compressor description
Description Get the current image compressor description on local PC
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CString GetFilename()
Argument None
Return Current recording AVI path and filename.
Description Get the current image recording AVI path and filename.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CString GetFilePathAndName()
Obsolete function.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
short GetStreamFps()
Argument None
Return Number of current image FPS. In 0.01 FPS unit.
Description Get the current image FPS in 0.01 FPS unit.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CString GetStrIpAddr()
Argument None
Return the domain name or IP of the current iCAMView connection.
Description Get the current connected iCAMView domain name or IP address.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CString GetStrPassword()
Argument None
Return the password that is using to connect iCAMView
Description Get the current password using to connect iCAMView.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CString GetStrUserName ()
Argument None
Return the account that is using to connect iCAMView.
Description Get the current account name using to connect iCAMView.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL IsMoveJpg()
Argument None
Return Result of Motion Detection. If TRUE, means there is motion detected
since last query. If FALSE, means there is no motion detected since last query.
Description Get the result of motion detection. If there is motion detected in he
image since last query by using this function, the return values will be TRUE.
Otherwise, the return is FALSE.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL RefreshDraw(BOOL)
Argument Reserved. No use at this version.
Return TRUE
Description When rotate the image, use this function to redraw the image
window.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL SetAVIParam(VARIANT* filename, short fps, long fccType, long fccHandler,
long compfccHandler);
Argument filename - Recording AVI filename.
fps – current frame per second
fccType image compression type
fccHandler image compression handler
compfccHandler image compression handler
In usual cased, the compfccHandler and the same as the fccHandler
Return TRUE, set AVI parameter success.
FALSE, failed when set the AVI parameters.
Description When make the image recording, we have to setup these parameters
before start the recording. Please also check the function SetAviSerial. For detail
description of using this function, please refer to the sample problem at later
section. Recording Sample
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL SetAviSerial(short nSerial);
Argument nSerial – the index number of the compression method intend to use.
Return TRUE, set compression method index success
FALSE, set compression method index failed
Description When make the image recording, we could set the method of image
rcording by using this function. Please also check the function SetAVIParam. For
detail description of using this function, please refer to the sample problem at
later section. Recording Sample
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL SetCamCmd(short nParam, short cmdLen)
Argument nParam –command send to iCAMView.
Ex. 13 small step moving left.
23 big step moving left.
11 small step moving up
21 big step moving up.
14 small step moving right.
24 big step moving right.
12 small step moving down.
22 big step moving down.
31 enable auto-scan function.
31 cancel auto-scan function.
cmdLen command length must be 8
Return TRUE, send command to iCAMView success
FALSE, send command to iCAMView failed
Description send control command to iCAMView. This will change the
iCAMView camera immediately.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL SetDelayTime(short nDelay);
Argument nDelay – the maximum FPS in 0.01FPS unit.
Return TRUE, set Max. FPS success.
FALSE, set Max. FPS failed.
Description Configure the maximum image FPS. The unit of argument is
0.01FPS. So, if you want to set the limit at 10FPS, you should use this function
with argument 1000, SetDelayTime(1000),
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SetFilename(LPCTSTR);
Argument name of the AVI filename.
Return None
Description Set the filename of the recording AVI. It is the same as the 1st
argument of function SetAVIParam. Please also refer to function SetAviSerial for
more information.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL SetImageState(short nState)
Argument nState – configure if mirror activated. If ‘1’, the mirror is activated.
Otherwise, the function is disabled.
Return TRUE, set parameter success.
FALSE, set parameter failed.
Description Use this function to configure if the image need to be mirror when ?
displayed.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL SetIPAddr(long ipAddr, short port, short nCamera)
Argument ipAddr – the IP address of the iCAMView
port – the port of the iCAMView image data. Default is 9001.
nCamera – the camera is connecting. ‘1’for camera A, ‘2’ for
camera B.
Return TRUE, set connection successfully.
FALSE, set connection failed.
Description Configured the ActiveX control to connect to specific iCAMView IP,
port and camera. After this function, the image is ready to be displayed on the
screen.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL SetIPAddrStr(short port, short nCamera)
Argument port - the port of the iCAMView image data. Default is 9001.
nCamera – the camera is connecting. ‘1’for camera A, ‘2’ for
camera B.
Return TRUE, set connection successfully.
FALSE, set connection failed.
Description Configured the ActiveX control to connect to specific iCAMView
port and camera. After this function, the image is ready to be displayed on the
screen. Please also refer to function SetStrIpAddr for detailed description.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL SetLeftTop(short nLeft, short nTop)
Argument nLeft – set the image window upper- left X position.
nTop– set the image window upper- left Y position.
Return TRUE, set parameter success.
FALSE, set parameter failed.
Description Set the CJpgView control image display position in the parent
window.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL SetRadio(short nRadio);
Argument nRadi – set the image display ratio.
Return TRUE, set parameter success.
FALSE, set parameter failed.
Description configure the image display ratio. Ex. 100 is for original size.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL SetRevAngle(short angle);
Argument angle – set the image rotation angel when display.
0: unchanged
1: Rotate counter-clockwise 90 degree
2: Rotate counter-clockwise 180 degree
3: Rotate counter-clockwise 270 degree
Return TRUE, set parameter success.
FALSE, set parameter failed.
Description Configure the rotation angel of the displayed image. This is for
display the image on local screen only.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL SetSense(short nSense);
Argument nSense – set the sensitivity of motion detection
0 – less sensitive. 100 – most sensitive.
Return TRUE, set parameter success.
FALSE, set parameter failed.
Description Set the sensitivity of the motion detection. Please refer to function
IsMoveJpg for more information.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SetStrIpAddr(LPCTSTR);
Argument configure the IP or doma in name of the iCAMView address.
Return None
Description Configure the IP or domain name of the iCAMView address. The
connection to the iCAMView will be reinitiated every time this function been
used. Recommend using the function SetIPAddrStr. In usual cases, please use the
function SetIPAddr to replace the function SetStrIpAddr, SetIPAddrStr. If the
input is domain name, please convert that into real IP address and pass into by
using SetIPAddr.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void SetStrUserName(LPCTSTR);
void SetStrPassword(LPCTSTR);
Argument Account/Password
Return None
Description set the user name and password for image query. Please set these
parameter before make the first connection.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CloseAVI()
Argument None
Return TRUE, close AVI file successfully.
FALSE close AVI failed.
Description Stop the recording after using the function SetAVIParam or
SetAviSerial to start the image recording.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
5. Sample program
//////////////////////////////////////////////////////////////////////////////////////////////////////
//SAMPLE1 Sample for SetAVIParam:
//////////////////////////////////////////////////////////////////////////////////////////////////
BITMAPINFOHEADER bmiHeader;
DWORD fccType;
DWORD fccHandler;
/////////////////////////////////////////////////////////////////////////////////
// Set the control parameters
////////////////////////////////////////////////////////////////////////////////////
bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmiHeader.biWidth = 320;/// image resolution
bmiHeader.biHeight = 240; /// image resolution
bmiHeader.biPlanes = 1;
bmiHeader.biBitCount = 32;
bmiHeader.biCompression = BI_RGB;
bmiHeader.biSizeImage = 0;
bmiHeader.biXPelsPerMeter = 0;
bmiHeader.biYPelsPerMeter = 0;
bmiHeader.biClrUsed = 0;
bmiHeader.biClrImportant = 0;
ICINFO * compressor_info = (ICINFO *) calloc(30,sizeof(ICINFO));
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// Samples for showing the image recording and compressor selection
///////////////////////////////////////////////////////////////////////////////////////////////////////////
int num_compressor =0;
for(int i=0; ICInfo(ICTYPE_VIDEO, i, &compressor_info[num_compressor]);
i++) {
if (num_compressor>=30) break; //maximum allows 30 compressors
HIC hic;
hic = ICOpen(compressor_info[num_compressor].fccType,
compressor_info[num_compressor].fccHandler, ICMODE_QUERY);
if (hic) {
if (ICERR_OK==ICCompressQuery(hic, &bmiHeader, NULL)) {
ICGetInfo(hic, &compressor_info[num_compressor],
sizeof(ICINFO));
num_compressor ++ ;
}
ICClose(hic);
}
}
if(num_compressor<=0)return FALSE;
////////////////////////////////////////////////////////////////////
// If user select the 1st compression method
////////////////////////////////////////////////////////////////
int selected_compressor=0;
ULONG fccType=compressor_info[selected_compressor].fccType;
ULONG compfccHandler = compressor_info[selected_compressor].fccHandler;
ULONG fccHandler=compressor_info[selected_compressor].fccHandler;
BOOL
bSuccess=m_JpgView.SetAVIParam((VARIANT*)(“test.avi”),10,fccType,fccHandler,
comp fccHandler);
if(bSuccess==TRUE)
{
… … … … … … … … … … … … … … … … … … … … … … … … … … ..
bSuccess = m_JpgView.CloseAVI();
if(bSuccess==TRUE)
{
TRACE(“AVI OK\n”);
return TRUE;

}else
TRACE(“error occurs\n”);

}else
TRACE(“error occurs\n”);
return FALSE;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//SAMPLE2 Sample for SetAviSerial:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

BITMAPINFOHEADER bmiHeader;
DWORD fccType;
DWORD fccHandler;
/////////////////////////////////////////////////////////////////////////////////
// Set the control parameters
////////////////////////////////////////////////////////////////////////////////////
bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmiHeader.biWidth = 320;/// image resolution
bmiHeader.biHeight = 240; /// image resolution
bmiHeader.biPlanes = 1;
bmiHeader.biBitCount = 32;
bmiHeader.biCompression = BI_RGB;
bmiHeader.biSizeImage = 0;
bmiHeader.biXPelsPerMeter = 0;
bmiHeader.biYPelsPerMeter = 0;
bmiHeader.biClrUsed = 0;
bmiHeader.biClrImportant = 0;
ICINFO * compressor_info = (ICINFO *) calloc(30,sizeof(ICINFO));
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// Samples for showing the image recording and compressor selection
///////////////////////////////////////////////////////////////////////////////////////////////////////////
int num_compressor =0;
for(int i=0; ICInfo(ICTYPE_VIDEO, i, &compressor_info[num_compressor]);
i++) {
if (num_compressor>=30) break; //maximum allows 30 compressors
HIC hic;
hic = ICOpen(compressor_info[num_compressor].fccType,
compressor_info[num_compressor].fccHandler, ICMODE_QUERY);
if (hic) {
if (ICERR_OK==ICCompressQuery(hic, &bmiHeader, NULL)) {
ICGetInfo(hic, &compressor_info[num_compressor],
sizeof(ICINFO));
num_compressor ++ ;
}
ICClose(hic);
}
}
if(num_compressor<=0)return FALSE;
////////////////////////////////////////////////////////////////////
// If user select the 1st compression method
////////////////////////////////////////////////////////////////
int selected_compressor=0;
BOOL bSuccess=m_JpgView.SetAviSerial(selected_compressor);
if(bSuccess==TRUE)
{
… … … … … … … … … … … … … … … … … … … … … … … … … … ..
bSuccess = m_JpgView.CloseAVI();
if(bSuccess==TRUE)
{
TRACE(“AVI OK\n”);
return TRUE;

}else
TRACE(“error occurs\n”);

}else
TRACE(“error occurs\n”);

return FALSE;;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Sample for connecting an iCAMView with IP address
// 192.168.0.101, port 9001 camera A. And control the camera.
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
DWORD nAddr = inet_addr(“192.168.0.101”);
m_JpgView.SetStrUserName(“test”);
m_JpgView.SetStrPassword(“test”);
m_JpgView.SetIPAddr(nAddr,9001,1);
m_JpgView.SetDelayTime(1000);//10 FPS
m_JpgView.SetSense(60);//sensitive 60
m_JpgView.SetLeftTop(10,10);//position (10,10) of parent window
m_JpgView.SetRadio(150); //set the image ratio 1.5
m_JpgView.SetImageState(0); // disable mirror function
m_JpgView.SetRevAngle(1);// rotate counter-clockwise 90 degree
m_JpgView.RefreshDraw(TRUE);// redraw the window after rotation
m_JpgView.SetCamCmd(31,8);// Enable the auto-scan function of camera A
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////////////////////////////////

You might also like