OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_ | |
6 #define CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/macros.h" | |
12 #include "base/memory/scoped_vector.h" | |
13 #include "chrome/browser/copresence/chrome_whispernet_config.h" | |
14 #include "components/audio_modem/public/whispernet_client.h" | |
15 | |
16 namespace content { | |
17 class BrowserContext; | |
18 } | |
19 | |
20 namespace extensions { | |
21 | |
22 struct Event; | |
23 class EventRouter; | |
24 | |
25 namespace api { | |
26 namespace copresence_private { | |
27 struct AudioParameters; | |
28 } | |
29 } | |
30 | |
31 } // namespace extensions | |
32 | |
33 namespace media { | |
34 class AudioBusRefCounted; | |
35 } | |
36 | |
37 // This class is responsible for communication with our whispernet_proxy | |
38 // extension that talks to the whispernet audio library. | |
39 class ChromeWhispernetClient final : public audio_modem::WhispernetClient { | |
40 public: | |
41 // The browser context needs to outlive this class. | |
42 explicit ChromeWhispernetClient(content::BrowserContext* browser_context); | |
43 ~ChromeWhispernetClient() override; | |
44 | |
45 // WhispernetClient overrides: | |
46 void Initialize(const audio_modem::SuccessCallback& init_callback) override; | |
47 void EncodeToken(const std::string& token_str, | |
48 audio_modem::AudioType type, | |
49 const audio_modem::TokenParameters token_params[2]) override; | |
50 void DecodeSamples( | |
51 audio_modem::AudioType type, | |
52 const std::string& samples, | |
53 const audio_modem::TokenParameters token_params[2]) override; | |
54 void RegisterTokensCallback( | |
55 const audio_modem::TokensCallback& tokens_callback) override; | |
56 void RegisterSamplesCallback( | |
57 const audio_modem::SamplesCallback& samples_callback) override; | |
58 | |
59 audio_modem::TokensCallback GetTokensCallback() override; | |
60 audio_modem::SamplesCallback GetSamplesCallback() override; | |
61 audio_modem::SuccessCallback GetInitializedCallback() override; | |
62 | |
63 static const char kWhispernetProxyExtensionId[]; | |
64 | |
65 private: | |
66 // Fire an event to configure whispernet with the given audio parameters. | |
67 void AudioConfiguration(const AudioParamData& params); | |
68 | |
69 void SendEventIfLoaded(std::unique_ptr<extensions::Event> event); | |
70 | |
71 // This gets called when the proxy extension loads. | |
72 void OnExtensionLoaded(bool success); | |
73 | |
74 content::BrowserContext* const browser_context_; | |
75 extensions::EventRouter* const event_router_; | |
76 std::string client_id_; | |
77 | |
78 audio_modem::SuccessCallback extension_loaded_callback_; | |
79 audio_modem::SuccessCallback init_callback_; | |
80 | |
81 audio_modem::TokensCallback tokens_callback_; | |
82 audio_modem::SamplesCallback samples_callback_; | |
83 | |
84 ScopedVector<extensions::Event> queued_events_; | |
85 bool extension_loaded_; | |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(ChromeWhispernetClient); | |
88 }; | |
89 | |
90 #endif // CHROME_BROWSER_COPRESENCE_CHROME_WHISPERNET_CLIENT_H_ | |
OLD | NEW |