Example #1
0
        /// <summary>
        /// Prints out all sources
        /// </summary>
        /// <param name="streamSources">stream sources to print out</param>
        /// <param name="indent">indentation level (in spaces), used for nesting purposes</param>
        private static void PrintSources(StreamSources streamSources, int indent)
        {
            if (streamSources.Count < 1)
            {
                PrintIndent(indent);
                Console.WriteLine("-- no sources --");
                return;
            }

            foreach (StreamSourceInfo i in streamSources.Items)
            {
                PrintIndent(indent);
                Console.WriteLine(String.Format("{0} - {1} ({2}){3}", i.SourceName, i.Description, i.SourceType, (i.Hidden ? " [HIDDEN]" : "")));
                if (i.CameraControl != null)
                {
                    PrintIndent(indent + 2);
                    Console.WriteLine(String.Format("Camera control: {0} address={1}", i.CameraControl.PTZType, i.CameraControl.Address));
                }
                if (i.MicrowaveControl != null)
                {
                    PrintIndent(indent + 2);
                    Console.WriteLine(String.Format("Micro RX control: {0} address={1}", i.MicrowaveControl.ReceiverType, i.MicrowaveControl.Address));
                }
            }
        }
Example #2
0
        /// <summary>
        /// This method uses the OpenGraphRequest to configure the StreamSourceInfo which is then used to
        /// actually open the physical graph.
        /// </summary>
        /// <returns>Returns the StreamSourceInfo neccesary to open the physical graph</returns>
        protected virtual StreamSourceInfo GetSourceConfig()
        {
            StreamSourceInfo sourceConfig;
            StreamSources sources = StreamSources.LoadFromFile();

            if (ClientConnectRequest.SourceName == null)
            {
                throw new ArgumentNullException("ClientConnectRequest.SourceName", "ClientConnectRequest.SourceName cannot be null!");
            }
//            if (ClientConnectRequest.SourceName.Contains(":"))
//            {
//                string[] parts = ClientConnectRequest.SourceName.Split(new char[] { ':' }, 2);
//                string originServerAddress = parts[0];
//                string sourceName = parts[1];
//                AppLogger.Message("OpenGraph is for OriginServer " + originServerAddress);
//                StreamSourceInfo originServerSourceInfo = QueryOriginServers.FindSource(ClientConnectRequest.SourceName);
//                AppLogger.Message("Found originServerSourceInfo; Description = " + originServerSourceInfo.Description);

//                sourceConfig = new StreamSourceInfo(sources.FindSource(CommonStreamService.RestreamerSourceName));
//                sourceConfig.SourceType = SourceType.LTRestreamer;
//                sourceConfig.SourceName = ClientConnectRequest.SourceName;
//                sourceConfig.Description = originServerSourceInfo.Description;
//                sourceConfig.CameraControl = null;  //removes the CameraControl from restreamed streams
//            }
//            else
            {
                sourceConfig = sources.FindSource(ClientConnectRequest.SourceName);
            }

            return(sourceConfig);
        }
