C#編寫的IP攝像頭源碼

在研發(fā)期間,把做工程過程中比較常用的一些內(nèi)容片段做個(gè)收藏,如下的內(nèi)容內(nèi)容是關(guān)于C#編寫的IP攝像頭的內(nèi)容,希望能對(duì)碼農(nóng)有些用。

#region IP攝像頭代碼

? ? private IntPtr m_hChannel;

? ? private IntPtr m_hServer, phPlay;

? ? public delegate void MyInvoke(string str);


? ? public void BeforeRecordFrame(IntPtr hChannel, ref RECORD_INFO pRecordInfo, ref FRAME_HEADER pFrameHeader, IntPtr pcontext)

? ? {

? ? }

? ? public void FileSearchCallback(IntPtr hSearch, ref DVSNET_FILE_TIME pFileTime, ref DVSNET_FILE_INFO pFileInfo, IntPtr pcontext)

? ? {

? ? ? ? OutText(hSearch, pFileTime, pFileInfo, pcontext);? ? ? ? ? ?

? ? }

? ? public void OutText(IntPtr hSearch, DVSNET_FILE_TIME pFileTime, DVSNET_FILE_INFO pFileInfo, IntPtr pcontext)

? ? {

? ? ? ? if (lvVideo.InvokeRequired)

? ? ? ? {

? ? ? ? ? ? OutDelegate outdelegate = new OutDelegate(OutText);

? ? ? ? ? ? this.BeginInvoke(outdelegate, new object[] { hSearch, pFileTime, pFileInfo, pcontext });

? ? ? ? ? ? return;

? ? ? ? }

? ? ? ? lvVideo.View = View.Details;

? ? ? ? lvVideo.FullRowSelect = true;

? ? ? ? for (int i = 0; i < pFileInfo.sFileName.Count(); i++)

? ? ? ? {

? ? ? ? ? ? ListViewItem item1 = new ListViewItem(pFileInfo.sFileName, i);

? ? ? ? ? ? lvVideo.Items.AddRange(new ListViewItem[] { item1 });

? ? ? ? }

? ? }

? ? private void pb_del_video_Click(object sender, EventArgs e)

? ? {

? ? ? ? this.Close();

? ? }

? ? public void SearchNotify(int nDevType, string sServName, string sServSerial, string sUrl, IntPtr MacAddr, ushort wWebPort, ushort wDataPort, string sSubNetMask, string sGateWay, string sMultiIp, string sDNS, ushort wMultiPort, int nChCount, uint bDHCP, IntPtr pcontext)

? ? {

? ? ? ? string str = Convert.ToString(wDataPort);

? ? ? ? string str2 = sUrl;

? ? ? ? this.AddText(str2);

? ? }

? ? private void AddText(string str)

? ? {

? ? ? ? MyInvoke method = new MyInvoke(this.AddTextToCmb);

? ? ? ? base.BeginInvoke(method, new object[] { str });

? ? }

? ? public void AddTextToCmb(string str)

? ? {

? ? ? ? this.CmbIP.Items.Add(str);

? ? }

? ? private void btnVideoSearck_Click(object sender, EventArgs e)

? ? {



? ? ? ? ? ? this.CmbIP.Items.Clear();

? ? ? ? ? ? errornum errornum = DVSNETClient.DVSNET_SearchServers(0xbb8, 1, new DVSNETClient.SearchNotify(this.SearchNotify), base.Handle, IntPtr.Zero);

? ? ? ? ? ? if (errornum == errornum.DVSNET_ERR_OK)

? ? ? ? ? ? {

? ? ? ? ? ? ? timerVideo.Enabled = true;

? ? ? ? ? ? ? btnVideoSearck.Enabled = false;

? ? ? ? ? ? }

? ? ? ? ? ? else

? ? ? ? ? ? {

? ? ? ? ? ? }

? ? }

? ? private void btnVideoOpen_Click(object sender, EventArgs e)

