using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.IO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Api.Playback.Hls
{
///
/// Class BaseHlsService
///
public abstract class BaseHlsService : BaseStreamingService
{
protected BaseHlsService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IDtoService dtoService, IFileSystem fileSystem, IItemRepository itemRepository, ILiveTvManager liveTvManager, IEncodingManager encodingManager, IDlnaManager dlnaManager)
: base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, dtoService, fileSystem, itemRepository, liveTvManager, encodingManager, dlnaManager)
{
}
protected override string GetOutputFilePath(StreamState state)
{
var folder = ServerConfigurationManager.ApplicationPaths.TranscodingTempPath;
var outputFileExtension = GetOutputFileExtension(state);
return Path.Combine(folder, GetCommandLineArguments("dummy\\dummy", state, false).GetMD5() + (outputFileExtension ?? string.Empty).ToLower());
}
///
/// Gets the audio arguments.
///
/// The state.
/// System.String.
protected abstract string GetAudioArguments(StreamState state);
///
/// Gets the video arguments.
///
/// The state.
/// if set to true [perform subtitle conversion].
/// System.String.
protected abstract string GetVideoArguments(StreamState state, bool performSubtitleConversion);
///
/// Gets the segment file extension.
///
/// The state.
/// System.String.
protected abstract string GetSegmentFileExtension(StreamState state);
///
/// Gets the type of the transcoding job.
///
/// The type of the transcoding job.
protected override TranscodingJobType TranscodingJobType
{
get { return TranscodingJobType.Hls; }
}
///
/// Processes the request.
///
/// The request.
/// System.Object.
protected object ProcessRequest(StreamRequest request)
{
return ProcessRequestAsync(request).Result;
}
private static readonly SemaphoreSlim FfmpegStartLock = new SemaphoreSlim(1, 1);
///
/// Processes the request async.
///
/// The request.
/// Task{System.Object}.
///
/// A video bitrate is required
/// or
/// An audio bitrate is required
///
private async Task