[mythtv] memory buffer for live video video stream

Martin Long martin at longhome.co.uk
Sun Nov 12 01:49:58 UTC 2006


> Actually mythv even when you are watching live TV get the stream from 
> capture or dvb card, writes the stream to disk in a file, then the 
> frontend asks for data from this file to the backend.
> I believe that when watching live TV with a small lag from real time, 
> the backend could feed the frontend with data coming from ram instead of 
> Reading on disk.

Well... this is provided by linux (and pretty much any OS). A think called
the buffer cache uses almost all of the free RAM (leaving a couple of meg
free), all writes are written to this before being written to the disk, then
when the frontend (or backend streaming the file on a split system) reads
the file it doesn't bother going to disk. Try doing a 'vmstat 1' - you'll
see that there's virtually no disk reads happening while you're on live TV.
The reason for the slight delay is to give the feed a little breathing space
(think of it like 'tailgating' the car in front), to buffer and decode the
feed without interruption. 

> 1 minutes of mpeg2 costs 100 mega bytes, so we could imagine a mem 
> buffer of parametrable size according to your hardware.
> DVB card get the data stream, and instead of writting it to file, data 
> are wrote to the memory buffer.
> When 3/4 of the memory buffer is full, we start to write to disk the 
> first half of the mem buffer.
> When second half is full we buffer data in the first half of the mem 
> buffer, when we reach 1/4 of the buffer (half of the first half buffer), 
> we then write to disk the second half of the buffer.
> Writting could be done earlier the idea is to always have a confortable 
> amount of stream into ram.

That's pretty much how a ringbuffer works, and similar to the way the buffer
cache works, although it does the writes as soon as possible (allowing reads
priority as they are normally synchronous), but still leaving the writes in
the buffer caches so that reads which 'hit' the cache don't need to use the
disk.

> Now I guess it could be done without any modification to the frontend, 
> but for the backend that's another story ...

So, yeah... it's aready being done, but in the kernel, not in the backend.
Horray!

_______________________________________________
mythtv-dev mailing list
mythtv-dev at mythtv.org
http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev



More information about the mythtv-dev mailing list