Example #3
0
        public ServerInfo GetServerInfoSpecific(int serverParams, int sourceParams)
        {
            AppLogger.Message("ServerConfigService.GetServerInfoSpecific");
            ServerInfo output = new ServerInfo();

            if ((serverParams & RequestedServerInfoParams.RevisionNumber) == RequestedServerInfoParams.RevisionNumber)
            {
                output.RevisionNumber = ServerConfigService.RevisionNumber;
            }
            if (serverParams == RequestedServerInfoParams.RevisionNumber)   //quick optimization to avoid wasting time on "pings"
            {
                return(output);
            }

            if ((serverParams & RequestedServerInfoParams.ServerName) == RequestedServerInfoParams.ServerName)
            {
                output.ServerName = Dns.GetHostName();
            }

            if ((serverParams & RequestedServerInfoParams.ServerAddress) == RequestedServerInfoParams.ServerAddress)
            {
                output.ServerAddress = OperationContext.Current.IncomingMessageHeaders.To.Host;
            }

            if ((serverParams & RequestedServerInfoParams.VersionInfo) == RequestedServerInfoParams.VersionInfo)
            {
                output.VersionInfo = Assembly.GetAssembly(typeof(MediaServer)).ToString();
            }

            if ((serverParams & RequestedServerInfoParams.StreamSources) == RequestedServerInfoParams.StreamSources)
            {
                StreamSources temp;
                CopyStreamSourceInfo(StreamSources.LoadFromFile(), sourceParams, out temp);
                output.StreamSources = temp;
            }

            if ((serverParams & RequestedServerInfoParams.ProfileGroups) == RequestedServerInfoParams.ProfileGroups)
            {
                output.ProfileGroups = ProfileGroups.LoadFromFile();
            }

//            if ((serverParams & RequestedServerInfoParams.OriginServers) == RequestedServerInfoParams.OriginServers)
//            {
//                output.OriginServers = new List<ServerInfo>();
//                if (QueryOriginServers.OriginServers != null)
//                {
//                    foreach (ServerInfo cur in QueryOriginServers.OriginServers)
//                    {
//                        ServerInfo copy;
//                        CopyServerInfo(cur, serverParams, sourceParams, out copy);
//                        output.OriginServers.Add(copy);
//                    }
//                }
//            }

            return(output);
        }
Example #4
0
        /// <summary>
        /// Opens the microwave control service
        /// </summary>
        /// <param name="sourceName">source name to open</param>
        public void Open(ClientConnectRequest request)
        {
            try
            {
                this.clientRequest = request;
                AppLogger.Message(request.UserName + " MicrowaveControlService.Open " + request.SourceName);

                if (!ResourceManager.Acquire <ResourceManager.MutexRule>(request.SourceName,
                                                                         typeof(MicrowaveControlService),
                                                                         request.UserName))
                {
                    string owner = ResourceManager.GetOwner(request.SourceName, typeof(MicrowaveControlService));
                    throw new SourceHasMaxClientsException("The microwave receiver is in use by " + ((owner == null) ? "<unknown>" : owner) + ".");
                }
                resourceAcquired = true;

                StreamSourceInfo sourceConfig = StreamSources.LoadFromFile().FindSource(request.SourceName);
                if (sourceConfig.MicrowaveControl == null)
                {
                    throw new SourceConfigException("Source does not have MicrowaveControl section defined!");
                }
                microwaveConfig = sourceConfig.MicrowaveControl;

                //get client callback
                clientCallback = OperationContext.Current.GetCallbackChannel <IMicrowaveControl2Callback>();

                //create microwave receiver instance
                microwaveReceiver = MicrowaveControlService2.CreateInstance(microwaveConfig);
                if (!microwaveReceiver.Connected)
                {
                    throw new SourceConfigException("Communication with the microwave receiver could not be established.");
                }
                microwaveReceiver.ReceiverTuningChange      += new EventHandler <MicrowaveReceiver.ReceiverEventArgs>(microwaveReceiver_ReceiverTuningChange);
                microwaveReceiver.ReceiverLinkQualityChange += new EventHandler <MicrowaveReceiver.ReceiverEventArgs>(microwaveReceiver_ReceiverLinkQualityChange);
                microwaveReceiver.ReceiverConnectionChange  += new EventHandler(microwaveReceiver_ReceiverConnectionChange);

                scanner = new PeakScan(microwaveReceiver);
                scanner.ScanCompleted += new EventHandler <ScanCompleteEvent>(scanner_ScanCompleted);

                //load cached presets
                LoadSavedPresets();

                microwaveReceiver.StartPollingLinkQuality();
            }
            catch (Exception exc)
            {
                AppLogger.Dump(exc);
                throw;
            }
        }
