*
* Author: Jean-Paul Saman <jpsaman _AT_ videolan _DOT_ org>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
for (size_t i = 0; i < ARRAY_SIZE(ext); i++)
{
size_t len = strlen(ext[i]);
- if (size < len)
+ if (size < 0 || (size_t)size < len)
continue;
if (!memcmp(peek, ext[i], len))
return true;
if (hls == NULL)
return VLC_EGENERIC;
- /* Download first 2 segments of this HLS stream */
- for (int i = 0; i < 2; i++)
+ if (vlc_array_count(hls->segments) == 0)
+ return VLC_EGENERIC;
+ else if (vlc_array_count(hls->segments) == 1 && p_sys->b_live)
+ msg_Warn(s, "Only 1 segment available to prefetch in live stream; may stall");
+
+ /* Download first 2 segments of this HLS stream if they exist */
+ for (int i = 0; i < __MIN(vlc_array_count(hls->segments), 2); i++)
{
segment_t *segment = segment_GetSegment(hls, p_sys->download.segment);
if (segment == NULL )
uint64_t size = hls->size;
int count = vlc_array_count(hls->segments);
- /* restore current segment to start position */
- segment_t *segment = segment_GetSegment(hls, p_sys->playback.segment);
- if (segment == NULL)
+ segment_t *currentSegment = segment_GetSegment(hls, p_sys->playback.segment);
+ if (currentSegment == NULL)
{
vlc_mutex_unlock(&hls->lock);
return VLC_EGENERIC;
}
- vlc_mutex_lock(&segment->lock);
- segment_RestorePos(segment);
- vlc_mutex_unlock(&segment->lock);
for (int n = 0; n < count; n++)
{
/* */
if (b_found)
{
- /* restore segment to start position */
+
+ /* restore current segment to start position */
+ vlc_mutex_lock(¤tSegment->lock);
+ segment_RestorePos(currentSegment);
+ vlc_mutex_unlock(¤tSegment->lock);
+
+ /* restore seeked segment to start position */
segment_t *segment = segment_GetSegment(hls, p_sys->playback.segment);
if (segment == NULL)
{