Index: device/bluetooth/bluetooth_audio_sink_chromeos.h |
diff --git a/device/bluetooth/bluetooth_audio_sink_chromeos.h b/device/bluetooth/bluetooth_audio_sink_chromeos.h |
index 58d1fb2fee932852dbe410e65ee2e2cd2598ed1a..13d56d88cef886ff38847477ff90a1e727425f45 100644 |
--- a/device/bluetooth/bluetooth_audio_sink_chromeos.h |
+++ b/device/bluetooth/bluetooth_audio_sink_chromeos.h |
@@ -9,8 +9,10 @@ |
#include <string> |
#include <vector> |
+#include "base/files/file.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/memory/weak_ptr.h" |
+#include "base/message_loop/message_loop.h" |
#include "base/observer_list.h" |
#include "chromeos/dbus/bluetooth_media_client.h" |
#include "chromeos/dbus/bluetooth_media_endpoint_service_provider.h" |
@@ -30,7 +32,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAudioSinkChromeOS |
public device::BluetoothAdapter::Observer, |
public BluetoothMediaClient::Observer, |
public BluetoothMediaTransportClient::Observer, |
- public BluetoothMediaEndpointServiceProvider::Delegate { |
+ public BluetoothMediaEndpointServiceProvider::Delegate, |
+ public base::MessageLoopForIO::Watcher { |
public: |
explicit BluetoothAudioSinkChromeOS( |
scoped_refptr<device::BluetoothAdapter> adapter); |
@@ -79,6 +82,10 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAudioSinkChromeOS |
const base::Closure& callback, |
const device::BluetoothAudioSink::ErrorCallback& error_callback); |
+ // base::MessageLoopForIO::Watcher overrides. |
+ void OnFileCanReadWithoutBlocking(int fd) override; |
+ void OnFileCanWriteWithoutBlocking(int fd) override; |
armansito
2015/03/12 03:42:55
These can be private.
Miao
2015/03/12 22:33:32
Done.
|
+ |
// Returns a pointer to the media endpoint object. This function should be |
// used for testing purpose only. |
BluetoothMediaEndpointServiceProvider* GetEndpointServiceProvider(); |
@@ -86,6 +93,20 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAudioSinkChromeOS |
private: |
~BluetoothAudioSinkChromeOS() override; |
+ // Acquires file descriptor via current transport object when the state change |
+ // is triggered by MediaTransportPropertyChanged. |
+ void AcquireFD(); |
+ |
+ // Watches if there is any available data from |fd_|. |
+ void WatchFD(); |
+ |
+ // Stops watching |fd_| and resets |fd_|. |
+ void StopWatchingFD(); |
+ |
+ // Reads from the file descriptor acquired via Media Transport object and |
+ // notify |observer_| while the audio data is available. |
+ void ReadFromFile(); |
+ |
// Called when the state property of BluetoothMediaTransport has been updated. |
void StateChanged(device::BluetoothAudioSink::State state); |
@@ -112,9 +133,22 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAudioSinkChromeOS |
const std::string& error_name, |
const std::string& error_message); |
- // Reads from the file descriptor acquired via Media Transport object and |
- // notify |observer_| while the audio data is available. |
- void ReadFromFD(); |
+ // Called when the file descriptor, read MTU and write MTU are retrieved |
+ // successfully using |transport_path_|. |
+ void OnAcquireSucceeded(const int fd, |
+ const uint16_t read_mtu, |
+ const uint16_t write_mtu); |
+ |
+ // Called when acquiring the file descriptor, read MTU and write MTU failed. |
+ void OnAcquireFailed(const std::string& error_name, |
+ const std::string& error_message); |
+ |
+ // Called when the file descriptor is released successfully. |
+ void OnReleaseFDSucceeded(); |
+ |
+ // Called when it failed to release file descriptor. |
+ void OnReleaseFDFailed(const std::string& error_name, |
+ const std::string& error_message); |
// Helper functions to clean up media, media transport and media endpoint. |
// Called when the |state_| changes to either STATE_INVALID or |
@@ -132,13 +166,25 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAudioSinkChromeOS |
uint16_t volume_; |
// Read MTU of the file descriptor acquired via Media Transport object. |
- scoped_ptr<uint16_t> read_mtu_; |
+ uint16_t read_mtu_; |
// Write MTU of the file descriptor acquired via Media Transport object. |
- scoped_ptr<uint16_t> write_mtu_; |
+ uint16_t write_mtu_; |
+ |
+ // Flag for logging the read failure in ReadFromFD. |
+ bool read_failed_logged_; |
+ |
+ // The file which takes ownership of the file descriptor acquired via Media |
+ // Transport object. |
+ scoped_ptr<base::File> file_; |
+ |
+ // To avoid reallocation of memory, data will be updated only when |read_mtu_| |
+ // changes. |
+ scoped_ptr<char[]> data_; |
- // File descriptor acquired via Media Transport object. |
- dbus::FileDescriptor fd_; |
+ // File descriptor watcher for the file descriptor acquired via Media |
+ // Transport object. |
+ base::MessageLoopForIO::FileDescriptorWatcher fd_read_watcher_; |
// Object path of the media object being used. |
dbus::ObjectPath media_path_; |