1 /*
2  * Copyright (C) 2018 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 #define LOG_TAG "APM_ClientDescriptor"
18 //#define LOG_NDEBUG 0
19 
20 #include <sstream>
21 #include <utils/Log.h>
22 #include <utils/String8.h>
23 #include <TypeConverter.h>
24 #include "AudioOutputDescriptor.h"
25 #include "AudioPatch.h"
26 #include "ClientDescriptor.h"
27 #include "DeviceDescriptor.h"
28 #include "HwModule.h"
29 #include "IOProfile.h"
30 
31 namespace android {
32 
toShortString() const33 std::string ClientDescriptor::toShortString() const
34 {
35     std::stringstream ss;
36 
37     ss << "PortId: " << mPortId << " SessionId: " << mSessionId << " Uid: " << mUid;
38     return ss.str();
39 }
40 
dump(String8 * dst,int spaces,int index) const41 void ClientDescriptor::dump(String8 *dst, int spaces, int index) const
42 {
43     dst->appendFormat("%*sClient %d:\n", spaces, "", index+1);
44     dst->appendFormat("%*s- Port Id: %d Session Id: %d UID: %d\n", spaces, "",
45              mPortId, mSessionId, mUid);
46     dst->appendFormat("%*s- Format: %08x Sampling rate: %d Channels: %08x\n", spaces, "",
47              mConfig.format, mConfig.sample_rate, mConfig.channel_mask);
48     dst->appendFormat("%*s- Attributes: %s\n", spaces, "", toString(mAttributes).c_str());
49     dst->appendFormat("%*s- Preferred Device Id: %08x\n", spaces, "", mPreferredDeviceId);
50     dst->appendFormat("%*s- State: %s\n", spaces, "", mActive ? "Active" : "Inactive");
51 }
52 
dump(String8 * dst,int spaces,int index) const53 void TrackClientDescriptor::dump(String8 *dst, int spaces, int index) const
54 {
55     ClientDescriptor::dump(dst, spaces, index);
56     dst->appendFormat("%*s- Stream: %d flags: %08x\n", spaces, "", mStream, mFlags);
57     dst->appendFormat("%*s- Refcount: %d\n", spaces, "", mActivityCount);
58 }
59 
toShortString() const60 std::string TrackClientDescriptor::toShortString() const
61 {
62     std::stringstream ss;
63 
64     ss << ClientDescriptor::toShortString() << " Stream: " << mStream;
65     return ss.str();
66 }
67 
trackEffectEnabled(const sp<EffectDescriptor> & effect,bool enabled)68 void RecordClientDescriptor::trackEffectEnabled(const sp<EffectDescriptor> &effect, bool enabled)
69 {
70     if (enabled) {
71         mEnabledEffects.replaceValueFor(effect->mId, effect);
72     } else {
73         mEnabledEffects.removeItem(effect->mId);
74     }
75 }
76 
dump(String8 * dst,int spaces,int index) const77 void RecordClientDescriptor::dump(String8 *dst, int spaces, int index) const
78 {
79     ClientDescriptor::dump(dst, spaces, index);
80     dst->appendFormat("%*s- Source: %d flags: %08x\n", spaces, "", mSource, mFlags);
81     mEnabledEffects.dump(dst, spaces + 2 /*spaces*/, false /*verbose*/);
82 }
83 
SourceClientDescriptor(audio_port_handle_t portId,uid_t uid,audio_attributes_t attributes,const struct audio_port_config & config,const sp<DeviceDescriptor> & srcDevice,audio_stream_type_t stream,product_strategy_t strategy,VolumeSource volumeSource)84 SourceClientDescriptor::SourceClientDescriptor(audio_port_handle_t portId, uid_t uid,
85          audio_attributes_t attributes, const struct audio_port_config &config,
86          const sp<DeviceDescriptor>& srcDevice, audio_stream_type_t stream,
87          product_strategy_t strategy, VolumeSource volumeSource) :
88     TrackClientDescriptor::TrackClientDescriptor(portId, uid, AUDIO_SESSION_NONE, attributes,
89         {config.sample_rate, config.channel_mask, config.format}, AUDIO_PORT_HANDLE_NONE,
90         stream, strategy, volumeSource, AUDIO_OUTPUT_FLAG_NONE, false,
91         {} /* Sources do not support secondary outputs*/), mSrcDevice(srcDevice)
92 {
93 }
94 
setSwOutput(const sp<SwAudioOutputDescriptor> & swOutput)95 void SourceClientDescriptor::setSwOutput(const sp<SwAudioOutputDescriptor>& swOutput)
96 {
97     mSwOutput = swOutput;
98 }
99 
setHwOutput(const sp<HwAudioOutputDescriptor> & hwOutput)100 void SourceClientDescriptor::setHwOutput(const sp<HwAudioOutputDescriptor>& hwOutput)
101 {
102     mHwOutput = hwOutput;
103 }
104 
dump(String8 * dst,int spaces,int index) const105 void SourceClientDescriptor::dump(String8 *dst, int spaces, int index) const
106 {
107     TrackClientDescriptor::dump(dst, spaces, index);
108     dst->appendFormat("%*s- Device:\n", spaces, "");
109     mSrcDevice->dump(dst, 2, 0);
110 }
111 
dump(String8 * dst) const112 void SourceClientCollection::dump(String8 *dst) const
113 {
114     dst->append("\nAudio sources:\n");
115     for (size_t i = 0; i < size(); i++) {
116         valueAt(i)->dump(dst, 2, i);
117     }
118 }
119 
120 }; //namespace android
121