diff --git a/musikr/src/main/jni/shim/mp4_shim.cpp b/musikr/src/main/jni/shim/mp4_shim.cpp index ae16a98c8..3c2964fdf 100644 --- a/musikr/src/main/jni/shim/mp4_shim.cpp +++ b/musikr/src/main/jni/shim/mp4_shim.cpp @@ -7,12 +7,12 @@ namespace taglib_shim { ItemMapEntry::ItemMapEntry(TagLib::String key, TagLib::MP4::Item value) : key_(std::move(key)), value_(std::move(value)) {} - const TagLib::String& ItemMapEntry::key() const { - return key_; + std::unique_ptr ItemMapEntry::key() const { + return std::make_unique(key_); } - const TagLib::MP4::Item& ItemMapEntry::value() const { - return value_; + std::unique_ptr ItemMapEntry::value() const { + return std::make_unique(value_); } std::unique_ptr> ItemMap_to_entries(const TagLib::MP4::ItemMap& map) { diff --git a/musikr/src/main/jni/shim/mp4_shim.hpp b/musikr/src/main/jni/shim/mp4_shim.hpp index da73a92f6..3a2833ac6 100644 --- a/musikr/src/main/jni/shim/mp4_shim.hpp +++ b/musikr/src/main/jni/shim/mp4_shim.hpp @@ -10,8 +10,8 @@ namespace taglib_shim { class ItemMapEntry { public: ItemMapEntry(TagLib::String key, TagLib::MP4::Item value); - const TagLib::String& key() const; - const TagLib::MP4::Item& value() const; + std::unique_ptr key() const; + std::unique_ptr value() const; private: TagLib::String key_; diff --git a/musikr/src/main/jni/shim/xiph_shim.cpp b/musikr/src/main/jni/shim/xiph_shim.cpp index d15f4c8ae..102ce984a 100644 --- a/musikr/src/main/jni/shim/xiph_shim.cpp +++ b/musikr/src/main/jni/shim/xiph_shim.cpp @@ -4,14 +4,14 @@ namespace taglib_shim { FieldListEntry::FieldListEntry(TagLib::String key, TagLib::StringList value) : key_(key), value_(value) {} - const TagLib::String &FieldListEntry::key() const + std::unique_ptr FieldListEntry::key() const { - return key_; + return std::make_unique(key_); } - const TagLib::StringList &FieldListEntry::value() const + std::unique_ptr FieldListEntry::value() const { - return value_; + return std::make_unique(value_); } std::unique_ptr> FieldListMap_to_entries(const TagLib::SimplePropertyMap &map) diff --git a/musikr/src/main/jni/shim/xiph_shim.hpp b/musikr/src/main/jni/shim/xiph_shim.hpp index 0b8a60752..d2a5cd6df 100644 --- a/musikr/src/main/jni/shim/xiph_shim.hpp +++ b/musikr/src/main/jni/shim/xiph_shim.hpp @@ -8,8 +8,8 @@ namespace taglib_shim struct FieldListEntry { FieldListEntry(TagLib::String key, TagLib::StringList value); - const TagLib::String &key() const; - const TagLib::StringList &value() const; + std::unique_ptr key() const; + std::unique_ptr value() const; private: TagLib::String key_; diff --git a/musikr/src/main/jni/src/taglib/bridge.rs b/musikr/src/main/jni/src/taglib/bridge.rs index f8f8429cc..4accba15f 100644 --- a/musikr/src/main/jni/src/taglib/bridge.rs +++ b/musikr/src/main/jni/src/taglib/bridge.rs @@ -40,6 +40,8 @@ mod bridge_impl { include!("shim/mp4_shim.hpp"); include!("taglib/mpegfile.h"); + // CORE + #[namespace = "TagLib"] #[cxx_name = "IOStream"] type CPPIOStream<'io_stream>; @@ -77,6 +79,8 @@ mod bridge_impl { fn sampleRate(self: &CppAudioProperties) -> i32; fn channels(self: &CppAudioProperties) -> i32; + // XIPH + #[namespace = "TagLib::Ogg::Vorbis"] #[cxx_name = "File"] type CPPVorbisFile; @@ -115,38 +119,20 @@ mod bridge_impl { type CPPFLACPicturePointer; fn get(self: &CPPFLACPicturePointer) -> *const CPPFLACPicture; - #[namespace = "TagLib::MPEG"] - #[cxx_name = "File"] - type CPPMPEGFile; - #[cxx_name = "ID3v1Tag"] - fn MPEGID3v1Tag(self: Pin<&mut CPPMPEGFile>, create: bool) -> *mut CPPID3v1Tag; - #[cxx_name = "ID3v2Tag"] - fn MPEGID3v2Tag(self: Pin<&mut CPPMPEGFile>, create: bool) -> *mut CPPID3v2Tag; - - #[namespace = "TagLib::MP4"] - #[cxx_name = "File"] - type CPPMP4File; - #[cxx_name = "tag"] - fn MP4Tag(self: &CPPMP4File) -> *mut CPPMP4Tag; - - #[namespace = "TagLib::RIFF::WAV"] - #[cxx_name = "File"] - type CPPWAVFile; - #[cxx_name = "ID3v2Tag"] - fn WAVID3v2Tag(self: &CPPWAVFile) -> *mut CPPID3v2Tag; - #[namespace = "TagLib::FLAC"] #[cxx_name = "Picture"] type CPPFLACPicture; #[namespace = "taglib_shim"] fn Picture_data(picture: &CPPFLACPicture) -> UniquePtr; + // XIPHComment + #[namespace = "TagLib::Ogg"] #[cxx_name = "XiphComment"] type CPPXiphComment; // Explicit lifecycle definition to state while the Pin is temporary, the CPPFieldListMap // ref returned actually has the same lifetime as the CPPXiphComment. - fn fieldListMap<'slf, 'file_ref>(self: &'slf CPPXiphComment) -> &'file_ref CPPFieldListMap; + fn fieldListMap(self: &CPPXiphComment) -> &CPPFieldListMap; #[namespace = "TagLib"] #[cxx_name = "SimplePropertyMap"] @@ -159,8 +145,102 @@ mod bridge_impl { #[namespace = "taglib_shim"] #[cxx_name = "FieldListEntry"] type CPPFieldListEntry; - fn key<'slf, 'file_ref>(self: &'slf CPPFieldListEntry) -> &'file_ref CPPString; - fn value<'slf, 'file_ref>(self: &'slf CPPFieldListEntry) -> &'file_ref CPPStringList; + fn key(self: &CPPFieldListEntry) -> UniquePtr; + fn value(self: &CPPFieldListEntry) -> UniquePtr; + + // MPEG + + #[namespace = "TagLib::MPEG"] + #[cxx_name = "File"] + type CPPMPEGFile; + #[cxx_name = "ID3v1Tag"] + fn MPEGID3v1Tag(self: Pin<&mut CPPMPEGFile>, create: bool) -> *mut CPPID3v1Tag; + #[cxx_name = "ID3v2Tag"] + fn MPEGID3v2Tag(self: Pin<&mut CPPMPEGFile>, create: bool) -> *mut CPPID3v2Tag; + + // MP4 + + #[namespace = "TagLib::MP4"] + #[cxx_name = "File"] + type CPPMP4File; + #[cxx_name = "tag"] + fn MP4Tag(self: &CPPMP4File) -> *mut CPPMP4Tag; + + #[namespace = "TagLib::MP4"] + #[cxx_name = "Tag"] + type CPPMP4Tag; + + #[namespace = "TagLib::MP4"] + #[cxx_name = "ItemMap"] + type CPPItemMap; + fn itemMap(self: &CPPMP4Tag) -> &CPPItemMap; + fn ItemMap_to_entries(map: &CPPItemMap) -> UniquePtr>; + + #[namespace = "taglib_shim"] + #[cxx_name = "ItemMapEntry"] + type CPPItemMapEntry; + fn key(self: &CPPItemMapEntry) -> UniquePtr; + fn value(self: &CPPItemMapEntry) -> UniquePtr; + + #[namespace = "TagLib::MP4"] + #[cxx_name = "Item"] + type CPPMP4Item; + fn isValid(self: &CPPMP4Item) -> bool; + fn toBool(self: &CPPMP4Item) -> bool; + fn toInt(self: &CPPMP4Item) -> i32; + fn toByte(self: &CPPMP4Item) -> u8; + fn toUInt(self: &CPPMP4Item) -> u32; + + fn Item_type(item: &CPPMP4Item) -> u32; + #[namespace = "taglib_shim"] + fn Item_toIntPair(item: &CPPMP4Item) -> UniquePtr; + #[namespace = "taglib_shim"] + fn Item_toStringList(item: &CPPMP4Item) -> UniquePtr; + #[namespace = "taglib_shim"] + fn Item_toByteVectorList(item: &CPPMP4Item) -> UniquePtr; + #[namespace = "taglib_shim"] + fn Item_toCoverArtList(item: &CPPMP4Item) -> UniquePtr; + #[namespace = "taglib_shim"] + fn Item_toLongLong(item: &CPPMP4Item) -> i64; + + #[namespace = "taglib_shim"] + #[cxx_name = "IntPair"] + type CPPIntPair; + fn first(self: &CPPIntPair) -> i32; + fn second(self: &CPPIntPair) -> i32; + + #[namespace = "taglib_shim"] + #[cxx_name = "CoverArtList"] + type CPPCoverArtList; + fn to_vector(self: &CPPCoverArtList) -> UniquePtr>; + + #[namespace = "taglib_shim"] + #[cxx_name = "CoverArt"] + type CPPCoverArt; + fn format(self: &CPPCoverArt) -> u32; + fn data(self: &CPPCoverArt) -> UniquePtr; + + #[namespace = "TagLib::RIFF::WAV"] + #[cxx_name = "File"] + type CPPWAVFile; + #[cxx_name = "ID3v2Tag"] + fn WAVID3v2Tag(self: &CPPWAVFile) -> *mut CPPID3v2Tag; + + // ID3v1 + + #[namespace = "TagLib::ID3v1"] + #[cxx_name = "Tag"] + type CPPID3v1Tag; + + fn ID3v1Tag_title(tag: &CPPID3v1Tag) -> UniquePtr; + fn ID3v1Tag_artist(tag: &CPPID3v1Tag) -> UniquePtr; + fn ID3v1Tag_album(tag: &CPPID3v1Tag) -> UniquePtr; + fn ID3v1Tag_comment(tag: &CPPID3v1Tag) -> UniquePtr; + fn ID3v1Tag_genreIndex(tag: &CPPID3v1Tag) -> u32; + fn ID3v1Tag_year(tag: &CPPID3v1Tag) -> u32; + fn ID3v1Tag_track(tag: &CPPID3v1Tag) -> u32; + + // ID3v2 #[namespace = "TagLib::ID3v2"] #[cxx_name = "Tag"] @@ -247,72 +327,6 @@ mod bridge_impl { type CPPByteVector; fn size(self: &CPPByteVector) -> u32; fn data(self: &CPPByteVector) -> *const c_char; - - #[namespace = "TagLib::ID3v1"] - #[cxx_name = "Tag"] - type CPPID3v1Tag; - - fn ID3v1Tag_title(tag: &CPPID3v1Tag) -> UniquePtr; - fn ID3v1Tag_artist(tag: &CPPID3v1Tag) -> UniquePtr; - fn ID3v1Tag_album(tag: &CPPID3v1Tag) -> UniquePtr; - fn ID3v1Tag_comment(tag: &CPPID3v1Tag) -> UniquePtr; - fn ID3v1Tag_genreIndex(tag: &CPPID3v1Tag) -> u32; - fn ID3v1Tag_year(tag: &CPPID3v1Tag) -> u32; - fn ID3v1Tag_track(tag: &CPPID3v1Tag) -> u32; - - #[namespace = "TagLib::MP4"] - #[cxx_name = "Tag"] - type CPPMP4Tag; - - #[namespace = "TagLib::MP4"] - #[cxx_name = "ItemMap"] - type CPPItemMap; - fn itemMap<'slf, 'file_ref>(self: &'slf CPPMP4Tag) -> &'file_ref CPPItemMap; - fn ItemMap_to_entries(map: &CPPItemMap) -> UniquePtr>; - - #[namespace = "taglib_shim"] - #[cxx_name = "ItemMapEntry"] - type CPPItemMapEntry; - fn key<'slf, 'file_ref>(self: &'slf CPPItemMapEntry) -> &'file_ref CPPString; - fn value<'slf, 'file_ref>(self: &'slf CPPItemMapEntry) -> &'file_ref CPPMP4Item; - - #[namespace = "TagLib::MP4"] - #[cxx_name = "Item"] - type CPPMP4Item; - fn isValid(self: &CPPMP4Item) -> bool; - fn toBool(self: &CPPMP4Item) -> bool; - fn toInt(self: &CPPMP4Item) -> i32; - fn toByte(self: &CPPMP4Item) -> u8; - fn toUInt(self: &CPPMP4Item) -> u32; - - fn Item_type(item: &CPPMP4Item) -> u32; - #[namespace = "taglib_shim"] - fn Item_toIntPair(item: &CPPMP4Item) -> UniquePtr; - #[namespace = "taglib_shim"] - fn Item_toStringList(item: &CPPMP4Item) -> UniquePtr; - #[namespace = "taglib_shim"] - fn Item_toByteVectorList(item: &CPPMP4Item) -> UniquePtr; - #[namespace = "taglib_shim"] - fn Item_toCoverArtList(item: &CPPMP4Item) -> UniquePtr; - #[namespace = "taglib_shim"] - fn Item_toLongLong(item: &CPPMP4Item) -> i64; - - #[namespace = "taglib_shim"] - #[cxx_name = "IntPair"] - type CPPIntPair; - fn first(self: &CPPIntPair) -> i32; - fn second(self: &CPPIntPair) -> i32; - - #[namespace = "taglib_shim"] - #[cxx_name = "CoverArtList"] - type CPPCoverArtList; - fn to_vector(self: &CPPCoverArtList) -> UniquePtr>; - - #[namespace = "taglib_shim"] - #[cxx_name = "CoverArt"] - type CPPCoverArt; - fn format(self: &CPPCoverArt) -> u32; - fn data(self: &CPPCoverArt) -> UniquePtr; } } diff --git a/musikr/src/main/jni/src/taglib/mp4.rs b/musikr/src/main/jni/src/taglib/mp4.rs index 5cf8a3097..b7062fae2 100644 --- a/musikr/src/main/jni/src/taglib/mp4.rs +++ b/musikr/src/main/jni/src/taglib/mp4.rs @@ -35,14 +35,14 @@ impl<'file_ref> MP4Tag<'file_ref> { Self { this } } - pub fn item_map(&self) -> ItemMap<'file_ref> { + pub fn item_map(&'file_ref self) -> ItemMap<'file_ref> { let map: &'file_ref CPPItemMap = self.this.as_ref().itemMap(); let map_this = unsafe { RefThis::new(map) }; ItemMap::new(map_this) } } -pub struct ItemMap<'file_ref> { +pub struct ItemMap<'file_ref> { this: RefThis<'file_ref, CPPItemMap>, } @@ -63,11 +63,11 @@ impl<'file_ref> ItemMap<'file_ref> { // - The values returned are copied and thus not dependent on the address // of self. let key_ref = property.key(); - let key_this = unsafe { RefThis::new(key_ref) }; + let key_this = unsafe { OwnedThis::new(key_ref) }.unwrap(); let key = tk::String::new(key_this).to_string(); let value_ref = property.value(); - let value_this = unsafe { RefThis::new(value_ref) }; + let value_this = unsafe { OwnedThis::new(value_ref) }.unwrap(); let value = MP4Item::new(value_this); (key, value) @@ -79,11 +79,11 @@ impl<'file_ref> ItemMap<'file_ref> { } pub struct MP4Item<'file_ref> { - this: RefThis<'file_ref, CPPMP4Item>, + this: OwnedThis<'file_ref, CPPMP4Item>, } impl<'file_ref> MP4Item<'file_ref> { - pub fn new(this: RefThis<'file_ref, CPPMP4Item>) -> Self { + pub fn new(this: OwnedThis<'file_ref, CPPMP4Item>) -> Self { Self { this } } diff --git a/musikr/src/main/jni/src/taglib/xiph.rs b/musikr/src/main/jni/src/taglib/xiph.rs index 9d1b476f7..034091b2c 100644 --- a/musikr/src/main/jni/src/taglib/xiph.rs +++ b/musikr/src/main/jni/src/taglib/xiph.rs @@ -15,7 +15,7 @@ impl<'file_ref> XiphComment<'file_ref> { Self { this } } - pub fn field_list_map(&self) -> FieldListMap<'file_ref> { + pub fn field_list_map(&'file_ref self) -> FieldListMap<'file_ref> { let map: &'file_ref CPPFieldListMap = self.this.as_ref().fieldListMap(); let map_this = unsafe { RefThis::new(map) }; FieldListMap::new(map_this) @@ -39,7 +39,7 @@ impl<'file_ref> FieldListMap<'file_ref> { } impl<'file_ref> FieldListMap<'file_ref> { - pub fn to_hashmap(&self) -> HashMap> { + pub fn to_hashmap(&self) -> HashMap> { let cxx_vec = FieldListMap_to_entries(self.this.as_ref()); cxx_vec .iter() @@ -51,10 +51,10 @@ impl<'file_ref> FieldListMap<'file_ref> { // - The values returned are copied and thus not dependent on the address // of self. let key_ref = property.key(); - let key_this = unsafe { RefThis::new(key_ref) }; + let key_this = unsafe { OwnedThis::new(key_ref) }.unwrap(); let key = tk::String::new(key_this).to_string(); let value_ref = property.value(); - let value_this = unsafe { RefThis::new(value_ref) }; + let value_this = unsafe { OwnedThis::new(value_ref) }.unwrap(); let value = tk::StringList::new(value_this); (key, value) })