musikr: reformat shim
This commit is contained in:
parent
20785300bb
commit
c115e34aac
8 changed files with 254 additions and 207 deletions
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
package org.oxycblt.musikr.metadata
|
||||
|
||||
|
||||
import android.os.ParcelFileDescriptor
|
||||
import android.util.Log
|
||||
import java.io.FileInputStream
|
||||
|
@ -39,7 +39,7 @@ private object MetadataExtractorImpl : MetadataExtractor {
|
|||
val fis = FileInputStream(fd.fileDescriptor)
|
||||
val input = NativeInputStream(deviceFile, fis)
|
||||
Log.d("MetadataExtractorImpl", MetadataJNI.openFile(input))
|
||||
// MetadataJNI.open(deviceFile, fis).also { fis.close() }
|
||||
null
|
||||
// MetadataJNI.open(deviceFile, fis).also { fis.close() }
|
||||
null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2024 Auxio Project
|
||||
* TagLibJNI.kt is part of Auxio.
|
||||
* MetadataJNI.kt 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
|
||||
|
|
|
@ -1,41 +1,51 @@
|
|||
#include "file_shim.hpp"
|
||||
|
||||
namespace taglib_shim {
|
||||
namespace taglib_shim
|
||||
{
|
||||
|
||||
const TagLib::Ogg::File* File_asOgg(const TagLib::File* file) {
|
||||
return dynamic_cast<const TagLib::Ogg::File*>(file);
|
||||
}
|
||||
const TagLib::Ogg::File *File_asOgg(const TagLib::File *file)
|
||||
{
|
||||
return dynamic_cast<const TagLib::Ogg::File *>(file);
|
||||
}
|
||||
|
||||
const TagLib::Ogg::Vorbis::File* File_asVorbis(const TagLib::File* file) {
|
||||
return dynamic_cast<const TagLib::Ogg::Vorbis::File*>(file);
|
||||
}
|
||||
const TagLib::Ogg::Vorbis::File *File_asVorbis(const TagLib::File *file)
|
||||
{
|
||||
return dynamic_cast<const TagLib::Ogg::Vorbis::File *>(file);
|
||||
}
|
||||
|
||||
const TagLib::Ogg::Opus::File* File_asOpus(const TagLib::File* file) {
|
||||
return dynamic_cast<const TagLib::Ogg::Opus::File*>(file);
|
||||
}
|
||||
const TagLib::Ogg::Opus::File *File_asOpus(const TagLib::File *file)
|
||||
{
|
||||
return dynamic_cast<const TagLib::Ogg::Opus::File *>(file);
|
||||
}
|
||||
|
||||
const TagLib::MPEG::File* File_asMPEG(const TagLib::File* file) {
|
||||
return dynamic_cast<const TagLib::MPEG::File*>(file);
|
||||
}
|
||||
const TagLib::MPEG::File *File_asMPEG(const TagLib::File *file)
|
||||
{
|
||||
return dynamic_cast<const TagLib::MPEG::File *>(file);
|
||||
}
|
||||
|
||||
const TagLib::FLAC::File* File_asFLAC(const TagLib::File* file) {
|
||||
return dynamic_cast<const TagLib::FLAC::File*>(file);
|
||||
}
|
||||
const TagLib::FLAC::File *File_asFLAC(const TagLib::File *file)
|
||||
{
|
||||
return dynamic_cast<const TagLib::FLAC::File *>(file);
|
||||
}
|
||||
|
||||
const TagLib::MP4::File* File_asMP4(const TagLib::File* file) {
|
||||
return dynamic_cast<const TagLib::MP4::File*>(file);
|
||||
}
|
||||
const TagLib::MP4::File *File_asMP4(const TagLib::File *file)
|
||||
{
|
||||
return dynamic_cast<const TagLib::MP4::File *>(file);
|
||||
}
|
||||
|
||||
const TagLib::RIFF::WAV::File* File_asWAV(const TagLib::File* file) {
|
||||
return dynamic_cast<const TagLib::RIFF::WAV::File*>(file);
|
||||
}
|
||||
const TagLib::RIFF::WAV::File *File_asWAV(const TagLib::File *file)
|
||||
{
|
||||
return dynamic_cast<const TagLib::RIFF::WAV::File *>(file);
|
||||
}
|
||||
|
||||
const TagLib::WavPack::File* File_asWavPack(const TagLib::File* file) {
|
||||
return dynamic_cast<const TagLib::WavPack::File*>(file);
|
||||
}
|
||||
const TagLib::WavPack::File *File_asWavPack(const TagLib::File *file)
|
||||
{
|
||||
return dynamic_cast<const TagLib::WavPack::File *>(file);
|
||||
}
|
||||
|
||||
const TagLib::APE::File* File_asAPE(const TagLib::File* file) {
|
||||
return dynamic_cast<const TagLib::APE::File*>(file);
|
||||
}
|
||||
const TagLib::APE::File *File_asAPE(const TagLib::File *file)
|
||||
{
|
||||
return dynamic_cast<const TagLib::APE::File *>(file);
|
||||
}
|
||||
|
||||
} // namespace taglib_shim
|
||||
} // namespace taglib_shim
|
|
@ -14,17 +14,18 @@
|
|||
#include <taglib/apefile.h>
|
||||
#include <taglib/vorbisfile.h>
|
||||
|
||||
namespace taglib_shim {
|
||||
namespace taglib_shim
|
||||
{
|
||||
|
||||
// File conversion functions
|
||||
const TagLib::Ogg::File* File_asOgg(const TagLib::File* file);
|
||||
const TagLib::Ogg::Vorbis::File* File_asVorbis(const TagLib::File* file);
|
||||
const TagLib::Ogg::Opus::File* File_asOpus(const TagLib::File* file);
|
||||
const TagLib::MPEG::File* File_asMPEG(const TagLib::File* file);
|
||||
const TagLib::FLAC::File* File_asFLAC(const TagLib::File* file);
|
||||
const TagLib::MP4::File* File_asMP4(const TagLib::File* file);
|
||||
const TagLib::RIFF::WAV::File* File_asWAV(const TagLib::File* file);
|
||||
const TagLib::WavPack::File* File_asWavPack(const TagLib::File* file);
|
||||
const TagLib::APE::File* File_asAPE(const TagLib::File* file);
|
||||
// File conversion functions
|
||||
const TagLib::Ogg::File *File_asOgg(const TagLib::File *file);
|
||||
const TagLib::Ogg::Vorbis::File *File_asVorbis(const TagLib::File *file);
|
||||
const TagLib::Ogg::Opus::File *File_asOpus(const TagLib::File *file);
|
||||
const TagLib::MPEG::File *File_asMPEG(const TagLib::File *file);
|
||||
const TagLib::FLAC::File *File_asFLAC(const TagLib::File *file);
|
||||
const TagLib::MP4::File *File_asMP4(const TagLib::File *file);
|
||||
const TagLib::RIFF::WAV::File *File_asWAV(const TagLib::File *file);
|
||||
const TagLib::WavPack::File *File_asWavPack(const TagLib::File *file);
|
||||
const TagLib::APE::File *File_asAPE(const TagLib::File *file);
|
||||
|
||||
} // namespace taglib_shim
|
||||
} // namespace taglib_shim
|
|
@ -4,126 +4,152 @@
|
|||
#include <vector>
|
||||
|
||||
// These are the functions we'll define in Rust
|
||||
extern "C" {
|
||||
const char* rust_stream_name(const void* stream);
|
||||
size_t rust_stream_read(void* stream, uint8_t* buffer, size_t length);
|
||||
void rust_stream_write(void* stream, const uint8_t* data, size_t length);
|
||||
void rust_stream_seek(void* stream, int64_t offset, int32_t whence);
|
||||
void rust_stream_truncate(void* stream, int64_t length);
|
||||
int64_t rust_stream_tell(const void* stream);
|
||||
int64_t rust_stream_length(const void* stream);
|
||||
bool rust_stream_is_readonly(const void* stream);
|
||||
extern "C"
|
||||
{
|
||||
const char *rust_stream_name(const void *stream);
|
||||
size_t rust_stream_read(void *stream, uint8_t *buffer, size_t length);
|
||||
void rust_stream_write(void *stream, const uint8_t *data, size_t length);
|
||||
void rust_stream_seek(void *stream, int64_t offset, int32_t whence);
|
||||
void rust_stream_truncate(void *stream, int64_t length);
|
||||
int64_t rust_stream_tell(const void *stream);
|
||||
int64_t rust_stream_length(const void *stream);
|
||||
bool rust_stream_is_readonly(const void *stream);
|
||||
}
|
||||
|
||||
namespace taglib_shim {
|
||||
namespace taglib_shim
|
||||
{
|
||||
|
||||
// Factory function to create a new RustIOStream
|
||||
std::unique_ptr<RustIOStream> new_rust_iostream(RustStream* stream) {
|
||||
return std::unique_ptr<RustIOStream>(new RustIOStream(stream));
|
||||
}
|
||||
|
||||
// Factory function to create a FileRef from a stream
|
||||
std::unique_ptr<TagLib::FileRef> new_FileRef_from_stream(std::unique_ptr<RustIOStream> stream) {
|
||||
return std::make_unique<TagLib::FileRef>(stream.release(), true);
|
||||
}
|
||||
|
||||
RustIOStream::RustIOStream(RustStream* stream) : rust_stream(stream) {}
|
||||
|
||||
RustIOStream::~RustIOStream() = default;
|
||||
|
||||
TagLib::FileName RustIOStream::name() const {
|
||||
return rust_stream_name(rust_stream);
|
||||
}
|
||||
|
||||
TagLib::ByteVector RustIOStream::readBlock(size_t length) {
|
||||
std::vector<uint8_t> buffer(length);
|
||||
size_t bytes_read = rust_stream_read(rust_stream, buffer.data(), length);
|
||||
return TagLib::ByteVector(reinterpret_cast<char*>(buffer.data()), bytes_read);
|
||||
}
|
||||
|
||||
void RustIOStream::writeBlock(const TagLib::ByteVector& data) {
|
||||
rust_stream_write(rust_stream,
|
||||
reinterpret_cast<const uint8_t*>(data.data()),
|
||||
data.size());
|
||||
}
|
||||
|
||||
void RustIOStream::insert(const TagLib::ByteVector& data, TagLib::offset_t start, size_t replace) {
|
||||
// Save current position
|
||||
auto current = tell();
|
||||
|
||||
// Seek to insert position
|
||||
seek(start);
|
||||
|
||||
// If replacing, remove that section first
|
||||
if (replace > 0) {
|
||||
removeBlock(start, replace);
|
||||
// Factory function to create a new RustIOStream
|
||||
std::unique_ptr<RustIOStream> new_rust_iostream(RustStream *stream)
|
||||
{
|
||||
return std::unique_ptr<RustIOStream>(new RustIOStream(stream));
|
||||
}
|
||||
|
||||
// Write new data
|
||||
writeBlock(data);
|
||||
|
||||
// Restore position
|
||||
seek(current);
|
||||
}
|
||||
|
||||
void RustIOStream::removeBlock(TagLib::offset_t start, size_t length) {
|
||||
if (length == 0) return;
|
||||
|
||||
// Save current position
|
||||
auto current = tell();
|
||||
|
||||
// Get file size
|
||||
auto file_length = this->length();
|
||||
|
||||
// Read everything after the removed section
|
||||
seek(start + length);
|
||||
auto remaining = readBlock(file_length - (start + length));
|
||||
|
||||
// Truncate to start position
|
||||
seek(start);
|
||||
truncate(start);
|
||||
|
||||
// Write remaining data
|
||||
writeBlock(remaining);
|
||||
|
||||
// Restore position
|
||||
seek(current);
|
||||
}
|
||||
|
||||
void RustIOStream::seek(TagLib::offset_t offset, Position p) {
|
||||
int32_t whence;
|
||||
switch (p) {
|
||||
case Beginning: whence = SEEK_SET; break;
|
||||
case Current: whence = SEEK_CUR; break;
|
||||
case End: whence = SEEK_END; break;
|
||||
default: throw std::runtime_error("Invalid seek position");
|
||||
// Factory function to create a FileRef from a stream
|
||||
std::unique_ptr<TagLib::FileRef> new_FileRef_from_stream(std::unique_ptr<RustIOStream> stream)
|
||||
{
|
||||
return std::make_unique<TagLib::FileRef>(stream.release(), true);
|
||||
}
|
||||
rust_stream_seek(rust_stream, offset, whence);
|
||||
}
|
||||
|
||||
void RustIOStream::clear() {
|
||||
truncate(0);
|
||||
seek(0);
|
||||
}
|
||||
RustIOStream::RustIOStream(RustStream *stream) : rust_stream(stream) {}
|
||||
|
||||
void RustIOStream::truncate(TagLib::offset_t length) {
|
||||
rust_stream_truncate(rust_stream, length);
|
||||
}
|
||||
RustIOStream::~RustIOStream() = default;
|
||||
|
||||
TagLib::offset_t RustIOStream::tell() const {
|
||||
return rust_stream_tell(rust_stream);
|
||||
}
|
||||
TagLib::FileName RustIOStream::name() const
|
||||
{
|
||||
return rust_stream_name(rust_stream);
|
||||
}
|
||||
|
||||
TagLib::offset_t RustIOStream::length() {
|
||||
return rust_stream_length(rust_stream);
|
||||
}
|
||||
TagLib::ByteVector RustIOStream::readBlock(size_t length)
|
||||
{
|
||||
std::vector<uint8_t> buffer(length);
|
||||
size_t bytes_read = rust_stream_read(rust_stream, buffer.data(), length);
|
||||
return TagLib::ByteVector(reinterpret_cast<char *>(buffer.data()), bytes_read);
|
||||
}
|
||||
|
||||
bool RustIOStream::readOnly() const {
|
||||
return rust_stream_is_readonly(rust_stream);
|
||||
}
|
||||
void RustIOStream::writeBlock(const TagLib::ByteVector &data)
|
||||
{
|
||||
rust_stream_write(rust_stream,
|
||||
reinterpret_cast<const uint8_t *>(data.data()),
|
||||
data.size());
|
||||
}
|
||||
|
||||
bool RustIOStream::isOpen() const {
|
||||
return true; // If we have a stream, it's open
|
||||
}
|
||||
void RustIOStream::insert(const TagLib::ByteVector &data, TagLib::offset_t start, size_t replace)
|
||||
{
|
||||
// Save current position
|
||||
auto current = tell();
|
||||
|
||||
} // namespace taglib_shim
|
||||
// Seek to insert position
|
||||
seek(start);
|
||||
|
||||
// If replacing, remove that section first
|
||||
if (replace > 0)
|
||||
{
|
||||
removeBlock(start, replace);
|
||||
}
|
||||
|
||||
// Write new data
|
||||
writeBlock(data);
|
||||
|
||||
// Restore position
|
||||
seek(current);
|
||||
}
|
||||
|
||||
void RustIOStream::removeBlock(TagLib::offset_t start, size_t length)
|
||||
{
|
||||
if (length == 0)
|
||||
return;
|
||||
|
||||
// Save current position
|
||||
auto current = tell();
|
||||
|
||||
// Get file size
|
||||
auto file_length = this->length();
|
||||
|
||||
// Read everything after the removed section
|
||||
seek(start + length);
|
||||
auto remaining = readBlock(file_length - (start + length));
|
||||
|
||||
// Truncate to start position
|
||||
seek(start);
|
||||
truncate(start);
|
||||
|
||||
// Write remaining data
|
||||
writeBlock(remaining);
|
||||
|
||||
// Restore position
|
||||
seek(current);
|
||||
}
|
||||
|
||||
void RustIOStream::seek(TagLib::offset_t offset, Position p)
|
||||
{
|
||||
int32_t whence;
|
||||
switch (p)
|
||||
{
|
||||
case Beginning:
|
||||
whence = SEEK_SET;
|
||||
break;
|
||||
case Current:
|
||||
whence = SEEK_CUR;
|
||||
break;
|
||||
case End:
|
||||
whence = SEEK_END;
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Invalid seek position");
|
||||
}
|
||||
rust_stream_seek(rust_stream, offset, whence);
|
||||
}
|
||||
|
||||
void RustIOStream::clear()
|
||||
{
|
||||
truncate(0);
|
||||
seek(0);
|
||||
}
|
||||
|
||||
void RustIOStream::truncate(TagLib::offset_t length)
|
||||
{
|
||||
rust_stream_truncate(rust_stream, length);
|
||||
}
|
||||
|
||||
TagLib::offset_t RustIOStream::tell() const
|
||||
{
|
||||
return rust_stream_tell(rust_stream);
|
||||
}
|
||||
|
||||
TagLib::offset_t RustIOStream::length()
|
||||
{
|
||||
return rust_stream_length(rust_stream);
|
||||
}
|
||||
|
||||
bool RustIOStream::readOnly() const
|
||||
{
|
||||
return rust_stream_is_readonly(rust_stream);
|
||||
}
|
||||
|
||||
bool RustIOStream::isOpen() const
|
||||
{
|
||||
return true; // If we have a stream, it's open
|
||||
}
|
||||
|
||||
} // namespace taglib_shim
|
|
@ -5,37 +5,39 @@
|
|||
#include <taglib/tiostream.h>
|
||||
#include <taglib/fileref.h>
|
||||
|
||||
namespace taglib_shim {
|
||||
namespace taglib_shim
|
||||
{
|
||||
|
||||
// Forward declaration of the Rust-side stream
|
||||
struct RustStream;
|
||||
// Forward declaration of the Rust-side stream
|
||||
struct RustStream;
|
||||
|
||||
// C++ implementation of TagLib::IOStream that delegates to Rust
|
||||
class RustIOStream : public TagLib::IOStream {
|
||||
public:
|
||||
explicit RustIOStream(RustStream* stream);
|
||||
~RustIOStream() override;
|
||||
// C++ implementation of TagLib::IOStream that delegates to Rust
|
||||
class RustIOStream : public TagLib::IOStream
|
||||
{
|
||||
public:
|
||||
explicit RustIOStream(RustStream *stream);
|
||||
~RustIOStream() override;
|
||||
|
||||
// TagLib::IOStream interface implementation
|
||||
TagLib::FileName name() const override;
|
||||
TagLib::ByteVector readBlock(size_t length) override;
|
||||
void writeBlock(const TagLib::ByteVector& data) override;
|
||||
void insert(const TagLib::ByteVector& data, TagLib::offset_t start = 0, size_t replace = 0) override;
|
||||
void removeBlock(TagLib::offset_t start = 0, size_t length = 0) override;
|
||||
void seek(TagLib::offset_t offset, Position p = Beginning) override;
|
||||
void clear() override;
|
||||
void truncate(TagLib::offset_t length) override;
|
||||
TagLib::offset_t tell() const override;
|
||||
TagLib::offset_t length() override;
|
||||
bool readOnly() const override;
|
||||
bool isOpen() const override;
|
||||
// TagLib::IOStream interface implementation
|
||||
TagLib::FileName name() const override;
|
||||
TagLib::ByteVector readBlock(size_t length) override;
|
||||
void writeBlock(const TagLib::ByteVector &data) override;
|
||||
void insert(const TagLib::ByteVector &data, TagLib::offset_t start = 0, size_t replace = 0) override;
|
||||
void removeBlock(TagLib::offset_t start = 0, size_t length = 0) override;
|
||||
void seek(TagLib::offset_t offset, Position p = Beginning) override;
|
||||
void clear() override;
|
||||
void truncate(TagLib::offset_t length) override;
|
||||
TagLib::offset_t tell() const override;
|
||||
TagLib::offset_t length() override;
|
||||
bool readOnly() const override;
|
||||
bool isOpen() const override;
|
||||
|
||||
private:
|
||||
RustStream* rust_stream;
|
||||
};
|
||||
private:
|
||||
RustStream *rust_stream;
|
||||
};
|
||||
|
||||
// Factory functions
|
||||
std::unique_ptr<RustIOStream> new_rust_iostream(RustStream* stream);
|
||||
std::unique_ptr<TagLib::FileRef> new_FileRef_from_stream(std::unique_ptr<RustIOStream> stream);
|
||||
// Factory functions
|
||||
std::unique_ptr<RustIOStream> new_rust_iostream(RustStream *stream);
|
||||
std::unique_ptr<TagLib::FileRef> new_FileRef_from_stream(std::unique_ptr<RustIOStream> stream);
|
||||
|
||||
} // namespace taglib_shim
|
||||
} // namespace taglib_shim
|
|
@ -1,30 +1,36 @@
|
|||
#include "tk_shim.hpp"
|
||||
|
||||
namespace taglib_shim
|
||||
{
|
||||
Property::Property(TagLib::String key, TagLib::StringList value) : key_(key), value_(value) {}
|
||||
|
||||
namespace taglib_shim {
|
||||
Property::Property(TagLib::String key, TagLib::StringList value) : key_(key), value_(value) {}
|
||||
const TagLib::String &Property::key() const
|
||||
{
|
||||
return key_;
|
||||
}
|
||||
|
||||
const TagLib::String &Property::key() const {
|
||||
return key_;
|
||||
}
|
||||
|
||||
const TagLib::StringList &Property::value() const {
|
||||
return value_;
|
||||
}
|
||||
std::unique_ptr<std::vector<Property>> SimplePropertyMap_to_vector(const TagLib::SimplePropertyMap &map) {
|
||||
const TagLib::StringList &Property::value() const
|
||||
{
|
||||
return value_;
|
||||
}
|
||||
std::unique_ptr<std::vector<Property>> SimplePropertyMap_to_vector(const TagLib::SimplePropertyMap &map)
|
||||
{
|
||||
std::unique_ptr<std::vector<Property>> result = std::make_unique<std::vector<Property>>();
|
||||
for (const auto &pair : map) {
|
||||
for (const auto &pair : map)
|
||||
{
|
||||
result->push_back(Property(pair.first, pair.second));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::unique_ptr<std::vector<TagLib::String>> StringList_to_vector(const TagLib::StringList &list) {
|
||||
std::unique_ptr<std::vector<TagLib::String>> StringList_to_vector(const TagLib::StringList &list)
|
||||
{
|
||||
std::unique_ptr<std::vector<TagLib::String>> result = std::make_unique<std::vector<TagLib::String>>();
|
||||
for (const auto &str : list) {
|
||||
for (const auto &str : list)
|
||||
{
|
||||
result->push_back(str);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,18 +7,20 @@
|
|||
#include <memory>
|
||||
#include <iterator>
|
||||
|
||||
namespace taglib_shim {
|
||||
namespace taglib_shim
|
||||
{
|
||||
|
||||
struct Property {
|
||||
Property(TagLib::String key, TagLib::StringList value);
|
||||
const TagLib::String &key() const;
|
||||
const TagLib::StringList &value() const;
|
||||
struct Property
|
||||
{
|
||||
Property(TagLib::String key, TagLib::StringList value);
|
||||
const TagLib::String &key() const;
|
||||
const TagLib::StringList &value() const;
|
||||
|
||||
private:
|
||||
TagLib::String key_;
|
||||
TagLib::StringList value_;
|
||||
};
|
||||
private:
|
||||
TagLib::String key_;
|
||||
TagLib::StringList value_;
|
||||
};
|
||||
|
||||
std::unique_ptr<std::vector<Property>> SimplePropertyMap_to_vector(const TagLib::SimplePropertyMap &map);
|
||||
std::unique_ptr<std::vector<TagLib::String>> StringList_to_vector(const TagLib::StringList &list);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue