AudioHwDevice.cpp revision 062e67a26e0553dd142be622821f493df541f0c6
1/* 2** 3** Copyright 2007, The Android Open Source Project 4** 5** Licensed under the Apache License, Version 2.0 (the "License"); 6** you may not use this file except in compliance with the License. 7** You may obtain a copy of the License at 8** 9** http://www.apache.org/licenses/LICENSE-2.0 10** 11** Unless required by applicable law or agreed to in writing, software 12** distributed under the License is distributed on an "AS IS" BASIS, 13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14** See the License for the specific language governing permissions and 15** limitations under the License. 16*/ 17 18#define LOG_TAG "AudioHwDevice" 19//#define LOG_NDEBUG 0 20 21#include <hardware/audio.h> 22#include <utils/Log.h> 23 24#include <audio_utils/spdif/SPDIFEncoder.h> 25 26#include "AudioHwDevice.h" 27#include "AudioStreamOut.h" 28#include "SpdifStreamOut.h" 29 30namespace android { 31 32// ---------------------------------------------------------------------------- 33 34status_t AudioHwDevice::openOutputStream( 35 AudioStreamOut **ppStreamOut, 36 audio_io_handle_t handle, 37 audio_devices_t devices, 38 audio_output_flags_t flags, 39 struct audio_config *config, 40 const char *address) 41{ 42 43 struct audio_config originalConfig = *config; 44 AudioStreamOut *outputStream = new AudioStreamOut(this, flags); 45 46 // Try to open the HAL first using the current format. 47 ALOGV("AudioHwDevice::openOutputStream(), try " 48 " sampleRate %d, Format %#x, " 49 "channelMask %#x", 50 config->sample_rate, 51 config->format, 52 config->channel_mask); 53 status_t status = outputStream->open(handle, devices, config, address); 54 55 if (status != NO_ERROR) { 56 delete outputStream; 57 outputStream = NULL; 58 59 // FIXME Look at any modification to the config. 60 // The HAL might modify the config to suggest a wrapped format. 61 // Log this so we can see what the HALs are doing. 62 ALOGI("AudioHwDevice::openOutputStream(), HAL returned" 63 " sampleRate %d, Format %#x, " 64 "channelMask %#x, status %d", 65 config->sample_rate, 66 config->format, 67 config->channel_mask, 68 status); 69 70 // If the data is encoded then try again using wrapped PCM. 71 bool wrapperNeeded = !audio_is_linear_pcm(originalConfig.format) 72 && ((flags & AUDIO_OUTPUT_FLAG_DIRECT) != 0) 73 && ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) == 0); 74 75 // FIXME - Add isEncodingSupported() query to SPDIF wrapper then 76 // call it from here. 77 if (wrapperNeeded) { 78 outputStream = new SpdifStreamOut(this, flags); 79 status = outputStream->open(handle, devices, &originalConfig, address); 80 if (status != NO_ERROR) { 81 ALOGE("ERROR - AudioHwDevice::openOutputStream(), SPDIF open returned %d", 82 status); 83 delete outputStream; 84 outputStream = NULL; 85 } 86 } 87 } 88 89 *ppStreamOut = outputStream; 90 return status; 91} 92 93 94}; // namespace android 95