mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 17:59:39 +02:00
call VideoRecoder class, do not allow VideoRecording if recoding is not available
This commit is contained in:
parent
3e41bf3533
commit
b1de21af60
2 changed files with 74 additions and 7 deletions
|
@ -109,6 +109,7 @@ import org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener;
|
||||||
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
|
||||||
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
|
||||||
import org.thoughtcrime.securesms.util.views.Stub;
|
import org.thoughtcrime.securesms.util.views.Stub;
|
||||||
|
import org.thoughtcrime.securesms.video.recode.VideoRecoder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -853,7 +854,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
case AttachmentTypeSelector.TAKE_PHOTO:
|
case AttachmentTypeSelector.TAKE_PHOTO:
|
||||||
attachmentManager.capturePhoto(this, TAKE_PHOTO); break;
|
attachmentManager.capturePhoto(this, TAKE_PHOTO); break;
|
||||||
case AttachmentTypeSelector.RECORD_VIDEO:
|
case AttachmentTypeSelector.RECORD_VIDEO:
|
||||||
attachmentManager.captureVideo(this, RECORD_VIDEO); break;
|
if(VideoRecoder.canRecode()) {
|
||||||
|
attachmentManager.captureVideo(this, RECORD_VIDEO);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Toast.makeText(this, "This device does not support video-compression (requires Android 4.4 KitKat)", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -959,7 +966,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
final SettableFuture<Integer> future = new SettableFuture<>();
|
final SettableFuture<Integer> future = new SettableFuture<>();
|
||||||
|
|
||||||
DcMsg msg = null;
|
DcMsg msg = null;
|
||||||
Boolean recompress = Boolean.FALSE;
|
Integer recompress = 0;
|
||||||
|
|
||||||
composeText.setText("");
|
composeText.setText("");
|
||||||
|
|
||||||
|
@ -976,7 +983,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
|
|
||||||
// recompress jpeg-files unless sent as documents
|
// recompress jpeg-files unless sent as documents
|
||||||
if (MediaUtil.isJpegType(contentType) && slideDeck.getDocumentSlide()==null) {
|
if (MediaUtil.isJpegType(contentType) && slideDeck.getDocumentSlide()==null) {
|
||||||
recompress = true;
|
recompress = DcMsg.DC_MSG_IMAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (MediaUtil.isAudioType(contentType)) {
|
else if (MediaUtil.isAudioType(contentType)) {
|
||||||
|
@ -985,6 +992,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
}
|
}
|
||||||
else if (MediaUtil.isVideoType(contentType)) {
|
else if (MediaUtil.isVideoType(contentType)) {
|
||||||
msg = new DcMsg(dcContext, DcMsg.DC_MSG_VIDEO);
|
msg = new DcMsg(dcContext, DcMsg.DC_MSG_VIDEO);
|
||||||
|
recompress = DcMsg.DC_MSG_VIDEO;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
msg = new DcMsg(dcContext, DcMsg.DC_MSG_FILE);
|
msg = new DcMsg(dcContext, DcMsg.DC_MSG_FILE);
|
||||||
|
@ -1008,12 +1016,17 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Object... param) {
|
protected Void doInBackground(Object... param) {
|
||||||
DcMsg msg = (DcMsg)param[0];
|
DcMsg msg = (DcMsg)param[0];
|
||||||
Boolean recompress = (Boolean)param[1];
|
Integer recompress = (Integer)param[1];
|
||||||
if (action==ACTION_SEND_OUT) {
|
if (action==ACTION_SEND_OUT) {
|
||||||
if(msg!=null) {
|
if(msg!=null) {
|
||||||
if(recompress) {
|
if(recompress!=0) {
|
||||||
|
if(recompress==DcMsg.DC_MSG_IMAGE) {
|
||||||
BitmapUtil.recodeImageMsg(ConversationActivity.this, msg);
|
BitmapUtil.recodeImageMsg(ConversationActivity.this, msg);
|
||||||
}
|
}
|
||||||
|
else if(recompress==DcMsg.DC_MSG_VIDEO) {
|
||||||
|
VideoRecoder.recodeVideo(ConversationActivity.this, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
dcContext.sendMsg(dcChat.getId(), msg);
|
dcContext.sendMsg(dcChat.getId(), msg);
|
||||||
Util.runOnMain(()-> sendComplete(dcChat.getId()));
|
Util.runOnMain(()-> sendComplete(dcChat.getId()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.video.recode;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
|
import android.content.Context;
|
||||||
import android.media.MediaCodec;
|
import android.media.MediaCodec;
|
||||||
import android.media.MediaCodecInfo;
|
import android.media.MediaCodecInfo;
|
||||||
import android.media.MediaCodecList;
|
import android.media.MediaCodecList;
|
||||||
|
@ -9,6 +10,8 @@ import android.media.MediaExtractor;
|
||||||
import android.media.MediaFormat;
|
import android.media.MediaFormat;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
|
import com.b44t.messenger.DcMsg;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
|
@ -618,7 +621,7 @@ public class VideoRecoder {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class VideoEditedInfo {
|
public static class VideoEditedInfo {
|
||||||
public long startTime;
|
public long startTime;
|
||||||
public long endTime;
|
public long endTime;
|
||||||
public int rotationValue;
|
public int rotationValue;
|
||||||
|
@ -631,4 +634,55 @@ public class VideoRecoder {
|
||||||
public String originalPath;
|
public String originalPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean canRecode()
|
||||||
|
{
|
||||||
|
boolean canRecode = true;
|
||||||
|
if (Build.VERSION.SDK_INT < 16 /*= Jelly Bean 4.1 (before that codecInfo.getName() was not there) */) {
|
||||||
|
canRecode = false;
|
||||||
|
}
|
||||||
|
else if (Build.VERSION.SDK_INT < 18 /*= Jelly Bean 4.3*/) {
|
||||||
|
try {
|
||||||
|
MediaCodecInfo codecInfo = VideoRecoder.selectCodec(VideoRecoder.MIME_TYPE);
|
||||||
|
if (codecInfo == null) {
|
||||||
|
canRecode = false;
|
||||||
|
} else {
|
||||||
|
String name = codecInfo.getName();
|
||||||
|
if (name.equals("OMX.google.h264.encoder") ||
|
||||||
|
name.equals("OMX.ST.VFM.H264Enc") ||
|
||||||
|
name.equals("OMX.Exynos.avc.enc") ||
|
||||||
|
name.equals("OMX.MARVELL.VIDEO.HW.CODA7542ENCODER") ||
|
||||||
|
name.equals("OMX.MARVELL.VIDEO.H264ENCODER") ||
|
||||||
|
name.equals("OMX.k3.video.encoder.avc") ||
|
||||||
|
name.equals("OMX.TI.DUCATI1.VIDEO.H264E")) {
|
||||||
|
canRecode = false;
|
||||||
|
} else {
|
||||||
|
if (VideoRecoder.selectColorFormat(codecInfo, VideoRecoder.MIME_TYPE) == 0) {
|
||||||
|
canRecode = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
canRecode = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return canRecode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void recodeVideo(Context context, DcMsg msg) {
|
||||||
|
|
||||||
|
if (!canRecode()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String source = msg.getFile();
|
||||||
|
|
||||||
|
VideoEditedInfo vei = new VideoEditedInfo();
|
||||||
|
vei.startTime = 0;
|
||||||
|
vei.endTime = 0;
|
||||||
|
vei.rotationValue = 0;
|
||||||
|
|
||||||
|
VideoRecoder videoRecoder = new VideoRecoder();
|
||||||
|
|
||||||
|
// TODO: call videoRecoder.convertVideo(source, vei);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue