refactor(mpv): get rid of last reference to findroid specific code and remove hwdec-codecs and gpu-api options from settings

You will later be able to change hwdec-codecs and gpu-api options using mpv.conf
This commit is contained in:
Jarne Demeulemeester 2023-12-31 16:16:14 +01:00
parent db9a6d6877
commit 96288db877
No known key found for this signature in database
GPG key ID: 1E5C6AFBD622E9F5
30 changed files with 72 additions and 129 deletions

View file

@ -120,7 +120,6 @@
<string name="theme_dark">Oscuro</string>
<string name="settings_category_network">Red</string>
<string name="pref_player_mpv_hwdec">Decodificación por hardware</string>
<string name="pref_player_mpv_hwdec_codecs">Códecs de decodificación por hardware</string>
<string name="pref_player_mpv_vo">Salida de vídeo</string>
<string name="pref_player_mpv_ao">Salida de audio</string>
<string name="addresses">Direcciones</string>

View file

@ -108,7 +108,6 @@
<string name="sort_by_options_1">Classificação IMDB</string>
<string name="sort_by_options_3">data adicionada</string>
<string name="seek_back_increment">Buscar incremento de volta (ms)</string>
<string name="pref_player_mpv_hwdec_codecs">Codecs de decodificação de hardware</string>
<string name="pref_player_mpv_vo">Saida de video</string>
<string name="pref_player_intro_skipper_summary">Requer que o plugin Confused Polar Bears Intro Skipper esteja instalado no servidor</string>
<string name="remove_user">Remover usuário</string>

View file

@ -134,7 +134,6 @@
<string name="pref_player_intro_skipper_summary">Benötigt ConfusedPolarBears Intro Skipper Plugin installiert auf dem Server</string>
<string name="theme_system">Übernehme Systemeinstellung</string>
<string name="pref_player_mpv_hwdec">Hardware-Dekodierung</string>
<string name="pref_player_mpv_hwdec_codecs">Hardware-Dekodierung Codecs</string>
<string name="pref_player_mpv_vo">Videoausgang</string>
<string name="pref_player_mpv_ao">Audioausgang</string>
<string name="pref_player_trick_play">Trickspiel</string>

View file

@ -128,7 +128,6 @@
<string name="users">Usuarios</string>
<string name="add_user">Agregar usuario</string>
<string name="pref_player_mpv_hwdec">Decodificación por hardware</string>
<string name="pref_player_mpv_hwdec_codecs">Codecs con decodificación por hardware</string>
<string name="pref_player_mpv_vo">Salida de video</string>
<string name="pref_player_mpv_ao">Salida de audio</string>
<string name="addresses">Direcciones</string>

View file

@ -125,7 +125,6 @@
<string name="settings_socket_timeout">Esperar zócalo (ms)</string>
<string name="users">Usuarios</string>
<string name="add_user">Agregar usuario</string>
<string name="pref_player_mpv_hwdec_codecs">Codecs de decodificación por hardware</string>
<string name="pref_player_mpv_vo">Salida de video</string>
<string name="pref_player_mpv_ao">Salida de audio</string>
<string name="remove_user">Quitar usuario</string>

View file

@ -123,7 +123,6 @@
<string name="remove_user">Supprimer l\'utilisateur</string>
<string name="remove_user_dialog_text">Voulez-vous vraiment supprimer l\'utilisateur %1$s</string>
<string name="users">Utilisateurs</string>
<string name="pref_player_mpv_hwdec_codecs">Décodages matériels supportés</string>
<string name="quick_connect">Connexion rapide</string>
<string name="pref_player_intro_skipper">Passer l\'introduction</string>
<string name="pref_player_intro_skipper_summary">Le plugin Intro Skipper de ConfusedPolarBear doit être installé sur le serveur</string>

View file

@ -128,7 +128,6 @@
<string name="settings_connect_timeout">Csatlakozási időtúllépés (ms)</string>
<string name="add_user">Felhasználó hozzádása</string>
<string name="pref_player_mpv_hwdec">Hardveres dekódolás</string>
<string name="pref_player_mpv_hwdec_codecs">Hardveres dekódolási kodekek</string>
<string name="settings_socket_timeout">Socket időtúllépése (ms)</string>
<string name="settings_request_timeout">Lekérdezési idő túllépés (ms)</string>
<string name="dynamic_colors">Dinamikus színek</string>

