diff options
Diffstat (limited to 'media/jni/android_media_MediaPlayer.cpp')
-rw-r--r-- | media/jni/android_media_MediaPlayer.cpp | 38 |
1 files changed, 6 insertions, 32 deletions
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp index ad744dc..b03aa38 100644 --- a/media/jni/android_media_MediaPlayer.cpp +++ b/media/jni/android_media_MediaPlayer.cpp @@ -33,6 +33,8 @@ #include "utils/Errors.h" // for status_t #include "utils/KeyedVector.h" #include "utils/String8.h" +#include "android_media_Utils.h" + #include "android_util_Binder.h" #include <binder/Parcel.h> #include <gui/SurfaceTexture.h> @@ -209,46 +211,18 @@ android_media_MediaPlayer_setDataSourceAndHeaders( env->ReleaseStringUTFChars(path, tmp); tmp = NULL; - int nKeyValuePairs = env->GetArrayLength(keys); - if (nKeyValuePairs != env->GetArrayLength(values)) { - LOGE("keys and values have different length: %d <-> %d", - nKeyValuePairs, env->GetArrayLength(values)); - jniThrowException(env, "java/lang/IllegalArgumentException", NULL); - return; - } - // We build a KeyedVector out of the key and val arrays KeyedVector<String8, String8> headersVector; - for (int i = 0; i < nKeyValuePairs; ++i) { - // No need to check ArrayIndexOutOfBoundsException, since we - // know it won't happen here. - jstring key = (jstring) env->GetObjectArrayElement(keys, i); - jstring val = (jstring) env->GetObjectArrayElement(values, i); - - const char* keyStr = env->GetStringUTFChars(key, NULL); - if (!keyStr) { // OutOfMemoryError - return; - } - - const char* valueStr = env->GetStringUTFChars(val, NULL); - if (!valueStr) { // OutOfMemoryError - env->ReleaseStringUTFChars(key, keyStr); - return; - } - - headersVector.add(String8(keyStr), String8(valueStr)); - - env->ReleaseStringUTFChars(key, keyStr); - env->ReleaseStringUTFChars(val, valueStr); - env->DeleteLocalRef(key); - env->DeleteLocalRef(val); + if (!ConvertKeyValueArraysToKeyedVector( + env, keys, values, &headersVector)) { + return; } LOGV("setDataSource: path %s", pathStr); status_t opStatus = mp->setDataSource( pathStr, - nKeyValuePairs > 0? &headersVector : NULL); + headersVector.size() > 0? &headersVector : NULL); process_media_player_call( env, thiz, opStatus, "java/io/IOException", |