From 4d704e86a65749104cee3d8bf7e792011638f99c Mon Sep 17 00:00:00 2001 From: Alexander Capehart Date: Wed, 15 Jan 2025 11:44:29 -0700 Subject: [PATCH] Revert "musikr: bubblewrap jvminputstream" This reverts commit b6d80189ca03b4ae8ab74c42b1c554fb0ffc3713. --- musikr/src/main/cpp/CMakeLists.txt | 1 - musikr/src/main/cpp/JVMInputStream.cpp | 70 +++++++++++--------------- musikr/src/main/cpp/util.cpp | 30 ----------- musikr/src/main/cpp/util.h | 6 --- 4 files changed, 28 insertions(+), 79 deletions(-) delete mode 100644 musikr/src/main/cpp/util.cpp diff --git a/musikr/src/main/cpp/CMakeLists.txt b/musikr/src/main/cpp/CMakeLists.txt index 96c170e70..dd0db4101 100644 --- a/musikr/src/main/cpp/CMakeLists.txt +++ b/musikr/src/main/cpp/CMakeLists.txt @@ -48,7 +48,6 @@ add_library(${CMAKE_PROJECT_NAME} SHARED JVMInputStream.cpp JVMTagMap.cpp JVMMetadataBuilder.cpp - util.cpp ) target_link_options(${CMAKE_PROJECT_NAME} # @Tolriq found that these flags can reduce the size of the linked diff --git a/musikr/src/main/cpp/JVMInputStream.cpp b/musikr/src/main/cpp/JVMInputStream.cpp index f65c3b86a..0ede3272d 100644 --- a/musikr/src/main/cpp/JVMInputStream.cpp +++ b/musikr/src/main/cpp/JVMInputStream.cpp @@ -17,42 +17,32 @@ */ #include "JVMInputStream.h" -#include "util.h" #include // TODO: Handle stream exceptions JVMInputStream::JVMInputStream(JNIEnv *env, jobject inputStream) : env(env), inputStream( inputStream) { - TRY(auto isNativeInputStream = env->IsInstanceOf(inputStream, - env->FindClass("org/oxycblt/musikr/metadata/NativeInputStream"))) - if (!isNativeInputStream) { + if (!env->IsInstanceOf(inputStream, + env->FindClass("org/oxycblt/musikr/metadata/NativeInputStream"))) { throw std::runtime_error("oStream is not an instance of TagLibOStream"); } - TRY(jclass inputStreamClass = env->FindClass( - "org/oxycblt/musikr/metadata/NativeInputStream")); - TRY( - inputStreamReadBlockMethod = env->GetMethodID(inputStreamClass, - "readBlock", "(J)[B")); - TRY( - inputStreamIsOpenMethod = env->GetMethodID(inputStreamClass, - "isOpen", "()Z")); - TRY( - inputStreamSeekFromBeginningMethod = env->GetMethodID( - inputStreamClass, "seekFromBeginning", "(J)V")); - TRY( - inputStreamSeekFromCurrentMethod = env->GetMethodID( - inputStreamClass, "seekFromCurrent", "(J)V")); - TRY( - inputStreamSeekFromEndMethod = env->GetMethodID(inputStreamClass, - "seekFromEnd", "(J)V")); - TRY( - inputStreamTellMethod = env->GetMethodID(inputStreamClass, "tell", - "()J")); - TRY( - inputStreamLengthMethod = env->GetMethodID(inputStreamClass, - "length", "()J")); - TRY(env->DeleteLocalRef(inputStreamClass)); + jclass inputStreamClass = env->FindClass( + "org/oxycblt/musikr/metadata/NativeInputStream"); + inputStreamReadBlockMethod = env->GetMethodID(inputStreamClass, "readBlock", + "(J)[B"); + inputStreamIsOpenMethod = env->GetMethodID(inputStreamClass, "isOpen", + "()Z"); + inputStreamSeekFromBeginningMethod = env->GetMethodID(inputStreamClass, + "seekFromBeginning", "(J)V"); + inputStreamSeekFromCurrentMethod = env->GetMethodID(inputStreamClass, + "seekFromCurrent", "(J)V"); + inputStreamSeekFromEndMethod = env->GetMethodID(inputStreamClass, + "seekFromEnd", "(J)V"); + inputStreamTellMethod = env->GetMethodID(inputStreamClass, "tell", "()J"); + inputStreamLengthMethod = env->GetMethodID(inputStreamClass, "length", + "()J"); + env->DeleteLocalRef(inputStreamClass); } JVMInputStream::~JVMInputStream() { @@ -66,15 +56,13 @@ TagLib::FileName JVMInputStream::name() const { } TagLib::ByteVector JVMInputStream::readBlock(size_t length) { - TRY(auto data = (jbyteArray) env->CallObjectMethod(inputStream, - inputStreamReadBlockMethod, length)); - // Check for an exception - // If we don't do this, data == nullptr and the remaining calls crash. - TRY(jsize dataLength = env->GetArrayLength(data)); - TRY(auto dataBytes = env->GetByteArrayElements(data, nullptr)); + auto data = (jbyteArray) env->CallObjectMethod(inputStream, + inputStreamReadBlockMethod, length); + jsize dataLength = env->GetArrayLength(data); + auto dataBytes = env->GetByteArrayElements(data, nullptr); TagLib::ByteVector byteVector(reinterpret_cast(dataBytes), dataLength); - TRY(env->ReleaseByteArrayElements(data, dataBytes, JNI_ABORT)); + env->ReleaseByteArrayElements(data, dataBytes, JNI_ABORT); return byteVector; } @@ -96,17 +84,15 @@ bool JVMInputStream::readOnly() const { } bool JVMInputStream::isOpen() const { - TRY(auto result = env->CallBooleanMethod(inputStream, inputStreamIsOpenMethod)); - return result; + return env->CallBooleanMethod(inputStream, inputStreamIsOpenMethod); } void JVMInputStream::seek(TagLib::offset_t offset, Position p) { auto joffset = static_cast(std::llround(offset)); switch (p) { case Beginning: - TRY( - env->CallVoidMethod(inputStream, - inputStreamSeekFromBeginningMethod, joffset)); + env->CallVoidMethod(inputStream, inputStreamSeekFromBeginningMethod, + joffset); break; case Current: env->CallVoidMethod(inputStream, inputStreamSeekFromCurrentMethod, @@ -123,12 +109,12 @@ void JVMInputStream::clear() { } TagLib::offset_t JVMInputStream::tell() const { - TRY(jlong jposition = env->CallLongMethod(inputStream, inputStreamTellMethod)); + jlong jposition = env->CallLongMethod(inputStream, inputStreamTellMethod); return static_cast(jposition); } TagLib::offset_t JVMInputStream::length() { - TRY(jlong jlength = env->CallLongMethod(inputStream, inputStreamLengthMethod)); + jlong jlength = env->CallLongMethod(inputStream, inputStreamLengthMethod); return static_cast(jlength); } diff --git a/musikr/src/main/cpp/util.cpp b/musikr/src/main/cpp/util.cpp deleted file mode 100644 index 2a966a7cf..000000000 --- a/musikr/src/main/cpp/util.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2025 Auxio Project - * util.cpp is part of Auxio. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include - -#include "util.h" - -void jni_check(JNIEnv *env) { - if (env->ExceptionCheck()) { - env->ExceptionDescribe(); - env->ExceptionClear(); - throw std::runtime_error( - "An exception occurred in a JNI call, see logcat"); - } -} diff --git a/musikr/src/main/cpp/util.h b/musikr/src/main/cpp/util.h index ec301e51c..ce9ad7255 100644 --- a/musikr/src/main/cpp/util.h +++ b/musikr/src/main/cpp/util.h @@ -28,10 +28,4 @@ #define LOGD(...) \ ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) -void jni_check(JNIEnv *env); - -#define TRY(block) \ - block; \ - jni_check(env); - #endif //AUXIO_UTIL_H