summaryrefslogtreecommitdiffstats
path: root/services/audiopolicy/managerdefault/Ports.h
blob: 6e0e2feb343246cca871baace9747be86be4f8fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 * Copyright (C) 2015 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.
 */

#pragma once

#include <utils/String8.h>
#include <utils/Vector.h>
#include <utils/RefBase.h>
#include <utils/Errors.h>
#include <system/audio.h>
#include <cutils/config_utils.h>

#define MAX_MIXER_SAMPLING_RATE 48000
#define MAX_MIXER_CHANNEL_COUNT 8

namespace android {

class HwModule;
class AudioGain;

class AudioPort: public virtual RefBase
{
public:
    AudioPort(const String8& name, audio_port_type_t type,
            audio_port_role_t role, const sp<HwModule>& module);
    virtual ~AudioPort() {}

    audio_port_handle_t getHandle() { return mId; }

    void attach(const sp<HwModule>& module);
    bool isAttached() { return mId != 0; }

    virtual void toAudioPort(struct audio_port *port) const;

    void importAudioPort(const sp<AudioPort> port);
    void clearCapabilities();

    void loadSamplingRates(char *name);
    void loadFormats(char *name);
    void loadOutChannels(char *name);
    void loadInChannels(char *name);

    audio_gain_mode_t loadGainMode(char *name);
    void loadGain(cnode *root, int index);
    virtual void loadGains(cnode *root);

    // searches for an exact match
    status_t checkExactSamplingRate(uint32_t samplingRate) const;
    // searches for a compatible match, and returns the best match via updatedSamplingRate
    status_t checkCompatibleSamplingRate(uint32_t samplingRate,
            uint32_t *updatedSamplingRate) const;
    // searches for an exact match
    status_t checkExactChannelMask(audio_channel_mask_t channelMask) const;
    // searches for a compatible match, currently implemented for input channel masks only
    status_t checkCompatibleChannelMask(audio_channel_mask_t channelMask) const;
    status_t checkFormat(audio_format_t format) const;
    status_t checkGain(const struct audio_gain_config *gainConfig, int index) const;

    uint32_t pickSamplingRate() const;
    audio_channel_mask_t pickChannelMask() const;
    audio_format_t pickFormat() const;

    static const audio_format_t sPcmFormatCompareTable[];
    static int compareFormats(audio_format_t format1, audio_format_t format2);

    void dump(int fd, int spaces) const;

    String8           mName;
    audio_port_type_t mType;
    audio_port_role_t mRole;
    bool              mUseInChannelMask;
    // by convention, "0' in the first entry in mSamplingRates, mChannelMasks or mFormats
    // indicates the supported parameters should be read from the output stream
    // after it is opened for the first time
    Vector <uint32_t> mSamplingRates; // supported sampling rates
    Vector <audio_channel_mask_t> mChannelMasks; // supported channel masks
    Vector <audio_format_t> mFormats; // supported audio formats
    Vector < sp<AudioGain> > mGains; // gain controllers
    sp<HwModule> mModule;                 // audio HW module exposing this I/O stream
    uint32_t mFlags; // attribute flags (e.g primary output,
                     // direct output...).


protected:
    //TODO - clarify the role of mId in this case, both an "attached" indicator
    // and a unique ID for identifying a port to the (upcoming) selection API,
    // and its relationship to the mId in AudioOutputDescriptor and AudioInputDescriptor.
    audio_port_handle_t mId;

private:
    static volatile int32_t mNextUniqueId;
};

class AudioPortConfig: public virtual RefBase
{
public:
    AudioPortConfig();
    virtual ~AudioPortConfig() {}

    status_t applyAudioPortConfig(const struct audio_port_config *config,
            struct audio_port_config *backupConfig = NULL);
    virtual void toAudioPortConfig(struct audio_port_config *dstConfig,
            const struct audio_port_config *srcConfig = NULL) const = 0;
    virtual sp<AudioPort> getAudioPort() const = 0;
    uint32_t mSamplingRate;
    audio_format_t mFormat;
    audio_channel_mask_t mChannelMask;
    struct audio_gain_config mGain;
};


class AudioPatch: public RefBase
{
public:
    AudioPatch(audio_patch_handle_t handle, const struct audio_patch *patch, uid_t uid);

    status_t dump(int fd, int spaces, int index) const;

    audio_patch_handle_t mHandle;
    struct audio_patch mPatch;
    uid_t mUid;
    audio_patch_handle_t mAfPatchHandle;
};

}; // namespace android