Merge branch 'video-selector' of https://github.com/licaon-kter/Conversations into licaon-kter-video-selector
This commit is contained in:
		
						commit
						84f7aeaea0
					
				|  | @ -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; | ||||||
|  | @ -24,7 +26,7 @@ import eu.siacs.conversations.entities.Message; | ||||||
| import eu.siacs.conversations.persistance.FileBackend; | 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.Android480pFormatStrategy; | import eu.siacs.conversations.utils.Android720pFormatStrategy; | ||||||
| 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 { | ||||||
|  | @ -91,8 +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 int runtime = mXmppConnectionService.getFileBackend().getMediaRuntime(uri); | 		final MediaFormatStrategy formatStrategy = "720".equals(getVideoCompression()) ? new Android720pFormatStrategy() : new Android360pFormatStrategy(); | ||||||
| 		final MediaFormatStrategy formatStrategy = runtime >= 20000 ? new Android360pFormatStrategy() : new Android480pFormatStrategy(); |  | ||||||
| 		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) { | ||||||
|  | @ -168,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()); | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -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; | ||||||
|  |  | ||||||
|  | @ -10,17 +10,17 @@ import net.ypresto.androidtranscoder.format.OutputFormatUnavailableException; | ||||||
| 
 | 
 | ||||||
| import eu.siacs.conversations.Config; | import eu.siacs.conversations.Config; | ||||||
| 
 | 
 | ||||||
| public class Android480pFormatStrategy implements MediaFormatStrategy { | public class Android720pFormatStrategy implements MediaFormatStrategy { | ||||||
| 
 | 
 | ||||||
|     private static final int LONGER_LENGTH = 854; |     private static final int LONGER_LENGTH = 1280; | ||||||
|     private static final int SHORTER_LENGTH = 480; |     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; | ||||||
| 
 | 
 | ||||||
|     public Android480pFormatStrategy() { |     public Android720pFormatStrategy() { | ||||||
|         mVideoBitrate = DEFAULT_VIDEO_BITRATE; |         mVideoBitrate = DEFAULT_VIDEO_BITRATE; | ||||||
|         mAudioBitrate = DEFAULT_AUDIO_BITRATE; |         mAudioBitrate = DEFAULT_AUDIO_BITRATE; | ||||||
|         mAudioChannels = 2; |         mAudioChannels = 2; | ||||||
|  | @ -46,7 +46,7 @@ public class Android480pFormatStrategy implements MediaFormatStrategy { | ||||||
|             throw new OutputFormatUnavailableException("This video is not 16:9, and is not able to transcode. (" + width + "x" + height + ")"); |             throw new OutputFormatUnavailableException("This video is not 16:9, and is not able to transcode. (" + width + "x" + height + ")"); | ||||||
|         } |         } | ||||||
|         if (shorter <= SHORTER_LENGTH) { |         if (shorter <= SHORTER_LENGTH) { | ||||||
|             Log.d(Config.LOGTAG, "This video is less or equal to 360p, pass-through. (" + width + "x" + height + ")"); |             Log.d(Config.LOGTAG, "This video is less or equal to 720p, pass-through. (" + width + "x" + height + ")"); | ||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
|         MediaFormat format = MediaFormat.createVideoFormat("video/avc", outWidth, outHeight); |         MediaFormat format = MediaFormat.createVideoFormat("video/avc", outWidth, outHeight); | ||||||
|  | @ -112,4 +112,14 @@ | ||||||
| 		<item>@string/medium</item> | 		<item>@string/medium</item> | ||||||
| 		<item>@string/large</item> | 		<item>@string/large</item> | ||||||
| 	</string-array> | 	</string-array> | ||||||
|  | 
 | ||||||
|  | 	<string-array name="video_compression_values"> | ||||||
|  | 		<item>360</item> | ||||||
|  | 		<item>720</item> | ||||||
|  | 	</string-array> | ||||||
|  | 
 | ||||||
|  | 	<string-array name="video_compression_entries"> | ||||||
|  | 		<item>@string/video_360p</item> | ||||||
|  | 		<item>@string/video_720p</item> | ||||||
|  | 	</string-array> | ||||||
| </resources> | </resources> | ||||||
|  |  | ||||||
|  | @ -42,4 +42,5 @@ | ||||||
|     <string name="default_font_size">small</string> |     <string name="default_font_size">small</string> | ||||||
|     <bool name="use_share_location_plugin">false</bool> |     <bool name="use_share_location_plugin">false</bool> | ||||||
|     <bool name="start_searching">false</bool> |     <bool name="start_searching">false</bool> | ||||||
|  |     <string name="video_compression">360</string> | ||||||
| </resources> | </resources> | ||||||
|  |  | ||||||
|  | @ -740,4 +740,8 @@ | ||||||
|     <string name="media_browser">Media browser</string> |     <string name="media_browser">Media browser</string> | ||||||
|     <string name="export_channel_name">History export</string> |     <string name="export_channel_name">History export</string> | ||||||
|     <string name="security_violation_not_attaching_file">File omitted due to security violation.</string> |     <string name="security_violation_not_attaching_file">File omitted due to security violation.</string> | ||||||
|  |     <string name="pref_video_compression">Compress Videos</string> | ||||||
|  |     <string name="pref_video_compression_summary">Resize and compress videos</string> | ||||||
|  |     <string name="video_360p">SD (360p)</string> | ||||||
|  |     <string name="video_720p">HD (720p)</string> | ||||||
| </resources> | </resources> | ||||||
|  |  | ||||||
|  | @ -137,6 +137,13 @@ | ||||||
|             android:key="picture_compression" |             android:key="picture_compression" | ||||||
|             android:summary="@string/pref_picture_compression_summary" |             android:summary="@string/pref_picture_compression_summary" | ||||||
|             android:title="@string/pref_picture_compression" /> |             android:title="@string/pref_picture_compression" /> | ||||||
|  |         <ListPreference | ||||||
|  |             android:defaultValue="@string/video_compression" | ||||||
|  |             android:entries="@array/video_compression_entries" | ||||||
|  |             android:entryValues="@array/video_compression_values" | ||||||
|  |             android:key="video_compression" | ||||||
|  |             android:summary="@string/pref_video_compression_summary" | ||||||
|  |             android:title="@string/pref_video_compression" /> | ||||||
|         <CheckBoxPreference |         <CheckBoxPreference | ||||||
|             android:defaultValue="@bool/use_share_location_plugin" |             android:defaultValue="@bool/use_share_location_plugin" | ||||||
|             android:key="use_share_location_plugin" |             android:key="use_share_location_plugin" | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Daniel Gultsch
						Daniel Gultsch