? ? {

? ? ? ? string text = this.CmbIP.Text;

? ? ? ? string sServIp = text;

? ? ? ? int index = text.IndexOf('(');

? ? ? ? if (index != -1)

? ? ? ? {

? ? ? ? ? ? string str3 = new string(text.ToCharArray(), 0, index);

? ? ? ? ? ? sServIp = str3;

? ? ? ? }

? ? ? ? errornum errornum = DVSNETClient.DVSNET_OpenServer(this.EdtName.Text, sServIp, Convert.ToUInt16(this.EdtPort.Text), this.EdtUser.Text, this.EdtPassword.Text, ref this.m_hServer, 0, 0);

? ? ? ? if (errornum == errornum.DVSNET_ERR_OK)

? ? ? ? {

? ? ? ? ? ? DVSNET_SERVER_INFO dvsnet_server_info = new DVSNET_SERVER_INFO();

? ? ? ? ? ? MessageBox.Show("打開鏈接成功!");

? ? ? ? ? ? dvsnet_server_info = new DVSNET_SERVER_INFO

? ? ? ? ? ? {

? ? ? ? ? ? ? ? lStructSize = Marshal.SizeOf(dvsnet_server_info)

? ? ? ? ? ? };

? ? ? ? ? ? DVSNETClient.DVSNET_GetServerInfo(this.m_hServer, ref dvsnet_server_info);

? ? ? ? ? ? for (int i = 0; i < dvsnet_server_info.nChnNum; i++)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? int num3 = i + 1;

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? MessageBox.Show("打開鏈接失敗,錯(cuò)誤碼為:" + errornum.ToString());

? ? ? ? }

? ? }

? ? private void btnVideoClose_Click(object sender, EventArgs e)

? ? {

? ? ? ? if (this.m_hChannel != IntPtr.Zero)

? ? ? ? {

? ? ? ? ? ? MessageBox.Show("請(qǐng)關(guān)閉通道!再關(guān)閉鏈接");

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? if (this.m_hServer != IntPtr.Zero)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? DVSNETClient.DVSNET_CloseServer(this.m_hServer);

? ? ? ? ? ? ? ? this.m_hServer = IntPtr.Zero;

? ? ? ? ? ? }

? ? ? ? }

? ? }

? ? IntPtr selServer = IntPtr.Zero;

? ? private void btnVideoOpenChnnel_Click(object sender, EventArgs e)

? ? {

? ? ? ? this.panelVideo.Visible = true;

? ? ? ? this.pannelVideoTwo.Visible = false;

? ? ? ? if (this.m_hServer != IntPtr.Zero)

? ? ? ? {

? ? ? ? ? ? DVSNET_CHANNEL_INFO dvsnet_channel_info = new DVSNET_CHANNEL_INFO();

? ? ? ? ? ? MessageBox.Show("打開通道成功!請(qǐng)稍候");

? ? ? ? ? ? dvsnet_channel_info = new DVSNET_CHANNEL_INFO

? ? ? ? ? ? {

? ? ? ? ? ? ? ? lStructSize = Marshal.SizeOf(dvsnet_channel_info),

? ? ? ? ? ? ? ? nProtocol = 0,

? ? ? ? ? ? ? ? hWndDisplay = this.panelVideo.Handle,

? ? ? ? ? ? ? ? bPlayStart = 1,

? ? ? ? ? ? ? ? dwStreamNo = 0

? ? ? ? ? ? };

? ? ? ? ? ? DVSNETClient.DVSNET_OpenChannel(this.m_hServer, Convert.ToUInt16(0), ref dvsnet_channel_info, ref this.m_hChannel);

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? MessageBox.Show("請(qǐng)打開鏈接!");

? ? ? ? }

? ? }

? ? private void btnVideoCloseChnnel_Click(object sender, EventArgs e)

? ? {

? ? ? ? if (this.m_hChannel != IntPtr.Zero)

? ? ? ? {


? ? ? ? ? ? DVSNETClient.DVSNET_CloseChannel(this.m_hChannel);

? ? ? ? ? ? MessageBox.Show("關(guān)閉通道成功!請(qǐng)稍候");

? ? ? ? ? ? this.m_hChannel = IntPtr.Zero;

? ? ? ? }

? ? }

? ? private void btnVideoOn_Click(object sender, EventArgs e)

? ? {

? ? ? ? try

? ? ? ? {

? ? ? ? ? ? string ss = DateTime.Now.ToString().Replace(":", "-").Replace(" ", "-").Replace("/", "-") + ".asf";? ? ?

? ? ? ? ? ? if (this.panelVideo.Visible == false)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? MessageBox.Show("請(qǐng)切換到打開通道");

? ? ? ? ? ? }

? ? ? ? ? ? else

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if (this.m_hChannel != IntPtr.Zero)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? DVSNETClient.DVSNET_StartRecord(this.m_hChannel, 1, FILETYPE.FILETYPE_ASF, ss,Before_RecordFrame, base.Handle);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? else

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? MessageBox.Show("請(qǐng)打開通道!");

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? catch (Exception ex)

? ? ? ? {

? ? ? ? ? ? MessageBox.Show(ex.ToString());

? ? ? ? }? ? ?

? ? }

