Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 20 | #include <media/audiohal/StreamHalInterface.h> |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | class DeviceHalLocal; |
| 25 | |
| 26 | class 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 | |
Eric Laurent | af35aad | 2016-12-15 14:25:36 -0800 | [diff] [blame] | 60 | // Start a stream operating in mmap mode. |
| 61 | virtual status_t start() = 0; |
| 62 | |
| 63 | // Stop a stream operating in mmap mode. |
| 64 | virtual status_t stop() = 0; |
| 65 | |
| 66 | // Retrieve information on the data buffer in mmap mode. |
| 67 | virtual status_t createMmapBuffer(int32_t minSizeFrames, |
| 68 | struct audio_mmap_buffer_info *info) = 0; |
| 69 | |
| 70 | // Get current read/write position in the mmap buffer |
| 71 | virtual status_t getMmapPosition(struct audio_mmap_position *position) = 0; |
| 72 | |
Mikhail Naganov | e1c4b5d | 2016-12-22 09:22:45 -0800 | [diff] [blame^] | 73 | // Set the priority of the thread that interacts with the HAL |
| 74 | // (must match the priority of the audioflinger's thread that calls 'read' / 'write') |
| 75 | virtual status_t setHalThreadPriority(int priority); |
| 76 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 77 | protected: |
| 78 | // Subclasses can not be constructed directly by clients. |
| 79 | StreamHalLocal(audio_stream_t *stream, sp<DeviceHalLocal> device); |
| 80 | |
| 81 | // The destructor automatically closes the stream. |
| 82 | virtual ~StreamHalLocal(); |
| 83 | |
| 84 | sp<DeviceHalLocal> mDevice; |
| 85 | |
| 86 | private: |
| 87 | audio_stream_t *mStream; |
| 88 | }; |
| 89 | |
| 90 | class StreamOutHalLocal : public StreamOutHalInterface, public StreamHalLocal { |
| 91 | public: |
| 92 | // Return the frame size (number of bytes per sample) of a stream. |
| 93 | virtual status_t getFrameSize(size_t *size); |
| 94 | |
| 95 | // Return the audio hardware driver estimated latency in milliseconds. |
| 96 | virtual status_t getLatency(uint32_t *latency); |
| 97 | |
| 98 | // Use this method in situations where audio mixing is done in the hardware. |
| 99 | virtual status_t setVolume(float left, float right); |
| 100 | |
| 101 | // Write audio buffer to driver. |
| 102 | virtual status_t write(const void *buffer, size_t bytes, size_t *written); |
| 103 | |
| 104 | // Return the number of audio frames written by the audio dsp to DAC since |
| 105 | // the output has exited standby. |
| 106 | virtual status_t getRenderPosition(uint32_t *dspFrames); |
| 107 | |
| 108 | // Get the local time at which the next write to the audio driver will be presented. |
| 109 | virtual status_t getNextWriteTimestamp(int64_t *timestamp); |
| 110 | |
| 111 | // Set the callback for notifying completion of non-blocking write and drain. |
Mikhail Naganov | 15897e4 | 2016-09-30 16:16:41 -0700 | [diff] [blame] | 112 | virtual status_t setCallback(wp<StreamOutHalInterfaceCallback> callback); |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 113 | |
| 114 | // Returns whether pause and resume operations are supported. |
| 115 | virtual status_t supportsPauseAndResume(bool *supportsPause, bool *supportsResume); |
| 116 | |
| 117 | // Notifies to the audio driver to resume playback following a pause. |
| 118 | virtual status_t pause(); |
| 119 | |
| 120 | // Notifies to the audio driver to resume playback following a pause. |
| 121 | virtual status_t resume(); |
| 122 | |
| 123 | // Returns whether drain operation is supported. |
| 124 | virtual status_t supportsDrain(bool *supportsDrain); |
| 125 | |
| 126 | // Requests notification when data buffered by the driver/hardware has been played. |
Mikhail Naganov | cbc8f61 | 2016-10-11 18:05:13 -0700 | [diff] [blame] | 127 | virtual status_t drain(bool earlyNotify); |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 128 | |
| 129 | // Notifies to the audio driver to flush the queued data. |
| 130 | virtual status_t flush(); |
| 131 | |
| 132 | // Return a recent count of the number of audio frames presented to an external observer. |
| 133 | virtual status_t getPresentationPosition(uint64_t *frames, struct timespec *timestamp); |
| 134 | |
Eric Laurent | af35aad | 2016-12-15 14:25:36 -0800 | [diff] [blame] | 135 | // Start a stream operating in mmap mode. |
| 136 | virtual status_t start(); |
| 137 | |
| 138 | // Stop a stream operating in mmap mode. |
| 139 | virtual status_t stop(); |
| 140 | |
| 141 | // Retrieve information on the data buffer in mmap mode. |
| 142 | virtual status_t createMmapBuffer(int32_t minSizeFrames, |
| 143 | struct audio_mmap_buffer_info *info); |
| 144 | |
| 145 | // Get current read/write position in the mmap buffer |
| 146 | virtual status_t getMmapPosition(struct audio_mmap_position *position); |
| 147 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 148 | private: |
| 149 | audio_stream_out_t *mStream; |
| 150 | wp<StreamOutHalInterfaceCallback> mCallback; |
| 151 | |
| 152 | friend class DeviceHalLocal; |
| 153 | |
| 154 | // Can not be constructed directly by clients. |
| 155 | StreamOutHalLocal(audio_stream_out_t *stream, sp<DeviceHalLocal> device); |
| 156 | |
| 157 | virtual ~StreamOutHalLocal(); |
| 158 | |
| 159 | static int asyncCallback(stream_callback_event_t event, void *param, void *cookie); |
| 160 | }; |
| 161 | |
| 162 | class StreamInHalLocal : public StreamInHalInterface, public StreamHalLocal { |
| 163 | public: |
| 164 | // Return the frame size (number of bytes per sample) of a stream. |
| 165 | virtual status_t getFrameSize(size_t *size); |
| 166 | |
| 167 | // Set the input gain for the audio driver. |
| 168 | virtual status_t setGain(float gain); |
| 169 | |
| 170 | // Read audio buffer in from driver. |
| 171 | virtual status_t read(void *buffer, size_t bytes, size_t *read); |
| 172 | |
| 173 | // Return the amount of input frames lost in the audio driver. |
| 174 | virtual status_t getInputFramesLost(uint32_t *framesLost); |
| 175 | |
| 176 | // Return a recent count of the number of audio frames received and |
| 177 | // the clock time associated with that frame count. |
| 178 | virtual status_t getCapturePosition(int64_t *frames, int64_t *time); |
| 179 | |
Eric Laurent | af35aad | 2016-12-15 14:25:36 -0800 | [diff] [blame] | 180 | // Start a stream operating in mmap mode. |
| 181 | virtual status_t start(); |
| 182 | |
| 183 | // Stop a stream operating in mmap mode. |
| 184 | virtual status_t stop(); |
| 185 | |
| 186 | // Retrieve information on the data buffer in mmap mode. |
| 187 | virtual status_t createMmapBuffer(int32_t minSizeFrames, |
| 188 | struct audio_mmap_buffer_info *info); |
| 189 | |
| 190 | // Get current read/write position in the mmap buffer |
| 191 | virtual status_t getMmapPosition(struct audio_mmap_position *position); |
| 192 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 193 | private: |
| 194 | audio_stream_in_t *mStream; |
| 195 | |
| 196 | friend class DeviceHalLocal; |
| 197 | |
| 198 | // Can not be constructed directly by clients. |
| 199 | StreamInHalLocal(audio_stream_in_t *stream, sp<DeviceHalLocal> device); |
| 200 | |
| 201 | virtual ~StreamInHalLocal(); |
| 202 | }; |
| 203 | |
| 204 | } // namespace android |
| 205 | |
| 206 | #endif // ANDROID_HARDWARE_STREAM_HAL_LOCAL_H |