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

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

Merge "Remove AndroidRuntime::getJNIEnv() usage from libmedia2_jni"

parents 99966b01 62fbf97b
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
#ifndef _ANDROID_MEDIA_MEDIAMETRICSJNI_H_
#define _ANDROID_MEDIA_MEDIAMETRICSJNI_H_

#include <android_runtime/AndroidRuntime.h>
#include <jni.h>
#include <nativehelper/JNIHelp.h>
#include <media/MediaAnalyticsItem.h>
+8 −8
Original line number Diff line number Diff line
@@ -20,12 +20,12 @@

#include "android_media_Media2DataSource.h"

#include "android_runtime/AndroidRuntime.h"
#include "android_runtime/Log.h"
#include "log/log.h"
#include "jni.h"
#include <nativehelper/JNIHelp.h>

#include <drm/drm_framework_common.h>
#include <mediaplayer2/JavaVMHelper.h>
#include <media/stagefright/foundation/ADebug.h>
#include <nativehelper/ScopedLocalRef.h>

@@ -56,7 +56,7 @@ JMedia2DataSource::JMedia2DataSource(JNIEnv* env, jobject source)
}

JMedia2DataSource::~JMedia2DataSource() {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JNIEnv* env = JavaVMHelper::getJNIEnv();
    env->DeleteGlobalRef(mMedia2DataSourceObj);
    env->DeleteGlobalRef(mByteArrayObj);
}
@@ -75,12 +75,12 @@ ssize_t JMedia2DataSource::readAt(off64_t offset, void *data, size_t size) {
        size = kBufferSize;
    }

    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JNIEnv* env = JavaVMHelper::getJNIEnv();
    jint numread = env->CallIntMethod(mMedia2DataSourceObj, mReadAtMethod,
            (jlong)offset, mByteArrayObj, (jint)0, (jint)size);
    if (env->ExceptionCheck()) {
        ALOGW("An exception occurred in readAt()");
        LOGW_EX(env);
        jniLogException(env, ANDROID_LOG_WARN, LOG_TAG);
        env->ExceptionClear();
        mJavaObjStatus = UNKNOWN_ERROR;
        return -1;
@@ -117,11 +117,11 @@ status_t JMedia2DataSource::getSize(off64_t* size) {
        return OK;
    }

    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JNIEnv* env = JavaVMHelper::getJNIEnv();
    *size = env->CallLongMethod(mMedia2DataSourceObj, mGetSizeMethod);
    if (env->ExceptionCheck()) {
        ALOGW("An exception occurred in getSize()");
        LOGW_EX(env);
        jniLogException(env, ANDROID_LOG_WARN, LOG_TAG);
        env->ExceptionClear();
        // After returning an error, size shouldn't be used by callers.
        *size = UNKNOWN_ERROR;
@@ -142,7 +142,7 @@ status_t JMedia2DataSource::getSize(off64_t* size) {
void JMedia2DataSource::close() {
    Mutex::Autolock lock(mLock);

    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JNIEnv* env = JavaVMHelper::getJNIEnv();
    env->CallVoidMethod(mMedia2DataSourceObj, mCloseMethod);
    // The closed state is effectively the same as an error state.
    mJavaObjStatus = UNKNOWN_ERROR;
+9 −9
Original line number Diff line number Diff line
@@ -18,14 +18,14 @@
#define LOG_TAG "Media2HTTPConnection-JNI"
#include <utils/Log.h>

#include <mediaplayer2/JavaVMHelper.h>
#include <media/stagefright/foundation/ADebug.h>
#include <nativehelper/ScopedLocalRef.h>

#include "android_media_Media2HTTPConnection.h"
#include "android_util_Binder.h"

#include "android_runtime/AndroidRuntime.h"
#include "android_runtime/Log.h"
#include "log/log.h"
#include "jni.h"
#include <nativehelper/JNIHelp.h>

@@ -84,7 +84,7 @@ JMedia2HTTPConnection::JMedia2HTTPConnection(JNIEnv *env, jobject thiz) {
}

JMedia2HTTPConnection::~JMedia2HTTPConnection() {
    JNIEnv *env = AndroidRuntime::getJNIEnv();
    JNIEnv *env = JavaVMHelper::getJNIEnv();
    env->DeleteGlobalRef(mMedia2HTTPConnectionObj);
    env->DeleteGlobalRef(mByteArrayObj);
}
@@ -101,7 +101,7 @@ bool JMedia2HTTPConnection::connect(
        }
    }

    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JNIEnv* env = JavaVMHelper::getJNIEnv();
    jstring juri = env->NewStringUTF(uri);
    jstring jheaders = env->NewStringUTF(tmp.string());

@@ -115,12 +115,12 @@ bool JMedia2HTTPConnection::connect(
}

void JMedia2HTTPConnection::disconnect() {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JNIEnv* env = JavaVMHelper::getJNIEnv();
    env->CallVoidMethod(mMedia2HTTPConnectionObj, mDisconnectMethod);
}

ssize_t JMedia2HTTPConnection::readAt(off64_t offset, void *data, size_t size) {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JNIEnv* env = JavaVMHelper::getJNIEnv();

    if (size > kBufferSize) {
        size = kBufferSize;
@@ -141,12 +141,12 @@ ssize_t JMedia2HTTPConnection::readAt(off64_t offset, void *data, size_t size) {
}

off64_t JMedia2HTTPConnection::getSize() {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JNIEnv* env = JavaVMHelper::getJNIEnv();
    return (off64_t)(env->CallLongMethod(mMedia2HTTPConnectionObj, mGetSizeMethod));
}

status_t JMedia2HTTPConnection::getMIMEType(String8 *mimeType) {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JNIEnv* env = JavaVMHelper::getJNIEnv();
    jstring jmime = (jstring)env->CallObjectMethod(mMedia2HTTPConnectionObj, mGetMIMETypeMethod);
    jboolean flag = env->ExceptionCheck();
    if (flag) {
@@ -165,7 +165,7 @@ status_t JMedia2HTTPConnection::getMIMEType(String8 *mimeType) {
}

status_t JMedia2HTTPConnection::getUri(String8 *uri) {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JNIEnv* env = JavaVMHelper::getJNIEnv();
    jstring juri = (jstring)env->CallObjectMethod(mMedia2HTTPConnectionObj, mGetUriMethod);
    jboolean flag = env->ExceptionCheck();
    if (flag) {
+4 −4
Original line number Diff line number Diff line
@@ -21,11 +21,11 @@
#include "android_media_Media2HTTPConnection.h"
#include "android_media_Media2HTTPService.h"

#include "android_runtime/AndroidRuntime.h"
#include "android_runtime/Log.h"
#include "log/log.h"
#include "jni.h"
#include <nativehelper/JNIHelp.h>

#include <mediaplayer2/JavaVMHelper.h>
#include <media/stagefright/foundation/ADebug.h>
#include <nativehelper/ScopedLocalRef.h>

@@ -46,12 +46,12 @@ JMedia2HTTPService::JMedia2HTTPService(JNIEnv *env, jobject thiz) {
}

JMedia2HTTPService::~JMedia2HTTPService() {
    JNIEnv *env = AndroidRuntime::getJNIEnv();
    JNIEnv *env = JavaVMHelper::getJNIEnv();
    env->DeleteGlobalRef(mMedia2HTTPServiceObj);
}

sp<MediaHTTPConnection> JMedia2HTTPService::makeHTTPConnection() {
    JNIEnv* env = AndroidRuntime::getJNIEnv();
    JNIEnv* env = JavaVMHelper::getJNIEnv();
    jobject media2HTTPConnectionObj =
        env->CallObjectMethod(mMedia2HTTPServiceObj, mMakeHTTPConnectionMethod);

+8 −6
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <media/stagefright/Utils.h>
#include <media/stagefright/foundation/ByteUtils.h>  // for FOURCC definition
#include <mediaplayer2/JAudioTrack.h>
#include <mediaplayer2/JavaVMHelper.h>
#include <mediaplayer2/mediaplayer2.h>
#include <stdio.h>
#include <assert.h>
@@ -39,7 +40,7 @@
#include "jni.h"
#include <nativehelper/JNIHelp.h>
#include "android/native_window_jni.h"
#include "android_runtime/Log.h"
#include "log/log.h"
#include "utils/Errors.h"  // for status_t
#include "utils/KeyedVector.h"
#include "utils/String8.h"
@@ -184,14 +185,14 @@ JNIMediaPlayer2Listener::JNIMediaPlayer2Listener(JNIEnv* env, jobject thiz, jobj
JNIMediaPlayer2Listener::~JNIMediaPlayer2Listener()
{
    // remove global references
    JNIEnv *env = AndroidRuntime::getJNIEnv();
    JNIEnv *env = JavaVMHelper::getJNIEnv();
    env->DeleteGlobalRef(mObject);
    env->DeleteGlobalRef(mClass);
}

void JNIMediaPlayer2Listener::notify(int64_t srcId, int msg, int ext1, int ext2, const Parcel *obj)
{
    JNIEnv *env = AndroidRuntime::getJNIEnv();
    JNIEnv *env = JavaVMHelper::getJNIEnv();
    if (obj && obj->dataSize() > 0) {
        jobject jParcel = createJavaParcelObject(env);
        if (jParcel != NULL) {
@@ -207,7 +208,7 @@ void JNIMediaPlayer2Listener::notify(int64_t srcId, int msg, int ext1, int ext2,
    }
    if (env->ExceptionCheck()) {
        ALOGW("An exception occurred while notifying an event.");
        LOGW_EX(env);
        jniLogException(env, ANDROID_LOG_WARN, LOG_TAG);
        env->ExceptionClear();
    }
}
@@ -1539,8 +1540,7 @@ static const JNINativeMethod gMethods[] = {
// This function only registers the native methods
static int register_android_media_MediaPlayer2Impl(JNIEnv *env)
{
    return AndroidRuntime::registerNativeMethods(env,
                "android/media/MediaPlayer2Impl", gMethods, NELEM(gMethods));
    return jniRegisterNativeMethods(env, "android/media/MediaPlayer2Impl", gMethods, NELEM(gMethods));
}

jint JNI_OnLoad(JavaVM* vm, void* /* reserved */)
@@ -1559,6 +1559,8 @@ jint JNI_OnLoad(JavaVM* vm, void* /* reserved */)
        goto bail;
    }

    JavaVMHelper::setJavaVM(vm);

    /* success -- return valid version number */
    result = JNI_VERSION_1_4;