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

@@ -114,8 +118,9 @@ interface MediaRepository {
/**
* Supply a custom [HttpDataSource.Factory]. This is important for Youtube.
*/
fun getHttpDataSourceFactory(item: String): HttpDataSource.Factory =
DefaultHttpDataSource.Factory()
fun getHttpDataSourceFactory(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.

Is an Android Context now really needed? If so, some doc should be added to explain why that's the case.

Copy link
Author

Choose a reason for hiding this comment

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

@AudricV
Yes an Android Context is needed when building CronetDataSource, OkhttpDataSource or HttpEngineDataSource

@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
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