1,183
社区成员
发帖
与我相关
我的任务
分享
#ifndef _NETCAMERA_SNAPSERVER_H_
#define _NETCAMERA_SNAPSERVER_H_
#ifndef _WIN32 //linux
#define NC_SNAP_EXT
#define CRITICAL_SECTION pthread_mutex_t
#define InitializeCriticalSection(x) pthread_mutex_init(x,NULL)
#define DeleteCriticalSection(x) pthread_mutex_destroy(x)
#define EnterCriticalSection(x) pthread_mutex_lock(x)
#define LeaveCriticalSection(x) pthread_mutex_unlock(x)
#else //windows
#define _CRTDBG_MAP_ALLOC
#include<stdlib.h>
#include<crtdbg.h>
#include<windows.h>
#ifndef NETCAMERA_SNAPSERVER_EXPORTS
#define NC_SNAP_EXT __declspec(dllimport)
#else
#define NC_SNAP_EXT __declspec(dllexport)
#endif
#endif
#include <queue>
using namespace std;
////////////////////////////////////////////////////////////////////////////////
//STRUCT DEFINE
#ifndef _FRAME_HEADER_
#define _FRAME_HEADER_
struct FRAME_HEADER
{
unsigned short w; //image width
unsigned short h; //image height
unsigned short bits; //bits
unsigned short format; //data type(0:gray 1:bayer_rg 2:bayer_GR 3:bayer_bg 5:RGB 6:YUV422 7:JPEG 8:MPEG4 9:H264)
unsigned short frame_type; //frame type:(0:normal frame 1:snap frame 2:heart-beat frame)
unsigned short frame_version; //frame version: current set to 0x0100
unsigned long firmware_version;//firmware version
unsigned long device_no; //device num
unsigned long len; //image size
unsigned long speed; //speed
unsigned long rs232; //rs232 info
unsigned short year; //image cap time:year
unsigned short month; //image cap time:month
unsigned short day; //image cap time:day
unsigned short hour; //image cap time:hour
unsigned short minute; //image cap time:minute
unsigned short second; //image cap time:second
unsigned long ip; //current camera ip
unsigned long frame_count; //total snap frame number
unsigned long trigger_count; //total trigger number
unsigned long trigger_index; //trigger index
unsigned long frame_no; //frame number
unsigned long gain; //gain
unsigned long time; //ex time
unsigned long gain_r; //red gain
unsigned long gain_g; //green gain
unsigned long gain_b; //blue gain
unsigned long mode; //camera work mode
unsigned long JpegQ; //jpeg quality
unsigned long td1; //td1
unsigned long td2; //td2
unsigned long trig_chl; //trigger channel
unsigned long msecond; //image cap time:msecond
unsigned long yavg; //yavg
unsigned long mpeg_head; //mpeg4/h264 header flag
unsigned long st_usr_param; //soft trigger user param
unsigned long rev[7]; //rev
unsigned char user_info[64]; //user info
};
#endif
class NC_SNAP_EXT NetCamera_SnapServer
{
public:
int Init();
int StartRecv(unsigned short port);
int GetImage(unsigned char* buf,int &total_length);
int UnInit();
int AddImage(unsigned char* pImage);
public:
unsigned int GetSocket();
unsigned short GetRecvPort();
NetCamera_SnapServer();
virtual ~NetCamera_SnapServer();
private:
int m_nMaxQueueLength; /*max length of image queue*/
unsigned short m_nPort; /*listen port*/
unsigned int m_nSocket; /*listen socket*/
queue<unsigned char*>* m_pImageQueue; /*image queue*/
CRITICAL_SECTION m_cs; /*mutex the queue*/
};
#endif
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <direct.h>
#include "NetCamera_SnapServer.h"
extern "C" _declspec(dllexport) int SnapServerInit();
int SnapServerInit()
{
NetCamera_SnapServer server; //如果有这句,就编译不过,没有,就可以。
return 0;
}