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
22 #include <android-base/stringprintf.h>
23 #include <TypeConverter.h>
24 #include <utils/Log.h>
25 #include <utils/String8.h>
26
27 #include "AudioOutputDescriptor.h"
28 #include "AudioPatch.h"
29 #include "AudioPolicyMix.h"
30 #include "ClientDescriptor.h"
31 #include "DeviceDescriptor.h"
32 #include "HwModule.h"
33 #include "IOProfile.h"
34
35 namespace android {
36
toShortString() const37 std::string ClientDescriptor::toShortString() const
38 {
39 std::stringstream ss;
40
41 ss << "PortId: " << mPortId << " SessionId: " << mSessionId << " Uid: " << mUid;
42 return ss.str();
43 }
44
dump(String8 * dst,int spaces) const45 void ClientDescriptor::dump(String8 *dst, int spaces) const
46 {
47 dst->appendFormat("Port ID: %d; Session ID: %d; uid %d; State: %s\n",
48 mPortId, mSessionId, mUid, mActive ? "Active" : "Inactive");
49 dst->appendFormat("%*s%s; %d; Channel mask: 0x%x\n", spaces, "",
50 audio_format_to_string(mConfig.format), mConfig.sample_rate, mConfig.channel_mask);
51 dst->appendFormat("%*sAttributes: %s\n", spaces, "", toString(mAttributes).c_str());
52 if (mPreferredDeviceId != AUDIO_PORT_HANDLE_NONE) {
53 dst->appendFormat("%*sPreferred Device Port ID: %d;\n", spaces, "", mPreferredDeviceId);
54 }
55 }
56
dump(String8 * dst,int spaces) const57 void TrackClientDescriptor::dump(String8 *dst, int spaces) const
58 {
59 ClientDescriptor::dump(dst, spaces);
60 dst->appendFormat("%*sStream: %d; Flags: %08x; Refcount: %d\n", spaces, "",
61 mStream, mFlags, mActivityCount);
62 dst->appendFormat("%*sDAP Primary Mix: %p\n", spaces, "", mPrimaryMix.promote().get());
63 if (!mSecondaryOutputs.empty()) {
64 dst->appendFormat("%*sDAP Secondary Outputs: ", spaces - 2, "");
65 for (auto desc : mSecondaryOutputs) {
66 dst->appendFormat("%d, ", desc.promote() == nullptr ? 0 : desc.promote()->mIoHandle);
67 }
68 dst->append("\n");
69 }
70 }
71
toShortString() const72 std::string TrackClientDescriptor::toShortString() const
73 {
74 std::stringstream ss;
75 ss << ClientDescriptor::toShortString() << " Stream: " << mStream;
76 return ss.str();
77 }
78
trackEffectEnabled(const sp<EffectDescriptor> & effect,bool enabled)79 void RecordClientDescriptor::trackEffectEnabled(const sp<EffectDescriptor> &effect, bool enabled)
80 {
81 if (enabled) {
82 mEnabledEffects.replaceValueFor(effect->mId, effect);
83 } else {
84 mEnabledEffects.removeItem(effect->mId);
85 }
86 }
87
dump(String8 * dst,int spaces) const88 void RecordClientDescriptor::dump(String8 *dst, int spaces) const
89 {
90 ClientDescriptor::dump(dst, spaces);
91 dst->appendFormat("%*sSource: %d; Flags: %08x; is soundtrigger: %d\n",
92 spaces, "", mSource, mFlags, mIsSoundTrigger);
93 mEnabledEffects.dump(dst, spaces + 2 /*spaces*/, false /*verbose*/);
94 }
95
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)96 SourceClientDescriptor::SourceClientDescriptor(audio_port_handle_t portId, uid_t uid,
97 audio_attributes_t attributes, const struct audio_port_config &config,
98 const sp<DeviceDescriptor>& srcDevice, audio_stream_type_t stream,
99 product_strategy_t strategy, VolumeSource volumeSource) :
100 TrackClientDescriptor::TrackClientDescriptor(portId, uid, AUDIO_SESSION_NONE, attributes,
101 {config.sample_rate, config.channel_mask, config.format}, AUDIO_PORT_HANDLE_NONE,
102 stream, strategy, volumeSource, AUDIO_OUTPUT_FLAG_NONE, false,
103 {} /* Sources do not support secondary outputs*/, nullptr),
104 mSrcDevice(srcDevice)
105 {
106 }
107
setSwOutput(const sp<SwAudioOutputDescriptor> & swOutput,bool closeOutput)108 void SourceClientDescriptor::setSwOutput(
109 const sp<SwAudioOutputDescriptor>& swOutput, bool closeOutput)
110 {
111 mSwOutput = swOutput;
112 mCloseOutput = closeOutput;
113 }
114
setHwOutput(const sp<HwAudioOutputDescriptor> & hwOutput)115 void SourceClientDescriptor::setHwOutput(const sp<HwAudioOutputDescriptor>& hwOutput)
116 {
117 mHwOutput = hwOutput;
118 }
119
dump(String8 * dst,int spaces) const120 void SourceClientDescriptor::dump(String8 *dst, int spaces) const
121 {
122 TrackClientDescriptor::dump(dst, spaces);
123 const std::string prefix = base::StringPrintf("%*sDevice: ", spaces, "");
124 dst->appendFormat("%s", prefix.c_str());
125 mSrcDevice->dump(dst, prefix.size());
126 }
127
dump(String8 * dst) const128 void SourceClientCollection::dump(String8 *dst) const
129 {
130 dst->appendFormat("\n Audio sources (%zu):\n", size());
131 for (size_t i = 0; i < size(); i++) {
132 const std::string prefix = base::StringPrintf(" %zu. ", i + 1);
133 dst->appendFormat("%s", prefix.c_str());
134 valueAt(i)->dump(dst, prefix.size());
135 }
136 }
137
138 }; //namespace android
139