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

Commit fa2877b9 authored by Eric Laurent's avatar Eric Laurent
Browse files

Fix issue 2001214: AudioFlinger and AudioPolicyService interfaces should not...

Fix issue 2001214: AudioFlinger and AudioPolicyService interfaces should not use pointers as handles to inputs and outputs.

Use integers instead of void* as input/output handles at IAudioFlinger and IAudioPolicyService interfaces.
AudioFlinger maintains an always increasing count of opened inputs or outputs as unique ID.
parent 285ead29
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
namespace android {

typedef void (*audio_error_callback)(status_t err);
typedef void * audio_io_handle_t;
typedef int audio_io_handle_t;

class IAudioPolicyService;
class String8;
@@ -184,8 +184,8 @@ public:
    static status_t getMasterMute(bool* mute);

    // set/get stream volume on specified output
    static status_t setStreamVolume(int stream, float value, void *output);
    static status_t getStreamVolume(int stream, float* volume, void *output);
    static status_t setStreamVolume(int stream, float value, int output);
    static status_t getStreamVolume(int stream, float* volume, int output);

    // mute/unmute stream
    static status_t setStreamMute(int stream, bool mute);
@@ -383,7 +383,7 @@ private:

        // indicate a change in the configuration of an output or input: keeps the cached
        // values for output/input parameters upto date in client process
        virtual void ioConfigChanged(int event, void *param1, void *param2);
        virtual void ioConfigChanged(int event, int ioHandle, void *param2);
    };

    class AudioPolicyServiceClient: public IBinder::DeathRecipient
+19 −19
Original line number Diff line number Diff line
@@ -50,12 +50,12 @@ public:
                                int frameCount,
                                uint32_t flags,
                                const sp<IMemory>& sharedBuffer,
                                void *output,
                                int output,
                                status_t *status) = 0;

    virtual sp<IAudioRecord> openRecord(
                                pid_t pid,
                                void *input,
                                int input,
                                uint32_t sampleRate,
                                int format,
                                int channelCount,
@@ -66,11 +66,11 @@ public:
    /* query the audio hardware state. This state never changes,
     * and therefore can be cached.
     */
    virtual     uint32_t    sampleRate(void *output) const = 0;
    virtual     int         channelCount(void *output) const = 0;
    virtual     int         format(void *output) const = 0;
    virtual     size_t      frameCount(void *output) const = 0;
    virtual     uint32_t    latency(void *output) const = 0;
    virtual     uint32_t    sampleRate(int output) const = 0;
    virtual     int         channelCount(int output) const = 0;
    virtual     int         format(int output) const = 0;
    virtual     size_t      frameCount(int output) const = 0;
    virtual     uint32_t    latency(int output) const = 0;

    /* set/get the audio hardware state. This will probably be used by
     * the preference panel, mostly.
@@ -84,10 +84,10 @@ public:
    /* set/get stream type state. This will probably be used by
     * the preference panel, mostly.
     */
    virtual     status_t    setStreamVolume(int stream, float value, void *output) = 0;
    virtual     status_t    setStreamVolume(int stream, float value, int output) = 0;
    virtual     status_t    setStreamMute(int stream, bool muted) = 0;

    virtual     float       streamVolume(int stream, void *output) const = 0;
    virtual     float       streamVolume(int stream, int output) const = 0;
    virtual     bool        streamMute(int stream) const = 0;

    // set audio mode
@@ -100,8 +100,8 @@ public:
    // is a music stream active?
    virtual     bool        isMusicActive() const = 0;

    virtual     status_t    setParameters(void *ioHandle, const String8& keyValuePairs) = 0;
    virtual     String8     getParameters(void *ioHandle, const String8& keys) = 0;
    virtual     status_t    setParameters(int ioHandle, const String8& keyValuePairs) = 0;
    virtual     String8     getParameters(int ioHandle, const String8& keys) = 0;
    
    // register a current process for audio output change notifications
    virtual void registerClient(const sp<IAudioFlingerClient>& client) = 0;
@@ -109,25 +109,25 @@ public:
    // retrieve the audio recording buffer size
    virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount) = 0;

    virtual void *openOutput(uint32_t *pDevices,
    virtual int openOutput(uint32_t *pDevices,
                                    uint32_t *pSamplingRate,
                                    uint32_t *pFormat,
                                    uint32_t *pChannels,
                                    uint32_t *pLatencyMs,
                                    uint32_t flags) = 0;
    virtual void *openDuplicateOutput(void *output1, void *output2) = 0;
    virtual status_t closeOutput(void *output) = 0;
    virtual status_t suspendOutput(void *output) = 0;
    virtual status_t restoreOutput(void *output) = 0;
    virtual int openDuplicateOutput(int output1, int output2) = 0;
    virtual status_t closeOutput(int output) = 0;
    virtual status_t suspendOutput(int output) = 0;
    virtual status_t restoreOutput(int output) = 0;

    virtual void *openInput(uint32_t *pDevices,
    virtual int openInput(uint32_t *pDevices,
                                    uint32_t *pSamplingRate,
                                    uint32_t *pFormat,
                                    uint32_t *pChannels,
                                    uint32_t acoustics) = 0;
    virtual status_t closeInput(void *input) = 0;
    virtual status_t closeInput(int input) = 0;

    virtual status_t setStreamOutput(uint32_t stream, void *output) = 0;
    virtual status_t setStreamOutput(uint32_t stream, int output) = 0;
};


+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ public:
    DECLARE_META_INTERFACE(AudioFlingerClient);

    // Notifies a change of audio input/output configuration.
    virtual void ioConfigChanged(int event, void *param1, void *param2) = 0;
    virtual void ioConfigChanged(int event, int ioHandle, void *param2) = 0;

};

+19 −20
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ status_t AudioSystem::getMasterMute(bool* mute)
    return NO_ERROR;
}

status_t AudioSystem::setStreamVolume(int stream, float value, void *output)
status_t AudioSystem::setStreamVolume(int stream, float value, int output)
{
    if (uint32_t(stream) >= NUM_STREAM_TYPES) return BAD_VALUE;
    const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
@@ -143,7 +143,7 @@ status_t AudioSystem::setStreamMute(int stream, bool mute)
    return NO_ERROR;
}

status_t AudioSystem::getStreamVolume(int stream, float* volume, void *output)
status_t AudioSystem::getStreamVolume(int stream, float* volume, int output)
{
    if (uint32_t(stream) >= NUM_STREAM_TYPES) return BAD_VALUE;
    const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
@@ -234,7 +234,7 @@ status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType)
    gLock.lock();
    outputDesc = AudioSystem::gOutputs.valueFor(output);
    if (outputDesc == 0) {
        LOGV("getOutputSamplingRate() no output descriptor for output %p in gOutputs", output);
        LOGV("getOutputSamplingRate() no output descriptor for output %d in gOutputs", output);
        gLock.unlock();
        const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
        if (af == 0) return PERMISSION_DENIED;
@@ -245,7 +245,7 @@ status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType)
        gLock.unlock();
    }

    LOGV("getOutputSamplingRate() streamType %d, output %p, sampling rate %d", streamType, output, *samplingRate);
    LOGV("getOutputSamplingRate() streamType %d, output %d, sampling rate %d", streamType, output, *samplingRate);

    return NO_ERROR;
}
@@ -276,7 +276,7 @@ status_t AudioSystem::getOutputFrameCount(int* frameCount, int streamType)
        gLock.unlock();
    }

    LOGV("getOutputFrameCount() streamType %d, output %p, frameCount %d", streamType, output, *frameCount);
    LOGV("getOutputFrameCount() streamType %d, output %d, frameCount %d", streamType, output, *frameCount);

    return NO_ERROR;
}
@@ -307,7 +307,7 @@ status_t AudioSystem::getOutputLatency(uint32_t* latency, int streamType)
        gLock.unlock();
    }

    LOGV("getOutputLatency() streamType %d, output %p, latency %d", streamType, output, *latency);
    LOGV("getOutputLatency() streamType %d, output %d, latency %d", streamType, output, *latency);

    return NO_ERROR;
}
@@ -348,13 +348,12 @@ void AudioSystem::AudioFlingerClient::binderDied(const wp<IBinder>& who) {
    LOGW("AudioFlinger server died!");
}

