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

Commit eb57617e authored by Atneya Nair's avatar Atneya Nair Committed by Harish Mahendrakar
Browse files

Remove legacy callback interfaces

Remove interfaces associated with the legacy callback interface.
Note, some dead code in AudioTrack cannot be removed due to dependence
of vendor code on link time (b/169889714).

Test: Compiles, modified tests pass
Bug: 199156212
Merged-In: I544613e61b6879c188ee6aafdc3bdbabac3cc064
Change-Id: I544613e61b6879c188ee6aafdc3bdbabac3cc064
parent 65c81dfb
Loading
Loading
Loading
Loading
+0 −95
Original line number Diff line number Diff line
@@ -139,39 +139,6 @@ AudioRecord::AudioRecord(const AttributionSourceState &client)
{
}

AudioRecord::AudioRecord(
        audio_source_t inputSource,
        uint32_t sampleRate,
        audio_format_t format,
        audio_channel_mask_t channelMask,
        const AttributionSourceState& client,
        size_t frameCount,
        legacy_callback_t callback,
        void* user,
        uint32_t notificationFrames,
        audio_session_t sessionId,
        transfer_type transferType,
        audio_input_flags_t flags,
        const audio_attributes_t* pAttributes,
        audio_port_handle_t selectedDeviceId,
        audio_microphone_direction_t selectedMicDirection,
        float microphoneFieldDimension)
    : mActive(false),
      mStatus(NO_INIT),
      mClientAttributionSource(client),
      mSessionId(AUDIO_SESSION_ALLOCATE),
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
      mPreviousSchedulingGroup(SP_DEFAULT),
      mProxy(NULL)
{
    uid_t uid = VALUE_OR_FATAL(aidl2legacy_int32_t_uid_t(mClientAttributionSource.uid));
    pid_t pid = VALUE_OR_FATAL(aidl2legacy_int32_t_pid_t(mClientAttributionSource.pid));
    (void)set(inputSource, sampleRate, format, channelMask, frameCount, callback, user,
            notificationFrames, false /*threadCanCallJava*/, sessionId, transferType, flags,
            uid, pid, pAttributes, selectedDeviceId, selectedMicDirection,
            microphoneFieldDimension);
}

AudioRecord::AudioRecord(
        audio_source_t inputSource,
        uint32_t sampleRate,
@@ -255,37 +222,6 @@ void AudioRecord::stopAndJoinCallbacks() {
        mDeviceCallback.clear();
    }
}
namespace {
class LegacyCallbackWrapper : public AudioRecord::IAudioRecordCallback {
    const AudioRecord::legacy_callback_t mCallback;
    void* const mData;

  public:
    LegacyCallbackWrapper(AudioRecord::legacy_callback_t callback, void* user)
        : mCallback(callback), mData(user) {}

    size_t onMoreData(const AudioRecord::Buffer& buffer) override {
        AudioRecord::Buffer copy = buffer;
        mCallback(AudioRecord::EVENT_MORE_DATA, mData, &copy);
        return copy.size();
    }

    void onOverrun() override { mCallback(AudioRecord::EVENT_OVERRUN, mData, nullptr); }

    void onMarker(uint32_t markerPosition) override {
        mCallback(AudioRecord::EVENT_MARKER, mData, &markerPosition);
    }

    void onNewPos(uint32_t newPos) override {
        mCallback(AudioRecord::EVENT_NEW_POS, mData, &newPos);
    }

    void onNewIAudioRecord() override {
        mCallback(AudioRecord::EVENT_NEW_IAUDIORECORD, mData, nullptr);
    }
};
}  // namespace

status_t AudioRecord::set(
        audio_source_t inputSource,
        uint32_t sampleRate,
@@ -479,37 +415,6 @@ exit:
    return status;
}

status_t AudioRecord::set(
        audio_source_t inputSource,
        uint32_t sampleRate,
        audio_format_t format,
        audio_channel_mask_t channelMask,
        size_t frameCount,
        legacy_callback_t callback,
        void* user,
        uint32_t notificationFrames,
        bool threadCanCallJava,
        audio_session_t sessionId,
        transfer_type transferType,
        audio_input_flags_t flags,
        uid_t uid,
        pid_t pid,
        const audio_attributes_t* pAttributes,
        audio_port_handle_t selectedDeviceId,
        audio_microphone_direction_t selectedMicDirection,
        float microphoneFieldDimension,
        int32_t maxSharedAudioHistoryMs)
{
    if (callback != nullptr) {
        mLegacyCallbackWrapper = sp<LegacyCallbackWrapper>::make(callback, user);
    } else if (user) {
        LOG_ALWAYS_FATAL("Callback data provided without callback pointer!");
    }
    return set(inputSource, sampleRate, format, channelMask, frameCount, mLegacyCallbackWrapper,
        notificationFrames, threadCanCallJava, sessionId, transferType, flags, uid, pid,
        pAttributes, selectedDeviceId, selectedMicDirection, microphoneFieldDimension,
        maxSharedAudioHistoryMs);
}
// -------------------------------------------------------------------------

