]> git.sesse.net Git - nageru/blobdiff - nageru/ffmpeg_capture.cpp
Move texture uploading out of a lambda.
[nageru] / nageru / ffmpeg_capture.cpp
index 0c3aa57bcfde150a221ec86bcc72a253ee606e37..87d1c007e9142a07e21b2c49820c706709b45c26 100644 (file)
@@ -286,6 +286,11 @@ FFmpegCapture::~FFmpegCapture()
                dequeue_cleanup_callback();
        }
        swr_free(&resampler);
+#ifdef HAVE_SRT
+       if (srt_sock != -1) {
+               srt_close(srt_sock);
+       }
+#endif
 }
 
 void FFmpegCapture::configure_card()
@@ -589,6 +594,22 @@ bool FFmpegCapture::play_video(const string &pathname)
                }
 
                VideoFormat video_format = construct_video_format(frame.get(), video_timebase);
+               if (video_format.frame_rate_nom == 0 || video_format.frame_rate_den == 0) {
+                       // Invalid frame rate; try constructing it from the previous frame length.
+                       // (This is especially important if we are the master card, for SRT,
+                       // since it affects audio. Not all senders have good timebases
+                       // (e.g., Larix rounds first to timebase 1000 and then multiplies by
+                       // 90 from there, it seems), but it's much better to have an oscillating
+                       // value than just locking at 60.
+                       if (last_pts != 0 && frame->pts > last_pts) {
+                               int64_t pts_diff = frame->pts - last_pts;
+                               video_format.frame_rate_nom = video_timebase.den;
+                               video_format.frame_rate_den = video_timebase.num * pts_diff;
+                       } else {
+                               video_format.frame_rate_nom = 60;
+                               video_format.frame_rate_den = 1;
+                       }
+               }
                UniqueFrame video_frame = make_video_frame(frame.get(), pathname, &error);
                if (error) {
                        return false;
@@ -932,11 +953,6 @@ VideoFormat FFmpegCapture::construct_video_format(const AVFrame *frame, AVRation
        }
        video_format.frame_rate_nom = video_timebase.den;
        video_format.frame_rate_den = frame->pkt_duration * video_timebase.num;
-       if (video_format.frame_rate_nom == 0 || video_format.frame_rate_den == 0) {
-               // Invalid frame rate.
-               video_format.frame_rate_nom = 60;
-               video_format.frame_rate_den = 1;
-       }
        video_format.has_signal = true;
        video_format.is_connected = true;
        return video_format;