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 #include "AudioGain.h"
23 
24 namespace android
25 {
26 
dump(String8 * dst,int spaces) const27 void AudioRoute::dump(String8 *dst, int spaces) const
28 {
29     dst->appendFormat("%*s- Type: %s\n", spaces, "", mType == AUDIO_ROUTE_MUX ? "Mux" : "Mix");
30     dst->appendFormat("%*s- Sink: %s\n", spaces, "", mSink->getTagName().string());
31     if (mSources.size() != 0) {
32         dst->appendFormat("%*s- Sources: \n", spaces, "");
33         for (size_t i = 0; i < mSources.size(); i++) {
34             dst->appendFormat("%*s%s \n", spaces + 4, "", mSources[i]->getTagName().string());
35         }
36     }
37     dst->append("\n");
38 }
39 
supportsPatch(const sp<AudioPort> & srcPort,const sp<AudioPort> & dstPort) const40 bool AudioRoute::supportsPatch(const sp<AudioPort> &srcPort, const sp<AudioPort> &dstPort) const
41 {
42     if (mSink == 0 || dstPort == 0 || dstPort != mSink) {
43         return false;
44     }
45     ALOGV("%s: sinks %s matching", __FUNCTION__, mSink->getTagName().string());
46     for (const auto &sourcePort : mSources) {
47         if (sourcePort == srcPort) {
48             ALOGV("%s: sources %s matching", __FUNCTION__, sourcePort->getTagName().string());
49             return true;
50         }
51     }
52     return false;
53 }
54 
55 }
56