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
3 changed files with 17 additions and 11 deletions
|
@ -28,6 +28,8 @@ import org.thoughtcrime.securesms.transport.UndeliverableMessageException;
|
|||
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||
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.VideoSizeException;
|
||||
import org.thoughtcrime.securesms.video.VideoSourceException;
|
||||
|
@ -110,7 +112,7 @@ public final class AttachmentCompressionJob extends BaseJob {
|
|||
DatabaseAttachment databaseAttachment = database.getAttachment(attachmentId);
|
||||
|
||||
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)
|
||||
|
@ -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)) {
|
||||
throw new UndeliverableMessageException("Duration not found, attachment too large to skip transcode", e);
|
||||
} else {
|
||||
|
|
|
@ -47,12 +47,12 @@ public final class MemoryFileDescriptor implements Closeable {
|
|||
* Use zero to avoid RAM check.
|
||||
* @return MemoryFileDescriptor
|
||||
* @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,
|
||||
@NonNull String debugName,
|
||||
long sizeEstimate)
|
||||
throws MemoryLimitException, IOException
|
||||
throws MemoryFileException
|
||||
{
|
||||
if (sizeEstimate < 0) throw new IllegalArgumentException();
|
||||
|
||||
|
@ -89,7 +89,8 @@ public final class MemoryFileDescriptor implements Closeable {
|
|||
int fileDescriptor = FileUtils.createMemoryFileDescriptor(debugName);
|
||||
|
||||
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);
|
||||
|
@ -155,4 +156,13 @@ public final class MemoryFileDescriptor implements Closeable {
|
|||
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…
Add table
Reference in a new issue