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 <vector> 20 21 #include "StreamAlsa.h" 22 #include "StreamSwitcher.h" 23 24 namespace aidl::android::hardware::audio::core { 25 26 class StreamPrimary : public StreamAlsa { 27 public: 28 StreamPrimary(StreamContext* context, const Metadata& metadata); 29 30 ::android::status_t start() override; 31 ::android::status_t transfer(void* buffer, size_t frameCount, size_t* actualFrameCount, 32 int32_t* latencyMs) override; 33 ::android::status_t refinePosition(StreamDescriptor::Position* position) override; 34 35 protected: 36 std::vector<alsa::DeviceProfile> getDeviceProfiles() override; 37 38 const bool mIsAsynchronous; 39 int64_t mStartTimeNs = 0; 40 long mFramesSinceStart = 0; 41 bool mSkipNextTransfer = false; 42 }; 43 44 class StreamInPrimary final : public StreamIn, public StreamSwitcher, public StreamInHwGainHelper { 45 public: 46 friend class ndk::SharedRefBase; 47 StreamInPrimary( 48 StreamContext&& context, 49 const ::aidl::android::hardware::audio::common::SinkMetadata& sinkMetadata, 50 const std::vector<::aidl::android::media::audio::common::MicrophoneInfo>& microphones); 51 52 private: 53 static bool useStubStream(const ::aidl::android::media::audio::common::AudioDevice& device); 54 55 DeviceSwitchBehavior switchCurrentStream( 56 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices) 57 override; 58 std::unique_ptr<StreamCommonInterfaceEx> createNewStream( 59 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices, 60 StreamContext* context, const Metadata& metadata) override; onClose(StreamDescriptor::State)61 void onClose(StreamDescriptor::State) override { defaultOnClose(); } 62 63 ndk::ScopedAStatus getHwGain(std::vector<float>* _aidl_return) override; 64 ndk::ScopedAStatus setHwGain(const std::vector<float>& in_channelGains) override; 65 }; 66 67 class StreamOutPrimary final : public StreamOut, 68 public StreamSwitcher, 69 public StreamOutHwVolumeHelper { 70 public: 71 friend class ndk::SharedRefBase; 72 StreamOutPrimary(StreamContext&& context, 73 const ::aidl::android::hardware::audio::common::SourceMetadata& sourceMetadata, 74 const std::optional<::aidl::android::media::audio::common::AudioOffloadInfo>& 75 offloadInfo); 76 77 private: 78 static bool useStubStream(const ::aidl::android::media::audio::common::AudioDevice& device); 79 80 DeviceSwitchBehavior switchCurrentStream( 81 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices) 82 override; 83 std::unique_ptr<StreamCommonInterfaceEx> createNewStream( 84 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices, 85 StreamContext* context, const Metadata& metadata) override; onClose(StreamDescriptor::State)86 void onClose(StreamDescriptor::State) override { defaultOnClose(); } 87 88 ndk::ScopedAStatus getHwVolume(std::vector<float>* _aidl_return) override; 89 ndk::ScopedAStatus setHwVolume(const std::vector<float>& in_channelVolumes) override; 90 91 ndk::ScopedAStatus setConnectedDevices( 92 const std::vector<::aidl::android::media::audio::common::AudioDevice>& devices) 93 override; 94 }; 95 96 } // namespace aidl::android::hardware::audio::core 97