1 /*
2  * Copyright 2022 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 "audio_aidl_interfaces.h"
20 #include "transport_instance.h"
21 
22 namespace bluetooth {
23 namespace audio {
24 namespace aidl {
25 
26 using ::aidl::android::hardware::audio::common::SinkMetadata;
27 using ::aidl::android::hardware::audio::common::SourceMetadata;
28 using ::aidl::android::hardware::bluetooth::audio::BnBluetoothAudioPort;
29 using ::aidl::android::hardware::bluetooth::audio::CodecType;
30 using ::aidl::android::hardware::bluetooth::audio::IBluetoothAudioProvider;
31 using ::aidl::android::hardware::bluetooth::audio::LatencyMode;
32 using ::aidl::android::hardware::bluetooth::audio::PresentationPosition;
33 
34 class BluetoothAudioPortImpl : public BnBluetoothAudioPort {
35  public:
36   BluetoothAudioPortImpl(
37       IBluetoothTransportInstance* transport_instance,
38       const std::shared_ptr<IBluetoothAudioProvider>& provider);
39 
40   ndk::ScopedAStatus startStream(bool is_low_latency) override;
41 
42   ndk::ScopedAStatus suspendStream() override;
43 
44   ndk::ScopedAStatus stopStream() override;
45 
46   ndk::ScopedAStatus getPresentationPosition(
47       PresentationPosition* _aidl_return) override;
48 
49   ndk::ScopedAStatus updateSourceMetadata(
50       const SourceMetadata& source_metadata) override;
51 
52   ndk::ScopedAStatus updateSinkMetadata(
53       const SinkMetadata& sink_metadata) override;
54 
55   ndk::ScopedAStatus setLatencyMode(LatencyMode latency_mode) override;
56 
57  protected:
58   virtual ~BluetoothAudioPortImpl();
59 
60   IBluetoothTransportInstance* transport_instance_;
61   const std::shared_ptr<IBluetoothAudioProvider> provider_;
62   PresentationPosition::TimeSpec timespec_convert_to_hal(const timespec& ts);
63 
64  private:
65   ndk::ScopedAStatus switchCodec(bool isLowLatency);
66 
67   ndk::SpAIBinder createBinder() override;
68 };
69 
70 }  // namespace aidl
71 }  // namespace audio
72 }  // namespace bluetooth
73