[player] Fix segfault if pause requested in the last two seconds of the

last item in the playqueue (cur_streaming is already NULL)
This commit is contained in:
chme 2015-09-18 20:01:20 +02:00
parent 2b037b67d9
commit cb2805800b

View File

@ -1122,7 +1122,7 @@ stream_stop(struct player_source *ps)
case DATA_KIND_SPOTIFY: case DATA_KIND_SPOTIFY:
#ifdef HAVE_SPOTIFY_H #ifdef HAVE_SPOTIFY_H
spotify_playback_stop(); //TODO [player] spotify cleanup functions? spotify_playback_stop();
#endif #endif
break; break;
@ -1215,20 +1215,23 @@ source_pause(uint64_t pos)
ps_playing = source_now_playing(); ps_playing = source_now_playing();
if (ps_playing != cur_streaming) if (cur_streaming)
{ {
DPRINTF(E_DBG, L_PLAYER, if (ps_playing != cur_streaming)
"Pause called on playing source (id=%d) and streaming source already " {
"switched to the next item (id=%d)\n", ps_playing->id, cur_streaming->id); DPRINTF(E_DBG, L_PLAYER,
ret = stream_stop(cur_streaming); "Pause called on playing source (id=%d) and streaming source already "
if (ret < 0) "switched to the next item (id=%d)\n", ps_playing->id, cur_streaming->id);
return -1; ret = stream_stop(cur_streaming);
} if (ret < 0)
else return -1;
{ }
ret = stream_pause(cur_streaming); else
if (ret < 0) {
return -1; ret = stream_pause(cur_streaming);
if (ret < 0)
return -1;
}
} }
ps_playnext = ps_playing->play_next; ps_playnext = ps_playing->play_next;
@ -1504,31 +1507,6 @@ source_read(uint8_t *buf, int len, uint64_t rtptime)
new = 0; new = 0;
while (nbytes < len) while (nbytes < len)
{ {
if (new)
{
DPRINTF(E_DBG, L_PLAYER, "New file\n");
new = 0;
item = queue_next(queue, cur_streaming->queueitem_id, shuffle, repeat);
if (item)
{
ret = source_open(item, cur_streaming->end + 1, 0);
if (ret < 0)
return -1;
ret = source_play();
if (ret < 0)
return -1;
metadata_trigger(cur_streaming, 0);
}
else
{
cur_streaming = NULL;
}
}
if (evbuffer_get_length(audio_buf) == 0) if (evbuffer_get_length(audio_buf) == 0)
{ {
if (cur_streaming) if (cur_streaming)
@ -1544,14 +1522,38 @@ source_read(uint8_t *buf, int len, uint64_t rtptime)
free(silence_buf); free(silence_buf);
ret = len - nbytes; ret = len - nbytes;
} }
if (ret <= 0) if (ret <= 0)
{ {
/* EOF or error */ /* EOF or error */
//TODO [player] distinguish between eof and error - on error remove item from queue two avoid endless loops if repeat is set
source_close(rtptime + BTOS(nbytes) - 1); source_close(rtptime + BTOS(nbytes) - 1);
new = 1; DPRINTF(E_DBG, L_PLAYER, "New file\n");
item = queue_next(queue, cur_streaming->queueitem_id, shuffle, repeat);
if (ret < 0)
{
DPRINTF(E_LOG, L_PLAYER, "Error reading source %d\n", cur_streaming->id);
queue_remove_byitemid(queue, cur_streaming->queueitem_id);
}
if (item)
{
ret = source_open(item, cur_streaming->end + 1, 0);
if (ret < 0)
return -1;
ret = source_play();
if (ret < 0)
return -1;
metadata_trigger(cur_streaming, 0);
}
else
{
cur_streaming = NULL;
}
continue; continue;
} }
} }