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