正文

家庭視頻監(jiān)控系統(tǒng)(8)

C#項(xiàng)目開(kāi)發(fā)案例全程實(shí)錄(第2版) 作者:明日科技


1.4.4 VideoOperate類

VideoOperate類主要封裝了操作視頻采集卡的各種枚舉及方法,由于要調(diào)用Sa7134Capture.dll動(dòng)態(tài)鏈接庫(kù),所以首先要引用命名空間using System.Runtime.InteropServices。封裝Sa7134Capture.dll動(dòng)態(tài)鏈接庫(kù)中各種枚舉及方法的關(guān)鍵代碼如下:

例程09 代碼位置:光盤(pán)\TM\01\VWMS\VWMS\CommonClass\VideoOperate.cs

#region 視頻采集卡中的枚舉

public enum DISPLAYTRANSTYPE

{

NOT_DISPLAY = 0,

PCI_VIEDOMEMORY = 1,

PCI_MEMORY_VIDEOMEMORY = 2

}

//視頻預(yù)覽和視頻捕捉數(shù)據(jù)流格式,目前版本只支持UUY2格式

public enum COLORFORMAT

{

RGB32 = 0x0,

RGB24 = 0x1,

RGB16 = 0x2,

RGB15 = 0x3,

YUY2 = 0x4,

TYUV = 0x5,

8 = 0x6,

GB8 = 0x7,

L422 = 0x8,

L411 = 0x9,

UV12 = 0xA,

UV9 = 0xB,

AW = 0xE

}

/*視頻預(yù)覽及視頻捕獲的顯示屬性,其中:

BRIGHTNESS為亮度,value范圍:0~255,最佳:80

CONTRAST為對(duì)比度,value范圍:-128~127,最佳:x44

SATURATION為飽和度,value范圍:-128~127,最佳:x40

HUE為色度,value范圍:-128~127,最佳:x0

只有當(dāng)COLORDEVICETYPE等于COLOR_DECODER時(shí)才有效

SHARPNESS為銳度,value范圍:-8~7,最佳:x0

只有當(dāng)COLORDEVICETYPE等于COLOR_DECODER時(shí)才有效

*/

public enum COLORCONTROL

{

BRIGHTNESS = 0,

CONTRAST = 1,

SATURATION = 2,

HUE = 3,

SHARPNESS = 4

}

/*顯示設(shè)備的顯示屬性,其中:

COLOR_DECODER為解碼器的顯示屬性,它會(huì)影響視頻預(yù)覽和視頻捕獲的顯示屬性

COLOR_PREVIEW為視頻預(yù)覽的顯示屬性

COLOR_CAPTURE為視頻捕獲的顯示屬性

*/

pblic enum COLORDEVICETYPE

{

COLOR_DECODER = 0,

COLOR_PREVIEW = 1,

COLOR_CAPTURE = 2,

}

/*視頻捕獲方式,其中:

CAP_NULL_STREAM 捕獲無(wú)效

CAP_ORIGIN_STREAM 捕獲為原始流回調(diào)

CAP_MPEG4_STREAM 捕獲為MPEG4

*/

public enum CAPMODEL

{

CAP_NULL_STREAM = 0,

CAP_ORIGIN_STREAM = 1,

CAP_MPEG4_STREAM = 2,

}

/*音視頻MPEG4捕獲方式,只有CAPMODEL等于CAP_MPEG4_STREAM時(shí)有效,其中:

MPEG4_AVIFILE_ONLY 存為MPEG4文件

MPEG4_CALLBACK_ONLY MPEG數(shù)據(jù)回調(diào)

MPEG4_AVIFILE_CALLBACK 存為MPEG文件并回調(diào)

*/

public enum MP4MODEL

{

MPEG4_AVIFILE_ONLY = 0,

MPEG4_CALLBACK_ONLY = 1,

MPEG4_AVIFILE_CALLBACK = 2,

}

/*MPEG4_XVID壓縮模式,其中:

XVID_CBR_MODE (固定碼率模式)

XVID_VBR_MODE (動(dòng)態(tài)碼率模式)

*/

public enum COMPRESSMODE

{

XVID_CBR_MODE = 0,

XVID_VBR_MODE = 1,

}

/*視頻源的輸入頻率,其中:

FIELD_FREQ_50HZ 50HZ,絕對(duì)多數(shù)為PAL制式

FIELD_FREQ_60HZ 60HZ,絕對(duì)多數(shù)為NTSC制式

FIELD_FREQ_0HZ,無(wú)信號(hào)

*/

public enum eFieldFrequency

{

FIELD_FREQ_50HZ = 0,

FIELD_FREQ_60HZ = 1,

FIELD_FREQ_0HZ = 2,

}

/*電平狀態(tài),其中:

HIGH_VOLTAGE為高電平

LOW_VOLTAGE為低電平

*/

public enum eVOLTAGELEVEL

{

HIGH_VOLTAGE = 0,

LOW_VOLTAGE = 1,

}

#endregion

#region 視頻采集卡中的API函數(shù)

//初始化系統(tǒng)資源

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAInitSdk")]

public extern static bool VCAInitSdk(IntPtr hWndMain, DISPLAYTRANSTYPE eDispTransType, bool bLnitAuDev);

//釋放系統(tǒng)資源

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAUnInitSdk")]

public extern static void VCAUnInitSdk();

