OLD | NEW |
1 function rtpAnalyze( input_file ) | 1 function rtpAnalyze( input_file ) |
2 %RTP_ANALYZE Analyze RTP stream(s) from a txt file | 2 %RTP_ANALYZE Analyze RTP stream(s) from a txt file |
3 % The function takes the output from the command line tool rtp_analyze | 3 % The function takes the output from the command line tool rtp_analyze |
4 % and analyzes the stream(s) therein. First, process your rtpdump file | 4 % and analyzes the stream(s) therein. First, process your rtpdump file |
5 % through rtp_analyze (from command line): | 5 % through rtp_analyze (from command line): |
6 % $ out/Debug/rtp_analyze my_file.rtp my_file.txt | 6 % $ out/Debug/rtp_analyze my_file.rtp my_file.txt |
7 % Then load it with this function (in Matlab): | 7 % Then load it with this function (in Matlab): |
8 % >> rtpAnalyze('my_file.txt') | 8 % >> rtpAnalyze('my_file.txt') |
9 | 9 |
10 % Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 10 % Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 uPT = unique(PT); | 58 uPT = unique(PT); |
59 if length(uPT) > 1 | 59 if length(uPT) > 1 |
60 warning('This tool cannot yet handle changes in codec sample rate'); | 60 warning('This tool cannot yet handle changes in codec sample rate'); |
61 end | 61 end |
62 fprintf('Payload type(s): %i', uPT(1)); | 62 fprintf('Payload type(s): %i', uPT(1)); |
63 if length(uPT) > 1 | 63 if length(uPT) > 1 |
64 fprintf(', %i', uPT(2:end)); | 64 fprintf(', %i', uPT(2:end)); |
65 end | 65 end |
66 fprintf('\n'); | 66 fprintf('\n'); |
67 fprintf('Packets: %i\n', length(SeqNo)); | 67 fprintf('Packets: %i\n', length(SeqNo)); |
| 68 SortSeqNo = sort(SeqNoUW); |
68 fprintf('Missing sequence numbers: %i\n', ... | 69 fprintf('Missing sequence numbers: %i\n', ... |
69 length(find(diff(sort(SeqNoUW)) > 1))); | 70 length(find(diff(SortSeqNo) > 1))); |
70 fprintf('Reordered packets: %i\n', length(find(diff(sort(SeqNoUW)) < 1))); | 71 fprintf('Duplicated packets: %i\n', length(find(diff(SortSeqNo) == 0))); |
| 72 reorderIx = findReorderedPackets(SeqNoUW); |
| 73 fprintf('Reordered packets: %i\n', length(reorderIx)); |
71 tsdiff = diff(TimeStampUW); | 74 tsdiff = diff(TimeStampUW); |
72 tsdiff = tsdiff(diff(SeqNoUW) == 1); | 75 tsdiff = tsdiff(diff(SeqNoUW) == 1); |
73 [utsdiff, ~, ixtsdiff] = unique(tsdiff); | 76 [utsdiff, ~, ixtsdiff] = unique(tsdiff); |
74 fprintf('Common packet sizes:\n'); | 77 fprintf('Common packet sizes:\n'); |
75 for i = 1:length(utsdiff) | 78 for i = 1:length(utsdiff) |
76 fprintf(' %i samples (%i%%)\n', ... | 79 fprintf(' %i samples (%i%%)\n', ... |
77 utsdiff(i), ... | 80 utsdiff(i), ... |
78 round(100 * length(find(ixtsdiff == i))/length(ixtsdiff))); | 81 round(100 * length(find(ixtsdiff == i))/length(ixtsdiff))); |
79 end | 82 end |
80 | 83 |
(...skipping 29 matching lines...) Expand all Loading... |
110 | 113 |
111 fprintf('Sent average bitrate: %i kbps\n', ... | 114 fprintf('Sent average bitrate: %i kbps\n', ... |
112 round(sum(Size) * 8 / (SendTimeMs(end)-SendTimeMs(1)))); | 115 round(sum(Size) * 8 / (SendTimeMs(end)-SendTimeMs(1)))); |
113 | 116 |
114 fprintf('Received average bitrate: %i kbps\n', ... | 117 fprintf('Received average bitrate: %i kbps\n', ... |
115 round(sum(Size) * 8 / (ArrTime(end)-ArrTime(1)))); | 118 round(sum(Size) * 8 / (ArrTime(end)-ArrTime(1)))); |
116 | 119 |
117 %% Plots. | 120 %% Plots. |
118 delay = ArrTime - SendTimeMs; | 121 delay = ArrTime - SendTimeMs; |
119 delay = delay - min(delay); | 122 delay = delay - min(delay); |
| 123 delayOrdered = delay; |
| 124 delayOrdered(reorderIx) = nan; % Set reordered packets to NaN. |
| 125 delayReordered = delay(reorderIx); % Pick the reordered packets. |
| 126 sendTimeMsReordered = SendTimeMs(reorderIx); |
| 127 |
| 128 % Sort time arrays in packet send order. |
| 129 [~, sortix] = sort(SeqNoUW); |
| 130 SendTimeMs = SendTimeMs(sortix); |
| 131 Size = Size(sortix); |
| 132 delayOrdered = delayOrdered(sortix); |
| 133 |
120 figure | 134 figure |
121 plot(SendTimeMs / 1000, delay); | 135 plot(SendTimeMs / 1000, delayOrdered, ... |
| 136 sendTimeMsReordered / 1000, delayReordered, 'r.'); |
122 xlabel('Send time [s]'); | 137 xlabel('Send time [s]'); |
123 ylabel('Relative transport delay [ms]'); | 138 ylabel('Relative transport delay [ms]'); |
124 title(sprintf('SSRC: %s', SSRC{1})); | 139 title(sprintf('SSRC: %s', SSRC{1})); |
125 | 140 |
126 SendBitrateKbps = 8 * Size(1:end-1) ./ diff(SendTimeMs); | 141 SendBitrateKbps = 8 * Size(1:end-1) ./ diff(SendTimeMs); |
127 figure | 142 figure |
128 plot(SendTimeMs(1:end-1)/1000, SendBitrateKbps); | 143 plot(SendTimeMs(1:end-1)/1000, SendBitrateKbps); |
129 xlabel('Send time [s]'); | 144 xlabel('Send time [s]'); |
130 ylabel('Send bitrate [kbps]'); | 145 ylabel('Send bitrate [kbps]'); |
131 end | 146 end |
132 | 147 |
| 148 %% Subfunctions. |
| 149 |
| 150 % findReorderedPackets returns the index to all packets that are considered |
| 151 % old compared with the largest seen sequence number. The input seqNo must |
| 152 % be unwrapped for this to work. |
| 153 function reorderIx = findReorderedPackets(seqNo) |
| 154 largestSeqNo = seqNo(1); |
| 155 reorderIx = []; |
| 156 for i = 2:length(seqNo) |
| 157 if seqNo(i) < largestSeqNo |
| 158 reorderIx = [reorderIx; i]; %#ok<AGROW> |
| 159 else |
| 160 largestSeqNo = seqNo(i); |
| 161 end |
| 162 end |
| 163 end |
| 164 |
133 %% Auto-generated subfunction. | 165 %% Auto-generated subfunction. |
134 function [SeqNo,TimeStamp,SendTime,Size,PT,M,SSRC] = ... | 166 function [SeqNo,TimeStamp,SendTime,Size,PT,M,SSRC] = ... |
135 importfile(filename, startRow, endRow) | 167 importfile(filename, startRow, endRow) |
136 %IMPORTFILE Import numeric data from a text file as column vectors. | 168 %IMPORTFILE Import numeric data from a text file as column vectors. |
137 % [SEQNO,TIMESTAMP,SENDTIME,SIZE,PT,M,SSRC] = IMPORTFILE(FILENAME) Reads | 169 % [SEQNO,TIMESTAMP,SENDTIME,SIZE,PT,M,SSRC] = IMPORTFILE(FILENAME) Reads |
138 % data from text file FILENAME for the default selection. | 170 % data from text file FILENAME for the default selection. |
139 % | 171 % |
140 % [SEQNO,TIMESTAMP,SENDTIME,SIZE,PT,M,SSRC] = IMPORTFILE(FILENAME, | 172 % [SEQNO,TIMESTAMP,SENDTIME,SIZE,PT,M,SSRC] = IMPORTFILE(FILENAME, |
141 % STARTROW, ENDROW) Reads data from rows STARTROW through ENDROW of text | 173 % STARTROW, ENDROW) Reads data from rows STARTROW through ENDROW of text |
142 % file FILENAME. | 174 % file FILENAME. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 %% Allocate imported array to column variable names | 230 %% Allocate imported array to column variable names |
199 SeqNo = dataArray{:, 1}; | 231 SeqNo = dataArray{:, 1}; |
200 TimeStamp = dataArray{:, 2}; | 232 TimeStamp = dataArray{:, 2}; |
201 SendTime = dataArray{:, 3}; | 233 SendTime = dataArray{:, 3}; |
202 Size = dataArray{:, 4}; | 234 Size = dataArray{:, 4}; |
203 PT = dataArray{:, 5}; | 235 PT = dataArray{:, 5}; |
204 M = dataArray{:, 6}; | 236 M = dataArray{:, 6}; |
205 SSRC = dataArray{:, 7}; | 237 SSRC = dataArray{:, 7}; |
206 end | 238 end |
207 | 239 |
OLD | NEW |