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

Commit b1c94a9b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "mp2-dep"

* changes:
  MediaPlayer2: remove libandroid_runtime + other static lib dependency.
  MediaPlayer2: remove unused code setMetadataFilter and getMetadata
  MediaPlayer2: temporarily disable set/getAudioAttribute
parents 8edeba38 bf98d54d
Loading
Loading
Loading
Loading
+2 −9
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ cc_library_shared {
        "android_media_Media2HTTPConnection.cpp",
        "android_media_Media2HTTPService.cpp",
        "android_media_Media2DataSource.cpp",
        "android_media_MediaMetricsJNI.cpp",
        "android_media_MediaPlayer2.cpp",
        "android_media_SyncParams.cpp",
    ],
@@ -98,7 +99,6 @@ cc_library_shared {
    shared_libs: [
        "android.hardware.cas@1.0",  // for CasManager. VNDK???
        "android.hardware.cas.native@1.0",  // CasManager. VNDK???
        "libandroid_runtime",  // ???
        "libaudioclient",  // for use of AudioTrack, AudioSystem. to be removed
        "libbinder",
        "libgui",  // for VideoFrameScheduler
@@ -120,13 +120,9 @@ cc_library_shared {
    header_libs: ["libhardware_headers"],

    static_libs: [
        "libbacktrace",
        "libbase",
        "libc_malloc_debug_backtrace",
        "libcrypto",
        "libcutils",
        "libdexfile",
        "liblzma",
        "libmedia_helper",
        "libmedia_player2_util",
        "libmediadrm",
@@ -135,7 +131,7 @@ cc_library_shared {
        "libmediaplayer2",
        "libmediaplayer2-protos",
        "libmediautils",
        "libnetd_client",
        "libnetd_client",  // for setNetworkForUser
        "libprotobuf-cpp-lite",
        "libstagefright_esds",
        "libstagefright_foundation",
@@ -146,9 +142,6 @@ cc_library_shared {
        "libstagefright_player2",
        "libstagefright_rtsp",
        "libstagefright_timedtext2",
        "libunwindstack",
        "libutilscallstack",
        "libziparchive",
    ],

    group_static_libs: true,
+90 −0
Original line number Diff line number Diff line
/*
 * Copyright 2017, 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.
 */

#include <jni.h>
#include <nativehelper/JNIHelp.h>

#include "android_media_MediaMetricsJNI.h"
#include <media/MediaAnalyticsItem.h>


// Copeid from core/jni/ (libandroid_runtime.so)
namespace android {

// place the attributes into a java PersistableBundle object
jobject MediaMetricsJNI::writeMetricsToBundle(JNIEnv* env, MediaAnalyticsItem *item, jobject mybundle) {

    jclass clazzBundle = env->FindClass("android/os/PersistableBundle");
    if (clazzBundle==NULL) {
        ALOGD("can't find android/os/PersistableBundle");
        return NULL;
    }
    // sometimes the caller provides one for us to fill
    if (mybundle == NULL) {
        // create the bundle
        jmethodID constructID = env->GetMethodID(clazzBundle, "<init>", "()V");
        mybundle = env->NewObject(clazzBundle, constructID);
        if (mybundle == NULL) {
            return NULL;
        }
    }

    // grab methods that we can invoke
    jmethodID setIntID = env->GetMethodID(clazzBundle, "putInt", "(Ljava/lang/String;I)V");
    jmethodID setLongID = env->GetMethodID(clazzBundle, "putLong", "(Ljava/lang/String;J)V");
    jmethodID setDoubleID = env->GetMethodID(clazzBundle, "putDouble", "(Ljava/lang/String;D)V");
    jmethodID setStringID = env->GetMethodID(clazzBundle, "putString", "(Ljava/lang/String;Ljava/lang/String;)V");

    // env, class, method, {parms}
    //env->CallVoidMethod(env, mybundle, setIntID, jstr, jint);

    // iterate through my attributes
    // -- get name, get type, get value
    // -- insert appropriately into the bundle
    for (size_t i = 0 ; i < item->mPropCount; i++ ) {
            MediaAnalyticsItem::Prop *prop = &item->mProps[i];
            // build the key parameter from prop->mName
            jstring keyName = env->NewStringUTF(prop->mName);
            // invoke the appropriate method to insert
            switch (prop->mType) {
                case MediaAnalyticsItem::kTypeInt32:
                    env->CallVoidMethod(mybundle, setIntID,
                                        keyName, (jint) prop->u.int32Value);
                    break;
                case MediaAnalyticsItem::kTypeInt64:
                    env->CallVoidMethod(mybundle, setLongID,
                                        keyName, (jlong) prop->u.int64Value);
                    break;
                case MediaAnalyticsItem::kTypeDouble:
                    env->CallVoidMethod(mybundle, setDoubleID,
                                        keyName, (jdouble) prop->u.doubleValue);
                    break;
                case MediaAnalyticsItem::kTypeCString:
                    env->CallVoidMethod(mybundle, setStringID, keyName,
                                        env->NewStringUTF(prop->u.CStringValue));
                    break;
                default:
                        ALOGE("to_String bad item type: %d for %s",
                              prop->mType, prop->mName);
                        break;
            }
    }

    return mybundle;
}

};  // namespace android
+34 −0
Original line number Diff line number Diff line
/*
 * Copyright 2017, 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.
 */

#ifndef _ANDROID_MEDIA_MEDIAMETRICSJNI_H_
#define _ANDROID_MEDIA_MEDIAMETRICSJNI_H_

#include <jni.h>
#include <nativehelper/JNIHelp.h>
#include <media/MediaAnalyticsItem.h>

// Copeid from core/jni/ (libandroid_runtime.so)
namespace android {

class MediaMetricsJNI {
public:
    static jobject writeMetricsToBundle(JNIEnv* env, MediaAnalyticsItem *item, jobject mybundle);
};

};  // namespace android

#endif //  _ANDROID_MEDIA_MEDIAMETRICSJNI_H_
+13 −55
Original line number Diff line number Diff line
@@ -909,7 +909,7 @@ android_media_MediaPlayer2_getAudioStreamType(JNIEnv *env, jobject thiz)
}

static jboolean
android_media_MediaPlayer2_setParameter(JNIEnv *env, jobject thiz, jint key, jobject java_request)
android_media_MediaPlayer2_setParameter(JNIEnv *env, jobject thiz, jint key, jobject)
{
    ALOGV("setParameter: key %d", key);
    sp<MediaPlayer2> mp = getMediaPlayer(env, thiz);
@@ -918,9 +918,11 @@ android_media_MediaPlayer2_setParameter(JNIEnv *env, jobject thiz, jint key, job
        return false;
    }

    // TODO: parcelForJavaObject() shouldn't be used since it's dependent on
    //       framework's Parcel implementation. This setParameter() is used
    //       only with AudioAttribute. Can this be used as jobject with JAudioTrack?
    return false;
    // TODO: set/getParameter is temporarily disabled to remove android_runtime.so dependency.
    //       Once JAudioTrack migration is done, the AudioAttribute jobject
    //       should be directly passed to AudioTrack without native parcel conversion.
    /*
    Parcel *request = parcelForJavaObject(env, java_request);
    status_t err = mp->setParameter(key, *request);
    if (err == OK) {
@@ -928,6 +930,7 @@ android_media_MediaPlayer2_setParameter(JNIEnv *env, jobject thiz, jint key, job
    } else {
        return false;
    }
    */
}

static jobject
@@ -940,6 +943,11 @@ android_media_MediaPlayer2_getParameter(JNIEnv *env, jobject thiz, jint key)
        return NULL;
    }

    return NULL;
    // TODO: set/getParameter is temporarily disabled to remove android_runtime.so dependency.
    //       Once JAudioTrack migration is done, the AudioAttribute jobject
    //       should be directly passed to AudioTrack without native parcel conversion.
    /*
    jobject jParcel = createJavaParcelObject(env);
    if (jParcel != NULL) {
        Parcel* nativeParcel = parcelForJavaObject(env, jParcel);
@@ -950,6 +958,7 @@ android_media_MediaPlayer2_getParameter(JNIEnv *env, jobject thiz, jint key)
        }
    }
    return jParcel;
    */
}

static void
@@ -1019,55 +1028,6 @@ android_media_MediaPlayer2_invoke(JNIEnv *env, jobject thiz, jbyteArray requestD
    return out;
}

// Sends the new filter to the client.
static jint
android_media_MediaPlayer2_setMetadataFilter(JNIEnv *env, jobject thiz, jobject request)
{
    sp<MediaPlayer2> media_player = getMediaPlayer(env, thiz);
    if (media_player == NULL ) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return UNKNOWN_ERROR;
    }

    Parcel *filter = parcelForJavaObject(env, request);

    if (filter == NULL ) {
        jniThrowException(env, "java/lang/RuntimeException", "Filter is null");
        return UNKNOWN_ERROR;
    }

    return (jint) media_player->setMetadataFilter(*filter);
}

static jboolean
android_media_MediaPlayer2_getMetadata(JNIEnv *env, jobject thiz, jboolean update_only,
                                      jboolean apply_filter, jobject reply)
{
    sp<MediaPlayer2> media_player = getMediaPlayer(env, thiz);
    if (media_player == NULL ) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return JNI_FALSE;
    }

    Parcel *metadata = parcelForJavaObject(env, reply);

    if (metadata == NULL ) {
        jniThrowException(env, "java/lang/RuntimeException", "Reply parcel is null");
        return JNI_FALSE;
    }

    metadata->freeData();
    // On return metadata is positioned at the beginning of the
    // metadata. Note however that the parcel actually starts with the
    // return code so you should not rewind the parcel using
    // setDataPosition(0).
    if (media_player->getMetadata(update_only, apply_filter, metadata) == OK) {
        return JNI_TRUE;
    } else {
        return JNI_FALSE;
    }
}

// This function gets some field IDs, which in turn causes class initialization.
// It is called from a static block in MediaPlayer2, which won't run until the
// first time an instance of this class is used.
@@ -1532,8 +1492,6 @@ static const JNINativeMethod gMethods[] = {
    {"isLooping",           "()Z",                              (void *)android_media_MediaPlayer2_isLooping},
    {"_setVolume",          "(FF)V",                            (void *)android_media_MediaPlayer2_setVolume},
    {"_invoke",             "([B)[B",                           (void *)android_media_MediaPlayer2_invoke},
    {"native_setMetadataFilter", "(Landroid/os/Parcel;)I",      (void *)android_media_MediaPlayer2_setMetadataFilter},
    {"native_getMetadata", "(ZZLandroid/os/Parcel;)Z",          (void *)android_media_MediaPlayer2_getMetadata},
    {"native_init",         "()V",                              (void *)android_media_MediaPlayer2_native_init},
    {"native_setup",        "(Ljava/lang/Object;)V",            (void *)android_media_MediaPlayer2_native_setup},
    {"native_finalize",     "()V",                              (void *)android_media_MediaPlayer2_native_finalize},