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

Commit b87f4cad authored by Andy Hung's avatar Andy Hung Committed by Gerrit Code Review
Browse files

Merge "AudioFlinger: Refactor SyncEvent"

parents c6ba2022 9a820085
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -3919,7 +3919,7 @@ void AudioFlinger::updateSecondaryOutputsForTrack_l(
    track->setTeePatches(std::move(teePatches));
    track->setTeePatches(std::move(teePatches));
}
}


sp<AudioFlinger::SyncEvent> AudioFlinger::createSyncEvent(AudioSystem::sync_event_t type,
sp<SyncEvent> AudioFlinger::createSyncEvent(AudioSystem::sync_event_t type,
                                    audio_session_t triggerSession,
                                    audio_session_t triggerSession,
                                    audio_session_t listenerSession,
                                    audio_session_t listenerSession,
                                    sync_event_callback_t callBack,
                                    sync_event_callback_t callBack,
+1 −37
Original line number Original line Diff line number Diff line
@@ -85,6 +85,7 @@
#include <audio_utils/TimestampVerifier.h>
#include <audio_utils/TimestampVerifier.h>


#include <timing/MonotonicFrameCounter.h>
#include <timing/MonotonicFrameCounter.h>
#include <timing/SyncEvent.h>


#include "FastCapture.h"
#include "FastCapture.h"
#include "FastMixer.h"
#include "FastMixer.h"
@@ -374,43 +375,6 @@ public:


    static inline std::atomic<AudioFlinger *> gAudioFlinger = nullptr;
    static inline std::atomic<AudioFlinger *> gAudioFlinger = nullptr;


    class SyncEvent;

    typedef void (*sync_event_callback_t)(const wp<SyncEvent>& event) ;

    class SyncEvent : public RefBase {
    public:
        SyncEvent(AudioSystem::sync_event_t type,
                  audio_session_t triggerSession,
                  audio_session_t listenerSession,
                  sync_event_callback_t callBack,
                  const wp<RefBase>& cookie)
        : mType(type), mTriggerSession(triggerSession), mListenerSession(listenerSession),
          mCallback(callBack), mCookie(cookie)
        {}

        virtual ~SyncEvent() {}

        void trigger() {
            Mutex::Autolock _l(mLock);
            if (mCallback) mCallback(wp<SyncEvent>(this));
        }
        bool isCancelled() const { Mutex::Autolock _l(mLock); return (mCallback == NULL); }
        void cancel() { Mutex::Autolock _l(mLock); mCallback = NULL; }
        AudioSystem::sync_event_t type() const { return mType; }
        audio_session_t triggerSession() const { return mTriggerSession; }
        audio_session_t listenerSession() const { return mListenerSession; }
        wp<RefBase> cookie() const { return mCookie; }

    private:
          const AudioSystem::sync_event_t mType;
          const audio_session_t mTriggerSession;
          const audio_session_t mListenerSession;
          sync_event_callback_t mCallback;
          const wp<RefBase> mCookie;
          mutable Mutex mLock;
    };

    sp<SyncEvent> createSyncEvent(AudioSystem::sync_event_t type,
    sp<SyncEvent> createSyncEvent(AudioSystem::sync_event_t type,
                                        audio_session_t triggerSession,
                                        audio_session_t triggerSession,
                                        audio_session_t listenerSession,
                                        audio_session_t listenerSession,
+58 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

namespace android {

class SyncEvent;

typedef void (*sync_event_callback_t)(const wp<SyncEvent>& event) ;

class SyncEvent : public RefBase {
public:
    SyncEvent(AudioSystem::sync_event_t type,
              audio_session_t triggerSession,
              audio_session_t listenerSession,
              sync_event_callback_t callBack,
              const wp<RefBase>& cookie)
    : mType(type), mTriggerSession(triggerSession), mListenerSession(listenerSession),
      mCallback(callBack), mCookie(cookie)
    {}

    virtual ~SyncEvent() {}

    void trigger() {
        Mutex::Autolock _l(mLock);
        if (mCallback) mCallback(wp<SyncEvent>(this));
    }
    bool isCancelled() const { Mutex::Autolock _l(mLock); return (mCallback == NULL); }
    void cancel() { Mutex::Autolock _l(mLock); mCallback = NULL; }
    AudioSystem::sync_event_t type() const { return mType; }
    audio_session_t triggerSession() const { return mTriggerSession; }
    audio_session_t listenerSession() const { return mListenerSession; }
    wp<RefBase> cookie() const { return mCookie; }

private:
      const AudioSystem::sync_event_t mType;
      const audio_session_t mTriggerSession;
      const audio_session_t mListenerSession;
      sync_event_callback_t mCallback;
      const wp<RefBase> mCookie;
      mutable Mutex mLock;
};

} // namespace android