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

📄 tccmmbdlg.cpp

📁 自己在wince的环境下做的一移动数字电视驱动
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		dwType   = REG_DWORD;
		if(dwStatus == ERROR_SUCCESS && dwType == REG_DWORD) 
		{
			dwSize = sizeof(DWORD);
			dwStatus = RegQueryValueEx(hk, _T("VIDEO_MEM_START"), NULL, &dwType, (LPBYTE) &decPhysicalMemStart, &dwSize);
		}
#else
		unsigned int decPhysicalMemStart = HW_MEM_BASE;	// defined in Common/Virtual.h  
#endif
		///////////////////////////////////////////////////////////////////
		if(m_pH264Dec->TCC_CODEC_H264Dec_Open(decPhysicalMemStart) < 0){
			printf("ERROR: TCCH264DecFilter  - m_pH264Dec->TCC_CODEC_H264Dec_Open Fail \r\n");
			m_pH264Dec->TCC_CODEC_H264Dec_Close();
			delete m_pH264Dec;
			m_pH264Dec = NULL;
		}
	}
	m_pH264Dec->m_IsAVC=0;
	
}

DWORD RawVideoProcess(PVOID pArg)
{
	BOOL lresult=FALSE;
	int  videoframesum=0,result=0;
	RawVideoPacket  getrawitem;
	while(Decodeing)
	{
		Sleep(1);
		memset(&getrawitem,0, sizeof(RawVideoPacket));

		EnterCriticalSection(&Video_section);
//		printf("RawVideoProcess::VideoCount=%d\n",VideoCount);
		if(VideoCount>(MAX_NUM_OF_VIDEO_ELEMENT-2))
		{
			LeaveCriticalSection(&Video_section);
			continue;			
		}
		LeaveCriticalSection(&Video_section);

		result=RawVideoQueue->Get((unsigned char *)&getrawitem,sizeof(RawVideoPacket));
		if(!result)
		{
			continue;
		}

		videoframesum=0;
		lresult=VideoDataProcess(getrawitem.rawdata,getrawitem.size,videoframesum);
		if(lresult==TRUE)
		{
#if 0
			if(DemuxVideo[0].flag==TRUE)
			{
			lresult=H264Decprocess(DemuxVideo[0].Data,
					DemuxVideo[0].size,getrawitem->StartPlayTime,getrawitem->streamstime);
			delete DemuxVideo[0].Data;
			memset(&(DemuxVideo[0]),0,sizeof(DEMUXVIDEOITEM));
			}
			
			if(DemuxVideo[1].flag==TRUE)
			{
			lresult=H264Decprocess(DemuxVideo[1].Data,
					DemuxVideo[1].size,getrawitem->StartPlayTime,getrawitem->streamstime);
			delete DemuxVideo[1].Data;
			memset(&(DemuxVideo[1]),0,sizeof(DEMUXVIDEOITEM));
			}
#else
			for(int i=0;i<videoframesum;i++)
			{
				if(DemuxVideo[i].flag!=TRUE)
					continue;
				lresult=H264Decprocess(DemuxVideo[i].Data,
						DemuxVideo[i].size,getrawitem.StartPlayTime,getrawitem.streamstime);
				delete DemuxVideo[i].Data;
				memset(&(DemuxVideo[i]),0,sizeof(DEMUXVIDEOITEM));

			}
#endif
		}
	}

	RawVideoQueue->Clear();
	
	return 1;
}

#define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24))
#define MKTAG2(a,b,c) (a | (b << 8) | (c << 16))

#define TAG3 0x010000
#define TAG4 0x01000000

