Ejemplo n.º 1
0
        public Stats()
        {
            log.Debug("Initializing stats service");
            StreamReader sr = null;

            try
            {
                sr = new StreamReader(FFRest.config["statsfile"]);
                if (!int.TryParse(sr.ReadLine(), out totalJobs))
                {
                    totalJobs = 0;
                }
                if (!int.TryParse(sr.ReadLine(), out totalFilesTranscoded))
                {
                    totalFilesTranscoded = 0;
                }
            }
            catch (Exception e)
            {
                log.Error("Exception in file loading occured", e);
                totalJobs            = 0;
                totalFilesTranscoded = 0;
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
            }

            runningJobs = 0;
            cancelToken = new CancellationTokenSource();
            TaskExecutorFactory.Begin(SaveFile, 100000, 100, Timeout.Infinite, -1, cancelToken.Token);
        }
Ejemplo n.º 2
0
        public void Begin()
        {
            try
            {
                log.Debug("Starting processoring");
                config = ConfigurationManager.AppSettings;
                host   = ConfigurationManager.AppSettings["bindhost"];
                port   = int.Parse(ConfigurationManager.AppSettings["bindport"]);
                stats  = new Stats();
                //BT = new BatchTranscoder();
                //LS = new ListenServer(host, port, BT);
                presets = new Presets();
                Dictionary <string, IHttpRequestHandler> handlers = new Dictionary <string, IHttpRequestHandler>();

                jobs = new ConcurrentDictionary <string, TranscodeJob>();

                expireCancelToken = new CancellationTokenSource();
                TaskExecutorFactory.Begin(ExpireJobs, 300000, 100, Timeout.Infinite, -1, expireCancelToken.Token);

                transcodingPool = new Sprite.ThreadPool(int.Parse(ConfigurationManager.AppSettings["maxtasks"]), Sprite.WaitStrategy.MODERATE);


                Directory.CreateDirectory(FFRest.config["file-root"] + Path.DirectorySeparatorChar + FFRest.config["thumb-destination"]);
                Directory.CreateDirectory(FFRest.config["file-root"] + Path.DirectorySeparatorChar + FFRest.config["video-destination"]);


                // Initialize all the endpoint handlers
                var jobHandler      = new JobHandler(jobs, transcodingPool);
                var presetHandler   = new PresetHandler(presets);
                var thumbHandler    = new ThumbnailHandler();
                var adaptiveHandler = new AdaptiveHandler(jobHandler.Jobs);
                var metaHandler     = new MetaHandler();
                var videoHandler    = new VideoHandler();
                handlers.Add("/stats", stats);
                handlers.Add("/jobs", jobHandler);
                handlers.Add("/presets", presetHandler);
                handlers.Add("/thumbs", thumbHandler);
                handlers.Add("/videos", videoHandler);
                handlers.Add("/playlist", adaptiveHandler);
                handlers.Add("/metadata", metaHandler);
                Server server = new Server(host, port, handlers);


                //server = new Httpd(5120, handlers);
                thread = new Thread(new ThreadStart(server.Listen));
                thread.Start();
                transcodingPool.StartPool();
            }
            catch (Exception ex)
            {
                log.Fatal("A fatal exception has occured", ex);
            }
        }
Ejemplo n.º 3
0
        public Presets()
        {
            presets = new ConcurrentDictionary <string, string>();

            // Check if we have an existing preset file
            if (File.Exists("presets.json"))
            {
                FastSerialize.Serializer serializer = new FastSerialize.Serializer(typeof(FastSerialize.JsonSerializerGeneric));
                StreamReader             sr         = new StreamReader(File.Open("presets.json", FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
                string data = sr.ReadToEnd();
                sr.Close();

                Dictionary <string, string> saved = serializer.Deserialize <Dictionary <string, string> >(data);
                foreach (var val in saved)
                {
                    presets.TryAdd(val.Key, val.Value);
                }
            }
            cancelToken = new CancellationTokenSource();
            // Start a background task to save the preset file on a regular basis
            presetSaveTask = TaskExecutorFactory.Begin(SaveAll, 5000, 100, Timeout.Infinite, -1, cancelToken.Token);
        }