I'm working on an OpenGL video player that uses Media Foundation as my video frame source. I start one video frame capture thread per video source, with potentially multiple videos playing at once. Currently I dump incoming frames to a local buffer on the sub thread, then my main render thread runs through my video capture objects, locking access to the buffer, and calling glTexSubImage2D() to upload to texture. It renders each texture as a quad for display.
I'm intending to switch to using Pixel Buffer Objects. What I would LIKE to do, is have twice as many PBO's as video sources, so on any given frame I can be drawing from the previous frames' upload target, while starting an upload to the previous frames render source. To speed things up even more, I was intending to map all upload target PBO's, give a mapped memory pointer to each video capture sub thread to write frames directly to as they arrive, then unmap and upload on my next main-thread render pass.
However, it seems as though you can only have one PBO bound/mapped at a time. So, this means I cant leave mapped ptrs to multiple PBO's to multiple video capture threads at a time between my render. Is this correct?
As far as I can tell, I have one of two reasonable options:
I can forget having my video capture threads write directly to mapped PBO's. They can cache frame pixels in a standard local memory buffer, then my my thread can do two loops in its render function; One to render the previous frames PBO uploads, and one to start uploading newly cached video frame data to the PBO's that are not being rendered from. It seems this would still benefit from asynchronous texture uploads, but would also still be bottlenecking. For example, I'd still be wastefully caching video frames to RAM in sub threads before trying to upload them to PBO/texture memory, and my main thread would be responsible to do the memcpy into the mapped PBO memory.
The second method I though of, was to create two large PBO's that each contain space for one frame of all video sources. This way my main thread could bind the current render source PBO, loop calling glTexSubImage2D for each texture with appropriate offsets into the PBO and render these textures. Then it could map the current 'back buffer' PBO, and pass pointers to the correct frame offsets to the video capture threads for direct writes as they receive frame data. On the next pass I could un-map the 'back buffer' pbo, and repeat previous steps to upload via glTexSubImage2D, then map the previous frames render PBO as the sub thread frame destination, etc, etc.
Sorry for making this long winded but I want to get some general advice/input with a good description of what I'm up to. Is my general understanding correct? What are thoughts on trade offs between sub threads being able to perform the memcpy into mapped PBO memory vs having to use a single large PBO to get around only being able to have one mapped with multiple data source threads?
Edited by Grumple, 31 May 2013 - 10:59 AM.