#if 0
BOOL VideoDataProcess(unsigned char *pDataIn,unsigned long nBitStreamSize)
{
	unsigned char *startptr=NULL, *endptr=NULL;
	unsigned char *startptr2=NULL, *endptr2=NULL;
	unsigned char *pDataInFirst=NULL, * pps=NULL, *sps=NULL;
	
	int count = 0, i = 0;
	unsigned char *fbuff = pDataIn;
	unsigned char *previous_fbuff;
	unsigned long fsize = nBitStreamSize;
	unsigned int nal_header = 0;
	unsigned int outbuff_size=0;
	bool hasPicture=FALSE;
	int ret=0;
	bool issps = FALSE, ispps = FALSE,start=TRUE;

	while((fsize - count)>=3)
	{
		if(TAG4 == MKTAG(fbuff[0], fbuff[1], fbuff[2], fbuff[3]))
			nal_header = 4;
		else if(TAG3 == MKTAG2(fbuff[0], fbuff[1], fbuff[2]))
			nal_header = 3;
		else{
			count++;
			fbuff++;
		}
		if(nal_header)
		{
			if(start)
			{
				pDataInFirst=fbuff;
				start=FALSE;
			}
			fbuff += nal_header;
			count += nal_header;
			if(issps)
			{
				issps=FALSE;
			}
			if(ispps)
			{
				ispps=FALSE;
			}
			previous_fbuff=fbuff;
			switch( *fbuff & 0x1F )
			{
				case 0x06:
					break;

				case 0x07:
					issps = TRUE;
					sps = fbuff;					
					break;

				case 0x08:
					ispps = TRUE;
					pps = fbuff;							
					break;

				case 0x09: //added for oneseg data */
					break;

				default:
					if(i == 0)
					{
						startptr = fbuff-nal_header;
					}if(i==1)
					{
						startptr2 = endptr = fbuff-nal_header;
					}
					else{
						endptr2 = fbuff;
					}
					hasPicture=TRUE;
					i++;
					break;
			}
			nal_header = 0;
		}
	}

	if(i==0)
		return FALSE;

	if(i==1)
		endptr=pDataIn+nBitStreamSize;

	if(i!=2){//(i>2)||(i<2)
		printf("++++H264 Video Data Error = %d-----\n",i);
//		for(int j=0;j<nBitStreamSize;j++)
//			printf("%x ",pDataIn[j]);
//		printf("\n");
	}

	if(i>=1)
	{
	memset(&DemuxVideo[0],0,sizeof(DEMUXVIDEOITEM));
	DemuxVideo[0].Data=new U8[endptr-pDataInFirst];
	memcpy(DemuxVideo[0].Data,pDataInFirst,endptr-pDataInFirst);
	DemuxVideo[0].size=endptr-pDataInFirst;
	DemuxVideo[0].flag=TRUE;
	}
	if(i>=2)
	{
	memset(&DemuxVideo[1],0,sizeof(DEMUXVIDEOITEM));
	DemuxVideo[1].Data=new U8[fsize-(endptr-pDataInFirst)-(pDataInFirst-pDataIn)];
	memcpy(DemuxVideo[1].Data,endptr,fsize-(endptr-pDataInFirst)-(pDataInFirst-pDataIn));
	DemuxVideo[1].size=fsize-(endptr-pDataInFirst)-(pDataInFirst-pDataIn);
	DemuxVideo[1].flag=TRUE;
	}

	return TRUE;
}
#else
/**********************************************************
*
*	Function of	
*
*	Input	: 
*	Output	: 
*	Return	: 
*
*	Description	: 
**********************************************************/
BOOL VideoDataProcess(unsigned char *pDataIn,unsigned long nBitStreamSize, int & iPTS)
{
	unsigned char *startptr[MAX_NAL_COUNT], *endptr[MAX_NAL_COUNT];
	unsigned char *pDataInFirst=NULL, * pps=NULL, *sps=NULL;
	
	int count = 0, i=0,j=0;
	unsigned char *fbuff = pDataIn;
	unsigned long fsize = nBitStreamSize;
	unsigned int nal_header = 0;
	unsigned int outbuff_size=0;
	int		hasPicture=0;
	int 		ret=0;
	int		iDataSize;
	unsigned char 	*ptrData;
	//int		loop_count;
	bool issps = FALSE, ispps = FALSE,combin=FALSE;

	while(fsize - count)
	{
		if(TAG4 == MKTAG(fbuff[0], fbuff[1], fbuff[2], fbuff[3]))
			nal_header = 4;
		else if(TAG3 == MKTAG2(fbuff[0], fbuff[1], fbuff[2]))
			nal_header = 3;
		else{
			count++;
			fbuff++;
		}

		if(nal_header)
		{
			fbuff += nal_header;
			count += nal_header;
			
			if(combin==FALSE)
				startptr[hasPicture] = fbuff - nal_header;

			switch( *fbuff & 0x1F )
			{
				case 0x07:
					issps = TRUE;
					sps = fbuff - nal_header;					
					break;

				case 0x08:
					ispps = TRUE;
					pps = fbuff - nal_header;							
					break;

				default:
					ispps = issps = FALSE;
					break;
			}
			
			if(issps||ispps)
			{
				combin=TRUE;
				if(hasPicture==0)
					hasPicture++;
				nal_header = 0;
				continue;
			}
			if(combin)
			{
				combin=FALSE;
				nal_header = 0;
				continue;
			}
			if(hasPicture>0)
				endptr[hasPicture-1] = startptr[hasPicture];
			
			if( hasPicture < MAX_NAL_COUNT )
				hasPicture ++;
			else
				break;
			nal_header = 0;
		}
	}

	endptr[hasPicture-1] 	= pDataIn+fsize;
	startptr[hasPicture] 	= NULL;
	endptr[hasPicture] 		= NULL;

//	if(hasPicture!=2){//(hasPicture>2)||(hasPicture<2)
//		printf("++++H264 Video Data Sum = %d-----\n",hasPicture);
//		for(int j=0;j<nBitStreamSize;j++)
//			printf("%x ",pDataIn[j]);
//		printf("\n");
//	}

	// push to buffer a NAL data
	for ( i=0 ; i<hasPicture ; i++ )
	{
		ptrData		= startptr[i];
		iDataSize 	= endptr[i]-startptr[i];
		memset(&DemuxVideo[i],0,sizeof(DEMUXVIDEOITEM));
		DemuxVideo[i].Data=NULL;
		DemuxVideo[i].Data=new U8[iDataSize];
		if(DemuxVideo[i].Data==NULL)
		{
			DemuxVideo[i].size=0;
			DemuxVideo[i].flag=FALSE;	
			continue;
		}
		memcpy(DemuxVideo[i].Data,ptrData,iDataSize);
		DemuxVideo[i].size=iDataSize;
		DemuxVideo[i].flag=TRUE;
	}
	iPTS=hasPicture;

	return TRUE;
}
#endif

