Home | History | Annotate | Download | only in include
      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 <system/audio.h>
     23 #include <utils/String8.h>
     24 
     25 namespace android {
     26 
     27 class SwAudioOutputDescriptor;
     28 
     29 /**
     30  * custom mix entry in mPolicyMixes
     31  */
     32 class AudioPolicyMix : public RefBase {
     33 public:
     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 
     46     status_t dump(int fd, int spaces, int index) const;
     47 
     48 private:
     49     AudioMix    mMix;                   // Audio policy mix descriptor
     50     sp<SwAudioOutputDescriptor> mOutput;  // Corresponding output stream
     51 };
     52 
     53 
     54 class AudioPolicyMixCollection : public DefaultKeyedVector<String8, sp<AudioPolicyMix> >
     55 {
     56 public:
     57     status_t getAudioPolicyMix(const String8& address, sp<AudioPolicyMix> &policyMix) const;
     58 
     59     status_t registerMix(const String8& address, AudioMix mix, sp<SwAudioOutputDescriptor> desc);
     60 
     61     status_t unregisterMix(const String8& address);
     62 
     63     void closeOutput(sp<SwAudioOutputDescriptor> &desc);
     64 
     65     /**
     66      * Try to find an output descriptor for the given attributes.
     67      *
     68      * @param[in] attributes to consider fowr the research of output descriptor.
     69      * @param[out] desc to return if an output could be found.
     70      *
     71      * @return NO_ERROR if an output was found for the given attribute (in this case, the
     72      *                  descriptor output param is initialized), error code otherwise.
     73      */
     74     status_t getOutputForAttr(audio_attributes_t attributes, uid_t uid,
     75             sp<SwAudioOutputDescriptor> &desc);
     76 
     77     audio_devices_t getDeviceAndMixForInputSource(audio_source_t inputSource,
     78                                                   audio_devices_t availableDeviceTypes,
     79                                                   AudioMix **policyMix);
     80 
     81     status_t getInputMixForAttr(audio_attributes_t attr, AudioMix **policyMix);
     82 
     83     status_t dump(int fd) const;
     84 };
     85 
     86 }; // namespace android
     87