⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qsdlwidget.cpp

📁 海康威视视频采集卡linux开发包4.22版
💻 CPP
📖 第 1 页 / 共 4 页
字号:
void QSDLWidget::ContrastSet(int value){	dsdemoclass[SelectPort]->SetContrastScale(value);	}void QSDLWidget::ContrastAllSet(int value){	int temp = SelectPort;	int port;	for (port = 0; port < GetTotalChannels(); port++)	{		SelectPort = port;		ContrastSet(value);	}		SelectPort = temp;}void QSDLWidget::SaturationSet(int value){	dsdemoclass[SelectPort]->SetSaturationScale(value);	}void QSDLWidget::SaturationAllSet(int value){	int temp = SelectPort;	int port;	for (port = 0; port < GetTotalChannels(); port++)	{		SelectPort = port;		SaturationSet(value);	}		SelectPort = temp;	}void QSDLWidget::HueSet(int value){	dsdemoclass[SelectPort]->SetHueScale(value);	}void QSDLWidget::HueAllSet(int value){		int temp = SelectPort;	int port;	for (port = 0; port < GetTotalChannels(); port++)	{		SelectPort = port;		HueSet(value);	}		SelectPort = temp;	}int	QSDLWidget::GetChanNum(){	int totalport;	totalport = GetTotalChannels();	int chan = 1;		if(totalport <= 4)					chan = 2;    else	{		if(totalport <= 9)				chan = 3;		else		{			if (totalport <= 16)	    chan = 4;			else			{				if(totalport <= 25)     chan = 5;				else					chan = 6;			}		}	}	return chan;}void QSDLWidget::paintEvent ( QPaintEvent * e){	setPaletteBackgroundColor (QColor( 0, 0 ,0));	setPaletteForegroundColor (QColor( 0, 255, 0));}	void QSDLWidget::mousePressEvent ( QMouseEvent * e ){		int i;	int totalport;	if (FullArea || AllArea)			return;		QPoint pnt = e->pos();		totalport = GetTotalChannels();		//if  (e->button() == Qt::LeftButton)	//{		for(i = 0; i< totalport; i++)			{			if(PtInRect(DSCLASSDEMO(i)->dstRect, pnt.x(), pnt.y()))			{				SelectPort = i;				break;			}		}		if(i == totalport)			return;		if(DSCLASSDEMO(SelectPort)-> record_flag)		{						emit audioChange(SelectPort, (float)0.0);			emit videoChange(SelectPort, (float)0.0);			emit totalChange(SelectPort, 0);			emit bitRateChange(SelectPort, 0);		}				emit clicked(LEFTCLICKED);	//}	}	voidQSDLWidget::mouseDoubleClickEvent ( QMouseEvent * e ){	int temp;	int totalport;	int chan;	QRect qr( 0, 0, WIN_W, WIN_H);	QPaintEvent Qp(qr, TRUE);	totalport = GetTotalChannels();	chan = GetChanNum();	if (e != NULL && (e->button() == Qt::LeftButton || e->button() == Qt::RightButton) && (!(FullArea || AllArea)))	{				// 保证是有效区域内点击		int i;		QPoint pnt = e->pos();		for(i = 0; i< totalport; i++)			{			if(PtInRect(DSCLASSDEMO(i)->dstRect, pnt.x(), pnt.y()))			{				SelectPort = i;				break;			}		}		if(i == totalport)			return;	}	if(e !=NULL && e->button() == Qt::LeftButton && AllArea)	// 当全屏时双击左键实效	 	return;	if(e !=NULL && e->button() == Qt::RightButton && FullArea)	// 当局部全屏时双击右键实效	 	return;	 	if(e != NULL && e->button() == Qt::RightButton && !FullArea)  // 当局部没有全屏时双击左键	 	emit clicked(RIGHTCLICKED);	if ( e == NULL || (e->button() == Qt::LeftButton && !AllArea) )	{		if ( DSCLASSDEMO(SelectPort)->bPreviewOpen )		{			if (!FullArea)			{				for(temp = 0; temp < totalport; temp++)				{					if(DSCLASSDEMO(temp)->bPreviewOpen)						dsdemoclass[temp]->StopPreview();					if (DSCLASSDEMO(temp)->motion_flag)						dsdemoclass[temp]->DestoryMotion();				}						(DSCLASSDEMO(SelectPort)->dstRect).x = 0;				(DSCLASSDEMO(SelectPort)->dstRect).y = 0;				(DSCLASSDEMO(SelectPort)->dstRect).w = WIN_W;				(DSCLASSDEMO(SelectPort)->dstRect).h = WIN_H;				(DSCLASSDEMO(SelectPort)->motion_list).RectLeft = 0;				(DSCLASSDEMO(SelectPort)->motion_list).RectTop = 0;				(DSCLASSDEMO(SelectPort)->motion_list).RectRight = WIN_W;				(DSCLASSDEMO(SelectPort)->motion_list).RectBottom = WIN_H;				#ifdef USE_PREVIEW_TIMER				dsdemoclass[SelectPort]->SetPreview(0);#else				dsdemoclass[SelectPort]->SetPreview(1);#endif				if(DSCLASSDEMO(SelectPort)->motion_flag)					dsdemoclass[SelectPort]->SetupMotion();				FullArea = TRUE;			}			else			{				dsdemoclass[SelectPort]->DestoryMotion();				dsdemoclass[SelectPort]->StopPreview();					dsdemoclass[SelectPort]->SetdstRect(chan);				dsdemoclass[SelectPort]->SetMotion(chan);				erase();				paintEvent( &Qp );						for(temp = 0; temp < totalport; temp++)				{#ifdef USE_PREVIEW_TIMER					dsdemoclass[temp]->SetPreview(0);#else					dsdemoclass[temp]->SetPreview(1);#endif								}				MotionBegin();				FullArea = FALSE;			}		}	}	else if (e->button() == Qt::RightButton && !FullArea)	{		OutputDebugString("change the status, bPreviewOpen[%2d] = %d\n", SelectPort, DSCLASSDEMO(SelectPort)->bPreviewOpen);		if ( DSCLASSDEMO(SelectPort)->bPreviewOpen )		{			if (!AllArea)			{				for(temp = 0; temp < totalport; temp++)				{					if(DSCLASSDEMO(temp)->bPreviewOpen)						dsdemoclass[temp]->StopPreview();					if (DSCLASSDEMO(temp)->motion_flag)						dsdemoclass[temp]->DestoryMotion();				}								(DSCLASSDEMO(SelectPort)->dstRect).x = 0;				(DSCLASSDEMO(SelectPort)->dstRect).y = 0;				(DSCLASSDEMO(SelectPort)->dstRect).w = fsWidth;				(DSCLASSDEMO(SelectPort)->dstRect).h = fsHeight;				(DSCLASSDEMO(SelectPort)->motion_list).RectLeft = 0;				(DSCLASSDEMO(SelectPort)->motion_list).RectTop = 0;				(DSCLASSDEMO(SelectPort)->motion_list).RectRight = fsWidth;				(DSCLASSDEMO(SelectPort)->motion_list).RectBottom = fsHeight;				#ifdef USE_PREVIEW_TIMER				dsdemoclass[SelectPort]->SetPreview(0);#else				dsdemoclass[SelectPort]->SetPreview(1);#endif				if(DSCLASSDEMO(SelectPort)->motion_flag)					dsdemoclass[SelectPort]->SetupMotion();				AllArea = TRUE;				OutputDebugString("change the status complete, bPreviewOpen[%2d] = %d\n", SelectPort, DSCLASSDEMO(SelectPort)->bPreviewOpen);			}			else			{				OutputDebugString("&&&&&&&&&&&&&&&&&&&&&&Begin Ending FullScreen\n");				dsdemoclass[SelectPort]->DestoryMotion();				dsdemoclass[SelectPort]->StopPreview();					dsdemoclass[SelectPort]->SetdstRect(chan);				dsdemoclass[SelectPort]->SetMotion(chan);							erase();				//paintEvent( &Qp );						for(temp = 0; temp < totalport; temp++)				{#ifdef USE_PREVIEW_TIMER					dsdemoclass[temp]->SetPreview(0);#else					dsdemoclass[temp]->SetPreview(1);#endif								}				MotionBegin();				AllArea = FALSE;			}					}			OutputDebugString("change the status, bPreviewOpen[%2d] = %d\n", SelectPort, DSCLASSDEMO(SelectPort)->bPreviewOpen);	}}void QSDLWidget::MotionBegin()		//本应该这段程序直接放在mouseDoubleClickEvent中,									//但是经过测试,发现立刻打开motion会产生干扰,所以另新建了个MotionBegin程序{	int port;	for (port = 0; port < GetTotalChannels(); port++)	{		if (DSCLASSDEMO(port)->motion_flag)			dsdemoclass[port]->SetupMotion();	}}int QSDLWidget::PtInRect(SDL_Rect rect, int x, int y){	if((x > rect.x) && (x < (rect.x + rect.w)) && (y > rect.y) && (y < ( rect.y + rect.h))) 		return 1;	return 0;}int QSDLWidget::GetSelectPort(){	return SelectPort;}int QSDLWidget::GetLastPort(){	return LastPort;}bool QSDLWidget::GetFullState(){	return FullArea;}/**************************************************************************/void QSDLWidget::StreamRead_callback(int channel, char *databuf, int frametype, int framelength){		int head_size = 40;		pthread_mutex_lock(&(DSCLASSDEMO(channel)->major_start));	pthread_mutex_lock(&(DSCLASSDEMO(channel)->minor_start));#if 0	switch(frametype)	{		case PktSubIFrames:			printf(" here PktSubIFrames\n"); 			break;		case PktSubPFrames:			printf(" here PktSubPFrames\n"); 			break;		case PktSubBBPFrames:{printf(" here PktSubBBPFrames\n"); break;}		case PktSubSysHeader:{printf(" here PktSubSysHeader\n"); break;}		case PktSysHeader:{printf(" here PktSysHeader: ,net: %d\n", DSCLASSDEMO(channel)->net_flag); break;}		case PktIFrames:{printf(" here PktIFrames\n"); break;}				case PktPFrames:{printf(" here PktPFrames\n"); break;}		case PktBBPFrames:{printf(" here PktBBPFrames\n"); break;}		case PktAudioFrames:{printf(" here PktAudioFrames\n"); break;}		case PktSFrames:{printf(" here PktSFrames\n"); break;}		case PktMotionDetection:{printf(" here PktMotionDetection\n"); break;}		default:break;	}#endif	switch(frametype)	{		case PktSubIFrames:		case PktSubPFrames:		case PktSubBBPFrames:		case PktSubSysHeader:				{			if(frametype == PktSubSysHeader)			{				memcpy(DSCLASSDEMO(channel)->cifqciffile_head, databuf, framelength);				if (DSCLASSDEMO(channel)->cifqcif_fd)				{					(DSCLASSDEMO(channel)->cifqcif_fd)->writeBlock(databuf, framelength);					DSCLASSDEMO(channel)-> cifqciffilehead_flag = 1;				}								head_size = framelength;							}					if(DSCLASSDEMO(channel)->cifqcif_flag && DSCLASSDEMO(channel)->cifqcif_fd 												  && (DSCLASSDEMO(channel)-> cifqciffilehead_flag))			{				(DSCLASSDEMO(channel)->cifqcif_fd)->writeBlock(databuf, framelength);			}			break;		}			case PktAudioFrames:		{			if(DSCLASSDEMO(channel)->cifqcif_flag && DSCLASSDEMO(channel)->cifqcif_fd 												  && DSCLASSDEMO(channel)-> cifqciffilehead_flag)				{				(DSCLASSDEMO(channel)->cifqcif_fd)->writeBlock(databuf, framelength);			}			if (DSCLASSDEMO(channel)->record_flag && DSCLASSDEMO(channel)->record_fd 												  && DSCLASSDEMO(channel)-> filehead_flag)			{				(DSCLASSDEMO(channel)->record_fd)->writeBlock(databuf, framelength);			}			break;		}		case PktSysHeader:		case PktIFrames:					case PktPFrames:		case PktBBPFrames:		case PktSFrames:		{			if(frametype == PktSysHeader)			{				memcpy(DSCLASSDEMO(channel)->file_head, databuf, framelength);				if (DSCLASSDEMO(channel)->record_fd)				{					(DSCLASSDEMO(channel)->record_fd)->writeBlock(databuf, framelength);					DSCLASSDEMO(channel)->nodeinfo.FrameNum=0;					DSCLASSDEMO(channel)-> filehead_flag = 1;				}								head_size = framelength;											}			if (DSCLASSDEMO(channel)->record_flag && DSCLASSDEMO(channel)->record_fd &&  				DSCLASSDEMO(channel)->index_fd    && DSCLASSDEMO(channel)-> filehead_flag)			{				(DSCLASSDEMO(channel)->record_fd)->writeBlock(databuf, framelength);				DSCLASSDEMO(channel)->nodeinfo.FilePos += framelength;				if(frametype == PktIFrames)				{					(DSCLASSDEMO(channel)->index_fd)->writeBlock((char *)(&(DSCLASSDEMO(channel)->nodeinfo)), 																sizeof(INDEX_NODE));					DSCLASSDEMO(channel)->nodeinfo.FrameNum++;				}							if(frametype == PktBBPFrames)										DSCLASSDEMO(channel)->nodeinfo.FrameNum+=3;				}					DSCLASSDEMO(channel)->bit_rate_size += framelength;				break;		}		case PktMotionDetection:			{								int length;				length = framelength;											//fprintf(stderr,"motion pkt!\n");				memcpy(DSCLASSDEMO(channel)->motion_data, databuf,  length);	//fixed at 2005.3.1				if ( DSCLASSDEMO(channel)->motion_flag )					motion_detect(channel);				break;			}		default:			break;	}	if (DSCLASSDEMO(channel)->net_flag)	{		switch(frametype)		{			case PktSysHeader:			case PktIFrames:						case PktPFrames:			case PktBBPFrames:			case PktSFrames:			{								if(DSCLASSDEMO(channel)->net_head_flag == 0)				{					if(frametype != PktSysHeader)					{						MP4_ServerWriteDataEx(channel,DSCLASSDEMO(channel)->file_head, head_size, PktSysHeader, 0,0);	//双编码的时候用这个函数?					}					else						MP4_ServerWriteDataEx(channel,(char*)databuf,framelength,frametype, 0,0);						DSCLASSDEMO(channel)->net_head_flag = 1;				}				else					MP4_ServerWriteDataEx(channel,(char*)databuf, framelength, frametype, 0, 0);						break;			}			case PktSubIFrames:			case PktSubPFrames:			case PktSubBBPFrames:			case PktSubSysHeader:			{								if(DSCLASSDEMO(channel)->subchan_net_head_flag == 0)				{					if(frametype != PktSubSysHeader)					{						MP4_ServerWriteDataEx(channel,DSCLASSDEMO(channel)->cifqciffile_head, head_size, PktSysHeader, 0, 1);					}					else						MP4_ServerWriteDataEx(channel,(char*)databuf,framelength,frametype, 0,1);					DSCLASSDEMO(channel)->subchan_net_head_flag = 1;				}				else					MP4_ServerWriteDataEx(channel,(char*)databuf, framelength, frametype, 0, 1);				break;			}						case PktAudioFrames:			{					MP4_ServerWriteDataEx(channel, (char*)databuf, framelength, frametype, 0, 0);					MP4_ServerWriteDataEx(channel, (char*)databuf, framelength, frametype, 0, 1);				break;						}		}		if (checkpass[channel])		{			CaptureIFrame(DSCLASSDEMO(channel)-> ChannelHandle);			checkpass[channel] = 0;		}	}	pthread_mutex_unlock(&(DSCLASSDEMO(channel)->major_start));	pthread_mutex_unlock(&(DSCLASSDEMO(channel)->minor_start));}/**************************************************************************/void	QSDLWidget::motion_detect(int port){	float ratioX, ratioY;	unsigned int *pBuf;	int maxY;	int i, j;	int chan;	int Left, Top, Width, Height;			OutputDebugString("in function QSDLWidget::motion_detect\n");	chan = GetChanNum();	maxY = dsdemoclass[port]->GetVideoHeight();	if(FullArea)	{		if( port != SelectPort) return;		ratioX = (float)WIN_W / (float)704;  //由于全屏后存在一定的差异 800*700		ratioY = (float)WIN_H /(float)(maxY);	}	else	{		ratioX = (float)(WIN_W/chan) /(float)704;		ratioY = (float)(WIN_H/chan) /(float)(maxY);	}	maxY = maxY / 32;		pBuf = (unsigned int *)(DSCLASSDEMO(port)->motion_data);	for (i =0; i<maxY; i++)			{			int val = pBuf[i];					for (j=0; j< 22; j++)		{			if (val & (1 << j))				{				Left = (DSCLASSDEMO(port)->motion_list).RectLeft +   (int)((float)j * ratioX * 32.0);				Top  = (DSCLASSDEMO(port)->motion_list).RectTop  + (int)((float)i * ratioY * 32.0);				Width = int(ratioX * 32.0);				Height = int( ratioY * 32.0 );#if 0				QPainter Qp;				QBrush Qb(QColor(0,255,0), Qt::SolidPattern);				Qp.begin(this);				Qp.fillRect(Left, Top, Width, Height, Qb); 				Qp.end();#endif#if 0								bitBlt( this, Left, Top, pm, 0, 0, Width, Height);#endif				QRect *rectp;				rectp = new QRect(Left, Top, Width, Height);				QCustomEvent *event;				event = new QCustomEvent(198109);				event->setData(rectp);				QApplication::postEvent(this, event);			}		}				}	}/**/void QSDLWidget::customEvent ( QCustomEvent * e){	QRect *rt = (QRect *)(e->data());		if ( e->type() == 198109 )   // It must be a QMotionEvent	{		bitBlt( this, rt->left(), rt->top(), pm, 0, 0, rt->width(), rt->height());	}	delete rt;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -