Exemplo n.º 1
0
        private static void SetKeyProperties(IMediaSourceProvider provider, MediaSourceInfo mediaSource)
        {
            var prefix = provider.GetType().FullName.GetMD5().ToString("N", CultureInfo.InvariantCulture) + LiveStreamIdDelimeter;

            if (!string.IsNullOrEmpty(mediaSource.OpenToken) && !mediaSource.OpenToken.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
            {
                mediaSource.OpenToken = prefix + mediaSource.OpenToken;
            }

            if (!string.IsNullOrEmpty(mediaSource.LiveStreamId) && !mediaSource.LiveStreamId.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
            {
                mediaSource.LiveStreamId = prefix + mediaSource.LiveStreamId;
            }
        }
Exemplo n.º 2
0
        private async Task CloseLiveStreamWithProvider(IMediaSourceProvider provider, string streamId)
        {
            _logger.Info("Closing live stream {0} with provider {1}", streamId, provider.GetType().Name);

            try
            {
                await provider.CloseMediaSource(streamId).ConfigureAwait(false);
            }
            catch (NotImplementedException)
            {
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error closing live stream {0}", ex, streamId);
            }
        }
Exemplo n.º 3
0
        private async Task <IEnumerable <MediaSourceInfo> > GetDynamicMediaSources(BaseItem item, IMediaSourceProvider provider, CancellationToken cancellationToken)
        {
            try
            {
                var sources = await provider.GetMediaSources(item, cancellationToken).ConfigureAwait(false);

                var list = sources.ToList();

                foreach (var mediaSource in list)
                {
                    mediaSource.InferTotalBitrate();

                    SetKeyProperties(provider, mediaSource);
                }

                return(list);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error getting media sources", ex);
                return(new List <MediaSourceInfo>());
            }
        }
Exemplo n.º 4
0
        private async Task CloseLiveStreamWithProvider(IMediaSourceProvider provider, string streamId)
        {
            _logger.Info("Closing live stream {0} with provider {1}", streamId, provider.GetType().Name);

            try
            {
                await provider.CloseMediaSource(streamId).ConfigureAwait(false);
            }
            catch (NotImplementedException)
            {
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error closing live stream {0}", ex, streamId);
            }
        }
Exemplo n.º 5
0
        private void SetKeyProperties(IMediaSourceProvider provider, MediaSourceInfo mediaSource)
        {
            var prefix = provider.GetType().FullName.GetMD5().ToString("N") + LiveStreamIdDelimeter;

            if (!string.IsNullOrWhiteSpace(mediaSource.OpenToken) && !mediaSource.OpenToken.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
            {
                mediaSource.OpenToken = prefix + mediaSource.OpenToken;
            }

            if (!string.IsNullOrWhiteSpace(mediaSource.LiveStreamId) && !mediaSource.LiveStreamId.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
            {
                mediaSource.LiveStreamId = prefix + mediaSource.LiveStreamId;
            }
        }
Exemplo n.º 6
0
        private async Task<IEnumerable<MediaSourceInfo>> GetDynamicMediaSources(IHasMediaSources item, IMediaSourceProvider provider, CancellationToken cancellationToken)
        {
            try
            {
                var sources = await provider.GetMediaSources(item, cancellationToken).ConfigureAwait(false);
                var list = sources.ToList();

                foreach (var mediaSource in list)
                {
                    SetKeyProperties(provider, mediaSource);
                }

                return list;
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error getting media sources", ex);
                return new List<MediaSourceInfo>();
            }
        }
Exemplo n.º 7
0
 private async Task <IEnumerable <MediaSourceInfo> > GetDynamicMediaSources(IHasMediaSources item, IMediaSourceProvider provider, CancellationToken cancellationToken)
 {
     try
     {
         return(await provider.GetMediaSources(item, cancellationToken).ConfigureAwait(false));
     }
     catch (Exception ex)
     {
         _logger.ErrorException("Error getting media sources", ex);
         return(new List <MediaSourceInfo>());
     }
 }