//打開(kāi)指定卡號(hào)的設(shè)備,分配相應(yīng)系統(tǒng)資源

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAOpenDevice")]

public extern static bool VCAOpenDevice(Int32 dwCard, IntPtr hPreviewWnd);

//關(guān)閉指定卡號(hào)的設(shè)備,釋放相應(yīng)系統(tǒng)資源

[DllImport("Sa7134Capture.dll", EntryPoint = "VCACloseDevice")]

public extern static bool VCACloseDevice(Int32 dwCard);

//返回系統(tǒng)當(dāng)中卡號(hào)數(shù)量,即為SAA7134硬件數(shù)目,為0時(shí)表示沒(méi)有設(shè)備存在

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAGetDevNum")]

public extern static int VCAGetDevNum();

//開(kāi)始視頻預(yù)覽

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAStartVideoPreview")]

public extern static bool VCAStartVideoPreview(Int32 dwCard);

//停止視頻預(yù)覽

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAStopVideoPreview")]

public extern static bool VCAStopVideoPreview(Int32 dwCard);

//更新視頻預(yù)覽

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAUpdateVideoPreview")]

public extern static bool VCAUpdateVideoPreview(Int32 dwCard, IntPtr hPreviewWnd);

//更新overlay窗口,當(dāng)overlay窗口句柄改變或尺寸、位置改變時(shí)調(diào)用,overlay窗口就是包含

//多路顯示小窗口的大窗口,overlay窗口必須有一個(gè),多路顯示小窗口必須包含在其內(nèi)部

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAUpdateOverlayWnd")]

public extern static bool VCAUpdateOverlayWnd(IntPtr hOverlayWnd);

//保存快照為JPEG文件

[DllImport("Sa7134Capture.dll", EntryPoint = "VCASaveAsJpegFile")]

public extern static bool VCASaveAsJpegFile(Int32 dwCard, string lpFileName, Int32 dwQuality);

//保存快照為BMP文件

[DllImport("Sa7134Capture.dll", EntryPoint = "VCASaveAsBmpFile")]

public extern static bool VCASaveAsBmpFile(Int32 dwCard, string lpFileName);

//開(kāi)始視頻捕獲

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAStartVideoCapture")]

public extern static bool VCAStartVideoCapture(Int32 dwCard, CAPMODEL enCapMode, MP4MODEL enMp4Mode, string lpFileName);

//停止視頻捕獲

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAStopVideoCapture")]

public extern static bool VCAStopVideoCapture(Int32 dwCard);

//設(shè)置視頻捕獲尺寸,dwWidth和dwHeight最好為16的倍數(shù),否則,動(dòng)態(tài)檢測(cè)為16×16的一個(gè)檢測(cè)小塊,檢測(cè)將會(huì)不準(zhǔn)確

[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetVidCapSize")]

public extern static bool VCASetVidCapSize(Int32 dwCard, Int32 dwWidth, Int32 dwHeight);

//得到視頻捕獲尺寸

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAGetVidCapSize")]

public extern static bool VCAGetVidCapSize(Int32 dwCard, Int32 dwWidth, Int32 dwHeight);

//設(shè)置視頻捕獲頻率

[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetVidCapFrameRate")]

public extern static bool VCASetVidCapFrameRate(Int32 dwCard, Int32 dwFrameRate, bool bFrameRateReduction);

//設(shè)置MPEG壓縮的位率

[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetBitRate")]

public extern static bool VCASetBitRate(Int32 dwCard, Int32 dwBitRate);

//設(shè)置MPEG壓縮的關(guān)鍵幀間隔,必須大于等于幀率

[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetKeyFrmInterval")]

public extern static bool VCASetKeyFrmInterval(Int32 dwCard, Int32 dwKeyFrmInterval);

//設(shè)置MPEG4_XVID壓縮的質(zhì)量

[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetXVIDQuality")]

public extern static bool VCASetXVIDQuality(Int32 dwCard, Int32 dwQuantizer, Int32 dwMotionPrecision);

//設(shè)置MPEG4_XVID壓縮的模式

[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetXVIDCompressMode")]

public extern static bool VCASetXVIDCompressMode(Int32 dwCard, COMPRESSMODE enCompessMode);

//設(shè)置視頻顏色屬性,它將影響視頻預(yù)覽和視頻捕獲的顯示屬性

[DllImport("Sa7134Capture.dll", EntryPoint = "VCASetVidDeviceColor")]

public extern static bool VCASetVidDeviceColor(Int32 dwCard, COLORCONTROL enCtlType, Int32 dwValue);

//得到視頻源輸入頻率,即可得到視頻源輸入制式

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAGetVidFieldFrq")]

public extern static bool VCAGetVidFieldFrq(Int32 dwCard, eFieldFrequency eVidSourceFieldRate);

//初始化視頻設(shè)備,當(dāng)視頻不顯示,只需視頻錄像獲得音頻處理時(shí),或通過(guò)VCAInitSdk()函數(shù)已經(jīng)初始化完成,

//可以不初始化

[DllImport("Sa7134Capture.dll", EntryPoint = "VCAInitVidDev")]

public extern static bool VCAInitVidDev();

#endregion


上一章目錄下一章

Copyright ? 讀書(shū)網(wǎng) m.ranfinancial.com 2005-2020, All Rights Reserved.
鄂ICP備15019699號(hào) 鄂公網(wǎng)安備 42010302001612號(hào)