AudioPatch.cpp revision 98cc191247388132b6fd8a4ecd07abd6e4c5a0ed
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::AudioPatch" 18//#define LOG_NDEBUG 0 19 20#include "AudioPatch.h" 21#include "ConfigParsingUtils.h" 22#include <cutils/log.h> 23#include <utils/String8.h> 24 25namespace android { 26 27int32_t volatile AudioPatch::mNextUniqueId = 1; 28 29AudioPatch::AudioPatch(const struct audio_patch *patch, uid_t uid) : 30 mHandle(static_cast<audio_patch_handle_t>(android_atomic_inc(&mNextUniqueId))), 31 mPatch(*patch), 32 mUid(uid), 33 mAfPatchHandle(0) 34{ 35} 36 37status_t AudioPatch::dump(int fd, int spaces, int index) const 38{ 39 const size_t SIZE = 256; 40 char buffer[SIZE]; 41 String8 result; 42 43 snprintf(buffer, SIZE, "%*sAudio patch %d:\n", spaces, "", index+1); 44 result.append(buffer); 45 snprintf(buffer, SIZE, "%*s- handle: %2d\n", spaces, "", mHandle); 46 result.append(buffer); 47 snprintf(buffer, SIZE, "%*s- audio flinger handle: %2d\n", spaces, "", mAfPatchHandle); 48 result.append(buffer); 49 snprintf(buffer, SIZE, "%*s- owner uid: %2d\n", spaces, "", mUid); 50 result.append(buffer); 51 snprintf(buffer, SIZE, "%*s- %d sources:\n", spaces, "", mPatch.num_sources); 52 result.append(buffer); 53 for (size_t i = 0; i < mPatch.num_sources; i++) { 54 if (mPatch.sources[i].type == AUDIO_PORT_TYPE_DEVICE) { 55 snprintf(buffer, SIZE, "%*s- Device ID %d %s\n", spaces + 2, "", 56 mPatch.sources[i].id, ConfigParsingUtils::enumToString(sDeviceNameToEnumTable, 57 ARRAY_SIZE(sDeviceNameToEnumTable), 58 mPatch.sources[i].ext.device.type)); 59 } else { 60 snprintf(buffer, SIZE, "%*s- Mix ID %d I/O handle %d\n", spaces + 2, "", 61 mPatch.sources[i].id, mPatch.sources[i].ext.mix.handle); 62 } 63 result.append(buffer); 64 } 65 snprintf(buffer, SIZE, "%*s- %d sinks:\n", spaces, "", mPatch.num_sinks); 66 result.append(buffer); 67 for (size_t i = 0; i < mPatch.num_sinks; i++) { 68 if (mPatch.sinks[i].type == AUDIO_PORT_TYPE_DEVICE) { 69 snprintf(buffer, SIZE, "%*s- Device ID %d %s\n", spaces + 2, "", 70 mPatch.sinks[i].id, ConfigParsingUtils::enumToString(sDeviceNameToEnumTable, 71 ARRAY_SIZE(sDeviceNameToEnumTable), 72 mPatch.sinks[i].ext.device.type)); 73 } else { 74 snprintf(buffer, SIZE, "%*s- Mix ID %d I/O handle %d\n", spaces + 2, "", 75 mPatch.sinks[i].id, mPatch.sinks[i].ext.mix.handle); 76 } 77 result.append(buffer); 78 } 79 80 write(fd, result.string(), result.size()); 81 return NO_ERROR; 82} 83 84}; // namespace android 85