execute video compression on seperate thread

This commit is contained in:
Daniel Gultsch 2017-09-21 21:54:10 +02:00
parent e5becc2e12
commit a3be1e964c
2 changed files with 10 additions and 2 deletions

View File

@ -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); 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() { private void processAsFile() {
final String path = mXmppConnectionService.getFileBackend().getOriginalPath(uri); final String path = mXmppConnectionService.getFileBackend().getOriginalPath(uri);

View File

@ -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_TOKEN_REFRESH = "gcm_token_refresh";
public static final String ACTION_GCM_MESSAGE_RECEIVED = "gcm_message_received"; public static final String ACTION_GCM_MESSAGE_RECEIVED = "gcm_message_received";
private final SerialSingleThreadExecutor mFileAddingExecutor = new SerialSingleThreadExecutor(); private final SerialSingleThreadExecutor mFileAddingExecutor = new SerialSingleThreadExecutor();
private final SerialSingleThreadExecutor mVideoCompressionExecutor = new SerialSingleThreadExecutor();
private final SerialSingleThreadExecutor mDatabaseExecutor = new SerialSingleThreadExecutor(); private final SerialSingleThreadExecutor mDatabaseExecutor = new SerialSingleThreadExecutor();
private ReplacingSerialSingleThreadExecutor mContactMergerExecutor = new ReplacingSerialSingleThreadExecutor(true); private ReplacingSerialSingleThreadExecutor mContactMergerExecutor = new ReplacingSerialSingleThreadExecutor(true);
private final IBinder mBinder = new XmppConnectionBinder(); private final IBinder mBinder = new XmppConnectionBinder();
@ -487,9 +488,13 @@ public class XmppConnectionService extends Service {
} }
message.setCounterpart(conversation.getNextCounterpart()); message.setCounterpart(conversation.getNextCounterpart());
message.setType(Message.TYPE_FILE); message.setType(Message.TYPE_FILE);
AttachFileToConversationRunnable runnable = new AttachFileToConversationRunnable(this,uri,message,callback); final AttachFileToConversationRunnable runnable = new AttachFileToConversationRunnable(this,uri,message,callback);
if (runnable.isVideoMessage()) {
mVideoCompressionExecutor.execute(runnable);
} else {
mFileAddingExecutor.execute(runnable); mFileAddingExecutor.execute(runnable);
} }
}
public void attachImageToConversation(final Conversation conversation, final Uri uri, final UiCallback<Message> callback) { public void attachImageToConversation(final Conversation conversation, final Uri uri, final UiCallback<Message> callback) {
if (FileBackend.weOwnFile(this, uri)) { if (FileBackend.weOwnFile(this, uri)) {