diff options
| author | Laurence Laforest <l.laforest@gmail.com> | 2026-10-07 12:25:43 -0400 |
|---|---|---|
| committer | Laurence Laforest <l.laforest@gmail.com> | 2026-10-13 18:10:03 -0400 |
| commit | 23ca550053adc564e2c082eeb2f7a36439d6e814 (patch) | |
| tree | c826aa18b0f15b77775d4b16d8c727783ab66437 | |
| parent | e53a6d3e6ae29cb05c55c7b8edf2d237a1f75c16 (diff) | |
Add active stream count to live tv channels
| -rw-r--r-- | Emby.Server.Implementations/Library/MediaSourceManager.cs | 8 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Library/ILiveStream.cs | 5 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Library/IMediaSourceManager.cs | 7 | ||||
| -rw-r--r-- | MediaBrowser.Model/Dto/BaseItemDto.cs | 6 | ||||
| -rw-r--r-- | src/Jellyfin.LiveTv/IO/ExclusiveLiveStream.cs | 2 | ||||
| -rw-r--r-- | src/Jellyfin.LiveTv/LiveTvManager.cs | 10 | ||||
| -rw-r--r-- | src/Jellyfin.LiveTv/LiveTvMediaSourceProvider.cs | 2 | ||||
| -rw-r--r-- | src/Jellyfin.LiveTv/TunerHosts/LiveStream.cs | 2 |
8 files changed, 42 insertions, 0 deletions
diff --git a/Emby.Server.Implementations/Library/MediaSourceManager.cs b/Emby.Server.Implementations/Library/MediaSourceManager.cs index e9bba05839..a8cd247273 100644 --- a/Emby.Server.Implementations/Library/MediaSourceManager.cs +++ b/Emby.Server.Implementations/Library/MediaSourceManager.cs @@ -972,6 +972,14 @@ namespace Emby.Server.Implementations.Library return _openStreams.Values.FirstOrDefault(stream => string.Equals(uniqueId, stream?.UniqueId, StringComparison.OrdinalIgnoreCase)); } + /// <inheritdoc /> + public IReadOnlyList<ILiveStream> GetLiveStreams(Guid channelId) + { + return _openStreams.Values + .Where(stream => stream.ChannelId.Equals(channelId)) + .ToList(); + } + public async Task<MediaSourceInfo> GetLiveStream(string id, CancellationToken cancellationToken) { var result = await GetLiveStreamWithDirectStreamProvider(id, cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.Controller/Library/ILiveStream.cs b/MediaBrowser.Controller/Library/ILiveStream.cs index bf64aca0f0..9e0199cb08 100644 --- a/MediaBrowser.Controller/Library/ILiveStream.cs +++ b/MediaBrowser.Controller/Library/ILiveStream.cs @@ -24,6 +24,11 @@ namespace MediaBrowser.Controller.Library string UniqueId { get; } + /// <summary> + /// Gets or sets the channel id for live tv streams. + /// </summary> + Guid ChannelId { get; set; } + Task Open(CancellationToken openCancellationToken); Task Close(); diff --git a/MediaBrowser.Controller/Library/IMediaSourceManager.cs b/MediaBrowser.Controller/Library/IMediaSourceManager.cs index 2b6781a197..8efd67193a 100644 --- a/MediaBrowser.Controller/Library/IMediaSourceManager.cs +++ b/MediaBrowser.Controller/Library/IMediaSourceManager.cs @@ -141,5 +141,12 @@ namespace MediaBrowser.Controller.Library void SetDefaultAudioAndSubtitleStreamIndices(BaseItem item, MediaSourceInfo source, User user); Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudio, string cacheKey, bool addProbeDelay, bool isLiveStream, CancellationToken cancellationToken); + + /// <summary> + /// Gets the open streams for the provided channel. + /// </summary> + /// <param name="channelId">The channel id.</param> + /// <returns>The open streams held for the channel.</returns> + IReadOnlyList<ILiveStream> GetLiveStreams(Guid channelId); } } diff --git a/MediaBrowser.Model/Dto/BaseItemDto.cs b/MediaBrowser.Model/Dto/BaseItemDto.cs index 062034327e..db9f54fb25 100644 --- a/MediaBrowser.Model/Dto/BaseItemDto.cs +++ b/MediaBrowser.Model/Dto/BaseItemDto.cs @@ -730,6 +730,12 @@ namespace MediaBrowser.Model.Dto public ChannelType? ChannelType { get; set; } /// <summary> + /// Gets or sets the number of streams currently open on the channel, including playback and active recordings. + /// </summary> + /// <value>The number of streams currently open on the channel.</value> + public int? ActiveStreamCount { get; set; } + + /// <summary> /// Gets or sets the audio. /// </summary> /// <value>The audio.</value> diff --git a/src/Jellyfin.LiveTv/IO/ExclusiveLiveStream.cs b/src/Jellyfin.LiveTv/IO/ExclusiveLiveStream.cs index 394b9cf11d..dece5ffc82 100644 --- a/src/Jellyfin.LiveTv/IO/ExclusiveLiveStream.cs +++ b/src/Jellyfin.LiveTv/IO/ExclusiveLiveStream.cs @@ -32,6 +32,8 @@ namespace Jellyfin.LiveTv.IO public string TunerHostId => null; + public Guid ChannelId { get; set; } + public bool EnableStreamSharing { get; set; } public MediaSourceInfo MediaSource { get; set; } diff --git a/src/Jellyfin.LiveTv/LiveTvManager.cs b/src/Jellyfin.LiveTv/LiveTvManager.cs index 93f9083178..5b13c8103d 100644 --- a/src/Jellyfin.LiveTv/LiveTvManager.cs +++ b/src/Jellyfin.LiveTv/LiveTvManager.cs @@ -45,6 +45,7 @@ namespace Jellyfin.LiveTv private readonly ILocalizationManager _localization; private readonly IChannelManager _channelManager; private readonly IRecordingsManager _recordingsManager; + private readonly IMediaSourceManager _mediaSourceManager; private readonly LiveTvDtoService _tvDtoService; private readonly ILiveTvService[] _services; @@ -58,6 +59,7 @@ namespace Jellyfin.LiveTv ILocalizationManager localization, IChannelManager channelManager, IRecordingsManager recordingsManager, + IMediaSourceManager mediaSourceManager, LiveTvDtoService liveTvDtoService, IEnumerable<ILiveTvService> services) { @@ -71,6 +73,7 @@ namespace Jellyfin.LiveTv _channelManager = channelManager; _tvDtoService = liveTvDtoService; _recordingsManager = recordingsManager; + _mediaSourceManager = mediaSourceManager; _services = services.ToArray(); var defaultService = _services.OfType<DefaultLiveTvService>().First(); @@ -987,6 +990,13 @@ namespace Jellyfin.LiveTv dto.ChannelNumber = channel.Number; dto.ChannelType = channel.ChannelType; + var activeStreamCount = _mediaSourceManager.GetLiveStreams(channel.Id).Sum(i => i.ConsumerCount); + + if (activeStreamCount > 0) + { + dto.ActiveStreamCount = activeStreamCount; + } + currentChannelsDict[dto.Id] = dto; if (addCurrentProgram) diff --git a/src/Jellyfin.LiveTv/LiveTvMediaSourceProvider.cs b/src/Jellyfin.LiveTv/LiveTvMediaSourceProvider.cs index 40ac5ce0fd..b336591c53 100644 --- a/src/Jellyfin.LiveTv/LiveTvMediaSourceProvider.cs +++ b/src/Jellyfin.LiveTv/LiveTvMediaSourceProvider.cs @@ -296,6 +296,8 @@ namespace Jellyfin.LiveTv _logger.LogInformation("Live stream opened after {0}ms", (endTime - startTime).TotalMilliseconds); } + liveStream.ChannelId = channel.Id; + info.RequiresClosing = true; var idPrefix = service.GetType().FullName!.GetMD5().ToString("N", CultureInfo.InvariantCulture) + "_"; diff --git a/src/Jellyfin.LiveTv/TunerHosts/LiveStream.cs b/src/Jellyfin.LiveTv/TunerHosts/LiveStream.cs index 70d8afc5d0..c73afa4435 100644 --- a/src/Jellyfin.LiveTv/TunerHosts/LiveStream.cs +++ b/src/Jellyfin.LiveTv/TunerHosts/LiveStream.cs @@ -72,6 +72,8 @@ namespace Jellyfin.LiveTv.TunerHosts public string TunerHostId { get; } + public Guid ChannelId { get; set; } + public DateTime DateOpened { get; protected set; } protected void SetTempFilePath(string extension) |