View file

@ -128,7 +128,6 @@
<string name="users">Utenti</string>
<string name="add_user">Aggiungi utente</string>
<string name="pref_player_mpv_hwdec">Decodifica hardware</string>
<string name="pref_player_mpv_hwdec_codecs">Codec di decodifica hardware</string>
<string name="pref_player_mpv_vo">Output video</string>
<string name="addresses">Indirizzi</string>
<string name="add_address">Aggiungi indirizzo</string>

View file

@ -117,7 +117,6 @@
<string name="subtitle">כתוביות</string>
<string name="extra_info">הצג מידע נוסף</string>
<string name="settings_socket_timeout">זמן קצוב ל-Socket (מילי שניות)</string>
<string name="pref_player_mpv_hwdec_codecs">מפענחי חומרה</string>
<string name="pref_player_mpv_vo">יציאת וידאו</string>
<string name="pref_player_mpv_ao">יציאת שמע</string>
<string name="pref_player_intro_skipper">מדלג פתיחים</string>

View file

@ -128,7 +128,6 @@
<string name="add_user">유저 추가</string>
<string name="pref_player_mpv_hwdec">하드웨어 디코딩</string>
<string name="add_server_address">서버 주소 추가</string>
<string name="pref_player_mpv_hwdec_codecs">하드웨어 디코딩 코덱</string>
<string name="pref_player_mpv_vo">비디오 출력</string>
<string name="pref_player_mpv_ao">오디오 출력</string>
<string name="addresses">주소</string>

View file

@ -70,7 +70,6 @@
<string name="seek_forward_increment">Zoek vooruitstap (ms)</string>
<string name="select_video_version_title">Selecteer versie</string>
<string name="pref_player_mpv_hwdec">Hardware decoding</string>
<string name="pref_player_mpv_hwdec_codecs">Hardware decodering codecs</string>
<string name="pref_player_mpv_vo">Video uitvoer</string>
<string name="pref_player_mpv_ao">Audio uitvoer</string>
<string name="libraries">Bibliotheken</string>

View file

@ -122,7 +122,6 @@
<string name="theme_dark">Ciemny</string>
<string name="episodes_label">Odcinki</string>
<string name="add_user">Dodaj użytkownika</string>
<string name="pref_player_mpv_hwdec_codecs">Sprzętowe kodeki do dekodowania</string>
<string name="pref_player_mpv_vo">Wyjście wideo</string>
<string name="pref_player_mpv_ao">Wyjście audio</string>
<string name="seek_back_increment">Krok przesuwania wstecznego (ms)</string>

View file

@ -115,7 +115,6 @@
<string name="users">Usuários</string>
<string name="add_user">Adicionar usuário</string>
<string name="pref_player_mpv_hwdec">Decodificação de hardware</string>
<string name="pref_player_mpv_hwdec_codecs">Codecs de decodificação de hardware</string>
<string name="sort_by_options_3">Data de Adição</string>
<string name="sort_by_options_4">Data de Reprodução</string>
<string name="ascending">Crescente</string>

View file

@ -124,7 +124,6 @@
<string name="remove_user_dialog_text">Tem certeza de que deseja remover o usuário %1$s</string>
<string name="pref_player_mpv_vo">Saida de video</string>
<string name="pref_player_mpv_ao">Saída de áudio</string>
<string name="pref_player_mpv_hwdec_codecs">Codecs de decodificação de hardware</string>
<string name="add_address">Adicionar endereço</string>
<string name="pref_player_trick_play">Jogo de truque</string>
<string name="episode_name">%1$d. %2$s</string>

View file

@ -77,7 +77,6 @@
<string name="users">Utilizatori</string>
<string name="add_user">Adaugă un utilizator</string>
<string name="pref_player_mpv_hwdec">Decodare hardware</string>
<string name="pref_player_mpv_hwdec_codecs">Codecuri de decodare hardware</string>
<string name="pref_player_mpv_vo">Ieșire video</string>
<string name="pref_player_mpv_ao">Ieșire audio</string>
<string name="pref_player_intro_skipper_summary">Necesită ca pluginul IntroSkipper de ConfusedPolarBear să fie instalat pe server</string>

View file

@ -110,7 +110,6 @@
<string name="theme_light">Светлая</string>
<string name="theme_dark">Тёмная</string>
<string name="pref_player_mpv_hwdec">Аппаратное декодирование</string>
<string name="pref_player_mpv_hwdec_codecs">Кодеки аппаратного декодирования</string>
<string name="pref_player_mpv_vo">Вывод видео</string>
<string name="pref_player_intro_skipper">Intro Skipper (Пропуск заставок)</string>
<string name="addresses">Адреса</string>

View file

@ -100,7 +100,6 @@
<string name="settings_socket_timeout">Limit čakania na socket (ms)</string>
<string name="users">Používatelia</string>
<string name="pref_player_mpv_hwdec">Hardvérové dekódovanie</string>
<string name="pref_player_mpv_hwdec_codecs">Kodeky hardvérového dekódovania</string>
<string name="pref_player_mpv_vo">Výstup videa</string>
<string name="pref_player_mpv_ao">Výstup zvuku</string>
<string name="pref_player_intro_skipper_summary">Vyžaduje nainštalovaný plugin Intro Skipper od ConfusedPolarBear na serveri</string>

View file

@ -100,7 +100,6 @@
<string name="users">Uporabniki</string>
<string name="add_user">Dodaj uporabnika</string>
<string name="pref_player_mpv_hwdec">Strojno dekodiranje</string>
<string name="pref_player_mpv_hwdec_codecs">Kodeki za strojno dekodiranje</string>
<string name="pref_player_mpv_vo">Video izhod</string>
<string name="pref_player_mpv_ao">Avdio izhod</string>
<string name="pref_player_intro_skipper">Preskoči uvode</string>

View file

@ -91,7 +91,6 @@
<string name="settings_connect_timeout">Timeout för anslutning (ms)</string>
<string name="users">Användare</string>
<string name="add_user">Lägg till användare</string>
<string name="pref_player_mpv_hwdec_codecs">Hårdvaruavkodningsformat</string>
<string name="pref_player_mpv_vo">Videooutput</string>
<string name="pref_player_mpv_ao">Ljudoutput</string>
<string name="pref_player_trick_play">Trickspel</string>

View file

@ -160,7 +160,6 @@
<string name="dynamic_colors_summary">Використовувати кольори Material You (доступно лише на Android 12+)</string>
<string name="theme_system">Як на пристрої</string>
<string name="settings_connect_timeout">Тайм-аут підключення (мс)</string>
<string name="pref_player_mpv_hwdec_codecs">Апаратні кодеки декодування</string>
<string name="add">Додати</string>
<string name="audio">Аудіо</string>
<string name="subtitle">Субтитри</string>

View file

@ -100,7 +100,6 @@
<string name="settings_socket_timeout">Thời gian socket hết hạn (ms)</string>
<string name="users">Người dùng</string>
<string name="pref_player_mpv_hwdec">Giải mã phần cứng</string>
<string name="pref_player_mpv_hwdec_codecs">Các bộ giải mã phần cứng</string>
<string name="pref_player_mpv_vo">Đầu ra hình ảnh</string>
<string name="pref_player_mpv_ao">Đầu ra âm thanh</string>
<string name="addresses">Địa chỉ</string>

View file

@ -127,7 +127,6 @@
<string name="users">用户</string>
<string name="add_user">添加用户</string>
<string name="pref_player_mpv_hwdec">硬解</string>
<string name="pref_player_mpv_hwdec_codecs">硬解解码器</string>
<string name="pref_player_mpv_vo">视频输出</string>
<string name="pref_player_mpv_ao">音频输出</string>
<string name="addresses">地址</string>

View file

@ -130,7 +130,6 @@
<string name="pref_player_intro_skipper">片頭跳過器</string>
<string name="pref_player_intro_skipper_summary">需要在服務器上安裝ConfusedPolarBear的Intro Skipper挿件</string>
<string name="pref_player_mpv_hwdec">硬體解碼</string>
<string name="pref_player_mpv_hwdec_codecs">硬體解碼轉碼器</string>
<string name="pref_player_mpv_vo">視頻輸出</string>
<string name="pref_player_mpv_ao">音頻輸出</string>
<string name="addresses">地址</string>

