mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-08 03:06:20 +00:00
move media encoder to server project
This commit is contained in:
@@ -368,7 +368,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
return null;
|
||||
}
|
||||
|
||||
private const string InternalVersionNumber = "2";
|
||||
private const string InternalVersionNumber = "3";
|
||||
|
||||
public Guid GetInternalChannelId(string serviceName, string externalId)
|
||||
{
|
||||
|
||||
@@ -6,12 +6,14 @@ using MediaBrowser.Controller.Dto;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.LiveTv;
|
||||
using MediaBrowser.Controller.MediaInfo;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.LiveTv;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -23,7 +25,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
/// <summary>
|
||||
/// Class LiveTvManager
|
||||
/// </summary>
|
||||
public class LiveTvManager : ILiveTvManager
|
||||
public class LiveTvManager : ILiveTvManager, IDisposable
|
||||
{
|
||||
private readonly IServerApplicationPaths _appPaths;
|
||||
private readonly IFileSystem _fileSystem;
|
||||
@@ -31,15 +33,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
private readonly IItemRepository _itemRepo;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IMediaEncoder _mediaEncoder;
|
||||
|
||||
private readonly LiveTvDtoService _tvDtoService;
|
||||
|
||||
private readonly List<ILiveTvService> _services = new List<ILiveTvService>();
|
||||
|
||||
private readonly ConcurrentDictionary<string, LiveStreamInfo> _openStreams =
|
||||
new ConcurrentDictionary<string, LiveStreamInfo>();
|
||||
|
||||
private List<Guid> _channelIdList = new List<Guid>();
|
||||
private Dictionary<Guid, LiveTvProgram> _programs = new Dictionary<Guid, LiveTvProgram>();
|
||||
|
||||
public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager)
|
||||
public LiveTvManager(IServerApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, IMediaEncoder mediaEncoder)
|
||||
{
|
||||
_appPaths = appPaths;
|
||||
_fileSystem = fileSystem;
|
||||
@@ -47,6 +53,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
_itemRepo = itemRepo;
|
||||
_userManager = userManager;
|
||||
_libraryManager = libraryManager;
|
||||
_mediaEncoder = mediaEncoder;
|
||||
|
||||
_tvDtoService = new LiveTvDtoService(dtoService, userDataManager, imageProcessor, logger, _itemRepo);
|
||||
}
|
||||
@@ -180,7 +187,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
|
||||
var recording = recordings.First(i => _tvDtoService.GetInternalRecordingId(service.Name, i.Id) == new Guid(id));
|
||||
|
||||
return await service.GetRecordingStream(recording.Id, cancellationToken).ConfigureAwait(false);
|
||||
var result = await service.GetRecordingStream(recording.Id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (!string.IsNullOrEmpty(result.Id))
|
||||
{
|
||||
_openStreams.AddOrUpdate(result.Id, result, (key, info) => result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<LiveStreamInfo> GetChannelStream(string id, CancellationToken cancellationToken)
|
||||
@@ -189,12 +203,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
|
||||
var channel = GetInternalChannel(id);
|
||||
|
||||
return await service.GetChannelStream(channel.ChannelInfo.Id, cancellationToken).ConfigureAwait(false);
|
||||
var result = await service.GetChannelStream(channel.ChannelInfo.Id, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
if (!string.IsNullOrEmpty(result.Id))
|
||||
{
|
||||
_openStreams.AddOrUpdate(result.Id, result, (key, info) => result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<LiveTvChannel> GetChannel(ChannelInfo channelInfo, string serviceName, CancellationToken cancellationToken)
|
||||
{
|
||||
var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(serviceName), _fileSystem.GetValidFilename(channelInfo.Name));
|
||||
var path = Path.Combine(_appPaths.ItemsByNamePath, "channels", _fileSystem.GetValidFilename(channelInfo.Name));
|
||||
|
||||
var fileInfo = new DirectoryInfo(path);
|
||||
|
||||
@@ -1047,5 +1068,36 @@ namespace MediaBrowser.Server.Implementations.LiveTv
|
||||
EndDate = endDate
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
private readonly object _disposeLock = new object();
|
||||
/// <summary>
|
||||
/// Releases unmanaged and - optionally - managed resources.
|
||||
/// </summary>
|
||||
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
||||
protected virtual void Dispose(bool dispose)
|
||||
{
|
||||
if (dispose)
|
||||
{
|
||||
lock (_disposeLock)
|
||||
{
|
||||
foreach (var stream in _openStreams.Values.ToList())
|
||||
{
|
||||
var task = CloseLiveStream(stream.Id, CancellationToken.None);
|
||||
|
||||
Task.WaitAll(task);
|
||||
}
|
||||
|
||||
_openStreams.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Common.MediaInfo;
|
||||
using MediaBrowser.Controller.MediaInfo;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
@@ -104,10 +104,10 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
public Task<MediaInfoResult> GetMediaInfo(string[] inputFiles, InputType type,
|
||||
public Task<InternalMediaInfoResult> GetMediaInfo(string[] inputFiles, InputType type,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
return GetMediaInfoInternal(GetInputArgument(inputFiles, type), type != InputType.AudioFile,
|
||||
return GetMediaInfoInternal(GetInputArgument(inputFiles, type), type != InputType.File,
|
||||
GetProbeSizeArgument(type), cancellationToken);
|
||||
}
|
||||
|
||||
@@ -125,8 +125,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
|
||||
switch (type)
|
||||
{
|
||||
case InputType.Dvd:
|
||||
case InputType.VideoFile:
|
||||
case InputType.AudioFile:
|
||||
case InputType.File:
|
||||
inputPath = GetConcatInputArgument(inputFiles);
|
||||
break;
|
||||
case InputType.Bluray:
|
||||
@@ -173,7 +172,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task{MediaInfoResult}.</returns>
|
||||
/// <exception cref="System.ApplicationException"></exception>
|
||||
private async Task<MediaInfoResult> GetMediaInfoInternal(string inputPath, bool extractChapters,
|
||||
private async Task<InternalMediaInfoResult> GetMediaInfoInternal(string inputPath, bool extractChapters,
|
||||
string probeSizeArgument,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
@@ -206,7 +205,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
|
||||
|
||||
await _ffProbeResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
MediaInfoResult result;
|
||||
InternalMediaInfoResult result;
|
||||
string standardError = null;
|
||||
|
||||
try
|
||||
@@ -236,7 +235,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
|
||||
process.BeginErrorReadLine();
|
||||
}
|
||||
|
||||
result = _jsonSerializer.DeserializeFromStream<MediaInfoResult>(process.StandardOutput.BaseStream);
|
||||
result = _jsonSerializer.DeserializeFromStream<InternalMediaInfoResult>(process.StandardOutput.BaseStream);
|
||||
|
||||
if (extractChapters)
|
||||
{
|
||||
@@ -307,7 +306,7 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
|
||||
/// </summary>
|
||||
/// <param name="result">The result.</param>
|
||||
/// <param name="standardError">The standard error.</param>
|
||||
private void AddChapters(MediaInfoResult result, string standardError)
|
||||
private void AddChapters(InternalMediaInfoResult result, string standardError)
|
||||
{
|
||||
var lines = standardError.Split('\n').Select(l => l.TrimStart());
|
||||
|
||||
@@ -797,19 +796,20 @@ namespace MediaBrowser.Server.Implementations.MediaEncoder
|
||||
/// </summary>
|
||||
/// <param name="inputFiles">The input files.</param>
|
||||
/// <param name="type">The type.</param>
|
||||
/// <param name="isAudio">if set to <c>true</c> [is audio].</param>
|
||||
/// <param name="threedFormat">The threed format.</param>
|
||||
/// <param name="offset">The offset.</param>
|
||||
/// <param name="outputPath">The output path.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentException">Must use inputPath list overload</exception>
|
||||
public async Task ExtractImage(string[] inputFiles, InputType type, Video3DFormat? threedFormat, TimeSpan? offset, string outputPath, CancellationToken cancellationToken)
|
||||
public async Task ExtractImage(string[] inputFiles, InputType type, bool isAudio, Video3DFormat? threedFormat, TimeSpan? offset, string outputPath, CancellationToken cancellationToken)
|
||||
{
|
||||
var resourcePool = type == InputType.AudioFile ? _audioImageResourcePool : _videoImageResourcePool;
|
||||
var resourcePool = isAudio ? _audioImageResourcePool : _videoImageResourcePool;
|
||||
|
||||
var inputArgument = GetInputArgument(inputFiles, type);
|
||||
|
||||
if (type != InputType.AudioFile)
|
||||
if (!isAudio)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user