Skip to content

Commit c573bd3

Browse files
committed
chore(sabr): add infrastructure for chunked streaming
Adds the required classes that are needed to create and handle chunked sample streams.
1 parent 72f90cf commit c573bd3

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.github.libretube.player
2+
3+
import androidx.annotation.OptIn
4+
import androidx.media3.common.util.UnstableApi
5+
import androidx.media3.exoplayer.LoadingInfo
6+
import androidx.media3.exoplayer.SeekParameters
7+
import androidx.media3.exoplayer.source.chunk.Chunk
8+
import androidx.media3.exoplayer.source.chunk.ChunkHolder
9+
import androidx.media3.exoplayer.source.chunk.MediaChunk
10+
import androidx.media3.exoplayer.trackselection.ExoTrackSelection
11+
import androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy
12+
import androidx.media3.extractor.mp4.FragmentedMp4Extractor
13+
import com.github.libretube.player.manifest.SABRManifest
14+
15+
@OptIn(UnstableApi::class)
16+
class DefaultSABRChunkSource : SABRChunkSource {
17+
override fun updateManifest(newManifest: SABRManifest?) {}
18+
19+
override fun updateTrackSelection(trackSelection: ExoTrackSelection?) {
20+
TODO("Not yet implemented")
21+
}
22+
23+
override fun getAdjustedSeekPositionUs(
24+
positionUs: Long,
25+
seekParameters: SeekParameters
26+
): Long {
27+
TODO("Not yet implemented")
28+
}
29+
30+
override fun maybeThrowError() {}
31+
32+
override fun getPreferredQueueSize(
33+
playbackPositionUs: Long,
34+
queue: List<out MediaChunk>
35+
): Int {
36+
TODO("Not yet implemented")
37+
}
38+
39+
override fun shouldCancelLoad(
40+
playbackPositionUs: Long,
41+
loadingChunk: Chunk,
42+
queue: List<out MediaChunk>
43+
): Boolean {
44+
TODO("Not yet implemented")
45+
}
46+
47+
override fun getNextChunk(
48+
loadingInfo: LoadingInfo,
49+
loadPositionUs: Long,
50+
queue: List<out MediaChunk>,
51+
out: ChunkHolder
52+
) {
53+
TODO("Not yet implemented")
54+
}
55+
56+
override fun onChunkLoadCompleted(chunk: Chunk) {
57+
TODO("Not yet implemented")
58+
}
59+
60+
override fun onChunkLoadError(
61+
chunk: Chunk,
62+
cancelable: Boolean,
63+
loadErrorInfo: LoadErrorHandlingPolicy.LoadErrorInfo,
64+
loadErrorHandlingPolicy: LoadErrorHandlingPolicy
65+
): Boolean {
66+
TODO("Not yet implemented")
67+
}
68+
69+
override fun release() {
70+
TODO("Not yet implemented")
71+
}
72+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.github.libretube.player
2+
3+
import androidx.media3.common.Format
4+
import androidx.media3.common.util.UnstableApi
5+
import androidx.media3.datasource.TransferListener
6+
import androidx.media3.exoplayer.source.chunk.ChunkSource
7+
import androidx.media3.exoplayer.trackselection.ExoTrackSelection
8+
import androidx.media3.exoplayer.upstream.CmcdConfiguration
9+
import androidx.media3.exoplayer.upstream.LoaderErrorThrower
10+
import androidx.media3.extractor.text.SubtitleParser
11+
import com.github.libretube.player.manifest.SABRManifest
12+
13+
/** A [ChunkSource] for SABR streams. */
14+
@UnstableApi
15+
interface SABRChunkSource : ChunkSource {
16+
interface Factory {
17+
/**
18+
* Creates a new [SABRChunkSource].
19+
*
20+
* @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
21+
* @param manifest The initial manifest.
22+
* @param streamElementIndex The index of the corresponding stream element in the manifest.
23+
* @param trackSelection The track selection.
24+
* @param transferListener The transfer listener which should be informed of any data transfers.
25+
* May be null if no listener is available.
26+
* @param cmcdConfiguration The [CmcdConfiguration] for this chunk source.
27+
* @return The created [SABRChunkSource].
28+
*/
29+
fun createChunkSource(
30+
manifestLoaderErrorThrower: LoaderErrorThrower?,
31+
manifest: SABRManifest?,
32+
streamElementIndex: Int,
33+
trackSelection: ExoTrackSelection?,
34+
): SABRChunkSource?
35+
}
36+
37+
/**
38+
* Updates the manifest.
39+
*
40+
* @param newManifest The new manifest.
41+
*/
42+
fun updateManifest(newManifest: SABRManifest?)
43+
44+
/**
45+
* Updates the track selection.
46+
*
47+
* @param trackSelection The new track selection instance. Must be equivalent to the previous one.
48+
*/
49+
fun updateTrackSelection(trackSelection: ExoTrackSelection?)
50+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.github.libretube.player.manifest
2+
3+
import androidx.media3.common.C
4+
import androidx.media3.common.StreamKey
5+
import androidx.media3.common.util.UnstableApi
6+
import androidx.media3.exoplayer.offline.FilterableManifest
7+
8+
/**
9+
* Represents a SABR streaming manifest.
10+
*/
11+
@UnstableApi
12+
class SABRManifest private constructor(
13+
/**
14+
* The overall presentation duration of the media in microseconds, or [C.TIME_UNSET] if the
15+
* duration is unknown.
16+
*/
17+
val durationUs: Long,
18+
) : FilterableManifest<SABRManifest?> {
19+
20+
override fun copy(streamKeys: List<StreamKey>): SABRManifest {
21+
TODO("Not yet implemented")
22+
}
23+
}

0 commit comments

Comments
 (0)