enable query and provide stream assumed stream info if missing.
This commit is contained in:
parent
14b6c33542
commit
4f9ebe2bce
@ -1,7 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Plugin.SRFPlay.Configuration;
|
using Jellyfin.Plugin.SRFPlay.Configuration;
|
||||||
@ -22,12 +20,10 @@ namespace Jellyfin.Plugin.SRFPlay.Providers;
|
|||||||
public class SRFMediaProvider : IMediaSourceProvider
|
public class SRFMediaProvider : IMediaSourceProvider
|
||||||
{
|
{
|
||||||
private readonly ILogger<SRFMediaProvider> _logger;
|
private readonly ILogger<SRFMediaProvider> _logger;
|
||||||
private readonly ILoggerFactory _loggerFactory;
|
|
||||||
private readonly IMediaCompositionFetcher _compositionFetcher;
|
private readonly IMediaCompositionFetcher _compositionFetcher;
|
||||||
private readonly IStreamUrlResolver _streamResolver;
|
private readonly IStreamUrlResolver _streamResolver;
|
||||||
private readonly IStreamProxyService _proxyService;
|
private readonly IStreamProxyService _proxyService;
|
||||||
private readonly IServerApplicationHost _appHost;
|
private readonly IServerApplicationHost _appHost;
|
||||||
private readonly Dictionary<string, string> _openTokenToItemId = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SRFMediaProvider"/> class.
|
/// Initializes a new instance of the <see cref="SRFMediaProvider"/> class.
|
||||||
@ -44,7 +40,6 @@ public class SRFMediaProvider : IMediaSourceProvider
|
|||||||
IStreamProxyService proxyService,
|
IStreamProxyService proxyService,
|
||||||
IServerApplicationHost appHost)
|
IServerApplicationHost appHost)
|
||||||
{
|
{
|
||||||
_loggerFactory = loggerFactory;
|
|
||||||
_logger = loggerFactory.CreateLogger<SRFMediaProvider>();
|
_logger = loggerFactory.CreateLogger<SRFMediaProvider>();
|
||||||
_compositionFetcher = compositionFetcher;
|
_compositionFetcher = compositionFetcher;
|
||||||
_streamResolver = streamResolver;
|
_streamResolver = streamResolver;
|
||||||
@ -172,14 +167,8 @@ public class SRFMediaProvider : IMediaSourceProvider
|
|||||||
? config.PublicServerUrl.TrimEnd('/') // Use configured public URL (important for Android/remote clients)
|
? config.PublicServerUrl.TrimEnd('/') // Use configured public URL (important for Android/remote clients)
|
||||||
: _appHost.GetSmartApiUrl(string.Empty); // Fall back to Jellyfin's smart URL resolution
|
: _appHost.GetSmartApiUrl(string.Empty); // Fall back to Jellyfin's smart URL resolution
|
||||||
|
|
||||||
// Generate an open token for this media source (used to track transcoding sessions)
|
// Create proxy URL - item ID is all we need since proxy handles auth
|
||||||
var openToken = Guid.NewGuid().ToString("N");
|
var proxyUrl = $"{serverUrl}/Plugins/SRFPlay/Proxy/{itemIdStr}/master.m3u8";
|
||||||
_openTokenToItemId[openToken] = itemIdStr;
|
|
||||||
_logger.LogDebug("Created open token {OpenToken} for item {ItemId}", openToken, itemIdStr);
|
|
||||||
|
|
||||||
// Create proxy URL using token instead of item ID in path
|
|
||||||
// This prevents Jellyfin from rewriting the URL during transcoding
|
|
||||||
var proxyUrl = $"{serverUrl}/Plugins/SRFPlay/Proxy/{itemIdStr}/master.m3u8?token={openToken}";
|
|
||||||
|
|
||||||
_logger.LogInformation(
|
_logger.LogInformation(
|
||||||
"Using proxy URL for item {ItemId}: {ProxyUrl} (PublicServerUrl configured: {IsPublicConfigured})",
|
"Using proxy URL for item {ItemId}: {ProxyUrl} (PublicServerUrl configured: {IsPublicConfigured})",
|
||||||
@ -197,36 +186,17 @@ public class SRFMediaProvider : IMediaSourceProvider
|
|||||||
Container = "hls",
|
Container = "hls",
|
||||||
SupportsDirectStream = true,
|
SupportsDirectStream = true,
|
||||||
SupportsDirectPlay = true, // ✅ Enabled! Proxy handles auth
|
SupportsDirectPlay = true, // ✅ Enabled! Proxy handles auth
|
||||||
SupportsTranscoding = true,
|
SupportsTranscoding = false, // Prefer DirectPlay - no transcoding needed for HLS
|
||||||
IsRemote = false, // False because it's a local proxy endpoint
|
IsRemote = false, // False because it's a local proxy endpoint
|
||||||
Type = MediaSourceType.Default,
|
Type = MediaSourceType.Default,
|
||||||
RunTimeTicks = chapter.Duration > 0 ? TimeSpan.FromMilliseconds(chapter.Duration).Ticks : null,
|
RunTimeTicks = chapter.Duration > 0 ? TimeSpan.FromMilliseconds(chapter.Duration).Ticks : null,
|
||||||
VideoType = VideoType.VideoFile,
|
VideoType = VideoType.VideoFile,
|
||||||
IsInfiniteStream = isLiveStream, // True for live streams!
|
IsInfiniteStream = isLiveStream, // True for live streams!
|
||||||
RequiresOpening = true, // Enable to handle transcoding sessions
|
RequiresOpening = false, // Proxy handles auth - no need for OpenMediaSource
|
||||||
RequiresClosing = false,
|
RequiresClosing = false,
|
||||||
SupportsProbing = false, // Disable probing for proxy URLs
|
SupportsProbing = true, // Enable probing so Jellyfin can verify stream compatibility
|
||||||
ReadAtNativeFramerate = isLiveStream, // Read at native framerate for live streams
|
ReadAtNativeFramerate = isLiveStream, // Read at native framerate for live streams
|
||||||
OpenToken = openToken, // Token to identify this media source
|
MediaStreams = CreateMediaStreams(qualityPref)
|
||||||
MediaStreams = new List<MediaBrowser.Model.Entities.MediaStream>
|
|
||||||
{
|
|
||||||
new MediaBrowser.Model.Entities.MediaStream
|
|
||||||
{
|
|
||||||
Type = MediaStreamType.Video,
|
|
||||||
Codec = "h264",
|
|
||||||
Profile = "high",
|
|
||||||
IsInterlaced = false,
|
|
||||||
IsDefault = true,
|
|
||||||
Index = 0
|
|
||||||
},
|
|
||||||
new MediaBrowser.Model.Entities.MediaStream
|
|
||||||
{
|
|
||||||
Type = MediaStreamType.Audio,
|
|
||||||
Codec = "aac",
|
|
||||||
IsDefault = true,
|
|
||||||
Index = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
sources.Add(mediaSource);
|
sources.Add(mediaSource);
|
||||||
@ -271,26 +241,57 @@ public class SRFMediaProvider : IMediaSourceProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<ILiveStream> OpenMediaSource(string openToken, List<ILiveStream> currentLiveStreams, CancellationToken cancellationToken)
|
public Task<ILiveStream> OpenMediaSource(string openToken, List<ILiveStream> currentLiveStreams, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("OpenMediaSource called with openToken: {OpenToken}", openToken);
|
// Not used - RequiresOpening is false, proxy handles authentication directly
|
||||||
|
_logger.LogWarning("OpenMediaSource unexpectedly called with openToken: {OpenToken}", openToken);
|
||||||
|
throw new NotSupportedException("OpenMediaSource not supported - streams use direct proxy access");
|
||||||
|
}
|
||||||
|
|
||||||
// Look up the original item ID from the open token
|
/// <summary>
|
||||||
if (!_openTokenToItemId.TryGetValue(openToken, out var originalItemId))
|
/// Creates MediaStream metadata based on quality preference.
|
||||||
|
/// These are approximate values - HLS adaptive streaming will use actual stream qualities.
|
||||||
|
/// </summary>
|
||||||
|
private static List<MediaBrowser.Model.Entities.MediaStream> CreateMediaStreams(QualityPreference quality)
|
||||||
|
{
|
||||||
|
// Set resolution/bitrate based on quality preference
|
||||||
|
// These are typical values for SRF streams - actual HLS will adapt
|
||||||
|
var (width, height, videoBitrate) = quality switch
|
||||||
{
|
{
|
||||||
_logger.LogError("Open token {OpenToken} not found in registry", openToken);
|
QualityPreference.SD => (1280, 720, 2500000),
|
||||||
throw new InvalidOperationException($"Open token {openToken} not found");
|
QualityPreference.HD => (1920, 1080, 5000000),
|
||||||
}
|
_ => (1280, 720, 3000000)
|
||||||
|
};
|
||||||
|
|
||||||
_logger.LogInformation("Open token {OpenToken} maps to original item ID: {ItemId}", openToken, originalItemId);
|
return new List<MediaBrowser.Model.Entities.MediaStream>
|
||||||
|
{
|
||||||
// Create a live stream wrapper
|
new MediaBrowser.Model.Entities.MediaStream
|
||||||
var liveStream = new SRFLiveStream(
|
{
|
||||||
_logger,
|
Type = MediaStreamType.Video,
|
||||||
_proxyService,
|
Codec = "h264",
|
||||||
originalItemId,
|
Profile = "high",
|
||||||
openToken);
|
Level = 40,
|
||||||
|
Width = width,
|
||||||
return await Task.FromResult<ILiveStream>(liveStream).ConfigureAwait(false);
|
Height = height,
|
||||||
|
BitRate = videoBitrate,
|
||||||
|
BitDepth = 8,
|
||||||
|
IsInterlaced = false,
|
||||||
|
IsDefault = true,
|
||||||
|
Index = 0,
|
||||||
|
IsAVC = true,
|
||||||
|
PixelFormat = "yuv420p"
|
||||||
|
},
|
||||||
|
new MediaBrowser.Model.Entities.MediaStream
|
||||||
|
{
|
||||||
|
Type = MediaStreamType.Audio,
|
||||||
|
Codec = "aac",
|
||||||
|
Profile = "LC",
|
||||||
|
Channels = 2,
|
||||||
|
SampleRate = 48000,
|
||||||
|
BitRate = 128000,
|
||||||
|
IsDefault = true,
|
||||||
|
Index = 1
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user