From a3be1e964c2fd97875579e5a1ca1b88aaceaf7d1 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 21 Sep 2017 21:54:10 +0200 Subject: [PATCH] execute video compression on seperate thread --- .../services/AttachFileToConversationRunnable.java | 3 +++ .../conversations/services/XmppConnectionService.java | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java b/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java index f68056be8..9d9f200e3 100644 --- a/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java +++ b/src/main/java/eu/siacs/conversations/services/AttachFileToConversationRunnable.java @@ -42,6 +42,9 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod this.isVideoMessage = (mimeType != null && mimeType.startsWith("video/") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2); } + public boolean isVideoMessage() { + return this.isVideoMessage; + } private void processAsFile() { final String path = mXmppConnectionService.getFileBackend().getOriginalPath(uri); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 1d894b8f3..9ae69f435 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -156,6 +156,7 @@ public class XmppConnectionService extends Service { public static final String ACTION_GCM_TOKEN_REFRESH = "gcm_token_refresh"; public static final String ACTION_GCM_MESSAGE_RECEIVED = "gcm_message_received"; private final SerialSingleThreadExecutor mFileAddingExecutor = new SerialSingleThreadExecutor(); + private final SerialSingleThreadExecutor mVideoCompressionExecutor = new SerialSingleThreadExecutor(); private final SerialSingleThreadExecutor mDatabaseExecutor = new SerialSingleThreadExecutor(); private ReplacingSerialSingleThreadExecutor mContactMergerExecutor = new ReplacingSerialSingleThreadExecutor(true); private final IBinder mBinder = new XmppConnectionBinder(); @@ -487,8 +488,12 @@ public class XmppConnectionService extends Service { } message.setCounterpart(conversation.getNextCounterpart()); message.setType(Message.TYPE_FILE); - AttachFileToConversationRunnable runnable = new AttachFileToConversationRunnable(this,uri,message,callback); - mFileAddingExecutor.execute(runnable); + final AttachFileToConversationRunnable runnable = new AttachFileToConversationRunnable(this,uri,message,callback); + if (runnable.isVideoMessage()) { + mVideoCompressionExecutor.execute(runnable); + } else { + mFileAddingExecutor.execute(runnable); + } } public void attachImageToConversation(final Conversation conversation, final Uri uri, final UiCallback callback) {