blob: 950d68fc73ed76e685c6f827dd3cd82f4587cb9b [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
Mikhail Naganov936279e2017-03-29 09:31:18 -070030#include "Device.h"
Mikhail Naganov10548292016-10-31 10:39:47 -070031#include "Stream.h"
32
33namespace android {
34namespace hardware {
35namespace audio {
36namespace V2_0 {
37namespace implementation {
38
39using ::android::hardware::audio::common::V2_0::AudioChannelMask;
40using ::android::hardware::audio::common::V2_0::AudioDevice;
41using ::android::hardware::audio::common::V2_0::AudioFormat;
42using ::android::hardware::audio::common::V2_0::AudioSource;
43using ::android::hardware::audio::V2_0::DeviceAddress;
44using ::android::hardware::audio::V2_0::IStream;
45using ::android::hardware::audio::V2_0::IStreamIn;
46using ::android::hardware::audio::V2_0::ParameterValue;
47using ::android::hardware::audio::V2_0::Result;
48using ::android::hardware::Return;
49using ::android::hardware::Void;
50using ::android::hardware::hidl_vec;
51using ::android::hardware::hidl_string;
52using ::android::sp;
53
54struct StreamIn : public IStreamIn {
Mikhail Naganova468fa82017-01-31 13:56:02 -080055 typedef MessageQueue<ReadParameters, kSynchronizedReadWrite> CommandMQ;
Mikhail Naganovb29438e2016-12-22 09:21:34 -080056 typedef MessageQueue<uint8_t, kSynchronizedReadWrite> DataMQ;
57 typedef MessageQueue<ReadStatus, kSynchronizedReadWrite> StatusMQ;
58
Mikhail Naganov936279e2017-03-29 09:31:18 -070059 StreamIn(const sp<Device>& device, audio_stream_in_t* stream);
Mikhail Naganov10548292016-10-31 10:39:47 -070060
61 // Methods from ::android::hardware::audio::V2_0::IStream follow.
62 Return<uint64_t> getFrameSize() override;
63 Return<uint64_t> getFrameCount() override;
64 Return<uint64_t> getBufferSize() override;
65 Return<uint32_t> getSampleRate() override;
66 Return<void> getSupportedSampleRates(getSupportedSampleRates_cb _hidl_cb) override;
67 Return<Result> setSampleRate(uint32_t sampleRateHz) override;
68 Return<AudioChannelMask> getChannelMask() override;
69 Return<void> getSupportedChannelMasks(getSupportedChannelMasks_cb _hidl_cb) override;
70 Return<Result> setChannelMask(AudioChannelMask mask) override;
71 Return<AudioFormat> getFormat() override;
72 Return<void> getSupportedFormats(getSupportedFormats_cb _hidl_cb) override;
73 Return<Result> setFormat(AudioFormat format) override;
74 Return<void> getAudioProperties(getAudioProperties_cb _hidl_cb) override;
75 Return<Result> addEffect(uint64_t effectId) override;
76 Return<Result> removeEffect(uint64_t effectId) override;
77 Return<Result> standby() override;
78 Return<AudioDevice> getDevice() override;
79 Return<Result> setDevice(const DeviceAddress& address) override;
80 Return<Result> setConnectedState(const DeviceAddress& address, bool connected) override;
81 Return<Result> setHwAvSync(uint32_t hwAvSync) override;
82 Return<void> getParameters(
83 const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) override;
84 Return<Result> setParameters(const hidl_vec<ParameterValue>& parameters) override;
Martijn Coenen70b9a152016-11-18 15:29:32 +010085 Return<void> debugDump(const hidl_handle& fd) override;
Mikhail Naganovb29438e2016-12-22 09:21:34 -080086 Return<Result> close() override;
Mikhail Naganov10548292016-10-31 10:39:47 -070087
88 // Methods from ::android::hardware::audio::V2_0::IStreamIn follow.
89 Return<void> getAudioSource(getAudioSource_cb _hidl_cb) override;
90 Return<Result> setGain(float gain) override;
Mikhail Naganovb29438e2016-12-22 09:21:34 -080091 Return<void> prepareForReading(
Mikhail Naganova1db22a2017-02-07 10:49:18 -080092 uint32_t frameSize, uint32_t framesCount, prepareForReading_cb _hidl_cb) override;
Mikhail Naganov10548292016-10-31 10:39:47 -070093 Return<uint32_t> getInputFramesLost() override;
94 Return<void> getCapturePosition(getCapturePosition_cb _hidl_cb) override;
Eric Laurent7deb7da2016-12-15 19:15:45 -080095 Return<Result> start() override;
96 Return<Result> stop() override;
97 Return<void> createMmapBuffer(int32_t minSizeFrames, createMmapBuffer_cb _hidl_cb) override;
98 Return<void> getMmapPosition(getMmapPosition_cb _hidl_cb) override;
Mikhail Naganov10548292016-10-31 10:39:47 -070099
Mikhail Naganova468fa82017-01-31 13:56:02 -0800100 static Result getCapturePositionImpl(
101 audio_stream_in_t *stream, uint64_t *frames, uint64_t *time);
102
Mikhail Naganov10548292016-10-31 10:39:47 -0700103 private:
Mikhail Naganovb29438e2016-12-22 09:21:34 -0800104 bool mIsClosed;
Mikhail Naganov936279e2017-03-29 09:31:18 -0700105 const sp<Device> mDevice;
Mikhail Naganov10548292016-10-31 10:39:47 -0700106 audio_stream_in_t *mStream;
Mikhail Naganov936279e2017-03-29 09:31:18 -0700107 const sp<Stream> mStreamCommon;
108 const sp<StreamMmap<audio_stream_in_t>> mStreamMmap;
Mikhail Naganova468fa82017-01-31 13:56:02 -0800109 std::unique_ptr<CommandMQ> mCommandMQ;
Mikhail Naganovb29438e2016-12-22 09:21:34 -0800110 std::unique_ptr<DataMQ> mDataMQ;
111 std::unique_ptr<StatusMQ> mStatusMQ;
112 EventFlag* mEfGroup;
113 std::atomic<bool> mStopReadThread;
114 sp<Thread> mReadThread;
Mikhail Naganov10548292016-10-31 10:39:47 -0700115
116 virtual ~StreamIn();
117};
118
119} // namespace implementation
120} // namespace V2_0
121} // namespace audio
122} // namespace hardware
123} // namespace android
124
Steven Morelandd6e4f032016-11-28 18:37:07 -0800125#endif // ANDROID_HARDWARE_AUDIO_V2_0_STREAMIN_H