diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-08-19 15:43:35 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-08-19 15:43:35 -0400 |
| commit | 1ad990ad720931309afadd9f7912d66595dcc04e (patch) | |
| tree | 7769cfe0e14092046bb772607f31c1fbc908be1d /Emby.Server.Implementations/LiveTv | |
| parent | bd31c0175d87ec00a675b92ae9a92af569228775 (diff) | |
update live tv data transfer
Diffstat (limited to 'Emby.Server.Implementations/LiveTv')
6 files changed, 85 insertions, 111 deletions
diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 99b5558a2d..ecad5c0eb2 100644 --- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -208,7 +208,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV continue; } - if (virtualFolder.Locations.Count == 1) + if (virtualFolder.Locations.Length == 1) { // remove entire virtual folder try @@ -458,7 +458,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV return GetEpgChannelFromTunerChannel(info, tunerChannel, epgChannels); } - private string GetMappedChannel(string channelId, List<NameValuePair> mappings) + private string GetMappedChannel(string channelId, NameValuePair[] mappings) { foreach (NameValuePair mapping in mappings) { @@ -472,10 +472,10 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV private ChannelInfo GetEpgChannelFromTunerChannel(ListingsProviderInfo info, ChannelInfo tunerChannel, List<ChannelInfo> epgChannels) { - return GetEpgChannelFromTunerChannel(info.ChannelMappings.ToList(), tunerChannel, epgChannels); + return GetEpgChannelFromTunerChannel(info.ChannelMappings, tunerChannel, epgChannels); } - public ChannelInfo GetEpgChannelFromTunerChannel(List<NameValuePair> mappings, ChannelInfo tunerChannel, List<ChannelInfo> epgChannels) + public ChannelInfo GetEpgChannelFromTunerChannel(NameValuePair[] mappings, ChannelInfo tunerChannel, List<ChannelInfo> epgChannels) { if (!string.IsNullOrWhiteSpace(tunerChannel.Id)) { @@ -2591,7 +2591,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV { list.Add(new VirtualFolderInfo { - Locations = new List<string> { defaultFolder }, + Locations = new string[] { defaultFolder }, Name = defaultName }); } @@ -2601,7 +2601,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV { list.Add(new VirtualFolderInfo { - Locations = new List<string> { customPath }, + Locations = new string[] { customPath }, Name = "Recorded Movies", CollectionType = CollectionType.Movies }); @@ -2612,7 +2612,7 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV { list.Add(new VirtualFolderInfo { - Locations = new List<string> { customPath }, + Locations = new string[] { customPath }, Name = "Recorded Shows", CollectionType = CollectionType.TvShows }); diff --git a/Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs b/Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs index 619d2378df..eff2909fdb 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvDtoService.cs @@ -15,6 +15,8 @@ using System.Threading; using System.Threading.Tasks; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Extensions; +using MediaBrowser.Model.Querying; namespace Emby.Server.Implementations.LiveTv { @@ -110,7 +112,7 @@ namespace Emby.Server.Implementations.LiveTv PostPaddingSeconds = info.PostPaddingSeconds, IsPostPaddingRequired = info.IsPostPaddingRequired, IsPrePaddingRequired = info.IsPrePaddingRequired, - Days = info.Days, + Days = info.Days.ToArray(), Priority = info.Priority, RecordAnyChannel = info.RecordAnyChannel, RecordAnyTime = info.RecordAnyTime, @@ -135,7 +137,7 @@ namespace Emby.Server.Implementations.LiveTv dto.ProgramId = GetInternalProgramId(service.Name, info.ProgramId).ToString("N"); } - dto.DayPattern = info.Days == null ? null : GetDayPattern(info.Days); + dto.DayPattern = info.Days == null ? null : GetDayPattern(info.Days.ToArray(info.Days.Count)); FillImages(dto, info.Name, info.SeriesId); @@ -150,10 +152,7 @@ namespace Emby.Server.Implementations.LiveTv Name = seriesName, Limit = 1, ImageTypes = new ImageType[] { ImageType.Thumb }, - DtoOptions = new DtoOptions - { - Fields = new List<MediaBrowser.Model.Querying.ItemFields>() - } + DtoOptions = new DtoOptions(false) }).FirstOrDefault(); @@ -196,10 +195,7 @@ namespace Emby.Server.Implementations.LiveTv ExternalSeriesId = programSeriesId, Limit = 1, ImageTypes = new ImageType[] { ImageType.Primary }, - DtoOptions = new DtoOptions - { - Fields = new List<MediaBrowser.Model.Querying.ItemFields>() - } + DtoOptions = new DtoOptions(false) }).FirstOrDefault(); @@ -248,10 +244,7 @@ namespace Emby.Server.Implementations.LiveTv Name = seriesName, Limit = 1, ImageTypes = new ImageType[] { ImageType.Thumb }, - DtoOptions = new DtoOptions - { - Fields = new List<MediaBrowser.Model.Querying.ItemFields>() - } + DtoOptions = new DtoOptions(false) }).FirstOrDefault(); @@ -274,7 +267,7 @@ namespace Emby.Server.Implementations.LiveTv { try { - dto.ParentBackdropImageTags = new List<string> + dto.ParentBackdropImageTags = new string[] { _imageProcessor.GetImageCacheTag(librarySeries, image) }; @@ -294,10 +287,7 @@ namespace Emby.Server.Implementations.LiveTv Name = seriesName, Limit = 1, ImageTypes = new ImageType[] { ImageType.Primary }, - DtoOptions = new DtoOptions - { - Fields = new List<MediaBrowser.Model.Querying.ItemFields>() - } + DtoOptions = new DtoOptions(false) }).FirstOrDefault() ?? _libraryManager.GetItemList(new InternalItemsQuery { @@ -305,10 +295,7 @@ namespace Emby.Server.Implementations.LiveTv ExternalSeriesId = programSeriesId, Limit = 1, ImageTypes = new ImageType[] { ImageType.Primary }, - DtoOptions = new DtoOptions - { - Fields = new List<MediaBrowser.Model.Querying.ItemFields>() - } + DtoOptions = new DtoOptions(false) }).FirstOrDefault(); @@ -327,14 +314,14 @@ namespace Emby.Server.Implementations.LiveTv } } - if (dto.ParentBackdropImageTags == null || dto.ParentBackdropImageTags.Count == 0) + if (dto.ParentBackdropImageTags == null || dto.ParentBackdropImageTags.Length == 0) { image = program.GetImageInfo(ImageType.Backdrop, 0); if (image != null) { try { - dto.ParentBackdropImageTags = new List<string> + dto.ParentBackdropImageTags = new string[] { _imageProcessor.GetImageCacheTag(program, image) }; @@ -349,24 +336,24 @@ namespace Emby.Server.Implementations.LiveTv } } - public DayPattern? GetDayPattern(List<DayOfWeek> days) + public DayPattern? GetDayPattern(DayOfWeek[] days) { DayPattern? pattern = null; - if (days.Count > 0) + if (days.Length > 0) { - if (days.Count == 7) + if (days.Length == 7) { pattern = DayPattern.Daily; } - else if (days.Count == 2) + else if (days.Length == 2) { if (days.Contains(DayOfWeek.Saturday) && days.Contains(DayOfWeek.Sunday)) { pattern = DayPattern.Weekends; } } - else if (days.Count == 5) + else if (days.Length == 5) { if (days.Contains(DayOfWeek.Monday) && days.Contains(DayOfWeek.Tuesday) && days.Contains(DayOfWeek.Wednesday) && days.Contains(DayOfWeek.Thursday) && days.Contains(DayOfWeek.Friday)) { @@ -384,7 +371,7 @@ namespace Emby.Server.Implementations.LiveTv { Name = info.Name, Id = info.Id, - Clients = info.Clients, + Clients = info.Clients.ToArray(), ProgramName = info.ProgramName, SourceType = info.SourceType, Status = info.Status, @@ -543,7 +530,7 @@ namespace Emby.Server.Implementations.LiveTv PostPaddingSeconds = dto.PostPaddingSeconds, IsPostPaddingRequired = dto.IsPostPaddingRequired, IsPrePaddingRequired = dto.IsPrePaddingRequired, - Days = dto.Days, + Days = dto.Days.ToList(), Priority = dto.Priority, RecordAnyChannel = dto.RecordAnyChannel, RecordAnyTime = dto.RecordAnyTime, diff --git a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs index 3fbbc8390e..2882af007f 100644 --- a/Emby.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/Emby.Server.Implementations/LiveTv/LiveTvManager.cs @@ -985,9 +985,8 @@ namespace Emby.Server.Implementations.LiveTv var queryResult = _libraryManager.QueryItems(internalQuery); - var returnList = (await _dtoService.GetBaseItemDtos(queryResult.Items, options, user) + var returnArray = (await _dtoService.GetBaseItemDtos(queryResult.Items, options, user) .ConfigureAwait(false)); - var returnArray = returnList.ToArray(returnList.Count); var result = new QueryResult<BaseItemDto> { @@ -998,7 +997,7 @@ namespace Emby.Server.Implementations.LiveTv return result; } - public async Task<QueryResult<LiveTvProgram>> GetRecommendedProgramsInternal(RecommendedProgramQuery query, DtoOptions options, CancellationToken cancellationToken) + public async Task<QueryResult<BaseItem>> GetRecommendedProgramsInternal(RecommendedProgramQuery query, DtoOptions options, CancellationToken cancellationToken) { var user = _userManager.GetUserById(query.UserId); @@ -1036,10 +1035,10 @@ namespace Emby.Server.Implementations.LiveTv } } - var programList = _libraryManager.QueryItems(internalQuery).Items.Cast<LiveTvProgram>().ToList(); - var totalCount = programList.Count; + var programList = _libraryManager.QueryItems(internalQuery).Items; + var totalCount = programList.Length; - IOrderedEnumerable<LiveTvProgram> orderedPrograms = programList.OrderBy(i => i.StartDate.Date); + IOrderedEnumerable<LiveTvProgram> orderedPrograms = programList.Cast<LiveTvProgram>().OrderBy(i => i.StartDate.Date); if (query.IsAiring ?? false) { @@ -1047,14 +1046,14 @@ namespace Emby.Server.Implementations.LiveTv .ThenByDescending(i => GetRecommendationScore(i, user.Id, true)); } - IEnumerable<LiveTvProgram> programs = orderedPrograms; + IEnumerable<BaseItem> programs = orderedPrograms; if (query.Limit.HasValue) { programs = programs.Take(query.Limit.Value); } - var result = new QueryResult<LiveTvProgram> + var result = new QueryResult<BaseItem> { Items = programs.ToArray(), TotalRecordCount = totalCount @@ -1071,9 +1070,8 @@ namespace Emby.Server.Implementations.LiveTv var user = _userManager.GetUserById(query.UserId); - var returnList = (await _dtoService.GetBaseItemDtos(internalResult.Items, options, user) + var returnArray = (await _dtoService.GetBaseItemDtos(internalResult.Items, options, user) .ConfigureAwait(false)); - var returnArray = returnList.ToArray(returnList.Count); var result = new QueryResult<BaseItemDto> { @@ -1262,8 +1260,8 @@ namespace Emby.Server.Implementations.LiveTv progress.Report(100 * percent); } - await CleanDatabaseInternal(newChannelIdList, new[] { typeof(LiveTvChannel).Name }, progress, cancellationToken).ConfigureAwait(false); - await CleanDatabaseInternal(newProgramIdList, new[] { typeof(LiveTvProgram).Name }, progress, cancellationToken).ConfigureAwait(false); + await CleanDatabaseInternal(newChannelIdList.ToArray(), new[] { typeof(LiveTvChannel).Name }, progress, cancellationToken).ConfigureAwait(false); + await CleanDatabaseInternal(newProgramIdList.ToArray(), new[] { typeof(LiveTvProgram).Name }, progress, cancellationToken).ConfigureAwait(false); var coreService = _services.OfType<EmbyTV.EmbyTV>().FirstOrDefault(); @@ -1275,8 +1273,11 @@ namespace Emby.Server.Implementations.LiveTv // Load these now which will prefetch metadata var dtoOptions = new DtoOptions(); - dtoOptions.Fields.Remove(ItemFields.SyncInfo); - dtoOptions.Fields.Remove(ItemFields.BasicSyncInfo); + var fields = dtoOptions.Fields.ToList(); + fields.Remove(ItemFields.SyncInfo); + fields.Remove(ItemFields.BasicSyncInfo); + dtoOptions.Fields = fields.ToArray(fields.Count); + await GetRecordings(new RecordingQuery(), dtoOptions, cancellationToken).ConfigureAwait(false); progress.Report(100); @@ -1446,14 +1447,14 @@ namespace Emby.Server.Implementations.LiveTv return new Tuple<List<Guid>, List<Guid>>(channels, programs); } - private async Task CleanDatabaseInternal(List<Guid> currentIdList, string[] validTypes, IProgress<double> progress, CancellationToken cancellationToken) + private async Task CleanDatabaseInternal(Guid[] currentIdList, string[] validTypes, IProgress<double> progress, CancellationToken cancellationToken) { var list = _itemRepo.GetItemIdsList(new InternalItemsQuery { IncludeItemTypes = validTypes, DtoOptions = new DtoOptions(false) - }).ToList(); + }); var numComplete = 0; @@ -1543,7 +1544,7 @@ namespace Emby.Server.Implementations.LiveTv var idList = await Task.WhenAll(recordingTasks).ConfigureAwait(false); - await CleanDatabaseInternal(idList.ToList(), new[] { typeof(LiveTvVideoRecording).Name, typeof(LiveTvAudioRecording).Name }, new SimpleProgress<double>(), cancellationToken).ConfigureAwait(false); + await CleanDatabaseInternal(idList, new[] { typeof(LiveTvVideoRecording).Name, typeof(LiveTvAudioRecording).Name }, new SimpleProgress<double>(), cancellationToken).ConfigureAwait(false); _lastRecordingRefreshTime = DateTime.UtcNow; } @@ -1701,11 +1702,9 @@ namespace Emby.Server.Implementations.LiveTv DtoOptions = options }); - var returnList = (await _dtoService.GetBaseItemDtos(internalResult.Items, options, user) + var returnArray = (await _dtoService.GetBaseItemDtos(internalResult.Items, options, user) .ConfigureAwait(false)); - var returnArray = returnList.ToArray(returnList.Count); - return new QueryResult<BaseItemDto> { Items = returnArray, @@ -1841,7 +1840,7 @@ namespace Emby.Server.Implementations.LiveTv }; } - public async Task AddInfoToProgramDto(List<Tuple<BaseItem, BaseItemDto>> tuples, List<ItemFields> fields, User user = null) + public async Task AddInfoToProgramDto(List<Tuple<BaseItem, BaseItemDto>> tuples, ItemFields[] fields, User user = null) { var programTuples = new List<Tuple<BaseItemDto, string, string, string>>(); var hasChannelImage = fields.Contains(ItemFields.ChannelImage); @@ -1961,7 +1960,7 @@ namespace Emby.Server.Implementations.LiveTv if (dto.MediaStreams == null) { - dto.MediaStreams = dto.MediaSources.SelectMany(i => i.MediaStreams).ToList(); + dto.MediaStreams = dto.MediaSources.SelectMany(i => i.MediaStreams).ToArray(); } if (info.Status == RecordingStatus.InProgress && info.EndDate.HasValue) @@ -1995,9 +1994,8 @@ namespace Emby.Server.Implementations.LiveTv var internalResult = await GetInternalRecordings(query, options, cancellationToken).ConfigureAwait(false); - var returnList = (await _dtoService.GetBaseItemDtos(internalResult.Items, options, user) + var returnArray = (await _dtoService.GetBaseItemDtos(internalResult.Items, options, user) .ConfigureAwait(false)); - var returnArray = returnList.ToArray(returnList.Count); return new QueryResult<BaseItemDto> { @@ -2479,7 +2477,7 @@ namespace Emby.Server.Implementations.LiveTv var defaults = await GetNewTimerDefaultsInternal(cancellationToken, program).ConfigureAwait(false); var info = _tvDtoService.GetSeriesTimerInfoDto(defaults.Item1, defaults.Item2, null); - info.Days = defaults.Item1.Days; + info.Days = defaults.Item1.Days.ToArray(); info.DayPattern = _tvDtoService.GetDayPattern(info.Days); @@ -2656,8 +2654,7 @@ namespace Emby.Server.Implementations.LiveTv var series = recordings .Where(i => i.IsSeries) - .ToLookup(i => i.Name, StringComparer.OrdinalIgnoreCase) - .ToList(); + .ToLookup(i => i.Name, StringComparer.OrdinalIgnoreCase); groups.AddRange(series.OrderByString(i => i.Key).Select(i => new BaseItemDto { @@ -2762,7 +2759,7 @@ namespace Emby.Server.Implementations.LiveTv } } - private async Task<IEnumerable<LiveTvServiceInfo>> GetServiceInfos(CancellationToken cancellationToken) + private async Task<LiveTvServiceInfo[]> GetServiceInfos(CancellationToken cancellationToken) { var tasks = Services.Select(i => GetServiceInfo(i, cancellationToken)); @@ -2806,7 +2803,7 @@ namespace Emby.Server.Implementations.LiveTv return dto; - }).ToList(); + }).ToArray(); } catch (Exception ex) { @@ -2822,25 +2819,24 @@ namespace Emby.Server.Implementations.LiveTv public async Task<LiveTvInfo> GetLiveTvInfo(CancellationToken cancellationToken) { var services = await GetServiceInfos(CancellationToken.None).ConfigureAwait(false); - var servicesList = services.ToList(); var info = new LiveTvInfo { - Services = servicesList.ToList(), - IsEnabled = servicesList.Count > 0 + Services = services, + IsEnabled = services.Length > 0 }; info.EnabledUsers = _userManager.Users .Where(IsLiveTvEnabled) .Select(i => i.Id.ToString("N")) - .ToList(); + .ToArray(); return info; } private bool IsLiveTvEnabled(User user) { - return user.Policy.EnableLiveTvAccess && (Services.Count > 1 || GetConfiguration().TunerHosts.Count > 0); + return user.Policy.EnableLiveTvAccess && (Services.Count > 1 || GetConfiguration().TunerHosts.Length > 0); } public IEnumerable<User> GetEnabledUsers() @@ -2880,10 +2876,13 @@ namespace Emby.Server.Implementations.LiveTv private void RemoveFields(DtoOptions options) { - options.Fields.Remove(ItemFields.CanDelete); - options.Fields.Remove(ItemFields.CanDownload); - options.Fields.Remove(ItemFields.DisplayPreferencesId); - options.Fields.Remove(ItemFields.Etag); + var fields = options.Fields.ToList(); + + fields.Remove(ItemFields.CanDelete); + fields.Remove(ItemFields.CanDownload); + fields.Remove(ItemFields.DisplayPreferencesId); + fields.Remove(ItemFields.Etag); + options.Fields = fields.ToArray(fields.Count); } public async Task<Folder> GetInternalLiveTvFolder(CancellationToken cancellationToken) @@ -2911,12 +2910,14 @@ namespace Emby.Server.Implementations.LiveTv var config = GetConfiguration(); - var index = config.TunerHosts.FindIndex(i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase)); + var list = config.TunerHosts.ToList(); + var index = list.FindIndex(i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase)); if (index == -1 || string.IsNullOrWhiteSpace(info.Id)) { info.Id = Guid.NewGuid().ToString("N"); - config.TunerHosts.Add(info); + list.Add(info); + config.TunerHosts = list.ToArray(list.Count); } else { @@ -2948,12 +2949,14 @@ namespace Emby.Server.Implementations.LiveTv var config = GetConfiguration(); - var index = config.ListingProviders.FindIndex(i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase)); + var list = config.ListingProviders.ToList(); + var index = list.FindIndex(i => string.Equals(i.Id, info.Id, StringComparison.OrdinalIgnoreCase)); if (index == -1 || string.IsNullOrWhiteSpace(info.Id)) { info.Id = Guid.NewGuid().ToString("N"); - config.ListingProviders.Add(info); + list.Add(info); + config.ListingProviders = list.ToArray(list.Count); info.EnableNewProgramIds = true; } else @@ -2972,7 +2975,7 @@ namespace Emby.Server.Implementations.LiveTv { var config = GetConfiguration(); - config.ListingProviders = config.ListingProviders.Where(i => !string.Equals(id, i.Id, StringComparison.OrdinalIgnoreCase)).ToList(); + config.ListingProviders = config.ListingProviders.Where(i => !string.Equals(id, i.Id, StringComparison.OrdinalIgnoreCase)).ToArray(); _config.SaveConfiguration("livetv", config); _taskManager.CancelIfRunningAndQueue<RefreshChannelsScheduledTask>(); @@ -3004,7 +3007,7 @@ namespace Emby.Server.Implementations.LiveTv var providerChannels = await GetChannelsFromListingsProviderData(providerId, CancellationToken.None) .ConfigureAwait(false); - var mappings = listingsProviderInfo.ChannelMappings.ToList(); + var mappings = listingsProviderInfo.ChannelMappings; var tunerChannelMappings = tunerChannels.Select(i => GetTunerChannelMapping(i, mappings, providerChannels)).ToList(); @@ -3014,7 +3017,7 @@ namespace Emby.Server.Implementations.LiveTv return tunerChannelMappings.First(i => string.Equals(i.Id, tunerChannelId, StringComparison.OrdinalIgnoreCase)); } - public TunerChannelMapping GetTunerChannelMapping(ChannelInfo tunerChannel, List<NameValuePair> mappings, List<ChannelInfo> epgChannels) + public TunerChannelMapping GetTunerChannelMapping(ChannelInfo tunerChannel, NameValuePair[] mappings, List<ChannelInfo> epgChannels) { var result = new TunerChannelMapping { @@ -3078,7 +3081,7 @@ namespace Emby.Server.Implementations.LiveTv if (string.Equals(feature, "dvr-l", StringComparison.OrdinalIgnoreCase)) { var config = GetConfiguration(); - if (config.TunerHosts.Count > 0 && + if (config.TunerHosts.Length > 0 && config.ListingProviders.Count(i => (i.EnableAllTuners || i.EnabledTuners.Length > 0) && string.Equals(i.Type, SchedulesDirect.TypeName, StringComparison.OrdinalIgnoreCase)) > 0) { return Task.FromResult(new MBRegistrationRecord diff --git a/Emby.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs b/Emby.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs index 5582d8f35e..cad28c809c 100644 --- a/Emby.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs +++ b/Emby.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs @@ -62,7 +62,7 @@ namespace Emby.Server.Implementations.LiveTv public bool IsHidden { - get { return _liveTvManager.Services.Count == 1 && GetConfiguration().TunerHosts.Count == 0; } + get { return _liveTvManager.Services.Count == 1 && GetConfiguration().TunerHosts.Length == 0; } } public bool IsEnabled diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs index cf50e60921..567f4ce204 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/MulticastStream.cs @@ -24,8 +24,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts public async Task CopyUntilCancelled(Stream source, Action onStarted, CancellationToken cancellationToken) { - byte[] buffer = new byte[BufferSize]; - if (source == null) { throw new ArgumentNullException("source"); @@ -35,6 +33,8 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { cancellationToken.ThrowIfCancellationRequested(); + byte[] buffer = new byte[BufferSize]; + var bytesRead = source.Read(buffer, 0, buffer.Length); if (bytesRead > 0) @@ -47,12 +47,12 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts //} //else { - byte[] copy = new byte[bytesRead]; - Buffer.BlockCopy(buffer, 0, copy, 0, bytesRead); + //byte[] copy = new byte[bytesRead]; + //Buffer.BlockCopy(buffer, 0, copy, 0, bytesRead); foreach (var stream in allStreams) { - stream.Value.Queue(copy, 0, copy.Length); + stream.Value.Queue(buffer, 0, bytesRead); } } diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs index 61bc390b40..f1ec8d5af3 100644 --- a/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs +++ b/Emby.Server.Implementations/LiveTv/TunerHosts/QueueStream.cs @@ -13,7 +13,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts public class QueueStream { private readonly Stream _outputStream; - private readonly ConcurrentQueue<Tuple<byte[], int, int>> _queue = new ConcurrentQueue<Tuple<byte[], int, int>>(); + private readonly BlockingCollection<Tuple<byte[], int, int>> _queue = new BlockingCollection<Tuple<byte[], int, int>>(); public TaskCompletionSource<bool> TaskCompletion { get; private set; } public Action<QueueStream> OnFinished { get; set; } @@ -29,7 +29,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts public void Queue(byte[] bytes, int offset, int count) { - _queue.Enqueue(new Tuple<byte[], int, int>(bytes, offset, count)); + _queue.Add(new Tuple<byte[], int, int>(bytes, offset, count)); } public void Start(CancellationToken cancellationToken) @@ -37,17 +37,6 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts Task.Run(() => StartInternal(cancellationToken)); } - private Tuple<byte[], int, int> Dequeue() - { - Tuple<byte[], int, int> result; - if (_queue.TryDequeue(out result)) - { - return result; - } - - return null; - } - private void OnClosed() { GC.Collect(); @@ -79,7 +68,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts } } - private async Task StartInternal(CancellationToken cancellationToken) + private void StartInternal(CancellationToken cancellationToken) { try { @@ -87,15 +76,10 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts { cancellationToken.ThrowIfCancellationRequested(); - var result = Dequeue(); - if (result != null) + foreach (var result in _queue.GetConsumingEnumerable()) { _outputStream.Write(result.Item1, result.Item2, result.Item3); } - else - { - await Task.Delay(50, cancellationToken).ConfigureAwait(false); - } } } catch (OperationCanceledException) |
