예제 #1
0
 /// <summary>
 /// Initializes an instance of <see cref="AudioOnlyStreamInfo"/>.
 /// </summary>
 public AudioOnlyStreamInfo(
     string url,
     Container container,
     FileSize size,
     Bitrate bitrate,
     string audioCodec)
 {
     Url        = url;
     Container  = container;
     Size       = size;
     Bitrate    = bitrate;
     AudioCodec = audioCodec;
 }
예제 #2
0
 /// <summary>
 /// Initializes an instance of <see cref="VideoOnlyStreamInfo"/>.
 /// </summary>
 public VideoOnlyStreamInfo(
     string url,
     Container container,
     FileSize size,
     Bitrate bitrate,
     string videoCodec,
     VideoQuality videoQuality,
     Resolution videoResolution)
 {
     Url             = url;
     Container       = container;
     Size            = size;
     Bitrate         = bitrate;
     VideoCodec      = videoCodec;
     VideoQuality    = videoQuality;
     VideoResolution = videoResolution;
 }
예제 #3
0
 /// <summary>
 /// Initializes an instance of <see cref="MuxedStreamInfo"/>.
 /// </summary>
 public MuxedStreamInfo(
     string url,
     Container container,
     FileSize size,
     Bitrate bitrate,
     string audioCodec,
     string videoCodec,
     VideoQuality videoQuality,
     Resolution resolution)
 {
     Url             = url;
     Container       = container;
     Size            = size;
     Bitrate         = bitrate;
     AudioCodec      = audioCodec;
     VideoCodec      = videoCodec;
     VideoQuality    = videoQuality;
     VideoResolution = resolution;
 }
예제 #4
0
        private async Task <StreamManifest> GetManifestAsync(StreamContext streamContext)
        {
            // To make sure there are no duplicates streams, group them by tag
            var streams = new Dictionary <int, IStreamInfo>();

            foreach (var streamInfo in streamContext.StreamInfoProviders)
            {
                var tag = streamInfo.GetTag();
                var url = streamInfo.GetUrl();

                // Signature
                var signature          = streamInfo.TryGetSignature();
                var signatureParameter = streamInfo.TryGetSignatureParameter() ?? "signature";

                if (!string.IsNullOrWhiteSpace(signature))
                {
                    signature = streamContext.CipherOperations.Decipher(signature);
                    url       = Url.SetQueryParameter(url, signatureParameter, signature);
                }

                // Content length
                var contentLength = streamInfo.TryGetContentLength() ??
                                    await _httpClient.TryGetContentLengthAsync(url, false) ??
                                    0;

                if (contentLength <= 0)
                {
                    continue; // broken stream URL?
                }
                // Common
                var container = Container.Parse(streamInfo.GetContainer());
                var fileSize  = new FileSize(contentLength);
                var bitrate   = new Bitrate(streamInfo.GetBitrate());

                var audioCodec = streamInfo.TryGetAudioCodec();
                var videoCodec = streamInfo.TryGetVideoCodec();

                // Muxed or Video-only
                if (!string.IsNullOrWhiteSpace(videoCodec))
                {
                    var framerate = new Framerate(streamInfo.TryGetFramerate() ?? 24);

                    var videoQualityLabel = streamInfo.TryGetVideoQualityLabel() ??
                                            Heuristics.GetVideoQualityLabel(tag, framerate.FramesPerSecond);

                    var videoQuality = Heuristics.GetVideoQuality(videoQualityLabel);

                    var videoWidth      = streamInfo.TryGetVideoWidth();
                    var videoHeight     = streamInfo.TryGetVideoHeight();
                    var videoResolution = videoWidth != null && videoHeight != null
                        ? new VideoResolution(videoWidth.Value, videoHeight.Value)
                        : Heuristics.GetVideoResolution(videoQuality);

                    // Muxed
                    if (!string.IsNullOrWhiteSpace(audioCodec))
                    {
                        streams[tag] = new MuxedStreamInfo(
                            tag,
                            url,
                            container,
                            fileSize,
                            bitrate,
                            audioCodec,
                            videoCodec,
                            videoQualityLabel,
                            videoQuality,
                            videoResolution,
                            framerate
                            );
                    }
                    // Video-only
                    else
                    {
                        streams[tag] = new VideoOnlyStreamInfo(
                            tag,
                            url,
                            container,
                            fileSize,
                            bitrate,
                            videoCodec,
                            videoQualityLabel,
                            videoQuality,
                            videoResolution,
                            framerate
                            );
                    }
                }
                // Audio-only
                else if (!string.IsNullOrWhiteSpace(audioCodec))
                {
                    streams[tag] = new AudioOnlyStreamInfo(
                        tag,
                        url,
                        container,
                        fileSize,
                        bitrate,
                        audioCodec
                        );
                }
                else
                {
#if DEBUG
                    throw FatalFailureException.Generic("Stream info doesn't contain audio/video codec information.");
#endif
                }
            }

            return(new StreamManifest(streams.Values.ToArray()));
        }