Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0eb2f4aa authored by Eric Laurent's avatar Eric Laurent
Browse files

AudioPolicyInterface: add note on nullptr checks

Add note in AudioPolicyInterface.h specifying that nullptr checks on
input arguments are not needed in the implementation.

Also fix line lengths.

Bug: 136491767
Test: make
Change-Id: I214f5e7461758862055571bfbff575c91398f2e9
parent e5c3eb64
Loading
Loading
Loading
Loading
+59 −34
Original line number Diff line number Diff line
@@ -32,30 +32,42 @@ using content::AttributionSourceState;

// ----------------------------------------------------------------------------

// The AudioPolicyInterface and AudioPolicyClientInterface classes define the communication interfaces
// between the platform specific audio policy manager and Android generic audio policy manager.
// The platform specific audio policy manager must implement methods of the AudioPolicyInterface class.
// The AudioPolicyInterface and AudioPolicyClientInterface classes define the communication
// interfaces between the platform specific audio policy manager and Android generic audio policy
// manager.
// The platform specific audio policy manager must implement methods of the AudioPolicyInterface
// class.
// This implementation makes use of the AudioPolicyClientInterface to control the activity and
// configuration of audio input and output streams.
//
// The platform specific audio policy manager is in charge of the audio routing and volume control
// policies for a given platform.
// The main roles of this module are:
//   - keep track of current system state (removable device connections, phone state, user requests...).
//   System state changes and user actions are notified to audio policy manager with methods of the AudioPolicyInterface.
//   - keep track of current system state (removable device connections, phone state,
//   user requests...).
//   System state changes and user actions are notified to audio policy manager with methods of the
//   AudioPolicyInterface.
//   - process getOutput() queries received when AudioTrack objects are created: Those queries
//   return a handler on an output that has been selected, configured and opened by the audio policy manager and that
//   must be used by the AudioTrack when registering to the AudioFlinger with the createTrack() method.
//   When the AudioTrack object is released, a putOutput() query is received and the audio policy manager can decide
//   to close or reconfigure the output depending on other streams using this output and current system state.
//   - similarly process getInput() and putInput() queries received from AudioRecord objects and configure audio inputs.
//   - process volume control requests: the stream volume is converted from an index value (received from UI) to a float value
//   applicable to each output as a function of platform specific settings and current output route (destination device). It
//   also make sure that streams are not muted if not allowed (e.g. camera shutter sound in some countries).
//   return a handler on an output that has been selected, configured and opened by the audio
//   policy manager and that must be used by the AudioTrack when registering to the AudioFlinger
//   with the createTrack() method.
//   When the AudioTrack object is released, a putOutput() query is received and the audio policy
//   manager can decide to close or reconfigure the output depending on other streams using this
//   output and current system state.
//   - similarly process getInput() and putInput() queries received from AudioRecord objects and
//   configure audio inputs.
//   - process volume control requests: the stream volume is converted from an index value
//   (received from UI) to a float value applicable to each output as a function of platform
//   specificsettings and current output route (destination device). It also make sure that streams
//   are not muted if not allowed (e.g. camera shutter sound in some countries).
//
// The platform specific audio policy manager is provided as a shared library by platform vendors (as for libaudio.so)
// and is linked with libaudioflinger.so

// The platform specific audio policy manager is provided as a shared library by platform vendors
// (as for libaudio.so) and is linked with libaudioflinger.so
//
// NOTE: by convention, the implementation of the AudioPolicyInterface in AudioPolicyManager does
// not have to perform any nullptr check on input arguments: The caller of this API is
// AudioPolicyService running in the same process and in charge of validating arguments received
// from incoming binder calls before calling AudioPolicyManager.

