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