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 "core-impl/Stream.h" 20 21 namespace aidl::android::hardware::audio::core { 22 23 class StreamStub : public StreamCommonImpl { 24 public: 25 StreamStub(StreamContext* context, const Metadata& metadata); 26 // Methods of 'DriverInterface'. 27 ::android::status_t init() override; 28 ::android::status_t drain(StreamDescriptor::DrainMode) override; 29 ::android::status_t flush() override; 30 ::android::status_t pause() override; 31 ::android::status_t standby() override; 32 ::android::status_t start() override; 33 ::android::status_t transfer(void* buffer, size_t frameCount, size_t* actualFrameCount, 34 int32_t* latencyMs) override; 35 void shutdown() override; 36 37 private: 38 const size_t mBufferSizeFrames; 39 const size_t mFrameSizeBytes; 40 const int mSampleRate; 41 const bool mIsAsynchronous; 42 const bool mIsInput; 43 bool mIsInitialized = false; // Used for validating the state machine logic. 44 bool mIsStandby = true; // Used for validating the state machine logic. 45 }; 46 47 class StreamInStub final : public StreamIn, public StreamStub { 48 public: 49 friend class ndk::SharedRefBase; 50 StreamInStub( 51 StreamContext&& context, 52 const ::aidl::android::hardware::audio::common::SinkMetadata& sinkMetadata, 53 const std::vector<::aidl::android::media::audio::common::MicrophoneInfo>& microphones); 54 55 private: onClose(StreamDescriptor::State)56 void onClose(StreamDescriptor::State) override { defaultOnClose(); } 57 }; 58 59 class StreamOutStub final : public StreamOut, public StreamStub { 60 public: 61 friend class ndk::SharedRefBase; 62 StreamOutStub(StreamContext&& context, 63 const ::aidl::android::hardware::audio::common::SourceMetadata& sourceMetadata, 64 const std::optional<::aidl::android::media::audio::common::AudioOffloadInfo>& 65 offloadInfo); 66 67 private: onClose(StreamDescriptor::State)68 void onClose(StreamDescriptor::State) override { defaultOnClose(); } 69 }; 70 71 } // namespace aidl::android::hardware::audio::core 72