Skip to content

Commit

Permalink
Workaround WebM playback bug after AudioServer latency fixes
Browse files Browse the repository at this point in the history
af9bb0e fixed AudioServer's
`get_output_delay()` (which used to always return 0) while renaming it
to `get_output_latency()`. It now returns the latency from the
AudioDriver, which can be non-0.

While this was a clear bugfix, it broke playback for WebM files without
audio track. It seems like the playback code, even though it queried
the output delay to calculate a time compensation, was designed to work
even though the delay value was actually bogus. Now that it's correct,
it's not working.

As a workaround we comment out uses of the output latency, restoring
the behavior of Godot 3.1.

This code should still be reviewed by someone more versed in video
playback and fixed to properly account for the non-0 driver latency.

Fixes godotengine#35760.

(cherry picked from commit da411d1)
  • Loading branch information
akien-mga committed Feb 14, 2020
1 parent 3b2490f commit ac63e5d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 4 additions & 2 deletions modules/theora/video_stream_theora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,10 @@ void VideoStreamPlaybackTheora::set_file(const String &p_file) {
};

float VideoStreamPlaybackTheora::get_time() const {

return time - AudioServer::get_singleton()->get_output_latency() - delay_compensation; //-((get_total())/(float)vi.rate);
// FIXME: AudioServer output latency was fixed in af9bb0e, previously it used to
// systematically return 0. Now that it gives a proper latency, it broke this
// code where the delay compensation likely never really worked.
return time - /* AudioServer::get_singleton()->get_output_latency() - */ delay_compensation;
};

Ref<Texture> VideoStreamPlaybackTheora::get_texture() const {
Expand Down
15 changes: 10 additions & 5 deletions modules/webm/video_stream_webm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,17 +393,22 @@ int VideoStreamPlaybackWebm::get_mix_rate() const {

inline bool VideoStreamPlaybackWebm::has_enough_video_frames() const {
if (video_frames_pos > 0) {

const double audio_delay = AudioServer::get_singleton()->get_output_latency();
// FIXME: AudioServer output latency was fixed in af9bb0e, previously it used to
// systematically return 0. Now that it gives a proper latency, it broke this
// code where the delay compensation likely never really worked.
//const double audio_delay = AudioServer::get_singleton()->get_output_latency();
const double video_time = video_frames[video_frames_pos - 1]->time;
return video_time >= time + audio_delay + delay_compensation;
return video_time >= time + /* audio_delay + */ delay_compensation;
}
return false;
}

bool VideoStreamPlaybackWebm::should_process(WebMFrame &video_frame) {
const double audio_delay = AudioServer::get_singleton()->get_output_latency();
return video_frame.time >= time + audio_delay + delay_compensation;
// FIXME: AudioServer output latency was fixed in af9bb0e, previously it used to
// systematically return 0. Now that it gives a proper latency, it broke this
// code where the delay compensation likely never really worked.
//const double audio_delay = AudioServer::get_singleton()->get_output_latency();
return video_frame.time >= time + /* audio_delay + */ delay_compensation;
}

void VideoStreamPlaybackWebm::delete_pointers() {
Expand Down
8 changes: 2 additions & 6 deletions servers/audio_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,19 @@
/*************************************************************************/

#include "audio_server.h"

#include "core/io/resource_loader.h"
#include "core/os/file_access.h"
#include "core/os/os.h"
#include "core/project_settings.h"
#include "scene/resources/audio_stream_sample.h"
#include "servers/audio/audio_driver_dummy.h"
#include "servers/audio/effects/audio_effect_compressor.h"
#ifdef TOOLS_ENABLED

#ifdef TOOLS_ENABLED
#define MARK_EDITED set_edited(true);

#else

#define MARK_EDITED

#endif

AudioDriver *AudioDriver::singleton = NULL;
Expand Down Expand Up @@ -1405,8 +1403,6 @@ AudioServer::AudioServer() {
mix_frames = 0;
channel_count = 0;
to_mix = 0;
output_latency = 0;
output_latency_ticks = 0;
#ifdef DEBUG_ENABLED
prof_time = 0;
#endif
Expand Down
3 changes: 0 additions & 3 deletions servers/audio_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ class AudioServer : public Object {

Mutex *audio_data_lock;

float output_latency;
uint64_t output_latency_ticks;

void init_channels_and_buffers();

void _mix_step();
Expand Down

0 comments on commit ac63e5d

Please sign in to comment.