blob: 9fcbea5b345a8524e2212a0c9736f1e96f888bb2 [file] [log] [blame]
The Android Open Source Project2729ea92008-10-21 07:00:00 -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 ANDROID_AUDIOSYSTEM_H_
18#define ANDROID_AUDIOSYSTEM_H_
19
20#include <utils/RefBase.h>
21#include <utils/threads.h>
22#include <media/IAudioFlinger.h>
23
24namespace android {
25
26typedef void (*audio_error_callback)(status_t err);
27
28class AudioSystem
29{
30public:
31
32 enum audio_format {
33 DEFAULT = 0,
34 PCM_16_BIT,
35 PCM_8_BIT,
36 INVALID_FORMAT
37 };
38
39 enum audio_mode {
40 MODE_INVALID = -2,
41 MODE_CURRENT = -1,
42 MODE_NORMAL = 0,
43 MODE_RINGTONE,
44 MODE_IN_CALL,
45 NUM_MODES // not a valid entry, denotes end-of-list
46 };
47
48 enum audio_routes {
49 ROUTE_EARPIECE = (1 << 0),
50 ROUTE_SPEAKER = (1 << 1),
51 ROUTE_BLUETOOTH = (1 << 2),
52 ROUTE_HEADSET = (1 << 3),
53 ROUTE_ALL = (ROUTE_EARPIECE | ROUTE_SPEAKER | ROUTE_BLUETOOTH | ROUTE_HEADSET)
54 };
55
56 /* These are static methods to control the system-wide AudioFlinger
57 * only privileged processes can have access to them
58 */
59
60 // routing helper functions
61 static status_t speakerphone(bool state);
62 static status_t isSpeakerphoneOn(bool* state);
63 static status_t bluetoothSco(bool state);
64 static status_t isBluetoothScoOn(bool* state);
65 static status_t muteMicrophone(bool state);
66 static status_t isMicrophoneMuted(bool *state);
67
68 static status_t setMasterVolume(float value);
69 static status_t setMasterMute(bool mute);
70 static status_t getMasterVolume(float* volume);
71 static status_t getMasterMute(bool* mute);
72
73 static status_t setStreamVolume(int stream, float value);
74 static status_t setStreamMute(int stream, bool mute);
75 static status_t getStreamVolume(int stream, float* volume);
76 static status_t getStreamMute(int stream, bool* mute);
77
78 static status_t setMode(int mode);
79 static status_t getMode(int* mode);
80
81 static status_t setRouting(int mode, uint32_t routes, uint32_t mask);
82 static status_t getRouting(int mode, uint32_t* routes);
83
84 static status_t isMusicActive(bool *state);
85
86 // Temporary interface, do not use
87 // TODO: Replace with a more generic key:value get/set mechanism
88 static status_t setParameter(const char* key, const char* value);
89
90 static void setErrorCallback(audio_error_callback cb);
91
92 // helper function to obtain AudioFlinger service handle
93 static const sp<IAudioFlinger>& get_audio_flinger();
94
95 static float linearToLog(int volume);
96 static int logToLinear(float volume);
97
98 // ----------------------------------------------------------------------------
99
100private:
101
102 class DeathNotifier: public IBinder::DeathRecipient
103 {
104 public:
105 DeathNotifier() {
106 }
107
108 virtual void binderDied(const wp<IBinder>& who);
109 };
110
111 static sp<DeathNotifier> gDeathNotifier;
112
113 friend class DeathNotifier;
114
115 static Mutex gLock;
116 static sp<IAudioFlinger> gAudioFlinger;
117 static audio_error_callback gAudioErrorCallback;
118};
119
120}; // namespace android
121
122#endif /*ANDROID_AUDIOSYSTEM_H_*/