blob: 03bf933371d11cdaac07166619876d4f9c72a826 [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
25#include <hardware/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 virtual status_t standby();
39
40 virtual status_t setVoiceVolume(float volume);
41 virtual status_t setMasterVolume(float volume);
42
43 // mic mute
44 virtual status_t setMicMute(bool state);
45 virtual status_t getMicMute(bool* state);
46
47 // Temporary interface, do not use
48 // TODO: Replace with a more generic key:value get/set mechanism
49 virtual status_t setParameter(const char *key, const char *value);
50
51 // create I/O streams
52 virtual AudioStreamOut* openOutputStream(
53 int format=0,
54 int channelCount=0,
55 uint32_t sampleRate=0,
56 status_t *status=0);
57
58 virtual AudioStreamIn* openInputStream(
59 int format,
60 int channelCount,
61 uint32_t sampleRate,
62 status_t *status);
63
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; }
77 // must be 32-bit aligned - driver only seems to like 4800
78 virtual size_t bufferSize() const { return 5120; }
79 virtual int channelCount() const { return 2; }
80 virtual int format() const { return AudioSystem::PCM_16_BIT; }
81 virtual uint32_t latency() const { return 0; }
82 virtual status_t setVolume(float volume) { return INVALID_OPERATION; }
83 virtual ssize_t write(const void* buffer, size_t bytes);
84 status_t standby();
85 virtual status_t dump(int fd, const Vector<String16>& args);
86
87 private:
88 int mFd;
89 int mStartCount;
90 int mRetryCount;
91 void* mData;
92 bool mInitialized;
93
94#define kBufferSize 50000
95 char mBuffer[kBufferSize];
96 int mBufferRemaining;
97 };
98
99 Mutex mLock;
100 A2dpAudioStreamOut* mOutput;
101};
102
103// ----------------------------------------------------------------------------
104
105}; // namespace android
106
107#endif // A2DP_AUDIO_HARDWARE_H