diff options
Diffstat (limited to 'src/wx/film_viewer.cc')
| -rw-r--r-- | src/wx/film_viewer.cc | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index b01498fc8..dcee453d4 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -88,6 +88,8 @@ rtaudio_callback(void* out, void *, unsigned int frames, double, RtAudioStreamSt FilmViewer::FilmViewer(wxWindow* p, bool wake) : _closed_captions_dialog(new ClosedCaptionsDialog(p, this)) + , _stream_time(0) + , _stream_time_update_needed(true) { #if wxCHECK_VERSION(3, 1, 0) switch (Config::instance()->video_view_type()) { @@ -353,7 +355,8 @@ FilmViewer::start_audio_stream_if_open() auto& audio = AudioBackend::instance()->rtaudio(); if (audio.isStreamOpen()) { - audio.setStreamTime(_video_view->position().seconds()); + _stream_time = _video_view->position().seconds(); + _stream_time_update_needed = true; auto error = AudioBackend::instance()->start_stream(); if (error) { _audio_channels = 0; @@ -696,7 +699,7 @@ FilmViewer::uncorrected_time() const auto& audio = AudioBackend::instance()->rtaudio(); if (audio.isStreamRunning()) { - return DCPTime::from_seconds(audio.getStreamTime()); + return DCPTime::from_seconds(_stream_time); } return _video_view->position(); @@ -712,8 +715,7 @@ FilmViewer::audio_time() const return {}; } - return DCPTime::from_seconds(audio.getStreamTime()) - - DCPTime::from_frames(average_latency(), _film->audio_frame_rate()); + return DCPTime::from_seconds(_stream_time) - DCPTime::from_frames(average_latency(), _film->audio_frame_rate()); } @@ -727,6 +729,15 @@ FilmViewer::time() const int FilmViewer::audio_callback(void* out_p, unsigned int frames) { + auto& audio = AudioBackend::instance()->rtaudio(); + + if (_stream_time_update_needed) { + audio.setStreamTime(_stream_time); + _stream_time_update_needed = false; + } else { + _stream_time = audio.getStreamTime(); + } + while (true) { auto t = _butler->get_audio(Butler::Behaviour::NON_BLOCKING, reinterpret_cast<float*>(out_p), frames); if (!t || DCPTime(uncorrected_time() - *t) < one_video_frame()) { @@ -736,10 +747,7 @@ FilmViewer::audio_callback(void* out_p, unsigned int frames) /* The audio we just got was (very) late; drop it and get some more. */ } - auto& audio = AudioBackend::instance()->rtaudio(); - - boost::mutex::scoped_lock lm(_latency_history_mutex, boost::try_to_lock); - if (lm) { + if (auto lm = boost::mutex::scoped_lock(_latency_history_mutex, boost::try_to_lock)) { _latency_history.push_back(audio.getStreamLatency()); if (_latency_history.size() > static_cast<size_t>(_latency_history_count)) { _latency_history.pop_front(); |
