【正文】
圖 22 所示 圖 22 啟動 Webcamservice 3 項目的設(shè)計原理 3 DirectShow 技術(shù) 采用網(wǎng)絡(luò)攝像機的遠程視頻監(jiān)控具有錄像時間長、圖像質(zhì)量好、查詢速度快等優(yōu)點,目前應(yīng)用非常廣泛。 DirectShow 是一個開放的框架,因此只要有合適的 Filter 來分析和解碼,可以支持任何格式。 ? 應(yīng)用層協(xié)議 相反地,應(yīng)用層協(xié)議用戶是可以看得到的。也可以這樣說, IP 地址形成了許多服務(wù)的認(rèn)證基礎(chǔ),這些服務(wù)相信數(shù)據(jù)包是從一個有效的主機發(fā)送來的。 圖 31 c/s 結(jié)構(gòu) 4 程序流程圖及設(shè)計 程序時序圖與系統(tǒng)架構(gòu) 本系統(tǒng)采用面向連接的客戶 /服務(wù)模型,服務(wù)器必須首先啟動,否則客戶進程的 Connect()系統(tǒng)調(diào)用將返回錯誤代碼表示連接失敗。 監(jiān)聽連接,服務(wù)器端 socket 并不定位具體的客戶端 socket,而是處于等待連接的狀態(tài)。 private volatile bool m_bShuttingDown。 // Verify we got an IP address. if( aryLocalAddr == null || 1 ) { throw new Exception( Unable to get local address )。 // Only want one thread to be preforming shutdown at a time. lock (this) { // Have we already shutdown? if (!m_bShuttingDown) { m_bShuttingDown = true。 m_sockListener = null。 } public int Connections { get { return 。 // Create the listener socket in this machine39。 } } } } private void _SendOne(SockWrapper s, byte [] b, int iLength) { try { bool bSend = true。 // Set up an async wait for packets from the client AsyncCallback receiveData = new AsyncCallback( OnReceivedData )。 if( nBytesRec 0 ) { if (DataReceived != null) DataReceived(this, ref , ref , nBytesRec)。 } catch {} // Fire the Disconnected event if (Disconnected != null) Disconnected(this, ref )。 14 public delegate void TcpSend(Object sender, ref object o, ref bool b)。 } endregion [STAThread] public static void Main(string[] args) { = Main thread。 private volatile bool bShutDown。 // zero based index of video capture device to use const int FRAMERATE = 15。 EncoderParameters myEncoderParameters。 += new TcpReceive(Receive)。 } cam = new Capture(VIDEODEVICE, FRAMERATE, VIDEOWIDTH, VIDEOHEIGHT)。 IntPtr ip = 。 // save it to jpeg using quality options //保存為 JPEG(默認(rèn)的格式選項) = 10。 } catch(Exception ex) { try { (())。 private int m_MaxPackets。 } public void RemovePacket() { lock (this) { if (m_PacketCount 0) { m_PacketCount。 if (iConnectionCount == 0) { ()。 j 。 private label1。 public Form1() { // // Required for Windows Form Designer support // InitializeComponent()。 = new ()。 (()()).BeginInit()。 = false。 = Start。 // // label1 // = (()(( | )))。 = new (10, 374)。 = true。 = new (19, 236)。 // // txtServer 25 // = (()(( | )))。 = 。 // // pictureBox1 // = (()(((( | ) | ) | )))。 = new ()。 } } if (doImages != null) { = true。 23 private txtPort。 } return null。 ()。 } } } public int Count() { return m_PacketCount。 20 m_PacketCount = 0。 } catch {} } finally { if (ip != ) { (ip)。 // Send the length as a fixed length string //作為固定的字符串長度發(fā)送長度 = 0。 ()。 } catch(Exception ex) { try { (({0}: Failed on startup {1}, (), ex))。 myEncoderParameters = null。 try { // Set up member vars ConnectionReady = new ManualResetEvent(false)。 // Depends on video device caps const int VIDEOHEIGHT = 480。 endregion /// summary /// Set things in motion so your service can do its work. /// 為了服務(wù)器可以工作而設(shè)置的選項 /// /summary protected override void OnStart(string[] args) { ThreadStart starter = new ThreadStart(Run)。 15 if ( ) { ()。 } WebCamService 類 : namespace WebCamService { public class WebCamService : ServiceBase { region Required Service R