/* */
hls_thread_t *thread;
- vlc_array_t *hls_stream;/* bandwidth adaptation */
+ vlc_array_t *hls_stream;/* bandwidth adaptation */
+ uint64_t bandwidth; /* measured bandwidth (bits per second) */
/* Playback */
uint64_t offset; /* current offset in media */
return VLC_SUCCESS;
}
+ /* sanity check - can we download this segment on time? */
+ if (s->p_sys->bandwidth > 0)
+ {
+ uint64_t size = (segment->duration * hls->bandwidth); /* bits */
+ int estimated = (int)(size / s->p_sys->bandwidth);
+ if (estimated > segment->duration)
+ {
+ msg_Err(s, "cannot quarantee smooth playback");
+ msg_Warn(s,"downloading takes (%ds) takes longer then playback (%ds) of segment %d",
+ estimated, segment->duration, segment->sequence);
+ vlc_mutex_unlock(&segment->lock);
+ return VLC_EGENERIC;
+ }
+ }
+
mtime_t start = mdate();
if (AccessDownload(s, segment) != VLC_SUCCESS)
{
return VLC_SUCCESS;
uint64_t bw = ((double)(segment->size * 8) / ms) * 1000; /* bits / s */
- segment->bandwidth = bw;
+ s->p_sys->bandwidth = bw;
if (hls->bandwidth != bw)
{
int newstream = BandwidthAdaptation(s, hls->id, &bw);
}
else if (Download(client->s, hls, segment, &client->current) != VLC_SUCCESS)
{
- if (!p_sys->b_live) break;
+ if (!p_sys->b_live)
+ {
+ p_sys->b_error = true;
+ break;
+ }
}
/* download succeeded */
if (p_sys == NULL)
return VLC_ENOMEM;
+ p_sys->bandwidth = -1;
p_sys->b_live = true;
p_sys->b_meta = false;
+ p_sys->b_error = false;
p_sys->hls_stream = vlc_array_new();
if (p_sys->hls_stream == NULL)
assert(p_sys->hls_stream);
+ if (p_sys->b_error)
+ return 0;
+
if (buffer == NULL)
{
/* caller skips data, get big enough buffer */
segment = GetSegment(s);
if (segment == NULL)
{
- msg_Err(s, "segment should have been available");
+ msg_Err(s, "segment %d should have been available (stream %d)",
+ p_sys->segment, p_sys->current);
return 0; /* eof? */
}