| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 | 
							- using System;
 
- using System.Globalization;
 
- using System.Linq;
 
- using System.Threading;
 
- using System.Threading.Tasks;
 
- using MediaBrowser.Controller.MediaEncoding;
 
- using MediaBrowser.Model.Dlna;
 
- using MediaBrowser.Model.Dto;
 
- using MediaBrowser.Model.Entities;
 
- using MediaBrowser.Model.Logging;
 
- namespace Emby.Server.Implementations.LiveTv
 
- {
 
-     public class LiveStreamHelper
 
-     {
 
-         private readonly IMediaEncoder _mediaEncoder;
 
-         private readonly ILogger _logger;
 
-         const int ProbeAnalyzeDurationMs = 3000;
 
-         const int PlaybackAnalyzeDurationMs = 3000;
 
-         public LiveStreamHelper(IMediaEncoder mediaEncoder, ILogger logger)
 
-         {
 
-             _mediaEncoder = mediaEncoder;
 
-             _logger = logger;
 
-         }
 
-         public async Task AddMediaInfoWithProbe(MediaSourceInfo mediaSource, bool isAudio, CancellationToken cancellationToken)
 
-         {
 
-             var originalRuntime = mediaSource.RunTimeTicks;
 
-             var now = DateTime.UtcNow;
 
-             var info = await _mediaEncoder.GetMediaInfo(new MediaInfoRequest
 
-             {
 
-                 InputPath = mediaSource.Path,
 
-                 Protocol = mediaSource.Protocol,
 
-                 MediaType = isAudio ? DlnaProfileType.Audio : DlnaProfileType.Video,
 
-                 ExtractChapters = false,
 
-                 AnalyzeDurationMs = ProbeAnalyzeDurationMs
 
-             }, cancellationToken).ConfigureAwait(false);
 
-             _logger.Info("Live tv media info probe took {0} seconds", (DateTime.UtcNow - now).TotalSeconds.ToString(CultureInfo.InvariantCulture));
 
-             mediaSource.Bitrate = info.Bitrate;
 
-             mediaSource.Container = info.Container;
 
-             mediaSource.Formats = info.Formats;
 
-             mediaSource.MediaStreams = info.MediaStreams;
 
-             mediaSource.RunTimeTicks = info.RunTimeTicks;
 
-             mediaSource.Size = info.Size;
 
-             mediaSource.Timestamp = info.Timestamp;
 
-             mediaSource.Video3DFormat = info.Video3DFormat;
 
-             mediaSource.VideoType = info.VideoType;
 
-             mediaSource.DefaultSubtitleStreamIndex = null;
 
-             // Null this out so that it will be treated like a live stream
 
-             if (!originalRuntime.HasValue)
 
-             {
 
-                 mediaSource.RunTimeTicks = null;
 
-             }
 
-             var audioStream = mediaSource.MediaStreams.FirstOrDefault(i => i.Type == MediaBrowser.Model.Entities.MediaStreamType.Audio);
 
-             if (audioStream == null || audioStream.Index == -1)
 
-             {
 
-                 mediaSource.DefaultAudioStreamIndex = null;
 
-             }
 
-             else
 
-             {
 
-                 mediaSource.DefaultAudioStreamIndex = audioStream.Index;
 
-             }
 
-             var videoStream = mediaSource.MediaStreams.FirstOrDefault(i => i.Type == MediaBrowser.Model.Entities.MediaStreamType.Video);
 
-             if (videoStream != null)
 
-             {
 
-                 if (!videoStream.BitRate.HasValue)
 
-                 {
 
-                     var width = videoStream.Width ?? 1920;
 
-                     if (width >= 3000)
 
-                     {
 
-                         videoStream.BitRate = 30000000;
 
-                     }
 
-                     else if (width >= 1900)
 
-                     {
 
-                         videoStream.BitRate = 20000000;
 
-                     }
 
-                     else if (width >= 1200)
 
-                     {
 
-                         videoStream.BitRate = 8000000;
 
-                     }
 
-                     else if (width >= 700)
 
-                     {
 
-                         videoStream.BitRate = 2000000;
 
-                     }
 
-                 }
 
-                 // This is coming up false and preventing stream copy
 
-                 videoStream.IsAVC = null;
 
-             }
 
-             // Try to estimate this
 
-             mediaSource.InferTotalBitrate(true);
 
-             mediaSource.AnalyzeDurationMs = PlaybackAnalyzeDurationMs;
 
-         }
 
-     }
 
- }
 
 
  |