static int Prefetch(stream_t *s, int *current)
{
stream_sys_t *p_sys = s->p_sys;
- int i_segment = p_sys->segment;
+ int stream;
/* Try to pick best matching stream */
- int count = vlc_array_count(p_sys->hls_stream);
- for (int stream = 0; stream < count; stream++)
- {
- hls_stream_t *hls = hls_Get(p_sys->hls_stream, stream);
- if (hls == NULL)
- return VLC_EGENERIC;
-
- segment_t *segment = segment_GetSegment(hls,i_segment);
- if (segment == NULL )
- return VLC_EGENERIC;
+again:
+ stream = *current;
- if (Download(s, hls, segment, &stream) != VLC_SUCCESS)
- return VLC_EGENERIC;
+ hls_stream_t *hls = hls_Get(p_sys->hls_stream, *current);
+ if (hls == NULL)
+ return VLC_EGENERIC;
- i_segment++;
+ segment_t *segment = segment_GetSegment(hls, p_sys->segment);
+ if (segment == NULL )
+ return VLC_EGENERIC;
- /* */
- *current = stream;
- }
+ if (Download(s, hls, segment, current) != VLC_SUCCESS)
+ return VLC_EGENERIC;
- /* Download first 3 segments of this HLS stream */
- hls_stream_t *hls = hls_Get(p_sys->hls_stream, *current);
- if (hls == NULL)
- return VLC_EGENERIC; /* FIXME: */
+ /* Found better bandwidth match, try again */
+ if (*current != stream)
+ goto again;
- for (int i = 0; i < 3; i++)
+ /* Download first 2 segments of this HLS stream */
+ for (int i = 0; i < 2; i++)
{
segment_t *segment = segment_GetSegment(hls, p_sys->segment);
if (segment == NULL )
goto fail;
}
- /* */
- int current = p_sys->current = hls_LowestBandwidthStream(p_sys->hls_stream);
+ /* Choose first HLS stream to start with */
+ int current = p_sys->current = 0;
p_sys->segment = 0;
if (Prefetch(s, ¤t) != VLC_SUCCESS)