Skip to content

Commit

Permalink
avoid ReceivedPacketsDropped for first received packet
Browse files Browse the repository at this point in the history
added firstMessageReceived to the Particpant struct. Set to false when packet is receievd.
Only when USE_EXT_CALLBACKS is defined
  • Loading branch information
lathoub committed Jan 16, 2021
1 parent 3504cfc commit 84f3dca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/AppleMIDI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,21 +1011,21 @@ void AppleMIDISession<UdpClass, Settings, Platform>::ReceivedRtp(const Rtp_t& rt
#ifdef USE_EXT_CALLBACKS
auto offset = (rtp.timestamp - pParticipant->offsetEstimate);
auto latency = (int32_t)(rtpMidiClock.Now() - offset);
#endif
if (rtp.sequenceNr - pParticipant->receiveSequenceNr - 1 != 0) {

#ifdef USE_EXT_CALLBACKS
if (pParticipant->firstMessageReceived == false
&& rtp.sequenceNr - pParticipant->receiveSequenceNr - 1 != 0) {
// avoids first message to generate sequence exception
// as we do not know the last sequenceNr received.
pParticipant->firstMessageReceived = false;
if (nullptr != _exceptionCallback)
_exceptionCallback(ssrc, ReceivedPacketsDropped, rtp.sequenceNr - pParticipant->receiveSequenceNr - 1);
#endif
}

pParticipant->receiveSequenceNr = rtp.sequenceNr;

#ifdef USE_EXT_CALLBACKS
if (nullptr != _receivedRtpCallback)
_receivedRtpCallback(pParticipant->ssrc, rtp, latency);
#endif

pParticipant->receiveSequenceNr = rtp.sequenceNr;
}
else
{
Expand Down
4 changes: 3 additions & 1 deletion src/AppleMIDI_Participant.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ struct Participant
bool doReceiverFeedback = false;

uint16_t sendSequenceNr = random(1, UINT16_MAX); // http://www.rfc-editor.org/rfc/rfc6295.txt , 2.1. RTP Header
uint16_t receiveSequenceNr;
uint16_t receiveSequenceNr = 0;

unsigned long lastSyncExchangeTime;

#ifdef APPLEMIDI_INITIATOR
Expand All @@ -33,6 +34,7 @@ struct Participant
#endif

#ifdef USE_EXT_CALLBACKS
bool firstMessageReceived = true;
uint32_t offsetEstimate;
#endif

Expand Down

0 comments on commit 84f3dca

Please sign in to comment.