Mark //testing/perf target testonly.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_audio_sink.h
blob331ef0d83d1dac7653b745d899a694339ae7fce2
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 presented/powered.
44 ERROR_NOT_REGISTERED, // BluetoothAudioSink not registered.
47 // Options to configure an A2DP audio sink.
48 struct Options {
49 Options();
50 ~Options();
52 uint8_t codec;
53 std::vector<uint8_t> capabilities;
56 // Interface for observing changes from a BluetoothAudioSink.
57 class Observer {
58 public:
59 virtual ~Observer() {}
61 // Called when the state of the BluetoothAudioSink object is changed.
62 // |audio_sink| indicates the object being changed, and |state| indicates
63 // the new state of that object.
64 virtual void BluetoothAudioSinkStateChanged(
65 BluetoothAudioSink* audio_sink,
66 BluetoothAudioSink::State state) = 0;
68 // Called when the volume of the BluetoothAudioSink object is changed.
69 // |audio_sink| indicates the object being changed, and |volume| indicates
70 // the new volume level of that object.
71 virtual void BluetoothAudioSinkVolumeChanged(
72 BluetoothAudioSink* audio_sink,
73 uint16_t volume) = 0;
75 // TODO(mcchou): Add method to monitor the availability of audio data during
76 // the streaming. This method should associate with BluetoothAudioSink
77 // specific IOBuffer wrapping fd, read_mtu and write_mtu.
80 // The ErrorCallback is used for the methods that can fail in which case it
81 // is called.
82 typedef base::Callback<void(ErrorCode)> ErrorCallback;
84 // Unregisters the audio sink. An audio sink will unregister itself
85 // automatically in its destructor, but calling Unregister is recommended,
86 // since user applications can be notified of an error returned by the call.
87 virtual void Unregister(const base::Closure& callback,
88 const ErrorCallback& error_callback) = 0;
90 // Adds and removes an observer for events on the BluetoothAudioSink object.
91 // If monitoring multiple audio sinks, check the |audio_sink| parameter of
92 // observer methods to determine which audio sink is issuing the event.
93 virtual void AddObserver(Observer* observer) = 0;
94 virtual void RemoveObserver(Observer* observer) = 0;
96 // Getters for state and volume.
97 virtual State GetState() const = 0;
98 virtual uint16_t GetVolume() const = 0;
100 protected:
101 friend class base::RefCounted<BluetoothAudioSink>;
102 BluetoothAudioSink();
104 // The destructor invokes Unregister() to ensure the audio sink will be
105 // unregistered even if the user applications fail to do so.
106 virtual ~BluetoothAudioSink();
108 private:
109 DISALLOW_COPY_AND_ASSIGN(BluetoothAudioSink);
112 } // namespace device
114 #endif // DEVICE_BLUETOOTH_BLUETOOTH_AUDIO_SINK_H_