Fix random audio dropouts and corruption of audio data (1/2)#6133
Fix random audio dropouts and corruption of audio data (1/2)#6133floele wants to merge 1 commit intoobsproject:masterfrom
Conversation
|
Hi, still testing, but tried using the 2022-03-12-85e941123-27.2.0-win64 that you posted 6 days ago, but I try record I get "Starting the output failed". Tried with NVENC and x264. Not sure what is wrong? Is this build even intended for testing? Thanks |
Previously, source->next_audio_ts_min was incremented by conv_frames_to_time(sample_rate, in.frames) in each call of source_output_audio_data(), so only by the duration of the audio data itself. However, this does not take the current timestamp into account, which also includes execution time (audio source timestamps are not necessarily continuous). This causes the incoming audio timestamp to gradually deviate further from the expected next_audio_ts_min timestamp, eventually exceeding TS_SMOOTHING_THRESHOLD and then causing a call to source_output_audio_place() which either overwrites existing audio data and causes a glitch or puts data beyond the end of the buffer, inserting a gap and thus causing a dropout. Now use incoming timestamp for calculation of the next minimum timestamp.
5c2d27c to
0351889
Compare
|
Hi @Stuwot, looks like you're right, I apparently based it on a broken version of OBS. Updated it now, please try again :) As for audio/video sync issues, please check the following things:
|
|
Does the delay accumulate over time or is there a fixed delay across the whole recording? To be clear too: the audio goes out of sync on things like camera to microphone, but also capturing a Chrome window and playing Youtube video, the audio on the video slips out of sync. Can the same delay be seen in regular OBS versions too? Possibly the sync issue does not happen every time so you might want to try a few recordings with each version. Finally, it would be good to know if you experience the issue with builds from both of my PRs or only the second one which includes both changes. I would assume that the changes made with this PR (only one of two issues fixed) have no impact on audio/video sync. Thanks! |
|
Sorry, just another update. In the OBS-Studio-27.2.0-5cd247710-Win64 build, the browser seems to be broken. Nothing displays, local or remote. Not sure why. |
Any behaviours you see outside of audio is due to unrelated changes in the OBS master branch. We completely overhauled how we build OBS, so we expect things to be broken while we figure it out. |
Ahhh ok. Understood! Thanks! |
|
@Lain-B Is this actually a desirable change? As @norihiro pointed out in the original PR, the audio subsystem runs on its own timer and calculates "expected" timestamps for incoming audio packets accordingly. A minor deviation of device timestamps to this internal timestamp is baked into the code (we just treat incoming audio packets as having arrived at the calculated timestamp then). A runaway difference (as explained in the OP) could only happen if the source is not able to consistently produce new audio packets within 70µs of the calculated timestamps (in my tests with CoreAudio, differences sat between 7µs and 21µs) but instead takes considerably longer every time. Wouldn't that be indicative of an issue with the audio device or the subsystem then? |
Description
This is the first part of the original PR #5993. Would appreciate a "Seeking testers" so we can test this change separately from the other one if in doubt about side effects.
Previously,
source->next_audio_ts_minwas incremented byconv_frames_to_time(sample_rate, in.frames)in each call ofsource_output_audio_data(), so only by the duration of the audio data which is basically a fixed value (ifin.framesdoesn't vary).However, this does not take the incoming audio timestamps into account, which also include execution time. In
ProcessCaptureData()for exampleos_gettime_ns()is used to generate the audio timestamp if device timestamps are off so it's unavoidable that the incoming timestamps are always a little later than the raw duration of the audio data. This also applies if device timestamps are enabled though, at least when recording from desktop audio (Windows 10) which I have used to verify the issue.This adds up, because
in.timestampis being set tosource->next_audio_ts_minbefore calculating the next timestampsource->next_audio_ts_min = in.timestamp + conv_frames_to_time(sample_rate, in.frames).If you watch the values over time, you can see the timestamps deviating like this (extract of a few thousand iterations):
So the incoming audio timestamps gradually deviate further from the expected
next_audio_ts_mintimestamp, eventually exceedingTS_SMOOTHING_THRESHOLDand then causing a call tosource_output_audio_place()which either overwrites existing audio data and causes a glitch or puts data beyond the end of the buffer, resizing it and inserting a gap and thus causing an audio dropout.Now
next_audio_ts_minis incremented based on the current incoming audio timestamp to prevent this issue.For testing purposes, this issue can be detected by looking for "frames: %lu, size: %lu, placement: %lu, base_ts: %llu, ts: %llu" debug messages (with DEBUG_AUDIO enabled).
Motivation and Context
Fixes #4600 (one of the two kinds of dropouts investigated).
In short, audio recorded or streamed by OBS contains random short dropouts or corruption, independently of settings and environment, though frequency may vary. The frequency of the issue occuring ranges from every couple of minutes to maybe once or twice per hour based on my observations and the reports in the mentioned issue.
How Has This Been Tested?
For my tests I use a test tone generator to record continuous uniform audio data with OBS (default settings, Windows 10). I then check the resulting audio stream for dropouts. For testing, I usually record 1 to 2 h of audio data.
Types of changes
Checklist: