musikr: reformat

This commit is contained in:
Alexander Capehart 2025-02-12 19:15:01 -07:00
parent f3f349847a
commit 42dfe4edcc
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 36 additions and 47 deletions

View file

@ -47,7 +47,7 @@ fn main() {
} else { } else {
panic!("Unsupported Android target: {}", target); panic!("Unsupported Android target: {}", target);
}; };
let clang_path = env::var("CLANG_PATH").expect("CLANG_PATH env var not set"); let clang_path = env::var("CLANG_PATH").expect("CLANG_PATH env var not set");
let toolchains_marker = "/toolchains"; let toolchains_marker = "/toolchains";
let ndk_path = if let Some(pos) = clang_path.find(toolchains_marker) { let ndk_path = if let Some(pos) = clang_path.find(toolchains_marker) {

View file

@ -13,10 +13,7 @@ impl<'local, 'a> JInputStream<'local, 'a> {
env: &'a mut JNIEnv<'local>, env: &'a mut JNIEnv<'local>,
input: JObject<'local>, input: JObject<'local>,
) -> Result<Self, jni::errors::Error> { ) -> Result<Self, jni::errors::Error> {
Ok(JInputStream { Ok(JInputStream { env, input })
env,
input,
})
} }
} }

View file

@ -2,11 +2,11 @@ use jni::objects::{JClass, JObject};
use jni::sys::jstring; use jni::sys::jstring;
use jni::JNIEnv; use jni::JNIEnv;
mod taglib;
mod jni_stream; mod jni_stream;
mod taglib;
pub use taglib::*;
use jni_stream::JInputStream; use jni_stream::JInputStream;
pub use taglib::*;
#[no_mangle] #[no_mangle]
pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>( pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>(
@ -19,7 +19,9 @@ pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>(
Ok(stream) => stream, Ok(stream) => stream,
Err(e) => { Err(e) => {
let error = format!("Failed to create input stream: {}", e); let error = format!("Failed to create input stream: {}", e);
let error_str = env.new_string(error).expect("Couldn't create error string!"); let error_str = env
.new_string(error)
.expect("Couldn't create error string!");
return error_str.into_raw(); return error_str.into_raw();
} }
}; };
@ -29,7 +31,9 @@ pub extern "C" fn Java_org_oxycblt_musikr_metadata_MetadataJNI_openFile<'local>(
Some(file_ref) => file_ref, Some(file_ref) => file_ref,
None => { None => {
let error = "Failed to create File"; let error = "Failed to create File";
let error_str = env.new_string(error).expect("Couldn't create error string!"); let error_str = env
.new_string(error)
.expect("Couldn't create error string!");
return error_str.into_raw(); return error_str.into_raw();
} }
}; };

View file

