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 <system/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
30 namespace android {
31
32 using media::audio::common::AudioMMapPolicyInfo;
33 using media::audio::common::AudioMMapPolicyType;
34
35 // ----------------------------------------------------------------------------
36
openOutputStream(AudioStreamOut ** ppStreamOut,audio_io_handle_t handle,audio_devices_t deviceType,audio_output_flags_t flags,struct audio_config * config,const char * address)37 status_t AudioHwDevice::openOutputStream(
38 AudioStreamOut **ppStreamOut,
39 audio_io_handle_t handle,
40 audio_devices_t deviceType,
41 audio_output_flags_t flags,
42 struct audio_config *config,
43 const char *address)
44 {
45
46 struct audio_config originalConfig = *config;
47 AudioStreamOut *outputStream = new AudioStreamOut(this, flags);
48
49 // Try to open the HAL first using the current format.
50 ALOGV("openOutputStream(), try "
51 " sampleRate %d, Format %#x, "
52 "channelMask %#x",
53 config->sample_rate,
54 config->format,
55 config->channel_mask);
56 status_t status = outputStream->open(handle, deviceType, config, address);
57
58 if (status != NO_ERROR) {
59 delete outputStream;
60 outputStream = NULL;
61
62 // FIXME Look at any modification to the config.
63 // The HAL might modify the config to suggest a wrapped format.
64 // Log this so we can see what the HALs are doing.
65 ALOGI("openOutputStream(), HAL returned"
66 " sampleRate %d, Format %#x, "
67 "channelMask %#x, status %d",
68 config->sample_rate,
69 config->format,
70 config->channel_mask,
71 status);
72
73 // If the data is encoded then try again using wrapped PCM.
74 bool wrapperNeeded = !audio_has_proportional_frames(originalConfig.format)
75 && ((flags & AUDIO_OUTPUT_FLAG_DIRECT) != 0)
76 && ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) == 0);
77
78 if (wrapperNeeded) {
79 if (SPDIFEncoder::isFormatSupported(originalConfig.format)) {
80 outputStream = new SpdifStreamOut(this, flags, originalConfig.format);
81 status = outputStream->open(handle, deviceType, &originalConfig, address);
82 if (status != NO_ERROR) {
83 ALOGE("ERROR - openOutputStream(), SPDIF open returned %d",
84 status);
85 delete outputStream;
86 outputStream = NULL;
87 }
88 } else {
89 ALOGE("ERROR - openOutputStream(), SPDIFEncoder does not support format 0x%08x",
90 originalConfig.format);
91 }
92 }
93 }
94
95 *ppStreamOut = outputStream;
96 return status;
97 }
98
supportsAudioPatches() const99 bool AudioHwDevice::supportsAudioPatches() const {
100 bool result;
101 return mHwDevice->supportsAudioPatches(&result) == OK ? result : false;
102 }
103
getAudioPort(struct audio_port_v7 * port) const104 status_t AudioHwDevice::getAudioPort(struct audio_port_v7 *port) const {
105 return mHwDevice->getAudioPort(port);
106 }
107
getMmapPolicyInfos(AudioMMapPolicyType policyType,std::vector<AudioMMapPolicyInfo> * policyInfos) const108 status_t AudioHwDevice::getMmapPolicyInfos(
109 AudioMMapPolicyType policyType, std::vector<AudioMMapPolicyInfo> *policyInfos) const {
110 return mHwDevice->getMmapPolicyInfos(policyType, policyInfos);
111 }
112
getAAudioMixerBurstCount() const113 int32_t AudioHwDevice::getAAudioMixerBurstCount() const {
114 return mHwDevice->getAAudioMixerBurstCount();
115 }
116
getAAudioHardwareBurstMinUsec() const117 int32_t AudioHwDevice::getAAudioHardwareBurstMinUsec() const {
118 return mHwDevice->getAAudioHardwareBurstMinUsec();
119 }
120
121
122 }; // namespace android
123