Bug 1692903 - Set mLiveFramesAppended in NotifyInputData instead of the first Pull. r=padenot

In a case where the packetizer is used and NotifyInputData receives less than a
full packet on the first notification, the first Pull of input data will not
happen during the same iteration.

During the iteration where the first Pull of input data happens, commonly the
following iteration, the appropriate amount of buffering will be calculated.
This calculation will fail to accomodate the silence added in the Pulls since
input data was added to the packetizer but where no input data was pulled.

Thus when input data is pulled we get more than expected out of the packetizer,
and this sets off an assert.

In practice on a non-debug build this patch means that latency is consistently
low (10ms + 128 frames with the packetizer, 128 frames without). Without this
patch it could be up to a packet (10ms) higher when using the packetizer.

Differential Revision: https://phabricator.services.mozilla.com/D105302
This commit is contained in:
Andreas Pehrson 2021-02-17 21:48:33 +00:00
Родитель 04f4cf76f7
Коммит f0d20add62
1 изменённых файлов: 3 добавлений и 15 удалений

Просмотреть файл

@ -821,12 +821,9 @@ void AudioInputProcessing::Pull(MediaTrackGraphImpl* aGraph, GraphTime aFrom,
if (MOZ_LIKELY(mLiveFramesAppended)) {
if (MOZ_UNLIKELY(buffering > mLiveBufferingAppended)) {
// We need to buffer more data, to cover for pending data in the
// We need to buffer more data. This could happen the first time we pull
// input data, or the first iteration after starting to use the
// packetizer.
MOZ_ASSERT(!PassThrough(aGraph), "Must have turned off passthrough");
MOZ_ASSERT(mPacketizerInput);
MOZ_ASSERT((buffering - mLiveBufferingAppended) ==
mPacketizerInput->mPacketSize);
LOG_FRAME("AudioInputProcessing %p Inserting %" PRId64
" frames of silence due to buffer increase",
this, buffering - mLiveBufferingAppended);
@ -849,16 +846,6 @@ void AudioInputProcessing::Pull(MediaTrackGraphImpl* aGraph, GraphTime aFrom,
}
if (mSegment.GetDuration() > 0) {
if (!mLiveFramesAppended) {
// First real data being pulled in. Add the appropriate amount of
// buffering before the real data to avoid glitches.
LOG_FRAME("AudioInputProcessing %p Buffering %" PRId64
" frames of pre-silence for %u channels.",
this, buffering, mRequestedInputChannelCount);
mSegment.InsertNullDataAtStart(buffering - mLiveBufferingAppended);
mLiveFramesAppended = true;
mLiveBufferingAppended = buffering;
}
MOZ_ASSERT(buffering == mLiveBufferingAppended);
TrackTime frames = std::min(mSegment.GetDuration(), delta);
LOG_FRAME("AudioInputProcessing %p Appending %" PRId64
@ -1175,6 +1162,7 @@ void AudioInputProcessing::NotifyInputData(MediaTrackGraphImpl* aGraph,
if (!mLiveFramesAppended) {
// First time we see live frames getting added. Use what's already buffered
// in the driver's scratch buffer as a starting point.
mLiveFramesAppended = true;
mLiveBufferingAppended = aAlreadyBuffered;
}