musikr.metadata: dont expose file name
Not needed.
This commit is contained in:
parent
c431e90af8
commit
7e8764d6d4
5 changed files with 10 additions and 22 deletions
|
@ -30,8 +30,6 @@ JVMInputStream::JVMInputStream(JNIEnv *env, jobject inputStream) : env(env), inp
|
||||||
}
|
}
|
||||||
jclass inputStreamClass = env->FindClass(
|
jclass inputStreamClass = env->FindClass(
|
||||||
"org/oxycblt/musikr/metadata/NativeInputStream");
|
"org/oxycblt/musikr/metadata/NativeInputStream");
|
||||||
inputStreamNameMethod = env->GetMethodID(inputStreamClass, "name",
|
|
||||||
"()Ljava/lang/String;");
|
|
||||||
inputStreamReadBlockMethod = env->GetMethodID(inputStreamClass, "readBlock",
|
inputStreamReadBlockMethod = env->GetMethodID(inputStreamClass, "readBlock",
|
||||||
"(J)[B");
|
"(J)[B");
|
||||||
inputStreamIsOpenMethod = env->GetMethodID(inputStreamClass, "isOpen",
|
inputStreamIsOpenMethod = env->GetMethodID(inputStreamClass, "isOpen",
|
||||||
|
@ -55,12 +53,8 @@ JVMInputStream::~JVMInputStream() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TagLib::FileName JVMInputStream::name() const {
|
TagLib::FileName JVMInputStream::name() const {
|
||||||
auto name = (jstring) env->CallObjectMethod(inputStream,
|
// Not actually used except in FileRef, can safely ignore.
|
||||||
inputStreamNameMethod);
|
return "";
|
||||||
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) {
|
TagLib::ByteVector JVMInputStream::readBlock(size_t length) {
|
||||||
|
|
|
@ -19,20 +19,18 @@
|
||||||
package org.oxycblt.musikr.metadata
|
package org.oxycblt.musikr.metadata
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.net.Uri
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.nio.ByteBuffer
|
import java.nio.ByteBuffer
|
||||||
|
|
||||||
internal class AndroidInputStream(context: Context, fileRef: FileRef) : NativeInputStream {
|
internal class AndroidInputStream(context: Context, uri: Uri) : NativeInputStream {
|
||||||
private val fileName = fileRef.fileName
|
|
||||||
private val fd =
|
private val fd =
|
||||||
requireNotNull(context.contentResolver.openFileDescriptor(fileRef.uri, "r")) {
|
requireNotNull(context.contentResolver.openFileDescriptor(uri, "r")) {
|
||||||
"Failed to open file descriptor for ${fileRef.fileName}"
|
"Failed to open file descriptor for $uri"
|
||||||
}
|
}
|
||||||
private val fis = FileInputStream(fd.fileDescriptor)
|
private val fis = FileInputStream(fd.fileDescriptor)
|
||||||
private val channel = fis.channel
|
private val channel = fis.channel
|
||||||
|
|
||||||
override fun name() = fileName
|
|
||||||
|
|
||||||
override fun readBlock(length: Long): ByteArray {
|
override fun readBlock(length: Long): ByteArray {
|
||||||
val buffer = ByteBuffer.allocate(length.toInt())
|
val buffer = ByteBuffer.allocate(length.toInt())
|
||||||
channel.read(buffer)
|
channel.read(buffer)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.oxycblt.musikr.metadata
|
package org.oxycblt.musikr.metadata
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
@ -35,6 +35,6 @@ internal interface MetadataExtractor {
|
||||||
private class MetadataExtractorImpl(private val context: Context) : MetadataExtractor {
|
private class MetadataExtractorImpl(private val context: Context) : MetadataExtractor {
|
||||||
override suspend fun extract(file: DeviceFile) =
|
override suspend fun extract(file: DeviceFile) =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
TagLibJNI.open(context, FileRef(unlikelyToBeNull(file.path.name), file.uri))
|
TagLibJNI.open(context, file.uri)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,6 @@ package org.oxycblt.musikr.metadata
|
||||||
* The vast majority of IO shim between Taglib/KTaglib should occur here to minimize JNI calls.
|
* The vast majority of IO shim between Taglib/KTaglib should occur here to minimize JNI calls.
|
||||||
*/
|
*/
|
||||||
internal interface NativeInputStream {
|
internal interface NativeInputStream {
|
||||||
fun name(): String
|
|
||||||
|
|
||||||
fun readBlock(length: Long): ByteArray
|
fun readBlock(length: Long): ByteArray
|
||||||
|
|
||||||
fun isOpen(): Boolean
|
fun isOpen(): Boolean
|
||||||
|
|
|
@ -31,8 +31,8 @@ internal object TagLibJNI {
|
||||||
*
|
*
|
||||||
* Note: This method is blocking and should be handled as such if calling from a coroutine.
|
* Note: This method is blocking and should be handled as such if calling from a coroutine.
|
||||||
*/
|
*/
|
||||||
fun open(context: Context, ref: FileRef): Metadata? {
|
fun open(context: Context, uri: Uri): Metadata? {
|
||||||
val inputStream = AndroidInputStream(context, ref)
|
val inputStream = AndroidInputStream(context, uri)
|
||||||
val tag = openNative(inputStream)
|
val tag = openNative(inputStream)
|
||||||
inputStream.close()
|
inputStream.close()
|
||||||
return tag
|
return tag
|
||||||
|
@ -40,5 +40,3 @@ internal object TagLibJNI {
|
||||||
|
|
||||||
private external fun openNative(ioStream: AndroidInputStream): Metadata?
|
private external fun openNative(ioStream: AndroidInputStream): Metadata?
|
||||||
}
|
}
|
||||||
|
|
||||||
internal data class FileRef(val fileName: String, val uri: Uri)
|
|
||||||
|
|
Loading…
Reference in a new issue