Skip to content

Synchronous vs asynchronous connection

TVideoGrabber can connect to the IP cameras and URLs:

  • synchronously if OpenURLAsync is disabled In this case when invoking StartPreview() or StartRecording(), the function blocks until the connection succeeds or fails.

  • synchronously if OpenURLAsync is enabled (default) In this case, when invoking StartPreview() or StartRecording(), the function returns immediately so the main thread is not blocked and the application continues to respond to key and mouse events.

Once the connection is completed, the OnPreviewStarted() or OnRecordingStarted() event occurs to notify the application that the component is running.

If the connection fails, the OnLog event occurs with a "e_failed_to_start_preview" or "e_failed_to_start_recording" LogType error.

Example of generic StartPreview() / StartRecording() set of functions that handles the asynchronous connection result through the OnPreviewStarted() / OnRecordingStarted() and OnLog() events: function StartPreview() { VideoGrabber.OpenURLAsyncVidGrab.TVideoGrabber.OpenURLAsync = true // default VideoGrabber.VideoSource = vs_IPCamera VideoGrabber.IPCameraURL = "rtsp://192.168.0.25/axis-media/media.amp?videocodec=h264" VideoGrabber.SetAuthentication (at_IPCamera, "root", "admin"); VideoGrabber.StartPreview ()} function StartRecord() { VideoGrabber.OpenURLAsyncVidGrab.TVideoGrabber.OpenURLAsync = true // default VideoGrabber.VideoSource = vs_IPCamera VideoGrabber.IPCameraURL = "rtsp://192.168.0.25/axis-media/media.amp?videocodec=h264&audio=1" VideoGrabber.SetAuthentication (at_IPCamera, "root", "admin"); VideoGrabber.RecordingInNativeFormat = true VideoGrabber.RecordingMethod = rm_MP4 VideoGrabber.AudioRecording = true VideoGrabber.StartRecording () } event function OnRecordingStartedEvent(Sender, Filename) { ShowMessage (filename + " recording started!") }

event function OnPreviewStartedEvent(Sender) { ShowMessage ("preview started!") }

event function OnLogEvent(Sender, Logtype, Severity, Errormsg) { if (LogType = e_failed_to_start_recording) { ShowMessage ("error: recording failed to start") } else if (LogType = e_failed_to_start_preview) { ShowMessage ("error: preview failed to start")