I am working on an embedded Linux VCR application that writes MP4 video to a file (on a FAT format SD card).
Some complicating factors are that video and audio data come from hardware codecs that must be serviced with low latency and must be written to DMA-compatible buffers.
At the moment, I use open () and write () for the output file, but I find that write () can take hundreds of milliseconds to return when the system is under load, so my records are executed in a separate thread.
In the order of things, I copy data from DMA buffers (a small, limited number) to the malloc'd multibyte circular buffer, and then write () from this to another stream. This means that I make at least two copies, once to the application buffer and once to the system buffer cache.
I am considering writing O_DIRECT to avoid copying, but I'm interested in any comments. I note that Robert Love comments that O_DIRECT is terrible , but does not say why.
On the other hand, I would also be interested if someone knows a way to make write () not stop for long periods of time (AIO?), Then I could use the buffer cache, as Linus suggested.
This question is not related to my very old question about creating stalls .
c linux file-io embedded
blueshift
source share