mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-05 21:33:02 +02:00
Remove unnecessary allocations in TunerHostManager
This commit is contained in:
parent
9c2c066e6f
commit
c23a038ba8
|
@ -1144,8 +1144,8 @@ public class LiveTvController : BaseJellyfinApiController
|
||||||
[HttpGet("Tuners/Discover")]
|
[HttpGet("Tuners/Discover")]
|
||||||
[Authorize(Policy = Policies.LiveTvManagement)]
|
[Authorize(Policy = Policies.LiveTvManagement)]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
public async Task<ActionResult<IEnumerable<TunerHostInfo>>> DiscoverTuners([FromQuery] bool newDevicesOnly = false)
|
public IAsyncEnumerable<TunerHostInfo> DiscoverTuners([FromQuery] bool newDevicesOnly = false)
|
||||||
=> await _tunerHostManager.DiscoverTuners(newDevicesOnly, CancellationToken.None).ConfigureAwait(false);
|
=> _tunerHostManager.DiscoverTuners(newDevicesOnly);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a live tv recording stream.
|
/// Gets a live tv recording stream.
|
||||||
|
|
|
@ -34,9 +34,8 @@ public interface ITunerHostManager
|
||||||
/// Discovers the available tuners.
|
/// Discovers the available tuners.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="newDevicesOnly">A value indicating whether to only return new devices.</param>
|
/// <param name="newDevicesOnly">A value indicating whether to only return new devices.</param>
|
||||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
|
|
||||||
/// <returns>The <see cref="TunerHostInfo"/>s.</returns>
|
/// <returns>The <see cref="TunerHostInfo"/>s.</returns>
|
||||||
Task<List<TunerHostInfo>> DiscoverTuners(bool newDevicesOnly, CancellationToken cancellationToken);
|
IAsyncEnumerable<TunerHostInfo> DiscoverTuners(bool newDevicesOnly);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Scans for tuner devices that have changed URLs.
|
/// Scans for tuner devices that have changed URLs.
|
||||||
|
|
|
@ -5,7 +5,6 @@ using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Extensions;
|
|
||||||
using Jellyfin.LiveTv.Configuration;
|
using Jellyfin.LiveTv.Configuration;
|
||||||
using MediaBrowser.Common.Configuration;
|
using MediaBrowser.Common.Configuration;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
|
@ -101,10 +100,8 @@ public class TunerHostManager : ITunerHostManager
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public async Task<List<TunerHostInfo>> DiscoverTuners(bool newDevicesOnly, CancellationToken cancellationToken)
|
public async IAsyncEnumerable<TunerHostInfo> DiscoverTuners(bool newDevicesOnly)
|
||||||
{
|
{
|
||||||
var list = new List<TunerHostInfo>();
|
|
||||||
|
|
||||||
var configuredDeviceIds = _config.GetLiveTvConfiguration().TunerHosts
|
var configuredDeviceIds = _config.GetLiveTvConfiguration().TunerHosts
|
||||||
.Where(i => !string.IsNullOrWhiteSpace(i.DeviceId))
|
.Where(i => !string.IsNullOrWhiteSpace(i.DeviceId))
|
||||||
.Select(i => i.DeviceId)
|
.Select(i => i.DeviceId)
|
||||||
|
@ -112,19 +109,15 @@ public class TunerHostManager : ITunerHostManager
|
||||||
|
|
||||||
foreach (var host in _tunerHosts)
|
foreach (var host in _tunerHosts)
|
||||||
{
|
{
|
||||||
var discoveredDevices = await DiscoverDevices(host, TunerDiscoveryDurationMs, cancellationToken).ConfigureAwait(false);
|
var discoveredDevices = await DiscoverDevices(host, TunerDiscoveryDurationMs, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
foreach (var tuner in discoveredDevices)
|
||||||
if (newDevicesOnly)
|
|
||||||
{
|
{
|
||||||
discoveredDevices = discoveredDevices
|
if (!newDevicesOnly || !configuredDeviceIds.Contains(tuner.DeviceId, StringComparer.OrdinalIgnoreCase))
|
||||||
.Where(d => !configuredDeviceIds.Contains(d.DeviceId, StringComparison.OrdinalIgnoreCase))
|
{
|
||||||
.ToList();
|
yield return tuner;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list.AddRange(discoveredDevices);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -158,7 +151,7 @@ public class TunerHostManager : ITunerHostManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<List<TunerHostInfo>> DiscoverDevices(ITunerHost host, int discoveryDurationMs, CancellationToken cancellationToken)
|
private async Task<IList<TunerHostInfo>> DiscoverDevices(ITunerHost host, int discoveryDurationMs, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -175,7 +168,7 @@ public class TunerHostManager : ITunerHostManager
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Error discovering tuner devices");
|
_logger.LogError(ex, "Error discovering tuner devices");
|
||||||
|
|
||||||
return new List<TunerHostInfo>();
|
return Array.Empty<TunerHostInfo>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue