blob: 37414b3d75c39959edfbcb009ec6f8724877ea58 [file] [log] [blame]
Mikhail Naganovc337a872023-07-07 12:01:17 -07001/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <functional>
20#include <iostream>
21#include <memory>
22#include <optional>
23#include <vector>
24
25#include <aidl/android/media/audio/common/AudioChannelLayout.h>
26#include <aidl/android/media/audio/common/AudioFormatDescription.h>
27#include <aidl/android/media/audio/common/AudioPort.h>
28
29#include "core-impl/Stream.h"
30
31extern "C" {
32#include <tinyalsa/pcm.h>
33#include "alsa_device_profile.h"
34#include "alsa_device_proxy.h"
35}
36
37namespace aidl::android::hardware::audio::core::alsa {
38
39struct DeviceProfile {
40 int card;
41 int device;
42 int direction; /* PCM_OUT or PCM_IN */
Mikhail Naganov422f7e62023-07-13 16:32:08 -070043 bool isExternal;
Mikhail Naganovc337a872023-07-07 12:01:17 -070044};
45std::ostream& operator<<(std::ostream& os, const DeviceProfile& device);
46using DeviceProxyDeleter = std::function<void(alsa_device_proxy*)>;
47using DeviceProxy = std::unique_ptr<alsa_device_proxy, DeviceProxyDeleter>;
48
49::aidl::android::media::audio::common::AudioChannelLayout getChannelLayoutMaskFromChannelCount(
50 unsigned int channelCount, int isInput);
51::aidl::android::media::audio::common::AudioChannelLayout getChannelIndexMaskFromChannelCount(
52 unsigned int channelCount);
53unsigned int getChannelCountFromChannelMask(
54 const ::aidl::android::media::audio::common::AudioChannelLayout& channelMask, bool isInput);
55std::vector<::aidl::android::media::audio::common::AudioChannelLayout> getChannelMasksFromProfile(
56 const alsa_device_profile* profile);
57std::optional<DeviceProfile> getDeviceProfile(
58 const ::aidl::android::media::audio::common::AudioDevice& audioDevice, bool isInput);
59std::optional<DeviceProfile> getDeviceProfile(
60 const ::aidl::android::media::audio::common::AudioPort& audioPort);
61std::optional<struct pcm_config> getPcmConfig(const StreamContext& context, bool isInput);
62std::vector<int> getSampleRatesFromProfile(const alsa_device_profile* profile);
63DeviceProxy makeDeviceProxy();
Mikhail Naganov422f7e62023-07-13 16:32:08 -070064DeviceProxy openProxyForAttachedDevice(const DeviceProfile& deviceProfile,
65 struct pcm_config* pcmConfig, size_t bufferFrameCount);
66DeviceProxy openProxyForExternalDevice(const DeviceProfile& deviceProfile,
67 struct pcm_config* pcmConfig, bool requireExactMatch);
Mikhail Naganovc337a872023-07-07 12:01:17 -070068std::optional<alsa_device_profile> readAlsaDeviceInfo(const DeviceProfile& deviceProfile);
Mikhail Naganovcf824f62023-07-24 14:51:36 -070069void resetTransferredFrames(DeviceProxy& proxy, uint64_t frames);
Mikhail Naganovc337a872023-07-07 12:01:17 -070070
71::aidl::android::media::audio::common::AudioFormatDescription
72c2aidl_pcm_format_AudioFormatDescription(enum pcm_format legacy);
73pcm_format aidl2c_AudioFormatDescription_pcm_format(
74 const ::aidl::android::media::audio::common::AudioFormatDescription& aidl);
75
76} // namespace aidl::android::hardware::audio::core::alsa