Skip to content

Commit

Permalink
Bug 1523920 - P4: Move the state from SpeechSynthesisUtterance to nsS…
Browse files Browse the repository at this point in the history
…peechTask. r=eeejay

It would be easier to reuse the utterance if it's stateless. The state
could still be tracked by moving from SpeechSynthesisUtterance to
nsSpeechTask, which is the place to change the state in original
implementation. By removing state in utterance, we don't need to check
the state of utterance when it's pushed into the speech queue.

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

UltraBlame original commit: c5c1ac80fd436e1c002b2ad25fb0a9529ebcdadd
  • Loading branch information
marco-c committed Oct 4, 2019
1 parent 480827a commit f35d54a
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 267 deletions.
220 changes: 89 additions & 131 deletions dom/media/webspeech/synth/SpeechSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,50 +499,92 @@ Pending
)
const
{
switch
(
/
/
If
we
don
'
t
have
any
task
nothing
is
pending
.
If
we
have
only
one
task
/
/
check
if
that
task
is
currently
pending
.
If
we
have
more
than
one
task
/
/
then
the
tasks
after
the
first
one
are
definitely
pending
.
return
mSpeechQueue
.
Length
(
)
)
{
case
0
:
return
false
;
case
>
1
:
return
|
|
(
mSpeechQueue
.
ElementAt
Length
(
0
)
=
=
1
&
&
(
!
mCurrentTask
|
|
mCurrentTask
-
>
GetState
IsPending
(
)
=
=
SpeechSynthesisUtterance
:
:
STATE_PENDING
;
default
:
return
true
)
)
;
}
}
bool
SpeechSynthesis
:
Expand All @@ -552,7 +594,21 @@ Speaking
)
const
{
/
/
Check
global
speaking
state
if
there
is
no
active
speaking
task
.
return
(
!
mSpeechQueue
Expand All @@ -562,45 +618,12 @@ IsEmpty
)
&
&
mSpeechQueue
.
ElementAt
HasSpeakingTask
(
0
)
-
>
GetState
(
)
=
=
SpeechSynthesisUtterance
:
:
STATE_SPEAKING
)
{
return
true
;
}
/
/
Returns
global
speaking
state
if
global
queue
is
enabled
.
Or
false
.
return
|
|
nsSynthVoiceRegistry
:
:
Expand Down Expand Up @@ -769,31 +792,6 @@ mInnerID
return
;
}
if
(
aUtterance
.
mState
!
=
SpeechSynthesisUtterance
:
:
STATE_NONE
)
{
/
/
XXX
:
Should
probably
raise
an
error
return
;
}
mSpeechQueue
.
AppendElement
Expand All @@ -802,15 +800,6 @@ AppendElement
aUtterance
)
;
aUtterance
.
mState
=
SpeechSynthesisUtterance
:
:
STATE_PENDING
;
/
/
If
Expand Down Expand Up @@ -1037,23 +1026,9 @@ IsEmpty
)
&
&
mSpeechQueue
.
ElementAt
HasSpeakingTask
(
0
)
-
>
GetState
(
)
=
=
SpeechSynthesisUtterance
:
:
STATE_SPEAKING
)
{
/
Expand Down Expand Up @@ -1132,9 +1107,6 @@ return
}
if
(
mCurrentTask
&
&
!
mSpeechQueue
.
Expand All @@ -1143,23 +1115,9 @@ IsEmpty
)
&
&
mSpeechQueue
.
ElementAt
(
0
)
-
>
GetState
HasSpeakingTask
(
)
=
=
SpeechSynthesisUtterance
:
:
STATE_SPEAKING
)
{
mCurrentTask
Expand Down
18 changes: 18 additions & 0 deletions dom/media/webspeech/synth/SpeechSynthesis.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,24 @@ HasVoices
)
const
;
bool
HasSpeakingTask
(
)
const
{
return
mCurrentTask
&
&
mCurrentTask
-
>
IsSpeaking
(
)
;
}
nsTArray
<
RefPtr
Expand Down
4 changes: 0 additions & 4 deletions dom/media/webspeech/synth/SpeechSynthesisUtterance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@ mPitch
(
1
)
mState
(
STATE_NONE
)
mPaused
(
false
Expand Down
20 changes: 0 additions & 20 deletions dom/media/webspeech/synth/SpeechSynthesisUtterance.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,23 +369,6 @@ aResult
)
const
;
enum
{
STATE_NONE
STATE_PENDING
STATE_SPEAKING
STATE_ENDED
}
;
uint32_t
GetState
(
)
{
return
mState
;
}
bool
IsPaused
(
Expand Down Expand Up @@ -473,9 +456,6 @@ mPitch
nsString
mChosenVoiceURI
;
uint32_t
mState
;
bool
mPaused
;
Expand Down
Loading

0 comments on commit f35d54a

Please sign in to comment.