blob: 48154f9428787e871353b24e1df214d873d1731b [file] [log] [blame]
Mathias Agopian65ab4712010-07-14 17:59:35 -07001/*
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
28namespace android {
29
30class A2dpAudioInterface : public AudioHardwareBase
31{
32 class A2dpAudioStreamOut;
33
34public:
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
72protected:
73 virtual status_t dump(int fd, const Vector<String16>& args);
74
75private:
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);
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; }
87 virtual uint32_t channels() const { return AudioSystem::CHANNEL_OUT_STEREO; }
88 virtual int format() const { return AudioSystem::PCM_16_BIT; }
89 virtual uint32_t latency() const { return ((1000*bufferSize())/frameSize())/sampleRate() + 200; }
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 virtual status_t getRenderPosition(uint32_t *dspFrames);
97
98 private:
99 friend class A2dpAudioInterface;
100 status_t init();
101 status_t close();
102 status_t close_l();
103 status_t setAddress(const char* address);
104 status_t setBluetoothEnabled(bool enabled);
105 status_t setSuspended(bool onOff);
106
107 private:
108 int mFd;
109 bool mStandby;
110 int mStartCount;
111 int mRetryCount;
112 char mA2dpAddress[20];
113 void* mData;
114 Mutex mLock;
115 bool mBluetoothEnabled;
116 uint32_t mDevice;
117 bool mClosing;
118 bool mSuspended;
119 };
120
121 friend class A2dpAudioStreamOut;
122
123 A2dpAudioStreamOut* mOutput;
124 AudioHardwareInterface *mHardwareInterface;
125 char mA2dpAddress[20];
126 bool mBluetoothEnabled;
127 bool mSuspended;
128};
129
130
131// ----------------------------------------------------------------------------
132
133}; // namespace android
134
135#endif // A2DP_AUDIO_HARDWARE_H