Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Cronet network stack for ExoPlayer #797

Merged
merged 2 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ dependencies {
}
implementation(libs.okhttp)
implementation(libs.coil)
implementation(libs.cronet.embedded)

// Media
implementation(libs.androidx.media)
implementation(libs.androidx.mediarouter)
implementation(libs.bundles.exoplayer)
implementation(libs.bundles.exoplayer) {
// Exclude Play Services cronet provider library
exclude("com.google.android.gms", "play-services-cronet")
}
implementation(libs.jellyfin.exoplayer.ffmpegextension)
@Suppress("UnstableApiUsage")
proprietaryImplementation(libs.exoplayer.cast)
Expand Down
22 changes: 21 additions & 1 deletion app/src/main/java/org/jellyfin/mobile/app/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.jellyfin.mobile.app

import android.content.Context
import coil.ImageLoader
import com.google.android.exoplayer2.ext.cronet.CronetDataSource
import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory
import com.google.android.exoplayer2.extractor.ts.TsExtractor
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory
Expand All @@ -15,6 +16,8 @@ import com.google.android.exoplayer2.upstream.DefaultHttpDataSource
import com.google.android.exoplayer2.util.Util
import kotlinx.coroutines.channels.Channel
import okhttp3.OkHttpClient
import org.chromium.net.CronetEngine
import org.chromium.net.CronetProvider
import org.jellyfin.mobile.MainViewModel
import org.jellyfin.mobile.bridge.ExternalPlayer
import org.jellyfin.mobile.player.audio.car.LibraryBrowser
Expand All @@ -34,6 +37,7 @@ import org.koin.androidx.fragment.dsl.fragment
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.qualifier.named
import org.koin.dsl.module
import java.util.concurrent.Executors

const val PLAYER_EVENT_CHANNEL = "PlayerEventChannel"
private const val TS_SEARCH_PACKETS = 1800
Expand Down Expand Up @@ -67,7 +71,23 @@ val applicationModule = module {
// ExoPlayer factories
single<DataSource.Factory> {
val context: Context = get()
val baseDataSourceFactory = DefaultHttpDataSource.Factory().setUserAgent(Util.getUserAgent(context, Constants.APP_INFO_NAME))

val provider = CronetProvider.getAllProviders(context).firstOrNull { provider: CronetProvider ->
(provider.name == CronetProvider.PROVIDER_NAME_APP_PACKAGED) && provider.isEnabled
}

val baseDataSourceFactory = if (provider != null) {
val cronetEngine = provider.createBuilder()
.enableHttp2(true)
.enableQuic(true)
.enableBrotli(true)
.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_IN_MEMORY, 16 * 1024 * 1024)
.build()
CronetDataSource.Factory(cronetEngine, Executors.newCachedThreadPool()).setUserAgent(Util.getUserAgent(context, Constants.APP_INFO_NAME))
} else {
DefaultHttpDataSource.Factory().setUserAgent(Util.getUserAgent(context, Constants.APP_INFO_NAME))
}

DefaultDataSource.Factory(context, baseDataSourceFactory)
}
single<MediaSource.Factory> {
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ modernandroidpreferences = "2.3.1"
jellyfin-sdk = "1.3.5"
okhttp = "4.10.0"
coil = "2.2.1"
cronet-embedded = "102.5005.125"

# Media
androidx-media = "1.6.0"
Expand Down Expand Up @@ -93,6 +94,7 @@ modernandroidpreferences = { group = "de.maxr1998", name = "modernandroidprefere
jellyfin-sdk = { group = "org.jellyfin.sdk", name = "jellyfin-core", version.ref = "jellyfin-sdk" }
okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
coil = { group = "io.coil-kt", name = "coil-base", version.ref = "coil" }
cronet-embedded = { group = "org.chromium.net", name = "cronet-embedded", version.ref = "cronet-embedded" }

# Media
androidx-media = { group = "androidx.media", name = "media", version.ref = "androidx-media" }
Expand All @@ -102,6 +104,7 @@ exoplayer-ui = { group = "com.google.android.exoplayer", name = "exoplayer-ui",
exoplayer-mediaSession = { group = "com.google.android.exoplayer", name = "extension-mediasession", version.ref = "exoplayer" }
exoplayer-hls = { group = "com.google.android.exoplayer", name = "exoplayer-hls", version.ref = "exoplayer" }
exoplayer-cast = { group = "com.google.android.exoplayer", name = "extension-cast", version.ref = "exoplayer" }
exoplayer-cronet = { group = "com.google.android.exoplayer", name = "extension-cronet", version.ref = "exoplayer" }
playservices-cast = { group = "com.google.android.gms", name = "play-services-cast", version.ref = "playservices" }
playservices-castframework = { group = "com.google.android.gms", name = "play-services-cast-framework", version.ref = "playservices" }
jellyfin-exoplayer-ffmpegextension = { group = "org.jellyfin.exoplayer", name = "exoplayer-ffmpeg-extension", version.ref = "jellyfin-exoplayer-ffmpegextension" }
Expand Down Expand Up @@ -144,6 +147,7 @@ exoplayer = [
"exoplayer-ui",
"exoplayer-mediaSession",
"exoplayer-hls",
"exoplayer-cronet",
]
playservices = [
"playservices-cast",
Expand Down