rework live stream creation
This commit is contained in:
parent
2e0e1697a8
commit
539fecd08b
|
@ -6,11 +6,6 @@ namespace MediaBrowser.Controller.IO
|
|||
{
|
||||
public static class StreamHelper
|
||||
{
|
||||
public static void CopyTo(Stream source, Stream destination, int bufferSize, CancellationToken cancellationToken)
|
||||
{
|
||||
CopyTo(source, destination, bufferSize, null, cancellationToken);
|
||||
}
|
||||
|
||||
public static void CopyTo(Stream source, Stream destination, int bufferSize, Action onStarted, CancellationToken cancellationToken)
|
||||
{
|
||||
byte[] buffer = new byte[bufferSize];
|
||||
|
|
|
@ -383,7 +383,7 @@ namespace MediaBrowser.Controller.LiveTv
|
|||
event EventHandler<GenericEventArgs<TimerEventInfo>> SeriesTimerCreated;
|
||||
|
||||
string GetEmbyTvActiveRecordingPath(string id);
|
||||
Task<LiveStream> GetEmbyTvLiveStream(string id);
|
||||
Task<ILiveStream> GetEmbyTvLiveStream(string id);
|
||||
|
||||
ActiveRecordingInfo GetActiveRecordingInfo(string path);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ namespace MediaBrowser.Controller.LiveTv
|
|||
/// <param name="streamId">The stream identifier.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task<MediaSourceInfo>.</returns>
|
||||
Task<LiveStream> GetChannelStream(string channelId, string streamId, CancellationToken cancellationToken);
|
||||
Task<ILiveStream> GetChannelStream(string channelId, string streamId, CancellationToken cancellationToken);
|
||||
/// <summary>
|
||||
/// Gets the channel stream media sources.
|
||||
/// </summary>
|
||||
|
@ -56,4 +56,17 @@ namespace MediaBrowser.Controller.LiveTv
|
|||
/// <returns>Task.</returns>
|
||||
Task Validate(TunerHostInfo info);
|
||||
}
|
||||
|
||||
public interface ILiveStream
|
||||
{
|
||||
Task Open(CancellationToken cancellationToken);
|
||||
Task Close();
|
||||
int ConsumerCount { get; }
|
||||
string OriginalStreamId { get; set; }
|
||||
bool EnableStreamSharing { get; set; }
|
||||
ITunerHost TunerHost { get; set; }
|
||||
MediaSourceInfo OpenedMediaSource { get; set; }
|
||||
string UniqueId { get; }
|
||||
List<string> SharedStreamIds { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Model.System;
|
||||
|
||||
namespace MediaBrowser.Controller.LiveTv
|
||||
{
|
||||
public class LiveStream
|
||||
{
|
||||
public MediaSourceInfo OriginalMediaSource { get; set; }
|
||||
public MediaSourceInfo OpenedMediaSource { get; set; }
|
||||
public int ConsumerCount
|
||||
{
|
||||
get { return SharedStreamIds.Count; }
|
||||
}
|
||||
public ITunerHost TunerHost { get; set; }
|
||||
public string OriginalStreamId { get; set; }
|
||||
public bool EnableStreamSharing { get; set; }
|
||||
public string UniqueId = Guid.NewGuid().ToString("N");
|
||||
|
||||
public List<string> SharedStreamIds = new List<string>();
|
||||
protected readonly IEnvironmentInfo Environment;
|
||||
protected readonly IFileSystem FileSystem;
|
||||
const int StreamCopyToBufferSize = 81920;
|
||||
|
||||
public LiveStream(MediaSourceInfo mediaSource, IEnvironmentInfo environment, IFileSystem fileSystem)
|
||||
{
|
||||
OriginalMediaSource = mediaSource;
|
||||
Environment = environment;
|
||||
FileSystem = fileSystem;
|
||||
OpenedMediaSource = mediaSource;
|
||||
EnableStreamSharing = true;
|
||||
}
|
||||
|
||||
public Task Open(CancellationToken cancellationToken)
|
||||
{
|
||||
return OpenInternal(cancellationToken);
|
||||
}
|
||||
|
||||
protected virtual Task OpenInternal(CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
public virtual Task Close()
|
||||
{
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
protected Stream GetInputStream(string path, bool allowAsyncFileRead)
|
||||
{
|
||||
var fileOpenOptions = FileOpenOptions.SequentialScan;
|
||||
|
||||
if (allowAsyncFileRead)
|
||||
{
|
||||
fileOpenOptions |= FileOpenOptions.Asynchronous;
|
||||
}
|
||||
|
||||
return FileSystem.GetFileStream(path, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.ReadWrite, fileOpenOptions);
|
||||
}
|
||||
|
||||
protected async Task DeleteTempFile(string path, int retryCount = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileSystem.DeleteFile(path);
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (retryCount > 20)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await Task.Delay(500).ConfigureAwait(false);
|
||||
await DeleteTempFile(path, retryCount + 1).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -145,7 +145,6 @@
|
|||
<Compile Include="Library\UserDataSaveEventArgs.cs" />
|
||||
<Compile Include="LiveTv\IListingsProvider.cs" />
|
||||
<Compile Include="LiveTv\ITunerHost.cs" />
|
||||
<Compile Include="LiveTv\LiveStream.cs" />
|
||||
<Compile Include="LiveTv\RecordingGroup.cs" />
|
||||
<Compile Include="LiveTv\RecordingStatusChangedEventArgs.cs" />
|
||||
<Compile Include="LiveTv\ILiveTvRecording.cs" />
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace MediaBrowser.Server.Mono
|
|||
get
|
||||
{
|
||||
// A restart script must be provided
|
||||
return false;
|
||||
return StartupOptions.ContainsOption("-restartpath") && StartupOptions.ContainsOption("-ffmpeg");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@ using System.Reflection;
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Drawing;
|
||||
using Emby.Server.Core.Cryptography;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.EnvironmentInfo;
|
||||
using Emby.Server.Implementations.IO;
|
||||
|
|
|
@ -16,9 +16,7 @@ using System.Text;
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Emby.Server.Core.Cryptography;
|
||||
using Emby.Drawing;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.Browser;
|
||||
using Emby.Server.Implementations.EnvironmentInfo;
|
||||
|
|
|
@ -6,7 +6,6 @@ using System.Reflection;
|
|||
using System.Runtime.InteropServices.ComTypes;
|
||||
using Emby.Server.CinemaMode;
|
||||
using Emby.Server.Connect;
|
||||
using Emby.Server.Core;
|
||||
using Emby.Server.Implementations;
|
||||
using Emby.Server.Implementations.EntryPoints;
|
||||
using Emby.Server.Implementations.FFMpeg;
|
||||
|
|
Loading…
Reference in New Issue
Block a user