diff --git a/Jellyfin.Xtream/LiveTvService.cs b/Jellyfin.Xtream/LiveTvService.cs index b798a95..813a98d 100644 --- a/Jellyfin.Xtream/LiveTvService.cs +++ b/Jellyfin.Xtream/LiveTvService.cs @@ -217,7 +217,7 @@ public Task ResetTuner(string id, CancellationToken cancellationToken) } /// - public Task GetChannelStreamWithDirectStreamProvider(string channelId, string streamId, List currentLiveStreams, CancellationToken cancellationToken) + public async Task GetChannelStreamWithDirectStreamProvider(string channelId, string streamId, List currentLiveStreams, CancellationToken cancellationToken) { Guid guid = Guid.Parse(channelId); StreamService.FromGuid(guid, out int prefix, out int channel, out int _, out int _); @@ -233,9 +233,10 @@ public Task GetChannelStreamWithDirectStreamProvider(string channel if (stream == null) { stream = new Restream(appHost, httpClientFactory, logger, mediaSourceInfo); + await stream.Open(cancellationToken).ConfigureAwait(false); } stream.ConsumerCount++; - return Task.FromResult(stream); + return stream; } } diff --git a/Jellyfin.Xtream/Service/Restream.cs b/Jellyfin.Xtream/Service/Restream.cs index b604491..e0b3814 100644 --- a/Jellyfin.Xtream/Service/Restream.cs +++ b/Jellyfin.Xtream/Service/Restream.cs @@ -32,7 +32,7 @@ namespace Jellyfin.Xtream.Service; /// /// A live stream implementation that can be restreamed. /// -public class Restream : ILiveStream, IDisposable +public class Restream : ILiveStream, IDirectStreamProvider, IDisposable { /// /// The global constant for the restream tuner host. @@ -113,7 +113,7 @@ public async Task Open(CancellationToken openCancellationToken) { if (inputStream != null) { - // Channel is already opened. + logger.LogWarning("Restream for channel {ChannelId} is already open.", MediaSource.Id); return; } @@ -122,7 +122,7 @@ public async Task Open(CancellationToken openCancellationToken) // Response stream is disposed manually. HttpResponseMessage response = await httpClientFactory.CreateClient(NamedClient.Default) - .GetAsync(uri, HttpCompletionOption.ResponseHeadersRead, CancellationToken.None) + .GetAsync(uri, HttpCompletionOption.ResponseHeadersRead, openCancellationToken) .ConfigureAwait(true); logger.LogDebug("Stream for channel {ChannelId} using url {Url}", channelId, uri); @@ -131,7 +131,7 @@ public async Task Open(CancellationToken openCancellationToken) { logger.LogDebug("Stream for channel {ChannelId} redirected to url {Url}", channelId, response.Headers.Location); response = await httpClientFactory.CreateClient(NamedClient.Default) - .GetAsync(response.Headers.Location, HttpCompletionOption.ResponseHeadersRead, CancellationToken.None) + .GetAsync(response.Headers.Location, HttpCompletionOption.ResponseHeadersRead, openCancellationToken) .ConfigureAwait(true); } @@ -166,7 +166,7 @@ public Stream GetStream() { if (inputStream == null) { - logger.LogInformation("Restream for channel {ChannelId} was not opened.", mediaSource.Id); + logger.LogWarning("Restream for channel {ChannelId} was not opened.", mediaSource.Id); _ = Open(CancellationToken.None); }