diff options
author | Manikanta Sivapala <msivap@codeaurora.org> | 2015-07-31 18:45:44 +0530 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2015-10-06 03:27:10 -0600 |
commit | 2faea7ee16198a12417befa65df8bf86c5413fdb (patch) | |
tree | e174cdd3b8828fa0570ca21824b2dede29ae6156 | |
parent | b08a47e50ca6e3c81ea84846464fcde8ed7e794b (diff) | |
download | frameworks_base-2faea7ee16198a12417befa65df8bf86c5413fdb.zip frameworks_base-2faea7ee16198a12417befa65df8bf86c5413fdb.tar.gz frameworks_base-2faea7ee16198a12417befa65df8bf86c5413fdb.tar.bz2 |
frameworks/base: Changes related to DASH
Creating Extended MediaPlayerListener and Native MediaPlayer
for DASH.
Change-Id: Ief49777e94b818851052715d6dbd9e51982da85a
-rw-r--r-- | media/jni/android_media_MediaPlayer.cpp | 155 |
1 files changed, 151 insertions, 4 deletions
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp index d8041f4..c39bb4e 100644 --- a/media/jni/android_media_MediaPlayer.cpp +++ b/media/jni/android_media_MediaPlayer.cpp @@ -49,6 +49,7 @@ #include <gui/Surface.h> #include <binder/IPCThreadState.h> #include <binder/IServiceManager.h> +#include <dlfcn.h> #include "android_util_Binder.h" // ---------------------------------------------------------------------------- @@ -137,6 +138,138 @@ void JNIMediaPlayerListener::notify(int msg, int ext1, int ext2, const Parcel *o } } + +static const char *EXTMEDIAJNI_LIB_NAME = "libextmedia_jni.so"; +static const char *kCreateJNIExtMediaPlayerListener = "CreateJNIExtMediaPlayerListener"; +static const char *kCheckExtMedia = "checkExtMedia"; +static const char *kCreateNativeQCMediaPlayer = "CreateNativeQCMediaPlayer"; +typedef MediaPlayerListener* (*CreateJNIExtMediaPlayerListenerFn)(JNIEnv *, jobject, jobject, sp<MediaPlayerListener> listener); +typedef bool (*CheckExtMediaFn)(JNIEnv *env, jobject); +typedef MediaPlayer* (*CreateNativeQCMediaPlayerFn)(); + + + +class JNIMediaPlayerFactory { + public: + JNIMediaPlayerFactory() {}; + static sp<MediaPlayerListener> createExtMediaPlayerListener(JNIEnv *env, jobject thiz, jobject weak_this, sp<MediaPlayerListener> listener); + static void CreateNativeQCMediaPlayer(sp<MediaPlayer> &mp); + static bool checkExtMedia(JNIEnv *env, jobject thiz); + private: + static void *mLibHandle; + static void loadLib(); + + static CreateJNIExtMediaPlayerListenerFn loadJNIExtMediaPlayerListener(); + static CreateJNIExtMediaPlayerListenerFn sExtDashListnerFnPtr; + + static CheckExtMediaFn sExtMediaFn; + static CheckExtMediaFn loadExtMedia(); + + static CreateNativeQCMediaPlayerFn sNativeQCMediaPlayerFn; + static CreateNativeQCMediaPlayerFn loadNativeQCMediaPlayer(); +}; + +void *JNIMediaPlayerFactory::mLibHandle = NULL; + +CreateJNIExtMediaPlayerListenerFn JNIMediaPlayerFactory::sExtDashListnerFnPtr = + JNIMediaPlayerFactory::loadJNIExtMediaPlayerListener(); + +CheckExtMediaFn JNIMediaPlayerFactory::sExtMediaFn = + JNIMediaPlayerFactory::loadExtMedia(); + +CreateNativeQCMediaPlayerFn JNIMediaPlayerFactory::sNativeQCMediaPlayerFn = + JNIMediaPlayerFactory::loadNativeQCMediaPlayer(); + + +void JNIMediaPlayerFactory::loadLib() +{ + if (!mLibHandle) { + mLibHandle = ::dlopen(EXTMEDIAJNI_LIB_NAME, RTLD_LAZY); + if (!mLibHandle) { + ALOGV("%s", dlerror()); + return; + } + ALOGV("Opened %s", EXTMEDIAJNI_LIB_NAME); + } +} + +CreateJNIExtMediaPlayerListenerFn JNIMediaPlayerFactory::loadJNIExtMediaPlayerListener() +{ + loadLib(); + CreateJNIExtMediaPlayerListenerFn pCreateExtDashListnerFnPtr = NULL; + if (mLibHandle != NULL) { + pCreateExtDashListnerFnPtr = (CreateJNIExtMediaPlayerListenerFn) + dlsym(mLibHandle, kCreateJNIExtMediaPlayerListener); + if (pCreateExtDashListnerFnPtr == NULL) { + ALOGW("Failed to load symbol %s : %s", kCreateJNIExtMediaPlayerListener, dlerror()); + } + } + return pCreateExtDashListnerFnPtr; +} + +CheckExtMediaFn JNIMediaPlayerFactory::loadExtMedia() +{ + loadLib(); + CheckExtMediaFn pCheckExtMediaFnPtr = NULL; + if (mLibHandle != NULL) { + pCheckExtMediaFnPtr = (CheckExtMediaFn)dlsym(mLibHandle, kCheckExtMedia); + if (pCheckExtMediaFnPtr == NULL) { + ALOGW("Failed to load symbol %s : %s", kCheckExtMedia, dlerror()); + } + } + return pCheckExtMediaFnPtr; +} + +CreateNativeQCMediaPlayerFn JNIMediaPlayerFactory::loadNativeQCMediaPlayer() +{ + loadLib(); + CreateNativeQCMediaPlayerFn pCreateNativeQCMediaPlayerFnPtr = NULL; + if (mLibHandle != NULL) { + pCreateNativeQCMediaPlayerFnPtr = (CreateNativeQCMediaPlayerFn) + dlsym(mLibHandle, kCreateNativeQCMediaPlayer); + if (pCreateNativeQCMediaPlayerFnPtr == NULL) { + ALOGW("Failed to load symbol %s : %s", kCreateNativeQCMediaPlayer, dlerror()); + } + } + return pCreateNativeQCMediaPlayerFnPtr; +} + + +sp<MediaPlayerListener> JNIMediaPlayerFactory::createExtMediaPlayerListener(JNIEnv *env, jobject thiz, jobject weak_this, sp<MediaPlayerListener> listener) +{ + if (checkExtMedia(env, thiz)) { + if (sExtDashListnerFnPtr ) { + listener = (*sExtDashListnerFnPtr)(env, thiz, weak_this, listener); + if (listener != NULL) { + ALOGE("JNIMediaPlayerFactory: createExtMediaPlayerListener : success"); + } + } + } + return listener; +} + +void JNIMediaPlayerFactory::CreateNativeQCMediaPlayer(sp<MediaPlayer> &mp) +{ + if (sNativeQCMediaPlayerFn) { + mp = (*sNativeQCMediaPlayerFn)(); + if (mp != NULL) { + ALOGE("JNIMediaPlayerFactory: CreateNativeQCMediaPlayer : Success"); + } + } +} + + +bool JNIMediaPlayerFactory::checkExtMedia(JNIEnv *env, jobject thiz) +{ + bool bIsQCMediaPlayerPresent = false; + if (sExtMediaFn) { + bIsQCMediaPlayerPresent = (*sExtMediaFn)(env, thiz); + } + ALOGE("JNIMediaPlayerFactory: bIsQCMediaPlayerPresent %d", bIsQCMediaPlayerPresent); + return bIsQCMediaPlayerPresent; +} + + // ---------------------------------------------------------------------------- static sp<MediaPlayer> getMediaPlayer(JNIEnv* env, jobject thiz) @@ -868,14 +1001,28 @@ static void android_media_MediaPlayer_native_setup(JNIEnv *env, jobject thiz, jobject weak_this) { ALOGV("native_setup"); - sp<MediaPlayer> mp = new MediaPlayer(); + + sp<MediaPlayer> mp = NULL; + + JNIMediaPlayerFactory *jniMediaPlayerFactory = new JNIMediaPlayerFactory(); + + sp<MediaPlayerListener> listener = new JNIMediaPlayerListener(env, thiz, weak_this); + + if (jniMediaPlayerFactory) { + listener = jniMediaPlayerFactory->createExtMediaPlayerListener(env, thiz, weak_this, listener); + if (jniMediaPlayerFactory->checkExtMedia(env,thiz)) { + jniMediaPlayerFactory->CreateNativeQCMediaPlayer(mp); + } + delete(jniMediaPlayerFactory); + } + + if (mp == NULL){ + mp = new MediaPlayer(); + } if (mp == NULL) { jniThrowException(env, "java/lang/RuntimeException", "Out of memory"); return; } - - // create new listener and give it to MediaPlayer - sp<JNIMediaPlayerListener> listener = new JNIMediaPlayerListener(env, thiz, weak_this); mp->setListener(listener); // Stow our new C++ MediaPlayer in an opaque field in the Java object. |