mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-20 17:57:29 +00:00
Don't fail video send on postprocess failure.
This commit is contained in:
@@ -40,6 +40,7 @@ import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.MemoryFileDescriptor.MemoryFileException;
|
||||
import org.thoughtcrime.securesms.video.InMemoryTranscoder;
|
||||
import org.thoughtcrime.securesms.video.StreamingTranscoder;
|
||||
import org.thoughtcrime.securesms.video.exceptions.VideoPostProcessingException;
|
||||
import org.thoughtcrime.securesms.video.interfaces.TranscoderCancelationSignal;
|
||||
import org.thoughtcrime.securesms.video.TranscoderOptions;
|
||||
import org.thoughtcrime.securesms.video.exceptions.VideoSourceException;
|
||||
@@ -287,7 +288,8 @@ public final class AttachmentCompressionJob extends BaseJob {
|
||||
try {
|
||||
return ModernDecryptingPartInputStream.createFor(attachmentSecret, file, 0);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
Log.w(TAG, "IOException thrown while creating CipherInputStream.", e);
|
||||
throw new VideoPostProcessingException("Exception while opening InputStream!", e);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -295,6 +297,20 @@ public final class AttachmentCompressionJob extends BaseJob {
|
||||
try (MediaStream mediaStream = new MediaStream(postProcessor.process(plaintextLength), MimeTypes.VIDEO_MP4, 0, 0, true)) {
|
||||
attachmentDatabase.updateAttachmentData(attachment, mediaStream, true);
|
||||
faststart = true;
|
||||
} catch (VideoPostProcessingException e) {
|
||||
Log.w(TAG, "Exception thrown during post processing.", e);
|
||||
final Throwable cause = e.getCause();
|
||||
if (cause instanceof IOException) {
|
||||
throw (IOException) cause;
|
||||
} else if (cause instanceof EncodingException) {
|
||||
throw (EncodingException) cause;
|
||||
}
|
||||
}
|
||||
|
||||
if (!faststart) {
|
||||
try (MediaStream mediaStream = new MediaStream(ModernDecryptingPartInputStream.createFor(attachmentSecret, file, 0), MimeTypes.VIDEO_MP4, 0, 0, false)) {
|
||||
attachmentDatabase.updateAttachmentData(attachment, mediaStream, true);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (!file.delete()) {
|
||||
|
||||
@@ -185,7 +185,7 @@ public final class InMemoryTranscoder implements Closeable {
|
||||
final Throwable cause = e.getCause();
|
||||
if (cause instanceof IOException) {
|
||||
throw (IOException) cause;
|
||||
} else if ( cause instanceof EncodingException) {
|
||||
} else if (cause instanceof EncodingException) {
|
||||
throw (EncodingException) cause;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.thoughtcrime.securesms.video.postprocessing
|
||||
import org.signal.core.util.readLength
|
||||
import org.signal.libsignal.media.Mp4Sanitizer
|
||||
import org.signal.libsignal.media.SanitizedMetadata
|
||||
import org.thoughtcrime.securesms.video.exceptions.VideoPostProcessingException
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.FilterInputStream
|
||||
import java.io.IOException
|
||||
@@ -26,7 +27,12 @@ class Mp4FaststartPostProcessor(private val inputStreamFactory: InputStreamFacto
|
||||
* It is the responsibility of the caller to close the resulting [InputStream].
|
||||
*/
|
||||
fun process(inputLength: Long = calculateStreamLength(inputStreamFactory.create())): SequenceInputStream {
|
||||
val metadata = sanitizeMetadata(inputStreamFactory.create(), inputLength)
|
||||
val metadata = inputStreamFactory.create().use { inputStream ->
|
||||
sanitizeMetadata(inputStream, inputLength)
|
||||
}
|
||||
if (metadata.sanitizedMetadata == null) {
|
||||
throw VideoPostProcessingException("Sanitized metadata was null!")
|
||||
}
|
||||
val inputStream = inputStreamFactory.create()
|
||||
inputStream.skip(metadata.dataOffset)
|
||||
return SequenceInputStream(ByteArrayInputStream(metadata.sanitizedMetadata), LimitedInputStream(inputStream, metadata.dataLength))
|
||||
|
||||
Reference in New Issue
Block a user