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

Commit 57303cc4 authored by jiabin's avatar jiabin Committed by Eric Laurent
Browse files

Interface between audio server and vibrator service

The haptic playback should be controlled by vibrator service. Via the
interface, audio server could notify vibrator service about starting or
stopping haptic playback and get vibrator intensity from vibrator
service. Vibrator service could call mute/unmute to control the haptic
playback.

Test: Manually
Change-Id: Iad24813977e4dea0d67a91f8f8b390a016ce4ca2
parent 77270b88
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@ LOCAL_SHARED_LIBRARIES := \
	libnbaio \
	libnblog \
	libsoundtriggerservice \
	libutils
	libutils \
	libvibrator

# TODO oboeservice is the old folder name for aaudioservice. It will be changed.
LOCAL_C_INCLUDES := \
+2 −1
Original line number Diff line number Diff line
@@ -38,7 +38,8 @@ LOCAL_SHARED_LIBRARIES := \
    libpowermanager \
    libmediautils \
    libmemunreachable \
    libmedia_helper
    libmedia_helper \
    libvibrator

LOCAL_STATIC_LIBRARIES := \
    libcpustats \
+37 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include <sys/time.h>
#include <sys/resource.h>

#include <android/os/IExternalVibratorService.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <utils/Log.h>
@@ -122,6 +123,21 @@ static void sMediaLogInit()
    }
}

// Keep a strong reference to external vibrator service
static sp<os::IExternalVibratorService> sExternalVibratorService;

static sp<os::IExternalVibratorService> getExternalVibratorService() {
    if (sExternalVibratorService == 0) {
        sp <IBinder> binder = defaultServiceManager()->getService(
            String16("external_vibrator_service"));
        if (binder != 0) {
            sExternalVibratorService =
                interface_cast<os::IExternalVibratorService>(binder);
        }
    }
    return sExternalVibratorService;
}

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

std::string formatToString(audio_format_t format) {
@@ -318,6 +334,27 @@ status_t AudioFlinger::openMmapStream(MmapStreamInterface::stream_direction_t di
    return ret;
}

/* static */
int AudioFlinger::onExternalVibrationStart(const sp<os::ExternalVibration>& externalVibration) {
    sp<os::IExternalVibratorService> evs = getExternalVibratorService();
    if (evs != 0) {
        int32_t ret;
        binder::Status status = evs->onExternalVibrationStart(*externalVibration, &ret);
        if (status.isOk()) {
            return ret;
        }
    }
    return AudioMixer::HAPTIC_SCALE_NONE;
}

/* static */
void AudioFlinger::onExternalVibrationStop(const sp<os::ExternalVibration>& externalVibration) {
    sp<os::IExternalVibratorService> evs = getExternalVibratorService();
    if (evs != 0) {
        evs->onExternalVibrationStop(*externalVibration);
    }
}

static const char * const audio_interfaces[] = {
    AUDIO_HARDWARE_MODULE_ID_PRIMARY,
    AUDIO_HARDWARE_MODULE_ID_A2DP,
+6 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <sys/types.h>
#include <limits.h>

#include <android/os/BnExternalVibrationController.h>
#include <android-base/macros.h>

#include <cutils/atomic.h>
@@ -84,6 +85,8 @@
#include <private/media/AudioEffectShared.h>
#include <private/media/AudioTrackShared.h>

#include <vibrator/ExternalVibration.h>

#include "android/media/BnAudioRecord.h"

namespace android {
@@ -284,6 +287,9 @@ public:
                            const sp<MmapStreamCallback>& callback,
                            sp<MmapStreamInterface>& interface,
                            audio_port_handle_t *handle);

    static int onExternalVibrationStart(const sp<os::ExternalVibration>& externalVibration);
    static void onExternalVibrationStop(const sp<os::ExternalVibration>& externalVibration);
private:
    // FIXME The 400 is temporarily too high until a leak of writers in media.log is fixed.
    static const size_t kLogMemorySize = 400 * 1024;
+11 −0
Original line number Diff line number Diff line
@@ -127,6 +127,7 @@ public:
                    mHapticIntensity = hapticIntensity;
                }
            }
            sp<os::ExternalVibration> getExternalVibration() const { return mExternalVibration; }

protected:
    // for numerous
@@ -207,6 +208,16 @@ protected:
    bool                mHapticPlaybackEnabled = false; // indicates haptic playback enabled or not
    // intensity to play haptic data
    AudioMixer::haptic_intensity_t mHapticIntensity = AudioMixer::HAPTIC_SCALE_NONE;
    class AudioVibrationController : public os::BnExternalVibrationController {
    public:
        explicit AudioVibrationController(Track* track) : mTrack(track) {}
        binder::Status mute(/*out*/ bool *ret) override;
        binder::Status unmute(/*out*/ bool *ret) override;
    private:
        Track* const mTrack;
    };
    sp<AudioVibrationController> mAudioVibrationController;
    sp<os::ExternalVibration>    mExternalVibration;

private:
    // The following fields are only for fast tracks, and should be in a subclass
Loading