|
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 nsPicoService_h |
|
8 #define nsPicoService_h |
|
9 |
|
10 #include "mozilla/Mutex.h" |
|
11 #include "nsAutoPtr.h" |
|
12 #include "nsTArray.h" |
|
13 #include "nsIThread.h" |
|
14 #include "nsISpeechService.h" |
|
15 #include "nsRefPtrHashtable.h" |
|
16 #include "mozilla/StaticPtr.h" |
|
17 #include "mozilla/Monitor.h" |
|
18 |
|
19 namespace mozilla { |
|
20 namespace dom { |
|
21 |
|
22 class PicoVoice; |
|
23 class PicoCallbackRunnable; |
|
24 |
|
25 typedef void* pico_System; |
|
26 typedef void* pico_Resource; |
|
27 typedef void* pico_Engine; |
|
28 |
|
29 class nsPicoService : public nsISpeechService |
|
30 { |
|
31 friend class PicoCallbackRunnable; |
|
32 friend class PicoInitRunnable; |
|
33 |
|
34 public: |
|
35 NS_DECL_THREADSAFE_ISUPPORTS |
|
36 NS_DECL_NSISPEECHSERVICE |
|
37 |
|
38 nsPicoService(); |
|
39 |
|
40 virtual ~nsPicoService(); |
|
41 |
|
42 static nsPicoService* GetInstance(); |
|
43 |
|
44 static already_AddRefed<nsPicoService> GetInstanceForService(); |
|
45 |
|
46 static void Shutdown(); |
|
47 |
|
48 private: |
|
49 |
|
50 void Init(); |
|
51 |
|
52 void RegisterVoices(); |
|
53 |
|
54 bool GetVoiceFileLanguage(const nsACString& aFileName, nsAString& aLang); |
|
55 |
|
56 void LoadEngine(PicoVoice* aVoice); |
|
57 |
|
58 void UnloadEngine(); |
|
59 |
|
60 PicoVoice* CurrentVoice(); |
|
61 |
|
62 bool mInitialized; |
|
63 |
|
64 nsCOMPtr<nsIThread> mThread; |
|
65 |
|
66 nsRefPtrHashtable<nsStringHashKey, PicoVoice> mVoices; |
|
67 |
|
68 Monitor mVoicesMonitor; |
|
69 |
|
70 PicoVoice* mCurrentVoice; |
|
71 |
|
72 Atomic<nsISpeechTask*> mCurrentTask; |
|
73 |
|
74 pico_System mPicoSystem; |
|
75 |
|
76 pico_Engine mPicoEngine; |
|
77 |
|
78 pico_Resource mSgResource; |
|
79 |
|
80 pico_Resource mTaResource; |
|
81 |
|
82 nsAutoPtr<uint8_t> mPicoMemArea; |
|
83 |
|
84 static StaticRefPtr<nsPicoService> sSingleton; |
|
85 }; |
|
86 |
|
87 } // namespace dom |
|
88 } // namespace mozilla |
|
89 |
|
90 #endif |