ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / device / bluetooth / bluetooth_audio_sink.h
blob6abb8a5d14e43909ab140d00845ff152df95fa09
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 // TODO(mcchou): Add method to monitor the availability of audio data during
77 // the streaming. This method should associate with BluetoothAudioSink
78 // specific IOBuffer wrapping fd, read_mtu and write_mtu.
81 // The ErrorCallback is used for the methods that can fail in which case it
82 // is called.
83 typedef base::Callback<void(ErrorCode)> ErrorCallback;
85 // Possible volumes for media transport are 0-127, and 128 is used to
86 // represent invalid volume.
87 static const uint16_t kInvalidVolume;
89 // Unregisters the audio sink. An audio sink will unregister itself
90 // automatically in its destructor, but calling Unregister is recommended,
91 // since user applications can be notified of an error returned by the call.
92 virtual void Unregister(const base::Closure& callback,
93 const ErrorCallback& error_callback) = 0;
95 // Adds and removes an observer for events on the BluetoothAudioSink object.
96 // If monitoring multiple audio sinks, check the |audio_sink| parameter of
97 // observer methods to determine which audio sink is issuing the event.
98 virtual void AddObserver(Observer* observer) = 0;
99 virtual void RemoveObserver(Observer* observer) = 0;
101 // Getters for state and volume.
102 virtual State GetState() const = 0;
104 // Returns the current volume level of the audio sink. The valid volumes are
105 // 0-127, and |kInvalidVolume| is returned instead if the volume is unknown.
106 virtual uint16_t GetVolume() const = 0;
108 protected:
109 friend class base::RefCounted<BluetoothAudioSink>;
110 BluetoothAudioSink();
112 // The destructor invokes Unregister() to ensure the audio sink will be
113 // unregistered even if the user applications fail to do so.
114 virtual ~BluetoothAudioSink();
116 private:
117 DISALLOW_COPY_AND_ASSIGN(BluetoothAudioSink);
120 } // namespace device
122 #endif // DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_H_