Example #5
0
        /// <summary>
        /// Attempts to locate a graph in the map, given the source name. Also verifies that the provided
        /// source name has been actually configured in the server's source configuration.
        /// </summary>
        /// <param name="SourceName">source name to retreive</param>
        /// <returns>the graph instance associated with the given source name.</returns>
        /// <exception cref="T:FutureConcepts.Media.SourceConfigException">
        /// Thrown if the given sourcename is not configured in the server's source config
        /// </exception>
        /// <exception cref="T:System.Exception">
        /// Thrown if no such graph has been instantiated; Can also be thrown if the server configuration does not exist.
        /// </exception>
        public static BaseGraph FindGraph(string SourceName)
        {
            StreamSourceInfo source = StreamSources.LoadFromFile().FindSource(SourceName);

            lock (_graphMap)
            {
                BaseGraph graph = _graphMap[source.SourceName];
                if (graph == null)
                {
                    throw new Exception("A graph for source " + SourceName + " does not exist.");
                }
                return(graph);
            }
        }
Example #6
0
        protected BaseGraph OpenGraph()
        {
            AppLogger.Message(String.Format("OpenGraph {0}", ClientConnectRequest.SourceName));

            //retreives the correct source config based on the OpenGraphRequest
            StreamSourceInfo sourceConfig = GetSourceConfig();

            //handles logical groups
            if (sourceConfig.SourceType == SourceType.LogicalGroup)
            {
                StreamSources sources = StreamSources.LoadFromFile();
                foreach (string physicalName in sourceConfig.LogicalGroupSourceNames)
                {
                    StreamSourceInfo physicalSourceConfig = sources.FindSource(physicalName);
                    BaseGraph graph = GraphManager.TryFindGraph(physicalName);
                    if (graph == null)
                    {
                        return(OpenPhysicalGraph(physicalSourceConfig));
                    }
                    else
                    {
                        if (graph.NumberOfClients < physicalSourceConfig.MaxClients)
                        {
                            return(OpenPhysicalGraph(physicalSourceConfig));
                        }
                    }
                }
                throw new Exception("no sources available for " + ClientConnectRequest.SourceName);
            }
            else
            {
                try
                {
                    return(OpenPhysicalGraph(sourceConfig));
                }
                catch (SourceHasMaxClientsException e)
                {
                    throw e;
                }
                catch (Exception exc)
                {
                    AppLogger.Dump(exc);
                    throw new Exception("Source " + ClientConnectRequest.SourceName + " is not currently available", exc);
                }
            }
        }
Example #7
0
        public ServerInfo GetServerInfo()
        {
            AppLogger.Message("ServerConfigService.GetServerInfo");

            ServerInfo serverInfo = new ServerInfo();

            serverInfo.ServerName    = Dns.GetHostName();
            serverInfo.ServerAddress = OperationContext.Current.IncomingMessageHeaders.To.Host;
            serverInfo.VersionInfo   = Assembly.GetAssembly(typeof(MediaServer)).ToString();
            serverInfo.StreamSources = StreamSources.LoadFromFile();
            serverInfo.ProfileGroups = ProfileGroups.LoadFromFile();
//            serverInfo.OriginServers = QueryOriginServers.OriginServers;
            serverInfo.OriginServers  = null;
            serverInfo.RevisionNumber = ServerConfigService.RevisionNumber;

            return(serverInfo);
        }
