musikr: reformat shim
This commit is contained in:
parent
20785300bb
commit
c115e34aac
8 changed files with 254 additions and 207 deletions
|
@ -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,40 +1,50 @@
|
|||
#include "file_shim.hpp"
|
||||
|
||||
namespace taglib_shim {
|
||||
namespace taglib_shim
|
||||
{
|
||||
|
||||
const TagLib::Ogg::File* File_asOgg(const TagLib::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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
const TagLib::APE::File *File_asAPE(const TagLib::File *file)
|
||||
{
|
||||
return dynamic_cast<const TagLib::APE::File *>(file);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
#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);
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
#include <vector>
|
||||
|
||||
// These are the functions we'll define in Rust
|
||||
extern "C" {
|
||||
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);
|
||||
|
@ -15,15 +16,18 @@ extern "C" {
|
|||
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) {
|
||||
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) {
|
||||
std::unique_ptr<TagLib::FileRef> new_FileRef_from_stream(std::unique_ptr<RustIOStream> stream)
|
||||
{
|
||||
return std::make_unique<TagLib::FileRef>(stream.release(), true);
|
||||
}
|
||||
|
||||
|
@ -31,23 +35,27 @@ RustIOStream::RustIOStream(RustStream* stream) : rust_stream(stream) {}
|
|||
|
||||
RustIOStream::~RustIOStream() = default;
|
||||
|
||||
TagLib::FileName RustIOStream::name() const {
|
||||
TagLib::FileName RustIOStream::name() const
|
||||
{
|
||||
return rust_stream_name(rust_stream);
|
||||
}
|
||||
|
||||
TagLib::ByteVector RustIOStream::readBlock(size_t length) {
|
||||
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) {
|
||||
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) {
|
||||
void RustIOStream::insert(const TagLib::ByteVector &data, TagLib::offset_t start, size_t replace)
|
||||
{
|
||||
// Save current position
|
||||
auto current = tell();
|
||||
|
||||
|
@ -55,7 +63,8 @@ void RustIOStream::insert(const TagLib::ByteVector& data, TagLib::offset_t start
|
|||
seek(start);
|
||||
|
||||
// If replacing, remove that section first
|
||||
if (replace > 0) {
|
||||
if (replace > 0)
|
||||
{
|
||||
removeBlock(start, replace);
|
||||
}
|
||||
|
||||
|
@ -66,8 +75,10 @@ void RustIOStream::insert(const TagLib::ByteVector& data, TagLib::offset_t start
|
|||
seek(current);
|
||||
}
|
||||
|
||||
void RustIOStream::removeBlock(TagLib::offset_t start, size_t length) {
|
||||
if (length == 0) return;
|
||||
void RustIOStream::removeBlock(TagLib::offset_t start, size_t length)
|
||||
{
|
||||
if (length == 0)
|
||||
return;
|
||||
|
||||
// Save current position
|
||||
auto current = tell();
|
||||
|
@ -90,39 +101,54 @@ void RustIOStream::removeBlock(TagLib::offset_t start, size_t length) {
|
|||
seek(current);
|
||||
}
|
||||
|
||||
void RustIOStream::seek(TagLib::offset_t offset, Position p) {
|
||||
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");
|
||||
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() {
|
||||
void RustIOStream::clear()
|
||||
{
|
||||
truncate(0);
|
||||
seek(0);
|
||||
}
|
||||
|
||||
void RustIOStream::truncate(TagLib::offset_t length) {
|
||||
void RustIOStream::truncate(TagLib::offset_t length)
|
||||
{
|
||||
rust_stream_truncate(rust_stream, length);
|
||||
}
|
||||
|
||||
TagLib::offset_t RustIOStream::tell() const {
|
||||
TagLib::offset_t RustIOStream::tell() const
|
||||
{
|
||||
return rust_stream_tell(rust_stream);
|
||||
}
|
||||
|
||||
TagLib::offset_t RustIOStream::length() {
|
||||
TagLib::offset_t RustIOStream::length()
|
||||
{
|
||||
return rust_stream_length(rust_stream);
|
||||
}
|
||||
|
||||
bool RustIOStream::readOnly() const {
|
||||
bool RustIOStream::readOnly() const
|
||||
{
|
||||
return rust_stream_is_readonly(rust_stream);
|
||||
}
|
||||
|
||||
bool RustIOStream::isOpen() const {
|
||||
bool RustIOStream::isOpen() const
|
||||
{
|
||||
return true; // If we have a stream, it's open
|
||||
}
|
||||
|
||||
|
|
|
@ -5,13 +5,15 @@
|
|||
#include <taglib/tiostream.h>
|
||||
#include <taglib/fileref.h>
|
||||
|
||||
namespace taglib_shim {
|
||||
namespace taglib_shim
|
||||
{
|
||||
|
||||
// Forward declaration of the Rust-side stream
|
||||
struct RustStream;
|
||||
|
||||
// C++ implementation of TagLib::IOStream that delegates to Rust
|
||||
class RustIOStream : public TagLib::IOStream {
|
||||
class RustIOStream : public TagLib::IOStream
|
||||
{
|
||||
public:
|
||||
explicit RustIOStream(RustStream *stream);
|
||||
~RustIOStream() override;
|
||||
|
|
|
@ -1,27 +1,33 @@
|
|||
#include "tk_shim.hpp"
|
||||
|
||||
|
||||
namespace taglib_shim {
|
||||
namespace taglib_shim
|
||||
{
|
||||
Property::Property(TagLib::String key, TagLib::StringList value) : key_(key), value_(value) {}
|
||||
|
||||
const TagLib::String &Property::key() const {
|
||||
const TagLib::String &Property::key() const
|
||||
{
|
||||
return key_;
|
||||
}
|
||||
|
||||
const TagLib::StringList &Property::value() const {
|
||||
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>> 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,9 +7,11 @@
|
|||
#include <memory>
|
||||
#include <iterator>
|
||||
|
||||
namespace taglib_shim {
|
||||
namespace taglib_shim
|
||||
{
|
||||
|
||||
struct Property {
|
||||
struct Property
|
||||
{
|
||||
Property(TagLib::String key, TagLib::StringList value);
|
||||
const TagLib::String &key() const;
|
||||
const TagLib::StringList &value() const;
|
||||
|
|
Loading…
Reference in a new issue