| | | 1 | | #nullable disable |
| | | 2 | | |
| | | 3 | | #pragma warning disable CS1591 |
| | | 4 | | |
| | | 5 | | using System; |
| | | 6 | | using System.Collections.Concurrent; |
| | | 7 | | using System.Collections.Generic; |
| | | 8 | | using System.Collections.Immutable; |
| | | 9 | | using System.Globalization; |
| | | 10 | | using System.IO; |
| | | 11 | | using System.Linq; |
| | | 12 | | using System.Text.Json; |
| | | 13 | | using System.Threading; |
| | | 14 | | using System.Threading.Tasks; |
| | | 15 | | using AsyncKeyedLock; |
| | | 16 | | using Jellyfin.Data; |
| | | 17 | | using Jellyfin.Data.Enums; |
| | | 18 | | using Jellyfin.Database.Implementations.Entities; |
| | | 19 | | using Jellyfin.Database.Implementations.Enums; |
| | | 20 | | using Jellyfin.Extensions; |
| | | 21 | | using Jellyfin.Extensions.Json; |
| | | 22 | | using MediaBrowser.Common.Configuration; |
| | | 23 | | using MediaBrowser.Common.Extensions; |
| | | 24 | | using MediaBrowser.Controller; |
| | | 25 | | using MediaBrowser.Controller.Entities; |
| | | 26 | | using MediaBrowser.Controller.Library; |
| | | 27 | | using MediaBrowser.Controller.LiveTv; |
| | | 28 | | using MediaBrowser.Controller.MediaEncoding; |
| | | 29 | | using MediaBrowser.Controller.Persistence; |
| | | 30 | | using MediaBrowser.Controller.Providers; |
| | | 31 | | using MediaBrowser.Model.Dlna; |
| | | 32 | | using MediaBrowser.Model.Dto; |
| | | 33 | | using MediaBrowser.Model.Entities; |
| | | 34 | | using MediaBrowser.Model.Globalization; |
| | | 35 | | using MediaBrowser.Model.IO; |
| | | 36 | | using MediaBrowser.Model.MediaInfo; |
| | | 37 | | using Microsoft.Extensions.Logging; |
| | | 38 | | |
| | | 39 | | namespace Emby.Server.Implementations.Library |
| | | 40 | | { |
| | | 41 | | public class MediaSourceManager : IMediaSourceManager, IDisposable |
| | | 42 | | { |
| | | 43 | | // Do not use a pipe here because Roku http requests to the server will fail, without any explicit error message |
| | | 44 | | private const char LiveStreamIdDelimiter = '_'; |
| | | 45 | | |
| | | 46 | | private readonly IServerApplicationHost _appHost; |
| | | 47 | | private readonly IItemRepository _itemRepo; |
| | | 48 | | private readonly IUserManager _userManager; |
| | | 49 | | private readonly ILibraryManager _libraryManager; |
| | | 50 | | private readonly IFileSystem _fileSystem; |
| | | 51 | | private readonly ILogger<MediaSourceManager> _logger; |
| | | 52 | | private readonly IUserDataManager _userDataManager; |
| | | 53 | | private readonly IMediaEncoder _mediaEncoder; |
| | | 54 | | private readonly ILocalizationManager _localizationManager; |
| | | 55 | | private readonly IApplicationPaths _appPaths; |
| | | 56 | | private readonly IDirectoryService _directoryService; |
| | | 57 | | private readonly IMediaStreamRepository _mediaStreamRepository; |
| | | 58 | | private readonly IMediaAttachmentRepository _mediaAttachmentRepository; |
| | 27 | 59 | | private readonly ConcurrentDictionary<string, ILiveStream> _openStreams = new ConcurrentDictionary<string, ILive |
| | 27 | 60 | | private readonly AsyncNonKeyedLocker _liveStreamLocker = new(1); |
| | 27 | 61 | | private readonly JsonSerializerOptions _jsonOptions = JsonDefaults.Options; |
| | | 62 | | |
| | | 63 | | private IMediaSourceProvider[] _providers; |
| | | 64 | | |
| | | 65 | | public MediaSourceManager( |
| | | 66 | | IServerApplicationHost appHost, |
| | | 67 | | IItemRepository itemRepo, |
| | | 68 | | IApplicationPaths applicationPaths, |
| | | 69 | | ILocalizationManager localizationManager, |
| | | 70 | | IUserManager userManager, |
| | | 71 | | ILibraryManager libraryManager, |
| | | 72 | | ILogger<MediaSourceManager> logger, |
| | | 73 | | IFileSystem fileSystem, |
| | | 74 | | IUserDataManager userDataManager, |
| | | 75 | | IMediaEncoder mediaEncoder, |
| | | 76 | | IDirectoryService directoryService, |
| | | 77 | | IMediaStreamRepository mediaStreamRepository, |
| | | 78 | | IMediaAttachmentRepository mediaAttachmentRepository) |
| | | 79 | | { |
| | 27 | 80 | | _appHost = appHost; |
| | 27 | 81 | | _itemRepo = itemRepo; |
| | 27 | 82 | | _userManager = userManager; |
| | 27 | 83 | | _libraryManager = libraryManager; |
| | 27 | 84 | | _logger = logger; |
| | 27 | 85 | | _fileSystem = fileSystem; |
| | 27 | 86 | | _userDataManager = userDataManager; |
| | 27 | 87 | | _mediaEncoder = mediaEncoder; |
| | 27 | 88 | | _localizationManager = localizationManager; |
| | 27 | 89 | | _appPaths = applicationPaths; |
| | 27 | 90 | | _directoryService = directoryService; |
| | 27 | 91 | | _mediaStreamRepository = mediaStreamRepository; |
| | 27 | 92 | | _mediaAttachmentRepository = mediaAttachmentRepository; |
| | 27 | 93 | | } |
| | | 94 | | |
| | | 95 | | public void AddParts(IEnumerable<IMediaSourceProvider> providers) |
| | | 96 | | { |
| | 21 | 97 | | _providers = providers.ToArray(); |
| | 21 | 98 | | } |
| | | 99 | | |
| | | 100 | | public IReadOnlyList<MediaStream> GetMediaStreams(MediaStreamQuery query) |
| | | 101 | | { |
| | 0 | 102 | | var list = _mediaStreamRepository.GetMediaStreams(query); |
| | | 103 | | |
| | 0 | 104 | | foreach (var stream in list) |
| | | 105 | | { |
| | 0 | 106 | | stream.SupportsExternalStream = StreamSupportsExternalStream(stream); |
| | | 107 | | } |
| | | 108 | | |
| | 0 | 109 | | return list; |
| | | 110 | | } |
| | | 111 | | |
| | | 112 | | private static bool StreamSupportsExternalStream(MediaStream stream) |
| | | 113 | | { |
| | 0 | 114 | | if (stream.IsExternal) |
| | | 115 | | { |
| | 0 | 116 | | return true; |
| | | 117 | | } |
| | | 118 | | |
| | 0 | 119 | | if (stream.IsTextSubtitleStream) |
| | | 120 | | { |
| | 0 | 121 | | return true; |
| | | 122 | | } |
| | | 123 | | |
| | 0 | 124 | | if (stream.IsPgsSubtitleStream) |
| | | 125 | | { |
| | 0 | 126 | | return true; |
| | | 127 | | } |
| | | 128 | | |
| | 0 | 129 | | return false; |
| | | 130 | | } |
| | | 131 | | |
| | | 132 | | public IReadOnlyList<MediaStream> GetMediaStreams(Guid itemId) |
| | | 133 | | { |
| | 0 | 134 | | var list = GetMediaStreams(new MediaStreamQuery |
| | 0 | 135 | | { |
| | 0 | 136 | | ItemId = itemId |
| | 0 | 137 | | }); |
| | | 138 | | |
| | 0 | 139 | | return GetMediaStreamsForItem(list); |
| | | 140 | | } |
| | | 141 | | |
| | | 142 | | private IReadOnlyList<MediaStream> GetMediaStreamsForItem(IReadOnlyList<MediaStream> streams) |
| | | 143 | | { |
| | 0 | 144 | | foreach (var stream in streams) |
| | | 145 | | { |
| | 0 | 146 | | if (stream.Type == MediaStreamType.Subtitle) |
| | | 147 | | { |
| | 0 | 148 | | stream.SupportsExternalStream = StreamSupportsExternalStream(stream); |
| | | 149 | | } |
| | | 150 | | } |
| | | 151 | | |
| | 0 | 152 | | return streams; |
| | | 153 | | } |
| | | 154 | | |
| | | 155 | | /// <inheritdoc /> |
| | | 156 | | public IReadOnlyList<MediaAttachment> GetMediaAttachments(MediaAttachmentQuery query) |
| | | 157 | | { |
| | 0 | 158 | | return _mediaAttachmentRepository.GetMediaAttachments(query); |
| | | 159 | | } |
| | | 160 | | |
| | | 161 | | /// <inheritdoc /> |
| | | 162 | | public IReadOnlyList<MediaAttachment> GetMediaAttachments(Guid itemId) |
| | | 163 | | { |
| | 0 | 164 | | return GetMediaAttachments(new MediaAttachmentQuery |
| | 0 | 165 | | { |
| | 0 | 166 | | ItemId = itemId |
| | 0 | 167 | | }); |
| | | 168 | | } |
| | | 169 | | |
| | | 170 | | public async Task<IReadOnlyList<MediaSourceInfo>> GetPlaybackMediaSources(BaseItem item, User user, bool allowMe |
| | | 171 | | { |
| | | 172 | | var mediaSources = GetStaticMediaSources(item, enablePathSubstitution, user); |
| | | 173 | | |
| | | 174 | | // If file is strm or main media stream is missing, force a metadata refresh with remote probing |
| | | 175 | | if (allowMediaProbe && mediaSources[0].Type != MediaSourceType.Placeholder |
| | | 176 | | && (item.Path.EndsWith(".strm", StringComparison.OrdinalIgnoreCase) |
| | | 177 | | || (item.MediaType == MediaType.Video && mediaSources[0].MediaStreams.All(i => i.Type != MediaStream |
| | | 178 | | || (item.MediaType == MediaType.Audio && mediaSources[0].MediaStreams.All(i => i.Type != MediaStream |
| | | 179 | | { |
| | | 180 | | await item.RefreshMetadata( |
| | | 181 | | new MetadataRefreshOptions(_directoryService) |
| | | 182 | | { |
| | | 183 | | EnableRemoteContentProbe = true, |
| | | 184 | | MetadataRefreshMode = MetadataRefreshMode.FullRefresh |
| | | 185 | | }, |
| | | 186 | | cancellationToken).ConfigureAwait(false); |
| | | 187 | | |
| | | 188 | | mediaSources = GetStaticMediaSources(item, enablePathSubstitution, user); |
| | | 189 | | } |
| | | 190 | | |
| | | 191 | | var dynamicMediaSources = await GetDynamicMediaSources(item, cancellationToken).ConfigureAwait(false); |
| | | 192 | | |
| | | 193 | | var list = new List<MediaSourceInfo>(); |
| | | 194 | | |
| | | 195 | | list.AddRange(mediaSources); |
| | | 196 | | |
| | | 197 | | foreach (var source in dynamicMediaSources) |
| | | 198 | | { |
| | | 199 | | // Validate that this is actually possible |
| | | 200 | | if (source.SupportsDirectStream) |
| | | 201 | | { |
| | | 202 | | source.SupportsDirectStream = SupportsDirectStream(source.Path, source.Protocol); |
| | | 203 | | } |
| | | 204 | | |
| | | 205 | | if (user is not null) |
| | | 206 | | { |
| | | 207 | | SetDefaultAudioAndSubtitleStreamIndices(item, source, user); |
| | | 208 | | |
| | | 209 | | if (item.MediaType == MediaType.Audio) |
| | | 210 | | { |
| | | 211 | | source.SupportsTranscoding = user.HasPermission(PermissionKind.EnableAudioPlaybackTranscoding); |
| | | 212 | | } |
| | | 213 | | else if (item.MediaType == MediaType.Video) |
| | | 214 | | { |
| | | 215 | | source.SupportsTranscoding = user.HasPermission(PermissionKind.EnableVideoPlaybackTranscoding); |
| | | 216 | | source.SupportsDirectStream = user.HasPermission(PermissionKind.EnablePlaybackRemuxing); |
| | | 217 | | } |
| | | 218 | | } |
| | | 219 | | |
| | | 220 | | list.Add(source); |
| | | 221 | | } |
| | | 222 | | |
| | | 223 | | return SortMediaSources(list).ToArray(); |
| | | 224 | | } |
| | | 225 | | |
| | | 226 | | /// <inheritdoc />> |
| | | 227 | | public MediaProtocol GetPathProtocol(string path) |
| | | 228 | | { |
| | 2371 | 229 | | if (path.StartsWith("Rtsp", StringComparison.OrdinalIgnoreCase)) |
| | | 230 | | { |
| | 1 | 231 | | return MediaProtocol.Rtsp; |
| | | 232 | | } |
| | | 233 | | |
| | 2370 | 234 | | if (path.StartsWith("Rtmp", StringComparison.OrdinalIgnoreCase)) |
| | | 235 | | { |
| | 0 | 236 | | return MediaProtocol.Rtmp; |
| | | 237 | | } |
| | | 238 | | |
| | 2370 | 239 | | if (path.StartsWith("Http", StringComparison.OrdinalIgnoreCase)) |
| | | 240 | | { |
| | 2 | 241 | | return MediaProtocol.Http; |
| | | 242 | | } |
| | | 243 | | |
| | 2368 | 244 | | if (path.StartsWith("rtp", StringComparison.OrdinalIgnoreCase)) |
| | | 245 | | { |
| | 0 | 246 | | return MediaProtocol.Rtp; |
| | | 247 | | } |
| | | 248 | | |
| | 2368 | 249 | | if (path.StartsWith("ftp", StringComparison.OrdinalIgnoreCase)) |
| | | 250 | | { |
| | 0 | 251 | | return MediaProtocol.Ftp; |
| | | 252 | | } |
| | | 253 | | |
| | 2368 | 254 | | if (path.StartsWith("udp", StringComparison.OrdinalIgnoreCase)) |
| | | 255 | | { |
| | 0 | 256 | | return MediaProtocol.Udp; |
| | | 257 | | } |
| | | 258 | | |
| | 2368 | 259 | | return _fileSystem.IsPathFile(path) ? MediaProtocol.File : MediaProtocol.Http; |
| | | 260 | | } |
| | | 261 | | |
| | | 262 | | public bool SupportsDirectStream(string path, MediaProtocol protocol) |
| | | 263 | | { |
| | 0 | 264 | | if (protocol == MediaProtocol.File) |
| | | 265 | | { |
| | 0 | 266 | | return true; |
| | | 267 | | } |
| | | 268 | | |
| | 0 | 269 | | if (protocol == MediaProtocol.Http) |
| | | 270 | | { |
| | 0 | 271 | | if (path is not null) |
| | | 272 | | { |
| | 0 | 273 | | if (path.Contains(".m3u", StringComparison.OrdinalIgnoreCase)) |
| | | 274 | | { |
| | 0 | 275 | | return false; |
| | | 276 | | } |
| | | 277 | | |
| | 0 | 278 | | return true; |
| | | 279 | | } |
| | | 280 | | } |
| | | 281 | | |
| | 0 | 282 | | return false; |
| | | 283 | | } |
| | | 284 | | |
| | | 285 | | private async Task<IEnumerable<MediaSourceInfo>> GetDynamicMediaSources(BaseItem item, CancellationToken cancell |
| | | 286 | | { |
| | | 287 | | var tasks = _providers.Select(i => GetDynamicMediaSources(item, i, cancellationToken)); |
| | | 288 | | var results = await Task.WhenAll(tasks).ConfigureAwait(false); |
| | | 289 | | |
| | | 290 | | return results.SelectMany(i => i); |
| | | 291 | | } |
| | | 292 | | |
| | | 293 | | private async Task<IEnumerable<MediaSourceInfo>> GetDynamicMediaSources(BaseItem item, IMediaSourceProvider prov |
| | | 294 | | { |
| | | 295 | | try |
| | | 296 | | { |
| | | 297 | | var sources = await provider.GetMediaSources(item, cancellationToken).ConfigureAwait(false); |
| | | 298 | | var list = sources.ToList(); |
| | | 299 | | |
| | | 300 | | foreach (var mediaSource in list) |
| | | 301 | | { |
| | | 302 | | mediaSource.InferTotalBitrate(); |
| | | 303 | | |
| | | 304 | | SetKeyProperties(provider, mediaSource); |
| | | 305 | | } |
| | | 306 | | |
| | | 307 | | return list; |
| | | 308 | | } |
| | | 309 | | catch (Exception ex) |
| | | 310 | | { |
| | | 311 | | _logger.LogError(ex, "Error getting media sources"); |
| | | 312 | | return []; |
| | | 313 | | } |
| | | 314 | | } |
| | | 315 | | |
| | | 316 | | private static void SetKeyProperties(IMediaSourceProvider provider, MediaSourceInfo mediaSource) |
| | | 317 | | { |
| | 0 | 318 | | var prefix = provider.GetType().FullName.GetMD5().ToString("N", CultureInfo.InvariantCulture) + LiveStreamId |
| | | 319 | | |
| | 0 | 320 | | if (!string.IsNullOrEmpty(mediaSource.OpenToken) && !mediaSource.OpenToken.StartsWith(prefix, StringComparis |
| | | 321 | | { |
| | 0 | 322 | | mediaSource.OpenToken = prefix + mediaSource.OpenToken; |
| | | 323 | | } |
| | | 324 | | |
| | 0 | 325 | | if (!string.IsNullOrEmpty(mediaSource.LiveStreamId) && !mediaSource.LiveStreamId.StartsWith(prefix, StringCo |
| | | 326 | | { |
| | 0 | 327 | | mediaSource.LiveStreamId = prefix + mediaSource.LiveStreamId; |
| | | 328 | | } |
| | 0 | 329 | | } |
| | | 330 | | |
| | | 331 | | public async Task<MediaSourceInfo> GetMediaSource(BaseItem item, string mediaSourceId, string liveStreamId, bool |
| | | 332 | | { |
| | | 333 | | if (!string.IsNullOrEmpty(liveStreamId)) |
| | | 334 | | { |
| | | 335 | | return await GetLiveStream(liveStreamId, cancellationToken).ConfigureAwait(false); |
| | | 336 | | } |
| | | 337 | | |
| | | 338 | | var sources = await GetPlaybackMediaSources(item, null, false, enablePathSubstitution, cancellationToken).Co |
| | | 339 | | |
| | | 340 | | return sources.FirstOrDefault(i => string.Equals(i.Id, mediaSourceId, StringComparison.OrdinalIgnoreCase)); |
| | | 341 | | } |
| | | 342 | | |
| | | 343 | | public IReadOnlyList<MediaSourceInfo> GetStaticMediaSources(BaseItem item, bool enablePathSubstitution, User use |
| | | 344 | | { |
| | 0 | 345 | | ArgumentNullException.ThrowIfNull(item); |
| | | 346 | | |
| | 0 | 347 | | var hasMediaSources = (IHasMediaSources)item; |
| | | 348 | | |
| | 0 | 349 | | var sources = hasMediaSources.GetMediaSources(enablePathSubstitution); |
| | | 350 | | |
| | 0 | 351 | | if (user is not null) |
| | | 352 | | { |
| | 0 | 353 | | foreach (var source in sources) |
| | | 354 | | { |
| | 0 | 355 | | SetDefaultAudioAndSubtitleStreamIndices(item, source, user); |
| | | 356 | | |
| | 0 | 357 | | if (item.MediaType == MediaType.Audio) |
| | | 358 | | { |
| | 0 | 359 | | source.SupportsTranscoding = user.HasPermission(PermissionKind.EnableAudioPlaybackTranscoding); |
| | | 360 | | } |
| | 0 | 361 | | else if (item.MediaType == MediaType.Video) |
| | | 362 | | { |
| | 0 | 363 | | source.SupportsTranscoding = user.HasPermission(PermissionKind.EnableVideoPlaybackTranscoding); |
| | 0 | 364 | | source.SupportsDirectStream = user.HasPermission(PermissionKind.EnablePlaybackRemuxing); |
| | | 365 | | } |
| | | 366 | | } |
| | | 367 | | } |
| | | 368 | | |
| | 0 | 369 | | return sources; |
| | | 370 | | } |
| | | 371 | | |
| | | 372 | | private IReadOnlyList<string> NormalizeLanguage(string language) |
| | | 373 | | { |
| | 0 | 374 | | if (string.IsNullOrEmpty(language)) |
| | | 375 | | { |
| | 0 | 376 | | return []; |
| | | 377 | | } |
| | | 378 | | |
| | 0 | 379 | | var culture = _localizationManager.FindLanguageInfo(language); |
| | 0 | 380 | | if (culture is not null) |
| | | 381 | | { |
| | 0 | 382 | | return culture.Name.Contains('-', StringComparison.OrdinalIgnoreCase) ? [culture.Name] : culture.ThreeLe |
| | | 383 | | } |
| | | 384 | | |
| | 0 | 385 | | return [language]; |
| | | 386 | | } |
| | | 387 | | |
| | | 388 | | private void SetDefaultSubtitleStreamIndex(MediaSourceInfo source, UserItemData userData, User user, bool allowR |
| | | 389 | | { |
| | 0 | 390 | | if (userData is not null |
| | 0 | 391 | | && userData.SubtitleStreamIndex.HasValue |
| | 0 | 392 | | && user.RememberSubtitleSelections |
| | 0 | 393 | | && user.SubtitleMode != SubtitlePlaybackMode.None |
| | 0 | 394 | | && allowRememberingSelection) |
| | | 395 | | { |
| | 0 | 396 | | var index = userData.SubtitleStreamIndex.Value; |
| | | 397 | | // Make sure the saved index is still valid |
| | 0 | 398 | | if (index == -1 || source.MediaStreams.Any(i => i.Type == MediaStreamType.Subtitle && i.Index == index)) |
| | | 399 | | { |
| | 0 | 400 | | source.DefaultSubtitleStreamIndex = index; |
| | 0 | 401 | | return; |
| | | 402 | | } |
| | | 403 | | } |
| | | 404 | | |
| | 0 | 405 | | var preferredSubs = NormalizeLanguage(user.SubtitleLanguagePreference); |
| | | 406 | | |
| | 0 | 407 | | var defaultAudioIndex = source.DefaultAudioStreamIndex; |
| | 0 | 408 | | var audioLanguage = defaultAudioIndex is null |
| | 0 | 409 | | ? null |
| | 0 | 410 | | : source.MediaStreams.Where(i => i.Type == MediaStreamType.Audio && i.Index == defaultAudioIndex).Select |
| | | 411 | | |
| | 0 | 412 | | source.DefaultSubtitleStreamIndex = MediaStreamSelector.GetDefaultSubtitleStreamIndex( |
| | 0 | 413 | | source.MediaStreams, |
| | 0 | 414 | | preferredSubs, |
| | 0 | 415 | | user.SubtitleMode, |
| | 0 | 416 | | audioLanguage); |
| | | 417 | | |
| | 0 | 418 | | MediaStreamSelector.SetSubtitleStreamScores(source.MediaStreams, preferredSubs, user.SubtitleMode, audioLang |
| | 0 | 419 | | } |
| | | 420 | | |
| | | 421 | | private void SetDefaultAudioStreamIndex(MediaSourceInfo source, UserItemData userData, User user, bool allowReme |
| | | 422 | | { |
| | 0 | 423 | | if (userData is not null && userData.AudioStreamIndex.HasValue && user.RememberAudioSelections && allowRemem |
| | | 424 | | { |
| | 0 | 425 | | var index = userData.AudioStreamIndex.Value; |
| | | 426 | | // Make sure the saved index is still valid |
| | 0 | 427 | | if (source.MediaStreams.Any(i => i.Type == MediaStreamType.Audio && i.Index == index)) |
| | | 428 | | { |
| | 0 | 429 | | source.DefaultAudioStreamIndex = index; |
| | 0 | 430 | | source.DefaultAudioIndexSource = AudioIndexSource.User; |
| | 0 | 431 | | return; |
| | | 432 | | } |
| | | 433 | | } |
| | | 434 | | |
| | 0 | 435 | | var preferredAudio = NormalizeLanguage(user.AudioLanguagePreference); |
| | | 436 | | |
| | 0 | 437 | | source.DefaultAudioStreamIndex = MediaStreamSelector.GetDefaultAudioStreamIndex(source.MediaStreams, preferr |
| | 0 | 438 | | if (user.PlayDefaultAudioTrack) |
| | | 439 | | { |
| | 0 | 440 | | source.DefaultAudioIndexSource |= AudioIndexSource.Default; |
| | | 441 | | } |
| | | 442 | | |
| | 0 | 443 | | if (preferredAudio.Count > 0) |
| | | 444 | | { |
| | 0 | 445 | | source.DefaultAudioIndexSource |= AudioIndexSource.Language; |
| | | 446 | | } |
| | 0 | 447 | | } |
| | | 448 | | |
| | | 449 | | public void SetDefaultAudioAndSubtitleStreamIndices(BaseItem item, MediaSourceInfo source, User user) |
| | | 450 | | { |
| | | 451 | | // Item would only be null if the app didn't supply ItemId as part of the live stream open request |
| | 0 | 452 | | var mediaType = item?.MediaType ?? MediaType.Video; |
| | | 453 | | |
| | 0 | 454 | | if (mediaType == MediaType.Video) |
| | | 455 | | { |
| | 0 | 456 | | var userData = item is null ? null : _userDataManager.GetUserData(user, item); |
| | | 457 | | |
| | 0 | 458 | | var allowRememberingSelection = item is null || item.EnableRememberingTrackSelections; |
| | | 459 | | |
| | 0 | 460 | | SetDefaultAudioStreamIndex(source, userData, user, allowRememberingSelection); |
| | 0 | 461 | | SetDefaultSubtitleStreamIndex(source, userData, user, allowRememberingSelection); |
| | | 462 | | } |
| | 0 | 463 | | else if (mediaType == MediaType.Audio) |
| | | 464 | | { |
| | 0 | 465 | | var audio = source.MediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio); |
| | | 466 | | |
| | 0 | 467 | | if (audio is not null) |
| | | 468 | | { |
| | 0 | 469 | | source.DefaultAudioStreamIndex = audio.Index; |
| | | 470 | | } |
| | | 471 | | } |
| | 0 | 472 | | } |
| | | 473 | | |
| | | 474 | | private static IEnumerable<MediaSourceInfo> SortMediaSources(IEnumerable<MediaSourceInfo> sources) |
| | | 475 | | { |
| | 0 | 476 | | return sources.OrderBy(i => |
| | 0 | 477 | | { |
| | 0 | 478 | | if (i.VideoType.HasValue && i.VideoType.Value == VideoType.VideoFile) |
| | 0 | 479 | | { |
| | 0 | 480 | | return 0; |
| | 0 | 481 | | } |
| | 0 | 482 | | |
| | 0 | 483 | | return 1; |
| | 0 | 484 | | }).ThenBy(i => i.Video3DFormat.HasValue ? 1 : 0) |
| | 0 | 485 | | .ThenByDescending(i => |
| | 0 | 486 | | { |
| | 0 | 487 | | var stream = i.VideoStream; |
| | 0 | 488 | | |
| | 0 | 489 | | return stream?.Width ?? 0; |
| | 0 | 490 | | }) |
| | 0 | 491 | | .Where(i => i.Type != MediaSourceType.Placeholder); |
| | | 492 | | } |
| | | 493 | | |
| | | 494 | | public async Task<Tuple<LiveStreamResponse, IDirectStreamProvider>> OpenLiveStreamInternal(LiveStreamRequest req |
| | | 495 | | { |
| | | 496 | | MediaSourceInfo mediaSource; |
| | | 497 | | ILiveStream liveStream; |
| | | 498 | | |
| | | 499 | | using (await _liveStreamLocker.LockAsync(cancellationToken).ConfigureAwait(false)) |
| | | 500 | | { |
| | | 501 | | var (provider, keyId) = GetProvider(request.OpenToken); |
| | | 502 | | |
| | | 503 | | var currentLiveStreams = _openStreams.Values.ToList(); |
| | | 504 | | |
| | | 505 | | liveStream = await provider.OpenMediaSource(keyId, currentLiveStreams, cancellationToken).ConfigureAwait |
| | | 506 | | |
| | | 507 | | mediaSource = liveStream.MediaSource; |
| | | 508 | | |
| | | 509 | | // Validate that this is actually possible |
| | | 510 | | if (mediaSource.SupportsDirectStream) |
| | | 511 | | { |
| | | 512 | | mediaSource.SupportsDirectStream = SupportsDirectStream(mediaSource.Path, mediaSource.Protocol); |
| | | 513 | | } |
| | | 514 | | |
| | | 515 | | SetKeyProperties(provider, mediaSource); |
| | | 516 | | |
| | | 517 | | _openStreams[mediaSource.LiveStreamId] = liveStream; |
| | | 518 | | } |
| | | 519 | | |
| | | 520 | | try |
| | | 521 | | { |
| | | 522 | | if (mediaSource.MediaStreams.Any(i => i.Index != -1) || !mediaSource.SupportsProbing) |
| | | 523 | | { |
| | | 524 | | AddMediaInfo(mediaSource); |
| | | 525 | | } |
| | | 526 | | else |
| | | 527 | | { |
| | | 528 | | // hack - these two values were taken from LiveTVMediaSourceProvider |
| | | 529 | | string cacheKey = request.OpenToken; |
| | | 530 | | |
| | | 531 | | await new LiveStreamHelper(_mediaEncoder, _logger, _appPaths) |
| | | 532 | | .AddMediaInfoWithProbe(mediaSource, false, cacheKey, true, cancellationToken) |
| | | 533 | | .ConfigureAwait(false); |
| | | 534 | | } |
| | | 535 | | } |
| | | 536 | | catch (Exception ex) |
| | | 537 | | { |
| | | 538 | | _logger.LogError(ex, "Error probing live tv stream"); |
| | | 539 | | AddMediaInfo(mediaSource); |
| | | 540 | | } |
| | | 541 | | |
| | | 542 | | // TODO: @bond Fix |
| | | 543 | | var json = JsonSerializer.SerializeToUtf8Bytes(mediaSource, _jsonOptions); |
| | | 544 | | _logger.LogInformation("Live stream opened: {@MediaSource}", mediaSource); |
| | | 545 | | var clone = JsonSerializer.Deserialize<MediaSourceInfo>(json, _jsonOptions); |
| | | 546 | | |
| | | 547 | | if (!request.UserId.IsEmpty()) |
| | | 548 | | { |
| | | 549 | | var user = _userManager.GetUserById(request.UserId); |
| | | 550 | | var item = request.ItemId.IsEmpty() |
| | | 551 | | ? null |
| | | 552 | | : _libraryManager.GetItemById(request.ItemId); |
| | | 553 | | SetDefaultAudioAndSubtitleStreamIndices(item, clone, user); |
| | | 554 | | } |
| | | 555 | | |
| | | 556 | | return new Tuple<LiveStreamResponse, IDirectStreamProvider>(new LiveStreamResponse(clone), liveStream as IDi |
| | | 557 | | } |
| | | 558 | | |
| | | 559 | | private static void AddMediaInfo(MediaSourceInfo mediaSource) |
| | | 560 | | { |
| | 0 | 561 | | mediaSource.DefaultSubtitleStreamIndex = null; |
| | | 562 | | |
| | | 563 | | // Null this out so that it will be treated like a live stream |
| | 0 | 564 | | if (mediaSource.IsInfiniteStream) |
| | | 565 | | { |
| | 0 | 566 | | mediaSource.RunTimeTicks = null; |
| | | 567 | | } |
| | | 568 | | |
| | 0 | 569 | | var audioStream = mediaSource.MediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio); |
| | | 570 | | |
| | 0 | 571 | | if (audioStream is null || audioStream.Index == -1) |
| | | 572 | | { |
| | 0 | 573 | | mediaSource.DefaultAudioStreamIndex = null; |
| | | 574 | | } |
| | | 575 | | else |
| | | 576 | | { |
| | 0 | 577 | | mediaSource.DefaultAudioStreamIndex = audioStream.Index; |
| | | 578 | | } |
| | | 579 | | |
| | 0 | 580 | | var videoStream = mediaSource.MediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video); |
| | 0 | 581 | | if (videoStream is not null) |
| | | 582 | | { |
| | 0 | 583 | | if (!videoStream.BitRate.HasValue) |
| | | 584 | | { |
| | 0 | 585 | | var width = videoStream.Width ?? 1920; |
| | | 586 | | |
| | 0 | 587 | | if (width >= 3000) |
| | | 588 | | { |
| | 0 | 589 | | videoStream.BitRate = 30000000; |
| | | 590 | | } |
| | 0 | 591 | | else if (width >= 1900) |
| | | 592 | | { |
| | 0 | 593 | | videoStream.BitRate = 20000000; |
| | | 594 | | } |
| | 0 | 595 | | else if (width >= 1200) |
| | | 596 | | { |
| | 0 | 597 | | videoStream.BitRate = 8000000; |
| | | 598 | | } |
| | 0 | 599 | | else if (width >= 700) |
| | | 600 | | { |
| | 0 | 601 | | videoStream.BitRate = 2000000; |
| | | 602 | | } |
| | | 603 | | } |
| | | 604 | | } |
| | | 605 | | |
| | | 606 | | // Try to estimate this |
| | 0 | 607 | | mediaSource.InferTotalBitrate(); |
| | 0 | 608 | | } |
| | | 609 | | |
| | | 610 | | public async Task<LiveStreamResponse> OpenLiveStream(LiveStreamRequest request, CancellationToken cancellationTo |
| | | 611 | | { |
| | | 612 | | var result = await OpenLiveStreamInternal(request, cancellationToken).ConfigureAwait(false); |
| | | 613 | | return result.Item1; |
| | | 614 | | } |
| | | 615 | | |
| | | 616 | | public async Task<MediaSourceInfo> GetLiveStreamMediaInfo(string id, CancellationToken cancellationToken) |
| | | 617 | | { |
| | | 618 | | // TODO probably shouldn't throw here but it is kept for "backwards compatibility" |
| | | 619 | | var liveStreamInfo = GetLiveStreamInfo(id) ?? throw new ResourceNotFoundException(); |
| | | 620 | | |
| | | 621 | | var mediaSource = liveStreamInfo.MediaSource; |
| | | 622 | | |
| | | 623 | | if (liveStreamInfo is IDirectStreamProvider) |
| | | 624 | | { |
| | | 625 | | var info = await _mediaEncoder.GetMediaInfo( |
| | | 626 | | new MediaInfoRequest |
| | | 627 | | { |
| | | 628 | | MediaSource = mediaSource, |
| | | 629 | | ExtractChapters = false, |
| | | 630 | | MediaType = DlnaProfileType.Video |
| | | 631 | | }, |
| | | 632 | | cancellationToken).ConfigureAwait(false); |
| | | 633 | | |
| | | 634 | | mediaSource.MediaStreams = info.MediaStreams; |
| | | 635 | | mediaSource.Container = info.Container; |
| | | 636 | | mediaSource.Bitrate = info.Bitrate; |
| | | 637 | | } |
| | | 638 | | |
| | | 639 | | return mediaSource; |
| | | 640 | | } |
| | | 641 | | |
| | | 642 | | public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudio, string cacheKey, bool addProb |
| | | 643 | | { |
| | | 644 | | var originalRuntime = mediaSource.RunTimeTicks; |
| | | 645 | | |
| | | 646 | | var now = DateTime.UtcNow; |
| | | 647 | | |
| | | 648 | | MediaInfo mediaInfo = null; |
| | | 649 | | var cacheFilePath = string.IsNullOrEmpty(cacheKey) ? null : Path.Combine(_appPaths.CachePath, "mediainfo", c |
| | | 650 | | |
| | | 651 | | if (!string.IsNullOrEmpty(cacheKey)) |
| | | 652 | | { |
| | | 653 | | FileStream jsonStream = AsyncFile.OpenRead(cacheFilePath); |
| | | 654 | | try |
| | | 655 | | { |
| | | 656 | | mediaInfo = await JsonSerializer.DeserializeAsync<MediaInfo>(jsonStream, _jsonOptions, cancellationT |
| | | 657 | | } |
| | | 658 | | catch (Exception ex) |
| | | 659 | | { |
| | | 660 | | _logger.LogDebug(ex, "Error parsing cached media info."); |
| | | 661 | | } |
| | | 662 | | finally |
| | | 663 | | { |
| | | 664 | | await jsonStream.DisposeAsync().ConfigureAwait(false); |
| | | 665 | | } |
| | | 666 | | } |
| | | 667 | | |
| | | 668 | | if (mediaInfo is null) |
| | | 669 | | { |
| | | 670 | | if (addProbeDelay) |
| | | 671 | | { |
| | | 672 | | var delayMs = mediaSource.AnalyzeDurationMs ?? 0; |
| | | 673 | | delayMs = Math.Max(3000, delayMs); |
| | | 674 | | await Task.Delay(delayMs, cancellationToken).ConfigureAwait(false); |
| | | 675 | | } |
| | | 676 | | |
| | | 677 | | if (isLiveStream) |
| | | 678 | | { |
| | | 679 | | mediaSource.AnalyzeDurationMs = 3000; |
| | | 680 | | } |
| | | 681 | | |
| | | 682 | | mediaInfo = await _mediaEncoder.GetMediaInfo( |
| | | 683 | | new MediaInfoRequest |
| | | 684 | | { |
| | | 685 | | MediaSource = mediaSource, |
| | | 686 | | MediaType = isAudio ? DlnaProfileType.Audio : DlnaProfileType.Video, |
| | | 687 | | ExtractChapters = false |
| | | 688 | | }, |
| | | 689 | | cancellationToken).ConfigureAwait(false); |
| | | 690 | | |
| | | 691 | | if (cacheFilePath is not null) |
| | | 692 | | { |
| | | 693 | | Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath)); |
| | | 694 | | FileStream createStream = AsyncFile.Create(cacheFilePath); |
| | | 695 | | await using (createStream.ConfigureAwait(false)) |
| | | 696 | | { |
| | | 697 | | await JsonSerializer.SerializeAsync(createStream, mediaInfo, _jsonOptions, cancellationToken).Co |
| | | 698 | | } |
| | | 699 | | |
| | | 700 | | // _logger.LogDebug("Saved media info to {0}", cacheFilePath); |
| | | 701 | | } |
| | | 702 | | } |
| | | 703 | | |
| | | 704 | | var mediaStreams = mediaInfo.MediaStreams; |
| | | 705 | | |
| | | 706 | | if (isLiveStream && !string.IsNullOrEmpty(cacheKey)) |
| | | 707 | | { |
| | | 708 | | var newList = new List<MediaStream>(); |
| | | 709 | | newList.AddRange(mediaStreams.Where(i => i.Type == MediaStreamType.Video).Take(1)); |
| | | 710 | | newList.AddRange(mediaStreams.Where(i => i.Type == MediaStreamType.Audio).Take(1)); |
| | | 711 | | |
| | | 712 | | foreach (var stream in newList) |
| | | 713 | | { |
| | | 714 | | stream.Index = -1; |
| | | 715 | | stream.Language = null; |
| | | 716 | | } |
| | | 717 | | |
| | | 718 | | mediaStreams = newList; |
| | | 719 | | } |
| | | 720 | | |
| | | 721 | | _logger.LogInformation("Live tv media info probe took {0} seconds", (DateTime.UtcNow - now).TotalSeconds.ToS |
| | | 722 | | |
| | | 723 | | mediaSource.Bitrate = mediaInfo.Bitrate; |
| | | 724 | | mediaSource.Container = mediaInfo.Container; |
| | | 725 | | mediaSource.Formats = mediaInfo.Formats; |
| | | 726 | | mediaSource.MediaStreams = mediaStreams; |
| | | 727 | | mediaSource.RunTimeTicks = mediaInfo.RunTimeTicks; |
| | | 728 | | mediaSource.Size = mediaInfo.Size; |
| | | 729 | | mediaSource.Timestamp = mediaInfo.Timestamp; |
| | | 730 | | mediaSource.Video3DFormat = mediaInfo.Video3DFormat; |
| | | 731 | | mediaSource.VideoType = mediaInfo.VideoType; |
| | | 732 | | |
| | | 733 | | mediaSource.DefaultSubtitleStreamIndex = null; |
| | | 734 | | |
| | | 735 | | if (isLiveStream) |
| | | 736 | | { |
| | | 737 | | // Null this out so that it will be treated like a live stream |
| | | 738 | | if (!originalRuntime.HasValue) |
| | | 739 | | { |
| | | 740 | | mediaSource.RunTimeTicks = null; |
| | | 741 | | } |
| | | 742 | | } |
| | | 743 | | |
| | | 744 | | var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio); |
| | | 745 | | |
| | | 746 | | if (audioStream is null || audioStream.Index == -1) |
| | | 747 | | { |
| | | 748 | | mediaSource.DefaultAudioStreamIndex = null; |
| | | 749 | | } |
| | | 750 | | else |
| | | 751 | | { |
| | | 752 | | mediaSource.DefaultAudioStreamIndex = audioStream.Index; |
| | | 753 | | } |
| | | 754 | | |
| | | 755 | | var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video); |
| | | 756 | | if (videoStream is not null) |
| | | 757 | | { |
| | | 758 | | if (!videoStream.BitRate.HasValue) |
| | | 759 | | { |
| | | 760 | | var width = videoStream.Width ?? 1920; |
| | | 761 | | |
| | | 762 | | if (width >= 3000) |
| | | 763 | | { |
| | | 764 | | videoStream.BitRate = 30000000; |
| | | 765 | | } |
| | | 766 | | else if (width >= 1900) |
| | | 767 | | { |
| | | 768 | | videoStream.BitRate = 20000000; |
| | | 769 | | } |
| | | 770 | | else if (width >= 1200) |
| | | 771 | | { |
| | | 772 | | videoStream.BitRate = 8000000; |
| | | 773 | | } |
| | | 774 | | else if (width >= 700) |
| | | 775 | | { |
| | | 776 | | videoStream.BitRate = 2000000; |
| | | 777 | | } |
| | | 778 | | } |
| | | 779 | | |
| | | 780 | | // This is coming up false and preventing stream copy |
| | | 781 | | videoStream.IsAVC = null; |
| | | 782 | | } |
| | | 783 | | |
| | | 784 | | if (isLiveStream) |
| | | 785 | | { |
| | | 786 | | mediaSource.AnalyzeDurationMs = 3000; |
| | | 787 | | } |
| | | 788 | | |
| | | 789 | | // Try to estimate this |
| | | 790 | | mediaSource.InferTotalBitrate(true); |
| | | 791 | | } |
| | | 792 | | |
| | | 793 | | public Task<Tuple<MediaSourceInfo, IDirectStreamProvider>> GetLiveStreamWithDirectStreamProvider(string id, Canc |
| | | 794 | | { |
| | 0 | 795 | | ArgumentException.ThrowIfNullOrEmpty(id); |
| | | 796 | | |
| | 0 | 797 | | var info = GetLiveStreamInfo(id); |
| | 0 | 798 | | if (info is null) |
| | | 799 | | { |
| | 0 | 800 | | return Task.FromResult<Tuple<MediaSourceInfo, IDirectStreamProvider>>(new Tuple<MediaSourceInfo, IDirect |
| | | 801 | | } |
| | | 802 | | |
| | 0 | 803 | | return Task.FromResult<Tuple<MediaSourceInfo, IDirectStreamProvider>>(new Tuple<MediaSourceInfo, IDirectStre |
| | | 804 | | } |
| | | 805 | | |
| | | 806 | | public ILiveStream GetLiveStreamInfo(string id) |
| | | 807 | | { |
| | 0 | 808 | | ArgumentException.ThrowIfNullOrEmpty(id); |
| | | 809 | | |
| | 0 | 810 | | if (_openStreams.TryGetValue(id, out ILiveStream info)) |
| | | 811 | | { |
| | 0 | 812 | | return info; |
| | | 813 | | } |
| | | 814 | | |
| | 0 | 815 | | return null; |
| | | 816 | | } |
| | | 817 | | |
| | | 818 | | /// <inheritdoc /> |
| | | 819 | | public ILiveStream GetLiveStreamInfoByUniqueId(string uniqueId) |
| | | 820 | | { |
| | 0 | 821 | | return _openStreams.Values.FirstOrDefault(stream => string.Equals(uniqueId, stream?.UniqueId, StringComparis |
| | | 822 | | } |
| | | 823 | | |
| | | 824 | | public async Task<MediaSourceInfo> GetLiveStream(string id, CancellationToken cancellationToken) |
| | | 825 | | { |
| | | 826 | | var result = await GetLiveStreamWithDirectStreamProvider(id, cancellationToken).ConfigureAwait(false); |
| | | 827 | | return result.Item1; |
| | | 828 | | } |
| | | 829 | | |
| | | 830 | | public async Task<IReadOnlyList<MediaSourceInfo>> GetRecordingStreamMediaSources(ActiveRecordingInfo info, Cance |
| | | 831 | | { |
| | | 832 | | var stream = new MediaSourceInfo |
| | | 833 | | { |
| | | 834 | | EncoderPath = _appHost.GetApiUrlForLocalAccess() + "/LiveTv/LiveRecordings/" + info.Id + "/stream", |
| | | 835 | | EncoderProtocol = MediaProtocol.Http, |
| | | 836 | | Path = info.Path, |
| | | 837 | | Protocol = MediaProtocol.File, |
| | | 838 | | Id = info.Id, |
| | | 839 | | SupportsDirectPlay = false, |
| | | 840 | | SupportsDirectStream = true, |
| | | 841 | | SupportsTranscoding = true, |
| | | 842 | | IsInfiniteStream = true, |
| | | 843 | | RequiresOpening = false, |
| | | 844 | | RequiresClosing = false, |
| | | 845 | | BufferMs = 0, |
| | | 846 | | IgnoreDts = true, |
| | | 847 | | IgnoreIndex = true |
| | | 848 | | }; |
| | | 849 | | |
| | | 850 | | await new LiveStreamHelper(_mediaEncoder, _logger, _appPaths) |
| | | 851 | | .AddMediaInfoWithProbe(stream, false, false, cancellationToken).ConfigureAwait(false); |
| | | 852 | | |
| | | 853 | | return [stream]; |
| | | 854 | | } |
| | | 855 | | |
| | | 856 | | public async Task CloseLiveStream(string id) |
| | | 857 | | { |
| | | 858 | | ArgumentException.ThrowIfNullOrEmpty(id); |
| | | 859 | | |
| | | 860 | | using (await _liveStreamLocker.LockAsync().ConfigureAwait(false)) |
| | | 861 | | { |
| | | 862 | | if (_openStreams.TryGetValue(id, out ILiveStream liveStream)) |
| | | 863 | | { |
| | | 864 | | liveStream.ConsumerCount--; |
| | | 865 | | |
| | | 866 | | _logger.LogInformation("Live stream {0} consumer count is now {1}", liveStream.OriginalStreamId, liv |
| | | 867 | | |
| | | 868 | | if (liveStream.ConsumerCount <= 0) |
| | | 869 | | { |
| | | 870 | | _openStreams.TryRemove(id, out _); |
| | | 871 | | |
| | | 872 | | _logger.LogInformation("Closing live stream {0}", id); |
| | | 873 | | |
| | | 874 | | await liveStream.Close().ConfigureAwait(false); |
| | | 875 | | _logger.LogInformation("Live stream {0} closed successfully", id); |
| | | 876 | | } |
| | | 877 | | } |
| | | 878 | | } |
| | | 879 | | } |
| | | 880 | | |
| | | 881 | | private (IMediaSourceProvider MediaSourceProvider, string KeyId) GetProvider(string key) |
| | | 882 | | { |
| | 0 | 883 | | ArgumentException.ThrowIfNullOrEmpty(key); |
| | | 884 | | |
| | 0 | 885 | | var keys = key.Split(LiveStreamIdDelimiter, 2); |
| | | 886 | | |
| | 0 | 887 | | var provider = _providers.FirstOrDefault(i => string.Equals(i.GetType().FullName.GetMD5().ToString("N", Cult |
| | | 888 | | |
| | 0 | 889 | | var splitIndex = key.IndexOf(LiveStreamIdDelimiter, StringComparison.Ordinal); |
| | 0 | 890 | | var keyId = key.Substring(splitIndex + 1); |
| | | 891 | | |
| | 0 | 892 | | return (provider, keyId); |
| | | 893 | | } |
| | | 894 | | |
| | | 895 | | /// <inheritdoc /> |
| | | 896 | | public void Dispose() |
| | | 897 | | { |
| | 21 | 898 | | Dispose(true); |
| | 21 | 899 | | GC.SuppressFinalize(this); |
| | 21 | 900 | | } |
| | | 901 | | |
| | | 902 | | /// <summary> |
| | | 903 | | /// Releases unmanaged and - optionally - managed resources. |
| | | 904 | | /// </summary> |
| | | 905 | | /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release o |
| | | 906 | | protected virtual void Dispose(bool dispose) |
| | | 907 | | { |
| | 21 | 908 | | if (dispose) |
| | | 909 | | { |
| | 42 | 910 | | foreach (var key in _openStreams.Keys.ToList()) |
| | | 911 | | { |
| | 0 | 912 | | CloseLiveStream(key).GetAwaiter().GetResult(); |
| | | 913 | | } |
| | | 914 | | |
| | 21 | 915 | | _liveStreamLocker.Dispose(); |
| | | 916 | | } |
| | 21 | 917 | | } |
| | | 918 | | } |
| | | 919 | | } |