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 <media/AudioProfile.h> 20 #include <system/audio.h> 21 22 namespace android { 23 24 void sortAudioProfiles(AudioProfileVector &audioProfileVector); 25 26 ssize_t addAudioProfileAndSort(AudioProfileVector &audioProfileVector, 27 const sp<AudioProfile> &profile); 28 29 // One audio profile will be added for each format supported by Audio HAL 30 void addProfilesForFormats(AudioProfileVector &audioProfileVector, 31 const FormatVector &formatVector); 32 33 // This API is intended to be used by the policy manager once retrieving capabilities 34 // for a profile with dynamic format, rate and channels attributes 35 void addDynamicAudioProfileAndSort(AudioProfileVector &audioProfileVector, 36 const sp<AudioProfile> &profileToAdd); 37 38 void appendAudioProfiles(AudioProfileVector &audioProfileVector, 39 const AudioProfileVector &audioProfileVectorToAppend); 40 41 /** 42 * Check if the profile vector contains a profile that matches the given sampling rate, channel 43 * mask and format. Note that this method uses `audio_formats_match` from policy.h, which will 44 * consider PCM formats match if their bytes per sample are greater than 2. 45 * 46 * @param audioProfileVector 47 * @param samplingRate 48 * @param channelMask 49 * @param format 50 * @return NO_ERROR if the given profile vector is empty or it contains a profile that matches the 51 * given sampling rate, channel mask and format. Otherwise, returns BAD_VALUE. 52 */ 53 status_t checkExactProfile(const AudioProfileVector &audioProfileVector, 54 const uint32_t samplingRate, 55 audio_channel_mask_t channelMask, 56 audio_format_t format); 57 58 /** 59 * Check if the profile vector contains a profile that has exactly the same sampling rate, channel 60 * mask and format as the given values. 61 * 62 * @param audioProfileVector 63 * @param samplingRate 64 * @param channelMask 65 * @param format 66 * @return NO_ERROR if the given profile vector is empty or it contains a profile that that has 67 * exactly the same sampling rate, channel mask and format as the given values. Otherwise, 68 * returns BAD_VALUE. 69 */ 70 status_t checkIdenticalProfile(const AudioProfileVector &audioProfileVector, 71 const uint32_t samplingRate, 72 audio_channel_mask_t channelMask, 73 audio_format_t format); 74 75 status_t checkCompatibleProfile(const AudioProfileVector &audioProfileVector, 76 uint32_t &samplingRate, 77 audio_channel_mask_t &channelMask, 78 audio_format_t &format, 79 audio_port_type_t portType, 80 audio_port_role_t portRole); 81 82 // Assuming that this profile vector contains input profiles, 83 // find the best matching config from 'outputProfiles', according to 84 // the given preferences for audio formats and channel masks. 85 // Note: std::vectors are used because specialized containers for formats 86 // and channels can be sorted and use their own ordering. 87 status_t findBestMatchingOutputConfig( 88 const AudioProfileVector &audioProfileVector, 89 const AudioProfileVector &outputProfileVector, 90 const std::vector<audio_format_t> &preferredFormatVector, // order: most pref -> least pref 91 const std::vector<audio_channel_mask_t> &preferredOutputChannelVector, 92 bool preferHigherSamplingRates, 93 audio_config_base &bestOutputConfig); 94 95 96 } // namespace android