From 76381d921f817888d9c050d5f2fcbe3de412e0d7 Mon Sep 17 00:00:00 2001 From: Henrik Lundin Date: Tue, 16 Jun 2015 09:28:09 +0200 Subject: [PATCH] Update rtpAnalyze matlab tool to handle reordered packets With this change, the tool will find and mark reordered packets in the plot. Furthermore, the instantaneous send bitrate will be correct even for reordered packets. BUG=webrtc:2692 R=tina.legrand@webrtc.org Review URL: https://codereview.webrtc.org/1172533004. Cr-Commit-Position: refs/heads/master@{#9443} --- tools/matlab/rtpAnalyze.m | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/tools/matlab/rtpAnalyze.m b/tools/matlab/rtpAnalyze.m index 7ad45631b..eb0cb8f58 100644 --- a/tools/matlab/rtpAnalyze.m +++ b/tools/matlab/rtpAnalyze.m @@ -65,9 +65,12 @@ if length(uPT) > 1 end fprintf('\n'); fprintf('Packets: %i\n', length(SeqNo)); +SortSeqNo = sort(SeqNoUW); fprintf('Missing sequence numbers: %i\n', ... - length(find(diff(sort(SeqNoUW)) > 1))); -fprintf('Reordered packets: %i\n', length(find(diff(sort(SeqNoUW)) < 1))); + length(find(diff(SortSeqNo) > 1))); +fprintf('Duplicated packets: %i\n', length(find(diff(SortSeqNo) == 0))); +reorderIx = findReorderedPackets(SeqNoUW); +fprintf('Reordered packets: %i\n', length(reorderIx)); tsdiff = diff(TimeStampUW); tsdiff = tsdiff(diff(SeqNoUW) == 1); [utsdiff, ~, ixtsdiff] = unique(tsdiff); @@ -117,8 +120,20 @@ fprintf('Received average bitrate: %i kbps\n', ... %% Plots. delay = ArrTime - SendTimeMs; delay = delay - min(delay); +delayOrdered = delay; +delayOrdered(reorderIx) = nan; % Set reordered packets to NaN. +delayReordered = delay(reorderIx); % Pick the reordered packets. +sendTimeMsReordered = SendTimeMs(reorderIx); + +% Sort time arrays in packet send order. +[~, sortix] = sort(SeqNoUW); +SendTimeMs = SendTimeMs(sortix); +Size = Size(sortix); +delayOrdered = delayOrdered(sortix); + figure -plot(SendTimeMs / 1000, delay); +plot(SendTimeMs / 1000, delayOrdered, ... + sendTimeMsReordered / 1000, delayReordered, 'r.'); xlabel('Send time [s]'); ylabel('Relative transport delay [ms]'); title(sprintf('SSRC: %s', SSRC{1})); @@ -130,6 +145,23 @@ xlabel('Send time [s]'); ylabel('Send bitrate [kbps]'); end +%% Subfunctions. + +% findReorderedPackets returns the index to all packets that are considered +% old compared with the largest seen sequence number. The input seqNo must +% be unwrapped for this to work. +function reorderIx = findReorderedPackets(seqNo) +largestSeqNo = seqNo(1); +reorderIx = []; +for i = 2:length(seqNo) + if seqNo(i) < largestSeqNo + reorderIx = [reorderIx; i]; %#ok + else + largestSeqNo = seqNo(i); + end +end +end + %% Auto-generated subfunction. function [SeqNo,TimeStamp,SendTime,Size,PT,M,SSRC] = ... importfile(filename, startRow, endRow)