BOOL H264Decprocess(unsigned char *pDataIn,unsigned long nBitStreamSize,int playtime,int time)
{
	HRESULT	hr=S_OK;
	int nRet;

	if(m_pH264Dec)
	{
		if(nBitStreamSize > 0)
		{
			nRet = m_pH264Dec->TCC_CODEC_H264_DECODE(pDataIn, nBitStreamSize);
			if(nRet <=0)
			{
				if(nRet<0)
				{
					printf("TCCH264DecFilter  - m_pH264Dec->TCC_CODEC_H264_DECODE < 0  =%d \r\n",nRet);
					m_pH264Dec->TCC_CODEC_H264Dec_Close();
					delete m_pH264Dec;
					InitH264Dec();
				}
				if(nRet==TCC_CODEC_ERROR_CODEC_INIT||nRet==TCC_CODEC_ERROR_OUTPUT_BUFFER_SIZE||nRet==TCC_CODEC_ERROR_NOT_DECODABLE_TYPE)
					//NotifyEvent(EC_USER_UNSUPPORTTED_VIDEO,0,0); // Unsupported Video 
					printf("EC_USER_UNSUPPORTTED_VIDEO!\n");
				hr=S_FALSE;
			}	
		}
		else
			hr=S_FALSE;
	}
	else{
		printf("ERROR: TCCH264DecFilter - m_pH264Dec is NULL\r\n");
		return FALSE;
	}
	if(hr==S_FALSE)
		return FALSE;

	VideoPacket * videoitem=NULL;
    videoitem = new VideoPacket;
	if(videoitem!=NULL)
	{
	memset(videoitem,0,sizeof(VideoPacket));
	videoitem->DataOut.pFrame=(unsigned char*)m_pH264Dec->H264GetVideoBuffer();
	videoitem->DataOut.nWidth=m_pH264Dec->gWidth;
	videoitem->DataOut.nHeight=m_pH264Dec->gHeight;
	videoitem->DataOut.nType=1;
	videoitem->DataOut.nHeightOffset=(m_pH264Dec->gHeight - m_pH264Dec->gActualHeight);
	videoitem->DataOut.nWidthOffset=(m_pH264Dec->gWidth - m_pH264Dec->gActualWidth);
	videoitem->StartPlayTime = playtime;
	videoitem->streamstime = time;
	videoitem->Next=NULL;
	EnterCriticalSection(&Video_section);
	if((VideoFirst==NULL))
		VideoFirst=VideoLast=videoitem;
	else{
		VideoLast->Next=videoitem;
		VideoLast=videoitem;
	}
	VideoCount++;
	LeaveCriticalSection(&Video_section);
	}
	
	m_pH264Dec->gbuffindex++;
	if(m_pH264Dec->gbuffindex >= MAX_NUM_OF_VIDEO_ELEMENT)
		m_pH264Dec->gbuffindex = 0;
	
	return TRUE;
}

