mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1238906 - part1 : check whether audio data is audible. r=jwwang
This commit is contained in:
parent
aea33f9f42
commit
f430bca6bf
@ -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,
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user