View file

@ -17,15 +17,6 @@
<item>mediacodec</item>
<item>mediacodec-copy</item>
</string-array>
<string-array name="mpv_hwdec_codecs">
<item>h264</item>
<item>hevc</item>
<item>mpeg4</item>
<item>mpeg2video</item>
<item>vp8</item>
<item>vp9</item>
<item>av1</item>
</string-array>
<string-array name="mpv_vos">
<item>gpu</item>
<item>gpu-next</item>
@ -34,7 +25,4 @@
<item>audiotrack</item>
<item>opensles</item>
</string-array>
<string-array name="mpv_gpu_api">
<item>opengl</item>
</string-array>
</resources>

View file

@ -137,10 +137,8 @@
<string name="users">Users</string>
<string name="add_user">Add user</string>
<string name="pref_player_mpv_hwdec">Hardware decoding</string>
<string name="pref_player_mpv_hwdec_codecs">Hardware decoding codecs</string>
<string name="pref_player_mpv_vo">Video output</string>
<string name="pref_player_mpv_ao">Audio output</string>
<string name="pref_player_mpv_gpu_api" translatable="false">GPU API</string>
<string name="pref_player_intro_skipper">Intro Skipper</string>
<string name="pref_player_intro_skipper_summary">Requires ConfusedPolarBear\'s Intro Skipper plugin to be installed on the server</string>
<string name="pref_player_trick_play">Trick Play</string>

View file

@ -11,20 +11,13 @@
app:summary="@string/mpv_player_summary"
app:title="@string/mpv_player" />
<ListPreference
app:defaultValue="mediacodec-copy"
app:defaultValue="mediacodec"
app:dependency="pref_player_mpv"
app:entries="@array/mpv_hwdec"
app:entryValues="@array/mpv_hwdec"
app:key="pref_player_mpv_hwdec"
app:title="@string/pref_player_mpv_hwdec"
app:useSimpleSummaryProvider="true" />
<MultiSelectListPreference
app:defaultValue="@array/mpv_hwdec_codecs"
app:dependency="pref_player_mpv"
app:entries="@array/mpv_hwdec_codecs"
app:entryValues="@array/mpv_hwdec_codecs"
app:key="pref_player_mpv_hwdec_codecs"
app:title="@string/pref_player_mpv_hwdec_codecs" />
<ListPreference
app:defaultValue="gpu"
app:dependency="pref_player_mpv"
@ -41,14 +34,6 @@
app:key="pref_player_mpv_ao"
app:title="@string/pref_player_mpv_ao"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="opengl"
app:dependency="pref_player_mpv"
app:entries="@array/mpv_gpu_api"
app:entryValues="@array/mpv_gpu_api"
app:key="pref_player_mpv_gpu_api"
app:title="@string/pref_player_mpv_gpu_api"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/gestures">

View file

