aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-09-19 19:42:56 +0200
committerChristian Schneppe <christian@pix-art.de>2017-09-19 19:42:56 +0200
commit5dddcb32ef11d57fc0bb6f4476e360d414849394 (patch)
tree2fbe5a6ecb4016a644795ba27f0139c5b094a5bc /src/main
parentb52d0e489bf24193d5f677958d488b4374bec12d (diff)
ignore http upload file size constraints for videos that will be compressed
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java33
-rw-r--r--src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java10
2 files changed, 38 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index ee645c50b..62153cb48 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -169,6 +169,18 @@ public class FileBackend {
return true; //exception to be compatible with HTTP Upload < v0.2
}
for (Uri uri : uris) {
+ String mime = context.getContentResolver().getType(uri);
+ if (mime != null && mime.startsWith("video/")) {
+ try {
+ Dimensions dimensions = FileBackend.getVideoDimensions(context, uri);
+ if (dimensions.getMin() >= 720) {
+ Log.d(Config.LOGTAG, "do not consider video file with min width larger or equal than 720 for size check");
+ continue;
+ }
+ } catch (NotAVideoFile notAVideoFile) {
+ //ignore and fall through
+ }
+ }
if (FileBackend.getFileSize(context, uri) > max) {
Log.d(Config.LOGTAG, "not all files are under " + max + " bytes. suggesting falling back to jingle");
return false;
@@ -863,6 +875,17 @@ public class FileBackend {
} catch (Exception e) {
throw new NotAVideoFile();
}
+ return getVideoDimensions(metadataRetriever);
+ }
+
+
+ private static Dimensions getVideoDimensions(Context context, Uri uri) throws NotAVideoFile {
+ MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
+ mediaMetadataRetriever.setDataSource(context, uri);
+ return getVideoDimensions(mediaMetadataRetriever);
+ }
+
+ private static Dimensions getVideoDimensions(MediaMetadataRetriever metadataRetriever) throws NotAVideoFile {
String hasVideo = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_VIDEO);
if (hasVideo == null) {
throw new NotAVideoFile();
@@ -888,7 +911,7 @@ public class FileBackend {
return rotated ? new Dimensions(width, height) : new Dimensions(height, width);
}
- private int extractRotationFromMediaRetriever(MediaMetadataRetriever metadataRetriever) {
+ private static int extractRotationFromMediaRetriever(MediaMetadataRetriever metadataRetriever) {
int rotation;
if (Build.VERSION.SDK_INT >= 17) {
String r = metadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_ROTATION);
@@ -903,7 +926,7 @@ public class FileBackend {
return rotation;
}
- private class Dimensions {
+ private static class Dimensions {
public final int width;
public final int height;
@@ -911,9 +934,13 @@ public class FileBackend {
this.width = width;
this.height = height;
}
+
+ public int getMin() {
+ return Math.min(width, height);
+ }
}
- private class NotAVideoFile extends Exception {
+ private static class NotAVideoFile extends Exception {
}
diff --git a/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java b/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java
index 40e8bd242..1a9980e17 100644
--- a/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java
+++ b/src/main/java/de/pixart/messenger/services/AttachFileToConversationRunnable.java
@@ -13,6 +13,7 @@ import java.io.FileNotFoundException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
+import java.util.concurrent.Future;
import de.pixart.messenger.Config;
import de.pixart.messenger.R;
@@ -81,7 +82,12 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
file.getParentFile().mkdirs();
ParcelFileDescriptor parcelFileDescriptor = mXmppConnectionService.getContentResolver().openFileDescriptor(uri, "r");
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
- MediaTranscoder.getInstance().transcodeVideo(fileDescriptor, file.getAbsolutePath(), MediaFormatStrategyPresets.createAndroidStandardStrategy(mXmppConnectionService.getCompressVideoBitratePreference(), mXmppConnectionService.getCompressVideoResolutionPreference()), this);
+ Future<Void> future = MediaTranscoder.getInstance().transcodeVideo(fileDescriptor, file.getAbsolutePath(), MediaFormatStrategyPresets.createAndroidStandardStrategy(mXmppConnectionService.getCompressVideoBitratePreference(), mXmppConnectionService.getCompressVideoResolutionPreference()), this);
+ try {
+ future.get();
+ } catch (Exception e) {
+ throw new AssertionError(e);
+ }
}
@Override
@@ -113,7 +119,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
@Override
public void onTranscodeFailed(Exception e) {
mXmppConnectionService.stopForcingForegroundNotification();
- Log.d(Config.LOGTAG, "video transcoding failed " + e.getMessage());
+ Log.d(Config.LOGTAG, "video transcoding failed", e);
processAsFile();
}