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

📄 601cman.c

📁 视频601芯片的驱动源码,你可以完全掌控该芯片了,对于其它多媒体芯片的设计具有参考价值
💻 C
📖 第 1 页 / 共 4 页
字号:
    return OK;
}

// -------------------------------------------------------------------------
//
// Load ADV601 VxD Dynamically
//
// -------------------------------------------------------------------------
DLLEXPORT int Load601VxD(EV601 * * pExport601Info)
{
	DWORD	Tid;				// id of created thread
	const 	PCHAR VxDName = "\\\\.\\601rpman";
	DWORD	dwThreadParam;
	static	LoadVxDCnt=0;


	// Make sure the pointer to pointer is initialized with NULL
	if (pExport601Info != NULL)
		*pExport601Info = NULL;

	// Only Want to open VxD Once !
	if (LoadVxDCnt)
	{
		*pExport601Info = pEV601Info;
		return OK;
	}

	// Only Want to open VxD Once !
	if (LoadDllCnt)
		return CMAN_LOAD_VXD_ERR;

#if 0
	// This call is only good for the DLL to dynamic load the VxD, will
	// not work with Plug and Play !
	// SL		3-10-96
	hDevice = CreateFile(VxDName, 0,0,0,
                        CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0);
#else
	hDevice = CreateFile(VxDName, 0, 0, NULL, 0, 0, NULL);
#endif

	if (hDevice == INVALID_HANDLE_VALUE)
		return CMAN_EV601_NOT_FOUND;


	if ( ! DeviceIoControl(hDevice, INIT_VXD_VXDMSG,
               inBuf, sizeof(PVOID), (LPVOID)RetInfo, sizeof(RetInfo),
               &cbBytesReturned, NULL)
	   )
		return CMAN_LOAD_VXD_ERR;

	p601RTErr = (DWORD*)RetInfo[0];

	// Get PCI Configuration information
	if (OK != QueryPCIInfo())
		return CMAN_GET_PCI_INFO_ERR;

	// Check if EV601 found if the PCI config. table is available
	if (!pPciInfo->vendor_found_flg) 
		return CMAN_VENDOR_ID_NOT_FOUND;

	if (pPciInfo->interrupt_vector == 0xFF) 
		return CMAN_IRQ_NOT_VALID;

	// Get PCI Configuration information
	if (0 != Query601Config())
		return CMAN_GET_EV601_CFG_ERR;


	// Create a thread that will wait for notification by the VxD.
	hThread = CreateThread(0, 0x1000, (LPTHREAD_START_ROUTINE)ServiceThread, &dwThreadParam, 0, &Tid);

	// Need to increment the reference count here !
	LoadVxDCnt++;

	// Export the EV601 info structure
	if (pExport601Info == NULL)
		return OK;
	else
		*pExport601Info = pEV601Info;


	return OK;
}


// -------------------------------------------------------------------------
//
// 	GetRunTimeErr()
//
// -------------------------------------------------------------------------
DLLEXPORT DWORD GetCapPlyBkRunTimeStatus(CapPlyBkRTinfo *pCapPlyBkRTinfo)
{
	dword 	ErrFlg;

	if (pCapPlyBkRTinfo == NULL)
		return CMAN_GET_CAP_PLYBK_INFO_ERR;

	inBuf[0] = pCapPlyBkRTinfo;
	RetInfo[0] = 0;

    if ( ! DeviceIoControl(hDevice, GET_CAP_PLYBK_RT_INFO_VXDMSG,
               inBuf, sizeof(PVOID), (LPVOID)RetInfo, sizeof(RetInfo),
               &cbBytesReturned, NULL)
	   )
			return CMAN_VXD_IFACE_ERR;

	// Also update the Bin Width Calculation count in CapPlyBkRTinfo 
	// structure.
	pCapPlyBkRTinfo->BWCcnt = BWCcnt;

	return ErrFlg;
}


// -------------------------------------------------------------------------
//
// Read601Statistic
//
// -------------------------------------------------------------------------
DLLEXPORT int	Read601Statistic(BWCinput *pBWcIn)
{

	return OK;
}

// -------------------------------------------------------------------------
//
// WriteBWCoeff
//
// -------------------------------------------------------------------------
DLLEXPORT int	WriteBWCoeff(BWCoutput * pBWcOut)
{

	return OK;
}

static word video_wd[4][6] = 
{
	720, 360, 180, 90, 45, 23,
	640, 320, 160, 80, 40, 20,
	720, 360, 180, 90, 45, 23,
	768, 384, 192, 96, 48, 24
};

static word video_ht[4][6] =
{
	486, 243, 122, 61, 31, 16,
	486, 243, 122, 61, 31, 16,
	576, 288, 144, 72, 36, 18,
	576, 288, 144, 72, 36, 18
};

// -------------------------------------------------------------------------
//
// 	InitBWCalculator
//
// -------------------------------------------------------------------------
DLLEXPORT int	InitBWCalculator(CaptureCfg * pEncCfg)
{

	int		  i, V_Sz_Idx, V_Frm_Idx;

	if (pEncCfg == NULL)
		return FAILURE;

	V_Sz_Idx = pEncCfg->Resolution;
	V_Frm_Idx = (CapVideo.VideoFormat == NTSC) ? 0 : 2;
	if (CapVideo.PixelType == SQ_PIXEL)
		V_Frm_Idx++;

    init_rec.ImageWidth  = video_wd[V_Frm_Idx][V_Sz_Idx];
    init_rec.ImageHeight = video_ht[V_Frm_Idx][V_Sz_Idx];
    init_rec.Bpp         = pEncCfg->BitPerPixel;
    init_rec.scene_detection_p = pEncCfg->SceneDetectFlg;
    init_rec.special_effects_p = pEncCfg->SpecialEffectFlg;
    init_rec.ImgType     = GENERAL;

	// Initialize the BW calculator
    bw_config();
    bw_init(&init_rec);

	// Alpha an Beta gain is not used for now, it's always safe
	// to initialize them to 1.
    for (i=0; i<42; i++) 
		in_rec.AlphaGain[i] = in_rec.BetaGain[i] = 1.0f;

	return OK;
}

// -------------------------------------------------------------------------
//
// 	BWCalculation
//
// -------------------------------------------------------------------------
DWORD WINAPI BWCalculation(void)
{



#ifdef BW_DEBUG
	int 	j;

	// Use Canned Statistic to debug B.W. Calculator !
	for (j=0; j<42; j++)
		in_rec.SumOfSq[j] = SumOfSq[j];
#else
	// Read ADV601 statistic exported by VxD
    bw_calculator_input(&in_rec, pEV601Info->pStatsBuf);
#endif

	// report stats ready count count to Bin Width Calculator
	in_rec.isrnum = BWCcnt;

	// report previous BPP to Bin Width Calculator
	in_rec.OldBp = 
	(float)(pEV601Info->CurFieldSz*16)/(float)(init_rec.ImageWidth*init_rec.ImageHeight);

    bw_compute (&in_rec, &out_rec);

	bwm_modify (out_rec.BWCoeff, out_rec.RBWCoeff);

	bw_calculator_output(&out_rec, pEV601Info->pBWCoeffBuf);

	return OK;
}

// -------------------------------------------------------------------------
//
// 	BWCalculationEnable
//
//  This function set the Bin Width Calculation Status flag (*pBWStatusFlg)
//  exported from "601rpman.vxd". Setting this flag will enable the run time 
//	Bin Width coefficients calculation.
//
//  Note:	This function can not be called during capture and playback.
//
// -------------------------------------------------------------------------
DLLEXPORT int	BWCalculationEnable()
{
	if (*pBWStatusFlg== ENABLE || CapPlyBkState != S_Stop)
		return 	CMAN_BW_CALC_ENB_ERR;
	else
		*pBWStatusFlg = ENABLE;
	return OK;
}


// -------------------------------------------------------------------------
//
// 	BWCalculationDisable
//
//  This function reset the Bin Width Calculation Status flag (*pBWStatusFlg)
//  exported from "601rpman.vxd". Setting this flag will disable the run time 
//	Bin Width coefficients calculation.
//
//  Note:	This function can not be called during capture and playback.
//
// -------------------------------------------------------------------------
DLLEXPORT int	BWCalculationDisable()
{

	if (*pBWStatusFlg== DISABLE || CapPlyBkState != S_Stop)
		return CMAN_BW_CALC_DIS_ERR;
	else
		*pBWStatusFlg = DISABLE;

	return OK;
}

// -------------------------------------------------------------------------
//
// QueryEV601Config
//
// -------------------------------------------------------------------------
DLLEXPORT int Query601Config(void)
{


	inBuf[0] = 0;
	if ( ! DeviceIoControl(hDevice, GET_CFG_INFO_VXDMSG,
               inBuf, sizeof(PVOID), (LPVOID)RetInfo, sizeof(RetInfo),
               &cbBytesReturned, NULL)
	   )
		return CMAN_GET_EV601_CFG_ERR;
	else
	{
		// VxD returns two addresses of the AMCC Base Register Address
		pEV601Info = (EV601 *)RetInfo[0];
		
	}

	return OK;
}

// -------------------------------------------------------------------------
//
// QueryPCIInfo
//
// -------------------------------------------------------------------------
DLLEXPORT int QueryPCIInfo(void)
{

	inBuf[0] = 0;
	if ( ! DeviceIoControl(hDevice, GET_PCI_INFO_VXDMSG,
               inBuf, sizeof(PVOID), (LPVOID)RetInfo, sizeof(RetInfo),
               &cbBytesReturned, NULL)
	   )
		return CMAN_GET_PCI_INFO_ERR;
	else
	{
		// VxD returns two addresses of the AMCC Base Register Address
		pPciInfo = (PCI_INFO*)RetInfo[0];
	}
	return OK;
}



// -------------------------------------------------------------------------
//
// 	SetVxdOption
//
//  This function will control some of the following option in 601rpman.vxd
//  	blue_screen_report : ENABLE - enable blue screen report from VxD
//							 DISABLE - disable blue screen report
//		reserve1: not use
//  	reserve2: not use
//		reserve3: not use
// -------------------------------------------------------------------------
DLLEXPORT int WINAPI SetVxdOption(	int blue_screen_report,
									int reserve1,
									int reserve2,
									int reserve3)
{

	if (blue_screen_report > ENABLE || 
		blue_screen_report < DISABLE)
			return FAILURE;

	inBuf[0] = blue_screen_report;
	RetInfo[0] = 0;
	if ( ! DeviceIoControl(hDevice, SET_VXD_OPTION_VXDMSG,
               inBuf, sizeof(PVOID), (LPVOID)RetInfo, sizeof(RetInfo),
               &cbBytesReturned, NULL)
	   )
		return CMAN_VXD_IFACE_ERR;

	return SUCCESS;
}

//----------------------------------------------------------------------------
//  FUNCTION: BashBoard()
//
//	Note:
//
//----------------------------------------------------------------------------
DLLEXPORT Error * BashBoard(	int Vformat, 
								int VideoInType, 
								int VideoOutType,
								int VCRmode,
								int Cap_PlyBk,
								byte fifo_threshold)
{
	int		VideoOutput;
 	Error	*pErr;

	pErr = PrepareErrorReport();

	// Reset the Bin Width Calculation counter.
	BWCcnt = 0;

	// Config the Input Video
	pErr->init_SAA7111_err = adc_init(Vformat,Cap_PlyBk, VideoInType, VCRmode, pAmccOpRegs);
									 
	// Config the Output Video
	VideoOutput = (VideoOutType == YC_OUT) ? VideoInType : (VideoInType| (RGB_OUT << 31));
	pErr->init_ADV7175_err = dac_init(Vformat, Cap_PlyBk, VideoOutput);

	if (*pBWStatusFlg == ENABLE)
	{
		// If Run time Bin Width Calculator is enable, we
		// need to reinitialize the ADV601 B.W. Regs and 
		// BWCoeffBuf[] buffer before Bin Width Calculation 
		// starts.
		pErr->init_ADV601_err = wavelet_init(Vformat, Cap_PlyBk, fifo_threshold, pEV601Info, med_bw);

	}
	else
		// Config ADV601 wavelet compression chip
		pErr->init_ADV601_err = wavelet_init(Vformat, Cap_PlyBk, fifo_threshold, pEV601Info, NULL);

   	return pErr;
}

//----------------------------------------------------------------------------
//  FUNCTION: PrepareErrorReport 
//
//	Note: This function will clean up a local error report structure and 
//		  return a pointer to this structure to the caller.
//
//----------------------------------------------------------------------------
Error *		PrepareErrorReport(void)
{


	memset(&ErrorReport, 0, sizeof(ErrorReport));
	return &ErrorReport;
}



//----------------------------------------------------------------------------
//  FUNCTION: DLLMain(HINSTANCE, DWORD, LPVOID)
//----------------------------------------------------------------------------
BOOL WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            // The DLL is being loaded for the first time by a given process.
            // Perform per-process initialization here.  If the initialization
            // is successful, return TRUE; if unsuccessful, return FALSE.

            // In this DLL, we want to initialize a critical section used
            // by one of its exported functions, DLLFunction2().
            // InitializeCriticalSection(&gCriticalSection);

			// Now load our VxD
			LoadVxDFlg = Load601VxD(NULL);
			// Need to increment the reference count here !
			LoadDllCnt++;

			// Get the current Video Lab directory
			GetCurrentDirectory(sizeof(VLabDir), VLabDir);
				
            hstart = 0;                 /* initialize ADV601 */
            hend = 0x3FF;               /* cropping registers to "no crop" */
            vstart = 0;                 /* aka "encode the whole field". */
            vend = 0x3FF;
            
            break;

        case DLL_PROCESS_DETACH:
            // The DLL is being unloaded by a given process.  Do any
            // per-process clean up here, such as undoing what was done in
            // DLL_PROCESS_ATTACH.  The return value is ignored.
			CloseHandle(hDevice);

            // In this DLL, we need to clean up the critical section we
            // created in the DLL_PROCESS_ATTACH message.
            // DeleteCriticalSection(&gCriticalSection);

            break;

        case DLL_THREAD_ATTACH:
            // A thread is being created in a process that has already loaded
            // this DLL.  Perform any per-thread initialization here.  The
            // return value is ignored.

            break;

        case DLL_THREAD_DETACH:
            // A thread is exiting cleanly in a process that has already
            // loaded this DLL.  Perform any per-thread clean up here.  The
            // return value is ignored.

            break;
    }


    return TRUE;
}

⌨️ 快捷键说明

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