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_INTERFACE_H |
| 18 | #define ANDROID_HARDWARE_STREAM_HAL_INTERFACE_H |
| 19 | |
Mikhail Naganov | a0c9133 | 2016-09-19 10:01:12 -0700 | [diff] [blame] | 20 | #include <hardware/audio.h> |
| 21 | #include <media/audiohal/EffectHalInterface.h> |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 22 | #include <utils/Errors.h> |
| 23 | #include <utils/RefBase.h> |
| 24 | #include <utils/String8.h> |
| 25 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 26 | namespace android { |
| 27 | |
| 28 | class StreamHalInterface : public virtual RefBase |
| 29 | { |
| 30 | public: |
| 31 | // Return the sampling rate in Hz - eg. 44100. |
| 32 | virtual status_t getSampleRate(uint32_t *rate) = 0; |
| 33 | |
| 34 | // Return size of input/output buffer in bytes for this stream - eg. 4800. |
| 35 | virtual status_t getBufferSize(size_t *size) = 0; |
| 36 | |
| 37 | // Return the channel mask. |
| 38 | virtual status_t getChannelMask(audio_channel_mask_t *mask) = 0; |
| 39 | |
| 40 | // Return the audio format - e.g. AUDIO_FORMAT_PCM_16_BIT. |
| 41 | virtual status_t getFormat(audio_format_t *format) = 0; |
| 42 | |
| 43 | // Convenience method. |
| 44 | virtual status_t getAudioProperties( |
| 45 | uint32_t *sampleRate, audio_channel_mask_t *mask, audio_format_t *format) = 0; |
| 46 | |
| 47 | // Set audio stream parameters. |
| 48 | virtual status_t setParameters(const String8& kvPairs) = 0; |
| 49 | |
| 50 | // Get audio stream parameters. |
| 51 | virtual status_t getParameters(const String8& keys, String8 *values) = 0; |
| 52 | |
| 53 | // Return the frame size (number of bytes per sample) of a stream. |
| 54 | virtual status_t getFrameSize(size_t *size) = 0; |
| 55 | |
| 56 | // Add or remove the effect on the stream. |
| 57 | virtual status_t addEffect(sp<EffectHalInterface> effect) = 0; |
| 58 | virtual status_t removeEffect(sp<EffectHalInterface> effect) = 0; |
| 59 | |
| 60 | // Put the audio hardware input/output into standby mode. |
| 61 | virtual status_t standby() = 0; |
| 62 | |
| 63 | virtual status_t dump(int fd) = 0; |
| 64 | |
| 65 | protected: |
| 66 | // Subclasses can not be constructed directly by clients. |
| 67 | StreamHalInterface() {} |
| 68 | |
| 69 | // The destructor automatically closes the stream. |
| 70 | virtual ~StreamHalInterface() {} |
| 71 | }; |
| 72 | |
| 73 | class StreamOutHalInterfaceCallback : public virtual RefBase { |
| 74 | public: |
| 75 | virtual void onWriteReady() {} |
| 76 | virtual void onDrainReady() {} |
| 77 | virtual void onError() {} |
| 78 | |
| 79 | protected: |
| 80 | StreamOutHalInterfaceCallback() {} |
| 81 | virtual ~StreamOutHalInterfaceCallback() {} |
| 82 | }; |
| 83 | |
| 84 | class StreamOutHalInterface : public virtual StreamHalInterface { |
| 85 | public: |
| 86 | // Return the audio hardware driver estimated latency in milliseconds. |
| 87 | virtual status_t getLatency(uint32_t *latency) = 0; |
| 88 | |
| 89 | // Use this method in situations where audio mixing is done in the hardware. |
| 90 | virtual status_t setVolume(float left, float right) = 0; |
| 91 | |
| 92 | // Write audio buffer to driver. |
| 93 | virtual status_t write(const void *buffer, size_t bytes, size_t *written) = 0; |
| 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) = 0; |
| 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) = 0; |
| 101 | |
| 102 | // Set the callback for notifying completion of non-blocking write and drain. |
| 103 | // The callback must be owned by someone else. The output stream does not own it |
| 104 | // to avoid strong pointer loops. |
Mikhail Naganov | 15897e4 | 2016-09-30 16:16:41 -0700 | [diff] [blame] | 105 | virtual status_t setCallback(wp<StreamOutHalInterfaceCallback> callback) = 0; |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 106 | |
| 107 | // Returns whether pause and resume operations are supported. |
| 108 | virtual status_t supportsPauseAndResume(bool *supportsPause, bool *supportsResume) = 0; |
| 109 | |
| 110 | // Notifies to the audio driver to resume playback following a pause. |
| 111 | virtual status_t pause() = 0; |
| 112 | |
| 113 | // Notifies to the audio driver to resume playback following a pause. |
| 114 | virtual status_t resume() = 0; |
| 115 | |
| 116 | // Returns whether drain operation is supported. |
| 117 | virtual status_t supportsDrain(bool *supportsDrain) = 0; |
| 118 | |
| 119 | // Requests notification when data buffered by the driver/hardware has been played. |
| 120 | virtual status_t drain(audio_drain_type_t type) = 0; |
| 121 | |
| 122 | // Notifies to the audio driver to flush the queued data. |
| 123 | virtual status_t flush() = 0; |
| 124 | |
| 125 | // Return a recent count of the number of audio frames presented to an external observer. |
| 126 | virtual status_t getPresentationPosition(uint64_t *frames, struct timespec *timestamp) = 0; |
| 127 | |
| 128 | protected: |
| 129 | virtual ~StreamOutHalInterface() {} |
| 130 | }; |
| 131 | |
| 132 | class StreamInHalInterface : public virtual StreamHalInterface { |
| 133 | public: |
| 134 | // Set the input gain for the audio driver. |
| 135 | virtual status_t setGain(float gain) = 0; |
| 136 | |
| 137 | // Read audio buffer in from driver. |
| 138 | virtual status_t read(void *buffer, size_t bytes, size_t *read) = 0; |
| 139 | |
| 140 | // Return the amount of input frames lost in the audio driver. |
| 141 | virtual status_t getInputFramesLost(uint32_t *framesLost) = 0; |
| 142 | |
| 143 | // Return a recent count of the number of audio frames received and |
| 144 | // the clock time associated with that frame count. |
| 145 | virtual status_t getCapturePosition(int64_t *frames, int64_t *time) = 0; |
| 146 | |
| 147 | protected: |
| 148 | virtual ~StreamInHalInterface() {} |
| 149 | }; |
| 150 | |
| 151 | } // namespace android |
| 152 | |
| 153 | #endif // ANDROID_HARDWARE_STREAM_HAL_INTERFACE_H |