@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::ffi::CStr; use std::ffi::CStr;
use std::pin::Pin; use std::pin::Pin;
use std::string::ToString; use std::string::ToString;
use std::collections::HashMap;
#[cxx::bridge] #[cxx::bridge]
pub(crate) mod bindings { pub(crate) mod bindings {
@ -148,7 +148,7 @@ impl bindings::FileRef {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The file data is a pointer that does not depend on the // - The file data is a pointer that does not depend on the
// address of self. // address of self.
let this = Pin::new_unchecked(&*self); let this = Pin::new_unchecked(&*self);
@ -179,7 +179,7 @@ impl bindings::BaseFile {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The audio properties data is a pointer that does not depend on the // - The audio properties data is a pointer that does not depend on the
// address of self. // address of self.
let this: Pin<&bindings::BaseFile> = Pin::new_unchecked(self); let this: Pin<&bindings::BaseFile> = Pin::new_unchecked(self);
@ -195,7 +195,7 @@ impl bindings::BaseFile {
props.as_ref() props.as_ref()
} }
} }
pub fn as_opus(&self) -> Option<&bindings::OpusFile> { pub fn as_opus(&self) -> Option<&bindings::OpusFile> {
let ptr_self = self as *const Self; let ptr_self = self as *const Self;
let opus_file = unsafe { let opus_file = unsafe {
@ -243,7 +243,7 @@ impl bindings::AudioProperties {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The value is copied and thus not dependent on the address of self. // - The value is copied and thus not dependent on the address of self.
let this = Pin::new_unchecked(self); let this = Pin::new_unchecked(self);
this.thisLengthInMilliseconds() this.thisLengthInMilliseconds()
@ -255,7 +255,7 @@ impl bindings::AudioProperties {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The value is copied and thus not dependent on the address of self. // - The value is copied and thus not dependent on the address of self.
let this = Pin::new_unchecked(self); let this = Pin::new_unchecked(self);
this.thisBitrate() this.thisBitrate()
@ -267,7 +267,7 @@ impl bindings::AudioProperties {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The value is copied and thus not dependent on the address of self. // - The value is copied and thus not dependent on the address of self.
let this = Pin::new_unchecked(self); let this = Pin::new_unchecked(self);
this.thisSampleRate() this.thisSampleRate()
@ -279,7 +279,7 @@ impl bindings::AudioProperties {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The value is copied and thus not dependent on the address of self. // - The value is copied and thus not dependent on the address of self.
let this = Pin::new_unchecked(self); let this = Pin::new_unchecked(self);
this.thisChannels() this.thisChannels()
@ -293,12 +293,12 @@ impl bindings::OpusFile {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The value is a pointer that does not depend on the address of self. // - The value is a pointer that does not depend on the address of self.
let this = Pin::new_unchecked(self); let this = Pin::new_unchecked(self);
this.opusThisTag() this.opusThisTag()
}; };
unsafe { unsafe {
// SAFETY: This pointer is a valid type, and can only used and accessed // SAFETY: This pointer is a valid type, and can only used and accessed
// via this function and thus cannot be mutated, satisfying the aliasing rules. // via this function and thus cannot be mutated, satisfying the aliasing rules.
tag.as_ref() tag.as_ref()
@ -312,12 +312,12 @@ impl bindings::VorbisFile {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The value is a pointer that does not depend on the address of self. // - The value is a pointer that does not depend on the address of self.
let this = Pin::new_unchecked(self); let this = Pin::new_unchecked(self);
this.vorbisThisTag() this.vorbisThisTag()
}; };
unsafe { unsafe {
// SAFETY: This pointer is a valid type, and can only used and accessed // SAFETY: This pointer is a valid type, and can only used and accessed
// via this function and thus cannot be mutated, satisfying the aliasing rules. // via this function and thus cannot be mutated, satisfying the aliasing rules.
tag.as_ref() tag.as_ref()
@ -331,7 +331,7 @@ impl bindings::XiphComment {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The value is a reference that does not depend on the address of self. // - The value is a reference that does not depend on the address of self.
let this = Pin::new_unchecked(self); let this = Pin::new_unchecked(self);
this.thisFieldListMap() this.thisFieldListMap()
@ -345,7 +345,7 @@ impl bindings::SimplePropertyMap {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The value is a unique_ptr to a copied vector that is not dependent // - The value is a unique_ptr to a copied vector that is not dependent
// on the address of self. // on the address of self.
let this = Pin::new_unchecked(self); let this = Pin::new_unchecked(self);
@ -361,7 +361,7 @@ impl bindings::Property {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The values returned are copied and thus not dependent on the address // - The values returned are copied and thus not dependent on the address
// of self. // of self.
let this = Pin::new_unchecked(self); let this = Pin::new_unchecked(self);
@ -377,26 +377,26 @@ impl ToString for bindings::TString {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The value returned are pointers and thus not dependent on the address // - The value returned are pointers and thus not dependent on the address
// of self. // of self.
let this: Pin<&bindings::TString> = Pin::new_unchecked(self); let this: Pin<&bindings::TString> = Pin::new_unchecked(self);
this.thisToCString(true) this.thisToCString(true)
}; };
unsafe { unsafe {
// SAFETY: // SAFETY:
// - This is a C-string returned by a C++ method guaranteed to have // - This is a C-string returned by a C++ method guaranteed to have
// a null terminator. // a null terminator.
// - This C-string is fully allocated and owned by the TagString instance, // - This C-string is fully allocated and owned by the TagString instance,
// in a continous block from start to null terminator. // in a continous block from start to null terminator.
// - This C-string will be non-null even if empty. // - This C-string will be non-null even if empty.
// - This pointer will not be mutated before it's entirely copied into // - This pointer will not be mutated before it's entirely copied into
// rust. // rust.
// - This C-string is copied to a rust string before TagString is destroyed. // - This C-string is copied to a rust string before TagString is destroyed.
CStr::from_ptr(c_str) CStr::from_ptr(c_str)
} }
.to_string_lossy() .to_string_lossy()
.to_string() .to_string()
} }
} }
@ -406,7 +406,7 @@ impl bindings::TStringList {
// SAFETY: // SAFETY:
// - This pin is only used in this unsafe scope. // - This pin is only used in this unsafe scope.
// - The pin is used as a C++ this pointer in the ffi call, which does // - The pin is used as a C++ this pointer in the ffi call, which does
// not change address by C++ semantics. // not change address by C++ semantics.
// - The value returned is a unique ptr to a copied vector that is not // - The value returned is a unique ptr to a copied vector that is not
// dependent on the address of self. // dependent on the address of self.
let this = Pin::new_unchecked(self); let this = Pin::new_unchecked(self);

View file

@ -28,33 +28,21 @@ pub extern "C" fn rust_stream_name(stream: *mut c_void) -> *const c_char {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn rust_stream_read( pub extern "C" fn rust_stream_read(stream: *mut c_void, buffer: *mut u8, length: usize) -> usize {
stream: *mut c_void,
buffer: *mut u8,
length: usize,
) -> usize {
let stream = unsafe { &mut *(stream as *mut RustStream<'_>) }; let stream = unsafe { &mut *(stream as *mut RustStream<'_>) };
let buffer = unsafe { std::slice::from_raw_parts_mut(buffer, length) }; let buffer = unsafe { std::slice::from_raw_parts_mut(buffer, length) };
stream.0.read(buffer).unwrap_or(0) stream.0.read(buffer).unwrap_or(0)
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn rust_stream_write( pub extern "C" fn rust_stream_write(stream: *mut c_void, data: *const u8, length: usize) {
stream: *mut c_void,
data: *const u8,
length: usize,
) {
let stream = unsafe { &mut *(stream as *mut RustStream<'_>) }; let stream = unsafe { &mut *(stream as *mut RustStream<'_>) };
let data = unsafe { std::slice::from_raw_parts(data, length) }; let data = unsafe { std::slice::from_raw_parts(data, length) };
stream.0.write_all(data).unwrap(); stream.0.write_all(data).unwrap();
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn rust_stream_seek( pub extern "C" fn rust_stream_seek(stream: *mut c_void, offset: i64, whence: i32) {
stream: *mut c_void,
offset: i64,
whence: i32,
) {
let stream = unsafe { &mut *(stream as *mut RustStream<'_>) }; let stream = unsafe { &mut *(stream as *mut RustStream<'_>) };
let pos = match whence { let pos = match whence {
0 => SeekFrom::Start(offset as u64), 0 => SeekFrom::Start(offset as u64),
@ -91,4 +79,4 @@ pub extern "C" fn rust_stream_length(stream: *mut c_void) -> i64 {
pub extern "C" fn rust_stream_is_readonly(stream: *const c_void) -> bool { pub extern "C" fn rust_stream_is_readonly(stream: *const c_void) -> bool {
let stream = unsafe { &*(stream as *const RustStream<'_>) }; let stream = unsafe { &*(stream as *const RustStream<'_>) };
stream.0.is_readonly() stream.0.is_readonly()
} }