• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "AudioGain.h"
25 #include "AudioOutputDescriptor.h"
26 #include "AudioPatch.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 }
60 
toShortString() const61 std::string TrackClientDescriptor::toShortString() const
62 {
63     std::stringstream ss;
64 
65     ss << ClientDescriptor::toShortString() << " Stream: " << mStream;
66     return ss.str();
67 }
68 
trackEffectEnabled(const sp<EffectDescriptor> & effect,bool enabled)69 void RecordClientDescriptor::trackEffectEnabled(const sp<EffectDescriptor> &effect, bool enabled)
70 {
71     if (enabled) {
72         mEnabledEffects.replaceValueFor(effect->mId, effect);
73     } else {
74         mEnabledEffects.removeItem(effect->mId);
75     }
76 }
77 
dump(String8 * dst,int spaces,int index) const78 void RecordClientDescriptor::dump(String8 *dst, int spaces, int index) const
79 {
80     ClientDescriptor::dump(dst, spaces, index);
81     dst->appendFormat("%*s- Source: %d flags: %08x\n", spaces, "", mSource, mFlags);
82     mEnabledEffects.dump(dst, spaces + 2 /*spaces*/, false /*verbose*/);
83 }
84 
SourceClientDescriptor(audio_port_handle_t portId,uid_t uid,audio_attributes_t attributes,const sp<AudioPatch> & patchDesc,const sp<DeviceDescriptor> & srcDevice,audio_stream_type_t stream,product_strategy_t strategy,VolumeSource volumeSource)85 SourceClientDescriptor::SourceClientDescriptor(audio_port_handle_t portId, uid_t uid,
86          audio_attributes_t attributes, const sp<AudioPatch>& patchDesc,
87          const sp<DeviceDescriptor>& srcDevice, audio_stream_type_t stream,
88          product_strategy_t strategy, VolumeSource volumeSource) :
89     TrackClientDescriptor::TrackClientDescriptor(portId, uid, AUDIO_SESSION_NONE, attributes,
90         AUDIO_CONFIG_BASE_INITIALIZER, AUDIO_PORT_HANDLE_NONE,
91         stream, strategy, volumeSource, AUDIO_OUTPUT_FLAG_NONE, false,
92         {} /* Sources do not support secondary outputs*/),
93         mPatchDesc(patchDesc), mSrcDevice(srcDevice)
94 {
95 }
96 
setSwOutput(const sp<SwAudioOutputDescriptor> & swOutput)97 void SourceClientDescriptor::setSwOutput(const sp<SwAudioOutputDescriptor>& swOutput)
98 {
99     mSwOutput = swOutput;
100 }
101 
setHwOutput(const sp<HwAudioOutputDescriptor> & hwOutput)102 void SourceClientDescriptor::setHwOutput(const sp<HwAudioOutputDescriptor>& hwOutput)
103 {
104     mHwOutput = hwOutput;
105 }
106 
dump(String8 * dst,int spaces,int index) const107 void SourceClientDescriptor::dump(String8 *dst, int spaces, int index) const
108 {
109     TrackClientDescriptor::dump(dst, spaces, index);
110     dst->appendFormat("%*s- Device:\n", spaces, "");
111     mSrcDevice->dump(dst, 2, 0);
112 }
113 
dump(String8 * dst) const114 void SourceClientCollection::dump(String8 *dst) const
115 {
116     dst->append("\nAudio sources:\n");
117     for (size_t i = 0; i < size(); i++) {
118         valueAt(i)->dump(dst, 2, i);
119     }
120 }
121 
122 }; //namespace android
123