mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-09-12 12:32:27 +00:00
casting(experimental): removed unused hls cast function
This commit is contained in:
parent
6ff70d2df0
commit
bf35da8ee3
1 changed files with 0 additions and 221 deletions
|
@ -1383,227 +1383,6 @@ class ExpStateCasting {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun castHlsIndirect(
|
|
||||||
contentResolver: ContentResolver,
|
|
||||||
video: IPlatformVideoDetails,
|
|
||||||
videoSource: IVideoUrlSource?,
|
|
||||||
audioSource: IAudioUrlSource?,
|
|
||||||
subtitleSource: ISubtitleSource?,
|
|
||||||
resumePosition: Double,
|
|
||||||
speed: Double?
|
|
||||||
): List<String> {
|
|
||||||
val ad = activeDevice ?: return listOf();
|
|
||||||
val url = getLocalUrl(ad);
|
|
||||||
val id = UUID.randomUUID();
|
|
||||||
|
|
||||||
val hlsPath = "/hls-${id}"
|
|
||||||
|
|
||||||
val hlsUrl = url + hlsPath;
|
|
||||||
Logger.i(TAG, "HLS url: $hlsUrl");
|
|
||||||
|
|
||||||
val mediaRenditions = arrayListOf<HLS.MediaRendition>()
|
|
||||||
val variantPlaylistReferences = arrayListOf<HLS.VariantPlaylistReference>()
|
|
||||||
|
|
||||||
if (audioSource != null) {
|
|
||||||
val audioPath = "/audio-${id}"
|
|
||||||
val audioUrl = url + audioPath
|
|
||||||
|
|
||||||
val duration =
|
|
||||||
audioSource.duration ?: videoSource?.duration ?: throw Exception("Duration unknown")
|
|
||||||
val audioVariantPlaylistPath = "/audio-playlist-${id}"
|
|
||||||
val audioVariantPlaylistUrl = url + audioVariantPlaylistPath
|
|
||||||
val audioVariantPlaylistSegments =
|
|
||||||
listOf(HLS.MediaSegment(duration.toDouble(), audioUrl))
|
|
||||||
val audioVariantPlaylist = HLS.VariantPlaylist(
|
|
||||||
3,
|
|
||||||
duration.toInt(),
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
audioVariantPlaylistSegments
|
|
||||||
)
|
|
||||||
|
|
||||||
_castServer.addHandlerWithAllowAllOptions(
|
|
||||||
HttpConstantHandler(
|
|
||||||
"GET", audioVariantPlaylistPath, audioVariantPlaylist.buildM3U8(),
|
|
||||||
"application/vnd.apple.mpegurl"
|
|
||||||
)
|
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
|
||||||
).withTag("castHlsIndirectVariant");
|
|
||||||
|
|
||||||
mediaRenditions.add(
|
|
||||||
HLS.MediaRendition(
|
|
||||||
"AUDIO",
|
|
||||||
audioVariantPlaylistUrl,
|
|
||||||
"audio",
|
|
||||||
"df",
|
|
||||||
"default",
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
_castServer.addHandlerWithAllowAllOptions(
|
|
||||||
HttpProxyHandler("GET", audioPath, audioSource.getAudioUrl(), true)
|
|
||||||
.withInjectedHost()
|
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
|
||||||
).withTag("castHlsIndirectVariant");
|
|
||||||
}
|
|
||||||
|
|
||||||
val subtitlesUri = if (subtitleSource != null) withContext(Dispatchers.IO) {
|
|
||||||
return@withContext subtitleSource.getSubtitlesURI();
|
|
||||||
} else null;
|
|
||||||
|
|
||||||
var subtitlesUrl: String? = null;
|
|
||||||
if (subtitlesUri != null) {
|
|
||||||
val subtitlePath = "/subtitles-${id}"
|
|
||||||
if (subtitlesUri.scheme == "file") {
|
|
||||||
var content: String? = null;
|
|
||||||
val inputStream = contentResolver.openInputStream(subtitlesUri);
|
|
||||||
inputStream?.use { stream ->
|
|
||||||
val reader = stream.bufferedReader();
|
|
||||||
content = reader.use { it.readText() };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (content != null) {
|
|
||||||
_castServer.addHandlerWithAllowAllOptions(
|
|
||||||
HttpConstantHandler(
|
|
||||||
"GET",
|
|
||||||
subtitlePath,
|
|
||||||
content!!,
|
|
||||||
subtitleSource?.format ?: "text/vtt"
|
|
||||||
)
|
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
|
||||||
).withTag("castHlsIndirectVariant");
|
|
||||||
}
|
|
||||||
|
|
||||||
subtitlesUrl = url + subtitlePath;
|
|
||||||
} else {
|
|
||||||
subtitlesUrl = subtitlesUri.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (subtitlesUrl != null) {
|
|
||||||
val duration = videoSource?.duration ?: audioSource?.duration
|
|
||||||
?: throw Exception("Duration unknown")
|
|
||||||
val subtitleVariantPlaylistPath = "/subtitle-playlist-${id}"
|
|
||||||
val subtitleVariantPlaylistUrl = url + subtitleVariantPlaylistPath
|
|
||||||
val subtitleVariantPlaylistSegments =
|
|
||||||
listOf(HLS.MediaSegment(duration.toDouble(), subtitlesUrl))
|
|
||||||
val subtitleVariantPlaylist = HLS.VariantPlaylist(
|
|
||||||
3,
|
|
||||||
duration.toInt(),
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
subtitleVariantPlaylistSegments
|
|
||||||
)
|
|
||||||
|
|
||||||
_castServer.addHandlerWithAllowAllOptions(
|
|
||||||
HttpConstantHandler(
|
|
||||||
"GET", subtitleVariantPlaylistPath, subtitleVariantPlaylist.buildM3U8(),
|
|
||||||
"application/vnd.apple.mpegurl"
|
|
||||||
)
|
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
|
||||||
).withTag("castHlsIndirectVariant");
|
|
||||||
|
|
||||||
mediaRenditions.add(
|
|
||||||
HLS.MediaRendition(
|
|
||||||
"SUBTITLES",
|
|
||||||
subtitleVariantPlaylistUrl,
|
|
||||||
"subtitles",
|
|
||||||
"df",
|
|
||||||
"default",
|
|
||||||
true,
|
|
||||||
true,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (videoSource != null) {
|
|
||||||
val videoPath = "/video-${id}"
|
|
||||||
val videoUrl = url + videoPath
|
|
||||||
|
|
||||||
val duration = videoSource.duration
|
|
||||||
val videoVariantPlaylistPath = "/video-playlist-${id}"
|
|
||||||
val videoVariantPlaylistUrl = url + videoVariantPlaylistPath
|
|
||||||
val videoVariantPlaylistSegments =
|
|
||||||
listOf(HLS.MediaSegment(duration.toDouble(), videoUrl))
|
|
||||||
val videoVariantPlaylist = HLS.VariantPlaylist(
|
|
||||||
3,
|
|
||||||
duration.toInt(),
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
videoVariantPlaylistSegments
|
|
||||||
)
|
|
||||||
|
|
||||||
_castServer.addHandlerWithAllowAllOptions(
|
|
||||||
HttpConstantHandler(
|
|
||||||
"GET", videoVariantPlaylistPath, videoVariantPlaylist.buildM3U8(),
|
|
||||||
"application/vnd.apple.mpegurl"
|
|
||||||
)
|
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
|
||||||
).withTag("castHlsIndirectVariant");
|
|
||||||
|
|
||||||
variantPlaylistReferences.add(
|
|
||||||
HLS.VariantPlaylistReference(
|
|
||||||
videoVariantPlaylistUrl, HLS.StreamInfo(
|
|
||||||
videoSource.bitrate ?: 0,
|
|
||||||
"${videoSource.width}x${videoSource.height}",
|
|
||||||
videoSource.codec,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
if (audioSource != null) "audio" else null,
|
|
||||||
if (subtitleSource != null) "subtitles" else null,
|
|
||||||
null, null
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
_castServer.addHandlerWithAllowAllOptions(
|
|
||||||
HttpProxyHandler("GET", videoPath, videoSource.getVideoUrl(), true)
|
|
||||||
.withInjectedHost()
|
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
|
||||||
).withTag("castHlsIndirectVariant");
|
|
||||||
}
|
|
||||||
|
|
||||||
val masterPlaylist =
|
|
||||||
HLS.MasterPlaylist(variantPlaylistReferences, mediaRenditions, listOf(), true)
|
|
||||||
_castServer.addHandlerWithAllowAllOptions(
|
|
||||||
HttpConstantHandler(
|
|
||||||
"GET", hlsPath, masterPlaylist.buildM3U8(),
|
|
||||||
"application/vnd.apple.mpegurl"
|
|
||||||
)
|
|
||||||
.withHeader("Access-Control-Allow-Origin", "*"), true
|
|
||||||
).withTag("castHlsIndirectMaster")
|
|
||||||
|
|
||||||
Logger.i(TAG, "added new castHls handlers (hlsPath: $hlsPath).");
|
|
||||||
ad.loadVideo(
|
|
||||||
"application/vnd.apple.mpegurl",
|
|
||||||
hlsUrl,
|
|
||||||
resumePosition,
|
|
||||||
video.duration.toDouble(),
|
|
||||||
speed,
|
|
||||||
metadataFromVideo(video)
|
|
||||||
);
|
|
||||||
|
|
||||||
return listOf(
|
|
||||||
hlsUrl,
|
|
||||||
videoSource?.getVideoUrl() ?: "",
|
|
||||||
audioSource?.getAudioUrl() ?: "",
|
|
||||||
subtitlesUri.toString()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private suspend fun castDashIndirect(
|
private suspend fun castDashIndirect(
|
||||||
contentResolver: ContentResolver,
|
contentResolver: ContentResolver,
|
||||||
video: IPlatformVideoDetails,
|
video: IPlatformVideoDetails,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue