QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_audio_sink.h
blob37359256c3c60cf13965b57f8539c352bf09efb0
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.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_H_
8 #include <stdint.h>
9 #include <string>
10 #include <vector>
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "device/bluetooth/bluetooth_export.h"
17 namespace device {
19 // TODO(mcchou): Define a BluetoothAudioSink specific IOBuffer abstraction.
21 // BluetoothAudioSink represents a local A2DP audio sink where a remote device
22 // can stream audio data. Once a BluetoothAudioSink is successfully registered,
23 // user applications can obtain a pointer to a BluetoothAudioSink object via
24 // the interface provided by BluetoothAdapter. The validity of a
25 // BluetoothAudioSink depends on whether BluetoothAdapter is present and whether
26 // it is powered.
27 class DEVICE_BLUETOOTH_EXPORT BluetoothAudioSink
28 : public base::RefCounted<BluetoothAudioSink> {
29 public:
30 // Possible values indicating the connection states between the
31 // BluetoothAudioSink and the remote device.
32 enum State {
33 STATE_INVALID, // BluetoothAdapter not presented or not powered.
34 STATE_DISCONNECTED, // Not connected.
35 STATE_IDLE, // Connected but not streaming.
36 STATE_PENDING, // Connected, streaming but not acquired.
37 STATE_ACTIVE, // Connected, streaming and acquired.
40 // Possible types of error raised by Audio Sink object.
41 enum ErrorCode {
42 ERROR_UNSUPPORTED_PLATFORM, // A2DP sink not supported on current platform.
43 ERROR_INVALID_ADAPTER, // BluetoothAdapter not present/powered.
44 ERROR_NOT_REGISTERED, // BluetoothAudioSink not registered.
45 ERROR_NOT_UNREGISTERED, // BluetoothAudioSink not unregistered.
48 // Options to configure an A2DP audio sink.
49 struct Options {
50 Options();
51 ~Options();
53 uint8_t codec;
54 std::vector<uint8_t> capabilities;
57 // Interface for observing changes from a BluetoothAudioSink.
58 class Observer {
59 public:
60 virtual ~Observer() {}
62 // Called when the state of the BluetoothAudioSink object is changed.
63 // |audio_sink| indicates the object being changed, and |state| indicates
64 // the new state of that object.
65 virtual void BluetoothAudioSinkStateChanged(
66 BluetoothAudioSink* audio_sink,
67 BluetoothAudioSink::State state) = 0;
69 // Called when the volume of the BluetoothAudioSink object is changed.
70 // |audio_sink| indicates the object being changed, and |volume| indicates
71 // the new volume level of that object.
72 virtual void BluetoothAudioSinkVolumeChanged(
73 BluetoothAudioSink* audio_sink,
74 uint16_t volume) = 0;
76 // Called when there is audio data available. |audio_sink| indicates the
77 // object being changed. |data| is the pointer to the audio data and |size|
78 // is the number of bytes in |data|. |read_mtu| is the max size of the RTP
79 // packet. This method provides the raw audio data which hasn't been
80 // processed, so RTP assembling and SBC decoding need to be handled in order
81 // to get PCM data.
82 virtual void BluetoothAudioSinkDataAvailable(BluetoothAudioSink* audio_sink,
83 char* data,
84 size_t size,
85 uint16_t read_mtu) = 0;
88 // The ErrorCallback is used for the methods that can fail in which case it
89 // is called.
90 typedef base::Callback<void(ErrorCode)> ErrorCallback;
92 // Possible volumes for media transport are 0-127, and 128 is used to
93 // represent invalid volume.
94 static const uint16_t kInvalidVolume;
96 // Unregisters the audio sink. An audio sink will unregister itself
97 // automatically in its destructor, but calling Unregister is recommended,
98 // since user applications can be notified of an error returned by the call.
99 virtual void Unregister(const base::Closure& callback,
100 const ErrorCallback& error_callback) = 0;
102 // Adds and removes an observer for events on the BluetoothAudioSink object.
103 // If monitoring multiple audio sinks, check the |audio_sink| parameter of
104 // observer methods to determine which audio sink is issuing the event.
105 virtual void AddObserver(Observer* observer) = 0;
106 virtual void RemoveObserver(Observer* observer) = 0;
108 // Getters for state and volume.
109 virtual State GetState() const = 0;
111 // Returns the current volume level of the audio sink. The valid volumes are
112 // 0-127, and |kInvalidVolume| is returned instead if the volume is unknown.
113 virtual uint16_t GetVolume() const = 0;
115 protected:
116 friend class base::RefCounted<BluetoothAudioSink>;
117 BluetoothAudioSink();
119 // The destructor invokes Unregister() to ensure the audio sink will be
120 // unregistered even if the user applications fail to do so.
121 virtual ~BluetoothAudioSink();
123 private:
124 DISALLOW_COPY_AND_ASSIGN(BluetoothAudioSink);
127 } // namespace device
129 #endif // DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_H_