Camera - Add Method Start, Stop, Destructor.
This commit is contained in:
parent
f9fcca2902
commit
4648ac01fe
|
@ -7,9 +7,8 @@ namespace AIParkingApplication
|
|||
public class Camera
|
||||
{
|
||||
private string streamUrl;
|
||||
private bool isCapturing;
|
||||
private object lockSyncObject;
|
||||
private volatile bool isFrameRequested;
|
||||
private Thread readStreamThread;
|
||||
|
||||
public event CameraEvent OnVideoFrameReceived;
|
||||
public event CameraEvent OnOneVideoFrameRequested;
|
||||
|
@ -17,16 +16,24 @@ namespace AIParkingApplication
|
|||
public Camera(string streamUrl)
|
||||
{
|
||||
this.streamUrl = streamUrl;
|
||||
isCapturing = true;
|
||||
isFrameRequested = false;
|
||||
lockSyncObject = new object();
|
||||
readStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
||||
readStreamThread.IsBackground = true;
|
||||
}
|
||||
|
||||
public void Startcapture()
|
||||
~Camera()
|
||||
{
|
||||
Thread readVideoStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
||||
readVideoStreamThread.IsBackground = true;
|
||||
readVideoStreamThread.Start();
|
||||
Stop();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (!readStreamThread.IsAlive)
|
||||
{
|
||||
readStreamThread = new Thread(new ThreadStart(ReadVideoStream));
|
||||
readStreamThread.IsBackground = true;
|
||||
readStreamThread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public void RequestCaptureOneFrame()
|
||||
|
@ -47,10 +54,6 @@ namespace AIParkingApplication
|
|||
{
|
||||
Thread.Sleep(50); //Stream Thread Sleep
|
||||
//Thread.Sleep(40); //Video Thread Sleep
|
||||
if (!isCapturing)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (videoCapture.Read(videoFrame) && videoFrame.Width > 0 && videoFrame.Height > 0)
|
||||
{
|
||||
|
@ -64,11 +67,11 @@ namespace AIParkingApplication
|
|||
}
|
||||
}
|
||||
|
||||
public void PauseCapture()
|
||||
public void Stop()
|
||||
{
|
||||
lock (lockSyncObject)
|
||||
if (readStreamThread.IsAlive)
|
||||
{
|
||||
isCapturing = false;
|
||||
readStreamThread.Abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user