[SCM] crtmpserver/master: Add basic Lua configuration scripts

jet-guest at users.alioth.debian.org jet-guest at users.alioth.debian.org
Sun Oct 9 21:04:39 UTC 2011


The following commit has been merged in the master branch:
commit 03989bccb0cffa90703e280a91a3e4ecc59b833f
Author: Andriy Beregovenko <jet at jet.kiev.ua>
Date:   Sun Oct 9 23:58:11 2011 +0300

    Add basic Lua configuration scripts
    
    This is first part of scripts that provides flexible configuration layer.
    It allows to configure application(modules for crtmpserver daemon) in
    separated file. So main configuration script "crtmpserver.lua" only reads
    applications list(enabled_applications.conf) and try to load its Lua scripts.

diff --git a/debian/crtmpserver-apps-scripts/appselector.lua b/debian/crtmpserver-apps-scripts/appselector.lua
new file mode 100644
index 0000000..3f585d6
--- /dev/null
+++ b/debian/crtmpserver-apps-scripts/appselector.lua
@@ -0,0 +1,53 @@
+application = 
+{
+	-- The name of the application. It is mandatory and must be unique 
+	name = "appselector",
+	-- Short description of the application. Optional
+	description = "Application for selecting the rest of the applications",
+	-- The type of the application. Possible values are:
+	-- dynamiclinklibrary - the application is a shared library
+	protocol = "dynamiclinklibrary",
+	-- the complete path to the library. This is optional. If not provided, 
+	-- the server will try to load the library from here
+	-- <rootDirectory>/<name>/lib<name>.{so|dll|dylib}
+	-- library="/some/path/to/some/shared/library.so"
+	
+	-- Tells the server to validate the clien's handshake before going further. 
+	-- It is optional, defaulted to true
+	validateHandshake = true,
+	-- this is the folder from where the current application gets it's content.
+	-- It is optional. If not specified, it will be defaulted to:
+	-- <rootDirectory>/<name>/mediaFolder
+	-- mediaFolder="/some/directory/where/media/files/are/stored"
+	-- the application will also be known by that names. It is optional
+	--aliases=
+	--{
+	--	"simpleLive",
+	--	"vod",
+	--	"live",
+	--},
+	-- This flag designates the default application. The default application
+	-- is responsable of analyzing the "connect" request and distribute 
+	-- the future connection to the correct application.
+	default = true,
+	acceptors = 
+	{
+		{
+			ip = "0.0.0.0",
+			port = 1935,
+			protocol = "inboundRtmp"
+		},
+		{
+			ip = "0.0.0.0",
+			port = 8080,
+			protocol = "inboundRtmpt"
+		},
+		--[[{
+			ip = "0.0.0.0",
+			port = 8081,
+			protocol = "inboundRtmps",
+			sslKey = "server.key",
+			sslCert = "server.crt"
+		},]]--
+	}
+}
diff --git a/debian/crtmpserver-scripts/crtmpserver.lua b/debian/crtmpserver-scripts/crtmpserver.lua
new file mode 100644
index 0000000..5654240
--- /dev/null
+++ b/debian/crtmpserver-scripts/crtmpserver.lua
@@ -0,0 +1,101 @@
+
+
+confdir = "/etc/crtmpserver"
+libdir = "/usr/lib/crtmpserver"
+
+enabled_apps = confdir.."/enabled_applications.conf"
+app_lib_path = libdir.."/applications"
+logger_config_path = confdir.."/log_appenders.lua"
+
+-- Print anything - including nested tables                                                                                                                           
+function table_print (tt, indent, done)                                                                                                                               
+	done = done or {}                                                                                                                                             
+	indent = indent or 0                                                                                                                                          
+	if type(tt) == "table" then                                                                                                                                   
+		for key, value in pairs (tt) do                                                                                                                               
+			io.write(string.rep (" ", indent)) -- indent it                                                                                               
+			if type (value) == "table" and not done [value] then                                                                                          
+				done [value] = true                                                                                                                   
+				io.write(string.format("[%s] => table\n", tostring (key)));                                                                           
+				io.write(string.rep (" ", indent+4)) -- indent it                                                                                     
+				io.write("(\n");                                                                                                                      
+				table_print (value, indent + 7, done)                                                                                                 
+				io.write(string.rep (" ", indent+4)) -- indent it                                                                                     
+				io.write(")\n");                                                                                                                      
+			else                                                                                                                                          
+				io.write(string.format("[%s] => %s\n",                                                                                                
+				tostring (key), tostring(value)))                                                                                                     
+			end                                                                                                                                           
+		end                                                                                                                                                   
+	else                                                                                                                                                          
+		io.write(tt .. "\n")                                                                                                                                  
+	end                                                                                                                                                           
+end
+
+function exists(fname)
+	local f = io.open(fname, "r")
+	if (f) then 
+		return true
+	else
+		return false
+	end
+end
+
+-- Function generate "logAppenders" section for crtmpserver
+function read_logappenders()
+	result = {}
+	dofile(logger_config_path)
+	result = logAppenders
+	return result
+end
+
+-- Function generate "applications" section for crtmpserver
+-- Reads apps Lua script to main configuration section
+function read_applications()
+	result = {}
+	local app_config
+	-- Must specify whre application libs can be found
+	result.rootDirectory = app_lib_path
+	
+	-- Loads applications configuration listed in file "enabled_apps"
+	for app in io.lines(enabled_apps) do
+		if ( app:match("^#.*$") or app:match("^$") or app:match("^\s+$") ) then
+			--print("string '"..app.."' is unneeded, skip it")
+		else
+			app_config = confdir.."/applications/"..app..".lua"
+			if (not exists(app_config)) then
+				print("Application configuration file '"..app_config.."' not found")
+				os.exit()
+			end
+			dofile(app_config)
+			table.insert(result, application)
+		end
+	end
+	return result
+end
+
+-- Check if logger configuration exists
+if (not exists(logger_config_path)) then
+	print("Logger configuration file '"..logger_config_path.."' not found");
+	return
+end
+
+-- Check if list of applications exists
+if (not exists(enabled_apps)) then
+	print("Applications list file '"..enabled_apps.."' not found");
+	return
+end
+
+-- Main section of configuration.
+-- This variable reads by crtmpserver as main configuration section
+-- It must be always defined
+configuration =
+{
+	daemon = true,
+	pathSeparator = "/",
+	logAppenders = read_logappenders(),
+	applications = read_applications()
+}
+print("__________________________")
+table_print(configuration)
+print("__________________________")
diff --git a/debian/crtmpserver-scripts/enabled_applications.conf b/debian/crtmpserver-scripts/enabled_applications.conf
new file mode 100644
index 0000000..7944d40
--- /dev/null
+++ b/debian/crtmpserver-scripts/enabled_applications.conf
@@ -0,0 +1,6 @@
+######
+# Here must be placed 
+# list of enabled applications
+# it will reads by configuration script
+# and will be loaded correspondisn applications
+appselector
diff --git a/debian/crtmpserver-scripts/log_appenders.lua b/debian/crtmpserver-scripts/log_appenders.lua
new file mode 100644
index 0000000..04d0fd6
--- /dev/null
+++ b/debian/crtmpserver-scripts/log_appenders.lua
@@ -0,0 +1,25 @@
+-- Configuration for LogAppender subsystem of crtmpserver
+
+logAppenders=
+{
+	{
+		-- name of the appender. Not too important, but is mandatory
+		name="console appender",
+		-- type of the appender. We can have the following values:
+		-- console, coloredConsole and file
+		-- NOTE: console appenders will be ignored if we run the server
+		-- as a daemon
+		type="coloredConsole",
+		-- the level of logging. 6 is the FINEST message, 0 is FATAL message.
+		-- The appender will "catch" all the messages below or equal to this level
+		-- bigger the level, more messages are recorded
+		level=6
+	},
+	{
+		name="file appender",
+		type="file",
+		level=6,
+		-- the file where the log messages are going to land
+		fileName="/var/log/crtmpserver/main.log"
+	}
+}
\ No newline at end of file

-- 
crtmpserver packaging



More information about the pkg-multimedia-commits mailing list