status_t AudioRecord::start(AudioSystem::sync_event_t event, audio_session_t triggerSession)
+0 −109
Original line number Diff line number Diff line
@@ -325,45 +325,6 @@ namespace {
        }
    };
}

AudioTrack::AudioTrack(
        audio_stream_type_t streamType,
        uint32_t sampleRate,
        audio_format_t format,
        audio_channel_mask_t channelMask,
        size_t frameCount,
        audio_output_flags_t flags,
        legacy_callback_t callback,
        void* user,
        int32_t notificationFrames,
        audio_session_t sessionId,
        transfer_type transferType,
        const audio_offload_info_t *offloadInfo,
        const AttributionSourceState& attributionSource,
        const audio_attributes_t* pAttributes,
        bool doNotReconnect,
        float maxRequiredSpeed,
        audio_port_handle_t selectedDeviceId)
    : mStatus(NO_INIT),
      mState(STATE_STOPPED),
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
      mPreviousSchedulingGroup(SP_DEFAULT),
      mPausedPosition(0),
      mAudioTrackCallback(new AudioTrackCallback())
{
    mAttributes = AUDIO_ATTRIBUTES_INITIALIZER;
    if (callback != nullptr) {
        mLegacyCallbackWrapper = sp<LegacyCallbackWrapper>::make(callback, user);
    } else if (user) {
        LOG_ALWAYS_FATAL("Callback data provided without callback pointer!");
    }
    mSetParams = std::unique_ptr<SetParams>{new SetParams{
            streamType, sampleRate, format, channelMask, frameCount, flags, mLegacyCallbackWrapper,
            notificationFrames, 0 /*sharedBuffer*/, false /*threadCanCallJava*/, sessionId,
            transferType, offloadInfo, attributionSource, pAttributes, doNotReconnect,
            maxRequiredSpeed, selectedDeviceId}};
}

AudioTrack::AudioTrack(
        audio_stream_type_t streamType,
        uint32_t sampleRate,
@@ -397,44 +358,6 @@ AudioTrack::AudioTrack(
                          doNotReconnect, maxRequiredSpeed, AUDIO_PORT_HANDLE_NONE}};
}

AudioTrack::AudioTrack(
        audio_stream_type_t streamType,
        uint32_t sampleRate,
        audio_format_t format,
        audio_channel_mask_t channelMask,
        const sp<IMemory>& sharedBuffer,
        audio_output_flags_t flags,
        legacy_callback_t callback,
        void* user,
        int32_t notificationFrames,
        audio_session_t sessionId,
        transfer_type transferType,
        const audio_offload_info_t *offloadInfo,
        const AttributionSourceState& attributionSource,
        const audio_attributes_t* pAttributes,
        bool doNotReconnect,
        float maxRequiredSpeed)
    : mStatus(NO_INIT),
      mState(STATE_STOPPED),
      mPreviousPriority(ANDROID_PRIORITY_NORMAL),
      mPreviousSchedulingGroup(SP_DEFAULT),
      mPausedPosition(0),
      mSelectedDeviceId(AUDIO_PORT_HANDLE_NONE),
      mAudioTrackCallback(new AudioTrackCallback())
{
    mAttributes = AUDIO_ATTRIBUTES_INITIALIZER;
    if (callback) {
        mLegacyCallbackWrapper = sp<LegacyCallbackWrapper>::make(callback, user);
    } else if (user) {
        LOG_ALWAYS_FATAL("Callback data provided without callback pointer!");
    }
    mSetParams = std::unique_ptr<SetParams>{new SetParams{
            streamType, sampleRate, format, channelMask, 0 /*frameCount*/, flags,
            mLegacyCallbackWrapper, notificationFrames, sharedBuffer, false /*threadCanCallJava*/,
            sessionId, transferType, offloadInfo, attributionSource, pAttributes, doNotReconnect,
            maxRequiredSpeed, AUDIO_PORT_HANDLE_NONE}};
}

