Home | History | Annotate | Download | only in audiohal
      1 /*
      2  * Copyright (C) 2016 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 #ifndef ANDROID_HARDWARE_DEVICE_HAL_INTERFACE_H
     18 #define ANDROID_HARDWARE_DEVICE_HAL_INTERFACE_H
     19 
     20 #include <media/MicrophoneInfo.h>
     21 #include <system/audio.h>
     22 #include <utils/Errors.h>
     23 #include <utils/RefBase.h>
     24 #include <utils/String8.h>
     25 
     26 namespace android {
     27 
     28 class StreamInHalInterface;
     29 class StreamOutHalInterface;
     30 
     31 class DeviceHalInterface : public RefBase
     32 {
     33   public:
     34     // Sets the value of 'devices' to a bitmask of 1 or more values of audio_devices_t.
     35     virtual status_t getSupportedDevices(uint32_t *devices) = 0;
     36 
     37     // Check to see if the audio hardware interface has been initialized.
     38     virtual status_t initCheck() = 0;
     39 
     40     // Set the audio volume of a voice call. Range is between 0.0 and 1.0.
     41     virtual status_t setVoiceVolume(float volume) = 0;
     42 
     43     // Set the audio volume for all audio activities other than voice call.
     44     virtual status_t setMasterVolume(float volume) = 0;
     45 
     46     // Get the current master volume value for the HAL.
     47     virtual status_t getMasterVolume(float *volume) = 0;
     48 
     49     // Called when the audio mode changes.
     50     virtual status_t setMode(audio_mode_t mode) = 0;
     51 
     52     // Muting control.
     53     virtual status_t setMicMute(bool state) = 0;
     54     virtual status_t getMicMute(bool *state) = 0;
     55     virtual status_t setMasterMute(bool state) = 0;
     56     virtual status_t getMasterMute(bool *state) = 0;
     57 
     58     // Set global audio parameters.
     59     virtual status_t setParameters(const String8& kvPairs) = 0;
     60 
     61     // Get global audio parameters.
     62     virtual status_t getParameters(const String8& keys, String8 *values) = 0;
     63 
     64     // Returns audio input buffer size according to parameters passed.
     65     virtual status_t getInputBufferSize(const struct audio_config *config,
     66             size_t *size) = 0;
     67 
     68     // Creates and opens the audio hardware output stream. The stream is closed
     69     // by releasing all references to the returned object.
     70     virtual status_t openOutputStream(
     71             audio_io_handle_t handle,
     72             audio_devices_t devices,
     73             audio_output_flags_t flags,
     74             struct audio_config *config,
     75             const char *address,
     76             sp<StreamOutHalInterface> *outStream) = 0;
     77 
     78     // Creates and opens the audio hardware input stream. The stream is closed
     79     // by releasing all references to the returned object.
     80     virtual status_t openInputStream(
     81             audio_io_handle_t handle,
     82             audio_devices_t devices,
     83             struct audio_config *config,
     84             audio_input_flags_t flags,
     85             const char *address,
     86             audio_source_t source,
     87             sp<StreamInHalInterface> *inStream) = 0;
     88 
     89     // Returns whether createAudioPatch and releaseAudioPatch operations are supported.
     90     virtual status_t supportsAudioPatches(bool *supportsPatches) = 0;
     91 
     92     // Creates an audio patch between several source and sink ports.
     93     virtual status_t createAudioPatch(
     94             unsigned int num_sources,
     95             const struct audio_port_config *sources,
     96             unsigned int num_sinks,
     97             const struct audio_port_config *sinks,
     98             audio_patch_handle_t *patch) = 0;
     99 
    100     // Releases an audio patch.
    101     virtual status_t releaseAudioPatch(audio_patch_handle_t patch) = 0;
    102 
    103     // Fills the list of supported attributes for a given audio port.
    104     virtual status_t getAudioPort(struct audio_port *port) = 0;
    105 
    106     // Set audio port configuration.
    107     virtual status_t setAudioPortConfig(const struct audio_port_config *config) = 0;
    108 
    109     // List microphones
    110     virtual status_t getMicrophones(std::vector<media::MicrophoneInfo> *microphones) = 0;
    111 
    112     virtual status_t dump(int fd) = 0;
    113 
    114   protected:
    115     // Subclasses can not be constructed directly by clients.
    116     DeviceHalInterface() {}
    117 
    118     // The destructor automatically closes the device.
    119     virtual ~DeviceHalInterface() {}
    120 };
    121 
    122 } // namespace android
    123 
    124 #endif // ANDROID_HARDWARE_DEVICE_HAL_INTERFACE_H
    125