Example #1
0
        public static VideoChunk First(VideoEvent @event)
        {
            if (@event.Type != VideoEventType.Add)
            {
                throw new InvalidOperationException($"Unexpected video event type '{@event.Type}'.");
            }

            return(new VideoChunk
            {
                Segments = new[] { @event.Segment },
                StartTimestamp = @event.Timestamp,
            });
        }
Example #2
0
        public VideoChunk Next(VideoEvent @event)
        {
            StopTimestamp = @event.Timestamp;

            switch (@event.Type)
            {
            case VideoEventType.Add:
                return(new VideoChunk
                {
                    Segments = Segments.Concat(new[] { @event.Segment }).ToArray(),
                    StartTimestamp = @event.Timestamp
                });

            case VideoEventType.Remove:
                var segments = Segments.Where(x => x != @event.LastSegment).ToArray();
                if (segments.Length == 0)
                {
                    return(null);
                }
                return(new VideoChunk
                {
                    Segments = segments,
                    StartTimestamp = @event.Timestamp
                });

            case VideoEventType.Update:
                return(new VideoChunk
                {
                    Segments = Segments.Where(x => x != @event.LastSegment).Concat(new[] { @event.Segment }).ToArray(),
                    StartTimestamp = @event.Timestamp
                });

            default:
                throw new InvalidOperationException($"Unexpected video event type '{@event.Type}'.");
            }
        }