void AudioTrack::onFirstRef() {
    if (mSetParams) {
        set(*mSetParams);
@@ -496,38 +419,6 @@ void AudioTrack::stopAndJoinCallbacks() {
        mDeviceCallback.clear();
    }
}

status_t AudioTrack::set(
        audio_stream_type_t streamType,
        uint32_t sampleRate,
        audio_format_t format,
        audio_channel_mask_t channelMask,
        size_t frameCount,
        audio_output_flags_t flags,
        legacy_callback_t callback,
        void * user,
        int32_t notificationFrames,
        const sp<IMemory>& sharedBuffer,
        bool threadCanCallJava,
        audio_session_t sessionId,
        transfer_type transferType,
        const audio_offload_info_t *offloadInfo,
        const AttributionSourceState& attributionSource,
        const audio_attributes_t* pAttributes,
        bool doNotReconnect,
        float maxRequiredSpeed,
        audio_port_handle_t selectedDeviceId)
{
    if (callback) {
        mLegacyCallbackWrapper = sp<LegacyCallbackWrapper>::make(callback, user);
    } else if (user) {
        LOG_ALWAYS_FATAL("Callback data provided without callback pointer!");
    }
    return set(streamType, sampleRate,format, channelMask, frameCount, flags,
               mLegacyCallbackWrapper, notificationFrames, sharedBuffer, threadCanCallJava,
               sessionId, transferType, offloadInfo, attributionSource, pAttributes,
               doNotReconnect, maxRequiredSpeed, selectedDeviceId);
}
status_t AudioTrack::set(
        audio_stream_type_t streamType,
        uint32_t sampleRate,
+0 −61
Original line number Diff line number Diff line
@@ -46,27 +46,6 @@ class AudioRecord : public AudioSystem::AudioDeviceCallback
{
public:

    /* Events used by AudioRecord callback function (legacy_callback_t).
     * Keep in sync with frameworks/base/media/java/android/media/AudioRecord.java NATIVE_EVENT_*.
     */
    enum event_type {
        EVENT_MORE_DATA = 0,        // Request to read available data from buffer.
                                    // If this event is delivered but the callback handler
                                    // does not want to read the available data, the handler must
                                    // explicitly ignore the event by setting frameCount to zero.
        EVENT_OVERRUN = 1,          // Buffer overrun occurred.
        EVENT_MARKER = 2,           // Record head is at the specified marker position
                                    // (See setMarkerPosition()).
        EVENT_NEW_POS = 3,          // Record head is at a new position
                                    // (See setPositionUpdatePeriod()).
        EVENT_NEW_IAUDIORECORD = 4, // IAudioRecord was re-created, either due to re-routing and
                                    // voluntary invalidation by mediaserver, or mediaserver crash.
    };

    /* Client should declare a Buffer and pass address to obtainBuffer()
     * and releaseBuffer().  See also legacy_callback_t for EVENT_MORE_DATA.
     */

    class Buffer
    {
      friend AudioRecord;
@@ -122,7 +101,6 @@ public:
     *          - EVENT_NEW_IAUDIORECORD: unused.
     */

    typedef void (*legacy_callback_t)(int event, void* user, void *info);

    class IAudioRecordCallback : public virtual RefBase {
        friend AudioRecord;
@@ -226,24 +204,6 @@ public:
                                    float selectedMicFieldDimension = MIC_FIELD_DIMENSION_DEFAULT);


                        AudioRecord(audio_source_t inputSource,
                                    uint32_t sampleRate,
                                    audio_format_t format,
                                    audio_channel_mask_t channelMask,
                                    const android::content::AttributionSourceState& client,
                                    size_t frameCount,
                                    legacy_callback_t callback,
                                    void* user,
                                    uint32_t notificationFrames = 0,
                                    audio_session_t sessionId = AUDIO_SESSION_ALLOCATE,
                                    transfer_type transferType = TRANSFER_DEFAULT,
                                    audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE,
                                    const audio_attributes_t* pAttributes = nullptr,
                                    audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE,
                                    audio_microphone_direction_t
                                        selectedMicDirection = MIC_DIRECTION_UNSPECIFIED,
                                    float selectedMicFieldDimension = MIC_FIELD_DIMENSION_DEFAULT);

    /* Terminates the AudioRecord and unregisters it from AudioFlinger.
     * Also destroys all resources associated with the AudioRecord.
     */
@@ -286,27 +246,6 @@ public:
                            float selectedMicFieldDimension = MIC_FIELD_DIMENSION_DEFAULT,
                            int32_t maxSharedAudioHistoryMs = 0);

           status_t    set(audio_source_t inputSource,
                            uint32_t sampleRate,
                            audio_format_t format,
                            audio_channel_mask_t channelMask,
                            size_t frameCount,
                            legacy_callback_t callback,
                            void* user,
                            uint32_t notificationFrames = 0,
                            bool threadCanCallJava = false,
                            audio_session_t sessionId = AUDIO_SESSION_ALLOCATE,
                            transfer_type transferType = TRANSFER_DEFAULT,
                            audio_input_flags_t flags = AUDIO_INPUT_FLAG_NONE,
                            uid_t uid = AUDIO_UID_INVALID,
                            pid_t pid = -1,
                            const audio_attributes_t* pAttributes = nullptr,
                            audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE,
                            audio_microphone_direction_t
                                selectedMicDirection = MIC_DIRECTION_UNSPECIFIED,
                            float selectedMicFieldDimension = MIC_FIELD_DIMENSION_DEFAULT,
                            int32_t maxSharedAudioHistoryMs = 0);

    /* Result of constructing the AudioRecord. This must be checked for successful initialization
     * before using any AudioRecord API (except for set()), because using
     * an uninitialized AudioRecord produces undefined results.
+2 −62
Original line number Diff line number Diff line
@@ -148,7 +148,6 @@ public:
     *          - EVENT_NEW_TIMESTAMP: pointer to const AudioTimestamp.
     */

    typedef void (*legacy_callback_t)(int event, void* user, void* info);
    class IAudioTrackCallback : public virtual RefBase {
      friend AudioTrack;
      protected:
@@ -343,26 +342,6 @@ public:
                                    float maxRequiredSpeed = 1.0f,
                                    audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE);


                        AudioTrack( audio_stream_type_t streamType,
                                    uint32_t sampleRate,
                                    audio_format_t format,
                                    audio_channel_mask_t channelMask,
                                    size_t frameCount,
                                    audio_output_flags_t flags,
                                    legacy_callback_t cbf,
                                    void* user = nullptr,
                                    int32_t notificationFrames = 0,
                                    audio_session_t sessionId  = AUDIO_SESSION_ALLOCATE,
                                    transfer_type transferType = TRANSFER_DEFAULT,
                                    const audio_offload_info_t *offloadInfo = nullptr,
                                    const AttributionSourceState& attributionSource =
                                        AttributionSourceState(),
                                    const audio_attributes_t* pAttributes = nullptr,
                                    bool doNotReconnect = false,
                                    float maxRequiredSpeed = 1.0f,
                                    audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE);

    /* Creates an audio track and registers it with AudioFlinger.
     * With this constructor, the track is configured for static buffer mode.
     * Data to be rendered is passed in a shared memory buffer
@@ -391,25 +370,6 @@ public:
                                    bool doNotReconnect = false,
                                    float maxRequiredSpeed = 1.0f);


                        AudioTrack( audio_stream_type_t streamType,
                                    uint32_t sampleRate,
                                    audio_format_t format,
                                    audio_channel_mask_t channelMask,
                                    const sp<IMemory>& sharedBuffer,
                                    audio_output_flags_t flags,
                                    legacy_callback_t cbf,
                                    void* user          = nullptr,
                                    int32_t notificationFrames = 0,
                                    audio_session_t sessionId   = AUDIO_SESSION_ALLOCATE,
                                    transfer_type transferType = TRANSFER_DEFAULT,
                                    const audio_offload_info_t *offloadInfo = nullptr,
                                    const AttributionSourceState& attributionSource =
                                        AttributionSourceState(),
                                    const audio_attributes_t* pAttributes = nullptr,
                                    bool doNotReconnect = false,
                                    float maxRequiredSpeed = 1.0f);

    /* Terminates the AudioTrack and unregisters it from AudioFlinger.
     * Also destroys all resources associated with the AudioTrack.
     */
@@ -490,27 +450,7 @@ public:
                        }
            void       onFirstRef() override;
        public:
            status_t    set(audio_stream_type_t streamType,
                            uint32_t sampleRate,
                            audio_format_t format,
                            audio_channel_mask_t channelMask,
                            size_t frameCount,
                            audio_output_flags_t flags,
                            legacy_callback_t callback,
                            void * user = nullptr,
                            int32_t notificationFrames = 0,
                            const sp<IMemory>& sharedBuffer = 0,
                            bool threadCanCallJava = false,
                            audio_session_t sessionId  = AUDIO_SESSION_ALLOCATE,
                            transfer_type transferType = TRANSFER_DEFAULT,
                            const audio_offload_info_t *offloadInfo = nullptr,
                            const AttributionSourceState& attributionSource =
                                AttributionSourceState(),
                            const audio_attributes_t* pAttributes = nullptr,
                            bool doNotReconnect = false,
                            float maxRequiredSpeed = 1.0f,
                            audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE);

            typedef void (*legacy_callback_t)(int event, void* user, void* info);
            // FIXME(b/169889714): Vendor code depends on the old method signature at link time
            status_t    set(audio_stream_type_t streamType,
                            uint32_t sampleRate,
+15 −23
Original line number Diff line number Diff line
@@ -45,22 +45,6 @@ status_t OnAudioDeviceUpdateNotifier::waitForAudioDeviceCb() {
    return OK;
}

// AudioTrack callback function.
static void AudioTrackCallBackFunction(int event, void* user, void* info __unused) {
    switch (event) {
        case AudioTrack::EVENT_BUFFER_END: {
            AudioPlayback* ap = (AudioPlayback*)user;
            std::unique_lock<std::mutex> lock{ap->mMutex};
            ap->mStopPlaying = true;
            ap->mCondition.notify_all();
            break;
        }
        default:
            ALOGV("received audiotrack callback %d", event);
            break;
    }
}

AudioPlayback::AudioPlayback(uint32_t sampleRate, audio_format_t format,
                             audio_channel_mask_t channelMask, audio_output_flags_t flags,
                             audio_session_t sessionId, AudioTrack::transfer_type transferType,
@@ -94,13 +78,14 @@ status_t AudioPlayback::create() {
    attributionSource.token = sp<BBinder>::make();
    if (mTransferType == AudioTrack::TRANSFER_OBTAIN) {
        mTrack = new AudioTrack(attributionSource);
        mTrack->set(AUDIO_STREAM_MUSIC, mSampleRate, mFormat, mChannelMask, 0, mFlags, nullptr,
                    nullptr, 0, 0, false, mSessionId, mTransferType, nullptr, attributionSource,
                    mAttributes);
        mTrack->set(AUDIO_STREAM_MUSIC, mSampleRate, mFormat, mChannelMask, 0 /* frameCount */,
                    mFlags, nullptr /* callback */, 0 /* notificationFrames */,
                    nullptr /* sharedBuffer */, false /*canCallJava */, mSessionId, mTransferType,
                    nullptr /* offloadInfo */, attributionSource, mAttributes);
    } else if (mTransferType == AudioTrack::TRANSFER_SHARED) {
        mTrack = new AudioTrack(AUDIO_STREAM_MUSIC, mSampleRate, mFormat, mChannelMask, mMemory,
                                mFlags, AudioTrackCallBackFunction, this, 0, mSessionId,
                                mTransferType, nullptr, attributionSource, mAttributes);
                                mFlags, wp<AudioTrack::IAudioTrackCallback>::fromExisting(this), 0,
                                mSessionId, mTransferType, nullptr, attributionSource, mAttributes);
    } else {
        ALOGE("Required Transfer type not existed");
        return INVALID_OPERATION;
@@ -157,6 +142,12 @@ status_t AudioPlayback::start() {
    return status;
}

void AudioPlayback::onBufferEnd() {
    std::unique_lock<std::mutex> lock{mMutex};
    mStopPlaying = true;
    mCondition.notify_all();
}

status_t AudioPlayback::fillBuffer() {
    if (PLAY_STARTED != mState && PLAY_STOPPED != mState) return INVALID_OPERATION;
    int retry = 25;
@@ -415,12 +406,13 @@ status_t AudioCapture::create() {
    if (mTransferType == AudioRecord::TRANSFER_OBTAIN) {
        if (mSampleRate == 48000) {  // test all available constructors
            mRecord = new AudioRecord(mInputSource, mSampleRate, mFormat, mChannelMask,
                                      attributionSource, mFrameCount, nullptr, nullptr,
                                      attributionSource, mFrameCount, nullptr /* callback */,
                                      mNotificationFrames, mSessionId, mTransferType, mFlags);
        } else {
            mRecord = new AudioRecord(attributionSource);
            status = mRecord->set(mInputSource, mSampleRate, mFormat, mChannelMask, mFrameCount,
                                  nullptr, nullptr, 0, false, mSessionId, mTransferType, mFlags,
                                  nullptr /* callback */, 0 /* notificationFrames */,
                                  false /* canCallJava */, mSessionId, mTransferType, mFlags,
                                  attributionSource.uid, attributionSource.pid);
        }
        if (NO_ERROR != status) return status;
Loading