/// <summary>
 /// Remove handler that protects stream playback.
 /// </summary>
 /// <param name="handler">Handler to remove.</param>
 public void UnregisterStreamPlaybackSecurity(IStreamPlaybackSecurity handler)
 {
     _playbackSecurityHandlers.Remove(handler);
 }
 /// <summary>
 /// Add handler that protects stream playback.
 /// </summary>
 /// <param name="handler">Handler to add.</param>
 public void RegisterStreamPlaybackSecurity(IStreamPlaybackSecurity handler)
 {
     _playbackSecurityHandlers.Add(handler);
 }
 /// <summary>
 /// Remove handler that protects stream playback.
 /// </summary>
 /// <param name="handler">Handler to remove.</param>
 public void UnregisterStreamPlaybackSecurity(IStreamPlaybackSecurity handler)
 {
     _playbackSecurityHandlers.Remove(handler);
 }
 /// <summary>
 /// Add handler that protects stream playback.
 /// </summary>
 /// <param name="handler">Handler to add.</param>
 public void RegisterStreamPlaybackSecurity(IStreamPlaybackSecurity handler)
 {
     _playbackSecurityHandlers.Add(handler);
 }
Example #5
0
        public void play(string name, double start, double length, bool flushPlaylist)
        {
            IConnection connection = FluorineContext.Current.Connection;

            if (!(connection is IStreamCapableConnection))
            {
                return;
            }
            IStreamCapableConnection streamConnection = connection as IStreamCapableConnection;
            IScope scope    = connection.Scope;
            int    streamId = GetCurrentStreamId();

            if (name == null || string.Empty.Equals(name))
            {
                SendNSFailed(streamConnection as RtmpConnection, "The stream name may not be empty.", name, streamId);
                return;
            }
            IStreamSecurityService security = ScopeUtils.GetScopeService(scope, typeof(IStreamSecurityService)) as IStreamSecurityService;

            if (security != null)
            {
                IEnumerator handlers = security.GetStreamPlaybackSecurity();
                while (handlers.MoveNext())
                {
                    IStreamPlaybackSecurity handler = handlers.Current as IStreamPlaybackSecurity;
                    if (!handler.IsPlaybackAllowed(scope, name, (long)start, (long)length, flushPlaylist))
                    {
                        SendNSFailed(streamConnection as RtmpConnection, "You are not allowed to play the stream.", name, streamId);
                        return;
                    }
                }
            }
            IClientStream stream  = streamConnection.GetStreamById(streamId);
            bool          created = false;

            if (stream == null)
            {
                stream = streamConnection.NewPlaylistSubscriberStream(streamId);
                stream.Start();
                created = true;
            }
            if (!(stream is ISubscriberStream))
            {
                return;
            }
            ISubscriberStream subscriberStream = stream as ISubscriberStream;
            SimplePlayItem    item             = new SimplePlayItem();

            item.Name   = name;
            item.Start  = (long)start;
            item.Length = (long)length;
            if (subscriberStream is IPlaylistSubscriberStream)
            {
                IPlaylistSubscriberStream playlistStream = subscriberStream as IPlaylistSubscriberStream;
                if (flushPlaylist)
                {
                    playlistStream.RemoveAllItems();
                }
                playlistStream.AddItem(item);
            }
            else if (subscriberStream is ISingleItemSubscriberStream)
            {
                ISingleItemSubscriberStream singleStream = subscriberStream as ISingleItemSubscriberStream;
                singleStream.PlayItem = item;
            }
            else
            {
                // not supported by this stream service
                return;
            }
            try
            {
                subscriberStream.Play();
            } catch (System.IO.IOException ex)
            {
                if (created)
                {
                    stream.Close();
                    streamConnection.DeleteStreamById(streamId);
                }
                SendNSFailed(streamConnection as RtmpConnection, ex.Message, name, streamId);
            }
        }
Example #6
0
        public void play(string name, double start, double length, bool flushPlaylist)
        {
            IConnection connection = FluorineContext.Current.Connection;

            if (connection is IStreamCapableConnection)
            {
                IStreamCapableConnection connection2 = connection as IStreamCapableConnection;
                IScope scope           = connection.Scope;
                int    currentStreamId = this.GetCurrentStreamId();
                if ((name == null) || string.Empty.Equals(name))
                {
                    this.SendNSFailed(connection2 as RtmpConnection, "The stream name may not be empty.", name, currentStreamId);
                }
                else
                {
                    IStreamSecurityService scopeService = ScopeUtils.GetScopeService(scope, typeof(IStreamSecurityService)) as IStreamSecurityService;
                    if (scopeService != null)
                    {
                        IEnumerator streamPlaybackSecurity = scopeService.GetStreamPlaybackSecurity();
                        while (streamPlaybackSecurity.MoveNext())
                        {
                            IStreamPlaybackSecurity current = streamPlaybackSecurity.Current as IStreamPlaybackSecurity;
                            if (!current.IsPlaybackAllowed(scope, name, (long)start, (long)length, flushPlaylist))
                            {
                                this.SendNSFailed(connection2 as RtmpConnection, "You are not allowed to play the stream.", name, currentStreamId);
                                return;
                            }
                        }
                    }
                    IClientStream streamById = connection2.GetStreamById(currentStreamId);
                    bool          flag       = false;
                    if (streamById == null)
                    {
                        streamById = connection2.NewPlaylistSubscriberStream(currentStreamId);
                        streamById.Start();
                        flag = true;
                    }
                    if (streamById is ISubscriberStream)
                    {
                        ISubscriberStream stream2 = streamById as ISubscriberStream;
                        SimplePlayItem    item    = new SimplePlayItem {
                            Name   = name,
                            Start  = (long)start,
                            Length = (long)length
                        };
                        if (stream2 is IPlaylistSubscriberStream)
                        {
                            IPlaylistSubscriberStream stream3 = stream2 as IPlaylistSubscriberStream;
                            if (flushPlaylist)
                            {
                                stream3.RemoveAllItems();
                            }
                            stream3.AddItem(item);
                        }
                        else if (stream2 is ISingleItemSubscriberStream)
                        {
                            ISingleItemSubscriberStream stream4 = stream2 as ISingleItemSubscriberStream;
                            stream4.PlayItem = item;
                        }
                        else
                        {
                            return;
                        }
                        try
                        {
                            stream2.Play();
                        }
                        catch (IOException exception)
                        {
                            if (flag)
                            {
                                streamById.Close();
                                connection2.DeleteStreamById(currentStreamId);
                            }
                            this.SendNSFailed(connection2 as RtmpConnection, exception.Message, name, currentStreamId);
                        }
                    }
                }
            }
        }