aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs')
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs136
1 files changed, 98 insertions, 38 deletions
diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
index 2bc6cbadfe..a39781d6a3 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
@@ -1,10 +1,8 @@
-using System.Globalization;
-using MediaBrowser.Common;
+using MediaBrowser.Common;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Progress;
using MediaBrowser.Common.ScheduledTasks;
-using MediaBrowser.Controller.Channels;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Dto;
@@ -15,7 +13,6 @@ using MediaBrowser.Controller.Localization;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Sorting;
-using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.LiveTv;
@@ -88,8 +85,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
get { return _services; }
}
- public ILiveTvService ActiveService { get; private set; }
-
private LiveTvOptions GetConfiguration()
{
return _config.GetConfiguration<LiveTvOptions>("livetv");
@@ -103,8 +98,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
{
_services.AddRange(services);
- ActiveService = _services.FirstOrDefault();
-
foreach (var service in _services)
{
service.DataSourceChanged += service_DataSourceChanged;
@@ -316,6 +309,22 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return await GetLiveStream(id, true, cancellationToken).ConfigureAwait(false);
}
+ public async Task<IEnumerable<MediaSourceInfo>> GetRecordingMediaSources(string id, CancellationToken cancellationToken)
+ {
+ var item = await GetInternalRecording(id, cancellationToken).ConfigureAwait(false);
+ var service = GetService(item);
+
+ return await service.GetRecordingStreamMediaSources(id, cancellationToken).ConfigureAwait(false);
+ }
+
+ public async Task<IEnumerable<MediaSourceInfo>> GetChannelMediaSources(string id, CancellationToken cancellationToken)
+ {
+ var item = GetInternalChannel(id);
+ var service = GetService(item);
+
+ return await service.GetChannelStreamMediaSources(id, cancellationToken).ConfigureAwait(false);
+ }
+
private ILiveTvService GetService(ILiveTvItem item)
{
return GetService(item.ServiceName);
@@ -333,30 +342,48 @@ namespace MediaBrowser.Server.Implementations.LiveTv
try
{
MediaSourceInfo info;
+ bool isVideo;
if (isChannel)
{
var channel = GetInternalChannel(id);
+ isVideo = channel.ChannelType == ChannelType.TV;
var service = GetService(channel);
_logger.Info("Opening channel stream from {0}, external channel Id: {1}", service.Name, channel.ExternalId);
info = await service.GetChannelStream(channel.ExternalId, null, cancellationToken).ConfigureAwait(false);
+ info.RequiresClosing = true;
+
+ if (info.RequiresClosing)
+ {
+ var idPrefix = service.GetType().FullName.GetMD5().ToString("N") + "_";
+
+ info.LiveStreamId = idPrefix + info.Id;
+ }
}
else
{
var recording = await GetInternalRecording(id, cancellationToken).ConfigureAwait(false);
+ isVideo = !string.Equals(recording.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase);
var service = GetService(recording);
_logger.Info("Opening recording stream from {0}, external recording Id: {1}", service.Name, recording.RecordingInfo.Id);
info = await service.GetRecordingStream(recording.RecordingInfo.Id, null, cancellationToken).ConfigureAwait(false);
+ info.RequiresClosing = true;
+
+ if (info.RequiresClosing)
+ {
+ var idPrefix = service.GetType().FullName.GetMD5().ToString("N") + "_";
+
+ info.LiveStreamId = idPrefix + info.Id;
+ }
}
_logger.Info("Live stream info: {0}", _jsonSerializer.SerializeToString(info));
- Sanitize(info);
+ Normalize(info, isVideo);
var data = new LiveStreamData
{
Info = info,
- ConsumerCount = 1,
IsChannel = isChannel,
ItemId = id
};
@@ -377,25 +404,43 @@ namespace MediaBrowser.Server.Implementations.LiveTv
}
}
- private void Sanitize(MediaSourceInfo mediaSource)
+ private void Normalize(MediaSourceInfo mediaSource, bool isVideo)
{
if (mediaSource.MediaStreams.Count == 0)
{
- mediaSource.MediaStreams.AddRange(new List<MediaStream>
+ if (isVideo)
{
- new MediaStream
+ mediaSource.MediaStreams.AddRange(new List<MediaStream>
{
- Type = MediaStreamType.Video,
- // Set the index to -1 because we don't know the exact index of the video stream within the container
- Index = -1
- },
- new MediaStream
+ new MediaStream
+ {
+ Type = MediaStreamType.Video,
+ // Set the index to -1 because we don't know the exact index of the video stream within the container
+ Index = -1,
+
+ // Set to true if unknown to enable deinterlacing
+ IsInterlaced = true
+ },
+ new MediaStream
+ {
+ Type = MediaStreamType.Audio,
+ // Set the index to -1 because we don't know the exact index of the audio stream within the container
+ Index = -1
+ }
+ });
+ }
+ else
+ {
+ mediaSource.MediaStreams.AddRange(new List<MediaStream>
{
- Type = MediaStreamType.Audio,
- // Set the index to -1 because we don't know the exact index of the audio stream within the container
- Index = -1
- }
- });
+ new MediaStream
+ {
+ Type = MediaStreamType.Audio,
+ // Set the index to -1 because we don't know the exact index of the audio stream within the container
+ Index = -1
+ }
+ });
+ }
}
// Clean some bad data coming from providers
@@ -544,13 +589,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv
item.Name = info.Name;
item.OfficialRating = info.OfficialRating;
item.Overview = info.Overview;
- item.PremiereDate = info.OriginalAirDate;
+ item.OriginalAirDate = info.OriginalAirDate;
item.ProviderImagePath = info.ImagePath;
item.ProviderImageUrl = info.ImageUrl;
item.RunTimeTicks = (info.EndDate - info.StartDate).Ticks;
item.StartDate = info.StartDate;
- item.ProductionYear = info.ProductionYear;
+ item.ProductionYear = info.ProductionYear;
+ item.PremiereDate = item.PremiereDate ?? info.OriginalAirDate;
+
await item.UpdateToRepository(ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
return item;
@@ -1742,7 +1789,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv
class LiveStreamData
{
internal MediaSourceInfo Info;
- internal int ConsumerCount;
internal string ItemId;
internal bool IsChannel;
}
@@ -1753,19 +1799,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv
try
{
- var service = ActiveService;
+ var parts = id.Split(new[] { '_' }, 2);
- LiveStreamData data;
- if (_openStreams.TryGetValue(id, out data))
- {
- if (data.ConsumerCount > 1)
- {
- data.ConsumerCount--;
- _logger.Info("Decrementing live stream client count.");
- return;
- }
+ var service = _services.FirstOrDefault(i => string.Equals(i.GetType().FullName.GetMD5().ToString("N"), parts[0], StringComparison.OrdinalIgnoreCase));
+ if (service == null)
+ {
+ throw new ArgumentException("Service not found.");
}
+
+ id = parts[1];
+
+ LiveStreamData data;
_openStreams.TryRemove(id, out data);
_logger.Info("Closing live stream from {0}, stream Id: {1}", service.Name, id);
@@ -1846,6 +1891,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv
Name = service.Name
};
+ var tunerIdPrefix = service.GetType().FullName.GetMD5().ToString("N") + "_";
+
try
{
var statusInfo = await service.GetStatusInfoAsync(cancellationToken).ConfigureAwait(false);
@@ -1867,7 +1914,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv
channelName = channel == null ? null : channel.Name;
}
- return _tvDtoService.GetTunerInfoDto(service.Name, i, channelName);
+ var dto = _tvDtoService.GetTunerInfoDto(service.Name, i, channelName);
+
+ dto.Id = tunerIdPrefix + dto.Id;
+
+ return dto;
}).ToList();
}
@@ -1920,7 +1971,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv
/// <returns>Task.</returns>
public Task ResetTuner(string id, CancellationToken cancellationToken)
{
- return ActiveService.ResetTuner(id, cancellationToken);
+ var parts = id.Split(new[] { '_' }, 2);
+
+ var service = _services.FirstOrDefault(i => string.Equals(i.GetType().FullName.GetMD5().ToString("N"), parts[0], StringComparison.OrdinalIgnoreCase));
+
+ if (service == null)
+ {
+ throw new ArgumentException("Service not found.");
+ }
+
+ return service.ResetTuner(parts[1], cancellationToken);
}
public async Task<BaseItemDto> GetLiveTvFolder(string userId, CancellationToken cancellationToken)