1 /*
2  * Copyright (C) 2015 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::AudioRoute"
18 //#define LOG_NDEBUG 0
19 
20 #include "AudioRoute.h"
21 #include "HwModule.h"
22 
23 namespace android
24 {
25 
dump(String8 * dst,int spaces) const26 void AudioRoute::dump(String8 *dst, int spaces) const
27 {
28     dst->appendFormat("%s; Sink: \"%s\"\n",
29             mType == AUDIO_ROUTE_MUX ? "Mux" : "Mix", mSink->getTagName().c_str());
30     if (mSources.size() != 0) {
31         dst->appendFormat("%*sSources: ", spaces, "");
32         for (size_t i = 0; i < mSources.size(); i++) {
33             dst->appendFormat("\"%s\"", mSources[i]->getTagName().c_str());
34             if (i + 1 < mSources.size()) dst->append(", ");
35         }
36         dst->append("\n");
37     }
38 }
39 
supportsPatch(const sp<PolicyAudioPort> & srcPort,const sp<PolicyAudioPort> & dstPort) const40 bool AudioRoute::supportsPatch(const sp<PolicyAudioPort> &srcPort,
41                                const sp<PolicyAudioPort> &dstPort) const
42 {
43     if (mSink == 0 || srcPort == 0 || dstPort == 0 || !dstPort->equals(mSink)) {
44         return false;
45     }
46     ALOGV("%s: sinks %s matching", __FUNCTION__, mSink->getTagName().c_str());
47     for (const auto &sourcePort : mSources) {
48         if (sourcePort->equals(srcPort)) {
49             ALOGV("%s: sources %s matching", __FUNCTION__, sourcePort->getTagName().c_str());
50             return true;
51         }
52     }
53     return false;
54 }
55 
56 }
57