Bug 1238906 - part1 : check whether audio data is audible. r=jwwang

--HG--
extra : rebase_source : 46869a13ba565e0af5413cc2bb387e7c7e0c2df8
This commit is contained in:
Alastor Wu 2016-01-21 10:19:19 +08:00
parent d799e31aae
commit f8cd6def9a
4 changed files with 55 additions and 0 deletions

View File

@ -54,6 +54,23 @@ AudioData::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
return size;
}
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) {
return true;
}
}
}
return false;
}
/* static */
already_AddRefed<AudioData>
AudioData::TransferAndUpdateTimestampAndDuration(AudioData* aOther,

View File

@ -149,6 +149,10 @@ public:
// If mAudioBuffer is null, creates it from mAudioData.
void EnsureAudioBuffer();
// To check whether mAudioData has audible signal, it's used to distinguish
// the audiable data and silent data.
bool IsAudible() const;
const uint32_t mChannels;
const uint32_t mRate;
// At least one of mAudioBuffer/mAudioData must be non-null.

View File

@ -116,6 +116,11 @@ static const int AUDIO_DURATION_USECS = 40000;
// increase it by more.
static const int THRESHOLD_FACTOR = 2;
// When the continuous silent data is over this threshold, means the a/v does
// not produce any sound. This time is decided by UX suggestion, see
// https://bugzilla.mozilla.org/show_bug.cgi?id=1235612#c18
static const uint32_t SILENT_DATA_THRESHOLD_USECS = 10000000;
namespace detail {
// If we have less than this much undecoded data available, we'll consider
@ -236,6 +241,8 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
mOutputStreamManager(new OutputStreamManager()),
mResource(aDecoder->GetResource()),
mAudioOffloading(false),
mIsAudioDataAudible(false),
mSilentDataDuration(0),
mBuffered(mTaskQueue, TimeIntervals(),
"MediaDecoderStateMachine::mBuffered (Mirror)"),
mEstimatedDuration(mTaskQueue, NullableTimeUnit(),
@ -709,14 +716,36 @@ MediaDecoderStateMachine::PushFront(MediaData* aSample, MediaData::Type aSampleT
UpdateNextFrameStatus();
}
void
MediaDecoderStateMachine::CheckIsAudible(const MediaData* aSample)
{
MOZ_ASSERT(OnTaskQueue());
MOZ_ASSERT(aSample->mType == MediaData::AUDIO_DATA);
const AudioData* data = aSample->As<AudioData>();
bool isAudible = data->IsAudible();
if (isAudible && !mIsAudioDataAudible) {
mIsAudioDataAudible = true;
mSilentDataDuration = 0;
} else if (isAudible && mIsAudioDataAudible) {
mSilentDataDuration += data->mDuration;
if (mSilentDataDuration > SILENT_DATA_THRESHOLD_USECS) {
mIsAudioDataAudible = false;
mSilentDataDuration = 0;
}
}
}
void
MediaDecoderStateMachine::OnAudioPopped(const RefPtr<MediaData>& aSample)
{
MOZ_ASSERT(OnTaskQueue());
mPlaybackOffset = std::max(mPlaybackOffset.Ref(), aSample->mOffset);
UpdateNextFrameStatus();
DispatchAudioDecodeTaskIfNeeded();
MaybeStartBuffering();
CheckIsAudible(aSample);
}
void

View File

@ -405,6 +405,7 @@ protected:
void OnAudioPopped(const RefPtr<MediaData>& aSample);
void OnVideoPopped(const RefPtr<MediaData>& aSample);
void CheckIsAudible(const MediaData* aSample);
void VolumeChanged();
void LogicalPlaybackRateChanged();
void PreservesPitchChanged();
@ -1195,6 +1196,10 @@ private:
// Playback will not start when audio is offloading.
bool mAudioOffloading;
// Used to distiguish continuous silent audio data.
bool mIsAudioDataAudible;
uint32_t mSilentDataDuration;
#ifdef MOZ_EME
void OnCDMProxyReady(RefPtr<CDMProxy> aProxy);
void OnCDMProxyNotReady();