• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 <map>
20 
21 #include <utils/RefBase.h>
22 
23 #include "AudioRoute.h"
24 #include "HwModule.h"
25 #include "IOProfile.h"
26 
27 namespace android {
28 
29 class PreferredMixerAttributesInfo : public RefBase {
30 public:
PreferredMixerAttributesInfo(uid_t uid,audio_port_handle_t devicePortId,const sp<IOProfile> & profile,audio_output_flags_t flags,const audio_mixer_attributes_t & mixerAttributes)31     PreferredMixerAttributesInfo(uid_t uid, audio_port_handle_t devicePortId,
32                                  const sp<IOProfile>& profile, audio_output_flags_t flags,
33                                  const audio_mixer_attributes_t& mixerAttributes)
34         : mDevicePortId(devicePortId), mUid(uid), mProfile(profile),
35           mOutputFlags(flags), mMixerAttributes(mixerAttributes) { }
36 
getDeviceId()37     audio_port_handle_t getDeviceId() const { return mDevicePortId; }
getConfigBase()38     const audio_config_base_t& getConfigBase() const { return mMixerAttributes.config; }
getUid()39     uid_t getUid() const { return mUid; }
getActiveClientCount()40     int getActiveClientCount() const { return mActiveClientsCount; }
getProfile()41     const sp<IOProfile> getProfile() const { return mProfile; };
getFlags()42     audio_output_flags_t getFlags() const { return mOutputFlags; }
getMixerAttributes()43     const audio_mixer_attributes_t& getMixerAttributes() const { return mMixerAttributes; }
44 
increaseActiveClient()45     void increaseActiveClient() { mActiveClientsCount++; }
decreaseActiveClient()46     void decreaseActiveClient() { mActiveClientsCount--; }
resetActiveClient()47     void resetActiveClient() { mActiveClientsCount = 0; }
48 
isBitPerfect()49     bool isBitPerfect() const {
50         return (getFlags() & AUDIO_OUTPUT_FLAG_BIT_PERFECT) != AUDIO_OUTPUT_FLAG_NONE;
51     }
52 
configMatches(const audio_config_t & config)53     bool configMatches(const audio_config_t& config) const {
54         return config.format == mMixerAttributes.config.format &&
55                 config.channel_mask == mMixerAttributes.config.channel_mask &&
56                 config.sample_rate == mMixerAttributes.config.sample_rate;
57     }
58 
59     void dump(String8 *dst);
60 
61 private:
62     const audio_port_handle_t mDevicePortId;
63     const uid_t mUid;
64     const sp<IOProfile> mProfile;
65     const audio_output_flags_t mOutputFlags;
66     const audio_mixer_attributes_t mMixerAttributes;
67     int mActiveClientsCount = 0;
68 };
69 
70 } // namespace android