2012-03-11 168 views

回答

1

它將是一個多線程應用程序。其中每個線程(工作人員)從源(USB視頻)記錄到目標(文件流)。

你可以做這樣的事情(僞C#) 我希望它給你一個基本的想法...

class Worker 
{ 
    bool _record; 
    ISource _source; 
    IDestination _dest; 

    public Worker(ISource source, IDestination dest) 
    { 
     _source = source; 
     _dest = dest; 
    } 

    public void Record() 
    { 
     lock(this) 
      _record = true; 
     pos = 0; 
     while(_record) 
     { 
      var buffer = new byte[4096]; 
      len = _source.Read(pos, buffer); 
      pos += len; 
      dest.Write(buffer, len); 
     } 
    } 

    public void Stop() 
    { 
     lock (this) 
      _record = false; 
    } 
} 

class Program 
{ 
    public static Main() 
    { 
     var w1 = new Worker(new UsbVideo(), new FileDestination()); 
     Thread.Start(w1.Record); 

     ... 

     Console.Readline(); 
     w1.Stop(); 
    } 
}