Exemplo n.º 1
0
        /// <summary>
        /// 接続先を指定してチャンネルのリレーを開始します。
        /// URIから接続プロトコルも判別します
        /// </summary>
        /// <param name="channel_id">リレーするチャンネルID</param>
        /// <param name="tracker">接続起点およびプロトコル</param>
        /// <returns>Channelのインスタンス</returns>
        public Channel RelayChannel(Guid channel_id, Uri tracker)
        {
            Channel channel = null;

            logger.Debug("Requesting channel {0} from {1}", channel_id.ToString("N"), tracker);
            ISourceStreamFactory source_factory = SourceStreamFactories.FirstOrDefault(factory => tracker.Scheme == factory.Scheme);

            if (source_factory == null)
            {
                logger.Error("Protocol `{0}' is not found", tracker.Scheme);
                throw new ArgumentException(String.Format("Protocol `{0}' is not found", tracker.Scheme));
            }
            channel = new Channel(this, channel_id, tracker);
            Utils.ReplaceCollection(ref channels, orig => {
                var new_collection = new List <Channel>(orig);
                new_collection.Add(channel);
                return(new_collection);
            });
            var source_stream = source_factory.Create(channel, tracker);

            channel.Start(source_stream);
            if (ChannelAdded != null)
            {
                ChannelAdded(this, new ChannelChangedEventArgs(channel));
            }
            return(channel);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 配信を開始します。
        /// </summary>
        /// <param name="yp">チャンネル情報を載せるYellowPage</param>
        /// <param name="channel_id">チャンネルID</param>
        /// <param name="channel_info">チャンネル情報</param>
        /// <param name="source">配信ソース</param>
        /// <param name="content_reader_factory">配信ソースのコンテンツを解析するIContentReaderFactory</param>
        /// <returns>Channelのインスタンス</returns>
        public Channel BroadcastChannel(IYellowPageClient yp, Guid channel_id, ChannelInfo channel_info, Uri source, IContentReaderFactory content_reader_factory)
        {
            Channel channel = null;

            logger.Debug("Broadcasting channel {0} from {1}", channel_id.ToString("N"), source);
            ISourceStreamFactory source_factory = SourceStreamFactories.FirstOrDefault(factory => source.Scheme == factory.Scheme);

            if (source_factory == null)
            {
                logger.Error("Protocol `{0}' is not found", source.Scheme);
                throw new ArgumentException(String.Format("Protocol `{0}' is not found", source.Scheme));
            }
            channel = new Channel(this, channel_id, this.BroadcastID, source);
            Utils.ReplaceCollection(ref channels, orig => {
                var new_collection = new List <Channel>(orig);
                new_collection.Add(channel);
                return(new_collection);
            });
            channel.ChannelInfo = channel_info;
            var content_reader = content_reader_factory.Create(channel);
            var source_stream  = source_factory.Create(channel, source, content_reader);

            channel.Start(source_stream);
            if (ChannelAdded != null)
            {
                ChannelAdded(this, new ChannelChangedEventArgs(channel));
            }
            if (yp != null)
            {
                yp.Announce(channel);
            }
            return(channel);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 配信を開始します。
        /// </summary>
        /// <param name="yp">チャンネル情報を載せるYellowPage</param>
        /// <param name="channel_id">チャンネルID</param>
        /// <param name="channel_info">チャンネル情報</param>
        /// <param name="source">配信ソース</param>
        /// <param name="source_stream_factory">配信ソースからコンテンツを取得するISourceStreamFactory</param>
        /// <param name="content_reader_factory">配信ソースのコンテンツを解析するIContentReaderFactory</param>
        /// <returns>Channelのインスタンス</returns>
        public Channel BroadcastChannel(
            NetworkType network,
            IYellowPageClient yp,
            Guid channel_id,
            ChannelInfo channel_info,
            Uri source,
            ISourceStreamFactory source_stream_factory,
            IContentReaderFactory content_reader_factory)
        {
            logger.Debug("Broadcasting channel {0} from {1}", channel_id.ToString("N"), source);
            var channel = new BroadcastChannel(this, network, channel_id, channel_info, source_stream_factory, content_reader_factory);

            channel.Start(source);
            ReplaceCollection(ref channels, orig => {
                var new_collection = new List <Channel>(orig);
                new_collection.Add(channel);
                return(new_collection);
            });
            if (ChannelAdded != null)
            {
                ChannelAdded(this, new ChannelChangedEventArgs(channel));
            }
            if (yp != null)
            {
                yp.Announce(channel);
            }
            return(channel);
        }
Exemplo n.º 4
0
 public BroadcastChannel(
     PeerCast peercast,
     Guid channel_id,
     ChannelInfo channel_info,
     ISourceStreamFactory source_stream_factory,
     IContentReaderFactory content_reader_factory)
     : base(peercast, channel_id)
 {
     this.ChannelInfo          = channel_info;
     this.SourceStreamFactory  = source_stream_factory;
     this.ContentReaderFactory = content_reader_factory;
 }
Exemplo n.º 5
0
 public BroadcastChannel(
     PeerCast peercast,
     Guid channel_id,
     ChannelInfo channel_info,
     ISourceStreamFactory source_stream_factory,
     IContentReaderFactory content_reader_factory)
   : base(peercast, channel_id)
 {
   this.ChannelInfo = channel_info;
   this.SourceStreamFactory = source_stream_factory;
   this.ContentReaderFactory = content_reader_factory;
 }
Exemplo n.º 6
0
        private void AddSourceStreamFactory(Type type)
        {
            ISourceStreamFactory factory = null;
            var constructor = type.GetConstructor(Type.EmptyTypes);

            if (constructor != null)
            {
                factory = constructor.Invoke(null) as ISourceStreamFactory;
            }
            else if ((constructor = type.GetConstructor(new Type[] { typeof(PeerCast) })) != null)
            {
                factory = constructor.Invoke(new object[] { peerCast }) as ISourceStreamFactory;
            }
            if (factory != null)
            {
                peerCast.SourceStreamFactories.Add(factory);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 配信を開始します。
        /// </summary>
        /// <param name="yp">チャンネル情報を載せるYellowPage</param>
        /// <param name="channel_id">チャンネルID</param>
        /// <param name="channel_info">チャンネル情報</param>
        /// <param name="source">配信ソース</param>
        /// <param name="source_stream_factory">配信ソースからコンテンツを取得するISourceStreamFactory</param>
        /// <param name="content_reader_factory">配信ソースのコンテンツを解析するIContentReaderFactory</param>
        /// <returns>Channelのインスタンス</returns>
        public Channel BroadcastChannel(
            NetworkType network,
            IYellowPageClient yp,
            Guid channel_id,
            ChannelInfo channel_info,
            Uri source,
            ISourceStreamFactory source_stream_factory,
            IContentReaderFactory content_reader_factory)
        {
            logger.Debug("Broadcasting channel {0} from {1}", channel_id.ToString("N"), source);
            var channel = new BroadcastChannel(this, network, channel_id, channel_info, source_stream_factory, content_reader_factory);

            channel.Start(source);
            ReplaceCollection(ref channels, orig => orig.Add(channel));
            DispatchMonitorEvent(mon => mon.OnChannelChanged(PeerCastChannelAction.Added, channel));
            if (yp != null)
            {
                yp.Announce(channel);
            }
            return(channel);
        }