-
-
Notifications
You must be signed in to change notification settings - Fork 512
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
Initial video support in playback rewrite #3557
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6f09d9a
Add PlayerSurfaceView to display video output
nielsvanvelzen 2f50b85
Check for mediaType in AudioMediaStreamResolver
nielsvanvelzen c5b2c58
Fix PlaybackLauncher not converting item id to string
nielsvanvelzen f25be04
Add hls dependency to media3 module
nielsvanvelzen 217e83d
Fix typo in AudioMediaStreamResolver
nielsvanvelzen 0a49e17
Update PlaybackForwardingActivity to show video output
nielsvanvelzen 3a8e913
Add VideoMediaStreamResolver
nielsvanvelzen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.jellyfin.playback.core.ui | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.SurfaceView | ||
import android.view.ViewGroup | ||
import android.widget.FrameLayout | ||
import org.jellyfin.playback.core.PlaybackManager | ||
|
||
/** | ||
* A view that is used to display the video output of the playing media. | ||
* The [playbackManager] must be set when the view is initialized. | ||
*/ | ||
class PlayerSurfaceView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = 0, | ||
defStyleRes: Int = 0, | ||
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) { | ||
lateinit var playbackManager: PlaybackManager | ||
|
||
val surface = SurfaceView(context, attrs).apply { | ||
addView(this, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) | ||
} | ||
|
||
override fun onAttachedToWindow() { | ||
super.onAttachedToWindow() | ||
|
||
if (!isInEditMode) { | ||
playbackManager.backendService.attachSurfaceView(surface) | ||
} | ||
} | ||
} | ||
|
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
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
111 changes: 111 additions & 0 deletions
111
playback/jellyfin/src/main/kotlin/mediastream/VideoMediaStreamResolver.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,111 @@ | ||
package org.jellyfin.playback.jellyfin.mediastream | ||
|
||
import org.jellyfin.playback.core.mediastream.BasicMediaStream | ||
import org.jellyfin.playback.core.mediastream.MediaConversionMethod | ||
import org.jellyfin.playback.core.mediastream.MediaStream | ||
import org.jellyfin.playback.core.mediastream.MediaStreamContainer | ||
import org.jellyfin.playback.core.mediastream.PlayableMediaStream | ||
import org.jellyfin.playback.core.queue.QueueEntry | ||
import org.jellyfin.playback.core.support.PlaySupportReport | ||
import org.jellyfin.playback.jellyfin.queue.baseItem | ||
import org.jellyfin.sdk.api.client.ApiClient | ||
import org.jellyfin.sdk.api.client.extensions.dynamicHlsApi | ||
import org.jellyfin.sdk.api.client.extensions.videosApi | ||
import org.jellyfin.sdk.model.api.DeviceProfile | ||
import org.jellyfin.sdk.model.constant.MediaType | ||
|
||
class VideoMediaStreamResolver( | ||
val api: ApiClient, | ||
val profile: DeviceProfile, | ||
) : JellyfinStreamResolver(api, profile) { | ||
companion object { | ||
private val REMUX_CONTAINERS = arrayOf("mp4", "mkv") | ||
private const val REMUX_SEGMENT_CONTAINER = "mp4" | ||
} | ||
|
||
private fun MediaInfo.getDirectPlayStream() = BasicMediaStream( | ||
identifier = playSessionId, | ||
conversionMethod = MediaConversionMethod.None, | ||
container = getMediaStreamContainer(), | ||
tracks = getTracks() | ||
) | ||
|
||
private fun MediaInfo.getRemuxStream(container: String) = BasicMediaStream( | ||
identifier = playSessionId, | ||
conversionMethod = MediaConversionMethod.Remux, | ||
container = MediaStreamContainer( | ||
format = container | ||
), | ||
tracks = getTracks() | ||
) | ||
|
||
private fun MediaInfo.getTranscodeStream() = BasicMediaStream( | ||
identifier = playSessionId, | ||
conversionMethod = MediaConversionMethod.Transcode, | ||
// The server doesn't provide us with the transcode information so we return mock data | ||
container = MediaStreamContainer(format = "unknown"), | ||
tracks = emptyList() | ||
) | ||
|
||
override suspend fun getStream( | ||
queueEntry: QueueEntry, | ||
testStream: (stream: MediaStream) -> PlaySupportReport, | ||
): PlayableMediaStream? { | ||
val baseItem = queueEntry.baseItem | ||
if (baseItem == null || baseItem.mediaType != MediaType.Video) return null | ||
|
||
val mediaInfo = getPlaybackInfo(baseItem) | ||
|
||
// Test for direct play support | ||
val directPlayStream = mediaInfo.getDirectPlayStream() | ||
if (testStream(directPlayStream).canPlay) { | ||
return directPlayStream.toPlayableMediaStream( | ||
queueEntry = queueEntry, | ||
url = api.videosApi.getVideoStreamUrl( | ||
itemId = baseItem.id, | ||
mediaSourceId = mediaInfo.mediaSource.id, | ||
playSessionId = mediaInfo.playSessionId, | ||
static = true, | ||
) | ||
) | ||
} | ||
|
||
// Try remuxing | ||
if (mediaInfo.mediaSource.supportsDirectStream) { | ||
for (container in REMUX_CONTAINERS) { | ||
val remuxStream = mediaInfo.getRemuxStream(container) | ||
if (testStream(remuxStream).canPlay) { | ||
return remuxStream.toPlayableMediaStream( | ||
queueEntry = queueEntry, | ||
url = api.videosApi.getVideoStreamByContainerUrl( | ||
itemId = baseItem.id, | ||
mediaSourceId = mediaInfo.mediaSource.id, | ||
playSessionId = mediaInfo.playSessionId, | ||
container = container, | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
// Fallback to provided transcode | ||
if (mediaInfo.mediaSource.supportsTranscoding) { | ||
val transcodeStream = mediaInfo.getTranscodeStream() | ||
|
||
// Skip testing transcode stream because we lack the information to do so | ||
return transcodeStream.toPlayableMediaStream( | ||
queueEntry = queueEntry, | ||
url = api.dynamicHlsApi.getMasterHlsVideoPlaylistUrl( | ||
itemId = baseItem.id, | ||
mediaSourceId = requireNotNull(mediaInfo.mediaSource.id), | ||
playSessionId = mediaInfo.playSessionId, | ||
tag = mediaInfo.mediaSource.eTag, | ||
segmentContainer = REMUX_SEGMENT_CONTAINER, | ||
) | ||
) | ||
} | ||
|
||
// Unable to find a suitable stream, return | ||
return null | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / detekt
Flags a forbidden comment. Warning