#include "utils/Log.h"
#include <media/mediaplayer.h>
+#include <media/IMediaHTTPService.h>
#include <media/MediaPlayerInterface.h>
#include <stdio.h>
#include <assert.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
+#include "android_util_Binder.h"
// ----------------------------------------------------------------------------
using namespace android;
static sp<MediaPlayer> getMediaPlayer(JNIEnv* env, jobject thiz)
{
Mutex::Autolock l(sLock);
- MediaPlayer* const p = (MediaPlayer*)env->GetIntField(thiz, fields.context);
+ MediaPlayer* const p = (MediaPlayer*)env->GetLongField(thiz, fields.context);
return sp<MediaPlayer>(p);
}
static sp<MediaPlayer> setMediaPlayer(JNIEnv* env, jobject thiz, const sp<MediaPlayer>& player)
{
Mutex::Autolock l(sLock);
- sp<MediaPlayer> old = (MediaPlayer*)env->GetIntField(thiz, fields.context);
+ sp<MediaPlayer> old = (MediaPlayer*)env->GetLongField(thiz, fields.context);
if (player.get()) {
player->incStrong((void*)setMediaPlayer);
}
if (old != 0) {
old->decStrong((void*)setMediaPlayer);
}
- env->SetIntField(thiz, fields.context, (int)player.get());
+ env->SetLongField(thiz, fields.context, (jlong)player.get());
return old;
}
static void
android_media_MediaPlayer_setDataSourceAndHeaders(
- JNIEnv *env, jobject thiz, jstring path,
+ JNIEnv *env, jobject thiz, jobject httpServiceBinderObj, jstring path,
jobjectArray keys, jobjectArray values) {
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
return;
}
+ sp<IMediaHTTPService> httpService;
+ if (httpServiceBinderObj != NULL) {
+ sp<IBinder> binder = ibinderForJavaObject(env, httpServiceBinderObj);
+ httpService = interface_cast<IMediaHTTPService>(binder);
+ }
+
status_t opStatus =
mp->setDataSource(
+ httpService,
pathStr,
headersVector.size() > 0? &headersVector : NULL);
static sp<IGraphicBufferProducer>
getVideoSurfaceTexture(JNIEnv* env, jobject thiz) {
- IGraphicBufferProducer * const p = (IGraphicBufferProducer*)env->GetIntField(thiz, fields.surface_texture);
+ IGraphicBufferProducer * const p = (IGraphicBufferProducer*)env->GetLongField(thiz, fields.surface_texture);
return sp<IGraphicBufferProducer>(p);
}
}
}
- env->SetIntField(thiz, fields.surface_texture, (int)new_st.get());
+ env->SetLongField(thiz, fields.surface_texture, (jlong)new_st.get());
// This will fail if the media player has not been initialized yet. This
// can be the case if setDisplay() on MediaPlayer.java has been called
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
if (mp == NULL ) {
jniThrowException(env, "java/lang/IllegalStateException", NULL);
- return false;
+ return JNI_FALSE;
}
const jboolean is_playing = mp->isPlaying();
}
static void
-android_media_MediaPlayer_seekTo(JNIEnv *env, jobject thiz, int msec)
+android_media_MediaPlayer_seekTo(JNIEnv *env, jobject thiz, jint msec)
{
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
if (mp == NULL ) {
process_media_player_call( env, thiz, mp->seekTo(msec), NULL, NULL );
}
-static int
+static jint
android_media_MediaPlayer_getVideoWidth(JNIEnv *env, jobject thiz)
{
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
w = 0;
}
ALOGV("getVideoWidth: %d", w);
- return w;
+ return (jint) w;
}
-static int
+static jint
android_media_MediaPlayer_getVideoHeight(JNIEnv *env, jobject thiz)
{
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
h = 0;
}
ALOGV("getVideoHeight: %d", h);
- return h;
+ return (jint) h;
}
-static int
+static jint
android_media_MediaPlayer_getCurrentPosition(JNIEnv *env, jobject thiz)
{
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
int msec;
process_media_player_call( env, thiz, mp->getCurrentPosition(&msec), NULL, NULL );
ALOGV("getCurrentPosition: %d (msec)", msec);
- return msec;
+ return (jint) msec;
}
-static int
+static jint
android_media_MediaPlayer_getDuration(JNIEnv *env, jobject thiz)
{
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
int msec;
process_media_player_call( env, thiz, mp->getDuration(&msec), NULL, NULL );
ALOGV("getDuration: %d (msec)", msec);
- return msec;
+ return (jint) msec;
}
static void
}
static void
-android_media_MediaPlayer_setAudioStreamType(JNIEnv *env, jobject thiz, int streamtype)
+android_media_MediaPlayer_setAudioStreamType(JNIEnv *env, jobject thiz, jint streamtype)
{
ALOGV("setAudioStreamType: %d", streamtype);
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
process_media_player_call( env, thiz, mp->setAudioStreamType((audio_stream_type_t) streamtype) , NULL, NULL );
}
+static jint
+android_media_MediaPlayer_getAudioStreamType(JNIEnv *env, jobject thiz)
+{
+ sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
+ if (mp == NULL ) {
+ jniThrowException(env, "java/lang/IllegalStateException", NULL);
+ return 0;
+ }
+ audio_stream_type_t streamtype;
+ process_media_player_call( env, thiz, mp->getAudioStreamType(&streamtype), NULL, NULL );
+ ALOGV("getAudioStreamType: %d (streamtype)", streamtype);
+ return (jint) streamtype;
+}
+
+static jboolean
+android_media_MediaPlayer_setParameter(JNIEnv *env, jobject thiz, jint key, jobject java_request)
+{
+ ALOGV("setParameter: key %d", key);
+ sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
+ if (mp == NULL ) {
+ jniThrowException(env, "java/lang/IllegalStateException", NULL);
+ return false;
+ }
+
+ Parcel *request = parcelForJavaObject(env, java_request);
+ status_t err = mp->setParameter(key, *request);
+ if (err == OK) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
static void
android_media_MediaPlayer_setLooping(JNIEnv *env, jobject thiz, jboolean looping)
{
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
if (mp == NULL ) {
jniThrowException(env, "java/lang/IllegalStateException", NULL);
- return false;
+ return JNI_FALSE;
}
- return mp->isLooping();
+ return mp->isLooping() ? JNI_TRUE : JNI_FALSE;
}
static void
-android_media_MediaPlayer_setVolume(JNIEnv *env, jobject thiz, float leftVolume, float rightVolume)
+android_media_MediaPlayer_setVolume(JNIEnv *env, jobject thiz, jfloat leftVolume, jfloat rightVolume)
{
- ALOGV("setVolume: left %f right %f", leftVolume, rightVolume);
+ ALOGV("setVolume: left %f right %f", (float) leftVolume, (float) rightVolume);
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
if (mp == NULL ) {
jniThrowException(env, "java/lang/IllegalStateException", NULL);
return;
}
- process_media_player_call( env, thiz, mp->setVolume(leftVolume, rightVolume), NULL, NULL );
+ process_media_player_call( env, thiz, mp->setVolume((float) leftVolume, (float) rightVolume), NULL, NULL );
}
// Sends the request and reply parcels to the media player via the
// Don't use process_media_player_call which use the async loop to
// report errors, instead returns the status.
- return media_player->invoke(*request, reply);
+ return (jint) media_player->invoke(*request, reply);
}
// Sends the new filter to the client.
return UNKNOWN_ERROR;
}
- return media_player->setMetadataFilter(*filter);
+ return (jint) media_player->setMetadataFilter(*filter);
}
static jboolean
sp<MediaPlayer> media_player = getMediaPlayer(env, thiz);
if (media_player == NULL ) {
jniThrowException(env, "java/lang/IllegalStateException", NULL);
- return false;
+ return JNI_FALSE;
}
Parcel *metadata = parcelForJavaObject(env, reply);
if (metadata == NULL ) {
jniThrowException(env, "java/lang/RuntimeException", "Reply parcel is null");
- return false;
+ return JNI_FALSE;
}
metadata->freeData();
// metadata. Note however that the parcel actually starts with the
// return code so you should not rewind the parcel using
// setDataPosition(0).
- return media_player->getMetadata(update_only, apply_filter, metadata) == OK;
+ 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.
return;
}
- fields.context = env->GetFieldID(clazz, "mNativeContext", "I");
+ fields.context = env->GetFieldID(clazz, "mNativeContext", "J");
if (fields.context == NULL) {
return;
}
return;
}
- fields.surface_texture = env->GetFieldID(clazz, "mNativeSurfaceTexture", "I");
+ fields.surface_texture = env->GetFieldID(clazz, "mNativeSurfaceTexture", "J");
if (fields.surface_texture == NULL) {
return;
}
- clazz = env->FindClass("android/net/ProxyProperties");
+ clazz = env->FindClass("android/net/ProxyInfo");
if (clazz == NULL) {
return;
}
env->GetMethodID(clazz, "getPort", "()I");
fields.proxyConfigGetExclusionList =
- env->GetMethodID(clazz, "getExclusionList", "()Ljava/lang/String;");
+ env->GetMethodID(clazz, "getExclusionListAsString", "()Ljava/lang/String;");
}
static void
return 0;
}
- return mp->getAudioSessionId();
+ return (jint) mp->getAudioSessionId();
}
static void
}
static jint
-android_media_MediaPlayer_pullBatteryData(JNIEnv *env, jobject thiz, jobject java_reply)
+android_media_MediaPlayer_pullBatteryData(
+ JNIEnv *env, jobject /* thiz */, jobject java_reply)
{
sp<IBinder> binder = defaultServiceManager()->getService(String16("media.player"));
sp<IMediaPlayerService> service = interface_cast<IMediaPlayerService>(binder);
Parcel *reply = parcelForJavaObject(env, java_reply);
- return service->pullBatteryData(reply);
+ return (jint) service->pullBatteryData(reply);
}
static jint
jniThrowException(env, "java/lang/IllegalStateException", NULL);
}
- return ret;
+ return (jint) ret;
}
static void
;
}
-static void
-android_media_MediaPlayer_updateProxyConfig(
- JNIEnv *env, jobject thiz, jobject proxyProps)
-{
- ALOGV("updateProxyConfig");
- sp<MediaPlayer> thisplayer = getMediaPlayer(env, thiz);
- if (thisplayer == NULL) {
- return;
- }
-
- if (proxyProps == NULL) {
- thisplayer->updateProxyConfig(
- NULL /* host */, 0 /* port */, NULL /* exclusionList */);
- } else {
- jstring hostObj = (jstring)env->CallObjectMethod(
- proxyProps, fields.proxyConfigGetHost);
-
- const char *host = env->GetStringUTFChars(hostObj, NULL);
-
- int port = env->CallIntMethod(proxyProps, fields.proxyConfigGetPort);
-
- jstring exclusionListObj = (jstring)env->CallObjectMethod(
- proxyProps, fields.proxyConfigGetExclusionList);
-
- const char *exclusionList =
- env->GetStringUTFChars(exclusionListObj, NULL);
-
- if (host != NULL && exclusionListObj != NULL) {
- thisplayer->updateProxyConfig(host, port, exclusionList);
- }
-
- if (exclusionList != NULL) {
- env->ReleaseStringUTFChars(exclusionListObj, exclusionList);
- exclusionList = NULL;
- }
-
- if (host != NULL) {
- env->ReleaseStringUTFChars(hostObj, host);
- host = NULL;
- }
- }
-}
-
// ----------------------------------------------------------------------------
static JNINativeMethod gMethods[] = {
{
- "_setDataSource",
- "(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)V",
+ "nativeSetDataSource",
+ "(Landroid/os/IBinder;Ljava/lang/String;[Ljava/lang/String;"
+ "[Ljava/lang/String;)V",
(void *)android_media_MediaPlayer_setDataSourceAndHeaders
},
{"_setDataSource", "(Ljava/io/FileDescriptor;JJ)V", (void *)android_media_MediaPlayer_setDataSourceFD},
{"_setVideoSurface", "(Landroid/view/Surface;)V", (void *)android_media_MediaPlayer_setVideoSurface},
- {"prepare", "()V", (void *)android_media_MediaPlayer_prepare},
+ {"_prepare", "()V", (void *)android_media_MediaPlayer_prepare},
{"prepareAsync", "()V", (void *)android_media_MediaPlayer_prepareAsync},
{"_start", "()V", (void *)android_media_MediaPlayer_start},
{"_stop", "()V", (void *)android_media_MediaPlayer_stop},
{"getDuration", "()I", (void *)android_media_MediaPlayer_getDuration},
{"_release", "()V", (void *)android_media_MediaPlayer_release},
{"_reset", "()V", (void *)android_media_MediaPlayer_reset},
- {"setAudioStreamType", "(I)V", (void *)android_media_MediaPlayer_setAudioStreamType},
+ {"_setAudioStreamType", "(I)V", (void *)android_media_MediaPlayer_setAudioStreamType},
+ {"_getAudioStreamType", "()I", (void *)android_media_MediaPlayer_getAudioStreamType},
+ {"setParameter", "(ILandroid/os/Parcel;)Z", (void *)android_media_MediaPlayer_setParameter},
{"setLooping", "(Z)V", (void *)android_media_MediaPlayer_setLooping},
{"isLooping", "()Z", (void *)android_media_MediaPlayer_isLooping},
- {"setVolume", "(FF)V", (void *)android_media_MediaPlayer_setVolume},
+ {"_setVolume", "(FF)V", (void *)android_media_MediaPlayer_setVolume},
{"native_invoke", "(Landroid/os/Parcel;Landroid/os/Parcel;)I",(void *)android_media_MediaPlayer_invoke},
{"native_setMetadataFilter", "(Landroid/os/Parcel;)I", (void *)android_media_MediaPlayer_setMetadataFilter},
{"native_getMetadata", "(ZZLandroid/os/Parcel;)Z", (void *)android_media_MediaPlayer_getMetadata},
{"native_finalize", "()V", (void *)android_media_MediaPlayer_native_finalize},
{"getAudioSessionId", "()I", (void *)android_media_MediaPlayer_get_audio_session_id},
{"setAudioSessionId", "(I)V", (void *)android_media_MediaPlayer_set_audio_session_id},
- {"setAuxEffectSendLevel", "(F)V", (void *)android_media_MediaPlayer_setAuxEffectSendLevel},
+ {"_setAuxEffectSendLevel", "(F)V", (void *)android_media_MediaPlayer_setAuxEffectSendLevel},
{"attachAuxEffect", "(I)V", (void *)android_media_MediaPlayer_attachAuxEffect},
{"native_pullBatteryData", "(Landroid/os/Parcel;)I", (void *)android_media_MediaPlayer_pullBatteryData},
{"native_setRetransmitEndpoint", "(Ljava/lang/String;I)I", (void *)android_media_MediaPlayer_setRetransmitEndpoint},
{"setNextMediaPlayer", "(Landroid/media/MediaPlayer;)V", (void *)android_media_MediaPlayer_setNextMediaPlayer},
- {"updateProxyConfig", "(Landroid/net/ProxyProperties;)V", (void *)android_media_MediaPlayer_updateProxyConfig},
};
static const char* const kClassPathName = "android/media/MediaPlayer";
extern int register_android_media_MediaCodec(JNIEnv *env);
extern int register_android_media_MediaExtractor(JNIEnv *env);
extern int register_android_media_MediaCodecList(JNIEnv *env);
+extern int register_android_media_MediaHTTPConnection(JNIEnv *env);
extern int register_android_media_MediaMetadataRetriever(JNIEnv *env);
extern int register_android_media_MediaMuxer(JNIEnv *env);
extern int register_android_media_MediaRecorder(JNIEnv *env);
extern int register_android_mtp_MtpDevice(JNIEnv *env);
extern int register_android_mtp_MtpServer(JNIEnv *env);
-jint JNI_OnLoad(JavaVM* vm, void* reserved)
+jint JNI_OnLoad(JavaVM* vm, void* /* reserved */)
{
JNIEnv* env = NULL;
jint result = -1;
goto bail;
}
+ if (register_android_media_MediaHTTPConnection(env) < 0) {
+ ALOGE("ERROR: MediaHTTPConnection native registration failed");
+ goto bail;
+ }
+
/* success -- return valid version number */
result = JNI_VERSION_1_4;