-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename TrackSelector to StreamSelector and introduce TrackUtils
- Loading branch information
Showing
6 changed files
with
209 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
new-player/src/main/java/net/newpipe/newplayer/utils/StreamSelector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* NewPlayer | ||
* | ||
* @author Christian Schabesberger | ||
* | ||
* Copyright (C) NewPipe e.V. 2024 <code(at)newpipe-ev.de> | ||
* | ||
* NewPlayer is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* NewPlayer is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.newpipe.newplayer.utils | ||
|
||
import net.newpipe.newplayer.utils.TrackUtils.getDynamicStreams | ||
import net.newpipe.newplayer.utils.TrackUtils.hasVideoStreams | ||
import net.newpipe.newplayer.utils.TrackUtils.tryAndGetMedianAudioOnlyStream | ||
import net.newpipe.newplayer.utils.TrackUtils.tryAndGetMedianCombinedVideoAndAudioStream | ||
import net.newpipe.newplayer.utils.TrackUtils.tryAndGetMedianVideoOnlyStream | ||
|
||
internal class StreamSelector( | ||
val preferredLanguages: List<LanguageIdentifier>, | ||
) { | ||
internal fun selectStreamAutomatically( | ||
item: String, | ||
availableStreams: List<Stream>, | ||
): StreamSelection { | ||
|
||
|
||
// filter for best fitting language stream variants | ||
|
||
val bestFittingLanguage = | ||
TrackUtils.getBestLanguageFit(availableStreams, preferredLanguages) | ||
val availablesInPreferredLanguage = | ||
if (bestFittingLanguage != null) TrackUtils.filtersByLanguage( | ||
availableStreams, bestFittingLanguage | ||
) | ||
else { | ||
emptyList() | ||
} | ||
|
||
|
||
// is it a video stream or a pure audio stream? | ||
if (hasVideoStreams(availableStreams)) { | ||
|
||
// first: try and get a dynamic stream variant | ||
val dynamicStreams = getDynamicStreams(availablesInPreferredLanguage) | ||
if (dynamicStreams.isNotEmpty()) { | ||
return SingleSelection(dynamicStreams[0]) | ||
} | ||
|
||
// second: try and get separate audio and video stream variants | ||
|
||
val videoOnlyStream = tryAndGetMedianVideoOnlyStream(availableStreams) | ||
|
||
|
||
if (videoOnlyStream != null) { | ||
|
||
val audioStream = tryAndGetMedianAudioOnlyStream(availableStreams) | ||
|
||
if (videoOnlyStream != null && audioStream != null) { | ||
return MultiSelection(listOf(videoOnlyStream, audioStream)) | ||
} | ||
} /* if (vdeioOnlyStream != null) */ | ||
|
||
// fourth: try to get a video and audio stream variant with the best fitting identifier | ||
|
||
tryAndGetMedianCombinedVideoAndAudioStream(availableStreams)?.let { | ||
return SingleSelection(it) | ||
} | ||
|
||
} else { /* if(!hasVideoStreams(availableStreams)) */ | ||
|
||
// first: try to get an audio stream variant with the best fitting identifier | ||
|
||
tryAndGetMedianAudioOnlyStream(availableStreams)?.let { | ||
return SingleSelection(it) | ||
} | ||
} | ||
|
||
throw NewPlayerException("StreamSelector: No suitable Stream found that.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 0 additions & 172 deletions
172
new-player/src/main/java/net/newpipe/newplayer/utils/TrackSelector.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.