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

Implement CronetEngine and HttpEngine support #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

uzu09811
Copy link

@uzu09811 uzu09811 commented Nov 6, 2024

This modification is just made to allow people people to override other data sources like Okhttp3, Cronet, HttpEngine.

TobiGr
TobiGr previously requested changes Nov 9, 2024
Copy link
Contributor

@TobiGr TobiGr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution. Please add more info toyour PR, e.g. why is cronet needed here and why did you choose it over similar dependencies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The detailed info on the libs (group, name, version) are placed in the version catalog

Copy link
Author

@uzu09811 uzu09811 Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The detailed info on the libs (group, name, version) are placed in the version catalog

now I need to remove them and just keep the important context change as NewPipeTeam will override the get data source obviously.

implementation(libs.coil.compose)
implementation(libs.reorderable)
implementation(libs.androidx.media3.session)
implementation(libs.androidx.media3.exoplayer.dash)
implementation(libs.androidx.adaptive.android)

implementation("org.chromium.net:cronet-embedded:119.6045.31")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why cronet-embedded and not cronet?

Copy link
Author

@uzu09811 uzu09811 Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because said by Audric and Stypox but now I need to remove them and just keep the important context change as they will override the get data source obviously

} else {
if (!CronetProvider.getAllProviders(context).filter { it.isEnabled }.toList().isEmpty()) {
val cronetEngine = CronetEngine.Builder(context)
.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_IN_MEMORY, 10 * 1024 * 1024)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you choose exactly this value?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10 x 1024 x 1024 = 10485760 bytes
which means 10MB so highest 10MB wil be cached in memory

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uzu09811 can you please put this value into a named constant so its no MagicNumber.

Copy link
Member

@theScrabi theScrabi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, after the PR description was added I understood the intention behind the PR.
I like it. @uzu09811 I think you could maybe still add CornetEngine support by creating a meta MediaRepository implementation that only implements getDataSourceFactory(). What do you think?

} else {
if (!CronetProvider.getAllProviders(context).filter { it.isEnabled }.toList().isEmpty()) {
val cronetEngine = CronetEngine.Builder(context)
.enableHttpCache(CronetEngine.Builder.HTTP_CACHE_IN_MEMORY, 10 * 1024 * 1024)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uzu09811 can you please put this value into a named constant so its no MagicNumber.

Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am taking care of this PR since @uzu09811 contacted me on Matrix. I would say it's better to let apps choose whether to use cronet or not (because e.g. cronet-embedded adds 9mb). So in the end the PR just modifies the API to allow the usage of cronet in apps. @theScrabi you reviewed an old version of the code for some reason (?).

@TobiGr TobiGr dismissed their stale review November 11, 2024 11:19

outdated

@AudricV
Copy link
Member

AudricV commented Nov 11, 2024

As a general point of view, except maybe the context change, for a pure HTTP implementation, I don't think changing anything else is needed, as all ExoPlayer data sources for network stacks implement HttpDataSource and not only DataSource.

However, this may allow to use data source with non HTTP origins (like local files), but as I don't really know the NewPlayer structure, I am not certain of this.

@theScrabi
Copy link
Member

However, this may allow to use data source with non HTTP origins (like local files), but as I don't really know the NewPlayer structure, I am not certain of this.

NewPlayer should support playing local files, so does ExoPlayer. However I don't think HttpDataSource is required for playing local files.

@uzu09811
Copy link
Author

DefaultDataSource is needed for local video files because DefaultHttpDataSource will not work for local files

@uzu09811 uzu09811 requested a review from AudricV November 29, 2024 09:20
@AudricV AudricV dismissed their stale review November 29, 2024 17:50

Outdated + I don't have the capacity to review properly the code

@AudricV AudricV removed their request for review November 29, 2024 17:51
@ShareASmile ShareASmile added dependency Issues and PRs related to dependencies enhancement New feature or request labels Dec 4, 2024
@theScrabi
Copy link
Member

theScrabi commented Jan 3, 2025

@uzu09811 Sorry for the late reply and for us maintainers cutting and truncating down your Pull request. However, as you see NewPlayer is in an early stage, and with your pull request you triggered some discussions about how we want to solve several problems we may not have thought about before. Especially the interface between two modules is something that needs to be disused and watched closely, as such interfaces must not change or should really change if really required.

We had another discussion about weather a Context should be supplied by the Interface, and we came to the conclusion: No, because the implementation of a MediaRepository will always have access to a Context even if Context is not supplied though a call.

This being said, thank you very much. I have suggested the changes for the Context. If you apply them you are good to go to merge. Now of course I could directly apply the changes, but I think it is cooler for you if you appear in the commit history. :D

@theScrabi theScrabi removed the request for review from TobiGr January 3, 2025 13:47
@@ -501,7 +501,7 @@ internalPlayStream(mediaSource: MediaSource, playMode: PlayMode) {
val builder = MediaSourceBuilder(
repository = repository,
mutableErrorFlow = mutableErrorFlow,
httpDataSourceFactory = repository.getHttpDataSourceFactory(item),
dataSourceFactory = repository.getDataSourceFactory(item, app),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dataSourceFactory = repository.getDataSourceFactory(item, app),
dataSourceFactory = repository.getDataSourceFactory(item),

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A repository will have the ability to access a Context regardless of weather that Context was supplied from the interface call or not. So this should be removed eventually.

@@ -114,8 +116,9 @@ interface MediaRepository {
/**
* Supply a custom [HttpDataSource.Factory]. This is important for Youtube.
*/
fun getHttpDataSourceFactory(item: String): HttpDataSource.Factory =
DefaultHttpDataSource.Factory()
fun getDataSourceFactory(item: String, context: Context): DataSource.Factory {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fun getDataSourceFactory(item: String, context: Context): DataSource.Factory {
fun getDataSourceFactory(item: String): DataSource.Factory {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependency Issues and PRs related to dependencies enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants