blob: 5bef5da1af484c5522d6976ef6243d20d68b9cfa [file] [log] [blame]
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -08001/*
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
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080025#include <hardware_legacy/AudioHardwareBase.h>
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080026
27
28namespace android {
29
30class A2dpAudioInterface : public AudioHardwareBase
31{
32 class A2dpAudioStreamOut;
33
34public:
35 A2dpAudioInterface();
36 virtual ~A2dpAudioInterface();
37 virtual status_t initCheck();
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080038
39 virtual status_t setVoiceVolume(float volume);
40 virtual status_t setMasterVolume(float volume);
41
42 // mic mute
43 virtual status_t setMicMute(bool state);
44 virtual status_t getMicMute(bool* state);
45
46 // Temporary interface, do not use
47 // TODO: Replace with a more generic key:value get/set mechanism
48 virtual status_t setParameter(const char *key, const char *value);
49
50 // create I/O streams
51 virtual AudioStreamOut* openOutputStream(
52 int format=0,
53 int channelCount=0,
54 uint32_t sampleRate=0,
55 status_t *status=0);
56
57 virtual AudioStreamIn* openInputStream(
58 int format,
59 int channelCount,
60 uint32_t sampleRate,
The Android Open Source Projectd2bd26d2009-02-19 10:57:31 -080061 status_t *status,
62 AudioSystem::audio_in_acoustics acoustics);
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080063
64protected:
65 virtual status_t doRouting();
66 virtual status_t dump(int fd, const Vector<String16>& args);
67
68private:
69 class A2dpAudioStreamOut : public AudioStreamOut {
70 public:
71 A2dpAudioStreamOut();
72 virtual ~A2dpAudioStreamOut();
73 status_t set(int format,
74 int channelCount,
75 uint32_t sampleRate);
76 virtual uint32_t sampleRate() const { return 44100; }
The Android Open Source Project27629322009-01-09 17:51:23 -080077 // SBC codec wants a multiple of 512
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080078 virtual size_t bufferSize() const { return 512 * 20; }
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080079 virtual int channelCount() const { return 2; }
80 virtual int format() const { return AudioSystem::PCM_16_BIT; }
The Android Open Source Projecta6938ba2009-02-10 15:44:00 -080081 virtual uint32_t latency() const { return ((1000*bufferSize())/frameSize())/sampleRate() + 200; }
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080082 virtual status_t setVolume(float volume) { return INVALID_OPERATION; }
83 virtual ssize_t write(const void* buffer, size_t bytes);
84 status_t standby();
The Android Open Source Projecta6938ba2009-02-10 15:44:00 -080085 status_t close();
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080086 virtual status_t dump(int fd, const Vector<String16>& args);
87
88 private:
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080089 friend class A2dpAudioInterface;
90 status_t setAddress(const char* address);
91
92 private:
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080093 int mFd;
The Android Open Source Project27629322009-01-09 17:51:23 -080094 bool mStandby;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080095 int mStartCount;
96 int mRetryCount;
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080097 char mA2dpAddress[20];
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080098 void* mData;
The Android Open Source Project43aa2b12009-03-03 14:04:24 -080099 bool mInitialized;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800100 };
101
102 Mutex mLock;
103 A2dpAudioStreamOut* mOutput;
104};
105
106// ----------------------------------------------------------------------------
107
108}; // namespace android
109
110#endif // A2DP_AUDIO_HARDWARE_H