summaryrefslogtreecommitdiffstats
path: root/media/jni/android_media_MediaMetadataRetriever.cpp
diff options
context:
space:
mode:
authorJames Dong <jdong@google.com>2011-05-05 12:50:04 -0700
committerJames Dong <jdong@google.com>2011-05-05 15:11:23 -0700
commit79f407cc6c5ae34fc6f04d52fd034b49d1f002c4 (patch)
treed416e43ca5458a0292dfcc515eabdb15e1304c02 /media/jni/android_media_MediaMetadataRetriever.cpp
parent8b1b0548b21e6d8fdfb769d9064cd2ff4232bc3d (diff)
downloadframeworks_base-79f407cc6c5ae34fc6f04d52fd034b49d1f002c4.zip
frameworks_base-79f407cc6c5ae34fc6f04d52fd034b49d1f002c4.tar.gz
frameworks_base-79f407cc6c5ae34fc6f04d52fd034b49d1f002c4.tar.bz2
Refactor to share code between MediaPlayer and MediaMetadataRetriever JNI
Change-Id: Ib847213f566dee79126d7c14d00750a9a8dedeb9
Diffstat (limited to 'media/jni/android_media_MediaMetadataRetriever.cpp')
-rw-r--r--media/jni/android_media_MediaMetadataRetriever.cpp40
1 files changed, 6 insertions, 34 deletions
diff --git a/media/jni/android_media_MediaMetadataRetriever.cpp b/media/jni/android_media_MediaMetadataRetriever.cpp
index 4a2a4af..73aea2a 100644
--- a/media/jni/android_media_MediaMetadataRetriever.cpp
+++ b/media/jni/android_media_MediaMetadataRetriever.cpp
@@ -28,6 +28,7 @@
#include "jni.h"
#include "JNIHelp.h"
#include "android_runtime/AndroidRuntime.h"
+#include "android_media_Utils.h"
using namespace android;
@@ -108,14 +109,6 @@ android_media_MediaMetadataRetriever_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;
- }
// Don't let somebody trick us in to reading some random block of memory
if (strncmp("mem://", pathStr.string(), 6) == 0) {
jniThrowException(
@@ -125,41 +118,20 @@ android_media_MediaMetadataRetriever_setDataSourceAndHeaders(
// We build a similar KeyedVector out of it.
KeyedVector<String8, String8> headersVector;
- for (int i = 0; i < nKeyValuePairs; ++i) {
- // No need to check on the ArrayIndexOutOfBoundsException, since
- // it won't happen here.
- jstring key = (jstring) env->GetObjectArrayElement(keys, i);
- jstring value = (jstring) env->GetObjectArrayElement(values, i);
-
- const char* keyStr = env->GetStringUTFChars(key, NULL);
- if (!keyStr) { // OutOfMemoryError
- return;
- }
-
- const char* valueStr = env->GetStringUTFChars(value, NULL);
- if (!valueStr) { // OutOfMemoryError
- env->ReleaseStringUTFChars(key, keyStr);
- return;
- }
-
- headersVector.add(String8(keyStr), String8(valueStr));
-
- env->ReleaseStringUTFChars(key, keyStr);
- env->ReleaseStringUTFChars(value, valueStr);
- env->DeleteLocalRef(key);
- env->DeleteLocalRef(value);
-
+ if (!ConvertKeyValueArraysToKeyedVector(
+ env, keys, values, &headersVector)) {
+ return;
}
-
process_media_retriever_call(
env,
retriever->setDataSource(
- pathStr.string(), nKeyValuePairs > 0 ? &headersVector : NULL),
+ pathStr.string(), headersVector.size() > 0 ? &headersVector : NULL),
"java/lang/RuntimeException",
"setDataSource failed");
}
+
static void android_media_MediaMetadataRetriever_setDataSource(
JNIEnv *env, jobject thiz, jstring path) {
android_media_MediaMetadataRetriever_setDataSourceAndHeaders(