@ -34,7 +34,6 @@ import androidx.media3.common.util.Clock
import androidx.media3.common.util.ListenerSet
import androidx.media3.common.util.Size
import androidx.media3.common.util.Util
import dev.jdtech.jellyfin.AppPreferences
import dev.jdtech.mpv.MPVLib
import org.json.JSONArray
import org.json.JSONException
@ -48,8 +47,12 @@ import java.util.concurrent.CopyOnWriteArraySet
class MPVPlayer(
context: Context,
private val requestAudioFocus: Boolean,
private val appPreferences: AppPreferences,
private var trackSelectionParameters: TrackSelectionParameters = TrackSelectionParameters.Builder(context).build(),
private val seekBackIncrement: Long = C.DEFAULT_SEEK_BACK_INCREMENT_MS,
private val seekForwardIncrement: Long = C.DEFAULT_SEEK_FORWARD_INCREMENT_MS,
videoOutput: String = "gpu",
audioOutput: String = "audiotrack",
hwDec: String = "mediacodec",
) : BasePlayer(), MPVLib.EventObserver, AudioManager.OnAudioFocusChangeListener {
private val audioManager: AudioManager by lazy { context.getSystemService()!! }
@ -74,14 +77,13 @@ class MPVPlayer(
// General
MPVLib.setOptionString("config", "yes")
MPVLib.setOptionString("config-dir", mpvDir.path)
MPVLib.setOptionString("vo", appPreferences.playerMpvVo)
MPVLib.setOptionString("vo", videoOutput)
MPVLib.setOptionString("ao", audioOutput)
MPVLib.setOptionString("gpu-context", "android")
MPVLib.setOptionString("gpu-api", appPreferences.playerMpvGpuApi)
MPVLib.setOptionString("ao", appPreferences.playerMpvAo)
// Hardware video decoding
MPVLib.setOptionString("hwdec", appPreferences.playerMpvHwdec)
MPVLib.setOptionString("hwdec-codecs", appPreferences.playerMpvHwdecCodecs.joinToString(separator = ","))
MPVLib.setOptionString("hwdec", hwDec)
MPVLib.setOptionString("hwdec-codecs", "h264,hevc,mpeg4,mpeg2video,vp8,vp9,av1")
// TLS
MPVLib.setOptionString("tls-verify", "no")
@ -111,8 +113,6 @@ class MPVPlayer(
MPVLib.init()
companionPrefs = appPreferences
MPVLib.addObserver(this)
// Observe properties
@ -885,11 +885,11 @@ class MPVPlayer(
}
override fun getSeekBackIncrement(): Long {
return appPreferences.playerSeekBackIncrement
return seekBackIncrement
}
override fun getSeekForwardIncrement(): Long {
return appPreferences.playerSeekForwardIncrement
return seekForwardIncrement
}
override fun getMaxSeekToPreviousPosition(): Long {
@ -1316,6 +1316,58 @@ class MPVPlayer(
}
}
private val surfaceHolder: SurfaceHolder.Callback = object : SurfaceHolder.Callback {
/**
* This is called immediately after the surface is first created.
* Implementations of this should start up whatever rendering code
* they desire. Note that only one thread can ever draw into
* a [Surface], so you should not draw into the Surface here
* if your normal rendering will be in another thread.
*
* @param holder The SurfaceHolder whose surface is being created.
*/
override fun surfaceCreated(holder: SurfaceHolder) {
MPVLib.attachSurface(holder.surface)
MPVLib.setOptionString("force-window", "yes")
MPVLib.setOptionString("vo", videoOutput)
}
/**
* This is called immediately after any structural changes (format or
* size) have been made to the surface. You should at this point update
* the imagery in the surface. This method is always called at least
* once, after [.surfaceCreated].
*
* @param holder The SurfaceHolder whose surface has changed.
* @param format The new [android.graphics.PixelFormat] of the surface.
* @param width The new width of the surface.
* @param height The new height of the surface.
*/
override fun surfaceChanged(
holder: SurfaceHolder,
format: Int,
width: Int,
height: Int,
) {
MPVLib.setPropertyString("android-surface-size", "${width}x$height")
}
/**
* This is called immediately before a surface is being destroyed. After
* returning from this call, you should no longer try to access this
* surface. If you have a rendering thread that directly accesses
* the surface, you must ensure that thread is no longer touching the
* Surface before returning from this function.
*
* @param holder The SurfaceHolder whose surface is being destroyed.
*/
override fun surfaceDestroyed(holder: SurfaceHolder) {
MPVLib.setOptionString("vo", "null")
MPVLib.setOptionString("force-window", "no")
MPVLib.detachSurface()
}
}
companion object {
/**
* Fraction to which audio volume is ducked on loss of audio focus
@ -1335,60 +1387,6 @@ class MPVPlayer(
)
.build()
private lateinit var companionPrefs: AppPreferences
private val surfaceHolder: SurfaceHolder.Callback = object : SurfaceHolder.Callback {
/**
* This is called immediately after the surface is first created.
* Implementations of this should start up whatever rendering code
* they desire. Note that only one thread can ever draw into
* a [Surface], so you should not draw into the Surface here
* if your normal rendering will be in another thread.
*
* @param holder The SurfaceHolder whose surface is being created.
*/
override fun surfaceCreated(holder: SurfaceHolder) {
MPVLib.attachSurface(holder.surface)
MPVLib.setOptionString("force-window", "yes")
MPVLib.setOptionString("vo", companionPrefs.playerMpvVo)
}
/**
* This is called immediately after any structural changes (format or
* size) have been made to the surface. You should at this point update
* the imagery in the surface. This method is always called at least
* once, after [.surfaceCreated].
*
* @param holder The SurfaceHolder whose surface has changed.
* @param format The new [android.graphics.PixelFormat] of the surface.
* @param width The new width of the surface.
* @param height The new height of the surface.
*/
override fun surfaceChanged(
holder: SurfaceHolder,
format: Int,
width: Int,
height: Int,
) {
MPVLib.setPropertyString("android-surface-size", "${width}x$height")
}
/**
* This is called immediately before a surface is being destroyed. After
* returning from this call, you should no longer try to access this
* surface. If you have a rendering thread that directly accesses
* the surface, you must ensure that thread is no longer touching the
* Surface before returning from this function.
*
* @param holder The SurfaceHolder whose surface is being destroyed.
*/
override fun surfaceDestroyed(holder: SurfaceHolder) {
MPVLib.setOptionString("vo", "null")
MPVLib.setOptionString("force-window", "no")
MPVLib.detachSurface()
}
}
private fun JSONObject.optNullableString(name: String): String? {
return if (this.has(name) && !this.isNull(name)) {
this.getString(name)

View file

@ -93,10 +93,14 @@ constructor(
.setPreferredTextLanguage(appPreferences.preferredSubtitleLanguage)
.build()
player = MPVPlayer(
application,
false,
appPreferences,
trackSelectionParameters,
context = application,
requestAudioFocus = false,
trackSelectionParameters = trackSelectionParameters,
seekBackIncrement = appPreferences.playerSeekBackIncrement,
seekForwardIncrement = appPreferences.playerSeekForwardIncrement,
videoOutput = appPreferences.playerMpvVo,
audioOutput = appPreferences.playerMpvAo,
hwDec = appPreferences.playerMpvHwdec,
)
} else {
val renderersFactory =

View file

@ -71,13 +71,8 @@ constructor(
)!!.toLongOrNull() ?: DEFAULT_SEEK_FORWARD_INCREMENT_MS
val playerMpv get() = sharedPreferences.getBoolean(Constants.PREF_PLAYER_MPV, false)
val playerMpvHwdec get() = sharedPreferences.getString(Constants.PREF_PLAYER_MPV_HWDEC, "mediacodec-copy")!!
val playerMpvHwdecCodecs: Set<String> get() = sharedPreferences.getStringSet(
Constants.PREF_PLAYER_MPV_HWDEC_CODECS,
setOf("h264", "hevc", "mpeg4", "mpeg2video", "vp8", "vp9"),
)!!
val playerMpvVo get() = sharedPreferences.getString(Constants.PREF_PLAYER_MPV_VO, "gpu")!!
val playerMpvAo get() = sharedPreferences.getString(Constants.PREF_PLAYER_MPV_AO, "audiotrack")!!
val playerMpvGpuApi get() = sharedPreferences.getString(Constants.PREF_PLAYER_MPV_GPU_API, "opengl")!!
val playerIntroSkipper get() = sharedPreferences.getBoolean(Constants.PREF_PLAYER_INTRO_SKIPPER, true)
val playerTrickPlay get() = sharedPreferences.getBoolean(Constants.PREF_PLAYER_TRICK_PLAY, true)

View file

@ -22,10 +22,8 @@ object Constants {
const val PREF_PLAYER_SEEK_FORWARD_INC = "pref_player_seek_forward_inc"
const val PREF_PLAYER_MPV = "pref_player_mpv"
const val PREF_PLAYER_MPV_HWDEC = "pref_player_mpv_hwdec"
const val PREF_PLAYER_MPV_HWDEC_CODECS = "pref_player_mpv_hwdec_codecs"
const val PREF_PLAYER_MPV_VO = "pref_player_mpv_vo"
const val PREF_PLAYER_MPV_AO = "pref_player_mpv_ao"
const val PREF_PLAYER_MPV_GPU_API = "pref_player_mpv_gpu_api"
const val PREF_PLAYER_INTRO_SKIPPER = "pref_player_intro_skipper"
const val PREF_PLAYER_TRICK_PLAY = "pref_player_trick_play"
const val PREF_PLAYER_PIP_GESTURE = "pref_player_picture_in_picture_gesture"