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