diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj index cdc0cd6aea..db8961a66c 100644 --- a/MediaBrowser.Api/MediaBrowser.Api.csproj +++ b/MediaBrowser.Api/MediaBrowser.Api.csproj @@ -80,8 +80,6 @@ - - diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 00ac7be879..2c3abe95ed 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1026,7 +1026,7 @@ namespace MediaBrowser.Api.Playback StartStreamingLog(transcodingJob, state, process.StandardError.BaseStream, state.LogFileStream); // Wait for the file to exist before proceeeding - while (!FileSystem.FileExists(state.WaitForPath ?? outputPath) && !transcodingJob.HasExited) + while (!FileSystem.FileExists(state.WaitForPath ?? outputPath) && !transcodingJob.HasExited) { await Task.Delay(100, cancellationTokenSource.Token).ConfigureAwait(false); } @@ -1452,10 +1452,7 @@ namespace MediaBrowser.Api.Playback } else if (i == 19) { - if (videoRequest != null) - { - videoRequest.Cabac = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); - } + // cabac no longer used } else if (i == 20) { @@ -1654,9 +1651,9 @@ namespace MediaBrowser.Api.Playback if (state.OutputVideoBitrate.HasValue) { var resolution = ResolutionNormalizer.Normalize( - state.VideoStream == null ? (int?)null : state.VideoStream.BitRate, - state.OutputVideoBitrate.Value, - state.VideoStream == null ? null : state.VideoStream.Codec, + state.VideoStream == null ? (int?)null : state.VideoStream.BitRate, + state.OutputVideoBitrate.Value, + state.VideoStream == null ? null : state.VideoStream.Codec, state.OutputVideoCodec, videoRequest.MaxWidth, videoRequest.MaxHeight); @@ -1680,12 +1677,12 @@ namespace MediaBrowser.Api.Playback private void TryStreamCopy(StreamState state, VideoStreamRequest videoRequest) { - if (state.VideoStream != null && CanStreamCopyVideo(videoRequest, state.VideoStream)) + if (state.VideoStream != null && CanStreamCopyVideo(state)) { state.OutputVideoCodec = "copy"; } - if (state.AudioStream != null && CanStreamCopyAudio(videoRequest, state.AudioStream, state.SupportedAudioCodecs)) + if (state.AudioStream != null && CanStreamCopyAudio(state, state.SupportedAudioCodecs)) { state.OutputAudioCodec = "copy"; } @@ -1773,8 +1770,11 @@ namespace MediaBrowser.Api.Playback state.MediaSource = mediaSource; } - protected virtual bool CanStreamCopyVideo(VideoStreamRequest request, MediaStream videoStream) + protected virtual bool CanStreamCopyVideo(StreamState state) { + var request = state.VideoRequest; + var videoStream = state.VideoStream; + if (videoStream.IsInterlaced) { return false; @@ -1784,7 +1784,7 @@ namespace MediaBrowser.Api.Playback { return false; } - + // Can't stream copy if we're burning in subtitles if (request.SubtitleStreamIndex.HasValue) { @@ -1805,10 +1805,10 @@ namespace MediaBrowser.Api.Playback { if (string.IsNullOrEmpty(videoStream.Profile)) { - return false; + //return false; } - if (!string.Equals(request.Profile, videoStream.Profile, StringComparison.OrdinalIgnoreCase)) + if (!string.IsNullOrEmpty(videoStream.Profile) && !string.Equals(request.Profile, videoStream.Profile, StringComparison.OrdinalIgnoreCase)) { var currentScore = GetVideoProfileScore(videoStream.Profile); var requestedScore = GetVideoProfileScore(request.Profile); @@ -1884,24 +1884,16 @@ namespace MediaBrowser.Api.Playback { if (!videoStream.Level.HasValue) { - return false; + //return false; } - if (videoStream.Level.Value > requestLevel) + if (videoStream.Level.HasValue && videoStream.Level.Value > requestLevel) { return false; } } } - if (request.Cabac.HasValue && request.Cabac.Value) - { - if (videoStream.IsCabac.HasValue && !videoStream.IsCabac.Value) - { - return false; - } - } - return request.EnableAutoStreamCopy; } @@ -1921,8 +1913,11 @@ namespace MediaBrowser.Api.Playback return Array.FindIndex(list.ToArray(), t => string.Equals(t, profile, StringComparison.OrdinalIgnoreCase)); } - protected virtual bool CanStreamCopyAudio(VideoStreamRequest request, MediaStream audioStream, List supportedAudioCodecs) + protected virtual bool CanStreamCopyAudio(StreamState state, List supportedAudioCodecs) { + var request = state.VideoRequest; + var audioStream = state.AudioStream; + // Source and target codecs must match if (string.IsNullOrEmpty(audioStream.Codec) || !supportedAudioCodecs.Contains(audioStream.Codec, StringComparer.OrdinalIgnoreCase)) { @@ -2028,7 +2023,6 @@ namespace MediaBrowser.Api.Playback state.TargetPacketLength, state.TargetTimestamp, state.IsTargetAnamorphic, - state.IsTargetCabac, state.TargetRefFrames, state.TargetVideoStreamCount, state.TargetAudioStreamCount, @@ -2054,6 +2048,7 @@ namespace MediaBrowser.Api.Playback if (state.VideoRequest != null) { state.VideoRequest.CopyTimestamps = transcodingProfile.CopyTimestamps; + state.VideoRequest.ForceLiveStream = transcodingProfile.ForceLiveStream; } } } @@ -2131,7 +2126,6 @@ namespace MediaBrowser.Api.Playback state.TargetPacketLength, state.TranscodeSeekInfo, state.IsTargetAnamorphic, - state.IsTargetCabac, state.TargetRefFrames, state.TargetVideoStreamCount, state.TargetAudioStreamCount, @@ -2223,7 +2217,7 @@ namespace MediaBrowser.Api.Playback inputModifier += " -noaccurate_seek"; } } - + return inputModifier; } diff --git a/MediaBrowser.Api/Playback/Dash/ManifestBuilder.cs b/MediaBrowser.Api/Playback/Dash/ManifestBuilder.cs deleted file mode 100644 index 35e252a198..0000000000 --- a/MediaBrowser.Api/Playback/Dash/ManifestBuilder.cs +++ /dev/null @@ -1,224 +0,0 @@ -using System; -using System.Globalization; -using System.Security; -using System.Text; - -namespace MediaBrowser.Api.Playback.Dash -{ - public class ManifestBuilder - { - protected readonly CultureInfo UsCulture = new CultureInfo("en-US"); - - public string GetManifestText(StreamState state, string playlistUrl) - { - var builder = new StringBuilder(); - - var time = TimeSpan.FromTicks(state.RunTimeTicks.Value); - - var duration = "PT" + time.Hours.ToString("00", UsCulture) + "H" + time.Minutes.ToString("00", UsCulture) + "M" + time.Seconds.ToString("00", UsCulture) + ".00S"; - - builder.Append(""); - - builder.AppendFormat( - "", - duration); - - builder.Append(""); - builder.Append(""); - - builder.Append(""); - builder.Append(GetVideoAdaptationSet(state, playlistUrl)); - builder.Append(GetAudioAdaptationSet(state, playlistUrl)); - builder.Append(""); - - builder.Append(""); - - return builder.ToString(); - } - - private string GetVideoAdaptationSet(StreamState state, string playlistUrl) - { - var builder = new StringBuilder(); - - builder.Append(""); - builder.Append(GetVideoRepresentationOpenElement(state)); - - AppendSegmentList(state, builder, "0", playlistUrl); - - builder.Append(""); - builder.Append(""); - - return builder.ToString(); - } - - private string GetAudioAdaptationSet(StreamState state, string playlistUrl) - { - var builder = new StringBuilder(); - - builder.Append(""); - builder.Append(GetAudioRepresentationOpenElement(state)); - - builder.Append(""); - - AppendSegmentList(state, builder, "1", playlistUrl); - - builder.Append(""); - builder.Append(""); - - return builder.ToString(); - } - - private string GetVideoRepresentationOpenElement(StreamState state) - { - var codecs = GetVideoCodecDescriptor(state); - - var mime = "video/mp4"; - - var xml = "= 4.1) - { - return "avc1.640028"; - } - - if (level >= 4) - { - return "avc1.640028"; - } - - return "avc1.64001f"; - } - - if (profile.IndexOf("main", StringComparison.OrdinalIgnoreCase) != -1) - { - if (level >= 4) - { - return "avc1.4d0028"; - } - - if (level >= 3.1) - { - return "avc1.4d001f"; - } - - return "avc1.4d001e"; - } - - if (level >= 3.1) - { - return "avc1.42001f"; - } - - return "avc1.42E01E"; - } - - private string GetAudioCodecDescriptor(StreamState state) - { - // https://developer.apple.com/library/ios/documentation/networkinginternet/conceptual/streamingmediaguide/FrequentlyAskedQuestions/FrequentlyAskedQuestions.html - - if (string.Equals(state.OutputAudioCodec, "mp3", StringComparison.OrdinalIgnoreCase)) - { - return "mp4a.40.34"; - } - - // AAC 5ch - if (state.OutputAudioChannels.HasValue && state.OutputAudioChannels.Value >= 5) - { - return "mp4a.40.5"; - } - - // AAC 2ch - return "mp4a.40.2"; - } - - private void AppendSegmentList(StreamState state, StringBuilder builder, string type, string playlistUrl) - { - var extension = ".m4s"; - - var seconds = TimeSpan.FromTicks(state.RunTimeTicks ?? 0).TotalSeconds; - - var queryStringIndex = playlistUrl.IndexOf('?'); - var queryString = queryStringIndex == -1 ? string.Empty : playlistUrl.Substring(queryStringIndex); - - var index = 0; - var duration = 1000000 * state.SegmentLength; - builder.AppendFormat("", duration.ToString(CultureInfo.InvariantCulture)); - - while (seconds > 0) - { - var filename = index == 0 - ? "init" - : (index - 1).ToString(UsCulture); - - var segmentUrl = string.Format("dash/{3}/{0}{1}{2}", - filename, - extension, - SecurityElement.Escape(queryString), - type); - - if (index == 0) - { - builder.AppendFormat("", segmentUrl); - } - else - { - builder.AppendFormat("", segmentUrl); - } - - seconds -= state.SegmentLength; - index++; - } - builder.Append(""); - } - } -} diff --git a/MediaBrowser.Api/Playback/Dash/MpegDashService.cs b/MediaBrowser.Api/Playback/Dash/MpegDashService.cs deleted file mode 100644 index a35d13c5b3..0000000000 --- a/MediaBrowser.Api/Playback/Dash/MpegDashService.cs +++ /dev/null @@ -1,547 +0,0 @@ -using MediaBrowser.Api.Playback.Hls; -using MediaBrowser.Common.Net; -using MediaBrowser.Controller.Configuration; -using MediaBrowser.Controller.Devices; -using MediaBrowser.Controller.Dlna; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.MediaEncoding; -using MediaBrowser.Controller.Net; -using MediaBrowser.Model.IO; -using MediaBrowser.Model.Serialization; -using ServiceStack; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using CommonIO; -using MimeTypes = MediaBrowser.Model.Net.MimeTypes; - -namespace MediaBrowser.Api.Playback.Dash -{ - /// - /// Options is needed for chromecast. Threw Head in there since it's related - /// - [Route("/Videos/{Id}/master.mpd", "GET", Summary = "Gets a video stream using Mpeg dash.")] - [Route("/Videos/{Id}/master.mpd", "HEAD", Summary = "Gets a video stream using Mpeg dash.")] - public class GetMasterManifest : VideoStreamRequest - { - public bool EnableAdaptiveBitrateStreaming { get; set; } - - public GetMasterManifest() - { - EnableAdaptiveBitrateStreaming = true; - } - } - - [Route("/Videos/{Id}/dash/{RepresentationId}/{SegmentId}.m4s", "GET")] - public class GetDashSegment : VideoStreamRequest - { - /// - /// Gets or sets the segment id. - /// - /// The segment id. - public string SegmentId { get; set; } - - /// - /// Gets or sets the representation identifier. - /// - /// The representation identifier. - public string RepresentationId { get; set; } - } - - public class MpegDashService : BaseHlsService - { - public MpegDashService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager, IZipClient zipClient, IJsonSerializer jsonSerializer, INetworkManager networkManager) : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, dlnaManager, subtitleEncoder, deviceManager, mediaSourceManager, zipClient, jsonSerializer) - { - NetworkManager = networkManager; - } - - protected INetworkManager NetworkManager { get; private set; } - - public object Get(GetMasterManifest request) - { - var result = GetAsync(request, "GET").Result; - - return result; - } - - public object Head(GetMasterManifest request) - { - var result = GetAsync(request, "HEAD").Result; - - return result; - } - - protected override bool EnableOutputInSubFolder - { - get - { - return true; - } - } - - private async Task GetAsync(GetMasterManifest request, string method) - { - if (string.IsNullOrEmpty(request.MediaSourceId)) - { - throw new ArgumentException("MediaSourceId is required"); - } - - var state = await GetState(request, CancellationToken.None).ConfigureAwait(false); - - var playlistText = string.Empty; - - if (string.Equals(method, "GET", StringComparison.OrdinalIgnoreCase)) - { - playlistText = new ManifestBuilder().GetManifestText(state, Request.RawUrl); - } - - return ResultFactory.GetResult(playlistText, MimeTypes.GetMimeType("playlist.mpd"), new Dictionary()); - } - - public object Get(GetDashSegment request) - { - return GetDynamicSegment(request, request.SegmentId, request.RepresentationId).Result; - } - - private async Task GetDynamicSegment(VideoStreamRequest request, string segmentId, string representationId) - { - if ((request.StartTimeTicks ?? 0) > 0) - { - throw new ArgumentException("StartTimeTicks is not allowed."); - } - - var cancellationTokenSource = new CancellationTokenSource(); - var cancellationToken = cancellationTokenSource.Token; - - var requestedIndex = string.Equals(segmentId, "init", StringComparison.OrdinalIgnoreCase) ? - -1 : - int.Parse(segmentId, NumberStyles.Integer, UsCulture); - - var state = await GetState(request, cancellationToken).ConfigureAwait(false); - - var playlistPath = Path.ChangeExtension(state.OutputFilePath, ".mpd"); - - var segmentExtension = GetSegmentFileExtension(state); - - var segmentPath = FindSegment(playlistPath, representationId, segmentExtension, requestedIndex); - var segmentLength = state.SegmentLength; - - TranscodingJob job = null; - - if (!string.IsNullOrWhiteSpace(segmentPath)) - { - job = ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType); - return await GetSegmentResult(playlistPath, segmentPath, requestedIndex, segmentLength, job, cancellationToken).ConfigureAwait(false); - } - - await ApiEntryPoint.Instance.TranscodingStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false); - try - { - segmentPath = FindSegment(playlistPath, representationId, segmentExtension, requestedIndex); - if (!string.IsNullOrWhiteSpace(segmentPath)) - { - job = ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType); - return await GetSegmentResult(playlistPath, segmentPath, requestedIndex, segmentLength, job, cancellationToken).ConfigureAwait(false); - } - else - { - if (string.Equals(representationId, "0", StringComparison.OrdinalIgnoreCase)) - { - job = ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType); - var currentTranscodingIndex = GetCurrentTranscodingIndex(playlistPath, segmentExtension); - var segmentGapRequiringTranscodingChange = 24 / state.SegmentLength; - Logger.Debug("Current transcoding index is {0}. requestedIndex={1}. segmentGapRequiringTranscodingChange={2}", currentTranscodingIndex ?? -2, requestedIndex, segmentGapRequiringTranscodingChange); - if (currentTranscodingIndex == null || requestedIndex < currentTranscodingIndex.Value || requestedIndex - currentTranscodingIndex.Value > segmentGapRequiringTranscodingChange) - { - // If the playlist doesn't already exist, startup ffmpeg - try - { - ApiEntryPoint.Instance.KillTranscodingJobs(request.DeviceId, request.PlaySessionId, p => false); - - if (currentTranscodingIndex.HasValue) - { - DeleteLastTranscodedFiles(playlistPath, 0); - } - - var positionTicks = GetPositionTicks(state, requestedIndex); - request.StartTimeTicks = positionTicks; - - var startNumber = GetStartNumber(state); - - var workingDirectory = Path.Combine(Path.GetDirectoryName(playlistPath), (startNumber == -1 ? 0 : startNumber).ToString(CultureInfo.InvariantCulture)); - state.WaitForPath = Path.Combine(workingDirectory, Path.GetFileName(playlistPath)); - FileSystem.CreateDirectory(workingDirectory); - job = await StartFfMpeg(state, playlistPath, cancellationTokenSource, workingDirectory).ConfigureAwait(false); - await WaitForMinimumDashSegmentCount(Path.Combine(workingDirectory, Path.GetFileName(playlistPath)), 1, cancellationTokenSource.Token).ConfigureAwait(false); - } - catch - { - state.Dispose(); - throw; - } - } - } - } - } - finally - { - ApiEntryPoint.Instance.TranscodingStartLock.Release(); - } - - while (string.IsNullOrWhiteSpace(segmentPath)) - { - segmentPath = FindSegment(playlistPath, representationId, segmentExtension, requestedIndex); - await Task.Delay(50, cancellationToken).ConfigureAwait(false); - } - - Logger.Info("returning {0}", segmentPath); - return await GetSegmentResult(playlistPath, segmentPath, requestedIndex, segmentLength, job ?? ApiEntryPoint.Instance.GetTranscodingJob(playlistPath, TranscodingJobType), cancellationToken).ConfigureAwait(false); - } - - private long GetPositionTicks(StreamState state, int requestedIndex) - { - if (requestedIndex <= 0) - { - return 0; - } - - var startSeconds = requestedIndex * state.SegmentLength; - return TimeSpan.FromSeconds(startSeconds).Ticks; - } - - protected Task WaitForMinimumDashSegmentCount(string playlist, int segmentCount, CancellationToken cancellationToken) - { - return WaitForSegment(playlist, "stream0-" + segmentCount.ToString("00000", CultureInfo.InvariantCulture) + ".m4s", cancellationToken); - } - - private async Task GetSegmentResult(string playlistPath, - string segmentPath, - int segmentIndex, - int segmentLength, - TranscodingJob transcodingJob, - CancellationToken cancellationToken) - { - // If all transcoding has completed, just return immediately - if (transcodingJob != null && transcodingJob.HasExited) - { - return GetSegmentResult(segmentPath, segmentIndex, segmentLength, transcodingJob); - } - - // Wait for the file to stop being written to, then stream it - var length = new FileInfo(segmentPath).Length; - var eofCount = 0; - - while (eofCount < 10) - { - var info = new FileInfo(segmentPath); - - if (!info.Exists) - { - break; - } - - var newLength = info.Length; - - if (newLength == length) - { - eofCount++; - } - else - { - eofCount = 0; - } - - length = newLength; - await Task.Delay(100, cancellationToken).ConfigureAwait(false); - } - - return GetSegmentResult(segmentPath, segmentIndex, segmentLength, transcodingJob); - } - - private object GetSegmentResult(string segmentPath, int index, int segmentLength, TranscodingJob transcodingJob) - { - var segmentEndingSeconds = (1 + index) * segmentLength; - var segmentEndingPositionTicks = TimeSpan.FromSeconds(segmentEndingSeconds).Ticks; - - return ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions - { - Path = segmentPath, - FileShare = FileShare.ReadWrite, - OnComplete = () => - { - if (transcodingJob != null) - { - transcodingJob.DownloadPositionTicks = Math.Max(transcodingJob.DownloadPositionTicks ?? segmentEndingPositionTicks, segmentEndingPositionTicks); - } - - } - }); - } - - public int? GetCurrentTranscodingIndex(string playlist, string segmentExtension) - { - var job = ApiEntryPoint.Instance.GetTranscodingJob(playlist, TranscodingJobType); - - if (job == null || job.HasExited) - { - return null; - } - - var file = GetLastTranscodingFiles(playlist, segmentExtension, FileSystem, 1).FirstOrDefault(); - - if (file == null) - { - return null; - } - - return GetIndex(file.FullName); - } - - public int GetIndex(string segmentPath) - { - var indexString = Path.GetFileNameWithoutExtension(segmentPath).Split('-').LastOrDefault(); - - if (string.Equals(indexString, "init", StringComparison.OrdinalIgnoreCase)) - { - return -1; - } - var startNumber = int.Parse(Path.GetFileNameWithoutExtension(Path.GetDirectoryName(segmentPath)), NumberStyles.Integer, UsCulture); - - return startNumber + int.Parse(indexString, NumberStyles.Integer, UsCulture) - 1; - } - - private void DeleteLastTranscodedFiles(string playlistPath, int retryCount) - { - if (retryCount >= 5) - { - return; - } - } - - private static List GetLastTranscodingFiles(string playlist, string segmentExtension, IFileSystem fileSystem, int count) - { - var folder = Path.GetDirectoryName(playlist); - - try - { - return fileSystem.GetFiles(folder) - .Where(i => string.Equals(i.Extension, segmentExtension, StringComparison.OrdinalIgnoreCase)) - .OrderByDescending(fileSystem.GetLastWriteTimeUtc) - .Take(count) - .ToList(); - } - catch (DirectoryNotFoundException) - { - return new List(); - } - } - - private string FindSegment(string playlist, string representationId, string segmentExtension, int requestedIndex) - { - var folder = Path.GetDirectoryName(playlist); - - if (requestedIndex == -1) - { - var path = Path.Combine(folder, "0", "stream" + representationId + "-" + "init" + segmentExtension); - return FileSystem.FileExists(path) ? path : null; - } - - try - { - foreach (var subfolder in FileSystem.GetDirectoryPaths(folder).ToList()) - { - var subfolderName = Path.GetFileNameWithoutExtension(subfolder); - int startNumber; - if (int.TryParse(subfolderName, NumberStyles.Any, UsCulture, out startNumber)) - { - var segmentIndex = requestedIndex - startNumber + 1; - var path = Path.Combine(folder, subfolderName, "stream" + representationId + "-" + segmentIndex.ToString("00000", CultureInfo.InvariantCulture) + segmentExtension); - if (FileSystem.FileExists(path)) - { - return path; - } - } - } - } - catch (DirectoryNotFoundException) - { - - } - - return null; - } - - protected override string GetAudioArguments(StreamState state) - { - var codec = GetAudioEncoder(state); - - if (string.Equals(codec, "copy", StringComparison.OrdinalIgnoreCase)) - { - return "-codec:a:0 copy"; - } - - var args = "-codec:a:0 " + codec; - - var channels = state.OutputAudioChannels; - - if (channels.HasValue) - { - args += " -ac " + channels.Value; - } - - var bitrate = state.OutputAudioBitrate; - - if (bitrate.HasValue) - { - args += " -ab " + bitrate.Value.ToString(UsCulture); - } - - args += " " + GetAudioFilterParam(state, true); - - return args; - } - - protected override string GetVideoArguments(StreamState state) - { - var codec = GetVideoEncoder(state); - - var args = "-codec:v:0 " + codec; - - if (state.EnableMpegtsM2TsMode) - { - args += " -mpegts_m2ts_mode 1"; - } - - // See if we can save come cpu cycles by avoiding encoding - if (codec.Equals("copy", StringComparison.OrdinalIgnoreCase)) - { - return state.VideoStream != null && IsH264(state.VideoStream) ? - args + " -bsf:v h264_mp4toannexb" : - args; - } - - var keyFrameArg = string.Format(" -force_key_frames expr:gte(t,n_forced*{0})", - state.SegmentLength.ToString(UsCulture)); - - var hasGraphicalSubs = state.SubtitleStream != null && !state.SubtitleStream.IsTextSubtitleStream; - - args += " " + GetVideoQualityParam(state, GetH264Encoder(state)) + keyFrameArg; - - // Add resolution params, if specified - if (!hasGraphicalSubs) - { - args += GetOutputSizeParam(state, codec, false); - } - - // This is for internal graphical subs - if (hasGraphicalSubs) - { - args += GetGraphicalSubtitleParam(state, codec); - } - - return args; - } - - protected override string GetCommandLineArguments(string outputPath, StreamState state, bool isEncoding) - { - // test url http://192.168.1.2:8096/videos/233e8905d559a8f230db9bffd2ac9d6d/master.mpd?mediasourceid=233e8905d559a8f230db9bffd2ac9d6d&videocodec=h264&audiocodec=aac&maxwidth=1280&videobitrate=500000&audiobitrate=128000&profile=baseline&level=3 - // Good info on i-frames http://blog.streamroot.io/encode-multi-bitrate-videos-mpeg-dash-mse-based-media-players/ - - var threads = GetNumberOfThreads(state, false); - - var inputModifier = GetInputModifier(state); - - var initSegmentName = "stream$RepresentationID$-init.m4s"; - var segmentName = "stream$RepresentationID$-$Number%05d$.m4s"; - - var args = string.Format("{0} {1} -map_metadata -1 -threads {2} {3} {4} -copyts {5} -f dash -init_seg_name \"{6}\" -media_seg_name \"{7}\" -use_template 0 -use_timeline 1 -min_seg_duration {8} -y \"{9}\"", - inputModifier, - GetInputArgument(state), - threads, - GetMapArgs(state), - GetVideoArguments(state), - GetAudioArguments(state), - initSegmentName, - segmentName, - (state.SegmentLength * 1000000).ToString(CultureInfo.InvariantCulture), - state.WaitForPath - ).Trim(); - - return args; - } - - protected override int GetStartNumber(StreamState state) - { - return GetStartNumber(state.VideoRequest); - } - - private int GetStartNumber(VideoStreamRequest request) - { - var segmentId = "0"; - - var segmentRequest = request as GetDashSegment; - if (segmentRequest != null) - { - segmentId = segmentRequest.SegmentId; - } - - if (string.Equals(segmentId, "init", StringComparison.OrdinalIgnoreCase)) - { - return -1; - } - - return int.Parse(segmentId, NumberStyles.Integer, UsCulture); - } - - /// - /// Gets the segment file extension. - /// - /// The state. - /// System.String. - protected override string GetSegmentFileExtension(StreamState state) - { - return ".m4s"; - } - - protected override TranscodingJobType TranscodingJobType - { - get - { - return TranscodingJobType.Dash; - } - } - - private async Task WaitForSegment(string playlist, string segment, CancellationToken cancellationToken) - { - var segmentFilename = Path.GetFileName(segment); - - Logger.Debug("Waiting for {0} in {1}", segmentFilename, playlist); - - while (true) - { - // Need to use FileShare.ReadWrite because we're reading the file at the same time it's being written - using (var fileStream = GetPlaylistFileStream(playlist)) - { - using (var reader = new StreamReader(fileStream)) - { - while (!reader.EndOfStream) - { - var line = await reader.ReadLineAsync().ConfigureAwait(false); - - if (line.IndexOf(segmentFilename, StringComparison.OrdinalIgnoreCase) != -1) - { - Logger.Debug("Finished waiting for {0} in {1}", segmentFilename, playlist); - return; - } - } - await Task.Delay(100, cancellationToken).ConfigureAwait(false); - } - } - } - } - } -} diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index c112657427..cb344690cd 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -83,11 +83,6 @@ namespace MediaBrowser.Api.Playback.Hls var state = await GetState(request, cancellationTokenSource.Token).ConfigureAwait(false); - if (isLive) - { - state.Request.StartTimeTicks = null; - } - TranscodingJob job = null; var playlist = state.OutputFilePath; @@ -137,13 +132,6 @@ namespace MediaBrowser.Api.Playback.Hls var appendBaselineStream = false; var baselineStreamBitrate = 64000; - var hlsVideoRequest = state.VideoRequest as GetHlsVideoStreamLegacy; - if (hlsVideoRequest != null) - { - appendBaselineStream = hlsVideoRequest.AppendBaselineStream; - baselineStreamBitrate = hlsVideoRequest.BaselineStreamAudioBitRate ?? baselineStreamBitrate; - } - var playlistText = GetMasterPlaylistFileText(playlist, videoBitrate + audioBitrate, appendBaselineStream, baselineStreamBitrate); job = job ?? ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlist, TranscodingJobType); @@ -248,11 +236,7 @@ namespace MediaBrowser.Api.Playback.Hls protected override string GetCommandLineArguments(string outputPath, StreamState state, bool isEncoding) { - var hlsVideoRequest = state.VideoRequest as GetHlsVideoStreamLegacy; - - var itsOffsetMs = hlsVideoRequest == null - ? 0 - : hlsVideoRequest.TimeStampOffsetMs; + var itsOffsetMs = 0; var itsOffset = itsOffsetMs == 0 ? string.Empty : string.Format("-itsoffset {0} ", TimeSpan.FromMilliseconds(itsOffsetMs).TotalSeconds.ToString(UsCulture)); @@ -286,26 +270,6 @@ namespace MediaBrowser.Api.Playback.Hls outputPath ).Trim(); - if (hlsVideoRequest != null) - { - if (hlsVideoRequest.AppendBaselineStream) - { - var lowBitratePath = Path.Combine(Path.GetDirectoryName(outputPath), Path.GetFileNameWithoutExtension(outputPath) + "-low.m3u8"); - - var bitrate = hlsVideoRequest.BaselineStreamAudioBitRate ?? 64000; - - var lowBitrateParams = string.Format(" -threads {0} -vn -codec:a:0 libmp3lame -ac 2 -ab {1} -hls_time {2} -start_number {3} -hls_list_size {4} -y \"{5}\"", - threads, - bitrate / 2, - state.SegmentLength.ToString(UsCulture), - startNumberParam, - state.HlsListSize.ToString(UsCulture), - lowBitratePath); - - args += " " + lowBitrateParams; - } - } - return args; } @@ -314,9 +278,28 @@ namespace MediaBrowser.Api.Playback.Hls return 0; } - protected override bool CanStreamCopyAudio(VideoStreamRequest request, MediaStream audioStream, List supportedAudioCodecs) + protected bool IsLiveStream(StreamState state) { - return false; + var isLiveStream = (state.RunTimeTicks ?? 0) == 0; + + if (state.VideoRequest.ForceLiveStream) + { + return true; + } + + return isLiveStream; + } + + protected override bool CanStreamCopyAudio(StreamState state, List supportedAudioCodecs) + { + var isLiveStream = IsLiveStream(state); + + if (!isLiveStream) + { + return false; + } + + return base.CanStreamCopyAudio(state, supportedAudioCodecs); } } } \ No newline at end of file diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index 3e46ee4268..65e2365256 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -500,13 +500,25 @@ namespace MediaBrowser.Api.Playback.Hls return ResultFactory.GetResult(playlistText, MimeTypes.GetMimeType("playlist.m3u8"), new Dictionary()); } + private bool IsLiveStream(StreamState state) + { + var isLiveStream = (state.RunTimeTicks ?? 0) == 0; + + if (state.VideoRequest.ForceLiveStream) + { + return true; + } + + return isLiveStream; + } + private string GetMasterPlaylistFileText(StreamState state, int totalBitrate) { var builder = new StringBuilder(); builder.AppendLine("#EXTM3U"); - var isLiveStream = (state.RunTimeTicks ?? 0) == 0; + var isLiveStream = IsLiveStream(state); var queryStringIndex = Request.RawUrl.IndexOf('?'); var queryString = queryStringIndex == -1 ? string.Empty : Request.RawUrl.Substring(queryStringIndex); @@ -929,10 +941,16 @@ namespace MediaBrowser.Api.Playback.Hls return isOutputVideo ? ".ts" : ".ts"; } - protected override bool CanStreamCopyVideo(VideoStreamRequest request, MediaStream videoStream) + protected override bool CanStreamCopyVideo(StreamState state) { - return false; - //return base.CanStreamCopyVideo(request, videoStream); + var isLiveStream = IsLiveStream(state); + + if (!isLiveStream) + { + return false; + } + + return base.CanStreamCopyVideo(state); } } } \ No newline at end of file diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs index b44d7f6606..e9f33161e4 100644 --- a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs +++ b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs @@ -31,25 +31,6 @@ namespace MediaBrowser.Api.Playback.Hls public string SegmentId { get; set; } } - /// - /// Class GetHlsVideoStream - /// - [Route("/Videos/{Id}/stream.m3u8", "GET")] - [Api(Description = "Gets a video stream using HTTP live streaming.")] - public class GetHlsVideoStreamLegacy : VideoStreamRequest - { - // TODO: Deprecate with new iOS app - - [ApiMember(Name = "BaselineStreamAudioBitRate", Description = "Optional. Specify the audio bitrate for the baseline stream.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] - public int? BaselineStreamAudioBitRate { get; set; } - - [ApiMember(Name = "AppendBaselineStream", Description = "Optional. Whether or not to include a baseline audio-only stream in the master playlist.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool AppendBaselineStream { get; set; } - - [ApiMember(Name = "TimeStampOffsetMs", Description = "Optional. Alter the timestamps in the playlist by a given amount, in ms. Default is 1000.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")] - public int TimeStampOffsetMs { get; set; } - } - /// /// Class GetHlsVideoSegment /// diff --git a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs index f154a05ccf..610628ced9 100644 --- a/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/VideoHlsService.cs @@ -27,16 +27,6 @@ namespace MediaBrowser.Api.Playback.Hls { } - /// - /// Gets the specified request. - /// - /// The request. - /// System.Object. - public object Get(GetHlsVideoStreamLegacy request) - { - return ProcessRequest(request, false); - } - public object Get(GetLiveHlsStream request) { return ProcessRequest(request, true); diff --git a/MediaBrowser.Api/Playback/Progressive/VideoService.cs b/MediaBrowser.Api/Playback/Progressive/VideoService.cs index 7c68b17312..b0d87c975b 100644 --- a/MediaBrowser.Api/Playback/Progressive/VideoService.cs +++ b/MediaBrowser.Api/Playback/Progressive/VideoService.cs @@ -137,12 +137,10 @@ namespace MediaBrowser.Api.Playback.Progressive args += " -mpegts_m2ts_mode 1"; } - var isOutputMkv = string.Equals(state.OutputContainer, "mkv", StringComparison.OrdinalIgnoreCase); - if (string.Equals(videoCodec, "copy", StringComparison.OrdinalIgnoreCase)) { if (state.VideoStream != null && IsH264(state.VideoStream) && - (string.Equals(state.OutputContainer, "ts", StringComparison.OrdinalIgnoreCase) || isOutputMkv)) + (string.Equals(state.OutputContainer, "ts", StringComparison.OrdinalIgnoreCase))) { args += " -bsf:v h264_mp4toannexb"; } diff --git a/MediaBrowser.Api/Playback/StreamRequest.cs b/MediaBrowser.Api/Playback/StreamRequest.cs index 1135a3a54d..371dbbda2a 100644 --- a/MediaBrowser.Api/Playback/StreamRequest.cs +++ b/MediaBrowser.Api/Playback/StreamRequest.cs @@ -189,10 +189,9 @@ namespace MediaBrowser.Api.Playback [ApiMember(Name = "CopyTimestamps", Description = "Whether or not to copy timestamps when transcoding with an offset. Defaults to false.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] public bool CopyTimestamps { get; set; } - - [ApiMember(Name = "Cabac", Description = "Enable if cabac encoding is required", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")] - public bool? Cabac { get; set; } - + + public bool ForceLiveStream { get; set; } + public VideoStreamRequest() { EnableAutoStreamCopy = true; diff --git a/MediaBrowser.Api/Playback/StreamState.cs b/MediaBrowser.Api/Playback/StreamState.cs index f1f6bb71f3..ed8a27fafe 100644 --- a/MediaBrowser.Api/Playback/StreamState.cs +++ b/MediaBrowser.Api/Playback/StreamState.cs @@ -480,18 +480,5 @@ namespace MediaBrowser.Api.Playback return false; } } - - public bool? IsTargetCabac - { - get - { - if (Request.Static) - { - return VideoStream == null ? null : VideoStream.IsCabac; - } - - return true; - } - } } } diff --git a/MediaBrowser.Controller/LiveTv/ChannelInfo.cs b/MediaBrowser.Controller/LiveTv/ChannelInfo.cs index 7d8df96ede..372b095fd1 100644 --- a/MediaBrowser.Controller/LiveTv/ChannelInfo.cs +++ b/MediaBrowser.Controller/LiveTv/ChannelInfo.cs @@ -59,5 +59,9 @@ namespace MediaBrowser.Controller.LiveTv /// /// null if [is favorite] contains no value, true if [is favorite]; otherwise, false. public bool? IsFavorite { get; set; } + + public bool? IsHD { get; set; } + public string AudioCodec { get; set; } + public string VideoCodec { get; set; } } } diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs b/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs index ddaf7ff6d2..c87ac4e734 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingJobOptions.cs @@ -58,8 +58,6 @@ namespace MediaBrowser.Controller.MediaEncoding } } - public bool? Cabac { get; set; } - public EncodingJobOptions() { @@ -87,7 +85,6 @@ namespace MediaBrowser.Controller.MediaEncoding MaxRefFrames = info.MaxRefFrames; MaxVideoBitDepth = info.MaxVideoBitDepth; SubtitleMethod = info.SubtitleDeliveryMethod; - Cabac = info.Cabac; Context = info.Context; if (info.SubtitleDeliveryMethod != SubtitleDeliveryMethod.External) diff --git a/MediaBrowser.Dlna/Didl/DidlBuilder.cs b/MediaBrowser.Dlna/Didl/DidlBuilder.cs index e8e969a5f1..728b397dee 100644 --- a/MediaBrowser.Dlna/Didl/DidlBuilder.cs +++ b/MediaBrowser.Dlna/Didl/DidlBuilder.cs @@ -171,7 +171,6 @@ namespace MediaBrowser.Dlna.Didl streamInfo.TargetPacketLength, streamInfo.TranscodeSeekInfo, streamInfo.IsTargetAnamorphic, - streamInfo.IsTargetCabac, streamInfo.TargetRefFrames, streamInfo.TargetVideoStreamCount, streamInfo.TargetAudioStreamCount, @@ -317,7 +316,6 @@ namespace MediaBrowser.Dlna.Didl streamInfo.TargetPacketLength, streamInfo.TargetTimestamp, streamInfo.IsTargetAnamorphic, - streamInfo.IsTargetCabac, streamInfo.TargetRefFrames, streamInfo.TargetVideoStreamCount, streamInfo.TargetAudioStreamCount, diff --git a/MediaBrowser.Dlna/PlayTo/PlayToController.cs b/MediaBrowser.Dlna/PlayTo/PlayToController.cs index 314756cdf2..db5e0ee293 100644 --- a/MediaBrowser.Dlna/PlayTo/PlayToController.cs +++ b/MediaBrowser.Dlna/PlayTo/PlayToController.cs @@ -523,7 +523,6 @@ namespace MediaBrowser.Dlna.PlayTo streamInfo.TargetPacketLength, streamInfo.TranscodeSeekInfo, streamInfo.IsTargetAnamorphic, - streamInfo.IsTargetCabac, streamInfo.TargetRefFrames, streamInfo.TargetVideoStreamCount, streamInfo.TargetAudioStreamCount, diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs index ae676dbc5a..b23bd16f35 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJob.cs @@ -391,19 +391,6 @@ namespace MediaBrowser.MediaEncoding.Encoder } } - public bool? IsTargetCabac - { - get - { - if (Options.Static) - { - return VideoStream == null ? null : VideoStream.IsCabac; - } - - return true; - } - } - public int? TargetVideoStreamCount { get diff --git a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs index f782fd05f4..070aae3a70 100644 --- a/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs +++ b/MediaBrowser.MediaEncoding/Encoder/EncodingJobFactory.cs @@ -664,14 +664,6 @@ namespace MediaBrowser.MediaEncoding.Encoder } } - if (request.Cabac.HasValue && request.Cabac.Value) - { - if (videoStream.IsCabac.HasValue && !videoStream.IsCabac.Value) - { - return false; - } - } - return request.EnableAutoStreamCopy; } @@ -773,7 +765,6 @@ namespace MediaBrowser.MediaEncoding.Encoder state.TargetPacketLength, state.TargetTimestamp, state.IsTargetAnamorphic, - state.IsTargetCabac, state.TargetRefFrames, state.TargetVideoStreamCount, state.TargetAudioStreamCount, diff --git a/MediaBrowser.Model/Dlna/ConditionProcessor.cs b/MediaBrowser.Model/Dlna/ConditionProcessor.cs index fef04647a4..69f1369dc0 100644 --- a/MediaBrowser.Model/Dlna/ConditionProcessor.cs +++ b/MediaBrowser.Model/Dlna/ConditionProcessor.cs @@ -17,7 +17,6 @@ namespace MediaBrowser.Model.Dlna int? packetLength, TransportStreamTimestamp? timestamp, bool? isAnamorphic, - bool? isCabac, int? refFrames, int? numVideoStreams, int? numAudioStreams, @@ -27,8 +26,6 @@ namespace MediaBrowser.Model.Dlna { case ProfileConditionValue.IsAnamorphic: return IsConditionSatisfied(condition, isAnamorphic); - case ProfileConditionValue.IsCabac: - return IsConditionSatisfied(condition, isCabac); case ProfileConditionValue.VideoFramerate: return IsConditionSatisfied(condition, videoFramerate); case ProfileConditionValue.VideoLevel: diff --git a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs index 58d669c220..c4b3383a2b 100644 --- a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs +++ b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs @@ -115,7 +115,6 @@ namespace MediaBrowser.Model.Dlna int? packetLength, TranscodeSeekInfo transcodeSeekInfo, bool? isAnamorphic, - bool? isCabac, int? refFrames, int? numVideoStreams, int? numAudioStreams, @@ -157,7 +156,6 @@ namespace MediaBrowser.Model.Dlna packetLength, timestamp, isAnamorphic, - isCabac, refFrames, numVideoStreams, numAudioStreams, diff --git a/MediaBrowser.Model/Dlna/DeviceProfile.cs b/MediaBrowser.Model/Dlna/DeviceProfile.cs index 80c060c499..423928f620 100644 --- a/MediaBrowser.Model/Dlna/DeviceProfile.cs +++ b/MediaBrowser.Model/Dlna/DeviceProfile.cs @@ -283,7 +283,6 @@ namespace MediaBrowser.Model.Dlna int? packetLength, TransportStreamTimestamp timestamp, bool? isAnamorphic, - bool? isCabac, int? refFrames, int? numVideoStreams, int? numAudioStreams, @@ -321,7 +320,7 @@ namespace MediaBrowser.Model.Dlna var anyOff = false; foreach (ProfileCondition c in i.Conditions) { - if (!conditionProcessor.IsVideoConditionSatisfied(c, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, isCabac, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) + if (!conditionProcessor.IsVideoConditionSatisfied(c, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) { anyOff = true; break; diff --git a/MediaBrowser.Model/Dlna/ProfileConditionValue.cs b/MediaBrowser.Model/Dlna/ProfileConditionValue.cs index 4ad326e519..c17a09c3fb 100644 --- a/MediaBrowser.Model/Dlna/ProfileConditionValue.cs +++ b/MediaBrowser.Model/Dlna/ProfileConditionValue.cs @@ -17,7 +17,6 @@ VideoTimestamp = 12, IsAnamorphic = 13, RefFrames = 14, - IsCabac = 15, NumAudioStreams = 16, NumVideoStreams = 17, IsSecondaryAudio = 18, diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index e5477cfd03..d28e21bf25 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -443,6 +443,7 @@ namespace MediaBrowser.Model.Dlna playlistItem.VideoCodec = transcodingProfile.VideoCodec; playlistItem.CopyTimestamps = transcodingProfile.CopyTimestamps; + playlistItem.ForceLiveStream = transcodingProfile.ForceLiveStream; playlistItem.SubProtocol = transcodingProfile.Protocol; playlistItem.AudioStreamIndex = audioStreamIndex; @@ -513,7 +514,14 @@ namespace MediaBrowser.Model.Dlna { if (targetAudioChannels.Value >= 5 && (maxTotalBitrate ?? 0) >= 2000000) { - defaultBitrate = 320000; + if (StringHelper.EqualsIgnoreCase(targetAudioCodec, "ac3")) + { + defaultBitrate = 384000; + } + else + { + defaultBitrate = 320000; + } } } @@ -597,7 +605,6 @@ namespace MediaBrowser.Model.Dlna string videoProfile = videoStream == null ? null : videoStream.Profile; float? videoFramerate = videoStream == null ? null : videoStream.AverageFrameRate ?? videoStream.AverageFrameRate; bool? isAnamorphic = videoStream == null ? null : videoStream.IsAnamorphic; - bool? isCabac = videoStream == null ? null : videoStream.IsCabac; string videoCodecTag = videoStream == null ? null : videoStream.CodecTag; int? audioBitrate = audioStream == null ? null : audioStream.BitRate; @@ -614,7 +621,7 @@ namespace MediaBrowser.Model.Dlna // Check container conditions foreach (ProfileCondition i in conditions) { - if (!conditionProcessor.IsVideoConditionSatisfied(i, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, isCabac, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) + if (!conditionProcessor.IsVideoConditionSatisfied(i, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) { LogConditionFailure(profile, "VideoContainerProfile", i, mediaSource); @@ -647,7 +654,7 @@ namespace MediaBrowser.Model.Dlna foreach (ProfileCondition i in conditions) { - if (!conditionProcessor.IsVideoConditionSatisfied(i, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, isCabac, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) + if (!conditionProcessor.IsVideoConditionSatisfied(i, width, height, bitDepth, videoBitrate, videoProfile, videoLevel, videoFramerate, packetLength, timestamp, isAnamorphic, refFrames, numVideoStreams, numAudioStreams, videoCodecTag)) { LogConditionFailure(profile, "VideoCodecProfile", i, mediaSource); @@ -910,22 +917,6 @@ namespace MediaBrowser.Model.Dlna } break; } - case ProfileConditionValue.IsCabac: - { - bool val; - if (BoolHelper.TryParseCultureInvariant(value, out val)) - { - if (condition.Condition == ProfileConditionType.Equals) - { - item.Cabac = val; - } - else if (condition.Condition == ProfileConditionType.NotEquals) - { - item.Cabac = !val; - } - } - break; - } case ProfileConditionValue.IsAnamorphic: case ProfileConditionValue.AudioProfile: case ProfileConditionValue.Has64BitOffsets: diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs index 436ed20712..644f732a74 100644 --- a/MediaBrowser.Model/Dlna/StreamInfo.cs +++ b/MediaBrowser.Model/Dlna/StreamInfo.cs @@ -30,8 +30,8 @@ namespace MediaBrowser.Model.Dlna public string VideoCodec { get; set; } public string VideoProfile { get; set; } - public bool? Cabac { get; set; } public bool CopyTimestamps { get; set; } + public bool ForceLiveStream { get; set; } public string AudioCodec { get; set; } public int? AudioStreamIndex { get; set; } @@ -205,7 +205,7 @@ namespace MediaBrowser.Model.Dlna list.Add(new NameValuePair("MaxWidth", item.MaxWidth.HasValue ? StringHelper.ToStringCultureInvariant(item.MaxWidth.Value) : string.Empty)); list.Add(new NameValuePair("MaxHeight", item.MaxHeight.HasValue ? StringHelper.ToStringCultureInvariant(item.MaxHeight.Value) : string.Empty)); - if (StringHelper.EqualsIgnoreCase(item.SubProtocol, "hls")) + if (StringHelper.EqualsIgnoreCase(item.SubProtocol, "hls") && !item.ForceLiveStream) { list.Add(new NameValuePair("StartTimeTicks", string.Empty)); } @@ -219,7 +219,9 @@ namespace MediaBrowser.Model.Dlna list.Add(new NameValuePair("MaxRefFrames", item.MaxRefFrames.HasValue ? StringHelper.ToStringCultureInvariant(item.MaxRefFrames.Value) : string.Empty)); list.Add(new NameValuePair("MaxVideoBitDepth", item.MaxVideoBitDepth.HasValue ? StringHelper.ToStringCultureInvariant(item.MaxVideoBitDepth.Value) : string.Empty)); list.Add(new NameValuePair("Profile", item.VideoProfile ?? string.Empty)); - list.Add(new NameValuePair("Cabac", item.Cabac.HasValue ? item.Cabac.Value.ToString() : string.Empty)); + + // no longer used + list.Add(new NameValuePair("Cabac", string.Empty)); list.Add(new NameValuePair("PlaySessionId", item.PlaySessionId ?? string.Empty)); list.Add(new NameValuePair("api_key", accessToken ?? string.Empty)); @@ -233,6 +235,7 @@ namespace MediaBrowser.Model.Dlna } list.Add(new NameValuePair("CopyTimestamps", item.CopyTimestamps.ToString().ToLower())); + list.Add(new NameValuePair("ForceLiveStream", item.ForceLiveStream.ToString().ToLower())); list.Add(new NameValuePair("SubtitleMethod", item.SubtitleStreamIndex.HasValue && item.SubtitleDeliveryMethod != SubtitleDeliveryMethod.External ? item.SubtitleDeliveryMethod.ToString() : string.Empty)); return list; @@ -632,19 +635,6 @@ namespace MediaBrowser.Model.Dlna } } - public bool? IsTargetCabac - { - get - { - if (IsDirectStream) - { - return TargetVideoStream == null ? null : TargetVideoStream.IsCabac; - } - - return true; - } - } - public int? TargetWidth { get diff --git a/MediaBrowser.Model/Dlna/TranscodingProfile.cs b/MediaBrowser.Model/Dlna/TranscodingProfile.cs index e59ee6d634..bf6bf092f3 100644 --- a/MediaBrowser.Model/Dlna/TranscodingProfile.cs +++ b/MediaBrowser.Model/Dlna/TranscodingProfile.cs @@ -35,6 +35,9 @@ namespace MediaBrowser.Model.Dlna [XmlAttribute("context")] public EncodingContext Context { get; set; } + [XmlAttribute("forceLiveStream")] + public bool ForceLiveStream { get; set; } + public List GetAudioCodecs() { List list = new List(); diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs index 79fa46baf4..bdc043e9a7 100644 --- a/MediaBrowser.Model/Entities/MediaStream.cs +++ b/MediaBrowser.Model/Entities/MediaStream.cs @@ -232,11 +232,5 @@ namespace MediaBrowser.Model.Entities /// /// true if this instance is anamorphic; otherwise, false. public bool? IsAnamorphic { get; set; } - - /// - /// Gets or sets a value indicating whether this instance is cabac. - /// - /// null if [is cabac] contains no value, true if [is cabac]; otherwise, false. - public bool? IsCabac { get; set; } } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs index db7f6f86c3..ef8efbe987 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs @@ -59,7 +59,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun return id; } - protected override async Task> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken) + private async Task> GetLineup(TunerHostInfo info, CancellationToken cancellationToken) { var options = new HttpRequestOptions { @@ -68,31 +68,34 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun }; using (var stream = await _httpClient.Get(options)) { - var root = JsonSerializer.DeserializeFromStream>(stream); + var lineup = JsonSerializer.DeserializeFromStream>(stream) ?? new List(); - if (root != null) + if (info.ImportFavoritesOnly) { - var result = root.Select(i => new ChannelInfo - { - Name = i.GuideName, - Number = i.GuideNumber.ToString(CultureInfo.InvariantCulture), - Id = GetChannelId(info, i), - IsFavorite = i.Favorite, - TunerHostId = info.Id - - }); - - if (info.ImportFavoritesOnly) - { - result = result.Where(i => i.IsFavorite ?? true).ToList(); - } - - return result; + lineup = lineup.Where(i => i.Favorite).ToList(); } - return new List(); + + return lineup; } } + protected override async Task> GetChannelsInternal(TunerHostInfo info, CancellationToken cancellationToken) + { + var lineup = await GetLineup(info, cancellationToken).ConfigureAwait(false); + + return lineup.Select(i => new ChannelInfo + { + Name = i.GuideName, + Number = i.GuideNumber.ToString(CultureInfo.InvariantCulture), + Id = GetChannelId(info, i), + IsFavorite = i.Favorite, + TunerHostId = info.Id, + IsHD = i.HD == 1, + AudioCodec = i.AudioCodec, + VideoCodec = i.VideoCodec + }); + } + private async Task GetModelInfo(TunerHostInfo info, CancellationToken cancellationToken) { using (var stream = await _httpClient.Get(new HttpRequestOptions() @@ -226,17 +229,21 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun { public string GuideNumber { get; set; } public string GuideName { get; set; } + public string VideoCodec { get; set; } + public string AudioCodec { get; set; } public string URL { get; set; } public bool Favorite { get; set; } public bool DRM { get; set; } + public int HD { get; set; } } - private MediaSourceInfo GetMediaSource(TunerHostInfo info, string channelId, string profile) + private async Task GetMediaSource(TunerHostInfo info, string channelId, string profile) { int? width = null; int? height = null; bool isInterlaced = true; - var videoCodec = !string.IsNullOrWhiteSpace(GetEncodingOptions().HardwareAccelerationType) ? null : "mpeg2video"; + string videoCodec = null; + string audioCodec = "ac3"; int? videoBitrate = null; @@ -297,6 +304,25 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun videoBitrate = 1000000; } + if (string.IsNullOrWhiteSpace(videoCodec)) + { + var channels = await GetChannels(info, true, CancellationToken.None).ConfigureAwait(false); + var channel = channels.FirstOrDefault(i => string.Equals(i.Number, channelId, StringComparison.OrdinalIgnoreCase)); + if (channel != null) + { + videoCodec = channel.VideoCodec; + audioCodec = channel.AudioCodec; + + videoBitrate = (channel.IsHD ?? true) ? 15000000 : 2000000; + } + } + + // normalize + if (string.Equals(videoCodec, "mpeg2", StringComparison.OrdinalIgnoreCase)) + { + videoCodec = "mpeg2video"; + } + var url = GetApiUrl(info, true) + "/auto/v" + channelId; if (!string.IsNullOrWhiteSpace(profile) && !string.Equals(profile, "native", StringComparison.OrdinalIgnoreCase)) @@ -320,14 +346,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun Width = width, Height = height, BitRate = videoBitrate - + }, new MediaStream { Type = MediaStreamType.Audio, // Set the index to -1 because we don't know the exact index of the audio stream within the container Index = -1, - Codec = "ac3", + Codec = audioCodec, BitRate = 192000 } }, @@ -364,7 +390,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun } var hdhrId = GetHdHrIdFromChannelId(channelId); - list.Add(GetMediaSource(info, hdhrId, "native")); + list.Add(await GetMediaSource(info, hdhrId, "native").ConfigureAwait(false)); try { @@ -373,12 +399,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun if (model.IndexOf("hdtc", StringComparison.OrdinalIgnoreCase) != -1) { - list.Insert(0, GetMediaSource(info, hdhrId, "heavy")); + list.Add(await GetMediaSource(info, hdhrId, "heavy").ConfigureAwait(false)); - list.Add(GetMediaSource(info, hdhrId, "internet480")); - list.Add(GetMediaSource(info, hdhrId, "internet360")); - list.Add(GetMediaSource(info, hdhrId, "internet240")); - list.Add(GetMediaSource(info, hdhrId, "mobile")); + list.Add(await GetMediaSource(info, hdhrId, "internet480").ConfigureAwait(false)); + list.Add(await GetMediaSource(info, hdhrId, "internet360").ConfigureAwait(false)); + list.Add(await GetMediaSource(info, hdhrId, "internet240").ConfigureAwait(false)); + list.Add(await GetMediaSource(info, hdhrId, "mobile").ConfigureAwait(false)); } } catch (Exception ex) @@ -409,7 +435,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts.HdHomerun } var hdhrId = GetHdHrIdFromChannelId(channelId); - return GetMediaSource(info, hdhrId, streamId); + return await GetMediaSource(info, hdhrId, streamId).ConfigureAwait(false); } public async Task Validate(TunerHostInfo info) diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index eda0a263ac..71c338fdb3 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -2755,7 +2755,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveStreamCommand.GetParameter(index++).Value = stream.BitDepth; _saveStreamCommand.GetParameter(index++).Value = stream.IsAnamorphic; _saveStreamCommand.GetParameter(index++).Value = stream.RefFrames; - _saveStreamCommand.GetParameter(index++).Value = stream.IsCabac; + _saveStreamCommand.GetParameter(index++).Value = null; _saveStreamCommand.GetParameter(index++).Value = stream.CodecTag; _saveStreamCommand.GetParameter(index++).Value = stream.Comment; @@ -2907,10 +2907,7 @@ namespace MediaBrowser.Server.Implementations.Persistence item.RefFrames = reader.GetInt32(24); } - if (!reader.IsDBNull(25)) - { - item.IsCabac = reader.GetBoolean(25); - } + // cabac no longer used if (!reader.IsDBNull(26)) { diff --git a/MediaBrowser.WebDashboard/Api/PackageCreator.cs b/MediaBrowser.WebDashboard/Api/PackageCreator.cs index 79e2d61023..01c2a4104e 100644 --- a/MediaBrowser.WebDashboard/Api/PackageCreator.cs +++ b/MediaBrowser.WebDashboard/Api/PackageCreator.cs @@ -477,7 +477,7 @@ namespace MediaBrowser.WebDashboard.Api var tags = files.Select(s => { - if (s.IndexOf("require", StringComparison.OrdinalIgnoreCase) == -1) + if (s.IndexOf("require", StringComparison.OrdinalIgnoreCase) == -1 && s.IndexOf("alameda", StringComparison.OrdinalIgnoreCase) == -1) { return string.Format("", s); } diff --git a/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs b/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs index 5a190ab729..c39917e298 100644 --- a/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs +++ b/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs @@ -51,47 +51,45 @@ namespace XmlRpcHandler XmlWriterSettings sett = new XmlWriterSettings(); sett.Indent = true; - var requestXmlPath = Path.Combine(Path.GetTempPath(), "request.xml"); - sett.Encoding = Encoding.UTF8; - FileStream str = new FileStream(requestXmlPath, FileMode.Create, FileAccess.Write); - XmlWriter XMLwrt = XmlWriter.Create(str, sett); - // Let's write the methods - foreach (XmlRpcMethodCall method in methods) + using (var ms = new MemoryStream()) { - XMLwrt.WriteStartElement("methodCall");//methodCall - XMLwrt.WriteStartElement("methodName");//methodName - XMLwrt.WriteString(method.Name); - XMLwrt.WriteEndElement();//methodName - XMLwrt.WriteStartElement("params");//params - // Write values - foreach (IXmlRpcValue p in method.Parameters) + XmlWriter XMLwrt = XmlWriter.Create(ms, sett); + // Let's write the methods + foreach (XmlRpcMethodCall method in methods) { - XMLwrt.WriteStartElement("param");//param - if (p is XmlRpcValueBasic) + XMLwrt.WriteStartElement("methodCall");//methodCall + XMLwrt.WriteStartElement("methodName");//methodName + XMLwrt.WriteString(method.Name); + XMLwrt.WriteEndElement();//methodName + XMLwrt.WriteStartElement("params");//params + // Write values + foreach (IXmlRpcValue p in method.Parameters) { - WriteBasicValue(XMLwrt, (XmlRpcValueBasic)p); + XMLwrt.WriteStartElement("param");//param + if (p is XmlRpcValueBasic) + { + WriteBasicValue(XMLwrt, (XmlRpcValueBasic)p); + } + else if (p is XmlRpcValueStruct) + { + WriteStructValue(XMLwrt, (XmlRpcValueStruct)p); + } + else if (p is XmlRpcValueArray) + { + WriteArrayValue(XMLwrt, (XmlRpcValueArray)p); + } + XMLwrt.WriteEndElement();//param } - else if (p is XmlRpcValueStruct) - { - WriteStructValue(XMLwrt, (XmlRpcValueStruct)p); - } - else if (p is XmlRpcValueArray) - { - WriteArrayValue(XMLwrt, (XmlRpcValueArray)p); - } - XMLwrt.WriteEndElement();//param - } - XMLwrt.WriteEndElement();//params - XMLwrt.WriteEndElement();//methodCall + XMLwrt.WriteEndElement();//params + XMLwrt.WriteEndElement();//methodCall + } + XMLwrt.Flush(); + XMLwrt.Close(); + return ms.ToArray(); } - XMLwrt.Flush(); - XMLwrt.Close(); - str.Close(); - string requestContent = File.ReadAllText(requestXmlPath); - return Encoding.UTF8.GetBytes(requestContent); } /// /// Decode response then return the values