From def92d1b8e9d373e2f6f27c366d578d97d8960c6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:34:50 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- .../webspeech/recognition/SpeechRecognition.cpp | 25 +++++++++++++++++----- .../webspeech/recognition/SpeechRecognition.h | 22 +++++++++++++++++-- .../webspeech/synth/nsISynthVoiceRegistry.idl | 4 ++-- 3 files changed, 42 insertions(+), 9 deletions(-) (limited to 'dom/media/webspeech') diff --git a/dom/media/webspeech/recognition/SpeechRecognition.cpp b/dom/media/webspeech/recognition/SpeechRecognition.cpp index 7239a88237..44ad5fdd61 100644 --- a/dom/media/webspeech/recognition/SpeechRecognition.cpp +++ b/dom/media/webspeech/recognition/SpeechRecognition.cpp @@ -136,7 +136,7 @@ CreateSpeechRecognitionService(nsPIDOMWindowInner* aWindow, NS_IMPL_CYCLE_COLLECTION_WEAK_PTR_INHERITED(SpeechRecognition, DOMEventTargetHelper, mStream, mTrack, mRecognitionService, - mSpeechGrammarList) + mSpeechGrammarList, mListener) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SpeechRecognition) NS_INTERFACE_MAP_ENTRY(nsIObserver) @@ -145,6 +145,16 @@ NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) NS_IMPL_ADDREF_INHERITED(SpeechRecognition, DOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(SpeechRecognition, DOMEventTargetHelper) +NS_IMPL_CYCLE_COLLECTION_INHERITED(SpeechRecognition::TrackListener, + DOMMediaStream::TrackListener, + mSpeechRecognition) +NS_IMPL_ADDREF_INHERITED(SpeechRecognition::TrackListener, + DOMMediaStream::TrackListener) +NS_IMPL_RELEASE_INHERITED(SpeechRecognition::TrackListener, + DOMMediaStream::TrackListener) +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SpeechRecognition::TrackListener) +NS_INTERFACE_MAP_END_INHERITING(DOMMediaStream::TrackListener) + SpeechRecognition::SpeechRecognition(nsPIDOMWindowInner* aOwnerWindow) : DOMEventTargetHelper(aOwnerWindow), mEndpointer(kSAMPLE_RATE), @@ -472,8 +482,9 @@ void SpeechRecognition::Reset() { ++mStreamGeneration; if (mStream) { - mStream->UnregisterTrackListener(this); + mStream->UnregisterTrackListener(mListener); mStream = nullptr; + mListener = nullptr; } mTrack = nullptr; mTrackIsOwned = false; @@ -642,7 +653,8 @@ RefPtr SpeechRecognition::StopRecording() { if (mStream) { // Ensure we don't start recording because a track became available // before we get reset. - mStream->UnregisterTrackListener(this); + mStream->UnregisterTrackListener(mListener); + mListener = nullptr; } return GenericNonExclusivePromise::CreateAndResolve(true, __func__); } @@ -801,10 +813,13 @@ void SpeechRecognition::Start(const Optional>& aStream, MediaStreamConstraints constraints; constraints.mAudio.SetAsBoolean() = true; + MOZ_ASSERT(!mListener); + mListener = new TrackListener(this); + if (aStream.WasPassed()) { mStream = &aStream.Value(); mTrackIsOwned = false; - mStream->RegisterTrackListener(this); + mStream->RegisterTrackListener(mListener); nsTArray> tracks; mStream->GetAudioTracks(tracks); for (const RefPtr& track : tracks) { @@ -839,7 +854,7 @@ void SpeechRecognition::Start(const Optional>& aStream, return; } mStream = std::move(aStream); - mStream->RegisterTrackListener(this); + mStream->RegisterTrackListener(mListener); for (const RefPtr& track : tracks) { if (!track->Ended()) { NotifyTrackAdded(track); diff --git a/dom/media/webspeech/recognition/SpeechRecognition.h b/dom/media/webspeech/recognition/SpeechRecognition.h index 687f38041e..465cadc8cb 100644 --- a/dom/media/webspeech/recognition/SpeechRecognition.h +++ b/dom/media/webspeech/recognition/SpeechRecognition.h @@ -52,7 +52,6 @@ LogModule* GetSpeechRecognitionLog(); class SpeechRecognition final : public DOMEventTargetHelper, public nsIObserver, - public DOMMediaStream::TrackListener, public SupportsWeakPtr { public: explicit SpeechRecognition(nsPIDOMWindowInner* aOwnerWindow); @@ -133,7 +132,24 @@ class SpeechRecognition final : public DOMEventTargetHelper, EVENT_COUNT }; - void NotifyTrackAdded(const RefPtr& aTrack) override; + void NotifyTrackAdded(const RefPtr& aTrack); + + class TrackListener final : public DOMMediaStream::TrackListener { + public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TrackListener, + DOMMediaStream::TrackListener) + explicit TrackListener(SpeechRecognition* aSpeechRecognition) + : mSpeechRecognition(aSpeechRecognition) {} + void NotifyTrackAdded(const RefPtr& aTrack) override { + mSpeechRecognition->NotifyTrackAdded(aTrack); + } + + private: + virtual ~TrackListener() = default; + RefPtr mSpeechRecognition; + }; + // aMessage should be valid UTF-8, but invalid UTF-8 byte sequences are // replaced with the REPLACEMENT CHARACTER on conversion to UTF-16. void DispatchError(EventType aErrorType, @@ -266,6 +282,8 @@ class SpeechRecognition final : public DOMEventTargetHelper, // a conforming implementation. uint32_t mMaxAlternatives; + RefPtr mListener; + void ProcessTestEventRequest(nsISupports* aSubject, const nsAString& aEventName); diff --git a/dom/media/webspeech/synth/nsISynthVoiceRegistry.idl b/dom/media/webspeech/synth/nsISynthVoiceRegistry.idl index 8192eff045..e5189e0bc1 100644 --- a/dom/media/webspeech/synth/nsISynthVoiceRegistry.idl +++ b/dom/media/webspeech/synth/nsISynthVoiceRegistry.idl @@ -55,9 +55,9 @@ interface nsISynthVoiceRegistry : nsISupports AString getVoice(in uint32_t aIndex); - bool isDefaultVoice(in AString aUri); + boolean isDefaultVoice(in AString aUri); - bool isLocalVoice(in AString aUri); + boolean isLocalVoice(in AString aUri); AString getVoiceLang(in AString aUri); -- cgit v1.2.3