Files
hardware_interfaces/audio/aidl/default/alsa/ModuleAlsa.cpp
Mikhail Naganov a4513dcf05 audio: Move tinyALSA-specific code to Module/StreamAlsa
Extract code interacting with tinyALSA which is not
specific to USB into "abstract" module and stream
implementations ModuleAlsa and StreamAlsa. Also, move
utility code which does not need module or stream
context into Utils.

This facilitates implementation of the CF core HAL which
also uses tinyALSA, allowing to share common code.

Bug: 264712385
Test: atest VtsHalAudioCoreTargetTest

Change-Id: I2134b15e970c78e8a48b254e15199b8207a8ab34
(cherry picked from commit c337a8799b)
Merged-In: I2134b15e970c78e8a48b254e15199b8207a8ab34
2023-08-01 14:27:28 -07:00

68 lines
2.5 KiB
C++

/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define LOG_TAG "AHAL_ModuleAlsa"
#include <vector>
#include <android-base/logging.h>
#include "Utils.h"
#include "core-impl/ModuleAlsa.h"
extern "C" {
#include "alsa_device_profile.h"
}
using aidl::android::media::audio::common::AudioChannelLayout;
using aidl::android::media::audio::common::AudioFormatType;
using aidl::android::media::audio::common::AudioPort;
using aidl::android::media::audio::common::AudioProfile;
namespace aidl::android::hardware::audio::core {
ndk::ScopedAStatus ModuleAlsa::populateConnectedDevicePort(AudioPort* audioPort) {
auto deviceProfile = alsa::getDeviceProfile(*audioPort);
if (!deviceProfile.has_value()) {
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
}
auto profile = alsa::readAlsaDeviceInfo(*deviceProfile);
if (!profile.has_value()) {
return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
}
std::vector<AudioChannelLayout> channels = alsa::getChannelMasksFromProfile(&profile.value());
std::vector<int> sampleRates = alsa::getSampleRatesFromProfile(&profile.value());
for (size_t i = 0; i < std::min(MAX_PROFILE_FORMATS, AUDIO_PORT_MAX_AUDIO_PROFILES) &&
profile->formats[i] != PCM_FORMAT_INVALID;
++i) {
auto audioFormatDescription =
alsa::c2aidl_pcm_format_AudioFormatDescription(profile->formats[i]);
if (audioFormatDescription.type == AudioFormatType::DEFAULT) {
LOG(WARNING) << __func__ << ": unknown pcm type=" << profile->formats[i];
continue;
}
AudioProfile audioProfile = {.format = audioFormatDescription,
.channelMasks = channels,
.sampleRates = sampleRates};
audioPort->profiles.push_back(std::move(audioProfile));
}
return ndk::ScopedAStatus::ok();
}
} // namespace aidl::android::hardware::audio::core