예제 #1
0
파일: gop_lock.c 프로젝트: 119/ipnc
/**
 * @brief	Unlock GOP by serial
 * @param	"int serial" : serial no.
 * @param	"VIDEO_BLK_INFO *pVidInfo"
 * @param	"int index" : index
 * @return	GOP_COMPLETE (0) : success ; others : fail
 */
GopRet_t UnlockGopBySerial(int serial, VIDEO_BLK_INFO *pVidInfo,int index)
{
	GopInfo_t* pGopInfo;
	GopRet_t ret = GOP_COMPLETE;
	int cur_serial = GetCurrentSerialNo(pVidInfo);
	if(pVidInfo == NULL || serial < 0)
		return GOP_INVALID_PRM;
	Sem_lock(STREAM_SEM_GOP);
	if((pGopInfo = GetGopInfoBySerial(serial,index)) != NULL){
		pGopInfo->lock--;
	}else{
		Sem_unlock(STREAM_SEM_GOP);
		return GOP_INVALID_PRM;
	}
	if(pGopInfo->lock == 0){
		if(pGopInfo->start_serial <= cur_serial && pGopInfo->end_serial >= cur_serial)
			ret = GOP_INCOMPLETE;
		if(UnlockGop(pGopInfo->start_serial, pGopInfo->end_serial, pVidInfo) != GOP_COMPLETE)
			ERR("Unlock fail, Memory leak will occure\n");
		if(DeleteGop(pGopInfo,index) != GOP_COMPLETE)
			ERR("Can not found GOP at address 0x%x\n", (unsigned int)pGopInfo);
	}
	Sem_unlock(STREAM_SEM_GOP);



	return ret;
}
예제 #2
0
/**
 * @brief	Memory copy funtion
 * @param	"void *Des" : destination address
 * @param	"void *Src" : source address
 * @param	"int size" : size
 * @return	0 : success ; -1 : fail
 */
int CacheMng_MemCpy( void *Des, void *Src, int size )
{
    if( Des == NULL || Src == NULL )
    {
        return CACHE_PARM_ERR;
    }

#if	CACHEMNG_DMA

    DRV_DmaCopy1D copy1D;

    Sem_lock( STREAM_SEM_CACHECPY);

    copy1D.srcPhysAddr 	= (unsigned long)DRV_dmaGetPhysAddr((unsigned long)Src);
    copy1D.dstPhysAddr 	= (unsigned long)DRV_dmaGetPhysAddr((unsigned long)Des);
    copy1D.size 				=	size;
    DRV_dmaCopy1D(&dmaHndl, &copy1D, 1);

    Sem_unlock( STREAM_SEM_CACHECPY);

#else
    memcpy( Des, Src , size );
#endif

    return 0;
}
예제 #3
0
/**
 * @brief    check if file need write
 * @param    none
 * @retval    ret = IsFileQuit
 */
static int FileNeedWrite()
{
    int ret;
    Sem_lock();
    ret = bNeedWrite;
    Sem_unlock();
    return ret;
}
예제 #4
0
/**
 * @brief    check if file thread quit
 * @param    none
 * @retval    ret = IsFileQuit
 */
int IsFileThreadQuit()
{
    int ret;
    Sem_lock();
    ret = IsFileQuit;
    Sem_unlock();
    return ret;
}
예제 #5
0
파일: gop_lock.c 프로젝트: 119/ipnc
/**
 * @brief	Lock GOP
 * @param	"VIDEO_BLK_INFO *pVidInfo"
 * @param	"int index" : index
 * @return	none
 */
void GopCleanup(VIDEO_BLK_INFO *pVidInfo, int index)
{
	GopInfo_t* pGopInfo;
	Sem_lock(STREAM_SEM_GOP);
	while(gGopList[index] != NULL){
		pGopInfo = gGopList[index];
		UnlockGop(pGopInfo->start_serial, pGopInfo->end_serial, pVidInfo);
		gGopList[index] = gGopList[index]->next;
		GopInfoFree(pGopInfo);
	}
	Sem_unlock(STREAM_SEM_GOP);
}
예제 #6
0
파일: gop_lock.c 프로젝트: 119/ipnc
/**
 * @brief	Lock current GOP
 * @param	"VIDEO_BLK_INFO *pVidInfo"
 * @param	"int index" : index
 * @return	GOP_COMPLETE(0) : success ; others : fail
 */
