1036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie/*
2036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie * Copyright (C) 2015 The Android Open Source Project
3036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie *
4036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie * Licensed under the Apache License, Version 2.0 (the "License");
5036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie * you may not use this file except in compliance with the License.
6036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie * You may obtain a copy of the License at
7036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie *
8036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie *      http://www.apache.org/licenses/LICENSE-2.0
9036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie *
10036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie * Unless required by applicable law or agreed to in writing, software
11036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie * distributed under the License is distributed on an "AS IS" BASIS,
12036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie * See the License for the specific language governing permissions and
14036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie * limitations under the License.
15036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie */
16036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
17036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie#pragma once
18036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
19036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie#include <utils/RefBase.h>
20036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie#include <media/AudioPolicy.h>
21036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie#include <utils/KeyedVector.h>
22cbc8f617c1aebef5d041fa40dcd38a5466690b99Mikhail Naganov#include <system/audio.h>
23036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie#include <utils/String8.h>
24036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
25036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffienamespace android {
26036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
27c75307b73d324d590d0dbc05b44bce9aa89b7145Eric Laurentclass SwAudioOutputDescriptor;
28036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
29036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie/**
30036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie * custom mix entry in mPolicyMixes
31036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie */
32036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffieclass AudioPolicyMix : public RefBase {
33036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffiepublic:
34036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie    AudioPolicyMix() {}
35036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
36c75307b73d324d590d0dbc05b44bce9aa89b7145Eric Laurent    const sp<SwAudioOutputDescriptor> &getOutput() const;
37036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
38c75307b73d324d590d0dbc05b44bce9aa89b7145Eric Laurent    void setOutput(sp<SwAudioOutputDescriptor> &output);
39036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
40036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie    void clearOutput();
41036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
42dacc06f5e8d00ace9d16a149fc41ff65323ffbb3Jean-Michel Trivi    android::AudioMix *getMix();
43036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
44036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie    void setMix(AudioMix &mix);
45036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
4644344b05261cb9ad46a43e635f637b89aecc7afeMikhail Naganov    status_t dump(int fd, int spaces, int index) const;
4744344b05261cb9ad46a43e635f637b89aecc7afeMikhail Naganov
48036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffieprivate:
49036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie    AudioMix    mMix;                   // Audio policy mix descriptor
50c75307b73d324d590d0dbc05b44bce9aa89b7145Eric Laurent    sp<SwAudioOutputDescriptor> mOutput;  // Corresponding output stream
51036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie};
52036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
53036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
54036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffieclass AudioPolicyMixCollection : public DefaultKeyedVector<String8, sp<AudioPolicyMix> >
55036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie{
56036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffiepublic:
57e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh    status_t getAudioPolicyMix(const String8& address, sp<AudioPolicyMix> &policyMix) const;
58036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
59e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh    status_t registerMix(const String8& address, AudioMix mix, sp<SwAudioOutputDescriptor> desc);
60036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
61e964d4e421e2d1ca937227a580c0c837091a11e3Chih-Hung Hsieh    status_t unregisterMix(const String8& address);
62036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
63c75307b73d324d590d0dbc05b44bce9aa89b7145Eric Laurent    void closeOutput(sp<SwAudioOutputDescriptor> &desc);
64036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
65036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie    /**
66036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie     * Try to find an output descriptor for the given attributes.
67036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie     *
68c75307b73d324d590d0dbc05b44bce9aa89b7145Eric Laurent     * @param[in] attributes to consider fowr the research of output descriptor.
69036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie     * @param[out] desc to return if an output could be found.
70036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie     *
71036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie     * @return NO_ERROR if an output was found for the given attribute (in this case, the
72036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie     *                  descriptor output param is initialized), error code otherwise.
73036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie     */
74e8decedb429ed76dfa84cdb3e80ab3b969e77298Jean-Michel Trivi    status_t getOutputForAttr(audio_attributes_t attributes, uid_t uid,
75e8decedb429ed76dfa84cdb3e80ab3b969e77298Jean-Michel Trivi            sp<SwAudioOutputDescriptor> &desc);
76036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
77036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie    audio_devices_t getDeviceAndMixForInputSource(audio_source_t inputSource,
78036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie                                                  audio_devices_t availableDeviceTypes,
79036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie                                                  AudioMix **policyMix);
80036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
81dacc06f5e8d00ace9d16a149fc41ff65323ffbb3Jean-Michel Trivi    status_t getInputMixForAttr(audio_attributes_t attr, AudioMix **policyMix);
8244344b05261cb9ad46a43e635f637b89aecc7afeMikhail Naganov
8344344b05261cb9ad46a43e635f637b89aecc7afeMikhail Naganov    status_t dump(int fd) const;
84036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie};
85036e1e9126dcd496203434aa69e52115d8e730ccFrançois Gaffie
861b2a794a27caab3a1320d22b872b04ef73e96555Mikhail Naganov} // namespace android
87