├── rtp_aac_export.lua ├── .gitignore ├── README.md ├── rtp_pcma_export.lua ├── rtp_g729_export.lua ├── rtp_pcmu_export.lua ├── rtp_amr_export.lua ├── rtp_ps_export.lua ├── rtp_silk_export.lua ├── rtp_h264_export.lua ├── rtp_h265_export.lua ├── rtp_ps_assemble.lua ├── LICENSE └── rtp_ps_no_assemble.lua /rtp_aac_export.lua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hongch911/WiresharkPlugin/HEAD/rtp_aac_export.lua -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Lua sources 2 | luac.out 3 | 4 | # luarocks build files 5 | *.src.rock 6 | *.zip 7 | *.tar.gz 8 | 9 | # Object files 10 | *.o 11 | *.os 12 | *.ko 13 | *.obj 14 | *.elf 15 | 16 | # Precompiled Headers 17 | *.gch 18 | *.pch 19 | 20 | # Libraries 21 | *.lib 22 | *.a 23 | *.la 24 | *.lo 25 | *.def 26 | *.exp 27 | 28 | # Shared objects (inc. Windows DLLs) 29 | *.dll 30 | *.so 31 | *.so.* 32 | *.dylib 33 | 34 | # Executables 35 | *.exe 36 | *.out 37 | *.app 38 | *.i*86 39 | *.x86_64 40 | *.hex 41 | 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WiresharkPlugin 2 | There is the Video and Audio plugin for Wireshark 3 | 4 | Wireshark的音视频插件 5 | 6 | # 更新说明 7 | 当前版本自测支持WireShark 4.4.0+版本(lua5.4) 8 | 9 | # 文件说明 10 | 11 | > [!IMPORTANT] 12 | > *rtp_ps_no_assemble.lua*不能与*rtp_ps_assemble.lua*同时使用。 13 | > 14 | *rtp_h264_export.lua*用于解析RTP包中的H264编码数据。本插件参考作者HuangQiangxiong(qiangxiong.huang@gmail.com)所作的H264解析插件,并进行了修改。 15 | 16 | *rtp_h265_export.lua*用于解析RTP包中的H265编码数据,并提取裸数据到码流文件中。 17 | 18 | *rtp_ps_no_assemble.lua*为早期的不组合ps,直接对每一个RTP数据进行解析。 19 | 20 | *rtp_ps_assemble.lua*通过把ps流组装完整后解析数据。 21 | 22 | *rtp_ps_export.lua*插件用于实现对PS媒体流进行解析及导出ps裸流到文件中。同时也可以直接使用ps中的相应媒体协议导出媒体数据流。 23 | 24 | *rtp_pcma_export.lua*、*rtp_pcmu_export.lua*、*rtp_silk_export.lua*、*rtp_g729_export.lua*、*rtp_amr_export.lua*等插件用于对RTP流中的相应格式的音频流进行解析并导出成文件。 25 | 26 | 27 | # 加载插件方法 28 | 29 | 在Wireshark的About(关于)页面Folders(文件夹)目录下Personal plugins(个人Lua插件)对应的目录中存放lua插件文件。本方法中的插件只能存放在该的目录下,不能识别该目录下的子目录。 30 | 31 | # 插件中直接播放媒体 32 | 33 | 如果需要在插件中直接播放媒体,需要使用到ffmpeg程序。 34 | 35 | 为了在Wireshark中直接点击插件对话框的 play 按钮进行播放,需要额外准备ffmpeg可执行程序。 36 | 把下载的ffmpeg可执行程序解压后,需设置好系统变量 FFMPEG= ,以便可以直接执行 $FFMPEG/bin/ffmpeg -version或者(%FFMPEG%/bin/ffmpeg -version) ,并正常输出ffmpeg信息。 37 | 38 | 39 | # ffmpeg二进制文件下载 40 | 41 | 下载ffmpeg可执行程序 42 | 从 2020.09.18 开始原来的 https://ffmpeg.zeranoe.com/builds/ 已经彻底关闭 43 | 新的编译下载地址移到 https://github.com/BtbN/FFmpeg-Builds/releases 44 | -------------------------------------------------------------------------------- /rtp_pcma_export.lua: -------------------------------------------------------------------------------- 1 | -- Dump RTP PCM payload to raw file 2 | -- Write it to fromto file. 3 | -- You can access this feature by menu "Tools" 4 | -- Author: Yang Xing (hongch_911@126.com) 5 | ------------------------------------------------------------------------------------------------ 6 | do 7 | local proto_pcm = Proto("pcma", "PCMA") 8 | 9 | local fp_payload = ProtoField.bytes("pcma.payload", "Raw") 10 | 11 | proto_pcm.fields = { 12 | fp_payload 13 | } 14 | 15 | -- Wireshark对每个相关数据包调用该函数 16 | -- tvb:Testy Virtual Buffer报文缓存; pinfo:packet infomarmation报文信息; treeitem:解析树节点 17 | function proto_pcm.dissector(tvb, pinfo, tree) 18 | -- add proto item to tree 19 | local proto_tree = tree:add(proto_pcm, tvb()) 20 | proto_tree:append_text(string.format(" (Len: %d)",tvb:len())) 21 | pinfo.columns.protocol = "PCMA" 22 | end 23 | 24 | -- register this dissector to specific payload type (specified in preferences windows) 25 | local payload_type_table = DissectorTable.get("rtp.pt") 26 | function proto_pcm.init() 27 | payload_type_table:add(8, proto_pcm) 28 | end 29 | 30 | function get_temp_path() 31 | local tmp = nil 32 | if tmp == nil or tmp == '' then 33 | tmp = os.getenv('HOME') 34 | if tmp == nil or tmp == '' then 35 | tmp = os.getenv('USERPROFILE') 36 | if tmp == nil or tmp == '' then 37 | tmp = persconffile_path('temp') 38 | else 39 | tmp = tmp .. "/wireshark_temp" 40 | end 41 | else 42 | tmp = tmp .. "/wireshark_temp" 43 | end 44 | end 45 | return tmp 46 | end 47 | 48 | -- 导出数据到文件部分 49 | -- for geting data (the field's value is type of ByteArray) 50 | local f_data = Field.new("pcma") 51 | 52 | local filter_string = nil 53 | 54 | -- menu action. When you click "Tools" will run this function 55 | local function export_data_to_file() 56 | -- window for showing information 57 | local tw = TextWindow.new("Export File Info Win") 58 | 59 | -- add message to information window 60 | function twappend(str) 61 | tw:append(str) 62 | tw:append("\n") 63 | end 64 | 65 | -- temp path 66 | local temp_path = get_temp_path() 67 | 68 | -- variable for storing rtp stream and dumping parameters 69 | local stream_infos = nil 70 | 71 | -- trigered by all ps packats 72 | local list_filter = '' 73 | if filter_string == nil or filter_string == '' then 74 | list_filter = "pcma" 75 | elseif string.find(filter_string,"pcma")~=nil then 76 | list_filter = filter_string 77 | else 78 | list_filter = "pcma && "..filter_string 79 | end 80 | twappend("Listener filter: " .. list_filter .. "\n") 81 | local my_tap = Listener.new("frame", list_filter) 82 | 83 | -- get rtp stream info by src and dst address 84 | function get_stream_info(pinfo) 85 | local key = "from_" .. tostring(pinfo.src) .. "_" .. tostring(pinfo.src_port) .. "_to_" .. tostring(pinfo.dst) .. "_" .. tostring(pinfo.dst_port) 86 | key = key:gsub(":", ".") 87 | local stream_info = stream_infos[key] 88 | if not stream_info then -- if not exists, create one 89 | stream_info = { } 90 | stream_info.filename = key.. ".pcma.raw" 91 | -- stream_info.file = io.open(stream_info.filename, "wb") 92 | if not Dir.exists(temp_path) then 93 | Dir.make(temp_path) 94 | end 95 | stream_info.filepath = temp_path.."/"..stream_info.filename 96 | stream_info.file,msg = io.open(temp_path.."/"..stream_info.filename, "wb") 97 | if msg then 98 | twappend("io.open "..stream_info.filepath..", error "..msg) 99 | end 100 | stream_infos[key] = stream_info 101 | twappend("Ready to export data (RTP from " .. tostring(pinfo.src) .. ":" .. tostring(pinfo.src_port) 102 | .. " to " .. tostring(pinfo.dst) .. ":" .. tostring(pinfo.dst_port) .. " write to file:[" .. stream_info.filename .. "] ...\n") 103 | end 104 | return stream_info 105 | end 106 | 107 | -- write data to file. 108 | local function write_to_file(stream_info, data_bytes) 109 | stream_info.file:write(data_bytes:raw()) 110 | end 111 | 112 | -- call this function if a packet contains ps payload 113 | function my_tap.packet(pinfo,tvb) 114 | if stream_infos == nil then 115 | -- not triggered by button event, so do nothing. 116 | return 117 | end 118 | local datas = { f_data() } -- using table because one packet may contains more than one RTP 119 | 120 | for i,data_f in ipairs(datas) do 121 | if data_f.len < 1 then 122 | return 123 | end 124 | local data = data_f.range:bytes() 125 | local stream_info = get_stream_info(pinfo) 126 | write_to_file(stream_info, data) 127 | end 128 | end 129 | 130 | -- close all open files 131 | local function close_all_files() 132 | if stream_infos then 133 | local no_streams = true 134 | for id,stream in pairs(stream_infos) do 135 | if stream and stream.file then 136 | stream.file:flush() 137 | stream.file:close() 138 | stream.file = nil 139 | twappend("File [" .. stream.filename .. "] generated OK!") 140 | twappend("ffplay -ar 8000 -ac 1 -f s16le -acodec pcm_alaw -autoexit "..stream.filename) 141 | no_streams = false 142 | end 143 | end 144 | 145 | if no_streams then 146 | twappend("Not found any Data over RTP streams!") 147 | else 148 | tw:add_button("Browser", function () browser_open_data_file(temp_path) end) 149 | end 150 | end 151 | end 152 | 153 | function my_tap.reset() 154 | -- do nothing now 155 | end 156 | 157 | tw:set_atclose(function () 158 | my_tap:remove() 159 | if Dir.exists(temp_path) then 160 | Dir.remove_all(temp_path) 161 | end 162 | end) 163 | 164 | local function export_data() 165 | stream_infos = {} 166 | retap_packets() 167 | close_all_files() 168 | stream_infos = nil 169 | end 170 | 171 | tw:add_button("Export All", function () 172 | export_data() 173 | end) 174 | 175 | tw:add_button("Set Filter", function () 176 | tw:close() 177 | dialog_menu() 178 | end) 179 | end 180 | 181 | local function dialog_func(str) 182 | filter_string = str 183 | export_data_to_file() 184 | end 185 | 186 | function dialog_menu() 187 | new_dialog("Filter Dialog",dialog_func,"Filter") 188 | end 189 | 190 | local function dialog_default() 191 | filter_string = get_filter() 192 | export_data_to_file() 193 | end 194 | 195 | -- Find this feature in menu "Tools" 196 | register_menu("Audio/Export PCMA", dialog_default, MENU_TOOLS_UNSORTED) 197 | end 198 | -------------------------------------------------------------------------------- /rtp_g729_export.lua: -------------------------------------------------------------------------------- 1 | -- Dump RTP G.729 payload to raw file 2 | -- Write it to fromto file. 3 | -- You can access this feature by menu "Tools" 4 | -- Author: Yang Xing (hongch_911@126.com) 5 | ------------------------------------------------------------------------------------------------ 6 | do 7 | local proto_g729 = Proto("g729", "G.729") 8 | 9 | local fp_payload = ProtoField.bytes("g729.payload", "Raw") 10 | 11 | proto_g729.fields = { 12 | fp_payload 13 | } 14 | 15 | -- Wireshark对每个相关数据包调用该函数 16 | -- tvb:Testy Virtual Buffer报文缓存; pinfo:packet infomarmation报文信息; treeitem:解析树节点 17 | function proto_g729.dissector(tvb, pinfo, tree) 18 | -- add proto item to tree 19 | local proto_tree = tree:add(proto_g729, tvb()) 20 | proto_tree:append_text(string.format(" (Len: %d)",tvb:len())) 21 | pinfo.columns.protocol = "G.729" 22 | end 23 | 24 | -- register this dissector to specific payload type (specified in preferences windows) 25 | local payload_type_table = DissectorTable.get("rtp.pt") 26 | function proto_g729.init() 27 | payload_type_table:add(18, proto_g729) 28 | end 29 | 30 | function get_temp_path() 31 | local tmp = nil 32 | if tmp == nil or tmp == '' then 33 | tmp = os.getenv('HOME') 34 | if tmp == nil or tmp == '' then 35 | tmp = os.getenv('USERPROFILE') 36 | if tmp == nil or tmp == '' then 37 | tmp = persconffile_path('temp') 38 | else 39 | tmp = tmp .. "/wireshark_temp" 40 | end 41 | else 42 | tmp = tmp .. "/wireshark_temp" 43 | end 44 | end 45 | return tmp 46 | end 47 | 48 | -- 导出数据到文件部分 49 | -- for geting data (the field's value is type of ByteArray) 50 | local f_data = Field.new("g729") 51 | 52 | local filter_string = nil 53 | 54 | -- menu action. When you click "Tools" will run this function 55 | local function export_data_to_file() 56 | -- window for showing information 57 | local tw = TextWindow.new("Export File Info Win") 58 | 59 | -- add message to information window 60 | function twappend(str) 61 | tw:append(str) 62 | tw:append("\n") 63 | end 64 | 65 | -- temp path 66 | local temp_path = get_temp_path() 67 | 68 | -- variable for storing rtp stream and dumping parameters 69 | local stream_infos = nil 70 | 71 | -- trigered by all ps packats 72 | local list_filter = '' 73 | if filter_string == nil or filter_string == '' then 74 | list_filter = "g729" 75 | elseif string.find(filter_string,"g729")~=nil then 76 | list_filter = filter_string 77 | else 78 | list_filter = "g729 && "..filter_string 79 | end 80 | twappend("Listener filter: " .. list_filter .. "\n") 81 | local my_tap = Listener.new("frame", list_filter) 82 | 83 | -- get rtp stream info by src and dst address 84 | function get_stream_info(pinfo) 85 | local key = "from_" .. tostring(pinfo.src) .. "_" .. tostring(pinfo.src_port) .. "_to_" .. tostring(pinfo.dst) .. "_" .. tostring(pinfo.dst_port) 86 | key = key:gsub(":", ".") 87 | local stream_info = stream_infos[key] 88 | if not stream_info then -- if not exists, create one 89 | stream_info = { } 90 | stream_info.filename = key.. ".g729" 91 | -- stream_info.file = io.open(stream_info.filename, "wb") 92 | if not Dir.exists(temp_path) then 93 | Dir.make(temp_path) 94 | end 95 | stream_info.filepath = temp_path.."/"..stream_info.filename 96 | stream_info.file,msg = io.open(temp_path.."/"..stream_info.filename, "wb") 97 | if msg then 98 | twappend("io.open "..stream_info.filepath..", error "..msg) 99 | end 100 | stream_infos[key] = stream_info 101 | twappend("Ready to export data (RTP from " .. tostring(pinfo.src) .. ":" .. tostring(pinfo.src_port) 102 | .. " to " .. tostring(pinfo.dst) .. ":" .. tostring(pinfo.dst_port) .. " write to file:[" .. stream_info.filename .. "] ...\n") 103 | end 104 | return stream_info 105 | end 106 | 107 | -- write data to file. 108 | local function write_to_file(stream_info, data_bytes) 109 | stream_info.file:write(data_bytes:raw()) 110 | end 111 | 112 | -- call this function if a packet contains ps payload 113 | function my_tap.packet(pinfo,tvb) 114 | if stream_infos == nil then 115 | -- not triggered by button event, so do nothing. 116 | return 117 | end 118 | local datas = { f_data() } -- using table because one packet may contains more than one RTP 119 | 120 | for i,data_f in ipairs(datas) do 121 | if data_f.len < 1 then 122 | return 123 | end 124 | local data = data_f.range:bytes() 125 | local stream_info = get_stream_info(pinfo) 126 | write_to_file(stream_info, data) 127 | end 128 | end 129 | 130 | -- close all open files 131 | local function close_all_files() 132 | if stream_infos then 133 | local no_streams = true 134 | for id,stream in pairs(stream_infos) do 135 | if stream and stream.file then 136 | stream.file:flush() 137 | stream.file:close() 138 | stream.file = nil 139 | twappend("File [" .. stream.filename .. "] generated OK!") 140 | twappend("ffplay -ar 8000 -ac 1 -f g729 -acodec g729 -autoexit "..stream.filename) 141 | no_streams = false 142 | end 143 | end 144 | 145 | if no_streams then 146 | twappend("Not found any Data over RTP streams!") 147 | else 148 | tw:add_button("Browser", function () browser_open_data_file(temp_path) end) 149 | end 150 | end 151 | end 152 | 153 | function my_tap.reset() 154 | -- do nothing now 155 | end 156 | 157 | tw:set_atclose(function () 158 | my_tap:remove() 159 | if Dir.exists(temp_path) then 160 | Dir.remove_all(temp_path) 161 | end 162 | end) 163 | 164 | local function export_data() 165 | stream_infos = {} 166 | retap_packets() 167 | close_all_files() 168 | stream_infos = nil 169 | end 170 | 171 | tw:add_button("Export All", function () 172 | export_data() 173 | end) 174 | 175 | tw:add_button("Set Filter", function () 176 | tw:close() 177 | dialog_menu() 178 | end) 179 | end 180 | 181 | local function dialog_func(str) 182 | filter_string = str 183 | export_data_to_file() 184 | end 185 | 186 | function dialog_menu() 187 | new_dialog("Filter Dialog",dialog_func,"Filter") 188 | end 189 | 190 | local function dialog_default() 191 | filter_string = get_filter() 192 | export_data_to_file() 193 | end 194 | 195 | -- Find this feature in menu "Tools" 196 | register_menu("Audio/Export G729", dialog_default, MENU_TOOLS_UNSORTED) 197 | end 198 | -------------------------------------------------------------------------------- /rtp_pcmu_export.lua: -------------------------------------------------------------------------------- 1 | -- Dump RTP PCM payload to raw file 2 | -- Write it to fromto file. 3 | -- You can access this feature by menu "Tools" 4 | -- Author: Yang Xing (hongch_911@126.com) 5 | ------------------------------------------------------------------------------------------------ 6 | do 7 | local proto_pcm = Proto("pcmu", "PCMU") 8 | 9 | local fp_payload = ProtoField.bytes("pcmu.payload", "Raw") 10 | 11 | proto_pcm.fields = { 12 | fp_payload 13 | } 14 | 15 | -- Wireshark对每个相关数据包调用该函数 16 | -- tvb:Testy Virtual Buffer报文缓存; pinfo:packet infomarmation报文信息; treeitem:解析树节点 17 | function proto_pcm.dissector(tvb, pinfo, tree) 18 | -- add proto item to tree 19 | local proto_tree = tree:add(proto_pcm, tvb()) 20 | proto_tree:append_text(string.format(" (Len: %d)",tvb:len())) 21 | pinfo.columns.protocol = "PCMU" 22 | end 23 | 24 | -- register this dissector to specific payload type (specified in preferences windows) 25 | local payload_type_table = DissectorTable.get("rtp.pt") 26 | function proto_pcm.init() 27 | payload_type_table:add(0, proto_pcm) 28 | end 29 | 30 | function get_temp_path() 31 | local tmp = nil 32 | if tmp == nil or tmp == '' then 33 | tmp = os.getenv('HOME') 34 | if tmp == nil or tmp == '' then 35 | tmp = os.getenv('USERPROFILE') 36 | if tmp == nil or tmp == '' then 37 | tmp = persconffile_path('temp') 38 | else 39 | tmp = tmp .. "/wireshark_temp" 40 | end 41 | else 42 | tmp = tmp .. "/wireshark_temp" 43 | end 44 | end 45 | return tmp 46 | end 47 | 48 | -- 导出数据到文件部分 49 | -- for geting data (the field's value is type of ByteArray) 50 | local f_data = Field.new("pcmu") 51 | 52 | local filter_string = nil 53 | 54 | -- menu action. When you click "Tools" will run this function 55 | local function export_data_to_file() 56 | -- window for showing information 57 | local tw = TextWindow.new("Export File Info Win") 58 | 59 | -- add message to information window 60 | function twappend(str) 61 | tw:append(str) 62 | tw:append("\n") 63 | end 64 | 65 | -- temp path 66 | local temp_path = get_temp_path() 67 | 68 | -- variable for storing rtp stream and dumping parameters 69 | local stream_infos = nil 70 | 71 | -- trigered by all ps packats 72 | local list_filter = '' 73 | if filter_string == nil or filter_string == '' then 74 | list_filter = "pcmu" 75 | elseif string.find(filter_string,"pcmu")~=nil then 76 | list_filter = filter_string 77 | else 78 | list_filter = "pcmu && "..filter_string 79 | end 80 | twappend("Listener filter: " .. list_filter .. "\n") 81 | local my_tap = Listener.new("frame", list_filter) 82 | 83 | -- get rtp stream info by src and dst address 84 | function get_stream_info(pinfo) 85 | local key = "from_" .. tostring(pinfo.src) .. "_" .. tostring(pinfo.src_port) .. "_to_" .. tostring(pinfo.dst) .. "_" .. tostring(pinfo.dst_port) 86 | key = key:gsub(":", ".") 87 | local stream_info = stream_infos[key] 88 | if not stream_info then -- if not exists, create one 89 | stream_info = { } 90 | stream_info.filename = key.. ".pcmu.raw" 91 | -- stream_info.file = io.open(stream_info.filename, "wb") 92 | if not Dir.exists(temp_path) then 93 | Dir.make(temp_path) 94 | end 95 | stream_info.filepath = temp_path.."/"..stream_info.filename 96 | stream_info.file,msg = io.open(temp_path.."/"..stream_info.filename, "wb") 97 | if msg then 98 | twappend("io.open "..stream_info.filepath..", error "..msg) 99 | end 100 | stream_infos[key] = stream_info 101 | twappend("Ready to export data (RTP from " .. tostring(pinfo.src) .. ":" .. tostring(pinfo.src_port) 102 | .. " to " .. tostring(pinfo.dst) .. ":" .. tostring(pinfo.dst_port) .. " write to file:[" .. stream_info.filename .. "] ...\n") 103 | end 104 | return stream_info 105 | end 106 | 107 | -- write data to file. 108 | local function write_to_file(stream_info, data_bytes) 109 | stream_info.file:write(data_bytes:raw()) 110 | end 111 | 112 | -- call this function if a packet contains ps payload 113 | function my_tap.packet(pinfo,tvb) 114 | if stream_infos == nil then 115 | -- not triggered by button event, so do nothing. 116 | return 117 | end 118 | local datas = { f_data() } -- using table because one packet may contains more than one RTP 119 | 120 | for i,data_f in ipairs(datas) do 121 | if data_f.len < 1 then 122 | return 123 | end 124 | local data = data_f.range:bytes() 125 | local stream_info = get_stream_info(pinfo) 126 | write_to_file(stream_info, data) 127 | end 128 | end 129 | 130 | -- close all open files 131 | local function close_all_files() 132 | if stream_infos then 133 | local no_streams = true 134 | for id,stream in pairs(stream_infos) do 135 | if stream and stream.file then 136 | stream.file:flush() 137 | stream.file:close() 138 | stream.file = nil 139 | twappend("File [" .. stream.filename .. "] generated OK!") 140 | twappend("ffplay -ar 8000 -ac 1 -f s16le -acodec pcm_mulaw -autoexit "..stream.filename) 141 | no_streams = false 142 | end 143 | end 144 | 145 | if no_streams then 146 | twappend("Not found any Data over RTP streams!") 147 | else 148 | tw:add_button("Browser", function () browser_open_data_file(temp_path) end) 149 | end 150 | end 151 | end 152 | 153 | function my_tap.reset() 154 | -- do nothing now 155 | end 156 | 157 | tw:set_atclose(function () 158 | my_tap:remove() 159 | if Dir.exists(temp_path) then 160 | Dir.remove_all(temp_path) 161 | end 162 | end) 163 | 164 | local function export_data() 165 | stream_infos = {} 166 | retap_packets() 167 | close_all_files() 168 | stream_infos = nil 169 | end 170 | 171 | tw:add_button("Export All", function () 172 | export_data() 173 | end) 174 | 175 | tw:add_button("Set Filter", function () 176 | tw:close() 177 | dialog_menu() 178 | end) 179 | end 180 | 181 | local function dialog_func(str) 182 | filter_string = str 183 | export_data_to_file() 184 | end 185 | 186 | function dialog_menu() 187 | new_dialog("Filter Dialog",dialog_func,"Filter") 188 | end 189 | 190 | local function dialog_default() 191 | filter_string = get_filter() 192 | export_data_to_file() 193 | end 194 | 195 | -- Find this feature in menu "Tools" 196 | register_menu("Audio/Export PCMU", dialog_default, MENU_TOOLS_UNSORTED) 197 | end 198 | -------------------------------------------------------------------------------- /rtp_amr_export.lua: -------------------------------------------------------------------------------- 1 | -- Dump RTP AMR payload to raw file 2 | -- According to RFC3267 to dissector payload of RTP to NALU 3 | -- The AMR file header (#!AMR\n) 4 | -- +---------------+---------------+---------------+ 5 | -- | 0x23 0x21 | 0x41 0x4d | 0x52 0x0a | 6 | -- | 语音帧1 | 7 | -- | 语音帧2 | 8 | -- | ... | 9 | -- Write it to fromto file. 10 | -- You can access this feature by menu "Tools" 11 | -- Author: Yang Xing (hongch_911@126.com) 12 | ------------------------------------------------------------------------------------------------ 13 | do 14 | 15 | function get_temp_path() 16 | local tmp = nil 17 | if tmp == nil or tmp == '' then 18 | tmp = os.getenv('HOME') 19 | if tmp == nil or tmp == '' then 20 | tmp = os.getenv('USERPROFILE') 21 | if tmp == nil or tmp == '' then 22 | tmp = persconffile_path('temp') 23 | else 24 | tmp = tmp .. "/wireshark_temp" 25 | end 26 | else 27 | tmp = tmp .. "/wireshark_temp" 28 | end 29 | end 30 | return tmp 31 | end 32 | 33 | -- 导出数据到文件部分 34 | local version_str = string.match(_VERSION, "%d+[.]%d*") 35 | local version_num = version_str and tonumber(version_str) or 5.1 36 | -- lua>=5.4 直接使用位操作 37 | -- 使用bit32进行位操作 38 | if (version_num >= 5.4) then 39 | local function band(a,b) 40 | return(a&b) 41 | end 42 | 43 | local function bor(a,b) 44 | return(a|b) 45 | end 46 | 47 | local function lshift(a,b) 48 | return(a<= 5.2) and require("bit32") or require("bit") 52 | end 53 | 54 | -- for geting data (the field's value is type of ByteArray) 55 | local f_data = Field.new("amr") 56 | local f_amr_decode_mode = Field.new("amr.payload_decoded_as") 57 | local f_amr_ft = Field.new("amr.nb.toc.ft") 58 | 59 | local data_vaild_len_vals = { 60 | [0] = 13, 61 | [1] = 14, 62 | [2] = 16, 63 | [3] = 18, 64 | [4] = 20, 65 | [5] = 21, 66 | [6] = 27, 67 | [7] = 32, 68 | [8] = 6 69 | } 70 | 71 | local filter_string = nil 72 | 73 | -- menu action. When you click "Tools" will run this function 74 | local function export_data_to_file() 75 | -- window for showing information 76 | local tw = TextWindow.new("Export File Info Win") 77 | 78 | -- add message to information window 79 | function twappend(str) 80 | tw:append(str) 81 | tw:append("\n") 82 | end 83 | 84 | -- temp path 85 | local temp_path = get_temp_path() 86 | 87 | -- variable for storing rtp stream and dumping parameters 88 | local stream_infos = nil 89 | 90 | -- trigered by all ps packats 91 | local list_filter = '' 92 | if filter_string == nil or filter_string == '' then 93 | list_filter = "amr" 94 | elseif string.find(filter_string,"amr")~=nil then 95 | list_filter = filter_string 96 | else 97 | list_filter = "amr && "..filter_string 98 | end 99 | twappend("Listener filter: " .. list_filter .. "\n") 100 | local my_tap = Listener.new("frame", list_filter) 101 | 102 | -- get rtp stream info by src and dst address 103 | function get_stream_info(pinfo) 104 | local key = "from_" .. tostring(pinfo.src) .. "_" .. tostring(pinfo.src_port) .. "_to_" .. tostring(pinfo.dst) .. "_" .. tostring(pinfo.dst_port) 105 | key = key:gsub(":", ".") 106 | local stream_info = stream_infos[key] 107 | if not stream_info then -- if not exists, create one 108 | stream_info = { } 109 | stream_info.filename = key.. ".amr" 110 | -- stream_info.file = io.open(stream_info.filename, "wb") 111 | if not Dir.exists(temp_path) then 112 | Dir.make(temp_path) 113 | end 114 | stream_info.filepath = temp_path.."/"..stream_info.filename 115 | stream_info.file,msg = io.open(temp_path.."/"..stream_info.filename, "wb") 116 | if msg then 117 | twappend("io.open "..stream_info.filepath..", error "..msg) 118 | end 119 | stream_info.file:write("\x23\x21\x41\x4d\x52\x0a") -- "#!AMR\n" 120 | stream_infos[key] = stream_info 121 | twappend("Ready to export data (RTP from " .. tostring(pinfo.src) .. ":" .. tostring(pinfo.src_port) 122 | .. " to " .. tostring(pinfo.dst) .. ":" .. tostring(pinfo.dst_port) .. " write to file:[" .. stream_info.filename .. "] ...\n") 123 | end 124 | return stream_info 125 | end 126 | 127 | -- write data to file. 128 | local function write_to_file(stream_info, ft, data_bytes) 129 | local frame_header = bit.bor(0x04 ,bit.lshift(ft, 3)) 130 | data_bytes:set_index(0, frame_header) 131 | -- 需要byte数组整体左移两个bit 132 | for index=1,data_bytes:len()-2 do 133 | local A = bit.lshift(data_bytes:get_index(index), 2) 134 | local B = bit.rshift(data_bytes:get_index(index+1), 6) 135 | data_bytes:set_index(index, bit.band(bit.bor(A, B), 0xff)) 136 | end 137 | data_bytes:set_index(data_bytes:len()-1, bit.band(bit.lshift(data_bytes:get_index(data_bytes:len()-1), 2), 0xff)) 138 | 139 | local data_vaild_len = data_vaild_len_vals[ft] 140 | 141 | stream_info.file:write(data_bytes:raw(0, data_vaild_len)) 142 | end 143 | 144 | -- call this function if a packet contains ps payload 145 | function my_tap.packet(pinfo,tvb) 146 | if stream_infos == nil then 147 | -- not triggered by button event, so do nothing. 148 | return 149 | end 150 | local datas = { f_data() } -- using table because one packet may contains more than one RTP 151 | 152 | for i,data_f in ipairs(datas) do 153 | if data_f.len < 1 then 154 | return 155 | end 156 | 157 | local decoded_mode = f_amr_decode_mode().value 158 | if decoded_mode == 1 then 159 | local ft_bits = f_amr_ft().value 160 | local stream_info = get_stream_info(pinfo) 161 | local data = data_f.range:bytes() 162 | write_to_file(stream_info, ft_bits, data) 163 | end 164 | end 165 | end 166 | 167 | -- close all open files 168 | local function close_all_files() 169 | if stream_infos then 170 | local no_streams = true 171 | for id,stream in pairs(stream_infos) do 172 | if stream and stream.file then 173 | stream.file:flush() 174 | stream.file:close() 175 | stream.file = nil 176 | twappend("File [" .. stream.filename .. "] generated OK!") 177 | twappend("ffplay -f amr -acodec amrnb -autoexit "..stream.filename) 178 | no_streams = false 179 | end 180 | end 181 | 182 | if no_streams then 183 | twappend("Not found any Data over RTP streams!") 184 | else 185 | tw:add_button("Browser", function () browser_open_data_file(temp_path) end) 186 | end 187 | end 188 | end 189 | 190 | twappend("Only support BW-efficient mode") 191 | 192 | function my_tap.reset() 193 | -- do nothing now 194 | end 195 | 196 | tw:set_atclose(function () 197 | my_tap:remove() 198 | if Dir.exists(temp_path) then 199 | Dir.remove_all(temp_path) 200 | end 201 | end) 202 | 203 | local function export_data() 204 | stream_infos = {} 205 | retap_packets() 206 | close_all_files() 207 | stream_infos = nil 208 | end 209 | 210 | tw:add_button("Export All", function () 211 | export_data() 212 | end) 213 | 214 | tw:add_button("Set Filter", function () 215 | tw:close() 216 | dialog_menu() 217 | end) 218 | end 219 | 220 | local function dialog_func(str) 221 | filter_string = str 222 | export_data_to_file() 223 | end 224 | 225 | function dialog_menu() 226 | new_dialog("Filter Dialog",dialog_func,"Filter") 227 | end 228 | 229 | local function dialog_default() 230 | filter_string = get_filter() 231 | export_data_to_file() 232 | end 233 | 234 | -- Find this feature in menu "Tools" 235 | register_menu("Audio/Export AMR", dialog_default, MENU_TOOLS_UNSORTED) 236 | end 237 | -------------------------------------------------------------------------------- /rtp_ps_export.lua: -------------------------------------------------------------------------------- 1 | -- Dump RTP PS payload to raw h.264/5 file 2 | -- According to RFC2250 to dissector payload of RTP to NALU 3 | -- Write it to fromto file. 4 | -- You can access this feature by menu "Tools" 5 | -- Author: Yang Xing (hongch_911@126.com) 6 | ------------------------------------------------------------------------------------------------ 7 | do 8 | local version_str = string.match(_VERSION, "%d+[.]%d*") 9 | local version_num = version_str and tonumber(version_str) or 5.1 10 | -- lua>=5.4 直接使用位操作 11 | -- 使用bit32进行位操作 12 | if (version_num >= 5.4) then 13 | local function band(a,b) 14 | return(a&b) 15 | end 16 | 17 | local function bor(a,b) 18 | return(a|b) 19 | end 20 | 21 | local function lshift(a,b) 22 | return(a<= 5.2) and require("bit32") or require("bit") 26 | end 27 | 28 | function get_temp_path() 29 | local tmp = nil 30 | if tmp == nil or tmp == '' then 31 | tmp = os.getenv('HOME') 32 | if tmp == nil or tmp == '' then 33 | tmp = os.getenv('USERPROFILE') 34 | if tmp == nil or tmp == '' then 35 | tmp = persconffile_path('temp') 36 | else 37 | tmp = tmp .. "/wireshark_temp" 38 | end 39 | else 40 | tmp = tmp .. "/wireshark_temp" 41 | end 42 | end 43 | return tmp 44 | end 45 | function get_ffmpeg_path() 46 | local tmp = nil 47 | if tmp == nil or tmp == '' then 48 | tmp = os.getenv('FFMPEG') 49 | if tmp == nil or tmp == '' then 50 | tmp = "" 51 | else 52 | if not string.ends(tmp, "/bin/") then 53 | tmp = tmp .. "/bin/" 54 | end 55 | end 56 | end 57 | return tmp 58 | end 59 | 60 | -- for geting ps data (the field's value is type of ByteArray) 61 | local f_ps = Field.new("ps") 62 | 63 | local filter_string = nil 64 | 65 | -- menu action. When you click "Tools" will run this function 66 | local function export_data_to_file() 67 | -- window for showing information 68 | local tw = TextWindow.new("Export PS to File Info Win") 69 | local pgtw; 70 | 71 | -- add message to information window 72 | function twappend(str) 73 | tw:append(str) 74 | tw:append("\n") 75 | end 76 | 77 | local ffmpeg_path = get_ffmpeg_path() 78 | -- temp path 79 | local temp_path = get_temp_path() 80 | 81 | -- running first time for counting and finding sps+pps, second time for real saving 82 | local first_run = true 83 | -- variable for storing rtp stream and dumping parameters 84 | local stream_infos = nil 85 | 86 | -- trigered by all ps packats 87 | local list_filter = '' 88 | if filter_string == nil or filter_string == '' then 89 | list_filter = "ps" 90 | elseif string.find(filter_string,"ps")~=nil then 91 | list_filter = filter_string 92 | else 93 | list_filter = "ps && "..filter_string 94 | end 95 | twappend("Listener filter: " .. list_filter .. "\n") 96 | local my_ps_tap = Listener.new("frame", list_filter) 97 | 98 | -- get rtp stream info by src and dst address 99 | function get_stream_info(pinfo) 100 | local key = "from_" .. tostring(pinfo.src) .. "_" .. tostring(pinfo.src_port) .. "_to_" .. tostring(pinfo.dst) .. "_" .. tostring(pinfo.dst_port) 101 | key = key:gsub(":", ".") 102 | local stream_info = stream_infos[key] 103 | if not stream_info then -- if not exists, create one 104 | stream_info = { } 105 | stream_info.filename = key.. ".ps" 106 | -- stream_info.filepath = stream_info.filename 107 | -- stream_info.file,msg = io.open(stream_info.filename, "wb") 108 | if not Dir.exists(temp_path) then 109 | Dir.make(temp_path) 110 | end 111 | stream_info.filepath = temp_path.."/"..stream_info.filename 112 | stream_info.file,msg = io.open(temp_path.."/"..stream_info.filename, "wb") 113 | if msg then 114 | twappend("io.open "..stream_info.filepath..", error "..msg) 115 | end 116 | -- twappend("Output file path:" .. stream_info.filepath) 117 | stream_info.counter = 0 -- counting ps total NALUs 118 | stream_info.counter2 = 0 -- for second time running 119 | stream_infos[key] = stream_info 120 | twappend("Ready to export PS data (RTP from " .. tostring(pinfo.src) .. ":" .. tostring(pinfo.src_port) 121 | .. " to " .. tostring(pinfo.dst) .. ":" .. tostring(pinfo.dst_port) .. " write to file:[" .. stream_info.filename .. "] ...") 122 | end 123 | return stream_info 124 | end 125 | 126 | -- write a NALU or part of NALU to file. 127 | local function write_to_file(stream_info, str_bytes) 128 | if first_run then 129 | stream_info.counter = stream_info.counter + 1 130 | 131 | else -- second time running 132 | 133 | stream_info.file:write(str_bytes) 134 | stream_info.counter2 = stream_info.counter2 + 1 135 | 136 | -- update progress window's progress bar 137 | if stream_info.counter > 0 and stream_info.counter2 < stream_info.counter then 138 | pgtw:update(stream_info.counter2 / stream_info.counter) 139 | end 140 | end 141 | end 142 | 143 | -- call this function if a packet contains ps payload 144 | function my_ps_tap.packet(pinfo,tvb) 145 | if stream_infos == nil then 146 | -- not triggered by button event, so do nothing. 147 | return 148 | end 149 | local datas = { f_ps() } -- using table because one packet may contains more than one RTP 150 | 151 | for i,data_f in ipairs(datas) do 152 | -- if data_f.len < 5 then 153 | -- return 154 | -- end 155 | local data = data_f.range:bytes() 156 | local stream_info = get_stream_info(pinfo) 157 | if stream_info then 158 | write_to_file(stream_info, data:tvb():raw()) 159 | end 160 | end 161 | end 162 | 163 | -- close all open files 164 | local function close_all_files() 165 | twappend("") 166 | local index = 0; 167 | if stream_infos then 168 | local no_streams = true 169 | for id,stream in pairs(stream_infos) do 170 | if stream and stream.file then 171 | stream.file:flush() 172 | stream.file:close() 173 | stream.file = nil 174 | index = index + 1 175 | twappend(index .. ": [" .. stream.filename .. "] generated OK!") 176 | local anony_fuc = function () 177 | twappend("ffplay -x 640 -y 640 -autoexit "..stream.filename) 178 | --copy_to_clipboard("ffplay -x 640 -y 640 -autoexit "..stream.filepath) 179 | os.execute(ffmpeg_path.."ffplay -x 640 -y 640 -autoexit "..stream.filepath) 180 | end 181 | tw:add_button("Play "..index, anony_fuc) 182 | no_streams = false 183 | end 184 | end 185 | 186 | if no_streams then 187 | twappend("Not found any PS over RTP streams!") 188 | else 189 | tw:add_button("Browser", function () browser_open_data_file(temp_path) end) 190 | end 191 | end 192 | end 193 | 194 | function my_ps_tap.reset() 195 | -- do nothing now 196 | end 197 | 198 | tw:set_atclose(function () 199 | my_ps_tap:remove() 200 | if Dir.exists(temp_path) then 201 | Dir.remove_all(temp_path) 202 | end 203 | end) 204 | 205 | local function export_data() 206 | pgtw = ProgDlg.new("Export PS to File Process", "Dumping PS data to file...") 207 | first_run = true 208 | stream_infos = {} 209 | -- first time it runs for counting ps packets and finding SPS and PPS 210 | retap_packets() 211 | first_run = false 212 | -- second time it runs for saving ps data to target file. 213 | retap_packets() 214 | close_all_files() 215 | -- close progress window 216 | pgtw:close() 217 | stream_infos = nil 218 | end 219 | 220 | tw:add_button("Export All", function () 221 | export_data() 222 | end) 223 | 224 | tw:add_button("Set Filter", function () 225 | tw:close() 226 | dialog_menu() 227 | end) 228 | end 229 | 230 | local function dialog_func(str) 231 | filter_string = str 232 | export_data_to_file() 233 | end 234 | 235 | function dialog_menu() 236 | new_dialog("Filter Dialog",dialog_func,"Filter") 237 | end 238 | 239 | local function dialog_default() 240 | filter_string = get_filter() 241 | export_data_to_file() 242 | end 243 | 244 | -- Find this feature in menu "Tools" 245 | register_menu("Video/Export PS", dialog_default, MENU_TOOLS_UNSORTED) 246 | end 247 | -------------------------------------------------------------------------------- /rtp_silk_export.lua: -------------------------------------------------------------------------------- 1 | -- Dump RTP SILK payload to raw file 2 | -- According to draft-spittka-silk-payload-format-00 RFC3550 to dissector payload of RTP to NALU 3 | -- Write it to fromto file. 4 | -- +------------------+ 5 | -- | Header | 6 | -- +-----------+------+ 7 | -- | block 1 | 8 | -- +--------------+--+ 9 | -- : ... : 10 | -- +--------------+--+ 11 | -- | block n | 12 | -- +-----------------+ 13 | -- The header is "#!SILK_V3", and block struction 14 | -- +------------------+ 15 | -- | len | payload | 16 | -- +------------------+ 17 | -- You can access this feature by menu "Tools" 18 | -- Author: Yang Xing (hongch_911@126.com) 19 | ------------------------------------------------------------------------------------------------ 20 | do 21 | -- 解析为SILK音频部分 22 | local proto_silk = Proto("silk", "Audio SILK") 23 | 24 | -- Wireshark对每个相关数据包调用该函数 25 | -- tvb:Testy Virtual Buffer报文缓存; pinfo:packet infomarmation报文信息; treeitem:解析树节点 26 | function proto_silk.dissector(tvb, pinfo, tree) 27 | -- add proto item to tree 28 | local proto_tree = tree:add(proto_silk, tvb()) 29 | proto_tree:append_text(string.format(" (Len: %d)",tvb:len())) 30 | pinfo.columns.protocol = "SILK" 31 | end 32 | 33 | -- set this protocal preferences 34 | local prefs = proto_silk.prefs 35 | prefs.dyn_pt = Pref.range("SILK dynamic payload type", "", "Dynamic payload types which will be interpreted as SILK; Values must be in the range 96 - 127", 127) 36 | 37 | -- register this dissector to dynamic payload type dissectorTable 38 | local dyn_payload_type_table = DissectorTable.get("rtp_dyn_payload_type") 39 | dyn_payload_type_table:add("silk", proto_silk) 40 | 41 | -- register this dissector to specific payload type (specified in preferences windows) 42 | local payload_type_table = DissectorTable.get("rtp.pt") 43 | local old_dyn_pt = nil 44 | local old_dissector = nil 45 | 46 | function proto_silk.init() 47 | if (prefs.dyn_pt ~= old_dyn_pt) then 48 | -- reset old dissector 49 | if (old_dyn_pt ~= nil and string.len(old_dyn_pt) > 0) then 50 | local pt_numbers = getArray(tostring(old_dyn_pt)) 51 | for index,pt_number in pairs(pt_numbers) do 52 | -- replace this proto with old proto on old payload type 53 | if old_dissector ~= nil and old_dissector[index] ~= nil then 54 | payload_type_table:add(pt_number, old_dissector[index]) 55 | else -- just remove this proto 56 | payload_type_table:remove(pt_number, proto_silk) 57 | end 58 | end 59 | end 60 | 61 | old_dyn_pt = prefs.dyn_pt -- save current payload type's dissector 62 | 63 | if (prefs.dyn_pt ~= nil and string.len(prefs.dyn_pt) > 0) then 64 | local pt_numbers = getArray(tostring(prefs.dyn_pt)) 65 | old_dissector = {} 66 | for index,pt_number in pairs(pt_numbers) do 67 | local dissector = payload_type_table:get_dissector(pt_number) 68 | -- table.insert(old_dissector,index,dissector) 69 | old_dissector[index] = dissector 70 | payload_type_table:add(pt_number, proto_silk) 71 | end 72 | end 73 | end 74 | end 75 | 76 | function getArray(str) 77 | local strList = {} 78 | string.gsub(str, '[^,]+',function (w) 79 | local pos = string.find(w,'-') 80 | if not pos then 81 | table.insert(strList,tonumber(w)) 82 | else 83 | local begin_index = string.sub(w,1,pos-1) 84 | local end_index = string.sub(w,pos+1,#w) 85 | for index = begin_index,end_index do 86 | table.insert(strList,index) 87 | end 88 | end 89 | end) 90 | return strList 91 | end 92 | 93 | function get_temp_path() 94 | local tmp = nil 95 | if tmp == nil or tmp == '' then 96 | tmp = os.getenv('HOME') 97 | if tmp == nil or tmp == '' then 98 | tmp = os.getenv('USERPROFILE') 99 | if tmp == nil or tmp == '' then 100 | tmp = persconffile_path('temp') 101 | else 102 | tmp = tmp .. "/wireshark_temp" 103 | end 104 | else 105 | tmp = tmp .. "/wireshark_temp" 106 | end 107 | end 108 | return tmp 109 | end 110 | 111 | -- 导出数据到文件部分 112 | -- for geting data (the field's value is type of ByteArray) 113 | local f_data = Field.new("silk") 114 | 115 | local filter_string = nil 116 | 117 | -- menu action. When you click "Tools" will run this function 118 | local function export_data_to_file() 119 | -- window for showing information 120 | local tw = TextWindow.new("Export File Info Win") 121 | 122 | -- add message to information window 123 | function twappend(str) 124 | tw:append(str) 125 | tw:append("\n") 126 | end 127 | 128 | -- temp path 129 | local temp_path = get_temp_path() 130 | 131 | -- variable for storing rtp stream and dumping parameters 132 | local stream_infos = nil 133 | 134 | -- trigered by all ps packats 135 | local list_filter = '' 136 | if filter_string == nil or filter_string == '' then 137 | list_filter = "silk" 138 | elseif string.find(filter_string,"silk")~=nil then 139 | list_filter = filter_string 140 | else 141 | list_filter = "silk && "..filter_string 142 | end 143 | twappend("Listener filter: " .. list_filter .. "\n") 144 | local my_tap = Listener.new("frame", list_filter) 145 | 146 | -- get rtp stream info by src and dst address 147 | function get_stream_info(pinfo) 148 | local key = "from_" .. tostring(pinfo.src) .. "_" .. tostring(pinfo.src_port) .. "_to_" .. tostring(pinfo.dst) .. "_" .. tostring(pinfo.dst_port) 149 | key = key:gsub(":", ".") 150 | local stream_info = stream_infos[key] 151 | if not stream_info then -- if not exists, create one 152 | stream_info = { } 153 | stream_info.filename = key.. ".silk" 154 | -- stream_info.file = io.open(stream_info.filename, "wb") 155 | if not Dir.exists(temp_path) then 156 | Dir.make(temp_path) 157 | end 158 | stream_info.filepath = temp_path.."/"..stream_info.filename 159 | stream_info.file,msg = io.open(temp_path.."/"..stream_info.filename, "wb") 160 | if msg then 161 | twappend("io.open "..stream_info.filepath..", error "..msg) 162 | end 163 | stream_info.file:write("\x02\x23\x21\x53\x49\x4C\x4B\x5F\x56\x33") -- #!SILK_V3 first 02 is for wx 164 | stream_infos[key] = stream_info 165 | twappend("Ready to export data (RTP from " .. tostring(pinfo.src) .. ":" .. tostring(pinfo.src_port) 166 | .. " to " .. tostring(pinfo.dst) .. ":" .. tostring(pinfo.dst_port) .. " write to file:[" .. stream_info.filename .. "] ...\n") 167 | end 168 | return stream_info 169 | end 170 | 171 | -- write data to file. 172 | local function write_to_file(stream_info, data_bytes) 173 | local len = data_bytes:len() 174 | local b1=string.char(len%256) len=(len-len%256)/256 175 | local b2=string.char(len%256) len=(len-len%256)/256 176 | stream_info.file:write(b1,b2) 177 | stream_info.file:write(data_bytes:raw()) 178 | end 179 | 180 | -- call this function if a packet contains ps payload 181 | function my_tap.packet(pinfo,tvb) 182 | if stream_infos == nil then 183 | -- not triggered by button event, so do nothing. 184 | return 185 | end 186 | local datas = { f_data() } -- using table because one packet may contains more than one RTP 187 | 188 | for i,data_f in ipairs(datas) do 189 | if data_f.len < 1 then 190 | return 191 | end 192 | local data = data_f.range:bytes() 193 | local stream_info = get_stream_info(pinfo) 194 | write_to_file(stream_info, data) 195 | end 196 | end 197 | 198 | -- close all open files 199 | local function close_all_files() 200 | if stream_infos then 201 | local no_streams = true 202 | for id,stream in pairs(stream_infos) do 203 | if stream and stream.file then 204 | stream.file:flush() 205 | stream.file:close() 206 | stream.file = nil 207 | twappend("File [" .. stream.filename .. "] generated OK!") 208 | no_streams = false 209 | end 210 | end 211 | 212 | if no_streams then 213 | twappend("Not found any Data over RTP streams!") 214 | else 215 | tw:add_button("Browser", function () browser_open_data_file(temp_path) end) 216 | end 217 | end 218 | end 219 | 220 | function my_tap.reset() 221 | -- do nothing now 222 | end 223 | 224 | tw:set_atclose(function () 225 | my_tap:remove() 226 | if Dir.exists(temp_path) then 227 | Dir.remove_all(temp_path) 228 | end 229 | end) 230 | 231 | local function export_data() 232 | stream_infos = {} 233 | retap_packets() 234 | close_all_files() 235 | stream_infos = nil 236 | end 237 | 238 | tw:add_button("Export All", function () 239 | export_data() 240 | end) 241 | 242 | tw:add_button("Set Filter", function () 243 | tw:close() 244 | dialog_menu() 245 | end) 246 | end 247 | 248 | local function dialog_func(str) 249 | filter_string = str 250 | export_data_to_file() 251 | end 252 | 253 | function dialog_menu() 254 | new_dialog("Filter Dialog",dialog_func,"Filter") 255 | end 256 | 257 | local function dialog_default() 258 | filter_string = get_filter() 259 | export_data_to_file() 260 | end 261 | 262 | -- Find this feature in menu "Tools" 263 | register_menu("Audio/Export SILK", dialog_default, MENU_TOOLS_UNSORTED) 264 | end 265 | -------------------------------------------------------------------------------- /rtp_h264_export.lua: -------------------------------------------------------------------------------- 1 | -- Dump RTP h.264 payload to raw h.264 file (*.264) 2 | -- According to RFC3984 to dissector H264 payload of RTP to NALU, and write it 3 | -- to fromto.264 file. By now, we support single NALU, 4 | -- STAP-A and FU-A format RTP payload for H.264. 5 | -- You can access this feature by menu "Tools" 6 | -- Author: Huang Qiangxiong (qiangxiong.huang@gmail.com) 7 | -- Modify by Yang Xing (hongch_911@126.com) 8 | ------------------------------------------------------------------------------------------------ 9 | do 10 | local version_str = string.match(_VERSION, "%d+[.]%d*") 11 | local version_num = version_str and tonumber(version_str) or 5.1 12 | -- lua>=5.4 直接使用位操作 13 | -- 使用bit32进行位操作 14 | if (version_num >= 5.4) then 15 | local function band(a,b) 16 | return(a&b) 17 | end 18 | 19 | local function bor(a,b) 20 | return(a|b) 21 | end 22 | 23 | local function lshift(a,b) 24 | return(a<= 5.2) and require("bit32") or require("bit") 28 | end 29 | 30 | function string.starts(String,Start) 31 | return string.sub(String,1,string.len(Start))==Start 32 | end 33 | 34 | function string.ends(String,End) 35 | return End=='' or string.sub(String,-string.len(End))==End 36 | end 37 | function get_temp_path() 38 | local tmp = nil 39 | if tmp == nil or tmp == '' then 40 | tmp = os.getenv('HOME') 41 | if tmp == nil or tmp == '' then 42 | tmp = os.getenv('USERPROFILE') 43 | if tmp == nil or tmp == '' then 44 | tmp = persconffile_path('temp') 45 | else 46 | tmp = tmp .. "/wireshark_temp" 47 | end 48 | else 49 | tmp = tmp .. "/wireshark_temp" 50 | end 51 | end 52 | return tmp 53 | end 54 | function get_ffmpeg_path() 55 | local tmp = nil 56 | if tmp == nil or tmp == '' then 57 | tmp = os.getenv('FFMPEG') 58 | if tmp == nil or tmp == '' then 59 | tmp = "" 60 | else 61 | if not string.ends(tmp, "/bin/") then 62 | tmp = tmp .. "/bin/" 63 | end 64 | end 65 | end 66 | return tmp 67 | end 68 | 69 | -- for geting h264 data (the field's value is type of ByteArray) 70 | local f_h264 = Field.new("h264") 71 | local f_rtp = Field.new("rtp") 72 | local f_rtp_seq = Field.new("rtp.seq") 73 | local f_rtp_timestamp = Field.new("rtp.timestamp") 74 | 75 | local filter_string = nil 76 | 77 | -- menu action. When you click "Tools->Export H264 to file" will run this function 78 | local function export_h264_to_file() 79 | -- window for showing information 80 | local tw = TextWindow.new("Export H264 to File Info Win") 81 | local pgtw; 82 | 83 | -- add message to information window 84 | function twappend(str) 85 | tw:append(str) 86 | tw:append("\n") 87 | end 88 | 89 | local ffmpeg_path = get_ffmpeg_path() 90 | -- temp path 91 | local temp_path = get_temp_path() 92 | 93 | -- running first time for counting and finding sps+pps, second time for real saving 94 | local first_run = true 95 | local writed_nalu_begin = false 96 | -- variable for storing rtp stream and dumping parameters 97 | local stream_infos = nil 98 | 99 | -- trigered by all h264 packats 100 | local list_filter = '' 101 | if filter_string == nil or filter_string == '' then 102 | list_filter = "h264" 103 | elseif string.find(filter_string,"h264")~=nil then 104 | list_filter = filter_string 105 | else 106 | list_filter = "h264 && "..filter_string 107 | end 108 | twappend("Listener filter: " .. list_filter .. "\n") 109 | local my_h264_tap = Listener.new("frame", list_filter) 110 | 111 | -- get rtp stream info by src and dst address 112 | function get_stream_info(pinfo) 113 | local key = "from_" .. tostring(pinfo.src) .. "_" .. tostring(pinfo.src_port) .. "_to_" .. tostring(pinfo.dst) .. "_" .. tostring(pinfo.dst_port) 114 | key = key:gsub(":", ".") 115 | local stream_info = stream_infos[key] 116 | if not stream_info then -- if not exists, create one 117 | stream_info = { } 118 | stream_info.filename = key.. ".264" 119 | -- stream_info.filepath = stream_info.filename 120 | -- stream_info.file,msg = io.open(stream_info.filename, "wb") 121 | if not Dir.exists(temp_path) then 122 | Dir.make(temp_path) 123 | end 124 | stream_info.filepath = temp_path.."/"..stream_info.filename 125 | stream_info.file,msg = io.open(temp_path.."/"..stream_info.filename, "wb") 126 | if msg then 127 | twappend("io.open "..stream_info.filepath..", error "..msg) 128 | end 129 | -- twappend("Output file path:" .. stream_info.filepath) 130 | stream_info.counter = 0 -- counting h264 total NALUs 131 | stream_info.counter2 = 0 -- for second time running 132 | stream_infos[key] = stream_info 133 | twappend("Ready to export H.264 data (RTP from " .. tostring(pinfo.src) .. ":" .. tostring(pinfo.src_port) 134 | .. " to " .. tostring(pinfo.dst) .. ":" .. tostring(pinfo.dst_port) .. " write to file:[" .. stream_info.filename .. "] ...") 135 | end 136 | return stream_info 137 | end 138 | 139 | -- write a NALU or part of NALU to file. 140 | local function write_to_file(stream_info, str_bytes, begin_with_nalu_hdr, end_of_nalu) 141 | if first_run then 142 | stream_info.counter = stream_info.counter + 1 143 | 144 | if begin_with_nalu_hdr then 145 | -- save SPS PPS 146 | local nalu_type = bit.band(str_bytes:byte(0,1), 0x1F) 147 | if not stream_info.sps and nalu_type == 7 then 148 | stream_info.sps = str_bytes 149 | elseif not stream_info.pps and nalu_type == 8 then 150 | stream_info.pps = str_bytes 151 | end 152 | end 153 | 154 | else -- second time running 155 | 156 | if not writed_nalu_begin then 157 | if begin_with_nalu_hdr then 158 | writed_nalu_begin = true 159 | else 160 | return 161 | end 162 | end 163 | 164 | if stream_info.counter2 == 0 then 165 | local nalu_type = bit.band(str_bytes:byte(0,1), 0x1F) 166 | if nalu_type ~= 7 then 167 | -- write SPS and PPS to file header first 168 | if stream_info.sps then 169 | stream_info.file:write("\x00\x00\x00\x01") 170 | stream_info.file:write(stream_info.sps) 171 | else 172 | twappend("Not found SPS for [" .. stream_info.filename .. "], it might not be played!") 173 | end 174 | if stream_info.pps then 175 | stream_info.file:write("\x00\x00\x00\x01") 176 | stream_info.file:write(stream_info.pps) 177 | else 178 | twappend("Not found PPS for [" .. stream_info.filename .. "], it might not be played!") 179 | end 180 | end 181 | end 182 | 183 | if begin_with_nalu_hdr then 184 | -- *.264 raw file format seams that every nalu start with 0x00000001 185 | stream_info.file:write("\x00\x00\x00\x01") 186 | end 187 | stream_info.file:write(str_bytes) 188 | stream_info.counter2 = stream_info.counter2 + 1 189 | 190 | -- update progress window's progress bar 191 | if stream_info.counter > 0 and stream_info.counter2 < stream_info.counter then 192 | pgtw:update(stream_info.counter2 / stream_info.counter) 193 | end 194 | end 195 | end 196 | 197 | -- read RFC3984 about single nalu/stap-a/fu-a H264 payload format of rtp 198 | -- single NALU: one rtp payload contains only NALU 199 | local function process_single_nalu(stream_info, h264) 200 | write_to_file(stream_info, h264:tvb():raw(), true, true) 201 | end 202 | 203 | -- STAP-A: one rtp payload contains more than one NALUs 204 | local function process_stap_a(stream_info, h264) 205 | local h264tvb = h264:tvb() 206 | local offset = 1 207 | repeat 208 | local size = h264tvb(offset,2):uint() 209 | write_to_file(stream_info, h264tvb:raw(offset+2, size), true, true) 210 | offset = offset + 2 + size 211 | until offset >= h264tvb:len() 212 | end 213 | 214 | -- FU-A: one rtp payload contains only one part of a NALU (might be begin, middle and end part of a NALU) 215 | local function process_fu_a(stream_info, h264) 216 | local h264tvb = h264:tvb() 217 | local fu_idr = h264:get_index(0) 218 | local fu_hdr = h264:get_index(1) 219 | local end_of_nalu = (bit.band(fu_hdr, 0x40) ~= 0) 220 | if bit.band(fu_hdr, 0x80) ~= 0 then 221 | -- start bit is set then save nalu header and body 222 | local nalu_hdr = bit.bor(bit.band(fu_idr, 0xE0), bit.band(fu_hdr, 0x1F)) 223 | write_to_file(stream_info, string.char(nalu_hdr) .. h264tvb:raw(2), true, end_of_nalu) 224 | else 225 | -- start bit not set, just write part of nalu body 226 | write_to_file(stream_info, h264tvb:raw(2), false, end_of_nalu) 227 | end 228 | end 229 | 230 | -- call this function if a packet contains h264 payload 231 | function my_h264_tap.packet(pinfo,tvb) 232 | if stream_infos == nil then 233 | -- not triggered by button event, so do nothing. 234 | return 235 | end 236 | local h264s = { f_h264() } -- using table because one packet may contains more than one RTP 237 | 238 | for i,h264_f in ipairs(h264s) do 239 | if h264_f.len < 2 then 240 | return 241 | end 242 | local h264 = h264_f.range:bytes() 243 | local hdr_type = bit.band(h264:get_index(0), 0x1F) 244 | local stream_info = get_stream_info(pinfo) 245 | 246 | if hdr_type > 0 and hdr_type < 24 then 247 | -- Single NALU 248 | process_single_nalu(stream_info, h264) 249 | elseif hdr_type == 24 then 250 | -- STAP-A Single-time aggregation 251 | process_stap_a(stream_info, h264) 252 | elseif hdr_type == 28 then 253 | -- FU-A 254 | process_fu_a(stream_info, h264) 255 | else 256 | twappend("Error: No.=" .. tostring(pinfo.number) .. " unknown type=" .. hdr_type .. " ; we only know 1-23(Single NALU),24(STAP-A),28(FU-A)!") 257 | end 258 | end 259 | end 260 | 261 | -- close all open files 262 | local function close_all_files() 263 | twappend("") 264 | local index = 0; 265 | if stream_infos then 266 | local no_streams = true 267 | for id,stream in pairs(stream_infos) do 268 | if stream and stream.file then 269 | stream.file:flush() 270 | stream.file:close() 271 | stream.file = nil 272 | index = index + 1 273 | twappend(index .. ": [" .. stream.filename .. "] generated OK!") 274 | local anony_fuc = function () 275 | twappend("ffplay -x 640 -y 640 -autoexit "..stream.filename) 276 | --copy_to_clipboard("ffplay -x 640 -y 640 -autoexit "..stream.filepath) 277 | os.execute(ffmpeg_path.."ffplay -x 640 -y 640 -autoexit "..stream.filepath) 278 | end 279 | tw:add_button("Play "..index, anony_fuc) 280 | no_streams = false 281 | end 282 | end 283 | 284 | if no_streams then 285 | twappend("Not found any H.264 over RTP streams!") 286 | else 287 | tw:add_button("Browser", function () browser_open_data_file(temp_path) end) 288 | end 289 | end 290 | end 291 | 292 | function my_h264_tap.reset() 293 | -- do nothing now 294 | end 295 | 296 | tw:set_atclose(function () 297 | my_h264_tap:remove() 298 | if Dir.exists(temp_path) then 299 | Dir.remove_all(temp_path) 300 | end 301 | end) 302 | 303 | local function export_h264() 304 | pgtw = ProgDlg.new("Export H264 to File Process", "Dumping H264 data to file...") 305 | first_run = true 306 | stream_infos = {} 307 | -- first time it runs for counting h.264 packets and finding SPS and PPS 308 | retap_packets() 309 | first_run = false 310 | -- second time it runs for saving h264 data to target file. 311 | retap_packets() 312 | close_all_files() 313 | -- close progress window 314 | pgtw:close() 315 | stream_infos = nil 316 | end 317 | 318 | tw:add_button("Export All", function () 319 | export_h264() 320 | end) 321 | 322 | tw:add_button("Set Filter", function () 323 | tw:close() 324 | dialog_menu() 325 | end) 326 | end 327 | 328 | local function dialog_func(str) 329 | filter_string = str 330 | export_h264_to_file() 331 | end 332 | 333 | function dialog_menu() 334 | new_dialog("Filter Dialog",dialog_func,"Filter") 335 | end 336 | 337 | local function dialog_default() 338 | filter_string = get_filter() 339 | export_h264_to_file() 340 | end 341 | 342 | -- Find this feature in menu "Tools" 343 | register_menu("Video/Export H264", dialog_default, MENU_TOOLS_UNSORTED) 344 | end 345 | -------------------------------------------------------------------------------- /rtp_h265_export.lua: -------------------------------------------------------------------------------- 1 | -- Dump RTP h.265 payload to raw h.265 file (*.265) 2 | -- According to RFC7798 to dissector H265 payload of RTP to NALU, and write it 3 | -- to fromto.265 file. 4 | -- By now, we support Single NAL Unit Packets, Aggregation Packets (APs) 5 | -- and Fragmentation Units (FUs) format RTP payload for H.265. 6 | -- You can access this feature by menu "Tools" 7 | -- Reference from Huang Qiangxiong (qiangxiong.huang@gmail.com) 8 | -- Author: Yang Xing (hongch_911@126.com) 9 | ------------------------------------------------------------------------------------------------ 10 | do 11 | local version_str = string.match(_VERSION, "%d+[.]%d*") 12 | local version_num = version_str and tonumber(version_str) or 5.1 13 | -- lua>=5.4 直接使用位操作 14 | -- 使用bit32进行位操作 15 | if (version_num >= 5.4) then 16 | local function band(a,b) 17 | return(a&b) 18 | end 19 | 20 | local function bor(a,b) 21 | return(a|b) 22 | end 23 | 24 | local function lshift(a,b) 25 | return(a<= 5.2) and require("bit32") or require("bit") 29 | end 30 | 31 | function string.starts(String,Start) 32 | return string.sub(String,1,string.len(Start))==Start 33 | end 34 | 35 | function string.ends(String,End) 36 | return End=='' or string.sub(String,-string.len(End))==End 37 | end 38 | function get_temp_path() 39 | local tmp = nil 40 | if tmp == nil or tmp == '' then 41 | tmp = os.getenv('HOME') 42 | if tmp == nil or tmp == '' then 43 | tmp = os.getenv('USERPROFILE') 44 | if tmp == nil or tmp == '' then 45 | tmp = persconffile_path('temp') 46 | else 47 | tmp = tmp .. "/wireshark_temp" 48 | end 49 | else 50 | tmp = tmp .. "/wireshark_temp" 51 | end 52 | end 53 | return tmp 54 | end 55 | function get_ffmpeg_path() 56 | local tmp = nil 57 | if tmp == nil or tmp == '' then 58 | tmp = os.getenv('FFMPEG') 59 | if tmp == nil or tmp == '' then 60 | tmp = "" 61 | else 62 | if not string.ends(tmp, "/bin/") then 63 | tmp = tmp .. "/bin/" 64 | end 65 | end 66 | end 67 | return tmp 68 | end 69 | 70 | -- for geting h265 data (the field's value is type of ByteArray) 71 | local f_h265 = Field.new("h265") 72 | local f_rtp = Field.new("rtp") 73 | local f_rtp_seq = Field.new("rtp.seq") 74 | local f_rtp_timestamp = Field.new("rtp.timestamp") 75 | 76 | local filter_string = nil 77 | 78 | -- menu action. When you click "Tools->Export H265 to file" will run this function 79 | local function export_h265_to_file() 80 | -- window for showing information 81 | local tw = TextWindow.new("Export H265 to File Info Win") 82 | local pgtw; 83 | 84 | -- add message to information window 85 | function twappend(str) 86 | tw:append(str) 87 | tw:append("\n") 88 | end 89 | 90 | local ffmpeg_path = get_ffmpeg_path() 91 | -- temp path 92 | local temp_path = get_temp_path() 93 | 94 | -- running first time for counting and finding sps+pps, second time for real saving 95 | local first_run = true 96 | local writed_nalu_begin = false 97 | -- variable for storing rtp stream and dumping parameters 98 | local stream_infos = nil 99 | 100 | -- trigered by all h265 packats 101 | local list_filter = '' 102 | if filter_string == nil or filter_string == '' then 103 | list_filter = "h265" 104 | elseif string.find(filter_string,"h265")~=nil then 105 | list_filter = filter_string 106 | else 107 | list_filter = "h265 && "..filter_string 108 | end 109 | twappend("Listener filter: " .. list_filter .. "\n") 110 | local my_h265_tap = Listener.new("frame", list_filter) 111 | 112 | -- get rtp stream info by src and dst address 113 | function get_stream_info(pinfo) 114 | local key = "from_" .. tostring(pinfo.src) .. "_" .. tostring(pinfo.src_port) .. "_to_" .. tostring(pinfo.dst) .. "_" .. tostring(pinfo.dst_port) 115 | key = key:gsub(":", ".") 116 | local stream_info = stream_infos[key] 117 | if not stream_info then -- if not exists, create one 118 | stream_info = { } 119 | stream_info.filename = key.. ".265" 120 | -- stream_info.filepath = stream_info.filename 121 | -- stream_info.file,msg = io.open(stream_info.filename, "wb") 122 | if not Dir.exists(temp_path) then 123 | Dir.make(temp_path) 124 | end 125 | stream_info.filepath = temp_path.."/"..stream_info.filename 126 | stream_info.file,msg = io.open(temp_path.."/"..stream_info.filename, "wb") 127 | if msg then 128 | twappend("io.open "..stream_info.filepath..", error "..msg) 129 | end 130 | -- twappend("Output file path:" .. stream_info.filepath) 131 | stream_info.counter = 0 -- counting h265 total NALUs 132 | stream_info.counter2 = 0 -- for second time running 133 | stream_infos[key] = stream_info 134 | twappend("Ready to export H.265 data (RTP from " .. tostring(pinfo.src) .. ":" .. tostring(pinfo.src_port) 135 | .. " to " .. tostring(pinfo.dst) .. ":" .. tostring(pinfo.dst_port) .. " write to file:[" .. stream_info.filename .. "] ...") 136 | end 137 | return stream_info 138 | end 139 | 140 | -- write a NALU or part of NALU to file. 141 | local function write_to_file(stream_info, str_bytes, begin_with_nalu_hdr, end_of_nalu) 142 | if first_run then 143 | stream_info.counter = stream_info.counter + 1 144 | 145 | if begin_with_nalu_hdr then 146 | -- save VPS SPS PPS 147 | local nalu_type = bit.rshift(bit.band(str_bytes:byte(0,1), 0x7e),1) 148 | if not stream_info.vps and nalu_type == 32 then 149 | stream_info.vps = str_bytes 150 | elseif not stream_info.sps and nalu_type == 33 then 151 | stream_info.sps = str_bytes 152 | elseif not stream_info.pps and nalu_type == 34 then 153 | stream_info.pps = str_bytes 154 | end 155 | end 156 | 157 | else -- second time running 158 | 159 | if not writed_nalu_begin then 160 | if begin_with_nalu_hdr then 161 | writed_nalu_begin = true 162 | else 163 | return 164 | end 165 | end 166 | 167 | if stream_info.counter2 == 0 then 168 | local nalu_type = bit.rshift(bit.band(str_bytes:byte(0,1), 0x7e),1) 169 | if nalu_type ~= 32 then 170 | -- write VPS SPS and PPS to file header first 171 | if stream_info.vps then 172 | stream_info.file:write("\x00\x00\x00\x01") 173 | stream_info.file:write(stream_info.vps) 174 | else 175 | twappend("Not found VPS for [" .. stream_info.filename .. "], it might not be played!") 176 | end 177 | if stream_info.sps then 178 | stream_info.file:write("\x00\x00\x00\x01") 179 | stream_info.file:write(stream_info.sps) 180 | else 181 | twappend("Not found SPS for [" .. stream_info.filename .. "], it might not be played!") 182 | end 183 | if stream_info.pps then 184 | stream_info.file:write("\x00\x00\x00\x01") 185 | stream_info.file:write(stream_info.pps) 186 | else 187 | twappend("Not found PPS for [" .. stream_info.filename .. "], it might not be played!") 188 | end 189 | end 190 | end 191 | 192 | if begin_with_nalu_hdr then 193 | -- *.265 raw file format seams that every nalu start with 0x00000001 194 | stream_info.file:write("\x00\x00\x00\x01") 195 | end 196 | stream_info.file:write(str_bytes) 197 | stream_info.counter2 = stream_info.counter2 + 1 198 | 199 | -- update progress window's progress bar 200 | if stream_info.counter > 0 and stream_info.counter2 < stream_info.counter then 201 | pgtw:update(stream_info.counter2 / stream_info.counter) 202 | end 203 | end 204 | end 205 | 206 | -- read RFC3984 about single nalu/ap/fu H265 payload format of rtp 207 | -- single NALU: one rtp payload contains only NALU 208 | local function process_single_nalu(stream_info, h265) 209 | write_to_file(stream_info, h265:tvb():raw(), true, true) 210 | end 211 | 212 | -- APs: one rtp payload contains more than one NALUs 213 | local function process_ap(stream_info, h265) 214 | local h265tvb = h265:tvb() 215 | local offset = 2 216 | repeat 217 | local size = h265tvb(offset,2):uint() 218 | write_to_file(stream_info, h265tvb:raw(offset+2, size), true, true) 219 | offset = offset + 2 + size 220 | until offset >= h265tvb:len() 221 | end 222 | 223 | -- FUs: one rtp payload contains only one part of a NALU (might be begin, middle and end part of a NALU) 224 | local function process_fu(stream_info, h265) 225 | local h265tvb = h265:tvb() 226 | local start_of_nalu = (h265tvb:range(2, 1):bitfield(0,1) ~= 0) 227 | local end_of_nalu = (h265tvb:range(2, 1):bitfield(1,1) ~= 0) 228 | if start_of_nalu then 229 | -- start bit is set then save nalu header and body 230 | local nalu_hdr_0 = bit.bor(bit.band(h265:get_index(0), 0x81), bit.lshift(bit.band(h265:get_index(2),0x3F), 1)) 231 | local nalu_hdr_1 = h265:get_index(1) 232 | write_to_file(stream_info, string.char(nalu_hdr_0, nalu_hdr_1) .. h265tvb:raw(3), start_of_nalu, end_of_nalu) 233 | else 234 | -- start bit not set, just write part of nalu body 235 | write_to_file(stream_info, h265tvb:raw(3), start_of_nalu, end_of_nalu) 236 | end 237 | end 238 | 239 | -- call this function if a packet contains h265 payload 240 | function my_h265_tap.packet(pinfo,tvb) 241 | if stream_infos == nil then 242 | -- not triggered by button event, so do nothing. 243 | return 244 | end 245 | local h265s = { f_h265() } -- using table because one packet may contains more than one RTP 246 | 247 | for i,h265_f in ipairs(h265s) do 248 | if h265_f.len < 5 then 249 | return 250 | end 251 | local h265 = h265_f.range:bytes() 252 | local hdr_type = h265_f.range(0,1):bitfield(1,6) 253 | local stream_info = get_stream_info(pinfo) 254 | 255 | if hdr_type > 0 and hdr_type < 48 then 256 | -- Single NALU 257 | process_single_nalu(stream_info, h265) 258 | elseif hdr_type == 48 then 259 | -- APs 260 | process_ap(stream_info, h265) 261 | elseif hdr_type == 49 then 262 | -- FUs 263 | process_fu(stream_info, h265) 264 | else 265 | twappend("Error: No.=" .. tostring(pinfo.number) .. " unknown type=" .. hdr_type .. " ; we only know 1-47(Single NALU),48(APs),49(FUs)!") 266 | end 267 | end 268 | end 269 | 270 | -- close all open files 271 | local function close_all_files() 272 | twappend("") 273 | local index = 0; 274 | if stream_infos then 275 | local no_streams = true 276 | for id,stream in pairs(stream_infos) do 277 | if stream and stream.file then 278 | stream.file:flush() 279 | stream.file:close() 280 | stream.file = nil 281 | index = index + 1 282 | twappend(index .. ": [" .. stream.filename .. "] generated OK!") 283 | local anony_fuc = function () 284 | twappend("ffplay -x 640 -y 640 -autoexit "..stream.filename) 285 | --copy_to_clipboard("ffplay -x 640 -y 640 -autoexit "..stream.filepath) 286 | os.execute(ffmpeg_path.."ffplay -x 640 -y 640 -autoexit "..stream.filepath) 287 | end 288 | tw:add_button("Play "..index, anony_fuc) 289 | no_streams = false 290 | end 291 | end 292 | 293 | if no_streams then 294 | twappend("Not found any H.265 over RTP streams!") 295 | else 296 | tw:add_button("Browser", function () browser_open_data_file(temp_path) end) 297 | end 298 | end 299 | end 300 | 301 | function my_h265_tap.reset() 302 | -- do nothing now 303 | end 304 | 305 | tw:set_atclose(function () 306 | my_h265_tap:remove() 307 | if Dir.exists(temp_path) then 308 | Dir.remove_all(temp_path) 309 | end 310 | end) 311 | 312 | local function export_h265() 313 | pgtw = ProgDlg.new("Export H265 to File Process", "Dumping H265 data to file...") 314 | first_run = true 315 | stream_infos = {} 316 | -- first time it runs for counting h.265 packets and finding SPS and PPS 317 | retap_packets() 318 | first_run = false 319 | -- second time it runs for saving h265 data to target file. 320 | retap_packets() 321 | close_all_files() 322 | -- close progress window 323 | pgtw:close() 324 | stream_infos = nil 325 | end 326 | 327 | tw:add_button("Export All", function () 328 | export_h265() 329 | end) 330 | 331 | tw:add_button("Set Filter", function () 332 | tw:close() 333 | dialog_menu() 334 | end) 335 | end 336 | 337 | local function dialog_func(str) 338 | filter_string = str 339 | export_h265_to_file() 340 | end 341 | 342 | function dialog_menu() 343 | new_dialog("Filter Dialog",dialog_func,"Filter") 344 | end 345 | 346 | local function dialog_default() 347 | filter_string = get_filter() 348 | export_h265_to_file() 349 | end 350 | 351 | -- Find this feature in menu "Tools" 352 | register_menu("Video/Export H265", dialog_default, MENU_TOOLS_UNSORTED) 353 | end 354 | -------------------------------------------------------------------------------- /rtp_ps_assemble.lua: -------------------------------------------------------------------------------- 1 | -- Dissector for rtp payload PS 2 | -- According to RFC2250 to dissector payload of RTP to NALU 3 | -- Author: yangxing (hongch_911@126.com) 4 | ------------------------------------------------------------------------------------------------ 5 | do 6 | local version_str = string.match(_VERSION, "%d+[.]%d*") 7 | local version_num = version_str and tonumber(version_str) or 5.1 8 | -- lua>=5.4 直接使用位操作 9 | -- 使用bit32进行位操作 10 | if (version_num >= 5.4) then 11 | local function band(a,b) 12 | return(a&b) 13 | end 14 | 15 | local function bor(a,b) 16 | return(a|b) 17 | end 18 | 19 | local function lshift(a,b) 20 | return(a<= 5.2) and require("bit32") or require("bit") 24 | end 25 | 26 | local ps_stream_type_vals = { 27 | [0x0f] = "AAC", 28 | [0x10] = "MPEG-4 Video", 29 | [0x1b] = "H.264", 30 | [0x24] = "H.265", 31 | [0x80] = "SVAC Video", 32 | [0x90] = "G.711A", 33 | [0x91] = "G.711U", 34 | [0x92] = "G.722.1", 35 | [0x93] = "G.723.1", 36 | [0x99] = "G.729", 37 | [0x9b] = "SVAC Audio", 38 | } 39 | local ps_stream_id_vals = { 40 | [0xbc] = "Program Stream Map", 41 | [0xbd] = "Private Stream-1", 42 | [0xbe] = "Padding Stream", 43 | [0xbf] = "Private Stream-2", 44 | -- [0xc0 .. 0xdf] = "Audio stream", 45 | -- [0xe0 .. 0xef] = "Video stream", 46 | [0xf0] = "ECM Stream", 47 | [0xf1] = "EMM Stream", 48 | [0xf2] = "DSMCC Stream", 49 | [0xf3] = "ISO/IEC 13522 Stream", 50 | [0xf4] = "ITU-T Rec. H.222.1 Type A", 51 | [0xf5] = "ITU-T Rec. H.222.1 Type B", 52 | [0xf6] = "ITU-T Rec. H.222.1 Type C", 53 | [0xf7] = "ITU-T Rec. H.222.1 Type D", 54 | [0xf8] = "ITU-T Rec. H.222.1 Type E", 55 | [0xf9] = "Ancillary Stream", 56 | [0xff] = "Program Stream Directory", 57 | } 58 | for i=0xc0,0xdf do 59 | ps_stream_id_vals[i] = "Audio stream" 60 | end 61 | for i=0xe0,0xef do 62 | ps_stream_id_vals[i] = "Video stream" 63 | end 64 | 65 | local function get_enum_name(list, index) 66 | local value = list[index] 67 | return value and value or string.format("Unknown (%d)",index) 68 | end 69 | 70 | local function get_int64_string(high_int32, low_int32) 71 | return string.format("%x%x",high_int32,low_int32) 72 | end 73 | 74 | local proto_ps = Proto("ps", "PS") 75 | 76 | local ps_hdr = ProtoField.none("ps.pack_header", "PS Header") 77 | local ps_start_code = ProtoField.bytes("ps.pack_start_code", "Start code", base.SPACE) 78 | local ps_scr_base = ProtoField.none("ps.scr_base", "SCR base") 79 | local ps_scr_ext = ProtoField.none("ps.scr_ext", "SCR extension") 80 | local ps_multiplex_rate = ProtoField.new("Multiplex rate", "ps.multiplex_rate", ftypes.UINT24, nil, base.DEC, 0xfffffc) 81 | local ps_stuffing_length = ProtoField.new("Stuffing length", "ps.stuffing_length", ftypes.UINT8, nil, base.DEC, 0x07) 82 | local ps_stuffing_bytes = ProtoField.bytes("ps.stuffing_bytes", "Stuffing bytes") 83 | 84 | local ps_system_header = ProtoField.none("ps.system_header", "System Header") 85 | local ps_system_header_start_code = ProtoField.bytes("ps.system_header.start_code", "Start code", base.SPACE) 86 | local ps_system_header_length = ProtoField.new("Header length", "ps.system_header.header_length", ftypes.UINT16, nil, base.DEC) 87 | local ps_system_header_rate_bound = ProtoField.new("Rate bound", "ps.system_header.rate_bound", ftypes.UINT24, nil, base.DEC, 0x7ffffe) 88 | local ps_system_header_audio_bound = ProtoField.new("Audio bound", "ps.system_header.audio_bound", ftypes.UINT8, nil, base.DEC, 0xfc) 89 | local ps_system_header_fixed_flag = ProtoField.new("Fixed flag", "ps.system_header.fixed_flag", ftypes.UINT8, nil, base.DEC, 0x02) 90 | local ps_system_header_CSPS_flag = ProtoField.new("CSPS flag", "ps.system_header.csps_flag", ftypes.UINT8, nil, base.DEC, 0x01) 91 | local ps_system_header_system_audio_lock_flag = ProtoField.new("System audio lock flag", "ps.system_header.system_audio_lock_flag", ftypes.UINT8, nil, base.DEC, 0x80) 92 | local ps_system_header_system_video_lock_flag = ProtoField.new("System video lock flag", "ps.system_header.system_video_lock_flag", ftypes.UINT8, nil, base.DEC, 0x40) 93 | local ps_system_header_vedio_bound = ProtoField.new("Vedio bound", "ps.system_header.vedio_bound", ftypes.UINT8, nil, base.DEC, 0x1f) 94 | local ps_system_header_packet_rate_restriction_flag = ProtoField.new("Packet rate restriction flag", "ps.system_header.packet_rate_restriction_flag", ftypes.UINT8, nil, base.DEC, 0x80) 95 | local ps_system_header_stream_id = ProtoField.new("Stream ID", "ps.system_header.stream_id", ftypes.UINT8, ps_stream_id_vals, base.HEX) 96 | local ps_system_header_P_STD_scale = ProtoField.new("P-STD buffer bound scale", "ps.system_header.buffer_bound_scale", ftypes.UINT16, nil, base.DEC, 0x2000) 97 | local ps_system_header_P_STD_bound = ProtoField.new("P-STD buffer size bound", "ps.system_header.buffer_size_bound", ftypes.UINT16, nil, base.DEC, 0x1fff) 98 | 99 | local ps_program_stream = ProtoField.none("ps.program_map", "Program Stream Map") 100 | local ps_program_stream_start_code = ProtoField.bytes("ps.program_map.start_code", "Start code", base.SPACE) 101 | local ps_program_stream_id = ProtoField.new("Stream ID", "ps.program_map.stream_id", ftypes.UINT8, ps_stream_id_vals, base.HEX) 102 | local ps_program_stream_length = ProtoField.new("Header length", "ps.program_map.header_length", ftypes.UINT16, nil, base.DEC) 103 | local ps_program_stream_current_next_indicator = ProtoField.new("Current next indicator", "ps.program_map.current_next_indicator", ftypes.UINT8, nil, base.DEC, 0x80) 104 | local ps_program_stream_map_version = ProtoField.new("Version", "ps.program_map.version", ftypes.UINT8, nil, base.DEC, 0x1f) 105 | local ps_program_stream_info_length = ProtoField.new("Info length", "ps.program_map.info_length", ftypes.UINT16, nil, base.DEC) 106 | local ps_program_stream_map_length = ProtoField.new("Map length", "ps.program_map.map_length", ftypes.UINT16, nil, base.DEC) 107 | local ps_program_stream_map_stream_type = ProtoField.new("Elementary Stream type", "ps.program_map.map.stream_type", ftypes.UINT8, ps_stream_type_vals, base.DEC) 108 | local ps_program_stream_map_stream_id = ProtoField.new("Elementary Stream ID", "ps.program_map.map.stream_id", ftypes.UINT8, ps_stream_id_vals, base.HEX) 109 | local ps_program_stream_map_info_length = ProtoField.new("Elementary Stream info length", "ps.program_map.map.stream_info_length", ftypes.UINT16, nil, base.DEC) 110 | local ps_program_stream_CRC = ProtoField.bytes("ps.program_map.crc", "CRC", base.SPACE) 111 | 112 | local ps_pes = ProtoField.none("ps.pes", "PES Packet") 113 | local ps_pes_start_code = ProtoField.bytes("ps.pes.start_code", "Start code", base.SPACE) 114 | local ps_pes_stream_id = ProtoField.new("Stream ID", "ps.pes.stream_id", ftypes.UINT8, ps_stream_id_vals, base.HEX) 115 | local ps_pes_length = ProtoField.new("Length", "ps.pes.packet_length", ftypes.UINT16, nil, base.DEC) 116 | local ps_pes_scrambing_control = ProtoField.new("Scrambing control", "ps.pes.scrambing_control", ftypes.UINT8, nil, base.DEC, 0x30) 117 | local ps_pes_priority = ProtoField.new("Priority", "ps.pes.priority", ftypes.UINT8, nil, base.DEC, 0x08) 118 | local ps_pes_alignment = ProtoField.new("Alignment", "ps.pes.alignment", ftypes.UINT8, nil, base.DEC, 0x04) 119 | local ps_pes_copyright = ProtoField.new("Copyright", "ps.pes.copyright", ftypes.UINT8, nil, base.DEC, 0x02) 120 | local ps_pes_original = ProtoField.new("Original", "ps.pes.original", ftypes.UINT8, nil, base.DEC, 0x01) 121 | local ps_pes_pts_dts_flag = ProtoField.new("PTS DTS flag", "ps.pes.pts_dts_flag", ftypes.UINT8, nil, base.DEC, 0xc0) 122 | local ps_pes_escr_flag = ProtoField.new("ESCR flag", "ps.pes.escr_flag", ftypes.UINT8, nil, base.DEC, 0x20) 123 | local ps_pes_es_rate_flag = ProtoField.new("ES rate flag", "ps.pes.es_rate_flag", ftypes.UINT8, nil, base.DEC, 0x10) 124 | local ps_pes_dsm_trick_mode_flag = ProtoField.new("DSM trick mode flag", "ps.pes.dsm_trick_mode_flag", ftypes.UINT8, nil, base.DEC, 0x08) 125 | local ps_pes_additional_info_flag = ProtoField.new("Additional info flag", "ps.pes.additional_info_flag", ftypes.UINT8, nil, base.DEC, 0x04) 126 | local ps_pes_crc_flag = ProtoField.new("CRC flag", "ps.pes.crc_flag", ftypes.UINT8, nil, base.DEC, 0x02) 127 | local ps_pes_extension_flag = ProtoField.new("Extension flag", "ps.pes.extension_flag", ftypes.UINT8, nil, base.DEC, 0x01) 128 | local ps_pes_header_data_length = ProtoField.new("Header Data Length", "ps.pes.header_data_length", ftypes.UINT8, nil, base.DEC) 129 | local ps_pes_header_data_bytes = ProtoField.bytes("ps.pes.header_data_bytes", "Header Data bytes", base.SPACE) 130 | local ps_pes_pts = ProtoField.none("ps.pes.pts", "PTS") 131 | local ps_pes_dts = ProtoField.none("ps.pes.dts", "DTS") 132 | local ps_pes_escr = ProtoField.none("ps.pes.escr", "ESCR") 133 | local ps_pes_es_rate = ProtoField.none("ps.pes.es_rate", "ES rate") 134 | local ps_pes_dsm_trick_mode = ProtoField.new("DSM trick mode", "ps.pes.dsm_trick_mode", ftypes.UINT8, nil, base.HEX) 135 | local ps_pes_additional_info = ProtoField.new("Copyright Info", "ps.pes.additional_info", ftypes.UINT8, nil, base.HEX) 136 | local ps_pes_crc = ProtoField.new("CRC", "ps.pes.crc", ftypes.UINT16, nil, base.HEX) 137 | local ps_pes_extension = ProtoField.new("Extension", "ps.pes.extension", ftypes.UINT8, nil, base.HEX) 138 | local ps_pes_data_bytes = ProtoField.bytes("ps.pes.data_bytes", "Data bytes") 139 | -- local ps_data = ProtoField.bytes("ps.data", "Data") 140 | 141 | proto_ps.fields = { 142 | ps_hdr,ps_start_code,ps_scr_base,ps_scr_ext,ps_multiplex_rate,ps_stuffing_length,ps_stuffing_bytes, 143 | ps_system_header,ps_system_header_start_code,ps_system_header_length,ps_system_header_rate_bound,ps_system_header_audio_bound,ps_system_header_fixed_flag,ps_system_header_CSPS_flag,ps_system_header_system_audio_lock_flag,ps_system_header_system_video_lock_flag,ps_system_header_vedio_bound,ps_system_header_packet_rate_restriction_flag,ps_system_header_stream_id,ps_system_header_P_STD_scale,ps_system_header_P_STD_bound, 144 | ps_program_stream,ps_program_stream_start_code,ps_program_stream_id,ps_program_stream_length,ps_program_stream_current_next_indicator,ps_program_stream_map_version,ps_program_stream_info_length,ps_program_stream_map_length,ps_program_stream_map_stream_type,ps_program_stream_map_stream_id,ps_program_stream_map_info_length,ps_program_stream_CRC, 145 | ps_pes,ps_pes_start_code,ps_pes_stream_id,ps_pes_length,ps_pes_scrambing_control,ps_pes_priority,ps_pes_alignment,ps_pes_copyright,ps_pes_original,ps_pes_pts_dts_flag,ps_pes_escr_flag,ps_pes_es_rate_flag,ps_pes_dsm_trick_mode_flag,ps_pes_additional_info_flag,ps_pes_crc_flag,ps_pes_extension_flag, 146 | ps_pes_header_data_length,ps_pes_header_data_bytes,ps_pes_pts,ps_pes_dts,ps_pes_escr,ps_pes_es_rate,ps_pes_dsm_trick_mode,ps_pes_additional_info,ps_pes_crc,ps_pes_extension,ps_pes_data_bytes, 147 | -- ps_data 148 | } 149 | 150 | function isInTable(item, tbl) 151 | for k,v in ipairs(tbl) do 152 | if v == item then 153 | return true 154 | end 155 | end 156 | return false 157 | end 158 | 159 | -- local frame_num = Field.new("frame.number") 160 | local h264_dis = Dissector.get("h264") 161 | local h265_dis = Dissector.get("h265") 162 | local pcma_dis = nil 163 | local pcmu_dis = nil 164 | if isInTable("pcma", Dissector.list()) then 165 | pcma_dis = Dissector.get("pcma") 166 | end 167 | if isInTable("pcmu", Dissector.list()) then 168 | pcmu_dis = Dissector.get("pcmu") 169 | end 170 | -- variable for storing stream info 171 | local stream_info_map = {} 172 | 173 | function is_ps_header(tvb, offset) 174 | if (tvb:len() < (offset+4)) then 175 | return false 176 | end 177 | 178 | if ((tvb:range(offset, 1):uint() == 0x00) and (tvb:range(offset+1, 1):uint() == 0x00) 179 | and (tvb:range(offset+2, 1):uint() == 0x01) and (tvb:range(offset+3, 1):uint() == 0xba)) then 180 | return true 181 | else 182 | return false 183 | end 184 | end 185 | function is_system_header(tvb, offset) 186 | if (tvb:len() < (offset+4)) then 187 | return false 188 | end 189 | 190 | --print(string.format("start code %x %x %x %x",tvb:range(offset, 1):uint(),tvb:range(offset+1, 1):uint(),tvb:range(offset+2, 1):uint(),tvb:range(offset+3, 1):uint())) 191 | if ((tvb:range(offset, 1):uint() == 0x00) and (tvb:range(offset+1, 1):uint() == 0x00) 192 | and (tvb:range(offset+2, 1):uint() == 0x01) and (tvb:range(offset+3, 1):uint() == 0xbb)) then 193 | return true 194 | else 195 | return false 196 | end 197 | end 198 | function is_pes_header(tvb, offset) 199 | if (tvb:len() < (offset+4)) then 200 | return false 201 | end 202 | if ((tvb:range(offset, 1):uint() == 0x00) and (tvb:range(offset+1, 1):uint() == 0x00) 203 | and (tvb:range(offset+2, 1):uint() == 0x01)) then 204 | return true 205 | else 206 | return false 207 | end 208 | end 209 | function is_raw_start(tvb, offset) 210 | if (tvb:len() < (offset+4)) then 211 | return false 212 | end 213 | if ((tvb:range(offset, 1):uint() == 0x00) and (tvb:range(offset+1, 1):uint() == 0x00) 214 | and (tvb:range(offset+2, 1):uint() == 0x00) and (tvb:range(offset+3, 1):uint() == 0x01)) then 215 | return true 216 | else 217 | return false 218 | end 219 | end 220 | function dis_ps_packet_header(tvb, tree, offset) 221 | -- PS packet header 222 | local stuffing_size = tvb:range(offset+13,1):bitfield(5, 3) 223 | local ps_hdr_tree = tree:add(ps_hdr, tvb:range(offset,14+stuffing_size)) 224 | ps_hdr_tree:add(ps_start_code, tvb:range(offset,4)) 225 | 226 | local scr_1 = tvb:range(offset+4,1):bitfield(2,3) 227 | local scr_2 = tvb:range(offset+4,3):bitfield(6,15) 228 | local scr_3 = tvb:range(offset+6,3):bitfield(6,15) 229 | local scr_e = tvb:range(offset+8,2):bitfield(6,9) 230 | local scr = bit.lshift(scr_1,30)+bit.lshift(scr_2,15)+scr_3 231 | ps_hdr_tree:add(ps_scr_base, tvb:range(offset+4,6)):append_text(string.format(": %u",scr)) 232 | ps_hdr_tree:add(ps_scr_ext, tvb:range(offset+4,6)):append_text(string.format(": %u",scr_e)) 233 | ps_hdr_tree:add(ps_multiplex_rate, tvb:range(offset+10,3)) 234 | ps_hdr_tree:add(ps_stuffing_length, tvb:range(offset+13,1)) 235 | if (stuffing_size > 0) then 236 | ps_hdr_tree:add(ps_stuffing_bytes, tvb:range(offset+14,stuffing_size)) 237 | end 238 | end 239 | function dis_system_header(tvb, tree, offset) 240 | -- System header 241 | local system_header_length = tvb:range(offset+4, 2):uint() 242 | local ps_system_header_tree = tree:add(ps_system_header, tvb:range(offset,system_header_length+4+2)) 243 | ps_system_header_tree:add(ps_system_header_start_code, tvb:range(offset,4)) 244 | ps_system_header_tree:add(ps_system_header_length, tvb:range(offset+4,2)) 245 | ps_system_header_tree:add(ps_system_header_rate_bound, tvb:range(offset+6,3)) 246 | ps_system_header_tree:add(ps_system_header_audio_bound, tvb:range(offset+9,1)) 247 | ps_system_header_tree:add(ps_system_header_fixed_flag, tvb:range(offset+9,1)) 248 | ps_system_header_tree:add(ps_system_header_CSPS_flag, tvb:range(offset+9,1)) 249 | ps_system_header_tree:add(ps_system_header_system_audio_lock_flag, tvb:range(offset+10,1)) 250 | ps_system_header_tree:add(ps_system_header_system_video_lock_flag, tvb:range(offset+10,1)) 251 | ps_system_header_tree:add(ps_system_header_vedio_bound, tvb:range(offset+10,1)) 252 | ps_system_header_tree:add(ps_system_header_packet_rate_restriction_flag, tvb:range(offset+11,1)) 253 | if (system_header_length>6) then 254 | local remain_length = system_header_length-6 255 | local shif = offset+12 256 | repeat 257 | ps_system_header_tree:add(ps_system_header_stream_id, tvb:range(shif,1)) 258 | ps_system_header_tree:add(ps_system_header_P_STD_scale, tvb:range(shif+1,2)) 259 | ps_system_header_tree:add(ps_system_header_P_STD_bound, tvb:range(shif+1,2)) 260 | shif = shif+3 261 | remain_length = remain_length-3 262 | until(remain_length<=0) 263 | end 264 | end 265 | function dis_stream_map(tvb, tree, offset) 266 | -- Program stream map 267 | local program_map_length = tvb:range(offset+4, 2):uint() 268 | local ps_program_map_tree = tree:add(ps_program_stream, tvb:range(offset,program_map_length+4+2)) 269 | ps_program_map_tree:add(ps_program_stream_start_code, tvb:range(offset,3)) 270 | ps_program_map_tree:add(ps_program_stream_id, tvb:range(offset+3,1)) 271 | ps_program_map_tree:add(ps_program_stream_length, tvb:range(offset+4,2)) 272 | ps_program_map_tree:add(ps_program_stream_current_next_indicator, tvb:range(offset+6,1)) 273 | ps_program_map_tree:add(ps_program_stream_map_version, tvb:range(offset+6,1)) 274 | ps_program_map_tree:add(ps_program_stream_info_length, tvb:range(offset+8,2)) 275 | local info_len = tvb:range(offset+8, 2):uint() 276 | 277 | ps_program_map_tree:add(ps_program_stream_map_length, tvb:range(offset+10+info_len,2)) --10 = 8+2(info len) 278 | local map_len = tvb:range(offset+10+info_len, 2):uint() 279 | local remain_length = map_len 280 | local shif = offset+12+info_len 281 | repeat 282 | ps_program_map_tree:add(ps_program_stream_map_stream_type, tvb:range(shif,1)) 283 | ps_program_map_tree:add(ps_program_stream_map_stream_id, tvb:range(shif+1,1)) 284 | local stream_type = tvb:range(shif,1):uint() 285 | local stream_id = tvb:range(shif+1,1):uint() 286 | stream_info_map[stream_id] = get_enum_name(ps_stream_type_vals, stream_type) 287 | ps_program_map_tree:add(ps_program_stream_map_info_length, tvb:range(shif+2,2)) 288 | local map_info_len = tvb:range(shif+2, 2):uint() 289 | shif = shif+4+map_info_len 290 | remain_length = remain_length-4-map_info_len 291 | until(remain_length<=0) 292 | 293 | ps_program_map_tree:add(ps_program_stream_CRC, tvb:range(offset+12+info_len+map_len,4)) --12 = 8+2(info len)+2(map len) 294 | end 295 | function dis_pes(tvb, tree, offset, pinfo) 296 | -- PES header 297 | local pes_length = tvb:range(offset+4, 2):uint() 298 | local tvb_len = tvb:len() 299 | local complete_packet = tvb_len>=(offset+pes_length+6) 300 | local ps_pes_tree = tree:add(ps_pes, tvb:range(offset,complete_packet and (pes_length+4+2) or (tvb_len-offset))) 301 | ps_pes_tree:add(ps_pes_start_code, tvb:range(offset,3)) 302 | ps_pes_tree:add(ps_pes_stream_id, tvb:range(offset+3,1)) 303 | local pes_length_tree = ps_pes_tree:add(ps_pes_length, tvb:range(offset+4,2)) 304 | 305 | ps_pes_tree:add(ps_pes_scrambing_control, tvb:range(offset+6,1)) 306 | ps_pes_tree:add(ps_pes_priority, tvb:range(offset+6,1)) 307 | ps_pes_tree:add(ps_pes_alignment, tvb:range(offset+6,1)) 308 | ps_pes_tree:add(ps_pes_copyright, tvb:range(offset+6,1)) 309 | ps_pes_tree:add(ps_pes_original, tvb:range(offset+6,1)) 310 | 311 | ps_pes_tree:add(ps_pes_pts_dts_flag, tvb:range(offset+7,1)) 312 | ps_pes_tree:add(ps_pes_escr_flag, tvb:range(offset+7,1)) 313 | ps_pes_tree:add(ps_pes_es_rate_flag, tvb:range(offset+7,1)) 314 | ps_pes_tree:add(ps_pes_dsm_trick_mode_flag, tvb:range(offset+7,1)) 315 | ps_pes_tree:add(ps_pes_additional_info_flag, tvb:range(offset+7,1)) 316 | ps_pes_tree:add(ps_pes_crc_flag, tvb:range(offset+7,1)) 317 | ps_pes_tree:add(ps_pes_extension_flag, tvb:range(offset+7,1)) 318 | 319 | local pes_header_data_len = tvb:range(offset+8, 1):uint() 320 | local header_data_tree = ps_pes_tree:add(ps_pes_header_data_length, tvb:range(offset+8,1)) 321 | if complete_packet then 322 | pes_length_tree:append_text(string.format(" (Data Len: %u)",pes_length-pes_header_data_len-3)) 323 | else 324 | pes_length_tree:append_text(string.format(" (Data Len: %u|Actual Len: %u)",pes_length-pes_header_data_len-3,tvb_len-offset-9-pes_header_data_len)) 325 | end 326 | 327 | if pes_header_data_len>0 then 328 | header_data_tree:add(ps_pes_header_data_bytes, tvb:range(offset+9,pes_header_data_len)) 329 | 330 | local index = offset+9 331 | local pts_dts_flag = tvb:range(offset+7,1):bitfield(0,2) 332 | if pts_dts_flag == 0x2 then 333 | -- local pts_1 = tvb:range(index,1):bitfield(4,3) 334 | local pts_high = tvb:range(index,1):bitfield(4,1) 335 | local pts_1 = tvb:range(index,1):bitfield(5,2) 336 | local pts_2 = tvb:range(index+1,2):bitfield(0,15) 337 | local pts_3 = tvb:range(index+3,2):bitfield(0,15) 338 | local pts = bit.lshift(pts_1,30)+bit.lshift(pts_2,15)+pts_3 339 | -- ps_pes_tree:add(ps_pes_pts, tvb:range(index,5)):append_text(string.format(": %u",pts)) 340 | ps_pes_tree:add(ps_pes_pts, tvb:range(index,5)):append_text(string.format(": 0x%s",get_int64_string(pts_high,pts))) 341 | index = index + 5 342 | elseif pts_dts_flag == 0x3 then 343 | -- local pts_1 = tvb:range(index,1):bitfield(4,3) 344 | local pts_high = tvb:range(index,1):bitfield(4,1) 345 | local pts_1 = tvb:range(index,1):bitfield(5,2) 346 | local pts_2 = tvb:range(index+1,2):bitfield(0,15) 347 | local pts_3 = tvb:range(index+3,2):bitfield(0,15) 348 | local pts = bit.lshift(pts_1,30)+bit.lshift(pts_2,15)+pts_3 349 | ps_pes_tree:add(ps_pes_pts, tvb:range(index,5)):append_text(string.format(": 0x%s",get_int64_string(pts_high,pts))) 350 | 351 | -- local dts_1 = tvb:range(index+5,1):bitfield(4,3) 352 | local dts_high = tvb:range(index+5,1):bitfield(4,1) 353 | local dts_1 = tvb:range(index+5,1):bitfield(5,2) 354 | local dts_2 = tvb:range(index+6,2):bitfield(0,15) 355 | local dts_3 = tvb:range(index+8,2):bitfield(0,15) 356 | local dts = bit.lshift(dts_1,30)+bit.lshift(dts_2,15)+dts_3 357 | ps_pes_tree:add(ps_pes_dts, tvb:range(index+5,5)):append_text(string.format(": 0x%s",get_int64_string(dts_high,dts))) 358 | index = index + 10 359 | end 360 | local escr_flag = tvb:range(offset+7,1):bitfield(2,1) 361 | if escr_flag == 1 then 362 | -- local escr_1 = tvb:range(index,1):bitfield(2,3) 363 | local escr_high = tvb:range(index,1):bitfield(2,1) 364 | local escr_1 = tvb:range(index,1):bitfield(3,2) 365 | local escr_2 = tvb:range(index,3):bitfield(6,15) 366 | local escr_3 = tvb:range(index+2,3):bitfield(6,15) 367 | local escr_e = tvb:range(index+4,2):bitfield(6,9) 368 | local escr = bit.lshift(escr_1,30)+bit.lshift(escr_2,15)+escr_3 369 | ps_pes_tree:add(ps_pes_escr, tvb:range(index,6)):append_text(string.format(": 0x%s, extension: %u",get_int64_string(escr_high,escr),escr_e)) 370 | index = index + 6 371 | end 372 | local es_rate_flag = tvb:range(offset+7,1):bitfield(3,1) 373 | if es_rate_flag == 1 then 374 | local es_rate = tvb:range(index,3):bitfield(1,22) 375 | ps_pes_tree:add(ps_pes_es_rate, tvb:range(index,3)):append_text(string.format(": %u",dts)) 376 | index = index + 3 377 | end 378 | local dsm_trick_mode_flag = tvb:range(offset+7,1):bitfield(4,1) 379 | if dsm_trick_mode_flag == 1 then 380 | ps_pes_tree:add(ps_pes_dsm_trick_mode, tvb:range(index,1)) 381 | index = index + 1 382 | end 383 | local additional_info_flag = tvb:range(offset+7,1):bitfield(5,1) 384 | if additional_info_flag == 1 then 385 | ps_pes_tree:add(ps_pes_additional_info, tvb:range(index,1)) 386 | index = index + 1 387 | end 388 | local crc_flag = tvb:range(offset+7,1):bitfield(6,1) 389 | if crc_flag == 1 then 390 | ps_pes_tree:add(ps_pes_crc, tvb:range(index,2)) 391 | index = index + 2 392 | end 393 | local extension_flag = tvb:range(offset+7,1):bitfield(7,1) 394 | if extension_flag == 1 then 395 | ps_pes_tree:add(ps_pes_extension, tvb:range(index,1)) 396 | index = index + 1 397 | end 398 | end 399 | 400 | local stream_id = tvb:range(offset+3,1):uint() 401 | local stream_id_name = stream_info_map[stream_id] 402 | 403 | -- Start code 3, stream id 1, packet length 2, scrambing|PTS 2, Header length 1 404 | if offset+9+pes_header_data_len>=tvb_len then 405 | return 406 | end 407 | 408 | local date_len = complete_packet and (pes_length-3-pes_header_data_len) or (tvb_len-offset-9-pes_header_data_len) 409 | local shif = offset+9+pes_header_data_len 410 | local dec_tvb = tvb:bytes(shif,date_len):tvb() 411 | if "H.264" == stream_id_name then 412 | -- h264/h265 not contain start code 00 00 00 01 413 | h264_dis:call(dec_tvb:bytes(4):tvb(), pinfo, ps_pes_tree) 414 | elseif "H.265" == stream_id_name then 415 | h265_dis:call(dec_tvb:bytes(4):tvb(), pinfo, ps_pes_tree) 416 | elseif "G.711A" == stream_id_name and pcma_dis ~= nil then 417 | pcma_dis:call(dec_tvb, pinfo, ps_pes_tree) 418 | elseif "G.711U" == stream_id_name and pcmu_dis ~= nil then 419 | pcmu_dis:call(dec_tvb, pinfo, ps_pes_tree) 420 | else 421 | local media_raw_tree = ps_pes_tree:add(ps_pes_data_bytes, tvb:range(offset+9+pes_header_data_len, date_len)) 422 | if stream_id_name then 423 | media_raw_tree:set_text(stream_id_name) 424 | media_raw_tree:append_text(string.format(" (%d)",date_len)) 425 | else 426 | media_raw_tree:set_text(string.format("0x%x",stream_id)) 427 | media_raw_tree:append_text(string.format(" (%d)",date_len)) 428 | end 429 | end 430 | 431 | end 432 | 433 | local lastNumber = 0 434 | local tempArray = nil 435 | local completeRTP = {} 436 | 437 | -- PS dissector for rtp payload 438 | function proto_ps.dissector(tvb, pinfo, tree) 439 | -- local frame_seqs = frame_num() 440 | -- if (frame_seqs.value == 1) 441 | 442 | if pinfo.visited == false then 443 | if (is_ps_header(tvb, 0)) then 444 | tempArray = nil 445 | end 446 | if (tempArray == nil) then 447 | tempArray = ByteArray.new() 448 | tempArray:append(tvb:bytes()) 449 | else 450 | tempArray:append(tvb:bytes()) 451 | end 452 | completeRTP[pinfo.number] = tempArray 453 | -- clean not complete buffer 454 | if (is_ps_header(tvb, 0) == false) then 455 | if (lastNumber > 0) then 456 | completeRTP[lastNumber] = nil 457 | end 458 | end 459 | lastNumber = pinfo.number 460 | 461 | return 462 | end 463 | 464 | -- add proto item to tree 465 | if (completeRTP[pinfo.number] ~= nil) then 466 | local rtp_tvb = completeRTP[pinfo.number]:tvb() 467 | local proto_tree = tree:add(proto_ps, rtp_tvb:range()) 468 | local offset = 0 469 | 470 | if (is_ps_header(rtp_tvb, offset)) then 471 | local stuffing_size = rtp_tvb:range(offset+13,1):bitfield(5, 3) 472 | dis_ps_packet_header(rtp_tvb, proto_tree, offset) 473 | offset = offset + 14 + stuffing_size 474 | 475 | if (is_system_header(rtp_tvb, offset)) then 476 | local system_header_length = rtp_tvb:range(offset+4, 2):uint() 477 | dis_system_header(rtp_tvb, proto_tree, offset) 478 | offset = offset + 4 + 2 + system_header_length 479 | 480 | -- program stream map 481 | local program_map_length = rtp_tvb:range(offset+4, 2):uint() 482 | dis_stream_map(rtp_tvb, proto_tree, offset) 483 | offset = offset + 4 + 2 + program_map_length 484 | end 485 | 486 | while (is_pes_header(rtp_tvb, offset)) 487 | do 488 | local pes_length = rtp_tvb:range(offset+4, 2):uint() 489 | dis_pes(rtp_tvb, proto_tree, offset, pinfo) 490 | offset = offset + 4 + 2 + pes_length 491 | end 492 | else 493 | while (is_pes_header(rtp_tvb, offset)) 494 | do 495 | local pes_length = rtp_tvb:range(offset+4, 2):uint() 496 | dis_pes(rtp_tvb, proto_tree, offset, pinfo) 497 | offset = offset + 4 + 2 + pes_length 498 | end 499 | end 500 | 501 | pinfo.columns.protocol = "PS" 502 | else 503 | pinfo.columns.protocol = "PS" 504 | end 505 | end 506 | 507 | -- set this protocal preferences 508 | local prefs = proto_ps.prefs 509 | prefs.dyn_pt = Pref.range("PS dynamic payload type", "", "Dynamic payload types which will be interpreted as PS; Values must be in the range 96 - 127", 127) 510 | 511 | -- register this dissector to dynamic payload type dissectorTable 512 | local dyn_payload_type_table = DissectorTable.get("rtp_dyn_payload_type") 513 | dyn_payload_type_table:add("ps", proto_ps) 514 | 515 | -- register this dissector to specific payload type (specified in preferences windows) 516 | local payload_type_table = DissectorTable.get("rtp.pt") 517 | local old_dyn_pt = nil 518 | local old_dissector = nil 519 | 520 | function proto_ps.init() 521 | if (prefs.dyn_pt ~= old_dyn_pt) then 522 | -- reset old dissector 523 | if (old_dyn_pt ~= nil and string.len(old_dyn_pt) > 0) then 524 | local pt_numbers = getArray(tostring(old_dyn_pt)) 525 | for index,pt_number in pairs(pt_numbers) do 526 | -- replace this proto with old proto on old payload type 527 | if old_dissector ~= nil and old_dissector[index] ~= nil then 528 | payload_type_table:add(pt_number, old_dissector[index]) 529 | else -- just remove this proto 530 | payload_type_table:remove(pt_number, proto_ps) 531 | end 532 | end 533 | end 534 | 535 | old_dyn_pt = prefs.dyn_pt -- save current payload type's dissector 536 | 537 | if (prefs.dyn_pt ~= nil and string.len(prefs.dyn_pt) > 0) then 538 | local pt_numbers = getArray(tostring(prefs.dyn_pt)) 539 | old_dissector = {} 540 | for index,pt_number in pairs(pt_numbers) do 541 | local dissector = payload_type_table:get_dissector(pt_number) 542 | -- table.insert(old_dissector,index,dissector) 543 | old_dissector[index] = dissector 544 | payload_type_table:add(pt_number, proto_ps) 545 | end 546 | end 547 | end 548 | end 549 | 550 | function getArray(str) 551 | local strList = {} 552 | string.gsub(str, '[^,]+',function (w) 553 | local pos = string.find(w,'-') 554 | if not pos then 555 | table.insert(strList,tonumber(w)) 556 | else 557 | local begin_index = string.sub(w,1,pos-1) 558 | local end_index = string.sub(w,pos+1,#w) 559 | for index = begin_index,end_index do 560 | table.insert(strList,index) 561 | end 562 | end 563 | end) 564 | return strList 565 | end 566 | end 567 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /rtp_ps_no_assemble.lua: -------------------------------------------------------------------------------- 1 | -- Dissector for rtp payload PS 2 | -- According to RFC2250 to dissector payload of RTP to NALU 3 | -- Author: yangxing (hongch_911@126.com) 4 | ------------------------------------------------------------------------------------------------ 5 | do 6 | local version_str = string.match(_VERSION, "%d+[.]%d*") 7 | local version_num = version_str and tonumber(version_str) or 5.1 8 | -- lua>=5.4 直接使用位操作 9 | -- 使用bit32进行位操作 10 | if (version_num >= 5.4) then 11 | local function band(a,b) 12 | return(a&b) 13 | end 14 | 15 | local function bor(a,b) 16 | return(a|b) 17 | end 18 | 19 | local function lshift(a,b) 20 | return(a<= 5.2) and require("bit32") or require("bit") 24 | end 25 | 26 | local ps_stream_type_vals = { 27 | [0x0f] = "AAC", 28 | [0x10] = "MPEG-4 Video", 29 | [0x1b] = "H.264", 30 | [0x24] = "H.265", 31 | [0x80] = "SVAC Video", 32 | [0x90] = "G.711A", 33 | [0x91] = "G.711U", 34 | [0x92] = "G.722.1", 35 | [0x93] = "G.723.1", 36 | [0x99] = "G.729", 37 | [0x9b] = "SVAC Audio", 38 | } 39 | local h264_nal_unit_type_vals = { 40 | [0] = "Unspecified", 41 | [1] = "Coded slice of a non-IDR picture", 42 | [2] = "Coded slice data partition A", 43 | [3] = "Coded slice data partition B", 44 | [4] = "Coded slice data partition C", 45 | [5] = "Coded slice of an IDR picture", 46 | [6] = "Supplemental enhancement information (SEI)", 47 | [7] = "Sequence parameter set", 48 | [8] = "Picture parameter set", 49 | [9] = "Access unit delimiter", 50 | [10] = "End of sequence", 51 | [11] = "End of stream", 52 | [12] = "Filler data", 53 | [13] = "Sequence parameter set extension", 54 | [14] = "Prefix", 55 | [15] = "Subset sequence parameter set", 56 | [16] = "Reserved", 57 | [17] = "Reserved", 58 | [18] = "Reserved", 59 | [19] = "Coded slice of an auxiliary coded picture without partitioning", 60 | [20] = "Coded slice extension", 61 | [21] = "Coded slice extension for depth view components", 62 | [22] = "Reserved", 63 | [23] = "Reserved" 64 | } 65 | local h264_type_summary_values = { 66 | [0] = "Undefined", 67 | [1] = "non-IDR-Slice", 68 | [2] = "Slice-A", 69 | [3] = "Slice-B", 70 | [4] = "Slice-C", 71 | [5] = "IDR-Slice", 72 | [6] = "SEI", 73 | [7] = "SPS", 74 | [8] = "PPS", 75 | [9] = "AUD", 76 | [10] = "End-of-Seq", 77 | [11] = "End-of-Stream", 78 | [12] = "Filler", 79 | [13] = "SPS-Ext", 80 | [14] = "Prefix", 81 | [15] = "Subset-SPS", 82 | [16] = "Reserved", 83 | [17] = "Reserved", 84 | [18] = "Reserved", 85 | [19] = "Slice-Aux", 86 | [20] = "Slice-Ext", 87 | [21] = "Slice-Ext-Depth", 88 | [22] = "Reserved", 89 | [23] = "Reserved" 90 | } 91 | local h265_nal_unit_type_vals = { 92 | [0] = "Coded slice segment of a non-TSA, non-STSA trailing picture", 93 | [1] = "Coded slice segment of a non-TSA, non-STSA trailing picture", 94 | [2] = "Coded slice segment of a TSA picture", 95 | [3] = "Coded slice segment of a TSA picture", 96 | [4] = "Coded slice segment of an STSA picture", 97 | [5] = "Coded slice segment of an STSA picture", 98 | [6] = "Coded slice segment of a RADL picture", 99 | [7] = "Coded slice segment of a RADL picture", 100 | [8] = "Coded slice segment of a RASL picture", 101 | [9] = "Coded slice segment of a RASL picture", 102 | [10] = "Reserved non-IRAP SLNR VCL NAL unit types", 103 | [11] = "Reserved non-IRAP sub-layer reference VCL NAL unit types", 104 | [12] = "Reserved non-IRAP SLNR VCL NAL unit types", 105 | [13] = "Reserved non-IRAP sub-layer reference VCL NAL unit types", 106 | [14] = "Reserved non-IRAP SLNR VCL NAL unit types", 107 | [15] = "Reserved non-IRAP sub-layer reference VCL NAL unit types", 108 | [16] = "Coded slice segment of a BLA picture", 109 | [17] = "Coded slice segment of a BLA picture", 110 | [18] = "Coded slice segment of a BLA picture", 111 | [19] = "Coded slice segment of an IDR picture", 112 | [20] = "Coded slice segment of an IDR picture", 113 | [21] = "Coded slice segment of a CRA picture", 114 | [22] = "Reserved IRAP VCL NAL unit types", 115 | [23] = "Reserved IRAP VCL NAL unit types", 116 | [24 .. 31] = "Reserved non-IRAP VCL NAL unit types", 117 | [32] = "Video parameter set", 118 | [33] = "Sequence parameter set", 119 | [34] = "Picture parameter set", 120 | [35] = "Access unit delimiter", 121 | [36] = "End of sequence", 122 | [37] = "End of bitstream", 123 | [38] = "Filler data", 124 | [39] = "Prefix Supplemental enhancement information", 125 | [40] = "Suffix Supplemental enhancement information", 126 | [40 .. 47] = "Reserved", 127 | [48 .. 63] = "Unspecified" 128 | } 129 | local h265_type_summary_values = { 130 | [0] = "non-TSA, non-STSA", 131 | [1] = "non-TSA, non-STSA", 132 | [2] = "TSA", 133 | [3] = "TSA", 134 | [4] = "STSA", 135 | [5] = "STSA", 136 | [6] = "RADL", 137 | [7] = "RADL", 138 | [8] = "RASL", 139 | [9] = "RASL", 140 | [10] = "non-IRAP-SLNR-VCL", 141 | [11] = "non-IRAP-sub-layer", 142 | [12] = "non-IRAP-SLNR", 143 | [13] = "non-IRAP-sub-layer", 144 | [14] = "non-IRAP-SLNR", 145 | [15] = "non-IRAP-sub-layer", 146 | [16] = "BLA", 147 | [17] = "BLA", 148 | [18] = "BLA", 149 | [19] = "IDR", 150 | [20] = "IDR", 151 | [21] = "CRAe", 152 | [22] = "IRAP-VCL", 153 | [23] = "IRAP-VCL", 154 | [24 .. 31] = "non-IRAP-VCL", 155 | [32] = "VPS", 156 | [33] = "SPS", 157 | [34] = "PPS", 158 | [35] = "AUD", 159 | [36] = "End-of-Seq", 160 | [37] = "End-of-Stream", 161 | [38] = "Filler", 162 | [39] = "Prefix-SEI", 163 | [40] = "Suffix-SEI", 164 | [40 .. 47] = "Reserved", 165 | [48 .. 63] = "Unspecified" 166 | } 167 | local function get_enum_name(list, index) 168 | local value = list[index] 169 | return value and value or string.format("Unknown (%d)",index) 170 | end 171 | 172 | local function get_int64_string(high_int32, low_int32) 173 | return string.format("%x%x",high_int32,low_int32) 174 | end 175 | 176 | local proto_ps = Proto("ps", "PS") 177 | 178 | local ps_hdr = ProtoField.none("ps.pack_header", "PS Header") 179 | local ps_start_code = ProtoField.bytes("ps.pack_start_code", "Start code", base.SPACE) 180 | local ps_scr_base = ProtoField.none("ps.scr_base", "SCR base") 181 | local ps_scr_ext = ProtoField.none("ps.scr_ext", "SCR extension") 182 | local ps_multiplex_rate = ProtoField.new("Multiplex rate", "ps.multiplex_rate", ftypes.UINT24, nil, base.DEC, 0xfffffc) 183 | local ps_stuffing_length = ProtoField.new("Stuffing length", "ps.stuffing_length", ftypes.UINT8, nil, base.DEC, 0x07) 184 | local ps_stuffing_bytes = ProtoField.bytes("ps.stuffing_bytes", "Stuffing bytes") 185 | 186 | local ps_system_header = ProtoField.none("ps.system_header", "System Header") 187 | local ps_system_header_start_code = ProtoField.bytes("ps.system_header.start_code", "Start code", base.SPACE) 188 | local ps_system_header_length = ProtoField.new("Header length", "ps.system_header.header_length", ftypes.UINT16, nil, base.DEC) 189 | local ps_system_header_rate_bound = ProtoField.new("Rate bound", "ps.system_header.rate_bound", ftypes.UINT24, nil, base.DEC, 0x7ffffe) 190 | local ps_system_header_audio_bound = ProtoField.new("Audio bound", "ps.system_header.audio_bound", ftypes.UINT8, nil, base.DEC, 0xfc) 191 | local ps_system_header_fixed_flag = ProtoField.new("Fixed flag", "ps.system_header.fixed_flag", ftypes.UINT8, nil, base.DEC, 0x02) 192 | local ps_system_header_CSPS_flag = ProtoField.new("CSPS flag", "ps.system_header.csps_flag", ftypes.UINT8, nil, base.DEC, 0x01) 193 | local ps_system_header_system_audio_lock_flag = ProtoField.new("System audio lock flag", "ps.system_header.system_audio_lock_flag", ftypes.UINT8, nil, base.DEC, 0x80) 194 | local ps_system_header_system_video_lock_flag = ProtoField.new("System video lock flag", "ps.system_header.system_video_lock_flag", ftypes.UINT8, nil, base.DEC, 0x40) 195 | local ps_system_header_vedio_bound = ProtoField.new("Vedio bound", "ps.system_header.vedio_bound", ftypes.UINT8, nil, base.DEC, 0x1f) 196 | local ps_system_header_packet_rate_restriction_flag = ProtoField.new("Packet rate restriction flag", "ps.system_header.packet_rate_restriction_flag", ftypes.UINT8, nil, base.DEC, 0x80) 197 | local ps_system_header_stream_id = ProtoField.new("Stream ID", "ps.system_header.stream_id", ftypes.UINT8, nil, base.HEX) 198 | local ps_system_header_P_STD_scale = ProtoField.new("P-STD buffer bound scale", "ps.system_header.buffer_bound_scale", ftypes.UINT16, nil, base.DEC, 0x2000) 199 | local ps_system_header_P_STD_bound = ProtoField.new("P-STD buffer size bound", "ps.system_header.buffer_size_bound", ftypes.UINT16, nil, base.DEC, 0x1fff) 200 | 201 | local ps_program_stream = ProtoField.none("ps.program_map", "Program Stream Map") 202 | local ps_program_stream_start_code = ProtoField.bytes("ps.program_map.start_code", "Start code", base.SPACE) 203 | local ps_program_stream_id = ProtoField.new("Stream ID", "ps.program_map.stream_id", ftypes.UINT8, nil, base.HEX) 204 | local ps_program_stream_length = ProtoField.new("Header length", "ps.program_map.header_length", ftypes.UINT16, nil, base.DEC) 205 | local ps_program_stream_current_next_indicator = ProtoField.new("Current next indicator", "ps.program_map.current_next_indicator", ftypes.UINT8, nil, base.DEC, 0x80) 206 | local ps_program_stream_map_version = ProtoField.new("Version", "ps.program_map.version", ftypes.UINT8, nil, base.DEC, 0x1f) 207 | local ps_program_stream_info_length = ProtoField.new("Info length", "ps.program_map.info_length", ftypes.UINT16, nil, base.DEC) 208 | local ps_program_stream_map_length = ProtoField.new("Map length", "ps.program_map.map_length", ftypes.UINT16, nil, base.DEC) 209 | local ps_program_stream_map_stream_type = ProtoField.new("Elementary Stream type", "ps.program_map.map.stream_type", ftypes.UINT8, ps_stream_type_vals, base.DEC) 210 | local ps_program_stream_map_stream_id = ProtoField.new("Elementary Stream ID", "ps.program_map.map.stream_id", ftypes.UINT8, nil, base.HEX) 211 | local ps_program_stream_map_info_length = ProtoField.new("Elementary Stream info length", "ps.program_map.map.stream_info_length", ftypes.UINT16, nil, base.DEC) 212 | local ps_program_stream_CRC = ProtoField.bytes("ps.program_map.crc", "CRC", base.SPACE) 213 | 214 | local ps_pes = ProtoField.none("ps.pes", "PES Packet") 215 | local ps_pes_start_code = ProtoField.bytes("ps.pes.start_code", "Start code", base.SPACE) 216 | local ps_pes_stream_id = ProtoField.new("Stream ID", "ps.pes.stream_id", ftypes.UINT8, nil, base.HEX) 217 | local ps_pes_length = ProtoField.new("Length", "ps.pes.packet_length", ftypes.UINT16, nil, base.DEC) 218 | local ps_pes_scrambing_control = ProtoField.new("Scrambing control", "ps.pes.scrambing_control", ftypes.UINT8, nil, base.DEC, 0x30) 219 | local ps_pes_priority = ProtoField.new("Priority", "ps.pes.priority", ftypes.UINT8, nil, base.DEC, 0x08) 220 | local ps_pes_alignment = ProtoField.new("Alignment", "ps.pes.alignment", ftypes.UINT8, nil, base.DEC, 0x04) 221 | local ps_pes_copyright = ProtoField.new("Copyright", "ps.pes.copyright", ftypes.UINT8, nil, base.DEC, 0x02) 222 | local ps_pes_original = ProtoField.new("Original", "ps.pes.original", ftypes.UINT8, nil, base.DEC, 0x01) 223 | local ps_pes_pts_dts_flag = ProtoField.new("PTS DTS flag", "ps.pes.pts_dts_flag", ftypes.UINT8, nil, base.DEC, 0xc0) 224 | local ps_pes_escr_flag = ProtoField.new("ESCR flag", "ps.pes.escr_flag", ftypes.UINT8, nil, base.DEC, 0x20) 225 | local ps_pes_es_rate_flag = ProtoField.new("ES rate flag", "ps.pes.es_rate_flag", ftypes.UINT8, nil, base.DEC, 0x10) 226 | local ps_pes_dsm_trick_mode_flag = ProtoField.new("DSM trick mode flag", "ps.pes.dsm_trick_mode_flag", ftypes.UINT8, nil, base.DEC, 0x08) 227 | local ps_pes_additional_info_flag = ProtoField.new("Additional info flag", "ps.pes.additional_info_flag", ftypes.UINT8, nil, base.DEC, 0x04) 228 | local ps_pes_crc_flag = ProtoField.new("CRC flag", "ps.pes.crc_flag", ftypes.UINT8, nil, base.DEC, 0x02) 229 | local ps_pes_extension_flag = ProtoField.new("Extension flag", "ps.pes.extension_flag", ftypes.UINT8, nil, base.DEC, 0x01) 230 | local ps_pes_header_data_length = ProtoField.new("Header Data Length", "ps.pes.header_data_length", ftypes.UINT8, nil, base.DEC) 231 | local ps_pes_header_data_bytes = ProtoField.bytes("ps.pes.header_data_bytes", "Header Data bytes", base.SPACE) 232 | local ps_pes_pts = ProtoField.none("ps.pes.pts", "PTS") 233 | -- local ps_pes_pts = ProtoField.int64("ps.pes.pts", "PTS", base.HEX, nil, 0x0000000efffefffe, nil); 234 | local ps_pes_dts = ProtoField.none("ps.pes.dts", "DTS") 235 | local ps_pes_escr = ProtoField.none("ps.pes.escr", "ESCR") 236 | local ps_pes_es_rate = ProtoField.none("ps.pes.es_rate", "ES rate") 237 | local ps_pes_dsm_trick_mode = ProtoField.new("DSM trick mode", "ps.pes.dsm_trick_mode", ftypes.UINT8, nil, base.HEX) 238 | local ps_pes_additional_info = ProtoField.new("Copyright Info", "ps.pes.additional_info", ftypes.UINT8, nil, base.HEX) 239 | local ps_pes_crc = ProtoField.new("CRC", "ps.pes.crc", ftypes.UINT16, nil, base.HEX) 240 | local ps_pes_extension = ProtoField.new("Extension", "ps.pes.extension", ftypes.UINT8, nil, base.HEX) 241 | local ps_pes_data_bytes = ProtoField.bytes("ps.pes.data_bytes", "Data bytes") 242 | local ps_data = ProtoField.bytes("ps.data", "Data") 243 | 244 | local h26x_f_bit_vals = { 245 | [1] = "Bit errors or other syntax violations", 246 | [0] = "No bit errors or other syntax violations" 247 | } 248 | local h264_f_bit = ProtoField.new("F bit", "ps.pes.h264.f", ftypes.UINT8, h26x_f_bit_vals, base.DEC, 0x80) 249 | local h264_nal_ref_idc = ProtoField.new("Nal_ref_idc (NRI)", "ps.pes.h264.layerid", ftypes.UINT8, nil, base.DEC, 0x60) 250 | local h264_nal_unit_type = ProtoField.new("Type", "ps.pes.h264.nal_unit_type", ftypes.UINT8, h264_nal_unit_type_vals, base.DEC, 0x1f) 251 | 252 | local h265_f_bit = ProtoField.new("F bit", "ps.pes.h265.f", ftypes.UINT16, h26x_f_bit_vals, base.DEC, 0x8000) 253 | local h265_nal_unit_type = ProtoField.new("Type", "ps.pes.h265.nal_unit_type", ftypes.UINT16, h265_nal_unit_type_vals, base.DEC, 0x7E00) 254 | local h265_nal_layer_id = ProtoField.new("Layer ID", "ps.pes.h265.layerid", ftypes.UINT16, nil, base.DEC, 0x01F8) 255 | local h265_nal_temporal_id = ProtoField.new("TID", "ps.pes.h265.tid", ftypes.UINT16, nil, base.DEC, 0x0007) 256 | 257 | proto_ps.fields = { 258 | ps_hdr,ps_start_code,ps_scr_base,ps_scr_ext,ps_multiplex_rate,ps_stuffing_length,ps_stuffing_bytes, 259 | ps_system_header,ps_system_header_start_code,ps_system_header_length,ps_system_header_rate_bound,ps_system_header_audio_bound,ps_system_header_fixed_flag,ps_system_header_CSPS_flag,ps_system_header_system_audio_lock_flag,ps_system_header_system_video_lock_flag,ps_system_header_vedio_bound,ps_system_header_packet_rate_restriction_flag,ps_system_header_stream_id,ps_system_header_P_STD_scale,ps_system_header_P_STD_bound, 260 | ps_program_stream,ps_program_stream_start_code,ps_program_stream_id,ps_program_stream_length,ps_program_stream_current_next_indicator,ps_program_stream_map_version,ps_program_stream_info_length,ps_program_stream_map_length,ps_program_stream_map_stream_type,ps_program_stream_map_stream_id,ps_program_stream_map_info_length,ps_program_stream_CRC, 261 | ps_pes,ps_pes_start_code,ps_pes_stream_id,ps_pes_length,ps_pes_scrambing_control,ps_pes_priority,ps_pes_alignment,ps_pes_copyright,ps_pes_original,ps_pes_pts_dts_flag,ps_pes_escr_flag,ps_pes_es_rate_flag,ps_pes_dsm_trick_mode_flag,ps_pes_additional_info_flag,ps_pes_crc_flag,ps_pes_extension_flag, 262 | ps_pes_header_data_length,ps_pes_header_data_bytes,ps_pes_pts,ps_pes_dts,ps_pes_escr,ps_pes_es_rate,ps_pes_dsm_trick_mode,ps_pes_additional_info,ps_pes_crc,ps_pes_extension,ps_pes_data_bytes, 263 | ps_data,h264_f_bit,h264_nal_ref_idc,h264_nal_unit_type,h265_f_bit,h265_nal_unit_type,h265_nal_layer_id,h265_nal_temporal_id 264 | } 265 | 266 | -- local frame_num = Field.new("frame.number") 267 | -- variable for storing stream info 268 | local stream_info_map = {} 269 | local stream_info_follow = nil 270 | 271 | function is_ps_header(tvb, offset) 272 | if (tvb:len() < (offset+4)) then 273 | return false 274 | end 275 | 276 | if ((tvb:range(offset, 1):uint() == 0x00) and (tvb:range(offset+1, 1):uint() == 0x00) 277 | and (tvb:range(offset+2, 1):uint() == 0x01) and (tvb:range(offset+3, 1):uint() == 0xba)) then 278 | return true 279 | else 280 | return false 281 | end 282 | end 283 | function is_system_header(tvb, offset) 284 | if (tvb:len() < (offset+4)) then 285 | return false 286 | end 287 | 288 | --print(string.format("start code %x %x %x %x",tvb:range(offset, 1):uint(),tvb:range(offset+1, 1):uint(),tvb:range(offset+2, 1):uint(),tvb:range(offset+3, 1):uint())) 289 | if ((tvb:range(offset, 1):uint() == 0x00) and (tvb:range(offset+1, 1):uint() == 0x00) 290 | and (tvb:range(offset+2, 1):uint() == 0x01) and (tvb:range(offset+3, 1):uint() == 0xbb)) then 291 | return true 292 | else 293 | return false 294 | end 295 | end 296 | function is_pes_header(tvb, offset) 297 | if (tvb:len() < (offset+4)) then 298 | return false 299 | end 300 | if ((tvb:range(offset, 1):uint() == 0x00) and (tvb:range(offset+1, 1):uint() == 0x00) 301 | and (tvb:range(offset+2, 1):uint() == 0x01)) then 302 | return true 303 | else 304 | return false 305 | end 306 | end 307 | function is_raw_start(tvb, offset) 308 | if (tvb:len() < (offset+4)) then 309 | return false 310 | end 311 | if ((tvb:range(offset, 1):uint() == 0x00) and (tvb:range(offset+1, 1):uint() == 0x00) 312 | and (tvb:range(offset+2, 1):uint() == 0x00) and (tvb:range(offset+3, 1):uint() == 0x01)) then 313 | return true 314 | else 315 | return false 316 | end 317 | end 318 | function dis_ps_packet_header(tvb, tree, offset) 319 | -- PS packet header 320 | local stuffing_size = tvb:range(offset+13,1):bitfield(5, 3) 321 | local ps_hdr_tree = tree:add(ps_hdr, tvb:range(offset,14+stuffing_size)) 322 | ps_hdr_tree:add(ps_start_code, tvb:range(offset,4)) 323 | 324 | local scr_1 = tvb:range(offset+4,1):bitfield(2,3) 325 | local scr_2 = tvb:range(offset+4,3):bitfield(6,15) 326 | local scr_3 = tvb:range(offset+6,3):bitfield(6,15) 327 | local scr_e = tvb:range(offset+8,2):bitfield(6,9) 328 | local scr = bit.lshift(scr_1,30)+bit.lshift(scr_2,15)+scr_3 329 | ps_hdr_tree:add(ps_scr_base, tvb:range(offset+4,6)):append_text(string.format(": %u",scr)) 330 | ps_hdr_tree:add(ps_scr_ext, tvb:range(offset+4,6)):append_text(string.format(": %u",scr_e)) 331 | ps_hdr_tree:add(ps_multiplex_rate, tvb:range(offset+10,3)) 332 | ps_hdr_tree:add(ps_stuffing_length, tvb:range(offset+13,1)) 333 | if (stuffing_size > 0) then 334 | ps_hdr_tree:add(ps_stuffing_bytes, tvb:range(offset+14,stuffing_size)) 335 | end 336 | end 337 | function dis_system_header(tvb, tree, offset) 338 | -- System header 339 | local system_header_length = tvb:range(offset+4, 2):uint() 340 | local ps_system_header_tree = tree:add(ps_system_header, tvb:range(offset,system_header_length+4+2)) 341 | ps_system_header_tree:add(ps_system_header_start_code, tvb:range(offset,4)) 342 | ps_system_header_tree:add(ps_system_header_length, tvb:range(offset+4,2)) 343 | ps_system_header_tree:add(ps_system_header_rate_bound, tvb:range(offset+6,3)) 344 | ps_system_header_tree:add(ps_system_header_audio_bound, tvb:range(offset+9,1)) 345 | ps_system_header_tree:add(ps_system_header_fixed_flag, tvb:range(offset+9,1)) 346 | ps_system_header_tree:add(ps_system_header_CSPS_flag, tvb:range(offset+9,1)) 347 | ps_system_header_tree:add(ps_system_header_system_audio_lock_flag, tvb:range(offset+10,1)) 348 | ps_system_header_tree:add(ps_system_header_system_video_lock_flag, tvb:range(offset+10,1)) 349 | ps_system_header_tree:add(ps_system_header_vedio_bound, tvb:range(offset+10,1)) 350 | ps_system_header_tree:add(ps_system_header_packet_rate_restriction_flag, tvb:range(offset+11,1)) 351 | if (system_header_length>6) then 352 | local remain_length = system_header_length-6 353 | local shif = offset+12 354 | repeat 355 | ps_system_header_tree:add(ps_system_header_stream_id, tvb:range(shif,1)) 356 | ps_system_header_tree:add(ps_system_header_P_STD_scale, tvb:range(shif+1,2)) 357 | ps_system_header_tree:add(ps_system_header_P_STD_bound, tvb:range(shif+1,2)) 358 | shif = shif+3 359 | remain_length = remain_length-3 360 | until(remain_length<=0) 361 | end 362 | end 363 | function dis_stream_map(tvb, tree, offset) 364 | -- Program stream map 365 | local program_map_length = tvb:range(offset+4, 2):uint() 366 | local ps_program_map_tree = tree:add(ps_program_stream, tvb:range(offset,program_map_length+4+2)) 367 | ps_program_map_tree:add(ps_program_stream_start_code, tvb:range(offset,3)) 368 | ps_program_map_tree:add(ps_program_stream_id, tvb:range(offset+3,1)) 369 | ps_program_map_tree:add(ps_program_stream_length, tvb:range(offset+4,2)) 370 | ps_program_map_tree:add(ps_program_stream_current_next_indicator, tvb:range(offset+6,1)) 371 | ps_program_map_tree:add(ps_program_stream_map_version, tvb:range(offset+6,1)) 372 | ps_program_map_tree:add(ps_program_stream_info_length, tvb:range(offset+8,2)) 373 | local info_len = tvb:range(offset+8, 2):uint() 374 | 375 | ps_program_map_tree:add(ps_program_stream_map_length, tvb:range(offset+10+info_len,2)) --10 = 8+2(info len) 376 | local map_len = tvb:range(offset+10+info_len, 2):uint() 377 | local remain_length = map_len 378 | local shif = offset+12+info_len 379 | repeat 380 | ps_program_map_tree:add(ps_program_stream_map_stream_type, tvb:range(shif,1)) 381 | ps_program_map_tree:add(ps_program_stream_map_stream_id, tvb:range(shif+1,1)) 382 | local stream_type = tvb:range(shif,1):uint() 383 | local stream_id = tvb:range(shif+1,1):uint() 384 | stream_info_map[stream_id] = get_enum_name(ps_stream_type_vals, stream_type) 385 | ps_program_map_tree:add(ps_program_stream_map_info_length, tvb:range(shif+2,2)) 386 | local map_info_len = tvb:range(shif+2, 2):uint() 387 | shif = shif+4+map_info_len 388 | remain_length = remain_length-4-map_info_len 389 | until(remain_length<=0) 390 | 391 | ps_program_map_tree:add(ps_program_stream_CRC, tvb:range(offset+12+info_len+map_len,4)) --12 = 8+2(info len)+2(map len) 392 | end 393 | function dis_pes(tvb, tree, offset, pinfo) 394 | -- PES header 395 | local pes_length = tvb:range(offset+4, 2):uint() 396 | local tvb_len = tvb:len() 397 | local complete_packet = tvb_len>=(offset+pes_length+6) 398 | local ps_pes_tree = tree:add(ps_pes, tvb:range(offset,complete_packet and (pes_length+4+2) or (tvb_len-offset))) 399 | ps_pes_tree:add(ps_pes_start_code, tvb:range(offset,3)) 400 | ps_pes_tree:add(ps_pes_stream_id, tvb:range(offset+3,1)) 401 | local pes_length_tree = ps_pes_tree:add(ps_pes_length, tvb:range(offset+4,2)) 402 | 403 | ps_pes_tree:add(ps_pes_scrambing_control, tvb:range(offset+6,1)) 404 | ps_pes_tree:add(ps_pes_priority, tvb:range(offset+6,1)) 405 | ps_pes_tree:add(ps_pes_alignment, tvb:range(offset+6,1)) 406 | ps_pes_tree:add(ps_pes_copyright, tvb:range(offset+6,1)) 407 | ps_pes_tree:add(ps_pes_original, tvb:range(offset+6,1)) 408 | 409 | ps_pes_tree:add(ps_pes_pts_dts_flag, tvb:range(offset+7,1)) 410 | ps_pes_tree:add(ps_pes_escr_flag, tvb:range(offset+7,1)) 411 | ps_pes_tree:add(ps_pes_es_rate_flag, tvb:range(offset+7,1)) 412 | ps_pes_tree:add(ps_pes_dsm_trick_mode_flag, tvb:range(offset+7,1)) 413 | ps_pes_tree:add(ps_pes_additional_info_flag, tvb:range(offset+7,1)) 414 | ps_pes_tree:add(ps_pes_crc_flag, tvb:range(offset+7,1)) 415 | ps_pes_tree:add(ps_pes_extension_flag, tvb:range(offset+7,1)) 416 | 417 | local pes_header_data_len = tvb:range(offset+8, 1):uint() 418 | local header_data_tree = ps_pes_tree:add(ps_pes_header_data_length, tvb:range(offset+8,1)) 419 | if complete_packet then 420 | pes_length_tree:append_text(string.format(" (Data Len: %u)",pes_length-pes_header_data_len-3)) 421 | else 422 | pes_length_tree:append_text(string.format(" (Data Len: %u|Actual Len: %u)",pes_length-pes_header_data_len-3,tvb_len-offset-9-pes_header_data_len)) 423 | end 424 | 425 | if pes_header_data_len>0 then 426 | header_data_tree:add(ps_pes_header_data_bytes, tvb:range(offset+9,pes_header_data_len)) 427 | 428 | local index = offset+9 429 | local pts_dts_flag = tvb:range(offset+7,1):bitfield(0,2) 430 | if pts_dts_flag == 0x2 then 431 | -- local pts_1 = tvb:range(index,1):bitfield(4,3) 432 | local pts_high = tvb:range(index,1):bitfield(4,1) 433 | local pts_1 = tvb:range(index,1):bitfield(5,2) 434 | local pts_2 = tvb:range(index+1,2):bitfield(0,15) 435 | local pts_3 = tvb:range(index+3,2):bitfield(0,15) 436 | local pts = bit.lshift(pts_1,30)+bit.lshift(pts_2,15)+pts_3 437 | -- ps_pes_tree:add(ps_pes_pts, tvb:range(index,5)):append_text(string.format(": %u",pts)) 438 | ps_pes_tree:add(ps_pes_pts, tvb:range(index,5)):append_text(string.format(": 0x%s",get_int64_string(pts_high,pts))) 439 | index = index + 5 440 | elseif pts_dts_flag == 0x3 then 441 | -- local pts_1 = tvb:range(index,1):bitfield(4,3) 442 | local pts_high = tvb:range(index,1):bitfield(4,1) 443 | local pts_1 = tvb:range(index,1):bitfield(5,2) 444 | local pts_2 = tvb:range(index+1,2):bitfield(0,15) 445 | local pts_3 = tvb:range(index+3,2):bitfield(0,15) 446 | local pts = bit.lshift(pts_1,30)+bit.lshift(pts_2,15)+pts_3 447 | ps_pes_tree:add(ps_pes_pts, tvb:range(index,5)):append_text(string.format(": 0x%s",get_int64_string(pts_high,pts))) 448 | 449 | -- local dts_1 = tvb:range(index+5,1):bitfield(4,3) 450 | local dts_high = tvb:range(index+5,1):bitfield(4,1) 451 | local dts_1 = tvb:range(index+5,1):bitfield(5,2) 452 | local dts_2 = tvb:range(index+6,2):bitfield(0,15) 453 | local dts_3 = tvb:range(index+8,2):bitfield(0,15) 454 | local dts = bit.lshift(dts_1,30)+bit.lshift(dts_2,15)+dts_3 455 | ps_pes_tree:add(ps_pes_dts, tvb:range(index+5,5)):append_text(string.format(": 0x%s",get_int64_string(dts_high,dts))) 456 | index = index + 10 457 | end 458 | local escr_flag = tvb:range(offset+7,1):bitfield(2,1) 459 | if escr_flag == 1 then 460 | -- local escr_1 = tvb:range(index,1):bitfield(2,3) 461 | local escr_high = tvb:range(index,1):bitfield(2,1) 462 | local escr_1 = tvb:range(index,1):bitfield(3,2) 463 | local escr_2 = tvb:range(index,3):bitfield(6,15) 464 | local escr_3 = tvb:range(index+2,3):bitfield(6,15) 465 | local escr_e = tvb:range(index+4,2):bitfield(6,9) 466 | local escr = bit.lshift(escr_1,30)+bit.lshift(escr_2,15)+escr_3 467 | ps_pes_tree:add(ps_pes_escr, tvb:range(index,6)):append_text(string.format(": 0x%s, extension: %u",get_int64_string(escr_high,escr),escr_e)) 468 | index = index + 6 469 | end 470 | local es_rate_flag = tvb:range(offset+7,1):bitfield(3,1) 471 | if es_rate_flag == 1 then 472 | local es_rate = tvb:range(index,3):bitfield(1,22) 473 | ps_pes_tree:add(ps_pes_es_rate, tvb:range(index,3)):append_text(string.format(": %u",dts)) 474 | index = index + 3 475 | end 476 | local dsm_trick_mode_flag = tvb:range(offset+7,1):bitfield(4,1) 477 | if dsm_trick_mode_flag == 1 then 478 | ps_pes_tree:add(ps_pes_dsm_trick_mode, tvb:range(index,1)) 479 | index = index + 1 480 | end 481 | local additional_info_flag = tvb:range(offset+7,1):bitfield(5,1) 482 | if additional_info_flag == 1 then 483 | ps_pes_tree:add(ps_pes_additional_info, tvb:range(index,1)) 484 | index = index + 1 485 | end 486 | local crc_flag = tvb:range(offset+7,1):bitfield(6,1) 487 | if crc_flag == 1 then 488 | ps_pes_tree:add(ps_pes_crc, tvb:range(index,2)) 489 | index = index + 2 490 | end 491 | local extension_flag = tvb:range(offset+7,1):bitfield(7,1) 492 | if extension_flag == 1 then 493 | ps_pes_tree:add(ps_pes_extension, tvb:range(index,1)) 494 | index = index + 1 495 | end 496 | end 497 | 498 | local stream_id = tvb:range(offset+3,1):uint() 499 | local stream_id_name = stream_info_map[stream_id] 500 | if stream_id_name then 501 | stream_info_follow = stream_id_name 502 | end 503 | 504 | -- Start code 3, stream id 1, packet length 2, scrambing|PTS 2, Header length 1 505 | if offset+9+pes_header_data_len>=tvb_len then 506 | return 507 | end 508 | 509 | -- Raw data 510 | local current_len = complete_packet and (pes_length-3-pes_header_data_len) or (tvb_len-offset-9-pes_header_data_len) 511 | local media_raw_tree = ps_pes_tree:add(ps_pes_data_bytes, tvb:range(offset+9+pes_header_data_len, current_len)) 512 | media_raw_tree:set_text(stream_info_follow) 513 | media_raw_tree:append_text(string.format(" (%d)",current_len)) 514 | 515 | local shif = offset+9+pes_header_data_len+4 516 | if "H.264" == stream_info_follow then 517 | media_raw_tree:add(h264_f_bit, tvb:range(shif,1)) 518 | media_raw_tree:add(h264_nal_ref_idc, tvb:range(shif,1)) 519 | media_raw_tree:add(h264_nal_unit_type, tvb:range(shif,1)) 520 | local type = tvb:range(shif,1):bitfield(3, 5) 521 | pinfo.columns.info:append(" ") 522 | pinfo.columns.info:append(get_enum_name(h264_type_summary_values, type)) 523 | elseif "H.265" == stream_info_follow then 524 | media_raw_tree:add(h265_f_bit, tvb:range(shif,2)) 525 | media_raw_tree:add(h265_nal_unit_type, tvb:range(shif,2)) 526 | media_raw_tree:add(h265_nal_layer_id, tvb:range(shif,2)) 527 | media_raw_tree:add(h265_nal_temporal_id, tvb:range(shif,2)) 528 | local type = tvb:range(shif,2):bitfield(1, 6) 529 | pinfo.columns.info:append(" ") 530 | pinfo.columns.info:append(get_enum_name(h265_type_summary_values, type)) 531 | end 532 | 533 | end 534 | function dis_raw_data(tvb, tree, offset, pinfo) 535 | local tvb_len = tvb:len() 536 | local media_raw_tree = tree:add(ps_pes_data_bytes, tvb:range(offset, tvb_len-offset)) 537 | if stream_info_follow then 538 | media_raw_tree:set_text(stream_info_follow) 539 | end 540 | media_raw_tree:append_text(string.format(" (%d)",tvb_len-offset)) 541 | end 542 | -- PS dissector for rtp payload 543 | function proto_ps.dissector(tvb, pinfo, tree) 544 | -- local frame_seqs = frame_num() 545 | -- if (frame_seqs.value == 1) 546 | 547 | -- add proto item to tree 548 | local proto_tree = tree:add(proto_ps, tvb()) 549 | local offset = 0 550 | 551 | if (is_ps_header(tvb, offset)) then 552 | local stuffing_size = tvb:range(offset+13,1):bitfield(5, 3) 553 | dis_ps_packet_header(tvb, proto_tree, offset) 554 | offset = offset + 14 + stuffing_size 555 | 556 | if (is_system_header(tvb, offset)) then 557 | local system_header_length = tvb:range(offset+4, 2):uint() 558 | dis_system_header(tvb, proto_tree, offset) 559 | offset = offset + 4 + 2 + system_header_length 560 | 561 | -- program stream map 562 | local program_map_length = tvb:range(offset+4, 2):uint() 563 | dis_stream_map(tvb, proto_tree, offset) 564 | offset = offset + 4 + 2 + program_map_length 565 | end 566 | 567 | while (is_pes_header(tvb, offset)) 568 | do 569 | local pes_length = tvb:range(offset+4, 2):uint() 570 | dis_pes(tvb, proto_tree, offset, pinfo) 571 | offset = offset + 4 + 2 + pes_length 572 | end 573 | else 574 | if (is_pes_header(tvb, offset)) then 575 | dis_pes(tvb, proto_tree, offset, pinfo) 576 | else 577 | dis_raw_data(tvb, proto_tree, offset, pinfo) 578 | end 579 | end 580 | 581 | pinfo.columns.protocol = "PS" 582 | end 583 | 584 | -- set this protocal preferences 585 | local prefs = proto_ps.prefs 586 | prefs.dyn_pt = Pref.range("PS dynamic payload type", "", "Dynamic payload types which will be interpreted as PS; Values must be in the range 96 - 127", 127) 587 | 588 | -- register this dissector to dynamic payload type dissectorTable 589 | local dyn_payload_type_table = DissectorTable.get("rtp_dyn_payload_type") 590 | dyn_payload_type_table:add("ps", proto_ps) 591 | 592 | -- register this dissector to specific payload type (specified in preferences windows) 593 | local payload_type_table = DissectorTable.get("rtp.pt") 594 | local old_dyn_pt = nil 595 | local old_dissector = nil 596 | 597 | function proto_ps.init() 598 | if (prefs.dyn_pt ~= old_dyn_pt) then 599 | -- reset old dissector 600 | if (old_dyn_pt ~= nil and string.len(old_dyn_pt) > 0) then 601 | local pt_numbers = getArray(tostring(old_dyn_pt)) 602 | for index,pt_number in pairs(pt_numbers) do 603 | -- replace this proto with old proto on old payload type 604 | if old_dissector ~= nil and old_dissector[index] ~= nil then 605 | payload_type_table:add(pt_number, old_dissector[index]) 606 | else -- just remove this proto 607 | payload_type_table:remove(pt_number, proto_ps) 608 | end 609 | end 610 | end 611 | 612 | old_dyn_pt = prefs.dyn_pt -- save current payload type's dissector 613 | 614 | if (prefs.dyn_pt ~= nil and string.len(prefs.dyn_pt) > 0) then 615 | local pt_numbers = getArray(tostring(prefs.dyn_pt)) 616 | old_dissector = {} 617 | for index,pt_number in pairs(pt_numbers) do 618 | local dissector = payload_type_table:get_dissector(pt_number) 619 | -- table.insert(old_dissector,index,dissector) 620 | old_dissector[index] = dissector 621 | payload_type_table:add(pt_number, proto_ps) 622 | end 623 | end 624 | end 625 | end 626 | 627 | function getArray(str) 628 | local strList = {} 629 | string.gsub(str, '[^,]+',function (w) 630 | local pos = string.find(w,'-') 631 | if not pos then 632 | table.insert(strList,tonumber(w)) 633 | else 634 | local begin_index = string.sub(w,1,pos-1) 635 | local end_index = string.sub(w,pos+1,#w) 636 | for index = begin_index,end_index do 637 | table.insert(strList,index) 638 | end 639 | end 640 | end) 641 | return strList 642 | end 643 | end 644 | --------------------------------------------------------------------------------