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- Type: %s\n", spaces, "", mType == AUDIO_ROUTE_MUX ? "Mux" : "Mix");
29     dst->appendFormat("%*s- Sink: %s\n", spaces, "", mSink->getTagName().c_str());
30     if (mSources.size() != 0) {
31         dst->appendFormat("%*s- Sources: \n", spaces, "");
32         for (size_t i = 0; i < mSources.size(); i++) {
33             dst->appendFormat("%*s%s \n", spaces + 4, "", mSources[i]->getTagName().c_str());
34         }
35     }
36     dst->append("\n");
37 }
38 
supportsPatch(const sp<PolicyAudioPort> & srcPort,const sp<PolicyAudioPort> & dstPort) const39 bool AudioRoute::supportsPatch(const sp<PolicyAudioPort> &srcPort,
40                                const sp<PolicyAudioPort> &dstPort) const
41 {
42     if (mSink == 0 || dstPort == 0 || dstPort != mSink) {
43         return false;
44     }
45     ALOGV("%s: sinks %s matching", __FUNCTION__, mSink->getTagName().c_str());
46     for (const auto &sourcePort : mSources) {
47         if (sourcePort == srcPort) {
48             ALOGV("%s: sources %s matching", __FUNCTION__, sourcePort->getTagName().c_str());
49             return true;
50         }
51     }
52     return false;
53 }
54 
55 }
56