/* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ANDROID_AUDIOSYSTEM_H_ #define ANDROID_AUDIOSYSTEM_H_ #include #include #include namespace android { typedef void (*audio_error_callback)(status_t err); class AudioSystem { public: enum audio_format { DEFAULT = 0, PCM_16_BIT, PCM_8_BIT, INVALID_FORMAT }; enum audio_mode { MODE_INVALID = -2, MODE_CURRENT = -1, MODE_NORMAL = 0, MODE_RINGTONE, MODE_IN_CALL, NUM_MODES // not a valid entry, denotes end-of-list }; enum audio_routes { ROUTE_EARPIECE = (1 << 0), ROUTE_SPEAKER = (1 << 1), ROUTE_BLUETOOTH_SCO = (1 << 2), ROUTE_HEADSET = (1 << 3), ROUTE_BLUETOOTH_A2DP = (1 << 4), ROUTE_ALL = 0xFFFFFFFF }; /* These are static methods to control the system-wide AudioFlinger * only privileged processes can have access to them */ // routing helper functions static status_t speakerphone(bool state); static status_t isSpeakerphoneOn(bool* state); static status_t bluetoothSco(bool state); static status_t isBluetoothScoOn(bool* state); static status_t muteMicrophone(bool state); static status_t isMicrophoneMuted(bool *state); static status_t setMasterVolume(float value); static status_t setMasterMute(bool mute); static status_t getMasterVolume(float* volume); static status_t getMasterMute(bool* mute); static status_t setStreamVolume(int stream, float value); static status_t setStreamMute(int stream, bool mute); static status_t getStreamVolume(int stream, float* volume); static status_t getStreamMute(int stream, bool* mute); static status_t setMode(int mode); static status_t getMode(int* mode); static status_t setRouting(int mode, uint32_t routes, uint32_t mask); static status_t getRouting(int mode, uint32_t* routes); static status_t isMusicActive(bool *state); // Temporary interface, do not use // TODO: Replace with a more generic key:value get/set mechanism static status_t setParameter(const char* key, const char* value); static void setErrorCallback(audio_error_callback cb); // helper function to obtain AudioFlinger service handle static const sp& get_audio_flinger(); static float linearToLog(int volume); static int logToLinear(float volume); static status_t getOutputSamplingRate(int* samplingRate); static status_t getOutputFrameCount(int* frameCount); static status_t getOutputLatency(uint32_t* latency); static status_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount, size_t* buffSize); // ---------------------------------------------------------------------------- private: class AudioFlingerClient: public IBinder::DeathRecipient, public BnAudioFlingerClient { public: AudioFlingerClient() { } // DeathRecipient virtual void binderDied(const wp& who); // IAudioFlingerClient virtual void audioOutputChanged(uint32_t frameCount, uint32_t samplingRate, uint32_t latency); }; static sp gAudioFlingerClient; friend class AudioFlingerClient; static Mutex gLock; static sp gAudioFlinger; static audio_error_callback gAudioErrorCallback; static int gOutSamplingRate; static int gOutFrameCount; static uint32_t gOutLatency; static size_t gInBuffSize; // previous parameters for recording buffer size queries static uint32_t gPrevInSamplingRate; static int gPrevInFormat; static int gPrevInChannelCount; }; }; // namespace android #endif /*ANDROID_AUDIOSYSTEM_H_*/