예제 #1
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);
            }
        }
예제 #2
0
파일: FFRest.cs 프로젝트: cchamplin/FFRest
        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);
            }
        }
예제 #3
0
파일: Server.cs 프로젝트: cchamplin/FFRest
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="host">Host to bind to</param>
        /// <param name="port">Port to bind to</param>
        /// <param name="handlers">List of request handlers</param>
        public Server(string host, int port, Dictionary<string,IHttpRequestHandler> handlers)
        {
            this.handlers = handlers;

            // Initialize our thread pool
            threads = new List<Thread>();
            // Todo the pool size should be based on the number of cores available
            // or a configuration option
            pool = new Sprite.ThreadPool(7,Sprite.WaitStrategy.MODERATE);
            taskSet = new Sprite.TaskSet(pool,Sprite.WaitStrategy.MODERATE);

            // We may need to handle a permission issue here with a prompt on windows machines
            this.listener = new HttpListener();
            this.listener.IgnoreWriteExceptions = true;
            string prefix = "http://" + host + ":" + port + "/";
            this.listener.Prefixes.Add(prefix);

            Thread thread = new Thread(new ThreadStart(this.Process));

            threads.Add(thread);
        }
예제 #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="host">Host to bind to</param>
        /// <param name="port">Port to bind to</param>
        /// <param name="handlers">List of request handlers</param>
        public Server(string host, int port, Dictionary <string, IHttpRequestHandler> handlers)
        {
            this.handlers = handlers;

            // Initialize our thread pool
            threads = new List <Thread>();
            // Todo the pool size should be based on the number of cores available
            // or a configuration option
            pool    = new Sprite.ThreadPool(7, Sprite.WaitStrategy.MODERATE);
            taskSet = new Sprite.TaskSet(pool, Sprite.WaitStrategy.MODERATE);


            // We may need to handle a permission issue here with a prompt on windows machines
            this.listener = new HttpListener();
            this.listener.IgnoreWriteExceptions = true;
            string prefix = "http://" + host + ":" + port + "/";

            this.listener.Prefixes.Add(prefix);

            Thread thread = new Thread(new ThreadStart(this.Process));

            threads.Add(thread);
        }
예제 #5
0
 public JobHandler(ConcurrentDictionary <string, TranscodeJob> jobs, Sprite.ThreadPool pool)
 {
     this.jobs    = jobs;
     this.jobPool = pool;
     rGenerator   = new Random();
 }