<div dir="ltr"><div><div><div><div>Ilkka,<br><br></div>I implemented with a condition variable as you asked. Tested on Ubuntu and Windows 7 and it works ok.<br><br></div>Please let me know if you have any comments.<br><br>
</div>Regards,<br></div>Avishay<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 15, 2013 at 12:11 PM, Ilkka Ollakka <span dir="ltr"><<a href="mailto:ileoo@videolan.org" target="_blank">ileoo@videolan.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Thu, Aug 15, 2013 at 10:13:29AM -0400, Avishay Spitzer wrote:<br>
> Ilkka,<br>
<br>
Hi,<br>
<br>
</div><div class="im">> Are you suggesting adding a new condition variable on which read will wait<br>
> until download thread signals?<br>
<br>
</div>Yes, I think it would be better aproach as it avoids polling. Ofcourse<br>
it needs timeout value so it won't get stuck.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
> > Hi,<br>
<br>
> > I think it would be better to implement this with signal wait with<br>
> > timeout instead of polling. So download thread would signal that new<br>
> > stuff is ready.<br>
<br>
> > On Thu, Aug 15, 2013 at 06:52:09AM -0400, Avishay Spitzer wrote:<br>
> > > From 768e199c6ac6d539f1a00606a26a905a5f1b1886 Mon Sep 17 00:00:00 2001<br>
> > > From: Avishay Spitzer <<a href="mailto:savishay@gmail.com">savishay@gmail.com</a>><br>
> > > Date: Thu, 15 Aug 2013 06:41:35 -0400<br>
> > > Subject: [PATCH 2/2] Added a retry mechanism with backoff to the read<br>
> > >  function of HLS module to handle situations where<br>
> > >  stream packets may delay due to slow connections or<br>
> > >  short playlists. In case hls_Read returns 0, the read<br>
> > >  function will wait until new data arrives.<br>
<br>
> > > ---<br>
> > >  modules/stream_filter/httplive.c |   48<br>
> > +++++++++++++++++++++++++++++++++-----<br>
> > >  1 file changed, 42 insertions(+), 6 deletions(-)<br>
<br>
> > > diff --git a/modules/stream_filter/httplive.c<br>
> > b/modules/stream_filter/httplive.c<br>
> > > index ed708bf..62ab17b 100644<br>
> > > --- a/modules/stream_filter/httplive.c<br>
> > > +++ b/modules/stream_filter/httplive.c<br>
> > > @@ -2280,16 +2280,52 @@ static int Read(stream_t *s, void *buffer,<br>
> > unsigned int i_read)<br>
> > >  {<br>
> > >      stream_sys_t *p_sys = s->p_sys;<br>
> > >      ssize_t length = 0;<br>
> > > +    uint32_t retries_counter = 0, aggregate_delay = 0;<br>
<br>
> > >      assert(p_sys->hls_stream);<br>
<br>
> > > -    if (p_sys->b_error)<br>
> > > -        return 0;<br>
> > > +    while (length == 0)<br>
> > > +    {<br>
> > > +     // In case an error occurred or the stream was closed return 0<br>
> > > +        if (p_sys->b_error || !vlc_object_alive(s))<br>
> > > +            return 0;<br>
<br>
> > > -    /* NOTE: buffer might be NULL if caller wants to skip data */<br>
> > > -    length = hls_Read(s, (uint8_t*) buffer, i_read);<br>
> > > -    if (length < 0)<br>
> > > -        return 0;<br>
> > > +             /* NOTE: buffer might be NULL if caller wants to skip data<br>
> > */<br>
> > > +             length = hls_Read(s, (uint8_t*) buffer, i_read);<br>
> > > +<br>
> > > +             // An error has occurred in hls_Read<br>
> > > +             if (length < 0)<br>
> > > +                     return 0;<br>
> > > +<br>
> > > +             // No data is available yet so we need to wait until new<br>
> > data will arrive.<br>
> > > +             // We use a retry mechanism with increasing backoff (up to<br>
> > 100ms per single sleep)<br>
> > > +             if (length == 0)<br>
> > > +             {<br>
> > > +             uint32_t delay = 0;<br>
> > > +<br>
> > > +                     retries_counter++;<br>
> > > +<br>
> > > +                     if (retries_counter < 10)<br>
> > > +                             delay = 10; // ms<br>
> > > +                     else if (retries_counter < 25)<br>
> > > +                             delay = 25; // ms<br>
> > > +                     else if (retries_counter < 100)<br>
> > > +                             delay = 50; // ms<br>
> > > +                     else<br>
> > > +                             delay = 100; // ms<br>
> > > +<br>
> > > +                     aggregate_delay += delay;<br>
> > > +<br>
> > > +                     msleep(delay * 1000);<br>
> > > +             }<br>
> > > +    }<br>
> > > +<br>
> > > +    if (retries_counter > 0)<br>
> > > +    {<br>
> > > +             msg_Info(s, "got data after %u retries (delay of [%u]ms)",<br>
> > > +                             retries_counter,<br>
> > > +                             aggregate_delay);<br>
> > > +    }<br>
<br>
> > >      p_sys->playback.offset += length;<br>
> > >      return length;<br>
> > --<br>
> > Ilkka Ollakka<br>
> > Is a computer language with goto's totally Wirth-less?<br>
<br>
> > _______________________________________________<br>
> > vlc-devel mailing list<br>
> > To unsubscribe or modify your subscription options:<br>
> > <a href="https://mailman.videolan.org/listinfo/vlc-devel" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a><br>
<br>
<br>
<br>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Ilkka Ollakka<br>
<gorgo> what do you get when someone cracks your debian machine ?<br>
<gorgo> mashed potato...<br>
</font></span><br>_______________________________________________<br>
vlc-devel mailing list<br>
To unsubscribe or modify your subscription options:<br>
<a href="https://mailman.videolan.org/listinfo/vlc-devel" target="_blank">https://mailman.videolan.org/listinfo/vlc-devel</a><br>
<br></blockquote></div><br></div>