blob: b86738741284a3d6254ea37a2995519d0fc1e2e2 [file] [log] [blame]
Mikhail Naganov10548292016-10-31 10:39:47 -07001/*
2 * Copyright (C) 2016 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
Steven Morelandd6e4f032016-11-28 18:37:07 -080017#ifndef ANDROID_HARDWARE_AUDIO_V2_0_STREAMIN_H
18#define ANDROID_HARDWARE_AUDIO_V2_0_STREAMIN_H
Mikhail Naganov10548292016-10-31 10:39:47 -070019
Mikhail Naganovb29438e2016-12-22 09:21:34 -080020#include <atomic>
21#include <memory>
Mikhail Naganov10548292016-10-31 10:39:47 -070022
Mikhail Naganovb29438e2016-12-22 09:21:34 -080023#include <android/hardware/audio/2.0/IStreamIn.h>
Mikhail Naganov10548292016-10-31 10:39:47 -070024#include <hidl/MQDescriptor.h>
Mikhail Naganovb29438e2016-12-22 09:21:34 -080025#include <fmq/EventFlag.h>
26#include <fmq/MessageQueue.h>
27#include <hidl/Status.h>
28#include <utils/Thread.h>
Mikhail Naganov10548292016-10-31 10:39:47 -070029
30#include "Stream.h"
31
32namespace android {
33namespace hardware {
34namespace audio {
35namespace V2_0 {
36namespace implementation {
37
38using ::android::hardware::audio::common::V2_0::AudioChannelMask;
39using ::android::hardware::audio::common::V2_0::AudioDevice;
40using ::android::hardware::audio::common::V2_0::AudioFormat;
41using ::android::hardware::audio::common::V2_0::AudioSource;
42using ::android::hardware::audio::V2_0::DeviceAddress;
43using ::android::hardware::audio::V2_0::IStream;
44using ::android::hardware::audio::V2_0::IStreamIn;
45using ::android::hardware::audio::V2_0::ParameterValue;
46using ::android::hardware::audio::V2_0::Result;
47using ::android::hardware::Return;
48using ::android::hardware::Void;
49using ::android::hardware::hidl_vec;
50using ::android::hardware::hidl_string;
51using ::android::sp;
52
53struct StreamIn : public IStreamIn {
Mikhail Naganova468fa82017-01-31 13:56:02 -080054 typedef MessageQueue<ReadParameters, kSynchronizedReadWrite> CommandMQ;
Mikhail Naganovb29438e2016-12-22 09:21:34 -080055 typedef MessageQueue<uint8_t, kSynchronizedReadWrite> DataMQ;
56 typedef MessageQueue<ReadStatus, kSynchronizedReadWrite> StatusMQ;
57
Mikhail Naganov10548292016-10-31 10:39:47 -070058 StreamIn(audio_hw_device_t* device, audio_stream_in_t* stream);
59
60 // Methods from ::android::hardware::audio::V2_0::IStream follow.
61 Return<uint64_t> getFrameSize() override;
62 Return<uint64_t> getFrameCount() override;
63 Return<uint64_t> getBufferSize() override;
64 Return<uint32_t> getSampleRate() override;
65 Return<void> getSupportedSampleRates(getSupportedSampleRates_cb _hidl_cb) override;
66 Return<Result> setSampleRate(uint32_t sampleRateHz) override;
67 Return<AudioChannelMask> getChannelMask() override;
68 Return<void> getSupportedChannelMasks(getSupportedChannelMasks_cb _hidl_cb) override;
69 Return<Result> setChannelMask(AudioChannelMask mask) override;
70 Return<AudioFormat> getFormat() override;
71 Return<void> getSupportedFormats(getSupportedFormats_cb _hidl_cb) override;
72 Return<Result> setFormat(AudioFormat format) override;
73 Return<void> getAudioProperties(getAudioProperties_cb _hidl_cb) override;
74 Return<Result> addEffect(uint64_t effectId) override;
75 Return<Result> removeEffect(uint64_t effectId) override;
76 Return<Result> standby() override;
77 Return<AudioDevice> getDevice() override;
78 Return<Result> setDevice(const DeviceAddress& address) override;
79 Return<Result> setConnectedState(const DeviceAddress& address, bool connected) override;
80 Return<Result> setHwAvSync(uint32_t hwAvSync) override;
81 Return<void> getParameters(
82 const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) override;
83 Return<Result> setParameters(const hidl_vec<ParameterValue>& parameters) override;
Martijn Coenen70b9a152016-11-18 15:29:32 +010084 Return<void> debugDump(const hidl_handle& fd) override;
Mikhail Naganovb29438e2016-12-22 09:21:34 -080085 Return<Result> close() override;
Mikhail Naganov10548292016-10-31 10:39:47 -070086
87 // Methods from ::android::hardware::audio::V2_0::IStreamIn follow.
88 Return<void> getAudioSource(getAudioSource_cb _hidl_cb) override;
89 Return<Result> setGain(float gain) override;
Mikhail Naganovb29438e2016-12-22 09:21:34 -080090 Return<void> prepareForReading(
Mikhail Naganova1db22a2017-02-07 10:49:18 -080091 uint32_t frameSize, uint32_t framesCount, prepareForReading_cb _hidl_cb) override;
Mikhail Naganov10548292016-10-31 10:39:47 -070092 Return<uint32_t> getInputFramesLost() override;
93 Return<void> getCapturePosition(getCapturePosition_cb _hidl_cb) override;
Eric Laurent7deb7da2016-12-15 19:15:45 -080094 Return<Result> start() override;
95 Return<Result> stop() override;
96 Return<void> createMmapBuffer(int32_t minSizeFrames, createMmapBuffer_cb _hidl_cb) override;
97 Return<void> getMmapPosition(getMmapPosition_cb _hidl_cb) override;
Mikhail Naganov10548292016-10-31 10:39:47 -070098
Mikhail Naganova468fa82017-01-31 13:56:02 -080099 static Result getCapturePositionImpl(
100 audio_stream_in_t *stream, uint64_t *frames, uint64_t *time);
101
Mikhail Naganov10548292016-10-31 10:39:47 -0700102 private:
Mikhail Naganovb29438e2016-12-22 09:21:34 -0800103 bool mIsClosed;
Mikhail Naganov10548292016-10-31 10:39:47 -0700104 audio_hw_device_t *mDevice;
105 audio_stream_in_t *mStream;
106 sp<Stream> mStreamCommon;
Eric Laurent7deb7da2016-12-15 19:15:45 -0800107 sp<StreamMmap<audio_stream_in_t>> mStreamMmap;
Mikhail Naganova468fa82017-01-31 13:56:02 -0800108 std::unique_ptr<CommandMQ> mCommandMQ;
Mikhail Naganovb29438e2016-12-22 09:21:34 -0800109 std::unique_ptr<DataMQ> mDataMQ;
110 std::unique_ptr<StatusMQ> mStatusMQ;
111 EventFlag* mEfGroup;
112 std::atomic<bool> mStopReadThread;
113 sp<Thread> mReadThread;
Mikhail Naganov10548292016-10-31 10:39:47 -0700114
115 virtual ~StreamIn();
116};
117
118} // namespace implementation
119} // namespace V2_0
120} // namespace audio
121} // namespace hardware
122} // namespace android
123
Steven Morelandd6e4f032016-11-28 18:37:07 -0800124#endif // ANDROID_HARDWARE_AUDIO_V2_0_STREAMIN_H