Example #8
0
        public void Open(ClientConnectRequest request)
        {
            try
            {
                clientRequest = request;
                AppLogger.Message(request.UserName + " CameraControlService.Open " + request.SourceName);

                StreamSourceInfo sourceConfig = StreamSources.LoadFromFile().FindSource(request.SourceName);
                if (sourceConfig.CameraControl == null)
                {
                    throw new SourceConfigException("Source does not have CameraControl defined!");
                }

                //lock against the camera control address -- this allows multiple sources to share the same camera.
                //    if the particular camera control does not require an address, then lock against the source name
                this.ResourceID = string.IsNullOrEmpty(sourceConfig.CameraControl.Address) ?
                                  request.SourceName :
                                  sourceConfig.CameraControl.Address;

                if (!ResourceManager.Acquire <ResourceManager.MutexRule>(this.ResourceID,
                                                                         typeof(CameraControlService),
                                                                         request.UserName))
                {
                    string owner = ResourceManager.GetOwner(this.ResourceID, typeof(CameraControlService));
                    throw new SourceHasMaxClientsException("The camera control is in use by " +
                                                           (string.IsNullOrEmpty(owner) ? "<unknown>" : owner) + ".");
                }
                resourceAcquired = true;

                CameraControl = sourceConfig.CameraControl;
                Plugin        = CameraControls.PluginFactory.Create(CameraControl, this);
                LoadSavedPositions();
            }
            catch (Exception exc)
            {
                AppLogger.Dump(exc);
                //throw new Exception("Unable to open camera control for " + sourceName, exc);
                throw;
            }
        }
