policy.h revision 05ddca504ce8e0e61b41e5c1aebea72086eea57b
1/* 2 * Copyright (C) 2015 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#pragma once 18 19#include <system/audio.h> 20 21static const audio_format_t gDynamicFormat = AUDIO_FORMAT_DEFAULT; 22 23// For mixed output and inputs, the policy will use max mixer sampling rates. 24// Do not limit sampling rate otherwise 25#define SAMPLE_RATE_HZ_MAX 192000 26 27// Used when a client opens a capture stream, without specifying a desired sample rate. 28#define SAMPLE_RATE_HZ_DEFAULT 48000 29 30// For mixed output and inputs, the policy will use max mixer channel count. 31// Do not limit channel count otherwise 32#define MAX_MIXER_CHANNEL_COUNT FCC_8 33 34/** 35 * A device mask for all audio input devices that are considered "virtual" when evaluating 36 * active inputs in getActiveInput() 37 */ 38#define APM_AUDIO_IN_DEVICE_VIRTUAL_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX|AUDIO_DEVICE_IN_FM_TUNER) 39 40 41/** 42 * A device mask for all audio input and output devices where matching inputs/outputs on device 43 * type alone is not enough: the address must match too 44 */ 45#define APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL (AUDIO_DEVICE_OUT_REMOTE_SUBMIX) 46 47#define APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL (AUDIO_DEVICE_IN_REMOTE_SUBMIX) 48 49/** 50 * Check if the state given correspond to an in call state. 51 * @TODO find a better name for widely call state 52 * 53 * @param[in] state to consider 54 * 55 * @return true if given state represents a device in a telephony or VoIP call 56 */ 57static inline bool is_state_in_call(int state) 58{ 59 return (state == AUDIO_MODE_IN_CALL) || (state == AUDIO_MODE_IN_COMMUNICATION); 60} 61 62/** 63 * Check if the input device given is considered as a virtual device. 64 * 65 * @param[in] device to consider 66 * 67 * @return true if the device is a virtual one, false otherwise. 68 */ 69static inline bool is_virtual_input_device(audio_devices_t device) 70{ 71 if ((device & AUDIO_DEVICE_BIT_IN) != 0) { 72 device &= ~AUDIO_DEVICE_BIT_IN; 73 if ((popcount(device) == 1) && ((device & ~APM_AUDIO_IN_DEVICE_VIRTUAL_ALL) == 0)) 74 return true; 75 } 76 return false; 77} 78 79/** 80 * Check whether the device type is one 81 * where addresses are used to distinguish between one connected device and another 82 * 83 * @param[in] device to consider 84 * 85 * @return true if the device needs distinguish on address, false otherwise.. 86 */ 87static inline bool device_distinguishes_on_address(audio_devices_t device) 88{ 89 return (((device & AUDIO_DEVICE_BIT_IN) != 0) && 90 ((~AUDIO_DEVICE_BIT_IN & device & APM_AUDIO_DEVICE_IN_MATCH_ADDRESS_ALL) != 0)) || 91 (((device & AUDIO_DEVICE_BIT_IN) == 0) && 92 ((device & APM_AUDIO_DEVICE_OUT_MATCH_ADDRESS_ALL) != 0)); 93} 94 95/* Indicates if audio formats are equivalent when considering a match between 96 * audio HAL supported formats and client requested formats 97 */ 98static inline bool audio_formats_match(audio_format_t format1, 99 audio_format_t format2) 100{ 101 if (audio_is_linear_pcm(format1) && 102 (audio_bytes_per_sample(format1) > 2) && 103 audio_is_linear_pcm(format2) && 104 (audio_bytes_per_sample(format2) > 2)) { 105 return true; 106 } 107 return format1 == format2; 108} 109