blob: e0a067ee340704803123426461c7b5b0333b3a3a [file] [log] [blame]
Mikhail Naganovf558e022016-11-14 17:45:17 -08001/*
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
17#ifndef ANDROID_HARDWARE_STREAM_HAL_HIDL_H
18#define ANDROID_HARDWARE_STREAM_HAL_HIDL_H
19
20#include <android/hardware/audio/2.0/IStream.h>
21#include <android/hardware/audio/2.0/IStreamIn.h>
22#include <android/hardware/audio/2.0/IStreamOut.h>
23#include <media/audiohal/StreamHalInterface.h>
24
25#include "ConversionHelperHidl.h"
26
27using ::android::hardware::audio::V2_0::IStream;
28using ::android::hardware::audio::V2_0::IStreamIn;
29using ::android::hardware::audio::V2_0::IStreamOut;
30using ::android::hardware::Return;
31
32namespace android {
33
34class DeviceHalHidl;
35
36class StreamHalHidl : public virtual StreamHalInterface, public ConversionHelperHidl
37{
38 public:
39 // Return the sampling rate in Hz - eg. 44100.
40 virtual status_t getSampleRate(uint32_t *rate);
41
42 // Return size of input/output buffer in bytes for this stream - eg. 4800.
43 virtual status_t getBufferSize(size_t *size);
44
45 // Return the channel mask.
46 virtual status_t getChannelMask(audio_channel_mask_t *mask);
47
48 // Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT.
49 virtual status_t getFormat(audio_format_t *format);
50
51 // Convenience method.
52 virtual status_t getAudioProperties(
53 uint32_t *sampleRate, audio_channel_mask_t *mask, audio_format_t *format);
54
55 // Set audio stream parameters.
56 virtual status_t setParameters(const String8& kvPairs);
57
58 // Get audio stream parameters.
59 virtual status_t getParameters(const String8& keys, String8 *values);
60
61 // Add or remove the effect on the stream.
62 virtual status_t addEffect(sp<EffectHalInterface> effect);
63 virtual status_t removeEffect(sp<EffectHalInterface> effect);
64
65 // Put the audio hardware input/output into standby mode.
66 virtual status_t standby();
67
68 virtual status_t dump(int fd);
69
70 protected:
71 // Subclasses can not be constructed directly by clients.
72 explicit StreamHalHidl(IStream *stream);
73
74 // The destructor automatically closes the stream.
75 virtual ~StreamHalHidl();
76
77 private:
78 IStream *mStream;
79};
80
81class StreamOutHalHidl : public StreamOutHalInterface, public StreamHalHidl {
82 public:
83 // Return the frame size (number of bytes per sample) of a stream.
84 virtual status_t getFrameSize(size_t *size);
85
86 // Return the audio hardware driver estimated latency in milliseconds.
87 virtual status_t getLatency(uint32_t *latency);
88
89 // Use this method in situations where audio mixing is done in the hardware.
90 virtual status_t setVolume(float left, float right);
91
92 // Write audio buffer to driver.
93 virtual status_t write(const void *buffer, size_t bytes, size_t *written);
94
95 // Return the number of audio frames written by the audio dsp to DAC since
96 // the output has exited standby.
97 virtual status_t getRenderPosition(uint32_t *dspFrames);
98
99 // Get the local time at which the next write to the audio driver will be presented.
100 virtual status_t getNextWriteTimestamp(int64_t *timestamp);
101
102 // Set the callback for notifying completion of non-blocking write and drain.
103 virtual status_t setCallback(wp<StreamOutHalInterfaceCallback> callback);
104
105 // Returns whether pause and resume operations are supported.
106 virtual status_t supportsPauseAndResume(bool *supportsPause, bool *supportsResume);
107
108 // Notifies to the audio driver to resume playback following a pause.
109 virtual status_t pause();
110
111 // Notifies to the audio driver to resume playback following a pause.
112 virtual status_t resume();
113
114 // Returns whether drain operation is supported.
115 virtual status_t supportsDrain(bool *supportsDrain);
116
117 // Requests notification when data buffered by the driver/hardware has been played.
118 virtual status_t drain(bool earlyNotify);
119
120 // Notifies to the audio driver to flush the queued data.
121 virtual status_t flush();
122
123 // Return a recent count of the number of audio frames presented to an external observer.
124 virtual status_t getPresentationPosition(uint64_t *frames, struct timespec *timestamp);
125
126 // Methods used by StreamOutCallback (HIDL).
127 void onWriteReady();
128 void onDrainReady();
129 void onError();
130
131 private:
132 friend class DeviceHalHidl;
133
134 wp<StreamOutHalInterfaceCallback> mCallback;
135 sp<IStreamOut> mStream;
136
137 // Can not be constructed directly by clients.
138 StreamOutHalHidl(const sp<IStreamOut>& stream);
139
140 virtual ~StreamOutHalHidl();
141};
142
143class StreamInHalHidl : public StreamInHalInterface, public StreamHalHidl {
144 public:
145 // Return the frame size (number of bytes per sample) of a stream.
146 virtual status_t getFrameSize(size_t *size);
147
148 // Set the input gain for the audio driver.
149 virtual status_t setGain(float gain);
150
151 // Read audio buffer in from driver.
152 virtual status_t read(void *buffer, size_t bytes, size_t *read);
153
154 // Return the amount of input frames lost in the audio driver.
155 virtual status_t getInputFramesLost(uint32_t *framesLost);
156
157 // Return a recent count of the number of audio frames received and
158 // the clock time associated with that frame count.
159 virtual status_t getCapturePosition(int64_t *frames, int64_t *time);
160
161 private:
162 friend class DeviceHalHidl;
163
164 sp<IStreamIn> mStream;
165
166 // Can not be constructed directly by clients.
167 StreamInHalHidl(const sp<IStreamIn>& stream);
168
169 virtual ~StreamInHalHidl();
170};
171
172} // namespace android
173
174#endif // ANDROID_HARDWARE_STREAM_HAL_HIDL_H