123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #pragma once
- #include <atomic>
- #include <mutex>
- #include <string>
- #include <vector>
- #include <base/macros.h>
- #include "service/bluetooth_instance.h"
- #include "service/common/bluetooth/a2dp_codec_config.h"
- #include "service/hal/bluetooth_av_interface.h"
- namespace bluetooth {
- class A2dpSource : public BluetoothInstance,
- private hal::BluetoothAvInterface::A2dpSourceObserver {
- public:
-
- static const int kSingletonInstanceId;
- class Delegate {
- public:
- virtual void OnConnectionState(const std::string& device_address,
- int state) = 0;
- virtual void OnAudioState(const std::string& device_address, int state) = 0;
- virtual void OnAudioConfig(
- const std::string& device_address, A2dpCodecConfig codec_config,
- const std::vector<A2dpCodecConfig>& codecs_local_capabilities,
- const std::vector<A2dpCodecConfig>& codecs_selectable_capabilities) = 0;
- protected:
- virtual ~Delegate() = default;
- };
- ~A2dpSource() override;
- void SetDelegate(Delegate* delegate);
-
- const Uuid& GetAppIdentifier() const override;
- int GetInstanceId() const override;
- bool Enable(const std::vector<A2dpCodecConfig>& codec_priorities);
- void Disable();
- bool Connect(const std::string& device_address);
- bool Disconnect(const std::string& device_address);
- bool ConfigCodec(const std::string& device_address,
- const std::vector<A2dpCodecConfig>& codec_preferences);
- private:
- friend class A2dpSourceFactory;
- explicit A2dpSource(const Uuid& uuid);
-
- void ConnectionStateCallback(hal::BluetoothAvInterface* iface,
- const RawAddress& bd_addr,
- btav_connection_state_t state) override;
- void AudioStateCallback(hal::BluetoothAvInterface* iface,
- const RawAddress& bd_addr,
- btav_audio_state_t state) override;
- void AudioConfigCallback(
- hal::BluetoothAvInterface* iface, const RawAddress& bd_addr,
- const btav_a2dp_codec_config_t& codec_config,
- const std::vector<btav_a2dp_codec_config_t> codecs_local_capabilities,
- const std::vector<btav_a2dp_codec_config_t>
- codecs_selectable_capabilities) override;
-
- const Uuid app_identifier_;
- std::mutex mutex_;
-
-
-
-
-
-
- std::mutex delegate_mutex_;
- Delegate* delegate_ = nullptr;
- DISALLOW_COPY_AND_ASSIGN(A2dpSource);
- };
- class A2dpSourceFactory : public BluetoothInstanceFactory {
- public:
- A2dpSourceFactory();
- ~A2dpSourceFactory() override;
-
- bool RegisterInstance(const Uuid& uuid,
- const RegisterCallback& callback) override;
- private:
- DISALLOW_COPY_AND_ASSIGN(A2dpSourceFactory);
- };
- }
|