all: fix formatting
This commit is contained in:
@@ -22,106 +22,110 @@
|
||||
|
||||
// TODO: Handle stream exceptions
|
||||
|
||||
JVMInputStream::JVMInputStream(JNIEnv *env, jobject inputStream)
|
||||
: env(env), inputStream(inputStream) {
|
||||
if (!env->IsInstanceOf(
|
||||
inputStream,
|
||||
env->FindClass("org/oxycblt/musikr/metadata/NativeInputStream"))) {
|
||||
throw std::runtime_error("oStream is not an instance of TagLibOStream");
|
||||
}
|
||||
jclass inputStreamClass =
|
||||
env->FindClass("org/oxycblt/musikr/metadata/NativeInputStream");
|
||||
inputStreamNameMethod =
|
||||
env->GetMethodID(inputStreamClass, "name", "()Ljava/lang/String;");
|
||||
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");
|
||||
inputStreamClearMethod = env->GetMethodID(inputStreamClass, "clear", "()V");
|
||||
inputStreamTellMethod = env->GetMethodID(inputStreamClass, "tell", "()J");
|
||||
inputStreamLengthMethod = env->GetMethodID(inputStreamClass, "length", "()J");
|
||||
env->DeleteLocalRef(inputStreamClass);
|
||||
JVMInputStream::JVMInputStream(JNIEnv *env, jobject inputStream) : env(env), inputStream(
|
||||
inputStream) {
|
||||
if (!env->IsInstanceOf(inputStream,
|
||||
env->FindClass("org/oxycblt/musikr/metadata/NativeInputStream"))) {
|
||||
throw std::runtime_error("oStream is not an instance of TagLibOStream");
|
||||
}
|
||||
jclass inputStreamClass = env->FindClass(
|
||||
"org/oxycblt/musikr/metadata/NativeInputStream");
|
||||
inputStreamNameMethod = env->GetMethodID(inputStreamClass, "name",
|
||||
"()Ljava/lang/String;");
|
||||
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");
|
||||
inputStreamClearMethod = env->GetMethodID(inputStreamClass, "clear", "()V");
|
||||
inputStreamTellMethod = env->GetMethodID(inputStreamClass, "tell", "()J");
|
||||
inputStreamLengthMethod = env->GetMethodID(inputStreamClass, "length",
|
||||
"()J");
|
||||
env->DeleteLocalRef(inputStreamClass);
|
||||
}
|
||||
|
||||
JVMInputStream::~JVMInputStream() {
|
||||
// The implicit assumption is that inputStream is managed by the owner,
|
||||
// so we don't need to delete any references here
|
||||
// The implicit assumption is that inputStream is managed by the owner,
|
||||
// so we don't need to delete any references here
|
||||
}
|
||||
|
||||
TagLib::FileName JVMInputStream::name() const {
|
||||
auto name =
|
||||
(jstring)env->CallObjectMethod(inputStream, inputStreamNameMethod);
|
||||
const char *nameChars = env->GetStringUTFChars(name, nullptr);
|
||||
auto fileName = TagLib::FileName(nameChars);
|
||||
env->ReleaseStringUTFChars(name, nameChars);
|
||||
return fileName;
|
||||
auto name = (jstring) env->CallObjectMethod(inputStream,
|
||||
inputStreamNameMethod);
|
||||
const char *nameChars = env->GetStringUTFChars(name, nullptr);
|
||||
auto fileName = TagLib::FileName(nameChars);
|
||||
env->ReleaseStringUTFChars(name, nameChars);
|
||||
return fileName;
|
||||
}
|
||||
|
||||
TagLib::ByteVector JVMInputStream::readBlock(size_t length) {
|
||||
auto data = (jbyteArray)env->CallObjectMethod(
|
||||
inputStream, inputStreamReadBlockMethod, length);
|
||||
jsize dataLength = env->GetArrayLength(data);
|
||||
auto dataBytes = env->GetByteArrayElements(data, nullptr);
|
||||
TagLib::ByteVector byteVector(reinterpret_cast<const char *>(dataBytes),
|
||||
dataLength);
|
||||
env->ReleaseByteArrayElements(data, dataBytes, JNI_ABORT);
|
||||
return byteVector;
|
||||
auto data = (jbyteArray) env->CallObjectMethod(inputStream,
|
||||
inputStreamReadBlockMethod, length);
|
||||
jsize dataLength = env->GetArrayLength(data);
|
||||
auto dataBytes = env->GetByteArrayElements(data, nullptr);
|
||||
TagLib::ByteVector byteVector(reinterpret_cast<const char*>(dataBytes),
|
||||
dataLength);
|
||||
env->ReleaseByteArrayElements(data, dataBytes, JNI_ABORT);
|
||||
return byteVector;
|
||||
}
|
||||
|
||||
void JVMInputStream::writeBlock(const TagLib::ByteVector &data) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
void JVMInputStream::insert(const TagLib::ByteVector &data,
|
||||
TagLib::offset_t start, size_t replace) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
TagLib::offset_t start, size_t replace) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
void JVMInputStream::removeBlock(TagLib::offset_t start, size_t length) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
bool JVMInputStream::readOnly() const { return true; }
|
||||
bool JVMInputStream::readOnly() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JVMInputStream::isOpen() const {
|
||||
return env->CallBooleanMethod(inputStream, inputStreamIsOpenMethod);
|
||||
return env->CallBooleanMethod(inputStream, inputStreamIsOpenMethod);
|
||||
}
|
||||
|
||||
void JVMInputStream::seek(TagLib::offset_t offset, Position p) {
|
||||
auto joffset = static_cast<jlong>(std::llround(offset));
|
||||
switch (p) {
|
||||
case Beginning:
|
||||
env->CallVoidMethod(inputStream, inputStreamSeekFromBeginningMethod,
|
||||
joffset);
|
||||
break;
|
||||
case Current:
|
||||
env->CallVoidMethod(inputStream, inputStreamSeekFromCurrentMethod, joffset);
|
||||
break;
|
||||
case End:
|
||||
env->CallVoidMethod(inputStream, inputStreamSeekFromEndMethod, joffset);
|
||||
break;
|
||||
}
|
||||
auto joffset = static_cast<jlong>(std::llround(offset));
|
||||
switch (p) {
|
||||
case Beginning:
|
||||
env->CallVoidMethod(inputStream, inputStreamSeekFromBeginningMethod,
|
||||
joffset);
|
||||
break;
|
||||
case Current:
|
||||
env->CallVoidMethod(inputStream, inputStreamSeekFromCurrentMethod,
|
||||
joffset);
|
||||
break;
|
||||
case End:
|
||||
env->CallVoidMethod(inputStream, inputStreamSeekFromEndMethod, joffset);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void JVMInputStream::clear() {
|
||||
env->CallVoidMethod(inputStream, inputStreamClearMethod);
|
||||
env->CallVoidMethod(inputStream, inputStreamClearMethod);
|
||||
}
|
||||
|
||||
TagLib::offset_t JVMInputStream::tell() const {
|
||||
jlong jposition = env->CallLongMethod(inputStream, inputStreamTellMethod);
|
||||
return static_cast<TagLib::offset_t>(jposition);
|
||||
jlong jposition = env->CallLongMethod(inputStream, inputStreamTellMethod);
|
||||
return static_cast<TagLib::offset_t>(jposition);
|
||||
}
|
||||
|
||||
TagLib::offset_t JVMInputStream::length() {
|
||||
jlong jlength = env->CallLongMethod(inputStream, inputStreamLengthMethod);
|
||||
return static_cast<TagLib::offset_t>(jlength);
|
||||
jlong jlength = env->CallLongMethod(inputStream, inputStreamLengthMethod);
|
||||
return static_cast<TagLib::offset_t>(jlength);
|
||||
}
|
||||
|
||||
void JVMInputStream::truncate(TagLib::offset_t length) {
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
@@ -21,142 +21,141 @@
|
||||
#include <taglib/mp4tag.h>
|
||||
#include <taglib/textidentificationframe.h>
|
||||
|
||||
JVMMetadataBuilder::JVMMetadataBuilder(JNIEnv *env)
|
||||
: env(env), id3v2(env), xiph(env), mp4(env), cover(), properties(nullptr) {}
|
||||
JVMMetadataBuilder::JVMMetadataBuilder(JNIEnv *env) : env(env), id3v2(env), xiph(
|
||||
env), mp4(env), cover(), properties(nullptr) {
|
||||
}
|
||||
|
||||
void JVMMetadataBuilder::setMimeType(const std::string_view type) {
|
||||
this->mimeType = type;
|
||||
this->mimeType = type;
|
||||
}
|
||||
|
||||
void JVMMetadataBuilder::setId3v2(const TagLib::ID3v2::Tag &tag) {
|
||||
for (auto frame : tag.frameList()) {
|
||||
if (auto txxxFrame =
|
||||
dynamic_cast<TagLib::ID3v2::UserTextIdentificationFrame *>(frame)) {
|
||||
TagLib::StringList frameText = txxxFrame->fieldList();
|
||||
// Frame text starts with the description then the remaining values
|
||||
auto begin = frameText.begin();
|
||||
TagLib::String key =
|
||||
TagLib::String(frame->frameID()) + ":" + begin->upper();
|
||||
frameText.erase(begin);
|
||||
id3v2.add(key, frameText);
|
||||
} else if (auto textFrame =
|
||||
dynamic_cast<TagLib::ID3v2::TextIdentificationFrame *>(
|
||||
frame)) {
|
||||
TagLib::String key = frame->frameID();
|
||||
TagLib::StringList frameText = textFrame->fieldList();
|
||||
id3v2.add(key, frameText);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
for (auto frame : tag.frameList()) {
|
||||
if (auto txxxFrame =
|
||||
dynamic_cast<TagLib::ID3v2::UserTextIdentificationFrame*>(frame)) {
|
||||
TagLib::StringList frameText = txxxFrame->fieldList();
|
||||
// Frame text starts with the description then the remaining values
|
||||
auto begin = frameText.begin();
|
||||
TagLib::String key = TagLib::String(frame->frameID()) + ":"
|
||||
+ begin->upper();
|
||||
frameText.erase(begin);
|
||||
id3v2.add(key, frameText);
|
||||
} else if (auto textFrame =
|
||||
dynamic_cast<TagLib::ID3v2::TextIdentificationFrame*>(frame)) {
|
||||
TagLib::String key = frame->frameID();
|
||||
TagLib::StringList frameText = textFrame->fieldList();
|
||||
id3v2.add(key, frameText);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JVMMetadataBuilder::setXiph(const TagLib::Ogg::XiphComment &tag) {
|
||||
for (auto field : tag.fieldListMap()) {
|
||||
auto key = field.first.upper();
|
||||
auto values = field.second;
|
||||
xiph.add(key, values);
|
||||
}
|
||||
for (auto field : tag.fieldListMap()) {
|
||||
auto key = field.first.upper();
|
||||
auto values = field.second;
|
||||
xiph.add(key, values);
|
||||
}
|
||||
}
|
||||
|
||||
void JVMMetadataBuilder::setMp4(const TagLib::MP4::Tag &tag) {
|
||||
for (auto item : tag.itemMap()) {
|
||||
auto itemName = TagLib::String(item.first);
|
||||
auto itemValue = item.second;
|
||||
auto type = itemValue.type();
|
||||
for (auto item : tag.itemMap()) {
|
||||
auto itemName = TagLib::String(item.first);
|
||||
auto itemValue = item.second;
|
||||
auto type = itemValue.type();
|
||||
|
||||
// TODO: Handle internal atoms
|
||||
// TODO: Handle internal atoms
|
||||
|
||||
// Only read out the atoms for the reasonable tags we are expecting.
|
||||
// None of the crazy binary atoms.
|
||||
if (type == TagLib::MP4::Item::Type::StringList) {
|
||||
auto value = itemValue.toStringList();
|
||||
mp4.add(itemName, value);
|
||||
return;
|
||||
}
|
||||
// Only read out the atoms for the reasonable tags we are expecting.
|
||||
// None of the crazy binary atoms.
|
||||
if (type == TagLib::MP4::Item::Type::StringList) {
|
||||
auto value = itemValue.toStringList();
|
||||
mp4.add(itemName, value);
|
||||
return;
|
||||
}
|
||||
|
||||
// Assume that taggers will be unhinged and store track numbers
|
||||
// as ints, uints, or longs.
|
||||
if (type == TagLib::MP4::Item::Type::Int) {
|
||||
auto value = std::to_string(itemValue.toInt());
|
||||
id3v2.add(itemName, value);
|
||||
return;
|
||||
}
|
||||
if (type == TagLib::MP4::Item::Type::UInt) {
|
||||
auto value = std::to_string(itemValue.toUInt());
|
||||
id3v2.add(itemName, value);
|
||||
return;
|
||||
}
|
||||
if (type == TagLib::MP4::Item::Type::LongLong) {
|
||||
auto value = std::to_string(itemValue.toLongLong());
|
||||
id3v2.add(itemName, value);
|
||||
return;
|
||||
}
|
||||
if (type == TagLib::MP4::Item::Type::IntPair) {
|
||||
// It's inefficient going from the integer representation back into
|
||||
// a string, but I fully expect taggers to just write "NN/TT" strings
|
||||
// anyway, and musikr doesn't have to do as much fiddly variant handling.
|
||||
auto value = std::to_string(itemValue.toIntPair().first) + "/" +
|
||||
std::to_string(itemValue.toIntPair().second);
|
||||
id3v2.add(itemName, value);
|
||||
return;
|
||||
}
|
||||
// Nothing else makes sense to handle as far as I can tell.
|
||||
}
|
||||
// Assume that taggers will be unhinged and store track numbers
|
||||
// as ints, uints, or longs.
|
||||
if (type == TagLib::MP4::Item::Type::Int) {
|
||||
auto value = std::to_string(itemValue.toInt());
|
||||
id3v2.add(itemName, value);
|
||||
return;
|
||||
}
|
||||
if (type == TagLib::MP4::Item::Type::UInt) {
|
||||
auto value = std::to_string(itemValue.toUInt());
|
||||
id3v2.add(itemName, value);
|
||||
return;
|
||||
}
|
||||
if (type == TagLib::MP4::Item::Type::LongLong) {
|
||||
auto value = std::to_string(itemValue.toLongLong());
|
||||
id3v2.add(itemName, value);
|
||||
return;
|
||||
}
|
||||
if (type == TagLib::MP4::Item::Type::IntPair) {
|
||||
// It's inefficient going from the integer representation back into
|
||||
// a string, but I fully expect taggers to just write "NN/TT" strings
|
||||
// anyway, and musikr doesn't have to do as much fiddly variant handling.
|
||||
auto value = std::to_string(itemValue.toIntPair().first) + "/"
|
||||
+ std::to_string(itemValue.toIntPair().second);
|
||||
id3v2.add(itemName, value);
|
||||
return;
|
||||
}
|
||||
// Nothing else makes sense to handle as far as I can tell.
|
||||
}
|
||||
}
|
||||
|
||||
void JVMMetadataBuilder::setCover(
|
||||
const TagLib::List<TagLib::VariantMap> covers) {
|
||||
if (covers.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// Find the cover with a "front cover" type
|
||||
for (auto cover : covers) {
|
||||
auto type = cover["pictureType"].toString();
|
||||
if (type == "Front Cover") {
|
||||
this->cover = cover["data"].toByteVector();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// No front cover, just pick first.
|
||||
// TODO: Consider having cascading fallbacks to increasingly less
|
||||
// relevant covers perhaps
|
||||
this->cover = covers.front()["data"].toByteVector();
|
||||
const TagLib::List<TagLib::VariantMap> covers) {
|
||||
if (covers.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// Find the cover with a "front cover" type
|
||||
for (auto cover : covers) {
|
||||
auto type = cover["pictureType"].toString();
|
||||
if (type == "Front Cover") {
|
||||
this->cover = cover["data"].toByteVector();
|
||||
return;
|
||||
}
|
||||
}
|
||||
// No front cover, just pick first.
|
||||
// TODO: Consider having cascading fallbacks to increasingly less
|
||||
// relevant covers perhaps
|
||||
this->cover = covers.front()["data"].toByteVector();
|
||||
}
|
||||
|
||||
void JVMMetadataBuilder::setProperties(TagLib::AudioProperties *properties) {
|
||||
this->properties = properties;
|
||||
this->properties = properties;
|
||||
}
|
||||
|
||||
jobject JVMMetadataBuilder::build() {
|
||||
jclass propertiesClass =
|
||||
env->FindClass("org/oxycblt/musikr/metadata/Properties");
|
||||
jmethodID propertiesInit =
|
||||
env->GetMethodID(propertiesClass, "<init>", "(Ljava/lang/String;JII)V");
|
||||
jobject propertiesObj = env->NewObject(
|
||||
propertiesClass, propertiesInit, env->NewStringUTF(mimeType.data()),
|
||||
(jlong)properties->lengthInMilliseconds(), properties->bitrate(),
|
||||
properties->sampleRate());
|
||||
env->DeleteLocalRef(propertiesClass);
|
||||
jclass propertiesClass = env->FindClass(
|
||||
"org/oxycblt/musikr/metadata/Properties");
|
||||
jmethodID propertiesInit = env->GetMethodID(propertiesClass, "<init>",
|
||||
"(Ljava/lang/String;JII)V");
|
||||
jobject propertiesObj = env->NewObject(propertiesClass, propertiesInit,
|
||||
env->NewStringUTF(mimeType.data()),
|
||||
(jlong) properties->lengthInMilliseconds(), properties->bitrate(),
|
||||
properties->sampleRate());
|
||||
env->DeleteLocalRef(propertiesClass);
|
||||
|
||||
jclass metadataClass = env->FindClass("org/oxycblt/musikr/metadata/Metadata");
|
||||
jmethodID metadataInit =
|
||||
env->GetMethodID(metadataClass, "<init>",
|
||||
"(Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;[BLorg/"
|
||||
"oxycblt/musikr/metadata/Properties;)V");
|
||||
jobject id3v2Map = id3v2.getObject();
|
||||
jobject xiphMap = xiph.getObject();
|
||||
jobject mp4Map = mp4.getObject();
|
||||
jbyteArray coverArray = nullptr;
|
||||
if (cover.has_value()) {
|
||||
auto coverSize = static_cast<jsize>(cover->size());
|
||||
coverArray = env->NewByteArray(coverSize);
|
||||
env->SetByteArrayRegion(coverArray, 0, coverSize,
|
||||
reinterpret_cast<const jbyte *>(cover->data()));
|
||||
}
|
||||
jobject metadataObj =
|
||||
env->NewObject(metadataClass, metadataInit, id3v2Map, xiphMap, mp4Map,
|
||||
coverArray, propertiesObj);
|
||||
env->DeleteLocalRef(metadataClass);
|
||||
return metadataObj;
|
||||
}
|
||||
jclass metadataClass = env->FindClass(
|
||||
"org/oxycblt/musikr/metadata/Metadata");
|
||||
jmethodID metadataInit = env->GetMethodID(metadataClass, "<init>",
|
||||
"(Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;[BLorg/"
|
||||
"oxycblt/musikr/metadata/Properties;)V");
|
||||
jobject id3v2Map = id3v2.getObject();
|
||||
jobject xiphMap = xiph.getObject();
|
||||
jobject mp4Map = mp4.getObject();
|
||||
jbyteArray coverArray = nullptr;
|
||||
if (cover.has_value()) {
|
||||
auto coverSize = static_cast<jsize>(cover->size());
|
||||
coverArray = env->NewByteArray(coverSize);
|
||||
env->SetByteArrayRegion(coverArray, 0, coverSize,
|
||||
reinterpret_cast<const jbyte*>(cover->data()));
|
||||
}
|
||||
jobject metadataObj = env->NewObject(metadataClass, metadataInit, id3v2Map,
|
||||
xiphMap, mp4Map, coverArray, propertiesObj);
|
||||
env->DeleteLocalRef(metadataClass);
|
||||
return metadataObj;
|
||||
}
|
||||
|
||||
@@ -19,68 +19,71 @@
|
||||
#include "JVMTagMap.h"
|
||||
|
||||
JVMTagMap::JVMTagMap(JNIEnv *env) : env(env) {
|
||||
jclass hashMapClass = env->FindClass("java/util/HashMap");
|
||||
jmethodID init = env->GetMethodID(hashMapClass, "<init>", "()V");
|
||||
hashMap = env->NewObject(hashMapClass, init);
|
||||
hashMapGetMethod = env->GetMethodID(hashMapClass, "get",
|
||||
"(Ljava/lang/Object;)Ljava/lang/Object;");
|
||||
hashMapPutMethod = env->GetMethodID(
|
||||
hashMapClass, "put",
|
||||
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
||||
env->DeleteLocalRef(hashMapClass);
|
||||
jclass hashMapClass = env->FindClass("java/util/HashMap");
|
||||
jmethodID init = env->GetMethodID(hashMapClass, "<init>", "()V");
|
||||
hashMap = env->NewObject(hashMapClass, init);
|
||||
hashMapGetMethod = env->GetMethodID(hashMapClass, "get",
|
||||
"(Ljava/lang/Object;)Ljava/lang/Object;");
|
||||
hashMapPutMethod = env->GetMethodID(hashMapClass, "put",
|
||||
"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
||||
env->DeleteLocalRef(hashMapClass);
|
||||
|
||||
jclass arrayListClass = env->FindClass("java/util/ArrayList");
|
||||
arrayListInitMethod = env->GetMethodID(arrayListClass, "<init>", "()V");
|
||||
arrayListAddMethod =
|
||||
env->GetMethodID(arrayListClass, "add", "(Ljava/lang/Object;)Z");
|
||||
env->DeleteLocalRef(arrayListClass);
|
||||
jclass arrayListClass = env->FindClass("java/util/ArrayList");
|
||||
arrayListInitMethod = env->GetMethodID(arrayListClass, "<init>", "()V");
|
||||
arrayListAddMethod = env->GetMethodID(arrayListClass, "add",
|
||||
"(Ljava/lang/Object;)Z");
|
||||
env->DeleteLocalRef(arrayListClass);
|
||||
}
|
||||
|
||||
JVMTagMap::~JVMTagMap() { env->DeleteLocalRef(hashMap); }
|
||||
JVMTagMap::~JVMTagMap() {
|
||||
env->DeleteLocalRef(hashMap);
|
||||
}
|
||||
|
||||
void JVMTagMap::add(TagLib::String &key, std::string_view value) {
|
||||
jstring jKey = env->NewStringUTF(key.toCString(true));
|
||||
jstring jValue = env->NewStringUTF(value.data());
|
||||
jstring jKey = env->NewStringUTF(key.toCString(true));
|
||||
jstring jValue = env->NewStringUTF(value.data());
|
||||
|
||||
// check if theres already a value arraylist in the map
|
||||
jobject existingValue =
|
||||
env->CallObjectMethod(hashMap, hashMapGetMethod, jKey);
|
||||
// if there is, add to the value to the existing arraylist
|
||||
if (existingValue != nullptr) {
|
||||
env->CallBooleanMethod(existingValue, arrayListAddMethod, jValue);
|
||||
} else {
|
||||
// if there isn't, create a new arraylist and add the value to it
|
||||
jclass arrayListClass = env->FindClass("java/util/ArrayList");
|
||||
jobject arrayList = env->NewObject(arrayListClass, arrayListInitMethod);
|
||||
env->CallBooleanMethod(arrayList, arrayListAddMethod, jValue);
|
||||
env->CallObjectMethod(hashMap, hashMapPutMethod, jKey, arrayList);
|
||||
env->DeleteLocalRef(arrayListClass);
|
||||
}
|
||||
// check if theres already a value arraylist in the map
|
||||
jobject existingValue = env->CallObjectMethod(hashMap, hashMapGetMethod,
|
||||
jKey);
|
||||
// if there is, add to the value to the existing arraylist
|
||||
if (existingValue != nullptr) {
|
||||
env->CallBooleanMethod(existingValue, arrayListAddMethod, jValue);
|
||||
} else {
|
||||
// if there isn't, create a new arraylist and add the value to it
|
||||
jclass arrayListClass = env->FindClass("java/util/ArrayList");
|
||||
jobject arrayList = env->NewObject(arrayListClass, arrayListInitMethod);
|
||||
env->CallBooleanMethod(arrayList, arrayListAddMethod, jValue);
|
||||
env->CallObjectMethod(hashMap, hashMapPutMethod, jKey, arrayList);
|
||||
env->DeleteLocalRef(arrayListClass);
|
||||
}
|
||||
}
|
||||
|
||||
void JVMTagMap::add(TagLib::String &key, TagLib::StringList &value) {
|
||||
jstring jKey = env->NewStringUTF(key.toCString(true));
|
||||
jstring jKey = env->NewStringUTF(key.toCString(true));
|
||||
|
||||
// check if theres already a value arraylist in the map
|
||||
jobject existingValue =
|
||||
env->CallObjectMethod(hashMap, hashMapGetMethod, jKey);
|
||||
// if there is, add to the value to the existing arraylist
|
||||
if (existingValue != nullptr) {
|
||||
for (auto &val : value) {
|
||||
jstring jValue = env->NewStringUTF(val.toCString(true));
|
||||
env->CallBooleanMethod(existingValue, arrayListAddMethod, jValue);
|
||||
}
|
||||
} else {
|
||||
// if there isn't, create a new arraylist and add the value to it
|
||||
jclass arrayListClass = env->FindClass("java/util/ArrayList");
|
||||
jobject arrayList = env->NewObject(arrayListClass, arrayListInitMethod);
|
||||
for (auto &val : value) {
|
||||
jstring jValue = env->NewStringUTF(val.toCString(true));
|
||||
env->CallBooleanMethod(arrayList, arrayListAddMethod, jValue);
|
||||
}
|
||||
env->CallObjectMethod(hashMap, hashMapPutMethod, jKey, arrayList);
|
||||
env->DeleteLocalRef(arrayListClass);
|
||||
}
|
||||
// check if theres already a value arraylist in the map
|
||||
jobject existingValue = env->CallObjectMethod(hashMap, hashMapGetMethod,
|
||||
jKey);
|
||||
// if there is, add to the value to the existing arraylist
|
||||
if (existingValue != nullptr) {
|
||||
for (auto &val : value) {
|
||||
jstring jValue = env->NewStringUTF(val.toCString(true));
|
||||
env->CallBooleanMethod(existingValue, arrayListAddMethod, jValue);
|
||||
}
|
||||
} else {
|
||||
// if there isn't, create a new arraylist and add the value to it
|
||||
jclass arrayListClass = env->FindClass("java/util/ArrayList");
|
||||
jobject arrayList = env->NewObject(arrayListClass, arrayListInitMethod);
|
||||
for (auto &val : value) {
|
||||
jstring jValue = env->NewStringUTF(val.toCString(true));
|
||||
env->CallBooleanMethod(arrayList, arrayListAddMethod, jValue);
|
||||
}
|
||||
env->CallObjectMethod(hashMap, hashMapPutMethod, jKey, arrayList);
|
||||
env->DeleteLocalRef(arrayListClass);
|
||||
}
|
||||
}
|
||||
|
||||
jobject JVMTagMap::getObject() { return hashMap; }
|
||||
jobject JVMTagMap::getObject() {
|
||||
return hashMap;
|
||||
}
|
||||
|
||||
@@ -32,43 +32,43 @@
|
||||
|
||||
extern "C" JNIEXPORT jobject JNICALL
|
||||
Java_org_oxycblt_musikr_metadata_TagLibJNI_openNative(JNIEnv *env,
|
||||
jobject /* this */,
|
||||
jobject inputStream) {
|
||||
JVMInputStream stream{env, inputStream};
|
||||
TagLib::FileRef fileRef{&stream};
|
||||
if (fileRef.isNull()) {
|
||||
return nullptr;
|
||||
}
|
||||
TagLib::File *file = fileRef.file();
|
||||
JVMMetadataBuilder builder{env};
|
||||
jobject /* this */,
|
||||
jobject inputStream) {
|
||||
JVMInputStream stream {env, inputStream};
|
||||
TagLib::FileRef fileRef {&stream};
|
||||
if (fileRef.isNull()) {
|
||||
return nullptr;
|
||||
}
|
||||
TagLib::File *file = fileRef.file();
|
||||
JVMMetadataBuilder builder {env};
|
||||
|
||||
if (auto *mpegFile = dynamic_cast<TagLib::MPEG::File *>(file)) {
|
||||
builder.setMimeType("audio/mpeg");
|
||||
builder.setId3v2(*mpegFile->ID3v2Tag());
|
||||
} else if (auto *mp4File = dynamic_cast<TagLib::MP4::File *>(file)) {
|
||||
builder.setMimeType("audio/mp4");
|
||||
builder.setMp4(*mp4File->tag());
|
||||
} else if (auto *flacFile = dynamic_cast<TagLib::FLAC::File *>(file)) {
|
||||
builder.setMimeType("audio/flac");
|
||||
builder.setId3v2(*flacFile->ID3v2Tag());
|
||||
builder.setXiph(*flacFile->xiphComment());
|
||||
} else if (auto *opusFile = dynamic_cast<TagLib::Ogg::Opus::File *>(file)) {
|
||||
builder.setMimeType("audio/opus");
|
||||
builder.setXiph(*opusFile->tag());
|
||||
} else if (auto *vorbisFile =
|
||||
dynamic_cast<TagLib::Ogg::Vorbis::File *>(file)) {
|
||||
builder.setMimeType("audio/vorbis");
|
||||
builder.setXiph(*vorbisFile->tag());
|
||||
} else if (auto *wavFile = dynamic_cast<TagLib::RIFF::WAV::File *>(file)) {
|
||||
builder.setMimeType("audio/wav");
|
||||
builder.setId3v2(*wavFile->ID3v2Tag());
|
||||
} else {
|
||||
// While taglib supports other formats, ExoPlayer does not. Ignore them.
|
||||
return nullptr;
|
||||
}
|
||||
if (auto *mpegFile = dynamic_cast<TagLib::MPEG::File *>(file)) {
|
||||
builder.setMimeType("audio/mpeg");
|
||||
builder.setId3v2(*mpegFile->ID3v2Tag());
|
||||
} else if (auto *mp4File = dynamic_cast<TagLib::MP4::File *>(file)) {
|
||||
builder.setMimeType("audio/mp4");
|
||||
builder.setMp4(*mp4File->tag());
|
||||
} else if (auto *flacFile = dynamic_cast<TagLib::FLAC::File *>(file)) {
|
||||
builder.setMimeType("audio/flac");
|
||||
builder.setId3v2(*flacFile->ID3v2Tag());
|
||||
builder.setXiph(*flacFile->xiphComment());
|
||||
} else if (auto *opusFile = dynamic_cast<TagLib::Ogg::Opus::File *>(file)) {
|
||||
builder.setMimeType("audio/opus");
|
||||
builder.setXiph(*opusFile->tag());
|
||||
} else if (auto *vorbisFile =
|
||||
dynamic_cast<TagLib::Ogg::Vorbis::File *>(file)) {
|
||||
builder.setMimeType("audio/vorbis");
|
||||
builder.setXiph(*vorbisFile->tag());
|
||||
} else if (auto *wavFile = dynamic_cast<TagLib::RIFF::WAV::File *>(file)) {
|
||||
builder.setMimeType("audio/wav");
|
||||
builder.setId3v2(*wavFile->ID3v2Tag());
|
||||
} else {
|
||||
// While taglib supports other formats, ExoPlayer does not. Ignore them.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
builder.setProperties(file->audioProperties());
|
||||
builder.setCover(file->tag()->complexProperties("PICTURE"));
|
||||
builder.setProperties(file->audioProperties());
|
||||
builder.setCover(file->tag()->complexProperties("PICTURE"));
|
||||
|
||||
return builder.build();
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user