• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 **
3 ** Copyright 2007, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 #ifndef ANDROID_AUDIO_HARDWARE_GENERIC_H
19 #define ANDROID_AUDIO_HARDWARE_GENERIC_H
20 
21 #include <stdint.h>
22 #include <sys/types.h>
23 
24 #include <utils/threads.h>
25 
26 #include <hardware_legacy/AudioSystemLegacy.h>
27 #include <hardware_legacy/AudioHardwareBase.h>
28 
29 namespace android_audio_legacy {
30     using android::Mutex;
31     using android::AutoMutex;
32 
33 // ----------------------------------------------------------------------------
34 
35 class AudioHardwareGeneric;
36 
37 class AudioStreamOutGeneric : public AudioStreamOut {
38 public:
AudioStreamOutGeneric()39                         AudioStreamOutGeneric() : mAudioHardware(0), mFd(-1) {}
40     virtual             ~AudioStreamOutGeneric();
41 
42     virtual status_t    set(
43             AudioHardwareGeneric *hw,
44             int mFd,
45             uint32_t devices,
46             int *pFormat,
47             uint32_t *pChannels,
48             uint32_t *pRate);
49 
sampleRate()50     virtual uint32_t    sampleRate() const { return 44100; }
bufferSize()51     virtual size_t      bufferSize() const { return 4096; }
channels()52     virtual uint32_t    channels() const { return AudioSystem::CHANNEL_OUT_STEREO; }
format()53     virtual int         format() const { return AudioSystem::PCM_16_BIT; }
latency()54     virtual uint32_t    latency() const { return 20; }
setVolume(float left,float right)55     virtual status_t    setVolume(float left, float right) { return INVALID_OPERATION; }
56     virtual ssize_t     write(const void* buffer, size_t bytes);
57     virtual status_t    standby();
58     virtual status_t    dump(int fd, const Vector<String16>& args);
59     virtual status_t    setParameters(const String8& keyValuePairs);
60     virtual String8     getParameters(const String8& keys);
61     virtual status_t    getRenderPosition(uint32_t *dspFrames);
62 
63 private:
64     AudioHardwareGeneric *mAudioHardware;
65     Mutex   mLock;
66     int     mFd;
67     uint32_t mDevice;
68 };
69 
70 class AudioStreamInGeneric : public AudioStreamIn {
71 public:
AudioStreamInGeneric()72                         AudioStreamInGeneric() : mAudioHardware(0), mFd(-1) {}
73     virtual             ~AudioStreamInGeneric();
74 
75     virtual status_t    set(
76             AudioHardwareGeneric *hw,
77             int mFd,
78             uint32_t devices,
79             int *pFormat,
80             uint32_t *pChannels,
81             uint32_t *pRate,
82             AudioSystem::audio_in_acoustics acoustics);
83 
sampleRate()84     virtual uint32_t    sampleRate() const { return 8000; }
bufferSize()85     virtual size_t      bufferSize() const { return 320; }
channels()86     virtual uint32_t    channels() const { return AudioSystem::CHANNEL_IN_MONO; }
format()87     virtual int         format() const { return AudioSystem::PCM_16_BIT; }
setGain(float gain)88     virtual status_t    setGain(float gain) { return INVALID_OPERATION; }
89     virtual ssize_t     read(void* buffer, ssize_t bytes);
90     virtual status_t    dump(int fd, const Vector<String16>& args);
standby()91     virtual status_t    standby() { return NO_ERROR; }
92     virtual status_t    setParameters(const String8& keyValuePairs);
93     virtual String8     getParameters(const String8& keys);
getInputFramesLost()94     virtual unsigned int  getInputFramesLost() const { return 0; }
addAudioEffect(effect_handle_t effect)95     virtual status_t addAudioEffect(effect_handle_t effect) { return NO_ERROR; }
removeAudioEffect(effect_handle_t effect)96     virtual status_t removeAudioEffect(effect_handle_t effect) { return NO_ERROR; }
97 
98 private:
99     AudioHardwareGeneric *mAudioHardware;
100     Mutex   mLock;
101     int     mFd;
102     uint32_t mDevice;
103 };
104 
105 
106 class AudioHardwareGeneric : public AudioHardwareBase
107 {
108 public:
109                         AudioHardwareGeneric();
110     virtual             ~AudioHardwareGeneric();
111     virtual status_t    initCheck();
112     virtual status_t    setVoiceVolume(float volume);
113     virtual status_t    setMasterVolume(float volume);
114 
115     // mic mute
116     virtual status_t    setMicMute(bool state);
117     virtual status_t    getMicMute(bool* state);
118 
119     // create I/O streams
120     virtual AudioStreamOut* openOutputStream(
121             uint32_t devices,
122             int *format=0,
123             uint32_t *channels=0,
124             uint32_t *sampleRate=0,
125             status_t *status=0);
126     virtual    void        closeOutputStream(AudioStreamOut* out);
127 
128     virtual AudioStreamIn* openInputStream(
129             uint32_t devices,
130             int *format,
131             uint32_t *channels,
132             uint32_t *sampleRate,
133             status_t *status,
134             AudioSystem::audio_in_acoustics acoustics);
135     virtual    void        closeInputStream(AudioStreamIn* in);
136 
137             void            closeOutputStream(AudioStreamOutGeneric* out);
138             void            closeInputStream(AudioStreamInGeneric* in);
139 protected:
140     virtual status_t        dump(int fd, const Vector<String16>& args);
141 
142 private:
143     status_t                dumpInternals(int fd, const Vector<String16>& args);
144 
145     Mutex                   mLock;
146     AudioStreamOutGeneric   *mOutput;
147     AudioStreamInGeneric    *mInput;
148     int                     mFd;
149     bool                    mMicMute;
150 };
151 
152 // ----------------------------------------------------------------------------
153 
154 }; // namespace android
155 
156 #endif // ANDROID_AUDIO_HARDWARE_GENERIC_H
157