diff --git a/src/stream/stream_viewer.c b/src/stream/stream_viewer.c index 65656a1a..f65c4061 100644 --- a/src/stream/stream_viewer.c +++ b/src/stream/stream_viewer.c @@ -171,7 +171,13 @@ static void process(void *arg) { struct stream_media_packet p; int result = stream_media_read(s->handle, s->position, video > 0, s->audio_ahead, &p); if (result == STREAM_OK) { - if (p.kind == STREAM_MEDIA_READ_END) { close_viewer(s, STREAM_VIEWER_END, 0); break; } + if (p.kind == STREAM_MEDIA_READ_END) { + if (stream_media_get_status(s->handle, &s->status) < 0) { + DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "viewer final status failed id=%llu", (unsigned long long)s->id); + close_viewer(s, STREAM_VIEWER_CLOSED, STREAM_CLOSE_FAILED); + } else close_viewer(s, STREAM_VIEWER_END, 0); + break; + } int kind = p.kind == STREAM_MEDIA_READ_VIDEO ? STREAM_VIEWER_VIDEO : STREAM_VIEWER_AUDIO; if (output(s, kind, 0, &p) < 0) { close_viewer(s, STREAM_VIEWER_CLOSED, STREAM_CLOSE_FAILED); break; } count++; bytes += s->tail->length; @@ -193,7 +199,7 @@ static void process(void *arg) { close_viewer(s, STREAM_VIEWER_CLOSED, STREAM_CLOSE_FAILED); break; } } while (count < s->records && bytes < 256u * 1024u && get_time_us() - began < 2000 && (video || s->audio_ahead >= 0)); - if (!s->handle) continue; + if (!s->handle || (s->tail && s->tail->kind == STREAM_VIEWER_GAP)) continue; if (stream_media_get_status(s->handle, &s->status) < 0) { DEBUG_ERROR(DEBUG_CATEGORY_STREAM, "viewer batch status failed id=%llu", (unsigned long long)s->id); close_viewer(s, STREAM_VIEWER_CLOSED, STREAM_CLOSE_FAILED); diff --git a/tools/chatgui/src/streamplayer_window.cpp b/tools/chatgui/src/streamplayer_window.cpp index 8bfa49dc..7568d822 100644 --- a/tools/chatgui/src/streamplayer_window.cpp +++ b/tools/chatgui/src/streamplayer_window.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -57,6 +58,9 @@ struct StreamPlayerWindow::Playback { uint64_t audioGeneration = 0; std::thread worker; std::mutex lock; + std::mutex wakeLock; + std::condition_variable wake; + uint64_t wakeVersion = 0, dataSignals = 0; std::deque