Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_dom_nsSpeechTask_h
8 : #define mozilla_dom_nsSpeechTask_h
9 :
10 : #include "MediaStreamGraph.h"
11 : #include "SpeechSynthesisUtterance.h"
12 : #include "nsIAudioChannelAgent.h"
13 : #include "nsISpeechService.h"
14 :
15 : namespace mozilla {
16 :
17 : class SharedBuffer;
18 :
19 : namespace dom {
20 :
21 : class SpeechSynthesisUtterance;
22 : class SpeechSynthesis;
23 : class SynthStreamListener;
24 :
25 : class nsSpeechTask : public nsISpeechTask
26 : , public nsIAudioChannelAgentCallback
27 : , public nsSupportsWeakReference
28 : {
29 : friend class SynthStreamListener;
30 :
31 : public:
32 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
33 0 : NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsSpeechTask, nsISpeechTask)
34 :
35 : NS_DECL_NSISPEECHTASK
36 : NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK
37 :
38 : explicit nsSpeechTask(SpeechSynthesisUtterance* aUtterance);
39 : nsSpeechTask(float aVolume, const nsAString& aText);
40 :
41 : virtual void Pause();
42 :
43 : virtual void Resume();
44 :
45 : virtual void Cancel();
46 :
47 : virtual void ForceEnd();
48 :
49 : float GetCurrentTime();
50 :
51 : uint32_t GetCurrentCharOffset();
52 :
53 : void SetSpeechSynthesis(SpeechSynthesis* aSpeechSynthesis);
54 :
55 : void InitDirectAudio();
56 : void InitIndirectAudio();
57 :
58 : void SetChosenVoiceURI(const nsAString& aUri);
59 :
60 : virtual void SetAudioOutputVolume(float aVolume);
61 :
62 0 : bool IsPreCanceled()
63 : {
64 0 : return mPreCanceled;
65 : };
66 :
67 0 : bool IsPrePaused()
68 : {
69 0 : return mPrePaused;
70 : }
71 :
72 : protected:
73 : virtual ~nsSpeechTask();
74 :
75 : nsresult DispatchStartImpl();
76 :
77 : virtual nsresult DispatchStartImpl(const nsAString& aUri);
78 :
79 : virtual nsresult DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex);
80 :
81 : virtual nsresult DispatchPauseImpl(float aElapsedTime, uint32_t aCharIndex);
82 :
83 : virtual nsresult DispatchResumeImpl(float aElapsedTime, uint32_t aCharIndex);
84 :
85 : virtual nsresult DispatchErrorImpl(float aElapsedTime, uint32_t aCharIndex);
86 :
87 : virtual nsresult DispatchBoundaryImpl(const nsAString& aName,
88 : float aElapsedTime,
89 : uint32_t aCharIndex,
90 : uint32_t aCharLength,
91 : uint8_t argc);
92 :
93 : virtual nsresult DispatchMarkImpl(const nsAString& aName,
94 : float aElapsedTime, uint32_t aCharIndex);
95 :
96 : RefPtr<SpeechSynthesisUtterance> mUtterance;
97 :
98 : float mVolume;
99 :
100 : nsString mText;
101 :
102 : bool mInited;
103 :
104 : bool mPrePaused;
105 :
106 : bool mPreCanceled;
107 :
108 : private:
109 : void End();
110 :
111 : void SendAudioImpl(RefPtr<mozilla::SharedBuffer>& aSamples, uint32_t aDataLen);
112 :
113 : nsresult DispatchStartInner();
114 :
115 : nsresult DispatchEndInner(float aElapsedTime, uint32_t aCharIndex);
116 :
117 : void CreateAudioChannelAgent();
118 :
119 : void DestroyAudioChannelAgent();
120 :
121 : RefPtr<SourceMediaStream> mStream;
122 :
123 : RefPtr<MediaInputPort> mPort;
124 :
125 : nsCOMPtr<nsISpeechTaskCallback> mCallback;
126 :
127 : nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent;
128 :
129 : uint32_t mChannels;
130 :
131 : RefPtr<SpeechSynthesis> mSpeechSynthesis;
132 :
133 : bool mIndirectAudio;
134 :
135 : nsString mChosenVoiceURI;
136 : };
137 :
138 : } // namespace dom
139 : } // namespace mozilla
140 :
141 : #endif
|