示例#1
0
        public static bool Add(Int32 ChannelNumber, String ChannelName, String ChannelPictureURL, ushort ServiceID, String MulticastIP, String MulticastPort)
        {
            try
            {
                // first check if it already exists...
                foreach (StationAndChannel station_ in ChannelsAndStations)
                {
                    // exists, now exit
                    if (station_.ServiceID == ServiceID)
                        return false;
                }

                // does not exist, so we add it...
                StationAndChannel newData = new StationAndChannel();

                newData.ChannelName = ChannelName;
                newData.ChannelPictureURL = ChannelPictureURL;
                newData.ChannelNumber = ChannelNumber;
                newData.ServiceID = ServiceID;
                newData.MulticastIP = MulticastIP;
                newData.MulticastPort = MulticastPort;

                lock (ChannelsAndStations)
                {
                    ChannelsAndStations.Add(newData);
                }

                return true;
            }
            catch (Exception e)
            {
                ConsoleOutputLogger.WriteLine("ChannelAndStationMapper.Add: " + e.Message);
                return false;
            }
        }
示例#2
0
        /// <summary>
        /// Handles a single VCR recording and spawns a new MulticastProcessor if needed or reuses one if existing
        /// </summary>
        /// <param name="url"></param>
        /// <param name="internal_http_server_object"></param>
        public void HandleVCR(StationAndChannel Channel, YAPS.HttpServer internal_http_server_object)
        {
            internal_HTTP_Server_Object = internal_http_server_object;

            #region build the channel ip endpoints...
            myChannel = Channel;
            IPAddress ip = null;
            IPEndPoint ipep;

            ip = IPAddress.Parse(myChannel.MulticastIP);
            ipep = new IPEndPoint(IPAddress.Any, int.Parse(myChannel.MulticastPort));
            #endregion

            #region MulticastProcessor checking and spawning/reusing
            lock (internal_http_server_object.MulticastProcessorList.SyncRoot)
            {
                if (internal_http_server_object.MulticastProcessorList.ContainsKey(myChannel.ServiceID))
                {
                    // okay we have a MulticastProcessor already
                    // get that MulticastProcessor object
                    internal_Multicast_Processor_Object = (MulticastProcessor)internal_http_server_object.MulticastProcessorList[myChannel.ServiceID];

                    lock (internal_Multicast_Processor_Object.ReceiverList.SyncRoot)
                    {
                        // add myself to the list
                        internal_Multicast_Processor_Object.ReceiverList.Add(myID, this);
                    }
                }
                else
                {
                    // we don't have a MulticastProcessor yet

                    // create one
                    internal_Multicast_Processor_Object = new MulticastProcessor(ip, ipep, internal_http_server_object, myChannel.ServiceID, myChannel.isRTP);
                    // add him to the global list
                    lock (internal_http_server_object.MulticastProcessorList.SyncRoot)
                    {
                        internal_http_server_object.MulticastProcessorList.Add(myChannel.ServiceID, internal_Multicast_Processor_Object);
                    }
                    lock (internal_Multicast_Processor_Object.ReceiverList.SyncRoot)
                    {
                        internal_Multicast_Processor_Object.ReceiverList.Add(myID, this);
                    }

                    Thread thread = new Thread(new ThreadStart(internal_Multicast_Processor_Object.Go));
                    thread.Start();
                }
            }
            #endregion
        }
示例#3
0
        public void HandleStreaming(String url, YAPS.HttpProcessor http_processor_object)
        {
            #region build the channel ip endpoints...

            try
            {
                // try to resolve the name
                myChannel = ChannelAndStationMapper.Name2Data(url.Remove(0, 5));

                if (myChannel == null)
                {
                    myChannel = ChannelAndStationMapper.Number2Data(Convert.ToInt32(url.Remove(0, 5)));

                    // nothing to do here...
                    if (myChannel == null)
                        return;
                }
            }
            catch (Exception e)
            {
                ConsoleOutputLogger.WriteLine("HandleStreaming: " + e.Message);
            }

            IPAddress ip = null;
            IPEndPoint ipep;

            internal_HTTP_Processor_Object = http_processor_object;

            internal_HTTP_Processor_Object.ns.WriteTimeout = 1000;

            ip = IPAddress.Parse(myChannel.MulticastIP);
            ipep = new IPEndPoint(IPAddress.Any, int.Parse(myChannel.MulticastPort));
            //                    long left = file.Length;
            internal_HTTP_Processor_Object.writeSuccess(0);
            #endregion

            #region MulticastProcessor checking and spawning/reusing
            lock (internal_HTTP_Processor_Object.HTTPServer.MulticastProcessorList.SyncRoot)
            {
                foreach (MulticastProcessor m in internal_HTTP_Processor_Object.HTTPServer.MulticastProcessorList.Values)
                {
                    ConsoleOutputLogger.WriteLine("we have a MulticastProcessor for " + m.my_ID);
                    if (m.diedalready) ConsoleOutputLogger.WriteLine("it died already...");
                    else
                        ConsoleOutputLogger.WriteLine("which is living...");
                }

                if (internal_HTTP_Processor_Object.HTTPServer.MulticastProcessorList.ContainsKey(myChannel.ServiceID))
                {
                    // okay we have a MulticastProcessor already
                    ConsoleOutputLogger.WriteLine("Reusing MulticastProcessor for channel " + myChannel.ChannelName);
                    // get that MulticastProcessor object
                    internal_Multicast_Processor_Object = (MulticastProcessor)internal_HTTP_Processor_Object.HTTPServer.MulticastProcessorList[myChannel.ServiceID];

                    lock (internal_Multicast_Processor_Object.ReceiverList.SyncRoot)
                    {
                        // add myself to the list
                        internal_Multicast_Processor_Object.ReceiverList.Add(myID, this);
                    }
                }
                else
                {
                    // we don't have a MulticastProcessor yet
                    ConsoleOutputLogger.WriteLine("Creating a new MulticastProcessor for channel " + myChannel.ChannelName);
                    // create one
                    internal_Multicast_Processor_Object = new MulticastProcessor(ip, ipep, internal_HTTP_Processor_Object.HTTPServer, myChannel.ServiceID, myChannel.isRTP);
                    lock (internal_HTTP_Processor_Object.HTTPServer.MulticastProcessorList.SyncRoot)
                    {
                        // add him to the global list
                        internal_HTTP_Processor_Object.HTTPServer.MulticastProcessorList.Add(myChannel.ServiceID, internal_Multicast_Processor_Object);
                    }

                    lock (internal_Multicast_Processor_Object.ReceiverList.SyncRoot)
                    {
                        internal_Multicast_Processor_Object.ReceiverList.Add(myID, this);
                    }
                    Thread thread = new Thread(new ThreadStart(internal_Multicast_Processor_Object.Go));
                    thread.Start();
                }
            }
            #endregion
        }