Fix selector, limit formats to 360 & 720 per CTS
This commit is contained in:
parent
fcccf545ba
commit
a6fef8101b
|
@ -1,8 +1,10 @@
|
||||||
package eu.siacs.conversations.services;
|
package eu.siacs.conversations.services;
|
||||||
|
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import net.ypresto.androidtranscoder.MediaTranscoder;
|
import net.ypresto.androidtranscoder.MediaTranscoder;
|
||||||
|
@ -25,7 +27,6 @@ import eu.siacs.conversations.persistance.FileBackend;
|
||||||
import eu.siacs.conversations.ui.UiCallback;
|
import eu.siacs.conversations.ui.UiCallback;
|
||||||
import eu.siacs.conversations.utils.Android360pFormatStrategy;
|
import eu.siacs.conversations.utils.Android360pFormatStrategy;
|
||||||
import eu.siacs.conversations.utils.Android720pFormatStrategy;
|
import eu.siacs.conversations.utils.Android720pFormatStrategy;
|
||||||
import eu.siacs.conversations.utils.Android1080pFormatStrategy;
|
|
||||||
import eu.siacs.conversations.utils.MimeUtils;
|
import eu.siacs.conversations.utils.MimeUtils;
|
||||||
|
|
||||||
public class AttachFileToConversationRunnable implements Runnable, MediaTranscoder.Listener {
|
public class AttachFileToConversationRunnable implements Runnable, MediaTranscoder.Listener {
|
||||||
|
@ -92,22 +93,7 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
|
||||||
mXmppConnectionService.startForcingForegroundNotification();
|
mXmppConnectionService.startForcingForegroundNotification();
|
||||||
message.setRelativeFilePath(message.getUuid() + ".mp4");
|
message.setRelativeFilePath(message.getUuid() + ".mp4");
|
||||||
final DownloadableFile file = mXmppConnectionService.getFileBackend().getFile(message);
|
final DownloadableFile file = mXmppConnectionService.getFileBackend().getFile(message);
|
||||||
final MediaFormatStrategy formatStrategy;
|
final MediaFormatStrategy formatStrategy = "720".equals(getVideoCompression()) ? new Android720pFormatStrategy() : new Android360pFormatStrategy();
|
||||||
final String compressVideo = mXmppConnectionService.getResources().getString(R.string.video_compression);
|
|
||||||
switch (compressVideo) {
|
|
||||||
case "720":
|
|
||||||
formatStrategy = new Android720pFormatStrategy();
|
|
||||||
Log.d(Config.LOGTAG,"WOOOMP 720 dar " + compressVideo);
|
|
||||||
break;
|
|
||||||
case "1080":
|
|
||||||
formatStrategy = new Android1080pFormatStrategy();
|
|
||||||
Log.d(Config.LOGTAG,"WOOOMP 1080 dar " + compressVideo);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
formatStrategy = new Android360pFormatStrategy();
|
|
||||||
Log.d(Config.LOGTAG,"WOOOMP 360 dar" + compressVideo);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
final ParcelFileDescriptor parcelFileDescriptor = mXmppConnectionService.getContentResolver().openFileDescriptor(uri, "r");
|
final ParcelFileDescriptor parcelFileDescriptor = mXmppConnectionService.getContentResolver().openFileDescriptor(uri, "r");
|
||||||
if (parcelFileDescriptor == null) {
|
if (parcelFileDescriptor == null) {
|
||||||
|
@ -183,4 +169,11 @@ public class AttachFileToConversationRunnable implements Runnable, MediaTranscod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getVideoCompression() {
|
||||||
|
return getPreferences().getString("video_compression", mXmppConnectionService.getResources().getString(R.string.video_compression));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SharedPreferences getPreferences() {
|
||||||
|
return PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService.getApplicationContext());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
package eu.siacs.conversations.utils;
|
|
||||||
|
|
||||||
import android.media.MediaCodecInfo;
|
|
||||||
import android.media.MediaFormat;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import net.ypresto.androidtranscoder.format.MediaFormatExtraConstants;
|
|
||||||
import net.ypresto.androidtranscoder.format.MediaFormatStrategy;
|
|
||||||
import net.ypresto.androidtranscoder.format.OutputFormatUnavailableException;
|
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
|
||||||
|
|
||||||
public class Android1080pFormatStrategy implements MediaFormatStrategy {
|
|
||||||
|
|
||||||
private static final int LONGER_LENGTH = 1920;
|
|
||||||
private static final int SHORTER_LENGTH = 1080;
|
|
||||||
private static final int DEFAULT_VIDEO_BITRATE = 4000 * 1000;
|
|
||||||
private static final int DEFAULT_AUDIO_BITRATE = 128 * 1000;
|
|
||||||
private final int mVideoBitrate;
|
|
||||||
private final int mAudioBitrate;
|
|
||||||
private final int mAudioChannels;
|
|
||||||
|
|
||||||
public Android1080pFormatStrategy() {
|
|
||||||
mVideoBitrate = DEFAULT_VIDEO_BITRATE;
|
|
||||||
mAudioBitrate = DEFAULT_AUDIO_BITRATE;
|
|
||||||
mAudioChannels = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MediaFormat createVideoOutputFormat(MediaFormat inputFormat) {
|
|
||||||
int width = inputFormat.getInteger(MediaFormat.KEY_WIDTH);
|
|
||||||
int height = inputFormat.getInteger(MediaFormat.KEY_HEIGHT);
|
|
||||||
int longer, shorter, outWidth, outHeight;
|
|
||||||
if (width >= height) {
|
|
||||||
longer = width;
|
|
||||||
shorter = height;
|
|
||||||
outWidth = LONGER_LENGTH;
|
|
||||||
outHeight = SHORTER_LENGTH;
|
|
||||||
} else {
|
|
||||||
shorter = width;
|
|
||||||
longer = height;
|
|
||||||
outWidth = SHORTER_LENGTH;
|
|
||||||
outHeight = LONGER_LENGTH;
|
|
||||||
}
|
|
||||||
if (longer * 9 != shorter * 16) {
|
|
||||||
throw new OutputFormatUnavailableException("This video is not 16:9, and is not able to transcode. (" + width + "x" + height + ")");
|
|
||||||
}
|
|
||||||
if (shorter <= SHORTER_LENGTH) {
|
|
||||||
Log.d(Config.LOGTAG, "This video is less or equal to 1080p, pass-through. (" + width + "x" + height + ")");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
MediaFormat format = MediaFormat.createVideoFormat("video/avc", outWidth, outHeight);
|
|
||||||
// From Nexus 4 Camera in 720p
|
|
||||||
format.setInteger(MediaFormat.KEY_BIT_RATE, mVideoBitrate);
|
|
||||||
format.setInteger(MediaFormat.KEY_FRAME_RATE, 30);
|
|
||||||
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, 3);
|
|
||||||
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MediaFormat createAudioOutputFormat(MediaFormat inputFormat) {
|
|
||||||
final MediaFormat format = MediaFormat.createAudioFormat(MediaFormatExtraConstants.MIMETYPE_AUDIO_AAC, inputFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE), mAudioChannels);
|
|
||||||
format.setInteger(MediaFormat.KEY_AAC_PROFILE, MediaCodecInfo.CodecProfileLevel.AACObjectLC);
|
|
||||||
format.setInteger(MediaFormat.KEY_BIT_RATE, mAudioBitrate);
|
|
||||||
return format;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -14,8 +14,8 @@ public class Android360pFormatStrategy implements MediaFormatStrategy {
|
||||||
|
|
||||||
private static final int LONGER_LENGTH = 640;
|
private static final int LONGER_LENGTH = 640;
|
||||||
private static final int SHORTER_LENGTH = 360;
|
private static final int SHORTER_LENGTH = 360;
|
||||||
private static final int DEFAULT_VIDEO_BITRATE = 1000 * 1000; // 1000 kbit/s upper range of what YouTube recommends
|
private static final int DEFAULT_VIDEO_BITRATE = 1000 * 1000;
|
||||||
private static final int DEFAULT_AUDIO_BITRATE = 96 * 1000;
|
private static final int DEFAULT_AUDIO_BITRATE = 128 * 1000;
|
||||||
private final int mVideoBitrate;
|
private final int mVideoBitrate;
|
||||||
private final int mAudioBitrate;
|
private final int mAudioBitrate;
|
||||||
private final int mAudioChannels;
|
private final int mAudioChannels;
|
||||||
|
|
|
@ -14,8 +14,8 @@ public class Android720pFormatStrategy implements MediaFormatStrategy {
|
||||||
|
|
||||||
private static final int LONGER_LENGTH = 1280;
|
private static final int LONGER_LENGTH = 1280;
|
||||||
private static final int SHORTER_LENGTH = 720;
|
private static final int SHORTER_LENGTH = 720;
|
||||||
private static final int DEFAULT_VIDEO_BITRATE = 2000 * 1000; // 2000 kbit/s upper range of what YouTube recommends
|
private static final int DEFAULT_VIDEO_BITRATE = 2000 * 1000;
|
||||||
private static final int DEFAULT_AUDIO_BITRATE = 96 * 1000;
|
private static final int DEFAULT_AUDIO_BITRATE = 192 * 1000;
|
||||||
private final int mVideoBitrate;
|
private final int mVideoBitrate;
|
||||||
private final int mAudioBitrate;
|
private final int mAudioBitrate;
|
||||||
private final int mAudioChannels;
|
private final int mAudioChannels;
|
||||||
|
|
|
@ -116,12 +116,10 @@
|
||||||
<string-array name="video_compression_values">
|
<string-array name="video_compression_values">
|
||||||
<item>360</item>
|
<item>360</item>
|
||||||
<item>720</item>
|
<item>720</item>
|
||||||
<item>1080</item>
|
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="video_compression_entries">
|
<string-array name="video_compression_entries">
|
||||||
<item>@string/video_360p</item>
|
<item>@string/video_360p</item>
|
||||||
<item>@string/video_720p</item>
|
<item>@string/video_720p</item>
|
||||||
<item>@string/video_1080p</item>
|
|
||||||
</string-array>
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue