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

Commit c39d2e3c authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Music visualizer support hack.

This currently assumes 44k stereo (won't crash on other formats, but won't give the correct results either), and links statically with libspeex to get FFT data, increasing the size of libmedia by about 45kb.
parent 52cde727
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -43,6 +43,10 @@ public:
    virtual sp<IMemory>         decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat) = 0;
    virtual sp<IMemory>         decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat) = 0;
    virtual sp<IOMX>            createOMX() = 0;

    // Take a peek at currently playing audio, for visualization purposes.
    // This returns a buffer of 16 bit mono PCM data, or NULL if no visualization buffer is currently available.
    virtual sp<IMemory>         snoop() = 0;
};

// ----------------------------------------------------------------------------
+1 −0
Original line number Diff line number Diff line
@@ -153,6 +153,7 @@ public:
            void            notify(int msg, int ext1, int ext2);
    static  sp<IMemory>     decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat);
    static  sp<IMemory>     decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat);
    static  int             snoop(short *data, int len, int kind);
            status_t        invoke(const Parcel& request, Parcel *reply);
            status_t        setMetadataFilter(const Parcel& filter);
            status_t        getMetadata(bool update_only, bool apply_filter, Parcel *metadata);
+5 −0
Original line number Diff line number Diff line
@@ -1494,4 +1494,9 @@ public class MediaPlayer
    }

    private OnInfoListener mOnInfoListener;

    /**
     * @hide
     */
    public native static int snoop(short [] outData, int kind);
}
+13 −0
Original line number Diff line number Diff line
@@ -594,6 +594,18 @@ android_media_MediaPlayer_native_finalize(JNIEnv *env, jobject thiz)
    android_media_MediaPlayer_release(env, thiz);
}

static jint
android_media_MediaPlayer_snoop(JNIEnv* env, jobject thiz, jobject data, jint kind) {
    jshort* ar = (jshort*)env->GetPrimitiveArrayCritical((jarray)data, 0);
    jsize len = env->GetArrayLength((jarray)data);
    int ret = 0;
    if (ar) {
        ret = MediaPlayer::snoop(ar, len, kind);
        env->ReleasePrimitiveArrayCritical((jarray)data, ar, 0);
    }
    return ret;
}

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

static JNINativeMethod gMethods[] = {
@@ -624,6 +636,7 @@ static JNINativeMethod gMethods[] = {
    {"native_init",         "()V",                              (void *)android_media_MediaPlayer_native_init},
    {"native_setup",        "(Ljava/lang/Object;)V",            (void *)android_media_MediaPlayer_native_setup},
    {"native_finalize",     "()V",                              (void *)android_media_MediaPlayer_native_finalize},
    {"snoop",               "([SI)I",                           (void *)android_media_MediaPlayer_snoop},
};

static const char* const kClassPathName = "android/media/MediaPlayer";
+7 −3
Original line number Diff line number Diff line
@@ -39,6 +39,10 @@ endif
LOCAL_C_INCLUDES := \
    $(JNI_H_INCLUDE) \
    $(call include-path-for, graphics corecg) \
        $(TOP)/external/opencore/extern_libs_v2/khronos/openmax/include
        $(TOP)/external/opencore/extern_libs_v2/khronos/openmax/include \
        external/speex/include \
        external/speex/libspeex

LOCAL_STATIC_LIBRARIES := libspeex

include $(BUILD_SHARED_LIBRARY)
Loading