Add extra logs for sending media (#5218)
* Add extra logs for sending media We have some issues with stuck media uploads that could use some logs to understand where the process gets stuck. * Fix mocks for test
This commit is contained in:
parent
5a3f803f46
commit
6e6440940f
5 changed files with 36 additions and 5 deletions
|
|
@ -17,6 +17,7 @@ import io.element.android.libraries.androidutils.file.TemporaryUriDeleter
|
|||
import io.element.android.libraries.androidutils.file.createTmpFile
|
||||
import io.element.android.libraries.androidutils.file.getFileName
|
||||
import io.element.android.libraries.androidutils.file.safeRenameTo
|
||||
import io.element.android.libraries.androidutils.hash.hash
|
||||
import io.element.android.libraries.androidutils.media.runAndRelease
|
||||
import io.element.android.libraries.core.coroutine.CoroutineDispatchers
|
||||
import io.element.android.libraries.core.data.tryOrNull
|
||||
|
|
@ -107,6 +108,8 @@ class AndroidMediaPreProcessor @Inject constructor(
|
|||
}.mapFailure { MediaPreProcessor.Failure(it) }
|
||||
|
||||
override fun cleanUp() {
|
||||
Timber.d("Cleaning up temporary media files")
|
||||
|
||||
// Clear temporary files created in older versions of the app
|
||||
cacheDir.listFiles()?.onEach { file ->
|
||||
if (file.isFile) {
|
||||
|
|
@ -129,6 +132,7 @@ class AndroidMediaPreProcessor @Inject constructor(
|
|||
}
|
||||
|
||||
private suspend fun processFile(uri: Uri, mimeType: String): MediaUploadInfo {
|
||||
Timber.d("Processing file ${uri.path.orEmpty().hash()}")
|
||||
val file = copyToTmpFile(uri)
|
||||
val info = FileInfo(
|
||||
mimetype = mimeType,
|
||||
|
|
@ -140,6 +144,7 @@ class AndroidMediaPreProcessor @Inject constructor(
|
|||
}
|
||||
|
||||
private fun MediaUploadInfo.postProcess(uri: Uri): MediaUploadInfo {
|
||||
Timber.d("Finished processing, post-processing ${uri.path.orEmpty().hash()}")
|
||||
val name = context.getFileName(uri) ?: return this
|
||||
val renamedFile = File(context.cacheDir, name).also {
|
||||
file.safeRenameTo(it)
|
||||
|
|
@ -154,6 +159,7 @@ class AndroidMediaPreProcessor @Inject constructor(
|
|||
}
|
||||
|
||||
private suspend fun processImage(uri: Uri, mimeType: String, shouldBeCompressed: Boolean): MediaUploadInfo {
|
||||
Timber.d("Processing image ${uri.path.orEmpty().hash()}")
|
||||
suspend fun processImageWithCompression(): MediaUploadInfo {
|
||||
// Read the orientation metadata from its own stream. Trying to reuse this stream for compression will fail.
|
||||
val orientation = contentResolver.openInputStream(uri).use { input ->
|
||||
|
|
@ -217,6 +223,7 @@ class AndroidMediaPreProcessor @Inject constructor(
|
|||
}
|
||||
|
||||
private suspend fun processVideo(uri: Uri, mimeType: String?, videoCompressionPreset: VideoCompressionPreset): MediaUploadInfo {
|
||||
Timber.d("Processing video ${uri.path.orEmpty().hash()}")
|
||||
val resultFile = runCatchingExceptions {
|
||||
videoCompressor.compress(uri, videoCompressionPreset)
|
||||
.onEach {
|
||||
|
|
@ -244,12 +251,14 @@ class AndroidMediaPreProcessor @Inject constructor(
|
|||
thumbnailFile = thumbnailInfo?.file
|
||||
)
|
||||
} else {
|
||||
Timber.d("Could not transcode video ${uri.path.orEmpty().hash()}, sending original file as plain file")
|
||||
// If the video could not be compressed, just use the original one, but send it as a file
|
||||
return processFile(uri, MimeTypes.OctetStream)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun processAudio(uri: Uri, mimeType: String?): MediaUploadInfo {
|
||||
Timber.d("Processing audio ${uri.path.orEmpty().hash()}")
|
||||
val file = copyToTmpFile(uri)
|
||||
return MediaMetadataRetriever().runAndRelease {
|
||||
setDataSource(context, Uri.fromFile(file))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue