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

Commit e829faf9 authored by Manikanta Sivapala's avatar Manikanta Sivapala Committed by Linux Build Service Account
Browse files

frameworks/base : Handling usecases for ext mediaplayer

Handling usecases while creating ext mediaplayer like
extmediaplayer listner creation fails but QCMediaplayer
creation succeeds or vice versa.

Change-Id: Ic5242161bf30bd2688bd6aba6d6115ab0768e963
parent fe23cf23
Loading
Loading
Loading
Loading
+21 −8
Original line number Diff line number Diff line
@@ -152,9 +152,7 @@ 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);
    static bool CheckAndCreateExtMediaPlayer(JNIEnv *env, jobject thiz, jobject weak_this, sp<MediaPlayerListener> &listener, sp<MediaPlayer> &mp);
  private:
    static void *mLibHandle;
    static void loadLib();
@@ -167,6 +165,10 @@ class JNIMediaPlayerFactory {

    static CreateNativeQCMediaPlayerFn  sNativeQCMediaPlayerFn;
    static CreateNativeQCMediaPlayerFn loadNativeQCMediaPlayer();

    static sp<MediaPlayerListener> createExtMediaPlayerListener(JNIEnv *env, jobject thiz, jobject weak_this, sp<MediaPlayerListener> listener);
    static bool checkExtMedia(JNIEnv *env, jobject thiz);
    static void CreateNativeQCMediaPlayer(sp<MediaPlayer> &mp);
};

void *JNIMediaPlayerFactory::mLibHandle = NULL;
@@ -269,6 +271,19 @@ bool JNIMediaPlayerFactory::checkExtMedia(JNIEnv *env, jobject thiz)
    return bIsQCMediaPlayerPresent;
}

bool JNIMediaPlayerFactory::CheckAndCreateExtMediaPlayer(
         JNIEnv *env, jobject thiz, jobject weak_this, sp<MediaPlayerListener> &listener, sp<MediaPlayer> &mp)
{
    bool bOk = false;
    listener = createExtMediaPlayerListener(env, thiz, weak_this, listener);
    if (listener != NULL && checkExtMedia(env,thiz)) {
        CreateNativeQCMediaPlayer(mp);
        if (mp != NULL) {
            bOk = true;
        }
    }
    return bOk;
}

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

@@ -1004,19 +1019,17 @@ android_media_MediaPlayer_native_setup(JNIEnv *env, jobject thiz, jobject weak_t

    sp<MediaPlayer> mp = NULL;

    bool bOk = false;
    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);
        }
        bOk = jniMediaPlayerFactory->CheckAndCreateExtMediaPlayer(env, thiz, weak_this, listener, mp);
        delete(jniMediaPlayerFactory);
    }

    if (mp == NULL){
    if (!bOk){
        mp = new MediaPlayer();
    }
    if (mp == NULL) {