]> git.sesse.net Git - nageru/commitdiff
Make FFmpegCapture send semi-reasonable timestamps with its audio data.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 11 Apr 2018 17:03:03 +0000 (19:03 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 11 Apr 2018 17:03:03 +0000 (19:03 +0200)
ffmpeg_capture.cpp
resampling_queue.cpp

index b8010d08219b52e30479b299822550ac8a850519..e7f25e3750a88237a66bda46c7425e7a953db2fd 100644 (file)
@@ -463,6 +463,7 @@ bool FFmpegCapture::play_video(const string &pathname)
                        }
                        next_frame_start = compute_frame_start(frame->pts, pts_origin, video_timebase, start, rate);
                        video_frame->received_timestamp = next_frame_start;
+                       audio_frame->received_timestamp = next_frame_start;
                        bool finished_wakeup = producer_thread_should_quit.sleep_until(next_frame_start);
                        if (finished_wakeup) {
                                if (audio_frame->len > 0) {
index 24811ebe5bbab43fa7cd68471c4ca69f82e673e8..df0c335447d7fad746be1fbb176be6716cbe4590 100644 (file)
@@ -49,6 +49,8 @@ void ResamplingQueue::add_input_samples(steady_clock::time_point ts, const float
                return;
        }
 
+       assert(duration<double>(ts.time_since_epoch()).count() >= 0.0);
+
        bool good_sample = (rate_adjustment_policy == ADJUST_RATE);
        if (good_sample && a1.good_sample) {
                a0 = a1;
@@ -88,8 +90,10 @@ bool ResamplingQueue::get_output_samples(steady_clock::time_point ts, float *sam
                // good point. Note that we could be extrapolating backward or
                // forward, depending on the timing of the calls.
                const InputPoint &base_point = a1.good_sample ? a1 : a0;
+               assert(duration<double>(base_point.ts.time_since_epoch()).count() >= 0.0);
                const double input_samples_received = base_point.input_samples_received +
                        current_estimated_freq_in * duration<double>(ts - base_point.ts).count();
+               assert(input_samples_received >= 0.0);
 
                // Estimate the number of input samples _consumed_ after we've run the resampler.
                const double input_samples_consumed = total_consumed_samples +