AudioInputDescriptor.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::AudioInputDescriptor" 18//#define LOG_NDEBUG 0 19 20#include "AudioInputDescriptor.h" 21#include "IOProfile.h" 22#include "AudioGain.h" 23#include "HwModule.h" 24#include <media/AudioPolicy.h> 25 26namespace android { 27 28AudioInputDescriptor::AudioInputDescriptor(const sp<IOProfile>& profile) 29 : mId(0), mIoHandle(0), 30 mDevice(AUDIO_DEVICE_NONE), mPolicyMix(NULL), mPatchHandle(0), mRefCount(0), 31 mInputSource(AUDIO_SOURCE_DEFAULT), mProfile(profile), mIsSoundTrigger(false) 32{ 33 if (profile != NULL) { 34 mSamplingRate = profile->pickSamplingRate(); 35 mFormat = profile->pickFormat(); 36 mChannelMask = profile->pickChannelMask(); 37 if (profile->mGains.size() > 0) { 38 profile->mGains[0]->getDefaultConfig(&mGain); 39 } 40 } 41} 42 43void AudioInputDescriptor::setIoHandle(audio_io_handle_t ioHandle) 44{ 45 mId = AudioPort::getNextUniqueId(); 46 mIoHandle = ioHandle; 47} 48 49void AudioInputDescriptor::toAudioPortConfig( 50 struct audio_port_config *dstConfig, 51 const struct audio_port_config *srcConfig) const 52{ 53 ALOG_ASSERT(mProfile != 0, 54 "toAudioPortConfig() called on input with null profile %d", mIoHandle); 55 dstConfig->config_mask = AUDIO_PORT_CONFIG_SAMPLE_RATE|AUDIO_PORT_CONFIG_CHANNEL_MASK| 56 AUDIO_PORT_CONFIG_FORMAT|AUDIO_PORT_CONFIG_GAIN; 57 if (srcConfig != NULL) { 58 dstConfig->config_mask |= srcConfig->config_mask; 59 } 60 61 AudioPortConfig::toAudioPortConfig(dstConfig, srcConfig); 62 63 dstConfig->id = mId; 64 dstConfig->role = AUDIO_PORT_ROLE_SINK; 65 dstConfig->type = AUDIO_PORT_TYPE_MIX; 66 dstConfig->ext.mix.hw_module = mProfile->mModule->mHandle; 67 dstConfig->ext.mix.handle = mIoHandle; 68 dstConfig->ext.mix.usecase.source = mInputSource; 69} 70 71void AudioInputDescriptor::toAudioPort( 72 struct audio_port *port) const 73{ 74 ALOG_ASSERT(mProfile != 0, "toAudioPort() called on input with null profile %d", mIoHandle); 75 76 mProfile->toAudioPort(port); 77 port->id = mId; 78 toAudioPortConfig(&port->active_config); 79 port->ext.mix.hw_module = mProfile->mModule->mHandle; 80 port->ext.mix.handle = mIoHandle; 81 port->ext.mix.latency_class = AUDIO_LATENCY_NORMAL; 82} 83 84status_t AudioInputDescriptor::dump(int fd) 85{ 86 const size_t SIZE = 256; 87 char buffer[SIZE]; 88 String8 result; 89 90 snprintf(buffer, SIZE, " ID: %d\n", mId); 91 result.append(buffer); 92 snprintf(buffer, SIZE, " Sampling rate: %d\n", mSamplingRate); 93 result.append(buffer); 94 snprintf(buffer, SIZE, " Format: %d\n", mFormat); 95 result.append(buffer); 96 snprintf(buffer, SIZE, " Channels: %08x\n", mChannelMask); 97 result.append(buffer); 98 snprintf(buffer, SIZE, " Devices %08x\n", mDevice); 99 result.append(buffer); 100 snprintf(buffer, SIZE, " Ref Count %d\n", mRefCount); 101 result.append(buffer); 102 snprintf(buffer, SIZE, " Open Ref Count %d\n", mOpenRefCount); 103 result.append(buffer); 104 105 write(fd, result.string(), result.size()); 106 107 return NO_ERROR; 108} 109 110}; //namespace android 111