eHttpStream::read is always called with a multiple of 188.
What if we just make sure it always returns a multiple of 188 (and store any leftovers in an intermediate buffer of 187 bytes)?
That would give the same result, but avoids having to sync on 0x47 all the time.
Actually, looking at the patch again, that's more or less what you are doing. And assuming we stay in sync, the cpu overhead is almost zero.
One more remark though; assuming that the stream delivers nice multiples of 188, you always end up doing two timedRead's in the eHttpStream::read call, instead of just one.
That's suboptimal for the fill level of the hardware buffer (especially for live streams, where the watermark might be rather low), because you end up reading in larger chunks (with larger intervals) than we would with just a single timedRead.
To be honest I would not have any concerns about 2 timedReads, they have not caused any problems to me, in this case algorithm correctness and playback reliability are the main priorities, I have tested this code with about 4-5 iptv providers over the last year, all these changes have real issues behind, I even can not recall them all.
So to reiterate, I see no visible benefit to the end user in optimizing those reads, but we risk the image quality in "extreme" situations. I find all this hard to argue as some of the code paths cover some edge cases, that are hard to prove or demonstrate.
Actually we could do filtering only at the first read making sure that stream is in sync, I think I had this in one of the versions and I can not recall any issues with it, then we probably could remove the double read. But we definitely need to filter at least at the first read, I had intermittent issues with one of the iptv providers that was starting streaming not at the start of the packet.
Edited by zakalibit, 13 November 2013 - 22:18.