Hi
Recently i've been trying to fix a really annoying problem with streaming live tv to clients (stuttering and discontinuities). After a lot of tinkering I think i've finally nailed it
I submitted a patch a few months ago that alleviated the problem but didn't completely fix it. See here https://forum.team-mediaportal.com/...325/fix-streaming-discontinuity-errors-87172/
The root of the problem is that tswriter, tsreader and streamingserver make a lot of unnecessary and an excessive number of read & write disk operations with live tv. Viewing a HD channel on my setup caused MP and tvserver to perform over 11,000 disk IO operations per second (very high for even a fast disk). This patch removes the unnecessary read/write calls and also reduces the frequency that packets are written to disk (every 43 packets instead of 10 - see below). These optimisations reduce the disk IOs by about 90% to ~1,200 per second on a HD channel.
The second cause of the problem is the precise timings that streamingserver seems to require to reliably stream live tv. In this patch i've modified tswriter to dump 43 packets at a time instead of 10. 43 packets equals 8084 bytes which exactly matches the buffer size that streamingserver uses. This, coupled with the reduced number of disk IOs means that the strict timing of streamingserver is matched almost perfectly. The difference has been massive on my setup.
I realise that MP1 is pretty much finished but I think this patch is extremely worthwhile for people who stream to clients for live tv. Give me a shout if you need any more in depth detail.
***** Version 2 *****
I have attached the patch and binaries for version 2. This version reduces disk IO's by a further 75% and adds the enhancements to MPFileWriter. I have no way to test MPFileWriter so it'd be appreciated if theres anyone who can test this - please post if so.
Due to the extra methods used to pass in the channel type, there are a few more binaries included that must be replaced. They are built over 1.2.0 Alpha tag.
Changes:
TSWriter now writes 172 packets for TV and 10 for radio at a time (reduces disk IOs by a further 75%)
Streaming server changed to use a variable buffer size to match the write frequency (1880 bytes for radio, 32336 for tv)
MPFileWriter patched and matches TSWriter by writing 172 packets for TV and 10 for radio
***** Version 3 ***** (11th January 2011)
I have now attached version 3 of the patch and binaries for the latest SVN 27238. Binaries for earlier versions will be posted tomorrow (Wednesday 12th January).
Please do not use the latest SVN 27238 binaries with any version earlier than 27231, they will not work due to changes made in this and earlier revisions.
Changes:
Buffer is now throttled in TsWriter and MpFileWriter. When a new channel is tuned, it starts by writing 2, 3, 5 ... packets which increments in 20 steps up to 172 packets for TV and 10 for radio - (Thanks to arion_p for this suggestion)
Several bug fixes in StreamingServer for discontinuity and stream corruption handling (Thanks to davidf for these fixes)
There should be a slight improvement in channel zapping times compared to version 2 (not massively noticeable, probably an improvement of around 0.1 - 0.2 seconds).
The fixes by davidf should help improve RTSP streaming when you have a bad signal or corruptions in a transport stream.
If anyone can test MpFileWriter (analog cards) and post their results, it would be much appreciated
Issues:
Reported that live TV can sometimes go into slow motion. Please post logs if you see this.
There seems to be a problem when timeshifting on a network drive when the tsbuffer switches to the next file (file not found error - some weird caching problem I believe). An additional fix may be needed for this. Again please post logs if this applies to you.
Radio RTSP streaming performs a huge number of disk read IOs (~20,000) for some bizarre reason. It seems this issue has always been in MP. Additional fix required for this.
Recently i've been trying to fix a really annoying problem with streaming live tv to clients (stuttering and discontinuities). After a lot of tinkering I think i've finally nailed it
I submitted a patch a few months ago that alleviated the problem but didn't completely fix it. See here https://forum.team-mediaportal.com/...325/fix-streaming-discontinuity-errors-87172/
The root of the problem is that tswriter, tsreader and streamingserver make a lot of unnecessary and an excessive number of read & write disk operations with live tv. Viewing a HD channel on my setup caused MP and tvserver to perform over 11,000 disk IO operations per second (very high for even a fast disk). This patch removes the unnecessary read/write calls and also reduces the frequency that packets are written to disk (every 43 packets instead of 10 - see below). These optimisations reduce the disk IOs by about 90% to ~1,200 per second on a HD channel.
The second cause of the problem is the precise timings that streamingserver seems to require to reliably stream live tv. In this patch i've modified tswriter to dump 43 packets at a time instead of 10. 43 packets equals 8084 bytes which exactly matches the buffer size that streamingserver uses. This, coupled with the reduced number of disk IOs means that the strict timing of streamingserver is matched almost perfectly. The difference has been massive on my setup.
I realise that MP1 is pretty much finished but I think this patch is extremely worthwhile for people who stream to clients for live tv. Give me a shout if you need any more in depth detail.
***** Version 2 *****
I have attached the patch and binaries for version 2. This version reduces disk IO's by a further 75% and adds the enhancements to MPFileWriter. I have no way to test MPFileWriter so it'd be appreciated if theres anyone who can test this - please post if so.
Due to the extra methods used to pass in the channel type, there are a few more binaries included that must be replaced. They are built over 1.2.0 Alpha tag.
Changes:
TSWriter now writes 172 packets for TV and 10 for radio at a time (reduces disk IOs by a further 75%)
Streaming server changed to use a variable buffer size to match the write frequency (1880 bytes for radio, 32336 for tv)
MPFileWriter patched and matches TSWriter by writing 172 packets for TV and 10 for radio
***** Version 3 ***** (11th January 2011)
I have now attached version 3 of the patch and binaries for the latest SVN 27238. Binaries for earlier versions will be posted tomorrow (Wednesday 12th January).
Please do not use the latest SVN 27238 binaries with any version earlier than 27231, they will not work due to changes made in this and earlier revisions.
Changes:
Buffer is now throttled in TsWriter and MpFileWriter. When a new channel is tuned, it starts by writing 2, 3, 5 ... packets which increments in 20 steps up to 172 packets for TV and 10 for radio - (Thanks to arion_p for this suggestion)
Several bug fixes in StreamingServer for discontinuity and stream corruption handling (Thanks to davidf for these fixes)
There should be a slight improvement in channel zapping times compared to version 2 (not massively noticeable, probably an improvement of around 0.1 - 0.2 seconds).
The fixes by davidf should help improve RTSP streaming when you have a bad signal or corruptions in a transport stream.
If anyone can test MpFileWriter (analog cards) and post their results, it would be much appreciated
Issues:
Reported that live TV can sometimes go into slow motion. Please post logs if you see this.
There seems to be a problem when timeshifting on a network drive when the tsbuffer switches to the next file (file not found error - some weird caching problem I believe). An additional fix may be needed for this. Again please post logs if this applies to you.
Radio RTSP streaming performs a huge number of disk read IOs (~20,000) for some bizarre reason. It seems this issue has always been in MP. Additional fix required for this.
Attachments
-
StreamingAndDiskIOFix.patch9 KB
-
StreamingAndDiskIOFixv2.patch63.3 KB
-
StreamingDiskIOFix-Binaries-v2.zip992.6 KB
-
StreamingDiskIOFix-V3-Binaries (SVN 27238).zip1,000 KB
-
DiscontinuityFixV3.patch65.2 KB
-
DiscontinuityFixV3 (for 1.1.2).patch65.2 KB
-
DiscontinuityFixV3 (for 1.2.0 Alpha).patch65.2 KB
-
StreamingDiskIOFix-V3-Binaries (1.1.2).zip996.1 KB
-
StreamingDiskIOFix-V3-Binaries (1.2.0 Alpha).zip994.4 KB