Exemple #1
0
        private void SelectPlaylistVideoStream()
        {
            if (string.IsNullOrEmpty(this.VideoStreamName))
            {
                return;
            }

            ISegment segment = this.CurrentSegment;

            if (segment != null && segment.AvailableStreams != null)
            {
                IMediaStream videoStream = segment.AvailableStreams.Where(s => s.Type == StreamType.Video).FirstOrDefault();

                if (videoStream == null)
                {
                    return;
                }

                // get all media tracks that which match the camera name (might be one per bitrate)
                IEnumerable <IMediaTrack> tracks =
                    videoStream.AvailableTracks.Where(
                        t =>
                        t.CustomAttributes.Any(kvp => IsCameraAttribute(kvp, this.VideoStreamName)));

                if (tracks.Count() > 0)
                {
                    videoStream.SetSelectedTracks(tracks);
                }
            }
        }
Exemple #2
0
        public void SelectTracks(string key, string value, long minBitrate, long maxBitrate)
        {
            if (this.CurrentSegment != null)
            {
                IMediaStream videoStream = this.CurrentSegment.AvailableStreams.FirstOrDefault(x => x.Type == StreamType.Video);

                if (videoStream != null)
                {
                    bool attributeAvailable    = false;
                    IList <IMediaTrack> tracks = new List <IMediaTrack>();

                    if (key != null && value != null)
                    {
                        foreach (IMediaTrack trackInfo in videoStream.AvailableTracks)
                        {
                            string keyValue;

                            trackInfo.CustomAttributes.TryGetValue(key, out keyValue);

                            if (!string.IsNullOrEmpty(keyValue) && keyValue.ToUpper(CultureInfo.InvariantCulture) == value.ToUpper(CultureInfo.InvariantCulture))
                            {
                                attributeAvailable = true;
                                if (trackInfo.Bitrate >= minBitrate && trackInfo.Bitrate <= maxBitrate)
                                {
                                    tracks.Add(trackInfo);
                                }
                            }
                        }
                    }

                    if (!attributeAvailable)
                    {
                        tracks = videoStream.AvailableTracks.Where(x => x.Bitrate >= minBitrate && x.Bitrate <= maxBitrate).ToList();
                    }

                    if (tracks.Count > 0)
                    {
                        if (this.singleBitrate && tracks.Count > 1)
                        {
                            long bitrate = tracks.Max(x => x.Bitrate);

                            IMediaTrack track = tracks.FirstOrDefault(x => x.Bitrate == bitrate);

                            tracks.Clear();
                            tracks.Add(track);
                        }

                        videoStream.SetSelectedTracks(tracks);
                    }
                }
            }
        }