blob: 12f8272d7d486289107e5f13797c947bb1f41e3a [file] [log] [blame]
Phil Burk062e67a2015-02-11 13:40:50 -08001/*
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
Mikhail Naganovcbc8f612016-10-11 18:05:13 -070021#include <system/audio.h>
Phil Burk062e67a2015-02-11 13:40:50 -080022#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
jiabine99d0882021-09-17 05:21:25 +000032using media::audio::common::AudioMMapPolicyInfo;
33using media::audio::common::AudioMMapPolicyType;
34
Phil Burk062e67a2015-02-11 13:40:50 -080035// ----------------------------------------------------------------------------
36
37status_t AudioHwDevice::openOutputStream(
38 AudioStreamOut **ppStreamOut,
39 audio_io_handle_t handle,
jiabin43810402019-10-24 14:58:31 -070040 audio_devices_t deviceType,
Phil Burk062e67a2015-02-11 13:40:50 -080041 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.
Phil Burk23d89972015-04-06 16:22:23 -070050 ALOGV("openOutputStream(), try "
Phil Burk062e67a2015-02-11 13:40:50 -080051 " sampleRate %d, Format %#x, "
52 "channelMask %#x",
53 config->sample_rate,
54 config->format,
55 config->channel_mask);
jiabin43810402019-10-24 14:58:31 -070056 status_t status = outputStream->open(handle, deviceType, config, address);
Phil Burk062e67a2015-02-11 13:40:50 -080057
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.
Phil Burk23d89972015-04-06 16:22:23 -070065 ALOGI("openOutputStream(), HAL returned"
Phil Burk062e67a2015-02-11 13:40:50 -080066 " 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.
Phil Burkfdb3c072016-02-09 10:47:02 -080074 bool wrapperNeeded = !audio_has_proportional_frames(originalConfig.format)
Phil Burk062e67a2015-02-11 13:40:50 -080075 && ((flags & AUDIO_OUTPUT_FLAG_DIRECT) != 0)
76 && ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) == 0);
77
Phil Burk062e67a2015-02-11 13:40:50 -080078 if (wrapperNeeded) {
Phil Burk23d89972015-04-06 16:22:23 -070079 if (SPDIFEncoder::isFormatSupported(originalConfig.format)) {
80 outputStream = new SpdifStreamOut(this, flags, originalConfig.format);
jiabin43810402019-10-24 14:58:31 -070081 status = outputStream->open(handle, deviceType, &originalConfig, address);
Phil Burk23d89972015-04-06 16:22:23 -070082 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);
Phil Burk062e67a2015-02-11 13:40:50 -080091 }
92 }
93 }
94
95 *ppStreamOut = outputStream;
96 return status;
97}
98
Mikhail Naganov9ee05402016-10-13 15:58:17 -070099bool AudioHwDevice::supportsAudioPatches() const {
100 bool result;
101 return mHwDevice->supportsAudioPatches(&result) == OK ? result : false;
Mikhail Naganove4f1f632016-08-31 11:35:10 -0700102}
Phil Burk062e67a2015-02-11 13:40:50 -0800103
jiabinb4fed192020-09-22 14:45:40 -0700104status_t AudioHwDevice::getAudioPort(struct audio_port_v7 *port) const {
105 return mHwDevice->getAudioPort(port);
106}
107
Jiabin Huangebe64102021-09-07 20:01:07 +0000108status_t AudioHwDevice::getMmapPolicyInfos(
jiabine99d0882021-09-17 05:21:25 +0000109 AudioMMapPolicyType policyType, std::vector<AudioMMapPolicyInfo> *policyInfos) const {
Jiabin Huangebe64102021-09-07 20:01:07 +0000110 return mHwDevice->getMmapPolicyInfos(policyType, policyInfos);
111}
112
113
Phil Burk062e67a2015-02-11 13:40:50 -0800114}; // namespace android