OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ | 5 #ifndef CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ |
6 #define CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ | 6 #define CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/shared_memory.h" | |
12 #include "base/message_loop/message_loop_proxy.h" | |
11 #include "content/public/common/speech_recognition_result.h" | 13 #include "content/public/common/speech_recognition_result.h" |
12 #include "content/public/renderer/render_view_observer.h" | 14 #include "content/public/renderer/render_view_observer.h" |
15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | |
13 #include "third_party/WebKit/public/platform/WebVector.h" | 16 #include "third_party/WebKit/public/platform/WebVector.h" |
14 #include "third_party/WebKit/public/web/WebSpeechRecognitionHandle.h" | 17 #include "third_party/WebKit/public/web/WebSpeechRecognitionHandle.h" |
15 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h" | 18 #include "third_party/WebKit/public/web/WebSpeechRecognizer.h" |
16 | 19 |
20 | |
21 namespace media { | |
22 class AudioParameters; | |
23 } | |
24 | |
17 namespace content { | 25 namespace content { |
18 class RenderViewImpl; | 26 class RenderViewImpl; |
27 class SpeechRecognitionAudioSourceProvider; | |
19 struct SpeechRecognitionError; | 28 struct SpeechRecognitionError; |
20 struct SpeechRecognitionResult; | 29 struct SpeechRecognitionResult; |
21 | 30 |
22 // SpeechRecognitionDispatcher is a delegate for methods used by WebKit for | 31 // SpeechRecognitionDispatcher is a delegate for methods used by WebKit for |
23 // scripted JS speech APIs. It's the complement of | 32 // scripted JS speech APIs. It's the complement of |
24 // SpeechRecognitionDispatcherHost (owned by RenderViewHost). | 33 // SpeechRecognitionDispatcherHost (owned by RenderViewHost). |
25 class SpeechRecognitionDispatcher : public RenderViewObserver, | 34 class SpeechRecognitionDispatcher : public RenderViewObserver, |
26 public blink::WebSpeechRecognizer { | 35 public blink::WebSpeechRecognizer { |
27 public: | 36 public: |
28 explicit SpeechRecognitionDispatcher(RenderViewImpl* render_view); | 37 explicit SpeechRecognitionDispatcher(RenderViewImpl* render_view); |
29 virtual ~SpeechRecognitionDispatcher(); | 38 virtual ~SpeechRecognitionDispatcher(); |
30 | 39 |
31 // Aborts all speech recognitions. | 40 // Aborts all speech recognitions. |
32 void AbortAllRecognitions(); | 41 void AbortAllRecognitions(); |
33 | 42 |
34 private: | 43 private: |
35 // RenderViewObserver implementation. | 44 // RenderViewObserver implementation. |
36 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 45 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
37 | 46 |
38 // blink::WebSpeechRecognizer implementation. | 47 // blink::WebSpeechRecognizer implementation. |
48 virtual void attach(const blink::WebSpeechRecognitionHandle&, | |
49 const blink::WebMediaStreamTrack&, | |
50 blink::WebSpeechRecognizerClient*) OVERRIDE; | |
51 virtual void detach(const blink::WebSpeechRecognitionHandle&, | |
52 blink::WebSpeechRecognizerClient*) OVERRIDE; | |
39 virtual void start(const blink::WebSpeechRecognitionHandle&, | 53 virtual void start(const blink::WebSpeechRecognitionHandle&, |
40 const blink::WebSpeechRecognitionParams&, | 54 const blink::WebSpeechRecognitionParams&, |
41 blink::WebSpeechRecognizerClient*) OVERRIDE; | 55 blink::WebSpeechRecognizerClient*) OVERRIDE; |
42 virtual void stop(const blink::WebSpeechRecognitionHandle&, | 56 virtual void stop(const blink::WebSpeechRecognitionHandle&, |
43 blink::WebSpeechRecognizerClient*) OVERRIDE; | 57 blink::WebSpeechRecognizerClient*) OVERRIDE; |
44 virtual void abort(const blink::WebSpeechRecognitionHandle&, | 58 virtual void abort(const blink::WebSpeechRecognitionHandle&, |
45 blink::WebSpeechRecognizerClient*) OVERRIDE; | 59 blink::WebSpeechRecognizerClient*) OVERRIDE; |
46 | 60 |
47 void OnRecognitionStarted(int request_id); | 61 void OnRecognitionStarted(int request_id); |
48 void OnAudioStarted(int request_id); | 62 void OnAudioStarted(int request_id); |
49 void OnSoundStarted(int request_id); | 63 void OnSoundStarted(int request_id); |
50 void OnSoundEnded(int request_id); | 64 void OnSoundEnded(int request_id); |
51 void OnAudioEnded(int request_id); | 65 void OnAudioEnded(int request_id); |
52 void OnErrorOccurred(int request_id, const SpeechRecognitionError& error); | 66 void OnErrorOccurred(int request_id, const SpeechRecognitionError& error); |
53 void OnRecognitionEnded(int request_id); | 67 void OnRecognitionEnded(int request_id); |
54 void OnResultsRetrieved(int request_id, | 68 void OnResultsRetrieved(int request_id, |
55 const SpeechRecognitionResults& result); | 69 const SpeechRecognitionResults& result); |
70 void OnAudioTrackReady(int session_id, const media::AudioParameters& params, | |
71 base::SharedMemoryHandle handle, uint32 length); | |
72 | |
73 // for receiving audio data via audio track | |
henrika (OOO until Aug 14)
2014/08/25 14:46:00
nit, capital 'F' end with period '.' as all other
| |
74 void OnAudioData(int request_id); | |
75 void OnAudioError(int request_id); | |
76 void OnAudioChunkProcessed(int request_id); | |
56 | 77 |
57 int GetOrCreateIDForHandle(const blink::WebSpeechRecognitionHandle& handle); | 78 int GetOrCreateIDForHandle(const blink::WebSpeechRecognitionHandle& handle); |
58 bool HandleExists(const blink::WebSpeechRecognitionHandle& handle); | 79 bool HandleExists(const blink::WebSpeechRecognitionHandle& handle); |
59 const blink::WebSpeechRecognitionHandle& GetHandleFromID(int handle_id); | 80 const blink::WebSpeechRecognitionHandle& GetHandleFromID(int handle_id); |
60 | 81 |
61 // The WebKit client class that we use to send events back to the JS world. | 82 // The WebKit client class that we use to send events back to the JS world. |
62 blink::WebSpeechRecognizerClient* recognizer_client_; | 83 blink::WebSpeechRecognizerClient* recognizer_client_; |
63 | 84 |
85 // Media stream audio track that the speech recognition connects to. | |
86 // Accessed on the render thread. | |
87 blink::WebMediaStreamTrack audio_track_; | |
88 | |
89 bool audio_track_set_; | |
henrika (OOO until Aug 14)
2014/08/25 14:46:00
Comment.
...and, capitals for all comments below
| |
90 | |
91 // Used by policy on which audio sources are allowed | |
henrika (OOO until Aug 14)
2014/08/25 14:46:00
Rather unclear comment to me. What is meant by "us
| |
92 bool is_allowed_audio_track_; | |
93 | |
94 // audio sink used to provide audio from the track | |
95 scoped_ptr<SpeechRecognitionAudioSourceProvider> audio_source_provider_; | |
96 | |
97 // for sending signal back to browser | |
98 scoped_refptr<base::MessageLoopProxy> render_loop_; | |
99 | |
64 typedef std::map<int, blink::WebSpeechRecognitionHandle> HandleMap; | 100 typedef std::map<int, blink::WebSpeechRecognitionHandle> HandleMap; |
65 HandleMap handle_map_; | 101 HandleMap handle_map_; |
66 int next_id_; | 102 int next_id_; |
67 | 103 |
68 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcher); | 104 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcher); |
69 }; | 105 }; |
70 | 106 |
71 } // namespace content | 107 } // namespace content |
72 | 108 |
73 #endif // CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ | 109 #endif // CONTENT_RENDERER_SPEECH_RECOGNITION_DISPATCHER_H_ |
OLD | NEW |