![]() |
VR-Vantage 2.2 API Documentation
|
This example opens, maps, and reads from a shared memory segment created by VR-Vantage that contains streamed video frames.
VR-Vantage creates a shared memory segment with the name specified in the video stream configuration dialog. The segment is organized as a header plus 3 fixed-size video frame buffers. Each buffer is the size specified in the video stream configuration dialog; it should be large enough to hold one video frame (typically your screen dimensions * 3 bytes when using 24bpp).
DtSharedMemoryTaskElement::DtSharedMemoryHeader contains the definition of the sgement header. This can be found in include\vrvVideoStream\DtSharedMemoryTaskElement.h.
The application attempts to open the indicated shared memory segment with read/write permissions.
It then maps the entire segment into the application's address space.
It sets a pointer to a DtSharedMemoryTaskElement::DtSharedMemoryHeader to point to the beginning of the mapped region.
It reads the video frames specs (format, bpp, height, width). These values are not used in the example, but will typically be needed to process / display your video frame.
It fills an array with pointers to each of the 3 fixed frame buffers. At this point, all the parts of the shared memory segment that we will want to access are mapped and references.
The application enters a loop to read video frames. It will continue until a 'q' or 'Q' key is pressed.
It reads the current frame indicator from the shared memory header, and sets the last frame variable (which starts at -1) to prevent re-reading the same frame in the case where the application runs faster than the the writer.
The application now locks the fixed buffer for the current frame so that the writer will not attempt to write to it. (It won't block, it will just skip over it, since we're triple-buffering).
Now that the buffer is locked, it can get the actual size of the image data, allocate a buffer, and read the bytes.
Once the data has been read, the application unlocks the current frame buffer.
VR-Vantage includes pre-built versions of the example application. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
This example is an application. You can run it by starting Vantage. Go to Settings -> Video Streams... Then select Compress and Shared Memory click Edit. Note the Shared Memory Names (which is 'video' by default). Click Start. On Windows, the video file will (by default) be created in C: LastBootUpTime from Win32_OperatingSystem Run ./bin/exampleReadVideoShm.exe "..\Select LastBootUpTime from Win32_OperatingSystem\<shared memory name>" (on Windows) or ./bin/exampleReadVideoShm "<shared memory name>" (on Linux). For more information about running examples, please see Running Applications and Examples.