Bug 1388660 - part1 : AudioData::IsAudible() should return false when its data is super small and near to zero. draft
authorAlastor Wu <alwu@mozilla.com>
Thu, 17 Aug 2017 11:02:11 +0800
changeset 647916 96ab14bec031f2dfe05d9daa9cd02fe1d680a1d1
parent 647355 9ab2470a3210324bc11320531b15d195aaf05051
child 647917 ed5b95c2fda8192327f862c79c1b50550c569e7b
push id74583
push useralwu@mozilla.com
push dateThu, 17 Aug 2017 03:11:01 +0000
bugs1388660
milestone57.0a1
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
dom/media/MediaData.cpp
--- 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 */