//    Audio Policy Manager Interface
class AudioPolicyInterface
@@ -134,9 +146,11 @@ public:
                                        audio_port_handle_t *portId,
                                        std::vector<audio_io_handle_t> *secondaryOutputs,
                                        output_type_t *outputType) = 0;
    // indicates to the audio policy manager that the output starts being used by corresponding stream.
    // indicates to the audio policy manager that the output starts being used by corresponding
    // stream.
    virtual status_t startOutput(audio_port_handle_t portId) = 0;
    // indicates to the audio policy manager that the output stops being used by corresponding stream.
    // indicates to the audio policy manager that the output stops being used by corresponding
    // stream.
    virtual status_t stopOutput(audio_port_handle_t portId) = 0;
    // releases the output, return true if the output descriptor is reopened.
    virtual bool releaseOutput(audio_port_handle_t portId) = 0;
@@ -398,10 +412,13 @@ public:
    // Audio output Control functions
    //

    // opens an audio output with the requested parameters. The parameter values can indicate to use the default values
    // in case the audio policy manager has no specific requirements for the output being opened.
    // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream.
    // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly.
    // opens an audio output with the requested parameters. The parameter values can indicate to
    // use the default values in case the audio policy manager has no specific requirements for the
    // output being opened.
    // When the function returns, the parameter values reflect the actual values used by the audio
    // hardware output stream.
    // The audio policy manager can check if the proposed parameters are suitable or not and act
    // accordingly.
    virtual status_t openOutput(audio_module_handle_t module,
                                audio_io_handle_t *output,
                                audio_config_t *halConfig,
@@ -409,13 +426,15 @@ public:
                                const sp<DeviceDescriptorBase>& device,
                                uint32_t *latencyMs,
                                audio_output_flags_t flags) = 0;
    // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by
    // a special mixer thread in the AudioFlinger.
    virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2) = 0;
    // creates a special output that is duplicated to the two outputs passed as arguments.
    // The duplication is performed by a special mixer thread in the AudioFlinger.
    virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1,
                                                  audio_io_handle_t output2) = 0;
    // closes the output stream
    virtual status_t closeOutput(audio_io_handle_t output) = 0;
    // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in
    // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded.
    // suspends the output. When an output is suspended, the corresponding audio hardware output
    // stream is placed in standby and the AudioTracks attached to the mixer thread are still
    // processed but the output mix is discarded.
    virtual status_t suspendOutput(audio_io_handle_t output) = 0;
    // restores a suspended output.
    virtual status_t restoreOutput(audio_io_handle_t output) = 0;
@@ -438,16 +457,21 @@ public:
    // misc control functions
    //

    // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes
    // set a stream volume for a particular output. For the same user setting, a given stream type
    // can have different volumes
    // for each output (destination device) it is attached to.
    virtual status_t setStreamVolume(audio_stream_type_t stream, float volume, audio_io_handle_t output, int delayMs = 0) = 0;
    virtual status_t setStreamVolume(audio_stream_type_t stream, float volume,
                                     audio_io_handle_t output, int delayMs = 0) = 0;

    // invalidate a stream type, causing a reroute to an unspecified new output
    virtual status_t invalidateStream(audio_stream_type_t stream) = 0;

    // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface.
    virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0) = 0;
    // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager.
    // function enabling to send proprietary informations directly from audio policy manager to
    // audio hardware interface.
    virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs,
                               int delayMs = 0) = 0;
    // function enabling to receive proprietary informations directly from audio hardware interface
    // to audio policy manager.
    virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) = 0;

    // set down link audio volume.
@@ -510,7 +534,8 @@ public:
    // These are the signatures of createAudioPolicyManager/destroyAudioPolicyManager
    // methods respectively, expected by AudioPolicyService, needs to be exposed by
    // libaudiopolicymanagercustom.
    using CreateAudioPolicyManagerInstance = AudioPolicyInterface* (*)(AudioPolicyClientInterface*);
    using CreateAudioPolicyManagerInstance =
            AudioPolicyInterface* (*)(AudioPolicyClientInterface*);
    using DestroyAudioPolicyManagerInstance = void (*)(AudioPolicyInterface*);

} // namespace android