static void wseemann_media_FFmpegMediaMetadataRetriever_setDataSourceFD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length) { __android_log_write(ANDROID_LOG_VERBOSE, LOG_TAG, "setDataSource"); MediaMetadataRetriever* retriever = getRetriever(env, thiz); if (retriever == 0) { jniThrowException(env, "java/lang/IllegalStateException", "No retriever available"); return; } if (!fileDescriptor) { jniThrowException(env, "java/lang/IllegalArgumentException", NULL); return; } int fd = jniGetFDFromFileDescriptor(env, fileDescriptor); if (offset < 0 || length < 0 || fd < 0) { if (offset < 0) { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "negative offset (%lld)", offset); } if (length < 0) { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "negative length (%lld)", length); } if (fd < 0) { __android_log_write(ANDROID_LOG_ERROR, LOG_TAG, "invalid file descriptor"); } jniThrowException(env, "java/lang/IllegalArgumentException", NULL); return; } process_media_retriever_call(env, retriever->setDataSource(fd, offset, length), "java/lang/RuntimeException", "setDataSource failed"); }
static void android_media_MediaMetadataRetriever_setDataSourceFD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length) { ALOGV("setDataSource Fd"); MediaMetadataRetriever* retriever = getRetriever(env, thiz); if (retriever == 0) { jniThrowException(env, "java/lang/IllegalStateException", "No retriever available"); return; } if (!fileDescriptor) { jniThrowException(env, "java/lang/IllegalArgumentException", NULL); return; } int fd = jniGetFDFromFileDescriptor(env, fileDescriptor); if (offset < 0 || length < 0 || fd < 0) { if (offset < 0) { ALOGE("negative offset (%lld)", offset); } if (length < 0) { ALOGE("negative length (%lld)", length); } if (fd < 0) { ALOGE("invalid file descriptor"); } jniThrowException(env, "java/lang/IllegalArgumentException", NULL); return; } process_media_retriever_call(env, retriever->setDataSource(fd, offset, length), "java/lang/RuntimeException", "setDataSource failed"); }
static void android_media_MediaMetadataRetriever_setDataSourceAndHeaders( JNIEnv *env, jobject thiz, jstring path, jobjectArray keys, jobjectArray values) { ALOGV("setDataSource Path"); MediaMetadataRetriever* retriever = getRetriever(env, thiz); if (retriever == 0) { jniThrowException( env, "java/lang/IllegalStateException", "No retriever available"); return; } if (!path) { jniThrowException( env, "java/lang/IllegalArgumentException", "Null pointer"); return; } const char *tmp = env->GetStringUTFChars(path, NULL); if (!tmp) { // OutOfMemoryError exception already thrown return; } String8 pathStr(tmp); env->ReleaseStringUTFChars(path, tmp); tmp = NULL; // Don't let somebody trick us in to reading some random block of memory if (strncmp("mem://", pathStr.string(), 6) == 0) { jniThrowException( env, "java/lang/IllegalArgumentException", "Invalid pathname"); return; } // We build a similar KeyedVector out of it. KeyedVector<String8, String8> headersVector; if (!ConvertKeyValueArraysToKeyedVector( env, keys, values, &headersVector)) { return; } process_media_retriever_call( env, retriever->setDataSource( pathStr.string(), headersVector.size() > 0 ? &headersVector : NULL), "java/lang/RuntimeException", "setDataSource failed"); }
static void wseemann_media_FFmpegMediaMetadataRetriever_setDataSourceAndHeaders( JNIEnv *env, jobject thiz, jstring path, jobjectArray keys, jobjectArray values) { __android_log_write(ANDROID_LOG_VERBOSE, LOG_TAG, "setDataSource"); MediaMetadataRetriever* retriever = getRetriever(env, thiz); if (retriever == 0) { jniThrowException(env, "java/lang/IllegalStateException", "No retriever available"); return; } if (!path) { jniThrowException(env, "java/lang/IllegalArgumentException", "Null pointer"); return; } const char *tmp = env->GetStringUTFChars(path, NULL); if (!tmp) { // OutOfMemoryError exception already thrown return; } // Don't let somebody trick us in to reading some random block of memory if (strncmp("mem://", tmp, 6) == 0) { jniThrowException(env, "java/lang/IllegalArgumentException", "Invalid pathname"); return; } // Workaround for FFmpeg ticket #998 // "must convert mms://... streams to mmsh://... for FFmpeg to work" char *restrict_to = strstr(tmp, "mms://"); if (restrict_to) { strncpy(restrict_to, "mmsh://", 6); puts(tmp); } char *headers = NULL; if (keys && values != NULL) { int keysCount = env->GetArrayLength(keys); int valuesCount = env->GetArrayLength(values); if (keysCount != valuesCount) { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "keys and values arrays have different length"); jniThrowException(env, "java/lang/IllegalArgumentException", NULL); return; } int i = 0; const char *rawString = NULL; char hdrs[2048]; for (i = 0; i < keysCount; i++) { jstring key = (jstring) env->GetObjectArrayElement(keys, i); rawString = env->GetStringUTFChars(key, NULL); strcat(hdrs, rawString); strcat(hdrs, ": "); env->ReleaseStringUTFChars(key, rawString); jstring value = (jstring) env->GetObjectArrayElement(values, i); rawString = env->GetStringUTFChars(value, NULL); strcat(hdrs, rawString); strcat(hdrs, "\r\n"); env->ReleaseStringUTFChars(value, rawString); } headers = &hdrs[0]; } process_media_retriever_call( env, retriever->setDataSource(tmp, headers), "java/lang/IllegalArgumentException", "setDataSource failed"); env->ReleaseStringUTFChars(path, tmp); tmp = NULL; }