blob: 134819748a5074a7ddb2a45d67235aa9d3050929 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -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
25#include <hardware_legacy/AudioHardwareBase.h>
26
27
28namespace android {
29
30class A2dpAudioInterface : public AudioHardwareBase
31{
32 class A2dpAudioStreamOut;
33
34public:
35 A2dpAudioInterface();
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 // 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(
Dave Sparks65547732009-05-19 18:28:20 -070058 int inputSource,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059 int format,
60 int channelCount,
61 uint32_t sampleRate,
62 status_t *status,
63 AudioSystem::audio_in_acoustics acoustics);
64
Dave Sparks65547732009-05-19 18:28:20 -070065 // DEPRECATED - WILL BE REMOVED
66 virtual AudioStreamIn* openInputStream(
67 int format,
68 int channelCount,
69 uint32_t sampleRate,
70 status_t *status,
71 AudioSystem::audio_in_acoustics acoustics)
72 {
73 return openInputStream(-1, format, channelCount, sampleRate, status, acoustics);
74 }
75
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076protected:
77 virtual status_t doRouting();
78 virtual status_t dump(int fd, const Vector<String16>& args);
79
80private:
81 class A2dpAudioStreamOut : public AudioStreamOut {
82 public:
83 A2dpAudioStreamOut();
84 virtual ~A2dpAudioStreamOut();
85 status_t set(int format,
86 int channelCount,
87 uint32_t sampleRate);
88 virtual uint32_t sampleRate() const { return 44100; }
89 // SBC codec wants a multiple of 512
90 virtual size_t bufferSize() const { return 512 * 20; }
91 virtual int channelCount() const { return 2; }
92 virtual int format() const { return AudioSystem::PCM_16_BIT; }
93 virtual uint32_t latency() const { return ((1000*bufferSize())/frameSize())/sampleRate() + 200; }
94 virtual status_t setVolume(float volume) { return INVALID_OPERATION; }
95 virtual ssize_t write(const void* buffer, size_t bytes);
96 status_t standby();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097 virtual status_t dump(int fd, const Vector<String16>& args);
98
99 private:
100 friend class A2dpAudioInterface;
The Android Open Source Project22f8def2009-03-09 11:52:12 -0700101 status_t init();
102 status_t close();
Nick Pelly819aa232009-04-02 01:21:13 -0700103 status_t close_l();
104 status_t setAddress(const char* address);
105 status_t setBluetoothEnabled(bool enabled);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106
107 private:
108 int mFd;
109 bool mStandby;
110 int mStartCount;
111 int mRetryCount;
112 char mA2dpAddress[20];
113 void* mData;
The Android Open Source Project22f8def2009-03-09 11:52:12 -0700114 Mutex mLock;
Nick Pelly819aa232009-04-02 01:21:13 -0700115 bool mBluetoothEnabled;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800116 };
117
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118 A2dpAudioStreamOut* mOutput;
119};
120
121// ----------------------------------------------------------------------------
122
123}; // namespace android
124
125#endif // A2DP_AUDIO_HARDWARE_H