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 "AudioPolicyMix.h"
27 #include "ClientDescriptor.h"
28 #include "DeviceDescriptor.h"
29 #include "HwModule.h"
30 #include "IOProfile.h"
31
32 namespace android {
33
toShortString() const34 std::string ClientDescriptor::toShortString() const
35 {
36 std::stringstream ss;
37
38 ss << "PortId: " << mPortId << " SessionId: " << mSessionId << " Uid: " << mUid;
39 return ss.str();
40 }
41
dump(String8 * dst,int spaces,int index) const42 void ClientDescriptor::dump(String8 *dst, int spaces, int index) const
43 {
44 dst->appendFormat("%*sClient %d:\n", spaces, "", index+1);
45 dst->appendFormat("%*s- Port Id: %d Session Id: %d UID: %d\n", spaces, "",
46 mPortId, mSessionId, mUid);
47 dst->appendFormat("%*s- Format: %08x Sampling rate: %d Channels: %08x\n", spaces, "",
48 mConfig.format, mConfig.sample_rate, mConfig.channel_mask);
49 dst->appendFormat("%*s- Attributes: %s\n", spaces, "", toString(mAttributes).c_str());
50 dst->appendFormat("%*s- Preferred Device Id: %08x\n", spaces, "", mPreferredDeviceId);
51 dst->appendFormat("%*s- State: %s\n", spaces, "", mActive ? "Active" : "Inactive");
52 }
53
dump(String8 * dst,int spaces,int index) const54 void TrackClientDescriptor::dump(String8 *dst, int spaces, int index) const
55 {
56 ClientDescriptor::dump(dst, spaces, index);
57 dst->appendFormat("%*s- Stream: %d flags: %08x\n", spaces, "", mStream, mFlags);
58 dst->appendFormat("%*s- Refcount: %d\n", spaces, "", mActivityCount);
59 dst->appendFormat("%*s- DAP Primary Mix: %p\n", spaces, "", mPrimaryMix.promote().get());
60 dst->appendFormat("%*s- DAP Secondary Outputs:\n", spaces, "");
61 for (auto desc : mSecondaryOutputs) {
62 dst->appendFormat("%*s - %d\n", spaces, "",
63 desc.promote() == nullptr ? 0 : desc.promote()->mIoHandle);
64 }
65 }
66
toShortString() const67 std::string TrackClientDescriptor::toShortString() const
68 {
69 std::stringstream ss;
70
71 ss << ClientDescriptor::toShortString() << " Stream: " << mStream;
72 return ss.str();
73 }
74
trackEffectEnabled(const sp<EffectDescriptor> & effect,bool enabled)75 void RecordClientDescriptor::trackEffectEnabled(const sp<EffectDescriptor> &effect, bool enabled)
76 {
77 if (enabled) {
78 mEnabledEffects.replaceValueFor(effect->mId, effect);
79 } else {
80 mEnabledEffects.removeItem(effect->mId);
81 }
82 }
83
dump(String8 * dst,int spaces,int index) const84 void RecordClientDescriptor::dump(String8 *dst, int spaces, int index) const
85 {
86 ClientDescriptor::dump(dst, spaces, index);
87 dst->appendFormat("%*s- Source: %d flags: %08x\n", spaces, "", mSource, mFlags);
88 mEnabledEffects.dump(dst, spaces + 2 /*spaces*/, false /*verbose*/);
89 }
90
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)91 SourceClientDescriptor::SourceClientDescriptor(audio_port_handle_t portId, uid_t uid,
92 audio_attributes_t attributes, const struct audio_port_config &config,
93 const sp<DeviceDescriptor>& srcDevice, audio_stream_type_t stream,
94 product_strategy_t strategy, VolumeSource volumeSource) :
95 TrackClientDescriptor::TrackClientDescriptor(portId, uid, AUDIO_SESSION_NONE, attributes,
96 {config.sample_rate, config.channel_mask, config.format}, AUDIO_PORT_HANDLE_NONE,
97 stream, strategy, volumeSource, AUDIO_OUTPUT_FLAG_NONE, false,
98 {} /* Sources do not support secondary outputs*/, nullptr), mSrcDevice(srcDevice)
99 {
100 }
101
setSwOutput(const sp<SwAudioOutputDescriptor> & swOutput)102 void SourceClientDescriptor::setSwOutput(const sp<SwAudioOutputDescriptor>& swOutput)
103 {
104 mSwOutput = swOutput;
105 }
106
setHwOutput(const sp<HwAudioOutputDescriptor> & hwOutput)107 void SourceClientDescriptor::setHwOutput(const sp<HwAudioOutputDescriptor>& hwOutput)
108 {
109 mHwOutput = hwOutput;
110 }
111
dump(String8 * dst,int spaces,int index) const112 void SourceClientDescriptor::dump(String8 *dst, int spaces, int index) const
113 {
114 TrackClientDescriptor::dump(dst, spaces, index);
115 dst->appendFormat("%*s- Device:\n", spaces, "");
116 mSrcDevice->dump(dst, 2, 0);
117 }
118
dump(String8 * dst) const119 void SourceClientCollection::dump(String8 *dst) const
120 {
121 dst->append("\nAudio sources:\n");
122 for (size_t i = 0; i < size(); i++) {
123 valueAt(i)->dump(dst, 2, i);
124 }
125 }
126
127 }; //namespace android
128