Bug 1388660 - part1 : AudioData::IsAudible() should return false when its data is super small and near to zero.
When the value of data is too small to be heard, AudioData::IsAudible() should return false so that we won't show the sound indicator for silent media.
In this case, the loudness of reported video is -673 dBFS, it's impossible to be heard.
MozReview-Commit-ID: Ewiko7RpkeX
--- a/dom/media/MediaData.cpp
+++ b/dom/media/MediaData.cpp
@@ -26,16 +26,26 @@ using namespace mozilla::gfx;
using layers::ImageContainer;
using layers::PlanarYCbCrImage;
using layers::PlanarYCbCrData;
using media::TimeUnit;
const char* AudioData::sTypeName = "audio";
const char* VideoData::sTypeName = "video";
+bool
+IsDataLoudnessHearable(const AudioDataValue aData)
+{
+ // We can transfer the digital value to dBFS via following formula. According
+ // to American SMPTE standard, 0 dBu equals -20 dBFS. In theory 0 dBu is still
+ // hearable, so we choose a smaller value as our threshold. If the loudness
+ // is under this threshold, it might not be hearable.
+ return 20.0f * std::log10(AudioSampleToFloat(aData)) > -100;
+}
+
void
AudioData::EnsureAudioBuffer()
{
if (mAudioBuffer)
return;
mAudioBuffer = SharedBuffer::Create(mFrames*mChannels*sizeof(AudioDataValue));
AudioDataValue* data = static_cast<AudioDataValue*>(mAudioBuffer->Data());
@@ -61,17 +71,17 @@ bool
AudioData::IsAudible() const
{
if (!mAudioData) {
return false;
}
for (uint32_t frame = 0; frame < mFrames; ++frame) {
for (uint32_t channel = 0; channel < mChannels; ++channel) {
- if (mAudioData[frame * mChannels + channel] != 0) {
+ if (IsDataLoudnessHearable(mAudioData[frame * mChannels + channel])) {
return true;
}
}
}
return false;
}
/* static */