mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 17:48:33 +00:00
Improve video transcoding exception handling.
Previously, we'd crash if we couldn't find the attachment at runtime, but that's not uncommon if someone deletes before sending. Now we just fail. Also, previously we'd fail if we couldn't create a memory file. Now we will only fail if the attachment is >100mb (same as the other video failures).
This commit is contained in:
parent
9257c6ddf3
commit
c6287547a3
@ -28,6 +28,8 @@ import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
|
|||||||
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
||||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||||
|
import org.thoughtcrime.securesms.util.MemoryFileDescriptor;
|
||||||
|
import org.thoughtcrime.securesms.util.MemoryFileDescriptor.MemoryFileException;
|
||||||
import org.thoughtcrime.securesms.video.InMemoryTranscoder;
|
import org.thoughtcrime.securesms.video.InMemoryTranscoder;
|
||||||
import org.thoughtcrime.securesms.video.VideoSizeException;
|
import org.thoughtcrime.securesms.video.VideoSizeException;
|
||||||
import org.thoughtcrime.securesms.video.VideoSourceException;
|
import org.thoughtcrime.securesms.video.VideoSourceException;
|
||||||
@ -110,7 +112,7 @@ public final class AttachmentCompressionJob extends BaseJob {
|
|||||||
DatabaseAttachment databaseAttachment = database.getAttachment(attachmentId);
|
DatabaseAttachment databaseAttachment = database.getAttachment(attachmentId);
|
||||||
|
|
||||||
if (databaseAttachment == null) {
|
if (databaseAttachment == null) {
|
||||||
throw new IllegalStateException("Cannot find the specified attachment.");
|
throw new UndeliverableMessageException("Cannot find the specified attachment.");
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaConstraints mediaConstraints = mms ? MediaConstraints.getMmsMediaConstraints(mmsSubscriptionId)
|
MediaConstraints mediaConstraints = mms ? MediaConstraints.getMmsMediaConstraints(mmsSubscriptionId)
|
||||||
@ -185,7 +187,7 @@ public final class AttachmentCompressionJob extends BaseJob {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (VideoSourceException | EncodingException e) {
|
} catch (VideoSourceException | EncodingException | MemoryFileException e) {
|
||||||
if (attachment.getSize() > constraints.getVideoMaxSize(context)) {
|
if (attachment.getSize() > constraints.getVideoMaxSize(context)) {
|
||||||
throw new UndeliverableMessageException("Duration not found, attachment too large to skip transcode", e);
|
throw new UndeliverableMessageException("Duration not found, attachment too large to skip transcode", e);
|
||||||
} else {
|
} else {
|
||||||
|
@ -47,12 +47,12 @@ public final class MemoryFileDescriptor implements Closeable {
|
|||||||
* Use zero to avoid RAM check.
|
* Use zero to avoid RAM check.
|
||||||
* @return MemoryFileDescriptor
|
* @return MemoryFileDescriptor
|
||||||
* @throws MemoryLimitException If there is not enough available RAM to comfortably fit this file.
|
* @throws MemoryLimitException If there is not enough available RAM to comfortably fit this file.
|
||||||
* @throws IOException If fails to create a memory file descriptor.
|
* @throws MemoryFileCreationException If fails to create a memory file descriptor.
|
||||||
*/
|
*/
|
||||||
public static MemoryFileDescriptor newMemoryFileDescriptor(@NonNull Context context,
|
public static MemoryFileDescriptor newMemoryFileDescriptor(@NonNull Context context,
|
||||||
@NonNull String debugName,
|
@NonNull String debugName,
|
||||||
long sizeEstimate)
|
long sizeEstimate)
|
||||||
throws MemoryLimitException, IOException
|
throws MemoryFileException
|
||||||
{
|
{
|
||||||
if (sizeEstimate < 0) throw new IllegalArgumentException();
|
if (sizeEstimate < 0) throw new IllegalArgumentException();
|
||||||
|
|
||||||
@ -89,7 +89,8 @@ public final class MemoryFileDescriptor implements Closeable {
|
|||||||
int fileDescriptor = FileUtils.createMemoryFileDescriptor(debugName);
|
int fileDescriptor = FileUtils.createMemoryFileDescriptor(debugName);
|
||||||
|
|
||||||
if (fileDescriptor < 0) {
|
if (fileDescriptor < 0) {
|
||||||
throw new IOException("Failed to create a memory file descriptor " + fileDescriptor);
|
Log.w(TAG, "Failed to create file descriptor: " + fileDescriptor);
|
||||||
|
throw new MemoryFileCreationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MemoryFileDescriptor(ParcelFileDescriptor.adoptFd(fileDescriptor), sizeEstimate);
|
return new MemoryFileDescriptor(ParcelFileDescriptor.adoptFd(fileDescriptor), sizeEstimate);
|
||||||
@ -155,4 +156,13 @@ public final class MemoryFileDescriptor implements Closeable {
|
|||||||
return fileInputStream.getChannel().size();
|
return fileInputStream.getChannel().size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class MemoryFileException extends IOException {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class MemoryLimitException extends MemoryFileException {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class MemoryFileCreationException extends MemoryFileException {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.util;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public final class MemoryLimitException extends IOException {
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user