summaryrefslogtreecommitdiffstats
path: root/dom/media/webspeech
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-15 03:34:42 +0000
commitda4c7e7ed675c3bf405668739c3012d140856109 (patch)
treecdd868dba063fecba609a1d819de271f0d51b23e /dom/media/webspeech
parentAdding upstream version 125.0.3. (diff)
downloadfirefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz
firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/webspeech')
-rw-r--r--dom/media/webspeech/recognition/SpeechRecognition.cpp25
-rw-r--r--dom/media/webspeech/recognition/SpeechRecognition.h22
-rw-r--r--dom/media/webspeech/synth/nsISynthVoiceRegistry.idl4
3 files changed, 42 insertions, 9 deletions
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<GenericNonExclusivePromise> 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<NonNull<DOMMediaStream>>& 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<RefPtr<AudioStreamTrack>> tracks;
mStream->GetAudioTracks(tracks);
for (const RefPtr<AudioStreamTrack>& track : tracks) {
@@ -839,7 +854,7 @@ void SpeechRecognition::Start(const Optional<NonNull<DOMMediaStream>>& aStream,
return;
}
mStream = std::move(aStream);
- mStream->RegisterTrackListener(this);
+ mStream->RegisterTrackListener(mListener);
for (const RefPtr<AudioStreamTrack>& 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<MediaStreamTrack>& aTrack) override;
+ void NotifyTrackAdded(const RefPtr<MediaStreamTrack>& 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<MediaStreamTrack>& aTrack) override {
+ mSpeechRecognition->NotifyTrackAdded(aTrack);
+ }
+
+ private:
+ virtual ~TrackListener() = default;
+ RefPtr<SpeechRecognition> 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<TrackListener> 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);