| OLD | NEW | 
|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 COMPONENTS_COPRESENCE_PUBLIC_WHISPERNET_CLIENT_H_ | 5 #ifndef COMPONENTS_COPRESENCE_PUBLIC_WHISPERNET_CLIENT_H_ | 
| 6 #define COMPONENTS_COPRESENCE_PUBLIC_WHISPERNET_CLIENT_H_ | 6 #define COMPONENTS_COPRESENCE_PUBLIC_WHISPERNET_CLIENT_H_ | 
| 7 | 7 | 
| 8 #include <string> | 8 #include <string> | 
| 9 #include <vector> | 9 #include <vector> | 
| 10 | 10 | 
| 11 #include "base/callback.h" | 11 #include "base/callback.h" | 
| 12 #include "base/macros.h" | 12 #include "base/macros.h" | 
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" | 
|  | 14 #include "components/copresence/public/copresence_constants.h" | 
| 14 | 15 | 
| 15 namespace media { | 16 namespace media { | 
| 16 class AudioBusRefCounted; | 17 class AudioBusRefCounted; | 
| 17 } | 18 } | 
| 18 | 19 | 
| 19 namespace copresence { | 20 namespace copresence { | 
| 20 | 21 | 
| 21 struct AudioToken { | 22 struct AudioToken { | 
| 22   AudioToken(const std::string& token, bool audible) | 23   AudioToken(const std::string& token, bool audible) | 
| 23       : token(token), audible(audible) {} | 24       : token(token), audible(audible) {} | 
| 24   std::string token; | 25   std::string token; | 
| 25   bool audible; | 26   bool audible; | 
| 26 }; | 27 }; | 
| 27 | 28 | 
| 28 // The interface that the whispernet client needs to implement. These methods | 29 // The interface that the whispernet client needs to implement. These methods | 
| 29 // provide us the ability to use the audio medium in copresence. Currently since | 30 // provide us the ability to use the audio medium in copresence. Currently since | 
| 30 // the only medium that copresence uses is audio, the implementation of this | 31 // the only medium that copresence uses is audio, the implementation of this | 
| 31 // interface is required. | 32 // interface is required. | 
| 32 class WhispernetClient { | 33 class WhispernetClient { | 
| 33  public: | 34  public: | 
| 34   // Generic callback to indicate a boolean success or failure. | 35   // Generic callback to indicate a boolean success or failure. | 
| 35   typedef base::Callback<void(bool)> SuccessCallback; | 36   typedef base::Callback<void(bool)> SuccessCallback; | 
| 36   // Callback that returns detected tokens. | 37   // Callback that returns detected tokens. | 
| 37   typedef base::Callback<void(const std::vector<AudioToken>&)> TokensCallback; | 38   typedef base::Callback<void(const std::vector<AudioToken>&)> TokensCallback; | 
| 38   // Callback that returns encoded samples for a given token. | 39   // Callback that returns encoded samples for a given token. | 
| 39   typedef base::Callback<void(const std::string&, | 40   typedef base::Callback<void(const std::string&, | 
| 40                               bool, | 41                               AudioType, | 
| 41                               const scoped_refptr<media::AudioBusRefCounted>&)> | 42                               const scoped_refptr<media::AudioBusRefCounted>&)> | 
| 42       SamplesCallback; | 43       SamplesCallback; | 
| 43 | 44 | 
| 44   // Initialize the whispernet client and call the callback when done. The | 45   // Initialize the whispernet client and call the callback when done. The | 
| 45   // parameter indicates whether we succeeded or failed. | 46   // parameter indicates whether we succeeded or failed. | 
| 46   virtual void Initialize(const SuccessCallback& init_callback) = 0; | 47   virtual void Initialize(const SuccessCallback& init_callback) = 0; | 
| 47   // Copresence will call this before making any calls to its destructors. | 48   // Copresence will call this before making any calls to its destructors. | 
| 48   virtual void Shutdown() = 0; | 49   virtual void Shutdown() = 0; | 
| 49 | 50 | 
| 50   // Fires an event to request a token encode. | 51   // Fires an event to request a token encode. | 
| 51   virtual void EncodeToken(const std::string& token, bool audible) = 0; | 52   virtual void EncodeToken(const std::string& token, AudioType type) = 0; | 
| 52   // Fires an event to request a decode for the given samples. | 53   // Fires an event to request a decode for the given samples. | 
| 53   virtual void DecodeSamples(const std::string& samples) = 0; | 54   virtual void DecodeSamples(AudioType type, const std::string& samples) = 0; | 
| 54   // Fires an event to request detection of a whispernet broadcast. | 55   // Fires an event to request detection of a whispernet broadcast. | 
| 55   virtual void DetectBroadcast() = 0; | 56   virtual void DetectBroadcast() = 0; | 
| 56 | 57 | 
| 57   // Callback registreation methods. These are the callbacks that will be | 58   // Callback registreation methods. These are the callbacks that will be | 
| 58   // registered by Copresence to receive data. | 59   // registered by Copresence to receive data. | 
| 59   virtual void RegisterTokensCallback( | 60   virtual void RegisterTokensCallback( | 
| 60       const TokensCallback& tokens_callback) = 0; | 61       const TokensCallback& tokens_callback) = 0; | 
| 61   virtual void RegisterSamplesCallback( | 62   virtual void RegisterSamplesCallback( | 
| 62       const SamplesCallback& samples_callback) = 0; | 63       const SamplesCallback& samples_callback) = 0; | 
| 63   virtual void RegisterDetectBroadcastCallback( | 64   virtual void RegisterDetectBroadcastCallback( | 
| 64       const SuccessCallback& db_callback) = 0; | 65       const SuccessCallback& db_callback) = 0; | 
| 65 | 66 | 
| 66   // Don't cache these callbacks, as they may become invalid at any time. | 67   // Don't cache these callbacks, as they may become invalid at any time. | 
| 67   // Always invoke callbacks directly through these accessors. | 68   // Always invoke callbacks directly through these accessors. | 
| 68   virtual TokensCallback GetTokensCallback() = 0; | 69   virtual TokensCallback GetTokensCallback() = 0; | 
| 69   virtual SamplesCallback GetSamplesCallback() = 0; | 70   virtual SamplesCallback GetSamplesCallback() = 0; | 
| 70   virtual SuccessCallback GetDetectBroadcastCallback() = 0; | 71   virtual SuccessCallback GetDetectBroadcastCallback() = 0; | 
| 71   virtual SuccessCallback GetInitializedCallback() = 0; | 72   virtual SuccessCallback GetInitializedCallback() = 0; | 
| 72 | 73 | 
| 73   virtual ~WhispernetClient() {} | 74   virtual ~WhispernetClient() {} | 
| 74 }; | 75 }; | 
| 75 | 76 | 
| 76 }  // namespace copresence | 77 }  // namespace copresence | 
| 77 | 78 | 
| 78 #endif  // COMPONENTS_COPRESENCE_PUBLIC_WHISPERNET_CLIENT_H_ | 79 #endif  // COMPONENTS_COPRESENCE_PUBLIC_WHISPERNET_CLIENT_H_ | 
| OLD | NEW | 
|---|