void ChangeAllScreen()
{
	if(m_pVideoRender==NULL)
		return;

	unsigned int Width=320,Height=240,h=LCD_VSIZE,w=LCD_HSIZE,m;
	VrenderModeFlag flag;
	flag.left=0;
	flag.top =0;
	flag.width=LCD_HSIZE;
	flag.height = LCD_VSIZE;
	
	if(AllScreenFlag)
	{
		AllScreenFlag=FALSE;
	}else{
		if (Width*h < Height*w)
		{
				w = (Width*h/Height);
				m = LCD_HSIZE;
				flag.left += (m-w)/2;
				flag.width -= (m-w);
		}
		else
		{
				h = (Height*w/Width);
				m = LCD_VSIZE;
				flag.top += (m-h)/2;
				flag.height -= (m-h);
		}
		AllScreenFlag=TRUE;
	}
	flag.mode =1;
	m_pVideoRender->SetModeFlag(flag);	
}


void InitVideoRender()
{
	m_pVideoRender = NULL;
	m_pVideoRender = new CVideoRenderer();
	ChangeAllScreen();
}

DWORD VideoRenderProcess(PVOID pArg)
{
	int tmp=0;
	VideoPacket * getItem;
	int flag=1;
	while (Decodeing)
	{
		Sleep(1);
		flag=1;
		EnterCriticalSection(&Video_section);
		if((VideoFirst==NULL))
		{
			VideoTimer=0;
			LeaveCriticalSection(&Video_section);
			continue;
		}
		VideoTimer = VideoFirst->streamstime + VideoFirst->StartPlayTime;
		LeaveCriticalSection(&Video_section);

		if((!IsFirstFrame))
		{
			tmp=GetTickCount();
			if((tmp-m_rendertime)<=35)
			{
//				printf("RenderTimer=%d \n",tmp-m_rendertime);
				continue;
			}else if((tmp-m_rendertime)>80)
			{
				printf("RenderTimer=%d \n",tmp-m_rendertime);
				flag=0;
/*
				EnterCriticalSection(&Video_section);
				VideoFirst = VideoFirst->Next;
				VideoCount--;
				LeaveCriticalSection(&Video_section);
				m_rendertime=tmp;
				continue;
//*/
			}
		}
		
		EnterCriticalSection(&Timer_section);
		if(((AudioTimer-VideoTimer)<400)&&flag)//&&(((RawVideoQueue->GetSum())/(sizeof(RawVideoPacket)))<65)
		{
			LeaveCriticalSection(&Timer_section);
			continue; 
		}
		LeaveCriticalSection(&Timer_section);

		if(m_pVideoRender)
		{
			EnterCriticalSection(&Video_section);
			getItem=VideoFirst;
			VideoFirst = VideoFirst->Next;
			VideoCount--;
			LeaveCriticalSection(&Video_section);
			m_pVideoRender->DoRenderSample(&(getItem->DataOut));
			tmp=GetTickCount();
			m_rendertime=tmp;
			if(IsFirstFrame)
			{
				IsFirstFrame=FALSE;
			}

			delete getItem;
			getItem = NULL;
		}else{
			return 1;
		}
	}

⌨️ 快捷键说明

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