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