mirror of
https://github.com/DigitalDevices/octonet.git
synced 2023-10-10 11:36:52 +00:00
added octoserve
This commit is contained in:
12
octoserve/var/mcsetup/astra19e.csv
Normal file
12
octoserve/var/mcsetup/astra19e.csv
Normal file
@@ -0,0 +1,12 @@
|
||||
TITLE,REQUEST,PIDS,LANPORTS
|
||||
"Das Erste","?src=1&freq=11837&msys=dvbs&sr=27500&pol=h","P0:100:101:104:102:103:106",""
|
||||
"Bayerisches FS Nord","-","P0:500:201:204:202:203:206",""
|
||||
"hr-fernsehen","-","P0:300:301:304:302:303",""
|
||||
"SWR Fernsehen BW","-","P0:800:801:804:802:803:806",""
|
||||
"WDR Köln","-","P0:600:601:604:602:603",""
|
||||
"ZDF","?src=1&freq=11954&msys=dvbs&sr=27500&pol=h","P0:100:110:130:120:121:122:125",""
|
||||
"zdf neo","-","P0:650:660:680:670:671:672:675",""
|
||||
"zdf kultur","-","P0:1100:1110:1130:1120:1121:1122:1125",""
|
||||
"ZDFInfo","-","P0:600:610:630:620:621:622:625",""
|
||||
"KiKA","-","P0:300:310:330:320:321:325","L3:4:5"
|
||||
"3sat","-","P0:200:210:230:220:221:222:225",""
|
|
13
octoserve/var/mcsetup/kabelbw.csv
Normal file
13
octoserve/var/mcsetup/kabelbw.csv
Normal file
@@ -0,0 +1,13 @@
|
||||
TITLE,REQUEST,PIDS,LANPORTS
|
||||
"Das Erste","?freq=346&msys=dvbc&sr=6900&mtype=256qam","P0:100:101:104:102:103:106",""
|
||||
"Bayerisches FS Nord","-","P0:500:201:204:202:203:206",""
|
||||
"hr-fernsehen","-","P0:300:301:304:302:303",""
|
||||
"SWR Fernsehen BW","-","P0:800:801:804:802:803:806",""
|
||||
"WDR Köln","-","P0:600:601:604:602:603",""
|
||||
"ZDF","?freq=370&msys=dvbc&sr=6900&mtype=256qam","P0:100:110:130:120:121:122:125",""
|
||||
"ZDF HD","-","P0:6100:6110:6130:6120:6121:6122:6123",""
|
||||
"zdf neo","-","P0:650:660:680:670:671:672:675",""
|
||||
"zdf kultur","-","P0:1100:1110:1130:1120:1121:1122:1125",""
|
||||
"ZDFInfo","-","P0:600:610:630:620:621:622:625",""
|
||||
"KiKA","-","P0:300:310:330:320:321:325","L3:4:5"
|
||||
"3sat","-","P0:200:210:230:220:221:222:225",""
|
|
13
octoserve/var/mcsetup/kabelbw_udp.csv
Normal file
13
octoserve/var/mcsetup/kabelbw_udp.csv
Normal file
@@ -0,0 +1,13 @@
|
||||
TITLE,REQUEST,PIDS,PROTO,IP,PORT,TTL,LANPORTS
|
||||
"Das Erste","?freq=346&msys=dvbc&sr=6900&mtype=256qam","P0:100:101:104:102:103:106","UDP","239.7.7.100",1234,7,""
|
||||
"Bayerisches FS Nord","-","P0:500:201:204:202:203:206","UDP","239.7.7.101",1234,7,""
|
||||
"hr-fernsehen","-","P0:300:301:304:302:303","UDP","239.7.7.102",1234,7,""
|
||||
"SWR Fernsehen BW","-","P0:800:801:804:802:803:806","UDP","239.7.7.103",1234,7,""
|
||||
"WDR Köln","-","P0:600:601:604:602:603","UDP","239.7.7.104",1234,7,""
|
||||
"ZDF","?freq=370&msys=dvbc&sr=6900&mtype=256qam","P0:100:110:130:120:121:122:125","UDP","239.7.8.100",1234,7,""
|
||||
"ZDF HD","-","P0:6100:6110:6130:6120:6121:6122:6123","UDP","239.7.8.101",1234,7,""
|
||||
"zdf neo","-","P0:650:660:680:670:671:672:675","UDP","239.7.8.102",1234,7,""
|
||||
"zdf kultur","-","P0:1100:1110:1130:1120:1121:1122:1125","UDP","239.7.8.103",1234,7,""
|
||||
"ZDFInfo","-","P0:600:610:630:620:621:622:625","UDP","239.7.8.104",1234,7,""
|
||||
"KiKA","-","P0:300:310:330:320:321:325","UDP","239.7.8.105",1234,7,"L3:4:5"
|
||||
"3sat","-","P0:200:210:230:220:221:222:225","UDP","239.7.8.106",1234,7,""
|
|
251
octoserve/var/mcsetup/mc.lua
Normal file
251
octoserve/var/mcsetup/mc.lua
Normal file
@@ -0,0 +1,251 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
mc = {}
|
||||
|
||||
local DebugFlag = true
|
||||
|
||||
function mc.CheckSignal()
|
||||
local tmp = io.open("/tmp/mc.signal")
|
||||
if tmp then
|
||||
tmp:close()
|
||||
os.remove("/tmp/mc.signal")
|
||||
return true
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function mc:ReadSetupFile(filename)
|
||||
local list = {}
|
||||
local file = io.open(filename,"r")
|
||||
print(filename,file)
|
||||
if file then
|
||||
local line = file:read()
|
||||
if line then
|
||||
if DebugFlag then print(line) end
|
||||
line = string.gsub(line,'"','')
|
||||
if line:match("TITLE,REQUEST,PIDS,LANPORTS") then
|
||||
while true do
|
||||
line = file:read()
|
||||
if not line then break end
|
||||
if DebugFlag then print(line) end
|
||||
local title,request,pids,lanports = line:match('%"(.*)%",%"(.*)%",%"P(%a-[%d%:]-)%",%"L(%a-[%d%:]-)%"')
|
||||
if not title then
|
||||
title,request,pids = line:match('%"(.*)%",%"(.*)%",%"P(%a-[%d%:]-)%"')
|
||||
end
|
||||
if not title or not request or not pids then
|
||||
break
|
||||
end
|
||||
if pids == "" then break end
|
||||
|
||||
pids = string.gsub(pids,":",",")
|
||||
if lanports then
|
||||
lanports = string.gsub(lanports,":",",")
|
||||
if lanports == "" then lanports = nil end
|
||||
if lanports == "all" then lanports = "1,2,3,4,5" end
|
||||
end
|
||||
local url
|
||||
if request == "" or string.sub(request,1,1) ~= "?" then
|
||||
url = "stream=%d?pids=" .. pids
|
||||
else
|
||||
url = request .. "&pids=" .. pids
|
||||
end
|
||||
table.insert(list,{ url = url, lanports = lanports })
|
||||
end
|
||||
elseif line:match("TITLE,REQUEST,PIDS,PROTO,IP,PORT,TTL,LANPORTS") then
|
||||
while true do
|
||||
line = file:read()
|
||||
if not line then break end
|
||||
if DebugFlag then print(line) end
|
||||
local title,request,pids,proto,ip,port,ttl,lanports = line:match('%"(.*)%",%"(.*)%",%"P(%a-[%d%:]-)%",%"(%u%u%u)%",%"(%d*%.%d*%.%d*%.%d*)%",(%d*),(%d*),%"L(%a-[%d%:]-)%"')
|
||||
if not title then
|
||||
title,request,pids,proto,ip,port,ttl = line:match('%"(.*)%",%"(.*)%",%"P(%a-[%d%:]-)%",%"(%u%u%u)%",%"(%d*%.%d*%.%d*%.%d*)%",(%d*),(%d*)')
|
||||
end
|
||||
if not title or not request or not pids then
|
||||
break
|
||||
end
|
||||
if pids == "" then break end
|
||||
if proto ~= "UDP" and proto ~= "RTP" then break end
|
||||
|
||||
pids = string.gsub(pids,":",",")
|
||||
if lanports then
|
||||
lanports = string.gsub(lanports,":",",")
|
||||
if lanports == "" then lanports = nil end
|
||||
if lanports == "all" then lanports = "1,2,3,4,5" end
|
||||
end
|
||||
local url
|
||||
if request == "" or string.sub(request,1,1) ~= "?" then
|
||||
url = "stream=%d?pids=" .. pids
|
||||
else
|
||||
url = request .. "&pids=" .. pids
|
||||
end
|
||||
table.insert(list,{ url = url, proto = proto, ip = ip, port = port, ttl = ttl, lanports = lanports })
|
||||
end
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function mc:Setup(mclist,serverip,devid)
|
||||
local streamid = 0
|
||||
local port = 6670
|
||||
local req = nil
|
||||
local dest = 1
|
||||
local SessionList = {}
|
||||
local entry
|
||||
|
||||
for _,entry in ipairs(mclist) do
|
||||
print("*************************************************************************")
|
||||
req = entry.url
|
||||
local rc = nil
|
||||
local attributes = nil
|
||||
local sdp = nil
|
||||
local server = socket.tcp()
|
||||
server:settimeout(2)
|
||||
local cseq = 1
|
||||
if server:connect(serverip,554) then
|
||||
--local transport = string.format("RTP/AVP;multicast;port=%d-%d;ttl=5",port,port + 1)
|
||||
local destip = string.format("239.%d.2.%d",devid,dest);
|
||||
local destport = port;
|
||||
local ttl = 5
|
||||
if entry.ip then
|
||||
destip = entry.ip
|
||||
end
|
||||
if entry.port then
|
||||
destport = tonumber(entry.port)
|
||||
end
|
||||
if entry.ttl then
|
||||
ttl = tonumber(entry.ttl)
|
||||
end
|
||||
local transport = nil
|
||||
if entry.proto and entry.proto == "UDP" then
|
||||
transport = string.format("UDP;multicast;destination=%s;port=%d;ttl=%d",destip,destport,ttl)
|
||||
else
|
||||
transport = string.format("RTP/AVP;multicast;destination=%s;port=%d-%d;ttl=%d",destip,destport,destport + 1,ttl)
|
||||
end
|
||||
|
||||
-- port = port + 2
|
||||
if string.match(req,"stream") then
|
||||
if streamid > 0 then
|
||||
req = string.format(req,streamid)
|
||||
rtsp:SendRequest(server,serverip,"SETUP",req,cseq,transport)
|
||||
rc,attributes,sdp = rtsp:ReadResponse(server)
|
||||
cseq = cseq + 1
|
||||
if rc == "200" then
|
||||
session = string.match(attributes["SESSION"],"^(%w*);")
|
||||
table.insert(SessionList,{ id = session, streamid = streamid, lanports = entry.lanports })
|
||||
end
|
||||
end
|
||||
else
|
||||
rtsp:SendRequest(server,serverip,"SETUP",req,cseq,transport)
|
||||
rc,attributes,sdp = rtsp:ReadResponse(server)
|
||||
cseq = cseq + 1
|
||||
if rc == "200" then
|
||||
streamid = tonumber(attributes["COM.SES.STREAMID"])
|
||||
session = string.match(attributes["SESSION"],"^(%w*);")
|
||||
table.insert(SessionList,{ id = session, streamid = streamid, lanports = entry.lanports })
|
||||
end
|
||||
end
|
||||
server:close()
|
||||
else
|
||||
print("Connect?")
|
||||
break
|
||||
end
|
||||
if rc ~= "200" then
|
||||
break
|
||||
end
|
||||
dest = dest + 1
|
||||
end
|
||||
return SessionList
|
||||
end
|
||||
|
||||
function mc:Play(SessionList,serverip)
|
||||
if #SessionList > 0 then
|
||||
local index,session
|
||||
for index,session in ipairs(SessionList) do
|
||||
print("*************************************************************************",index)
|
||||
if session.lanports then
|
||||
local server = socket.tcp()
|
||||
server:settimeout(2)
|
||||
if server:connect(serverip,554) then
|
||||
local req = string.format("stream=%d",session.streamid)
|
||||
rtsp:SendRequest(server,serverip,"PLAY",req,1,session.id, "switch="..session.lanports)
|
||||
local rc,attributes,sdp = rtsp:ReadResponse(server)
|
||||
server:close()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function pKeepAlive(mc,SessionList,ip)
|
||||
local index = 1
|
||||
local server = socket.tcp()
|
||||
server:settimeout(2)
|
||||
local cseq = 1
|
||||
print(SessionList,ip)
|
||||
local status = 0
|
||||
if server:connect(ip,554) then
|
||||
while status do
|
||||
socket.select(nil, nil, 3)
|
||||
if mc.CheckSignal() then
|
||||
status = 2
|
||||
break
|
||||
end
|
||||
print("*************************************************",index,SessionList[index].id)
|
||||
local err = rtsp:SendRequest(server,ip,"DESCRIBE",nil,cseq,SessionList[index].id)
|
||||
if err then
|
||||
print(err)
|
||||
break
|
||||
end
|
||||
local rc,attributes,sdp = rtsp:ReadResponse(server)
|
||||
if not rc or rc ~= "200" then
|
||||
break
|
||||
end
|
||||
cseq = cseq + 1
|
||||
index = index + 1
|
||||
if index > #SessionList then
|
||||
index = 1
|
||||
end
|
||||
collectgarbage()
|
||||
end
|
||||
server:close()
|
||||
end
|
||||
return status
|
||||
end
|
||||
|
||||
function mc:KeepAlive(SessionList,serverip)
|
||||
if #SessionList > 0 then
|
||||
local rc,status = pcall(pKeepAlive,mc,SessionList,serverip)
|
||||
if not rc then
|
||||
print(status)
|
||||
return 1
|
||||
else
|
||||
return status
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function mc:TearDown(SessionList,serverip)
|
||||
if #SessionList > 0 then
|
||||
local index,session
|
||||
for index,session in ipairs(SessionList) do
|
||||
print("*************************************************************************",index)
|
||||
local server = socket.tcp()
|
||||
server:settimeout(2)
|
||||
if server:connect(serverip,554) then
|
||||
local req = string.format("stream=%d",session.streamid)
|
||||
rtsp:SendRequest(server,serverip,"TEARDOWN",req,1,session.id)
|
||||
local rc,attributes,sdp = rtsp:ReadResponse(server)
|
||||
server:close()
|
||||
if rc ~= "200" then
|
||||
print("error",rc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return mc
|
112
octoserve/var/mcsetup/mcsetup.lua
Executable file
112
octoserve/var/mcsetup/mcsetup.lua
Executable file
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
local socket = require("socket")
|
||||
local mime = require("mime")
|
||||
local rtsp = require("rtsp")
|
||||
local mc = require("mc")
|
||||
|
||||
local ip = "10.0.4.53"
|
||||
local devid = 5
|
||||
local DoPlay = true
|
||||
local mclist = false
|
||||
local configfile = "/config/mcsetup.csv"
|
||||
local server = false
|
||||
|
||||
local a
|
||||
for _,a in ipairs(arg) do
|
||||
if a == "server" then server = true end
|
||||
if a == "noplay" then DoPlay = false end
|
||||
end
|
||||
|
||||
function GetIPAddr()
|
||||
local myip = nil
|
||||
local ifconfig = io.popen("ifconfig eth0")
|
||||
if ifconfig then
|
||||
local eth0 = ifconfig:read("*a")
|
||||
ifconfig:close()
|
||||
myip = string.match(eth0,"inet addr%:(%d+%.%d+%.%d+%.%d+)")
|
||||
end
|
||||
return myip
|
||||
end
|
||||
|
||||
function GetDevID()
|
||||
local devid = nil
|
||||
local tmp = io.open("/config/device.id")
|
||||
if tmp then
|
||||
devid = tonumber(tmp:read())
|
||||
tmp:close()
|
||||
end
|
||||
return devid
|
||||
end
|
||||
|
||||
function WaitSignal()
|
||||
print("WaitSignal")
|
||||
while true do
|
||||
socket.select(nil,nil,1)
|
||||
end
|
||||
print("Exit WaitSignal")
|
||||
end
|
||||
|
||||
if server then
|
||||
socket.select(nil,nil,10)
|
||||
end
|
||||
|
||||
while true do
|
||||
|
||||
ip = GetIPAddr()
|
||||
devid = GetDevID()
|
||||
print(ip,devid)
|
||||
|
||||
if devid and ip then
|
||||
mclist = mc:ReadSetupFile(configfile)
|
||||
print(mclist,#mclist)
|
||||
if #mclist > 0 then
|
||||
local SessionList = mc:Setup(mclist,ip,devid)
|
||||
if #SessionList > 0 then
|
||||
|
||||
if DoPlay then
|
||||
mc:Play(SessionList,ip)
|
||||
end
|
||||
|
||||
local rc = mc:KeepAlive(SessionList,ip)
|
||||
if rc > 0 then
|
||||
mc:TearDown(SessionList,ip)
|
||||
end
|
||||
if rc == 1 then
|
||||
break
|
||||
end
|
||||
if rc == 0 then
|
||||
socket.select(nil,nil,10)
|
||||
end
|
||||
end
|
||||
else
|
||||
while not mc.CheckSignal() do
|
||||
socket.select(nil,nil,1)
|
||||
end
|
||||
end
|
||||
end
|
||||
collectgarbage()
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- local server = socket.tcp()
|
||||
-- server:settimeout(2)
|
||||
|
||||
-- local cseq = 1
|
||||
|
||||
-- if server:connect(ip,554) then
|
||||
-- rtsp:SendRequest(server,ip,"DESCRIBE",nil,cseq)
|
||||
-- local rc,attributes,sdp = rtsp:ReadResponse(server)
|
||||
-- cseq = cseq + 1
|
||||
-- print(rc)
|
||||
-- for n,a in pairs(attributes) do
|
||||
-- print(n,a)
|
||||
-- end
|
||||
-- if sdp then
|
||||
-- for i,a in ipairs(sdp) do
|
||||
-- print(string.format("%2d:%s",i,a))
|
||||
-- end
|
||||
-- end
|
||||
-- server:close()
|
||||
-- end
|
94
octoserve/var/mcsetup/rtsp.lua
Normal file
94
octoserve/var/mcsetup/rtsp.lua
Normal file
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/lua
|
||||
|
||||
rtsp = {}
|
||||
|
||||
local DebugFlag = true
|
||||
local CRLF = "\r\n"
|
||||
|
||||
local function SplitLines(s)
|
||||
local lines = {}
|
||||
local line = nil
|
||||
for line in string.gmatch(s,"(.-)"..CRLF) do
|
||||
table.insert(lines,line)
|
||||
end
|
||||
return lines
|
||||
end
|
||||
|
||||
function rtsp:ReadResponse(server)
|
||||
|
||||
local linenum = 0
|
||||
local line, err = server:receive()
|
||||
|
||||
if err then
|
||||
if DebugFlag then print("RTSP Error "..err) end
|
||||
return
|
||||
end
|
||||
|
||||
if DebugFlag then print(string.format("%2d:%s",linenum,line)) end
|
||||
local rc = string.match(line,"%s+(%d+)")
|
||||
local attributes = {}
|
||||
|
||||
while true do
|
||||
local line, err = server:receive()
|
||||
if err then
|
||||
if DebugFlag then print("RTSP Error "..err.." Line: "..tostring(linenum)) end
|
||||
return
|
||||
end
|
||||
linenum = linenum + 1
|
||||
if DebugFlag then print(string.format("%2d:%s",linenum,line)) end
|
||||
if line == "" then break end
|
||||
|
||||
if linenum == 30 then
|
||||
if DebugFlag then print("RTSP Error "..tostring(linenum)) end
|
||||
return
|
||||
end
|
||||
|
||||
local n,v = string.match(line,"([%a%-%.]+)%s*%:%s*(.*)")
|
||||
if n and v then
|
||||
attributes[string.upper(n)] = v
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
local sdp = nil
|
||||
local ctype = attributes["CONTENT-TYPE"]
|
||||
if ctype then
|
||||
if string.lower(ctype) == "application/sdp" then
|
||||
local clen = attributes["CONTENT-LENGTH"]
|
||||
line, err = server:receive(tonumber(clen))
|
||||
if err then
|
||||
if DebugFlag then print("RTSP Error "..err.." Line: "..tostring(linenum)) end
|
||||
return
|
||||
else
|
||||
sdp = SplitLines(line)
|
||||
end
|
||||
end
|
||||
end
|
||||
return rc,attributes,sdp
|
||||
end
|
||||
|
||||
function rtsp:SendRequest(server,ip,command,request,cseq,session_transport,x_octonet)
|
||||
if not request then request = "" end
|
||||
local s = command .. " rtsp://"..ip..":554/"..request.." RTSP/1.0" .. CRLF
|
||||
.. "User-Agent: DD_MCSetup" .. CRLF
|
||||
if cseq then s = s .. "Cseq: ".. tostring(cseq)..CRLF end
|
||||
if session_transport then
|
||||
if command == "SETUP" then
|
||||
s = s .. "Transport: "..session_transport..CRLF
|
||||
else
|
||||
s = s .. "Session:" ..session_transport..CRLF
|
||||
end
|
||||
end
|
||||
if x_octonet then
|
||||
s = s .. "x_octonet: "..x_octonet..CRLF
|
||||
end
|
||||
s = s .. CRLF
|
||||
if DebugFlag then print(s) end
|
||||
local r,err = server:send(s)
|
||||
if not r then
|
||||
return err
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
return rtsp
|
13
octoserve/var/mcsetup/unitymedia.csv
Normal file
13
octoserve/var/mcsetup/unitymedia.csv
Normal file
@@ -0,0 +1,13 @@
|
||||
TITLE,REQUEST,PIDS,LANPORTS
|
||||
"Das Erste","?freq=410&msys=dvbc&sr=6900&mtype=256qam","P0:100:101:104:102:103:106",""
|
||||
"Bayerisches FS Nord","-","P0:500:201:204:202:203:206",""
|
||||
"hr-fernsehen","-","P0:300:301:304:302:303",""
|
||||
"SWR Fernsehen BW","-","P0:800:801:804:802:803:806",""
|
||||
"WDR Köln","-","P0:600:601:604:602:603",""
|
||||
"ZDF","?freq=394&msys=dvbc&sr=6900&mtype=256qam","P0:100:110:130:120:121:122:125",""
|
||||
"ZDF HD","-","P0:6100:6110:6130:6120:6121:6122:6123",""
|
||||
"zdf neo","-","P0:650:660:680:670:671:672:675",""
|
||||
"zdf kultur","-","P0:1100:1110:1130:1120:1121:1122:1125",""
|
||||
"ZDFInfo","-","P0:600:610:630:620:621:622:625",""
|
||||
"KiKA","-","P0:300:310:330:320:321:325","L3:4:5"
|
||||
"3sat","-","P0:200:210:230:220:221:222:225",""
|
|
Reference in New Issue
Block a user