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

Commit 64cfcab7 authored by Atneya Nair's avatar Atneya Nair Committed by Android (Google) Code Review
Browse files

Merge "[audio] Legacy AudioTrack::set cleanup" into main

parents fe1e9c0d f8f6eaf0
Loading
Loading
Loading
Loading
+0 −92
Original line number Diff line number Diff line
@@ -271,46 +271,6 @@ AudioTrack::AudioTrack(
        doNotReconnect, maxRequiredSpeed, selectedDeviceId);
}

namespace {
    class LegacyCallbackWrapper : public AudioTrack::IAudioTrackCallback {
      const AudioTrack::legacy_callback_t mCallback;
      void * const mData;
      public:
        LegacyCallbackWrapper(AudioTrack::legacy_callback_t callback, void* user)
            : mCallback(callback), mData(user) {}
        size_t onMoreData(const AudioTrack::Buffer & buffer) override {
          AudioTrack::Buffer copy = buffer;
          mCallback(AudioTrack::EVENT_MORE_DATA, mData, static_cast<void*>(&copy));
          return copy.size();
        }
        void onUnderrun() override {
            mCallback(AudioTrack::EVENT_UNDERRUN, mData, nullptr);
        }
        void onLoopEnd(int32_t loopsRemaining) override {
            mCallback(AudioTrack::EVENT_LOOP_END, mData, &loopsRemaining);
        }
        void onMarker(uint32_t markerPosition) override {
            mCallback(AudioTrack::EVENT_MARKER, mData, &markerPosition);
        }
        void onNewPos(uint32_t newPos) override {
            mCallback(AudioTrack::EVENT_NEW_POS, mData, &newPos);
        }
        void onBufferEnd() override {
            mCallback(AudioTrack::EVENT_BUFFER_END, mData, nullptr);
        }
        void onNewIAudioTrack() override {
            mCallback(AudioTrack::EVENT_NEW_IAUDIOTRACK, mData, nullptr);
        }
        void onStreamEnd() override {
            mCallback(AudioTrack::EVENT_STREAM_END, mData, nullptr);
        }
        size_t onCanWriteMoreData(const AudioTrack::Buffer & buffer) override {
          AudioTrack::Buffer copy = buffer;
          mCallback(AudioTrack::EVENT_CAN_WRITE_MORE_DATA, mData, static_cast<void*>(&copy));
          return copy.size();
        }
    };
}
AudioTrack::AudioTrack(
        audio_stream_type_t streamType,
        uint32_t sampleRate,
@@ -718,58 +678,6 @@ status_t AudioTrack::set(
    return logIfErrorAndReturnStatus(status, "");
}


status_t AudioTrack::set(
        audio_stream_type_t streamType,
        uint32_t sampleRate,
        audio_format_t format,
        uint32_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,
        uid_t uid,
        pid_t pid,
        const audio_attributes_t* pAttributes,
        bool doNotReconnect,
        float maxRequiredSpeed,
        audio_port_handle_t selectedDeviceId)
{
    AttributionSourceState attributionSource;
    auto attributionSourceUid = legacy2aidl_uid_t_int32_t(uid);
    if (!attributionSourceUid.ok()) {
        return logIfErrorAndReturnStatus(
                BAD_VALUE,
                StringPrintf("%s: received invalid attribution source uid, uid: %d, session id: %d",
                             __func__, uid, sessionId));
    }
    attributionSource.uid = attributionSourceUid.value();
    auto attributionSourcePid = legacy2aidl_pid_t_int32_t(pid);
    if (!attributionSourcePid.ok()) {
        return logIfErrorAndReturnStatus(
                BAD_VALUE,
                StringPrintf("%s: received invalid attribution source pid, pid: %d, sessionId: %d",
                             __func__, pid, sessionId));
    }
    attributionSource.pid = attributionSourcePid.value();
    attributionSource.token = sp<BBinder>::make();
    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, static_cast<audio_channel_mask_t>(channelMask),
               frameCount, flags, mLegacyCallbackWrapper, notificationFrames, sharedBuffer,
               threadCanCallJava, sessionId, transferType, offloadInfo, attributionSource,
               pAttributes, doNotReconnect, maxRequiredSpeed, selectedDeviceId);
}

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

status_t AudioTrack::start()
+0 −1
Original line number Diff line number Diff line
@@ -698,7 +698,6 @@ private:
    // for client callback handler

    wp<IAudioRecordCallback> mCallback;
    sp<IAudioRecordCallback> mLegacyCallbackWrapper;

    bool                    mInitialized = false;   // Protect against double set
    // for notification APIs
+0 −23
Original line number Diff line number Diff line
@@ -453,28 +453,6 @@ public:
                        }
            void       onFirstRef() override;
        public:
            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,
                            audio_format_t format,
                            uint32_t channelMask,
                            size_t frameCount   = 0,
                            audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE,
                            legacy_callback_t cbf = nullptr,
                            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,
                            uid_t uid = AUDIO_UID_INVALID,
                            pid_t pid = -1,
                            const audio_attributes_t* pAttributes = nullptr,
                            bool doNotReconnect = false,
                            float maxRequiredSpeed = 1.0f,
                            audio_port_handle_t selectedDeviceId = AUDIO_PORT_HANDLE_NONE);

    /* Result of constructing the AudioTrack. This must be checked for successful initialization
     * before using any AudioTrack API (except for set()), because using
@@ -1348,7 +1326,6 @@ public:

    // for client callback handler
    wp<IAudioTrackCallback> mCallback;                   // callback handler for events, or NULL
    sp<IAudioTrackCallback> mLegacyCallbackWrapper;      // wrapper for legacy callback interface
    // for notification APIs
    std::unique_ptr<SetParams> mSetParams;          // Temporary copy of ctor params to allow for
                                                    // deferred set after first reference.