GopRet_t LockCurrentGopP(VIDEO_BLK_INFO *pVidInfo, int index)
{
	int ret,cur_serial = GetCurrentSerialNo(pVidInfo);
	GopInfo_t* pGopInfo;

	Sem_lock(STREAM_SEM_GOP);
	pGopInfo = GetGopInfoBySerial(cur_serial - 1,index);
	if(pGopInfo == NULL)
	{
		ERR("cur_serial = %d\n",cur_serial);
		ShowAllGop(index);
		Sem_unlock(STREAM_SEM_GOP);
		return GOP_ERROR_OP;
	}
	//if(GetGopInfoBySerial(cur_serial,index)!= NULL)
	//	return GOP_COMPLETE;
	//CheckReCache( cur_serial, pVidInfo, __LINE__ ); -- DEBUG ONLY
	if((ret = CacheMng_Video_CacheLock(cur_serial, pVidInfo)) != 0){
		DBG("LockCurrentGopP: %d\n",ret);
		UnlockGop(pGopInfo->start_serial, pGopInfo->end_serial, pVidInfo);
		DeleteGop(pGopInfo,index);
		Sem_unlock(STREAM_SEM_GOP);
		if(ret == CACHE_NOMEM)
			return GOP_NOMEM;
		else
			return GOP_FAIL;
	}
	pGopInfo->end_serial = cur_serial;
	Sem_unlock(STREAM_SEM_GOP);
	#ifdef VANLINK_DVR_DM365_DEBUG	
	DBG(": -----------------vl Line %d cur_serial=%d\n", __LINE__,cur_serial);
	#endif
	//if(GetGopInfoBySerial(cur_serial,index)== NULL)
	//	return GOP_FAIL;
	return GOP_COMPLETE;
}
예제 #7
0
파일: mem_mng.c 프로젝트: lubing521/ipnc
/**
 * @brief	Do memory copy
 * @param	"void *pDes" : destination address
 * @param	"void *pSrc" : source address
 * @param	"int size" : size
 * @return	0 : success ; others : fail
 */
int MemMng_memcpy(void *pDes, void *pSrc, int size )
{
#if	MEMMNG_DMA

	DRV_DmaCopy1D copy1D;

	Sem_lock( STREAM_SEM_MEMCPY);

	copy1D.srcPhysAddr 	= (unsigned long)DRV_dmaGetPhysAddr((unsigned long)pSrc);
	copy1D.dstPhysAddr 	= (unsigned long)DRV_dmaGetPhysAddr((unsigned long)pDes);
	copy1D.size 				=	size ;
	DRV_dmaCopy1D(&dmaHndl, &copy1D, 1);

	Sem_unlock( STREAM_SEM_MEMCPY);

#else

	memcpy( pDes, pSrc, size );
#endif

	return 0;
}
예제 #8
0
파일: gop_lock.c 프로젝트: 119/ipnc
/**
 * @brief	Lock GOP by serial
 * @param	"int serial" : serial no.
 * @param	"VIDEO_BLK_INFO *pVidInfo"
 * @param	"int index" : index
 * @return	0 : success ; others : fail
 */
GopRet_t LockGopBySerial(int serial, VIDEO_BLK_INFO *pVidInfo, int index)
{
	VIDEO_FRAME* pFrame;
	GopInfo_t* pGopInfo;
	GopRet_t ret = GOP_COMPLETE;
	int end_serial, cur_serial;

	if(pVidInfo == NULL || serial < 0)
	{
		return GOP_INVALID_PRM;
	}

	Sem_lock(STREAM_SEM_GOP);
	if((pGopInfo = GetGopInfoBySerial(serial, index)) != NULL)
	{
		pGopInfo->lock++;
	}
	else
	{
		cur_serial = GetCurrentSerialNo(pVidInfo);

		if((pFrame = MemMng_GetFrameBySerial(serial, pVidInfo)) == NULL)
		{
			Sem_unlock(STREAM_SEM_GOP);
			if(cur_serial == serial)
				return GOP_FAIL;
			else if(cur_serial < serial)
				return GOP_NOT_READY;
			else
				return GOP_OVERWRITTEN;
		}
		if(pFrame->fram_type == I_FRAME)
		{
			end_serial = GetGopLastPwithStartSerial(serial, pVidInfo);
			if(0 > end_serial)
			{
				end_serial = cur_serial;
				ret = AddAndLockGop(serial, end_serial, pVidInfo,index);
				if(ret == GOP_COMPLETE)
					ret = GOP_INCOMPLETE;
			}
			else
			{
				ret = AddAndLockGop(serial, end_serial, pVidInfo,index);
			}

		}
		else if(pFrame->fram_type == P_FRAME)
		{


			if((pGopInfo = GetGopInfoBySerial(serial - 1,index)) != NULL)
			{
				//CheckReCache( serial, pVidInfo, __LINE__ ); -- DEBUG ONLY
				if((ret=CacheMng_Video_CacheLock(serial, pVidInfo)) == 0)
				{
					pGopInfo->lock++;
					pGopInfo->end_serial = serial;
				}else{
					if(ret == CACHE_NOMEM)
						ret = GOP_NOMEM;
					else
						ret = GOP_FAIL;
				}

			}
			else
			{
				ret = GOP_ERROR_OP;
			}
		} else
			ERR("Unkown fram type in %s\n", __func__);
	}
	Sem_unlock(STREAM_SEM_GOP);



	return ret;
}
예제 #9
0
/**
 * @brief    set file to be updated
 * @param    none
 * @retval    none
 */
static void SetFileUpdate()
{
    Sem_lock();
    bNeedWrite = 1;
    Sem_unlock();
}
예제 #10
0
/**
 * @brief    set file thread quit
 * @param    none
 * @retval    none
 */
static void SetFileQuit()
{
    Sem_lock();
    IsFileQuit = 1;
    Sem_unlock();
}
예제 #11
0
/**
 * @brief    file has been updated
 * @param    none
 * @retval    none
 */
static void FileUpdated()
{
    Sem_lock();
    bNeedWrite = 0;
    Sem_unlock();
}