Bug 1754006 - Add profiler markers in push/pop operations on the AudioSink ring buffer. r=alwu

Differential Revision: https://phabricator.services.mozilla.com/D138048
This commit is contained in:
Paul Adenot 2022-02-08 16:07:44 +00:00
Родитель 7a98b07c0b
Коммит b679353753
1 изменённых файлов: 13 добавлений и 0 удалений

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

@ -16,6 +16,7 @@
#include "mozilla/StaticPrefs_media.h"
#include "mozilla/StaticPrefs_dom.h"
#include "nsPrintfCString.h"
#include "Tracing.h"
namespace mozilla {
@ -215,6 +216,11 @@ uint32_t AudioSink::PopFrames(AudioDataValue* aBuffer, uint32_t aFrames,
if (aAudioThreadChanged) {
mProcessedSPSCQueue->ResetThreadIds();
}
TRACE_COMMENT("AudioSink::PopFrames", "%u frames (ringbuffer: %u/%u)",
aFrames, SampleToFrame(mProcessedSPSCQueue->AvailableRead()),
SampleToFrame(mProcessedSPSCQueue->Capacity()));
const int samplesToPop = static_cast<int>(aFrames * mOutputChannels);
const int samplesRead = mProcessedSPSCQueue->Dequeue(aBuffer, samplesToPop);
MOZ_ASSERT(samplesRead % mOutputChannels == 0);
@ -224,6 +230,8 @@ uint32_t AudioSink::PopFrames(AudioDataValue* aBuffer, uint32_t aFrames,
SINK_LOG("Last PopFrames -- Source ended.");
} else {
NS_WARNING("Underrun when popping samples from audiosink ring buffer.");
TRACE_COMMENT("AudioSink::PopFrames", "Underrun %u frames missing",
SampleToFrame(samplesToPop - samplesRead));
}
// silence the rest
PodZero(aBuffer + samplesRead, samplesToPop - samplesRead);
@ -390,6 +398,7 @@ void AudioSink::NotifyAudioNeeded() {
} else {
silenceData = CreateAudioFromBuffer(std::move(silenceBuffer), data);
}
TRACE("Pushing silence");
PushProcessedAudio(silenceData);
}
@ -419,6 +428,10 @@ uint32_t AudioSink::PushProcessedAudio(AudioData* aData) {
return 0;
}
int framesToEnqueue = static_cast<int>(aData->Frames() * aData->mChannels);
TRACE_COMMENT("AudioSink::PushProcessedAudio", "%u frames (%u/%u)",
framesToEnqueue,
SampleToFrame(mProcessedSPSCQueue->AvailableWrite()),
SampleToFrame(mProcessedSPSCQueue->Capacity()));
DebugOnly<int> rv =
mProcessedSPSCQueue->Enqueue(aData->Data().Elements(), framesToEnqueue);
NS_WARNING_ASSERTION(