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

miroslav22

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

    SilentException

    Retired Team Member
  • Premium Supporter
  • October 27, 2008
    2,617
    1,130
    Rijeka, Croatia
    Croatia Croatia
    Country flag
    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
    United Kingdom United Kingdom
    Country flag
    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
    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,546
    432
    Germany Germany
    Country flag
    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,546
    432
    Germany Germany
    Country flag
    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
    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
    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 (Users: 0, Guests: 1)

    OP Similar threads Forum Replies Date
    framug [solved] Some changes/fix in MP1 configuration client and server Submit: code patches (MediaPortal/TV-Server/etc.) 14
    framug [Approved] Fix Irtrans config bug Submit: code patches (MediaPortal/TV-Server/etc.) 4
    W [solved] [FIXED] Survivor season 40 not automatically matching My TVSeries 1
    P [solved] ATSC subtitles not fixed yet? General 2
    framug [Rejected] Fix PowerScheduler plugin for MP2 single seat Submit: Code Patches 9
    M [Pending] Fix for Inconsistent date display in TV Guide Submit: code patches (MediaPortal/TV-Server/etc.) 1
    doskabouter [Proposal] Merge PR Fix for source directory with spaces MediaPortal 1 15
    CyberSimian Fixes for Amped aMPed 5
    CyberSimian Fixes for Amped skin MediaPortal 1 10
    Stephen O'Kane [SOLVED] TV Stream stuttering - both Video and Audio Watch / Listen Media 14
    B some music videos stutter Watch / Listen Media 0
    I Video Playback Stuttering General Support 45
    limpwhizkid 1.22.0 Stutter and or artifact problem when recording and watching the same live tv channel 1.22 2
    P [solved] Analog FM Radio stutter General 11
    W Playback stuttering after upgrade from MP1 on Windows 7 to MP2 on Windows 10 General 2
    AberDino 4k TV Stutter with RTSP General Support 7
    bta489 [solved] Stuttering playback of edited recordings watch/edit Videos 2
    M VPN: Mediaportal TV-Server ist not using all available bandwidth which results in TV stuttering Newcomers Forum 0
    D [solved] (Micro)Stutter when playing TV General 28
    Stephen O'Kane MP1.20 - Stuttering Recordings (EXP-Upgrage_555_MM_Owlsroost) Watch / Listen Media 1
    J Over the air chanenels stuttering General 0
    M Apollo Lake and Gemini Lake 4K HEVC HDR10 performance General 1
    P Video and audio stutters after playing TV recording for few minutes 1.19 0
    F 1.25.0 Display corruption Bugreports 0
    D MP2 - V2.1 Recorded TV - recording corrupted if MP client used while recoding in progress Older releases 20
    Similar threads

























    Top Bottom