The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 A2DP_AUDIO_HARDWARE_H |
| 18 | #define A2DP_AUDIO_HARDWARE_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/threads.h> |
| 24 | |
| 25 | #include <hardware_legacy/AudioHardwareBase.h> |
| 26 | |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | class A2dpAudioInterface : public AudioHardwareBase |
| 31 | { |
| 32 | class A2dpAudioStreamOut; |
| 33 | |
| 34 | public: |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 35 | A2dpAudioInterface(AudioHardwareInterface* hw); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | virtual ~A2dpAudioInterface(); |
| 37 | virtual status_t initCheck(); |
| 38 | |
| 39 | virtual status_t setVoiceVolume(float volume); |
| 40 | virtual status_t setMasterVolume(float volume); |
| 41 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 42 | virtual status_t setMode(int mode); |
| 43 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | // mic mute |
| 45 | virtual status_t setMicMute(bool state); |
| 46 | virtual status_t getMicMute(bool* state); |
| 47 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 48 | virtual status_t setParameters(const String8& keyValuePairs); |
| 49 | virtual String8 getParameters(const String8& keys); |
| 50 | |
| 51 | virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | |
| 53 | // create I/O streams |
| 54 | virtual AudioStreamOut* openOutputStream( |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 55 | uint32_t devices, |
| 56 | int *format=0, |
| 57 | uint32_t *channels=0, |
| 58 | uint32_t *sampleRate=0, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | status_t *status=0); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 60 | virtual void closeOutputStream(AudioStreamOut* out); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
| 62 | virtual AudioStreamIn* openInputStream( |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 63 | uint32_t devices, |
| 64 | int *format, |
| 65 | uint32_t *channels, |
| 66 | uint32_t *sampleRate, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | status_t *status, |
| 68 | AudioSystem::audio_in_acoustics acoustics); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 69 | virtual void closeInputStream(AudioStreamIn* in); |
| 70 | // static AudioHardwareInterface* createA2dpInterface(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | |
| 72 | protected: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 74 | |
| 75 | private: |
| 76 | class A2dpAudioStreamOut : public AudioStreamOut { |
| 77 | public: |
| 78 | A2dpAudioStreamOut(); |
| 79 | virtual ~A2dpAudioStreamOut(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 80 | status_t set(uint32_t device, |
| 81 | int *pFormat, |
| 82 | uint32_t *pChannels, |
| 83 | uint32_t *pRate); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | virtual uint32_t sampleRate() const { return 44100; } |
| 85 | // SBC codec wants a multiple of 512 |
| 86 | virtual size_t bufferSize() const { return 512 * 20; } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 87 | virtual uint32_t channels() const { return AudioSystem::CHANNEL_OUT_STEREO; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 88 | virtual int format() const { return AudioSystem::PCM_16_BIT; } |
| 89 | virtual uint32_t latency() const { return ((1000*bufferSize())/frameSize())/sampleRate() + 200; } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 90 | virtual status_t setVolume(float left, float right) { return INVALID_OPERATION; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | virtual ssize_t write(const void* buffer, size_t bytes); |
| 92 | status_t standby(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 93 | virtual status_t dump(int fd, const Vector<String16>& args); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 94 | virtual status_t setParameters(const String8& keyValuePairs); |
| 95 | virtual String8 getParameters(const String8& keys); |
Eric Laurent | 0986e79 | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 96 | virtual status_t getRenderPosition(uint32_t *dspFrames); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | |
| 98 | private: |
| 99 | friend class A2dpAudioInterface; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 100 | status_t init(); |
| 101 | status_t close(); |
Nick Pelly | 0827c81 | 2009-04-02 01:21:13 -0700 | [diff] [blame] | 102 | status_t close_l(); |
| 103 | status_t setAddress(const char* address); |
| 104 | status_t setBluetoothEnabled(bool enabled); |
Eric Laurent | 80a6a22 | 2009-10-08 10:58:19 -0700 | [diff] [blame] | 105 | status_t setSuspended(bool onOff); |
Eric Laurent | 6dc08b3 | 2010-11-23 17:59:39 -0800 | [diff] [blame] | 106 | status_t standby_l(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | |
| 108 | private: |
| 109 | int mFd; |
| 110 | bool mStandby; |
| 111 | int mStartCount; |
| 112 | int mRetryCount; |
| 113 | char mA2dpAddress[20]; |
| 114 | void* mData; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 115 | Mutex mLock; |
Nick Pelly | 0827c81 | 2009-04-02 01:21:13 -0700 | [diff] [blame] | 116 | bool mBluetoothEnabled; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 117 | uint32_t mDevice; |
Eric Laurent | fe4fc91 | 2009-08-12 05:49:58 -0700 | [diff] [blame] | 118 | bool mClosing; |
Eric Laurent | 80a6a22 | 2009-10-08 10:58:19 -0700 | [diff] [blame] | 119 | bool mSuspended; |
Eric Laurent | e7155e6 | 2010-12-17 10:27:02 -0800 | [diff] [blame] | 120 | nsecs_t mLastWriteTime; |
| 121 | uint32_t mBufferDurationUs; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 124 | friend class A2dpAudioStreamOut; |
| 125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | A2dpAudioStreamOut* mOutput; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 127 | AudioHardwareInterface *mHardwareInterface; |
| 128 | char mA2dpAddress[20]; |
| 129 | bool mBluetoothEnabled; |
Eric Laurent | 80a6a22 | 2009-10-08 10:58:19 -0700 | [diff] [blame] | 130 | bool mSuspended; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | }; |
| 132 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 133 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | // ---------------------------------------------------------------------------- |
| 135 | |
| 136 | }; // namespace android |
| 137 | |
| 138 | #endif // A2DP_AUDIO_HARDWARE_H |