• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 #include <android/hardware/audio/6.0/IStreamIn.h>
19 #include <android/hardware/audio/6.0/IDevice.h>
20 #include "stream_common.h"
21 #include "io_thread.h"
22 
23 namespace android {
24 namespace hardware {
25 namespace audio {
26 namespace V6_0 {
27 namespace implementation {
28 
29 using ::android::sp;
30 using ::android::hardware::hidl_bitfield;
31 using ::android::hardware::hidl_string;
32 using ::android::hardware::hidl_vec;
33 using ::android::hardware::Return;
34 using namespace ::android::hardware::audio::common::V6_0;
35 using namespace ::android::hardware::audio::V6_0;
36 
37 struct StreamIn : public IStreamIn {
38     StreamIn(sp<IDevice> dev,
39              void (*unrefDevice)(IDevice*),
40              int32_t ioHandle,
41              const DeviceAddress& device,
42              const AudioConfig& config,
43              hidl_bitfield<AudioInputFlag> flags,
44              const SinkMetadata& sinkMetadata);
45     ~StreamIn();
46 
47     // IStream
48     Return<uint64_t> getFrameSize() override;
49     Return<uint64_t> getFrameCount() override;
50     Return<uint64_t> getBufferSize() override;
51     Return<uint32_t> getSampleRate() override;
52     Return<void> getSupportedSampleRates(AudioFormat format, getSupportedSampleRates_cb _hidl_cb) override;
53     Return<Result> setSampleRate(uint32_t sampleRateHz) override;
54     Return<hidl_bitfield<AudioChannelMask>> getChannelMask() override;
55     Return<void> getSupportedChannelMasks(AudioFormat format, getSupportedChannelMasks_cb _hidl_cb) override;
56     Return<Result> setChannelMask(hidl_bitfield<AudioChannelMask> mask) override;
57     Return<AudioFormat> getFormat() override;
58     Return<void> getSupportedFormats(getSupportedFormats_cb _hidl_cb) override;
59     Return<Result> setFormat(AudioFormat format) override;
60     Return<void> getAudioProperties(getAudioProperties_cb _hidl_cb) override;
61     Return<Result> addEffect(uint64_t effectId) override;
62     Return<Result> removeEffect(uint64_t effectId) override;
63     Return<Result> standby() override;
64     Return<void> getDevices(getDevices_cb _hidl_cb) override;
65     Return<Result> setDevices(const hidl_vec<DeviceAddress>& devices) override;
66     Return<Result> setHwAvSync(uint32_t hwAvSync) override;
67     Return<void> getParameters(const hidl_vec<ParameterValue>& context,
68                                const hidl_vec<hidl_string>& keys,
69                                getParameters_cb _hidl_cb) override;
70     Return<Result> setParameters(const hidl_vec<ParameterValue>& context,
71                                  const hidl_vec<ParameterValue>& parameters) override;
72     Return<Result> start() override;
73     Return<Result> stop() override;
74     Return<void> createMmapBuffer(int32_t minSizeFrames, createMmapBuffer_cb _hidl_cb) override;
75     Return<void> getMmapPosition(getMmapPosition_cb _hidl_cb) override;
76     Return<Result> close() override;
77 
78     // IStreamIn
79     Return<void> getAudioSource(getAudioSource_cb _hidl_cb) override;
80     Return<Result> setGain(float gain) override;
81     Return<void> updateSinkMetadata(const SinkMetadata& sinkMetadata) override;
82     Return<void> prepareForReading(uint32_t frameSize, uint32_t framesCount,
83                                    prepareForReading_cb _hidl_cb) override;
84     Return<uint32_t> getInputFramesLost() override;
85     Return<void> getCapturePosition(getCapturePosition_cb _hidl_cb) override;
86     Return<void> getActiveMicrophones(getActiveMicrophones_cb _hidl_cb) override;
87     Return<Result> setMicrophoneDirection(MicrophoneDirection direction) override;
88     Return<Result> setMicrophoneFieldDimension(float zoom) override;
89 
getDeviceAddressStreamIn90     const DeviceAddress &getDeviceAddress() const { return mCommon.m_device; }
getAudioConfigStreamIn91     const AudioConfig &getAudioConfig() const { return mCommon.m_config; }
getAudioOutputFlagsStreamIn92     const hidl_bitfield<AudioOutputFlag> &getAudioOutputFlags() const { return mCommon.m_flags; }
93 
getFrameCounterStreamIn94     uint64_t &getFrameCounter() { return mFrames; }
95 
96 private:
97     Result closeImpl(bool fromDctor);
98 
99     sp<IDevice> mDev;
100     void (* const mUnrefDevice)(IDevice*);
101     const StreamCommon mCommon;
102     const SinkMetadata mSinkMetadata;
103     std::unique_ptr<IOThread> mReadThread;
104 
105     // The count is not reset to zero when output enters standby.
106     uint64_t mFrames = 0;
107 };
108 
109 }  // namespace implementation
110 }  // namespace V6_0
111 }  // namespace audio
112 }  // namespace hardware
113 }  // namespace android
114