blob: 748f96b773dfee2760d227ea27b8d7135b7f3ad3 [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_DEVICE_H
18#define ANDROID_HARDWARE_AUDIO_V2_0_DEVICE_H
Mikhail Naganov10548292016-10-31 10:39:47 -070019
20#include <memory>
21
22#include <media/AudioParameter.h>
23#include <hardware/audio.h>
24
25#include <android/hardware/audio/2.0/IDevice.h>
26#include <hidl/Status.h>
27
28#include <hidl/MQDescriptor.h>
29
Mikhail Naganov10548292016-10-31 10:39:47 -070030namespace android {
31namespace hardware {
32namespace audio {
33namespace V2_0 {
34namespace implementation {
35
Mikhail Naganove4228e72017-04-28 13:20:56 -070036class ParametersUtil;
37
Mikhail Naganov10548292016-10-31 10:39:47 -070038using ::android::hardware::audio::common::V2_0::AudioConfig;
Mikhail Naganov10548292016-10-31 10:39:47 -070039using ::android::hardware::audio::common::V2_0::AudioHwSync;
40using ::android::hardware::audio::common::V2_0::AudioInputFlag;
Mikhail Naganov10548292016-10-31 10:39:47 -070041using ::android::hardware::audio::common::V2_0::AudioOutputFlag;
42using ::android::hardware::audio::common::V2_0::AudioPatchHandle;
43using ::android::hardware::audio::common::V2_0::AudioPort;
44using ::android::hardware::audio::common::V2_0::AudioPortConfig;
Mikhail Naganov10548292016-10-31 10:39:47 -070045using ::android::hardware::audio::common::V2_0::AudioSource;
Mikhail Naganov10548292016-10-31 10:39:47 -070046using ::android::hardware::audio::V2_0::DeviceAddress;
47using ::android::hardware::audio::V2_0::IDevice;
48using ::android::hardware::audio::V2_0::IStreamIn;
49using ::android::hardware::audio::V2_0::IStreamOut;
50using ::android::hardware::audio::V2_0::ParameterValue;
51using ::android::hardware::audio::V2_0::Result;
52using ::android::hardware::Return;
53using ::android::hardware::Void;
54using ::android::hardware::hidl_vec;
55using ::android::hardware::hidl_string;
56using ::android::sp;
57
Mikhail Naganove4228e72017-04-28 13:20:56 -070058struct Device : public IDevice {
Mikhail Naganov10548292016-10-31 10:39:47 -070059 explicit Device(audio_hw_device_t* device);
60
61 // Methods from ::android::hardware::audio::V2_0::IDevice follow.
62 Return<Result> initCheck() override;
63 Return<Result> setMasterVolume(float volume) override;
64 Return<void> getMasterVolume(getMasterVolume_cb _hidl_cb) override;
65 Return<Result> setMicMute(bool mute) override;
66 Return<void> getMicMute(getMicMute_cb _hidl_cb) override;
67 Return<Result> setMasterMute(bool mute) override;
68 Return<void> getMasterMute(getMasterMute_cb _hidl_cb) override;
69 Return<void> getInputBufferSize(
70 const AudioConfig& config, getInputBufferSize_cb _hidl_cb) override;
71 Return<void> openOutputStream(
72 int32_t ioHandle,
73 const DeviceAddress& device,
74 const AudioConfig& config,
75 AudioOutputFlag flags,
76 openOutputStream_cb _hidl_cb) override;
77 Return<void> openInputStream(
78 int32_t ioHandle,
79 const DeviceAddress& device,
80 const AudioConfig& config,
81 AudioInputFlag flags,
82 AudioSource source,
83 openInputStream_cb _hidl_cb) override;
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080084 Return<bool> supportsAudioPatches() override;
Mikhail Naganov10548292016-10-31 10:39:47 -070085 Return<void> createAudioPatch(
86 const hidl_vec<AudioPortConfig>& sources,
87 const hidl_vec<AudioPortConfig>& sinks,
88 createAudioPatch_cb _hidl_cb) override;
89 Return<Result> releaseAudioPatch(int32_t patch) override;
90 Return<void> getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) override;
91 Return<Result> setAudioPortConfig(const AudioPortConfig& config) override;
92 Return<AudioHwSync> getHwAvSync() override;
93 Return<Result> setScreenState(bool turnedOn) override;
94 Return<void> getParameters(
95 const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) override;
96 Return<Result> setParameters(const hidl_vec<ParameterValue>& parameters) override;
Martijn Coenen70b9a152016-11-18 15:29:32 +010097 Return<void> debugDump(const hidl_handle& fd) override;
Mikhail Naganov10548292016-10-31 10:39:47 -070098
99 // Utility methods for extending interfaces.
100 Result analyzeStatus(const char* funcName, int status);
Mikhail Naganov936279e2017-03-29 09:31:18 -0700101 void closeInputStream(audio_stream_in_t* stream);
102 void closeOutputStream(audio_stream_out_t* stream);
Mikhail Naganov10548292016-10-31 10:39:47 -0700103 audio_hw_device_t* device() const { return mDevice; }
Mikhail Naganove4228e72017-04-28 13:20:56 -0700104 Result getParam(const char* name, bool* value);
105 Result getParam(const char* name, int* value);
106 Result getParam(const char* name, String8* value);
107 Result setParam(const char* name, bool value);
108 Result setParam(const char* name, int value);
109 Result setParam(const char* name, const char* value);
Mikhail Naganov10548292016-10-31 10:39:47 -0700110
Mikhail Naganove4228e72017-04-28 13:20:56 -0700111 private:
Mikhail Naganov10548292016-10-31 10:39:47 -0700112 audio_hw_device_t *mDevice;
Mikhail Naganove4228e72017-04-28 13:20:56 -0700113 std::unique_ptr<ParametersUtil> mParameters;
Mikhail Naganov10548292016-10-31 10:39:47 -0700114
Mikhail Naganov10548292016-10-31 10:39:47 -0700115 virtual ~Device();
116
Mikhail Naganov10548292016-10-31 10:39:47 -0700117 uint32_t version() const { return mDevice->common.version; }
118};
119
120} // namespace implementation
121} // namespace V2_0
122} // namespace audio
123} // namespace hardware
124} // namespace android
125
Steven Morelandd6e4f032016-11-28 18:37:07 -0800126#endif // ANDROID_HARDWARE_AUDIO_V2_0_DEVICE_H