The most efficient way to write files for a Linux VCR

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 .

+8
c linux file-io embedded
source share
1 answer

If this is really an embedded product in that you control the source of the drivers, I would seriously look at mmap'ping the memory so that the user process could access the same memory as the device driver and avoid all these copies.

And here is an example of the implementation of driver memory shared with the user space process using mmap.

+2
source share

All Articles