]> git.sesse.net Git - nageru/commitdiff
When we get an FFmpeg error, send a blank frame to tell the theme about the disconnec...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 29 Apr 2017 21:01:32 +0000 (23:01 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 29 Apr 2017 21:01:32 +0000 (23:01 +0200)
ffmpeg_capture.cpp
ffmpeg_capture.h

index 04038056aa13aa6747dc2b82cdce0b5f38405df5..407f359104cff8444ac56cc9480c77c86366667c 100644 (file)
@@ -138,12 +138,14 @@ void FFmpegCapture::producer_thread_func()
                string pathname = search_for_file(filename);
                if (filename.empty()) {
                        fprintf(stderr, "%s not found, sleeping one second and trying again...\n", filename.c_str());
+                       send_disconnected_frame();
                        producer_thread_should_quit.sleep_for(seconds(1));
                        continue;
                }
                if (!play_video(pathname)) {
                        // Error.
                        fprintf(stderr, "Error when playing %s, sleeping one second and trying again...\n", pathname.c_str());
+                       send_disconnected_frame();
                        producer_thread_should_quit.sleep_for(seconds(1));
                        continue;
                }
@@ -157,6 +159,28 @@ void FFmpegCapture::producer_thread_func()
         }
 }
 
+void FFmpegCapture::send_disconnected_frame()
+{
+       // Send an empty frame to signal that we have no signal anymore.
+       FrameAllocator::Frame video_frame = video_frame_allocator->alloc_frame();
+       if (video_frame.data) {
+               VideoFormat video_format;
+               video_format.width = width;
+               video_format.height = height;
+               video_format.stride = width * 4;
+               video_format.frame_rate_nom = 60;
+               video_format.frame_rate_den = 1;
+               video_format.is_connected = false;
+
+               video_frame.len = width * height * 4;
+               memset(video_frame.data, 0, video_frame.len);
+
+               frame_callback(timecode++,
+                       video_frame, /*video_offset=*/0, video_format,
+                       FrameAllocator::Frame(), /*audio_offset=*/0, AudioFormat());
+       }
+}
+
 bool FFmpegCapture::play_video(const string &pathname)
 {
        // Note: Call before open, not after; otherwise, there's a race.
index 9753c0032f37ae184a91786335bb04534be9413c..05e92e21fec5bfecd75fdcfddeee1ea7365a7c86 100644 (file)
@@ -108,9 +108,7 @@ public:
        void configure_card() override;
        void start_bm_capture() override;
        void stop_dequeue_thread() override;
-
-       // TODO: Specify error status through this.
-       bool get_disconnected() const override { return false; }
+       bool get_disconnected() const override { return false; }  // We never unplug.
 
        std::map<uint32_t, bmusb::VideoMode> get_available_video_modes() const;
        void set_video_mode(uint32_t video_mode_id) override {}  // Ignore.
@@ -139,6 +137,7 @@ public:
 
 private:
        void producer_thread_func();
+       void send_disconnected_frame();
        bool play_video(const std::string &pathname);
        void internal_rewind();