AudioSystem.h revision 7b5eb023f8d87cca6d830ae6c11c6aadbe02aca8
1/*
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_SCO  = (1 << 2),
52        ROUTE_HEADSET        = (1 << 3),
53        ROUTE_BLUETOOTH_A2DP = (1 << 4),
54        ROUTE_ALL       = 0xFFFFFFFF
55    };
56
57    /* These are static methods to control the system-wide AudioFlinger
58     * only privileged processes can have access to them
59     */
60
61    // routing helper functions
62    static status_t speakerphone(bool state);
63    static status_t isSpeakerphoneOn(bool* state);
64    static status_t bluetoothSco(bool state);
65    static status_t isBluetoothScoOn(bool* state);
66    static status_t muteMicrophone(bool state);
67    static status_t isMicrophoneMuted(bool *state);
68
69    static status_t setMasterVolume(float value);
70    static status_t setMasterMute(bool mute);
71    static status_t getMasterVolume(float* volume);
72    static status_t getMasterMute(bool* mute);
73
74    static status_t setStreamVolume(int stream, float value);
75    static status_t setStreamMute(int stream, bool mute);
76    static status_t getStreamVolume(int stream, float* volume);
77    static status_t getStreamMute(int stream, bool* mute);
78
79    static status_t setMode(int mode);
80    static status_t getMode(int* mode);
81
82    static status_t setRouting(int mode, uint32_t routes, uint32_t mask);
83    static status_t getRouting(int mode, uint32_t* routes);
84
85    static status_t isMusicActive(bool *state);
86
87    // Temporary interface, do not use
88    // TODO: Replace with a more generic key:value get/set mechanism
89    static status_t setParameter(const char* key, const char* value);
90
91    static void setErrorCallback(audio_error_callback cb);
92
93    // helper function to obtain AudioFlinger service handle
94    static const sp<IAudioFlinger>& get_audio_flinger();
95
96    static float linearToLog(int volume);
97    static int logToLinear(float volume);
98
99    static status_t getOutputSamplingRate(int* samplingRate);
100    static status_t getOutputFrameCount(int* frameCount);
101    static status_t getOutputLatency(uint32_t* latency);
102
103    // ----------------------------------------------------------------------------
104
105private:
106
107    class DeathNotifier: public IBinder::DeathRecipient
108    {
109    public:
110        DeathNotifier() {
111        }
112
113        virtual void binderDied(const wp<IBinder>& who);
114    };
115
116    static sp<DeathNotifier> gDeathNotifier;
117
118    friend class DeathNotifier;
119
120    static Mutex gLock;
121    static sp<IAudioFlinger> gAudioFlinger;
122    static audio_error_callback gAudioErrorCallback;
123    static int gOutSamplingRate;
124    static int gOutFrameCount;
125    static uint32_t gOutLatency;
126};
127
128};  // namespace android
129
130#endif  /*ANDROID_AUDIOSYSTEM_H_*/
131