]> git.sesse.net Git - nageru/blobdiff - nageru/ffmpeg_capture.cpp
Fix an issue where Matroska HTTP FFmpeg streams would not correctly restart on connec...
[nageru] / nageru / ffmpeg_capture.cpp
index 1c7a30f2e82e1245574174420a145c7fa8b8ee0f..9beea857dd3ed41bdb69df3fae26cfe5123bb305 100644 (file)
@@ -451,6 +451,10 @@ bool FFmpegCapture::play_video(const string &pathname)
                if (process_queued_commands(format_ctx.get(), pathname, last_modified, /*rewound=*/nullptr)) {
                        return true;
                }
+               if (should_interrupt.load()) {
+                       // Check as a failsafe, so that we don't need to rely on avio if we don't have to.
+                       return false;
+               }
                UniqueFrame audio_frame = audio_frame_allocator->alloc_frame();
                AudioFormat audio_format;
 
@@ -463,6 +467,11 @@ bool FFmpegCapture::play_video(const string &pathname)
                }
                if (frame == nullptr) {
                        // EOF. Loop back to the start if we can.
+                       if (format_ctx->pb != nullptr && format_ctx->pb->seekable == 0) {
+                               // Not seekable (but seemingly, sometimes av_seek_frame() would return 0 anyway,
+                               // so don't try).
+                               return true;
+                       }
                        if (av_seek_frame(format_ctx.get(), /*stream_index=*/-1, /*timestamp=*/0, /*flags=*/0) < 0) {
                                fprintf(stderr, "%s: Rewind failed, not looping.\n", pathname.c_str());
                                return true;