[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,6 +1215,8 @@ source_pause(uint64_t pos)
ps_playing = source_now_playing(); ps_playing = source_now_playing();
if (cur_streaming)
{
if (ps_playing != cur_streaming) if (ps_playing != cur_streaming)
{ {
DPRINTF(E_DBG, L_PLAYER, DPRINTF(E_DBG, L_PLAYER,
@ -1230,6 +1232,7 @@ source_pause(uint64_t pos)
if (ret < 0) if (ret < 0)
return -1; return -1;
} }
}
ps_playnext = ps_playing->play_next; ps_playnext = ps_playing->play_next;
while (ps_playnext) while (ps_playnext)
@ -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)
@ -1548,10 +1526,34 @@ source_read(uint8_t *buf, int len, uint64_t rtptime)
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;
} }
} }