void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, void *param1, void *param2) {
void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, int ioHandle, void *param2) {
    LOGV("ioConfigChanged() event %d", event);
    audio_io_handle_t ioHandle = (audio_io_handle_t)param1;
    OutputDescriptor *desc;
    uint32_t stream;

    if (param1 == 0) return;
    if (ioHandle == 0) return;

    Mutex::Autolock _l(AudioSystem::gLock);

@@ -362,14 +361,14 @@ void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, void *param1, v
    case STREAM_CONFIG_CHANGED:
        if (param2 == 0) break;
        stream = *(uint32_t *)param2;
        LOGV("ioConfigChanged() STREAM_CONFIG_CHANGED stream %d, output %p", stream, ioHandle);
        LOGV("ioConfigChanged() STREAM_CONFIG_CHANGED stream %d, output %d", stream, ioHandle);
        if (gStreamOutputMap.indexOfKey(stream) >= 0) {
            gStreamOutputMap.replaceValueFor(stream, ioHandle);
        }
        break;
    case OUTPUT_OPENED: {
        if (gOutputs.indexOfKey(ioHandle) >= 0) {
            LOGV("ioConfigChanged() opening already existing output! %p", ioHandle);
            LOGV("ioConfigChanged() opening already existing output! %d", ioHandle);
            break;
        }
        if (param2 == 0) break;
@@ -382,10 +381,10 @@ void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, void *param1, v
        } break;
    case OUTPUT_CLOSED: {
        if (gOutputs.indexOfKey(ioHandle) < 0) {
            LOGW("ioConfigChanged() closing unknow output! %p", ioHandle);
            LOGW("ioConfigChanged() closing unknow output! %d", ioHandle);
            break;
        }
        LOGV("ioConfigChanged() output %p closed", ioHandle);
        LOGV("ioConfigChanged() output %d closed", ioHandle);

        gOutputs.removeItem(ioHandle);
        for (int i = gStreamOutputMap.size() - 1; i >= 0 ; i--) {
@@ -398,13 +397,13 @@ void AudioSystem::AudioFlingerClient::ioConfigChanged(int event, void *param1, v
    case OUTPUT_CONFIG_CHANGED: {
        int index = gOutputs.indexOfKey(ioHandle);
        if (index < 0) {
            LOGW("ioConfigChanged() modifying unknow output! %p", ioHandle);
            LOGW("ioConfigChanged() modifying unknow output! %d", ioHandle);
            break;
        }
        if (param2 == 0) break;
        desc = (OutputDescriptor *)param2;

        LOGV("ioConfigChanged() new config for output %p samplingRate %d, format %d channels %d frameCount %d latency %d",
        LOGV("ioConfigChanged() new config for output %d samplingRate %d, format %d channels %d frameCount %d latency %d",
                ioHandle, desc->samplingRate, desc->format,
                desc->channels, desc->frameCount, desc->latency);
        OutputDescriptor *outputDesc = gOutputs.valueAt(index);
@@ -524,15 +523,15 @@ audio_io_handle_t AudioSystem::getOutput(stream_type stream,
                                    uint32_t channels,
                                    output_flags flags)
{
    audio_io_handle_t output = NULL;
    audio_io_handle_t output = 0;
    if ((flags & AudioSystem::OUTPUT_FLAG_DIRECT) == 0) {
        Mutex::Autolock _l(gLock);
        output = AudioSystem::gStreamOutputMap.valueFor(stream);
        LOGV_IF((output != NULL), "getOutput() read %p from cache for stream %d", output, stream);
        LOGV_IF((output != 0), "getOutput() read %d from cache for stream %d", output, stream);
    }
    if (output == NULL) {
    if (output == 0) {
        const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
        if (aps == 0) return NULL;
        if (aps == 0) return 0;
        output = aps->getOutput(stream, samplingRate, format, channels, flags);
        if ((flags & AudioSystem::OUTPUT_FLAG_DIRECT) == 0) {
            Mutex::Autolock _l(gLock);
@@ -570,7 +569,7 @@ audio_io_handle_t AudioSystem::getInput(int inputSource,
                                    audio_in_acoustics acoustics)
{
    const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
    if (aps == 0) return NULL;
    if (aps == 0) return 0;
    return aps->getInput(inputSource, samplingRate, format, channels, acoustics);
}

+67 −99

File changed.

Preview size limit exceeded, changes collapsed.

Loading