diff --git a/fermata/src/main/java/me/aap/fermata/media/pref/MediaPrefs.java b/fermata/src/main/java/me/aap/fermata/media/pref/MediaPrefs.java index 70b7f355..22eaeda6 100644 --- a/fermata/src/main/java/me/aap/fermata/media/pref/MediaPrefs.java +++ b/fermata/src/main/java/me/aap/fermata/media/pref/MediaPrefs.java @@ -18,14 +18,22 @@ public interface MediaPrefs extends PreferenceStore { int MEDIA_ENG_VLC = 2; int MEDIA_ENG_YT = 3; int MEDIA_ENG_CAST = 4; + int SCALE_BEST = 0; int SCALE_FILL = 1; int SCALE_ORIGINAL = 2; int SCALE_4_3 = 3; int SCALE_16_9 = 4; + int MEDIA_SCANNER_DEFAULT = 0; int MEDIA_SCANNER_SYSTEM = 1; int MEDIA_SCANNER_VLC = 2; + + int HW_ACCEL_AUTO = 0; + int HW_ACCEL_FULL = 1; + int HW_ACCEL_DECODING = 2; + int HW_ACCEL_DISABLED = 3; + Pref AUDIO_ENGINE = Pref.i("AUDIO_ENGINE", MEDIA_ENG_MP); Pref VIDEO_ENGINE = Pref.i("VIDEO_ENGINE", MEDIA_ENG_MP); Pref VIDEO_SCALE = Pref.i("VIDEO_SCALE", SCALE_BEST); @@ -54,6 +62,9 @@ public interface MediaPrefs extends PreferenceStore { Pref> AUDIO_LANG = Pref.s("AUDIO_LANG", ""); Pref> AUDIO_KEY = Pref.s("AUDIO_KEY", ""); Pref WATCHED_THRESHOLD = Pref.i("WATCHED_THRESHOLD", 95); + Pref HW_ACCEL = Pref.i("HW_ACCEL", HW_ACCEL_DECODING); + + default int getAudioEnginePref() { return getIntPref(AUDIO_ENGINE); @@ -85,6 +96,14 @@ default void setVideoScalePref(int scale) { } } + default int getHwAccelPref() { + return getIntPref(HW_ACCEL); + } + + default void setHwAccelPref(int accel) { + applyIntPref(HW_ACCEL, accel); + } + default int getMediaScannerPref() { return getIntPref(MEDIA_SCANNER); } diff --git a/fermata/src/main/java/me/aap/fermata/ui/fragment/SettingsFragment.java b/fermata/src/main/java/me/aap/fermata/ui/fragment/SettingsFragment.java index 2357803a..f2d116ac 100644 --- a/fermata/src/main/java/me/aap/fermata/ui/fragment/SettingsFragment.java +++ b/fermata/src/main/java/me/aap/fermata/ui/fragment/SettingsFragment.java @@ -520,6 +520,16 @@ private PreferenceViewAdapter createAdapter(MainActivityDelegate a) { o.values = new int[]{R.string.video_scaling_best, R.string.video_scaling_fill, R.string.video_scaling_orig, R.string.video_scaling_4, R.string.video_scaling_16}; }); + sub1.addListPref(o -> { + o.store = mediaPrefs; + o.pref = MediaLibPrefs.HW_ACCEL; + o.title = R.string.hw_accel; + o.subtitle = R.string.string_format; + o.formatSubtitle = true; + o.values = new int[]{R.string.hw_accel_auto, R.string.hw_accel_full, + R.string.hw_accel_decoding, R.string.hw_accel_disabled}; + o.visibility = vlcCond; + }); sub1.addListPref(o -> { o.store = a.getPrefs(); o.pref = MainActivityPrefs.CLOCK_POS; @@ -557,7 +567,7 @@ private PreferenceViewAdapter createAdapter(MainActivityDelegate a) { sub2 = sub1.subSet(o -> { o.title = R.string.audio; - o.visibility = PrefCondition.create(mediaPrefs, MediaLibPrefs.VLC_ENABLED); + o.visibility = vlcCond; }); addAudioPrefs(sub2, mediaPrefs, isCar); diff --git a/fermata/src/main/java/me/aap/fermata/ui/view/MediaItemMenuHandler.java b/fermata/src/main/java/me/aap/fermata/ui/view/MediaItemMenuHandler.java index b38fa5cc..8ab1937b 100644 --- a/fermata/src/main/java/me/aap/fermata/ui/view/MediaItemMenuHandler.java +++ b/fermata/src/main/java/me/aap/fermata/ui/view/MediaItemMenuHandler.java @@ -1,6 +1,10 @@ package me.aap.fermata.ui.view; import static java.util.Objects.requireNonNull; +import static me.aap.fermata.media.pref.MediaPrefs.HW_ACCEL_AUTO; +import static me.aap.fermata.media.pref.MediaPrefs.HW_ACCEL_DECODING; +import static me.aap.fermata.media.pref.MediaPrefs.HW_ACCEL_DISABLED; +import static me.aap.fermata.media.pref.MediaPrefs.HW_ACCEL_FULL; import static me.aap.fermata.media.pref.MediaPrefs.SCALE_16_9; import static me.aap.fermata.media.pref.MediaPrefs.SCALE_4_3; import static me.aap.fermata.media.pref.MediaPrefs.SCALE_BEST; @@ -202,6 +206,10 @@ protected void buildVideoMenu(OverlayMenu.Builder b) { b.addItem(R.id.video_scaling, R.string.video_scaling).setSubmenu(this::buildVideoScalingMenu); + if (getMainActivity().getMediaSessionCallback().getEngineManager().isVlcPlayerSupported()) { + b.addItem(R.id.video_scaling, R.string.hw_accel).setSubmenu(this::buildHwAccelMenu); + } + if (!item.isExternal()) { b.addItem(R.id.watched_threshold, R.string.watched_threshold) .setSubmenu(this::buildWatchedThresholdMenu); @@ -287,6 +295,12 @@ private FutureSupplier buildBrowsableMenu(MainActivityDelegate a, OverlayM sb.addItem(R.id.audio_prefs, R.string.audio).setSubmenu(this::buildAudioPrefsMenu); sb.addItem(R.id.video_scaling, R.string.video_scaling) .setSubmenu(this::buildVideoScalingMenu); + + if (a.getMediaSessionCallback().getEngineManager().isVlcPlayerSupported()) { + sb.addItem(R.id.video_scaling, R.string.hw_accel) + .setSubmenu(this::buildHwAccelMenu); + } + sb.addItem(R.id.watched_threshold, R.string.watched_threshold) .setSubmenu(this::buildWatchedThresholdMenu); }); @@ -438,6 +452,19 @@ private void buildVideoScalingMenu(OverlayMenu.Builder b) { b.setSelectionHandler(this); } + private void buildHwAccelMenu(OverlayMenu.Builder b) { + int accel = item.getPrefs().getHwAccelPref(); + b.addItem(R.id.hw_accel_auto, null, R.string.hw_accel_auto) + .setChecked(accel == HW_ACCEL_AUTO, true); + b.addItem(R.id.hw_accel_full, null, R.string.hw_accel_full) + .setChecked(accel == HW_ACCEL_FULL, true); + b.addItem(R.id.hw_accel_decoding, null, R.string.hw_accel_decoding) + .setChecked(accel == HW_ACCEL_DECODING, true); + b.addItem(R.id.hw_accel_disabled, null, R.string.hw_accel_disabled) + .setChecked(accel == HW_ACCEL_DISABLED, true); + b.setSelectionHandler(this); + } + private void buildAudioPrefsMenu(OverlayMenu.Builder b) { PreferenceSet prefSet = new PreferenceSet(); addAudioPrefs(prefSet, item.getPrefs(), getMainActivity().isCarActivity()); @@ -562,6 +589,14 @@ public boolean menuItemSelected(OverlayMenuItem i) { item.getPrefs().setVideoScalePref(SCALE_4_3); } else if (id == R.id.video_scaling_16) { item.getPrefs().setVideoScalePref(SCALE_16_9); + } else if (id == R.id.hw_accel_auto) { + item.getPrefs().setHwAccelPref(HW_ACCEL_AUTO); + } else if (id == R.id.hw_accel_full) { + item.getPrefs().setHwAccelPref(HW_ACCEL_FULL); + } else if (id == R.id.hw_accel_decoding) { + item.getPrefs().setHwAccelPref(HW_ACCEL_DECODING); + } else if (id == R.id.hw_accel_disabled) { + item.getPrefs().setHwAccelPref(HW_ACCEL_DISABLED); } else if (id == R.id.delete) { UiUtils.showQuestion(getContext(), R.string.delete_file_title, R.string.delete_file_question, R.drawable.delete).onSuccess(v -> { diff --git a/fermata/src/main/res/values-ru/strings.xml b/fermata/src/main/res/values-ru/strings.xml index 35e6e38d..b68ac759 100644 --- a/fermata/src/main/res/values-ru/strings.xml +++ b/fermata/src/main/res/values-ru/strings.xml @@ -118,6 +118,11 @@ Видео Настройки видео Масштабирование видео + Аппаратное ускорение + Автоматически + Полное + Декодирование + Выключено Наиболее подходящее Заполнить экран Оригинальный размер diff --git a/fermata/src/main/res/values/ids.xml b/fermata/src/main/res/values/ids.xml index f9293a74..74bc41b1 100644 --- a/fermata/src/main/res/values/ids.xml +++ b/fermata/src/main/res/values/ids.xml @@ -71,6 +71,10 @@ + + + + diff --git a/fermata/src/main/res/values/strings.xml b/fermata/src/main/res/values/strings.xml index 2b9c310e..5586e98f 100644 --- a/fermata/src/main/res/values/strings.xml +++ b/fermata/src/main/res/values/strings.xml @@ -141,6 +141,11 @@ Video Video settings Video scaling + Hardware acceleration + Auto + Full + Decoding + Disabled Best fit Fill screen Original size diff --git a/modules/vlc/src/main/java/me/aap/fermata/engine/vlc/VlcEngine.java b/modules/vlc/src/main/java/me/aap/fermata/engine/vlc/VlcEngine.java index d9271bea..9df76a08 100644 --- a/modules/vlc/src/main/java/me/aap/fermata/engine/vlc/VlcEngine.java +++ b/modules/vlc/src/main/java/me/aap/fermata/engine/vlc/VlcEngine.java @@ -2,6 +2,9 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; import static java.util.Collections.emptyList; +import static me.aap.fermata.media.pref.MediaPrefs.HW_ACCEL_DECODING; +import static me.aap.fermata.media.pref.MediaPrefs.HW_ACCEL_DISABLED; +import static me.aap.fermata.media.pref.MediaPrefs.HW_ACCEL_FULL; import static me.aap.fermata.media.pref.MediaPrefs.SCALE_16_9; import static me.aap.fermata.media.pref.MediaPrefs.SCALE_4_3; import static me.aap.fermata.media.pref.MediaPrefs.SCALE_BEST; @@ -105,12 +108,19 @@ public void prepare(PlayableItem source) { } } + media.addOption(":input-fast-seek"); + switch (source.getPrefs().getHwAccelPref()) { + case HW_ACCEL_DECODING -> { + media.setHWDecoderEnabled(true, true); + media.addOption(":no-mediacodec-dr"); + media.addOption(":no-omxil-dr"); + } + case HW_ACCEL_FULL -> media.setHWDecoderEnabled(true, true); + case HW_ACCEL_DISABLED -> media.setHWDecoderEnabled(false, false); + } + PendingSource pending = new PendingSource(source, media, fd); this.source = pending; - media.setHWDecoderEnabled(true, true); - media.addOption(":no-omxil-dr"); - media.addOption(":no-mediacodec-dr"); - media.addOption(":input-fast-seek"); if (media.isParsed()) { prepared(pending);