<div dir="ltr"><div>I hope I understood what you meant. Let me know if it's still not ok.<br><br></div>Avishay<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Aug 19, 2013 at 4:31 AM, 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"><br>
Thanks for your patch, if you could clean up the indentation and remove<br>
tabs.<br>
<br>
On Mon, Aug 19, 2013 at 03:11:41AM -0400, Avishay Spitzer wrote:<br>
> From e4c56f0bec62e679d8c0d2364cac8f7da7cbcbaa Mon Sep 17 00:00:00 2001<br>
> From: Avishay Spitzer <<a href="mailto:savishay@gmail.com">savishay@gmail.com</a>><br>
<div class="im">> +    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>
</div>> +        // Lock the mutex before trying to read to avoid a race condition with the download thread<br>
> +        vlc_mutex_lock(&p_sys->read.lock_wait);<br>
<div class="im">> +<br>
> +             /* NOTE: buffer might be NULL if caller wants to skip data */<br>
> +             length = hls_Read(s, (uint8_t*) buffer, i_read);<br>
> +<br>
> +             // An error has occurred in hls_Read<br>
> +             if (length < 0)<br>
</div>> +             {<br>
> +             vlc_mutex_unlock(&p_sys->read.lock_wait);<br>
<div class="im">> +<br>
> +                     return 0;<br>
> +             }<br>
> +<br>
</div>> +             // There is no data available yet for the demuxer so we need to wait until reload and<br>
> +             // download operation are over.<br>
> +             // Download thread will signal once download is finished.<br>
> +             // A timed wait is used to avoid deadlock in case data never arrives since the thread<br>
> +             // running this read operation is also responsible for closing the stream<br>
<div class="im">> +             if (length == 0)<br>
> +             {<br>
</div>> +                 mtime_t start = mdate();<br>
> +<br>
> +                 // Wait for 10 seconds<br>
> +                 mtime_t timeout_limit = start + (10 * UINT64_C(1000000));<br>
> +<br>
> +             int res = vlc_cond_timedwait(&p_sys->read.wait, &p_sys->read.lock_wait, timeout_limit);<br>
> +<br>
> +             // Error - reached a timeout of 10 seconds without data arriving - kill the stream<br>
> +             if (res == ETIMEDOUT)<br>
> +             {<br>
> +                     msg_Info(s, "timeout limit reached!");<br>
> +<br>
> +                     vlc_mutex_unlock(&p_sys->read.lock_wait);<br>
<div class="im">> +<br>
> +                     return 0;<br>
> +             }<br>
</div>> +             else if (res == EINVAL)<br>
> +                     return 0; // Error - lock is not locked so we can just return<br>
> +             }<br>
> +<br>
> +        vlc_mutex_unlock(&p_sys->read.lock_wait);<br>
> +    }<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Ilkka Ollakka<br>
Disc space -- the final frontier!<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>