[Approved] Fix for stuttering/corrupted streaming of live tv (1 Viewer)

miroslav22

Development Group Member
  • Premium Supporter
  • September 4, 2009
    703
    460
    Warwick
    Home Country
    United Kingdom United Kingdom
    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.
     

    Attachments

    • StreamingAndDiskIOFix.patch
      9 KB
    • StreamingAndDiskIOFixv2.patch
      63.3 KB
    • StreamingDiskIOFix-Binaries-v2.zip
      992.6 KB
    • StreamingDiskIOFix-V3-Binaries (SVN 27238).zip
      1,000 KB
    • DiscontinuityFixV3.patch
      65.2 KB
    • DiscontinuityFixV3 (for 1.1.2).patch
      65.2 KB
    • DiscontinuityFixV3 (for 1.2.0 Alpha).patch
      65.2 KB
    • StreamingDiskIOFix-V3-Binaries (1.1.2).zip
      996.1 KB
    • StreamingDiskIOFix-V3-Binaries (1.2.0 Alpha).zip
      994.4 KB

    SilentException

    Retired Team Member
  • Premium Supporter
  • October 27, 2008
    2,617
    1,130
    Rijeka, Croatia
    Home Country
    Croatia Croatia
    Thanks for your contributions miroslav22! I'm really happy if you nailed it with this patch :) I'm sure someone from TVServer team will take a look at this soon.

    Can i close the other thread?
     

    miroslav22

    Development Group Member
  • Premium Supporter
  • September 4, 2009
    703
    460
    Warwick
    Home Country
    United Kingdom United Kingdom
    Yea sure no probs.

    The patch is generated over the tag of 1.2.0 alpha.

    The only risky part of the patch (IMO) is changing tswriter to dump 43 packets at a time instead of 10. There is a comment from ambass that this was set at 10 to fix a problem with live radio (before this it was 175).
     

    tourettes

    Retired Team Member
  • Premium Supporter
  • January 7, 2005
    17,301
    4,800
    I don't know that part of TsReader / TsWriter (or streaming at all) to be able to review that patch completely, but:

    Code:
    +#define WRITE_BUFFER_SIZE (188*43)                  // Reduced from 175 packets ( 32900 ) to 10 for Radio startup ( Ambass ) - Now 172 = 4*(8084/188) - 8084 is the buffer size of streaming server

    That would make the radio channels to start approx 4x times slower than currently. I think WRITE_BUFFER_SIZE needs to be detected on run time. For radio use the 188x10 and for tv 188*43 or even 188*86.

    Also MisterD reminded that MPFileWriter should be patched as well so that the analog side will stay in sync (and to make sure that no new issues are rising).
     

    Marvman

    Retired Team Member
  • Premium Supporter
  • November 14, 2007
    1,163
    735
    Bavaria
    Home Country
    Germany Germany
    Thanks for the great patch, only a side note, delete the out commented code lines, that isn't necessary do hold them for ever.
     

    disaster123

    MP Donator
  • Premium Supporter
  • May 14, 2008
    3,558
    434
    Home Country
    Germany Germany
    AW: Fix for stuttering/corrupted streaming of live tv

    thank you very much for this patch - will test it asap and post if my problems with HD channels and RTSP are gone :)
     

    tourettes

    Retired Team Member
  • Premium Supporter
  • January 7, 2005
    17,301
    4,800
    Re: AW: Fix for stuttering/corrupted streaming of live tv

    thank you very much for this patch - will test it asap and post if my problems with HD channels and RTSP are gone :)

    Please post as well in the case if the patch wont help.
     

    disaster123

    MP Donator
  • Premium Supporter
  • May 14, 2008
    3,558
    434
    Home Country
    Germany Germany
    AW: Fix for stuttering/corrupted streaming of live tv

    oh for sure :)

    just have to say a really BIG THANK YOU!! Absolutely amazing all my livetv problems with HD (at least for NON-RTSP) are gone - not sure if i will ever switch to RTSP again. HD is now working even for 30 minutes without any problem. Just great don't know what i should say.
     

    MacGyverek

    Portal Pro
    January 27, 2010
    144
    23
    Rydułtowy
    Home Country
    Poland Poland
    How can I test this path?? Where I find TsWriter and TsReader and streamingserver with this path ??
     

    Jelmo

    Portal Pro
    September 8, 2007
    711
    55
    Home Country
    Germany Germany
    AW: Fix for stuttering/corrupted streaming of live tv

    Hi i also wan´t to test the patch --- but how ?
     

    Users who are viewing this thread

    Top Bottom