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 <atomic> 20 #include <mutex> 21 #include <vector> 22 23 #include <aidl/android/media/audio/common/AudioChannelLayout.h> 24 25 #include "StreamAlsa.h" 26 27 namespace aidl::android::hardware::audio::core { 28 29 class StreamUsb : public StreamAlsa { 30 public: 31 StreamUsb(StreamContext* context, const Metadata& metadata); 32 33 // Methods of 'DriverInterface'. 34 ::android::status_t transfer(void* buffer, size_t frameCount, size_t* actualFrameCount, 35 int32_t* latencyMs) override; 36 37 // Overridden methods of 'StreamCommonImpl', called on a Binder thread. 38 ndk::ScopedAStatus setConnectedDevices(const ConnectedDevices& devices) override; 39 40 protected: 41 std::vector<alsa::DeviceProfile> getDeviceProfiles() override; 42 43 mutable std::mutex mLock; 44 std::vector<alsa::DeviceProfile> mConnectedDeviceProfiles GUARDED_BY(mLock); 45 std::atomic<bool> mConnectedDevicesUpdated = false; 46 }; 47 48 class StreamInUsb final : public StreamIn, public StreamUsb { 49 public: 50 friend class ndk::SharedRefBase; 51 StreamInUsb( 52 StreamContext&& context, 53 const ::aidl::android::hardware::audio::common::SinkMetadata& sinkMetadata, 54 const std::vector<::aidl::android::media::audio::common::MicrophoneInfo>& microphones); 55 56 private: onClose(StreamDescriptor::State)57 void onClose(StreamDescriptor::State) override { defaultOnClose(); } 58 ndk::ScopedAStatus getActiveMicrophones( 59 std::vector<::aidl::android::media::audio::common::MicrophoneDynamicInfo>* _aidl_return) 60 override; 61 }; 62 63 class StreamOutUsb final : public StreamOut, public StreamUsb, public StreamOutHwVolumeHelper { 64 public: 65 friend class ndk::SharedRefBase; 66 StreamOutUsb(StreamContext&& context, 67 const ::aidl::android::hardware::audio::common::SourceMetadata& sourceMetadata, 68 const std::optional<::aidl::android::media::audio::common::AudioOffloadInfo>& 69 offloadInfo); 70 71 private: onClose(StreamDescriptor::State)72 void onClose(StreamDescriptor::State) override { defaultOnClose(); } 73 ndk::ScopedAStatus getHwVolume(std::vector<float>* _aidl_return) override; 74 ndk::ScopedAStatus setHwVolume(const std::vector<float>& in_channelVolumes) override; 75 }; 76 77 } // namespace aidl::android::hardware::audio::core 78