public static String ToString(PaparazziResolution r)
        {
            if(r.Equals(PaparazziResolution.R_720p))
            {
                return "720p";
            }
            else if(r.Equals(PaparazziResolution.R_1024x768))
            {
                return "1024x768";
            }

            return "1080p";
        }
        public static Size ToSize(PaparazziResolution r)
        {
            if(r.Equals(PaparazziResolution.R_720p))
            {
                return new Size(1280, 720);
            }
            else if(r.Equals(PaparazziResolution.R_1024x768))
            {
                return new Size(1024, 768);
            }

            return new Size(1920, 1200);
        }
        public static PaparazziResolution FromString(string s, PaparazziResolution _DefaultResolution)
        {
            if (s.Equals("720p"))
            {
                return PaparazziResolution.R_720p;
            }
            else if (s.Equals("1080p"))
            {
                return PaparazziResolution.R_1080p;
            }
            else if (s.Equals("1024x768"))
            {
                return PaparazziResolution.R_1024x768;
            }

            return _DefaultResolution;
        }
        /// <summary>
        /// Starts the server to accepts any new connections on the specified port.
        /// </summary>
        /// <param name="port"></param>
        public void Start(int port, PaparazziResolution resolution)
        {
            lock (this)
            {
                _DefaultResolution = resolution;

                _Thread = new Thread(new ParameterizedThreadStart(ServerThread));
                _Thread.Name = "MjpegServerThread";
                _Thread.IsBackground = true;
                _Thread.Start(port);

                _Thread_Render = new Thread(new ParameterizedThreadStart(RenderThread));
                _Thread_Render.Name = "RenderThread";
                _Thread_Render.IsBackground = true;
                _Thread_Render.Start();
            }
        }
        public void Start(int port, PaparazziResolution resolution)
        {
            lock (this)
            {
                _DefaultResolution = resolution;

                var builder = new ContainerBuilder();
                builder.RegisterInstance<ImageStreamingServer2>(this);
                builder.RegisterApiControllers(typeof(ImageStreamingServer2).Assembly);
                var container = builder.Build();
                var dependencyResolver = new AutofacWebApiDependencyResolver(container);

                var config = new HttpSelfHostConfiguration("http://localhost:" + port)
                {
                    TransferMode = TransferMode.Streamed
                };
                config.DependencyResolver = dependencyResolver;
                config.Routes.MapHttpRoute(
                    "ApiDefault",
                    "{controller}/{resolution}",
                    new { resolution = RouteParameter.Optional });
                config.ReceiveTimeout = TimeSpan.FromHours(1);
                config.SendTimeout = TimeSpan.FromHours(1);
                _Server = new HttpSelfHostServer(config);
                _Server.OpenAsync().Wait();
                Trace.TraceInformation("server is opened");

                _Thread_Render = new Thread(new ParameterizedThreadStart(RenderThread));
                _Thread_Render.Name = "RenderThread";
                _Thread_Render.IsBackground = true;
                _Thread_Render.Start();
            }
        }