I have a program in C++ which runs a loop like this, grabbing frames from a video device, using a proprietary driver which I have no access to.
while(true) {
mybuf = getNextFrame(); // blocks
}
I would like to build some logic using other programming languages, so I was thinking of using the following interface. (I need only Linux support)
I was thinking of having a file somewhere, like:
/my/video/device
And every time I call read()
on it, it would give me the current frame. Also, if I call read() again, I would like it to block until the next frame is available and return that for me. Also, if I don't call open() for awhile, I don't want the frames in-between to be buffered.
What would be the best approach?
I tried to use FUSE to implement a filesystem, but it was trying to seek inside the file, if it was a regular file, and would only read up to the size I specified for the file. I then made a character device, but it would never call my read()
function, instead it would say permission denied...
I was thinking about trying CUSE, or something along the lines. Am I over complicating things? I just need to be able to work with a stream of frames which are constantly coming from my C++ loop, but I want to parse them in a different language, like Python or Go. I also do not want to mix the compilation of my C++ code with Go or python, I want the two to be completely separate. I thought having some sort of file API between the two would make things easier. What would be a good way of handling this?
I would write the program using named pipes. One thing to keep in mind is that if the recieving end disconnects in the middle of a write the server will recieve a SIGPIPE signal and unless this signal is handled or blocked the server will be terminated.