Example #9
0
 public static void StartPushGraphs()
 {
     try
     {
         StreamSources streamSources = StreamSources.LoadFromFile(false);
         StartSources  startSources  = StartSources.LoadFromFile(false);
         if ((streamSources != null) && (startSources != null))
         {
             foreach (StartSource startSource in startSources.Items)
             {
                 StreamSourceInfo streamSourceInfo = streamSources.FindSource(startSource.SourceName);
                 if (streamSourceInfo != null)
                 {
                     AppLogger.Message(String.Format("Starting source {0}", streamSourceInfo.SourceName));
                     if (streamSourceInfo.DeviceAddress != null)
                     {
                         AppLogger.Message(String.Format("Starting Channel={0} Input={1}", streamSourceInfo.DeviceAddress.Channel, streamSourceInfo.DeviceAddress.Input));
                     }
                     OpenGraphRequest openGraphRequest = new OpenGraphRequest();
                     openGraphRequest.Id         = Guid.NewGuid();
                     openGraphRequest.SourceName = streamSourceInfo.SourceName;
                     openGraphRequest.UserName   = "******";
                     BaseGraph graph = BaseGraph.CreateInstance(streamSourceInfo, openGraphRequest);
                     graph.Run();
                     if (graph != null)
                     {
                         _graphMap.Add(streamSourceInfo.SourceName, graph);
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         AppLogger.Dump(e);
     }
 }
Example #10
0
 public static void StartGraph(string sourceName)
 {
     if (_graphMap.ContainsKey(sourceName) == false)
     {
         StreamSources streamSources = StreamSources.LoadFromFile(false);
         if (streamSources != null)
         {
             StreamSourceInfo streamSourceInfo = streamSources.FindSource(sourceName);
             if (streamSourceInfo != null)
             {
                 OpenGraphRequest openGraphRequest = new OpenGraphRequest();
                 openGraphRequest.Id         = Guid.NewGuid();
                 openGraphRequest.SourceName = streamSourceInfo.SourceName;
                 openGraphRequest.UserName   = "******";
                 BaseGraph graph = BaseGraph.CreateInstance(streamSourceInfo, openGraphRequest);
                 graph.Run();
                 if (graph != null)
                 {
                     _graphMap.Add(streamSourceInfo.SourceName, graph);
                 }
             }
         }
     }
 }
Example #11
0
 public void PutStreamSources(StreamSources streamSources)
 {
     StreamSources.SaveToFile(streamSources);
 }
Example #12
0
        /// <summary>
        /// This method strips out info *not* requested from the given requested stream source info params
        /// </summary>
        /// <param name="streamSources">collection of stream sources to cleanse</param>
        /// <param name="sourceParams">the source parameters to keep</param>
        private void CopyStreamSourceInfo(StreamSources input, int sourceParams, out StreamSources output)
        {
            output = new StreamSources();

            if (input.Count < 1)
            {
                return;
            }

            //the numeric/primitive values used below are the ones set as the DefaultValue() in the attributes.
            //when this value is used, then no XML is generated

            foreach (StreamSourceInfo inSource in input.Items)
            {
                StreamSourceInfo outSource = new StreamSourceInfo();

                if ((sourceParams & RequestedStreamSourceInfoParams.CameraControl) == RequestedStreamSourceInfoParams.CameraControl)
                {
                    outSource.CameraControl = inSource.CameraControl;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.Description) == RequestedStreamSourceInfoParams.Description)
                {
                    outSource.Description = inSource.Description;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.DeviceAddress) == RequestedStreamSourceInfoParams.DeviceAddress)
                {
                    outSource.DeviceAddress = inSource.DeviceAddress;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.LiveSource) == RequestedStreamSourceInfoParams.LiveSource)
                {
                    outSource.LiveSource = inSource.LiveSource;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.LogicalGroupSourceNames) == RequestedStreamSourceInfoParams.LogicalGroupSourceNames)
                {
                    outSource.LogicalGroupSourceNames = inSource.LogicalGroupSourceNames;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.MaxClients) == RequestedStreamSourceInfoParams.MaxClients)
                {
                    outSource.MaxClients = inSource.MaxClients;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.MaxQueueDuration) == RequestedStreamSourceInfoParams.MaxQueueDuration)
                {
                    outSource.MaxQueueDuration = inSource.MaxQueueDuration;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.MaxRecordingChunkMinutes) == RequestedStreamSourceInfoParams.MaxRecordingChunkMinutes)
                {
                    outSource.MaxRecordingChunkMinutes = inSource.MaxRecordingChunkMinutes;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.MicrowaveControl) == RequestedStreamSourceInfoParams.MicrowaveControl)
                {
                    if (inSource.MicrowaveControl != null)
                    {
                        outSource.MicrowaveControl = new MicrowaveControlInfo(inSource.MicrowaveControl);
                        //HACK only return the well-known data
                        outSource.MicrowaveControl.BlockDownConverterFrequency = 0;
                        outSource.MicrowaveControl.ReceiverType = MicrowaveReceiverType.PMR_AR100;
                    }
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.ProfileGroupNames) == RequestedStreamSourceInfoParams.ProfileGroupNames)
                {
                    outSource.ProfileGroupNames = inSource.ProfileGroupNames;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.URLs) == RequestedStreamSourceInfoParams.URLs)
                {
//                    outSource.ClientURL = inSource.ClientURL;
//                    outSource.DirectURL = inSource.DirectURL;
                    outSource.SinkAddress = inSource.SinkAddress;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.SourceName) == RequestedStreamSourceInfoParams.SourceName)
                {
                    outSource.SourceName = inSource.SourceName;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.SourceType) == RequestedStreamSourceInfoParams.SourceType)
                {
                    outSource.SourceType = inSource.SourceType;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.SyncToleranceMilliseconds) == RequestedStreamSourceInfoParams.SyncToleranceMilliseconds)
                {
                    outSource.SyncToleranceMilliseconds = inSource.SyncToleranceMilliseconds;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.TVTuner) == RequestedStreamSourceInfoParams.TVTuner)
                {
                    outSource.TVTuner = inSource.TVTuner;
                }
                if ((sourceParams & RequestedStreamSourceInfoParams.Hidden) == RequestedStreamSourceInfoParams.Hidden)
                {
                    outSource.Hidden = inSource.Hidden;
                }

                output.Add(outSource);
            }
        }
Example #13
0
 /// <summary>
 /// Updates the StreamSources on the server
 /// </summary>
 /// <param name="streamSources"><see cref="T:StreamSources">StreamSources</see> object to use on the server</param>
 public void PutStreamSources(StreamSources streamSources)
 {
     Proxy.PutStreamSources(streamSources);
 }