• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <mutex>
20 #include <vector>
21 
22 #include <aidl/android/hardware/audio/core/IBluetooth.h>
23 #include <aidl/android/hardware/audio/core/IBluetoothA2dp.h>
24 #include <aidl/android/hardware/audio/core/IBluetoothLe.h>
25 
26 #include "core-impl/DevicePortProxy.h"
27 #include "core-impl/Module.h"
28 #include "core-impl/Stream.h"
29 
30 namespace aidl::android::hardware::audio::core {
31 
32 class StreamBluetooth : public StreamCommonImpl {
33   public:
34     StreamBluetooth(StreamContext* context, const Metadata& metadata,
35                     Module::BtProfileHandles&& btHandles);
36     // Methods of 'DriverInterface'.
37     ::android::status_t init() override;
38     ::android::status_t drain(StreamDescriptor::DrainMode) override;
39     ::android::status_t flush() override;
40     ::android::status_t pause() override;
41     ::android::status_t standby() override;
42     ::android::status_t start() override;
43     ::android::status_t transfer(void* buffer, size_t frameCount, size_t* actualFrameCount,
44                                  int32_t* latencyMs) override;
45     void shutdown() override;
46 
47     // Overridden methods of 'StreamCommonImpl', called on a Binder thread.
48     ndk::ScopedAStatus updateMetadataCommon(const Metadata& metadata) override;
49     ndk::ScopedAStatus prepareToClose() override;
50     const ConnectedDevices& getConnectedDevices() const override;
51     ndk::ScopedAStatus setConnectedDevices(const ConnectedDevices& devices) override;
52     ndk::ScopedAStatus bluetoothParametersUpdated() override;
53 
54   private:
55     // Audio Pcm Config
56     const uint32_t mSampleRate;
57     const ::aidl::android::media::audio::common::AudioChannelLayout mChannelLayout;
58     const ::aidl::android::media::audio::common::AudioFormatDescription mFormat;
59     const size_t mFrameSizeBytes;
60     const bool mIsInput;
61     const std::weak_ptr<IBluetoothA2dp> mBluetoothA2dp;
62     const std::weak_ptr<IBluetoothLe> mBluetoothLe;
63     size_t mPreferredDataIntervalUs;
64     size_t mPreferredFrameCount;
65 
66     mutable std::mutex mLock;
67     bool mIsInitialized GUARDED_BY(mLock);
68     bool mIsReadyToClose GUARDED_BY(mLock);
69     std::vector<std::shared_ptr<::android::bluetooth::audio::aidl::BluetoothAudioPortAidl>>
70             mBtDeviceProxies GUARDED_BY(mLock);
71 
72     ::android::status_t initialize() REQUIRES(mLock);
73     bool checkConfigParams(::aidl::android::hardware::bluetooth::audio::PcmConfiguration& config);
74 };
75 
76 class StreamInBluetooth final : public StreamIn, public StreamBluetooth {
77   public:
78     friend class ndk::SharedRefBase;
79     StreamInBluetooth(
80             StreamContext&& context,
81             const ::aidl::android::hardware::audio::common::SinkMetadata& sinkMetadata,
82             const std::vector<::aidl::android::media::audio::common::MicrophoneInfo>& microphones,
83             Module::BtProfileHandles&& btHandles);
84 
85   private:
onClose(StreamDescriptor::State)86     void onClose(StreamDescriptor::State) override { defaultOnClose(); }
87     ndk::ScopedAStatus getActiveMicrophones(
88             std::vector<::aidl::android::media::audio::common::MicrophoneDynamicInfo>* _aidl_return)
89             override;
90 };
91 
92 class StreamOutBluetooth final : public StreamOut, public StreamBluetooth {
93   public:
94     friend class ndk::SharedRefBase;
95     StreamOutBluetooth(
96             StreamContext&& context,
97             const ::aidl::android::hardware::audio::common::SourceMetadata& sourceMetadata,
98             const std::optional<::aidl::android::media::audio::common::AudioOffloadInfo>&
99                     offloadInfo,
100             Module::BtProfileHandles&& btHandles);
101 
102   private:
onClose(StreamDescriptor::State)103     void onClose(StreamDescriptor::State) override { defaultOnClose(); }
104 };
105 
106 }  // namespace aidl::android::hardware::audio::core
107