1/*
2 * Copyright (C) 2015 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 <utils/RefBase.h>
20#include <media/AudioPolicy.h>
21#include <utils/KeyedVector.h>
22#include <hardware/audio.h>
23#include <utils/String8.h>
24
25namespace android {
26
27class SwAudioOutputDescriptor;
28
29/**
30 * custom mix entry in mPolicyMixes
31 */
32class AudioPolicyMix : public RefBase {
33public:
34    AudioPolicyMix() {}
35
36    const sp<SwAudioOutputDescriptor> &getOutput() const;
37
38    void setOutput(sp<SwAudioOutputDescriptor> &output);
39
40    void clearOutput();
41
42    android::AudioMix *getMix();
43
44    void setMix(AudioMix &mix);
45
46private:
47    AudioMix    mMix;                   // Audio policy mix descriptor
48    sp<SwAudioOutputDescriptor> mOutput;  // Corresponding output stream
49};
50
51
52class AudioPolicyMixCollection : public DefaultKeyedVector<String8, sp<AudioPolicyMix> >
53{
54public:
55    status_t getAudioPolicyMix(String8 address, sp<AudioPolicyMix> &policyMix) const;
56
57    status_t registerMix(String8 address, AudioMix mix);
58
59    status_t unregisterMix(String8 address);
60
61    void closeOutput(sp<SwAudioOutputDescriptor> &desc);
62
63    /**
64     * Try to find an output descriptor for the given attributes.
65     *
66     * @param[in] attributes to consider fowr the research of output descriptor.
67     * @param[out] desc to return if an output could be found.
68     *
69     * @return NO_ERROR if an output was found for the given attribute (in this case, the
70     *                  descriptor output param is initialized), error code otherwise.
71     */
72    status_t getOutputForAttr(audio_attributes_t attributes, sp<SwAudioOutputDescriptor> &desc);
73
74    audio_devices_t getDeviceAndMixForInputSource(audio_source_t inputSource,
75                                                  audio_devices_t availableDeviceTypes,
76                                                  AudioMix **policyMix);
77
78    status_t getInputMixForAttr(audio_attributes_t attr, AudioMix **policyMix);
79};
80
81}; // namespace android
82