• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
35                         A2dpAudioInterface(AudioHardwareInterface* hw);
36     virtual             ~A2dpAudioInterface();
37     virtual status_t    initCheck();
38 
39     virtual status_t    setVoiceVolume(float volume);
40     virtual status_t    setMasterVolume(float volume);
41 
42     virtual status_t    setMode(int mode);
43 
44     // mic mute
45     virtual status_t    setMicMute(bool state);
46     virtual status_t    getMicMute(bool* state);
47 
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);
52 
53     // create I/O streams
54     virtual AudioStreamOut* openOutputStream(
55                                 uint32_t devices,
56                                 int *format=0,
57                                 uint32_t *channels=0,
58                                 uint32_t *sampleRate=0,
59                                 status_t *status=0);
60     virtual    void        closeOutputStream(AudioStreamOut* out);
61 
62     virtual AudioStreamIn* openInputStream(
63                                 uint32_t devices,
64                                 int *format,
65                                 uint32_t *channels,
66                                 uint32_t *sampleRate,
67                                 status_t *status,
68                                 AudioSystem::audio_in_acoustics acoustics);
69     virtual    void        closeInputStream(AudioStreamIn* in);
70 //    static AudioHardwareInterface* createA2dpInterface();
71 
72 protected:
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();
80                 status_t    set(uint32_t device,
81                                 int *pFormat,
82                                 uint32_t *pChannels,
83                                 uint32_t *pRate);
sampleRate()84         virtual uint32_t    sampleRate() const { return 44100; }
85         // SBC codec wants a multiple of 512
bufferSize()86         virtual size_t      bufferSize() const { return 512 * 20; }
channels()87         virtual uint32_t    channels() const { return AudioSystem::CHANNEL_OUT_STEREO; }
format()88         virtual int         format() const { return AudioSystem::PCM_16_BIT; }
latency()89         virtual uint32_t    latency() const { return ((1000*bufferSize())/frameSize())/sampleRate() + 200; }
setVolume(float left,float right)90         virtual status_t    setVolume(float left, float right) { return INVALID_OPERATION; }
91         virtual ssize_t     write(const void* buffer, size_t bytes);
92                 status_t    standby();
93         virtual status_t    dump(int fd, const Vector<String16>& args);
94         virtual status_t    setParameters(const String8& keyValuePairs);
95         virtual String8     getParameters(const String8& keys);
96 
97     private:
98         friend class A2dpAudioInterface;
99                 status_t    init();
100                 status_t    close();
101                 status_t    close_l();
102                 status_t    setAddress(const char* address);
103                 status_t    setBluetoothEnabled(bool enabled);
104                 status_t    setSuspended(bool onOff);
105 
106     private:
107                 int         mFd;
108                 bool        mStandby;
109                 int         mStartCount;
110                 int         mRetryCount;
111                 char        mA2dpAddress[20];
112                 void*       mData;
113                 Mutex       mLock;
114                 bool        mBluetoothEnabled;
115                 uint32_t    mDevice;
116                 bool        mClosing;
117                 bool        mSuspended;
118     };
119 
120     friend class A2dpAudioStreamOut;
121 
122     A2dpAudioStreamOut*     mOutput;
123     AudioHardwareInterface  *mHardwareInterface;
124     char        mA2dpAddress[20];
125     bool        mBluetoothEnabled;
126     bool        mSuspended;
127 };
128 
129 
130 // ----------------------------------------------------------------------------
131 
132 }; // namespace android
133 
134 #endif // A2DP_AUDIO_HARDWARE_H
135