? ? private void btnStopRec_Click(object sender, EventArgs e)

? ? {

? ? ? ? DVSNETClient.DVSNET_StopRecord(this.m_hChannel);

? ? ? ? MessageBox.Show("已停止錄像!");

? ? }

? ? IntPtr phPlayer;

? ? private void btnsearch_Click(object sender, EventArgs e)

? ? {

? ? ? ? try

? ? ? ? {

? ? ? ? ? ? if (m_hServer != IntPtr.Zero)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? string fName = "";

? ? ? ? ? ? ? ? OpenFileDialog openFileDialog = new OpenFileDialog();

? ? ? ? ? ? ? ? openFileDialog.RestoreDirectory = true;

? ? ? ? ? ? ? ? openFileDialog.FilterIndex = 1;

? ? ? ? ? ? ? ? if (openFileDialog.ShowDialog() == DialogResult.OK)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? this.panelVideo.Visible = false;

? ? ? ? ? ? ? ? ? ? this.pannelVideoTwo.Visible = true;

? ? ? ? ? ? ? ? ? ? this.btnsearch.Enabled = false;

? ? ? ? ? ? ? ? ? ? fName = openFileDialog.FileName;

? ? ? ? ? ? ? ? ? ? IntPtr hDisplayWnd = pannelVideoTwo.Handle;

? ? ? ? ? ? ? ? ? ? phPlayer = (IntPtr)0;

? ? ? ? ? ? ? ? ? ? errornum aa = DVSNETClient.DVSPLAYER_CreateInstance(hDisplayWnd, ref phPlayer, 0);? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? aa = DVSNETClient.DVSPLAYER_OpenFile(phPlayer,ref fName, 1);

? ? ? ? ? ? ? ? ? ? DVSNETClient.DVSPLAYER_Start(phPlayer);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? else

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? this.panelVideo.Visible = true;

? ? ? ? ? ? ? ? ? ? this.pannelVideoTwo.Visible = false;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? else

? ? ? ? ? ? {

? ? ? ? ? ? ? ? MessageBox.Show("請(qǐng)打開通道!");

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? catch (Exception)

? ? ? ? {


? ? ? ? ? ? throw;

? ? ? ? }? ? ? ? ? ?

? ? }

? ? private void btnhf_Click(object sender, EventArgs e)

? ? {

? ? ? ? this.panelVideo.Visible = true;

? ? ? ? this.pannelVideoTwo.Visible = false;

? ? ? ? IntPtr phPlayer = (IntPtr)0;

? ? ? ? DVSNETClient.DVSPLAYER_Stop(phPlayer);

? ? ? ? MessageBox.Show("已停止回放錄像!");

? ? ? ? this.btnsearch.Enabled = true; ;? ? ?

? ? }

? ? private void btnSearchbyName_Click(object sender, EventArgs e)

? ? {

? ? ? ? if (m_hServer == IntPtr.Zero)

? ? ? ? {

? ? ? ? ? ? MessageBox.Show("請(qǐng)先打開鏈接登錄服務(wù)器!");

? ? ? ? ? ? return;

? ? ? ? }

? ? ? ? this.btnSearchbyName.Enabled = false;

? ? ? ? DVSNET_FILE_TIME pStartTime = new DVSNET_FILE_TIME();

? ? ? ? pStartTime.lYear = (uint)this.dateTimePicker1.Value.Year;

? ? ? ? pStartTime.lMonth = (uint)this.dateTimePicker1.Value.Month;

? ? ? ? pStartTime.lDay = (uint)this.dateTimePicker1.Value.Day;

? ? ? ? pStartTime.nHour = 0;

? ? ? ? pStartTime.nMinute = 0;

? ? ? ? DVSNET_FILE_TIME pEndTime = new DVSNET_FILE_TIME();

? ? ? ? pEndTime.lYear = (uint)this.dateTimePicker1.Value.Year;

? ? ? ? pEndTime.lMonth = (uint)this.dateTimePicker1.Value.Month;

? ? ? ? pEndTime.lDay = (uint)this.dateTimePicker1.Value.Day;

? ? ? ? pEndTime.nHour = 23;

? ? ? ? pEndTime.nMinute = 59;

? ? ? ? IntPtr phSearch = IntPtr.Zero;

? ? ? ? errornum bak = DVSNETClient.DVSNET_ServerFindFile(m_hServer, 0, 0, (char)0xff, ref pStartTime, ref pEndTime, File_SearchCallback, (IntPtr)0, ref phSearch);

? ? ? ? if (bak != errornum.DVSNET_ERR_OK)

? ? ? ? {

? ? ? ? ? ? MessageBox.Show("查找遠(yuǎn)程視頻失敗!");

? ? ? ? }? ? ? ? ?

? ? ? ? this.btnSearchbyName.Enabled = true;

? ? }

? ? private void lvVideo_MouseDoubleClick(object sender, MouseEventArgs e)

? ? {

? ? ? ? this.panelVideo.Visible = false;

? ? ? ? this.pannelVideoTwo.Visible = true;? ? ? ? ?

? ? ? ? string sa = "";

? ? ? ? IntPtr hWnd = pannelVideoTwo.Handle;

? ? ? ? if (lvVideo.SelectedItems.Count > 0)

? ? ? ? ? ? sa = lvVideo.SelectedItems[0].Text.ToString();

? ? ? ? }



? ? ? ? phPlay = IntPtr.Zero;

? ? ? ? errornum bak = DVSNETClient.DVSNET_PlayFileByName(m_hServer, sa, 1, hWnd, ref phPlay);

? ? ? ? if (bak == errornum.DVSNET_ERR_OK)

? ? ? ? {

? ? ? ? ? ? UInt32 value = 0;

? ? ? ? ? ? DVSNETClient.DVSNET_ControlPlayFile(phPlay, 1, 0, ref value);

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? MessageBox.Show("回放遠(yuǎn)程文件 失敗,錯(cuò)誤碼為" + bak.ToString());

? ? ? ? }

? ? }

? ? #endregion

? ? private void timerVideo_Tick(object sender, EventArgs e)

? ? {

? ? ? ? int nStatus = 0;

? ? ? ? errornum errnum = DVSNETClient.DVSNET_GetSearchStatus(ref nStatus);

? ? ? ? if (errnum == errornum.DVSNET_ERR_OK)

? ? ? ? {

? ? ? ? ? ? if (nStatus == 1)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? btnVideoSearck.Enabled = true;

? ? ? ? ? ? ? ? timerVideo.Enabled = false;

? ? ? ? ? ? ? ? MessageBox.Show("沒有啟動(dòng)搜索");

? ? ? ? ? ? }

? ? ? ? ? ? if (nStatus == 2)

? ? ? ? ? ? {

? ? ? ? ? ? }

? ? ? ? ? ? if (nStatus == 3)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? timerVideo.Enabled = false;

? ? ? ? ? ? ? ? btnVideoSearck.Enabled = true;

? ? ? ? ? ? ? ? if (this.CmbIP.Items.Count == 0)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? MessageBox.Show("沒有找到設(shè)備!請(qǐng)接上設(shè)備");

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? else

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? MessageBox.Show("已找到設(shè)備,請(qǐng)選擇IP地址");

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? MessageBox.Show("DVSNET_GetSearchStatus 失敗,錯(cuò)誤碼為" + errnum.ToString());

? ? ? ? }

? ? }

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 右擊工具箱->選擇項(xiàng) -> 顯示"選擇工具箱項(xiàng)" -> COM組件 -> Windows Media Player...
    顏淵若水閱讀 6,987評(píng)論 0 0
  • 昨晚月兒和涵涵為了一條裙子爭執(zhí)不休,而我的角色就是充當(dāng)裁判和滅火器。 其實(shí)我很不喜歡給她們當(dāng)裁判,因?yàn)榻Y(jié)果我可以預(yù)...
    月知寒秋閱讀 549評(píng)論 0 1
  • 背負(fù)掙扎中浮沉 時(shí)移勢易謂生活 生活虐我千萬遍 我待生活如初戀 柴米油鹽琴書畫 多少...
    雨中聽荷萍閱讀 325評(píng)論 0 1
  • 天很藍(lán),片片白云漂浮在天空,河畔低垂的枝葉隨風(fēng)搖擺,平靜的河面不時(shí)泛起漣漪!微微的風(fēng),和煦的暖,我透過陽光的間隙...
    姑蘇雪舞閱讀 1,487評(píng)論 6 2
  • 大多數(shù)的人肯定有過這樣的經(jīng)歷:你養(yǎng)成了每天七點(diǎn)按時(shí)醒來的習(xí)慣,可是如果第二天有事,你想五點(diǎn)起床,于是第二天即使沒有...
    指尖傳奇閱讀 398評(píng)論 0 0

友情鏈接更多精彩內(nèi)容