[Approved] - Fix for stuttering/corrupted streaming of live tv

Discussion in 'Archive' started by miroslav22, December 22, 2010.

  1. miroslav22
    • Premium Supporter

    miroslav22 Development Group Member

    Joined:
    September 4, 2009
    Messages:
    703
    Likes Received:
    459
    Gender:
    Male
    Location:
    Warwick
    Ratings:
    +459 / 0
    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.
     

    Attached Files:

    • Like Like x 57
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. SilentException
    • Premium Supporter

    SilentException Retired Team Member

    Joined:
    October 27, 2008
    Messages:
    2,617
    Likes Received:
    1,125
    Gender:
    Male
    Location:
    Rijeka, Croatia
    Ratings:
    +1,129 / 0
    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?
     
  4. miroslav22
    • Premium Supporter

    miroslav22 Development Group Member

    Joined:
    September 4, 2009
    Messages:
    703
    Likes Received:
    459
    Gender:
    Male
    Location:
    Warwick
    Ratings:
    +459 / 0
    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).
     
  5. tourettes
    • Premium Supporter

    tourettes Retired Team Member

    Joined:
    January 7, 2005
    Messages:
    17,301
    Likes Received:
    4,595
    Ratings:
    +4,810 / 3
    I don't know that part of TsReader / TsWriter (or streaming at all) to be able to review that patch completely, but:

    Code (Text):
    1. +#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).
     
    • Like Like x 1
  6. Marvman
    • Premium Supporter

    Marvman Retired Team Member

    Joined:
    November 14, 2007
    Messages:
    1,163
    Likes Received:
    365
    Occupation:
    Application Developer
    Location:
    Bavaria
    Ratings:
    +368 / 0
    Home Country:
    Germany Germany
    Show System Specs
    Thanks for the great patch, only a side note, delete the out commented code lines, that isn't necessary do hold them for ever.
     
  7. disaster123
    • Premium Supporter

    disaster123 MP Donator

    Joined:
    May 14, 2008
    Messages:
    3,546
    Likes Received:
    417
    Ratings:
    +431 / 2
    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 :)
     
  8. tourettes
    • Premium Supporter

    tourettes Retired Team Member

    Joined:
    January 7, 2005
    Messages:
    17,301
    Likes Received:
    4,595
    Ratings:
    +4,810 / 3
    Re: AW: Fix for stuttering/corrupted streaming of live tv

    Please post as well in the case if the patch wont help.
     
  9. disaster123
    • Premium Supporter

    disaster123 MP Donator

    Joined:
    May 14, 2008
    Messages:
    3,546
    Likes Received:
    417
    Ratings:
    +431 / 2
    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.
     
    • Like Like x 1
  10. MacGyverek

    MacGyverek Portal Pro

    Joined:
    January 27, 2010
    Messages:
    144
    Likes Received:
    23
    Gender:
    Male
    Location:
    Rydułtowy
    Ratings:
    +23 / 0
    Home Country:
    Poland Poland
    Show System Specs
    How can I test this path?? Where I find TsWriter and TsReader and streamingserver with this path ??
     
  11. Jelmo

    Jelmo Portal Pro

    Joined:
    September 8, 2007
    Messages:
    711
    Likes Received:
    43
    Gender:
    Male
    Ratings:
    +52 / 0
    Home Country:
    Germany Germany
    Show System Specs
    AW: Fix for stuttering/corrupted streaming of live tv

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

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!