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 "DeviceDescriptor.h"
     20 #include "AudioRoute.h"
     21 #include <utils/RefBase.h>
     22 #include <utils/String8.h>
     23 #include <utils/Errors.h>
     24 #include <utils/Vector.h>
     25 #include <system/audio.h>
     26 #include <cutils/config_utils.h>
     27 #include <string>
     28 
     29 namespace android {
     30 
     31 class IOProfile;
     32 class InputProfile;
     33 class OutputProfile;
     34 
     35 typedef Vector<sp<IOProfile> > InputProfileCollection;
     36 typedef Vector<sp<IOProfile> > OutputProfileCollection;
     37 typedef Vector<sp<IOProfile> > IOProfileCollection;
     38 
     39 class HwModule : public RefBase
     40 {
     41 public:
     42     explicit HwModule(const char *name, uint32_t halVersionMajor = 0, uint32_t halVersionMinor = 0);
     43     ~HwModule();
     44 
     45     const char *getName() const { return mName.string(); }
     46 
     47 
     48     const DeviceVector &getDeclaredDevices() const { return mDeclaredDevices; }
     49     void setDeclaredDevices(const DeviceVector &devices);
     50 
     51     const InputProfileCollection &getInputProfiles() const { return mInputProfiles; }
     52 
     53     const OutputProfileCollection &getOutputProfiles() const { return mOutputProfiles; }
     54 
     55     void setProfiles(const IOProfileCollection &profiles);
     56 
     57     void setHalVersion(uint32_t major, uint32_t minor) {
     58         mHalVersion = (major << 8) | (minor & 0xff);
     59     }
     60     uint32_t getHalVersionMajor() const { return mHalVersion >> 8; }
     61     uint32_t getHalVersionMinor() const { return mHalVersion & 0xff; }
     62 
     63     sp<DeviceDescriptor> getRouteSinkDevice(const sp<AudioRoute> &route) const;
     64     DeviceVector getRouteSourceDevices(const sp<AudioRoute> &route) const;
     65     void setRoutes(const AudioRouteVector &routes);
     66 
     67     status_t addOutputProfile(const sp<IOProfile> &profile);
     68     status_t addInputProfile(const sp<IOProfile> &profile);
     69     status_t addProfile(const sp<IOProfile> &profile);
     70 
     71     status_t addOutputProfile(const String8& name, const audio_config_t *config,
     72             audio_devices_t device, const String8& address);
     73     status_t removeOutputProfile(const String8& name);
     74     status_t addInputProfile(const String8& name, const audio_config_t *config,
     75             audio_devices_t device, const String8& address);
     76     status_t removeInputProfile(const String8& name);
     77 
     78     audio_module_handle_t getHandle() const { return mHandle; }
     79 
     80     sp<AudioPort> findPortByTagName(const String8 &tagName) const
     81     {
     82         return mPorts.findByTagName(tagName);
     83     }
     84 
     85     // TODO remove from here (split serialization)
     86     void dump(int fd);
     87 
     88     const String8 mName; // base name of the audio HW module (primary, a2dp ...)
     89     audio_module_handle_t mHandle;
     90     OutputProfileCollection mOutputProfiles; // output profiles exposed by this module
     91     InputProfileCollection mInputProfiles;  // input profiles exposed by this module
     92 
     93 private:
     94     void refreshSupportedDevices();
     95 
     96     uint32_t mHalVersion; // audio HAL API version
     97     DeviceVector mDeclaredDevices; // devices declared in audio_policy configuration file.
     98     AudioRouteVector mRoutes;
     99     AudioPortVector mPorts;
    100 };
    101 
    102 class HwModuleCollection : public Vector<sp<HwModule> >
    103 {
    104 public:
    105     sp<HwModule> getModuleFromName(const char *name) const;
    106 
    107     sp<HwModule> getModuleForDevice(audio_devices_t device) const;
    108 
    109     sp<DeviceDescriptor> getDeviceDescriptor(const audio_devices_t device,
    110                                              const char *device_address,
    111                                              const char *device_name,
    112                                              bool matchAdress = true) const;
    113 
    114     status_t dump(int fd) const;
    115 };
    116 
    117 }; // namespace android
    118