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