blob: 16b25f6828e2b9e7b875eb2e50885ed251057ee2 [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
32// ----------------------------------------------------------------------------
33
34status_t AudioHwDevice::openOutputStream(
35 AudioStreamOut **ppStreamOut,
36 audio_io_handle_t handle,
jiabin43810402019-10-24 14:58:31 -070037 audio_devices_t deviceType,
Phil Burk062e67a2015-02-11 13:40:50 -080038 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.
Phil Burk23d89972015-04-06 16:22:23 -070047 ALOGV("openOutputStream(), try "
Phil Burk062e67a2015-02-11 13:40:50 -080048 " sampleRate %d, Format %#x, "
49 "channelMask %#x",
50 config->sample_rate,
51 config->format,
52 config->channel_mask);
jiabin43810402019-10-24 14:58:31 -070053 status_t status = outputStream->open(handle, deviceType, config, address);
Phil Burk062e67a2015-02-11 13:40:50 -080054
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.
Phil Burk23d89972015-04-06 16:22:23 -070062 ALOGI("openOutputStream(), HAL returned"
Phil Burk062e67a2015-02-11 13:40:50 -080063 " 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.
Phil Burkfdb3c072016-02-09 10:47:02 -080071 bool wrapperNeeded = !audio_has_proportional_frames(originalConfig.format)
Phil Burk062e67a2015-02-11 13:40:50 -080072 && ((flags & AUDIO_OUTPUT_FLAG_DIRECT) != 0)
73 && ((flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) == 0);
74
Phil Burk062e67a2015-02-11 13:40:50 -080075 if (wrapperNeeded) {
Phil Burk23d89972015-04-06 16:22:23 -070076 if (SPDIFEncoder::isFormatSupported(originalConfig.format)) {
77 outputStream = new SpdifStreamOut(this, flags, originalConfig.format);
jiabin43810402019-10-24 14:58:31 -070078 status = outputStream->open(handle, deviceType, &originalConfig, address);
Phil Burk23d89972015-04-06 16:22:23 -070079 if (status != NO_ERROR) {
80 ALOGE("ERROR - openOutputStream(), SPDIF open returned %d",
81 status);
82 delete outputStream;
83 outputStream = NULL;
84 }
85 } else {
86 ALOGE("ERROR - openOutputStream(), SPDIFEncoder does not support format 0x%08x",
87 originalConfig.format);
Phil Burk062e67a2015-02-11 13:40:50 -080088 }
89 }
90 }
91
92 *ppStreamOut = outputStream;
93 return status;
94}
95
Mikhail Naganov9ee05402016-10-13 15:58:17 -070096bool AudioHwDevice::supportsAudioPatches() const {
97 bool result;
98 return mHwDevice->supportsAudioPatches(&result) == OK ? result : false;
Mikhail Naganove4f1f632016-08-31 11:35:10 -070099}
Phil Burk062e67a2015-02-11 13:40:50 -0800100
jiabinb4fed192020-09-22 14:45:40 -0700101status_t AudioHwDevice::getAudioPort(struct audio_port_v7 *port) const {
102 return mHwDevice->getAudioPort(port);
103}
104
Mikhail Naganov9ee05402016-10-13 15:58:17 -0700105
Phil Burk062e67a2015-02-11 13:40:50 -0800106}; // namespace android