summaryrefslogtreecommitdiff
path: root/src/wx
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-08-04 00:01:30 +0100
committerCarl Hetherington <cth@carlh.net>2018-08-04 00:01:30 +0100
commit54e6f206305d4275808cfce36987edcc61a6a779 (patch)
treeba403ce56da8c5ce5a4a1652e83bd18855a41c01 /src/wx
parent4fe1a062eb31d680b8b4ac0191b9e2fc2d6aaec3 (diff)
Timestamp audio emissions from butler and hence discard very late
audio in FilmViewer. This should help with the case where lots of video frames are rapidly discarded when they are late but the corresponding audio is not, hence audio buffers get overfilled.
Diffstat (limited to 'src/wx')
-rw-r--r--src/wx/film_viewer.cc19
-rw-r--r--src/wx/film_viewer.h1
2 files changed, 19 insertions, 1 deletions
diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc
index ef28018e9..ce34b06b7 100644
--- a/src/wx/film_viewer.cc
+++ b/src/wx/film_viewer.cc
@@ -882,6 +882,16 @@ FilmViewer::config_changed (Config::Property p)
}
DCPTime
+FilmViewer::uncorrected_time () const
+{
+ if (_audio.isStreamRunning ()) {
+ return DCPTime::from_seconds (const_cast<RtAudio*>(&_audio)->getStreamTime());
+ }
+
+ return _video_position;
+}
+
+DCPTime
FilmViewer::time () const
{
if (_audio.isStreamRunning ()) {
@@ -895,7 +905,14 @@ FilmViewer::time () const
int
FilmViewer::audio_callback (void* out_p, unsigned int frames)
{
- _butler->get_audio (reinterpret_cast<float*> (out_p), frames);
+ while (true) {
+ optional<DCPTime> t = _butler->get_audio (reinterpret_cast<float*> (out_p), frames);
+ if (!t || DCPTime(uncorrected_time() - *t) < one_video_frame()) {
+ /* There was an underrun or this audio is on time; carry on */
+ break;
+ }
+ /* The audio we just got was (very) late; drop it and get some more. */
+ }
boost::mutex::scoped_lock lm (_latency_history_mutex, boost::try_to_lock);
if (lm) {
diff --git a/src/wx/film_viewer.h b/src/wx/film_viewer.h
index e4449fa2f..a41500ace 100644
--- a/src/wx/film_viewer.h
+++ b/src/wx/film_viewer.h
@@ -114,6 +114,7 @@ private:
void recreate_butler ();
void config_changed (Config::Property);
DCPTime time () const;
+ DCPTime uncorrected_time () const;
Frame average_latency () const;
DCPTime one_video_frame () const;