Skip to content

Commit

Permalink
Merge pull request #3287 from MediaBrowser/dev
Browse files Browse the repository at this point in the history
update live stream management
  • Loading branch information
LukePulverenti authored May 24, 2018
2 parents e770498 + 256dd51 commit f75e05f
Show file tree
Hide file tree
Showing 24 changed files with 273 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ public Task<IEnumerable<MediaSourceInfo>> GetMediaSources(BaseItem item, Cancell
return Task.FromResult<IEnumerable<MediaSourceInfo>>(new List<MediaSourceInfo>());
}

public Task<Tuple<MediaSourceInfo, IDirectStreamProvider, bool>> OpenMediaSource(string openToken, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

public Task CloseMediaSource(string liveStreamId)
public Task<ILiveStream> OpenMediaSource(string openToken, List<ILiveStream> currentLiveStreams, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@
<Compile Include="IO\ThrottledStream.cs" />
<Compile Include="Library\CoreResolutionIgnoreRule.cs" />
<Compile Include="Library\DefaultAuthenticationProvider.cs" />
<Compile Include="Library\ExclusiveLiveStream.cs" />
<Compile Include="Library\LibraryManager.cs" />
<Compile Include="Library\LiveStreamHelper.cs" />
<Compile Include="Library\LocalTrailerPostScanTask.cs" />
<Compile Include="Library\MediaSourceManager.cs" />
<Compile Include="Library\MediaStreamSelector.cs" />
Expand Down Expand Up @@ -387,7 +389,6 @@
<Compile Include="LiveTv\EmbyTV\SeriesTimerManager.cs" />
<Compile Include="LiveTv\EmbyTV\TimerManager.cs" />
<Compile Include="LiveTv\Listings\SchedulesDirect.cs" />
<Compile Include="LiveTv\LiveStreamHelper.cs" />
<Compile Include="LiveTv\LiveTvConfigurationFactory.cs" />
<Compile Include="LiveTv\LiveTvDtoService.cs" />
<Compile Include="LiveTv\LiveTvManager.cs" />
Expand Down
52 changes: 52 additions & 0 deletions Emby.Server.Implementations/Library/ExclusiveLiveStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.System;
using MediaBrowser.Model.LiveTv;
using System.Linq;
using MediaBrowser.Controller.Library;

namespace Emby.Server.Implementations.Library
{
public class ExclusiveLiveStream : ILiveStream
{
public int ConsumerCount { get; set; }
public string OriginalStreamId { get; set; }

public string TunerHostId => null;

public bool EnableStreamSharing { get; set; }
public MediaSourceInfo MediaSource { get; set; }

public string UniqueId => throw new NotImplementedException();

private ILiveTvService _liveTvService;
private string _openedId;

public ExclusiveLiveStream(MediaSourceInfo mediaSource, ILiveTvService liveTvService, string openedId)
{
MediaSource = mediaSource;
EnableStreamSharing = false;
_liveTvService = liveTvService;
_openedId = openedId;
}

public Task Close()
{
return _liveTvService.CloseLiveStream(_openedId, CancellationToken.None);
}

public Task Open(CancellationToken openCancellationToken)
{
return Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using System.IO;
using MediaBrowser.Common.Extensions;

namespace Emby.Server.Implementations.LiveTv
namespace Emby.Server.Implementations.Library
{
public class LiveStreamHelper
{
Expand All @@ -40,7 +40,7 @@ public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudi
var now = DateTime.UtcNow;

MediaInfo mediaInfo = null;
var cacheFilePath = string.IsNullOrEmpty(cacheKey) ? null : Path.Combine(_appPaths.CachePath, "livetvmediainfo", cacheKey.GetMD5().ToString("N") + ".json");
var cacheFilePath = string.IsNullOrEmpty(cacheKey) ? null : Path.Combine(_appPaths.CachePath, "mediainfo", cacheKey.GetMD5().ToString("N") + ".json");

if (!string.IsNullOrEmpty(cacheKey))
{
Expand All @@ -50,7 +50,7 @@ public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudi

//_logger.Debug("Found cached media info");
}
catch (Exception ex)
catch
{
}
}
Expand All @@ -61,7 +61,11 @@ public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudi
{
var delayMs = mediaSource.AnalyzeDurationMs ?? 0;
delayMs = Math.Max(3000, delayMs);
await Task.Delay(delayMs, cancellationToken).ConfigureAwait(false);
if (delayMs > 0)
{
_logger.Info("Waiting {0}ms before probing the live stream", delayMs);
await Task.Delay(delayMs, cancellationToken).ConfigureAwait(false);
}
}

mediaSource.AnalyzeDurationMs = 3000;
Expand Down
Loading

0 comments on commit f75e05f

Please sign in to comment.