coreaudio-encoder: Fix pts/dts not including encoder delay #10690
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Note
Requires #10689 to be fully functional as currently OBS will not treat negative audio timestamps correctly.
CoreAudio - and other AAC encoders - generally have an encoder delay that produces a number of silent "priming" samples. For CoreAudio AAC this is 2112 by default and this needs to be subtracted from the PTS/DTS to ensure that PTS 0 is the actual start of the input audio.
See Apple's documentation for a good explanation of AAC encoder delay and how to deal with it: https://web.archive.org/web/20170912012230/https://developer.apple.com/library/content/documentation/QuickTime/QTFF/QTFFAppenG/QTFFAppenG.html
Motivation and Context
Want audio to be in sync.
When using FFmpeg encoders libavcodec already handles this for us. This is also already done in the libfdk-aac module: https://github.com/obsproject/obs-studio/blob/master/plugins/obs-libfdk/obs-libfdk.c#L266-L272
How Has This Been Tested?
Validated on Windows that output DTS/PTS is now correct.
Types of changes
Checklist: