зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
655566a1f5
Коммит
f57c5ad7ab
|
@ -2417,11 +2417,14 @@ static void MoveToSegment(SourceMediaTrack* aTrack, MediaSegment* aIn,
|
|||
MOZ_ASSERT(aDesiredUpToTime >= aCurrentTime);
|
||||
if (aIn->GetType() == MediaSegment::AUDIO) {
|
||||
AudioSegment* in = static_cast<AudioSegment*>(aIn);
|
||||
AudioSegment* out = static_cast<AudioSegment*>(aOut);
|
||||
TrackTime desiredDurationToMove = aDesiredUpToTime - aCurrentTime;
|
||||
TrackTime end = std::min(in->GetDuration(), desiredDurationToMove);
|
||||
|
||||
aOut->AppendSlice(*in, 0, end);
|
||||
out->AppendSlice(*in, 0, end);
|
||||
in->RemoveLeading(end);
|
||||
|
||||
out->ApplyVolume(aTrack->GetVolumeLocked());
|
||||
} else {
|
||||
VideoSegment* in = static_cast<VideoSegment*>(aIn);
|
||||
VideoSegment* out = static_cast<VideoSegment*>(aOut);
|
||||
|
@ -2709,6 +2712,16 @@ void SourceMediaTrack::RemoveAllDirectListenersImpl() {
|
|||
mDirectTrackListeners.Clear();
|
||||
}
|
||||
|
||||
void SourceMediaTrack::SetVolume(float aVolume) {
|
||||
MutexAutoLock lock(mMutex);
|
||||
mVolume = aVolume;
|
||||
}
|
||||
|
||||
float SourceMediaTrack::GetVolumeLocked() {
|
||||
mMutex.AssertCurrentThreadOwns();
|
||||
return mVolume;
|
||||
}
|
||||
|
||||
SourceMediaTrack::~SourceMediaTrack() {}
|
||||
|
||||
void MediaInputPort::Init() {
|
||||
|
|
|
@ -682,6 +682,11 @@ class SourceMediaTrack : public MediaTrack {
|
|||
|
||||
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;
|
||||
|
||||
protected:
|
||||
|
@ -737,6 +742,7 @@ class SourceMediaTrack : public MediaTrack {
|
|||
// held together.
|
||||
Mutex mMutex;
|
||||
// protected by mMutex
|
||||
float mVolume = 1.0;
|
||||
UniquePtr<TrackData> mUpdateTrack;
|
||||
nsTArray<RefPtr<DirectMediaTrackListener>> mDirectTrackListeners;
|
||||
};
|
||||
|
|
|
@ -492,6 +492,9 @@ nsresult DecodedStream::Start(const TimeUnit& aStartTime,
|
|||
mVideoEndedPromise = mData->mVideoEndedPromise;
|
||||
mOutputListener = mData->OnOutput().Connect(mOwnerThread, this,
|
||||
&DecodedStream::NotifyOutput);
|
||||
if (mData->mAudioTrack) {
|
||||
mData->mAudioTrack->SetVolume(static_cast<float>(mVolume));
|
||||
}
|
||||
SendData();
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -560,6 +563,9 @@ void DecodedStream::SetPlaying(bool aPlaying) {
|
|||
void DecodedStream::SetVolume(double aVolume) {
|
||||
AssertOwnerThread();
|
||||
mVolume = aVolume;
|
||||
if (mData && mData->mAudioTrack) {
|
||||
mData->mAudioTrack->SetVolume(static_cast<float>(aVolume));
|
||||
}
|
||||
}
|
||||
|
||||
void DecodedStream::SetPlaybackRate(double aPlaybackRate) {
|
||||
|
@ -651,8 +657,6 @@ void DecodedStream::SendAudio(double aVolume,
|
|||
aPrincipalHandle);
|
||||
}
|
||||
|
||||
output.ApplyVolume(aVolume);
|
||||
|
||||
// |mNextAudioTime| is updated as we process each audio sample in
|
||||
// SendStreamAudio().
|
||||
if (output.GetDuration() > 0) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче