Skip to content

Commit f75e05f

Browse files
Merge pull request #3287 from MediaBrowser/dev
update live stream management
2 parents e770498 + 256dd51 commit f75e05f

24 files changed

+273
-327
lines changed

Emby.Server.Implementations/Channels/ChannelDynamicMediaSourceProvider.cs

+1-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ public Task<IEnumerable<MediaSourceInfo>> GetMediaSources(BaseItem item, Cancell
2828
return Task.FromResult<IEnumerable<MediaSourceInfo>>(new List<MediaSourceInfo>());
2929
}
3030

31-
public Task<Tuple<MediaSourceInfo, IDirectStreamProvider, bool>> OpenMediaSource(string openToken, CancellationToken cancellationToken)
32-
{
33-
throw new NotImplementedException();
34-
}
35-
36-
public Task CloseMediaSource(string liveStreamId)
31+
public Task<ILiveStream> OpenMediaSource(string openToken, List<ILiveStream> currentLiveStreams, CancellationToken cancellationToken)
3732
{
3833
throw new NotImplementedException();
3934
}

Emby.Server.Implementations/Emby.Server.Implementations.csproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@
338338
<Compile Include="IO\ThrottledStream.cs" />
339339
<Compile Include="Library\CoreResolutionIgnoreRule.cs" />
340340
<Compile Include="Library\DefaultAuthenticationProvider.cs" />
341+
<Compile Include="Library\ExclusiveLiveStream.cs" />
341342
<Compile Include="Library\LibraryManager.cs" />
343+
<Compile Include="Library\LiveStreamHelper.cs" />
342344
<Compile Include="Library\LocalTrailerPostScanTask.cs" />
343345
<Compile Include="Library\MediaSourceManager.cs" />
344346
<Compile Include="Library\MediaStreamSelector.cs" />
@@ -387,7 +389,6 @@
387389
<Compile Include="LiveTv\EmbyTV\SeriesTimerManager.cs" />
388390
<Compile Include="LiveTv\EmbyTV\TimerManager.cs" />
389391
<Compile Include="LiveTv\Listings\SchedulesDirect.cs" />
390-
<Compile Include="LiveTv\LiveStreamHelper.cs" />
391392
<Compile Include="LiveTv\LiveTvConfigurationFactory.cs" />
392393
<Compile Include="LiveTv\LiveTvDtoService.cs" />
393394
<Compile Include="LiveTv\LiveTvManager.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using MediaBrowser.Controller;
7+
using MediaBrowser.Controller.IO;
8+
using MediaBrowser.Controller.LiveTv;
9+
using MediaBrowser.Model.Dto;
10+
using MediaBrowser.Model.IO;
11+
using MediaBrowser.Model.Logging;
12+
using MediaBrowser.Model.System;
13+
using MediaBrowser.Model.LiveTv;
14+
using System.Linq;
15+
using MediaBrowser.Controller.Library;
16+
17+
namespace Emby.Server.Implementations.Library
18+
{
19+
public class ExclusiveLiveStream : ILiveStream
20+
{
21+
public int ConsumerCount { get; set; }
22+
public string OriginalStreamId { get; set; }
23+
24+
public string TunerHostId => null;
25+
26+
public bool EnableStreamSharing { get; set; }
27+
public MediaSourceInfo MediaSource { get; set; }
28+
29+
public string UniqueId => throw new NotImplementedException();
30+
31+
private ILiveTvService _liveTvService;
32+
private string _openedId;
33+
34+
public ExclusiveLiveStream(MediaSourceInfo mediaSource, ILiveTvService liveTvService, string openedId)
35+
{
36+
MediaSource = mediaSource;
37+
EnableStreamSharing = false;
38+
_liveTvService = liveTvService;
39+
_openedId = openedId;
40+
}
41+
42+
public Task Close()
43+
{
44+
return _liveTvService.CloseLiveStream(_openedId, CancellationToken.None);
45+
}
46+
47+
public Task Open(CancellationToken openCancellationToken)
48+
{
49+
return Task.CompletedTask;
50+
}
51+
}
52+
}

Emby.Server.Implementations/LiveTv/LiveStreamHelper.cs Emby.Server.Implementations/Library/LiveStreamHelper.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
using System.IO;
1616
using MediaBrowser.Common.Extensions;
1717

18-
namespace Emby.Server.Implementations.LiveTv
18+
namespace Emby.Server.Implementations.Library
1919
{
2020
public class LiveStreamHelper
2121
{
@@ -40,7 +40,7 @@ public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudi
4040
var now = DateTime.UtcNow;
4141

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

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

5151
//_logger.Debug("Found cached media info");
5252
}
53-
catch (Exception ex)
53+
catch
5454
{
5555
}
5656
}
@@ -61,7 +61,11 @@ public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudi
6161
{
6262
var delayMs = mediaSource.AnalyzeDurationMs ?? 0;
6363
delayMs = Math.Max(3000, delayMs);
64-
await Task.Delay(delayMs, cancellationToken).ConfigureAwait(false);
64+
if (delayMs > 0)
65+
{
66+
_logger.Info("Waiting {0}ms before probing the live stream", delayMs);
67+
await Task.Delay(delayMs, cancellationToken).ConfigureAwait(false);
68+
}
6569
}
6670

6771
mediaSource.AnalyzeDurationMs = 3000;

0 commit comments

Comments
 (0)