Revert "musikr: bubblewrap jvminputstream"

This reverts commit b6d80189ca.
This commit is contained in:
Alexander Capehart 2025-01-15 11:44:29 -07:00
parent ad2ec5a655
commit 4d704e86a6
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
4 changed files with 28 additions and 79 deletions

View file

@ -48,7 +48,6 @@ add_library(${CMAKE_PROJECT_NAME} SHARED
JVMInputStream.cpp JVMInputStream.cpp
JVMTagMap.cpp JVMTagMap.cpp
JVMMetadataBuilder.cpp JVMMetadataBuilder.cpp
util.cpp
) )
target_link_options(${CMAKE_PROJECT_NAME} target_link_options(${CMAKE_PROJECT_NAME}
# @Tolriq found that these flags can reduce the size of the linked # @Tolriq found that these flags can reduce the size of the linked

View file

@ -17,42 +17,32 @@
*/ */
#include "JVMInputStream.h" #include "JVMInputStream.h"
#include "util.h"
#include <cmath> #include <cmath>
// TODO: Handle stream exceptions // TODO: Handle stream exceptions
JVMInputStream::JVMInputStream(JNIEnv *env, jobject inputStream) : env(env), inputStream( JVMInputStream::JVMInputStream(JNIEnv *env, jobject inputStream) : env(env), inputStream(
inputStream) { inputStream) {
TRY(auto isNativeInputStream = env->IsInstanceOf(inputStream, if (!env->IsInstanceOf(inputStream,
env->FindClass("org/oxycblt/musikr/metadata/NativeInputStream"))) env->FindClass("org/oxycblt/musikr/metadata/NativeInputStream"))) {
if (!isNativeInputStream) {
throw std::runtime_error("oStream is not an instance of TagLibOStream"); throw std::runtime_error("oStream is not an instance of TagLibOStream");
} }
TRY(jclass inputStreamClass = env->FindClass( jclass inputStreamClass = env->FindClass(
"org/oxycblt/musikr/metadata/NativeInputStream")); "org/oxycblt/musikr/metadata/NativeInputStream");
TRY( inputStreamReadBlockMethod = env->GetMethodID(inputStreamClass, "readBlock",
inputStreamReadBlockMethod = env->GetMethodID(inputStreamClass, "(J)[B");
"readBlock", "(J)[B")); inputStreamIsOpenMethod = env->GetMethodID(inputStreamClass, "isOpen",
TRY( "()Z");
inputStreamIsOpenMethod = env->GetMethodID(inputStreamClass, inputStreamSeekFromBeginningMethod = env->GetMethodID(inputStreamClass,
"isOpen", "()Z")); "seekFromBeginning", "(J)V");
TRY( inputStreamSeekFromCurrentMethod = env->GetMethodID(inputStreamClass,
inputStreamSeekFromBeginningMethod = env->GetMethodID( "seekFromCurrent", "(J)V");
inputStreamClass, "seekFromBeginning", "(J)V"));
TRY(
inputStreamSeekFromCurrentMethod = env->GetMethodID(
inputStreamClass, "seekFromCurrent", "(J)V"));
TRY(
inputStreamSeekFromEndMethod = env->GetMethodID(inputStreamClass, inputStreamSeekFromEndMethod = env->GetMethodID(inputStreamClass,
"seekFromEnd", "(J)V")); "seekFromEnd", "(J)V");
TRY( inputStreamTellMethod = env->GetMethodID(inputStreamClass, "tell", "()J");
inputStreamTellMethod = env->GetMethodID(inputStreamClass, "tell", inputStreamLengthMethod = env->GetMethodID(inputStreamClass, "length",
"()J")); "()J");
TRY( env->DeleteLocalRef(inputStreamClass);
inputStreamLengthMethod = env->GetMethodID(inputStreamClass,
"length", "()J"));
TRY(env->DeleteLocalRef(inputStreamClass));
} }
JVMInputStream::~JVMInputStream() { JVMInputStream::~JVMInputStream() {
@ -66,15 +56,13 @@ TagLib::FileName JVMInputStream::name() const {
} }
TagLib::ByteVector JVMInputStream::readBlock(size_t length) { TagLib::ByteVector JVMInputStream::readBlock(size_t length) {
TRY(auto data = (jbyteArray) env->CallObjectMethod(inputStream, auto data = (jbyteArray) env->CallObjectMethod(inputStream,
inputStreamReadBlockMethod, length)); inputStreamReadBlockMethod, length);
// Check for an exception jsize dataLength = env->GetArrayLength(data);
// If we don't do this, data == nullptr and the remaining calls crash. auto dataBytes = env->GetByteArrayElements(data, nullptr);
TRY(jsize dataLength = env->GetArrayLength(data));
TRY(auto dataBytes = env->GetByteArrayElements(data, nullptr));
TagLib::ByteVector byteVector(reinterpret_cast<const char*>(dataBytes), TagLib::ByteVector byteVector(reinterpret_cast<const char*>(dataBytes),
dataLength); dataLength);
TRY(env->ReleaseByteArrayElements(data, dataBytes, JNI_ABORT)); env->ReleaseByteArrayElements(data, dataBytes, JNI_ABORT);
return byteVector; return byteVector;
} }
@ -96,17 +84,15 @@ bool JVMInputStream::readOnly() const {
} }
bool JVMInputStream::isOpen() const { bool JVMInputStream::isOpen() const {
TRY(auto result = env->CallBooleanMethod(inputStream, inputStreamIsOpenMethod)); return env->CallBooleanMethod(inputStream, inputStreamIsOpenMethod);
return result;
} }
void JVMInputStream::seek(TagLib::offset_t offset, Position p) { void JVMInputStream::seek(TagLib::offset_t offset, Position p) {
auto joffset = static_cast<jlong>(std::llround(offset)); auto joffset = static_cast<jlong>(std::llround(offset));
switch (p) { switch (p) {
case Beginning: case Beginning:
TRY( env->CallVoidMethod(inputStream, inputStreamSeekFromBeginningMethod,
env->CallVoidMethod(inputStream, joffset);
inputStreamSeekFromBeginningMethod, joffset));
break; break;
case Current: case Current:
env->CallVoidMethod(inputStream, inputStreamSeekFromCurrentMethod, env->CallVoidMethod(inputStream, inputStreamSeekFromCurrentMethod,
@ -123,12 +109,12 @@ void JVMInputStream::clear() {
} }
TagLib::offset_t JVMInputStream::tell() const { TagLib::offset_t JVMInputStream::tell() const {
TRY(jlong jposition = env->CallLongMethod(inputStream, inputStreamTellMethod)); jlong jposition = env->CallLongMethod(inputStream, inputStreamTellMethod);
return static_cast<TagLib::offset_t>(jposition); return static_cast<TagLib::offset_t>(jposition);
} }
TagLib::offset_t JVMInputStream::length() { TagLib::offset_t JVMInputStream::length() {
TRY(jlong jlength = env->CallLongMethod(inputStream, inputStreamLengthMethod)); jlong jlength = env->CallLongMethod(inputStream, inputStreamLengthMethod);
return static_cast<TagLib::offset_t>(jlength); return static_cast<TagLib::offset_t>(jlength);
} }

View file

@ -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 <https://www.gnu.org/licenses/>.
*/
#include <stdexcept>
#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");
}
}

View file

@ -28,10 +28,4 @@
#define LOGD(...) \ #define LOGD(...) \
((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) ((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 #endif //AUXIO_UTIL_H