Bug 1443511 - Apply HTMLMediaElement volume to currently playing audio segments. r=pehrsons

Rather than applying the volume change to the DecodedStream, which won't be
played until the buffer catches up, instead apply the volume to the segments
as they are consumed by the MediaTrackGraph.

Differential Revision: https://phabricator.services.mozilla.com/D56276

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jon Bauman 2019-12-12 23:41:13 +00:00
Родитель 655566a1f5
Коммит f57c5ad7ab
3 изменённых файлов: 26 добавлений и 3 удалений

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

@ -2417,11 +2417,14 @@ static void MoveToSegment(SourceMediaTrack* aTrack, MediaSegment* aIn,
MOZ_ASSERT(aDesiredUpToTime >= aCurrentTime); MOZ_ASSERT(aDesiredUpToTime >= aCurrentTime);
if (aIn->GetType() == MediaSegment::AUDIO) { if (aIn->GetType() == MediaSegment::AUDIO) {
AudioSegment* in = static_cast<AudioSegment*>(aIn); AudioSegment* in = static_cast<AudioSegment*>(aIn);
AudioSegment* out = static_cast<AudioSegment*>(aOut);
TrackTime desiredDurationToMove = aDesiredUpToTime - aCurrentTime; TrackTime desiredDurationToMove = aDesiredUpToTime - aCurrentTime;
TrackTime end = std::min(in->GetDuration(), desiredDurationToMove); TrackTime end = std::min(in->GetDuration(), desiredDurationToMove);
aOut->AppendSlice(*in, 0, end); out->AppendSlice(*in, 0, end);
in->RemoveLeading(end); in->RemoveLeading(end);
out->ApplyVolume(aTrack->GetVolumeLocked());
} else { } else {
VideoSegment* in = static_cast<VideoSegment*>(aIn); VideoSegment* in = static_cast<VideoSegment*>(aIn);
VideoSegment* out = static_cast<VideoSegment*>(aOut); VideoSegment* out = static_cast<VideoSegment*>(aOut);
@ -2709,6 +2712,16 @@ void SourceMediaTrack::RemoveAllDirectListenersImpl() {
mDirectTrackListeners.Clear(); mDirectTrackListeners.Clear();
} }
void SourceMediaTrack::SetVolume(float aVolume) {
MutexAutoLock lock(mMutex);
mVolume = aVolume;
}
float SourceMediaTrack::GetVolumeLocked() {
mMutex.AssertCurrentThreadOwns();
return mVolume;
}
SourceMediaTrack::~SourceMediaTrack() {} SourceMediaTrack::~SourceMediaTrack() {}
void MediaInputPort::Init() { void MediaInputPort::Init() {

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

@ -682,6 +682,11 @@ class SourceMediaTrack : public MediaTrack {
void RemoveAllDirectListenersImpl() override; void RemoveAllDirectListenersImpl() override;
// The value set here is applied in MoveToSegment so we can avoid the
// buffering delay in applying the change. See Bug 1443511.
void SetVolume(float aVolume);
float GetVolumeLocked();
friend class MediaTrackGraphImpl; friend class MediaTrackGraphImpl;
protected: protected:
@ -737,6 +742,7 @@ class SourceMediaTrack : public MediaTrack {
// held together. // held together.
Mutex mMutex; Mutex mMutex;
// protected by mMutex // protected by mMutex
float mVolume = 1.0;
UniquePtr<TrackData> mUpdateTrack; UniquePtr<TrackData> mUpdateTrack;
nsTArray<RefPtr<DirectMediaTrackListener>> mDirectTrackListeners; nsTArray<RefPtr<DirectMediaTrackListener>> mDirectTrackListeners;
}; };

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

@ -492,6 +492,9 @@ nsresult DecodedStream::Start(const TimeUnit& aStartTime,
mVideoEndedPromise = mData->mVideoEndedPromise; mVideoEndedPromise = mData->mVideoEndedPromise;
mOutputListener = mData->OnOutput().Connect(mOwnerThread, this, mOutputListener = mData->OnOutput().Connect(mOwnerThread, this,
&DecodedStream::NotifyOutput); &DecodedStream::NotifyOutput);
if (mData->mAudioTrack) {
mData->mAudioTrack->SetVolume(static_cast<float>(mVolume));
}
SendData(); SendData();
} }
return NS_OK; return NS_OK;
@ -560,6 +563,9 @@ void DecodedStream::SetPlaying(bool aPlaying) {
void DecodedStream::SetVolume(double aVolume) { void DecodedStream::SetVolume(double aVolume) {
AssertOwnerThread(); AssertOwnerThread();
mVolume = aVolume; mVolume = aVolume;
if (mData && mData->mAudioTrack) {
mData->mAudioTrack->SetVolume(static_cast<float>(aVolume));
}
} }
void DecodedStream::SetPlaybackRate(double aPlaybackRate) { void DecodedStream::SetPlaybackRate(double aPlaybackRate) {
@ -651,8 +657,6 @@ void DecodedStream::SendAudio(double aVolume,
aPrincipalHandle); aPrincipalHandle);
} }
output.ApplyVolume(aVolume);
// |mNextAudioTime| is updated as we process each audio sample in // |mNextAudioTime| is updated as we process each audio sample in
// SendStreamAudio(). // SendStreamAudio().
if (output.GetDuration() > 0) { if (output.GetDuration() > 0) {