It is possible to get a JPEG snaphot synchronously or asynchronously, by just adding the filter to the graph and loading the URL (without running the graph).
The snapshot can be returned as a JPEG file and/or as a pointer to a memory buffer containing the JPEG image.
Configuration steps to
capture a JPEG snapshot of the IP camera 192.168.5.22:
(sample
code in the CSharp "DatasteadRTSPSource_ONVIF_Shapshot"
demo project)
1. add the filter to the graph
2. set the user name and password
DatasteadRTSPSourceConfig.SetStr(RTSP_Source_AuthUser_str, "username")
DatasteadRTSPSourceConfig.SetStr(RTSP_Source_AuthPassword_str, "password")
3. set a non-default connection timeout if needed, e.g. for 5 seconds:
DatasteadRTSPSourceConfig.SetInt (RTSP_Source_ConnectionTimeOut_int, 5000)
4. if a JPEG file is needed, set also the recording file name:
DatasteadRTSPSourceConfig.SetStr(RTSP_Source_RecordingFileName_str,"c:\folder\shot.jpg")
A) to capture the snapshot synchronously, invoke:
int
hr = DatasteadRTSPSourceConfig.Action(RTSP_Action_GetONVIFSnapshot,
"onvif://192.168.1.22")
if (hr == 0) {
byte *pJPEGBuffer
DatasteadRTSPSourceConfig2.GetIntPtr (RTSP_ONVIF_LastJPEGSnapshotBuffer_intptr, &pJPEGBuffer)
int
JpegSize;
DatasteadRTSPSourceConfig.GetInt
(RTSP_ONVIF_LastJPEGSnapshotSize_int, &pJPEGSize)
}
B) to capture the snapshot asynchronously, invoke:
DatasteadRTSPSourceConfig.Action(RTSP_Action_GetONVIFSnapshotAsync, "onvif://192.168.5.22");
The connection and download will run in a separate thread, then IMediaEvent will return one of the following event:
- upon failure:
EC_RTSPNOTIFY with Param1 = EC_RTSP_PARAM1_ONVIF_SNAPSHOT_FAILED
- upon success:
EC_RTSPNOTIFY
with Param1 = EC_RTSP_PARAM1_ONVIF_SNAPSHOT_SUCCEEDED
Upon success, if needed, access the memory JPEG buffer as
follows:
byte *pJPEGBuffer
DatasteadRTSPSourceConfig2.GetIntPtr (RTSP_ONVIF_LastJPEGSnapshotBuffer_intptr, &pJPEGBuffer)
int
JpegSize;
DatasteadRTSPSourceConfig.GetInt
(RTSP_ONVIF_LastJPEGSnapshotSize_int, &pJPEGSize)
Note: NO NEED TO RUN THE GRAPH FOR THE SNAPSHOT CAPTURE.