Andy Hung | 4dbf0e9 | 2023-07-06 15:46:44 -0700 | [diff] [blame] | 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 | |
Andy Hung | c6f227f | 2023-07-18 18:31:50 -0700 | [diff] [blame^] | 19 | #include "AudioHwDevice.h" |
Andy Hung | 4dbf0e9 | 2023-07-06 15:46:44 -0700 | [diff] [blame] | 20 | #include <media/audiohal/DeviceHalInterface.h> |
| 21 | #include <media/audiohal/StreamHalInterface.h> |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | // Abstraction for the Audio Source for the RecordThread (HAL or PassthruPatchRecord). |
| 26 | struct Source { |
| 27 | virtual ~Source() = default; |
| 28 | // The following methods have the same signatures as in StreamHalInterface. |
| 29 | virtual status_t read(void* buffer, size_t bytes, size_t* read) = 0; |
| 30 | virtual status_t getCapturePosition(int64_t* frames, int64_t* time) = 0; |
| 31 | virtual status_t standby() = 0; |
| 32 | }; |
| 33 | |
| 34 | // AudioStreamIn is immutable, so its fields are const. |
| 35 | // The methods must not be const to match StreamHalInterface signature. |
| 36 | |
| 37 | struct AudioStreamIn : public Source { |
| 38 | const AudioHwDevice* const audioHwDev; |
| 39 | const sp<StreamInHalInterface> stream; |
| 40 | const audio_input_flags_t flags; |
| 41 | |
| 42 | AudioStreamIn( |
| 43 | const AudioHwDevice* dev, const sp<StreamInHalInterface>& in, |
| 44 | audio_input_flags_t flags) |
| 45 | : audioHwDev(dev), stream(in), flags(flags) {} |
| 46 | |
| 47 | status_t read(void* buffer, size_t bytes, size_t* read) final { |
| 48 | return stream->read(buffer, bytes, read); |
| 49 | } |
| 50 | |
| 51 | status_t getCapturePosition(int64_t* frames, int64_t* time) final { |
| 52 | return stream->getCapturePosition(frames, time); |
| 53 | } |
| 54 | |
| 55 | status_t standby() final { return stream->standby(); } |
| 56 | |
| 57 | sp<DeviceHalInterface> hwDev() const { return audioHwDev->hwDevice(); } |
| 58 | }; |
| 59 | |
| 60 | } // namespace android |